1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994-2013 Free Software Foundation, Inc.
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
9 This file is part of GAS, the GNU Assembler.
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3, or (at your option)
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
30 #include "safe-ctype.h"
33 #include "libiberty.h"
34 #include "opcode/arm.h"
38 #include "dw2gencfi.h"
41 #include "dwarf2dbg.h"
44 /* Must be at least the size of the largest unwind opcode (currently two). */
45 #define ARM_OPCODE_CHUNK_SIZE 8
47 /* This structure holds the unwinding state. */
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
55 /* The segment containing the function. */
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
62 /* The number of bytes pushed to the stack. */
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
67 offsetT pending_offset;
68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
69 hold the reg+offset to use when restoring sp from a frame pointer. */
72 /* Nonzero if an unwind_setfp directive has been seen. */
74 /* Nonzero if the last opcode restores sp from fp_reg. */
75 unsigned sp_restored:1;
80 /* Results from operand parsing worker functions. */
84 PARSE_OPERAND_SUCCESS,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87 } parse_operand_result;
96 /* Types of processor to assemble for. */
98 /* The code that was here used to select a default CPU depending on compiler
99 pre-defines which were only present when doing native builds, thus
100 changing gas' default behaviour depending upon the build host.
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
108 # define FPU_DEFAULT FPU_ARCH_FPA
109 # elif defined (TE_NetBSD)
111 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
113 /* Legacy a.out format. */
114 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
116 # elif defined (TE_VXWORKS)
117 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
119 /* For backwards compatibility, default to FPA. */
120 # define FPU_DEFAULT FPU_ARCH_FPA
122 #endif /* ifndef FPU_DEFAULT */
124 #define streq(a, b) (strcmp (a, b) == 0)
126 static arm_feature_set cpu_variant;
127 static arm_feature_set arm_arch_used;
128 static arm_feature_set thumb_arch_used;
130 /* Flags stored in private area of BFD structure. */
131 static int uses_apcs_26 = FALSE;
132 static int atpcs = FALSE;
133 static int support_interwork = FALSE;
134 static int uses_apcs_float = FALSE;
135 static int pic_code = FALSE;
136 static int fix_v4bx = FALSE;
137 /* Warn on using deprecated features. */
138 static int warn_on_deprecated = TRUE;
141 /* Variables that we set while parsing command-line options. Once all
142 options have been read we re-process these values to set the real
144 static const arm_feature_set *legacy_cpu = NULL;
145 static const arm_feature_set *legacy_fpu = NULL;
147 static const arm_feature_set *mcpu_cpu_opt = NULL;
148 static const arm_feature_set *mcpu_fpu_opt = NULL;
149 static const arm_feature_set *march_cpu_opt = NULL;
150 static const arm_feature_set *march_fpu_opt = NULL;
151 static const arm_feature_set *mfpu_opt = NULL;
152 static const arm_feature_set *object_arch = NULL;
154 /* Constants for known architecture features. */
155 static const arm_feature_set fpu_default = FPU_DEFAULT;
156 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
157 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
158 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
159 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
160 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
161 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
162 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
163 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166 static const arm_feature_set cpu_default = CPU_DEFAULT;
169 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
170 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
171 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
172 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
173 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
174 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
175 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
176 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
177 static const arm_feature_set arm_ext_v4t_5 =
178 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
179 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
180 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
181 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
182 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
183 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
184 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
185 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
186 static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
187 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
188 static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
189 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
190 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
191 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
192 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
193 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
194 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
195 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
196 static const arm_feature_set arm_ext_v8 = ARM_FEATURE (ARM_EXT_V8, 0);
197 static const arm_feature_set arm_ext_m =
198 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
199 static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
200 static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
201 static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
202 static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
203 static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 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;
209 static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
211 static const arm_feature_set arm_cext_iwmmxt2 =
212 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
213 static const arm_feature_set arm_cext_iwmmxt =
214 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
215 static const arm_feature_set arm_cext_xscale =
216 ARM_FEATURE (0, ARM_CEXT_XSCALE);
217 static const arm_feature_set arm_cext_maverick =
218 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
219 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
220 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
221 static const arm_feature_set fpu_vfp_ext_v1xd =
222 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
223 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
224 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
225 static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
226 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
227 static const arm_feature_set fpu_vfp_ext_d32 =
228 ARM_FEATURE (0, FPU_VFP_EXT_D32);
229 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
230 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
231 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
232 static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
233 static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
234 static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
235 static const arm_feature_set fpu_vfp_ext_armv8 =
236 ARM_FEATURE (0, FPU_VFP_EXT_ARMV8);
237 static const arm_feature_set fpu_neon_ext_armv8 =
238 ARM_FEATURE (0, FPU_NEON_EXT_ARMV8);
239 static const arm_feature_set fpu_crypto_ext_armv8 =
240 ARM_FEATURE (0, FPU_CRYPTO_EXT_ARMV8);
242 static int mfloat_abi_opt = -1;
243 /* Record user cpu selection for object attributes. */
244 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
245 /* Must be long enough to hold any of the names in arm_cpus. */
246 static char selected_cpu_name[16];
248 /* Return if no cpu was selected on command-line. */
250 no_cpu_selected (void)
252 return selected_cpu.core == arm_arch_none.core
253 && selected_cpu.coproc == arm_arch_none.coproc;
258 static int meabi_flags = EABI_DEFAULT;
260 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
263 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
268 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
273 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
274 symbolS * GOT_symbol;
277 /* 0: assemble for ARM,
278 1: assemble for Thumb,
279 2: assemble for Thumb even though target CPU does not support thumb
281 static int thumb_mode = 0;
282 /* A value distinct from the possible values for thumb_mode that we
283 can use to record whether thumb_mode has been copied into the
284 tc_frag_data field of a frag. */
285 #define MODE_RECORDED (1 << 4)
287 /* Specifies the intrinsic IT insn behavior mode. */
288 enum implicit_it_mode
290 IMPLICIT_IT_MODE_NEVER = 0x00,
291 IMPLICIT_IT_MODE_ARM = 0x01,
292 IMPLICIT_IT_MODE_THUMB = 0x02,
293 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
295 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
297 /* If unified_syntax is true, we are processing the new unified
298 ARM/Thumb syntax. Important differences from the old ARM mode:
300 - Immediate operands do not require a # prefix.
301 - Conditional affixes always appear at the end of the
302 instruction. (For backward compatibility, those instructions
303 that formerly had them in the middle, continue to accept them
305 - The IT instruction may appear, and if it does is validated
306 against subsequent conditional affixes. It does not generate
309 Important differences from the old Thumb mode:
311 - Immediate operands do not require a # prefix.
312 - Most of the V6T2 instructions are only available in unified mode.
313 - The .N and .W suffixes are recognized and honored (it is an error
314 if they cannot be honored).
315 - All instructions set the flags if and only if they have an 's' affix.
316 - Conditional affixes may be used. They are validated against
317 preceding IT instructions. Unlike ARM mode, you cannot use a
318 conditional affix except in the scope of an IT instruction. */
320 static bfd_boolean unified_syntax = FALSE;
322 /* An immediate operand can start with #, and ld*, st*, pld operands
323 can contain [ and ]. We need to tell APP not to elide whitespace
324 before a [, which can appear as the first operand for pld. */
325 const char arm_symbol_chars[] = "#[]";
340 enum neon_el_type type;
344 #define NEON_MAX_TYPE_ELS 4
348 struct neon_type_el el[NEON_MAX_TYPE_ELS];
352 enum it_instruction_type
357 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
358 if inside, should be the last one. */
359 NEUTRAL_IT_INSN, /* This could be either inside or outside,
360 i.e. BKPT and NOP. */
361 IT_INSN /* The IT insn has been parsed. */
364 /* The maximum number of operands we need. */
365 #define ARM_IT_MAX_OPERANDS 6
370 unsigned long instruction;
374 /* "uncond_value" is set to the value in place of the conditional field in
375 unconditional versions of the instruction, or -1 if nothing is
378 struct neon_type vectype;
379 /* This does not indicate an actual NEON instruction, only that
380 the mnemonic accepts neon-style type suffixes. */
382 /* Set to the opcode if the instruction needs relaxation.
383 Zero if the instruction is not relaxed. */
387 bfd_reloc_code_real_type type;
392 enum it_instruction_type it_insn_type;
398 struct neon_type_el vectype;
399 unsigned present : 1; /* Operand present. */
400 unsigned isreg : 1; /* Operand was a register. */
401 unsigned immisreg : 1; /* .imm field is a second register. */
402 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
403 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
404 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
405 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
406 instructions. This allows us to disambiguate ARM <-> vector insns. */
407 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
408 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
409 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
410 unsigned issingle : 1; /* Operand is VFP single-precision register. */
411 unsigned hasreloc : 1; /* Operand has relocation suffix. */
412 unsigned writeback : 1; /* Operand has trailing ! */
413 unsigned preind : 1; /* Preindexed address. */
414 unsigned postind : 1; /* Postindexed address. */
415 unsigned negative : 1; /* Index register was negated. */
416 unsigned shifted : 1; /* Shift applied to operation. */
417 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
418 } operands[ARM_IT_MAX_OPERANDS];
421 static struct arm_it inst;
423 #define NUM_FLOAT_VALS 8
425 const char * fp_const[] =
427 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
430 /* Number of littlenums required to hold an extended precision number. */
431 #define MAX_LITTLENUMS 6
433 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
443 #define CP_T_X 0x00008000
444 #define CP_T_Y 0x00400000
446 #define CONDS_BIT 0x00100000
447 #define LOAD_BIT 0x00100000
449 #define DOUBLE_LOAD_FLAG 0x00000001
453 const char * template_name;
457 #define COND_ALWAYS 0xE
461 const char * template_name;
465 struct asm_barrier_opt
467 const char * template_name;
469 const arm_feature_set arch;
472 /* The bit that distinguishes CPSR and SPSR. */
473 #define SPSR_BIT (1 << 22)
475 /* The individual PSR flag bits. */
476 #define PSR_c (1 << 16)
477 #define PSR_x (1 << 17)
478 #define PSR_s (1 << 18)
479 #define PSR_f (1 << 19)
484 bfd_reloc_code_real_type reloc;
489 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
490 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
495 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
498 /* Bits for DEFINED field in neon_typed_alias. */
499 #define NTA_HASTYPE 1
500 #define NTA_HASINDEX 2
502 struct neon_typed_alias
504 unsigned char defined;
506 struct neon_type_el eltype;
509 /* ARM register categories. This includes coprocessor numbers and various
510 architecture extensions' registers. */
537 /* Structure for a hash table entry for a register.
538 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
539 information which states whether a vector type or index is specified (for a
540 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
546 unsigned char builtin;
547 struct neon_typed_alias * neon;
550 /* Diagnostics used when we don't get a register of the expected type. */
551 const char * const reg_expected_msgs[] =
553 N_("ARM register expected"),
554 N_("bad or missing co-processor number"),
555 N_("co-processor register expected"),
556 N_("FPA register expected"),
557 N_("VFP single precision register expected"),
558 N_("VFP/Neon double precision register expected"),
559 N_("Neon quad precision register expected"),
560 N_("VFP single or double precision register expected"),
561 N_("Neon double or quad precision register expected"),
562 N_("VFP single, double or Neon quad precision register expected"),
563 N_("VFP system register expected"),
564 N_("Maverick MVF register expected"),
565 N_("Maverick MVD register expected"),
566 N_("Maverick MVFX register expected"),
567 N_("Maverick MVDX register expected"),
568 N_("Maverick MVAX register expected"),
569 N_("Maverick DSPSC register expected"),
570 N_("iWMMXt data register expected"),
571 N_("iWMMXt control register expected"),
572 N_("iWMMXt scalar register expected"),
573 N_("XScale accumulator register expected"),
576 /* Some well known registers that we refer to directly elsewhere. */
582 /* ARM instructions take 4bytes in the object file, Thumb instructions
588 /* Basic string to match. */
589 const char * template_name;
591 /* Parameters to instruction. */
592 unsigned int operands[8];
594 /* Conditional tag - see opcode_lookup. */
595 unsigned int tag : 4;
597 /* Basic instruction code. */
598 unsigned int avalue : 28;
600 /* Thumb-format instruction code. */
603 /* Which architecture variant provides this instruction. */
604 const arm_feature_set * avariant;
605 const arm_feature_set * tvariant;
607 /* Function to call to encode instruction in ARM format. */
608 void (* aencode) (void);
610 /* Function to call to encode instruction in Thumb format. */
611 void (* tencode) (void);
614 /* Defines for various bits that we will want to toggle. */
615 #define INST_IMMEDIATE 0x02000000
616 #define OFFSET_REG 0x02000000
617 #define HWOFFSET_IMM 0x00400000
618 #define SHIFT_BY_REG 0x00000010
619 #define PRE_INDEX 0x01000000
620 #define INDEX_UP 0x00800000
621 #define WRITE_BACK 0x00200000
622 #define LDM_TYPE_2_OR_3 0x00400000
623 #define CPSI_MMOD 0x00020000
625 #define LITERAL_MASK 0xf000f000
626 #define OPCODE_MASK 0xfe1fffff
627 #define V4_STR_BIT 0x00000020
629 #define T2_SUBS_PC_LR 0xf3de8f00
631 #define DATA_OP_SHIFT 21
633 #define T2_OPCODE_MASK 0xfe1fffff
634 #define T2_DATA_OP_SHIFT 21
636 #define A_COND_MASK 0xf0000000
637 #define A_PUSH_POP_OP_MASK 0x0fff0000
639 /* Opcodes for pushing/poping registers to/from the stack. */
640 #define A1_OPCODE_PUSH 0x092d0000
641 #define A2_OPCODE_PUSH 0x052d0004
642 #define A2_OPCODE_POP 0x049d0004
644 /* Codes to distinguish the arithmetic instructions. */
655 #define OPCODE_CMP 10
656 #define OPCODE_CMN 11
657 #define OPCODE_ORR 12
658 #define OPCODE_MOV 13
659 #define OPCODE_BIC 14
660 #define OPCODE_MVN 15
662 #define T2_OPCODE_AND 0
663 #define T2_OPCODE_BIC 1
664 #define T2_OPCODE_ORR 2
665 #define T2_OPCODE_ORN 3
666 #define T2_OPCODE_EOR 4
667 #define T2_OPCODE_ADD 8
668 #define T2_OPCODE_ADC 10
669 #define T2_OPCODE_SBC 11
670 #define T2_OPCODE_SUB 13
671 #define T2_OPCODE_RSB 14
673 #define T_OPCODE_MUL 0x4340
674 #define T_OPCODE_TST 0x4200
675 #define T_OPCODE_CMN 0x42c0
676 #define T_OPCODE_NEG 0x4240
677 #define T_OPCODE_MVN 0x43c0
679 #define T_OPCODE_ADD_R3 0x1800
680 #define T_OPCODE_SUB_R3 0x1a00
681 #define T_OPCODE_ADD_HI 0x4400
682 #define T_OPCODE_ADD_ST 0xb000
683 #define T_OPCODE_SUB_ST 0xb080
684 #define T_OPCODE_ADD_SP 0xa800
685 #define T_OPCODE_ADD_PC 0xa000
686 #define T_OPCODE_ADD_I8 0x3000
687 #define T_OPCODE_SUB_I8 0x3800
688 #define T_OPCODE_ADD_I3 0x1c00
689 #define T_OPCODE_SUB_I3 0x1e00
691 #define T_OPCODE_ASR_R 0x4100
692 #define T_OPCODE_LSL_R 0x4080
693 #define T_OPCODE_LSR_R 0x40c0
694 #define T_OPCODE_ROR_R 0x41c0
695 #define T_OPCODE_ASR_I 0x1000
696 #define T_OPCODE_LSL_I 0x0000
697 #define T_OPCODE_LSR_I 0x0800
699 #define T_OPCODE_MOV_I8 0x2000
700 #define T_OPCODE_CMP_I8 0x2800
701 #define T_OPCODE_CMP_LR 0x4280
702 #define T_OPCODE_MOV_HR 0x4600
703 #define T_OPCODE_CMP_HR 0x4500
705 #define T_OPCODE_LDR_PC 0x4800
706 #define T_OPCODE_LDR_SP 0x9800
707 #define T_OPCODE_STR_SP 0x9000
708 #define T_OPCODE_LDR_IW 0x6800
709 #define T_OPCODE_STR_IW 0x6000
710 #define T_OPCODE_LDR_IH 0x8800
711 #define T_OPCODE_STR_IH 0x8000
712 #define T_OPCODE_LDR_IB 0x7800
713 #define T_OPCODE_STR_IB 0x7000
714 #define T_OPCODE_LDR_RW 0x5800
715 #define T_OPCODE_STR_RW 0x5000
716 #define T_OPCODE_LDR_RH 0x5a00
717 #define T_OPCODE_STR_RH 0x5200
718 #define T_OPCODE_LDR_RB 0x5c00
719 #define T_OPCODE_STR_RB 0x5400
721 #define T_OPCODE_PUSH 0xb400
722 #define T_OPCODE_POP 0xbc00
724 #define T_OPCODE_BRANCH 0xe000
726 #define THUMB_SIZE 2 /* Size of thumb instruction. */
727 #define THUMB_PP_PC_LR 0x0100
728 #define THUMB_LOAD_BIT 0x0800
729 #define THUMB2_LOAD_BIT 0x00100000
731 #define BAD_ARGS _("bad arguments to instruction")
732 #define BAD_SP _("r13 not allowed here")
733 #define BAD_PC _("r15 not allowed here")
734 #define BAD_COND _("instruction cannot be conditional")
735 #define BAD_OVERLAP _("registers may not be the same")
736 #define BAD_HIREG _("lo register required")
737 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
738 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
739 #define BAD_BRANCH _("branch must be last instruction in IT block")
740 #define BAD_NOT_IT _("instruction not allowed in IT block")
741 #define BAD_FPU _("selected FPU does not support instruction")
742 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
743 #define BAD_IT_COND _("incorrect condition in IT block")
744 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
745 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
746 #define BAD_PC_ADDRESSING \
747 _("cannot use register index with PC-relative addressing")
748 #define BAD_PC_WRITEBACK \
749 _("cannot use writeback with PC-relative addressing")
750 #define BAD_RANGE _("branch out of range")
752 static struct hash_control * arm_ops_hsh;
753 static struct hash_control * arm_cond_hsh;
754 static struct hash_control * arm_shift_hsh;
755 static struct hash_control * arm_psr_hsh;
756 static struct hash_control * arm_v7m_psr_hsh;
757 static struct hash_control * arm_reg_hsh;
758 static struct hash_control * arm_reloc_hsh;
759 static struct hash_control * arm_barrier_opt_hsh;
761 /* Stuff needed to resolve the label ambiguity
770 symbolS * last_label_seen;
771 static int label_is_thumb_function_name = FALSE;
773 /* Literal pool structure. Held on a per-section
774 and per-sub-section basis. */
776 #define MAX_LITERAL_POOL_SIZE 1024
777 typedef struct literal_pool
779 expressionS literals [MAX_LITERAL_POOL_SIZE];
780 unsigned int next_free_entry;
786 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
788 struct literal_pool * next;
791 /* Pointer to a linked list of literal pools. */
792 literal_pool * list_of_pools = NULL;
795 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
797 static struct current_it now_it;
801 now_it_compatible (int cond)
803 return (cond & ~1) == (now_it.cc & ~1);
807 conditional_insn (void)
809 return inst.cond != COND_ALWAYS;
812 static int in_it_block (void);
814 static int handle_it_state (void);
816 static void force_automatic_it_block_close (void);
818 static void it_fsm_post_encode (void);
820 #define set_it_insn_type(type) \
823 inst.it_insn_type = type; \
824 if (handle_it_state () == FAIL) \
829 #define set_it_insn_type_nonvoid(type, failret) \
832 inst.it_insn_type = type; \
833 if (handle_it_state () == FAIL) \
838 #define set_it_insn_type_last() \
841 if (inst.cond == COND_ALWAYS) \
842 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
844 set_it_insn_type (INSIDE_IT_LAST_INSN); \
850 /* This array holds the chars that always start a comment. If the
851 pre-processor is disabled, these aren't very useful. */
852 const char comment_chars[] = "@";
854 /* This array holds the chars that only start a comment at the beginning of
855 a line. If the line seems to have the form '# 123 filename'
856 .line and .file directives will appear in the pre-processed output. */
857 /* Note that input_file.c hand checks for '#' at the beginning of the
858 first line of the input file. This is because the compiler outputs
859 #NO_APP at the beginning of its output. */
860 /* Also note that comments like this one will always work. */
861 const char line_comment_chars[] = "#";
863 const char line_separator_chars[] = ";";
865 /* Chars that can be used to separate mant
866 from exp in floating point numbers. */
867 const char EXP_CHARS[] = "eE";
869 /* Chars that mean this number is a floating point constant. */
873 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
875 /* Prefix characters that indicate the start of an immediate
877 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
879 /* Separator character handling. */
881 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
884 skip_past_char (char ** str, char c)
886 /* PR gas/14987: Allow for whitespace before the expected character. */
887 skip_whitespace (*str);
898 #define skip_past_comma(str) skip_past_char (str, ',')
900 /* Arithmetic expressions (possibly involving symbols). */
902 /* Return TRUE if anything in the expression is a bignum. */
905 walk_no_bignums (symbolS * sp)
907 if (symbol_get_value_expression (sp)->X_op == O_big)
910 if (symbol_get_value_expression (sp)->X_add_symbol)
912 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
913 || (symbol_get_value_expression (sp)->X_op_symbol
914 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
920 static int in_my_get_expression = 0;
922 /* Third argument to my_get_expression. */
923 #define GE_NO_PREFIX 0
924 #define GE_IMM_PREFIX 1
925 #define GE_OPT_PREFIX 2
926 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
927 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
928 #define GE_OPT_PREFIX_BIG 3
931 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
936 /* In unified syntax, all prefixes are optional. */
938 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
943 case GE_NO_PREFIX: break;
945 if (!is_immediate_prefix (**str))
947 inst.error = _("immediate expression requires a # prefix");
953 case GE_OPT_PREFIX_BIG:
954 if (is_immediate_prefix (**str))
960 memset (ep, 0, sizeof (expressionS));
962 save_in = input_line_pointer;
963 input_line_pointer = *str;
964 in_my_get_expression = 1;
965 seg = expression (ep);
966 in_my_get_expression = 0;
968 if (ep->X_op == O_illegal || ep->X_op == O_absent)
970 /* We found a bad or missing expression in md_operand(). */
971 *str = input_line_pointer;
972 input_line_pointer = save_in;
973 if (inst.error == NULL)
974 inst.error = (ep->X_op == O_absent
975 ? _("missing expression") :_("bad expression"));
980 if (seg != absolute_section
981 && seg != text_section
982 && seg != data_section
983 && seg != bss_section
984 && seg != undefined_section)
986 inst.error = _("bad segment");
987 *str = input_line_pointer;
988 input_line_pointer = save_in;
995 /* Get rid of any bignums now, so that we don't generate an error for which
996 we can't establish a line number later on. Big numbers are never valid
997 in instructions, which is where this routine is always called. */
998 if (prefix_mode != GE_OPT_PREFIX_BIG
999 && (ep->X_op == O_big
1000 || (ep->X_add_symbol
1001 && (walk_no_bignums (ep->X_add_symbol)
1003 && walk_no_bignums (ep->X_op_symbol))))))
1005 inst.error = _("invalid constant");
1006 *str = input_line_pointer;
1007 input_line_pointer = save_in;
1011 *str = input_line_pointer;
1012 input_line_pointer = save_in;
1016 /* Turn a string in input_line_pointer into a floating point constant
1017 of type TYPE, and store the appropriate bytes in *LITP. The number
1018 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1019 returned, or NULL on OK.
1021 Note that fp constants aren't represent in the normal way on the ARM.
1022 In big endian mode, things are as expected. However, in little endian
1023 mode fp constants are big-endian word-wise, and little-endian byte-wise
1024 within the words. For example, (double) 1.1 in big endian mode is
1025 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1026 the byte sequence 99 99 f1 3f 9a 99 99 99.
1028 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1031 md_atof (int type, char * litP, int * sizeP)
1034 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1066 return _("Unrecognized or unsupported floating point constant");
1069 t = atof_ieee (input_line_pointer, type, words);
1071 input_line_pointer = t;
1072 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1074 if (target_big_endian)
1076 for (i = 0; i < prec; i++)
1078 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1079 litP += sizeof (LITTLENUM_TYPE);
1084 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1085 for (i = prec - 1; i >= 0; i--)
1087 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1088 litP += sizeof (LITTLENUM_TYPE);
1091 /* For a 4 byte float the order of elements in `words' is 1 0.
1092 For an 8 byte float the order is 1 0 3 2. */
1093 for (i = 0; i < prec; i += 2)
1095 md_number_to_chars (litP, (valueT) words[i + 1],
1096 sizeof (LITTLENUM_TYPE));
1097 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1098 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1099 litP += 2 * sizeof (LITTLENUM_TYPE);
1106 /* We handle all bad expressions here, so that we can report the faulty
1107 instruction in the error message. */
1109 md_operand (expressionS * exp)
1111 if (in_my_get_expression)
1112 exp->X_op = O_illegal;
1115 /* Immediate values. */
1117 /* Generic immediate-value read function for use in directives.
1118 Accepts anything that 'expression' can fold to a constant.
1119 *val receives the number. */
1122 immediate_for_directive (int *val)
1125 exp.X_op = O_illegal;
1127 if (is_immediate_prefix (*input_line_pointer))
1129 input_line_pointer++;
1133 if (exp.X_op != O_constant)
1135 as_bad (_("expected #constant"));
1136 ignore_rest_of_line ();
1139 *val = exp.X_add_number;
1144 /* Register parsing. */
1146 /* Generic register parser. CCP points to what should be the
1147 beginning of a register name. If it is indeed a valid register
1148 name, advance CCP over it and return the reg_entry structure;
1149 otherwise return NULL. Does not issue diagnostics. */
1151 static struct reg_entry *
1152 arm_reg_parse_multi (char **ccp)
1156 struct reg_entry *reg;
1158 #ifdef REGISTER_PREFIX
1159 if (*start != REGISTER_PREFIX)
1163 #ifdef OPTIONAL_REGISTER_PREFIX
1164 if (*start == OPTIONAL_REGISTER_PREFIX)
1169 if (!ISALPHA (*p) || !is_name_beginner (*p))
1174 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1176 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1186 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1187 enum arm_reg_type type)
1189 /* Alternative syntaxes are accepted for a few register classes. */
1196 /* Generic coprocessor register names are allowed for these. */
1197 if (reg && reg->type == REG_TYPE_CN)
1202 /* For backward compatibility, a bare number is valid here. */
1204 unsigned long processor = strtoul (start, ccp, 10);
1205 if (*ccp != start && processor <= 15)
1209 case REG_TYPE_MMXWC:
1210 /* WC includes WCG. ??? I'm not sure this is true for all
1211 instructions that take WC registers. */
1212 if (reg && reg->type == REG_TYPE_MMXWCG)
1223 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1224 return value is the register number or FAIL. */
1227 arm_reg_parse (char **ccp, enum arm_reg_type type)
1230 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1233 /* Do not allow a scalar (reg+index) to parse as a register. */
1234 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1237 if (reg && reg->type == type)
1240 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1247 /* Parse a Neon type specifier. *STR should point at the leading '.'
1248 character. Does no verification at this stage that the type fits the opcode
1255 Can all be legally parsed by this function.
1257 Fills in neon_type struct pointer with parsed information, and updates STR
1258 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1259 type, FAIL if not. */
1262 parse_neon_type (struct neon_type *type, char **str)
1269 while (type->elems < NEON_MAX_TYPE_ELS)
1271 enum neon_el_type thistype = NT_untyped;
1272 unsigned thissize = -1u;
1279 /* Just a size without an explicit type. */
1283 switch (TOLOWER (*ptr))
1285 case 'i': thistype = NT_integer; break;
1286 case 'f': thistype = NT_float; break;
1287 case 'p': thistype = NT_poly; break;
1288 case 's': thistype = NT_signed; break;
1289 case 'u': thistype = NT_unsigned; break;
1291 thistype = NT_float;
1296 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1302 /* .f is an abbreviation for .f32. */
1303 if (thistype == NT_float && !ISDIGIT (*ptr))
1308 thissize = strtoul (ptr, &ptr, 10);
1310 if (thissize != 8 && thissize != 16 && thissize != 32
1313 as_bad (_("bad size %d in type specifier"), thissize);
1321 type->el[type->elems].type = thistype;
1322 type->el[type->elems].size = thissize;
1327 /* Empty/missing type is not a successful parse. */
1328 if (type->elems == 0)
1336 /* Errors may be set multiple times during parsing or bit encoding
1337 (particularly in the Neon bits), but usually the earliest error which is set
1338 will be the most meaningful. Avoid overwriting it with later (cascading)
1339 errors by calling this function. */
1342 first_error (const char *err)
1348 /* Parse a single type, e.g. ".s32", leading period included. */
1350 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1353 struct neon_type optype;
1357 if (parse_neon_type (&optype, &str) == SUCCESS)
1359 if (optype.elems == 1)
1360 *vectype = optype.el[0];
1363 first_error (_("only one type should be specified for operand"));
1369 first_error (_("vector type expected"));
1381 /* Special meanings for indices (which have a range of 0-7), which will fit into
1384 #define NEON_ALL_LANES 15
1385 #define NEON_INTERLEAVE_LANES 14
1387 /* Parse either a register or a scalar, with an optional type. Return the
1388 register number, and optionally fill in the actual type of the register
1389 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1390 type/index information in *TYPEINFO. */
1393 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1394 enum arm_reg_type *rtype,
1395 struct neon_typed_alias *typeinfo)
1398 struct reg_entry *reg = arm_reg_parse_multi (&str);
1399 struct neon_typed_alias atype;
1400 struct neon_type_el parsetype;
1404 atype.eltype.type = NT_invtype;
1405 atype.eltype.size = -1;
1407 /* Try alternate syntax for some types of register. Note these are mutually
1408 exclusive with the Neon syntax extensions. */
1411 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1419 /* Undo polymorphism when a set of register types may be accepted. */
1420 if ((type == REG_TYPE_NDQ
1421 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1422 || (type == REG_TYPE_VFSD
1423 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1424 || (type == REG_TYPE_NSDQ
1425 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1426 || reg->type == REG_TYPE_NQ))
1427 || (type == REG_TYPE_MMXWC
1428 && (reg->type == REG_TYPE_MMXWCG)))
1429 type = (enum arm_reg_type) reg->type;
1431 if (type != reg->type)
1437 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1439 if ((atype.defined & NTA_HASTYPE) != 0)
1441 first_error (_("can't redefine type for operand"));
1444 atype.defined |= NTA_HASTYPE;
1445 atype.eltype = parsetype;
1448 if (skip_past_char (&str, '[') == SUCCESS)
1450 if (type != REG_TYPE_VFD)
1452 first_error (_("only D registers may be indexed"));
1456 if ((atype.defined & NTA_HASINDEX) != 0)
1458 first_error (_("can't change index for operand"));
1462 atype.defined |= NTA_HASINDEX;
1464 if (skip_past_char (&str, ']') == SUCCESS)
1465 atype.index = NEON_ALL_LANES;
1470 my_get_expression (&exp, &str, GE_NO_PREFIX);
1472 if (exp.X_op != O_constant)
1474 first_error (_("constant expression required"));
1478 if (skip_past_char (&str, ']') == FAIL)
1481 atype.index = exp.X_add_number;
1496 /* Like arm_reg_parse, but allow allow the following extra features:
1497 - If RTYPE is non-zero, return the (possibly restricted) type of the
1498 register (e.g. Neon double or quad reg when either has been requested).
1499 - If this is a Neon vector type with additional type information, fill
1500 in the struct pointed to by VECTYPE (if non-NULL).
1501 This function will fault on encountering a scalar. */
1504 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1505 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1507 struct neon_typed_alias atype;
1509 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1514 /* Do not allow regname(... to parse as a register. */
1518 /* Do not allow a scalar (reg+index) to parse as a register. */
1519 if ((atype.defined & NTA_HASINDEX) != 0)
1521 first_error (_("register operand expected, but got scalar"));
1526 *vectype = atype.eltype;
1533 #define NEON_SCALAR_REG(X) ((X) >> 4)
1534 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1536 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1537 have enough information to be able to do a good job bounds-checking. So, we
1538 just do easy checks here, and do further checks later. */
1541 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1545 struct neon_typed_alias atype;
1547 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1549 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1552 if (atype.index == NEON_ALL_LANES)
1554 first_error (_("scalar must have an index"));
1557 else if (atype.index >= 64 / elsize)
1559 first_error (_("scalar index out of range"));
1564 *type = atype.eltype;
1568 return reg * 16 + atype.index;
1571 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1574 parse_reg_list (char ** strp)
1576 char * str = * strp;
1580 /* We come back here if we get ranges concatenated by '+' or '|'. */
1595 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1597 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1607 first_error (_("bad range in register list"));
1611 for (i = cur_reg + 1; i < reg; i++)
1613 if (range & (1 << i))
1615 (_("Warning: duplicated register (r%d) in register list"),
1623 if (range & (1 << reg))
1624 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1626 else if (reg <= cur_reg)
1627 as_tsktsk (_("Warning: register range not in ascending order"));
1632 while (skip_past_comma (&str) != FAIL
1633 || (in_range = 1, *str++ == '-'));
1638 first_error (_("missing `}'"));
1646 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1649 if (exp.X_op == O_constant)
1651 if (exp.X_add_number
1652 != (exp.X_add_number & 0x0000ffff))
1654 inst.error = _("invalid register mask");
1658 if ((range & exp.X_add_number) != 0)
1660 int regno = range & exp.X_add_number;
1663 regno = (1 << regno) - 1;
1665 (_("Warning: duplicated register (r%d) in register list"),
1669 range |= exp.X_add_number;
1673 if (inst.reloc.type != 0)
1675 inst.error = _("expression too complex");
1679 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1680 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1681 inst.reloc.pc_rel = 0;
1685 if (*str == '|' || *str == '+')
1691 while (another_range);
1697 /* Types of registers in a list. */
1706 /* Parse a VFP register list. If the string is invalid return FAIL.
1707 Otherwise return the number of registers, and set PBASE to the first
1708 register. Parses registers of type ETYPE.
1709 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1710 - Q registers can be used to specify pairs of D registers
1711 - { } can be omitted from around a singleton register list
1712 FIXME: This is not implemented, as it would require backtracking in
1715 This could be done (the meaning isn't really ambiguous), but doesn't
1716 fit in well with the current parsing framework.
1717 - 32 D registers may be used (also true for VFPv3).
1718 FIXME: Types are ignored in these register lists, which is probably a
1722 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1727 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1731 unsigned long mask = 0;
1736 inst.error = _("expecting {");
1745 regtype = REG_TYPE_VFS;
1750 regtype = REG_TYPE_VFD;
1753 case REGLIST_NEON_D:
1754 regtype = REG_TYPE_NDQ;
1758 if (etype != REGLIST_VFP_S)
1760 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1761 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1765 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1768 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1775 base_reg = max_regs;
1779 int setmask = 1, addregs = 1;
1781 new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL);
1783 if (new_base == FAIL)
1785 first_error (_(reg_expected_msgs[regtype]));
1789 if (new_base >= max_regs)
1791 first_error (_("register out of range in list"));
1795 /* Note: a value of 2 * n is returned for the register Q<n>. */
1796 if (regtype == REG_TYPE_NQ)
1802 if (new_base < base_reg)
1803 base_reg = new_base;
1805 if (mask & (setmask << new_base))
1807 first_error (_("invalid register list"));
1811 if ((mask >> new_base) != 0 && ! warned)
1813 as_tsktsk (_("register list not in ascending order"));
1817 mask |= setmask << new_base;
1820 if (*str == '-') /* We have the start of a range expression */
1826 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1829 inst.error = gettext (reg_expected_msgs[regtype]);
1833 if (high_range >= max_regs)
1835 first_error (_("register out of range in list"));
1839 if (regtype == REG_TYPE_NQ)
1840 high_range = high_range + 1;
1842 if (high_range <= new_base)
1844 inst.error = _("register range not in ascending order");
1848 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1850 if (mask & (setmask << new_base))
1852 inst.error = _("invalid register list");
1856 mask |= setmask << new_base;
1861 while (skip_past_comma (&str) != FAIL);
1865 /* Sanity check -- should have raised a parse error above. */
1866 if (count == 0 || count > max_regs)
1871 /* Final test -- the registers must be consecutive. */
1873 for (i = 0; i < count; i++)
1875 if ((mask & (1u << i)) == 0)
1877 inst.error = _("non-contiguous register range");
1887 /* True if two alias types are the same. */
1890 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1898 if (a->defined != b->defined)
1901 if ((a->defined & NTA_HASTYPE) != 0
1902 && (a->eltype.type != b->eltype.type
1903 || a->eltype.size != b->eltype.size))
1906 if ((a->defined & NTA_HASINDEX) != 0
1907 && (a->index != b->index))
1913 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1914 The base register is put in *PBASE.
1915 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1917 The register stride (minus one) is put in bit 4 of the return value.
1918 Bits [6:5] encode the list length (minus one).
1919 The type of the list elements is put in *ELTYPE, if non-NULL. */
1921 #define NEON_LANE(X) ((X) & 0xf)
1922 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1923 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1926 parse_neon_el_struct_list (char **str, unsigned *pbase,
1927 struct neon_type_el *eltype)
1934 int leading_brace = 0;
1935 enum arm_reg_type rtype = REG_TYPE_NDQ;
1936 const char *const incr_error = _("register stride must be 1 or 2");
1937 const char *const type_error = _("mismatched element/structure types in list");
1938 struct neon_typed_alias firsttype;
1940 if (skip_past_char (&ptr, '{') == SUCCESS)
1945 struct neon_typed_alias atype;
1946 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1950 first_error (_(reg_expected_msgs[rtype]));
1957 if (rtype == REG_TYPE_NQ)
1963 else if (reg_incr == -1)
1965 reg_incr = getreg - base_reg;
1966 if (reg_incr < 1 || reg_incr > 2)
1968 first_error (_(incr_error));
1972 else if (getreg != base_reg + reg_incr * count)
1974 first_error (_(incr_error));
1978 if (! neon_alias_types_same (&atype, &firsttype))
1980 first_error (_(type_error));
1984 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1988 struct neon_typed_alias htype;
1989 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1991 lane = NEON_INTERLEAVE_LANES;
1992 else if (lane != NEON_INTERLEAVE_LANES)
1994 first_error (_(type_error));
1999 else if (reg_incr != 1)
2001 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2005 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2008 first_error (_(reg_expected_msgs[rtype]));
2011 if (! neon_alias_types_same (&htype, &firsttype))
2013 first_error (_(type_error));
2016 count += hireg + dregs - getreg;
2020 /* If we're using Q registers, we can't use [] or [n] syntax. */
2021 if (rtype == REG_TYPE_NQ)
2027 if ((atype.defined & NTA_HASINDEX) != 0)
2031 else if (lane != atype.index)
2033 first_error (_(type_error));
2037 else if (lane == -1)
2038 lane = NEON_INTERLEAVE_LANES;
2039 else if (lane != NEON_INTERLEAVE_LANES)
2041 first_error (_(type_error));
2046 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2048 /* No lane set by [x]. We must be interleaving structures. */
2050 lane = NEON_INTERLEAVE_LANES;
2053 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2054 || (count > 1 && reg_incr == -1))
2056 first_error (_("error parsing element/structure list"));
2060 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2062 first_error (_("expected }"));
2070 *eltype = firsttype.eltype;
2075 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2078 /* Parse an explicit relocation suffix on an expression. This is
2079 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2080 arm_reloc_hsh contains no entries, so this function can only
2081 succeed if there is no () after the word. Returns -1 on error,
2082 BFD_RELOC_UNUSED if there wasn't any suffix. */
2085 parse_reloc (char **str)
2087 struct reloc_entry *r;
2091 return BFD_RELOC_UNUSED;
2096 while (*q && *q != ')' && *q != ',')
2101 if ((r = (struct reloc_entry *)
2102 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2109 /* Directives: register aliases. */
2111 static struct reg_entry *
2112 insert_reg_alias (char *str, unsigned number, int type)
2114 struct reg_entry *new_reg;
2117 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2119 if (new_reg->builtin)
2120 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2122 /* Only warn about a redefinition if it's not defined as the
2124 else if (new_reg->number != number || new_reg->type != type)
2125 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2130 name = xstrdup (str);
2131 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2133 new_reg->name = name;
2134 new_reg->number = number;
2135 new_reg->type = type;
2136 new_reg->builtin = FALSE;
2137 new_reg->neon = NULL;
2139 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2146 insert_neon_reg_alias (char *str, int number, int type,
2147 struct neon_typed_alias *atype)
2149 struct reg_entry *reg = insert_reg_alias (str, number, type);
2153 first_error (_("attempt to redefine typed alias"));
2159 reg->neon = (struct neon_typed_alias *)
2160 xmalloc (sizeof (struct neon_typed_alias));
2161 *reg->neon = *atype;
2165 /* Look for the .req directive. This is of the form:
2167 new_register_name .req existing_register_name
2169 If we find one, or if it looks sufficiently like one that we want to
2170 handle any error here, return TRUE. Otherwise return FALSE. */
2173 create_register_alias (char * newname, char *p)
2175 struct reg_entry *old;
2176 char *oldname, *nbuf;
2179 /* The input scrubber ensures that whitespace after the mnemonic is
2180 collapsed to single spaces. */
2182 if (strncmp (oldname, " .req ", 6) != 0)
2186 if (*oldname == '\0')
2189 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2192 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2196 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2197 the desired alias name, and p points to its end. If not, then
2198 the desired alias name is in the global original_case_string. */
2199 #ifdef TC_CASE_SENSITIVE
2202 newname = original_case_string;
2203 nlen = strlen (newname);
2206 nbuf = (char *) alloca (nlen + 1);
2207 memcpy (nbuf, newname, nlen);
2210 /* Create aliases under the new name as stated; an all-lowercase
2211 version of the new name; and an all-uppercase version of the new
2213 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2215 for (p = nbuf; *p; p++)
2218 if (strncmp (nbuf, newname, nlen))
2220 /* If this attempt to create an additional alias fails, do not bother
2221 trying to create the all-lower case alias. We will fail and issue
2222 a second, duplicate error message. This situation arises when the
2223 programmer does something like:
2226 The second .req creates the "Foo" alias but then fails to create
2227 the artificial FOO alias because it has already been created by the
2229 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2233 for (p = nbuf; *p; p++)
2236 if (strncmp (nbuf, newname, nlen))
2237 insert_reg_alias (nbuf, old->number, old->type);
2243 /* Create a Neon typed/indexed register alias using directives, e.g.:
2248 These typed registers can be used instead of the types specified after the
2249 Neon mnemonic, so long as all operands given have types. Types can also be
2250 specified directly, e.g.:
2251 vadd d0.s32, d1.s32, d2.s32 */
2254 create_neon_reg_alias (char *newname, char *p)
2256 enum arm_reg_type basetype;
2257 struct reg_entry *basereg;
2258 struct reg_entry mybasereg;
2259 struct neon_type ntype;
2260 struct neon_typed_alias typeinfo;
2261 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2264 typeinfo.defined = 0;
2265 typeinfo.eltype.type = NT_invtype;
2266 typeinfo.eltype.size = -1;
2267 typeinfo.index = -1;
2271 if (strncmp (p, " .dn ", 5) == 0)
2272 basetype = REG_TYPE_VFD;
2273 else if (strncmp (p, " .qn ", 5) == 0)
2274 basetype = REG_TYPE_NQ;
2283 basereg = arm_reg_parse_multi (&p);
2285 if (basereg && basereg->type != basetype)
2287 as_bad (_("bad type for register"));
2291 if (basereg == NULL)
2294 /* Try parsing as an integer. */
2295 my_get_expression (&exp, &p, GE_NO_PREFIX);
2296 if (exp.X_op != O_constant)
2298 as_bad (_("expression must be constant"));
2301 basereg = &mybasereg;
2302 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2308 typeinfo = *basereg->neon;
2310 if (parse_neon_type (&ntype, &p) == SUCCESS)
2312 /* We got a type. */
2313 if (typeinfo.defined & NTA_HASTYPE)
2315 as_bad (_("can't redefine the type of a register alias"));
2319 typeinfo.defined |= NTA_HASTYPE;
2320 if (ntype.elems != 1)
2322 as_bad (_("you must specify a single type only"));
2325 typeinfo.eltype = ntype.el[0];
2328 if (skip_past_char (&p, '[') == SUCCESS)
2331 /* We got a scalar index. */
2333 if (typeinfo.defined & NTA_HASINDEX)
2335 as_bad (_("can't redefine the index of a scalar alias"));
2339 my_get_expression (&exp, &p, GE_NO_PREFIX);
2341 if (exp.X_op != O_constant)
2343 as_bad (_("scalar index must be constant"));
2347 typeinfo.defined |= NTA_HASINDEX;
2348 typeinfo.index = exp.X_add_number;
2350 if (skip_past_char (&p, ']') == FAIL)
2352 as_bad (_("expecting ]"));
2357 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2358 the desired alias name, and p points to its end. If not, then
2359 the desired alias name is in the global original_case_string. */
2360 #ifdef TC_CASE_SENSITIVE
2361 namelen = nameend - newname;
2363 newname = original_case_string;
2364 namelen = strlen (newname);
2367 namebuf = (char *) alloca (namelen + 1);
2368 strncpy (namebuf, newname, namelen);
2369 namebuf[namelen] = '\0';
2371 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2372 typeinfo.defined != 0 ? &typeinfo : NULL);
2374 /* Insert name in all uppercase. */
2375 for (p = namebuf; *p; p++)
2378 if (strncmp (namebuf, newname, namelen))
2379 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2380 typeinfo.defined != 0 ? &typeinfo : NULL);
2382 /* Insert name in all lowercase. */
2383 for (p = namebuf; *p; p++)
2386 if (strncmp (namebuf, newname, namelen))
2387 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2388 typeinfo.defined != 0 ? &typeinfo : NULL);
2393 /* Should never be called, as .req goes between the alias and the
2394 register name, not at the beginning of the line. */
2397 s_req (int a ATTRIBUTE_UNUSED)
2399 as_bad (_("invalid syntax for .req directive"));
2403 s_dn (int a ATTRIBUTE_UNUSED)
2405 as_bad (_("invalid syntax for .dn directive"));
2409 s_qn (int a ATTRIBUTE_UNUSED)
2411 as_bad (_("invalid syntax for .qn directive"));
2414 /* The .unreq directive deletes an alias which was previously defined
2415 by .req. For example:
2421 s_unreq (int a ATTRIBUTE_UNUSED)
2426 name = input_line_pointer;
2428 while (*input_line_pointer != 0
2429 && *input_line_pointer != ' '
2430 && *input_line_pointer != '\n')
2431 ++input_line_pointer;
2433 saved_char = *input_line_pointer;
2434 *input_line_pointer = 0;
2437 as_bad (_("invalid syntax for .unreq directive"));
2440 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2444 as_bad (_("unknown register alias '%s'"), name);
2445 else if (reg->builtin)
2446 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2453 hash_delete (arm_reg_hsh, name, FALSE);
2454 free ((char *) reg->name);
2459 /* Also locate the all upper case and all lower case versions.
2460 Do not complain if we cannot find one or the other as it
2461 was probably deleted above. */
2463 nbuf = strdup (name);
2464 for (p = nbuf; *p; p++)
2466 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2469 hash_delete (arm_reg_hsh, nbuf, FALSE);
2470 free ((char *) reg->name);
2476 for (p = nbuf; *p; p++)
2478 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2481 hash_delete (arm_reg_hsh, nbuf, FALSE);
2482 free ((char *) reg->name);
2492 *input_line_pointer = saved_char;
2493 demand_empty_rest_of_line ();
2496 /* Directives: Instruction set selection. */
2499 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2500 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2501 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2502 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2504 /* Create a new mapping symbol for the transition to STATE. */
2507 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2510 const char * symname;
2517 type = BSF_NO_FLAGS;
2521 type = BSF_NO_FLAGS;
2525 type = BSF_NO_FLAGS;
2531 symbolP = symbol_new (symname, now_seg, value, frag);
2532 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2537 THUMB_SET_FUNC (symbolP, 0);
2538 ARM_SET_THUMB (symbolP, 0);
2539 ARM_SET_INTERWORK (symbolP, support_interwork);
2543 THUMB_SET_FUNC (symbolP, 1);
2544 ARM_SET_THUMB (symbolP, 1);
2545 ARM_SET_INTERWORK (symbolP, support_interwork);
2553 /* Save the mapping symbols for future reference. Also check that
2554 we do not place two mapping symbols at the same offset within a
2555 frag. We'll handle overlap between frags in
2556 check_mapping_symbols.
2558 If .fill or other data filling directive generates zero sized data,
2559 the mapping symbol for the following code will have the same value
2560 as the one generated for the data filling directive. In this case,
2561 we replace the old symbol with the new one at the same address. */
2564 if (frag->tc_frag_data.first_map != NULL)
2566 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2567 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2569 frag->tc_frag_data.first_map = symbolP;
2571 if (frag->tc_frag_data.last_map != NULL)
2573 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2574 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2575 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2577 frag->tc_frag_data.last_map = symbolP;
2580 /* We must sometimes convert a region marked as code to data during
2581 code alignment, if an odd number of bytes have to be padded. The
2582 code mapping symbol is pushed to an aligned address. */
2585 insert_data_mapping_symbol (enum mstate state,
2586 valueT value, fragS *frag, offsetT bytes)
2588 /* If there was already a mapping symbol, remove it. */
2589 if (frag->tc_frag_data.last_map != NULL
2590 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2592 symbolS *symp = frag->tc_frag_data.last_map;
2596 know (frag->tc_frag_data.first_map == symp);
2597 frag->tc_frag_data.first_map = NULL;
2599 frag->tc_frag_data.last_map = NULL;
2600 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2603 make_mapping_symbol (MAP_DATA, value, frag);
2604 make_mapping_symbol (state, value + bytes, frag);
2607 static void mapping_state_2 (enum mstate state, int max_chars);
2609 /* Set the mapping state to STATE. Only call this when about to
2610 emit some STATE bytes to the file. */
2613 mapping_state (enum mstate state)
2615 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2617 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2619 if (mapstate == state)
2620 /* The mapping symbol has already been emitted.
2621 There is nothing else to do. */
2624 if (state == MAP_ARM || state == MAP_THUMB)
2626 All ARM instructions require 4-byte alignment.
2627 (Almost) all Thumb instructions require 2-byte alignment.
2629 When emitting instructions into any section, mark the section
2632 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2633 but themselves require 2-byte alignment; this applies to some
2634 PC- relative forms. However, these cases will invovle implicit
2635 literal pool generation or an explicit .align >=2, both of
2636 which will cause the section to me marked with sufficient
2637 alignment. Thus, we don't handle those cases here. */
2638 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2640 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2641 /* This case will be evaluated later in the next else. */
2643 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2644 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2646 /* Only add the symbol if the offset is > 0:
2647 if we're at the first frag, check it's size > 0;
2648 if we're not at the first frag, then for sure
2649 the offset is > 0. */
2650 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2651 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2654 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2657 mapping_state_2 (state, 0);
2661 /* Same as mapping_state, but MAX_CHARS bytes have already been
2662 allocated. Put the mapping symbol that far back. */
2665 mapping_state_2 (enum mstate state, int max_chars)
2667 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2669 if (!SEG_NORMAL (now_seg))
2672 if (mapstate == state)
2673 /* The mapping symbol has already been emitted.
2674 There is nothing else to do. */
2677 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2678 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2681 #define mapping_state(x) ((void)0)
2682 #define mapping_state_2(x, y) ((void)0)
2685 /* Find the real, Thumb encoded start of a Thumb function. */
2689 find_real_start (symbolS * symbolP)
2692 const char * name = S_GET_NAME (symbolP);
2693 symbolS * new_target;
2695 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2696 #define STUB_NAME ".real_start_of"
2701 /* The compiler may generate BL instructions to local labels because
2702 it needs to perform a branch to a far away location. These labels
2703 do not have a corresponding ".real_start_of" label. We check
2704 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2705 the ".real_start_of" convention for nonlocal branches. */
2706 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2709 real_start = ACONCAT ((STUB_NAME, name, NULL));
2710 new_target = symbol_find (real_start);
2712 if (new_target == NULL)
2714 as_warn (_("Failed to find real start of function: %s\n"), name);
2715 new_target = symbolP;
2723 opcode_select (int width)
2730 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2731 as_bad (_("selected processor does not support THUMB opcodes"));
2734 /* No need to force the alignment, since we will have been
2735 coming from ARM mode, which is word-aligned. */
2736 record_alignment (now_seg, 1);
2743 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2744 as_bad (_("selected processor does not support ARM opcodes"));
2749 frag_align (2, 0, 0);
2751 record_alignment (now_seg, 1);
2756 as_bad (_("invalid instruction size selected (%d)"), width);
2761 s_arm (int ignore ATTRIBUTE_UNUSED)
2764 demand_empty_rest_of_line ();
2768 s_thumb (int ignore ATTRIBUTE_UNUSED)
2771 demand_empty_rest_of_line ();
2775 s_code (int unused ATTRIBUTE_UNUSED)
2779 temp = get_absolute_expression ();
2784 opcode_select (temp);
2788 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2793 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2795 /* If we are not already in thumb mode go into it, EVEN if
2796 the target processor does not support thumb instructions.
2797 This is used by gcc/config/arm/lib1funcs.asm for example
2798 to compile interworking support functions even if the
2799 target processor should not support interworking. */
2803 record_alignment (now_seg, 1);
2806 demand_empty_rest_of_line ();
2810 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2814 /* The following label is the name/address of the start of a Thumb function.
2815 We need to know this for the interworking support. */
2816 label_is_thumb_function_name = TRUE;
2819 /* Perform a .set directive, but also mark the alias as
2820 being a thumb function. */
2823 s_thumb_set (int equiv)
2825 /* XXX the following is a duplicate of the code for s_set() in read.c
2826 We cannot just call that code as we need to get at the symbol that
2833 /* Especial apologies for the random logic:
2834 This just grew, and could be parsed much more simply!
2836 name = input_line_pointer;
2837 delim = get_symbol_end ();
2838 end_name = input_line_pointer;
2841 if (*input_line_pointer != ',')
2844 as_bad (_("expected comma after name \"%s\""), name);
2846 ignore_rest_of_line ();
2850 input_line_pointer++;
2853 if (name[0] == '.' && name[1] == '\0')
2855 /* XXX - this should not happen to .thumb_set. */
2859 if ((symbolP = symbol_find (name)) == NULL
2860 && (symbolP = md_undefined_symbol (name)) == NULL)
2863 /* When doing symbol listings, play games with dummy fragments living
2864 outside the normal fragment chain to record the file and line info
2866 if (listing & LISTING_SYMBOLS)
2868 extern struct list_info_struct * listing_tail;
2869 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2871 memset (dummy_frag, 0, sizeof (fragS));
2872 dummy_frag->fr_type = rs_fill;
2873 dummy_frag->line = listing_tail;
2874 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2875 dummy_frag->fr_symbol = symbolP;
2879 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2882 /* "set" symbols are local unless otherwise specified. */
2883 SF_SET_LOCAL (symbolP);
2884 #endif /* OBJ_COFF */
2885 } /* Make a new symbol. */
2887 symbol_table_insert (symbolP);
2892 && S_IS_DEFINED (symbolP)
2893 && S_GET_SEGMENT (symbolP) != reg_section)
2894 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2896 pseudo_set (symbolP);
2898 demand_empty_rest_of_line ();
2900 /* XXX Now we come to the Thumb specific bit of code. */
2902 THUMB_SET_FUNC (symbolP, 1);
2903 ARM_SET_THUMB (symbolP, 1);
2904 #if defined OBJ_ELF || defined OBJ_COFF
2905 ARM_SET_INTERWORK (symbolP, support_interwork);
2909 /* Directives: Mode selection. */
2911 /* .syntax [unified|divided] - choose the new unified syntax
2912 (same for Arm and Thumb encoding, modulo slight differences in what
2913 can be represented) or the old divergent syntax for each mode. */
2915 s_syntax (int unused ATTRIBUTE_UNUSED)
2919 name = input_line_pointer;
2920 delim = get_symbol_end ();
2922 if (!strcasecmp (name, "unified"))
2923 unified_syntax = TRUE;
2924 else if (!strcasecmp (name, "divided"))
2925 unified_syntax = FALSE;
2928 as_bad (_("unrecognized syntax mode \"%s\""), name);
2931 *input_line_pointer = delim;
2932 demand_empty_rest_of_line ();
2935 /* Directives: sectioning and alignment. */
2937 /* Same as s_align_ptwo but align 0 => align 2. */
2940 s_align (int unused ATTRIBUTE_UNUSED)
2945 long max_alignment = 15;
2947 temp = get_absolute_expression ();
2948 if (temp > max_alignment)
2949 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2952 as_bad (_("alignment negative. 0 assumed."));
2956 if (*input_line_pointer == ',')
2958 input_line_pointer++;
2959 temp_fill = get_absolute_expression ();
2971 /* Only make a frag if we HAVE to. */
2972 if (temp && !need_pass_2)
2974 if (!fill_p && subseg_text_p (now_seg))
2975 frag_align_code (temp, 0);
2977 frag_align (temp, (int) temp_fill, 0);
2979 demand_empty_rest_of_line ();
2981 record_alignment (now_seg, temp);
2985 s_bss (int ignore ATTRIBUTE_UNUSED)
2987 /* We don't support putting frags in the BSS segment, we fake it by
2988 marking in_bss, then looking at s_skip for clues. */
2989 subseg_set (bss_section, 0);
2990 demand_empty_rest_of_line ();
2992 #ifdef md_elf_section_change_hook
2993 md_elf_section_change_hook ();
2998 s_even (int ignore ATTRIBUTE_UNUSED)
3000 /* Never make frag if expect extra pass. */
3002 frag_align (1, 0, 0);
3004 record_alignment (now_seg, 1);
3006 demand_empty_rest_of_line ();
3009 /* Directives: Literal pools. */
3011 static literal_pool *
3012 find_literal_pool (void)
3014 literal_pool * pool;
3016 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3018 if (pool->section == now_seg
3019 && pool->sub_section == now_subseg)
3026 static literal_pool *
3027 find_or_make_literal_pool (void)
3029 /* Next literal pool ID number. */
3030 static unsigned int latest_pool_num = 1;
3031 literal_pool * pool;
3033 pool = find_literal_pool ();
3037 /* Create a new pool. */
3038 pool = (literal_pool *) xmalloc (sizeof (* pool));
3042 pool->next_free_entry = 0;
3043 pool->section = now_seg;
3044 pool->sub_section = now_subseg;
3045 pool->next = list_of_pools;
3046 pool->symbol = NULL;
3048 /* Add it to the list. */
3049 list_of_pools = pool;
3052 /* New pools, and emptied pools, will have a NULL symbol. */
3053 if (pool->symbol == NULL)
3055 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3056 (valueT) 0, &zero_address_frag);
3057 pool->id = latest_pool_num ++;
3064 /* Add the literal in the global 'inst'
3065 structure to the relevant literal pool. */
3068 add_to_lit_pool (void)
3070 literal_pool * pool;
3073 pool = find_or_make_literal_pool ();
3075 /* Check if this literal value is already in the pool. */
3076 for (entry = 0; entry < pool->next_free_entry; entry ++)
3078 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3079 && (inst.reloc.exp.X_op == O_constant)
3080 && (pool->literals[entry].X_add_number
3081 == inst.reloc.exp.X_add_number)
3082 && (pool->literals[entry].X_unsigned
3083 == inst.reloc.exp.X_unsigned))
3086 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3087 && (inst.reloc.exp.X_op == O_symbol)
3088 && (pool->literals[entry].X_add_number
3089 == inst.reloc.exp.X_add_number)
3090 && (pool->literals[entry].X_add_symbol
3091 == inst.reloc.exp.X_add_symbol)
3092 && (pool->literals[entry].X_op_symbol
3093 == inst.reloc.exp.X_op_symbol))
3097 /* Do we need to create a new entry? */
3098 if (entry == pool->next_free_entry)
3100 if (entry >= MAX_LITERAL_POOL_SIZE)
3102 inst.error = _("literal pool overflow");
3106 pool->literals[entry] = inst.reloc.exp;
3108 /* PR ld/12974: Record the location of the first source line to reference
3109 this entry in the literal pool. If it turns out during linking that the
3110 symbol does not exist we will be able to give an accurate line number for
3111 the (first use of the) missing reference. */
3112 if (debug_type == DEBUG_DWARF2)
3113 dwarf2_where (pool->locs + entry);
3115 pool->next_free_entry += 1;
3118 inst.reloc.exp.X_op = O_symbol;
3119 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3120 inst.reloc.exp.X_add_symbol = pool->symbol;
3125 /* Can't use symbol_new here, so have to create a symbol and then at
3126 a later date assign it a value. Thats what these functions do. */
3129 symbol_locate (symbolS * symbolP,
3130 const char * name, /* It is copied, the caller can modify. */
3131 segT segment, /* Segment identifier (SEG_<something>). */
3132 valueT valu, /* Symbol value. */
3133 fragS * frag) /* Associated fragment. */
3135 unsigned int name_length;
3136 char * preserved_copy_of_name;
3138 name_length = strlen (name) + 1; /* +1 for \0. */
3139 obstack_grow (¬es, name, name_length);
3140 preserved_copy_of_name = (char *) obstack_finish (¬es);
3142 #ifdef tc_canonicalize_symbol_name
3143 preserved_copy_of_name =
3144 tc_canonicalize_symbol_name (preserved_copy_of_name);
3147 S_SET_NAME (symbolP, preserved_copy_of_name);
3149 S_SET_SEGMENT (symbolP, segment);
3150 S_SET_VALUE (symbolP, valu);
3151 symbol_clear_list_pointers (symbolP);
3153 symbol_set_frag (symbolP, frag);
3155 /* Link to end of symbol chain. */
3157 extern int symbol_table_frozen;
3159 if (symbol_table_frozen)
3163 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3165 obj_symbol_new_hook (symbolP);
3167 #ifdef tc_symbol_new_hook
3168 tc_symbol_new_hook (symbolP);
3172 verify_symbol_chain (symbol_rootP, symbol_lastP);
3173 #endif /* DEBUG_SYMS */
3178 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3181 literal_pool * pool;
3184 pool = find_literal_pool ();
3186 || pool->symbol == NULL
3187 || pool->next_free_entry == 0)
3190 mapping_state (MAP_DATA);
3192 /* Align pool as you have word accesses.
3193 Only make a frag if we have to. */
3195 frag_align (2, 0, 0);
3197 record_alignment (now_seg, 2);
3199 sprintf (sym_name, "$$lit_\002%x", pool->id);
3201 symbol_locate (pool->symbol, sym_name, now_seg,
3202 (valueT) frag_now_fix (), frag_now);
3203 symbol_table_insert (pool->symbol);
3205 ARM_SET_THUMB (pool->symbol, thumb_mode);
3207 #if defined OBJ_COFF || defined OBJ_ELF
3208 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3211 for (entry = 0; entry < pool->next_free_entry; entry ++)
3214 if (debug_type == DEBUG_DWARF2)
3215 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3217 /* First output the expression in the instruction to the pool. */
3218 emit_expr (&(pool->literals[entry]), 4); /* .word */
3221 /* Mark the pool as empty. */
3222 pool->next_free_entry = 0;
3223 pool->symbol = NULL;
3227 /* Forward declarations for functions below, in the MD interface
3229 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3230 static valueT create_unwind_entry (int);
3231 static void start_unwind_section (const segT, int);
3232 static void add_unwind_opcode (valueT, int);
3233 static void flush_pending_unwind (void);
3235 /* Directives: Data. */
3238 s_arm_elf_cons (int nbytes)
3242 #ifdef md_flush_pending_output
3243 md_flush_pending_output ();
3246 if (is_it_end_of_statement ())
3248 demand_empty_rest_of_line ();
3252 #ifdef md_cons_align
3253 md_cons_align (nbytes);
3256 mapping_state (MAP_DATA);
3260 char *base = input_line_pointer;
3264 if (exp.X_op != O_symbol)
3265 emit_expr (&exp, (unsigned int) nbytes);
3268 char *before_reloc = input_line_pointer;
3269 reloc = parse_reloc (&input_line_pointer);
3272 as_bad (_("unrecognized relocation suffix"));
3273 ignore_rest_of_line ();
3276 else if (reloc == BFD_RELOC_UNUSED)
3277 emit_expr (&exp, (unsigned int) nbytes);
3280 reloc_howto_type *howto = (reloc_howto_type *)
3281 bfd_reloc_type_lookup (stdoutput,
3282 (bfd_reloc_code_real_type) reloc);
3283 int size = bfd_get_reloc_size (howto);
3285 if (reloc == BFD_RELOC_ARM_PLT32)
3287 as_bad (_("(plt) is only valid on branch targets"));
3288 reloc = BFD_RELOC_UNUSED;
3293 as_bad (_("%s relocations do not fit in %d bytes"),
3294 howto->name, nbytes);
3297 /* We've parsed an expression stopping at O_symbol.
3298 But there may be more expression left now that we
3299 have parsed the relocation marker. Parse it again.
3300 XXX Surely there is a cleaner way to do this. */
3301 char *p = input_line_pointer;
3303 char *save_buf = (char *) alloca (input_line_pointer - base);
3304 memcpy (save_buf, base, input_line_pointer - base);
3305 memmove (base + (input_line_pointer - before_reloc),
3306 base, before_reloc - base);
3308 input_line_pointer = base + (input_line_pointer-before_reloc);
3310 memcpy (base, save_buf, p - base);
3312 offset = nbytes - size;
3313 p = frag_more ((int) nbytes);
3314 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3315 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3320 while (*input_line_pointer++ == ',');
3322 /* Put terminator back into stream. */
3323 input_line_pointer --;
3324 demand_empty_rest_of_line ();
3327 /* Emit an expression containing a 32-bit thumb instruction.
3328 Implementation based on put_thumb32_insn. */
3331 emit_thumb32_expr (expressionS * exp)
3333 expressionS exp_high = *exp;
3335 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3336 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3337 exp->X_add_number &= 0xffff;
3338 emit_expr (exp, (unsigned int) THUMB_SIZE);
3341 /* Guess the instruction size based on the opcode. */
3344 thumb_insn_size (int opcode)
3346 if ((unsigned int) opcode < 0xe800u)
3348 else if ((unsigned int) opcode >= 0xe8000000u)
3355 emit_insn (expressionS *exp, int nbytes)
3359 if (exp->X_op == O_constant)
3364 size = thumb_insn_size (exp->X_add_number);
3368 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3370 as_bad (_(".inst.n operand too big. "\
3371 "Use .inst.w instead"));
3376 if (now_it.state == AUTOMATIC_IT_BLOCK)
3377 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3379 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3381 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3382 emit_thumb32_expr (exp);
3384 emit_expr (exp, (unsigned int) size);
3386 it_fsm_post_encode ();
3390 as_bad (_("cannot determine Thumb instruction size. " \
3391 "Use .inst.n/.inst.w instead"));
3394 as_bad (_("constant expression required"));
3399 /* Like s_arm_elf_cons but do not use md_cons_align and
3400 set the mapping state to MAP_ARM/MAP_THUMB. */
3403 s_arm_elf_inst (int nbytes)
3405 if (is_it_end_of_statement ())
3407 demand_empty_rest_of_line ();
3411 /* Calling mapping_state () here will not change ARM/THUMB,
3412 but will ensure not to be in DATA state. */
3415 mapping_state (MAP_THUMB);
3420 as_bad (_("width suffixes are invalid in ARM mode"));
3421 ignore_rest_of_line ();
3427 mapping_state (MAP_ARM);
3436 if (! emit_insn (& exp, nbytes))
3438 ignore_rest_of_line ();
3442 while (*input_line_pointer++ == ',');
3444 /* Put terminator back into stream. */
3445 input_line_pointer --;
3446 demand_empty_rest_of_line ();
3449 /* Parse a .rel31 directive. */
3452 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3459 if (*input_line_pointer == '1')
3460 highbit = 0x80000000;
3461 else if (*input_line_pointer != '0')
3462 as_bad (_("expected 0 or 1"));
3464 input_line_pointer++;
3465 if (*input_line_pointer != ',')
3466 as_bad (_("missing comma"));
3467 input_line_pointer++;
3469 #ifdef md_flush_pending_output
3470 md_flush_pending_output ();
3473 #ifdef md_cons_align
3477 mapping_state (MAP_DATA);
3482 md_number_to_chars (p, highbit, 4);
3483 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3484 BFD_RELOC_ARM_PREL31);
3486 demand_empty_rest_of_line ();
3489 /* Directives: AEABI stack-unwind tables. */
3491 /* Parse an unwind_fnstart directive. Simply records the current location. */
3494 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3496 demand_empty_rest_of_line ();
3497 if (unwind.proc_start)
3499 as_bad (_("duplicate .fnstart directive"));
3503 /* Mark the start of the function. */
3504 unwind.proc_start = expr_build_dot ();
3506 /* Reset the rest of the unwind info. */
3507 unwind.opcode_count = 0;
3508 unwind.table_entry = NULL;
3509 unwind.personality_routine = NULL;
3510 unwind.personality_index = -1;
3511 unwind.frame_size = 0;
3512 unwind.fp_offset = 0;
3513 unwind.fp_reg = REG_SP;
3515 unwind.sp_restored = 0;
3519 /* Parse a handlerdata directive. Creates the exception handling table entry
3520 for the function. */
3523 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3525 demand_empty_rest_of_line ();
3526 if (!unwind.proc_start)
3527 as_bad (MISSING_FNSTART);
3529 if (unwind.table_entry)
3530 as_bad (_("duplicate .handlerdata directive"));
3532 create_unwind_entry (1);
3535 /* Parse an unwind_fnend directive. Generates the index table entry. */
3538 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3543 unsigned int marked_pr_dependency;
3545 demand_empty_rest_of_line ();
3547 if (!unwind.proc_start)
3549 as_bad (_(".fnend directive without .fnstart"));
3553 /* Add eh table entry. */
3554 if (unwind.table_entry == NULL)
3555 val = create_unwind_entry (0);
3559 /* Add index table entry. This is two words. */
3560 start_unwind_section (unwind.saved_seg, 1);
3561 frag_align (2, 0, 0);
3562 record_alignment (now_seg, 2);
3564 ptr = frag_more (8);
3566 where = frag_now_fix () - 8;
3568 /* Self relative offset of the function start. */
3569 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3570 BFD_RELOC_ARM_PREL31);
3572 /* Indicate dependency on EHABI-defined personality routines to the
3573 linker, if it hasn't been done already. */
3574 marked_pr_dependency
3575 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3576 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3577 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3579 static const char *const name[] =
3581 "__aeabi_unwind_cpp_pr0",
3582 "__aeabi_unwind_cpp_pr1",
3583 "__aeabi_unwind_cpp_pr2"
3585 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3586 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3587 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3588 |= 1 << unwind.personality_index;
3592 /* Inline exception table entry. */
3593 md_number_to_chars (ptr + 4, val, 4);
3595 /* Self relative offset of the table entry. */
3596 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3597 BFD_RELOC_ARM_PREL31);
3599 /* Restore the original section. */
3600 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3602 unwind.proc_start = NULL;
3606 /* Parse an unwind_cantunwind directive. */
3609 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3611 demand_empty_rest_of_line ();
3612 if (!unwind.proc_start)
3613 as_bad (MISSING_FNSTART);
3615 if (unwind.personality_routine || unwind.personality_index != -1)
3616 as_bad (_("personality routine specified for cantunwind frame"));
3618 unwind.personality_index = -2;
3622 /* Parse a personalityindex directive. */
3625 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3629 if (!unwind.proc_start)
3630 as_bad (MISSING_FNSTART);
3632 if (unwind.personality_routine || unwind.personality_index != -1)
3633 as_bad (_("duplicate .personalityindex directive"));
3637 if (exp.X_op != O_constant
3638 || exp.X_add_number < 0 || exp.X_add_number > 15)
3640 as_bad (_("bad personality routine number"));
3641 ignore_rest_of_line ();
3645 unwind.personality_index = exp.X_add_number;
3647 demand_empty_rest_of_line ();
3651 /* Parse a personality directive. */
3654 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3658 if (!unwind.proc_start)
3659 as_bad (MISSING_FNSTART);
3661 if (unwind.personality_routine || unwind.personality_index != -1)
3662 as_bad (_("duplicate .personality directive"));
3664 name = input_line_pointer;
3665 c = get_symbol_end ();
3666 p = input_line_pointer;
3667 unwind.personality_routine = symbol_find_or_make (name);
3669 demand_empty_rest_of_line ();
3673 /* Parse a directive saving core registers. */
3676 s_arm_unwind_save_core (void)
3682 range = parse_reg_list (&input_line_pointer);
3685 as_bad (_("expected register list"));
3686 ignore_rest_of_line ();
3690 demand_empty_rest_of_line ();
3692 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3693 into .unwind_save {..., sp...}. We aren't bothered about the value of
3694 ip because it is clobbered by calls. */
3695 if (unwind.sp_restored && unwind.fp_reg == 12
3696 && (range & 0x3000) == 0x1000)
3698 unwind.opcode_count--;
3699 unwind.sp_restored = 0;
3700 range = (range | 0x2000) & ~0x1000;
3701 unwind.pending_offset = 0;
3707 /* See if we can use the short opcodes. These pop a block of up to 8
3708 registers starting with r4, plus maybe r14. */
3709 for (n = 0; n < 8; n++)
3711 /* Break at the first non-saved register. */
3712 if ((range & (1 << (n + 4))) == 0)
3715 /* See if there are any other bits set. */
3716 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3718 /* Use the long form. */
3719 op = 0x8000 | ((range >> 4) & 0xfff);
3720 add_unwind_opcode (op, 2);
3724 /* Use the short form. */
3726 op = 0xa8; /* Pop r14. */
3728 op = 0xa0; /* Do not pop r14. */
3730 add_unwind_opcode (op, 1);
3737 op = 0xb100 | (range & 0xf);
3738 add_unwind_opcode (op, 2);
3741 /* Record the number of bytes pushed. */
3742 for (n = 0; n < 16; n++)
3744 if (range & (1 << n))
3745 unwind.frame_size += 4;
3750 /* Parse a directive saving FPA registers. */
3753 s_arm_unwind_save_fpa (int reg)
3759 /* Get Number of registers to transfer. */
3760 if (skip_past_comma (&input_line_pointer) != FAIL)
3763 exp.X_op = O_illegal;
3765 if (exp.X_op != O_constant)
3767 as_bad (_("expected , <constant>"));
3768 ignore_rest_of_line ();
3772 num_regs = exp.X_add_number;
3774 if (num_regs < 1 || num_regs > 4)
3776 as_bad (_("number of registers must be in the range [1:4]"));
3777 ignore_rest_of_line ();
3781 demand_empty_rest_of_line ();
3786 op = 0xb4 | (num_regs - 1);
3787 add_unwind_opcode (op, 1);
3792 op = 0xc800 | (reg << 4) | (num_regs - 1);
3793 add_unwind_opcode (op, 2);
3795 unwind.frame_size += num_regs * 12;
3799 /* Parse a directive saving VFP registers for ARMv6 and above. */
3802 s_arm_unwind_save_vfp_armv6 (void)
3807 int num_vfpv3_regs = 0;
3808 int num_regs_below_16;
3810 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3813 as_bad (_("expected register list"));
3814 ignore_rest_of_line ();
3818 demand_empty_rest_of_line ();
3820 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3821 than FSTMX/FLDMX-style ones). */
3823 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3825 num_vfpv3_regs = count;
3826 else if (start + count > 16)
3827 num_vfpv3_regs = start + count - 16;
3829 if (num_vfpv3_regs > 0)
3831 int start_offset = start > 16 ? start - 16 : 0;
3832 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3833 add_unwind_opcode (op, 2);
3836 /* Generate opcode for registers numbered in the range 0 .. 15. */
3837 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3838 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3839 if (num_regs_below_16 > 0)
3841 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3842 add_unwind_opcode (op, 2);
3845 unwind.frame_size += count * 8;
3849 /* Parse a directive saving VFP registers for pre-ARMv6. */
3852 s_arm_unwind_save_vfp (void)
3858 count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D);
3861 as_bad (_("expected register list"));
3862 ignore_rest_of_line ();
3866 demand_empty_rest_of_line ();
3871 op = 0xb8 | (count - 1);
3872 add_unwind_opcode (op, 1);
3877 op = 0xb300 | (reg << 4) | (count - 1);
3878 add_unwind_opcode (op, 2);
3880 unwind.frame_size += count * 8 + 4;
3884 /* Parse a directive saving iWMMXt data registers. */
3887 s_arm_unwind_save_mmxwr (void)
3895 if (*input_line_pointer == '{')
3896 input_line_pointer++;
3900 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3904 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3909 as_tsktsk (_("register list not in ascending order"));
3912 if (*input_line_pointer == '-')
3914 input_line_pointer++;
3915 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3918 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3921 else if (reg >= hi_reg)
3923 as_bad (_("bad register range"));
3926 for (; reg < hi_reg; reg++)
3930 while (skip_past_comma (&input_line_pointer) != FAIL);
3932 if (*input_line_pointer == '}')
3933 input_line_pointer++;
3935 demand_empty_rest_of_line ();
3937 /* Generate any deferred opcodes because we're going to be looking at
3939 flush_pending_unwind ();
3941 for (i = 0; i < 16; i++)
3943 if (mask & (1 << i))
3944 unwind.frame_size += 8;
3947 /* Attempt to combine with a previous opcode. We do this because gcc
3948 likes to output separate unwind directives for a single block of
3950 if (unwind.opcode_count > 0)
3952 i = unwind.opcodes[unwind.opcode_count - 1];
3953 if ((i & 0xf8) == 0xc0)
3956 /* Only merge if the blocks are contiguous. */
3959 if ((mask & 0xfe00) == (1 << 9))
3961 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3962 unwind.opcode_count--;
3965 else if (i == 6 && unwind.opcode_count >= 2)
3967 i = unwind.opcodes[unwind.opcode_count - 2];
3971 op = 0xffff << (reg - 1);
3973 && ((mask & op) == (1u << (reg - 1))))
3975 op = (1 << (reg + i + 1)) - 1;
3976 op &= ~((1 << reg) - 1);
3978 unwind.opcode_count -= 2;
3985 /* We want to generate opcodes in the order the registers have been
3986 saved, ie. descending order. */
3987 for (reg = 15; reg >= -1; reg--)
3989 /* Save registers in blocks. */
3991 || !(mask & (1 << reg)))
3993 /* We found an unsaved reg. Generate opcodes to save the
4000 op = 0xc0 | (hi_reg - 10);
4001 add_unwind_opcode (op, 1);
4006 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4007 add_unwind_opcode (op, 2);
4016 ignore_rest_of_line ();
4020 s_arm_unwind_save_mmxwcg (void)
4027 if (*input_line_pointer == '{')
4028 input_line_pointer++;
4032 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4036 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4042 as_tsktsk (_("register list not in ascending order"));
4045 if (*input_line_pointer == '-')
4047 input_line_pointer++;
4048 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4051 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4054 else if (reg >= hi_reg)
4056 as_bad (_("bad register range"));
4059 for (; reg < hi_reg; reg++)
4063 while (skip_past_comma (&input_line_pointer) != FAIL);
4065 if (*input_line_pointer == '}')
4066 input_line_pointer++;
4068 demand_empty_rest_of_line ();
4070 /* Generate any deferred opcodes because we're going to be looking at
4072 flush_pending_unwind ();
4074 for (reg = 0; reg < 16; reg++)
4076 if (mask & (1 << reg))
4077 unwind.frame_size += 4;
4080 add_unwind_opcode (op, 2);
4083 ignore_rest_of_line ();
4087 /* Parse an unwind_save directive.
4088 If the argument is non-zero, this is a .vsave directive. */
4091 s_arm_unwind_save (int arch_v6)
4094 struct reg_entry *reg;
4095 bfd_boolean had_brace = FALSE;
4097 if (!unwind.proc_start)
4098 as_bad (MISSING_FNSTART);
4100 /* Figure out what sort of save we have. */
4101 peek = input_line_pointer;
4109 reg = arm_reg_parse_multi (&peek);
4113 as_bad (_("register expected"));
4114 ignore_rest_of_line ();
4123 as_bad (_("FPA .unwind_save does not take a register list"));
4124 ignore_rest_of_line ();
4127 input_line_pointer = peek;
4128 s_arm_unwind_save_fpa (reg->number);
4131 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
4134 s_arm_unwind_save_vfp_armv6 ();
4136 s_arm_unwind_save_vfp ();
4138 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4139 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4142 as_bad (_(".unwind_save does not support this kind of register"));
4143 ignore_rest_of_line ();
4148 /* Parse an unwind_movsp directive. */
4151 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4157 if (!unwind.proc_start)
4158 as_bad (MISSING_FNSTART);
4160 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4163 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4164 ignore_rest_of_line ();
4168 /* Optional constant. */
4169 if (skip_past_comma (&input_line_pointer) != FAIL)
4171 if (immediate_for_directive (&offset) == FAIL)
4177 demand_empty_rest_of_line ();
4179 if (reg == REG_SP || reg == REG_PC)
4181 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4185 if (unwind.fp_reg != REG_SP)
4186 as_bad (_("unexpected .unwind_movsp directive"));
4188 /* Generate opcode to restore the value. */
4190 add_unwind_opcode (op, 1);
4192 /* Record the information for later. */
4193 unwind.fp_reg = reg;
4194 unwind.fp_offset = unwind.frame_size - offset;
4195 unwind.sp_restored = 1;
4198 /* Parse an unwind_pad directive. */
4201 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4205 if (!unwind.proc_start)
4206 as_bad (MISSING_FNSTART);
4208 if (immediate_for_directive (&offset) == FAIL)
4213 as_bad (_("stack increment must be multiple of 4"));
4214 ignore_rest_of_line ();
4218 /* Don't generate any opcodes, just record the details for later. */
4219 unwind.frame_size += offset;
4220 unwind.pending_offset += offset;
4222 demand_empty_rest_of_line ();
4225 /* Parse an unwind_setfp directive. */
4228 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4234 if (!unwind.proc_start)
4235 as_bad (MISSING_FNSTART);
4237 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4238 if (skip_past_comma (&input_line_pointer) == FAIL)
4241 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4243 if (fp_reg == FAIL || sp_reg == FAIL)
4245 as_bad (_("expected <reg>, <reg>"));
4246 ignore_rest_of_line ();
4250 /* Optional constant. */
4251 if (skip_past_comma (&input_line_pointer) != FAIL)
4253 if (immediate_for_directive (&offset) == FAIL)
4259 demand_empty_rest_of_line ();
4261 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4263 as_bad (_("register must be either sp or set by a previous"
4264 "unwind_movsp directive"));
4268 /* Don't generate any opcodes, just record the information for later. */
4269 unwind.fp_reg = fp_reg;
4271 if (sp_reg == REG_SP)
4272 unwind.fp_offset = unwind.frame_size - offset;
4274 unwind.fp_offset -= offset;
4277 /* Parse an unwind_raw directive. */
4280 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4283 /* This is an arbitrary limit. */
4284 unsigned char op[16];
4287 if (!unwind.proc_start)
4288 as_bad (MISSING_FNSTART);
4291 if (exp.X_op == O_constant
4292 && skip_past_comma (&input_line_pointer) != FAIL)
4294 unwind.frame_size += exp.X_add_number;
4298 exp.X_op = O_illegal;
4300 if (exp.X_op != O_constant)
4302 as_bad (_("expected <offset>, <opcode>"));
4303 ignore_rest_of_line ();
4309 /* Parse the opcode. */
4314 as_bad (_("unwind opcode too long"));
4315 ignore_rest_of_line ();
4317 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4319 as_bad (_("invalid unwind opcode"));
4320 ignore_rest_of_line ();
4323 op[count++] = exp.X_add_number;
4325 /* Parse the next byte. */
4326 if (skip_past_comma (&input_line_pointer) == FAIL)
4332 /* Add the opcode bytes in reverse order. */
4334 add_unwind_opcode (op[count], 1);
4336 demand_empty_rest_of_line ();
4340 /* Parse a .eabi_attribute directive. */
4343 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4345 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4347 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4348 attributes_set_explicitly[tag] = 1;
4351 /* Emit a tls fix for the symbol. */
4354 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4358 #ifdef md_flush_pending_output
4359 md_flush_pending_output ();
4362 #ifdef md_cons_align
4366 /* Since we're just labelling the code, there's no need to define a
4369 p = obstack_next_free (&frchain_now->frch_obstack);
4370 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4371 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4372 : BFD_RELOC_ARM_TLS_DESCSEQ);
4374 #endif /* OBJ_ELF */
4376 static void s_arm_arch (int);
4377 static void s_arm_object_arch (int);
4378 static void s_arm_cpu (int);
4379 static void s_arm_fpu (int);
4380 static void s_arm_arch_extension (int);
4385 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4392 if (exp.X_op == O_symbol)
4393 exp.X_op = O_secrel;
4395 emit_expr (&exp, 4);
4397 while (*input_line_pointer++ == ',');
4399 input_line_pointer--;
4400 demand_empty_rest_of_line ();
4404 /* This table describes all the machine specific pseudo-ops the assembler
4405 has to support. The fields are:
4406 pseudo-op name without dot
4407 function to call to execute this pseudo-op
4408 Integer arg to pass to the function. */
4410 const pseudo_typeS md_pseudo_table[] =
4412 /* Never called because '.req' does not start a line. */
4413 { "req", s_req, 0 },
4414 /* Following two are likewise never called. */
4417 { "unreq", s_unreq, 0 },
4418 { "bss", s_bss, 0 },
4419 { "align", s_align, 0 },
4420 { "arm", s_arm, 0 },
4421 { "thumb", s_thumb, 0 },
4422 { "code", s_code, 0 },
4423 { "force_thumb", s_force_thumb, 0 },
4424 { "thumb_func", s_thumb_func, 0 },
4425 { "thumb_set", s_thumb_set, 0 },
4426 { "even", s_even, 0 },
4427 { "ltorg", s_ltorg, 0 },
4428 { "pool", s_ltorg, 0 },
4429 { "syntax", s_syntax, 0 },
4430 { "cpu", s_arm_cpu, 0 },
4431 { "arch", s_arm_arch, 0 },
4432 { "object_arch", s_arm_object_arch, 0 },
4433 { "fpu", s_arm_fpu, 0 },
4434 { "arch_extension", s_arm_arch_extension, 0 },
4436 { "word", s_arm_elf_cons, 4 },
4437 { "long", s_arm_elf_cons, 4 },
4438 { "inst.n", s_arm_elf_inst, 2 },
4439 { "inst.w", s_arm_elf_inst, 4 },
4440 { "inst", s_arm_elf_inst, 0 },
4441 { "rel31", s_arm_rel31, 0 },
4442 { "fnstart", s_arm_unwind_fnstart, 0 },
4443 { "fnend", s_arm_unwind_fnend, 0 },
4444 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4445 { "personality", s_arm_unwind_personality, 0 },
4446 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4447 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4448 { "save", s_arm_unwind_save, 0 },
4449 { "vsave", s_arm_unwind_save, 1 },
4450 { "movsp", s_arm_unwind_movsp, 0 },
4451 { "pad", s_arm_unwind_pad, 0 },
4452 { "setfp", s_arm_unwind_setfp, 0 },
4453 { "unwind_raw", s_arm_unwind_raw, 0 },
4454 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4455 { "tlsdescseq", s_arm_tls_descseq, 0 },
4459 /* These are used for dwarf. */
4463 /* These are used for dwarf2. */
4464 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4465 { "loc", dwarf2_directive_loc, 0 },
4466 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4468 { "extend", float_cons, 'x' },
4469 { "ldouble", float_cons, 'x' },
4470 { "packed", float_cons, 'p' },
4472 {"secrel32", pe_directive_secrel, 0},
4477 /* Parser functions used exclusively in instruction operands. */
4479 /* Generic immediate-value read function for use in insn parsing.
4480 STR points to the beginning of the immediate (the leading #);
4481 VAL receives the value; if the value is outside [MIN, MAX]
4482 issue an error. PREFIX_OPT is true if the immediate prefix is
4486 parse_immediate (char **str, int *val, int min, int max,
4487 bfd_boolean prefix_opt)
4490 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4491 if (exp.X_op != O_constant)
4493 inst.error = _("constant expression required");
4497 if (exp.X_add_number < min || exp.X_add_number > max)
4499 inst.error = _("immediate value out of range");
4503 *val = exp.X_add_number;
4507 /* Less-generic immediate-value read function with the possibility of loading a
4508 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4509 instructions. Puts the result directly in inst.operands[i]. */
4512 parse_big_immediate (char **str, int i)
4517 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4519 if (exp.X_op == O_constant)
4521 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4522 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4523 O_constant. We have to be careful not to break compilation for
4524 32-bit X_add_number, though. */
4525 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
4527 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4528 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4529 inst.operands[i].regisimm = 1;
4532 else if (exp.X_op == O_big
4533 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
4535 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4537 /* Bignums have their least significant bits in
4538 generic_bignum[0]. Make sure we put 32 bits in imm and
4539 32 bits in reg, in a (hopefully) portable way. */
4540 gas_assert (parts != 0);
4542 /* Make sure that the number is not too big.
4543 PR 11972: Bignums can now be sign-extended to the
4544 size of a .octa so check that the out of range bits
4545 are all zero or all one. */
4546 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4548 LITTLENUM_TYPE m = -1;
4550 if (generic_bignum[parts * 2] != 0
4551 && generic_bignum[parts * 2] != m)
4554 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4555 if (generic_bignum[j] != generic_bignum[j-1])
4559 inst.operands[i].imm = 0;
4560 for (j = 0; j < parts; j++, idx++)
4561 inst.operands[i].imm |= generic_bignum[idx]
4562 << (LITTLENUM_NUMBER_OF_BITS * j);
4563 inst.operands[i].reg = 0;
4564 for (j = 0; j < parts; j++, idx++)
4565 inst.operands[i].reg |= generic_bignum[idx]
4566 << (LITTLENUM_NUMBER_OF_BITS * j);
4567 inst.operands[i].regisimm = 1;
4577 /* Returns the pseudo-register number of an FPA immediate constant,
4578 or FAIL if there isn't a valid constant here. */
4581 parse_fpa_immediate (char ** str)
4583 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4589 /* First try and match exact strings, this is to guarantee
4590 that some formats will work even for cross assembly. */
4592 for (i = 0; fp_const[i]; i++)
4594 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4598 *str += strlen (fp_const[i]);
4599 if (is_end_of_line[(unsigned char) **str])
4605 /* Just because we didn't get a match doesn't mean that the constant
4606 isn't valid, just that it is in a format that we don't
4607 automatically recognize. Try parsing it with the standard
4608 expression routines. */
4610 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4612 /* Look for a raw floating point number. */
4613 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4614 && is_end_of_line[(unsigned char) *save_in])
4616 for (i = 0; i < NUM_FLOAT_VALS; i++)
4618 for (j = 0; j < MAX_LITTLENUMS; j++)
4620 if (words[j] != fp_values[i][j])
4624 if (j == MAX_LITTLENUMS)
4632 /* Try and parse a more complex expression, this will probably fail
4633 unless the code uses a floating point prefix (eg "0f"). */
4634 save_in = input_line_pointer;
4635 input_line_pointer = *str;
4636 if (expression (&exp) == absolute_section
4637 && exp.X_op == O_big
4638 && exp.X_add_number < 0)
4640 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4642 if (gen_to_words (words, 5, (long) 15) == 0)
4644 for (i = 0; i < NUM_FLOAT_VALS; i++)
4646 for (j = 0; j < MAX_LITTLENUMS; j++)
4648 if (words[j] != fp_values[i][j])
4652 if (j == MAX_LITTLENUMS)
4654 *str = input_line_pointer;
4655 input_line_pointer = save_in;
4662 *str = input_line_pointer;
4663 input_line_pointer = save_in;
4664 inst.error = _("invalid FPA immediate expression");
4668 /* Returns 1 if a number has "quarter-precision" float format
4669 0baBbbbbbc defgh000 00000000 00000000. */
4672 is_quarter_float (unsigned imm)
4674 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4675 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4678 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4679 0baBbbbbbc defgh000 00000000 00000000.
4680 The zero and minus-zero cases need special handling, since they can't be
4681 encoded in the "quarter-precision" float format, but can nonetheless be
4682 loaded as integer constants. */
4685 parse_qfloat_immediate (char **ccp, int *immed)
4689 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4690 int found_fpchar = 0;
4692 skip_past_char (&str, '#');
4694 /* We must not accidentally parse an integer as a floating-point number. Make
4695 sure that the value we parse is not an integer by checking for special
4696 characters '.' or 'e'.
4697 FIXME: This is a horrible hack, but doing better is tricky because type
4698 information isn't in a very usable state at parse time. */
4700 skip_whitespace (fpnum);
4702 if (strncmp (fpnum, "0x", 2) == 0)
4706 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4707 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4717 if ((str = atof_ieee (str, 's', words)) != NULL)
4719 unsigned fpword = 0;
4722 /* Our FP word must be 32 bits (single-precision FP). */
4723 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4725 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4729 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4742 /* Shift operands. */
4745 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4748 struct asm_shift_name
4751 enum shift_kind kind;
4754 /* Third argument to parse_shift. */
4755 enum parse_shift_mode
4757 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4758 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4759 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4760 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4761 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4764 /* Parse a <shift> specifier on an ARM data processing instruction.
4765 This has three forms:
4767 (LSL|LSR|ASL|ASR|ROR) Rs
4768 (LSL|LSR|ASL|ASR|ROR) #imm
4771 Note that ASL is assimilated to LSL in the instruction encoding, and
4772 RRX to ROR #0 (which cannot be written as such). */
4775 parse_shift (char **str, int i, enum parse_shift_mode mode)
4777 const struct asm_shift_name *shift_name;
4778 enum shift_kind shift;
4783 for (p = *str; ISALPHA (*p); p++)
4788 inst.error = _("shift expression expected");
4792 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4795 if (shift_name == NULL)
4797 inst.error = _("shift expression expected");
4801 shift = shift_name->kind;
4805 case NO_SHIFT_RESTRICT:
4806 case SHIFT_IMMEDIATE: break;
4808 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4809 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4811 inst.error = _("'LSL' or 'ASR' required");
4816 case SHIFT_LSL_IMMEDIATE:
4817 if (shift != SHIFT_LSL)
4819 inst.error = _("'LSL' required");
4824 case SHIFT_ASR_IMMEDIATE:
4825 if (shift != SHIFT_ASR)
4827 inst.error = _("'ASR' required");
4835 if (shift != SHIFT_RRX)
4837 /* Whitespace can appear here if the next thing is a bare digit. */
4838 skip_whitespace (p);
4840 if (mode == NO_SHIFT_RESTRICT
4841 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4843 inst.operands[i].imm = reg;
4844 inst.operands[i].immisreg = 1;
4846 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4849 inst.operands[i].shift_kind = shift;
4850 inst.operands[i].shifted = 1;
4855 /* Parse a <shifter_operand> for an ARM data processing instruction:
4858 #<immediate>, <rotate>
4862 where <shift> is defined by parse_shift above, and <rotate> is a
4863 multiple of 2 between 0 and 30. Validation of immediate operands
4864 is deferred to md_apply_fix. */
4867 parse_shifter_operand (char **str, int i)
4872 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4874 inst.operands[i].reg = value;
4875 inst.operands[i].isreg = 1;
4877 /* parse_shift will override this if appropriate */
4878 inst.reloc.exp.X_op = O_constant;
4879 inst.reloc.exp.X_add_number = 0;
4881 if (skip_past_comma (str) == FAIL)
4884 /* Shift operation on register. */
4885 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4888 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4891 if (skip_past_comma (str) == SUCCESS)
4893 /* #x, y -- ie explicit rotation by Y. */
4894 if (my_get_expression (&exp, str, GE_NO_PREFIX))
4897 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4899 inst.error = _("constant expression expected");
4903 value = exp.X_add_number;
4904 if (value < 0 || value > 30 || value % 2 != 0)
4906 inst.error = _("invalid rotation");
4909 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4911 inst.error = _("invalid constant");
4915 /* Encode as specified. */
4916 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
4920 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4921 inst.reloc.pc_rel = 0;
4925 /* Group relocation information. Each entry in the table contains the
4926 textual name of the relocation as may appear in assembler source
4927 and must end with a colon.
4928 Along with this textual name are the relocation codes to be used if
4929 the corresponding instruction is an ALU instruction (ADD or SUB only),
4930 an LDR, an LDRS, or an LDC. */
4932 struct group_reloc_table_entry
4943 /* Varieties of non-ALU group relocation. */
4950 static struct group_reloc_table_entry group_reloc_table[] =
4951 { /* Program counter relative: */
4953 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4958 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4959 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4960 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4961 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4963 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4968 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4969 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4970 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4971 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4973 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4974 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4975 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4976 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4977 /* Section base relative */
4979 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4984 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4985 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4986 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4987 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4989 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4994 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4995 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4996 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4997 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4999 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5000 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5001 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5002 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
5004 /* Given the address of a pointer pointing to the textual name of a group
5005 relocation as may appear in assembler source, attempt to find its details
5006 in group_reloc_table. The pointer will be updated to the character after
5007 the trailing colon. On failure, FAIL will be returned; SUCCESS
5008 otherwise. On success, *entry will be updated to point at the relevant
5009 group_reloc_table entry. */
5012 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5015 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5017 int length = strlen (group_reloc_table[i].name);
5019 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5020 && (*str)[length] == ':')
5022 *out = &group_reloc_table[i];
5023 *str += (length + 1);
5031 /* Parse a <shifter_operand> for an ARM data processing instruction
5032 (as for parse_shifter_operand) where group relocations are allowed:
5035 #<immediate>, <rotate>
5036 #:<group_reloc>:<expression>
5040 where <group_reloc> is one of the strings defined in group_reloc_table.
5041 The hashes are optional.
5043 Everything else is as for parse_shifter_operand. */
5045 static parse_operand_result
5046 parse_shifter_operand_group_reloc (char **str, int i)
5048 /* Determine if we have the sequence of characters #: or just :
5049 coming next. If we do, then we check for a group relocation.
5050 If we don't, punt the whole lot to parse_shifter_operand. */
5052 if (((*str)[0] == '#' && (*str)[1] == ':')
5053 || (*str)[0] == ':')
5055 struct group_reloc_table_entry *entry;
5057 if ((*str)[0] == '#')
5062 /* Try to parse a group relocation. Anything else is an error. */
5063 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5065 inst.error = _("unknown group relocation");
5066 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5069 /* We now have the group relocation table entry corresponding to
5070 the name in the assembler source. Next, we parse the expression. */
5071 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5072 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5074 /* Record the relocation type (always the ALU variant here). */
5075 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
5076 gas_assert (inst.reloc.type != 0);
5078 return PARSE_OPERAND_SUCCESS;
5081 return parse_shifter_operand (str, i) == SUCCESS
5082 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5084 /* Never reached. */
5087 /* Parse a Neon alignment expression. Information is written to
5088 inst.operands[i]. We assume the initial ':' has been skipped.
5090 align .imm = align << 8, .immisalign=1, .preind=0 */
5091 static parse_operand_result
5092 parse_neon_alignment (char **str, int i)
5097 my_get_expression (&exp, &p, GE_NO_PREFIX);
5099 if (exp.X_op != O_constant)
5101 inst.error = _("alignment must be constant");
5102 return PARSE_OPERAND_FAIL;
5105 inst.operands[i].imm = exp.X_add_number << 8;
5106 inst.operands[i].immisalign = 1;
5107 /* Alignments are not pre-indexes. */
5108 inst.operands[i].preind = 0;
5111 return PARSE_OPERAND_SUCCESS;
5114 /* Parse all forms of an ARM address expression. Information is written
5115 to inst.operands[i] and/or inst.reloc.
5117 Preindexed addressing (.preind=1):
5119 [Rn, #offset] .reg=Rn .reloc.exp=offset
5120 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5121 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5122 .shift_kind=shift .reloc.exp=shift_imm
5124 These three may have a trailing ! which causes .writeback to be set also.
5126 Postindexed addressing (.postind=1, .writeback=1):
5128 [Rn], #offset .reg=Rn .reloc.exp=offset
5129 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5130 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5131 .shift_kind=shift .reloc.exp=shift_imm
5133 Unindexed addressing (.preind=0, .postind=0):
5135 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5139 [Rn]{!} shorthand for [Rn,#0]{!}
5140 =immediate .isreg=0 .reloc.exp=immediate
5141 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
5143 It is the caller's responsibility to check for addressing modes not
5144 supported by the instruction, and to set inst.reloc.type. */
5146 static parse_operand_result
5147 parse_address_main (char **str, int i, int group_relocations,
5148 group_reloc_type group_type)
5153 if (skip_past_char (&p, '[') == FAIL)
5155 if (skip_past_char (&p, '=') == FAIL)
5157 /* Bare address - translate to PC-relative offset. */
5158 inst.reloc.pc_rel = 1;
5159 inst.operands[i].reg = REG_PC;
5160 inst.operands[i].isreg = 1;
5161 inst.operands[i].preind = 1;
5163 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
5165 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5166 return PARSE_OPERAND_FAIL;
5169 return PARSE_OPERAND_SUCCESS;
5172 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5173 skip_whitespace (p);
5175 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5177 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5178 return PARSE_OPERAND_FAIL;
5180 inst.operands[i].reg = reg;
5181 inst.operands[i].isreg = 1;
5183 if (skip_past_comma (&p) == SUCCESS)
5185 inst.operands[i].preind = 1;
5188 else if (*p == '-') p++, inst.operands[i].negative = 1;
5190 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5192 inst.operands[i].imm = reg;
5193 inst.operands[i].immisreg = 1;
5195 if (skip_past_comma (&p) == SUCCESS)
5196 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5197 return PARSE_OPERAND_FAIL;
5199 else if (skip_past_char (&p, ':') == SUCCESS)
5201 /* FIXME: '@' should be used here, but it's filtered out by generic
5202 code before we get to see it here. This may be subject to
5204 parse_operand_result result = parse_neon_alignment (&p, i);
5206 if (result != PARSE_OPERAND_SUCCESS)
5211 if (inst.operands[i].negative)
5213 inst.operands[i].negative = 0;
5217 if (group_relocations
5218 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5220 struct group_reloc_table_entry *entry;
5222 /* Skip over the #: or : sequence. */
5228 /* Try to parse a group relocation. Anything else is an
5230 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5232 inst.error = _("unknown group relocation");
5233 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5236 /* We now have the group relocation table entry corresponding to
5237 the name in the assembler source. Next, we parse the
5239 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5240 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5242 /* Record the relocation type. */
5246 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5250 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5254 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5261 if (inst.reloc.type == 0)
5263 inst.error = _("this group relocation is not allowed on this instruction");
5264 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5270 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5271 return PARSE_OPERAND_FAIL;
5272 /* If the offset is 0, find out if it's a +0 or -0. */
5273 if (inst.reloc.exp.X_op == O_constant
5274 && inst.reloc.exp.X_add_number == 0)
5276 skip_whitespace (q);
5280 skip_whitespace (q);
5283 inst.operands[i].negative = 1;
5288 else if (skip_past_char (&p, ':') == SUCCESS)
5290 /* FIXME: '@' should be used here, but it's filtered out by generic code
5291 before we get to see it here. This may be subject to change. */
5292 parse_operand_result result = parse_neon_alignment (&p, i);
5294 if (result != PARSE_OPERAND_SUCCESS)
5298 if (skip_past_char (&p, ']') == FAIL)
5300 inst.error = _("']' expected");
5301 return PARSE_OPERAND_FAIL;
5304 if (skip_past_char (&p, '!') == SUCCESS)
5305 inst.operands[i].writeback = 1;
5307 else if (skip_past_comma (&p) == SUCCESS)
5309 if (skip_past_char (&p, '{') == SUCCESS)
5311 /* [Rn], {expr} - unindexed, with option */
5312 if (parse_immediate (&p, &inst.operands[i].imm,
5313 0, 255, TRUE) == FAIL)
5314 return PARSE_OPERAND_FAIL;
5316 if (skip_past_char (&p, '}') == FAIL)
5318 inst.error = _("'}' expected at end of 'option' field");
5319 return PARSE_OPERAND_FAIL;
5321 if (inst.operands[i].preind)
5323 inst.error = _("cannot combine index with option");
5324 return PARSE_OPERAND_FAIL;
5327 return PARSE_OPERAND_SUCCESS;
5331 inst.operands[i].postind = 1;
5332 inst.operands[i].writeback = 1;
5334 if (inst.operands[i].preind)
5336 inst.error = _("cannot combine pre- and post-indexing");
5337 return PARSE_OPERAND_FAIL;
5341 else if (*p == '-') p++, inst.operands[i].negative = 1;
5343 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5345 /* We might be using the immediate for alignment already. If we
5346 are, OR the register number into the low-order bits. */
5347 if (inst.operands[i].immisalign)
5348 inst.operands[i].imm |= reg;
5350 inst.operands[i].imm = reg;
5351 inst.operands[i].immisreg = 1;
5353 if (skip_past_comma (&p) == SUCCESS)
5354 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5355 return PARSE_OPERAND_FAIL;
5360 if (inst.operands[i].negative)
5362 inst.operands[i].negative = 0;
5365 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5366 return PARSE_OPERAND_FAIL;
5367 /* If the offset is 0, find out if it's a +0 or -0. */
5368 if (inst.reloc.exp.X_op == O_constant
5369 && inst.reloc.exp.X_add_number == 0)
5371 skip_whitespace (q);
5375 skip_whitespace (q);
5378 inst.operands[i].negative = 1;
5384 /* If at this point neither .preind nor .postind is set, we have a
5385 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5386 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5388 inst.operands[i].preind = 1;
5389 inst.reloc.exp.X_op = O_constant;
5390 inst.reloc.exp.X_add_number = 0;
5393 return PARSE_OPERAND_SUCCESS;
5397 parse_address (char **str, int i)
5399 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5403 static parse_operand_result
5404 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5406 return parse_address_main (str, i, 1, type);
5409 /* Parse an operand for a MOVW or MOVT instruction. */
5411 parse_half (char **str)
5416 skip_past_char (&p, '#');
5417 if (strncasecmp (p, ":lower16:", 9) == 0)
5418 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5419 else if (strncasecmp (p, ":upper16:", 9) == 0)
5420 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5422 if (inst.reloc.type != BFD_RELOC_UNUSED)
5425 skip_whitespace (p);
5428 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5431 if (inst.reloc.type == BFD_RELOC_UNUSED)
5433 if (inst.reloc.exp.X_op != O_constant)
5435 inst.error = _("constant expression expected");
5438 if (inst.reloc.exp.X_add_number < 0
5439 || inst.reloc.exp.X_add_number > 0xffff)
5441 inst.error = _("immediate value out of range");
5449 /* Miscellaneous. */
5451 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5452 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5454 parse_psr (char **str, bfd_boolean lhs)
5457 unsigned long psr_field;
5458 const struct asm_psr *psr;
5460 bfd_boolean is_apsr = FALSE;
5461 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
5463 /* PR gas/12698: If the user has specified -march=all then m_profile will
5464 be TRUE, but we want to ignore it in this case as we are building for any
5465 CPU type, including non-m variants. */
5466 if (selected_cpu.core == arm_arch_any.core)
5469 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5470 feature for ease of use and backwards compatibility. */
5472 if (strncasecmp (p, "SPSR", 4) == 0)
5475 goto unsupported_psr;
5477 psr_field = SPSR_BIT;
5479 else if (strncasecmp (p, "CPSR", 4) == 0)
5482 goto unsupported_psr;
5486 else if (strncasecmp (p, "APSR", 4) == 0)
5488 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5489 and ARMv7-R architecture CPUs. */
5498 while (ISALNUM (*p) || *p == '_');
5500 if (strncasecmp (start, "iapsr", 5) == 0
5501 || strncasecmp (start, "eapsr", 5) == 0
5502 || strncasecmp (start, "xpsr", 4) == 0
5503 || strncasecmp (start, "psr", 3) == 0)
5504 p = start + strcspn (start, "rR") + 1;
5506 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5512 /* If APSR is being written, a bitfield may be specified. Note that
5513 APSR itself is handled above. */
5514 if (psr->field <= 3)
5516 psr_field = psr->field;
5522 /* M-profile MSR instructions have the mask field set to "10", except
5523 *PSR variants which modify APSR, which may use a different mask (and
5524 have been handled already). Do that by setting the PSR_f field
5526 return psr->field | (lhs ? PSR_f : 0);
5529 goto unsupported_psr;
5535 /* A suffix follows. */
5541 while (ISALNUM (*p) || *p == '_');
5545 /* APSR uses a notation for bits, rather than fields. */
5546 unsigned int nzcvq_bits = 0;
5547 unsigned int g_bit = 0;
5550 for (bit = start; bit != p; bit++)
5552 switch (TOLOWER (*bit))
5555 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5559 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5563 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5567 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5571 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5575 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5579 inst.error = _("unexpected bit specified after APSR");
5584 if (nzcvq_bits == 0x1f)
5589 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5591 inst.error = _("selected processor does not "
5592 "support DSP extension");
5599 if ((nzcvq_bits & 0x20) != 0
5600 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5601 || (g_bit & 0x2) != 0)
5603 inst.error = _("bad bitmask specified after APSR");
5609 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5614 psr_field |= psr->field;
5620 goto error; /* Garbage after "[CS]PSR". */
5622 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5623 is deprecated, but allow it anyway. */
5627 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5630 else if (!m_profile)
5631 /* These bits are never right for M-profile devices: don't set them
5632 (only code paths which read/write APSR reach here). */
5633 psr_field |= (PSR_c | PSR_f);
5639 inst.error = _("selected processor does not support requested special "
5640 "purpose register");
5644 inst.error = _("flag for {c}psr instruction expected");
5648 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5649 value suitable for splatting into the AIF field of the instruction. */
5652 parse_cps_flags (char **str)
5661 case '\0': case ',':
5664 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5665 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5666 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5669 inst.error = _("unrecognized CPS flag");
5674 if (saw_a_flag == 0)
5676 inst.error = _("missing CPS flags");
5684 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5685 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5688 parse_endian_specifier (char **str)
5693 if (strncasecmp (s, "BE", 2))
5695 else if (strncasecmp (s, "LE", 2))
5699 inst.error = _("valid endian specifiers are be or le");
5703 if (ISALNUM (s[2]) || s[2] == '_')
5705 inst.error = _("valid endian specifiers are be or le");
5710 return little_endian;
5713 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5714 value suitable for poking into the rotate field of an sxt or sxta
5715 instruction, or FAIL on error. */
5718 parse_ror (char **str)
5723 if (strncasecmp (s, "ROR", 3) == 0)
5727 inst.error = _("missing rotation field after comma");
5731 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5736 case 0: *str = s; return 0x0;
5737 case 8: *str = s; return 0x1;
5738 case 16: *str = s; return 0x2;
5739 case 24: *str = s; return 0x3;
5742 inst.error = _("rotation can only be 0, 8, 16, or 24");
5747 /* Parse a conditional code (from conds[] below). The value returned is in the
5748 range 0 .. 14, or FAIL. */
5750 parse_cond (char **str)
5753 const struct asm_cond *c;
5755 /* Condition codes are always 2 characters, so matching up to
5756 3 characters is sufficient. */
5761 while (ISALPHA (*q) && n < 3)
5763 cond[n] = TOLOWER (*q);
5768 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
5771 inst.error = _("condition required");
5779 /* If the given feature available in the selected CPU, mark it as used.
5780 Returns TRUE iff feature is available. */
5782 mark_feature_used (const arm_feature_set *feature)
5784 /* Ensure the option is valid on the current architecture. */
5785 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
5788 /* Add the appropriate architecture feature for the barrier option used.
5791 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
5793 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
5798 /* Parse an option for a barrier instruction. Returns the encoding for the
5801 parse_barrier (char **str)
5804 const struct asm_barrier_opt *o;
5807 while (ISALPHA (*q))
5810 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5815 if (!mark_feature_used (&o->arch))
5822 /* Parse the operands of a table branch instruction. Similar to a memory
5825 parse_tb (char **str)
5830 if (skip_past_char (&p, '[') == FAIL)
5832 inst.error = _("'[' expected");
5836 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5838 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5841 inst.operands[0].reg = reg;
5843 if (skip_past_comma (&p) == FAIL)
5845 inst.error = _("',' expected");
5849 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5851 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5854 inst.operands[0].imm = reg;
5856 if (skip_past_comma (&p) == SUCCESS)
5858 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5860 if (inst.reloc.exp.X_add_number != 1)
5862 inst.error = _("invalid shift");
5865 inst.operands[0].shifted = 1;
5868 if (skip_past_char (&p, ']') == FAIL)
5870 inst.error = _("']' expected");
5877 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5878 information on the types the operands can take and how they are encoded.
5879 Up to four operands may be read; this function handles setting the
5880 ".present" field for each read operand itself.
5881 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5882 else returns FAIL. */
5885 parse_neon_mov (char **str, int *which_operand)
5887 int i = *which_operand, val;
5888 enum arm_reg_type rtype;
5890 struct neon_type_el optype;
5892 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5894 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5895 inst.operands[i].reg = val;
5896 inst.operands[i].isscalar = 1;
5897 inst.operands[i].vectype = optype;
5898 inst.operands[i++].present = 1;
5900 if (skip_past_comma (&ptr) == FAIL)
5903 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5906 inst.operands[i].reg = val;
5907 inst.operands[i].isreg = 1;
5908 inst.operands[i].present = 1;
5910 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5913 /* Cases 0, 1, 2, 3, 5 (D only). */
5914 if (skip_past_comma (&ptr) == FAIL)
5917 inst.operands[i].reg = val;
5918 inst.operands[i].isreg = 1;
5919 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5920 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5921 inst.operands[i].isvec = 1;
5922 inst.operands[i].vectype = optype;
5923 inst.operands[i++].present = 1;
5925 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5927 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5928 Case 13: VMOV <Sd>, <Rm> */
5929 inst.operands[i].reg = val;
5930 inst.operands[i].isreg = 1;
5931 inst.operands[i].present = 1;
5933 if (rtype == REG_TYPE_NQ)
5935 first_error (_("can't use Neon quad register here"));
5938 else if (rtype != REG_TYPE_VFS)
5941 if (skip_past_comma (&ptr) == FAIL)
5943 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5945 inst.operands[i].reg = val;
5946 inst.operands[i].isreg = 1;
5947 inst.operands[i].present = 1;
5950 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5953 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5954 Case 1: VMOV<c><q> <Dd>, <Dm>
5955 Case 8: VMOV.F32 <Sd>, <Sm>
5956 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5958 inst.operands[i].reg = val;
5959 inst.operands[i].isreg = 1;
5960 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5961 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5962 inst.operands[i].isvec = 1;
5963 inst.operands[i].vectype = optype;
5964 inst.operands[i].present = 1;
5966 if (skip_past_comma (&ptr) == SUCCESS)
5971 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5974 inst.operands[i].reg = val;
5975 inst.operands[i].isreg = 1;
5976 inst.operands[i++].present = 1;
5978 if (skip_past_comma (&ptr) == FAIL)
5981 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5984 inst.operands[i].reg = val;
5985 inst.operands[i].isreg = 1;
5986 inst.operands[i].present = 1;
5989 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5990 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5991 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5992 Case 10: VMOV.F32 <Sd>, #<imm>
5993 Case 11: VMOV.F64 <Dd>, #<imm> */
5994 inst.operands[i].immisfloat = 1;
5995 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5996 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5997 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6001 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6005 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6008 inst.operands[i].reg = val;
6009 inst.operands[i].isreg = 1;
6010 inst.operands[i++].present = 1;
6012 if (skip_past_comma (&ptr) == FAIL)
6015 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
6017 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6018 inst.operands[i].reg = val;
6019 inst.operands[i].isscalar = 1;
6020 inst.operands[i].present = 1;
6021 inst.operands[i].vectype = optype;
6023 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6025 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6026 inst.operands[i].reg = val;
6027 inst.operands[i].isreg = 1;
6028 inst.operands[i++].present = 1;
6030 if (skip_past_comma (&ptr) == FAIL)
6033 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6036 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6040 inst.operands[i].reg = val;
6041 inst.operands[i].isreg = 1;
6042 inst.operands[i].isvec = 1;
6043 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6044 inst.operands[i].vectype = optype;
6045 inst.operands[i].present = 1;
6047 if (rtype == REG_TYPE_VFS)
6051 if (skip_past_comma (&ptr) == FAIL)
6053 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6056 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6059 inst.operands[i].reg = val;
6060 inst.operands[i].isreg = 1;
6061 inst.operands[i].isvec = 1;
6062 inst.operands[i].issingle = 1;
6063 inst.operands[i].vectype = optype;
6064 inst.operands[i].present = 1;
6067 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6071 inst.operands[i].reg = val;
6072 inst.operands[i].isreg = 1;
6073 inst.operands[i].isvec = 1;
6074 inst.operands[i].issingle = 1;
6075 inst.operands[i].vectype = optype;
6076 inst.operands[i].present = 1;
6081 first_error (_("parse error"));
6085 /* Successfully parsed the operands. Update args. */
6091 first_error (_("expected comma"));
6095 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6099 /* Use this macro when the operand constraints are different
6100 for ARM and THUMB (e.g. ldrd). */
6101 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6102 ((arm_operand) | ((thumb_operand) << 16))
6104 /* Matcher codes for parse_operands. */
6105 enum operand_parse_code
6107 OP_stop, /* end of line */
6109 OP_RR, /* ARM register */
6110 OP_RRnpc, /* ARM register, not r15 */
6111 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6112 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6113 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6114 optional trailing ! */
6115 OP_RRw, /* ARM register, not r15, optional trailing ! */
6116 OP_RCP, /* Coprocessor number */
6117 OP_RCN, /* Coprocessor register */
6118 OP_RF, /* FPA register */
6119 OP_RVS, /* VFP single precision register */
6120 OP_RVD, /* VFP double precision register (0..15) */
6121 OP_RND, /* Neon double precision register (0..31) */
6122 OP_RNQ, /* Neon quad precision register */
6123 OP_RVSD, /* VFP single or double precision register */
6124 OP_RNDQ, /* Neon double or quad precision register */
6125 OP_RNSDQ, /* Neon single, double or quad precision register */
6126 OP_RNSC, /* Neon scalar D[X] */
6127 OP_RVC, /* VFP control register */
6128 OP_RMF, /* Maverick F register */
6129 OP_RMD, /* Maverick D register */
6130 OP_RMFX, /* Maverick FX register */
6131 OP_RMDX, /* Maverick DX register */
6132 OP_RMAX, /* Maverick AX register */
6133 OP_RMDS, /* Maverick DSPSC register */
6134 OP_RIWR, /* iWMMXt wR register */
6135 OP_RIWC, /* iWMMXt wC register */
6136 OP_RIWG, /* iWMMXt wCG register */
6137 OP_RXA, /* XScale accumulator register */
6139 OP_REGLST, /* ARM register list */
6140 OP_VRSLST, /* VFP single-precision register list */
6141 OP_VRDLST, /* VFP double-precision register list */
6142 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
6143 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6144 OP_NSTRLST, /* Neon element/structure list */
6146 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
6147 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
6148 OP_RR_RNSC, /* ARM reg or Neon scalar. */
6149 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
6150 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6151 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6152 OP_VMOV, /* Neon VMOV operands. */
6153 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
6154 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
6155 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
6157 OP_I0, /* immediate zero */
6158 OP_I7, /* immediate value 0 .. 7 */
6159 OP_I15, /* 0 .. 15 */
6160 OP_I16, /* 1 .. 16 */
6161 OP_I16z, /* 0 .. 16 */
6162 OP_I31, /* 0 .. 31 */
6163 OP_I31w, /* 0 .. 31, optional trailing ! */
6164 OP_I32, /* 1 .. 32 */
6165 OP_I32z, /* 0 .. 32 */
6166 OP_I63, /* 0 .. 63 */
6167 OP_I63s, /* -64 .. 63 */
6168 OP_I64, /* 1 .. 64 */
6169 OP_I64z, /* 0 .. 64 */
6170 OP_I255, /* 0 .. 255 */
6172 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6173 OP_I7b, /* 0 .. 7 */
6174 OP_I15b, /* 0 .. 15 */
6175 OP_I31b, /* 0 .. 31 */
6177 OP_SH, /* shifter operand */
6178 OP_SHG, /* shifter operand with possible group relocation */
6179 OP_ADDR, /* Memory address expression (any mode) */
6180 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6181 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6182 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
6183 OP_EXP, /* arbitrary expression */
6184 OP_EXPi, /* same, with optional immediate prefix */
6185 OP_EXPr, /* same, with optional relocation suffix */
6186 OP_HALF, /* 0 .. 65535 or low/high reloc. */
6188 OP_CPSF, /* CPS flags */
6189 OP_ENDI, /* Endianness specifier */
6190 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6191 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
6192 OP_COND, /* conditional code */
6193 OP_TB, /* Table branch. */
6195 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6197 OP_RRnpc_I0, /* ARM register or literal 0 */
6198 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6199 OP_RR_EXi, /* ARM register or expression with imm prefix */
6200 OP_RF_IF, /* FPA register or immediate */
6201 OP_RIWR_RIWC, /* iWMMXt R or C reg */
6202 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
6204 /* Optional operands. */
6205 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6206 OP_oI31b, /* 0 .. 31 */
6207 OP_oI32b, /* 1 .. 32 */
6208 OP_oI32z, /* 0 .. 32 */
6209 OP_oIffffb, /* 0 .. 65535 */
6210 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6212 OP_oRR, /* ARM register */
6213 OP_oRRnpc, /* ARM register, not the PC */
6214 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
6215 OP_oRRw, /* ARM register, not r15, optional trailing ! */
6216 OP_oRND, /* Optional Neon double precision register */
6217 OP_oRNQ, /* Optional Neon quad precision register */
6218 OP_oRNDQ, /* Optional Neon double or quad precision register */
6219 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
6220 OP_oSHll, /* LSL immediate */
6221 OP_oSHar, /* ASR immediate */
6222 OP_oSHllar, /* LSL or ASR immediate */
6223 OP_oROR, /* ROR 0/8/16/24 */
6224 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
6226 /* Some pre-defined mixed (ARM/THUMB) operands. */
6227 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6228 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6229 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6231 OP_FIRST_OPTIONAL = OP_oI7b
6234 /* Generic instruction operand parser. This does no encoding and no
6235 semantic validation; it merely squirrels values away in the inst
6236 structure. Returns SUCCESS or FAIL depending on whether the
6237 specified grammar matched. */
6239 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
6241 unsigned const int *upat = pattern;
6242 char *backtrack_pos = 0;
6243 const char *backtrack_error = 0;
6244 int i, val = 0, backtrack_index = 0;
6245 enum arm_reg_type rtype;
6246 parse_operand_result result;
6247 unsigned int op_parse_code;
6249 #define po_char_or_fail(chr) \
6252 if (skip_past_char (&str, chr) == FAIL) \
6257 #define po_reg_or_fail(regtype) \
6260 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6261 & inst.operands[i].vectype); \
6264 first_error (_(reg_expected_msgs[regtype])); \
6267 inst.operands[i].reg = val; \
6268 inst.operands[i].isreg = 1; \
6269 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6270 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6271 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6272 || rtype == REG_TYPE_VFD \
6273 || rtype == REG_TYPE_NQ); \
6277 #define po_reg_or_goto(regtype, label) \
6280 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6281 & inst.operands[i].vectype); \
6285 inst.operands[i].reg = val; \
6286 inst.operands[i].isreg = 1; \
6287 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6288 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6289 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6290 || rtype == REG_TYPE_VFD \
6291 || rtype == REG_TYPE_NQ); \
6295 #define po_imm_or_fail(min, max, popt) \
6298 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6300 inst.operands[i].imm = val; \
6304 #define po_scalar_or_goto(elsz, label) \
6307 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6310 inst.operands[i].reg = val; \
6311 inst.operands[i].isscalar = 1; \
6315 #define po_misc_or_fail(expr) \
6323 #define po_misc_or_fail_no_backtrack(expr) \
6327 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6328 backtrack_pos = 0; \
6329 if (result != PARSE_OPERAND_SUCCESS) \
6334 #define po_barrier_or_imm(str) \
6337 val = parse_barrier (&str); \
6340 if (ISALPHA (*str)) \
6347 if ((inst.instruction & 0xf0) == 0x60 \
6350 /* ISB can only take SY as an option. */ \
6351 inst.error = _("invalid barrier type"); \
6358 skip_whitespace (str);
6360 for (i = 0; upat[i] != OP_stop; i++)
6362 op_parse_code = upat[i];
6363 if (op_parse_code >= 1<<16)
6364 op_parse_code = thumb ? (op_parse_code >> 16)
6365 : (op_parse_code & ((1<<16)-1));
6367 if (op_parse_code >= OP_FIRST_OPTIONAL)
6369 /* Remember where we are in case we need to backtrack. */
6370 gas_assert (!backtrack_pos);
6371 backtrack_pos = str;
6372 backtrack_error = inst.error;
6373 backtrack_index = i;
6376 if (i > 0 && (i > 1 || inst.operands[0].present))
6377 po_char_or_fail (',');
6379 switch (op_parse_code)
6387 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6388 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6389 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6390 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6391 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6392 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6394 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6396 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6398 /* Also accept generic coprocessor regs for unknown registers. */
6400 po_reg_or_fail (REG_TYPE_CN);
6402 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6403 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6404 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6405 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6406 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6407 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6408 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6409 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6410 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6411 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6413 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6415 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6416 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6418 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6420 /* Neon scalar. Using an element size of 8 means that some invalid
6421 scalars are accepted here, so deal with those in later code. */
6422 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6426 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6429 po_imm_or_fail (0, 0, TRUE);
6434 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6439 po_scalar_or_goto (8, try_rr);
6442 po_reg_or_fail (REG_TYPE_RN);
6448 po_scalar_or_goto (8, try_nsdq);
6451 po_reg_or_fail (REG_TYPE_NSDQ);
6457 po_scalar_or_goto (8, try_ndq);
6460 po_reg_or_fail (REG_TYPE_NDQ);
6466 po_scalar_or_goto (8, try_vfd);
6469 po_reg_or_fail (REG_TYPE_VFD);
6474 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6475 not careful then bad things might happen. */
6476 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6481 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6484 /* There's a possibility of getting a 64-bit immediate here, so
6485 we need special handling. */
6486 if (parse_big_immediate (&str, i) == FAIL)
6488 inst.error = _("immediate value is out of range");
6496 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6499 po_imm_or_fail (0, 63, TRUE);
6504 po_char_or_fail ('[');
6505 po_reg_or_fail (REG_TYPE_RN);
6506 po_char_or_fail (']');
6512 po_reg_or_fail (REG_TYPE_RN);
6513 if (skip_past_char (&str, '!') == SUCCESS)
6514 inst.operands[i].writeback = 1;
6518 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6519 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6520 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6521 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6522 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6523 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6524 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6525 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6526 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6527 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6528 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6529 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6531 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6533 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6534 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6536 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6537 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6538 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
6539 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6541 /* Immediate variants */
6543 po_char_or_fail ('{');
6544 po_imm_or_fail (0, 255, TRUE);
6545 po_char_or_fail ('}');
6549 /* The expression parser chokes on a trailing !, so we have
6550 to find it first and zap it. */
6553 while (*s && *s != ',')
6558 inst.operands[i].writeback = 1;
6560 po_imm_or_fail (0, 31, TRUE);
6568 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6573 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6578 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6580 if (inst.reloc.exp.X_op == O_symbol)
6582 val = parse_reloc (&str);
6585 inst.error = _("unrecognized relocation suffix");
6588 else if (val != BFD_RELOC_UNUSED)
6590 inst.operands[i].imm = val;
6591 inst.operands[i].hasreloc = 1;
6596 /* Operand for MOVW or MOVT. */
6598 po_misc_or_fail (parse_half (&str));
6601 /* Register or expression. */
6602 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6603 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6605 /* Register or immediate. */
6606 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6607 I0: po_imm_or_fail (0, 0, FALSE); break;
6609 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6611 if (!is_immediate_prefix (*str))
6614 val = parse_fpa_immediate (&str);
6617 /* FPA immediates are encoded as registers 8-15.
6618 parse_fpa_immediate has already applied the offset. */
6619 inst.operands[i].reg = val;
6620 inst.operands[i].isreg = 1;
6623 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6624 I32z: po_imm_or_fail (0, 32, FALSE); break;
6626 /* Two kinds of register. */
6629 struct reg_entry *rege = arm_reg_parse_multi (&str);
6631 || (rege->type != REG_TYPE_MMXWR
6632 && rege->type != REG_TYPE_MMXWC
6633 && rege->type != REG_TYPE_MMXWCG))
6635 inst.error = _("iWMMXt data or control register expected");
6638 inst.operands[i].reg = rege->number;
6639 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6645 struct reg_entry *rege = arm_reg_parse_multi (&str);
6647 || (rege->type != REG_TYPE_MMXWC
6648 && rege->type != REG_TYPE_MMXWCG))
6650 inst.error = _("iWMMXt control register expected");
6653 inst.operands[i].reg = rege->number;
6654 inst.operands[i].isreg = 1;
6659 case OP_CPSF: val = parse_cps_flags (&str); break;
6660 case OP_ENDI: val = parse_endian_specifier (&str); break;
6661 case OP_oROR: val = parse_ror (&str); break;
6662 case OP_COND: val = parse_cond (&str); break;
6663 case OP_oBARRIER_I15:
6664 po_barrier_or_imm (str); break;
6666 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6672 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6673 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6675 inst.error = _("Banked registers are not available with this "
6681 val = parse_psr (&str, op_parse_code == OP_wPSR);
6685 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6688 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6690 if (strncasecmp (str, "APSR_", 5) == 0)
6697 case 'c': found = (found & 1) ? 16 : found | 1; break;
6698 case 'n': found = (found & 2) ? 16 : found | 2; break;
6699 case 'z': found = (found & 4) ? 16 : found | 4; break;
6700 case 'v': found = (found & 8) ? 16 : found | 8; break;
6701 default: found = 16;
6705 inst.operands[i].isvec = 1;
6706 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6707 inst.operands[i].reg = REG_PC;
6714 po_misc_or_fail (parse_tb (&str));
6717 /* Register lists. */
6719 val = parse_reg_list (&str);
6722 inst.operands[1].writeback = 1;
6728 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6732 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6736 /* Allow Q registers too. */
6737 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6742 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6744 inst.operands[i].issingle = 1;
6749 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6754 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6755 &inst.operands[i].vectype);
6758 /* Addressing modes */
6760 po_misc_or_fail (parse_address (&str, i));
6764 po_misc_or_fail_no_backtrack (
6765 parse_address_group_reloc (&str, i, GROUP_LDR));
6769 po_misc_or_fail_no_backtrack (
6770 parse_address_group_reloc (&str, i, GROUP_LDRS));
6774 po_misc_or_fail_no_backtrack (
6775 parse_address_group_reloc (&str, i, GROUP_LDC));
6779 po_misc_or_fail (parse_shifter_operand (&str, i));
6783 po_misc_or_fail_no_backtrack (
6784 parse_shifter_operand_group_reloc (&str, i));
6788 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6792 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6796 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6800 as_fatal (_("unhandled operand code %d"), op_parse_code);
6803 /* Various value-based sanity checks and shared operations. We
6804 do not signal immediate failures for the register constraints;
6805 this allows a syntax error to take precedence. */
6806 switch (op_parse_code)
6814 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6815 inst.error = BAD_PC;
6820 if (inst.operands[i].isreg)
6822 if (inst.operands[i].reg == REG_PC)
6823 inst.error = BAD_PC;
6824 else if (inst.operands[i].reg == REG_SP)
6825 inst.error = BAD_SP;
6830 if (inst.operands[i].isreg
6831 && inst.operands[i].reg == REG_PC
6832 && (inst.operands[i].writeback || thumb))
6833 inst.error = BAD_PC;
6842 case OP_oBARRIER_I15:
6851 inst.operands[i].imm = val;
6858 /* If we get here, this operand was successfully parsed. */
6859 inst.operands[i].present = 1;
6863 inst.error = BAD_ARGS;
6868 /* The parse routine should already have set inst.error, but set a
6869 default here just in case. */
6871 inst.error = _("syntax error");
6875 /* Do not backtrack over a trailing optional argument that
6876 absorbed some text. We will only fail again, with the
6877 'garbage following instruction' error message, which is
6878 probably less helpful than the current one. */
6879 if (backtrack_index == i && backtrack_pos != str
6880 && upat[i+1] == OP_stop)
6883 inst.error = _("syntax error");
6887 /* Try again, skipping the optional argument at backtrack_pos. */
6888 str = backtrack_pos;
6889 inst.error = backtrack_error;
6890 inst.operands[backtrack_index].present = 0;
6891 i = backtrack_index;
6895 /* Check that we have parsed all the arguments. */
6896 if (*str != '\0' && !inst.error)
6897 inst.error = _("garbage following instruction");
6899 return inst.error ? FAIL : SUCCESS;
6902 #undef po_char_or_fail
6903 #undef po_reg_or_fail
6904 #undef po_reg_or_goto
6905 #undef po_imm_or_fail
6906 #undef po_scalar_or_fail
6907 #undef po_barrier_or_imm
6909 /* Shorthand macro for instruction encoding functions issuing errors. */
6910 #define constraint(expr, err) \
6921 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6922 instructions are unpredictable if these registers are used. This
6923 is the BadReg predicate in ARM's Thumb-2 documentation. */
6924 #define reject_bad_reg(reg) \
6926 if (reg == REG_SP || reg == REG_PC) \
6928 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6933 /* If REG is R13 (the stack pointer), warn that its use is
6935 #define warn_deprecated_sp(reg) \
6937 if (warn_on_deprecated && reg == REG_SP) \
6938 as_warn (_("use of r13 is deprecated")); \
6941 /* Functions for operand encoding. ARM, then Thumb. */
6943 #define rotate_left(v, n) (v << n | v >> (32 - n))
6945 /* If VAL can be encoded in the immediate field of an ARM instruction,
6946 return the encoded form. Otherwise, return FAIL. */
6949 encode_arm_immediate (unsigned int val)
6953 for (i = 0; i < 32; i += 2)
6954 if ((a = rotate_left (val, i)) <= 0xff)
6955 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6960 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6961 return the encoded form. Otherwise, return FAIL. */
6963 encode_thumb32_immediate (unsigned int val)
6970 for (i = 1; i <= 24; i++)
6973 if ((val & ~(0xff << i)) == 0)
6974 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6978 if (val == ((a << 16) | a))
6980 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6984 if (val == ((a << 16) | a))
6985 return 0x200 | (a >> 8);
6989 /* Encode a VFP SP or DP register number into inst.instruction. */
6992 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6994 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6997 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
7000 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7003 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7008 first_error (_("D register out of range for selected VFP version"));
7016 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7020 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7024 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7028 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7032 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7036 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7044 /* Encode a <shift> in an ARM-format instruction. The immediate,
7045 if any, is handled by md_apply_fix. */
7047 encode_arm_shift (int i)
7049 if (inst.operands[i].shift_kind == SHIFT_RRX)
7050 inst.instruction |= SHIFT_ROR << 5;
7053 inst.instruction |= inst.operands[i].shift_kind << 5;
7054 if (inst.operands[i].immisreg)
7056 inst.instruction |= SHIFT_BY_REG;
7057 inst.instruction |= inst.operands[i].imm << 8;
7060 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7065 encode_arm_shifter_operand (int i)
7067 if (inst.operands[i].isreg)
7069 inst.instruction |= inst.operands[i].reg;
7070 encode_arm_shift (i);
7074 inst.instruction |= INST_IMMEDIATE;
7075 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7076 inst.instruction |= inst.operands[i].imm;
7080 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
7082 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
7085 Generate an error if the operand is not a register. */
7086 constraint (!inst.operands[i].isreg,
7087 _("Instruction does not support =N addresses"));
7089 inst.instruction |= inst.operands[i].reg << 16;
7091 if (inst.operands[i].preind)
7095 inst.error = _("instruction does not accept preindexed addressing");
7098 inst.instruction |= PRE_INDEX;
7099 if (inst.operands[i].writeback)
7100 inst.instruction |= WRITE_BACK;
7103 else if (inst.operands[i].postind)
7105 gas_assert (inst.operands[i].writeback);
7107 inst.instruction |= WRITE_BACK;
7109 else /* unindexed - only for coprocessor */
7111 inst.error = _("instruction does not accept unindexed addressing");
7115 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7116 && (((inst.instruction & 0x000f0000) >> 16)
7117 == ((inst.instruction & 0x0000f000) >> 12)))
7118 as_warn ((inst.instruction & LOAD_BIT)
7119 ? _("destination register same as write-back base")
7120 : _("source register same as write-back base"));
7123 /* inst.operands[i] was set up by parse_address. Encode it into an
7124 ARM-format mode 2 load or store instruction. If is_t is true,
7125 reject forms that cannot be used with a T instruction (i.e. not
7128 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
7130 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7132 encode_arm_addr_mode_common (i, is_t);
7134 if (inst.operands[i].immisreg)
7136 constraint ((inst.operands[i].imm == REG_PC
7137 || (is_pc && inst.operands[i].writeback)),
7139 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7140 inst.instruction |= inst.operands[i].imm;
7141 if (!inst.operands[i].negative)
7142 inst.instruction |= INDEX_UP;
7143 if (inst.operands[i].shifted)
7145 if (inst.operands[i].shift_kind == SHIFT_RRX)
7146 inst.instruction |= SHIFT_ROR << 5;
7149 inst.instruction |= inst.operands[i].shift_kind << 5;
7150 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7154 else /* immediate offset in inst.reloc */
7156 if (is_pc && !inst.reloc.pc_rel)
7158 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
7160 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7161 cannot use PC in addressing.
7162 PC cannot be used in writeback addressing, either. */
7163 constraint ((is_t || inst.operands[i].writeback),
7166 /* Use of PC in str is deprecated for ARMv7. */
7167 if (warn_on_deprecated
7169 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7170 as_warn (_("use of PC in this instruction is deprecated"));
7173 if (inst.reloc.type == BFD_RELOC_UNUSED)
7175 /* Prefer + for zero encoded value. */
7176 if (!inst.operands[i].negative)
7177 inst.instruction |= INDEX_UP;
7178 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7183 /* inst.operands[i] was set up by parse_address. Encode it into an
7184 ARM-format mode 3 load or store instruction. Reject forms that
7185 cannot be used with such instructions. If is_t is true, reject
7186 forms that cannot be used with a T instruction (i.e. not
7189 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
7191 if (inst.operands[i].immisreg && inst.operands[i].shifted)
7193 inst.error = _("instruction does not accept scaled register index");
7197 encode_arm_addr_mode_common (i, is_t);
7199 if (inst.operands[i].immisreg)
7201 constraint ((inst.operands[i].imm == REG_PC
7202 || inst.operands[i].reg == REG_PC),
7204 inst.instruction |= inst.operands[i].imm;
7205 if (!inst.operands[i].negative)
7206 inst.instruction |= INDEX_UP;
7208 else /* immediate offset in inst.reloc */
7210 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7211 && inst.operands[i].writeback),
7213 inst.instruction |= HWOFFSET_IMM;
7214 if (inst.reloc.type == BFD_RELOC_UNUSED)
7216 /* Prefer + for zero encoded value. */
7217 if (!inst.operands[i].negative)
7218 inst.instruction |= INDEX_UP;
7220 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7225 /* inst.operands[i] was set up by parse_address. Encode it into an
7226 ARM-format instruction. Reject all forms which cannot be encoded
7227 into a coprocessor load/store instruction. If wb_ok is false,
7228 reject use of writeback; if unind_ok is false, reject use of
7229 unindexed addressing. If reloc_override is not 0, use it instead
7230 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7231 (in which case it is preserved). */
7234 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
7236 inst.instruction |= inst.operands[i].reg << 16;
7238 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
7240 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
7242 gas_assert (!inst.operands[i].writeback);
7245 inst.error = _("instruction does not support unindexed addressing");
7248 inst.instruction |= inst.operands[i].imm;
7249 inst.instruction |= INDEX_UP;
7253 if (inst.operands[i].preind)
7254 inst.instruction |= PRE_INDEX;
7256 if (inst.operands[i].writeback)
7258 if (inst.operands[i].reg == REG_PC)
7260 inst.error = _("pc may not be used with write-back");
7265 inst.error = _("instruction does not support writeback");
7268 inst.instruction |= WRITE_BACK;
7272 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
7273 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7274 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7275 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7278 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7280 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7283 /* Prefer + for zero encoded value. */
7284 if (!inst.operands[i].negative)
7285 inst.instruction |= INDEX_UP;
7290 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
7291 Determine whether it can be performed with a move instruction; if
7292 it can, convert inst.instruction to that move instruction and
7293 return TRUE; if it can't, convert inst.instruction to a literal-pool
7294 load and return FALSE. If this is not a valid thing to do in the
7295 current context, set inst.error and return TRUE.
7297 inst.operands[i] describes the destination register. */
7300 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7305 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7309 if ((inst.instruction & tbit) == 0)
7311 inst.error = _("invalid pseudo operation");
7314 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
7316 inst.error = _("constant expression expected");
7319 if (inst.reloc.exp.X_op == O_constant)
7323 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
7325 /* This can be done with a mov(1) instruction. */
7326 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7327 inst.instruction |= inst.reloc.exp.X_add_number;
7333 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7336 /* This can be done with a mov instruction. */
7337 inst.instruction &= LITERAL_MASK;
7338 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7339 inst.instruction |= value & 0xfff;
7343 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7346 /* This can be done with a mvn instruction. */
7347 inst.instruction &= LITERAL_MASK;
7348 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7349 inst.instruction |= value & 0xfff;
7355 if (add_to_lit_pool () == FAIL)
7357 inst.error = _("literal pool insertion failed");
7360 inst.operands[1].reg = REG_PC;
7361 inst.operands[1].isreg = 1;
7362 inst.operands[1].preind = 1;
7363 inst.reloc.pc_rel = 1;
7364 inst.reloc.type = (thumb_p
7365 ? BFD_RELOC_ARM_THUMB_OFFSET
7367 ? BFD_RELOC_ARM_HWLITERAL
7368 : BFD_RELOC_ARM_LITERAL));
7372 /* Functions for instruction encoding, sorted by sub-architecture.
7373 First some generics; their names are taken from the conventional
7374 bit positions for register arguments in ARM format instructions. */
7384 inst.instruction |= inst.operands[0].reg << 12;
7390 inst.instruction |= inst.operands[0].reg << 12;
7391 inst.instruction |= inst.operands[1].reg;
7397 inst.instruction |= inst.operands[0].reg;
7398 inst.instruction |= inst.operands[1].reg << 16;
7404 inst.instruction |= inst.operands[0].reg << 12;
7405 inst.instruction |= inst.operands[1].reg << 16;
7411 inst.instruction |= inst.operands[0].reg << 16;
7412 inst.instruction |= inst.operands[1].reg << 12;
7416 check_obsolete (const arm_feature_set *feature, const char *msg)
7418 if (ARM_CPU_IS_ANY (cpu_variant))
7420 as_warn ("%s", msg);
7423 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
7435 unsigned Rn = inst.operands[2].reg;
7436 /* Enforce restrictions on SWP instruction. */
7437 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
7439 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7440 _("Rn must not overlap other operands"));
7442 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
7444 if (!check_obsolete (&arm_ext_v8,
7445 _("swp{b} use is obsoleted for ARMv8 and later"))
7446 && warn_on_deprecated
7447 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
7448 as_warn (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
7451 inst.instruction |= inst.operands[0].reg << 12;
7452 inst.instruction |= inst.operands[1].reg;
7453 inst.instruction |= Rn << 16;
7459 inst.instruction |= inst.operands[0].reg << 12;
7460 inst.instruction |= inst.operands[1].reg << 16;
7461 inst.instruction |= inst.operands[2].reg;
7467 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7468 constraint (((inst.reloc.exp.X_op != O_constant
7469 && inst.reloc.exp.X_op != O_illegal)
7470 || inst.reloc.exp.X_add_number != 0),
7472 inst.instruction |= inst.operands[0].reg;
7473 inst.instruction |= inst.operands[1].reg << 12;
7474 inst.instruction |= inst.operands[2].reg << 16;
7480 inst.instruction |= inst.operands[0].imm;
7486 inst.instruction |= inst.operands[0].reg << 12;
7487 encode_arm_cp_address (1, TRUE, TRUE, 0);
7490 /* ARM instructions, in alphabetical order by function name (except
7491 that wrapper functions appear immediately after the function they
7494 /* This is a pseudo-op of the form "adr rd, label" to be converted
7495 into a relative address of the form "add rd, pc, #label-.-8". */
7500 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7502 /* Frag hacking will turn this into a sub instruction if the offset turns
7503 out to be negative. */
7504 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7505 inst.reloc.pc_rel = 1;
7506 inst.reloc.exp.X_add_number -= 8;
7509 /* This is a pseudo-op of the form "adrl rd, label" to be converted
7510 into a relative address of the form:
7511 add rd, pc, #low(label-.-8)"
7512 add rd, rd, #high(label-.-8)" */
7517 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7519 /* Frag hacking will turn this into a sub instruction if the offset turns
7520 out to be negative. */
7521 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
7522 inst.reloc.pc_rel = 1;
7523 inst.size = INSN_SIZE * 2;
7524 inst.reloc.exp.X_add_number -= 8;
7530 if (!inst.operands[1].present)
7531 inst.operands[1].reg = inst.operands[0].reg;
7532 inst.instruction |= inst.operands[0].reg << 12;
7533 inst.instruction |= inst.operands[1].reg << 16;
7534 encode_arm_shifter_operand (2);
7540 if (inst.operands[0].present)
7542 constraint ((inst.instruction & 0xf0) != 0x40
7543 && inst.operands[0].imm > 0xf
7544 && inst.operands[0].imm < 0x0,
7545 _("bad barrier type"));
7546 inst.instruction |= inst.operands[0].imm;
7549 inst.instruction |= 0xf;
7555 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7556 constraint (msb > 32, _("bit-field extends past end of register"));
7557 /* The instruction encoding stores the LSB and MSB,
7558 not the LSB and width. */
7559 inst.instruction |= inst.operands[0].reg << 12;
7560 inst.instruction |= inst.operands[1].imm << 7;
7561 inst.instruction |= (msb - 1) << 16;
7569 /* #0 in second position is alternative syntax for bfc, which is
7570 the same instruction but with REG_PC in the Rm field. */
7571 if (!inst.operands[1].isreg)
7572 inst.operands[1].reg = REG_PC;
7574 msb = inst.operands[2].imm + inst.operands[3].imm;
7575 constraint (msb > 32, _("bit-field extends past end of register"));
7576 /* The instruction encoding stores the LSB and MSB,
7577 not the LSB and width. */
7578 inst.instruction |= inst.operands[0].reg << 12;
7579 inst.instruction |= inst.operands[1].reg;
7580 inst.instruction |= inst.operands[2].imm << 7;
7581 inst.instruction |= (msb - 1) << 16;
7587 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7588 _("bit-field extends past end of register"));
7589 inst.instruction |= inst.operands[0].reg << 12;
7590 inst.instruction |= inst.operands[1].reg;
7591 inst.instruction |= inst.operands[2].imm << 7;
7592 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7595 /* ARM V5 breakpoint instruction (argument parse)
7596 BKPT <16 bit unsigned immediate>
7597 Instruction is not conditional.
7598 The bit pattern given in insns[] has the COND_ALWAYS condition,
7599 and it is an error if the caller tried to override that. */
7604 /* Top 12 of 16 bits to bits 19:8. */
7605 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
7607 /* Bottom 4 of 16 bits to bits 3:0. */
7608 inst.instruction |= inst.operands[0].imm & 0xf;
7612 encode_branch (int default_reloc)
7614 if (inst.operands[0].hasreloc)
7616 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7617 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7618 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7619 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7620 ? BFD_RELOC_ARM_PLT32
7621 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
7624 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
7625 inst.reloc.pc_rel = 1;
7632 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7633 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7636 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7643 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7645 if (inst.cond == COND_ALWAYS)
7646 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7648 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7652 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7655 /* ARM V5 branch-link-exchange instruction (argument parse)
7656 BLX <target_addr> ie BLX(1)
7657 BLX{<condition>} <Rm> ie BLX(2)
7658 Unfortunately, there are two different opcodes for this mnemonic.
7659 So, the insns[].value is not used, and the code here zaps values
7660 into inst.instruction.
7661 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
7666 if (inst.operands[0].isreg)
7668 /* Arg is a register; the opcode provided by insns[] is correct.
7669 It is not illegal to do "blx pc", just useless. */
7670 if (inst.operands[0].reg == REG_PC)
7671 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
7673 inst.instruction |= inst.operands[0].reg;
7677 /* Arg is an address; this instruction cannot be executed
7678 conditionally, and the opcode must be adjusted.
7679 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7680 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
7681 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7682 inst.instruction = 0xfa000000;
7683 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
7690 bfd_boolean want_reloc;
7692 if (inst.operands[0].reg == REG_PC)
7693 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
7695 inst.instruction |= inst.operands[0].reg;
7696 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7697 it is for ARMv4t or earlier. */
7698 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7699 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7703 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
7708 inst.reloc.type = BFD_RELOC_ARM_V4BX;
7712 /* ARM v5TEJ. Jump to Jazelle code. */
7717 if (inst.operands[0].reg == REG_PC)
7718 as_tsktsk (_("use of r15 in bxj is not really useful"));
7720 inst.instruction |= inst.operands[0].reg;
7723 /* Co-processor data operation:
7724 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7725 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7729 inst.instruction |= inst.operands[0].reg << 8;
7730 inst.instruction |= inst.operands[1].imm << 20;
7731 inst.instruction |= inst.operands[2].reg << 12;
7732 inst.instruction |= inst.operands[3].reg << 16;
7733 inst.instruction |= inst.operands[4].reg;
7734 inst.instruction |= inst.operands[5].imm << 5;
7740 inst.instruction |= inst.operands[0].reg << 16;
7741 encode_arm_shifter_operand (1);
7744 /* Transfer between coprocessor and ARM registers.
7745 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7750 No special properties. */
7752 struct deprecated_coproc_regs_s
7759 arm_feature_set deprecated;
7760 arm_feature_set obsoleted;
7761 const char *dep_msg;
7762 const char *obs_msg;
7765 #define DEPR_ACCESS_V8 \
7766 N_("This coprocessor register access is deprecated in ARMv8")
7768 /* Table of all deprecated coprocessor registers. */
7769 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
7771 {15, 0, 7, 10, 5, /* CP15DMB. */
7772 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7773 DEPR_ACCESS_V8, NULL},
7774 {15, 0, 7, 10, 4, /* CP15DSB. */
7775 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7776 DEPR_ACCESS_V8, NULL},
7777 {15, 0, 7, 5, 4, /* CP15ISB. */
7778 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7779 DEPR_ACCESS_V8, NULL},
7780 {14, 6, 1, 0, 0, /* TEEHBR. */
7781 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7782 DEPR_ACCESS_V8, NULL},
7783 {14, 6, 0, 0, 0, /* TEECR. */
7784 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7785 DEPR_ACCESS_V8, NULL},
7788 #undef DEPR_ACCESS_V8
7790 static const size_t deprecated_coproc_reg_count =
7791 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
7799 Rd = inst.operands[2].reg;
7802 if (inst.instruction == 0xee000010
7803 || inst.instruction == 0xfe000010)
7805 reject_bad_reg (Rd);
7808 constraint (Rd == REG_SP, BAD_SP);
7813 if (inst.instruction == 0xe000010)
7814 constraint (Rd == REG_PC, BAD_PC);
7817 for (i = 0; i < deprecated_coproc_reg_count; ++i)
7819 const struct deprecated_coproc_regs_s *r =
7820 deprecated_coproc_regs + i;
7822 if (inst.operands[0].reg == r->cp
7823 && inst.operands[1].imm == r->opc1
7824 && inst.operands[3].reg == r->crn
7825 && inst.operands[4].reg == r->crm
7826 && inst.operands[5].imm == r->opc2)
7828 if (!check_obsolete (&r->obsoleted, r->obs_msg)
7829 && warn_on_deprecated
7830 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
7831 as_warn ("%s", r->dep_msg);
7835 inst.instruction |= inst.operands[0].reg << 8;
7836 inst.instruction |= inst.operands[1].imm << 21;
7837 inst.instruction |= Rd << 12;
7838 inst.instruction |= inst.operands[3].reg << 16;
7839 inst.instruction |= inst.operands[4].reg;
7840 inst.instruction |= inst.operands[5].imm << 5;
7843 /* Transfer between coprocessor register and pair of ARM registers.
7844 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7849 Two XScale instructions are special cases of these:
7851 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7852 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
7854 Result unpredictable if Rd or Rn is R15. */
7861 Rd = inst.operands[2].reg;
7862 Rn = inst.operands[3].reg;
7866 reject_bad_reg (Rd);
7867 reject_bad_reg (Rn);
7871 constraint (Rd == REG_PC, BAD_PC);
7872 constraint (Rn == REG_PC, BAD_PC);
7875 inst.instruction |= inst.operands[0].reg << 8;
7876 inst.instruction |= inst.operands[1].imm << 4;
7877 inst.instruction |= Rd << 12;
7878 inst.instruction |= Rn << 16;
7879 inst.instruction |= inst.operands[4].reg;
7885 inst.instruction |= inst.operands[0].imm << 6;
7886 if (inst.operands[1].present)
7888 inst.instruction |= CPSI_MMOD;
7889 inst.instruction |= inst.operands[1].imm;
7896 inst.instruction |= inst.operands[0].imm;
7902 unsigned Rd, Rn, Rm;
7904 Rd = inst.operands[0].reg;
7905 Rn = (inst.operands[1].present
7906 ? inst.operands[1].reg : Rd);
7907 Rm = inst.operands[2].reg;
7909 constraint ((Rd == REG_PC), BAD_PC);
7910 constraint ((Rn == REG_PC), BAD_PC);
7911 constraint ((Rm == REG_PC), BAD_PC);
7913 inst.instruction |= Rd << 16;
7914 inst.instruction |= Rn << 0;
7915 inst.instruction |= Rm << 8;
7921 /* There is no IT instruction in ARM mode. We
7922 process it to do the validation as if in
7923 thumb mode, just in case the code gets
7924 assembled for thumb using the unified syntax. */
7929 set_it_insn_type (IT_INSN);
7930 now_it.mask = (inst.instruction & 0xf) | 0x10;
7931 now_it.cc = inst.operands[0].imm;
7935 /* If there is only one register in the register list,
7936 then return its register number. Otherwise return -1. */
7938 only_one_reg_in_list (int range)
7940 int i = ffs (range) - 1;
7941 return (i > 15 || range != (1 << i)) ? -1 : i;
7945 encode_ldmstm(int from_push_pop_mnem)
7947 int base_reg = inst.operands[0].reg;
7948 int range = inst.operands[1].imm;
7951 inst.instruction |= base_reg << 16;
7952 inst.instruction |= range;
7954 if (inst.operands[1].writeback)
7955 inst.instruction |= LDM_TYPE_2_OR_3;
7957 if (inst.operands[0].writeback)
7959 inst.instruction |= WRITE_BACK;
7960 /* Check for unpredictable uses of writeback. */
7961 if (inst.instruction & LOAD_BIT)
7963 /* Not allowed in LDM type 2. */
7964 if ((inst.instruction & LDM_TYPE_2_OR_3)
7965 && ((range & (1 << REG_PC)) == 0))
7966 as_warn (_("writeback of base register is UNPREDICTABLE"));
7967 /* Only allowed if base reg not in list for other types. */
7968 else if (range & (1 << base_reg))
7969 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7973 /* Not allowed for type 2. */
7974 if (inst.instruction & LDM_TYPE_2_OR_3)
7975 as_warn (_("writeback of base register is UNPREDICTABLE"));
7976 /* Only allowed if base reg not in list, or first in list. */
7977 else if ((range & (1 << base_reg))
7978 && (range & ((1 << base_reg) - 1)))
7979 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7983 /* If PUSH/POP has only one register, then use the A2 encoding. */
7984 one_reg = only_one_reg_in_list (range);
7985 if (from_push_pop_mnem && one_reg >= 0)
7987 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
7989 inst.instruction &= A_COND_MASK;
7990 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
7991 inst.instruction |= one_reg << 12;
7998 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
8001 /* ARMv5TE load-consecutive (argument parse)
8010 constraint (inst.operands[0].reg % 2 != 0,
8011 _("first transfer register must be even"));
8012 constraint (inst.operands[1].present
8013 && inst.operands[1].reg != inst.operands[0].reg + 1,
8014 _("can only transfer two consecutive registers"));
8015 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8016 constraint (!inst.operands[2].isreg, _("'[' expected"));
8018 if (!inst.operands[1].present)
8019 inst.operands[1].reg = inst.operands[0].reg + 1;
8021 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8022 register and the first register written; we have to diagnose
8023 overlap between the base and the second register written here. */
8025 if (inst.operands[2].reg == inst.operands[1].reg
8026 && (inst.operands[2].writeback || inst.operands[2].postind))
8027 as_warn (_("base register written back, and overlaps "
8028 "second transfer register"));
8030 if (!(inst.instruction & V4_STR_BIT))
8032 /* For an index-register load, the index register must not overlap the
8033 destination (even if not write-back). */
8034 if (inst.operands[2].immisreg
8035 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8036 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8037 as_warn (_("index register overlaps transfer register"));
8039 inst.instruction |= inst.operands[0].reg << 12;
8040 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
8046 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8047 || inst.operands[1].postind || inst.operands[1].writeback
8048 || inst.operands[1].immisreg || inst.operands[1].shifted
8049 || inst.operands[1].negative
8050 /* This can arise if the programmer has written
8052 or if they have mistakenly used a register name as the last
8055 It is very difficult to distinguish between these two cases
8056 because "rX" might actually be a label. ie the register
8057 name has been occluded by a symbol of the same name. So we
8058 just generate a general 'bad addressing mode' type error
8059 message and leave it up to the programmer to discover the
8060 true cause and fix their mistake. */
8061 || (inst.operands[1].reg == REG_PC),
8064 constraint (inst.reloc.exp.X_op != O_constant
8065 || inst.reloc.exp.X_add_number != 0,
8066 _("offset must be zero in ARM encoding"));
8068 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8070 inst.instruction |= inst.operands[0].reg << 12;
8071 inst.instruction |= inst.operands[1].reg << 16;
8072 inst.reloc.type = BFD_RELOC_UNUSED;
8078 constraint (inst.operands[0].reg % 2 != 0,
8079 _("even register required"));
8080 constraint (inst.operands[1].present
8081 && inst.operands[1].reg != inst.operands[0].reg + 1,
8082 _("can only load two consecutive registers"));
8083 /* If op 1 were present and equal to PC, this function wouldn't
8084 have been called in the first place. */
8085 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8087 inst.instruction |= inst.operands[0].reg << 12;
8088 inst.instruction |= inst.operands[2].reg << 16;
8091 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8092 which is not a multiple of four is UNPREDICTABLE. */
8094 check_ldr_r15_aligned (void)
8096 constraint (!(inst.operands[1].immisreg)
8097 && (inst.operands[0].reg == REG_PC
8098 && inst.operands[1].reg == REG_PC
8099 && (inst.reloc.exp.X_add_number & 0x3)),
8100 _("ldr to register 15 must be 4-byte alligned"));
8106 inst.instruction |= inst.operands[0].reg << 12;
8107 if (!inst.operands[1].isreg)
8108 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
8110 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
8111 check_ldr_r15_aligned ();
8117 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8119 if (inst.operands[1].preind)
8121 constraint (inst.reloc.exp.X_op != O_constant
8122 || inst.reloc.exp.X_add_number != 0,
8123 _("this instruction requires a post-indexed address"));
8125 inst.operands[1].preind = 0;
8126 inst.operands[1].postind = 1;
8127 inst.operands[1].writeback = 1;
8129 inst.instruction |= inst.operands[0].reg << 12;
8130 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8133 /* Halfword and signed-byte load/store operations. */
8138 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8139 inst.instruction |= inst.operands[0].reg << 12;
8140 if (!inst.operands[1].isreg)
8141 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
8143 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
8149 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8151 if (inst.operands[1].preind)
8153 constraint (inst.reloc.exp.X_op != O_constant
8154 || inst.reloc.exp.X_add_number != 0,
8155 _("this instruction requires a post-indexed address"));
8157 inst.operands[1].preind = 0;
8158 inst.operands[1].postind = 1;
8159 inst.operands[1].writeback = 1;
8161 inst.instruction |= inst.operands[0].reg << 12;
8162 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8165 /* Co-processor register load/store.
8166 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8170 inst.instruction |= inst.operands[0].reg << 8;
8171 inst.instruction |= inst.operands[1].reg << 12;
8172 encode_arm_cp_address (2, TRUE, TRUE, 0);
8178 /* This restriction does not apply to mls (nor to mla in v6 or later). */
8179 if (inst.operands[0].reg == inst.operands[1].reg
8180 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
8181 && !(inst.instruction & 0x00400000))
8182 as_tsktsk (_("Rd and Rm should be different in mla"));
8184 inst.instruction |= inst.operands[0].reg << 16;
8185 inst.instruction |= inst.operands[1].reg;
8186 inst.instruction |= inst.operands[2].reg << 8;
8187 inst.instruction |= inst.operands[3].reg << 12;
8193 inst.instruction |= inst.operands[0].reg << 12;
8194 encode_arm_shifter_operand (1);
8197 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8204 top = (inst.instruction & 0x00400000) != 0;
8205 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8206 _(":lower16: not allowed this instruction"));
8207 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8208 _(":upper16: not allowed instruction"));
8209 inst.instruction |= inst.operands[0].reg << 12;
8210 if (inst.reloc.type == BFD_RELOC_UNUSED)
8212 imm = inst.reloc.exp.X_add_number;
8213 /* The value is in two pieces: 0:11, 16:19. */
8214 inst.instruction |= (imm & 0x00000fff);
8215 inst.instruction |= (imm & 0x0000f000) << 4;
8219 static void do_vfp_nsyn_opcode (const char *);
8222 do_vfp_nsyn_mrs (void)
8224 if (inst.operands[0].isvec)
8226 if (inst.operands[1].reg != 1)
8227 first_error (_("operand 1 must be FPSCR"));
8228 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8229 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8230 do_vfp_nsyn_opcode ("fmstat");
8232 else if (inst.operands[1].isvec)
8233 do_vfp_nsyn_opcode ("fmrx");
8241 do_vfp_nsyn_msr (void)
8243 if (inst.operands[0].isvec)
8244 do_vfp_nsyn_opcode ("fmxr");
8254 unsigned Rt = inst.operands[0].reg;
8256 if (thumb_mode && inst.operands[0].reg == REG_SP)
8258 inst.error = BAD_SP;
8262 /* APSR_ sets isvec. All other refs to PC are illegal. */
8263 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
8265 inst.error = BAD_PC;
8269 switch (inst.operands[1].reg)
8276 inst.instruction |= (inst.operands[1].reg << 16);
8279 first_error (_("operand 1 must be a VFP extension System Register"));
8282 inst.instruction |= (Rt << 12);
8288 unsigned Rt = inst.operands[1].reg;
8291 reject_bad_reg (Rt);
8292 else if (Rt == REG_PC)
8294 inst.error = BAD_PC;
8298 switch (inst.operands[0].reg)
8303 inst.instruction |= (inst.operands[0].reg << 16);
8306 first_error (_("operand 0 must be FPSID or FPSCR pr FPEXC"));
8309 inst.instruction |= (Rt << 12);
8317 if (do_vfp_nsyn_mrs () == SUCCESS)
8320 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8321 inst.instruction |= inst.operands[0].reg << 12;
8323 if (inst.operands[1].isreg)
8325 br = inst.operands[1].reg;
8326 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8327 as_bad (_("bad register for mrs"));
8331 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8332 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8334 _("'APSR', 'CPSR' or 'SPSR' expected"));
8335 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8338 inst.instruction |= br;
8341 /* Two possible forms:
8342 "{C|S}PSR_<field>, Rm",
8343 "{C|S}PSR_f, #expression". */
8348 if (do_vfp_nsyn_msr () == SUCCESS)
8351 inst.instruction |= inst.operands[0].imm;
8352 if (inst.operands[1].isreg)
8353 inst.instruction |= inst.operands[1].reg;
8356 inst.instruction |= INST_IMMEDIATE;
8357 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8358 inst.reloc.pc_rel = 0;
8365 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8367 if (!inst.operands[2].present)
8368 inst.operands[2].reg = inst.operands[0].reg;
8369 inst.instruction |= inst.operands[0].reg << 16;
8370 inst.instruction |= inst.operands[1].reg;
8371 inst.instruction |= inst.operands[2].reg << 8;
8373 if (inst.operands[0].reg == inst.operands[1].reg
8374 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8375 as_tsktsk (_("Rd and Rm should be different in mul"));
8378 /* Long Multiply Parser
8379 UMULL RdLo, RdHi, Rm, Rs
8380 SMULL RdLo, RdHi, Rm, Rs
8381 UMLAL RdLo, RdHi, Rm, Rs
8382 SMLAL RdLo, RdHi, Rm, Rs. */
8387 inst.instruction |= inst.operands[0].reg << 12;
8388 inst.instruction |= inst.operands[1].reg << 16;
8389 inst.instruction |= inst.operands[2].reg;
8390 inst.instruction |= inst.operands[3].reg << 8;
8392 /* rdhi and rdlo must be different. */
8393 if (inst.operands[0].reg == inst.operands[1].reg)
8394 as_tsktsk (_("rdhi and rdlo must be different"));
8396 /* rdhi, rdlo and rm must all be different before armv6. */
8397 if ((inst.operands[0].reg == inst.operands[2].reg
8398 || inst.operands[1].reg == inst.operands[2].reg)
8399 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8400 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8406 if (inst.operands[0].present
8407 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
8409 /* Architectural NOP hints are CPSR sets with no bits selected. */
8410 inst.instruction &= 0xf0000000;
8411 inst.instruction |= 0x0320f000;
8412 if (inst.operands[0].present)
8413 inst.instruction |= inst.operands[0].imm;
8417 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8418 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8419 Condition defaults to COND_ALWAYS.
8420 Error if Rd, Rn or Rm are R15. */
8425 inst.instruction |= inst.operands[0].reg << 12;
8426 inst.instruction |= inst.operands[1].reg << 16;
8427 inst.instruction |= inst.operands[2].reg;
8428 if (inst.operands[3].present)
8429 encode_arm_shift (3);
8432 /* ARM V6 PKHTB (Argument Parse). */
8437 if (!inst.operands[3].present)
8439 /* If the shift specifier is omitted, turn the instruction
8440 into pkhbt rd, rm, rn. */
8441 inst.instruction &= 0xfff00010;
8442 inst.instruction |= inst.operands[0].reg << 12;
8443 inst.instruction |= inst.operands[1].reg;
8444 inst.instruction |= inst.operands[2].reg << 16;
8448 inst.instruction |= inst.operands[0].reg << 12;
8449 inst.instruction |= inst.operands[1].reg << 16;
8450 inst.instruction |= inst.operands[2].reg;
8451 encode_arm_shift (3);
8455 /* ARMv5TE: Preload-Cache
8456 MP Extensions: Preload for write
8460 Syntactically, like LDR with B=1, W=0, L=1. */
8465 constraint (!inst.operands[0].isreg,
8466 _("'[' expected after PLD mnemonic"));
8467 constraint (inst.operands[0].postind,
8468 _("post-indexed expression used in preload instruction"));
8469 constraint (inst.operands[0].writeback,
8470 _("writeback used in preload instruction"));
8471 constraint (!inst.operands[0].preind,
8472 _("unindexed addressing used in preload instruction"));
8473 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8476 /* ARMv7: PLI <addr_mode> */
8480 constraint (!inst.operands[0].isreg,
8481 _("'[' expected after PLI mnemonic"));
8482 constraint (inst.operands[0].postind,
8483 _("post-indexed expression used in preload instruction"));
8484 constraint (inst.operands[0].writeback,
8485 _("writeback used in preload instruction"));
8486 constraint (!inst.operands[0].preind,
8487 _("unindexed addressing used in preload instruction"));
8488 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8489 inst.instruction &= ~PRE_INDEX;
8495 inst.operands[1] = inst.operands[0];
8496 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8497 inst.operands[0].isreg = 1;
8498 inst.operands[0].writeback = 1;
8499 inst.operands[0].reg = REG_SP;
8500 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
8503 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8504 word at the specified address and the following word
8506 Unconditionally executed.
8507 Error if Rn is R15. */
8512 inst.instruction |= inst.operands[0].reg << 16;
8513 if (inst.operands[0].writeback)
8514 inst.instruction |= WRITE_BACK;
8517 /* ARM V6 ssat (argument parse). */
8522 inst.instruction |= inst.operands[0].reg << 12;
8523 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8524 inst.instruction |= inst.operands[2].reg;
8526 if (inst.operands[3].present)
8527 encode_arm_shift (3);
8530 /* ARM V6 usat (argument parse). */
8535 inst.instruction |= inst.operands[0].reg << 12;
8536 inst.instruction |= inst.operands[1].imm << 16;
8537 inst.instruction |= inst.operands[2].reg;
8539 if (inst.operands[3].present)
8540 encode_arm_shift (3);
8543 /* ARM V6 ssat16 (argument parse). */
8548 inst.instruction |= inst.operands[0].reg << 12;
8549 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8550 inst.instruction |= inst.operands[2].reg;
8556 inst.instruction |= inst.operands[0].reg << 12;
8557 inst.instruction |= inst.operands[1].imm << 16;
8558 inst.instruction |= inst.operands[2].reg;
8561 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8562 preserving the other bits.
8564 setend <endian_specifier>, where <endian_specifier> is either
8570 if (warn_on_deprecated
8571 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8572 as_warn (_("setend use is deprecated for ARMv8"));
8574 if (inst.operands[0].imm)
8575 inst.instruction |= 0x200;
8581 unsigned int Rm = (inst.operands[1].present
8582 ? inst.operands[1].reg
8583 : inst.operands[0].reg);
8585 inst.instruction |= inst.operands[0].reg << 12;
8586 inst.instruction |= Rm;
8587 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
8589 inst.instruction |= inst.operands[2].reg << 8;
8590 inst.instruction |= SHIFT_BY_REG;
8591 /* PR 12854: Error on extraneous shifts. */
8592 constraint (inst.operands[2].shifted,
8593 _("extraneous shift as part of operand to shift insn"));
8596 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
8602 inst.reloc.type = BFD_RELOC_ARM_SMC;
8603 inst.reloc.pc_rel = 0;
8609 inst.reloc.type = BFD_RELOC_ARM_HVC;
8610 inst.reloc.pc_rel = 0;
8616 inst.reloc.type = BFD_RELOC_ARM_SWI;
8617 inst.reloc.pc_rel = 0;
8620 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8621 SMLAxy{cond} Rd,Rm,Rs,Rn
8622 SMLAWy{cond} Rd,Rm,Rs,Rn
8623 Error if any register is R15. */
8628 inst.instruction |= inst.operands[0].reg << 16;
8629 inst.instruction |= inst.operands[1].reg;
8630 inst.instruction |= inst.operands[2].reg << 8;
8631 inst.instruction |= inst.operands[3].reg << 12;
8634 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8635 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8636 Error if any register is R15.
8637 Warning if Rdlo == Rdhi. */
8642 inst.instruction |= inst.operands[0].reg << 12;
8643 inst.instruction |= inst.operands[1].reg << 16;
8644 inst.instruction |= inst.operands[2].reg;
8645 inst.instruction |= inst.operands[3].reg << 8;
8647 if (inst.operands[0].reg == inst.operands[1].reg)
8648 as_tsktsk (_("rdhi and rdlo must be different"));
8651 /* ARM V5E (El Segundo) signed-multiply (argument parse)
8652 SMULxy{cond} Rd,Rm,Rs
8653 Error if any register is R15. */
8658 inst.instruction |= inst.operands[0].reg << 16;
8659 inst.instruction |= inst.operands[1].reg;
8660 inst.instruction |= inst.operands[2].reg << 8;
8663 /* ARM V6 srs (argument parse). The variable fields in the encoding are
8664 the same for both ARM and Thumb-2. */
8671 if (inst.operands[0].present)
8673 reg = inst.operands[0].reg;
8674 constraint (reg != REG_SP, _("SRS base register must be r13"));
8679 inst.instruction |= reg << 16;
8680 inst.instruction |= inst.operands[1].imm;
8681 if (inst.operands[0].writeback || inst.operands[1].writeback)
8682 inst.instruction |= WRITE_BACK;
8685 /* ARM V6 strex (argument parse). */
8690 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8691 || inst.operands[2].postind || inst.operands[2].writeback
8692 || inst.operands[2].immisreg || inst.operands[2].shifted
8693 || inst.operands[2].negative
8694 /* See comment in do_ldrex(). */
8695 || (inst.operands[2].reg == REG_PC),
8698 constraint (inst.operands[0].reg == inst.operands[1].reg
8699 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8701 constraint (inst.reloc.exp.X_op != O_constant
8702 || inst.reloc.exp.X_add_number != 0,
8703 _("offset must be zero in ARM encoding"));
8705 inst.instruction |= inst.operands[0].reg << 12;
8706 inst.instruction |= inst.operands[1].reg;
8707 inst.instruction |= inst.operands[2].reg << 16;
8708 inst.reloc.type = BFD_RELOC_UNUSED;
8714 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8715 || inst.operands[2].postind || inst.operands[2].writeback
8716 || inst.operands[2].immisreg || inst.operands[2].shifted
8717 || inst.operands[2].negative,
8720 constraint (inst.operands[0].reg == inst.operands[1].reg
8721 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8729 constraint (inst.operands[1].reg % 2 != 0,
8730 _("even register required"));
8731 constraint (inst.operands[2].present
8732 && inst.operands[2].reg != inst.operands[1].reg + 1,
8733 _("can only store two consecutive registers"));
8734 /* If op 2 were present and equal to PC, this function wouldn't
8735 have been called in the first place. */
8736 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
8738 constraint (inst.operands[0].reg == inst.operands[1].reg
8739 || inst.operands[0].reg == inst.operands[1].reg + 1
8740 || inst.operands[0].reg == inst.operands[3].reg,
8743 inst.instruction |= inst.operands[0].reg << 12;
8744 inst.instruction |= inst.operands[1].reg;
8745 inst.instruction |= inst.operands[3].reg << 16;
8752 constraint (inst.operands[0].reg == inst.operands[1].reg
8753 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8761 constraint (inst.operands[0].reg == inst.operands[1].reg
8762 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8767 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8768 extends it to 32-bits, and adds the result to a value in another
8769 register. You can specify a rotation by 0, 8, 16, or 24 bits
8770 before extracting the 16-bit value.
8771 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8772 Condition defaults to COND_ALWAYS.
8773 Error if any register uses R15. */
8778 inst.instruction |= inst.operands[0].reg << 12;
8779 inst.instruction |= inst.operands[1].reg << 16;
8780 inst.instruction |= inst.operands[2].reg;
8781 inst.instruction |= inst.operands[3].imm << 10;
8786 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8787 Condition defaults to COND_ALWAYS.
8788 Error if any register uses R15. */
8793 inst.instruction |= inst.operands[0].reg << 12;
8794 inst.instruction |= inst.operands[1].reg;
8795 inst.instruction |= inst.operands[2].imm << 10;
8798 /* VFP instructions. In a logical order: SP variant first, monad
8799 before dyad, arithmetic then move then load/store. */
8802 do_vfp_sp_monadic (void)
8804 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8805 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8809 do_vfp_sp_dyadic (void)
8811 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8812 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8813 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8817 do_vfp_sp_compare_z (void)
8819 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8823 do_vfp_dp_sp_cvt (void)
8825 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8826 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8830 do_vfp_sp_dp_cvt (void)
8832 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8833 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8837 do_vfp_reg_from_sp (void)
8839 inst.instruction |= inst.operands[0].reg << 12;
8840 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8844 do_vfp_reg2_from_sp2 (void)
8846 constraint (inst.operands[2].imm != 2,
8847 _("only two consecutive VFP SP registers allowed here"));
8848 inst.instruction |= inst.operands[0].reg << 12;
8849 inst.instruction |= inst.operands[1].reg << 16;
8850 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8854 do_vfp_sp_from_reg (void)
8856 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
8857 inst.instruction |= inst.operands[1].reg << 12;
8861 do_vfp_sp2_from_reg2 (void)
8863 constraint (inst.operands[0].imm != 2,
8864 _("only two consecutive VFP SP registers allowed here"));
8865 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
8866 inst.instruction |= inst.operands[1].reg << 12;
8867 inst.instruction |= inst.operands[2].reg << 16;
8871 do_vfp_sp_ldst (void)
8873 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8874 encode_arm_cp_address (1, FALSE, TRUE, 0);
8878 do_vfp_dp_ldst (void)
8880 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8881 encode_arm_cp_address (1, FALSE, TRUE, 0);
8886 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
8888 if (inst.operands[0].writeback)
8889 inst.instruction |= WRITE_BACK;
8891 constraint (ldstm_type != VFP_LDSTMIA,
8892 _("this addressing mode requires base-register writeback"));
8893 inst.instruction |= inst.operands[0].reg << 16;
8894 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
8895 inst.instruction |= inst.operands[1].imm;
8899 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
8903 if (inst.operands[0].writeback)
8904 inst.instruction |= WRITE_BACK;
8906 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8907 _("this addressing mode requires base-register writeback"));
8909 inst.instruction |= inst.operands[0].reg << 16;
8910 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8912 count = inst.operands[1].imm << 1;
8913 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8916 inst.instruction |= count;
8920 do_vfp_sp_ldstmia (void)
8922 vfp_sp_ldstm (VFP_LDSTMIA);
8926 do_vfp_sp_ldstmdb (void)
8928 vfp_sp_ldstm (VFP_LDSTMDB);
8932 do_vfp_dp_ldstmia (void)
8934 vfp_dp_ldstm (VFP_LDSTMIA);
8938 do_vfp_dp_ldstmdb (void)
8940 vfp_dp_ldstm (VFP_LDSTMDB);
8944 do_vfp_xp_ldstmia (void)
8946 vfp_dp_ldstm (VFP_LDSTMIAX);
8950 do_vfp_xp_ldstmdb (void)
8952 vfp_dp_ldstm (VFP_LDSTMDBX);
8956 do_vfp_dp_rd_rm (void)
8958 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8959 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8963 do_vfp_dp_rn_rd (void)
8965 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8966 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8970 do_vfp_dp_rd_rn (void)
8972 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8973 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8977 do_vfp_dp_rd_rn_rm (void)
8979 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8980 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8981 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8987 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8991 do_vfp_dp_rm_rd_rn (void)
8993 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8994 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8995 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8998 /* VFPv3 instructions. */
9000 do_vfp_sp_const (void)
9002 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9003 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9004 inst.instruction |= (inst.operands[1].imm & 0x0f);
9008 do_vfp_dp_const (void)
9010 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9011 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9012 inst.instruction |= (inst.operands[1].imm & 0x0f);
9016 vfp_conv (int srcsize)
9018 int immbits = srcsize - inst.operands[1].imm;
9020 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9022 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
9023 i.e. immbits must be in range 0 - 16. */
9024 inst.error = _("immediate value out of range, expected range [0, 16]");
9027 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
9029 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
9030 i.e. immbits must be in range 0 - 31. */
9031 inst.error = _("immediate value out of range, expected range [1, 32]");
9035 inst.instruction |= (immbits & 1) << 5;
9036 inst.instruction |= (immbits >> 1);
9040 do_vfp_sp_conv_16 (void)
9042 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9047 do_vfp_dp_conv_16 (void)
9049 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9054 do_vfp_sp_conv_32 (void)
9056 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9061 do_vfp_dp_conv_32 (void)
9063 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9067 /* FPA instructions. Also in a logical order. */
9072 inst.instruction |= inst.operands[0].reg << 16;
9073 inst.instruction |= inst.operands[1].reg;
9077 do_fpa_ldmstm (void)
9079 inst.instruction |= inst.operands[0].reg << 12;
9080 switch (inst.operands[1].imm)
9082 case 1: inst.instruction |= CP_T_X; break;
9083 case 2: inst.instruction |= CP_T_Y; break;
9084 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9089 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9091 /* The instruction specified "ea" or "fd", so we can only accept
9092 [Rn]{!}. The instruction does not really support stacking or
9093 unstacking, so we have to emulate these by setting appropriate
9094 bits and offsets. */
9095 constraint (inst.reloc.exp.X_op != O_constant
9096 || inst.reloc.exp.X_add_number != 0,
9097 _("this instruction does not support indexing"));
9099 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9100 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
9102 if (!(inst.instruction & INDEX_UP))
9103 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
9105 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9107 inst.operands[2].preind = 0;
9108 inst.operands[2].postind = 1;
9112 encode_arm_cp_address (2, TRUE, TRUE, 0);
9115 /* iWMMXt instructions: strictly in alphabetical order. */
9118 do_iwmmxt_tandorc (void)
9120 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9124 do_iwmmxt_textrc (void)
9126 inst.instruction |= inst.operands[0].reg << 12;
9127 inst.instruction |= inst.operands[1].imm;
9131 do_iwmmxt_textrm (void)
9133 inst.instruction |= inst.operands[0].reg << 12;
9134 inst.instruction |= inst.operands[1].reg << 16;
9135 inst.instruction |= inst.operands[2].imm;
9139 do_iwmmxt_tinsr (void)
9141 inst.instruction |= inst.operands[0].reg << 16;
9142 inst.instruction |= inst.operands[1].reg << 12;
9143 inst.instruction |= inst.operands[2].imm;
9147 do_iwmmxt_tmia (void)
9149 inst.instruction |= inst.operands[0].reg << 5;
9150 inst.instruction |= inst.operands[1].reg;
9151 inst.instruction |= inst.operands[2].reg << 12;
9155 do_iwmmxt_waligni (void)
9157 inst.instruction |= inst.operands[0].reg << 12;
9158 inst.instruction |= inst.operands[1].reg << 16;
9159 inst.instruction |= inst.operands[2].reg;
9160 inst.instruction |= inst.operands[3].imm << 20;
9164 do_iwmmxt_wmerge (void)
9166 inst.instruction |= inst.operands[0].reg << 12;
9167 inst.instruction |= inst.operands[1].reg << 16;
9168 inst.instruction |= inst.operands[2].reg;
9169 inst.instruction |= inst.operands[3].imm << 21;
9173 do_iwmmxt_wmov (void)
9175 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9176 inst.instruction |= inst.operands[0].reg << 12;
9177 inst.instruction |= inst.operands[1].reg << 16;
9178 inst.instruction |= inst.operands[1].reg;
9182 do_iwmmxt_wldstbh (void)
9185 inst.instruction |= inst.operands[0].reg << 12;
9187 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9189 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9190 encode_arm_cp_address (1, TRUE, FALSE, reloc);
9194 do_iwmmxt_wldstw (void)
9196 /* RIWR_RIWC clears .isreg for a control register. */
9197 if (!inst.operands[0].isreg)
9199 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9200 inst.instruction |= 0xf0000000;
9203 inst.instruction |= inst.operands[0].reg << 12;
9204 encode_arm_cp_address (1, TRUE, TRUE, 0);
9208 do_iwmmxt_wldstd (void)
9210 inst.instruction |= inst.operands[0].reg << 12;
9211 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9212 && inst.operands[1].immisreg)
9214 inst.instruction &= ~0x1a000ff;
9215 inst.instruction |= (0xf << 28);
9216 if (inst.operands[1].preind)
9217 inst.instruction |= PRE_INDEX;
9218 if (!inst.operands[1].negative)
9219 inst.instruction |= INDEX_UP;
9220 if (inst.operands[1].writeback)
9221 inst.instruction |= WRITE_BACK;
9222 inst.instruction |= inst.operands[1].reg << 16;
9223 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9224 inst.instruction |= inst.operands[1].imm;
9227 encode_arm_cp_address (1, TRUE, FALSE, 0);
9231 do_iwmmxt_wshufh (void)
9233 inst.instruction |= inst.operands[0].reg << 12;
9234 inst.instruction |= inst.operands[1].reg << 16;
9235 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9236 inst.instruction |= (inst.operands[2].imm & 0x0f);
9240 do_iwmmxt_wzero (void)
9242 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9243 inst.instruction |= inst.operands[0].reg;
9244 inst.instruction |= inst.operands[0].reg << 12;
9245 inst.instruction |= inst.operands[0].reg << 16;
9249 do_iwmmxt_wrwrwr_or_imm5 (void)
9251 if (inst.operands[2].isreg)
9254 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9255 _("immediate operand requires iWMMXt2"));
9257 if (inst.operands[2].imm == 0)
9259 switch ((inst.instruction >> 20) & 0xf)
9265 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9266 inst.operands[2].imm = 16;
9267 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9273 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9274 inst.operands[2].imm = 32;
9275 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9282 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9284 wrn = (inst.instruction >> 16) & 0xf;
9285 inst.instruction &= 0xff0fff0f;
9286 inst.instruction |= wrn;
9287 /* Bail out here; the instruction is now assembled. */
9292 /* Map 32 -> 0, etc. */
9293 inst.operands[2].imm &= 0x1f;
9294 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9298 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9299 operations first, then control, shift, and load/store. */
9301 /* Insns like "foo X,Y,Z". */
9304 do_mav_triple (void)
9306 inst.instruction |= inst.operands[0].reg << 16;
9307 inst.instruction |= inst.operands[1].reg;
9308 inst.instruction |= inst.operands[2].reg << 12;
9311 /* Insns like "foo W,X,Y,Z".
9312 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
9317 inst.instruction |= inst.operands[0].reg << 5;
9318 inst.instruction |= inst.operands[1].reg << 12;
9319 inst.instruction |= inst.operands[2].reg << 16;
9320 inst.instruction |= inst.operands[3].reg;
9323 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9327 inst.instruction |= inst.operands[1].reg << 12;
9330 /* Maverick shift immediate instructions.
9331 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9332 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
9337 int imm = inst.operands[2].imm;
9339 inst.instruction |= inst.operands[0].reg << 12;
9340 inst.instruction |= inst.operands[1].reg << 16;
9342 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9343 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9344 Bit 4 should be 0. */
9345 imm = (imm & 0xf) | ((imm & 0x70) << 1);
9347 inst.instruction |= imm;
9350 /* XScale instructions. Also sorted arithmetic before move. */
9352 /* Xscale multiply-accumulate (argument parse)
9355 MIAxycc acc0,Rm,Rs. */
9360 inst.instruction |= inst.operands[1].reg;
9361 inst.instruction |= inst.operands[2].reg << 12;
9364 /* Xscale move-accumulator-register (argument parse)
9366 MARcc acc0,RdLo,RdHi. */
9371 inst.instruction |= inst.operands[1].reg << 12;
9372 inst.instruction |= inst.operands[2].reg << 16;
9375 /* Xscale move-register-accumulator (argument parse)
9377 MRAcc RdLo,RdHi,acc0. */
9382 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9383 inst.instruction |= inst.operands[0].reg << 12;
9384 inst.instruction |= inst.operands[1].reg << 16;
9387 /* Encoding functions relevant only to Thumb. */
9389 /* inst.operands[i] is a shifted-register operand; encode
9390 it into inst.instruction in the format used by Thumb32. */
9393 encode_thumb32_shifted_operand (int i)
9395 unsigned int value = inst.reloc.exp.X_add_number;
9396 unsigned int shift = inst.operands[i].shift_kind;
9398 constraint (inst.operands[i].immisreg,
9399 _("shift by register not allowed in thumb mode"));
9400 inst.instruction |= inst.operands[i].reg;
9401 if (shift == SHIFT_RRX)
9402 inst.instruction |= SHIFT_ROR << 4;
9405 constraint (inst.reloc.exp.X_op != O_constant,
9406 _("expression too complex"));
9408 constraint (value > 32
9409 || (value == 32 && (shift == SHIFT_LSL
9410 || shift == SHIFT_ROR)),
9411 _("shift expression is too large"));
9415 else if (value == 32)
9418 inst.instruction |= shift << 4;
9419 inst.instruction |= (value & 0x1c) << 10;
9420 inst.instruction |= (value & 0x03) << 6;
9425 /* inst.operands[i] was set up by parse_address. Encode it into a
9426 Thumb32 format load or store instruction. Reject forms that cannot
9427 be used with such instructions. If is_t is true, reject forms that
9428 cannot be used with a T instruction; if is_d is true, reject forms
9429 that cannot be used with a D instruction. If it is a store insn,
9433 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9435 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
9437 constraint (!inst.operands[i].isreg,
9438 _("Instruction does not support =N addresses"));
9440 inst.instruction |= inst.operands[i].reg << 16;
9441 if (inst.operands[i].immisreg)
9443 constraint (is_pc, BAD_PC_ADDRESSING);
9444 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9445 constraint (inst.operands[i].negative,
9446 _("Thumb does not support negative register indexing"));
9447 constraint (inst.operands[i].postind,
9448 _("Thumb does not support register post-indexing"));
9449 constraint (inst.operands[i].writeback,
9450 _("Thumb does not support register indexing with writeback"));
9451 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9452 _("Thumb supports only LSL in shifted register indexing"));
9454 inst.instruction |= inst.operands[i].imm;
9455 if (inst.operands[i].shifted)
9457 constraint (inst.reloc.exp.X_op != O_constant,
9458 _("expression too complex"));
9459 constraint (inst.reloc.exp.X_add_number < 0
9460 || inst.reloc.exp.X_add_number > 3,
9461 _("shift out of range"));
9462 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9464 inst.reloc.type = BFD_RELOC_UNUSED;
9466 else if (inst.operands[i].preind)
9468 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
9469 constraint (is_t && inst.operands[i].writeback,
9470 _("cannot use writeback with this instruction"));
9471 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9472 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
9476 inst.instruction |= 0x01000000;
9477 if (inst.operands[i].writeback)
9478 inst.instruction |= 0x00200000;
9482 inst.instruction |= 0x00000c00;
9483 if (inst.operands[i].writeback)
9484 inst.instruction |= 0x00000100;
9486 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9488 else if (inst.operands[i].postind)
9490 gas_assert (inst.operands[i].writeback);
9491 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9492 constraint (is_t, _("cannot use post-indexing with this instruction"));
9495 inst.instruction |= 0x00200000;
9497 inst.instruction |= 0x00000900;
9498 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9500 else /* unindexed - only for coprocessor */
9501 inst.error = _("instruction does not accept unindexed addressing");
9504 /* Table of Thumb instructions which exist in both 16- and 32-bit
9505 encodings (the latter only in post-V6T2 cores). The index is the
9506 value used in the insns table below. When there is more than one
9507 possible 16-bit encoding for the instruction, this table always
9509 Also contains several pseudo-instructions used during relaxation. */
9510 #define T16_32_TAB \
9511 X(_adc, 4140, eb400000), \
9512 X(_adcs, 4140, eb500000), \
9513 X(_add, 1c00, eb000000), \
9514 X(_adds, 1c00, eb100000), \
9515 X(_addi, 0000, f1000000), \
9516 X(_addis, 0000, f1100000), \
9517 X(_add_pc,000f, f20f0000), \
9518 X(_add_sp,000d, f10d0000), \
9519 X(_adr, 000f, f20f0000), \
9520 X(_and, 4000, ea000000), \
9521 X(_ands, 4000, ea100000), \
9522 X(_asr, 1000, fa40f000), \
9523 X(_asrs, 1000, fa50f000), \
9524 X(_b, e000, f000b000), \
9525 X(_bcond, d000, f0008000), \
9526 X(_bic, 4380, ea200000), \
9527 X(_bics, 4380, ea300000), \
9528 X(_cmn, 42c0, eb100f00), \
9529 X(_cmp, 2800, ebb00f00), \
9530 X(_cpsie, b660, f3af8400), \
9531 X(_cpsid, b670, f3af8600), \
9532 X(_cpy, 4600, ea4f0000), \
9533 X(_dec_sp,80dd, f1ad0d00), \
9534 X(_eor, 4040, ea800000), \
9535 X(_eors, 4040, ea900000), \
9536 X(_inc_sp,00dd, f10d0d00), \
9537 X(_ldmia, c800, e8900000), \
9538 X(_ldr, 6800, f8500000), \
9539 X(_ldrb, 7800, f8100000), \
9540 X(_ldrh, 8800, f8300000), \
9541 X(_ldrsb, 5600, f9100000), \
9542 X(_ldrsh, 5e00, f9300000), \
9543 X(_ldr_pc,4800, f85f0000), \
9544 X(_ldr_pc2,4800, f85f0000), \
9545 X(_ldr_sp,9800, f85d0000), \
9546 X(_lsl, 0000, fa00f000), \
9547 X(_lsls, 0000, fa10f000), \
9548 X(_lsr, 0800, fa20f000), \
9549 X(_lsrs, 0800, fa30f000), \
9550 X(_mov, 2000, ea4f0000), \
9551 X(_movs, 2000, ea5f0000), \
9552 X(_mul, 4340, fb00f000), \
9553 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9554 X(_mvn, 43c0, ea6f0000), \
9555 X(_mvns, 43c0, ea7f0000), \
9556 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9557 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9558 X(_orr, 4300, ea400000), \
9559 X(_orrs, 4300, ea500000), \
9560 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9561 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9562 X(_rev, ba00, fa90f080), \
9563 X(_rev16, ba40, fa90f090), \
9564 X(_revsh, bac0, fa90f0b0), \
9565 X(_ror, 41c0, fa60f000), \
9566 X(_rors, 41c0, fa70f000), \
9567 X(_sbc, 4180, eb600000), \
9568 X(_sbcs, 4180, eb700000), \
9569 X(_stmia, c000, e8800000), \
9570 X(_str, 6000, f8400000), \
9571 X(_strb, 7000, f8000000), \
9572 X(_strh, 8000, f8200000), \
9573 X(_str_sp,9000, f84d0000), \
9574 X(_sub, 1e00, eba00000), \
9575 X(_subs, 1e00, ebb00000), \
9576 X(_subi, 8000, f1a00000), \
9577 X(_subis, 8000, f1b00000), \
9578 X(_sxtb, b240, fa4ff080), \
9579 X(_sxth, b200, fa0ff080), \
9580 X(_tst, 4200, ea100f00), \
9581 X(_uxtb, b2c0, fa5ff080), \
9582 X(_uxth, b280, fa1ff080), \
9583 X(_nop, bf00, f3af8000), \
9584 X(_yield, bf10, f3af8001), \
9585 X(_wfe, bf20, f3af8002), \
9586 X(_wfi, bf30, f3af8003), \
9587 X(_sev, bf40, f3af8004), \
9588 X(_sevl, bf50, f3af8005)
9590 /* To catch errors in encoding functions, the codes are all offset by
9591 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9592 as 16-bit instructions. */
9593 #define X(a,b,c) T_MNEM##a
9594 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9597 #define X(a,b,c) 0x##b
9598 static const unsigned short thumb_op16[] = { T16_32_TAB };
9599 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9602 #define X(a,b,c) 0x##c
9603 static const unsigned int thumb_op32[] = { T16_32_TAB };
9604 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9605 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
9609 /* Thumb instruction encoders, in alphabetical order. */
9614 do_t_add_sub_w (void)
9618 Rd = inst.operands[0].reg;
9619 Rn = inst.operands[1].reg;
9621 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9622 is the SP-{plus,minus}-immediate form of the instruction. */
9624 constraint (Rd == REG_PC, BAD_PC);
9626 reject_bad_reg (Rd);
9628 inst.instruction |= (Rn << 16) | (Rd << 8);
9629 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9632 /* Parse an add or subtract instruction. We get here with inst.instruction
9633 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9640 Rd = inst.operands[0].reg;
9641 Rs = (inst.operands[1].present
9642 ? inst.operands[1].reg /* Rd, Rs, foo */
9643 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9646 set_it_insn_type_last ();
9654 flags = (inst.instruction == T_MNEM_adds
9655 || inst.instruction == T_MNEM_subs);
9657 narrow = !in_it_block ();
9659 narrow = in_it_block ();
9660 if (!inst.operands[2].isreg)
9664 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9666 add = (inst.instruction == T_MNEM_add
9667 || inst.instruction == T_MNEM_adds);
9669 if (inst.size_req != 4)
9671 /* Attempt to use a narrow opcode, with relaxation if
9673 if (Rd == REG_SP && Rs == REG_SP && !flags)
9674 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9675 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9676 opcode = T_MNEM_add_sp;
9677 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9678 opcode = T_MNEM_add_pc;
9679 else if (Rd <= 7 && Rs <= 7 && narrow)
9682 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9684 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9688 inst.instruction = THUMB_OP16(opcode);
9689 inst.instruction |= (Rd << 4) | Rs;
9690 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9691 if (inst.size_req != 2)
9692 inst.relax = opcode;
9695 constraint (inst.size_req == 2, BAD_HIREG);
9697 if (inst.size_req == 4
9698 || (inst.size_req != 2 && !opcode))
9702 constraint (add, BAD_PC);
9703 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9704 _("only SUBS PC, LR, #const allowed"));
9705 constraint (inst.reloc.exp.X_op != O_constant,
9706 _("expression too complex"));
9707 constraint (inst.reloc.exp.X_add_number < 0
9708 || inst.reloc.exp.X_add_number > 0xff,
9709 _("immediate value out of range"));
9710 inst.instruction = T2_SUBS_PC_LR
9711 | inst.reloc.exp.X_add_number;
9712 inst.reloc.type = BFD_RELOC_UNUSED;
9715 else if (Rs == REG_PC)
9717 /* Always use addw/subw. */
9718 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9719 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9723 inst.instruction = THUMB_OP32 (inst.instruction);
9724 inst.instruction = (inst.instruction & 0xe1ffffff)
9727 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9729 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9731 inst.instruction |= Rd << 8;
9732 inst.instruction |= Rs << 16;
9737 unsigned int value = inst.reloc.exp.X_add_number;
9738 unsigned int shift = inst.operands[2].shift_kind;
9740 Rn = inst.operands[2].reg;
9741 /* See if we can do this with a 16-bit instruction. */
9742 if (!inst.operands[2].shifted && inst.size_req != 4)
9744 if (Rd > 7 || Rs > 7 || Rn > 7)
9749 inst.instruction = ((inst.instruction == T_MNEM_adds
9750 || inst.instruction == T_MNEM_add)
9753 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9757 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
9759 /* Thumb-1 cores (except v6-M) require at least one high
9760 register in a narrow non flag setting add. */
9761 if (Rd > 7 || Rn > 7
9762 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9763 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
9770 inst.instruction = T_OPCODE_ADD_HI;
9771 inst.instruction |= (Rd & 8) << 4;
9772 inst.instruction |= (Rd & 7);
9773 inst.instruction |= Rn << 3;
9779 constraint (Rd == REG_PC, BAD_PC);
9780 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9781 constraint (Rs == REG_PC, BAD_PC);
9782 reject_bad_reg (Rn);
9784 /* If we get here, it can't be done in 16 bits. */
9785 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9786 _("shift must be constant"));
9787 inst.instruction = THUMB_OP32 (inst.instruction);
9788 inst.instruction |= Rd << 8;
9789 inst.instruction |= Rs << 16;
9790 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
9791 _("shift value over 3 not allowed in thumb mode"));
9792 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
9793 _("only LSL shift allowed in thumb mode"));
9794 encode_thumb32_shifted_operand (2);
9799 constraint (inst.instruction == T_MNEM_adds
9800 || inst.instruction == T_MNEM_subs,
9803 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
9805 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9806 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9809 inst.instruction = (inst.instruction == T_MNEM_add
9811 inst.instruction |= (Rd << 4) | Rs;
9812 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9816 Rn = inst.operands[2].reg;
9817 constraint (inst.operands[2].shifted, _("unshifted register required"));
9819 /* We now have Rd, Rs, and Rn set to registers. */
9820 if (Rd > 7 || Rs > 7 || Rn > 7)
9822 /* Can't do this for SUB. */
9823 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9824 inst.instruction = T_OPCODE_ADD_HI;
9825 inst.instruction |= (Rd & 8) << 4;
9826 inst.instruction |= (Rd & 7);
9828 inst.instruction |= Rn << 3;
9830 inst.instruction |= Rs << 3;
9832 constraint (1, _("dest must overlap one source register"));
9836 inst.instruction = (inst.instruction == T_MNEM_add
9837 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9838 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9848 Rd = inst.operands[0].reg;
9849 reject_bad_reg (Rd);
9851 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
9853 /* Defer to section relaxation. */
9854 inst.relax = inst.instruction;
9855 inst.instruction = THUMB_OP16 (inst.instruction);
9856 inst.instruction |= Rd << 4;
9858 else if (unified_syntax && inst.size_req != 2)
9860 /* Generate a 32-bit opcode. */
9861 inst.instruction = THUMB_OP32 (inst.instruction);
9862 inst.instruction |= Rd << 8;
9863 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9864 inst.reloc.pc_rel = 1;
9868 /* Generate a 16-bit opcode. */
9869 inst.instruction = THUMB_OP16 (inst.instruction);
9870 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9871 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9872 inst.reloc.pc_rel = 1;
9874 inst.instruction |= Rd << 4;
9878 /* Arithmetic instructions for which there is just one 16-bit
9879 instruction encoding, and it allows only two low registers.
9880 For maximal compatibility with ARM syntax, we allow three register
9881 operands even when Thumb-32 instructions are not available, as long
9882 as the first two are identical. For instance, both "sbc r0,r1" and
9883 "sbc r0,r0,r1" are allowed. */
9889 Rd = inst.operands[0].reg;
9890 Rs = (inst.operands[1].present
9891 ? inst.operands[1].reg /* Rd, Rs, foo */
9892 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9893 Rn = inst.operands[2].reg;
9895 reject_bad_reg (Rd);
9896 reject_bad_reg (Rs);
9897 if (inst.operands[2].isreg)
9898 reject_bad_reg (Rn);
9902 if (!inst.operands[2].isreg)
9904 /* For an immediate, we always generate a 32-bit opcode;
9905 section relaxation will shrink it later if possible. */
9906 inst.instruction = THUMB_OP32 (inst.instruction);
9907 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9908 inst.instruction |= Rd << 8;
9909 inst.instruction |= Rs << 16;
9910 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9916 /* See if we can do this with a 16-bit instruction. */
9917 if (THUMB_SETS_FLAGS (inst.instruction))
9918 narrow = !in_it_block ();
9920 narrow = in_it_block ();
9922 if (Rd > 7 || Rn > 7 || Rs > 7)
9924 if (inst.operands[2].shifted)
9926 if (inst.size_req == 4)
9932 inst.instruction = THUMB_OP16 (inst.instruction);
9933 inst.instruction |= Rd;
9934 inst.instruction |= Rn << 3;
9938 /* If we get here, it can't be done in 16 bits. */
9939 constraint (inst.operands[2].shifted
9940 && inst.operands[2].immisreg,
9941 _("shift must be constant"));
9942 inst.instruction = THUMB_OP32 (inst.instruction);
9943 inst.instruction |= Rd << 8;
9944 inst.instruction |= Rs << 16;
9945 encode_thumb32_shifted_operand (2);
9950 /* On its face this is a lie - the instruction does set the
9951 flags. However, the only supported mnemonic in this mode
9953 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9955 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9956 _("unshifted register required"));
9957 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9958 constraint (Rd != Rs,
9959 _("dest and source1 must be the same register"));
9961 inst.instruction = THUMB_OP16 (inst.instruction);
9962 inst.instruction |= Rd;
9963 inst.instruction |= Rn << 3;
9967 /* Similarly, but for instructions where the arithmetic operation is
9968 commutative, so we can allow either of them to be different from
9969 the destination operand in a 16-bit instruction. For instance, all
9970 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9977 Rd = inst.operands[0].reg;
9978 Rs = (inst.operands[1].present
9979 ? inst.operands[1].reg /* Rd, Rs, foo */
9980 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9981 Rn = inst.operands[2].reg;
9983 reject_bad_reg (Rd);
9984 reject_bad_reg (Rs);
9985 if (inst.operands[2].isreg)
9986 reject_bad_reg (Rn);
9990 if (!inst.operands[2].isreg)
9992 /* For an immediate, we always generate a 32-bit opcode;
9993 section relaxation will shrink it later if possible. */
9994 inst.instruction = THUMB_OP32 (inst.instruction);
9995 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9996 inst.instruction |= Rd << 8;
9997 inst.instruction |= Rs << 16;
9998 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10002 bfd_boolean narrow;
10004 /* See if we can do this with a 16-bit instruction. */
10005 if (THUMB_SETS_FLAGS (inst.instruction))
10006 narrow = !in_it_block ();
10008 narrow = in_it_block ();
10010 if (Rd > 7 || Rn > 7 || Rs > 7)
10012 if (inst.operands[2].shifted)
10014 if (inst.size_req == 4)
10021 inst.instruction = THUMB_OP16 (inst.instruction);
10022 inst.instruction |= Rd;
10023 inst.instruction |= Rn << 3;
10028 inst.instruction = THUMB_OP16 (inst.instruction);
10029 inst.instruction |= Rd;
10030 inst.instruction |= Rs << 3;
10035 /* If we get here, it can't be done in 16 bits. */
10036 constraint (inst.operands[2].shifted
10037 && inst.operands[2].immisreg,
10038 _("shift must be constant"));
10039 inst.instruction = THUMB_OP32 (inst.instruction);
10040 inst.instruction |= Rd << 8;
10041 inst.instruction |= Rs << 16;
10042 encode_thumb32_shifted_operand (2);
10047 /* On its face this is a lie - the instruction does set the
10048 flags. However, the only supported mnemonic in this mode
10049 says it doesn't. */
10050 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10052 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10053 _("unshifted register required"));
10054 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10056 inst.instruction = THUMB_OP16 (inst.instruction);
10057 inst.instruction |= Rd;
10060 inst.instruction |= Rn << 3;
10062 inst.instruction |= Rs << 3;
10064 constraint (1, _("dest must overlap one source register"));
10069 do_t_barrier (void)
10071 if (inst.operands[0].present)
10073 constraint ((inst.instruction & 0xf0) != 0x40
10074 && inst.operands[0].imm > 0xf
10075 && inst.operands[0].imm < 0x0,
10076 _("bad barrier type"));
10077 inst.instruction |= inst.operands[0].imm;
10080 inst.instruction |= 0xf;
10087 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10088 constraint (msb > 32, _("bit-field extends past end of register"));
10089 /* The instruction encoding stores the LSB and MSB,
10090 not the LSB and width. */
10091 Rd = inst.operands[0].reg;
10092 reject_bad_reg (Rd);
10093 inst.instruction |= Rd << 8;
10094 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10095 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10096 inst.instruction |= msb - 1;
10105 Rd = inst.operands[0].reg;
10106 reject_bad_reg (Rd);
10108 /* #0 in second position is alternative syntax for bfc, which is
10109 the same instruction but with REG_PC in the Rm field. */
10110 if (!inst.operands[1].isreg)
10114 Rn = inst.operands[1].reg;
10115 reject_bad_reg (Rn);
10118 msb = inst.operands[2].imm + inst.operands[3].imm;
10119 constraint (msb > 32, _("bit-field extends past end of register"));
10120 /* The instruction encoding stores the LSB and MSB,
10121 not the LSB and width. */
10122 inst.instruction |= Rd << 8;
10123 inst.instruction |= Rn << 16;
10124 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10125 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10126 inst.instruction |= msb - 1;
10134 Rd = inst.operands[0].reg;
10135 Rn = inst.operands[1].reg;
10137 reject_bad_reg (Rd);
10138 reject_bad_reg (Rn);
10140 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10141 _("bit-field extends past end of register"));
10142 inst.instruction |= Rd << 8;
10143 inst.instruction |= Rn << 16;
10144 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10145 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10146 inst.instruction |= inst.operands[3].imm - 1;
10149 /* ARM V5 Thumb BLX (argument parse)
10150 BLX <target_addr> which is BLX(1)
10151 BLX <Rm> which is BLX(2)
10152 Unfortunately, there are two different opcodes for this mnemonic.
10153 So, the insns[].value is not used, and the code here zaps values
10154 into inst.instruction.
10156 ??? How to take advantage of the additional two bits of displacement
10157 available in Thumb32 mode? Need new relocation? */
10162 set_it_insn_type_last ();
10164 if (inst.operands[0].isreg)
10166 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10167 /* We have a register, so this is BLX(2). */
10168 inst.instruction |= inst.operands[0].reg << 3;
10172 /* No register. This must be BLX(1). */
10173 inst.instruction = 0xf000e800;
10174 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
10186 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10188 if (in_it_block ())
10190 /* Conditional branches inside IT blocks are encoded as unconditional
10192 cond = COND_ALWAYS;
10197 if (cond != COND_ALWAYS)
10198 opcode = T_MNEM_bcond;
10200 opcode = inst.instruction;
10203 && (inst.size_req == 4
10204 || (inst.size_req != 2
10205 && (inst.operands[0].hasreloc
10206 || inst.reloc.exp.X_op == O_constant))))
10208 inst.instruction = THUMB_OP32(opcode);
10209 if (cond == COND_ALWAYS)
10210 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
10213 gas_assert (cond != 0xF);
10214 inst.instruction |= cond << 22;
10215 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
10220 inst.instruction = THUMB_OP16(opcode);
10221 if (cond == COND_ALWAYS)
10222 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
10225 inst.instruction |= cond << 8;
10226 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
10228 /* Allow section relaxation. */
10229 if (unified_syntax && inst.size_req != 2)
10230 inst.relax = opcode;
10232 inst.reloc.type = reloc;
10233 inst.reloc.pc_rel = 1;
10236 /* Actually do the work for Thumb state bkpt and hlt. The only difference
10237 between the two is the maximum immediate allowed - which is passed in
10240 do_t_bkpt_hlt1 (int range)
10242 constraint (inst.cond != COND_ALWAYS,
10243 _("instruction is always unconditional"));
10244 if (inst.operands[0].present)
10246 constraint (inst.operands[0].imm > range,
10247 _("immediate value out of range"));
10248 inst.instruction |= inst.operands[0].imm;
10251 set_it_insn_type (NEUTRAL_IT_INSN);
10257 do_t_bkpt_hlt1 (63);
10263 do_t_bkpt_hlt1 (255);
10267 do_t_branch23 (void)
10269 set_it_insn_type_last ();
10270 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
10272 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10273 this file. We used to simply ignore the PLT reloc type here --
10274 the branch encoding is now needed to deal with TLSCALL relocs.
10275 So if we see a PLT reloc now, put it back to how it used to be to
10276 keep the preexisting behaviour. */
10277 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10278 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
10280 #if defined(OBJ_COFF)
10281 /* If the destination of the branch is a defined symbol which does not have
10282 the THUMB_FUNC attribute, then we must be calling a function which has
10283 the (interfacearm) attribute. We look for the Thumb entry point to that
10284 function and change the branch to refer to that function instead. */
10285 if ( inst.reloc.exp.X_op == O_symbol
10286 && inst.reloc.exp.X_add_symbol != NULL
10287 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10288 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10289 inst.reloc.exp.X_add_symbol =
10290 find_real_start (inst.reloc.exp.X_add_symbol);
10297 set_it_insn_type_last ();
10298 inst.instruction |= inst.operands[0].reg << 3;
10299 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10300 should cause the alignment to be checked once it is known. This is
10301 because BX PC only works if the instruction is word aligned. */
10309 set_it_insn_type_last ();
10310 Rm = inst.operands[0].reg;
10311 reject_bad_reg (Rm);
10312 inst.instruction |= Rm << 16;
10321 Rd = inst.operands[0].reg;
10322 Rm = inst.operands[1].reg;
10324 reject_bad_reg (Rd);
10325 reject_bad_reg (Rm);
10327 inst.instruction |= Rd << 8;
10328 inst.instruction |= Rm << 16;
10329 inst.instruction |= Rm;
10335 set_it_insn_type (OUTSIDE_IT_INSN);
10336 inst.instruction |= inst.operands[0].imm;
10342 set_it_insn_type (OUTSIDE_IT_INSN);
10344 && (inst.operands[1].present || inst.size_req == 4)
10345 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
10347 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10348 inst.instruction = 0xf3af8000;
10349 inst.instruction |= imod << 9;
10350 inst.instruction |= inst.operands[0].imm << 5;
10351 if (inst.operands[1].present)
10352 inst.instruction |= 0x100 | inst.operands[1].imm;
10356 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10357 && (inst.operands[0].imm & 4),
10358 _("selected processor does not support 'A' form "
10359 "of this instruction"));
10360 constraint (inst.operands[1].present || inst.size_req == 4,
10361 _("Thumb does not support the 2-argument "
10362 "form of this instruction"));
10363 inst.instruction |= inst.operands[0].imm;
10367 /* THUMB CPY instruction (argument parse). */
10372 if (inst.size_req == 4)
10374 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10375 inst.instruction |= inst.operands[0].reg << 8;
10376 inst.instruction |= inst.operands[1].reg;
10380 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10381 inst.instruction |= (inst.operands[0].reg & 0x7);
10382 inst.instruction |= inst.operands[1].reg << 3;
10389 set_it_insn_type (OUTSIDE_IT_INSN);
10390 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10391 inst.instruction |= inst.operands[0].reg;
10392 inst.reloc.pc_rel = 1;
10393 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10399 inst.instruction |= inst.operands[0].imm;
10405 unsigned Rd, Rn, Rm;
10407 Rd = inst.operands[0].reg;
10408 Rn = (inst.operands[1].present
10409 ? inst.operands[1].reg : Rd);
10410 Rm = inst.operands[2].reg;
10412 reject_bad_reg (Rd);
10413 reject_bad_reg (Rn);
10414 reject_bad_reg (Rm);
10416 inst.instruction |= Rd << 8;
10417 inst.instruction |= Rn << 16;
10418 inst.instruction |= Rm;
10424 if (unified_syntax && inst.size_req == 4)
10425 inst.instruction = THUMB_OP32 (inst.instruction);
10427 inst.instruction = THUMB_OP16 (inst.instruction);
10433 unsigned int cond = inst.operands[0].imm;
10435 set_it_insn_type (IT_INSN);
10436 now_it.mask = (inst.instruction & 0xf) | 0x10;
10438 now_it.warn_deprecated = FALSE;
10440 /* If the condition is a negative condition, invert the mask. */
10441 if ((cond & 0x1) == 0x0)
10443 unsigned int mask = inst.instruction & 0x000f;
10445 if ((mask & 0x7) == 0)
10447 /* No conversion needed. */
10448 now_it.block_length = 1;
10450 else if ((mask & 0x3) == 0)
10453 now_it.block_length = 2;
10455 else if ((mask & 0x1) == 0)
10458 now_it.block_length = 3;
10463 now_it.block_length = 4;
10466 inst.instruction &= 0xfff0;
10467 inst.instruction |= mask;
10470 inst.instruction |= cond << 4;
10473 /* Helper function used for both push/pop and ldm/stm. */
10475 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10479 load = (inst.instruction & (1 << 20)) != 0;
10481 if (mask & (1 << 13))
10482 inst.error = _("SP not allowed in register list");
10484 if ((mask & (1 << base)) != 0
10486 inst.error = _("having the base register in the register list when "
10487 "using write back is UNPREDICTABLE");
10491 if (mask & (1 << 15))
10493 if (mask & (1 << 14))
10494 inst.error = _("LR and PC should not both be in register list");
10496 set_it_insn_type_last ();
10501 if (mask & (1 << 15))
10502 inst.error = _("PC not allowed in register list");
10505 if ((mask & (mask - 1)) == 0)
10507 /* Single register transfers implemented as str/ldr. */
10510 if (inst.instruction & (1 << 23))
10511 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10513 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10517 if (inst.instruction & (1 << 23))
10518 inst.instruction = 0x00800000; /* ia -> [base] */
10520 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10523 inst.instruction |= 0xf8400000;
10525 inst.instruction |= 0x00100000;
10527 mask = ffs (mask) - 1;
10530 else if (writeback)
10531 inst.instruction |= WRITE_BACK;
10533 inst.instruction |= mask;
10534 inst.instruction |= base << 16;
10540 /* This really doesn't seem worth it. */
10541 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10542 _("expression too complex"));
10543 constraint (inst.operands[1].writeback,
10544 _("Thumb load/store multiple does not support {reglist}^"));
10546 if (unified_syntax)
10548 bfd_boolean narrow;
10552 /* See if we can use a 16-bit instruction. */
10553 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10554 && inst.size_req != 4
10555 && !(inst.operands[1].imm & ~0xff))
10557 mask = 1 << inst.operands[0].reg;
10559 if (inst.operands[0].reg <= 7)
10561 if (inst.instruction == T_MNEM_stmia
10562 ? inst.operands[0].writeback
10563 : (inst.operands[0].writeback
10564 == !(inst.operands[1].imm & mask)))
10566 if (inst.instruction == T_MNEM_stmia
10567 && (inst.operands[1].imm & mask)
10568 && (inst.operands[1].imm & (mask - 1)))
10569 as_warn (_("value stored for r%d is UNKNOWN"),
10570 inst.operands[0].reg);
10572 inst.instruction = THUMB_OP16 (inst.instruction);
10573 inst.instruction |= inst.operands[0].reg << 8;
10574 inst.instruction |= inst.operands[1].imm;
10577 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10579 /* This means 1 register in reg list one of 3 situations:
10580 1. Instruction is stmia, but without writeback.
10581 2. lmdia without writeback, but with Rn not in
10583 3. ldmia with writeback, but with Rn in reglist.
10584 Case 3 is UNPREDICTABLE behaviour, so we handle
10585 case 1 and 2 which can be converted into a 16-bit
10586 str or ldr. The SP cases are handled below. */
10587 unsigned long opcode;
10588 /* First, record an error for Case 3. */
10589 if (inst.operands[1].imm & mask
10590 && inst.operands[0].writeback)
10592 _("having the base register in the register list when "
10593 "using write back is UNPREDICTABLE");
10595 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
10597 inst.instruction = THUMB_OP16 (opcode);
10598 inst.instruction |= inst.operands[0].reg << 3;
10599 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10603 else if (inst.operands[0] .reg == REG_SP)
10605 if (inst.operands[0].writeback)
10608 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10609 ? T_MNEM_push : T_MNEM_pop);
10610 inst.instruction |= inst.operands[1].imm;
10613 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10616 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10617 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10618 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10626 if (inst.instruction < 0xffff)
10627 inst.instruction = THUMB_OP32 (inst.instruction);
10629 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10630 inst.operands[0].writeback);
10635 constraint (inst.operands[0].reg > 7
10636 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
10637 constraint (inst.instruction != T_MNEM_ldmia
10638 && inst.instruction != T_MNEM_stmia,
10639 _("Thumb-2 instruction only valid in unified syntax"));
10640 if (inst.instruction == T_MNEM_stmia)
10642 if (!inst.operands[0].writeback)
10643 as_warn (_("this instruction will write back the base register"));
10644 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10645 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
10646 as_warn (_("value stored for r%d is UNKNOWN"),
10647 inst.operands[0].reg);
10651 if (!inst.operands[0].writeback
10652 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10653 as_warn (_("this instruction will write back the base register"));
10654 else if (inst.operands[0].writeback
10655 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10656 as_warn (_("this instruction will not write back the base register"));
10659 inst.instruction = THUMB_OP16 (inst.instruction);
10660 inst.instruction |= inst.operands[0].reg << 8;
10661 inst.instruction |= inst.operands[1].imm;
10668 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10669 || inst.operands[1].postind || inst.operands[1].writeback
10670 || inst.operands[1].immisreg || inst.operands[1].shifted
10671 || inst.operands[1].negative,
10674 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10676 inst.instruction |= inst.operands[0].reg << 12;
10677 inst.instruction |= inst.operands[1].reg << 16;
10678 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10684 if (!inst.operands[1].present)
10686 constraint (inst.operands[0].reg == REG_LR,
10687 _("r14 not allowed as first register "
10688 "when second register is omitted"));
10689 inst.operands[1].reg = inst.operands[0].reg + 1;
10691 constraint (inst.operands[0].reg == inst.operands[1].reg,
10694 inst.instruction |= inst.operands[0].reg << 12;
10695 inst.instruction |= inst.operands[1].reg << 8;
10696 inst.instruction |= inst.operands[2].reg << 16;
10702 unsigned long opcode;
10705 if (inst.operands[0].isreg
10706 && !inst.operands[0].preind
10707 && inst.operands[0].reg == REG_PC)
10708 set_it_insn_type_last ();
10710 opcode = inst.instruction;
10711 if (unified_syntax)
10713 if (!inst.operands[1].isreg)
10715 if (opcode <= 0xffff)
10716 inst.instruction = THUMB_OP32 (opcode);
10717 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10720 if (inst.operands[1].isreg
10721 && !inst.operands[1].writeback
10722 && !inst.operands[1].shifted && !inst.operands[1].postind
10723 && !inst.operands[1].negative && inst.operands[0].reg <= 7
10724 && opcode <= 0xffff
10725 && inst.size_req != 4)
10727 /* Insn may have a 16-bit form. */
10728 Rn = inst.operands[1].reg;
10729 if (inst.operands[1].immisreg)
10731 inst.instruction = THUMB_OP16 (opcode);
10733 if (Rn <= 7 && inst.operands[1].imm <= 7)
10735 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10736 reject_bad_reg (inst.operands[1].imm);
10738 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10739 && opcode != T_MNEM_ldrsb)
10740 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10741 || (Rn == REG_SP && opcode == T_MNEM_str))
10748 if (inst.reloc.pc_rel)
10749 opcode = T_MNEM_ldr_pc2;
10751 opcode = T_MNEM_ldr_pc;
10755 if (opcode == T_MNEM_ldr)
10756 opcode = T_MNEM_ldr_sp;
10758 opcode = T_MNEM_str_sp;
10760 inst.instruction = inst.operands[0].reg << 8;
10764 inst.instruction = inst.operands[0].reg;
10765 inst.instruction |= inst.operands[1].reg << 3;
10767 inst.instruction |= THUMB_OP16 (opcode);
10768 if (inst.size_req == 2)
10769 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10771 inst.relax = opcode;
10775 /* Definitely a 32-bit variant. */
10777 /* Warning for Erratum 752419. */
10778 if (opcode == T_MNEM_ldr
10779 && inst.operands[0].reg == REG_SP
10780 && inst.operands[1].writeback == 1
10781 && !inst.operands[1].immisreg)
10783 if (no_cpu_selected ()
10784 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10785 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10786 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10787 as_warn (_("This instruction may be unpredictable "
10788 "if executed on M-profile cores "
10789 "with interrupts enabled."));
10792 /* Do some validations regarding addressing modes. */
10793 if (inst.operands[1].immisreg)
10794 reject_bad_reg (inst.operands[1].imm);
10796 constraint (inst.operands[1].writeback == 1
10797 && inst.operands[0].reg == inst.operands[1].reg,
10800 inst.instruction = THUMB_OP32 (opcode);
10801 inst.instruction |= inst.operands[0].reg << 12;
10802 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
10803 check_ldr_r15_aligned ();
10807 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10809 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
10811 /* Only [Rn,Rm] is acceptable. */
10812 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10813 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10814 || inst.operands[1].postind || inst.operands[1].shifted
10815 || inst.operands[1].negative,
10816 _("Thumb does not support this addressing mode"));
10817 inst.instruction = THUMB_OP16 (inst.instruction);
10821 inst.instruction = THUMB_OP16 (inst.instruction);
10822 if (!inst.operands[1].isreg)
10823 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10826 constraint (!inst.operands[1].preind
10827 || inst.operands[1].shifted
10828 || inst.operands[1].writeback,
10829 _("Thumb does not support this addressing mode"));
10830 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
10832 constraint (inst.instruction & 0x0600,
10833 _("byte or halfword not valid for base register"));
10834 constraint (inst.operands[1].reg == REG_PC
10835 && !(inst.instruction & THUMB_LOAD_BIT),
10836 _("r15 based store not allowed"));
10837 constraint (inst.operands[1].immisreg,
10838 _("invalid base register for register offset"));
10840 if (inst.operands[1].reg == REG_PC)
10841 inst.instruction = T_OPCODE_LDR_PC;
10842 else if (inst.instruction & THUMB_LOAD_BIT)
10843 inst.instruction = T_OPCODE_LDR_SP;
10845 inst.instruction = T_OPCODE_STR_SP;
10847 inst.instruction |= inst.operands[0].reg << 8;
10848 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10852 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10853 if (!inst.operands[1].immisreg)
10855 /* Immediate offset. */
10856 inst.instruction |= inst.operands[0].reg;
10857 inst.instruction |= inst.operands[1].reg << 3;
10858 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10862 /* Register offset. */
10863 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10864 constraint (inst.operands[1].negative,
10865 _("Thumb does not support this addressing mode"));
10868 switch (inst.instruction)
10870 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10871 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10872 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10873 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10874 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10875 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10876 case 0x5600 /* ldrsb */:
10877 case 0x5e00 /* ldrsh */: break;
10881 inst.instruction |= inst.operands[0].reg;
10882 inst.instruction |= inst.operands[1].reg << 3;
10883 inst.instruction |= inst.operands[1].imm << 6;
10889 if (!inst.operands[1].present)
10891 inst.operands[1].reg = inst.operands[0].reg + 1;
10892 constraint (inst.operands[0].reg == REG_LR,
10893 _("r14 not allowed here"));
10894 constraint (inst.operands[0].reg == REG_R12,
10895 _("r12 not allowed here"));
10898 if (inst.operands[2].writeback
10899 && (inst.operands[0].reg == inst.operands[2].reg
10900 || inst.operands[1].reg == inst.operands[2].reg))
10901 as_warn (_("base register written back, and overlaps "
10902 "one of transfer registers"));
10904 inst.instruction |= inst.operands[0].reg << 12;
10905 inst.instruction |= inst.operands[1].reg << 8;
10906 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
10912 inst.instruction |= inst.operands[0].reg << 12;
10913 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10919 unsigned Rd, Rn, Rm, Ra;
10921 Rd = inst.operands[0].reg;
10922 Rn = inst.operands[1].reg;
10923 Rm = inst.operands[2].reg;
10924 Ra = inst.operands[3].reg;
10926 reject_bad_reg (Rd);
10927 reject_bad_reg (Rn);
10928 reject_bad_reg (Rm);
10929 reject_bad_reg (Ra);
10931 inst.instruction |= Rd << 8;
10932 inst.instruction |= Rn << 16;
10933 inst.instruction |= Rm;
10934 inst.instruction |= Ra << 12;
10940 unsigned RdLo, RdHi, Rn, Rm;
10942 RdLo = inst.operands[0].reg;
10943 RdHi = inst.operands[1].reg;
10944 Rn = inst.operands[2].reg;
10945 Rm = inst.operands[3].reg;
10947 reject_bad_reg (RdLo);
10948 reject_bad_reg (RdHi);
10949 reject_bad_reg (Rn);
10950 reject_bad_reg (Rm);
10952 inst.instruction |= RdLo << 12;
10953 inst.instruction |= RdHi << 8;
10954 inst.instruction |= Rn << 16;
10955 inst.instruction |= Rm;
10959 do_t_mov_cmp (void)
10963 Rn = inst.operands[0].reg;
10964 Rm = inst.operands[1].reg;
10967 set_it_insn_type_last ();
10969 if (unified_syntax)
10971 int r0off = (inst.instruction == T_MNEM_mov
10972 || inst.instruction == T_MNEM_movs) ? 8 : 16;
10973 unsigned long opcode;
10974 bfd_boolean narrow;
10975 bfd_boolean low_regs;
10977 low_regs = (Rn <= 7 && Rm <= 7);
10978 opcode = inst.instruction;
10979 if (in_it_block ())
10980 narrow = opcode != T_MNEM_movs;
10982 narrow = opcode != T_MNEM_movs || low_regs;
10983 if (inst.size_req == 4
10984 || inst.operands[1].shifted)
10987 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10988 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10989 && !inst.operands[1].shifted
10993 inst.instruction = T2_SUBS_PC_LR;
10997 if (opcode == T_MNEM_cmp)
10999 constraint (Rn == REG_PC, BAD_PC);
11002 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11004 warn_deprecated_sp (Rm);
11005 /* R15 was documented as a valid choice for Rm in ARMv6,
11006 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11007 tools reject R15, so we do too. */
11008 constraint (Rm == REG_PC, BAD_PC);
11011 reject_bad_reg (Rm);
11013 else if (opcode == T_MNEM_mov
11014 || opcode == T_MNEM_movs)
11016 if (inst.operands[1].isreg)
11018 if (opcode == T_MNEM_movs)
11020 reject_bad_reg (Rn);
11021 reject_bad_reg (Rm);
11025 /* This is mov.n. */
11026 if ((Rn == REG_SP || Rn == REG_PC)
11027 && (Rm == REG_SP || Rm == REG_PC))
11029 as_warn (_("Use of r%u as a source register is "
11030 "deprecated when r%u is the destination "
11031 "register."), Rm, Rn);
11036 /* This is mov.w. */
11037 constraint (Rn == REG_PC, BAD_PC);
11038 constraint (Rm == REG_PC, BAD_PC);
11039 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11043 reject_bad_reg (Rn);
11046 if (!inst.operands[1].isreg)
11048 /* Immediate operand. */
11049 if (!in_it_block () && opcode == T_MNEM_mov)
11051 if (low_regs && narrow)
11053 inst.instruction = THUMB_OP16 (opcode);
11054 inst.instruction |= Rn << 8;
11055 if (inst.size_req == 2)
11056 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11058 inst.relax = opcode;
11062 inst.instruction = THUMB_OP32 (inst.instruction);
11063 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11064 inst.instruction |= Rn << r0off;
11065 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11068 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11069 && (inst.instruction == T_MNEM_mov
11070 || inst.instruction == T_MNEM_movs))
11072 /* Register shifts are encoded as separate shift instructions. */
11073 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11075 if (in_it_block ())
11080 if (inst.size_req == 4)
11083 if (!low_regs || inst.operands[1].imm > 7)
11089 switch (inst.operands[1].shift_kind)
11092 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11095 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11098 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11101 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11107 inst.instruction = opcode;
11110 inst.instruction |= Rn;
11111 inst.instruction |= inst.operands[1].imm << 3;
11116 inst.instruction |= CONDS_BIT;
11118 inst.instruction |= Rn << 8;
11119 inst.instruction |= Rm << 16;
11120 inst.instruction |= inst.operands[1].imm;
11125 /* Some mov with immediate shift have narrow variants.
11126 Register shifts are handled above. */
11127 if (low_regs && inst.operands[1].shifted
11128 && (inst.instruction == T_MNEM_mov
11129 || inst.instruction == T_MNEM_movs))
11131 if (in_it_block ())
11132 narrow = (inst.instruction == T_MNEM_mov);
11134 narrow = (inst.instruction == T_MNEM_movs);
11139 switch (inst.operands[1].shift_kind)
11141 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11142 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11143 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11144 default: narrow = FALSE; break;
11150 inst.instruction |= Rn;
11151 inst.instruction |= Rm << 3;
11152 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11156 inst.instruction = THUMB_OP32 (inst.instruction);
11157 inst.instruction |= Rn << r0off;
11158 encode_thumb32_shifted_operand (1);
11162 switch (inst.instruction)
11165 /* In v4t or v5t a move of two lowregs produces unpredictable
11166 results. Don't allow this. */
11169 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11170 "MOV Rd, Rs with two low registers is not "
11171 "permitted on this architecture");
11172 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
11176 inst.instruction = T_OPCODE_MOV_HR;
11177 inst.instruction |= (Rn & 0x8) << 4;
11178 inst.instruction |= (Rn & 0x7);
11179 inst.instruction |= Rm << 3;
11183 /* We know we have low registers at this point.
11184 Generate LSLS Rd, Rs, #0. */
11185 inst.instruction = T_OPCODE_LSL_I;
11186 inst.instruction |= Rn;
11187 inst.instruction |= Rm << 3;
11193 inst.instruction = T_OPCODE_CMP_LR;
11194 inst.instruction |= Rn;
11195 inst.instruction |= Rm << 3;
11199 inst.instruction = T_OPCODE_CMP_HR;
11200 inst.instruction |= (Rn & 0x8) << 4;
11201 inst.instruction |= (Rn & 0x7);
11202 inst.instruction |= Rm << 3;
11209 inst.instruction = THUMB_OP16 (inst.instruction);
11211 /* PR 10443: Do not silently ignore shifted operands. */
11212 constraint (inst.operands[1].shifted,
11213 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11215 if (inst.operands[1].isreg)
11217 if (Rn < 8 && Rm < 8)
11219 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11220 since a MOV instruction produces unpredictable results. */
11221 if (inst.instruction == T_OPCODE_MOV_I8)
11222 inst.instruction = T_OPCODE_ADD_I3;
11224 inst.instruction = T_OPCODE_CMP_LR;
11226 inst.instruction |= Rn;
11227 inst.instruction |= Rm << 3;
11231 if (inst.instruction == T_OPCODE_MOV_I8)
11232 inst.instruction = T_OPCODE_MOV_HR;
11234 inst.instruction = T_OPCODE_CMP_HR;
11240 constraint (Rn > 7,
11241 _("only lo regs allowed with immediate"));
11242 inst.instruction |= Rn << 8;
11243 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11254 top = (inst.instruction & 0x00800000) != 0;
11255 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11257 constraint (top, _(":lower16: not allowed this instruction"));
11258 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11260 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11262 constraint (!top, _(":upper16: not allowed this instruction"));
11263 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11266 Rd = inst.operands[0].reg;
11267 reject_bad_reg (Rd);
11269 inst.instruction |= Rd << 8;
11270 if (inst.reloc.type == BFD_RELOC_UNUSED)
11272 imm = inst.reloc.exp.X_add_number;
11273 inst.instruction |= (imm & 0xf000) << 4;
11274 inst.instruction |= (imm & 0x0800) << 15;
11275 inst.instruction |= (imm & 0x0700) << 4;
11276 inst.instruction |= (imm & 0x00ff);
11281 do_t_mvn_tst (void)
11285 Rn = inst.operands[0].reg;
11286 Rm = inst.operands[1].reg;
11288 if (inst.instruction == T_MNEM_cmp
11289 || inst.instruction == T_MNEM_cmn)
11290 constraint (Rn == REG_PC, BAD_PC);
11292 reject_bad_reg (Rn);
11293 reject_bad_reg (Rm);
11295 if (unified_syntax)
11297 int r0off = (inst.instruction == T_MNEM_mvn
11298 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
11299 bfd_boolean narrow;
11301 if (inst.size_req == 4
11302 || inst.instruction > 0xffff
11303 || inst.operands[1].shifted
11304 || Rn > 7 || Rm > 7)
11306 else if (inst.instruction == T_MNEM_cmn)
11308 else if (THUMB_SETS_FLAGS (inst.instruction))
11309 narrow = !in_it_block ();
11311 narrow = in_it_block ();
11313 if (!inst.operands[1].isreg)
11315 /* For an immediate, we always generate a 32-bit opcode;
11316 section relaxation will shrink it later if possible. */
11317 if (inst.instruction < 0xffff)
11318 inst.instruction = THUMB_OP32 (inst.instruction);
11319 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11320 inst.instruction |= Rn << r0off;
11321 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11325 /* See if we can do this with a 16-bit instruction. */
11328 inst.instruction = THUMB_OP16 (inst.instruction);
11329 inst.instruction |= Rn;
11330 inst.instruction |= Rm << 3;
11334 constraint (inst.operands[1].shifted
11335 && inst.operands[1].immisreg,
11336 _("shift must be constant"));
11337 if (inst.instruction < 0xffff)
11338 inst.instruction = THUMB_OP32 (inst.instruction);
11339 inst.instruction |= Rn << r0off;
11340 encode_thumb32_shifted_operand (1);
11346 constraint (inst.instruction > 0xffff
11347 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11348 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11349 _("unshifted register required"));
11350 constraint (Rn > 7 || Rm > 7,
11353 inst.instruction = THUMB_OP16 (inst.instruction);
11354 inst.instruction |= Rn;
11355 inst.instruction |= Rm << 3;
11364 if (do_vfp_nsyn_mrs () == SUCCESS)
11367 Rd = inst.operands[0].reg;
11368 reject_bad_reg (Rd);
11369 inst.instruction |= Rd << 8;
11371 if (inst.operands[1].isreg)
11373 unsigned br = inst.operands[1].reg;
11374 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11375 as_bad (_("bad register for mrs"));
11377 inst.instruction |= br & (0xf << 16);
11378 inst.instruction |= (br & 0x300) >> 4;
11379 inst.instruction |= (br & SPSR_BIT) >> 2;
11383 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11385 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11387 /* PR gas/12698: The constraint is only applied for m_profile.
11388 If the user has specified -march=all, we want to ignore it as
11389 we are building for any CPU type, including non-m variants. */
11390 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11391 constraint ((flags != 0) && m_profile, _("selected processor does "
11392 "not support requested special purpose register"));
11395 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11397 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11398 _("'APSR', 'CPSR' or 'SPSR' expected"));
11400 inst.instruction |= (flags & SPSR_BIT) >> 2;
11401 inst.instruction |= inst.operands[1].imm & 0xff;
11402 inst.instruction |= 0xf0000;
11412 if (do_vfp_nsyn_msr () == SUCCESS)
11415 constraint (!inst.operands[1].isreg,
11416 _("Thumb encoding does not support an immediate here"));
11418 if (inst.operands[0].isreg)
11419 flags = (int)(inst.operands[0].reg);
11421 flags = inst.operands[0].imm;
11423 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11425 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11427 /* PR gas/12698: The constraint is only applied for m_profile.
11428 If the user has specified -march=all, we want to ignore it as
11429 we are building for any CPU type, including non-m variants. */
11430 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11431 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11432 && (bits & ~(PSR_s | PSR_f)) != 0)
11433 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11434 && bits != PSR_f)) && m_profile,
11435 _("selected processor does not support requested special "
11436 "purpose register"));
11439 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11440 "requested special purpose register"));
11442 Rn = inst.operands[1].reg;
11443 reject_bad_reg (Rn);
11445 inst.instruction |= (flags & SPSR_BIT) >> 2;
11446 inst.instruction |= (flags & 0xf0000) >> 8;
11447 inst.instruction |= (flags & 0x300) >> 4;
11448 inst.instruction |= (flags & 0xff);
11449 inst.instruction |= Rn << 16;
11455 bfd_boolean narrow;
11456 unsigned Rd, Rn, Rm;
11458 if (!inst.operands[2].present)
11459 inst.operands[2].reg = inst.operands[0].reg;
11461 Rd = inst.operands[0].reg;
11462 Rn = inst.operands[1].reg;
11463 Rm = inst.operands[2].reg;
11465 if (unified_syntax)
11467 if (inst.size_req == 4
11473 else if (inst.instruction == T_MNEM_muls)
11474 narrow = !in_it_block ();
11476 narrow = in_it_block ();
11480 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
11481 constraint (Rn > 7 || Rm > 7,
11488 /* 16-bit MULS/Conditional MUL. */
11489 inst.instruction = THUMB_OP16 (inst.instruction);
11490 inst.instruction |= Rd;
11493 inst.instruction |= Rm << 3;
11495 inst.instruction |= Rn << 3;
11497 constraint (1, _("dest must overlap one source register"));
11501 constraint (inst.instruction != T_MNEM_mul,
11502 _("Thumb-2 MUL must not set flags"));
11504 inst.instruction = THUMB_OP32 (inst.instruction);
11505 inst.instruction |= Rd << 8;
11506 inst.instruction |= Rn << 16;
11507 inst.instruction |= Rm << 0;
11509 reject_bad_reg (Rd);
11510 reject_bad_reg (Rn);
11511 reject_bad_reg (Rm);
11518 unsigned RdLo, RdHi, Rn, Rm;
11520 RdLo = inst.operands[0].reg;
11521 RdHi = inst.operands[1].reg;
11522 Rn = inst.operands[2].reg;
11523 Rm = inst.operands[3].reg;
11525 reject_bad_reg (RdLo);
11526 reject_bad_reg (RdHi);
11527 reject_bad_reg (Rn);
11528 reject_bad_reg (Rm);
11530 inst.instruction |= RdLo << 12;
11531 inst.instruction |= RdHi << 8;
11532 inst.instruction |= Rn << 16;
11533 inst.instruction |= Rm;
11536 as_tsktsk (_("rdhi and rdlo must be different"));
11542 set_it_insn_type (NEUTRAL_IT_INSN);
11544 if (unified_syntax)
11546 if (inst.size_req == 4 || inst.operands[0].imm > 15)
11548 inst.instruction = THUMB_OP32 (inst.instruction);
11549 inst.instruction |= inst.operands[0].imm;
11553 /* PR9722: Check for Thumb2 availability before
11554 generating a thumb2 nop instruction. */
11555 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
11557 inst.instruction = THUMB_OP16 (inst.instruction);
11558 inst.instruction |= inst.operands[0].imm << 4;
11561 inst.instruction = 0x46c0;
11566 constraint (inst.operands[0].present,
11567 _("Thumb does not support NOP with hints"));
11568 inst.instruction = 0x46c0;
11575 if (unified_syntax)
11577 bfd_boolean narrow;
11579 if (THUMB_SETS_FLAGS (inst.instruction))
11580 narrow = !in_it_block ();
11582 narrow = in_it_block ();
11583 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11585 if (inst.size_req == 4)
11590 inst.instruction = THUMB_OP32 (inst.instruction);
11591 inst.instruction |= inst.operands[0].reg << 8;
11592 inst.instruction |= inst.operands[1].reg << 16;
11596 inst.instruction = THUMB_OP16 (inst.instruction);
11597 inst.instruction |= inst.operands[0].reg;
11598 inst.instruction |= inst.operands[1].reg << 3;
11603 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11605 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11607 inst.instruction = THUMB_OP16 (inst.instruction);
11608 inst.instruction |= inst.operands[0].reg;
11609 inst.instruction |= inst.operands[1].reg << 3;
11618 Rd = inst.operands[0].reg;
11619 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11621 reject_bad_reg (Rd);
11622 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11623 reject_bad_reg (Rn);
11625 inst.instruction |= Rd << 8;
11626 inst.instruction |= Rn << 16;
11628 if (!inst.operands[2].isreg)
11630 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11631 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11637 Rm = inst.operands[2].reg;
11638 reject_bad_reg (Rm);
11640 constraint (inst.operands[2].shifted
11641 && inst.operands[2].immisreg,
11642 _("shift must be constant"));
11643 encode_thumb32_shifted_operand (2);
11650 unsigned Rd, Rn, Rm;
11652 Rd = inst.operands[0].reg;
11653 Rn = inst.operands[1].reg;
11654 Rm = inst.operands[2].reg;
11656 reject_bad_reg (Rd);
11657 reject_bad_reg (Rn);
11658 reject_bad_reg (Rm);
11660 inst.instruction |= Rd << 8;
11661 inst.instruction |= Rn << 16;
11662 inst.instruction |= Rm;
11663 if (inst.operands[3].present)
11665 unsigned int val = inst.reloc.exp.X_add_number;
11666 constraint (inst.reloc.exp.X_op != O_constant,
11667 _("expression too complex"));
11668 inst.instruction |= (val & 0x1c) << 10;
11669 inst.instruction |= (val & 0x03) << 6;
11676 if (!inst.operands[3].present)
11680 inst.instruction &= ~0x00000020;
11682 /* PR 10168. Swap the Rm and Rn registers. */
11683 Rtmp = inst.operands[1].reg;
11684 inst.operands[1].reg = inst.operands[2].reg;
11685 inst.operands[2].reg = Rtmp;
11693 if (inst.operands[0].immisreg)
11694 reject_bad_reg (inst.operands[0].imm);
11696 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11700 do_t_push_pop (void)
11704 constraint (inst.operands[0].writeback,
11705 _("push/pop do not support {reglist}^"));
11706 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11707 _("expression too complex"));
11709 mask = inst.operands[0].imm;
11710 if ((mask & ~0xff) == 0)
11711 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
11712 else if ((inst.instruction == T_MNEM_push
11713 && (mask & ~0xff) == 1 << REG_LR)
11714 || (inst.instruction == T_MNEM_pop
11715 && (mask & ~0xff) == 1 << REG_PC))
11717 inst.instruction = THUMB_OP16 (inst.instruction);
11718 inst.instruction |= THUMB_PP_PC_LR;
11719 inst.instruction |= mask & 0xff;
11721 else if (unified_syntax)
11723 inst.instruction = THUMB_OP32 (inst.instruction);
11724 encode_thumb2_ldmstm (13, mask, TRUE);
11728 inst.error = _("invalid register list to push/pop instruction");
11738 Rd = inst.operands[0].reg;
11739 Rm = inst.operands[1].reg;
11741 reject_bad_reg (Rd);
11742 reject_bad_reg (Rm);
11744 inst.instruction |= Rd << 8;
11745 inst.instruction |= Rm << 16;
11746 inst.instruction |= Rm;
11754 Rd = inst.operands[0].reg;
11755 Rm = inst.operands[1].reg;
11757 reject_bad_reg (Rd);
11758 reject_bad_reg (Rm);
11760 if (Rd <= 7 && Rm <= 7
11761 && inst.size_req != 4)
11763 inst.instruction = THUMB_OP16 (inst.instruction);
11764 inst.instruction |= Rd;
11765 inst.instruction |= Rm << 3;
11767 else if (unified_syntax)
11769 inst.instruction = THUMB_OP32 (inst.instruction);
11770 inst.instruction |= Rd << 8;
11771 inst.instruction |= Rm << 16;
11772 inst.instruction |= Rm;
11775 inst.error = BAD_HIREG;
11783 Rd = inst.operands[0].reg;
11784 Rm = inst.operands[1].reg;
11786 reject_bad_reg (Rd);
11787 reject_bad_reg (Rm);
11789 inst.instruction |= Rd << 8;
11790 inst.instruction |= Rm;
11798 Rd = inst.operands[0].reg;
11799 Rs = (inst.operands[1].present
11800 ? inst.operands[1].reg /* Rd, Rs, foo */
11801 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11803 reject_bad_reg (Rd);
11804 reject_bad_reg (Rs);
11805 if (inst.operands[2].isreg)
11806 reject_bad_reg (inst.operands[2].reg);
11808 inst.instruction |= Rd << 8;
11809 inst.instruction |= Rs << 16;
11810 if (!inst.operands[2].isreg)
11812 bfd_boolean narrow;
11814 if ((inst.instruction & 0x00100000) != 0)
11815 narrow = !in_it_block ();
11817 narrow = in_it_block ();
11819 if (Rd > 7 || Rs > 7)
11822 if (inst.size_req == 4 || !unified_syntax)
11825 if (inst.reloc.exp.X_op != O_constant
11826 || inst.reloc.exp.X_add_number != 0)
11829 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11830 relaxation, but it doesn't seem worth the hassle. */
11833 inst.reloc.type = BFD_RELOC_UNUSED;
11834 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11835 inst.instruction |= Rs << 3;
11836 inst.instruction |= Rd;
11840 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11841 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11845 encode_thumb32_shifted_operand (2);
11851 if (warn_on_deprecated
11852 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11853 as_warn (_("setend use is deprecated for ARMv8"));
11855 set_it_insn_type (OUTSIDE_IT_INSN);
11856 if (inst.operands[0].imm)
11857 inst.instruction |= 0x8;
11863 if (!inst.operands[1].present)
11864 inst.operands[1].reg = inst.operands[0].reg;
11866 if (unified_syntax)
11868 bfd_boolean narrow;
11871 switch (inst.instruction)
11874 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11876 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11878 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11880 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11884 if (THUMB_SETS_FLAGS (inst.instruction))
11885 narrow = !in_it_block ();
11887 narrow = in_it_block ();
11888 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11890 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11892 if (inst.operands[2].isreg
11893 && (inst.operands[1].reg != inst.operands[0].reg
11894 || inst.operands[2].reg > 7))
11896 if (inst.size_req == 4)
11899 reject_bad_reg (inst.operands[0].reg);
11900 reject_bad_reg (inst.operands[1].reg);
11904 if (inst.operands[2].isreg)
11906 reject_bad_reg (inst.operands[2].reg);
11907 inst.instruction = THUMB_OP32 (inst.instruction);
11908 inst.instruction |= inst.operands[0].reg << 8;
11909 inst.instruction |= inst.operands[1].reg << 16;
11910 inst.instruction |= inst.operands[2].reg;
11912 /* PR 12854: Error on extraneous shifts. */
11913 constraint (inst.operands[2].shifted,
11914 _("extraneous shift as part of operand to shift insn"));
11918 inst.operands[1].shifted = 1;
11919 inst.operands[1].shift_kind = shift_kind;
11920 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11921 ? T_MNEM_movs : T_MNEM_mov);
11922 inst.instruction |= inst.operands[0].reg << 8;
11923 encode_thumb32_shifted_operand (1);
11924 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11925 inst.reloc.type = BFD_RELOC_UNUSED;
11930 if (inst.operands[2].isreg)
11932 switch (shift_kind)
11934 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11935 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11936 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11937 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
11941 inst.instruction |= inst.operands[0].reg;
11942 inst.instruction |= inst.operands[2].reg << 3;
11944 /* PR 12854: Error on extraneous shifts. */
11945 constraint (inst.operands[2].shifted,
11946 _("extraneous shift as part of operand to shift insn"));
11950 switch (shift_kind)
11952 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11953 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11954 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11957 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11958 inst.instruction |= inst.operands[0].reg;
11959 inst.instruction |= inst.operands[1].reg << 3;
11965 constraint (inst.operands[0].reg > 7
11966 || inst.operands[1].reg > 7, BAD_HIREG);
11967 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11969 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11971 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11972 constraint (inst.operands[0].reg != inst.operands[1].reg,
11973 _("source1 and dest must be same register"));
11975 switch (inst.instruction)
11977 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11978 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11979 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11980 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11984 inst.instruction |= inst.operands[0].reg;
11985 inst.instruction |= inst.operands[2].reg << 3;
11987 /* PR 12854: Error on extraneous shifts. */
11988 constraint (inst.operands[2].shifted,
11989 _("extraneous shift as part of operand to shift insn"));
11993 switch (inst.instruction)
11995 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11996 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11997 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11998 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12001 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12002 inst.instruction |= inst.operands[0].reg;
12003 inst.instruction |= inst.operands[1].reg << 3;
12011 unsigned Rd, Rn, Rm;
12013 Rd = inst.operands[0].reg;
12014 Rn = inst.operands[1].reg;
12015 Rm = inst.operands[2].reg;
12017 reject_bad_reg (Rd);
12018 reject_bad_reg (Rn);
12019 reject_bad_reg (Rm);
12021 inst.instruction |= Rd << 8;
12022 inst.instruction |= Rn << 16;
12023 inst.instruction |= Rm;
12029 unsigned Rd, Rn, Rm;
12031 Rd = inst.operands[0].reg;
12032 Rm = inst.operands[1].reg;
12033 Rn = inst.operands[2].reg;
12035 reject_bad_reg (Rd);
12036 reject_bad_reg (Rn);
12037 reject_bad_reg (Rm);
12039 inst.instruction |= Rd << 8;
12040 inst.instruction |= Rn << 16;
12041 inst.instruction |= Rm;
12047 unsigned int value = inst.reloc.exp.X_add_number;
12048 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12049 _("SMC is not permitted on this architecture"));
12050 constraint (inst.reloc.exp.X_op != O_constant,
12051 _("expression too complex"));
12052 inst.reloc.type = BFD_RELOC_UNUSED;
12053 inst.instruction |= (value & 0xf000) >> 12;
12054 inst.instruction |= (value & 0x0ff0);
12055 inst.instruction |= (value & 0x000f) << 16;
12061 unsigned int value = inst.reloc.exp.X_add_number;
12063 inst.reloc.type = BFD_RELOC_UNUSED;
12064 inst.instruction |= (value & 0x0fff);
12065 inst.instruction |= (value & 0xf000) << 4;
12069 do_t_ssat_usat (int bias)
12073 Rd = inst.operands[0].reg;
12074 Rn = inst.operands[2].reg;
12076 reject_bad_reg (Rd);
12077 reject_bad_reg (Rn);
12079 inst.instruction |= Rd << 8;
12080 inst.instruction |= inst.operands[1].imm - bias;
12081 inst.instruction |= Rn << 16;
12083 if (inst.operands[3].present)
12085 offsetT shift_amount = inst.reloc.exp.X_add_number;
12087 inst.reloc.type = BFD_RELOC_UNUSED;
12089 constraint (inst.reloc.exp.X_op != O_constant,
12090 _("expression too complex"));
12092 if (shift_amount != 0)
12094 constraint (shift_amount > 31,
12095 _("shift expression is too large"));
12097 if (inst.operands[3].shift_kind == SHIFT_ASR)
12098 inst.instruction |= 0x00200000; /* sh bit. */
12100 inst.instruction |= (shift_amount & 0x1c) << 10;
12101 inst.instruction |= (shift_amount & 0x03) << 6;
12109 do_t_ssat_usat (1);
12117 Rd = inst.operands[0].reg;
12118 Rn = inst.operands[2].reg;
12120 reject_bad_reg (Rd);
12121 reject_bad_reg (Rn);
12123 inst.instruction |= Rd << 8;
12124 inst.instruction |= inst.operands[1].imm - 1;
12125 inst.instruction |= Rn << 16;
12131 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12132 || inst.operands[2].postind || inst.operands[2].writeback
12133 || inst.operands[2].immisreg || inst.operands[2].shifted
12134 || inst.operands[2].negative,
12137 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12139 inst.instruction |= inst.operands[0].reg << 8;
12140 inst.instruction |= inst.operands[1].reg << 12;
12141 inst.instruction |= inst.operands[2].reg << 16;
12142 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
12148 if (!inst.operands[2].present)
12149 inst.operands[2].reg = inst.operands[1].reg + 1;
12151 constraint (inst.operands[0].reg == inst.operands[1].reg
12152 || inst.operands[0].reg == inst.operands[2].reg
12153 || inst.operands[0].reg == inst.operands[3].reg,
12156 inst.instruction |= inst.operands[0].reg;
12157 inst.instruction |= inst.operands[1].reg << 12;
12158 inst.instruction |= inst.operands[2].reg << 8;
12159 inst.instruction |= inst.operands[3].reg << 16;
12165 unsigned Rd, Rn, Rm;
12167 Rd = inst.operands[0].reg;
12168 Rn = inst.operands[1].reg;
12169 Rm = inst.operands[2].reg;
12171 reject_bad_reg (Rd);
12172 reject_bad_reg (Rn);
12173 reject_bad_reg (Rm);
12175 inst.instruction |= Rd << 8;
12176 inst.instruction |= Rn << 16;
12177 inst.instruction |= Rm;
12178 inst.instruction |= inst.operands[3].imm << 4;
12186 Rd = inst.operands[0].reg;
12187 Rm = inst.operands[1].reg;
12189 reject_bad_reg (Rd);
12190 reject_bad_reg (Rm);
12192 if (inst.instruction <= 0xffff
12193 && inst.size_req != 4
12194 && Rd <= 7 && Rm <= 7
12195 && (!inst.operands[2].present || inst.operands[2].imm == 0))
12197 inst.instruction = THUMB_OP16 (inst.instruction);
12198 inst.instruction |= Rd;
12199 inst.instruction |= Rm << 3;
12201 else if (unified_syntax)
12203 if (inst.instruction <= 0xffff)
12204 inst.instruction = THUMB_OP32 (inst.instruction);
12205 inst.instruction |= Rd << 8;
12206 inst.instruction |= Rm;
12207 inst.instruction |= inst.operands[2].imm << 4;
12211 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12212 _("Thumb encoding does not support rotation"));
12213 constraint (1, BAD_HIREG);
12220 /* We have to do the following check manually as ARM_EXT_OS only applies
12222 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12224 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12225 /* This only applies to the v6m howver, not later architectures. */
12226 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
12227 as_bad (_("SVC is not permitted on this architecture"));
12228 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12231 inst.reloc.type = BFD_RELOC_ARM_SWI;
12240 half = (inst.instruction & 0x10) != 0;
12241 set_it_insn_type_last ();
12242 constraint (inst.operands[0].immisreg,
12243 _("instruction requires register index"));
12245 Rn = inst.operands[0].reg;
12246 Rm = inst.operands[0].imm;
12248 constraint (Rn == REG_SP, BAD_SP);
12249 reject_bad_reg (Rm);
12251 constraint (!half && inst.operands[0].shifted,
12252 _("instruction does not allow shifted index"));
12253 inst.instruction |= (Rn << 16) | Rm;
12259 do_t_ssat_usat (0);
12267 Rd = inst.operands[0].reg;
12268 Rn = inst.operands[2].reg;
12270 reject_bad_reg (Rd);
12271 reject_bad_reg (Rn);
12273 inst.instruction |= Rd << 8;
12274 inst.instruction |= inst.operands[1].imm;
12275 inst.instruction |= Rn << 16;
12278 /* Neon instruction encoder helpers. */
12280 /* Encodings for the different types for various Neon opcodes. */
12282 /* An "invalid" code for the following tables. */
12285 struct neon_tab_entry
12288 unsigned float_or_poly;
12289 unsigned scalar_or_imm;
12292 /* Map overloaded Neon opcodes to their respective encodings. */
12293 #define NEON_ENC_TAB \
12294 X(vabd, 0x0000700, 0x1200d00, N_INV), \
12295 X(vmax, 0x0000600, 0x0000f00, N_INV), \
12296 X(vmin, 0x0000610, 0x0200f00, N_INV), \
12297 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
12298 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
12299 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
12300 X(vadd, 0x0000800, 0x0000d00, N_INV), \
12301 X(vsub, 0x1000800, 0x0200d00, N_INV), \
12302 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
12303 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
12304 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
12305 /* Register variants of the following two instructions are encoded as
12306 vcge / vcgt with the operands reversed. */ \
12307 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
12308 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
12309 X(vfma, N_INV, 0x0000c10, N_INV), \
12310 X(vfms, N_INV, 0x0200c10, N_INV), \
12311 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
12312 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
12313 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
12314 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
12315 X(vmlal, 0x0800800, N_INV, 0x0800240), \
12316 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
12317 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
12318 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
12319 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
12320 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
12321 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
12322 X(vshl, 0x0000400, N_INV, 0x0800510), \
12323 X(vqshl, 0x0000410, N_INV, 0x0800710), \
12324 X(vand, 0x0000110, N_INV, 0x0800030), \
12325 X(vbic, 0x0100110, N_INV, 0x0800030), \
12326 X(veor, 0x1000110, N_INV, N_INV), \
12327 X(vorn, 0x0300110, N_INV, 0x0800010), \
12328 X(vorr, 0x0200110, N_INV, 0x0800010), \
12329 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
12330 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
12331 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
12332 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
12333 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12334 X(vst1, 0x0000000, 0x0800000, N_INV), \
12335 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12336 X(vst2, 0x0000100, 0x0800100, N_INV), \
12337 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12338 X(vst3, 0x0000200, 0x0800200, N_INV), \
12339 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12340 X(vst4, 0x0000300, 0x0800300, N_INV), \
12341 X(vmovn, 0x1b20200, N_INV, N_INV), \
12342 X(vtrn, 0x1b20080, N_INV, N_INV), \
12343 X(vqmovn, 0x1b20200, N_INV, N_INV), \
12344 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12345 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
12346 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12347 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
12348 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12349 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
12350 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12351 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12352 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
12353 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
12354 X(vseleq, 0xe000a00, N_INV, N_INV), \
12355 X(vselvs, 0xe100a00, N_INV, N_INV), \
12356 X(vselge, 0xe200a00, N_INV, N_INV), \
12357 X(vselgt, 0xe300a00, N_INV, N_INV), \
12358 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
12359 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
12360 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
12361 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
12362 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
12363 X(aes, 0x3b00300, N_INV, N_INV), \
12364 X(sha3op, 0x2000c00, N_INV, N_INV), \
12365 X(sha1h, 0x3b902c0, N_INV, N_INV), \
12366 X(sha2op, 0x3ba0380, N_INV, N_INV)
12370 #define X(OPC,I,F,S) N_MNEM_##OPC
12375 static const struct neon_tab_entry neon_enc_tab[] =
12377 #define X(OPC,I,F,S) { (I), (F), (S) }
12382 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
12383 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12384 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12385 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12386 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12387 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12388 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12389 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12390 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12391 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12392 #define NEON_ENC_SINGLE_(X) \
12393 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
12394 #define NEON_ENC_DOUBLE_(X) \
12395 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
12396 #define NEON_ENC_FPV8_(X) \
12397 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
12399 #define NEON_ENCODE(type, inst) \
12402 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12403 inst.is_neon = 1; \
12407 #define check_neon_suffixes \
12410 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12412 as_bad (_("invalid neon suffix for non neon instruction")); \
12418 /* Define shapes for instruction operands. The following mnemonic characters
12419 are used in this table:
12421 F - VFP S<n> register
12422 D - Neon D<n> register
12423 Q - Neon Q<n> register
12427 L - D<n> register list
12429 This table is used to generate various data:
12430 - enumerations of the form NS_DDR to be used as arguments to
12432 - a table classifying shapes into single, double, quad, mixed.
12433 - a table used to drive neon_select_shape. */
12435 #define NEON_SHAPE_DEF \
12436 X(3, (D, D, D), DOUBLE), \
12437 X(3, (Q, Q, Q), QUAD), \
12438 X(3, (D, D, I), DOUBLE), \
12439 X(3, (Q, Q, I), QUAD), \
12440 X(3, (D, D, S), DOUBLE), \
12441 X(3, (Q, Q, S), QUAD), \
12442 X(2, (D, D), DOUBLE), \
12443 X(2, (Q, Q), QUAD), \
12444 X(2, (D, S), DOUBLE), \
12445 X(2, (Q, S), QUAD), \
12446 X(2, (D, R), DOUBLE), \
12447 X(2, (Q, R), QUAD), \
12448 X(2, (D, I), DOUBLE), \
12449 X(2, (Q, I), QUAD), \
12450 X(3, (D, L, D), DOUBLE), \
12451 X(2, (D, Q), MIXED), \
12452 X(2, (Q, D), MIXED), \
12453 X(3, (D, Q, I), MIXED), \
12454 X(3, (Q, D, I), MIXED), \
12455 X(3, (Q, D, D), MIXED), \
12456 X(3, (D, Q, Q), MIXED), \
12457 X(3, (Q, Q, D), MIXED), \
12458 X(3, (Q, D, S), MIXED), \
12459 X(3, (D, Q, S), MIXED), \
12460 X(4, (D, D, D, I), DOUBLE), \
12461 X(4, (Q, Q, Q, I), QUAD), \
12462 X(2, (F, F), SINGLE), \
12463 X(3, (F, F, F), SINGLE), \
12464 X(2, (F, I), SINGLE), \
12465 X(2, (F, D), MIXED), \
12466 X(2, (D, F), MIXED), \
12467 X(3, (F, F, I), MIXED), \
12468 X(4, (R, R, F, F), SINGLE), \
12469 X(4, (F, F, R, R), SINGLE), \
12470 X(3, (D, R, R), DOUBLE), \
12471 X(3, (R, R, D), DOUBLE), \
12472 X(2, (S, R), SINGLE), \
12473 X(2, (R, S), SINGLE), \
12474 X(2, (F, R), SINGLE), \
12475 X(2, (R, F), SINGLE)
12477 #define S2(A,B) NS_##A##B
12478 #define S3(A,B,C) NS_##A##B##C
12479 #define S4(A,B,C,D) NS_##A##B##C##D
12481 #define X(N, L, C) S##N L
12494 enum neon_shape_class
12502 #define X(N, L, C) SC_##C
12504 static enum neon_shape_class neon_shape_class[] =
12522 /* Register widths of above. */
12523 static unsigned neon_shape_el_size[] =
12534 struct neon_shape_info
12537 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12540 #define S2(A,B) { SE_##A, SE_##B }
12541 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12542 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12544 #define X(N, L, C) { N, S##N L }
12546 static struct neon_shape_info neon_shape_tab[] =
12556 /* Bit masks used in type checking given instructions.
12557 'N_EQK' means the type must be the same as (or based on in some way) the key
12558 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12559 set, various other bits can be set as well in order to modify the meaning of
12560 the type constraint. */
12562 enum neon_type_mask
12586 N_KEY = 0x1000000, /* Key element (main type specifier). */
12587 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
12588 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
12589 N_UNT = 0x8000000, /* Must be explicitly untyped. */
12590 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12591 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12592 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12593 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12594 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12595 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12596 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
12598 N_MAX_NONSPECIAL = N_P64
12601 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12603 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12604 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12605 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12606 #define N_SUF_32 (N_SU_32 | N_F32)
12607 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12608 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12610 /* Pass this as the first type argument to neon_check_type to ignore types
12612 #define N_IGNORE_TYPE (N_KEY | N_EQK)
12614 /* Select a "shape" for the current instruction (describing register types or
12615 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12616 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12617 function of operand parsing, so this function doesn't need to be called.
12618 Shapes should be listed in order of decreasing length. */
12620 static enum neon_shape
12621 neon_select_shape (enum neon_shape shape, ...)
12624 enum neon_shape first_shape = shape;
12626 /* Fix missing optional operands. FIXME: we don't know at this point how
12627 many arguments we should have, so this makes the assumption that we have
12628 > 1. This is true of all current Neon opcodes, I think, but may not be
12629 true in the future. */
12630 if (!inst.operands[1].present)
12631 inst.operands[1] = inst.operands[0];
12633 va_start (ap, shape);
12635 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
12640 for (j = 0; j < neon_shape_tab[shape].els; j++)
12642 if (!inst.operands[j].present)
12648 switch (neon_shape_tab[shape].el[j])
12651 if (!(inst.operands[j].isreg
12652 && inst.operands[j].isvec
12653 && inst.operands[j].issingle
12654 && !inst.operands[j].isquad))
12659 if (!(inst.operands[j].isreg
12660 && inst.operands[j].isvec
12661 && !inst.operands[j].isquad
12662 && !inst.operands[j].issingle))
12667 if (!(inst.operands[j].isreg
12668 && !inst.operands[j].isvec))
12673 if (!(inst.operands[j].isreg
12674 && inst.operands[j].isvec
12675 && inst.operands[j].isquad
12676 && !inst.operands[j].issingle))
12681 if (!(!inst.operands[j].isreg
12682 && !inst.operands[j].isscalar))
12687 if (!(!inst.operands[j].isreg
12688 && inst.operands[j].isscalar))
12698 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
12699 /* We've matched all the entries in the shape table, and we don't
12700 have any left over operands which have not been matched. */
12706 if (shape == NS_NULL && first_shape != NS_NULL)
12707 first_error (_("invalid instruction shape"));
12712 /* True if SHAPE is predominantly a quadword operation (most of the time, this
12713 means the Q bit should be set). */
12716 neon_quad (enum neon_shape shape)
12718 return neon_shape_class[shape] == SC_QUAD;
12722 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12725 /* Allow modification to be made to types which are constrained to be
12726 based on the key element, based on bits set alongside N_EQK. */
12727 if ((typebits & N_EQK) != 0)
12729 if ((typebits & N_HLF) != 0)
12731 else if ((typebits & N_DBL) != 0)
12733 if ((typebits & N_SGN) != 0)
12734 *g_type = NT_signed;
12735 else if ((typebits & N_UNS) != 0)
12736 *g_type = NT_unsigned;
12737 else if ((typebits & N_INT) != 0)
12738 *g_type = NT_integer;
12739 else if ((typebits & N_FLT) != 0)
12740 *g_type = NT_float;
12741 else if ((typebits & N_SIZ) != 0)
12742 *g_type = NT_untyped;
12746 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12747 operand type, i.e. the single type specified in a Neon instruction when it
12748 is the only one given. */
12750 static struct neon_type_el
12751 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12753 struct neon_type_el dest = *key;
12755 gas_assert ((thisarg & N_EQK) != 0);
12757 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12762 /* Convert Neon type and size into compact bitmask representation. */
12764 static enum neon_type_mask
12765 type_chk_of_el_type (enum neon_el_type type, unsigned size)
12772 case 8: return N_8;
12773 case 16: return N_16;
12774 case 32: return N_32;
12775 case 64: return N_64;
12783 case 8: return N_I8;
12784 case 16: return N_I16;
12785 case 32: return N_I32;
12786 case 64: return N_I64;
12794 case 16: return N_F16;
12795 case 32: return N_F32;
12796 case 64: return N_F64;
12804 case 8: return N_P8;
12805 case 16: return N_P16;
12806 case 64: return N_P64;
12814 case 8: return N_S8;
12815 case 16: return N_S16;
12816 case 32: return N_S32;
12817 case 64: return N_S64;
12825 case 8: return N_U8;
12826 case 16: return N_U16;
12827 case 32: return N_U32;
12828 case 64: return N_U64;
12839 /* Convert compact Neon bitmask type representation to a type and size. Only
12840 handles the case where a single bit is set in the mask. */
12843 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12844 enum neon_type_mask mask)
12846 if ((mask & N_EQK) != 0)
12849 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12851 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
12853 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
12855 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
12860 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12862 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
12863 *type = NT_unsigned;
12864 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
12865 *type = NT_integer;
12866 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
12867 *type = NT_untyped;
12868 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
12870 else if ((mask & (N_F16 | N_F32 | N_F64)) != 0)
12878 /* Modify a bitmask of allowed types. This is only needed for type
12882 modify_types_allowed (unsigned allowed, unsigned mods)
12885 enum neon_el_type type;
12891 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12893 if (el_type_of_type_chk (&type, &size,
12894 (enum neon_type_mask) (allowed & i)) == SUCCESS)
12896 neon_modify_type_size (mods, &type, &size);
12897 destmask |= type_chk_of_el_type (type, size);
12904 /* Check type and return type classification.
12905 The manual states (paraphrase): If one datatype is given, it indicates the
12907 - the second operand, if there is one
12908 - the operand, if there is no second operand
12909 - the result, if there are no operands.
12910 This isn't quite good enough though, so we use a concept of a "key" datatype
12911 which is set on a per-instruction basis, which is the one which matters when
12912 only one data type is written.
12913 Note: this function has side-effects (e.g. filling in missing operands). All
12914 Neon instructions should call it before performing bit encoding. */
12916 static struct neon_type_el
12917 neon_check_type (unsigned els, enum neon_shape ns, ...)
12920 unsigned i, pass, key_el = 0;
12921 unsigned types[NEON_MAX_TYPE_ELS];
12922 enum neon_el_type k_type = NT_invtype;
12923 unsigned k_size = -1u;
12924 struct neon_type_el badtype = {NT_invtype, -1};
12925 unsigned key_allowed = 0;
12927 /* Optional registers in Neon instructions are always (not) in operand 1.
12928 Fill in the missing operand here, if it was omitted. */
12929 if (els > 1 && !inst.operands[1].present)
12930 inst.operands[1] = inst.operands[0];
12932 /* Suck up all the varargs. */
12934 for (i = 0; i < els; i++)
12936 unsigned thisarg = va_arg (ap, unsigned);
12937 if (thisarg == N_IGNORE_TYPE)
12942 types[i] = thisarg;
12943 if ((thisarg & N_KEY) != 0)
12948 if (inst.vectype.elems > 0)
12949 for (i = 0; i < els; i++)
12950 if (inst.operands[i].vectype.type != NT_invtype)
12952 first_error (_("types specified in both the mnemonic and operands"));
12956 /* Duplicate inst.vectype elements here as necessary.
12957 FIXME: No idea if this is exactly the same as the ARM assembler,
12958 particularly when an insn takes one register and one non-register
12960 if (inst.vectype.elems == 1 && els > 1)
12963 inst.vectype.elems = els;
12964 inst.vectype.el[key_el] = inst.vectype.el[0];
12965 for (j = 0; j < els; j++)
12967 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12970 else if (inst.vectype.elems == 0 && els > 0)
12973 /* No types were given after the mnemonic, so look for types specified
12974 after each operand. We allow some flexibility here; as long as the
12975 "key" operand has a type, we can infer the others. */
12976 for (j = 0; j < els; j++)
12977 if (inst.operands[j].vectype.type != NT_invtype)
12978 inst.vectype.el[j] = inst.operands[j].vectype;
12980 if (inst.operands[key_el].vectype.type != NT_invtype)
12982 for (j = 0; j < els; j++)
12983 if (inst.operands[j].vectype.type == NT_invtype)
12984 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12989 first_error (_("operand types can't be inferred"));
12993 else if (inst.vectype.elems != els)
12995 first_error (_("type specifier has the wrong number of parts"));
12999 for (pass = 0; pass < 2; pass++)
13001 for (i = 0; i < els; i++)
13003 unsigned thisarg = types[i];
13004 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13005 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13006 enum neon_el_type g_type = inst.vectype.el[i].type;
13007 unsigned g_size = inst.vectype.el[i].size;
13009 /* Decay more-specific signed & unsigned types to sign-insensitive
13010 integer types if sign-specific variants are unavailable. */
13011 if ((g_type == NT_signed || g_type == NT_unsigned)
13012 && (types_allowed & N_SU_ALL) == 0)
13013 g_type = NT_integer;
13015 /* If only untyped args are allowed, decay any more specific types to
13016 them. Some instructions only care about signs for some element
13017 sizes, so handle that properly. */
13018 if (((types_allowed & N_UNT) == 0)
13019 && ((g_size == 8 && (types_allowed & N_8) != 0)
13020 || (g_size == 16 && (types_allowed & N_16) != 0)
13021 || (g_size == 32 && (types_allowed & N_32) != 0)
13022 || (g_size == 64 && (types_allowed & N_64) != 0)))
13023 g_type = NT_untyped;
13027 if ((thisarg & N_KEY) != 0)
13031 key_allowed = thisarg & ~N_KEY;
13036 if ((thisarg & N_VFP) != 0)
13038 enum neon_shape_el regshape;
13039 unsigned regwidth, match;
13041 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13044 first_error (_("invalid instruction shape"));
13047 regshape = neon_shape_tab[ns].el[i];
13048 regwidth = neon_shape_el_size[regshape];
13050 /* In VFP mode, operands must match register widths. If we
13051 have a key operand, use its width, else use the width of
13052 the current operand. */
13058 if (regwidth != match)
13060 first_error (_("operand size must match register width"));
13065 if ((thisarg & N_EQK) == 0)
13067 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13069 if ((given_type & types_allowed) == 0)
13071 first_error (_("bad type in Neon instruction"));
13077 enum neon_el_type mod_k_type = k_type;
13078 unsigned mod_k_size = k_size;
13079 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13080 if (g_type != mod_k_type || g_size != mod_k_size)
13082 first_error (_("inconsistent types in Neon instruction"));
13090 return inst.vectype.el[key_el];
13093 /* Neon-style VFP instruction forwarding. */
13095 /* Thumb VFP instructions have 0xE in the condition field. */
13098 do_vfp_cond_or_thumb (void)
13103 inst.instruction |= 0xe0000000;
13105 inst.instruction |= inst.cond << 28;
13108 /* Look up and encode a simple mnemonic, for use as a helper function for the
13109 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13110 etc. It is assumed that operand parsing has already been done, and that the
13111 operands are in the form expected by the given opcode (this isn't necessarily
13112 the same as the form in which they were parsed, hence some massaging must
13113 take place before this function is called).
13114 Checks current arch version against that in the looked-up opcode. */
13117 do_vfp_nsyn_opcode (const char *opname)
13119 const struct asm_opcode *opcode;
13121 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
13126 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
13127 thumb_mode ? *opcode->tvariant : *opcode->avariant),
13134 inst.instruction = opcode->tvalue;
13135 opcode->tencode ();
13139 inst.instruction = (inst.cond << 28) | opcode->avalue;
13140 opcode->aencode ();
13145 do_vfp_nsyn_add_sub (enum neon_shape rs)
13147 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
13152 do_vfp_nsyn_opcode ("fadds");
13154 do_vfp_nsyn_opcode ("fsubs");
13159 do_vfp_nsyn_opcode ("faddd");
13161 do_vfp_nsyn_opcode ("fsubd");
13165 /* Check operand types to see if this is a VFP instruction, and if so call
13169 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
13171 enum neon_shape rs;
13172 struct neon_type_el et;
13177 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13178 et = neon_check_type (2, rs,
13179 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13183 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13184 et = neon_check_type (3, rs,
13185 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13192 if (et.type != NT_invtype)
13203 do_vfp_nsyn_mla_mls (enum neon_shape rs)
13205 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
13210 do_vfp_nsyn_opcode ("fmacs");
13212 do_vfp_nsyn_opcode ("fnmacs");
13217 do_vfp_nsyn_opcode ("fmacd");
13219 do_vfp_nsyn_opcode ("fnmacd");
13224 do_vfp_nsyn_fma_fms (enum neon_shape rs)
13226 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13231 do_vfp_nsyn_opcode ("ffmas");
13233 do_vfp_nsyn_opcode ("ffnmas");
13238 do_vfp_nsyn_opcode ("ffmad");
13240 do_vfp_nsyn_opcode ("ffnmad");
13245 do_vfp_nsyn_mul (enum neon_shape rs)
13248 do_vfp_nsyn_opcode ("fmuls");
13250 do_vfp_nsyn_opcode ("fmuld");
13254 do_vfp_nsyn_abs_neg (enum neon_shape rs)
13256 int is_neg = (inst.instruction & 0x80) != 0;
13257 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13262 do_vfp_nsyn_opcode ("fnegs");
13264 do_vfp_nsyn_opcode ("fabss");
13269 do_vfp_nsyn_opcode ("fnegd");
13271 do_vfp_nsyn_opcode ("fabsd");
13275 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13276 insns belong to Neon, and are handled elsewhere. */
13279 do_vfp_nsyn_ldm_stm (int is_dbmode)
13281 int is_ldm = (inst.instruction & (1 << 20)) != 0;
13285 do_vfp_nsyn_opcode ("fldmdbs");
13287 do_vfp_nsyn_opcode ("fldmias");
13292 do_vfp_nsyn_opcode ("fstmdbs");
13294 do_vfp_nsyn_opcode ("fstmias");
13299 do_vfp_nsyn_sqrt (void)
13301 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13302 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13305 do_vfp_nsyn_opcode ("fsqrts");
13307 do_vfp_nsyn_opcode ("fsqrtd");
13311 do_vfp_nsyn_div (void)
13313 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13314 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13315 N_F32 | N_F64 | N_KEY | N_VFP);
13318 do_vfp_nsyn_opcode ("fdivs");
13320 do_vfp_nsyn_opcode ("fdivd");
13324 do_vfp_nsyn_nmul (void)
13326 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13327 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13328 N_F32 | N_F64 | N_KEY | N_VFP);
13332 NEON_ENCODE (SINGLE, inst);
13333 do_vfp_sp_dyadic ();
13337 NEON_ENCODE (DOUBLE, inst);
13338 do_vfp_dp_rd_rn_rm ();
13340 do_vfp_cond_or_thumb ();
13344 do_vfp_nsyn_cmp (void)
13346 if (inst.operands[1].isreg)
13348 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13349 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13353 NEON_ENCODE (SINGLE, inst);
13354 do_vfp_sp_monadic ();
13358 NEON_ENCODE (DOUBLE, inst);
13359 do_vfp_dp_rd_rm ();
13364 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13365 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13367 switch (inst.instruction & 0x0fffffff)
13370 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13373 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13381 NEON_ENCODE (SINGLE, inst);
13382 do_vfp_sp_compare_z ();
13386 NEON_ENCODE (DOUBLE, inst);
13390 do_vfp_cond_or_thumb ();
13394 nsyn_insert_sp (void)
13396 inst.operands[1] = inst.operands[0];
13397 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
13398 inst.operands[0].reg = REG_SP;
13399 inst.operands[0].isreg = 1;
13400 inst.operands[0].writeback = 1;
13401 inst.operands[0].present = 1;
13405 do_vfp_nsyn_push (void)
13408 if (inst.operands[1].issingle)
13409 do_vfp_nsyn_opcode ("fstmdbs");
13411 do_vfp_nsyn_opcode ("fstmdbd");
13415 do_vfp_nsyn_pop (void)
13418 if (inst.operands[1].issingle)
13419 do_vfp_nsyn_opcode ("fldmias");
13421 do_vfp_nsyn_opcode ("fldmiad");
13424 /* Fix up Neon data-processing instructions, ORing in the correct bits for
13425 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13428 neon_dp_fixup (struct arm_it* insn)
13430 unsigned int i = insn->instruction;
13435 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13446 insn->instruction = i;
13449 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13453 neon_logbits (unsigned x)
13455 return ffs (x) - 4;
13458 #define LOW4(R) ((R) & 0xf)
13459 #define HI1(R) (((R) >> 4) & 1)
13461 /* Encode insns with bit pattern:
13463 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13464 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
13466 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13467 different meaning for some instruction. */
13470 neon_three_same (int isquad, int ubit, int size)
13472 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13473 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13474 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13475 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13476 inst.instruction |= LOW4 (inst.operands[2].reg);
13477 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13478 inst.instruction |= (isquad != 0) << 6;
13479 inst.instruction |= (ubit != 0) << 24;
13481 inst.instruction |= neon_logbits (size) << 20;
13483 neon_dp_fixup (&inst);
13486 /* Encode instructions of the form:
13488 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13489 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
13491 Don't write size if SIZE == -1. */
13494 neon_two_same (int qbit, int ubit, int size)
13496 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13497 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13498 inst.instruction |= LOW4 (inst.operands[1].reg);
13499 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13500 inst.instruction |= (qbit != 0) << 6;
13501 inst.instruction |= (ubit != 0) << 24;
13504 inst.instruction |= neon_logbits (size) << 18;
13506 neon_dp_fixup (&inst);
13509 /* Neon instruction encoders, in approximate order of appearance. */
13512 do_neon_dyadic_i_su (void)
13514 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13515 struct neon_type_el et = neon_check_type (3, rs,
13516 N_EQK, N_EQK, N_SU_32 | N_KEY);
13517 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13521 do_neon_dyadic_i64_su (void)
13523 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13524 struct neon_type_el et = neon_check_type (3, rs,
13525 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13526 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13530 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13533 unsigned size = et.size >> 3;
13534 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13535 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13536 inst.instruction |= LOW4 (inst.operands[1].reg);
13537 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13538 inst.instruction |= (isquad != 0) << 6;
13539 inst.instruction |= immbits << 16;
13540 inst.instruction |= (size >> 3) << 7;
13541 inst.instruction |= (size & 0x7) << 19;
13543 inst.instruction |= (uval != 0) << 24;
13545 neon_dp_fixup (&inst);
13549 do_neon_shl_imm (void)
13551 if (!inst.operands[2].isreg)
13553 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13554 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
13555 NEON_ENCODE (IMMED, inst);
13556 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
13560 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13561 struct neon_type_el et = neon_check_type (3, rs,
13562 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
13565 /* VSHL/VQSHL 3-register variants have syntax such as:
13567 whereas other 3-register operations encoded by neon_three_same have
13570 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13572 tmp = inst.operands[2].reg;
13573 inst.operands[2].reg = inst.operands[1].reg;
13574 inst.operands[1].reg = tmp;
13575 NEON_ENCODE (INTEGER, inst);
13576 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13581 do_neon_qshl_imm (void)
13583 if (!inst.operands[2].isreg)
13585 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13586 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13588 NEON_ENCODE (IMMED, inst);
13589 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13590 inst.operands[2].imm);
13594 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13595 struct neon_type_el et = neon_check_type (3, rs,
13596 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
13599 /* See note in do_neon_shl_imm. */
13600 tmp = inst.operands[2].reg;
13601 inst.operands[2].reg = inst.operands[1].reg;
13602 inst.operands[1].reg = tmp;
13603 NEON_ENCODE (INTEGER, inst);
13604 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13609 do_neon_rshl (void)
13611 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13612 struct neon_type_el et = neon_check_type (3, rs,
13613 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13616 tmp = inst.operands[2].reg;
13617 inst.operands[2].reg = inst.operands[1].reg;
13618 inst.operands[1].reg = tmp;
13619 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13623 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13625 /* Handle .I8 pseudo-instructions. */
13628 /* Unfortunately, this will make everything apart from zero out-of-range.
13629 FIXME is this the intended semantics? There doesn't seem much point in
13630 accepting .I8 if so. */
13631 immediate |= immediate << 8;
13637 if (immediate == (immediate & 0x000000ff))
13639 *immbits = immediate;
13642 else if (immediate == (immediate & 0x0000ff00))
13644 *immbits = immediate >> 8;
13647 else if (immediate == (immediate & 0x00ff0000))
13649 *immbits = immediate >> 16;
13652 else if (immediate == (immediate & 0xff000000))
13654 *immbits = immediate >> 24;
13657 if ((immediate & 0xffff) != (immediate >> 16))
13658 goto bad_immediate;
13659 immediate &= 0xffff;
13662 if (immediate == (immediate & 0x000000ff))
13664 *immbits = immediate;
13667 else if (immediate == (immediate & 0x0000ff00))
13669 *immbits = immediate >> 8;
13674 first_error (_("immediate value out of range"));
13678 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13682 neon_bits_same_in_bytes (unsigned imm)
13684 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13685 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13686 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13687 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13690 /* For immediate of above form, return 0bABCD. */
13693 neon_squash_bits (unsigned imm)
13695 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13696 | ((imm & 0x01000000) >> 21);
13699 /* Compress quarter-float representation to 0b...000 abcdefgh. */
13702 neon_qfloat_bits (unsigned imm)
13704 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
13707 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13708 the instruction. *OP is passed as the initial value of the op field, and
13709 may be set to a different value depending on the constant (i.e.
13710 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
13711 MVN). If the immediate looks like a repeated pattern then also
13712 try smaller element sizes. */
13715 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13716 unsigned *immbits, int *op, int size,
13717 enum neon_el_type type)
13719 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13721 if (type == NT_float && !float_p)
13724 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13726 if (size != 32 || *op == 1)
13728 *immbits = neon_qfloat_bits (immlo);
13734 if (neon_bits_same_in_bytes (immhi)
13735 && neon_bits_same_in_bytes (immlo))
13739 *immbits = (neon_squash_bits (immhi) << 4)
13740 | neon_squash_bits (immlo);
13745 if (immhi != immlo)
13751 if (immlo == (immlo & 0x000000ff))
13756 else if (immlo == (immlo & 0x0000ff00))
13758 *immbits = immlo >> 8;
13761 else if (immlo == (immlo & 0x00ff0000))
13763 *immbits = immlo >> 16;
13766 else if (immlo == (immlo & 0xff000000))
13768 *immbits = immlo >> 24;
13771 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13773 *immbits = (immlo >> 8) & 0xff;
13776 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13778 *immbits = (immlo >> 16) & 0xff;
13782 if ((immlo & 0xffff) != (immlo >> 16))
13789 if (immlo == (immlo & 0x000000ff))
13794 else if (immlo == (immlo & 0x0000ff00))
13796 *immbits = immlo >> 8;
13800 if ((immlo & 0xff) != (immlo >> 8))
13805 if (immlo == (immlo & 0x000000ff))
13807 /* Don't allow MVN with 8-bit immediate. */
13817 /* Write immediate bits [7:0] to the following locations:
13819 |28/24|23 19|18 16|15 4|3 0|
13820 | 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|
13822 This function is used by VMOV/VMVN/VORR/VBIC. */
13825 neon_write_immbits (unsigned immbits)
13827 inst.instruction |= immbits & 0xf;
13828 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13829 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13832 /* Invert low-order SIZE bits of XHI:XLO. */
13835 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13837 unsigned immlo = xlo ? *xlo : 0;
13838 unsigned immhi = xhi ? *xhi : 0;
13843 immlo = (~immlo) & 0xff;
13847 immlo = (~immlo) & 0xffff;
13851 immhi = (~immhi) & 0xffffffff;
13852 /* fall through. */
13855 immlo = (~immlo) & 0xffffffff;
13870 do_neon_logic (void)
13872 if (inst.operands[2].present && inst.operands[2].isreg)
13874 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13875 neon_check_type (3, rs, N_IGNORE_TYPE);
13876 /* U bit and size field were set as part of the bitmask. */
13877 NEON_ENCODE (INTEGER, inst);
13878 neon_three_same (neon_quad (rs), 0, -1);
13882 const int three_ops_form = (inst.operands[2].present
13883 && !inst.operands[2].isreg);
13884 const int immoperand = (three_ops_form ? 2 : 1);
13885 enum neon_shape rs = (three_ops_form
13886 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13887 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
13888 struct neon_type_el et = neon_check_type (2, rs,
13889 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13890 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
13894 if (et.type == NT_invtype)
13897 if (three_ops_form)
13898 constraint (inst.operands[0].reg != inst.operands[1].reg,
13899 _("first and second operands shall be the same register"));
13901 NEON_ENCODE (IMMED, inst);
13903 immbits = inst.operands[immoperand].imm;
13906 /* .i64 is a pseudo-op, so the immediate must be a repeating
13908 if (immbits != (inst.operands[immoperand].regisimm ?
13909 inst.operands[immoperand].reg : 0))
13911 /* Set immbits to an invalid constant. */
13912 immbits = 0xdeadbeef;
13919 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13923 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13927 /* Pseudo-instruction for VBIC. */
13928 neon_invert_size (&immbits, 0, et.size);
13929 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13933 /* Pseudo-instruction for VORR. */
13934 neon_invert_size (&immbits, 0, et.size);
13935 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13945 inst.instruction |= neon_quad (rs) << 6;
13946 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13947 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13948 inst.instruction |= cmode << 8;
13949 neon_write_immbits (immbits);
13951 neon_dp_fixup (&inst);
13956 do_neon_bitfield (void)
13958 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13959 neon_check_type (3, rs, N_IGNORE_TYPE);
13960 neon_three_same (neon_quad (rs), 0, -1);
13964 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13967 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13968 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13970 if (et.type == NT_float)
13972 NEON_ENCODE (FLOAT, inst);
13973 neon_three_same (neon_quad (rs), 0, -1);
13977 NEON_ENCODE (INTEGER, inst);
13978 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
13983 do_neon_dyadic_if_su (void)
13985 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13989 do_neon_dyadic_if_su_d (void)
13991 /* This version only allow D registers, but that constraint is enforced during
13992 operand parsing so we don't need to do anything extra here. */
13993 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13997 do_neon_dyadic_if_i_d (void)
13999 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14000 affected if we specify unsigned args. */
14001 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14004 enum vfp_or_neon_is_neon_bits
14007 NEON_CHECK_ARCH = 2,
14008 NEON_CHECK_ARCH8 = 4
14011 /* Call this function if an instruction which may have belonged to the VFP or
14012 Neon instruction sets, but turned out to be a Neon instruction (due to the
14013 operand types involved, etc.). We have to check and/or fix-up a couple of
14016 - Make sure the user hasn't attempted to make a Neon instruction
14018 - Alter the value in the condition code field if necessary.
14019 - Make sure that the arch supports Neon instructions.
14021 Which of these operations take place depends on bits from enum
14022 vfp_or_neon_is_neon_bits.
14024 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14025 current instruction's condition is COND_ALWAYS, the condition field is
14026 changed to inst.uncond_value. This is necessary because instructions shared
14027 between VFP and Neon may be conditional for the VFP variants only, and the
14028 unconditional Neon version must have, e.g., 0xF in the condition field. */
14031 vfp_or_neon_is_neon (unsigned check)
14033 /* Conditions are always legal in Thumb mode (IT blocks). */
14034 if (!thumb_mode && (check & NEON_CHECK_CC))
14036 if (inst.cond != COND_ALWAYS)
14038 first_error (_(BAD_COND));
14041 if (inst.uncond_value != -1)
14042 inst.instruction |= inst.uncond_value << 28;
14045 if ((check & NEON_CHECK_ARCH)
14046 && !mark_feature_used (&fpu_neon_ext_v1))
14048 first_error (_(BAD_FPU));
14052 if ((check & NEON_CHECK_ARCH8)
14053 && !mark_feature_used (&fpu_neon_ext_armv8))
14055 first_error (_(BAD_FPU));
14063 do_neon_addsub_if_i (void)
14065 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14068 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14071 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14072 affected if we specify unsigned args. */
14073 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
14076 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14078 V<op> A,B (A is operand 0, B is operand 2)
14083 so handle that case specially. */
14086 neon_exchange_operands (void)
14088 void *scratch = alloca (sizeof (inst.operands[0]));
14089 if (inst.operands[1].present)
14091 /* Swap operands[1] and operands[2]. */
14092 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14093 inst.operands[1] = inst.operands[2];
14094 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14098 inst.operands[1] = inst.operands[2];
14099 inst.operands[2] = inst.operands[0];
14104 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14106 if (inst.operands[2].isreg)
14109 neon_exchange_operands ();
14110 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
14114 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14115 struct neon_type_el et = neon_check_type (2, rs,
14116 N_EQK | N_SIZ, immtypes | N_KEY);
14118 NEON_ENCODE (IMMED, inst);
14119 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14120 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14121 inst.instruction |= LOW4 (inst.operands[1].reg);
14122 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14123 inst.instruction |= neon_quad (rs) << 6;
14124 inst.instruction |= (et.type == NT_float) << 10;
14125 inst.instruction |= neon_logbits (et.size) << 18;
14127 neon_dp_fixup (&inst);
14134 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14138 do_neon_cmp_inv (void)
14140 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14146 neon_compare (N_IF_32, N_IF_32, FALSE);
14149 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
14150 scalars, which are encoded in 5 bits, M : Rm.
14151 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14152 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14156 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14158 unsigned regno = NEON_SCALAR_REG (scalar);
14159 unsigned elno = NEON_SCALAR_INDEX (scalar);
14164 if (regno > 7 || elno > 3)
14166 return regno | (elno << 3);
14169 if (regno > 15 || elno > 1)
14171 return regno | (elno << 4);
14175 first_error (_("scalar out of range for multiply instruction"));
14181 /* Encode multiply / multiply-accumulate scalar instructions. */
14184 neon_mul_mac (struct neon_type_el et, int ubit)
14188 /* Give a more helpful error message if we have an invalid type. */
14189 if (et.type == NT_invtype)
14192 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
14193 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14194 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14195 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14196 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14197 inst.instruction |= LOW4 (scalar);
14198 inst.instruction |= HI1 (scalar) << 5;
14199 inst.instruction |= (et.type == NT_float) << 8;
14200 inst.instruction |= neon_logbits (et.size) << 20;
14201 inst.instruction |= (ubit != 0) << 24;
14203 neon_dp_fixup (&inst);
14207 do_neon_mac_maybe_scalar (void)
14209 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14212 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14215 if (inst.operands[2].isscalar)
14217 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
14218 struct neon_type_el et = neon_check_type (3, rs,
14219 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
14220 NEON_ENCODE (SCALAR, inst);
14221 neon_mul_mac (et, neon_quad (rs));
14225 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14226 affected if we specify unsigned args. */
14227 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14232 do_neon_fmac (void)
14234 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14237 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14240 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14246 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14247 struct neon_type_el et = neon_check_type (3, rs,
14248 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
14249 neon_three_same (neon_quad (rs), 0, et.size);
14252 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
14253 same types as the MAC equivalents. The polynomial type for this instruction
14254 is encoded the same as the integer type. */
14259 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14262 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14265 if (inst.operands[2].isscalar)
14266 do_neon_mac_maybe_scalar ();
14268 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
14272 do_neon_qdmulh (void)
14274 if (inst.operands[2].isscalar)
14276 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
14277 struct neon_type_el et = neon_check_type (3, rs,
14278 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
14279 NEON_ENCODE (SCALAR, inst);
14280 neon_mul_mac (et, neon_quad (rs));
14284 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14285 struct neon_type_el et = neon_check_type (3, rs,
14286 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
14287 NEON_ENCODE (INTEGER, inst);
14288 /* The U bit (rounding) comes from bit mask. */
14289 neon_three_same (neon_quad (rs), 0, et.size);
14294 do_neon_fcmp_absolute (void)
14296 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14297 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14298 /* Size field comes from bit mask. */
14299 neon_three_same (neon_quad (rs), 1, -1);
14303 do_neon_fcmp_absolute_inv (void)
14305 neon_exchange_operands ();
14306 do_neon_fcmp_absolute ();
14310 do_neon_step (void)
14312 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14313 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14314 neon_three_same (neon_quad (rs), 0, -1);
14318 do_neon_abs_neg (void)
14320 enum neon_shape rs;
14321 struct neon_type_el et;
14323 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14326 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14329 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14330 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
14332 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14333 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14334 inst.instruction |= LOW4 (inst.operands[1].reg);
14335 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14336 inst.instruction |= neon_quad (rs) << 6;
14337 inst.instruction |= (et.type == NT_float) << 10;
14338 inst.instruction |= neon_logbits (et.size) << 18;
14340 neon_dp_fixup (&inst);
14346 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14347 struct neon_type_el et = neon_check_type (2, rs,
14348 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14349 int imm = inst.operands[2].imm;
14350 constraint (imm < 0 || (unsigned)imm >= et.size,
14351 _("immediate out of range for insert"));
14352 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14358 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14359 struct neon_type_el et = neon_check_type (2, rs,
14360 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14361 int imm = inst.operands[2].imm;
14362 constraint (imm < 1 || (unsigned)imm > et.size,
14363 _("immediate out of range for insert"));
14364 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
14368 do_neon_qshlu_imm (void)
14370 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14371 struct neon_type_el et = neon_check_type (2, rs,
14372 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14373 int imm = inst.operands[2].imm;
14374 constraint (imm < 0 || (unsigned)imm >= et.size,
14375 _("immediate out of range for shift"));
14376 /* Only encodes the 'U present' variant of the instruction.
14377 In this case, signed types have OP (bit 8) set to 0.
14378 Unsigned types have OP set to 1. */
14379 inst.instruction |= (et.type == NT_unsigned) << 8;
14380 /* The rest of the bits are the same as other immediate shifts. */
14381 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14385 do_neon_qmovn (void)
14387 struct neon_type_el et = neon_check_type (2, NS_DQ,
14388 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14389 /* Saturating move where operands can be signed or unsigned, and the
14390 destination has the same signedness. */
14391 NEON_ENCODE (INTEGER, inst);
14392 if (et.type == NT_unsigned)
14393 inst.instruction |= 0xc0;
14395 inst.instruction |= 0x80;
14396 neon_two_same (0, 1, et.size / 2);
14400 do_neon_qmovun (void)
14402 struct neon_type_el et = neon_check_type (2, NS_DQ,
14403 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14404 /* Saturating move with unsigned results. Operands must be signed. */
14405 NEON_ENCODE (INTEGER, inst);
14406 neon_two_same (0, 1, et.size / 2);
14410 do_neon_rshift_sat_narrow (void)
14412 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14413 or unsigned. If operands are unsigned, results must also be unsigned. */
14414 struct neon_type_el et = neon_check_type (2, NS_DQI,
14415 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14416 int imm = inst.operands[2].imm;
14417 /* This gets the bounds check, size encoding and immediate bits calculation
14421 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14422 VQMOVN.I<size> <Dd>, <Qm>. */
14425 inst.operands[2].present = 0;
14426 inst.instruction = N_MNEM_vqmovn;
14431 constraint (imm < 1 || (unsigned)imm > et.size,
14432 _("immediate out of range"));
14433 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14437 do_neon_rshift_sat_narrow_u (void)
14439 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14440 or unsigned. If operands are unsigned, results must also be unsigned. */
14441 struct neon_type_el et = neon_check_type (2, NS_DQI,
14442 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14443 int imm = inst.operands[2].imm;
14444 /* This gets the bounds check, size encoding and immediate bits calculation
14448 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14449 VQMOVUN.I<size> <Dd>, <Qm>. */
14452 inst.operands[2].present = 0;
14453 inst.instruction = N_MNEM_vqmovun;
14458 constraint (imm < 1 || (unsigned)imm > et.size,
14459 _("immediate out of range"));
14460 /* FIXME: The manual is kind of unclear about what value U should have in
14461 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14463 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14467 do_neon_movn (void)
14469 struct neon_type_el et = neon_check_type (2, NS_DQ,
14470 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14471 NEON_ENCODE (INTEGER, inst);
14472 neon_two_same (0, 1, et.size / 2);
14476 do_neon_rshift_narrow (void)
14478 struct neon_type_el et = neon_check_type (2, NS_DQI,
14479 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14480 int imm = inst.operands[2].imm;
14481 /* This gets the bounds check, size encoding and immediate bits calculation
14485 /* If immediate is zero then we are a pseudo-instruction for
14486 VMOVN.I<size> <Dd>, <Qm> */
14489 inst.operands[2].present = 0;
14490 inst.instruction = N_MNEM_vmovn;
14495 constraint (imm < 1 || (unsigned)imm > et.size,
14496 _("immediate out of range for narrowing operation"));
14497 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14501 do_neon_shll (void)
14503 /* FIXME: Type checking when lengthening. */
14504 struct neon_type_el et = neon_check_type (2, NS_QDI,
14505 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14506 unsigned imm = inst.operands[2].imm;
14508 if (imm == et.size)
14510 /* Maximum shift variant. */
14511 NEON_ENCODE (INTEGER, inst);
14512 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14513 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14514 inst.instruction |= LOW4 (inst.operands[1].reg);
14515 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14516 inst.instruction |= neon_logbits (et.size) << 18;
14518 neon_dp_fixup (&inst);
14522 /* A more-specific type check for non-max versions. */
14523 et = neon_check_type (2, NS_QDI,
14524 N_EQK | N_DBL, N_SU_32 | N_KEY);
14525 NEON_ENCODE (IMMED, inst);
14526 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14530 /* Check the various types for the VCVT instruction, and return which version
14531 the current instruction is. */
14533 #define CVT_FLAVOUR_VAR \
14534 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
14535 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
14536 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
14537 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
14538 /* Half-precision conversions. */ \
14539 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
14540 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
14541 /* VFP instructions. */ \
14542 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
14543 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
14544 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
14545 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
14546 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
14547 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
14548 /* VFP instructions with bitshift. */ \
14549 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
14550 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
14551 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
14552 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
14553 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
14554 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
14555 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
14556 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
14558 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
14559 neon_cvt_flavour_##C,
14561 /* The different types of conversions we can do. */
14562 enum neon_cvt_flavour
14565 neon_cvt_flavour_invalid,
14566 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
14571 static enum neon_cvt_flavour
14572 get_neon_cvt_flavour (enum neon_shape rs)
14574 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
14575 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
14576 if (et.type != NT_invtype) \
14578 inst.error = NULL; \
14579 return (neon_cvt_flavour_##C); \
14582 struct neon_type_el et;
14583 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14584 || rs == NS_FF) ? N_VFP : 0;
14585 /* The instruction versions which take an immediate take one register
14586 argument, which is extended to the width of the full register. Thus the
14587 "source" and "destination" registers must have the same width. Hack that
14588 here by making the size equal to the key (wider, in this case) operand. */
14589 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
14593 return neon_cvt_flavour_invalid;
14608 /* Neon-syntax VFP conversions. */
14611 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
14613 const char *opname = 0;
14615 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
14617 /* Conversions with immediate bitshift. */
14618 const char *enc[] =
14620 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
14626 if (flavour < (int) ARRAY_SIZE (enc))
14628 opname = enc[flavour];
14629 constraint (inst.operands[0].reg != inst.operands[1].reg,
14630 _("operands 0 and 1 must be the same register"));
14631 inst.operands[1] = inst.operands[2];
14632 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14637 /* Conversions without bitshift. */
14638 const char *enc[] =
14640 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
14646 if (flavour < (int) ARRAY_SIZE (enc))
14647 opname = enc[flavour];
14651 do_vfp_nsyn_opcode (opname);
14655 do_vfp_nsyn_cvtz (void)
14657 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14658 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
14659 const char *enc[] =
14661 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
14667 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14668 do_vfp_nsyn_opcode (enc[flavour]);
14672 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
14673 enum neon_cvt_mode mode)
14678 set_it_insn_type (OUTSIDE_IT_INSN);
14682 case neon_cvt_flavour_s32_f64:
14686 case neon_cvt_flavour_s32_f32:
14690 case neon_cvt_flavour_u32_f64:
14694 case neon_cvt_flavour_u32_f32:
14699 first_error (_("invalid instruction shape"));
14705 case neon_cvt_mode_a: rm = 0; break;
14706 case neon_cvt_mode_n: rm = 1; break;
14707 case neon_cvt_mode_p: rm = 2; break;
14708 case neon_cvt_mode_m: rm = 3; break;
14709 default: first_error (_("invalid rounding mode")); return;
14712 NEON_ENCODE (FPV8, inst);
14713 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14714 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
14715 inst.instruction |= sz << 8;
14716 inst.instruction |= op << 7;
14717 inst.instruction |= rm << 16;
14718 inst.instruction |= 0xf0000000;
14719 inst.is_neon = TRUE;
14723 do_neon_cvt_1 (enum neon_cvt_mode mode)
14725 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
14726 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
14727 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
14729 /* PR11109: Handle round-to-zero for VCVT conversions. */
14730 if (mode == neon_cvt_mode_z
14731 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14732 && (flavour == neon_cvt_flavour_s32_f32
14733 || flavour == neon_cvt_flavour_u32_f32
14734 || flavour == neon_cvt_flavour_s32_f64
14735 || flavour == neon_cvt_flavour_u32_f64)
14736 && (rs == NS_FD || rs == NS_FF))
14738 do_vfp_nsyn_cvtz ();
14742 /* VFP rather than Neon conversions. */
14743 if (flavour >= neon_cvt_flavour_first_fp)
14745 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
14746 do_vfp_nsyn_cvt (rs, flavour);
14748 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
14759 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14761 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14764 /* Fixed-point conversion with #0 immediate is encoded as an
14765 integer conversion. */
14766 if (inst.operands[2].present && inst.operands[2].imm == 0)
14768 immbits = 32 - inst.operands[2].imm;
14769 NEON_ENCODE (IMMED, inst);
14770 if (flavour != neon_cvt_flavour_invalid)
14771 inst.instruction |= enctab[flavour];
14772 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14773 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14774 inst.instruction |= LOW4 (inst.operands[1].reg);
14775 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14776 inst.instruction |= neon_quad (rs) << 6;
14777 inst.instruction |= 1 << 21;
14778 inst.instruction |= immbits << 16;
14780 neon_dp_fixup (&inst);
14786 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
14788 NEON_ENCODE (FLOAT, inst);
14789 set_it_insn_type (OUTSIDE_IT_INSN);
14791 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
14794 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14795 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14796 inst.instruction |= LOW4 (inst.operands[1].reg);
14797 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14798 inst.instruction |= neon_quad (rs) << 6;
14799 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
14800 inst.instruction |= mode << 8;
14802 inst.instruction |= 0xfc000000;
14804 inst.instruction |= 0xf0000000;
14810 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14812 NEON_ENCODE (INTEGER, inst);
14814 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14817 if (flavour != neon_cvt_flavour_invalid)
14818 inst.instruction |= enctab[flavour];
14820 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14821 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14822 inst.instruction |= LOW4 (inst.operands[1].reg);
14823 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14824 inst.instruction |= neon_quad (rs) << 6;
14825 inst.instruction |= 2 << 18;
14827 neon_dp_fixup (&inst);
14832 /* Half-precision conversions for Advanced SIMD -- neon. */
14837 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14839 as_bad (_("operand size must match register width"));
14844 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14846 as_bad (_("operand size must match register width"));
14851 inst.instruction = 0x3b60600;
14853 inst.instruction = 0x3b60700;
14855 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14856 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14857 inst.instruction |= LOW4 (inst.operands[1].reg);
14858 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14859 neon_dp_fixup (&inst);
14863 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14864 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
14865 do_vfp_nsyn_cvt (rs, flavour);
14867 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
14872 do_neon_cvtr (void)
14874 do_neon_cvt_1 (neon_cvt_mode_x);
14880 do_neon_cvt_1 (neon_cvt_mode_z);
14884 do_neon_cvta (void)
14886 do_neon_cvt_1 (neon_cvt_mode_a);
14890 do_neon_cvtn (void)
14892 do_neon_cvt_1 (neon_cvt_mode_n);
14896 do_neon_cvtp (void)
14898 do_neon_cvt_1 (neon_cvt_mode_p);
14902 do_neon_cvtm (void)
14904 do_neon_cvt_1 (neon_cvt_mode_m);
14908 do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
14911 mark_feature_used (&fpu_vfp_ext_armv8);
14913 encode_arm_vfp_reg (inst.operands[0].reg,
14914 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
14915 encode_arm_vfp_reg (inst.operands[1].reg,
14916 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
14917 inst.instruction |= to ? 0x10000 : 0;
14918 inst.instruction |= t ? 0x80 : 0;
14919 inst.instruction |= is_double ? 0x100 : 0;
14920 do_vfp_cond_or_thumb ();
14924 do_neon_cvttb_1 (bfd_boolean t)
14926 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL);
14930 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
14933 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
14935 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
14938 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
14940 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
14943 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
14945 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
14948 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
14955 do_neon_cvtb (void)
14957 do_neon_cvttb_1 (FALSE);
14962 do_neon_cvtt (void)
14964 do_neon_cvttb_1 (TRUE);
14968 neon_move_immediate (void)
14970 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14971 struct neon_type_el et = neon_check_type (2, rs,
14972 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
14973 unsigned immlo, immhi = 0, immbits;
14974 int op, cmode, float_p;
14976 constraint (et.type == NT_invtype,
14977 _("operand size must be specified for immediate VMOV"));
14979 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14980 op = (inst.instruction & (1 << 5)) != 0;
14982 immlo = inst.operands[1].imm;
14983 if (inst.operands[1].regisimm)
14984 immhi = inst.operands[1].reg;
14986 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14987 _("immediate has bits set outside the operand size"));
14989 float_p = inst.operands[1].immisfloat;
14991 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
14992 et.size, et.type)) == FAIL)
14994 /* Invert relevant bits only. */
14995 neon_invert_size (&immlo, &immhi, et.size);
14996 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14997 with one or the other; those cases are caught by
14998 neon_cmode_for_move_imm. */
15000 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15001 &op, et.size, et.type)) == FAIL)
15003 first_error (_("immediate out of range"));
15008 inst.instruction &= ~(1 << 5);
15009 inst.instruction |= op << 5;
15011 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15012 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15013 inst.instruction |= neon_quad (rs) << 6;
15014 inst.instruction |= cmode << 8;
15016 neon_write_immbits (immbits);
15022 if (inst.operands[1].isreg)
15024 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15026 NEON_ENCODE (INTEGER, inst);
15027 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15028 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15029 inst.instruction |= LOW4 (inst.operands[1].reg);
15030 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15031 inst.instruction |= neon_quad (rs) << 6;
15035 NEON_ENCODE (IMMED, inst);
15036 neon_move_immediate ();
15039 neon_dp_fixup (&inst);
15042 /* Encode instructions of form:
15044 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
15045 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
15048 neon_mixed_length (struct neon_type_el et, unsigned size)
15050 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15051 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15052 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15053 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15054 inst.instruction |= LOW4 (inst.operands[2].reg);
15055 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15056 inst.instruction |= (et.type == NT_unsigned) << 24;
15057 inst.instruction |= neon_logbits (size) << 20;
15059 neon_dp_fixup (&inst);
15063 do_neon_dyadic_long (void)
15065 /* FIXME: Type checking for lengthening op. */
15066 struct neon_type_el et = neon_check_type (3, NS_QDD,
15067 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15068 neon_mixed_length (et, et.size);
15072 do_neon_abal (void)
15074 struct neon_type_el et = neon_check_type (3, NS_QDD,
15075 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15076 neon_mixed_length (et, et.size);
15080 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15082 if (inst.operands[2].isscalar)
15084 struct neon_type_el et = neon_check_type (3, NS_QDS,
15085 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
15086 NEON_ENCODE (SCALAR, inst);
15087 neon_mul_mac (et, et.type == NT_unsigned);
15091 struct neon_type_el et = neon_check_type (3, NS_QDD,
15092 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
15093 NEON_ENCODE (INTEGER, inst);
15094 neon_mixed_length (et, et.size);
15099 do_neon_mac_maybe_scalar_long (void)
15101 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15105 do_neon_dyadic_wide (void)
15107 struct neon_type_el et = neon_check_type (3, NS_QQD,
15108 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15109 neon_mixed_length (et, et.size);
15113 do_neon_dyadic_narrow (void)
15115 struct neon_type_el et = neon_check_type (3, NS_QDD,
15116 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
15117 /* Operand sign is unimportant, and the U bit is part of the opcode,
15118 so force the operand type to integer. */
15119 et.type = NT_integer;
15120 neon_mixed_length (et, et.size / 2);
15124 do_neon_mul_sat_scalar_long (void)
15126 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15130 do_neon_vmull (void)
15132 if (inst.operands[2].isscalar)
15133 do_neon_mac_maybe_scalar_long ();
15136 struct neon_type_el et = neon_check_type (3, NS_QDD,
15137 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
15139 if (et.type == NT_poly)
15140 NEON_ENCODE (POLY, inst);
15142 NEON_ENCODE (INTEGER, inst);
15144 /* For polynomial encoding the U bit must be zero, and the size must
15145 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15146 obviously, as 0b10). */
15149 /* Check we're on the correct architecture. */
15150 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15152 _("Instruction form not available on this architecture.");
15157 neon_mixed_length (et, et.size);
15164 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
15165 struct neon_type_el et = neon_check_type (3, rs,
15166 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15167 unsigned imm = (inst.operands[3].imm * et.size) / 8;
15169 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
15170 _("shift out of range"));
15171 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15172 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15173 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15174 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15175 inst.instruction |= LOW4 (inst.operands[2].reg);
15176 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15177 inst.instruction |= neon_quad (rs) << 6;
15178 inst.instruction |= imm << 8;
15180 neon_dp_fixup (&inst);
15186 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15187 struct neon_type_el et = neon_check_type (2, rs,
15188 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15189 unsigned op = (inst.instruction >> 7) & 3;
15190 /* N (width of reversed regions) is encoded as part of the bitmask. We
15191 extract it here to check the elements to be reversed are smaller.
15192 Otherwise we'd get a reserved instruction. */
15193 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
15194 gas_assert (elsize != 0);
15195 constraint (et.size >= elsize,
15196 _("elements must be smaller than reversal region"));
15197 neon_two_same (neon_quad (rs), 1, et.size);
15203 if (inst.operands[1].isscalar)
15205 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
15206 struct neon_type_el et = neon_check_type (2, rs,
15207 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15208 unsigned sizebits = et.size >> 3;
15209 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
15210 int logsize = neon_logbits (et.size);
15211 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
15213 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
15216 NEON_ENCODE (SCALAR, inst);
15217 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15218 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15219 inst.instruction |= LOW4 (dm);
15220 inst.instruction |= HI1 (dm) << 5;
15221 inst.instruction |= neon_quad (rs) << 6;
15222 inst.instruction |= x << 17;
15223 inst.instruction |= sizebits << 16;
15225 neon_dp_fixup (&inst);
15229 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
15230 struct neon_type_el et = neon_check_type (2, rs,
15231 N_8 | N_16 | N_32 | N_KEY, N_EQK);
15232 /* Duplicate ARM register to lanes of vector. */
15233 NEON_ENCODE (ARMREG, inst);
15236 case 8: inst.instruction |= 0x400000; break;
15237 case 16: inst.instruction |= 0x000020; break;
15238 case 32: inst.instruction |= 0x000000; break;
15241 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15242 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
15243 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
15244 inst.instruction |= neon_quad (rs) << 21;
15245 /* The encoding for this instruction is identical for the ARM and Thumb
15246 variants, except for the condition field. */
15247 do_vfp_cond_or_thumb ();
15251 /* VMOV has particularly many variations. It can be one of:
15252 0. VMOV<c><q> <Qd>, <Qm>
15253 1. VMOV<c><q> <Dd>, <Dm>
15254 (Register operations, which are VORR with Rm = Rn.)
15255 2. VMOV<c><q>.<dt> <Qd>, #<imm>
15256 3. VMOV<c><q>.<dt> <Dd>, #<imm>
15258 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
15259 (ARM register to scalar.)
15260 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
15261 (Two ARM registers to vector.)
15262 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
15263 (Scalar to ARM register.)
15264 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
15265 (Vector to two ARM registers.)
15266 8. VMOV.F32 <Sd>, <Sm>
15267 9. VMOV.F64 <Dd>, <Dm>
15268 (VFP register moves.)
15269 10. VMOV.F32 <Sd>, #imm
15270 11. VMOV.F64 <Dd>, #imm
15271 (VFP float immediate load.)
15272 12. VMOV <Rd>, <Sm>
15273 (VFP single to ARM reg.)
15274 13. VMOV <Sd>, <Rm>
15275 (ARM reg to VFP single.)
15276 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
15277 (Two ARM regs to two VFP singles.)
15278 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
15279 (Two VFP singles to two ARM regs.)
15281 These cases can be disambiguated using neon_select_shape, except cases 1/9
15282 and 3/11 which depend on the operand type too.
15284 All the encoded bits are hardcoded by this function.
15286 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
15287 Cases 5, 7 may be used with VFPv2 and above.
15289 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
15290 can specify a type where it doesn't make sense to, and is ignored). */
15295 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
15296 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
15298 struct neon_type_el et;
15299 const char *ldconst = 0;
15303 case NS_DD: /* case 1/9. */
15304 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15305 /* It is not an error here if no type is given. */
15307 if (et.type == NT_float && et.size == 64)
15309 do_vfp_nsyn_opcode ("fcpyd");
15312 /* fall through. */
15314 case NS_QQ: /* case 0/1. */
15316 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15318 /* The architecture manual I have doesn't explicitly state which
15319 value the U bit should have for register->register moves, but
15320 the equivalent VORR instruction has U = 0, so do that. */
15321 inst.instruction = 0x0200110;
15322 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15323 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15324 inst.instruction |= LOW4 (inst.operands[1].reg);
15325 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15326 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15327 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15328 inst.instruction |= neon_quad (rs) << 6;
15330 neon_dp_fixup (&inst);
15334 case NS_DI: /* case 3/11. */
15335 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15337 if (et.type == NT_float && et.size == 64)
15339 /* case 11 (fconstd). */
15340 ldconst = "fconstd";
15341 goto encode_fconstd;
15343 /* fall through. */
15345 case NS_QI: /* case 2/3. */
15346 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15348 inst.instruction = 0x0800010;
15349 neon_move_immediate ();
15350 neon_dp_fixup (&inst);
15353 case NS_SR: /* case 4. */
15355 unsigned bcdebits = 0;
15357 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15358 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
15360 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15361 logsize = neon_logbits (et.size);
15363 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15365 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15366 && et.size != 32, _(BAD_FPU));
15367 constraint (et.type == NT_invtype, _("bad type for scalar"));
15368 constraint (x >= 64 / et.size, _("scalar index out of range"));
15372 case 8: bcdebits = 0x8; break;
15373 case 16: bcdebits = 0x1; break;
15374 case 32: bcdebits = 0x0; break;
15378 bcdebits |= x << logsize;
15380 inst.instruction = 0xe000b10;
15381 do_vfp_cond_or_thumb ();
15382 inst.instruction |= LOW4 (dn) << 16;
15383 inst.instruction |= HI1 (dn) << 7;
15384 inst.instruction |= inst.operands[1].reg << 12;
15385 inst.instruction |= (bcdebits & 3) << 5;
15386 inst.instruction |= (bcdebits >> 2) << 21;
15390 case NS_DRR: /* case 5 (fmdrr). */
15391 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15394 inst.instruction = 0xc400b10;
15395 do_vfp_cond_or_thumb ();
15396 inst.instruction |= LOW4 (inst.operands[0].reg);
15397 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15398 inst.instruction |= inst.operands[1].reg << 12;
15399 inst.instruction |= inst.operands[2].reg << 16;
15402 case NS_RS: /* case 6. */
15405 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15406 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15407 unsigned abcdebits = 0;
15409 et = neon_check_type (2, NS_NULL,
15410 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
15411 logsize = neon_logbits (et.size);
15413 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15415 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15416 && et.size != 32, _(BAD_FPU));
15417 constraint (et.type == NT_invtype, _("bad type for scalar"));
15418 constraint (x >= 64 / et.size, _("scalar index out of range"));
15422 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15423 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15424 case 32: abcdebits = 0x00; break;
15428 abcdebits |= x << logsize;
15429 inst.instruction = 0xe100b10;
15430 do_vfp_cond_or_thumb ();
15431 inst.instruction |= LOW4 (dn) << 16;
15432 inst.instruction |= HI1 (dn) << 7;
15433 inst.instruction |= inst.operands[0].reg << 12;
15434 inst.instruction |= (abcdebits & 3) << 5;
15435 inst.instruction |= (abcdebits >> 2) << 21;
15439 case NS_RRD: /* case 7 (fmrrd). */
15440 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15443 inst.instruction = 0xc500b10;
15444 do_vfp_cond_or_thumb ();
15445 inst.instruction |= inst.operands[0].reg << 12;
15446 inst.instruction |= inst.operands[1].reg << 16;
15447 inst.instruction |= LOW4 (inst.operands[2].reg);
15448 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15451 case NS_FF: /* case 8 (fcpys). */
15452 do_vfp_nsyn_opcode ("fcpys");
15455 case NS_FI: /* case 10 (fconsts). */
15456 ldconst = "fconsts";
15458 if (is_quarter_float (inst.operands[1].imm))
15460 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
15461 do_vfp_nsyn_opcode (ldconst);
15464 first_error (_("immediate out of range"));
15467 case NS_RF: /* case 12 (fmrs). */
15468 do_vfp_nsyn_opcode ("fmrs");
15471 case NS_FR: /* case 13 (fmsr). */
15472 do_vfp_nsyn_opcode ("fmsr");
15475 /* The encoders for the fmrrs and fmsrr instructions expect three operands
15476 (one of which is a list), but we have parsed four. Do some fiddling to
15477 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
15479 case NS_RRFF: /* case 14 (fmrrs). */
15480 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
15481 _("VFP registers must be adjacent"));
15482 inst.operands[2].imm = 2;
15483 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15484 do_vfp_nsyn_opcode ("fmrrs");
15487 case NS_FFRR: /* case 15 (fmsrr). */
15488 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
15489 _("VFP registers must be adjacent"));
15490 inst.operands[1] = inst.operands[2];
15491 inst.operands[2] = inst.operands[3];
15492 inst.operands[0].imm = 2;
15493 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15494 do_vfp_nsyn_opcode ("fmsrr");
15503 do_neon_rshift_round_imm (void)
15505 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15506 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15507 int imm = inst.operands[2].imm;
15509 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
15512 inst.operands[2].present = 0;
15517 constraint (imm < 1 || (unsigned)imm > et.size,
15518 _("immediate out of range for shift"));
15519 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
15524 do_neon_movl (void)
15526 struct neon_type_el et = neon_check_type (2, NS_QD,
15527 N_EQK | N_DBL, N_SU_32 | N_KEY);
15528 unsigned sizebits = et.size >> 3;
15529 inst.instruction |= sizebits << 19;
15530 neon_two_same (0, et.type == NT_unsigned, -1);
15536 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15537 struct neon_type_el et = neon_check_type (2, rs,
15538 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15539 NEON_ENCODE (INTEGER, inst);
15540 neon_two_same (neon_quad (rs), 1, et.size);
15544 do_neon_zip_uzp (void)
15546 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15547 struct neon_type_el et = neon_check_type (2, rs,
15548 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15549 if (rs == NS_DD && et.size == 32)
15551 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
15552 inst.instruction = N_MNEM_vtrn;
15556 neon_two_same (neon_quad (rs), 1, et.size);
15560 do_neon_sat_abs_neg (void)
15562 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15563 struct neon_type_el et = neon_check_type (2, rs,
15564 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
15565 neon_two_same (neon_quad (rs), 1, et.size);
15569 do_neon_pair_long (void)
15571 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15572 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15573 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15574 inst.instruction |= (et.type == NT_unsigned) << 7;
15575 neon_two_same (neon_quad (rs), 1, et.size);
15579 do_neon_recip_est (void)
15581 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15582 struct neon_type_el et = neon_check_type (2, rs,
15583 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15584 inst.instruction |= (et.type == NT_float) << 8;
15585 neon_two_same (neon_quad (rs), 1, et.size);
15591 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15592 struct neon_type_el et = neon_check_type (2, rs,
15593 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
15594 neon_two_same (neon_quad (rs), 1, et.size);
15600 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15601 struct neon_type_el et = neon_check_type (2, rs,
15602 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
15603 neon_two_same (neon_quad (rs), 1, et.size);
15609 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15610 struct neon_type_el et = neon_check_type (2, rs,
15611 N_EQK | N_INT, N_8 | N_KEY);
15612 neon_two_same (neon_quad (rs), 1, et.size);
15618 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15619 neon_two_same (neon_quad (rs), 1, -1);
15623 do_neon_tbl_tbx (void)
15625 unsigned listlenbits;
15626 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
15628 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15630 first_error (_("bad list length for table lookup"));
15634 listlenbits = inst.operands[1].imm - 1;
15635 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15636 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15637 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15638 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15639 inst.instruction |= LOW4 (inst.operands[2].reg);
15640 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15641 inst.instruction |= listlenbits << 8;
15643 neon_dp_fixup (&inst);
15647 do_neon_ldm_stm (void)
15649 /* P, U and L bits are part of bitmask. */
15650 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15651 unsigned offsetbits = inst.operands[1].imm * 2;
15653 if (inst.operands[1].issingle)
15655 do_vfp_nsyn_ldm_stm (is_dbmode);
15659 constraint (is_dbmode && !inst.operands[0].writeback,
15660 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15662 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15663 _("register list must contain at least 1 and at most 16 "
15666 inst.instruction |= inst.operands[0].reg << 16;
15667 inst.instruction |= inst.operands[0].writeback << 21;
15668 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15669 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15671 inst.instruction |= offsetbits;
15673 do_vfp_cond_or_thumb ();
15677 do_neon_ldr_str (void)
15679 int is_ldr = (inst.instruction & (1 << 20)) != 0;
15681 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15682 And is UNPREDICTABLE in thumb mode. */
15684 && inst.operands[1].reg == REG_PC
15685 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15687 if (!thumb_mode && warn_on_deprecated)
15688 as_warn (_("Use of PC here is deprecated"));
15690 inst.error = _("Use of PC here is UNPREDICTABLE");
15693 if (inst.operands[0].issingle)
15696 do_vfp_nsyn_opcode ("flds");
15698 do_vfp_nsyn_opcode ("fsts");
15703 do_vfp_nsyn_opcode ("fldd");
15705 do_vfp_nsyn_opcode ("fstd");
15709 /* "interleave" version also handles non-interleaving register VLD1/VST1
15713 do_neon_ld_st_interleave (void)
15715 struct neon_type_el et = neon_check_type (1, NS_NULL,
15716 N_8 | N_16 | N_32 | N_64);
15717 unsigned alignbits = 0;
15719 /* The bits in this table go:
15720 0: register stride of one (0) or two (1)
15721 1,2: register list length, minus one (1, 2, 3, 4).
15722 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15723 We use -1 for invalid entries. */
15724 const int typetable[] =
15726 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15727 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15728 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15729 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15733 if (et.type == NT_invtype)
15736 if (inst.operands[1].immisalign)
15737 switch (inst.operands[1].imm >> 8)
15739 case 64: alignbits = 1; break;
15741 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15742 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15743 goto bad_alignment;
15747 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15748 goto bad_alignment;
15753 first_error (_("bad alignment"));
15757 inst.instruction |= alignbits << 4;
15758 inst.instruction |= neon_logbits (et.size) << 6;
15760 /* Bits [4:6] of the immediate in a list specifier encode register stride
15761 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15762 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15763 up the right value for "type" in a table based on this value and the given
15764 list style, then stick it back. */
15765 idx = ((inst.operands[0].imm >> 4) & 7)
15766 | (((inst.instruction >> 8) & 3) << 3);
15768 typebits = typetable[idx];
15770 constraint (typebits == -1, _("bad list type for instruction"));
15772 inst.instruction &= ~0xf00;
15773 inst.instruction |= typebits << 8;
15776 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15777 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15778 otherwise. The variable arguments are a list of pairs of legal (size, align)
15779 values, terminated with -1. */
15782 neon_alignment_bit (int size, int align, int *do_align, ...)
15785 int result = FAIL, thissize, thisalign;
15787 if (!inst.operands[1].immisalign)
15793 va_start (ap, do_align);
15797 thissize = va_arg (ap, int);
15798 if (thissize == -1)
15800 thisalign = va_arg (ap, int);
15802 if (size == thissize && align == thisalign)
15805 while (result != SUCCESS);
15809 if (result == SUCCESS)
15812 first_error (_("unsupported alignment for instruction"));
15818 do_neon_ld_st_lane (void)
15820 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15821 int align_good, do_align = 0;
15822 int logsize = neon_logbits (et.size);
15823 int align = inst.operands[1].imm >> 8;
15824 int n = (inst.instruction >> 8) & 3;
15825 int max_el = 64 / et.size;
15827 if (et.type == NT_invtype)
15830 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15831 _("bad list length"));
15832 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15833 _("scalar index out of range"));
15834 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15836 _("stride of 2 unavailable when element size is 8"));
15840 case 0: /* VLD1 / VST1. */
15841 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15843 if (align_good == FAIL)
15847 unsigned alignbits = 0;
15850 case 16: alignbits = 0x1; break;
15851 case 32: alignbits = 0x3; break;
15854 inst.instruction |= alignbits << 4;
15858 case 1: /* VLD2 / VST2. */
15859 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15861 if (align_good == FAIL)
15864 inst.instruction |= 1 << 4;
15867 case 2: /* VLD3 / VST3. */
15868 constraint (inst.operands[1].immisalign,
15869 _("can't use alignment with this instruction"));
15872 case 3: /* VLD4 / VST4. */
15873 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15874 16, 64, 32, 64, 32, 128, -1);
15875 if (align_good == FAIL)
15879 unsigned alignbits = 0;
15882 case 8: alignbits = 0x1; break;
15883 case 16: alignbits = 0x1; break;
15884 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15887 inst.instruction |= alignbits << 4;
15894 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15895 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15896 inst.instruction |= 1 << (4 + logsize);
15898 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15899 inst.instruction |= logsize << 10;
15902 /* Encode single n-element structure to all lanes VLD<n> instructions. */
15905 do_neon_ld_dup (void)
15907 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15908 int align_good, do_align = 0;
15910 if (et.type == NT_invtype)
15913 switch ((inst.instruction >> 8) & 3)
15915 case 0: /* VLD1. */
15916 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
15917 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15918 &do_align, 16, 16, 32, 32, -1);
15919 if (align_good == FAIL)
15921 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15924 case 2: inst.instruction |= 1 << 5; break;
15925 default: first_error (_("bad list length")); return;
15927 inst.instruction |= neon_logbits (et.size) << 6;
15930 case 1: /* VLD2. */
15931 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15932 &do_align, 8, 16, 16, 32, 32, 64, -1);
15933 if (align_good == FAIL)
15935 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15936 _("bad list length"));
15937 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15938 inst.instruction |= 1 << 5;
15939 inst.instruction |= neon_logbits (et.size) << 6;
15942 case 2: /* VLD3. */
15943 constraint (inst.operands[1].immisalign,
15944 _("can't use alignment with this instruction"));
15945 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15946 _("bad list length"));
15947 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15948 inst.instruction |= 1 << 5;
15949 inst.instruction |= neon_logbits (et.size) << 6;
15952 case 3: /* VLD4. */
15954 int align = inst.operands[1].imm >> 8;
15955 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15956 16, 64, 32, 64, 32, 128, -1);
15957 if (align_good == FAIL)
15959 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15960 _("bad list length"));
15961 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15962 inst.instruction |= 1 << 5;
15963 if (et.size == 32 && align == 128)
15964 inst.instruction |= 0x3 << 6;
15966 inst.instruction |= neon_logbits (et.size) << 6;
15973 inst.instruction |= do_align << 4;
15976 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15977 apart from bits [11:4]. */
15980 do_neon_ldx_stx (void)
15982 if (inst.operands[1].isreg)
15983 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15985 switch (NEON_LANE (inst.operands[0].imm))
15987 case NEON_INTERLEAVE_LANES:
15988 NEON_ENCODE (INTERLV, inst);
15989 do_neon_ld_st_interleave ();
15992 case NEON_ALL_LANES:
15993 NEON_ENCODE (DUP, inst);
15998 NEON_ENCODE (LANE, inst);
15999 do_neon_ld_st_lane ();
16002 /* L bit comes from bit mask. */
16003 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16004 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16005 inst.instruction |= inst.operands[1].reg << 16;
16007 if (inst.operands[1].postind)
16009 int postreg = inst.operands[1].imm & 0xf;
16010 constraint (!inst.operands[1].immisreg,
16011 _("post-index must be a register"));
16012 constraint (postreg == 0xd || postreg == 0xf,
16013 _("bad register for post-index"));
16014 inst.instruction |= postreg;
16016 else if (inst.operands[1].writeback)
16018 inst.instruction |= 0xd;
16021 inst.instruction |= 0xf;
16024 inst.instruction |= 0xf9000000;
16026 inst.instruction |= 0xf4000000;
16031 do_vfp_nsyn_fpv8 (enum neon_shape rs)
16033 NEON_ENCODE (FPV8, inst);
16036 do_vfp_sp_dyadic ();
16038 do_vfp_dp_rd_rn_rm ();
16041 inst.instruction |= 0x100;
16043 inst.instruction |= 0xf0000000;
16049 set_it_insn_type (OUTSIDE_IT_INSN);
16051 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16052 first_error (_("invalid instruction shape"));
16058 set_it_insn_type (OUTSIDE_IT_INSN);
16060 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16063 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16066 neon_dyadic_misc (NT_untyped, N_F32, 0);
16070 do_vrint_1 (enum neon_cvt_mode mode)
16072 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL);
16073 struct neon_type_el et;
16078 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
16079 if (et.type != NT_invtype)
16081 /* VFP encodings. */
16082 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
16083 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
16084 set_it_insn_type (OUTSIDE_IT_INSN);
16086 NEON_ENCODE (FPV8, inst);
16088 do_vfp_sp_monadic ();
16090 do_vfp_dp_rd_rm ();
16094 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
16095 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
16096 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
16097 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
16098 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
16099 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
16100 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
16104 inst.instruction |= (rs == NS_DD) << 8;
16105 do_vfp_cond_or_thumb ();
16109 /* Neon encodings (or something broken...). */
16111 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
16113 if (et.type == NT_invtype)
16116 set_it_insn_type (OUTSIDE_IT_INSN);
16117 NEON_ENCODE (FLOAT, inst);
16119 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16122 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16123 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16124 inst.instruction |= LOW4 (inst.operands[1].reg);
16125 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16126 inst.instruction |= neon_quad (rs) << 6;
16129 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
16130 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
16131 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
16132 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
16133 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
16134 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
16135 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
16140 inst.instruction |= 0xfc000000;
16142 inst.instruction |= 0xf0000000;
16149 do_vrint_1 (neon_cvt_mode_x);
16155 do_vrint_1 (neon_cvt_mode_z);
16161 do_vrint_1 (neon_cvt_mode_r);
16167 do_vrint_1 (neon_cvt_mode_a);
16173 do_vrint_1 (neon_cvt_mode_n);
16179 do_vrint_1 (neon_cvt_mode_p);
16185 do_vrint_1 (neon_cvt_mode_m);
16188 /* Crypto v1 instructions. */
16190 do_crypto_2op_1 (unsigned elttype, int op)
16192 set_it_insn_type (OUTSIDE_IT_INSN);
16194 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
16200 NEON_ENCODE (INTEGER, inst);
16201 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16202 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16203 inst.instruction |= LOW4 (inst.operands[1].reg);
16204 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16206 inst.instruction |= op << 6;
16209 inst.instruction |= 0xfc000000;
16211 inst.instruction |= 0xf0000000;
16215 do_crypto_3op_1 (int u, int op)
16217 set_it_insn_type (OUTSIDE_IT_INSN);
16219 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
16220 N_32 | N_UNT | N_KEY).type == NT_invtype)
16225 NEON_ENCODE (INTEGER, inst);
16226 neon_three_same (1, u, 8 << op);
16232 do_crypto_2op_1 (N_8, 0);
16238 do_crypto_2op_1 (N_8, 1);
16244 do_crypto_2op_1 (N_8, 2);
16250 do_crypto_2op_1 (N_8, 3);
16256 do_crypto_3op_1 (0, 0);
16262 do_crypto_3op_1 (0, 1);
16268 do_crypto_3op_1 (0, 2);
16274 do_crypto_3op_1 (0, 3);
16280 do_crypto_3op_1 (1, 0);
16286 do_crypto_3op_1 (1, 1);
16290 do_sha256su1 (void)
16292 do_crypto_3op_1 (1, 2);
16298 do_crypto_2op_1 (N_32, -1);
16304 do_crypto_2op_1 (N_32, 0);
16308 do_sha256su0 (void)
16310 do_crypto_2op_1 (N_32, 1);
16313 /* Overall per-instruction processing. */
16315 /* We need to be able to fix up arbitrary expressions in some statements.
16316 This is so that we can handle symbols that are an arbitrary distance from
16317 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
16318 which returns part of an address in a form which will be valid for
16319 a data instruction. We do this by pushing the expression into a symbol
16320 in the expr_section, and creating a fix for that. */
16323 fix_new_arm (fragS * frag,
16337 /* Create an absolute valued symbol, so we have something to
16338 refer to in the object file. Unfortunately for us, gas's
16339 generic expression parsing will already have folded out
16340 any use of .set foo/.type foo %function that may have
16341 been used to set type information of the target location,
16342 that's being specified symbolically. We have to presume
16343 the user knows what they are doing. */
16347 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
16349 symbol = symbol_find_or_make (name);
16350 S_SET_SEGMENT (symbol, absolute_section);
16351 symbol_set_frag (symbol, &zero_address_frag);
16352 S_SET_VALUE (symbol, exp->X_add_number);
16353 exp->X_op = O_symbol;
16354 exp->X_add_symbol = symbol;
16355 exp->X_add_number = 0;
16361 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
16362 (enum bfd_reloc_code_real) reloc);
16366 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
16367 pc_rel, (enum bfd_reloc_code_real) reloc);
16371 /* Mark whether the fix is to a THUMB instruction, or an ARM
16373 new_fix->tc_fix_data = thumb_mode;
16376 /* Create a frg for an instruction requiring relaxation. */
16378 output_relax_insn (void)
16384 /* The size of the instruction is unknown, so tie the debug info to the
16385 start of the instruction. */
16386 dwarf2_emit_insn (0);
16388 switch (inst.reloc.exp.X_op)
16391 sym = inst.reloc.exp.X_add_symbol;
16392 offset = inst.reloc.exp.X_add_number;
16396 offset = inst.reloc.exp.X_add_number;
16399 sym = make_expr_symbol (&inst.reloc.exp);
16403 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
16404 inst.relax, sym, offset, NULL/*offset, opcode*/);
16405 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
16408 /* Write a 32-bit thumb instruction to buf. */
16410 put_thumb32_insn (char * buf, unsigned long insn)
16412 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
16413 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
16417 output_inst (const char * str)
16423 as_bad ("%s -- `%s'", inst.error, str);
16428 output_relax_insn ();
16431 if (inst.size == 0)
16434 to = frag_more (inst.size);
16435 /* PR 9814: Record the thumb mode into the current frag so that we know
16436 what type of NOP padding to use, if necessary. We override any previous
16437 setting so that if the mode has changed then the NOPS that we use will
16438 match the encoding of the last instruction in the frag. */
16439 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
16441 if (thumb_mode && (inst.size > THUMB_SIZE))
16443 gas_assert (inst.size == (2 * THUMB_SIZE));
16444 put_thumb32_insn (to, inst.instruction);
16446 else if (inst.size > INSN_SIZE)
16448 gas_assert (inst.size == (2 * INSN_SIZE));
16449 md_number_to_chars (to, inst.instruction, INSN_SIZE);
16450 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
16453 md_number_to_chars (to, inst.instruction, inst.size);
16455 if (inst.reloc.type != BFD_RELOC_UNUSED)
16456 fix_new_arm (frag_now, to - frag_now->fr_literal,
16457 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
16460 dwarf2_emit_insn (inst.size);
16464 output_it_inst (int cond, int mask, char * to)
16466 unsigned long instruction = 0xbf00;
16469 instruction |= mask;
16470 instruction |= cond << 4;
16474 to = frag_more (2);
16476 dwarf2_emit_insn (2);
16480 md_number_to_chars (to, instruction, 2);
16485 /* Tag values used in struct asm_opcode's tag field. */
16488 OT_unconditional, /* Instruction cannot be conditionalized.
16489 The ARM condition field is still 0xE. */
16490 OT_unconditionalF, /* Instruction cannot be conditionalized
16491 and carries 0xF in its ARM condition field. */
16492 OT_csuffix, /* Instruction takes a conditional suffix. */
16493 OT_csuffixF, /* Some forms of the instruction take a conditional
16494 suffix, others place 0xF where the condition field
16496 OT_cinfix3, /* Instruction takes a conditional infix,
16497 beginning at character index 3. (In
16498 unified mode, it becomes a suffix.) */
16499 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
16500 tsts, cmps, cmns, and teqs. */
16501 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
16502 character index 3, even in unified mode. Used for
16503 legacy instructions where suffix and infix forms
16504 may be ambiguous. */
16505 OT_csuf_or_in3, /* Instruction takes either a conditional
16506 suffix or an infix at character index 3. */
16507 OT_odd_infix_unc, /* This is the unconditional variant of an
16508 instruction that takes a conditional infix
16509 at an unusual position. In unified mode,
16510 this variant will accept a suffix. */
16511 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
16512 are the conditional variants of instructions that
16513 take conditional infixes in unusual positions.
16514 The infix appears at character index
16515 (tag - OT_odd_infix_0). These are not accepted
16516 in unified mode. */
16519 /* Subroutine of md_assemble, responsible for looking up the primary
16520 opcode from the mnemonic the user wrote. STR points to the
16521 beginning of the mnemonic.
16523 This is not simply a hash table lookup, because of conditional
16524 variants. Most instructions have conditional variants, which are
16525 expressed with a _conditional affix_ to the mnemonic. If we were
16526 to encode each conditional variant as a literal string in the opcode
16527 table, it would have approximately 20,000 entries.
16529 Most mnemonics take this affix as a suffix, and in unified syntax,
16530 'most' is upgraded to 'all'. However, in the divided syntax, some
16531 instructions take the affix as an infix, notably the s-variants of
16532 the arithmetic instructions. Of those instructions, all but six
16533 have the infix appear after the third character of the mnemonic.
16535 Accordingly, the algorithm for looking up primary opcodes given
16538 1. Look up the identifier in the opcode table.
16539 If we find a match, go to step U.
16541 2. Look up the last two characters of the identifier in the
16542 conditions table. If we find a match, look up the first N-2
16543 characters of the identifier in the opcode table. If we
16544 find a match, go to step CE.
16546 3. Look up the fourth and fifth characters of the identifier in
16547 the conditions table. If we find a match, extract those
16548 characters from the identifier, and look up the remaining
16549 characters in the opcode table. If we find a match, go
16554 U. Examine the tag field of the opcode structure, in case this is
16555 one of the six instructions with its conditional infix in an
16556 unusual place. If it is, the tag tells us where to find the
16557 infix; look it up in the conditions table and set inst.cond
16558 accordingly. Otherwise, this is an unconditional instruction.
16559 Again set inst.cond accordingly. Return the opcode structure.
16561 CE. Examine the tag field to make sure this is an instruction that
16562 should receive a conditional suffix. If it is not, fail.
16563 Otherwise, set inst.cond from the suffix we already looked up,
16564 and return the opcode structure.
16566 CM. Examine the tag field to make sure this is an instruction that
16567 should receive a conditional infix after the third character.
16568 If it is not, fail. Otherwise, undo the edits to the current
16569 line of input and proceed as for case CE. */
16571 static const struct asm_opcode *
16572 opcode_lookup (char **str)
16576 const struct asm_opcode *opcode;
16577 const struct asm_cond *cond;
16580 /* Scan up to the end of the mnemonic, which must end in white space,
16581 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
16582 for (base = end = *str; *end != '\0'; end++)
16583 if (*end == ' ' || *end == '.')
16589 /* Handle a possible width suffix and/or Neon type suffix. */
16594 /* The .w and .n suffixes are only valid if the unified syntax is in
16596 if (unified_syntax && end[1] == 'w')
16598 else if (unified_syntax && end[1] == 'n')
16603 inst.vectype.elems = 0;
16605 *str = end + offset;
16607 if (end[offset] == '.')
16609 /* See if we have a Neon type suffix (possible in either unified or
16610 non-unified ARM syntax mode). */
16611 if (parse_neon_type (&inst.vectype, str) == FAIL)
16614 else if (end[offset] != '\0' && end[offset] != ' ')
16620 /* Look for unaffixed or special-case affixed mnemonic. */
16621 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16626 if (opcode->tag < OT_odd_infix_0)
16628 inst.cond = COND_ALWAYS;
16632 if (warn_on_deprecated && unified_syntax)
16633 as_warn (_("conditional infixes are deprecated in unified syntax"));
16634 affix = base + (opcode->tag - OT_odd_infix_0);
16635 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16638 inst.cond = cond->value;
16642 /* Cannot have a conditional suffix on a mnemonic of less than two
16644 if (end - base < 3)
16647 /* Look for suffixed mnemonic. */
16649 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16650 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16652 if (opcode && cond)
16655 switch (opcode->tag)
16657 case OT_cinfix3_legacy:
16658 /* Ignore conditional suffixes matched on infix only mnemonics. */
16662 case OT_cinfix3_deprecated:
16663 case OT_odd_infix_unc:
16664 if (!unified_syntax)
16666 /* else fall through */
16670 case OT_csuf_or_in3:
16671 inst.cond = cond->value;
16674 case OT_unconditional:
16675 case OT_unconditionalF:
16677 inst.cond = cond->value;
16680 /* Delayed diagnostic. */
16681 inst.error = BAD_COND;
16682 inst.cond = COND_ALWAYS;
16691 /* Cannot have a usual-position infix on a mnemonic of less than
16692 six characters (five would be a suffix). */
16693 if (end - base < 6)
16696 /* Look for infixed mnemonic in the usual position. */
16698 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16702 memcpy (save, affix, 2);
16703 memmove (affix, affix + 2, (end - affix) - 2);
16704 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16706 memmove (affix + 2, affix, (end - affix) - 2);
16707 memcpy (affix, save, 2);
16710 && (opcode->tag == OT_cinfix3
16711 || opcode->tag == OT_cinfix3_deprecated
16712 || opcode->tag == OT_csuf_or_in3
16713 || opcode->tag == OT_cinfix3_legacy))
16716 if (warn_on_deprecated && unified_syntax
16717 && (opcode->tag == OT_cinfix3
16718 || opcode->tag == OT_cinfix3_deprecated))
16719 as_warn (_("conditional infixes are deprecated in unified syntax"));
16721 inst.cond = cond->value;
16728 /* This function generates an initial IT instruction, leaving its block
16729 virtually open for the new instructions. Eventually,
16730 the mask will be updated by now_it_add_mask () each time
16731 a new instruction needs to be included in the IT block.
16732 Finally, the block is closed with close_automatic_it_block ().
16733 The block closure can be requested either from md_assemble (),
16734 a tencode (), or due to a label hook. */
16737 new_automatic_it_block (int cond)
16739 now_it.state = AUTOMATIC_IT_BLOCK;
16740 now_it.mask = 0x18;
16742 now_it.block_length = 1;
16743 mapping_state (MAP_THUMB);
16744 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
16745 now_it.warn_deprecated = FALSE;
16746 now_it.insn_cond = TRUE;
16749 /* Close an automatic IT block.
16750 See comments in new_automatic_it_block (). */
16753 close_automatic_it_block (void)
16755 now_it.mask = 0x10;
16756 now_it.block_length = 0;
16759 /* Update the mask of the current automatically-generated IT
16760 instruction. See comments in new_automatic_it_block (). */
16763 now_it_add_mask (int cond)
16765 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
16766 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
16767 | ((bitvalue) << (nbit)))
16768 const int resulting_bit = (cond & 1);
16770 now_it.mask &= 0xf;
16771 now_it.mask = SET_BIT_VALUE (now_it.mask,
16773 (5 - now_it.block_length));
16774 now_it.mask = SET_BIT_VALUE (now_it.mask,
16776 ((5 - now_it.block_length) - 1) );
16777 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
16780 #undef SET_BIT_VALUE
16783 /* The IT blocks handling machinery is accessed through the these functions:
16784 it_fsm_pre_encode () from md_assemble ()
16785 set_it_insn_type () optional, from the tencode functions
16786 set_it_insn_type_last () ditto
16787 in_it_block () ditto
16788 it_fsm_post_encode () from md_assemble ()
16789 force_automatic_it_block_close () from label habdling functions
16792 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
16793 initializing the IT insn type with a generic initial value depending
16794 on the inst.condition.
16795 2) During the tencode function, two things may happen:
16796 a) The tencode function overrides the IT insn type by
16797 calling either set_it_insn_type (type) or set_it_insn_type_last ().
16798 b) The tencode function queries the IT block state by
16799 calling in_it_block () (i.e. to determine narrow/not narrow mode).
16801 Both set_it_insn_type and in_it_block run the internal FSM state
16802 handling function (handle_it_state), because: a) setting the IT insn
16803 type may incur in an invalid state (exiting the function),
16804 and b) querying the state requires the FSM to be updated.
16805 Specifically we want to avoid creating an IT block for conditional
16806 branches, so it_fsm_pre_encode is actually a guess and we can't
16807 determine whether an IT block is required until the tencode () routine
16808 has decided what type of instruction this actually it.
16809 Because of this, if set_it_insn_type and in_it_block have to be used,
16810 set_it_insn_type has to be called first.
16812 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
16813 determines the insn IT type depending on the inst.cond code.
16814 When a tencode () routine encodes an instruction that can be
16815 either outside an IT block, or, in the case of being inside, has to be
16816 the last one, set_it_insn_type_last () will determine the proper
16817 IT instruction type based on the inst.cond code. Otherwise,
16818 set_it_insn_type can be called for overriding that logic or
16819 for covering other cases.
16821 Calling handle_it_state () may not transition the IT block state to
16822 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
16823 still queried. Instead, if the FSM determines that the state should
16824 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
16825 after the tencode () function: that's what it_fsm_post_encode () does.
16827 Since in_it_block () calls the state handling function to get an
16828 updated state, an error may occur (due to invalid insns combination).
16829 In that case, inst.error is set.
16830 Therefore, inst.error has to be checked after the execution of
16831 the tencode () routine.
16833 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
16834 any pending state change (if any) that didn't take place in
16835 handle_it_state () as explained above. */
16838 it_fsm_pre_encode (void)
16840 if (inst.cond != COND_ALWAYS)
16841 inst.it_insn_type = INSIDE_IT_INSN;
16843 inst.it_insn_type = OUTSIDE_IT_INSN;
16845 now_it.state_handled = 0;
16848 /* IT state FSM handling function. */
16851 handle_it_state (void)
16853 now_it.state_handled = 1;
16854 now_it.insn_cond = FALSE;
16856 switch (now_it.state)
16858 case OUTSIDE_IT_BLOCK:
16859 switch (inst.it_insn_type)
16861 case OUTSIDE_IT_INSN:
16864 case INSIDE_IT_INSN:
16865 case INSIDE_IT_LAST_INSN:
16866 if (thumb_mode == 0)
16869 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
16870 as_tsktsk (_("Warning: conditional outside an IT block"\
16875 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
16876 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
16878 /* Automatically generate the IT instruction. */
16879 new_automatic_it_block (inst.cond);
16880 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
16881 close_automatic_it_block ();
16885 inst.error = BAD_OUT_IT;
16891 case IF_INSIDE_IT_LAST_INSN:
16892 case NEUTRAL_IT_INSN:
16896 now_it.state = MANUAL_IT_BLOCK;
16897 now_it.block_length = 0;
16902 case AUTOMATIC_IT_BLOCK:
16903 /* Three things may happen now:
16904 a) We should increment current it block size;
16905 b) We should close current it block (closing insn or 4 insns);
16906 c) We should close current it block and start a new one (due
16907 to incompatible conditions or
16908 4 insns-length block reached). */
16910 switch (inst.it_insn_type)
16912 case OUTSIDE_IT_INSN:
16913 /* The closure of the block shall happen immediatelly,
16914 so any in_it_block () call reports the block as closed. */
16915 force_automatic_it_block_close ();
16918 case INSIDE_IT_INSN:
16919 case INSIDE_IT_LAST_INSN:
16920 case IF_INSIDE_IT_LAST_INSN:
16921 now_it.block_length++;
16923 if (now_it.block_length > 4
16924 || !now_it_compatible (inst.cond))
16926 force_automatic_it_block_close ();
16927 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16928 new_automatic_it_block (inst.cond);
16932 now_it.insn_cond = TRUE;
16933 now_it_add_mask (inst.cond);
16936 if (now_it.state == AUTOMATIC_IT_BLOCK
16937 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16938 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16939 close_automatic_it_block ();
16942 case NEUTRAL_IT_INSN:
16943 now_it.block_length++;
16944 now_it.insn_cond = TRUE;
16946 if (now_it.block_length > 4)
16947 force_automatic_it_block_close ();
16949 now_it_add_mask (now_it.cc & 1);
16953 close_automatic_it_block ();
16954 now_it.state = MANUAL_IT_BLOCK;
16959 case MANUAL_IT_BLOCK:
16961 /* Check conditional suffixes. */
16962 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16965 now_it.mask &= 0x1f;
16966 is_last = (now_it.mask == 0x10);
16967 now_it.insn_cond = TRUE;
16969 switch (inst.it_insn_type)
16971 case OUTSIDE_IT_INSN:
16972 inst.error = BAD_NOT_IT;
16975 case INSIDE_IT_INSN:
16976 if (cond != inst.cond)
16978 inst.error = BAD_IT_COND;
16983 case INSIDE_IT_LAST_INSN:
16984 case IF_INSIDE_IT_LAST_INSN:
16985 if (cond != inst.cond)
16987 inst.error = BAD_IT_COND;
16992 inst.error = BAD_BRANCH;
16997 case NEUTRAL_IT_INSN:
16998 /* The BKPT instruction is unconditional even in an IT block. */
17002 inst.error = BAD_IT_IT;
17012 struct depr_insn_mask
17014 unsigned long pattern;
17015 unsigned long mask;
17016 const char* description;
17019 /* List of 16-bit instruction patterns deprecated in an IT block in
17021 static const struct depr_insn_mask depr_it_insns[] = {
17022 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
17023 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
17024 { 0xa000, 0xb800, N_("ADR") },
17025 { 0x4800, 0xf800, N_("Literal loads") },
17026 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
17027 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
17032 it_fsm_post_encode (void)
17036 if (!now_it.state_handled)
17037 handle_it_state ();
17039 if (now_it.insn_cond
17040 && !now_it.warn_deprecated
17041 && warn_on_deprecated
17042 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
17044 if (inst.instruction >= 0x10000)
17046 as_warn (_("it blocks containing wide Thumb instructions are "
17047 "deprecated in ARMv8"));
17048 now_it.warn_deprecated = TRUE;
17052 const struct depr_insn_mask *p = depr_it_insns;
17054 while (p->mask != 0)
17056 if ((inst.instruction & p->mask) == p->pattern)
17058 as_warn (_("it blocks containing 16-bit Thumb intsructions "
17059 "of the following class are deprecated in ARMv8: "
17060 "%s"), p->description);
17061 now_it.warn_deprecated = TRUE;
17069 if (now_it.block_length > 1)
17071 as_warn (_("it blocks of more than one conditional instruction are "
17072 "deprecated in ARMv8"));
17073 now_it.warn_deprecated = TRUE;
17077 is_last = (now_it.mask == 0x10);
17080 now_it.state = OUTSIDE_IT_BLOCK;
17086 force_automatic_it_block_close (void)
17088 if (now_it.state == AUTOMATIC_IT_BLOCK)
17090 close_automatic_it_block ();
17091 now_it.state = OUTSIDE_IT_BLOCK;
17099 if (!now_it.state_handled)
17100 handle_it_state ();
17102 return now_it.state != OUTSIDE_IT_BLOCK;
17106 md_assemble (char *str)
17109 const struct asm_opcode * opcode;
17111 /* Align the previous label if needed. */
17112 if (last_label_seen != NULL)
17114 symbol_set_frag (last_label_seen, frag_now);
17115 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
17116 S_SET_SEGMENT (last_label_seen, now_seg);
17119 memset (&inst, '\0', sizeof (inst));
17120 inst.reloc.type = BFD_RELOC_UNUSED;
17122 opcode = opcode_lookup (&p);
17125 /* It wasn't an instruction, but it might be a register alias of
17126 the form alias .req reg, or a Neon .dn/.qn directive. */
17127 if (! create_register_alias (str, p)
17128 && ! create_neon_reg_alias (str, p))
17129 as_bad (_("bad instruction `%s'"), str);
17134 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
17135 as_warn (_("s suffix on comparison instruction is deprecated"));
17137 /* The value which unconditional instructions should have in place of the
17138 condition field. */
17139 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
17143 arm_feature_set variant;
17145 variant = cpu_variant;
17146 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
17147 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
17148 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
17149 /* Check that this instruction is supported for this CPU. */
17150 if (!opcode->tvariant
17151 || (thumb_mode == 1
17152 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
17154 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
17157 if (inst.cond != COND_ALWAYS && !unified_syntax
17158 && opcode->tencode != do_t_branch)
17160 as_bad (_("Thumb does not support conditional execution"));
17164 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
17166 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
17167 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
17168 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
17170 /* Two things are addressed here.
17171 1) Implicit require narrow instructions on Thumb-1.
17172 This avoids relaxation accidentally introducing Thumb-2
17174 2) Reject wide instructions in non Thumb-2 cores. */
17175 if (inst.size_req == 0)
17177 else if (inst.size_req == 4)
17179 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
17185 inst.instruction = opcode->tvalue;
17187 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
17189 /* Prepare the it_insn_type for those encodings that don't set
17191 it_fsm_pre_encode ();
17193 opcode->tencode ();
17195 it_fsm_post_encode ();
17198 if (!(inst.error || inst.relax))
17200 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
17201 inst.size = (inst.instruction > 0xffff ? 4 : 2);
17202 if (inst.size_req && inst.size_req != inst.size)
17204 as_bad (_("cannot honor width suffix -- `%s'"), str);
17209 /* Something has gone badly wrong if we try to relax a fixed size
17211 gas_assert (inst.size_req == 0 || !inst.relax);
17213 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17214 *opcode->tvariant);
17215 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
17216 set those bits when Thumb-2 32-bit instructions are seen. ie.
17217 anything other than bl/blx and v6-M instructions.
17218 This is overly pessimistic for relaxable instructions. */
17219 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
17221 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
17222 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
17223 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17226 check_neon_suffixes;
17230 mapping_state (MAP_THUMB);
17233 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
17237 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
17238 is_bx = (opcode->aencode == do_bx);
17240 /* Check that this instruction is supported for this CPU. */
17241 if (!(is_bx && fix_v4bx)
17242 && !(opcode->avariant &&
17243 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
17245 as_bad (_("selected processor does not support ARM mode `%s'"), str);
17250 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
17254 inst.instruction = opcode->avalue;
17255 if (opcode->tag == OT_unconditionalF)
17256 inst.instruction |= 0xF << 28;
17258 inst.instruction |= inst.cond << 28;
17259 inst.size = INSN_SIZE;
17260 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
17262 it_fsm_pre_encode ();
17263 opcode->aencode ();
17264 it_fsm_post_encode ();
17266 /* Arm mode bx is marked as both v4T and v5 because it's still required
17267 on a hypothetical non-thumb v5 core. */
17269 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
17271 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
17272 *opcode->avariant);
17274 check_neon_suffixes;
17278 mapping_state (MAP_ARM);
17283 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
17291 check_it_blocks_finished (void)
17296 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
17297 if (seg_info (sect)->tc_segment_info_data.current_it.state
17298 == MANUAL_IT_BLOCK)
17300 as_warn (_("section '%s' finished with an open IT block."),
17304 if (now_it.state == MANUAL_IT_BLOCK)
17305 as_warn (_("file finished with an open IT block."));
17309 /* Various frobbings of labels and their addresses. */
17312 arm_start_line_hook (void)
17314 last_label_seen = NULL;
17318 arm_frob_label (symbolS * sym)
17320 last_label_seen = sym;
17322 ARM_SET_THUMB (sym, thumb_mode);
17324 #if defined OBJ_COFF || defined OBJ_ELF
17325 ARM_SET_INTERWORK (sym, support_interwork);
17328 force_automatic_it_block_close ();
17330 /* Note - do not allow local symbols (.Lxxx) to be labelled
17331 as Thumb functions. This is because these labels, whilst
17332 they exist inside Thumb code, are not the entry points for
17333 possible ARM->Thumb calls. Also, these labels can be used
17334 as part of a computed goto or switch statement. eg gcc
17335 can generate code that looks like this:
17337 ldr r2, [pc, .Laaa]
17347 The first instruction loads the address of the jump table.
17348 The second instruction converts a table index into a byte offset.
17349 The third instruction gets the jump address out of the table.
17350 The fourth instruction performs the jump.
17352 If the address stored at .Laaa is that of a symbol which has the
17353 Thumb_Func bit set, then the linker will arrange for this address
17354 to have the bottom bit set, which in turn would mean that the
17355 address computation performed by the third instruction would end
17356 up with the bottom bit set. Since the ARM is capable of unaligned
17357 word loads, the instruction would then load the incorrect address
17358 out of the jump table, and chaos would ensue. */
17359 if (label_is_thumb_function_name
17360 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
17361 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
17363 /* When the address of a Thumb function is taken the bottom
17364 bit of that address should be set. This will allow
17365 interworking between Arm and Thumb functions to work
17368 THUMB_SET_FUNC (sym, 1);
17370 label_is_thumb_function_name = FALSE;
17373 dwarf2_emit_label (sym);
17377 arm_data_in_code (void)
17379 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
17381 *input_line_pointer = '/';
17382 input_line_pointer += 5;
17383 *input_line_pointer = 0;
17391 arm_canonicalize_symbol_name (char * name)
17395 if (thumb_mode && (len = strlen (name)) > 5
17396 && streq (name + len - 5, "/data"))
17397 *(name + len - 5) = 0;
17402 /* Table of all register names defined by default. The user can
17403 define additional names with .req. Note that all register names
17404 should appear in both upper and lowercase variants. Some registers
17405 also have mixed-case names. */
17407 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
17408 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
17409 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
17410 #define REGSET(p,t) \
17411 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
17412 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
17413 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
17414 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
17415 #define REGSETH(p,t) \
17416 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
17417 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
17418 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
17419 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
17420 #define REGSET2(p,t) \
17421 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
17422 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
17423 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
17424 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
17425 #define SPLRBANK(base,bank,t) \
17426 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
17427 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
17428 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
17429 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
17430 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
17431 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
17433 static const struct reg_entry reg_names[] =
17435 /* ARM integer registers. */
17436 REGSET(r, RN), REGSET(R, RN),
17438 /* ATPCS synonyms. */
17439 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
17440 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
17441 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
17443 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
17444 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
17445 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
17447 /* Well-known aliases. */
17448 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
17449 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
17451 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
17452 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
17454 /* Coprocessor numbers. */
17455 REGSET(p, CP), REGSET(P, CP),
17457 /* Coprocessor register numbers. The "cr" variants are for backward
17459 REGSET(c, CN), REGSET(C, CN),
17460 REGSET(cr, CN), REGSET(CR, CN),
17462 /* ARM banked registers. */
17463 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
17464 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
17465 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
17466 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
17467 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
17468 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
17469 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
17471 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
17472 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
17473 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
17474 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
17475 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
17476 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
17477 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
17478 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
17480 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
17481 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
17482 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
17483 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
17484 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
17485 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
17486 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
17487 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
17488 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
17490 /* FPA registers. */
17491 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
17492 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
17494 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
17495 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
17497 /* VFP SP registers. */
17498 REGSET(s,VFS), REGSET(S,VFS),
17499 REGSETH(s,VFS), REGSETH(S,VFS),
17501 /* VFP DP Registers. */
17502 REGSET(d,VFD), REGSET(D,VFD),
17503 /* Extra Neon DP registers. */
17504 REGSETH(d,VFD), REGSETH(D,VFD),
17506 /* Neon QP registers. */
17507 REGSET2(q,NQ), REGSET2(Q,NQ),
17509 /* VFP control registers. */
17510 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
17511 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
17512 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
17513 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
17514 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
17515 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
17517 /* Maverick DSP coprocessor registers. */
17518 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
17519 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
17521 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
17522 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
17523 REGDEF(dspsc,0,DSPSC),
17525 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
17526 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
17527 REGDEF(DSPSC,0,DSPSC),
17529 /* iWMMXt data registers - p0, c0-15. */
17530 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
17532 /* iWMMXt control registers - p1, c0-3. */
17533 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
17534 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
17535 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
17536 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
17538 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
17539 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
17540 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
17541 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
17542 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
17544 /* XScale accumulator registers. */
17545 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
17551 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
17552 within psr_required_here. */
17553 static const struct asm_psr psrs[] =
17555 /* Backward compatibility notation. Note that "all" is no longer
17556 truly all possible PSR bits. */
17557 {"all", PSR_c | PSR_f},
17561 /* Individual flags. */
17567 /* Combinations of flags. */
17568 {"fs", PSR_f | PSR_s},
17569 {"fx", PSR_f | PSR_x},
17570 {"fc", PSR_f | PSR_c},
17571 {"sf", PSR_s | PSR_f},
17572 {"sx", PSR_s | PSR_x},
17573 {"sc", PSR_s | PSR_c},
17574 {"xf", PSR_x | PSR_f},
17575 {"xs", PSR_x | PSR_s},
17576 {"xc", PSR_x | PSR_c},
17577 {"cf", PSR_c | PSR_f},
17578 {"cs", PSR_c | PSR_s},
17579 {"cx", PSR_c | PSR_x},
17580 {"fsx", PSR_f | PSR_s | PSR_x},
17581 {"fsc", PSR_f | PSR_s | PSR_c},
17582 {"fxs", PSR_f | PSR_x | PSR_s},
17583 {"fxc", PSR_f | PSR_x | PSR_c},
17584 {"fcs", PSR_f | PSR_c | PSR_s},
17585 {"fcx", PSR_f | PSR_c | PSR_x},
17586 {"sfx", PSR_s | PSR_f | PSR_x},
17587 {"sfc", PSR_s | PSR_f | PSR_c},
17588 {"sxf", PSR_s | PSR_x | PSR_f},
17589 {"sxc", PSR_s | PSR_x | PSR_c},
17590 {"scf", PSR_s | PSR_c | PSR_f},
17591 {"scx", PSR_s | PSR_c | PSR_x},
17592 {"xfs", PSR_x | PSR_f | PSR_s},
17593 {"xfc", PSR_x | PSR_f | PSR_c},
17594 {"xsf", PSR_x | PSR_s | PSR_f},
17595 {"xsc", PSR_x | PSR_s | PSR_c},
17596 {"xcf", PSR_x | PSR_c | PSR_f},
17597 {"xcs", PSR_x | PSR_c | PSR_s},
17598 {"cfs", PSR_c | PSR_f | PSR_s},
17599 {"cfx", PSR_c | PSR_f | PSR_x},
17600 {"csf", PSR_c | PSR_s | PSR_f},
17601 {"csx", PSR_c | PSR_s | PSR_x},
17602 {"cxf", PSR_c | PSR_x | PSR_f},
17603 {"cxs", PSR_c | PSR_x | PSR_s},
17604 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
17605 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
17606 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
17607 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
17608 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
17609 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
17610 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
17611 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
17612 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
17613 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
17614 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
17615 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
17616 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
17617 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
17618 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
17619 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
17620 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
17621 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
17622 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
17623 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
17624 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
17625 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
17626 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
17627 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
17630 /* Table of V7M psr names. */
17631 static const struct asm_psr v7m_psrs[] =
17633 {"apsr", 0 }, {"APSR", 0 },
17634 {"iapsr", 1 }, {"IAPSR", 1 },
17635 {"eapsr", 2 }, {"EAPSR", 2 },
17636 {"psr", 3 }, {"PSR", 3 },
17637 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
17638 {"ipsr", 5 }, {"IPSR", 5 },
17639 {"epsr", 6 }, {"EPSR", 6 },
17640 {"iepsr", 7 }, {"IEPSR", 7 },
17641 {"msp", 8 }, {"MSP", 8 },
17642 {"psp", 9 }, {"PSP", 9 },
17643 {"primask", 16}, {"PRIMASK", 16},
17644 {"basepri", 17}, {"BASEPRI", 17},
17645 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
17646 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
17647 {"faultmask", 19}, {"FAULTMASK", 19},
17648 {"control", 20}, {"CONTROL", 20}
17651 /* Table of all shift-in-operand names. */
17652 static const struct asm_shift_name shift_names [] =
17654 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
17655 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
17656 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
17657 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
17658 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
17659 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
17662 /* Table of all explicit relocation names. */
17664 static struct reloc_entry reloc_names[] =
17666 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
17667 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
17668 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
17669 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
17670 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
17671 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
17672 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
17673 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
17674 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
17675 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
17676 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
17677 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
17678 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
17679 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
17680 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
17681 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
17682 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
17683 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
17687 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
17688 static const struct asm_cond conds[] =
17692 {"cs", 0x2}, {"hs", 0x2},
17693 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
17707 #define UL_BARRIER(L,U,CODE,FEAT) \
17708 { L, CODE, ARM_FEATURE (FEAT, 0) }, \
17709 { U, CODE, ARM_FEATURE (FEAT, 0) }
17711 static struct asm_barrier_opt barrier_opt_names[] =
17713 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
17714 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
17715 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
17716 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
17717 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
17718 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
17719 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
17720 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
17721 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
17722 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
17723 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
17724 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
17725 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
17726 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
17727 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
17728 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
17733 /* Table of ARM-format instructions. */
17735 /* Macros for gluing together operand strings. N.B. In all cases
17736 other than OPS0, the trailing OP_stop comes from default
17737 zero-initialization of the unspecified elements of the array. */
17738 #define OPS0() { OP_stop, }
17739 #define OPS1(a) { OP_##a, }
17740 #define OPS2(a,b) { OP_##a,OP_##b, }
17741 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
17742 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
17743 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
17744 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
17746 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
17747 This is useful when mixing operands for ARM and THUMB, i.e. using the
17748 MIX_ARM_THUMB_OPERANDS macro.
17749 In order to use these macros, prefix the number of operands with _
17751 #define OPS_1(a) { a, }
17752 #define OPS_2(a,b) { a,b, }
17753 #define OPS_3(a,b,c) { a,b,c, }
17754 #define OPS_4(a,b,c,d) { a,b,c,d, }
17755 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
17756 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
17758 /* These macros abstract out the exact format of the mnemonic table and
17759 save some repeated characters. */
17761 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
17762 #define TxCE(mnem, op, top, nops, ops, ae, te) \
17763 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
17764 THUMB_VARIANT, do_##ae, do_##te }
17766 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
17767 a T_MNEM_xyz enumerator. */
17768 #define TCE(mnem, aop, top, nops, ops, ae, te) \
17769 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
17770 #define tCE(mnem, aop, top, nops, ops, ae, te) \
17771 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17773 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
17774 infix after the third character. */
17775 #define TxC3(mnem, op, top, nops, ops, ae, te) \
17776 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
17777 THUMB_VARIANT, do_##ae, do_##te }
17778 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
17779 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
17780 THUMB_VARIANT, do_##ae, do_##te }
17781 #define TC3(mnem, aop, top, nops, ops, ae, te) \
17782 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
17783 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
17784 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
17785 #define tC3(mnem, aop, top, nops, ops, ae, te) \
17786 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17787 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
17788 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17790 /* Mnemonic that cannot be conditionalized. The ARM condition-code
17791 field is still 0xE. Many of the Thumb variants can be executed
17792 conditionally, so this is checked separately. */
17793 #define TUE(mnem, op, top, nops, ops, ae, te) \
17794 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
17795 THUMB_VARIANT, do_##ae, do_##te }
17797 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
17798 condition code field. */
17799 #define TUF(mnem, op, top, nops, ops, ae, te) \
17800 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
17801 THUMB_VARIANT, do_##ae, do_##te }
17803 /* ARM-only variants of all the above. */
17804 #define CE(mnem, op, nops, ops, ae) \
17805 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17807 #define C3(mnem, op, nops, ops, ae) \
17808 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17810 /* Legacy mnemonics that always have conditional infix after the third
17812 #define CL(mnem, op, nops, ops, ae) \
17813 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
17814 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17816 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
17817 #define cCE(mnem, op, nops, ops, ae) \
17818 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17820 /* Legacy coprocessor instructions where conditional infix and conditional
17821 suffix are ambiguous. For consistency this includes all FPA instructions,
17822 not just the potentially ambiguous ones. */
17823 #define cCL(mnem, op, nops, ops, ae) \
17824 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
17825 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17827 /* Coprocessor, takes either a suffix or a position-3 infix
17828 (for an FPA corner case). */
17829 #define C3E(mnem, op, nops, ops, ae) \
17830 { mnem, OPS##nops ops, OT_csuf_or_in3, \
17831 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17833 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
17834 { m1 #m2 m3, OPS##nops ops, \
17835 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
17836 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17838 #define CM(m1, m2, op, nops, ops, ae) \
17839 xCM_ (m1, , m2, op, nops, ops, ae), \
17840 xCM_ (m1, eq, m2, op, nops, ops, ae), \
17841 xCM_ (m1, ne, m2, op, nops, ops, ae), \
17842 xCM_ (m1, cs, m2, op, nops, ops, ae), \
17843 xCM_ (m1, hs, m2, op, nops, ops, ae), \
17844 xCM_ (m1, cc, m2, op, nops, ops, ae), \
17845 xCM_ (m1, ul, m2, op, nops, ops, ae), \
17846 xCM_ (m1, lo, m2, op, nops, ops, ae), \
17847 xCM_ (m1, mi, m2, op, nops, ops, ae), \
17848 xCM_ (m1, pl, m2, op, nops, ops, ae), \
17849 xCM_ (m1, vs, m2, op, nops, ops, ae), \
17850 xCM_ (m1, vc, m2, op, nops, ops, ae), \
17851 xCM_ (m1, hi, m2, op, nops, ops, ae), \
17852 xCM_ (m1, ls, m2, op, nops, ops, ae), \
17853 xCM_ (m1, ge, m2, op, nops, ops, ae), \
17854 xCM_ (m1, lt, m2, op, nops, ops, ae), \
17855 xCM_ (m1, gt, m2, op, nops, ops, ae), \
17856 xCM_ (m1, le, m2, op, nops, ops, ae), \
17857 xCM_ (m1, al, m2, op, nops, ops, ae)
17859 #define UE(mnem, op, nops, ops, ae) \
17860 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17862 #define UF(mnem, op, nops, ops, ae) \
17863 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17865 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
17866 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
17867 use the same encoding function for each. */
17868 #define NUF(mnem, op, nops, ops, enc) \
17869 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
17870 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17872 /* Neon data processing, version which indirects through neon_enc_tab for
17873 the various overloaded versions of opcodes. */
17874 #define nUF(mnem, op, nops, ops, enc) \
17875 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
17876 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17878 /* Neon insn with conditional suffix for the ARM version, non-overloaded
17880 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
17881 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
17882 THUMB_VARIANT, do_##enc, do_##enc }
17884 #define NCE(mnem, op, nops, ops, enc) \
17885 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
17887 #define NCEF(mnem, op, nops, ops, enc) \
17888 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
17890 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
17891 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
17892 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
17893 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17895 #define nCE(mnem, op, nops, ops, enc) \
17896 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
17898 #define nCEF(mnem, op, nops, ops, enc) \
17899 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
17903 static const struct asm_opcode insns[] =
17905 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
17906 #define THUMB_VARIANT &arm_ext_v4t
17907 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
17908 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
17909 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
17910 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
17911 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
17912 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
17913 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
17914 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
17915 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
17916 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
17917 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
17918 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
17919 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
17920 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
17921 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
17922 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
17924 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
17925 for setting PSR flag bits. They are obsolete in V6 and do not
17926 have Thumb equivalents. */
17927 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17928 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17929 CL("tstp", 110f000, 2, (RR, SH), cmp),
17930 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17931 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17932 CL("cmpp", 150f000, 2, (RR, SH), cmp),
17933 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17934 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17935 CL("cmnp", 170f000, 2, (RR, SH), cmp),
17937 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
17938 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
17939 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
17940 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
17942 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
17943 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17944 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
17946 OP_ADDRGLDR),ldst, t_ldst),
17947 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17949 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17950 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17951 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17952 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17953 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17954 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17956 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
17957 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
17958 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
17959 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
17962 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
17963 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
17964 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
17966 /* Thumb-compatibility pseudo ops. */
17967 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17968 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17969 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17970 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17971 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17972 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17973 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17974 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17975 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17976 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17977 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17978 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
17980 /* These may simplify to neg. */
17981 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17982 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
17984 #undef THUMB_VARIANT
17985 #define THUMB_VARIANT & arm_ext_v6
17987 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
17989 /* V1 instructions with no Thumb analogue prior to V6T2. */
17990 #undef THUMB_VARIANT
17991 #define THUMB_VARIANT & arm_ext_v6t2
17993 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17994 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17995 CL("teqp", 130f000, 2, (RR, SH), cmp),
17997 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17998 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17999 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
18000 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18002 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18003 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18005 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18006 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18008 /* V1 instructions with no Thumb analogue at all. */
18009 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
18010 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
18012 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
18013 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
18014 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
18015 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
18016 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
18017 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
18018 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
18019 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
18022 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
18023 #undef THUMB_VARIANT
18024 #define THUMB_VARIANT & arm_ext_v4t
18026 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18027 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18029 #undef THUMB_VARIANT
18030 #define THUMB_VARIANT & arm_ext_v6t2
18032 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
18033 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
18035 /* Generic coprocessor instructions. */
18036 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18037 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18038 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18039 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18040 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18041 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18042 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
18045 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
18047 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18048 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18051 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
18052 #undef THUMB_VARIANT
18053 #define THUMB_VARIANT & arm_ext_msr
18055 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
18056 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
18059 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
18060 #undef THUMB_VARIANT
18061 #define THUMB_VARIANT & arm_ext_v6t2
18063 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18064 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18065 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18066 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18067 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18068 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18069 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18070 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18073 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
18074 #undef THUMB_VARIANT
18075 #define THUMB_VARIANT & arm_ext_v4t
18077 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18078 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18079 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18080 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18081 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18082 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18085 #define ARM_VARIANT & arm_ext_v4t_5
18087 /* ARM Architecture 4T. */
18088 /* Note: bx (and blx) are required on V5, even if the processor does
18089 not support Thumb. */
18090 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
18093 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
18094 #undef THUMB_VARIANT
18095 #define THUMB_VARIANT & arm_ext_v5t
18097 /* Note: blx has 2 variants; the .value coded here is for
18098 BLX(2). Only this variant has conditional execution. */
18099 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
18100 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
18102 #undef THUMB_VARIANT
18103 #define THUMB_VARIANT & arm_ext_v6t2
18105 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
18106 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18107 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18108 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18109 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18110 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18111 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18112 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18115 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
18116 #undef THUMB_VARIANT
18117 #define THUMB_VARIANT &arm_ext_v5exp
18119 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18120 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18121 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18122 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18124 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18125 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18127 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18128 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18129 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18130 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18132 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18133 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18134 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18135 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18137 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18138 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18140 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18141 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18142 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18143 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18146 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
18147 #undef THUMB_VARIANT
18148 #define THUMB_VARIANT &arm_ext_v6t2
18150 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
18151 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
18153 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
18154 ADDRGLDRS), ldrd, t_ldstd),
18156 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18157 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18160 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
18162 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
18165 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
18166 #undef THUMB_VARIANT
18167 #define THUMB_VARIANT & arm_ext_v6
18169 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
18170 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
18171 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18172 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18173 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18174 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18175 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18176 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18177 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18178 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
18180 #undef THUMB_VARIANT
18181 #define THUMB_VARIANT & arm_ext_v6t2
18183 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
18184 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18186 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18187 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18189 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
18190 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
18192 /* ARM V6 not included in V7M. */
18193 #undef THUMB_VARIANT
18194 #define THUMB_VARIANT & arm_ext_v6_notm
18195 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
18196 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
18197 UF(rfeib, 9900a00, 1, (RRw), rfe),
18198 UF(rfeda, 8100a00, 1, (RRw), rfe),
18199 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18200 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
18201 UF(rfefa, 8100a00, 1, (RRw), rfe),
18202 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18203 UF(rfeed, 9900a00, 1, (RRw), rfe),
18204 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18205 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18206 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18207 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
18208 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
18209 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
18210 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
18211 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
18212 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
18214 /* ARM V6 not included in V7M (eg. integer SIMD). */
18215 #undef THUMB_VARIANT
18216 #define THUMB_VARIANT & arm_ext_v6_dsp
18217 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
18218 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
18219 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
18220 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18221 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18222 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18223 /* Old name for QASX. */
18224 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18225 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18226 /* Old name for QSAX. */
18227 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18228 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18229 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18230 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18231 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18232 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18233 /* Old name for SASX. */
18234 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18235 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18236 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18237 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18238 /* Old name for SHASX. */
18239 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18240 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18241 /* Old name for SHSAX. */
18242 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18243 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18244 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18245 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18246 /* Old name for SSAX. */
18247 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18248 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18249 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18250 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18251 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18252 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18253 /* Old name for UASX. */
18254 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18255 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18256 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18257 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18258 /* Old name for UHASX. */
18259 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18260 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18261 /* Old name for UHSAX. */
18262 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18263 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18264 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18265 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18266 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18267 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18268 /* Old name for UQASX. */
18269 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18270 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18271 /* Old name for UQSAX. */
18272 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18273 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18274 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18275 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18276 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18277 /* Old name for USAX. */
18278 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18279 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18280 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18281 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18282 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18283 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18284 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18285 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18286 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18287 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18288 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18289 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18290 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18291 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18292 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18293 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18294 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18295 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18296 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18297 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18298 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18299 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18300 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18301 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18302 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18303 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18304 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18305 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18306 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18307 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
18308 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
18309 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18310 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18311 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
18314 #define ARM_VARIANT & arm_ext_v6k
18315 #undef THUMB_VARIANT
18316 #define THUMB_VARIANT & arm_ext_v6k
18318 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
18319 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
18320 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
18321 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
18323 #undef THUMB_VARIANT
18324 #define THUMB_VARIANT & arm_ext_v6_notm
18325 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
18327 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
18328 RRnpcb), strexd, t_strexd),
18330 #undef THUMB_VARIANT
18331 #define THUMB_VARIANT & arm_ext_v6t2
18332 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
18334 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
18336 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18338 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18340 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
18343 #define ARM_VARIANT & arm_ext_sec
18344 #undef THUMB_VARIANT
18345 #define THUMB_VARIANT & arm_ext_sec
18347 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
18350 #define ARM_VARIANT & arm_ext_virt
18351 #undef THUMB_VARIANT
18352 #define THUMB_VARIANT & arm_ext_virt
18354 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
18355 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
18358 #define ARM_VARIANT & arm_ext_v6t2
18359 #undef THUMB_VARIANT
18360 #define THUMB_VARIANT & arm_ext_v6t2
18362 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
18363 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
18364 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
18365 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
18367 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
18368 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
18369 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
18370 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
18372 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18373 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18374 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18375 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18377 /* Thumb-only instructions. */
18379 #define ARM_VARIANT NULL
18380 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
18381 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
18383 /* ARM does not really have an IT instruction, so always allow it.
18384 The opcode is copied from Thumb in order to allow warnings in
18385 -mimplicit-it=[never | arm] modes. */
18387 #define ARM_VARIANT & arm_ext_v1
18389 TUE("it", bf08, bf08, 1, (COND), it, t_it),
18390 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
18391 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
18392 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
18393 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
18394 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
18395 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
18396 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
18397 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
18398 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
18399 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
18400 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
18401 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
18402 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
18403 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
18404 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
18405 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
18406 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
18408 /* Thumb2 only instructions. */
18410 #define ARM_VARIANT NULL
18412 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
18413 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
18414 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
18415 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
18416 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
18417 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
18419 /* Hardware division instructions. */
18421 #define ARM_VARIANT & arm_ext_adiv
18422 #undef THUMB_VARIANT
18423 #define THUMB_VARIANT & arm_ext_div
18425 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
18426 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
18428 /* ARM V6M/V7 instructions. */
18430 #define ARM_VARIANT & arm_ext_barrier
18431 #undef THUMB_VARIANT
18432 #define THUMB_VARIANT & arm_ext_barrier
18434 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
18435 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
18436 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
18438 /* ARM V7 instructions. */
18440 #define ARM_VARIANT & arm_ext_v7
18441 #undef THUMB_VARIANT
18442 #define THUMB_VARIANT & arm_ext_v7
18444 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
18445 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
18448 #define ARM_VARIANT & arm_ext_mp
18449 #undef THUMB_VARIANT
18450 #define THUMB_VARIANT & arm_ext_mp
18452 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
18454 /* AArchv8 instructions. */
18456 #define ARM_VARIANT & arm_ext_v8
18457 #undef THUMB_VARIANT
18458 #define THUMB_VARIANT & arm_ext_v8
18460 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
18461 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
18462 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18463 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
18465 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
18466 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18467 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
18469 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
18471 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
18473 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
18475 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18476 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18477 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18478 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
18479 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
18480 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
18482 /* ARMv8 T32 only. */
18484 #define ARM_VARIANT NULL
18485 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
18486 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
18487 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
18489 /* FP for ARMv8. */
18491 #define ARM_VARIANT & fpu_vfp_ext_armv8
18492 #undef THUMB_VARIANT
18493 #define THUMB_VARIANT & fpu_vfp_ext_armv8
18495 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
18496 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
18497 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
18498 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
18499 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
18500 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
18501 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
18502 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
18503 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
18504 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
18505 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
18506 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
18507 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
18508 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
18509 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
18510 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
18511 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
18513 /* Crypto v1 extensions. */
18515 #define ARM_VARIANT & fpu_crypto_ext_armv8
18516 #undef THUMB_VARIANT
18517 #define THUMB_VARIANT & fpu_crypto_ext_armv8
18519 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
18520 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
18521 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
18522 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
18523 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
18524 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
18525 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
18526 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
18527 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
18528 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
18529 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
18530 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
18531 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
18532 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
18535 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
18536 #undef THUMB_VARIANT
18537 #define THUMB_VARIANT NULL
18539 cCE("wfs", e200110, 1, (RR), rd),
18540 cCE("rfs", e300110, 1, (RR), rd),
18541 cCE("wfc", e400110, 1, (RR), rd),
18542 cCE("rfc", e500110, 1, (RR), rd),
18544 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
18545 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
18546 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
18547 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
18549 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
18550 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
18551 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
18552 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
18554 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
18555 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
18556 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
18557 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
18558 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
18559 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
18560 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
18561 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
18562 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
18563 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
18564 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
18565 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
18567 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
18568 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
18569 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
18570 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
18571 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
18572 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
18573 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
18574 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
18575 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
18576 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
18577 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
18578 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
18580 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
18581 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
18582 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
18583 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
18584 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
18585 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
18586 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
18587 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
18588 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
18589 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
18590 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
18591 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
18593 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
18594 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
18595 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
18596 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
18597 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
18598 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
18599 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
18600 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
18601 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
18602 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
18603 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
18604 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
18606 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
18607 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
18608 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
18609 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
18610 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
18611 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
18612 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
18613 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
18614 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
18615 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
18616 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
18617 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
18619 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
18620 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
18621 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
18622 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
18623 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
18624 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
18625 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
18626 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
18627 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
18628 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
18629 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
18630 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
18632 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
18633 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
18634 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
18635 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
18636 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
18637 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
18638 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
18639 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
18640 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
18641 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
18642 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
18643 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
18645 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
18646 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
18647 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
18648 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
18649 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
18650 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
18651 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
18652 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
18653 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
18654 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
18655 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
18656 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
18658 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
18659 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
18660 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
18661 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
18662 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
18663 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
18664 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
18665 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
18666 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
18667 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
18668 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
18669 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
18671 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
18672 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
18673 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
18674 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
18675 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
18676 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
18677 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
18678 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
18679 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
18680 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
18681 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
18682 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
18684 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
18685 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
18686 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
18687 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
18688 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
18689 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
18690 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
18691 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
18692 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
18693 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
18694 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
18695 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
18697 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
18698 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
18699 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
18700 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
18701 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
18702 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
18703 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
18704 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
18705 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
18706 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
18707 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
18708 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
18710 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
18711 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
18712 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
18713 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
18714 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
18715 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
18716 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
18717 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
18718 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
18719 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
18720 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
18721 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
18723 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
18724 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
18725 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
18726 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
18727 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
18728 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
18729 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
18730 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
18731 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
18732 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
18733 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
18734 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
18736 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
18737 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
18738 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
18739 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
18740 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
18741 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
18742 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
18743 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
18744 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
18745 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
18746 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
18747 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
18749 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
18750 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
18751 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
18752 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
18753 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
18754 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
18755 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
18756 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
18757 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
18758 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
18759 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
18760 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
18762 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
18763 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
18764 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
18765 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
18766 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
18767 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18768 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18769 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18770 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
18771 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
18772 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
18773 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
18775 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
18776 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
18777 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
18778 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
18779 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
18780 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18781 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18782 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18783 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
18784 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
18785 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
18786 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
18788 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
18789 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
18790 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
18791 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
18792 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
18793 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18794 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18795 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18796 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
18797 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
18798 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
18799 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
18801 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
18802 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
18803 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
18804 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
18805 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
18806 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18807 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18808 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18809 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
18810 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
18811 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
18812 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
18814 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
18815 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
18816 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
18817 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
18818 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
18819 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18820 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18821 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18822 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
18823 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
18824 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
18825 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
18827 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
18828 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
18829 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
18830 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
18831 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
18832 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18833 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18834 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18835 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
18836 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
18837 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
18838 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
18840 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
18841 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
18842 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
18843 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
18844 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
18845 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18846 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18847 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18848 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
18849 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
18850 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
18851 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
18853 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
18854 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
18855 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
18856 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
18857 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
18858 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18859 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18860 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18861 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
18862 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
18863 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
18864 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
18866 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
18867 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
18868 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
18869 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
18870 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
18871 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18872 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18873 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18874 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
18875 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
18876 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
18877 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
18879 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
18880 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
18881 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
18882 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
18883 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
18884 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18885 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18886 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18887 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
18888 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
18889 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
18890 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
18892 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18893 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18894 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18895 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18896 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18897 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18898 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18899 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18900 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18901 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18902 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18903 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18905 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18906 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18907 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18908 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18909 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18910 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18911 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18912 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18913 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18914 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18915 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18916 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18918 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18919 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18920 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18921 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18922 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18923 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18924 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18925 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18926 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18927 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18928 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18929 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18931 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
18932 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
18933 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
18934 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
18936 cCL("flts", e000110, 2, (RF, RR), rn_rd),
18937 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
18938 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
18939 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
18940 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
18941 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
18942 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
18943 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
18944 cCL("flte", e080110, 2, (RF, RR), rn_rd),
18945 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
18946 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
18947 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
18949 /* The implementation of the FIX instruction is broken on some
18950 assemblers, in that it accepts a precision specifier as well as a
18951 rounding specifier, despite the fact that this is meaningless.
18952 To be more compatible, we accept it as well, though of course it
18953 does not set any bits. */
18954 cCE("fix", e100110, 2, (RR, RF), rd_rm),
18955 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
18956 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
18957 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
18958 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
18959 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
18960 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
18961 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
18962 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
18963 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
18964 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
18965 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
18966 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
18968 /* Instructions that were new with the real FPA, call them V2. */
18970 #define ARM_VARIANT & fpu_fpa_ext_v2
18972 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18973 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18974 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18975 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18976 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18977 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18980 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
18982 /* Moves and type conversions. */
18983 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
18984 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
18985 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
18986 cCE("fmstat", ef1fa10, 0, (), noargs),
18987 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
18988 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
18989 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
18990 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
18991 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
18992 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18993 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
18994 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18995 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
18996 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
18998 /* Memory operations. */
18999 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19000 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19001 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19002 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19003 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19004 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19005 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19006 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19007 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19008 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19009 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19010 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19011 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19012 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19013 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19014 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19015 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19016 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19018 /* Monadic operations. */
19019 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
19020 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
19021 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
19023 /* Dyadic operations. */
19024 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19025 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19026 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19027 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19028 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19029 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19030 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19031 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19032 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19035 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
19036 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
19037 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
19038 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
19040 /* Double precision load/store are still present on single precision
19041 implementations. */
19042 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19043 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19044 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19045 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19046 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19047 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19048 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19049 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19050 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19051 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19054 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
19056 /* Moves and type conversions. */
19057 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19058 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19059 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19060 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
19061 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
19062 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
19063 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
19064 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19065 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
19066 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19067 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19068 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19069 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19071 /* Monadic operations. */
19072 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19073 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19074 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19076 /* Dyadic operations. */
19077 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19078 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19079 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19080 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19081 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19082 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19083 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19084 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19085 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19088 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19089 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
19090 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19091 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
19094 #define ARM_VARIANT & fpu_vfp_ext_v2
19096 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
19097 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
19098 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
19099 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
19101 /* Instructions which may belong to either the Neon or VFP instruction sets.
19102 Individual encoder functions perform additional architecture checks. */
19104 #define ARM_VARIANT & fpu_vfp_ext_v1xd
19105 #undef THUMB_VARIANT
19106 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
19108 /* These mnemonics are unique to VFP. */
19109 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
19110 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
19111 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19112 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19113 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19114 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
19115 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
19116 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
19117 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
19118 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
19120 /* Mnemonics shared by Neon and VFP. */
19121 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
19122 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19123 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19125 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19126 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19128 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19129 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19131 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19132 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19133 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19134 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19135 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19136 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19137 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19138 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19140 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
19141 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
19142 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
19143 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
19146 /* NOTE: All VMOV encoding is special-cased! */
19147 NCE(vmov, 0, 1, (VMOV), neon_mov),
19148 NCE(vmovq, 0, 1, (VMOV), neon_mov),
19150 #undef THUMB_VARIANT
19151 #define THUMB_VARIANT & fpu_neon_ext_v1
19153 #define ARM_VARIANT & fpu_neon_ext_v1
19155 /* Data processing with three registers of the same length. */
19156 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
19157 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
19158 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
19159 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19160 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19161 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19162 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19163 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19164 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19165 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
19166 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19167 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19168 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19169 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19170 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19171 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19172 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19173 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19174 /* If not immediate, fall back to neon_dyadic_i64_su.
19175 shl_imm should accept I8 I16 I32 I64,
19176 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
19177 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
19178 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
19179 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
19180 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
19181 /* Logic ops, types optional & ignored. */
19182 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19183 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19184 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19185 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19186 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19187 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19188 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19189 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19190 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
19191 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
19192 /* Bitfield ops, untyped. */
19193 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19194 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19195 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19196 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19197 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19198 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19199 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
19200 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19201 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19202 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19203 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19204 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19205 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19206 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
19207 back to neon_dyadic_if_su. */
19208 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19209 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19210 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19211 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19212 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19213 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19214 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19215 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19216 /* Comparison. Type I8 I16 I32 F32. */
19217 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
19218 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
19219 /* As above, D registers only. */
19220 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19221 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19222 /* Int and float variants, signedness unimportant. */
19223 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19224 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19225 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
19226 /* Add/sub take types I8 I16 I32 I64 F32. */
19227 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19228 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19229 /* vtst takes sizes 8, 16, 32. */
19230 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
19231 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
19232 /* VMUL takes I8 I16 I32 F32 P8. */
19233 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
19234 /* VQD{R}MULH takes S16 S32. */
19235 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19236 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19237 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19238 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19239 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19240 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19241 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19242 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19243 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19244 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19245 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19246 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19247 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19248 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19249 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19250 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19252 /* Two address, int/float. Types S8 S16 S32 F32. */
19253 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
19254 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
19256 /* Data processing with two registers and a shift amount. */
19257 /* Right shifts, and variants with rounding.
19258 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
19259 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19260 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19261 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19262 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19263 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19264 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19265 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19266 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19267 /* Shift and insert. Sizes accepted 8 16 32 64. */
19268 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
19269 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
19270 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
19271 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
19272 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
19273 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
19274 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
19275 /* Right shift immediate, saturating & narrowing, with rounding variants.
19276 Types accepted S16 S32 S64 U16 U32 U64. */
19277 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19278 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19279 /* As above, unsigned. Types accepted S16 S32 S64. */
19280 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19281 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19282 /* Right shift narrowing. Types accepted I16 I32 I64. */
19283 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19284 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19285 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
19286 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
19287 /* CVT with optional immediate for fixed-point variant. */
19288 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
19290 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
19291 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
19293 /* Data processing, three registers of different lengths. */
19294 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
19295 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
19296 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
19297 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
19298 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
19299 /* If not scalar, fall back to neon_dyadic_long.
19300 Vector types as above, scalar types S16 S32 U16 U32. */
19301 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
19302 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
19303 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
19304 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19305 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19306 /* Dyadic, narrowing insns. Types I16 I32 I64. */
19307 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19308 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19309 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19310 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19311 /* Saturating doubling multiplies. Types S16 S32. */
19312 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19313 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19314 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19315 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
19316 S16 S32 U16 U32. */
19317 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
19319 /* Extract. Size 8. */
19320 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
19321 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
19323 /* Two registers, miscellaneous. */
19324 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
19325 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
19326 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
19327 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
19328 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
19329 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
19330 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
19331 /* Vector replicate. Sizes 8 16 32. */
19332 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
19333 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
19334 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
19335 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
19336 /* VMOVN. Types I16 I32 I64. */
19337 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
19338 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
19339 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
19340 /* VQMOVUN. Types S16 S32 S64. */
19341 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
19342 /* VZIP / VUZP. Sizes 8 16 32. */
19343 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
19344 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
19345 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
19346 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
19347 /* VQABS / VQNEG. Types S8 S16 S32. */
19348 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
19349 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
19350 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
19351 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
19352 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
19353 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
19354 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
19355 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
19356 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
19357 /* Reciprocal estimates. Types U32 F32. */
19358 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
19359 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
19360 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
19361 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
19362 /* VCLS. Types S8 S16 S32. */
19363 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
19364 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
19365 /* VCLZ. Types I8 I16 I32. */
19366 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
19367 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
19368 /* VCNT. Size 8. */
19369 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
19370 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
19371 /* Two address, untyped. */
19372 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
19373 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
19374 /* VTRN. Sizes 8 16 32. */
19375 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
19376 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
19378 /* Table lookup. Size 8. */
19379 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
19380 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
19382 #undef THUMB_VARIANT
19383 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
19385 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
19387 /* Neon element/structure load/store. */
19388 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
19389 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
19390 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
19391 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
19392 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
19393 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
19394 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
19395 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
19397 #undef THUMB_VARIANT
19398 #define THUMB_VARIANT &fpu_vfp_ext_v3xd
19400 #define ARM_VARIANT &fpu_vfp_ext_v3xd
19401 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
19402 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19403 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19404 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19405 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19406 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19407 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19408 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19409 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19411 #undef THUMB_VARIANT
19412 #define THUMB_VARIANT & fpu_vfp_ext_v3
19414 #define ARM_VARIANT & fpu_vfp_ext_v3
19416 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
19417 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
19418 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
19419 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
19420 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
19421 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
19422 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
19423 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
19424 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
19427 #define ARM_VARIANT &fpu_vfp_ext_fma
19428 #undef THUMB_VARIANT
19429 #define THUMB_VARIANT &fpu_vfp_ext_fma
19430 /* Mnemonics shared by Neon and VFP. These are included in the
19431 VFP FMA variant; NEON and VFP FMA always includes the NEON
19432 FMA instructions. */
19433 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
19434 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
19435 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
19436 the v form should always be used. */
19437 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19438 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19439 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19440 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19441 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19442 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19444 #undef THUMB_VARIANT
19446 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
19448 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19449 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19450 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19451 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19452 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19453 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19454 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
19455 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
19458 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
19460 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
19461 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
19462 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
19463 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
19464 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
19465 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
19466 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
19467 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
19468 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
19469 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19470 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19471 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19472 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19473 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19474 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19475 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19476 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19477 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19478 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
19479 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
19480 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19481 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19482 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19483 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19484 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19485 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19486 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
19487 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
19488 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
19489 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
19490 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
19491 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
19492 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
19493 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
19494 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
19495 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
19496 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
19497 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19498 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19499 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19500 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19501 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19502 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19503 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19504 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19505 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19506 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
19507 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19508 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19509 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19510 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19511 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19512 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19513 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19514 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19515 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19516 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19517 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19518 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19519 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19520 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19521 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19522 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19523 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19524 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19525 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19526 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19527 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19528 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
19529 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
19530 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19531 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19532 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19533 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19534 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19535 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19536 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19537 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19538 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19539 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19540 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19541 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19542 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19543 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19544 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19545 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19546 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19547 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19548 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
19549 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19550 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19551 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19552 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19553 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19554 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19555 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19556 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19557 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19558 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19559 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19560 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19561 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19562 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19563 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19564 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19565 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19566 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19567 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19568 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19569 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19570 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
19571 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19572 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19573 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19574 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19575 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19576 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19577 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19578 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19579 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19580 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19581 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19582 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19583 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19584 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19585 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19586 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19587 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19588 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19589 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19590 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19591 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
19592 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
19593 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19594 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19595 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19596 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19597 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19598 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19599 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19600 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19601 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19602 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
19603 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
19604 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
19605 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
19606 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
19607 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
19608 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19609 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19610 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19611 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
19612 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
19613 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
19614 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
19615 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
19616 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
19617 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19618 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19619 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19620 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19621 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
19624 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
19626 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
19627 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
19628 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
19629 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
19630 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
19631 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
19632 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19633 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19634 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19635 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19636 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19637 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19638 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19639 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19640 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19641 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19642 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19643 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19644 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19645 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19646 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
19647 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19648 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19649 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19650 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19651 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19652 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19653 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19654 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19655 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19656 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19657 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19658 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19659 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19660 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19661 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19662 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19663 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19664 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19665 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19666 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19667 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19668 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19669 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19670 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19671 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19672 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19673 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19674 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19675 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19676 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19677 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19678 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19679 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19680 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19681 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19682 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19685 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
19687 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
19688 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
19689 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
19690 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
19691 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
19692 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
19693 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
19694 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
19695 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
19696 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
19697 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
19698 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
19699 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
19700 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
19701 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
19702 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
19703 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
19704 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
19705 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
19706 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
19707 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
19708 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
19709 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
19710 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
19711 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
19712 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
19713 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
19714 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
19715 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
19716 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
19717 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
19718 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
19719 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
19720 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
19721 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
19722 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
19723 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
19724 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
19725 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
19726 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
19727 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
19728 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
19729 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
19730 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
19731 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
19732 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
19733 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
19734 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
19735 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
19736 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
19737 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
19738 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
19739 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
19740 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
19741 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
19742 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
19743 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
19744 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
19745 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
19746 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
19747 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
19748 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
19749 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
19750 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
19751 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19752 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19753 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19754 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19755 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19756 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19757 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19758 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19759 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
19760 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
19761 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
19762 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
19765 #undef THUMB_VARIANT
19791 /* MD interface: bits in the object file. */
19793 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
19794 for use in the a.out file, and stores them in the array pointed to by buf.
19795 This knows about the endian-ness of the target machine and does
19796 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
19797 2 (short) and 4 (long) Floating numbers are put out as a series of
19798 LITTLENUMS (shorts, here at least). */
19801 md_number_to_chars (char * buf, valueT val, int n)
19803 if (target_big_endian)
19804 number_to_chars_bigendian (buf, val, n);
19806 number_to_chars_littleendian (buf, val, n);
19810 md_chars_to_number (char * buf, int n)
19813 unsigned char * where = (unsigned char *) buf;
19815 if (target_big_endian)
19820 result |= (*where++ & 255);
19828 result |= (where[n] & 255);
19835 /* MD interface: Sections. */
19837 /* Calculate the maximum variable size (i.e., excluding fr_fix)
19838 that an rs_machine_dependent frag may reach. */
19841 arm_frag_max_var (fragS *fragp)
19843 /* We only use rs_machine_dependent for variable-size Thumb instructions,
19844 which are either THUMB_SIZE (2) or INSN_SIZE (4).
19846 Note that we generate relaxable instructions even for cases that don't
19847 really need it, like an immediate that's a trivial constant. So we're
19848 overestimating the instruction size for some of those cases. Rather
19849 than putting more intelligence here, it would probably be better to
19850 avoid generating a relaxation frag in the first place when it can be
19851 determined up front that a short instruction will suffice. */
19853 gas_assert (fragp->fr_type == rs_machine_dependent);
19857 /* Estimate the size of a frag before relaxing. Assume everything fits in
19861 md_estimate_size_before_relax (fragS * fragp,
19862 segT segtype ATTRIBUTE_UNUSED)
19868 /* Convert a machine dependent frag. */
19871 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
19873 unsigned long insn;
19874 unsigned long old_op;
19882 buf = fragp->fr_literal + fragp->fr_fix;
19884 old_op = bfd_get_16(abfd, buf);
19885 if (fragp->fr_symbol)
19887 exp.X_op = O_symbol;
19888 exp.X_add_symbol = fragp->fr_symbol;
19892 exp.X_op = O_constant;
19894 exp.X_add_number = fragp->fr_offset;
19895 opcode = fragp->fr_subtype;
19898 case T_MNEM_ldr_pc:
19899 case T_MNEM_ldr_pc2:
19900 case T_MNEM_ldr_sp:
19901 case T_MNEM_str_sp:
19908 if (fragp->fr_var == 4)
19910 insn = THUMB_OP32 (opcode);
19911 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
19913 insn |= (old_op & 0x700) << 4;
19917 insn |= (old_op & 7) << 12;
19918 insn |= (old_op & 0x38) << 13;
19920 insn |= 0x00000c00;
19921 put_thumb32_insn (buf, insn);
19922 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
19926 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
19928 pc_rel = (opcode == T_MNEM_ldr_pc2);
19931 if (fragp->fr_var == 4)
19933 insn = THUMB_OP32 (opcode);
19934 insn |= (old_op & 0xf0) << 4;
19935 put_thumb32_insn (buf, insn);
19936 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
19940 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19941 exp.X_add_number -= 4;
19949 if (fragp->fr_var == 4)
19951 int r0off = (opcode == T_MNEM_mov
19952 || opcode == T_MNEM_movs) ? 0 : 8;
19953 insn = THUMB_OP32 (opcode);
19954 insn = (insn & 0xe1ffffff) | 0x10000000;
19955 insn |= (old_op & 0x700) << r0off;
19956 put_thumb32_insn (buf, insn);
19957 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19961 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
19966 if (fragp->fr_var == 4)
19968 insn = THUMB_OP32(opcode);
19969 put_thumb32_insn (buf, insn);
19970 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
19973 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
19977 if (fragp->fr_var == 4)
19979 insn = THUMB_OP32(opcode);
19980 insn |= (old_op & 0xf00) << 14;
19981 put_thumb32_insn (buf, insn);
19982 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
19985 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
19988 case T_MNEM_add_sp:
19989 case T_MNEM_add_pc:
19990 case T_MNEM_inc_sp:
19991 case T_MNEM_dec_sp:
19992 if (fragp->fr_var == 4)
19994 /* ??? Choose between add and addw. */
19995 insn = THUMB_OP32 (opcode);
19996 insn |= (old_op & 0xf0) << 4;
19997 put_thumb32_insn (buf, insn);
19998 if (opcode == T_MNEM_add_pc)
19999 reloc_type = BFD_RELOC_ARM_T32_IMM12;
20001 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20004 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20012 if (fragp->fr_var == 4)
20014 insn = THUMB_OP32 (opcode);
20015 insn |= (old_op & 0xf0) << 4;
20016 insn |= (old_op & 0xf) << 16;
20017 put_thumb32_insn (buf, insn);
20018 if (insn & (1 << 20))
20019 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20021 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
20024 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20030 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
20031 (enum bfd_reloc_code_real) reloc_type);
20032 fixp->fx_file = fragp->fr_file;
20033 fixp->fx_line = fragp->fr_line;
20034 fragp->fr_fix += fragp->fr_var;
20037 /* Return the size of a relaxable immediate operand instruction.
20038 SHIFT and SIZE specify the form of the allowable immediate. */
20040 relax_immediate (fragS *fragp, int size, int shift)
20046 /* ??? Should be able to do better than this. */
20047 if (fragp->fr_symbol)
20050 low = (1 << shift) - 1;
20051 mask = (1 << (shift + size)) - (1 << shift);
20052 offset = fragp->fr_offset;
20053 /* Force misaligned offsets to 32-bit variant. */
20056 if (offset & ~mask)
20061 /* Get the address of a symbol during relaxation. */
20063 relaxed_symbol_addr (fragS *fragp, long stretch)
20069 sym = fragp->fr_symbol;
20070 sym_frag = symbol_get_frag (sym);
20071 know (S_GET_SEGMENT (sym) != absolute_section
20072 || sym_frag == &zero_address_frag);
20073 addr = S_GET_VALUE (sym) + fragp->fr_offset;
20075 /* If frag has yet to be reached on this pass, assume it will
20076 move by STRETCH just as we did. If this is not so, it will
20077 be because some frag between grows, and that will force
20081 && sym_frag->relax_marker != fragp->relax_marker)
20085 /* Adjust stretch for any alignment frag. Note that if have
20086 been expanding the earlier code, the symbol may be
20087 defined in what appears to be an earlier frag. FIXME:
20088 This doesn't handle the fr_subtype field, which specifies
20089 a maximum number of bytes to skip when doing an
20091 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
20093 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
20096 stretch = - ((- stretch)
20097 & ~ ((1 << (int) f->fr_offset) - 1));
20099 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
20111 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
20114 relax_adr (fragS *fragp, asection *sec, long stretch)
20119 /* Assume worst case for symbols not known to be in the same section. */
20120 if (fragp->fr_symbol == NULL
20121 || !S_IS_DEFINED (fragp->fr_symbol)
20122 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20123 || S_IS_WEAK (fragp->fr_symbol))
20126 val = relaxed_symbol_addr (fragp, stretch);
20127 addr = fragp->fr_address + fragp->fr_fix;
20128 addr = (addr + 4) & ~3;
20129 /* Force misaligned targets to 32-bit variant. */
20133 if (val < 0 || val > 1020)
20138 /* Return the size of a relaxable add/sub immediate instruction. */
20140 relax_addsub (fragS *fragp, asection *sec)
20145 buf = fragp->fr_literal + fragp->fr_fix;
20146 op = bfd_get_16(sec->owner, buf);
20147 if ((op & 0xf) == ((op >> 4) & 0xf))
20148 return relax_immediate (fragp, 8, 0);
20150 return relax_immediate (fragp, 3, 0);
20154 /* Return the size of a relaxable branch instruction. BITS is the
20155 size of the offset field in the narrow instruction. */
20158 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
20164 /* Assume worst case for symbols not known to be in the same section. */
20165 if (!S_IS_DEFINED (fragp->fr_symbol)
20166 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20167 || S_IS_WEAK (fragp->fr_symbol))
20171 if (S_IS_DEFINED (fragp->fr_symbol)
20172 && ARM_IS_FUNC (fragp->fr_symbol))
20175 /* PR 12532. Global symbols with default visibility might
20176 be preempted, so do not relax relocations to them. */
20177 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
20178 && (! S_IS_LOCAL (fragp->fr_symbol)))
20182 val = relaxed_symbol_addr (fragp, stretch);
20183 addr = fragp->fr_address + fragp->fr_fix + 4;
20186 /* Offset is a signed value *2 */
20188 if (val >= limit || val < -limit)
20194 /* Relax a machine dependent frag. This returns the amount by which
20195 the current size of the frag should change. */
20198 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
20203 oldsize = fragp->fr_var;
20204 switch (fragp->fr_subtype)
20206 case T_MNEM_ldr_pc2:
20207 newsize = relax_adr (fragp, sec, stretch);
20209 case T_MNEM_ldr_pc:
20210 case T_MNEM_ldr_sp:
20211 case T_MNEM_str_sp:
20212 newsize = relax_immediate (fragp, 8, 2);
20216 newsize = relax_immediate (fragp, 5, 2);
20220 newsize = relax_immediate (fragp, 5, 1);
20224 newsize = relax_immediate (fragp, 5, 0);
20227 newsize = relax_adr (fragp, sec, stretch);
20233 newsize = relax_immediate (fragp, 8, 0);
20236 newsize = relax_branch (fragp, sec, 11, stretch);
20239 newsize = relax_branch (fragp, sec, 8, stretch);
20241 case T_MNEM_add_sp:
20242 case T_MNEM_add_pc:
20243 newsize = relax_immediate (fragp, 8, 2);
20245 case T_MNEM_inc_sp:
20246 case T_MNEM_dec_sp:
20247 newsize = relax_immediate (fragp, 7, 2);
20253 newsize = relax_addsub (fragp, sec);
20259 fragp->fr_var = newsize;
20260 /* Freeze wide instructions that are at or before the same location as
20261 in the previous pass. This avoids infinite loops.
20262 Don't freeze them unconditionally because targets may be artificially
20263 misaligned by the expansion of preceding frags. */
20264 if (stretch <= 0 && newsize > 2)
20266 md_convert_frag (sec->owner, sec, fragp);
20270 return newsize - oldsize;
20273 /* Round up a section size to the appropriate boundary. */
20276 md_section_align (segT segment ATTRIBUTE_UNUSED,
20279 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
20280 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
20282 /* For a.out, force the section size to be aligned. If we don't do
20283 this, BFD will align it for us, but it will not write out the
20284 final bytes of the section. This may be a bug in BFD, but it is
20285 easier to fix it here since that is how the other a.out targets
20289 align = bfd_get_section_alignment (stdoutput, segment);
20290 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
20297 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
20298 of an rs_align_code fragment. */
20301 arm_handle_align (fragS * fragP)
20303 static char const arm_noop[2][2][4] =
20306 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
20307 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
20310 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
20311 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
20314 static char const thumb_noop[2][2][2] =
20317 {0xc0, 0x46}, /* LE */
20318 {0x46, 0xc0}, /* BE */
20321 {0x00, 0xbf}, /* LE */
20322 {0xbf, 0x00} /* BE */
20325 static char const wide_thumb_noop[2][4] =
20326 { /* Wide Thumb-2 */
20327 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
20328 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
20331 unsigned bytes, fix, noop_size;
20334 const char *narrow_noop = NULL;
20339 if (fragP->fr_type != rs_align_code)
20342 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
20343 p = fragP->fr_literal + fragP->fr_fix;
20346 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
20347 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
20349 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
20351 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
20353 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
20355 narrow_noop = thumb_noop[1][target_big_endian];
20356 noop = wide_thumb_noop[target_big_endian];
20359 noop = thumb_noop[0][target_big_endian];
20367 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
20368 [target_big_endian];
20375 fragP->fr_var = noop_size;
20377 if (bytes & (noop_size - 1))
20379 fix = bytes & (noop_size - 1);
20381 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
20383 memset (p, 0, fix);
20390 if (bytes & noop_size)
20392 /* Insert a narrow noop. */
20393 memcpy (p, narrow_noop, noop_size);
20395 bytes -= noop_size;
20399 /* Use wide noops for the remainder */
20403 while (bytes >= noop_size)
20405 memcpy (p, noop, noop_size);
20407 bytes -= noop_size;
20411 fragP->fr_fix += fix;
20414 /* Called from md_do_align. Used to create an alignment
20415 frag in a code section. */
20418 arm_frag_align_code (int n, int max)
20422 /* We assume that there will never be a requirement
20423 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
20424 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
20429 _("alignments greater than %d bytes not supported in .text sections."),
20430 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20431 as_fatal ("%s", err_msg);
20434 p = frag_var (rs_align_code,
20435 MAX_MEM_FOR_RS_ALIGN_CODE,
20437 (relax_substateT) max,
20444 /* Perform target specific initialisation of a frag.
20445 Note - despite the name this initialisation is not done when the frag
20446 is created, but only when its type is assigned. A frag can be created
20447 and used a long time before its type is set, so beware of assuming that
20448 this initialisationis performed first. */
20452 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
20454 /* Record whether this frag is in an ARM or a THUMB area. */
20455 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
20458 #else /* OBJ_ELF is defined. */
20460 arm_init_frag (fragS * fragP, int max_chars)
20462 /* If the current ARM vs THUMB mode has not already
20463 been recorded into this frag then do so now. */
20464 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
20466 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
20468 /* Record a mapping symbol for alignment frags. We will delete this
20469 later if the alignment ends up empty. */
20470 switch (fragP->fr_type)
20473 case rs_align_test:
20475 mapping_state_2 (MAP_DATA, max_chars);
20477 case rs_align_code:
20478 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
20486 /* When we change sections we need to issue a new mapping symbol. */
20489 arm_elf_change_section (void)
20491 /* Link an unlinked unwind index table section to the .text section. */
20492 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
20493 && elf_linked_to_section (now_seg) == NULL)
20494 elf_linked_to_section (now_seg) = text_section;
20498 arm_elf_section_type (const char * str, size_t len)
20500 if (len == 5 && strncmp (str, "exidx", 5) == 0)
20501 return SHT_ARM_EXIDX;
20506 /* Code to deal with unwinding tables. */
20508 static void add_unwind_adjustsp (offsetT);
20510 /* Generate any deferred unwind frame offset. */
20513 flush_pending_unwind (void)
20517 offset = unwind.pending_offset;
20518 unwind.pending_offset = 0;
20520 add_unwind_adjustsp (offset);
20523 /* Add an opcode to this list for this function. Two-byte opcodes should
20524 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
20528 add_unwind_opcode (valueT op, int length)
20530 /* Add any deferred stack adjustment. */
20531 if (unwind.pending_offset)
20532 flush_pending_unwind ();
20534 unwind.sp_restored = 0;
20536 if (unwind.opcode_count + length > unwind.opcode_alloc)
20538 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
20539 if (unwind.opcodes)
20540 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
20541 unwind.opcode_alloc);
20543 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
20548 unwind.opcodes[unwind.opcode_count] = op & 0xff;
20550 unwind.opcode_count++;
20554 /* Add unwind opcodes to adjust the stack pointer. */
20557 add_unwind_adjustsp (offsetT offset)
20561 if (offset > 0x200)
20563 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
20568 /* Long form: 0xb2, uleb128. */
20569 /* This might not fit in a word so add the individual bytes,
20570 remembering the list is built in reverse order. */
20571 o = (valueT) ((offset - 0x204) >> 2);
20573 add_unwind_opcode (0, 1);
20575 /* Calculate the uleb128 encoding of the offset. */
20579 bytes[n] = o & 0x7f;
20585 /* Add the insn. */
20587 add_unwind_opcode (bytes[n - 1], 1);
20588 add_unwind_opcode (0xb2, 1);
20590 else if (offset > 0x100)
20592 /* Two short opcodes. */
20593 add_unwind_opcode (0x3f, 1);
20594 op = (offset - 0x104) >> 2;
20595 add_unwind_opcode (op, 1);
20597 else if (offset > 0)
20599 /* Short opcode. */
20600 op = (offset - 4) >> 2;
20601 add_unwind_opcode (op, 1);
20603 else if (offset < 0)
20606 while (offset > 0x100)
20608 add_unwind_opcode (0x7f, 1);
20611 op = ((offset - 4) >> 2) | 0x40;
20612 add_unwind_opcode (op, 1);
20616 /* Finish the list of unwind opcodes for this function. */
20618 finish_unwind_opcodes (void)
20622 if (unwind.fp_used)
20624 /* Adjust sp as necessary. */
20625 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
20626 flush_pending_unwind ();
20628 /* After restoring sp from the frame pointer. */
20629 op = 0x90 | unwind.fp_reg;
20630 add_unwind_opcode (op, 1);
20633 flush_pending_unwind ();
20637 /* Start an exception table entry. If idx is nonzero this is an index table
20641 start_unwind_section (const segT text_seg, int idx)
20643 const char * text_name;
20644 const char * prefix;
20645 const char * prefix_once;
20646 const char * group_name;
20650 size_t sec_name_len;
20657 prefix = ELF_STRING_ARM_unwind;
20658 prefix_once = ELF_STRING_ARM_unwind_once;
20659 type = SHT_ARM_EXIDX;
20663 prefix = ELF_STRING_ARM_unwind_info;
20664 prefix_once = ELF_STRING_ARM_unwind_info_once;
20665 type = SHT_PROGBITS;
20668 text_name = segment_name (text_seg);
20669 if (streq (text_name, ".text"))
20672 if (strncmp (text_name, ".gnu.linkonce.t.",
20673 strlen (".gnu.linkonce.t.")) == 0)
20675 prefix = prefix_once;
20676 text_name += strlen (".gnu.linkonce.t.");
20679 prefix_len = strlen (prefix);
20680 text_len = strlen (text_name);
20681 sec_name_len = prefix_len + text_len;
20682 sec_name = (char *) xmalloc (sec_name_len + 1);
20683 memcpy (sec_name, prefix, prefix_len);
20684 memcpy (sec_name + prefix_len, text_name, text_len);
20685 sec_name[prefix_len + text_len] = '\0';
20691 /* Handle COMDAT group. */
20692 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
20694 group_name = elf_group_name (text_seg);
20695 if (group_name == NULL)
20697 as_bad (_("Group section `%s' has no group signature"),
20698 segment_name (text_seg));
20699 ignore_rest_of_line ();
20702 flags |= SHF_GROUP;
20706 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
20708 /* Set the section link for index tables. */
20710 elf_linked_to_section (now_seg) = text_seg;
20714 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
20715 personality routine data. Returns zero, or the index table value for
20716 and inline entry. */
20719 create_unwind_entry (int have_data)
20724 /* The current word of data. */
20726 /* The number of bytes left in this word. */
20729 finish_unwind_opcodes ();
20731 /* Remember the current text section. */
20732 unwind.saved_seg = now_seg;
20733 unwind.saved_subseg = now_subseg;
20735 start_unwind_section (now_seg, 0);
20737 if (unwind.personality_routine == NULL)
20739 if (unwind.personality_index == -2)
20742 as_bad (_("handlerdata in cantunwind frame"));
20743 return 1; /* EXIDX_CANTUNWIND. */
20746 /* Use a default personality routine if none is specified. */
20747 if (unwind.personality_index == -1)
20749 if (unwind.opcode_count > 3)
20750 unwind.personality_index = 1;
20752 unwind.personality_index = 0;
20755 /* Space for the personality routine entry. */
20756 if (unwind.personality_index == 0)
20758 if (unwind.opcode_count > 3)
20759 as_bad (_("too many unwind opcodes for personality routine 0"));
20763 /* All the data is inline in the index table. */
20766 while (unwind.opcode_count > 0)
20768 unwind.opcode_count--;
20769 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20773 /* Pad with "finish" opcodes. */
20775 data = (data << 8) | 0xb0;
20782 /* We get two opcodes "free" in the first word. */
20783 size = unwind.opcode_count - 2;
20787 gas_assert (unwind.personality_index == -1);
20789 /* An extra byte is required for the opcode count. */
20790 size = unwind.opcode_count + 1;
20793 size = (size + 3) >> 2;
20795 as_bad (_("too many unwind opcodes"));
20797 frag_align (2, 0, 0);
20798 record_alignment (now_seg, 2);
20799 unwind.table_entry = expr_build_dot ();
20801 /* Allocate the table entry. */
20802 ptr = frag_more ((size << 2) + 4);
20803 /* PR 13449: Zero the table entries in case some of them are not used. */
20804 memset (ptr, 0, (size << 2) + 4);
20805 where = frag_now_fix () - ((size << 2) + 4);
20807 switch (unwind.personality_index)
20810 /* ??? Should this be a PLT generating relocation? */
20811 /* Custom personality routine. */
20812 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
20813 BFD_RELOC_ARM_PREL31);
20818 /* Set the first byte to the number of additional words. */
20819 data = size > 0 ? size - 1 : 0;
20823 /* ABI defined personality routines. */
20825 /* Three opcodes bytes are packed into the first word. */
20832 /* The size and first two opcode bytes go in the first word. */
20833 data = ((0x80 + unwind.personality_index) << 8) | size;
20838 /* Should never happen. */
20842 /* Pack the opcodes into words (MSB first), reversing the list at the same
20844 while (unwind.opcode_count > 0)
20848 md_number_to_chars (ptr, data, 4);
20853 unwind.opcode_count--;
20855 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20858 /* Finish off the last word. */
20861 /* Pad with "finish" opcodes. */
20863 data = (data << 8) | 0xb0;
20865 md_number_to_chars (ptr, data, 4);
20870 /* Add an empty descriptor if there is no user-specified data. */
20871 ptr = frag_more (4);
20872 md_number_to_chars (ptr, 0, 4);
20879 /* Initialize the DWARF-2 unwind information for this procedure. */
20882 tc_arm_frame_initial_instructions (void)
20884 cfi_add_CFA_def_cfa (REG_SP, 0);
20886 #endif /* OBJ_ELF */
20888 /* Convert REGNAME to a DWARF-2 register number. */
20891 tc_arm_regname_to_dw2regnum (char *regname)
20893 int reg = arm_reg_parse (®name, REG_TYPE_RN);
20903 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
20907 exp.X_op = O_secrel;
20908 exp.X_add_symbol = symbol;
20909 exp.X_add_number = 0;
20910 emit_expr (&exp, size);
20914 /* MD interface: Symbol and relocation handling. */
20916 /* Return the address within the segment that a PC-relative fixup is
20917 relative to. For ARM, PC-relative fixups applied to instructions
20918 are generally relative to the location of the fixup plus 8 bytes.
20919 Thumb branches are offset by 4, and Thumb loads relative to PC
20920 require special handling. */
20923 md_pcrel_from_section (fixS * fixP, segT seg)
20925 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
20927 /* If this is pc-relative and we are going to emit a relocation
20928 then we just want to put out any pipeline compensation that the linker
20929 will need. Otherwise we want to use the calculated base.
20930 For WinCE we skip the bias for externals as well, since this
20931 is how the MS ARM-CE assembler behaves and we want to be compatible. */
20933 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
20934 || (arm_force_relocation (fixP)
20936 && !S_IS_EXTERNAL (fixP->fx_addsy)
20942 switch (fixP->fx_r_type)
20944 /* PC relative addressing on the Thumb is slightly odd as the
20945 bottom two bits of the PC are forced to zero for the
20946 calculation. This happens *after* application of the
20947 pipeline offset. However, Thumb adrl already adjusts for
20948 this, so we need not do it again. */
20949 case BFD_RELOC_ARM_THUMB_ADD:
20952 case BFD_RELOC_ARM_THUMB_OFFSET:
20953 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20954 case BFD_RELOC_ARM_T32_ADD_PC12:
20955 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
20956 return (base + 4) & ~3;
20958 /* Thumb branches are simply offset by +4. */
20959 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20960 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20961 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20962 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20963 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20966 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20968 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20969 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20970 && ARM_IS_FUNC (fixP->fx_addsy)
20971 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20972 base = fixP->fx_where + fixP->fx_frag->fr_address;
20975 /* BLX is like branches above, but forces the low two bits of PC to
20977 case BFD_RELOC_THUMB_PCREL_BLX:
20979 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20980 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20981 && THUMB_IS_FUNC (fixP->fx_addsy)
20982 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20983 base = fixP->fx_where + fixP->fx_frag->fr_address;
20984 return (base + 4) & ~3;
20986 /* ARM mode branches are offset by +8. However, the Windows CE
20987 loader expects the relocation not to take this into account. */
20988 case BFD_RELOC_ARM_PCREL_BLX:
20990 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20991 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20992 && ARM_IS_FUNC (fixP->fx_addsy)
20993 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20994 base = fixP->fx_where + fixP->fx_frag->fr_address;
20997 case BFD_RELOC_ARM_PCREL_CALL:
20999 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21000 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21001 && THUMB_IS_FUNC (fixP->fx_addsy)
21002 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21003 base = fixP->fx_where + fixP->fx_frag->fr_address;
21006 case BFD_RELOC_ARM_PCREL_BRANCH:
21007 case BFD_RELOC_ARM_PCREL_JUMP:
21008 case BFD_RELOC_ARM_PLT32:
21010 /* When handling fixups immediately, because we have already
21011 discovered the value of a symbol, or the address of the frag involved
21012 we must account for the offset by +8, as the OS loader will never see the reloc.
21013 see fixup_segment() in write.c
21014 The S_IS_EXTERNAL test handles the case of global symbols.
21015 Those need the calculated base, not just the pipe compensation the linker will need. */
21017 && fixP->fx_addsy != NULL
21018 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21019 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
21027 /* ARM mode loads relative to PC are also offset by +8. Unlike
21028 branches, the Windows CE loader *does* expect the relocation
21029 to take this into account. */
21030 case BFD_RELOC_ARM_OFFSET_IMM:
21031 case BFD_RELOC_ARM_OFFSET_IMM8:
21032 case BFD_RELOC_ARM_HWLITERAL:
21033 case BFD_RELOC_ARM_LITERAL:
21034 case BFD_RELOC_ARM_CP_OFF_IMM:
21038 /* Other PC-relative relocations are un-offset. */
21044 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
21045 Otherwise we have no need to default values of symbols. */
21048 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
21051 if (name[0] == '_' && name[1] == 'G'
21052 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
21056 if (symbol_find (name))
21057 as_bad (_("GOT already in the symbol table"));
21059 GOT_symbol = symbol_new (name, undefined_section,
21060 (valueT) 0, & zero_address_frag);
21070 /* Subroutine of md_apply_fix. Check to see if an immediate can be
21071 computed as two separate immediate values, added together. We
21072 already know that this value cannot be computed by just one ARM
21075 static unsigned int
21076 validate_immediate_twopart (unsigned int val,
21077 unsigned int * highpart)
21082 for (i = 0; i < 32; i += 2)
21083 if (((a = rotate_left (val, i)) & 0xff) != 0)
21089 * highpart = (a >> 8) | ((i + 24) << 7);
21091 else if (a & 0xff0000)
21093 if (a & 0xff000000)
21095 * highpart = (a >> 16) | ((i + 16) << 7);
21099 gas_assert (a & 0xff000000);
21100 * highpart = (a >> 24) | ((i + 8) << 7);
21103 return (a & 0xff) | (i << 7);
21110 validate_offset_imm (unsigned int val, int hwse)
21112 if ((hwse && val > 255) || val > 4095)
21117 /* Subroutine of md_apply_fix. Do those data_ops which can take a
21118 negative immediate constant by altering the instruction. A bit of
21123 by inverting the second operand, and
21126 by negating the second operand. */
21129 negate_data_op (unsigned long * instruction,
21130 unsigned long value)
21133 unsigned long negated, inverted;
21135 negated = encode_arm_immediate (-value);
21136 inverted = encode_arm_immediate (~value);
21138 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
21141 /* First negates. */
21142 case OPCODE_SUB: /* ADD <-> SUB */
21143 new_inst = OPCODE_ADD;
21148 new_inst = OPCODE_SUB;
21152 case OPCODE_CMP: /* CMP <-> CMN */
21153 new_inst = OPCODE_CMN;
21158 new_inst = OPCODE_CMP;
21162 /* Now Inverted ops. */
21163 case OPCODE_MOV: /* MOV <-> MVN */
21164 new_inst = OPCODE_MVN;
21169 new_inst = OPCODE_MOV;
21173 case OPCODE_AND: /* AND <-> BIC */
21174 new_inst = OPCODE_BIC;
21179 new_inst = OPCODE_AND;
21183 case OPCODE_ADC: /* ADC <-> SBC */
21184 new_inst = OPCODE_SBC;
21189 new_inst = OPCODE_ADC;
21193 /* We cannot do anything. */
21198 if (value == (unsigned) FAIL)
21201 *instruction &= OPCODE_MASK;
21202 *instruction |= new_inst << DATA_OP_SHIFT;
21206 /* Like negate_data_op, but for Thumb-2. */
21208 static unsigned int
21209 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
21213 unsigned int negated, inverted;
21215 negated = encode_thumb32_immediate (-value);
21216 inverted = encode_thumb32_immediate (~value);
21218 rd = (*instruction >> 8) & 0xf;
21219 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
21222 /* ADD <-> SUB. Includes CMP <-> CMN. */
21223 case T2_OPCODE_SUB:
21224 new_inst = T2_OPCODE_ADD;
21228 case T2_OPCODE_ADD:
21229 new_inst = T2_OPCODE_SUB;
21233 /* ORR <-> ORN. Includes MOV <-> MVN. */
21234 case T2_OPCODE_ORR:
21235 new_inst = T2_OPCODE_ORN;
21239 case T2_OPCODE_ORN:
21240 new_inst = T2_OPCODE_ORR;
21244 /* AND <-> BIC. TST has no inverted equivalent. */
21245 case T2_OPCODE_AND:
21246 new_inst = T2_OPCODE_BIC;
21253 case T2_OPCODE_BIC:
21254 new_inst = T2_OPCODE_AND;
21259 case T2_OPCODE_ADC:
21260 new_inst = T2_OPCODE_SBC;
21264 case T2_OPCODE_SBC:
21265 new_inst = T2_OPCODE_ADC;
21269 /* We cannot do anything. */
21274 if (value == (unsigned int)FAIL)
21277 *instruction &= T2_OPCODE_MASK;
21278 *instruction |= new_inst << T2_DATA_OP_SHIFT;
21282 /* Read a 32-bit thumb instruction from buf. */
21283 static unsigned long
21284 get_thumb32_insn (char * buf)
21286 unsigned long insn;
21287 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
21288 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21294 /* We usually want to set the low bit on the address of thumb function
21295 symbols. In particular .word foo - . should have the low bit set.
21296 Generic code tries to fold the difference of two symbols to
21297 a constant. Prevent this and force a relocation when the first symbols
21298 is a thumb function. */
21301 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
21303 if (op == O_subtract
21304 && l->X_op == O_symbol
21305 && r->X_op == O_symbol
21306 && THUMB_IS_FUNC (l->X_add_symbol))
21308 l->X_op = O_subtract;
21309 l->X_op_symbol = r->X_add_symbol;
21310 l->X_add_number -= r->X_add_number;
21314 /* Process as normal. */
21318 /* Encode Thumb2 unconditional branches and calls. The encoding
21319 for the 2 are identical for the immediate values. */
21322 encode_thumb2_b_bl_offset (char * buf, offsetT value)
21324 #define T2I1I2MASK ((1 << 13) | (1 << 11))
21327 addressT S, I1, I2, lo, hi;
21329 S = (value >> 24) & 0x01;
21330 I1 = (value >> 23) & 0x01;
21331 I2 = (value >> 22) & 0x01;
21332 hi = (value >> 12) & 0x3ff;
21333 lo = (value >> 1) & 0x7ff;
21334 newval = md_chars_to_number (buf, THUMB_SIZE);
21335 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21336 newval |= (S << 10) | hi;
21337 newval2 &= ~T2I1I2MASK;
21338 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
21339 md_number_to_chars (buf, newval, THUMB_SIZE);
21340 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21344 md_apply_fix (fixS * fixP,
21348 offsetT value = * valP;
21350 unsigned int newimm;
21351 unsigned long temp;
21353 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
21355 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
21357 /* Note whether this will delete the relocation. */
21359 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
21362 /* On a 64-bit host, silently truncate 'value' to 32 bits for
21363 consistency with the behaviour on 32-bit hosts. Remember value
21365 value &= 0xffffffff;
21366 value ^= 0x80000000;
21367 value -= 0x80000000;
21370 fixP->fx_addnumber = value;
21372 /* Same treatment for fixP->fx_offset. */
21373 fixP->fx_offset &= 0xffffffff;
21374 fixP->fx_offset ^= 0x80000000;
21375 fixP->fx_offset -= 0x80000000;
21377 switch (fixP->fx_r_type)
21379 case BFD_RELOC_NONE:
21380 /* This will need to go in the object file. */
21384 case BFD_RELOC_ARM_IMMEDIATE:
21385 /* We claim that this fixup has been processed here,
21386 even if in fact we generate an error because we do
21387 not have a reloc for it, so tc_gen_reloc will reject it. */
21390 if (fixP->fx_addsy)
21392 const char *msg = 0;
21394 if (! S_IS_DEFINED (fixP->fx_addsy))
21395 msg = _("undefined symbol %s used as an immediate value");
21396 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
21397 msg = _("symbol %s is in a different section");
21398 else if (S_IS_WEAK (fixP->fx_addsy))
21399 msg = _("symbol %s is weak and may be overridden later");
21403 as_bad_where (fixP->fx_file, fixP->fx_line,
21404 msg, S_GET_NAME (fixP->fx_addsy));
21409 temp = md_chars_to_number (buf, INSN_SIZE);
21411 /* If the offset is negative, we should use encoding A2 for ADR. */
21412 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
21413 newimm = negate_data_op (&temp, value);
21416 newimm = encode_arm_immediate (value);
21418 /* If the instruction will fail, see if we can fix things up by
21419 changing the opcode. */
21420 if (newimm == (unsigned int) FAIL)
21421 newimm = negate_data_op (&temp, value);
21424 if (newimm == (unsigned int) FAIL)
21426 as_bad_where (fixP->fx_file, fixP->fx_line,
21427 _("invalid constant (%lx) after fixup"),
21428 (unsigned long) value);
21432 newimm |= (temp & 0xfffff000);
21433 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
21436 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21438 unsigned int highpart = 0;
21439 unsigned int newinsn = 0xe1a00000; /* nop. */
21441 if (fixP->fx_addsy)
21443 const char *msg = 0;
21445 if (! S_IS_DEFINED (fixP->fx_addsy))
21446 msg = _("undefined symbol %s used as an immediate value");
21447 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
21448 msg = _("symbol %s is in a different section");
21449 else if (S_IS_WEAK (fixP->fx_addsy))
21450 msg = _("symbol %s is weak and may be overridden later");
21454 as_bad_where (fixP->fx_file, fixP->fx_line,
21455 msg, S_GET_NAME (fixP->fx_addsy));
21460 newimm = encode_arm_immediate (value);
21461 temp = md_chars_to_number (buf, INSN_SIZE);
21463 /* If the instruction will fail, see if we can fix things up by
21464 changing the opcode. */
21465 if (newimm == (unsigned int) FAIL
21466 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
21468 /* No ? OK - try using two ADD instructions to generate
21470 newimm = validate_immediate_twopart (value, & highpart);
21472 /* Yes - then make sure that the second instruction is
21474 if (newimm != (unsigned int) FAIL)
21476 /* Still No ? Try using a negated value. */
21477 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
21478 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
21479 /* Otherwise - give up. */
21482 as_bad_where (fixP->fx_file, fixP->fx_line,
21483 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
21488 /* Replace the first operand in the 2nd instruction (which
21489 is the PC) with the destination register. We have
21490 already added in the PC in the first instruction and we
21491 do not want to do it again. */
21492 newinsn &= ~ 0xf0000;
21493 newinsn |= ((newinsn & 0x0f000) << 4);
21496 newimm |= (temp & 0xfffff000);
21497 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
21499 highpart |= (newinsn & 0xfffff000);
21500 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
21504 case BFD_RELOC_ARM_OFFSET_IMM:
21505 if (!fixP->fx_done && seg->use_rela_p)
21508 case BFD_RELOC_ARM_LITERAL:
21514 if (validate_offset_imm (value, 0) == FAIL)
21516 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
21517 as_bad_where (fixP->fx_file, fixP->fx_line,
21518 _("invalid literal constant: pool needs to be closer"));
21520 as_bad_where (fixP->fx_file, fixP->fx_line,
21521 _("bad immediate value for offset (%ld)"),
21526 newval = md_chars_to_number (buf, INSN_SIZE);
21528 newval &= 0xfffff000;
21531 newval &= 0xff7ff000;
21532 newval |= value | (sign ? INDEX_UP : 0);
21534 md_number_to_chars (buf, newval, INSN_SIZE);
21537 case BFD_RELOC_ARM_OFFSET_IMM8:
21538 case BFD_RELOC_ARM_HWLITERAL:
21544 if (validate_offset_imm (value, 1) == FAIL)
21546 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
21547 as_bad_where (fixP->fx_file, fixP->fx_line,
21548 _("invalid literal constant: pool needs to be closer"));
21550 as_bad_where (fixP->fx_file, fixP->fx_line,
21551 _("bad immediate value for 8-bit offset (%ld)"),
21556 newval = md_chars_to_number (buf, INSN_SIZE);
21558 newval &= 0xfffff0f0;
21561 newval &= 0xff7ff0f0;
21562 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
21564 md_number_to_chars (buf, newval, INSN_SIZE);
21567 case BFD_RELOC_ARM_T32_OFFSET_U8:
21568 if (value < 0 || value > 1020 || value % 4 != 0)
21569 as_bad_where (fixP->fx_file, fixP->fx_line,
21570 _("bad immediate value for offset (%ld)"), (long) value);
21573 newval = md_chars_to_number (buf+2, THUMB_SIZE);
21575 md_number_to_chars (buf+2, newval, THUMB_SIZE);
21578 case BFD_RELOC_ARM_T32_OFFSET_IMM:
21579 /* This is a complicated relocation used for all varieties of Thumb32
21580 load/store instruction with immediate offset:
21582 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
21583 *4, optional writeback(W)
21584 (doubleword load/store)
21586 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
21587 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
21588 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
21589 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
21590 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
21592 Uppercase letters indicate bits that are already encoded at
21593 this point. Lowercase letters are our problem. For the
21594 second block of instructions, the secondary opcode nybble
21595 (bits 8..11) is present, and bit 23 is zero, even if this is
21596 a PC-relative operation. */
21597 newval = md_chars_to_number (buf, THUMB_SIZE);
21599 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
21601 if ((newval & 0xf0000000) == 0xe0000000)
21603 /* Doubleword load/store: 8-bit offset, scaled by 4. */
21605 newval |= (1 << 23);
21608 if (value % 4 != 0)
21610 as_bad_where (fixP->fx_file, fixP->fx_line,
21611 _("offset not a multiple of 4"));
21617 as_bad_where (fixP->fx_file, fixP->fx_line,
21618 _("offset out of range"));
21623 else if ((newval & 0x000f0000) == 0x000f0000)
21625 /* PC-relative, 12-bit offset. */
21627 newval |= (1 << 23);
21632 as_bad_where (fixP->fx_file, fixP->fx_line,
21633 _("offset out of range"));
21638 else if ((newval & 0x00000100) == 0x00000100)
21640 /* Writeback: 8-bit, +/- offset. */
21642 newval |= (1 << 9);
21647 as_bad_where (fixP->fx_file, fixP->fx_line,
21648 _("offset out of range"));
21653 else if ((newval & 0x00000f00) == 0x00000e00)
21655 /* T-instruction: positive 8-bit offset. */
21656 if (value < 0 || value > 0xff)
21658 as_bad_where (fixP->fx_file, fixP->fx_line,
21659 _("offset out of range"));
21667 /* Positive 12-bit or negative 8-bit offset. */
21671 newval |= (1 << 23);
21681 as_bad_where (fixP->fx_file, fixP->fx_line,
21682 _("offset out of range"));
21689 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
21690 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
21693 case BFD_RELOC_ARM_SHIFT_IMM:
21694 newval = md_chars_to_number (buf, INSN_SIZE);
21695 if (((unsigned long) value) > 32
21697 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
21699 as_bad_where (fixP->fx_file, fixP->fx_line,
21700 _("shift expression is too large"));
21705 /* Shifts of zero must be done as lsl. */
21707 else if (value == 32)
21709 newval &= 0xfffff07f;
21710 newval |= (value & 0x1f) << 7;
21711 md_number_to_chars (buf, newval, INSN_SIZE);
21714 case BFD_RELOC_ARM_T32_IMMEDIATE:
21715 case BFD_RELOC_ARM_T32_ADD_IMM:
21716 case BFD_RELOC_ARM_T32_IMM12:
21717 case BFD_RELOC_ARM_T32_ADD_PC12:
21718 /* We claim that this fixup has been processed here,
21719 even if in fact we generate an error because we do
21720 not have a reloc for it, so tc_gen_reloc will reject it. */
21724 && ! S_IS_DEFINED (fixP->fx_addsy))
21726 as_bad_where (fixP->fx_file, fixP->fx_line,
21727 _("undefined symbol %s used as an immediate value"),
21728 S_GET_NAME (fixP->fx_addsy));
21732 newval = md_chars_to_number (buf, THUMB_SIZE);
21734 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
21737 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21738 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
21740 newimm = encode_thumb32_immediate (value);
21741 if (newimm == (unsigned int) FAIL)
21742 newimm = thumb32_negate_data_op (&newval, value);
21744 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
21745 && newimm == (unsigned int) FAIL)
21747 /* Turn add/sum into addw/subw. */
21748 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
21749 newval = (newval & 0xfeffffff) | 0x02000000;
21750 /* No flat 12-bit imm encoding for addsw/subsw. */
21751 if ((newval & 0x00100000) == 0)
21753 /* 12 bit immediate for addw/subw. */
21757 newval ^= 0x00a00000;
21760 newimm = (unsigned int) FAIL;
21766 if (newimm == (unsigned int)FAIL)
21768 as_bad_where (fixP->fx_file, fixP->fx_line,
21769 _("invalid constant (%lx) after fixup"),
21770 (unsigned long) value);
21774 newval |= (newimm & 0x800) << 15;
21775 newval |= (newimm & 0x700) << 4;
21776 newval |= (newimm & 0x0ff);
21778 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
21779 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
21782 case BFD_RELOC_ARM_SMC:
21783 if (((unsigned long) value) > 0xffff)
21784 as_bad_where (fixP->fx_file, fixP->fx_line,
21785 _("invalid smc expression"));
21786 newval = md_chars_to_number (buf, INSN_SIZE);
21787 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21788 md_number_to_chars (buf, newval, INSN_SIZE);
21791 case BFD_RELOC_ARM_HVC:
21792 if (((unsigned long) value) > 0xffff)
21793 as_bad_where (fixP->fx_file, fixP->fx_line,
21794 _("invalid hvc expression"));
21795 newval = md_chars_to_number (buf, INSN_SIZE);
21796 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21797 md_number_to_chars (buf, newval, INSN_SIZE);
21800 case BFD_RELOC_ARM_SWI:
21801 if (fixP->tc_fix_data != 0)
21803 if (((unsigned long) value) > 0xff)
21804 as_bad_where (fixP->fx_file, fixP->fx_line,
21805 _("invalid swi expression"));
21806 newval = md_chars_to_number (buf, THUMB_SIZE);
21808 md_number_to_chars (buf, newval, THUMB_SIZE);
21812 if (((unsigned long) value) > 0x00ffffff)
21813 as_bad_where (fixP->fx_file, fixP->fx_line,
21814 _("invalid swi expression"));
21815 newval = md_chars_to_number (buf, INSN_SIZE);
21817 md_number_to_chars (buf, newval, INSN_SIZE);
21821 case BFD_RELOC_ARM_MULTI:
21822 if (((unsigned long) value) > 0xffff)
21823 as_bad_where (fixP->fx_file, fixP->fx_line,
21824 _("invalid expression in load/store multiple"));
21825 newval = value | md_chars_to_number (buf, INSN_SIZE);
21826 md_number_to_chars (buf, newval, INSN_SIZE);
21830 case BFD_RELOC_ARM_PCREL_CALL:
21832 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21834 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21835 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21836 && THUMB_IS_FUNC (fixP->fx_addsy))
21837 /* Flip the bl to blx. This is a simple flip
21838 bit here because we generate PCREL_CALL for
21839 unconditional bls. */
21841 newval = md_chars_to_number (buf, INSN_SIZE);
21842 newval = newval | 0x10000000;
21843 md_number_to_chars (buf, newval, INSN_SIZE);
21849 goto arm_branch_common;
21851 case BFD_RELOC_ARM_PCREL_JUMP:
21852 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21854 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21855 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21856 && THUMB_IS_FUNC (fixP->fx_addsy))
21858 /* This would map to a bl<cond>, b<cond>,
21859 b<always> to a Thumb function. We
21860 need to force a relocation for this particular
21862 newval = md_chars_to_number (buf, INSN_SIZE);
21866 case BFD_RELOC_ARM_PLT32:
21868 case BFD_RELOC_ARM_PCREL_BRANCH:
21870 goto arm_branch_common;
21872 case BFD_RELOC_ARM_PCREL_BLX:
21875 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21877 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21878 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21879 && ARM_IS_FUNC (fixP->fx_addsy))
21881 /* Flip the blx to a bl and warn. */
21882 const char *name = S_GET_NAME (fixP->fx_addsy);
21883 newval = 0xeb000000;
21884 as_warn_where (fixP->fx_file, fixP->fx_line,
21885 _("blx to '%s' an ARM ISA state function changed to bl"),
21887 md_number_to_chars (buf, newval, INSN_SIZE);
21893 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21894 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
21898 /* We are going to store value (shifted right by two) in the
21899 instruction, in a 24 bit, signed field. Bits 26 through 32 either
21900 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
21901 also be be clear. */
21903 as_bad_where (fixP->fx_file, fixP->fx_line,
21904 _("misaligned branch destination"));
21905 if ((value & (offsetT)0xfe000000) != (offsetT)0
21906 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
21907 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21909 if (fixP->fx_done || !seg->use_rela_p)
21911 newval = md_chars_to_number (buf, INSN_SIZE);
21912 newval |= (value >> 2) & 0x00ffffff;
21913 /* Set the H bit on BLX instructions. */
21917 newval |= 0x01000000;
21919 newval &= ~0x01000000;
21921 md_number_to_chars (buf, newval, INSN_SIZE);
21925 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
21926 /* CBZ can only branch forward. */
21928 /* Attempts to use CBZ to branch to the next instruction
21929 (which, strictly speaking, are prohibited) will be turned into
21932 FIXME: It may be better to remove the instruction completely and
21933 perform relaxation. */
21936 newval = md_chars_to_number (buf, THUMB_SIZE);
21937 newval = 0xbf00; /* NOP encoding T1 */
21938 md_number_to_chars (buf, newval, THUMB_SIZE);
21943 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21945 if (fixP->fx_done || !seg->use_rela_p)
21947 newval = md_chars_to_number (buf, THUMB_SIZE);
21948 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
21949 md_number_to_chars (buf, newval, THUMB_SIZE);
21954 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
21955 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
21956 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21958 if (fixP->fx_done || !seg->use_rela_p)
21960 newval = md_chars_to_number (buf, THUMB_SIZE);
21961 newval |= (value & 0x1ff) >> 1;
21962 md_number_to_chars (buf, newval, THUMB_SIZE);
21966 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
21967 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
21968 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21970 if (fixP->fx_done || !seg->use_rela_p)
21972 newval = md_chars_to_number (buf, THUMB_SIZE);
21973 newval |= (value & 0xfff) >> 1;
21974 md_number_to_chars (buf, newval, THUMB_SIZE);
21978 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21980 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21981 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21982 && ARM_IS_FUNC (fixP->fx_addsy)
21983 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21985 /* Force a relocation for a branch 20 bits wide. */
21988 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
21989 as_bad_where (fixP->fx_file, fixP->fx_line,
21990 _("conditional branch out of range"));
21992 if (fixP->fx_done || !seg->use_rela_p)
21995 addressT S, J1, J2, lo, hi;
21997 S = (value & 0x00100000) >> 20;
21998 J2 = (value & 0x00080000) >> 19;
21999 J1 = (value & 0x00040000) >> 18;
22000 hi = (value & 0x0003f000) >> 12;
22001 lo = (value & 0x00000ffe) >> 1;
22003 newval = md_chars_to_number (buf, THUMB_SIZE);
22004 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22005 newval |= (S << 10) | hi;
22006 newval2 |= (J1 << 13) | (J2 << 11) | lo;
22007 md_number_to_chars (buf, newval, THUMB_SIZE);
22008 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22012 case BFD_RELOC_THUMB_PCREL_BLX:
22013 /* If there is a blx from a thumb state function to
22014 another thumb function flip this to a bl and warn
22018 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22019 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22020 && THUMB_IS_FUNC (fixP->fx_addsy))
22022 const char *name = S_GET_NAME (fixP->fx_addsy);
22023 as_warn_where (fixP->fx_file, fixP->fx_line,
22024 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
22026 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22027 newval = newval | 0x1000;
22028 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22029 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22034 goto thumb_bl_common;
22036 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22037 /* A bl from Thumb state ISA to an internal ARM state function
22038 is converted to a blx. */
22040 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22041 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22042 && ARM_IS_FUNC (fixP->fx_addsy)
22043 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22045 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22046 newval = newval & ~0x1000;
22047 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22048 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
22054 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22055 /* For a BLX instruction, make sure that the relocation is rounded up
22056 to a word boundary. This follows the semantics of the instruction
22057 which specifies that bit 1 of the target address will come from bit
22058 1 of the base address. */
22059 value = (value + 3) & ~ 3;
22062 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
22063 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22064 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22067 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
22069 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
22070 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22071 else if ((value & ~0x1ffffff)
22072 && ((value & ~0x1ffffff) != ~0x1ffffff))
22073 as_bad_where (fixP->fx_file, fixP->fx_line,
22074 _("Thumb2 branch out of range"));
22077 if (fixP->fx_done || !seg->use_rela_p)
22078 encode_thumb2_b_bl_offset (buf, value);
22082 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22083 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
22084 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22086 if (fixP->fx_done || !seg->use_rela_p)
22087 encode_thumb2_b_bl_offset (buf, value);
22092 if (fixP->fx_done || !seg->use_rela_p)
22093 md_number_to_chars (buf, value, 1);
22097 if (fixP->fx_done || !seg->use_rela_p)
22098 md_number_to_chars (buf, value, 2);
22102 case BFD_RELOC_ARM_TLS_CALL:
22103 case BFD_RELOC_ARM_THM_TLS_CALL:
22104 case BFD_RELOC_ARM_TLS_DESCSEQ:
22105 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
22106 S_SET_THREAD_LOCAL (fixP->fx_addsy);
22109 case BFD_RELOC_ARM_TLS_GOTDESC:
22110 case BFD_RELOC_ARM_TLS_GD32:
22111 case BFD_RELOC_ARM_TLS_LE32:
22112 case BFD_RELOC_ARM_TLS_IE32:
22113 case BFD_RELOC_ARM_TLS_LDM32:
22114 case BFD_RELOC_ARM_TLS_LDO32:
22115 S_SET_THREAD_LOCAL (fixP->fx_addsy);
22118 case BFD_RELOC_ARM_GOT32:
22119 case BFD_RELOC_ARM_GOTOFF:
22120 if (fixP->fx_done || !seg->use_rela_p)
22121 md_number_to_chars (buf, 0, 4);
22124 case BFD_RELOC_ARM_GOT_PREL:
22125 if (fixP->fx_done || !seg->use_rela_p)
22126 md_number_to_chars (buf, value, 4);
22129 case BFD_RELOC_ARM_TARGET2:
22130 /* TARGET2 is not partial-inplace, so we need to write the
22131 addend here for REL targets, because it won't be written out
22132 during reloc processing later. */
22133 if (fixP->fx_done || !seg->use_rela_p)
22134 md_number_to_chars (buf, fixP->fx_offset, 4);
22138 case BFD_RELOC_RVA:
22140 case BFD_RELOC_ARM_TARGET1:
22141 case BFD_RELOC_ARM_ROSEGREL32:
22142 case BFD_RELOC_ARM_SBREL32:
22143 case BFD_RELOC_32_PCREL:
22145 case BFD_RELOC_32_SECREL:
22147 if (fixP->fx_done || !seg->use_rela_p)
22149 /* For WinCE we only do this for pcrel fixups. */
22150 if (fixP->fx_done || fixP->fx_pcrel)
22152 md_number_to_chars (buf, value, 4);
22156 case BFD_RELOC_ARM_PREL31:
22157 if (fixP->fx_done || !seg->use_rela_p)
22159 newval = md_chars_to_number (buf, 4) & 0x80000000;
22160 if ((value ^ (value >> 1)) & 0x40000000)
22162 as_bad_where (fixP->fx_file, fixP->fx_line,
22163 _("rel31 relocation overflow"));
22165 newval |= value & 0x7fffffff;
22166 md_number_to_chars (buf, newval, 4);
22171 case BFD_RELOC_ARM_CP_OFF_IMM:
22172 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
22173 if (value < -1023 || value > 1023 || (value & 3))
22174 as_bad_where (fixP->fx_file, fixP->fx_line,
22175 _("co-processor offset out of range"));
22180 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22181 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22182 newval = md_chars_to_number (buf, INSN_SIZE);
22184 newval = get_thumb32_insn (buf);
22186 newval &= 0xffffff00;
22189 newval &= 0xff7fff00;
22190 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
22192 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22193 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22194 md_number_to_chars (buf, newval, INSN_SIZE);
22196 put_thumb32_insn (buf, newval);
22199 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
22200 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
22201 if (value < -255 || value > 255)
22202 as_bad_where (fixP->fx_file, fixP->fx_line,
22203 _("co-processor offset out of range"));
22205 goto cp_off_common;
22207 case BFD_RELOC_ARM_THUMB_OFFSET:
22208 newval = md_chars_to_number (buf, THUMB_SIZE);
22209 /* Exactly what ranges, and where the offset is inserted depends
22210 on the type of instruction, we can establish this from the
22212 switch (newval >> 12)
22214 case 4: /* PC load. */
22215 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
22216 forced to zero for these loads; md_pcrel_from has already
22217 compensated for this. */
22219 as_bad_where (fixP->fx_file, fixP->fx_line,
22220 _("invalid offset, target not word aligned (0x%08lX)"),
22221 (((unsigned long) fixP->fx_frag->fr_address
22222 + (unsigned long) fixP->fx_where) & ~3)
22223 + (unsigned long) value);
22225 if (value & ~0x3fc)
22226 as_bad_where (fixP->fx_file, fixP->fx_line,
22227 _("invalid offset, value too big (0x%08lX)"),
22230 newval |= value >> 2;
22233 case 9: /* SP load/store. */
22234 if (value & ~0x3fc)
22235 as_bad_where (fixP->fx_file, fixP->fx_line,
22236 _("invalid offset, value too big (0x%08lX)"),
22238 newval |= value >> 2;
22241 case 6: /* Word load/store. */
22243 as_bad_where (fixP->fx_file, fixP->fx_line,
22244 _("invalid offset, value too big (0x%08lX)"),
22246 newval |= value << 4; /* 6 - 2. */
22249 case 7: /* Byte load/store. */
22251 as_bad_where (fixP->fx_file, fixP->fx_line,
22252 _("invalid offset, value too big (0x%08lX)"),
22254 newval |= value << 6;
22257 case 8: /* Halfword load/store. */
22259 as_bad_where (fixP->fx_file, fixP->fx_line,
22260 _("invalid offset, value too big (0x%08lX)"),
22262 newval |= value << 5; /* 6 - 1. */
22266 as_bad_where (fixP->fx_file, fixP->fx_line,
22267 "Unable to process relocation for thumb opcode: %lx",
22268 (unsigned long) newval);
22271 md_number_to_chars (buf, newval, THUMB_SIZE);
22274 case BFD_RELOC_ARM_THUMB_ADD:
22275 /* This is a complicated relocation, since we use it for all of
22276 the following immediate relocations:
22280 9bit ADD/SUB SP word-aligned
22281 10bit ADD PC/SP word-aligned
22283 The type of instruction being processed is encoded in the
22290 newval = md_chars_to_number (buf, THUMB_SIZE);
22292 int rd = (newval >> 4) & 0xf;
22293 int rs = newval & 0xf;
22294 int subtract = !!(newval & 0x8000);
22296 /* Check for HI regs, only very restricted cases allowed:
22297 Adjusting SP, and using PC or SP to get an address. */
22298 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
22299 || (rs > 7 && rs != REG_SP && rs != REG_PC))
22300 as_bad_where (fixP->fx_file, fixP->fx_line,
22301 _("invalid Hi register with immediate"));
22303 /* If value is negative, choose the opposite instruction. */
22307 subtract = !subtract;
22309 as_bad_where (fixP->fx_file, fixP->fx_line,
22310 _("immediate value out of range"));
22315 if (value & ~0x1fc)
22316 as_bad_where (fixP->fx_file, fixP->fx_line,
22317 _("invalid immediate for stack address calculation"));
22318 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
22319 newval |= value >> 2;
22321 else if (rs == REG_PC || rs == REG_SP)
22323 if (subtract || value & ~0x3fc)
22324 as_bad_where (fixP->fx_file, fixP->fx_line,
22325 _("invalid immediate for address calculation (value = 0x%08lX)"),
22326 (unsigned long) value);
22327 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
22329 newval |= value >> 2;
22334 as_bad_where (fixP->fx_file, fixP->fx_line,
22335 _("immediate value out of range"));
22336 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
22337 newval |= (rd << 8) | value;
22342 as_bad_where (fixP->fx_file, fixP->fx_line,
22343 _("immediate value out of range"));
22344 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
22345 newval |= rd | (rs << 3) | (value << 6);
22348 md_number_to_chars (buf, newval, THUMB_SIZE);
22351 case BFD_RELOC_ARM_THUMB_IMM:
22352 newval = md_chars_to_number (buf, THUMB_SIZE);
22353 if (value < 0 || value > 255)
22354 as_bad_where (fixP->fx_file, fixP->fx_line,
22355 _("invalid immediate: %ld is out of range"),
22358 md_number_to_chars (buf, newval, THUMB_SIZE);
22361 case BFD_RELOC_ARM_THUMB_SHIFT:
22362 /* 5bit shift value (0..32). LSL cannot take 32. */
22363 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
22364 temp = newval & 0xf800;
22365 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
22366 as_bad_where (fixP->fx_file, fixP->fx_line,
22367 _("invalid shift value: %ld"), (long) value);
22368 /* Shifts of zero must be encoded as LSL. */
22370 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
22371 /* Shifts of 32 are encoded as zero. */
22372 else if (value == 32)
22374 newval |= value << 6;
22375 md_number_to_chars (buf, newval, THUMB_SIZE);
22378 case BFD_RELOC_VTABLE_INHERIT:
22379 case BFD_RELOC_VTABLE_ENTRY:
22383 case BFD_RELOC_ARM_MOVW:
22384 case BFD_RELOC_ARM_MOVT:
22385 case BFD_RELOC_ARM_THUMB_MOVW:
22386 case BFD_RELOC_ARM_THUMB_MOVT:
22387 if (fixP->fx_done || !seg->use_rela_p)
22389 /* REL format relocations are limited to a 16-bit addend. */
22390 if (!fixP->fx_done)
22392 if (value < -0x8000 || value > 0x7fff)
22393 as_bad_where (fixP->fx_file, fixP->fx_line,
22394 _("offset out of range"));
22396 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22397 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
22402 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22403 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
22405 newval = get_thumb32_insn (buf);
22406 newval &= 0xfbf08f00;
22407 newval |= (value & 0xf000) << 4;
22408 newval |= (value & 0x0800) << 15;
22409 newval |= (value & 0x0700) << 4;
22410 newval |= (value & 0x00ff);
22411 put_thumb32_insn (buf, newval);
22415 newval = md_chars_to_number (buf, 4);
22416 newval &= 0xfff0f000;
22417 newval |= value & 0x0fff;
22418 newval |= (value & 0xf000) << 4;
22419 md_number_to_chars (buf, newval, 4);
22424 case BFD_RELOC_ARM_ALU_PC_G0_NC:
22425 case BFD_RELOC_ARM_ALU_PC_G0:
22426 case BFD_RELOC_ARM_ALU_PC_G1_NC:
22427 case BFD_RELOC_ARM_ALU_PC_G1:
22428 case BFD_RELOC_ARM_ALU_PC_G2:
22429 case BFD_RELOC_ARM_ALU_SB_G0_NC:
22430 case BFD_RELOC_ARM_ALU_SB_G0:
22431 case BFD_RELOC_ARM_ALU_SB_G1_NC:
22432 case BFD_RELOC_ARM_ALU_SB_G1:
22433 case BFD_RELOC_ARM_ALU_SB_G2:
22434 gas_assert (!fixP->fx_done);
22435 if (!seg->use_rela_p)
22438 bfd_vma encoded_addend;
22439 bfd_vma addend_abs = abs (value);
22441 /* Check that the absolute value of the addend can be
22442 expressed as an 8-bit constant plus a rotation. */
22443 encoded_addend = encode_arm_immediate (addend_abs);
22444 if (encoded_addend == (unsigned int) FAIL)
22445 as_bad_where (fixP->fx_file, fixP->fx_line,
22446 _("the offset 0x%08lX is not representable"),
22447 (unsigned long) addend_abs);
22449 /* Extract the instruction. */
22450 insn = md_chars_to_number (buf, INSN_SIZE);
22452 /* If the addend is positive, use an ADD instruction.
22453 Otherwise use a SUB. Take care not to destroy the S bit. */
22454 insn &= 0xff1fffff;
22460 /* Place the encoded addend into the first 12 bits of the
22462 insn &= 0xfffff000;
22463 insn |= encoded_addend;
22465 /* Update the instruction. */
22466 md_number_to_chars (buf, insn, INSN_SIZE);
22470 case BFD_RELOC_ARM_LDR_PC_G0:
22471 case BFD_RELOC_ARM_LDR_PC_G1:
22472 case BFD_RELOC_ARM_LDR_PC_G2:
22473 case BFD_RELOC_ARM_LDR_SB_G0:
22474 case BFD_RELOC_ARM_LDR_SB_G1:
22475 case BFD_RELOC_ARM_LDR_SB_G2:
22476 gas_assert (!fixP->fx_done);
22477 if (!seg->use_rela_p)
22480 bfd_vma addend_abs = abs (value);
22482 /* Check that the absolute value of the addend can be
22483 encoded in 12 bits. */
22484 if (addend_abs >= 0x1000)
22485 as_bad_where (fixP->fx_file, fixP->fx_line,
22486 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
22487 (unsigned long) addend_abs);
22489 /* Extract the instruction. */
22490 insn = md_chars_to_number (buf, INSN_SIZE);
22492 /* If the addend is negative, clear bit 23 of the instruction.
22493 Otherwise set it. */
22495 insn &= ~(1 << 23);
22499 /* Place the absolute value of the addend into the first 12 bits
22500 of the instruction. */
22501 insn &= 0xfffff000;
22502 insn |= addend_abs;
22504 /* Update the instruction. */
22505 md_number_to_chars (buf, insn, INSN_SIZE);
22509 case BFD_RELOC_ARM_LDRS_PC_G0:
22510 case BFD_RELOC_ARM_LDRS_PC_G1:
22511 case BFD_RELOC_ARM_LDRS_PC_G2:
22512 case BFD_RELOC_ARM_LDRS_SB_G0:
22513 case BFD_RELOC_ARM_LDRS_SB_G1:
22514 case BFD_RELOC_ARM_LDRS_SB_G2:
22515 gas_assert (!fixP->fx_done);
22516 if (!seg->use_rela_p)
22519 bfd_vma addend_abs = abs (value);
22521 /* Check that the absolute value of the addend can be
22522 encoded in 8 bits. */
22523 if (addend_abs >= 0x100)
22524 as_bad_where (fixP->fx_file, fixP->fx_line,
22525 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
22526 (unsigned long) addend_abs);
22528 /* Extract the instruction. */
22529 insn = md_chars_to_number (buf, INSN_SIZE);
22531 /* If the addend is negative, clear bit 23 of the instruction.
22532 Otherwise set it. */
22534 insn &= ~(1 << 23);
22538 /* Place the first four bits of the absolute value of the addend
22539 into the first 4 bits of the instruction, and the remaining
22540 four into bits 8 .. 11. */
22541 insn &= 0xfffff0f0;
22542 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
22544 /* Update the instruction. */
22545 md_number_to_chars (buf, insn, INSN_SIZE);
22549 case BFD_RELOC_ARM_LDC_PC_G0:
22550 case BFD_RELOC_ARM_LDC_PC_G1:
22551 case BFD_RELOC_ARM_LDC_PC_G2:
22552 case BFD_RELOC_ARM_LDC_SB_G0:
22553 case BFD_RELOC_ARM_LDC_SB_G1:
22554 case BFD_RELOC_ARM_LDC_SB_G2:
22555 gas_assert (!fixP->fx_done);
22556 if (!seg->use_rela_p)
22559 bfd_vma addend_abs = abs (value);
22561 /* Check that the absolute value of the addend is a multiple of
22562 four and, when divided by four, fits in 8 bits. */
22563 if (addend_abs & 0x3)
22564 as_bad_where (fixP->fx_file, fixP->fx_line,
22565 _("bad offset 0x%08lX (must be word-aligned)"),
22566 (unsigned long) addend_abs);
22568 if ((addend_abs >> 2) > 0xff)
22569 as_bad_where (fixP->fx_file, fixP->fx_line,
22570 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
22571 (unsigned long) addend_abs);
22573 /* Extract the instruction. */
22574 insn = md_chars_to_number (buf, INSN_SIZE);
22576 /* If the addend is negative, clear bit 23 of the instruction.
22577 Otherwise set it. */
22579 insn &= ~(1 << 23);
22583 /* Place the addend (divided by four) into the first eight
22584 bits of the instruction. */
22585 insn &= 0xfffffff0;
22586 insn |= addend_abs >> 2;
22588 /* Update the instruction. */
22589 md_number_to_chars (buf, insn, INSN_SIZE);
22593 case BFD_RELOC_ARM_V4BX:
22594 /* This will need to go in the object file. */
22598 case BFD_RELOC_UNUSED:
22600 as_bad_where (fixP->fx_file, fixP->fx_line,
22601 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
22605 /* Translate internal representation of relocation info to BFD target
22609 tc_gen_reloc (asection *section, fixS *fixp)
22612 bfd_reloc_code_real_type code;
22614 reloc = (arelent *) xmalloc (sizeof (arelent));
22616 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
22617 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
22618 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
22620 if (fixp->fx_pcrel)
22622 if (section->use_rela_p)
22623 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
22625 fixp->fx_offset = reloc->address;
22627 reloc->addend = fixp->fx_offset;
22629 switch (fixp->fx_r_type)
22632 if (fixp->fx_pcrel)
22634 code = BFD_RELOC_8_PCREL;
22639 if (fixp->fx_pcrel)
22641 code = BFD_RELOC_16_PCREL;
22646 if (fixp->fx_pcrel)
22648 code = BFD_RELOC_32_PCREL;
22652 case BFD_RELOC_ARM_MOVW:
22653 if (fixp->fx_pcrel)
22655 code = BFD_RELOC_ARM_MOVW_PCREL;
22659 case BFD_RELOC_ARM_MOVT:
22660 if (fixp->fx_pcrel)
22662 code = BFD_RELOC_ARM_MOVT_PCREL;
22666 case BFD_RELOC_ARM_THUMB_MOVW:
22667 if (fixp->fx_pcrel)
22669 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
22673 case BFD_RELOC_ARM_THUMB_MOVT:
22674 if (fixp->fx_pcrel)
22676 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
22680 case BFD_RELOC_NONE:
22681 case BFD_RELOC_ARM_PCREL_BRANCH:
22682 case BFD_RELOC_ARM_PCREL_BLX:
22683 case BFD_RELOC_RVA:
22684 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22685 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22686 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22687 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22688 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22689 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22690 case BFD_RELOC_VTABLE_ENTRY:
22691 case BFD_RELOC_VTABLE_INHERIT:
22693 case BFD_RELOC_32_SECREL:
22695 code = fixp->fx_r_type;
22698 case BFD_RELOC_THUMB_PCREL_BLX:
22700 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
22701 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
22704 code = BFD_RELOC_THUMB_PCREL_BLX;
22707 case BFD_RELOC_ARM_LITERAL:
22708 case BFD_RELOC_ARM_HWLITERAL:
22709 /* If this is called then the a literal has
22710 been referenced across a section boundary. */
22711 as_bad_where (fixp->fx_file, fixp->fx_line,
22712 _("literal referenced across section boundary"));
22716 case BFD_RELOC_ARM_TLS_CALL:
22717 case BFD_RELOC_ARM_THM_TLS_CALL:
22718 case BFD_RELOC_ARM_TLS_DESCSEQ:
22719 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
22720 case BFD_RELOC_ARM_GOT32:
22721 case BFD_RELOC_ARM_GOTOFF:
22722 case BFD_RELOC_ARM_GOT_PREL:
22723 case BFD_RELOC_ARM_PLT32:
22724 case BFD_RELOC_ARM_TARGET1:
22725 case BFD_RELOC_ARM_ROSEGREL32:
22726 case BFD_RELOC_ARM_SBREL32:
22727 case BFD_RELOC_ARM_PREL31:
22728 case BFD_RELOC_ARM_TARGET2:
22729 case BFD_RELOC_ARM_TLS_LE32:
22730 case BFD_RELOC_ARM_TLS_LDO32:
22731 case BFD_RELOC_ARM_PCREL_CALL:
22732 case BFD_RELOC_ARM_PCREL_JUMP:
22733 case BFD_RELOC_ARM_ALU_PC_G0_NC:
22734 case BFD_RELOC_ARM_ALU_PC_G0:
22735 case BFD_RELOC_ARM_ALU_PC_G1_NC:
22736 case BFD_RELOC_ARM_ALU_PC_G1:
22737 case BFD_RELOC_ARM_ALU_PC_G2:
22738 case BFD_RELOC_ARM_LDR_PC_G0:
22739 case BFD_RELOC_ARM_LDR_PC_G1:
22740 case BFD_RELOC_ARM_LDR_PC_G2:
22741 case BFD_RELOC_ARM_LDRS_PC_G0:
22742 case BFD_RELOC_ARM_LDRS_PC_G1:
22743 case BFD_RELOC_ARM_LDRS_PC_G2:
22744 case BFD_RELOC_ARM_LDC_PC_G0:
22745 case BFD_RELOC_ARM_LDC_PC_G1:
22746 case BFD_RELOC_ARM_LDC_PC_G2:
22747 case BFD_RELOC_ARM_ALU_SB_G0_NC:
22748 case BFD_RELOC_ARM_ALU_SB_G0:
22749 case BFD_RELOC_ARM_ALU_SB_G1_NC:
22750 case BFD_RELOC_ARM_ALU_SB_G1:
22751 case BFD_RELOC_ARM_ALU_SB_G2:
22752 case BFD_RELOC_ARM_LDR_SB_G0:
22753 case BFD_RELOC_ARM_LDR_SB_G1:
22754 case BFD_RELOC_ARM_LDR_SB_G2:
22755 case BFD_RELOC_ARM_LDRS_SB_G0:
22756 case BFD_RELOC_ARM_LDRS_SB_G1:
22757 case BFD_RELOC_ARM_LDRS_SB_G2:
22758 case BFD_RELOC_ARM_LDC_SB_G0:
22759 case BFD_RELOC_ARM_LDC_SB_G1:
22760 case BFD_RELOC_ARM_LDC_SB_G2:
22761 case BFD_RELOC_ARM_V4BX:
22762 code = fixp->fx_r_type;
22765 case BFD_RELOC_ARM_TLS_GOTDESC:
22766 case BFD_RELOC_ARM_TLS_GD32:
22767 case BFD_RELOC_ARM_TLS_IE32:
22768 case BFD_RELOC_ARM_TLS_LDM32:
22769 /* BFD will include the symbol's address in the addend.
22770 But we don't want that, so subtract it out again here. */
22771 if (!S_IS_COMMON (fixp->fx_addsy))
22772 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
22773 code = fixp->fx_r_type;
22777 case BFD_RELOC_ARM_IMMEDIATE:
22778 as_bad_where (fixp->fx_file, fixp->fx_line,
22779 _("internal relocation (type: IMMEDIATE) not fixed up"));
22782 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22783 as_bad_where (fixp->fx_file, fixp->fx_line,
22784 _("ADRL used for a symbol not defined in the same file"));
22787 case BFD_RELOC_ARM_OFFSET_IMM:
22788 if (section->use_rela_p)
22790 code = fixp->fx_r_type;
22794 if (fixp->fx_addsy != NULL
22795 && !S_IS_DEFINED (fixp->fx_addsy)
22796 && S_IS_LOCAL (fixp->fx_addsy))
22798 as_bad_where (fixp->fx_file, fixp->fx_line,
22799 _("undefined local label `%s'"),
22800 S_GET_NAME (fixp->fx_addsy));
22804 as_bad_where (fixp->fx_file, fixp->fx_line,
22805 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
22812 switch (fixp->fx_r_type)
22814 case BFD_RELOC_NONE: type = "NONE"; break;
22815 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
22816 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
22817 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
22818 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
22819 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
22820 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
22821 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
22822 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
22823 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
22824 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
22825 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
22826 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
22827 default: type = _("<unknown>"); break;
22829 as_bad_where (fixp->fx_file, fixp->fx_line,
22830 _("cannot represent %s relocation in this object file format"),
22837 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
22839 && fixp->fx_addsy == GOT_symbol)
22841 code = BFD_RELOC_ARM_GOTPC;
22842 reloc->addend = fixp->fx_offset = reloc->address;
22846 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
22848 if (reloc->howto == NULL)
22850 as_bad_where (fixp->fx_file, fixp->fx_line,
22851 _("cannot represent %s relocation in this object file format"),
22852 bfd_get_reloc_code_name (code));
22856 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
22857 vtable entry to be used in the relocation's section offset. */
22858 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
22859 reloc->address = fixp->fx_offset;
22864 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
22867 cons_fix_new_arm (fragS * frag,
22872 bfd_reloc_code_real_type type;
22876 FIXME: @@ Should look at CPU word size. */
22880 type = BFD_RELOC_8;
22883 type = BFD_RELOC_16;
22887 type = BFD_RELOC_32;
22890 type = BFD_RELOC_64;
22895 if (exp->X_op == O_secrel)
22897 exp->X_op = O_symbol;
22898 type = BFD_RELOC_32_SECREL;
22902 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
22905 #if defined (OBJ_COFF)
22907 arm_validate_fix (fixS * fixP)
22909 /* If the destination of the branch is a defined symbol which does not have
22910 the THUMB_FUNC attribute, then we must be calling a function which has
22911 the (interfacearm) attribute. We look for the Thumb entry point to that
22912 function and change the branch to refer to that function instead. */
22913 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
22914 && fixP->fx_addsy != NULL
22915 && S_IS_DEFINED (fixP->fx_addsy)
22916 && ! THUMB_IS_FUNC (fixP->fx_addsy))
22918 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
22925 arm_force_relocation (struct fix * fixp)
22927 #if defined (OBJ_COFF) && defined (TE_PE)
22928 if (fixp->fx_r_type == BFD_RELOC_RVA)
22932 /* In case we have a call or a branch to a function in ARM ISA mode from
22933 a thumb function or vice-versa force the relocation. These relocations
22934 are cleared off for some cores that might have blx and simple transformations
22938 switch (fixp->fx_r_type)
22940 case BFD_RELOC_ARM_PCREL_JUMP:
22941 case BFD_RELOC_ARM_PCREL_CALL:
22942 case BFD_RELOC_THUMB_PCREL_BLX:
22943 if (THUMB_IS_FUNC (fixp->fx_addsy))
22947 case BFD_RELOC_ARM_PCREL_BLX:
22948 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22949 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22950 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22951 if (ARM_IS_FUNC (fixp->fx_addsy))
22960 /* Resolve these relocations even if the symbol is extern or weak.
22961 Technically this is probably wrong due to symbol preemption.
22962 In practice these relocations do not have enough range to be useful
22963 at dynamic link time, and some code (e.g. in the Linux kernel)
22964 expects these references to be resolved. */
22965 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
22966 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
22967 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
22968 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
22969 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22970 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
22971 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
22972 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
22973 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22974 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
22975 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
22976 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
22977 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
22978 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
22981 /* Always leave these relocations for the linker. */
22982 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22983 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22984 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22987 /* Always generate relocations against function symbols. */
22988 if (fixp->fx_r_type == BFD_RELOC_32
22990 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
22993 return generic_force_reloc (fixp);
22996 #if defined (OBJ_ELF) || defined (OBJ_COFF)
22997 /* Relocations against function names must be left unadjusted,
22998 so that the linker can use this information to generate interworking
22999 stubs. The MIPS version of this function
23000 also prevents relocations that are mips-16 specific, but I do not
23001 know why it does this.
23004 There is one other problem that ought to be addressed here, but
23005 which currently is not: Taking the address of a label (rather
23006 than a function) and then later jumping to that address. Such
23007 addresses also ought to have their bottom bit set (assuming that
23008 they reside in Thumb code), but at the moment they will not. */
23011 arm_fix_adjustable (fixS * fixP)
23013 if (fixP->fx_addsy == NULL)
23016 /* Preserve relocations against symbols with function type. */
23017 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
23020 if (THUMB_IS_FUNC (fixP->fx_addsy)
23021 && fixP->fx_subsy == NULL)
23024 /* We need the symbol name for the VTABLE entries. */
23025 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
23026 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
23029 /* Don't allow symbols to be discarded on GOT related relocs. */
23030 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
23031 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
23032 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
23033 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
23034 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
23035 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
23036 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
23037 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
23038 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
23039 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
23040 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
23041 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
23042 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
23043 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
23046 /* Similarly for group relocations. */
23047 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23048 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23049 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
23052 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
23053 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
23054 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23055 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
23056 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
23057 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23058 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
23059 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
23060 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
23065 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
23070 elf32_arm_target_format (void)
23073 return (target_big_endian
23074 ? "elf32-bigarm-symbian"
23075 : "elf32-littlearm-symbian");
23076 #elif defined (TE_VXWORKS)
23077 return (target_big_endian
23078 ? "elf32-bigarm-vxworks"
23079 : "elf32-littlearm-vxworks");
23080 #elif defined (TE_NACL)
23081 return (target_big_endian
23082 ? "elf32-bigarm-nacl"
23083 : "elf32-littlearm-nacl");
23085 if (target_big_endian)
23086 return "elf32-bigarm";
23088 return "elf32-littlearm";
23093 armelf_frob_symbol (symbolS * symp,
23096 elf_frob_symbol (symp, puntp);
23100 /* MD interface: Finalization. */
23105 literal_pool * pool;
23107 /* Ensure that all the IT blocks are properly closed. */
23108 check_it_blocks_finished ();
23110 for (pool = list_of_pools; pool; pool = pool->next)
23112 /* Put it at the end of the relevant section. */
23113 subseg_set (pool->section, pool->sub_section);
23115 arm_elf_change_section ();
23122 /* Remove any excess mapping symbols generated for alignment frags in
23123 SEC. We may have created a mapping symbol before a zero byte
23124 alignment; remove it if there's a mapping symbol after the
23127 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
23128 void *dummy ATTRIBUTE_UNUSED)
23130 segment_info_type *seginfo = seg_info (sec);
23133 if (seginfo == NULL || seginfo->frchainP == NULL)
23136 for (fragp = seginfo->frchainP->frch_root;
23138 fragp = fragp->fr_next)
23140 symbolS *sym = fragp->tc_frag_data.last_map;
23141 fragS *next = fragp->fr_next;
23143 /* Variable-sized frags have been converted to fixed size by
23144 this point. But if this was variable-sized to start with,
23145 there will be a fixed-size frag after it. So don't handle
23147 if (sym == NULL || next == NULL)
23150 if (S_GET_VALUE (sym) < next->fr_address)
23151 /* Not at the end of this frag. */
23153 know (S_GET_VALUE (sym) == next->fr_address);
23157 if (next->tc_frag_data.first_map != NULL)
23159 /* Next frag starts with a mapping symbol. Discard this
23161 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23165 if (next->fr_next == NULL)
23167 /* This mapping symbol is at the end of the section. Discard
23169 know (next->fr_fix == 0 && next->fr_var == 0);
23170 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23174 /* As long as we have empty frags without any mapping symbols,
23176 /* If the next frag is non-empty and does not start with a
23177 mapping symbol, then this mapping symbol is required. */
23178 if (next->fr_address != next->fr_next->fr_address)
23181 next = next->fr_next;
23183 while (next != NULL);
23188 /* Adjust the symbol table. This marks Thumb symbols as distinct from
23192 arm_adjust_symtab (void)
23197 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
23199 if (ARM_IS_THUMB (sym))
23201 if (THUMB_IS_FUNC (sym))
23203 /* Mark the symbol as a Thumb function. */
23204 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
23205 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
23206 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
23208 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
23209 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
23211 as_bad (_("%s: unexpected function type: %d"),
23212 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
23214 else switch (S_GET_STORAGE_CLASS (sym))
23217 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
23220 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
23223 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
23231 if (ARM_IS_INTERWORK (sym))
23232 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
23239 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
23241 if (ARM_IS_THUMB (sym))
23243 elf_symbol_type * elf_sym;
23245 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
23246 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
23248 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
23249 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
23251 /* If it's a .thumb_func, declare it as so,
23252 otherwise tag label as .code 16. */
23253 if (THUMB_IS_FUNC (sym))
23254 elf_sym->internal_elf_sym.st_target_internal
23255 = ST_BRANCH_TO_THUMB;
23256 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23257 elf_sym->internal_elf_sym.st_info =
23258 ELF_ST_INFO (bind, STT_ARM_16BIT);
23263 /* Remove any overlapping mapping symbols generated by alignment frags. */
23264 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
23265 /* Now do generic ELF adjustments. */
23266 elf_adjust_symtab ();
23270 /* MD interface: Initialization. */
23273 set_constant_flonums (void)
23277 for (i = 0; i < NUM_FLOAT_VALS; i++)
23278 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
23282 /* Auto-select Thumb mode if it's the only available instruction set for the
23283 given architecture. */
23286 autoselect_thumb_from_cpu_variant (void)
23288 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
23289 opcode_select (16);
23298 if ( (arm_ops_hsh = hash_new ()) == NULL
23299 || (arm_cond_hsh = hash_new ()) == NULL
23300 || (arm_shift_hsh = hash_new ()) == NULL
23301 || (arm_psr_hsh = hash_new ()) == NULL
23302 || (arm_v7m_psr_hsh = hash_new ()) == NULL
23303 || (arm_reg_hsh = hash_new ()) == NULL
23304 || (arm_reloc_hsh = hash_new ()) == NULL
23305 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
23306 as_fatal (_("virtual memory exhausted"));
23308 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
23309 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
23310 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
23311 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
23312 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
23313 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
23314 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
23315 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
23316 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
23317 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
23318 (void *) (v7m_psrs + i));
23319 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
23320 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
23322 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
23324 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
23325 (void *) (barrier_opt_names + i));
23327 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
23329 struct reloc_entry * entry = reloc_names + i;
23331 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
23332 /* This makes encode_branch() use the EABI versions of this relocation. */
23333 entry->reloc = BFD_RELOC_UNUSED;
23335 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
23339 set_constant_flonums ();
23341 /* Set the cpu variant based on the command-line options. We prefer
23342 -mcpu= over -march= if both are set (as for GCC); and we prefer
23343 -mfpu= over any other way of setting the floating point unit.
23344 Use of legacy options with new options are faulted. */
23347 if (mcpu_cpu_opt || march_cpu_opt)
23348 as_bad (_("use of old and new-style options to set CPU type"));
23350 mcpu_cpu_opt = legacy_cpu;
23352 else if (!mcpu_cpu_opt)
23353 mcpu_cpu_opt = march_cpu_opt;
23358 as_bad (_("use of old and new-style options to set FPU type"));
23360 mfpu_opt = legacy_fpu;
23362 else if (!mfpu_opt)
23364 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
23365 || defined (TE_NetBSD) || defined (TE_VXWORKS))
23366 /* Some environments specify a default FPU. If they don't, infer it
23367 from the processor. */
23369 mfpu_opt = mcpu_fpu_opt;
23371 mfpu_opt = march_fpu_opt;
23373 mfpu_opt = &fpu_default;
23379 if (mcpu_cpu_opt != NULL)
23380 mfpu_opt = &fpu_default;
23381 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
23382 mfpu_opt = &fpu_arch_vfp_v2;
23384 mfpu_opt = &fpu_arch_fpa;
23390 mcpu_cpu_opt = &cpu_default;
23391 selected_cpu = cpu_default;
23395 selected_cpu = *mcpu_cpu_opt;
23397 mcpu_cpu_opt = &arm_arch_any;
23400 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23402 autoselect_thumb_from_cpu_variant ();
23404 arm_arch_used = thumb_arch_used = arm_arch_none;
23406 #if defined OBJ_COFF || defined OBJ_ELF
23408 unsigned int flags = 0;
23410 #if defined OBJ_ELF
23411 flags = meabi_flags;
23413 switch (meabi_flags)
23415 case EF_ARM_EABI_UNKNOWN:
23417 /* Set the flags in the private structure. */
23418 if (uses_apcs_26) flags |= F_APCS26;
23419 if (support_interwork) flags |= F_INTERWORK;
23420 if (uses_apcs_float) flags |= F_APCS_FLOAT;
23421 if (pic_code) flags |= F_PIC;
23422 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
23423 flags |= F_SOFT_FLOAT;
23425 switch (mfloat_abi_opt)
23427 case ARM_FLOAT_ABI_SOFT:
23428 case ARM_FLOAT_ABI_SOFTFP:
23429 flags |= F_SOFT_FLOAT;
23432 case ARM_FLOAT_ABI_HARD:
23433 if (flags & F_SOFT_FLOAT)
23434 as_bad (_("hard-float conflicts with specified fpu"));
23438 /* Using pure-endian doubles (even if soft-float). */
23439 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
23440 flags |= F_VFP_FLOAT;
23442 #if defined OBJ_ELF
23443 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
23444 flags |= EF_ARM_MAVERICK_FLOAT;
23447 case EF_ARM_EABI_VER4:
23448 case EF_ARM_EABI_VER5:
23449 /* No additional flags to set. */
23456 bfd_set_private_flags (stdoutput, flags);
23458 /* We have run out flags in the COFF header to encode the
23459 status of ATPCS support, so instead we create a dummy,
23460 empty, debug section called .arm.atpcs. */
23465 sec = bfd_make_section (stdoutput, ".arm.atpcs");
23469 bfd_set_section_flags
23470 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
23471 bfd_set_section_size (stdoutput, sec, 0);
23472 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
23478 /* Record the CPU type as well. */
23479 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
23480 mach = bfd_mach_arm_iWMMXt2;
23481 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
23482 mach = bfd_mach_arm_iWMMXt;
23483 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
23484 mach = bfd_mach_arm_XScale;
23485 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
23486 mach = bfd_mach_arm_ep9312;
23487 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
23488 mach = bfd_mach_arm_5TE;
23489 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
23491 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
23492 mach = bfd_mach_arm_5T;
23494 mach = bfd_mach_arm_5;
23496 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
23498 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
23499 mach = bfd_mach_arm_4T;
23501 mach = bfd_mach_arm_4;
23503 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
23504 mach = bfd_mach_arm_3M;
23505 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
23506 mach = bfd_mach_arm_3;
23507 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
23508 mach = bfd_mach_arm_2a;
23509 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
23510 mach = bfd_mach_arm_2;
23512 mach = bfd_mach_arm_unknown;
23514 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
23517 /* Command line processing. */
23520 Invocation line includes a switch not recognized by the base assembler.
23521 See if it's a processor-specific option.
23523 This routine is somewhat complicated by the need for backwards
23524 compatibility (since older releases of gcc can't be changed).
23525 The new options try to make the interface as compatible as
23528 New options (supported) are:
23530 -mcpu=<cpu name> Assemble for selected processor
23531 -march=<architecture name> Assemble for selected architecture
23532 -mfpu=<fpu architecture> Assemble for selected FPU.
23533 -EB/-mbig-endian Big-endian
23534 -EL/-mlittle-endian Little-endian
23535 -k Generate PIC code
23536 -mthumb Start in Thumb mode
23537 -mthumb-interwork Code supports ARM/Thumb interworking
23539 -m[no-]warn-deprecated Warn about deprecated features
23541 For now we will also provide support for:
23543 -mapcs-32 32-bit Program counter
23544 -mapcs-26 26-bit Program counter
23545 -macps-float Floats passed in FP registers
23546 -mapcs-reentrant Reentrant code
23548 (sometime these will probably be replaced with -mapcs=<list of options>
23549 and -matpcs=<list of options>)
23551 The remaining options are only supported for back-wards compatibility.
23552 Cpu variants, the arm part is optional:
23553 -m[arm]1 Currently not supported.
23554 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
23555 -m[arm]3 Arm 3 processor
23556 -m[arm]6[xx], Arm 6 processors
23557 -m[arm]7[xx][t][[d]m] Arm 7 processors
23558 -m[arm]8[10] Arm 8 processors
23559 -m[arm]9[20][tdmi] Arm 9 processors
23560 -mstrongarm[110[0]] StrongARM processors
23561 -mxscale XScale processors
23562 -m[arm]v[2345[t[e]]] Arm architectures
23563 -mall All (except the ARM1)
23565 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
23566 -mfpe-old (No float load/store multiples)
23567 -mvfpxd VFP Single precision
23569 -mno-fpu Disable all floating point instructions
23571 The following CPU names are recognized:
23572 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
23573 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
23574 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
23575 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
23576 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
23577 arm10t arm10e, arm1020t, arm1020e, arm10200e,
23578 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
23582 const char * md_shortopts = "m:k";
23584 #ifdef ARM_BI_ENDIAN
23585 #define OPTION_EB (OPTION_MD_BASE + 0)
23586 #define OPTION_EL (OPTION_MD_BASE + 1)
23588 #if TARGET_BYTES_BIG_ENDIAN
23589 #define OPTION_EB (OPTION_MD_BASE + 0)
23591 #define OPTION_EL (OPTION_MD_BASE + 1)
23594 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
23596 struct option md_longopts[] =
23599 {"EB", no_argument, NULL, OPTION_EB},
23602 {"EL", no_argument, NULL, OPTION_EL},
23604 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
23605 {NULL, no_argument, NULL, 0}
23608 size_t md_longopts_size = sizeof (md_longopts);
23610 struct arm_option_table
23612 char *option; /* Option name to match. */
23613 char *help; /* Help information. */
23614 int *var; /* Variable to change. */
23615 int value; /* What to change it to. */
23616 char *deprecated; /* If non-null, print this message. */
23619 struct arm_option_table arm_opts[] =
23621 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
23622 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
23623 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
23624 &support_interwork, 1, NULL},
23625 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
23626 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
23627 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
23629 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
23630 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
23631 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
23632 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
23635 /* These are recognized by the assembler, but have no affect on code. */
23636 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
23637 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
23639 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
23640 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
23641 &warn_on_deprecated, 0, NULL},
23642 {NULL, NULL, NULL, 0, NULL}
23645 struct arm_legacy_option_table
23647 char *option; /* Option name to match. */
23648 const arm_feature_set **var; /* Variable to change. */
23649 const arm_feature_set value; /* What to change it to. */
23650 char *deprecated; /* If non-null, print this message. */
23653 const struct arm_legacy_option_table arm_legacy_opts[] =
23655 /* DON'T add any new processors to this list -- we want the whole list
23656 to go away... Add them to the processors table instead. */
23657 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
23658 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
23659 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
23660 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
23661 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
23662 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
23663 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
23664 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
23665 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
23666 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
23667 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
23668 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
23669 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
23670 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
23671 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
23672 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
23673 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
23674 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
23675 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
23676 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
23677 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
23678 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
23679 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
23680 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
23681 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
23682 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
23683 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
23684 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
23685 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
23686 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
23687 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
23688 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
23689 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
23690 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
23691 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
23692 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
23693 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
23694 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
23695 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
23696 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
23697 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
23698 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
23699 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
23700 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
23701 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
23702 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
23703 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23704 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23705 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23706 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23707 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
23708 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
23709 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
23710 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
23711 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
23712 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
23713 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
23714 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
23715 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
23716 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
23717 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
23718 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
23719 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
23720 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
23721 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
23722 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
23723 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
23724 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
23725 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
23726 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
23727 N_("use -mcpu=strongarm110")},
23728 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
23729 N_("use -mcpu=strongarm1100")},
23730 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
23731 N_("use -mcpu=strongarm1110")},
23732 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
23733 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
23734 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
23736 /* Architecture variants -- don't add any more to this list either. */
23737 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
23738 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
23739 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
23740 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
23741 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
23742 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
23743 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
23744 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
23745 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
23746 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
23747 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
23748 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
23749 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
23750 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
23751 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
23752 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
23753 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
23754 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
23756 /* Floating point variants -- don't add any more to this list either. */
23757 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
23758 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
23759 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
23760 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
23761 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
23763 {NULL, NULL, ARM_ARCH_NONE, NULL}
23766 struct arm_cpu_option_table
23770 const arm_feature_set value;
23771 /* For some CPUs we assume an FPU unless the user explicitly sets
23773 const arm_feature_set default_fpu;
23774 /* The canonical name of the CPU, or NULL to use NAME converted to upper
23776 const char *canonical_name;
23779 /* This list should, at a minimum, contain all the cpu names
23780 recognized by GCC. */
23781 #define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
23782 static const struct arm_cpu_option_table arm_cpus[] =
23784 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
23785 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
23786 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
23787 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23788 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23789 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23790 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23791 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23792 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23793 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23794 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23795 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23796 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23797 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23798 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23799 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23800 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23801 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23802 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23803 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23804 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23805 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23806 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23807 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23808 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23809 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23810 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23811 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23812 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23813 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23814 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23815 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23816 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23817 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23818 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23819 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23820 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23821 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23822 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23823 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
23824 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23825 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23826 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23827 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23828 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23829 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23830 /* For V5 or later processors we default to using VFP; but the user
23831 should really set the FPU type explicitly. */
23832 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23833 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23834 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23835 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23836 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23837 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23838 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
23839 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23840 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23841 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
23842 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23843 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23844 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23845 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23846 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23847 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
23848 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23849 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23850 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23851 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
23853 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23854 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23855 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23856 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23857 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23858 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23859 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
23860 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
23861 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
23863 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
23864 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
23865 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
23866 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
23867 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
23868 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL),
23869 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL),
23870 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
23871 FPU_NONE, "Cortex-A5"),
23872 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23873 FPU_ARCH_NEON_VFP_V4,
23875 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
23876 ARM_FEATURE (0, FPU_VFP_V3
23877 | FPU_NEON_EXT_V1),
23879 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
23880 ARM_FEATURE (0, FPU_VFP_V3
23881 | FPU_NEON_EXT_V1),
23883 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23884 FPU_ARCH_NEON_VFP_V4,
23886 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
23887 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
23889 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
23890 FPU_NONE, "Cortex-R5"),
23891 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
23892 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
23893 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
23894 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
23895 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
23896 /* ??? XSCALE is really an architecture. */
23897 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
23898 /* ??? iwmmxt is not a processor. */
23899 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
23900 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
23901 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
23903 ARM_CPU_OPT ("ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
23904 FPU_ARCH_MAVERICK, "ARM920T"),
23905 /* Marvell processors. */
23906 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE (ARM_AEXT_V7A|ARM_EXT_MP|ARM_EXT_SEC),
23907 FPU_ARCH_VFP_V3D16, NULL),
23909 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
23913 struct arm_arch_option_table
23917 const arm_feature_set value;
23918 const arm_feature_set default_fpu;
23921 /* This list should, at a minimum, contain all the architecture names
23922 recognized by GCC. */
23923 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
23924 static const struct arm_arch_option_table arm_archs[] =
23926 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
23927 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
23928 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
23929 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
23930 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
23931 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
23932 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
23933 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
23934 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
23935 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
23936 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
23937 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
23938 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
23939 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
23940 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
23941 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
23942 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
23943 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
23944 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
23945 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
23946 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
23947 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP),
23948 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
23949 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
23950 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
23951 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP),
23952 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
23953 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
23954 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
23955 /* The official spelling of the ARMv7 profile variants is the dashed form.
23956 Accept the non-dashed form for compatibility with old toolchains. */
23957 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23958 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23959 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23960 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23961 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23962 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23963 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
23964 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
23965 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
23966 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
23967 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
23968 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
23970 #undef ARM_ARCH_OPT
23972 /* ISA extensions in the co-processor and main instruction set space. */
23973 struct arm_option_extension_value_table
23977 const arm_feature_set value;
23978 const arm_feature_set allowed_archs;
23981 /* The following table must be in alphabetical order with a NULL last entry.
23983 #define ARM_EXT_OPT(N, V, AA) { N, sizeof (N) - 1, V, AA }
23984 static const struct arm_option_extension_value_table arm_extensions[] =
23986 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
23987 ARM_FEATURE (ARM_EXT_V8, 0)),
23988 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8,
23989 ARM_FEATURE (ARM_EXT_V8, 0)),
23990 ARM_EXT_OPT ("idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
23991 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23992 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY),
23993 ARM_EXT_OPT ("iwmmxt2",
23994 ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY),
23995 ARM_EXT_OPT ("maverick",
23996 ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY),
23997 ARM_EXT_OPT ("mp", ARM_FEATURE (ARM_EXT_MP, 0),
23998 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23999 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
24000 ARM_FEATURE (ARM_EXT_V8, 0)),
24001 ARM_EXT_OPT ("os", ARM_FEATURE (ARM_EXT_OS, 0),
24002 ARM_FEATURE (ARM_EXT_V6M, 0)),
24003 ARM_EXT_OPT ("sec", ARM_FEATURE (ARM_EXT_SEC, 0),
24004 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)),
24005 ARM_EXT_OPT ("virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV
24007 ARM_FEATURE (ARM_EXT_V7A, 0)),
24008 ARM_EXT_OPT ("xscale",ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY),
24009 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
24013 /* ISA floating-point and Advanced SIMD extensions. */
24014 struct arm_option_fpu_value_table
24017 const arm_feature_set value;
24020 /* This list should, at a minimum, contain all the fpu names
24021 recognized by GCC. */
24022 static const struct arm_option_fpu_value_table arm_fpus[] =
24024 {"softfpa", FPU_NONE},
24025 {"fpe", FPU_ARCH_FPE},
24026 {"fpe2", FPU_ARCH_FPE},
24027 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
24028 {"fpa", FPU_ARCH_FPA},
24029 {"fpa10", FPU_ARCH_FPA},
24030 {"fpa11", FPU_ARCH_FPA},
24031 {"arm7500fe", FPU_ARCH_FPA},
24032 {"softvfp", FPU_ARCH_VFP},
24033 {"softvfp+vfp", FPU_ARCH_VFP_V2},
24034 {"vfp", FPU_ARCH_VFP_V2},
24035 {"vfp9", FPU_ARCH_VFP_V2},
24036 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
24037 {"vfp10", FPU_ARCH_VFP_V2},
24038 {"vfp10-r0", FPU_ARCH_VFP_V1},
24039 {"vfpxd", FPU_ARCH_VFP_V1xD},
24040 {"vfpv2", FPU_ARCH_VFP_V2},
24041 {"vfpv3", FPU_ARCH_VFP_V3},
24042 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
24043 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
24044 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
24045 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
24046 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
24047 {"arm1020t", FPU_ARCH_VFP_V1},
24048 {"arm1020e", FPU_ARCH_VFP_V2},
24049 {"arm1136jfs", FPU_ARCH_VFP_V2},
24050 {"arm1136jf-s", FPU_ARCH_VFP_V2},
24051 {"maverick", FPU_ARCH_MAVERICK},
24052 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
24053 {"neon-fp16", FPU_ARCH_NEON_FP16},
24054 {"vfpv4", FPU_ARCH_VFP_V4},
24055 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
24056 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
24057 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
24058 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
24059 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
24060 {"crypto-neon-fp-armv8",
24061 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
24062 {NULL, ARM_ARCH_NONE}
24065 struct arm_option_value_table
24071 static const struct arm_option_value_table arm_float_abis[] =
24073 {"hard", ARM_FLOAT_ABI_HARD},
24074 {"softfp", ARM_FLOAT_ABI_SOFTFP},
24075 {"soft", ARM_FLOAT_ABI_SOFT},
24080 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
24081 static const struct arm_option_value_table arm_eabis[] =
24083 {"gnu", EF_ARM_EABI_UNKNOWN},
24084 {"4", EF_ARM_EABI_VER4},
24085 {"5", EF_ARM_EABI_VER5},
24090 struct arm_long_option_table
24092 char * option; /* Substring to match. */
24093 char * help; /* Help information. */
24094 int (* func) (char * subopt); /* Function to decode sub-option. */
24095 char * deprecated; /* If non-null, print this message. */
24099 arm_parse_extension (char *str, const arm_feature_set **opt_p)
24101 arm_feature_set *ext_set = (arm_feature_set *)
24102 xmalloc (sizeof (arm_feature_set));
24104 /* We insist on extensions being specified in alphabetical order, and with
24105 extensions being added before being removed. We achieve this by having
24106 the global ARM_EXTENSIONS table in alphabetical order, and using the
24107 ADDING_VALUE variable to indicate whether we are adding an extension (1)
24108 or removing it (0) and only allowing it to change in the order
24110 const struct arm_option_extension_value_table * opt = NULL;
24111 int adding_value = -1;
24113 /* Copy the feature set, so that we can modify it. */
24114 *ext_set = **opt_p;
24117 while (str != NULL && *str != 0)
24124 as_bad (_("invalid architectural extension"));
24129 ext = strchr (str, '+');
24134 len = strlen (str);
24136 if (len >= 2 && strncmp (str, "no", 2) == 0)
24138 if (adding_value != 0)
24141 opt = arm_extensions;
24149 if (adding_value == -1)
24152 opt = arm_extensions;
24154 else if (adding_value != 1)
24156 as_bad (_("must specify extensions to add before specifying "
24157 "those to remove"));
24164 as_bad (_("missing architectural extension"));
24168 gas_assert (adding_value != -1);
24169 gas_assert (opt != NULL);
24171 /* Scan over the options table trying to find an exact match. */
24172 for (; opt->name != NULL; opt++)
24173 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
24175 /* Check we can apply the extension to this architecture. */
24176 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
24178 as_bad (_("extension does not apply to the base architecture"));
24182 /* Add or remove the extension. */
24184 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
24186 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
24191 if (opt->name == NULL)
24193 /* Did we fail to find an extension because it wasn't specified in
24194 alphabetical order, or because it does not exist? */
24196 for (opt = arm_extensions; opt->name != NULL; opt++)
24197 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
24200 if (opt->name == NULL)
24201 as_bad (_("unknown architectural extension `%s'"), str);
24203 as_bad (_("architectural extensions must be specified in "
24204 "alphabetical order"));
24210 /* We should skip the extension we've just matched the next time
24222 arm_parse_cpu (char *str)
24224 const struct arm_cpu_option_table *opt;
24225 char *ext = strchr (str, '+');
24231 len = strlen (str);
24235 as_bad (_("missing cpu name `%s'"), str);
24239 for (opt = arm_cpus; opt->name != NULL; opt++)
24240 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
24242 mcpu_cpu_opt = &opt->value;
24243 mcpu_fpu_opt = &opt->default_fpu;
24244 if (opt->canonical_name)
24245 strcpy (selected_cpu_name, opt->canonical_name);
24250 for (i = 0; i < len; i++)
24251 selected_cpu_name[i] = TOUPPER (opt->name[i]);
24252 selected_cpu_name[i] = 0;
24256 return arm_parse_extension (ext, &mcpu_cpu_opt);
24261 as_bad (_("unknown cpu `%s'"), str);
24266 arm_parse_arch (char *str)
24268 const struct arm_arch_option_table *opt;
24269 char *ext = strchr (str, '+');
24275 len = strlen (str);
24279 as_bad (_("missing architecture name `%s'"), str);
24283 for (opt = arm_archs; opt->name != NULL; opt++)
24284 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
24286 march_cpu_opt = &opt->value;
24287 march_fpu_opt = &opt->default_fpu;
24288 strcpy (selected_cpu_name, opt->name);
24291 return arm_parse_extension (ext, &march_cpu_opt);
24296 as_bad (_("unknown architecture `%s'\n"), str);
24301 arm_parse_fpu (char * str)
24303 const struct arm_option_fpu_value_table * opt;
24305 for (opt = arm_fpus; opt->name != NULL; opt++)
24306 if (streq (opt->name, str))
24308 mfpu_opt = &opt->value;
24312 as_bad (_("unknown floating point format `%s'\n"), str);
24317 arm_parse_float_abi (char * str)
24319 const struct arm_option_value_table * opt;
24321 for (opt = arm_float_abis; opt->name != NULL; opt++)
24322 if (streq (opt->name, str))
24324 mfloat_abi_opt = opt->value;
24328 as_bad (_("unknown floating point abi `%s'\n"), str);
24334 arm_parse_eabi (char * str)
24336 const struct arm_option_value_table *opt;
24338 for (opt = arm_eabis; opt->name != NULL; opt++)
24339 if (streq (opt->name, str))
24341 meabi_flags = opt->value;
24344 as_bad (_("unknown EABI `%s'\n"), str);
24350 arm_parse_it_mode (char * str)
24352 bfd_boolean ret = TRUE;
24354 if (streq ("arm", str))
24355 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
24356 else if (streq ("thumb", str))
24357 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
24358 else if (streq ("always", str))
24359 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
24360 else if (streq ("never", str))
24361 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
24364 as_bad (_("unknown implicit IT mode `%s', should be "\
24365 "arm, thumb, always, or never."), str);
24372 struct arm_long_option_table arm_long_opts[] =
24374 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
24375 arm_parse_cpu, NULL},
24376 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
24377 arm_parse_arch, NULL},
24378 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
24379 arm_parse_fpu, NULL},
24380 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
24381 arm_parse_float_abi, NULL},
24383 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
24384 arm_parse_eabi, NULL},
24386 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
24387 arm_parse_it_mode, NULL},
24388 {NULL, NULL, 0, NULL}
24392 md_parse_option (int c, char * arg)
24394 struct arm_option_table *opt;
24395 const struct arm_legacy_option_table *fopt;
24396 struct arm_long_option_table *lopt;
24402 target_big_endian = 1;
24408 target_big_endian = 0;
24412 case OPTION_FIX_V4BX:
24417 /* Listing option. Just ignore these, we don't support additional
24422 for (opt = arm_opts; opt->option != NULL; opt++)
24424 if (c == opt->option[0]
24425 && ((arg == NULL && opt->option[1] == 0)
24426 || streq (arg, opt->option + 1)))
24428 /* If the option is deprecated, tell the user. */
24429 if (warn_on_deprecated && opt->deprecated != NULL)
24430 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
24431 arg ? arg : "", _(opt->deprecated));
24433 if (opt->var != NULL)
24434 *opt->var = opt->value;
24440 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
24442 if (c == fopt->option[0]
24443 && ((arg == NULL && fopt->option[1] == 0)
24444 || streq (arg, fopt->option + 1)))
24446 /* If the option is deprecated, tell the user. */
24447 if (warn_on_deprecated && fopt->deprecated != NULL)
24448 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
24449 arg ? arg : "", _(fopt->deprecated));
24451 if (fopt->var != NULL)
24452 *fopt->var = &fopt->value;
24458 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
24460 /* These options are expected to have an argument. */
24461 if (c == lopt->option[0]
24463 && strncmp (arg, lopt->option + 1,
24464 strlen (lopt->option + 1)) == 0)
24466 /* If the option is deprecated, tell the user. */
24467 if (warn_on_deprecated && lopt->deprecated != NULL)
24468 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
24469 _(lopt->deprecated));
24471 /* Call the sup-option parser. */
24472 return lopt->func (arg + strlen (lopt->option) - 1);
24483 md_show_usage (FILE * fp)
24485 struct arm_option_table *opt;
24486 struct arm_long_option_table *lopt;
24488 fprintf (fp, _(" ARM-specific assembler options:\n"));
24490 for (opt = arm_opts; opt->option != NULL; opt++)
24491 if (opt->help != NULL)
24492 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
24494 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
24495 if (lopt->help != NULL)
24496 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
24500 -EB assemble code for a big-endian cpu\n"));
24505 -EL assemble code for a little-endian cpu\n"));
24509 --fix-v4bx Allow BX in ARMv4 code\n"));
24517 arm_feature_set flags;
24518 } cpu_arch_ver_table;
24520 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
24521 least features first. */
24522 static const cpu_arch_ver_table cpu_arch_ver[] =
24528 {4, ARM_ARCH_V5TE},
24529 {5, ARM_ARCH_V5TEJ},
24533 {11, ARM_ARCH_V6M},
24534 {12, ARM_ARCH_V6SM},
24535 {8, ARM_ARCH_V6T2},
24536 {10, ARM_ARCH_V7A_IDIV_MP_SEC_VIRT},
24537 {10, ARM_ARCH_V7R},
24538 {10, ARM_ARCH_V7M},
24539 {14, ARM_ARCH_V8A},
24543 /* Set an attribute if it has not already been set by the user. */
24545 aeabi_set_attribute_int (int tag, int value)
24548 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
24549 || !attributes_set_explicitly[tag])
24550 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
24554 aeabi_set_attribute_string (int tag, const char *value)
24557 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
24558 || !attributes_set_explicitly[tag])
24559 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
24562 /* Set the public EABI object attributes. */
24564 aeabi_set_public_attributes (void)
24569 int fp16_optional = 0;
24570 arm_feature_set flags;
24571 arm_feature_set tmp;
24572 const cpu_arch_ver_table *p;
24574 /* Choose the architecture based on the capabilities of the requested cpu
24575 (if any) and/or the instructions actually used. */
24576 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
24577 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
24578 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
24580 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
24581 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
24583 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
24584 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
24586 /* Allow the user to override the reported architecture. */
24589 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
24590 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
24593 /* We need to make sure that the attributes do not identify us as v6S-M
24594 when the only v6S-M feature in use is the Operating System Extensions. */
24595 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
24596 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
24597 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
24601 for (p = cpu_arch_ver; p->val; p++)
24603 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
24606 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
24610 /* The table lookup above finds the last architecture to contribute
24611 a new feature. Unfortunately, Tag13 is a subset of the union of
24612 v6T2 and v7-M, so it is never seen as contributing a new feature.
24613 We can not search for the last entry which is entirely used,
24614 because if no CPU is specified we build up only those flags
24615 actually used. Perhaps we should separate out the specified
24616 and implicit cases. Avoid taking this path for -march=all by
24617 checking for contradictory v7-A / v7-M features. */
24619 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
24620 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
24621 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
24624 /* Tag_CPU_name. */
24625 if (selected_cpu_name[0])
24629 q = selected_cpu_name;
24630 if (strncmp (q, "armv", 4) == 0)
24635 for (i = 0; q[i]; i++)
24636 q[i] = TOUPPER (q[i]);
24638 aeabi_set_attribute_string (Tag_CPU_name, q);
24641 /* Tag_CPU_arch. */
24642 aeabi_set_attribute_int (Tag_CPU_arch, arch);
24644 /* Tag_CPU_arch_profile. */
24645 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
24647 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
24649 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
24654 if (profile != '\0')
24655 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
24657 /* Tag_ARM_ISA_use. */
24658 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
24660 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
24662 /* Tag_THUMB_ISA_use. */
24663 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
24665 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
24666 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
24668 /* Tag_VFP_arch. */
24669 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8))
24670 aeabi_set_attribute_int (Tag_VFP_arch, 7);
24671 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
24672 aeabi_set_attribute_int (Tag_VFP_arch,
24673 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
24675 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
24678 aeabi_set_attribute_int (Tag_VFP_arch, 3);
24680 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
24682 aeabi_set_attribute_int (Tag_VFP_arch, 4);
24685 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
24686 aeabi_set_attribute_int (Tag_VFP_arch, 2);
24687 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
24688 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
24689 aeabi_set_attribute_int (Tag_VFP_arch, 1);
24691 /* Tag_ABI_HardFP_use. */
24692 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
24693 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
24694 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
24696 /* Tag_WMMX_arch. */
24697 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
24698 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
24699 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
24700 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
24702 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
24703 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
24704 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
24705 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
24707 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
24709 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
24713 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
24718 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
24719 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
24720 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
24724 We set Tag_DIV_use to two when integer divide instructions have been used
24725 in ARM state, or when Thumb integer divide instructions have been used,
24726 but we have no architecture profile set, nor have we any ARM instructions.
24728 For ARMv8 we set the tag to 0 as integer divide is implied by the base
24731 For new architectures we will have to check these tests. */
24732 gas_assert (arch <= TAG_CPU_ARCH_V8);
24733 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8))
24734 aeabi_set_attribute_int (Tag_DIV_use, 0);
24735 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
24736 || (profile == '\0'
24737 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
24738 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
24739 aeabi_set_attribute_int (Tag_DIV_use, 2);
24741 /* Tag_MP_extension_use. */
24742 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
24743 aeabi_set_attribute_int (Tag_MPextension_use, 1);
24745 /* Tag Virtualization_use. */
24746 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
24748 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
24751 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
24754 /* Add the default contents for the .ARM.attributes section. */
24758 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
24761 aeabi_set_public_attributes ();
24763 #endif /* OBJ_ELF */
24766 /* Parse a .cpu directive. */
24769 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
24771 const struct arm_cpu_option_table *opt;
24775 name = input_line_pointer;
24776 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24777 input_line_pointer++;
24778 saved_char = *input_line_pointer;
24779 *input_line_pointer = 0;
24781 /* Skip the first "all" entry. */
24782 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
24783 if (streq (opt->name, name))
24785 mcpu_cpu_opt = &opt->value;
24786 selected_cpu = opt->value;
24787 if (opt->canonical_name)
24788 strcpy (selected_cpu_name, opt->canonical_name);
24792 for (i = 0; opt->name[i]; i++)
24793 selected_cpu_name[i] = TOUPPER (opt->name[i]);
24795 selected_cpu_name[i] = 0;
24797 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24798 *input_line_pointer = saved_char;
24799 demand_empty_rest_of_line ();
24802 as_bad (_("unknown cpu `%s'"), name);
24803 *input_line_pointer = saved_char;
24804 ignore_rest_of_line ();
24808 /* Parse a .arch directive. */
24811 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
24813 const struct arm_arch_option_table *opt;
24817 name = input_line_pointer;
24818 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24819 input_line_pointer++;
24820 saved_char = *input_line_pointer;
24821 *input_line_pointer = 0;
24823 /* Skip the first "all" entry. */
24824 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24825 if (streq (opt->name, name))
24827 mcpu_cpu_opt = &opt->value;
24828 selected_cpu = opt->value;
24829 strcpy (selected_cpu_name, opt->name);
24830 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24831 *input_line_pointer = saved_char;
24832 demand_empty_rest_of_line ();
24836 as_bad (_("unknown architecture `%s'\n"), name);
24837 *input_line_pointer = saved_char;
24838 ignore_rest_of_line ();
24842 /* Parse a .object_arch directive. */
24845 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
24847 const struct arm_arch_option_table *opt;
24851 name = input_line_pointer;
24852 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24853 input_line_pointer++;
24854 saved_char = *input_line_pointer;
24855 *input_line_pointer = 0;
24857 /* Skip the first "all" entry. */
24858 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24859 if (streq (opt->name, name))
24861 object_arch = &opt->value;
24862 *input_line_pointer = saved_char;
24863 demand_empty_rest_of_line ();
24867 as_bad (_("unknown architecture `%s'\n"), name);
24868 *input_line_pointer = saved_char;
24869 ignore_rest_of_line ();
24872 /* Parse a .arch_extension directive. */
24875 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
24877 const struct arm_option_extension_value_table *opt;
24880 int adding_value = 1;
24882 name = input_line_pointer;
24883 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24884 input_line_pointer++;
24885 saved_char = *input_line_pointer;
24886 *input_line_pointer = 0;
24888 if (strlen (name) >= 2
24889 && strncmp (name, "no", 2) == 0)
24895 for (opt = arm_extensions; opt->name != NULL; opt++)
24896 if (streq (opt->name, name))
24898 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
24900 as_bad (_("architectural extension `%s' is not allowed for the "
24901 "current base architecture"), name);
24906 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
24908 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
24910 mcpu_cpu_opt = &selected_cpu;
24911 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24912 *input_line_pointer = saved_char;
24913 demand_empty_rest_of_line ();
24917 if (opt->name == NULL)
24918 as_bad (_("unknown architecture `%s'\n"), name);
24920 *input_line_pointer = saved_char;
24921 ignore_rest_of_line ();
24924 /* Parse a .fpu directive. */
24927 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
24929 const struct arm_option_fpu_value_table *opt;
24933 name = input_line_pointer;
24934 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24935 input_line_pointer++;
24936 saved_char = *input_line_pointer;
24937 *input_line_pointer = 0;
24939 for (opt = arm_fpus; opt->name != NULL; opt++)
24940 if (streq (opt->name, name))
24942 mfpu_opt = &opt->value;
24943 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24944 *input_line_pointer = saved_char;
24945 demand_empty_rest_of_line ();
24949 as_bad (_("unknown floating point format `%s'\n"), name);
24950 *input_line_pointer = saved_char;
24951 ignore_rest_of_line ();
24954 /* Copy symbol information. */
24957 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
24959 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
24963 /* Given a symbolic attribute NAME, return the proper integer value.
24964 Returns -1 if the attribute is not known. */
24967 arm_convert_symbolic_attribute (const char *name)
24969 static const struct
24974 attribute_table[] =
24976 /* When you modify this table you should
24977 also modify the list in doc/c-arm.texi. */
24978 #define T(tag) {#tag, tag}
24979 T (Tag_CPU_raw_name),
24982 T (Tag_CPU_arch_profile),
24983 T (Tag_ARM_ISA_use),
24984 T (Tag_THUMB_ISA_use),
24988 T (Tag_Advanced_SIMD_arch),
24989 T (Tag_PCS_config),
24990 T (Tag_ABI_PCS_R9_use),
24991 T (Tag_ABI_PCS_RW_data),
24992 T (Tag_ABI_PCS_RO_data),
24993 T (Tag_ABI_PCS_GOT_use),
24994 T (Tag_ABI_PCS_wchar_t),
24995 T (Tag_ABI_FP_rounding),
24996 T (Tag_ABI_FP_denormal),
24997 T (Tag_ABI_FP_exceptions),
24998 T (Tag_ABI_FP_user_exceptions),
24999 T (Tag_ABI_FP_number_model),
25000 T (Tag_ABI_align_needed),
25001 T (Tag_ABI_align8_needed),
25002 T (Tag_ABI_align_preserved),
25003 T (Tag_ABI_align8_preserved),
25004 T (Tag_ABI_enum_size),
25005 T (Tag_ABI_HardFP_use),
25006 T (Tag_ABI_VFP_args),
25007 T (Tag_ABI_WMMX_args),
25008 T (Tag_ABI_optimization_goals),
25009 T (Tag_ABI_FP_optimization_goals),
25010 T (Tag_compatibility),
25011 T (Tag_CPU_unaligned_access),
25012 T (Tag_FP_HP_extension),
25013 T (Tag_VFP_HP_extension),
25014 T (Tag_ABI_FP_16bit_format),
25015 T (Tag_MPextension_use),
25017 T (Tag_nodefaults),
25018 T (Tag_also_compatible_with),
25019 T (Tag_conformance),
25021 T (Tag_Virtualization_use),
25022 /* We deliberately do not include Tag_MPextension_use_legacy. */
25030 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
25031 if (streq (name, attribute_table[i].name))
25032 return attribute_table[i].tag;
25038 /* Apply sym value for relocations only in the case that
25039 they are for local symbols and you have the respective
25040 architectural feature for blx and simple switches. */
25042 arm_apply_sym_value (struct fix * fixP)
25045 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
25046 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
25048 switch (fixP->fx_r_type)
25050 case BFD_RELOC_ARM_PCREL_BLX:
25051 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25052 if (ARM_IS_FUNC (fixP->fx_addsy))
25056 case BFD_RELOC_ARM_PCREL_CALL:
25057 case BFD_RELOC_THUMB_PCREL_BLX:
25058 if (THUMB_IS_FUNC (fixP->fx_addsy))
25069 #endif /* OBJ_ELF */