1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
11 This file is part of GAS, the GNU Assembler.
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
32 #include "safe-ctype.h"
35 #include "libiberty.h"
36 #include "opcode/arm.h"
40 #include "dw2gencfi.h"
43 #include "dwarf2dbg.h"
46 /* Must be at least the size of the largest unwind opcode (currently two). */
47 #define ARM_OPCODE_CHUNK_SIZE 8
49 /* This structure holds the unwinding state. */
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
57 /* The segment containing the function. */
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
64 /* The number of bytes pushed to the stack. */
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
69 offsetT pending_offset;
70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
71 hold the reg+offset to use when restoring sp from a frame pointer. */
74 /* Nonzero if an unwind_setfp directive has been seen. */
76 /* Nonzero if the last opcode restores sp from fp_reg. */
77 unsigned sp_restored:1;
82 /* Results from operand parsing worker functions. */
86 PARSE_OPERAND_SUCCESS,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89 } parse_operand_result;
98 /* Types of processor to assemble for. */
100 /* The code that was here used to select a default CPU depending on compiler
101 pre-defines which were only present when doing native builds, thus
102 changing gas' default behaviour depending upon the build host.
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
110 # define FPU_DEFAULT FPU_ARCH_FPA
111 # elif defined (TE_NetBSD)
113 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115 /* Legacy a.out format. */
116 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118 # elif defined (TE_VXWORKS)
119 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
121 /* For backwards compatibility, default to FPA. */
122 # define FPU_DEFAULT FPU_ARCH_FPA
124 #endif /* ifndef FPU_DEFAULT */
126 #define streq(a, b) (strcmp (a, b) == 0)
128 static arm_feature_set cpu_variant;
129 static arm_feature_set arm_arch_used;
130 static arm_feature_set thumb_arch_used;
132 /* Flags stored in private area of BFD structure. */
133 static int uses_apcs_26 = FALSE;
134 static int atpcs = FALSE;
135 static int support_interwork = FALSE;
136 static int uses_apcs_float = FALSE;
137 static int pic_code = FALSE;
138 static int fix_v4bx = FALSE;
139 /* Warn on using deprecated features. */
140 static int warn_on_deprecated = TRUE;
143 /* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
146 static const arm_feature_set *legacy_cpu = NULL;
147 static const arm_feature_set *legacy_fpu = NULL;
149 static const arm_feature_set *mcpu_cpu_opt = NULL;
150 static const arm_feature_set *mcpu_fpu_opt = NULL;
151 static const arm_feature_set *march_cpu_opt = NULL;
152 static const arm_feature_set *march_fpu_opt = NULL;
153 static const arm_feature_set *mfpu_opt = NULL;
154 static const arm_feature_set *object_arch = NULL;
156 /* Constants for known architecture features. */
157 static const arm_feature_set fpu_default = FPU_DEFAULT;
158 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
160 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
162 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
168 static const arm_feature_set cpu_default = CPU_DEFAULT;
171 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179 static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
187 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
188 static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
189 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
190 static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
191 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
193 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
197 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
198 static const arm_feature_set arm_ext_m =
199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
200 static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
201 static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
202 static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
203 static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
204 static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0);
206 static const arm_feature_set arm_arch_any = ARM_ANY;
207 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
208 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
209 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
210 static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
212 static const arm_feature_set arm_cext_iwmmxt2 =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
214 static const arm_feature_set arm_cext_iwmmxt =
215 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
216 static const arm_feature_set arm_cext_xscale =
217 ARM_FEATURE (0, ARM_CEXT_XSCALE);
218 static const arm_feature_set arm_cext_maverick =
219 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
220 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
221 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
222 static const arm_feature_set fpu_vfp_ext_v1xd =
223 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
224 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
225 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
226 static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
227 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
228 static const arm_feature_set fpu_vfp_ext_d32 =
229 ARM_FEATURE (0, FPU_VFP_EXT_D32);
230 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
231 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
232 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
233 static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
234 static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
235 static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
237 static int mfloat_abi_opt = -1;
238 /* Record user cpu selection for object attributes. */
239 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
240 /* Must be long enough to hold any of the names in arm_cpus. */
241 static char selected_cpu_name[16];
243 /* Return if no cpu was selected on command-line. */
245 no_cpu_selected (void)
247 return selected_cpu.core == arm_arch_none.core
248 && selected_cpu.coproc == arm_arch_none.coproc;
253 static int meabi_flags = EABI_DEFAULT;
255 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
258 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
263 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
268 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
269 symbolS * GOT_symbol;
272 /* 0: assemble for ARM,
273 1: assemble for Thumb,
274 2: assemble for Thumb even though target CPU does not support thumb
276 static int thumb_mode = 0;
277 /* A value distinct from the possible values for thumb_mode that we
278 can use to record whether thumb_mode has been copied into the
279 tc_frag_data field of a frag. */
280 #define MODE_RECORDED (1 << 4)
282 /* Specifies the intrinsic IT insn behavior mode. */
283 enum implicit_it_mode
285 IMPLICIT_IT_MODE_NEVER = 0x00,
286 IMPLICIT_IT_MODE_ARM = 0x01,
287 IMPLICIT_IT_MODE_THUMB = 0x02,
288 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
290 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
292 /* If unified_syntax is true, we are processing the new unified
293 ARM/Thumb syntax. Important differences from the old ARM mode:
295 - Immediate operands do not require a # prefix.
296 - Conditional affixes always appear at the end of the
297 instruction. (For backward compatibility, those instructions
298 that formerly had them in the middle, continue to accept them
300 - The IT instruction may appear, and if it does is validated
301 against subsequent conditional affixes. It does not generate
304 Important differences from the old Thumb mode:
306 - Immediate operands do not require a # prefix.
307 - Most of the V6T2 instructions are only available in unified mode.
308 - The .N and .W suffixes are recognized and honored (it is an error
309 if they cannot be honored).
310 - All instructions set the flags if and only if they have an 's' affix.
311 - Conditional affixes may be used. They are validated against
312 preceding IT instructions. Unlike ARM mode, you cannot use a
313 conditional affix except in the scope of an IT instruction. */
315 static bfd_boolean unified_syntax = FALSE;
330 enum neon_el_type type;
334 #define NEON_MAX_TYPE_ELS 4
338 struct neon_type_el el[NEON_MAX_TYPE_ELS];
342 enum it_instruction_type
347 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
348 if inside, should be the last one. */
349 NEUTRAL_IT_INSN, /* This could be either inside or outside,
350 i.e. BKPT and NOP. */
351 IT_INSN /* The IT insn has been parsed. */
354 /* The maximum number of operands we need. */
355 #define ARM_IT_MAX_OPERANDS 6
360 unsigned long instruction;
364 /* "uncond_value" is set to the value in place of the conditional field in
365 unconditional versions of the instruction, or -1 if nothing is
368 struct neon_type vectype;
369 /* This does not indicate an actual NEON instruction, only that
370 the mnemonic accepts neon-style type suffixes. */
372 /* Set to the opcode if the instruction needs relaxation.
373 Zero if the instruction is not relaxed. */
377 bfd_reloc_code_real_type type;
382 enum it_instruction_type it_insn_type;
388 struct neon_type_el vectype;
389 unsigned present : 1; /* Operand present. */
390 unsigned isreg : 1; /* Operand was a register. */
391 unsigned immisreg : 1; /* .imm field is a second register. */
392 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
393 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
394 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
395 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
396 instructions. This allows us to disambiguate ARM <-> vector insns. */
397 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
398 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
399 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
400 unsigned issingle : 1; /* Operand is VFP single-precision register. */
401 unsigned hasreloc : 1; /* Operand has relocation suffix. */
402 unsigned writeback : 1; /* Operand has trailing ! */
403 unsigned preind : 1; /* Preindexed address. */
404 unsigned postind : 1; /* Postindexed address. */
405 unsigned negative : 1; /* Index register was negated. */
406 unsigned shifted : 1; /* Shift applied to operation. */
407 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
408 } operands[ARM_IT_MAX_OPERANDS];
411 static struct arm_it inst;
413 #define NUM_FLOAT_VALS 8
415 const char * fp_const[] =
417 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
420 /* Number of littlenums required to hold an extended precision number. */
421 #define MAX_LITTLENUMS 6
423 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
433 #define CP_T_X 0x00008000
434 #define CP_T_Y 0x00400000
436 #define CONDS_BIT 0x00100000
437 #define LOAD_BIT 0x00100000
439 #define DOUBLE_LOAD_FLAG 0x00000001
443 const char * template_name;
447 #define COND_ALWAYS 0xE
451 const char * template_name;
455 struct asm_barrier_opt
457 const char * template_name;
461 /* The bit that distinguishes CPSR and SPSR. */
462 #define SPSR_BIT (1 << 22)
464 /* The individual PSR flag bits. */
465 #define PSR_c (1 << 16)
466 #define PSR_x (1 << 17)
467 #define PSR_s (1 << 18)
468 #define PSR_f (1 << 19)
473 bfd_reloc_code_real_type reloc;
478 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
479 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
484 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
487 /* Bits for DEFINED field in neon_typed_alias. */
488 #define NTA_HASTYPE 1
489 #define NTA_HASINDEX 2
491 struct neon_typed_alias
493 unsigned char defined;
495 struct neon_type_el eltype;
498 /* ARM register categories. This includes coprocessor numbers and various
499 architecture extensions' registers. */
526 /* Structure for a hash table entry for a register.
527 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
528 information which states whether a vector type or index is specified (for a
529 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
535 unsigned char builtin;
536 struct neon_typed_alias * neon;
539 /* Diagnostics used when we don't get a register of the expected type. */
540 const char * const reg_expected_msgs[] =
542 N_("ARM register expected"),
543 N_("bad or missing co-processor number"),
544 N_("co-processor register expected"),
545 N_("FPA register expected"),
546 N_("VFP single precision register expected"),
547 N_("VFP/Neon double precision register expected"),
548 N_("Neon quad precision register expected"),
549 N_("VFP single or double precision register expected"),
550 N_("Neon double or quad precision register expected"),
551 N_("VFP single, double or Neon quad precision register expected"),
552 N_("VFP system register expected"),
553 N_("Maverick MVF register expected"),
554 N_("Maverick MVD register expected"),
555 N_("Maverick MVFX register expected"),
556 N_("Maverick MVDX register expected"),
557 N_("Maverick MVAX register expected"),
558 N_("Maverick DSPSC register expected"),
559 N_("iWMMXt data register expected"),
560 N_("iWMMXt control register expected"),
561 N_("iWMMXt scalar register expected"),
562 N_("XScale accumulator register expected"),
565 /* Some well known registers that we refer to directly elsewhere. */
571 /* ARM instructions take 4bytes in the object file, Thumb instructions
577 /* Basic string to match. */
578 const char * template_name;
580 /* Parameters to instruction. */
581 unsigned int operands[8];
583 /* Conditional tag - see opcode_lookup. */
584 unsigned int tag : 4;
586 /* Basic instruction code. */
587 unsigned int avalue : 28;
589 /* Thumb-format instruction code. */
592 /* Which architecture variant provides this instruction. */
593 const arm_feature_set * avariant;
594 const arm_feature_set * tvariant;
596 /* Function to call to encode instruction in ARM format. */
597 void (* aencode) (void);
599 /* Function to call to encode instruction in Thumb format. */
600 void (* tencode) (void);
603 /* Defines for various bits that we will want to toggle. */
604 #define INST_IMMEDIATE 0x02000000
605 #define OFFSET_REG 0x02000000
606 #define HWOFFSET_IMM 0x00400000
607 #define SHIFT_BY_REG 0x00000010
608 #define PRE_INDEX 0x01000000
609 #define INDEX_UP 0x00800000
610 #define WRITE_BACK 0x00200000
611 #define LDM_TYPE_2_OR_3 0x00400000
612 #define CPSI_MMOD 0x00020000
614 #define LITERAL_MASK 0xf000f000
615 #define OPCODE_MASK 0xfe1fffff
616 #define V4_STR_BIT 0x00000020
618 #define T2_SUBS_PC_LR 0xf3de8f00
620 #define DATA_OP_SHIFT 21
622 #define T2_OPCODE_MASK 0xfe1fffff
623 #define T2_DATA_OP_SHIFT 21
625 /* Codes to distinguish the arithmetic instructions. */
636 #define OPCODE_CMP 10
637 #define OPCODE_CMN 11
638 #define OPCODE_ORR 12
639 #define OPCODE_MOV 13
640 #define OPCODE_BIC 14
641 #define OPCODE_MVN 15
643 #define T2_OPCODE_AND 0
644 #define T2_OPCODE_BIC 1
645 #define T2_OPCODE_ORR 2
646 #define T2_OPCODE_ORN 3
647 #define T2_OPCODE_EOR 4
648 #define T2_OPCODE_ADD 8
649 #define T2_OPCODE_ADC 10
650 #define T2_OPCODE_SBC 11
651 #define T2_OPCODE_SUB 13
652 #define T2_OPCODE_RSB 14
654 #define T_OPCODE_MUL 0x4340
655 #define T_OPCODE_TST 0x4200
656 #define T_OPCODE_CMN 0x42c0
657 #define T_OPCODE_NEG 0x4240
658 #define T_OPCODE_MVN 0x43c0
660 #define T_OPCODE_ADD_R3 0x1800
661 #define T_OPCODE_SUB_R3 0x1a00
662 #define T_OPCODE_ADD_HI 0x4400
663 #define T_OPCODE_ADD_ST 0xb000
664 #define T_OPCODE_SUB_ST 0xb080
665 #define T_OPCODE_ADD_SP 0xa800
666 #define T_OPCODE_ADD_PC 0xa000
667 #define T_OPCODE_ADD_I8 0x3000
668 #define T_OPCODE_SUB_I8 0x3800
669 #define T_OPCODE_ADD_I3 0x1c00
670 #define T_OPCODE_SUB_I3 0x1e00
672 #define T_OPCODE_ASR_R 0x4100
673 #define T_OPCODE_LSL_R 0x4080
674 #define T_OPCODE_LSR_R 0x40c0
675 #define T_OPCODE_ROR_R 0x41c0
676 #define T_OPCODE_ASR_I 0x1000
677 #define T_OPCODE_LSL_I 0x0000
678 #define T_OPCODE_LSR_I 0x0800
680 #define T_OPCODE_MOV_I8 0x2000
681 #define T_OPCODE_CMP_I8 0x2800
682 #define T_OPCODE_CMP_LR 0x4280
683 #define T_OPCODE_MOV_HR 0x4600
684 #define T_OPCODE_CMP_HR 0x4500
686 #define T_OPCODE_LDR_PC 0x4800
687 #define T_OPCODE_LDR_SP 0x9800
688 #define T_OPCODE_STR_SP 0x9000
689 #define T_OPCODE_LDR_IW 0x6800
690 #define T_OPCODE_STR_IW 0x6000
691 #define T_OPCODE_LDR_IH 0x8800
692 #define T_OPCODE_STR_IH 0x8000
693 #define T_OPCODE_LDR_IB 0x7800
694 #define T_OPCODE_STR_IB 0x7000
695 #define T_OPCODE_LDR_RW 0x5800
696 #define T_OPCODE_STR_RW 0x5000
697 #define T_OPCODE_LDR_RH 0x5a00
698 #define T_OPCODE_STR_RH 0x5200
699 #define T_OPCODE_LDR_RB 0x5c00
700 #define T_OPCODE_STR_RB 0x5400
702 #define T_OPCODE_PUSH 0xb400
703 #define T_OPCODE_POP 0xbc00
705 #define T_OPCODE_BRANCH 0xe000
707 #define THUMB_SIZE 2 /* Size of thumb instruction. */
708 #define THUMB_PP_PC_LR 0x0100
709 #define THUMB_LOAD_BIT 0x0800
710 #define THUMB2_LOAD_BIT 0x00100000
712 #define BAD_ARGS _("bad arguments to instruction")
713 #define BAD_SP _("r13 not allowed here")
714 #define BAD_PC _("r15 not allowed here")
715 #define BAD_COND _("instruction cannot be conditional")
716 #define BAD_OVERLAP _("registers may not be the same")
717 #define BAD_HIREG _("lo register required")
718 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
719 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
720 #define BAD_BRANCH _("branch must be last instruction in IT block")
721 #define BAD_NOT_IT _("instruction not allowed in IT block")
722 #define BAD_FPU _("selected FPU does not support instruction")
723 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
724 #define BAD_IT_COND _("incorrect condition in IT block")
725 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
726 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
727 #define BAD_PC_ADDRESSING \
728 _("cannot use register index with PC-relative addressing")
729 #define BAD_PC_WRITEBACK \
730 _("cannot use writeback with PC-relative addressing")
731 #define BAD_RANGE _("branch out of range")
733 static struct hash_control * arm_ops_hsh;
734 static struct hash_control * arm_cond_hsh;
735 static struct hash_control * arm_shift_hsh;
736 static struct hash_control * arm_psr_hsh;
737 static struct hash_control * arm_v7m_psr_hsh;
738 static struct hash_control * arm_reg_hsh;
739 static struct hash_control * arm_reloc_hsh;
740 static struct hash_control * arm_barrier_opt_hsh;
742 /* Stuff needed to resolve the label ambiguity
751 symbolS * last_label_seen;
752 static int label_is_thumb_function_name = FALSE;
754 /* Literal pool structure. Held on a per-section
755 and per-sub-section basis. */
757 #define MAX_LITERAL_POOL_SIZE 1024
758 typedef struct literal_pool
760 expressionS literals [MAX_LITERAL_POOL_SIZE];
761 unsigned int next_free_entry;
767 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
769 struct literal_pool * next;
772 /* Pointer to a linked list of literal pools. */
773 literal_pool * list_of_pools = NULL;
776 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
778 static struct current_it now_it;
782 now_it_compatible (int cond)
784 return (cond & ~1) == (now_it.cc & ~1);
788 conditional_insn (void)
790 return inst.cond != COND_ALWAYS;
793 static int in_it_block (void);
795 static int handle_it_state (void);
797 static void force_automatic_it_block_close (void);
799 static void it_fsm_post_encode (void);
801 #define set_it_insn_type(type) \
804 inst.it_insn_type = type; \
805 if (handle_it_state () == FAIL) \
810 #define set_it_insn_type_nonvoid(type, failret) \
813 inst.it_insn_type = type; \
814 if (handle_it_state () == FAIL) \
819 #define set_it_insn_type_last() \
822 if (inst.cond == COND_ALWAYS) \
823 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
825 set_it_insn_type (INSIDE_IT_LAST_INSN); \
831 /* This array holds the chars that always start a comment. If the
832 pre-processor is disabled, these aren't very useful. */
833 const char comment_chars[] = "@";
835 /* This array holds the chars that only start a comment at the beginning of
836 a line. If the line seems to have the form '# 123 filename'
837 .line and .file directives will appear in the pre-processed output. */
838 /* Note that input_file.c hand checks for '#' at the beginning of the
839 first line of the input file. This is because the compiler outputs
840 #NO_APP at the beginning of its output. */
841 /* Also note that comments like this one will always work. */
842 const char line_comment_chars[] = "#";
844 const char line_separator_chars[] = ";";
846 /* Chars that can be used to separate mant
847 from exp in floating point numbers. */
848 const char EXP_CHARS[] = "eE";
850 /* Chars that mean this number is a floating point constant. */
854 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
856 /* Prefix characters that indicate the start of an immediate
858 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
860 /* Separator character handling. */
862 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
865 skip_past_char (char ** str, char c)
876 #define skip_past_comma(str) skip_past_char (str, ',')
878 /* Arithmetic expressions (possibly involving symbols). */
880 /* Return TRUE if anything in the expression is a bignum. */
883 walk_no_bignums (symbolS * sp)
885 if (symbol_get_value_expression (sp)->X_op == O_big)
888 if (symbol_get_value_expression (sp)->X_add_symbol)
890 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
891 || (symbol_get_value_expression (sp)->X_op_symbol
892 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
898 static int in_my_get_expression = 0;
900 /* Third argument to my_get_expression. */
901 #define GE_NO_PREFIX 0
902 #define GE_IMM_PREFIX 1
903 #define GE_OPT_PREFIX 2
904 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
905 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
906 #define GE_OPT_PREFIX_BIG 3
909 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
914 /* In unified syntax, all prefixes are optional. */
916 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
921 case GE_NO_PREFIX: break;
923 if (!is_immediate_prefix (**str))
925 inst.error = _("immediate expression requires a # prefix");
931 case GE_OPT_PREFIX_BIG:
932 if (is_immediate_prefix (**str))
938 memset (ep, 0, sizeof (expressionS));
940 save_in = input_line_pointer;
941 input_line_pointer = *str;
942 in_my_get_expression = 1;
943 seg = expression (ep);
944 in_my_get_expression = 0;
946 if (ep->X_op == O_illegal || ep->X_op == O_absent)
948 /* We found a bad or missing expression in md_operand(). */
949 *str = input_line_pointer;
950 input_line_pointer = save_in;
951 if (inst.error == NULL)
952 inst.error = (ep->X_op == O_absent
953 ? _("missing expression") :_("bad expression"));
958 if (seg != absolute_section
959 && seg != text_section
960 && seg != data_section
961 && seg != bss_section
962 && seg != undefined_section)
964 inst.error = _("bad segment");
965 *str = input_line_pointer;
966 input_line_pointer = save_in;
973 /* Get rid of any bignums now, so that we don't generate an error for which
974 we can't establish a line number later on. Big numbers are never valid
975 in instructions, which is where this routine is always called. */
976 if (prefix_mode != GE_OPT_PREFIX_BIG
977 && (ep->X_op == O_big
979 && (walk_no_bignums (ep->X_add_symbol)
981 && walk_no_bignums (ep->X_op_symbol))))))
983 inst.error = _("invalid constant");
984 *str = input_line_pointer;
985 input_line_pointer = save_in;
989 *str = input_line_pointer;
990 input_line_pointer = save_in;
994 /* Turn a string in input_line_pointer into a floating point constant
995 of type TYPE, and store the appropriate bytes in *LITP. The number
996 of LITTLENUMS emitted is stored in *SIZEP. An error message is
997 returned, or NULL on OK.
999 Note that fp constants aren't represent in the normal way on the ARM.
1000 In big endian mode, things are as expected. However, in little endian
1001 mode fp constants are big-endian word-wise, and little-endian byte-wise
1002 within the words. For example, (double) 1.1 in big endian mode is
1003 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1004 the byte sequence 99 99 f1 3f 9a 99 99 99.
1006 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1009 md_atof (int type, char * litP, int * sizeP)
1012 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1044 return _("Unrecognized or unsupported floating point constant");
1047 t = atof_ieee (input_line_pointer, type, words);
1049 input_line_pointer = t;
1050 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1052 if (target_big_endian)
1054 for (i = 0; i < prec; i++)
1056 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1057 litP += sizeof (LITTLENUM_TYPE);
1062 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1063 for (i = prec - 1; i >= 0; i--)
1065 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1066 litP += sizeof (LITTLENUM_TYPE);
1069 /* For a 4 byte float the order of elements in `words' is 1 0.
1070 For an 8 byte float the order is 1 0 3 2. */
1071 for (i = 0; i < prec; i += 2)
1073 md_number_to_chars (litP, (valueT) words[i + 1],
1074 sizeof (LITTLENUM_TYPE));
1075 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1076 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1077 litP += 2 * sizeof (LITTLENUM_TYPE);
1084 /* We handle all bad expressions here, so that we can report the faulty
1085 instruction in the error message. */
1087 md_operand (expressionS * exp)
1089 if (in_my_get_expression)
1090 exp->X_op = O_illegal;
1093 /* Immediate values. */
1095 /* Generic immediate-value read function for use in directives.
1096 Accepts anything that 'expression' can fold to a constant.
1097 *val receives the number. */
1100 immediate_for_directive (int *val)
1103 exp.X_op = O_illegal;
1105 if (is_immediate_prefix (*input_line_pointer))
1107 input_line_pointer++;
1111 if (exp.X_op != O_constant)
1113 as_bad (_("expected #constant"));
1114 ignore_rest_of_line ();
1117 *val = exp.X_add_number;
1122 /* Register parsing. */
1124 /* Generic register parser. CCP points to what should be the
1125 beginning of a register name. If it is indeed a valid register
1126 name, advance CCP over it and return the reg_entry structure;
1127 otherwise return NULL. Does not issue diagnostics. */
1129 static struct reg_entry *
1130 arm_reg_parse_multi (char **ccp)
1134 struct reg_entry *reg;
1136 #ifdef REGISTER_PREFIX
1137 if (*start != REGISTER_PREFIX)
1141 #ifdef OPTIONAL_REGISTER_PREFIX
1142 if (*start == OPTIONAL_REGISTER_PREFIX)
1147 if (!ISALPHA (*p) || !is_name_beginner (*p))
1152 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1154 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1164 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1165 enum arm_reg_type type)
1167 /* Alternative syntaxes are accepted for a few register classes. */
1174 /* Generic coprocessor register names are allowed for these. */
1175 if (reg && reg->type == REG_TYPE_CN)
1180 /* For backward compatibility, a bare number is valid here. */
1182 unsigned long processor = strtoul (start, ccp, 10);
1183 if (*ccp != start && processor <= 15)
1187 case REG_TYPE_MMXWC:
1188 /* WC includes WCG. ??? I'm not sure this is true for all
1189 instructions that take WC registers. */
1190 if (reg && reg->type == REG_TYPE_MMXWCG)
1201 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1202 return value is the register number or FAIL. */
1205 arm_reg_parse (char **ccp, enum arm_reg_type type)
1208 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1211 /* Do not allow a scalar (reg+index) to parse as a register. */
1212 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1215 if (reg && reg->type == type)
1218 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1225 /* Parse a Neon type specifier. *STR should point at the leading '.'
1226 character. Does no verification at this stage that the type fits the opcode
1233 Can all be legally parsed by this function.
1235 Fills in neon_type struct pointer with parsed information, and updates STR
1236 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1237 type, FAIL if not. */
1240 parse_neon_type (struct neon_type *type, char **str)
1247 while (type->elems < NEON_MAX_TYPE_ELS)
1249 enum neon_el_type thistype = NT_untyped;
1250 unsigned thissize = -1u;
1257 /* Just a size without an explicit type. */
1261 switch (TOLOWER (*ptr))
1263 case 'i': thistype = NT_integer; break;
1264 case 'f': thistype = NT_float; break;
1265 case 'p': thistype = NT_poly; break;
1266 case 's': thistype = NT_signed; break;
1267 case 'u': thistype = NT_unsigned; break;
1269 thistype = NT_float;
1274 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1280 /* .f is an abbreviation for .f32. */
1281 if (thistype == NT_float && !ISDIGIT (*ptr))
1286 thissize = strtoul (ptr, &ptr, 10);
1288 if (thissize != 8 && thissize != 16 && thissize != 32
1291 as_bad (_("bad size %d in type specifier"), thissize);
1299 type->el[type->elems].type = thistype;
1300 type->el[type->elems].size = thissize;
1305 /* Empty/missing type is not a successful parse. */
1306 if (type->elems == 0)
1314 /* Errors may be set multiple times during parsing or bit encoding
1315 (particularly in the Neon bits), but usually the earliest error which is set
1316 will be the most meaningful. Avoid overwriting it with later (cascading)
1317 errors by calling this function. */
1320 first_error (const char *err)
1326 /* Parse a single type, e.g. ".s32", leading period included. */
1328 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1331 struct neon_type optype;
1335 if (parse_neon_type (&optype, &str) == SUCCESS)
1337 if (optype.elems == 1)
1338 *vectype = optype.el[0];
1341 first_error (_("only one type should be specified for operand"));
1347 first_error (_("vector type expected"));
1359 /* Special meanings for indices (which have a range of 0-7), which will fit into
1362 #define NEON_ALL_LANES 15
1363 #define NEON_INTERLEAVE_LANES 14
1365 /* Parse either a register or a scalar, with an optional type. Return the
1366 register number, and optionally fill in the actual type of the register
1367 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1368 type/index information in *TYPEINFO. */
1371 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1372 enum arm_reg_type *rtype,
1373 struct neon_typed_alias *typeinfo)
1376 struct reg_entry *reg = arm_reg_parse_multi (&str);
1377 struct neon_typed_alias atype;
1378 struct neon_type_el parsetype;
1382 atype.eltype.type = NT_invtype;
1383 atype.eltype.size = -1;
1385 /* Try alternate syntax for some types of register. Note these are mutually
1386 exclusive with the Neon syntax extensions. */
1389 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1397 /* Undo polymorphism when a set of register types may be accepted. */
1398 if ((type == REG_TYPE_NDQ
1399 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1400 || (type == REG_TYPE_VFSD
1401 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1402 || (type == REG_TYPE_NSDQ
1403 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1404 || reg->type == REG_TYPE_NQ))
1405 || (type == REG_TYPE_MMXWC
1406 && (reg->type == REG_TYPE_MMXWCG)))
1407 type = (enum arm_reg_type) reg->type;
1409 if (type != reg->type)
1415 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1417 if ((atype.defined & NTA_HASTYPE) != 0)
1419 first_error (_("can't redefine type for operand"));
1422 atype.defined |= NTA_HASTYPE;
1423 atype.eltype = parsetype;
1426 if (skip_past_char (&str, '[') == SUCCESS)
1428 if (type != REG_TYPE_VFD)
1430 first_error (_("only D registers may be indexed"));
1434 if ((atype.defined & NTA_HASINDEX) != 0)
1436 first_error (_("can't change index for operand"));
1440 atype.defined |= NTA_HASINDEX;
1442 if (skip_past_char (&str, ']') == SUCCESS)
1443 atype.index = NEON_ALL_LANES;
1448 my_get_expression (&exp, &str, GE_NO_PREFIX);
1450 if (exp.X_op != O_constant)
1452 first_error (_("constant expression required"));
1456 if (skip_past_char (&str, ']') == FAIL)
1459 atype.index = exp.X_add_number;
1474 /* Like arm_reg_parse, but allow allow the following extra features:
1475 - If RTYPE is non-zero, return the (possibly restricted) type of the
1476 register (e.g. Neon double or quad reg when either has been requested).
1477 - If this is a Neon vector type with additional type information, fill
1478 in the struct pointed to by VECTYPE (if non-NULL).
1479 This function will fault on encountering a scalar. */
1482 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1483 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1485 struct neon_typed_alias atype;
1487 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1492 /* Do not allow regname(... to parse as a register. */
1496 /* Do not allow a scalar (reg+index) to parse as a register. */
1497 if ((atype.defined & NTA_HASINDEX) != 0)
1499 first_error (_("register operand expected, but got scalar"));
1504 *vectype = atype.eltype;
1511 #define NEON_SCALAR_REG(X) ((X) >> 4)
1512 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1514 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1515 have enough information to be able to do a good job bounds-checking. So, we
1516 just do easy checks here, and do further checks later. */
1519 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1523 struct neon_typed_alias atype;
1525 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1527 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1530 if (atype.index == NEON_ALL_LANES)
1532 first_error (_("scalar must have an index"));
1535 else if (atype.index >= 64 / elsize)
1537 first_error (_("scalar index out of range"));
1542 *type = atype.eltype;
1546 return reg * 16 + atype.index;
1549 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1552 parse_reg_list (char ** strp)
1554 char * str = * strp;
1558 /* We come back here if we get ranges concatenated by '+' or '|'. */
1573 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1575 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1585 first_error (_("bad range in register list"));
1589 for (i = cur_reg + 1; i < reg; i++)
1591 if (range & (1 << i))
1593 (_("Warning: duplicated register (r%d) in register list"),
1601 if (range & (1 << reg))
1602 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1604 else if (reg <= cur_reg)
1605 as_tsktsk (_("Warning: register range not in ascending order"));
1610 while (skip_past_comma (&str) != FAIL
1611 || (in_range = 1, *str++ == '-'));
1616 first_error (_("missing `}'"));
1624 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1627 if (exp.X_op == O_constant)
1629 if (exp.X_add_number
1630 != (exp.X_add_number & 0x0000ffff))
1632 inst.error = _("invalid register mask");
1636 if ((range & exp.X_add_number) != 0)
1638 int regno = range & exp.X_add_number;
1641 regno = (1 << regno) - 1;
1643 (_("Warning: duplicated register (r%d) in register list"),
1647 range |= exp.X_add_number;
1651 if (inst.reloc.type != 0)
1653 inst.error = _("expression too complex");
1657 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1658 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1659 inst.reloc.pc_rel = 0;
1663 if (*str == '|' || *str == '+')
1669 while (another_range);
1675 /* Types of registers in a list. */
1684 /* Parse a VFP register list. If the string is invalid return FAIL.
1685 Otherwise return the number of registers, and set PBASE to the first
1686 register. Parses registers of type ETYPE.
1687 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1688 - Q registers can be used to specify pairs of D registers
1689 - { } can be omitted from around a singleton register list
1690 FIXME: This is not implemented, as it would require backtracking in
1693 This could be done (the meaning isn't really ambiguous), but doesn't
1694 fit in well with the current parsing framework.
1695 - 32 D registers may be used (also true for VFPv3).
1696 FIXME: Types are ignored in these register lists, which is probably a
1700 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1705 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1709 unsigned long mask = 0;
1714 inst.error = _("expecting {");
1723 regtype = REG_TYPE_VFS;
1728 regtype = REG_TYPE_VFD;
1731 case REGLIST_NEON_D:
1732 regtype = REG_TYPE_NDQ;
1736 if (etype != REGLIST_VFP_S)
1738 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1739 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1743 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1746 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1753 base_reg = max_regs;
1757 int setmask = 1, addregs = 1;
1759 new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL);
1761 if (new_base == FAIL)
1763 first_error (_(reg_expected_msgs[regtype]));
1767 if (new_base >= max_regs)
1769 first_error (_("register out of range in list"));
1773 /* Note: a value of 2 * n is returned for the register Q<n>. */
1774 if (regtype == REG_TYPE_NQ)
1780 if (new_base < base_reg)
1781 base_reg = new_base;
1783 if (mask & (setmask << new_base))
1785 first_error (_("invalid register list"));
1789 if ((mask >> new_base) != 0 && ! warned)
1791 as_tsktsk (_("register list not in ascending order"));
1795 mask |= setmask << new_base;
1798 if (*str == '-') /* We have the start of a range expression */
1804 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1807 inst.error = gettext (reg_expected_msgs[regtype]);
1811 if (high_range >= max_regs)
1813 first_error (_("register out of range in list"));
1817 if (regtype == REG_TYPE_NQ)
1818 high_range = high_range + 1;
1820 if (high_range <= new_base)
1822 inst.error = _("register range not in ascending order");
1826 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1828 if (mask & (setmask << new_base))
1830 inst.error = _("invalid register list");
1834 mask |= setmask << new_base;
1839 while (skip_past_comma (&str) != FAIL);
1843 /* Sanity check -- should have raised a parse error above. */
1844 if (count == 0 || count > max_regs)
1849 /* Final test -- the registers must be consecutive. */
1851 for (i = 0; i < count; i++)
1853 if ((mask & (1u << i)) == 0)
1855 inst.error = _("non-contiguous register range");
1865 /* True if two alias types are the same. */
1868 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1876 if (a->defined != b->defined)
1879 if ((a->defined & NTA_HASTYPE) != 0
1880 && (a->eltype.type != b->eltype.type
1881 || a->eltype.size != b->eltype.size))
1884 if ((a->defined & NTA_HASINDEX) != 0
1885 && (a->index != b->index))
1891 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1892 The base register is put in *PBASE.
1893 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1895 The register stride (minus one) is put in bit 4 of the return value.
1896 Bits [6:5] encode the list length (minus one).
1897 The type of the list elements is put in *ELTYPE, if non-NULL. */
1899 #define NEON_LANE(X) ((X) & 0xf)
1900 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1901 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1904 parse_neon_el_struct_list (char **str, unsigned *pbase,
1905 struct neon_type_el *eltype)
1912 int leading_brace = 0;
1913 enum arm_reg_type rtype = REG_TYPE_NDQ;
1914 const char *const incr_error = _("register stride must be 1 or 2");
1915 const char *const type_error = _("mismatched element/structure types in list");
1916 struct neon_typed_alias firsttype;
1918 if (skip_past_char (&ptr, '{') == SUCCESS)
1923 struct neon_typed_alias atype;
1924 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1928 first_error (_(reg_expected_msgs[rtype]));
1935 if (rtype == REG_TYPE_NQ)
1941 else if (reg_incr == -1)
1943 reg_incr = getreg - base_reg;
1944 if (reg_incr < 1 || reg_incr > 2)
1946 first_error (_(incr_error));
1950 else if (getreg != base_reg + reg_incr * count)
1952 first_error (_(incr_error));
1956 if (! neon_alias_types_same (&atype, &firsttype))
1958 first_error (_(type_error));
1962 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1966 struct neon_typed_alias htype;
1967 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1969 lane = NEON_INTERLEAVE_LANES;
1970 else if (lane != NEON_INTERLEAVE_LANES)
1972 first_error (_(type_error));
1977 else if (reg_incr != 1)
1979 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1983 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1986 first_error (_(reg_expected_msgs[rtype]));
1989 if (! neon_alias_types_same (&htype, &firsttype))
1991 first_error (_(type_error));
1994 count += hireg + dregs - getreg;
1998 /* If we're using Q registers, we can't use [] or [n] syntax. */
1999 if (rtype == REG_TYPE_NQ)
2005 if ((atype.defined & NTA_HASINDEX) != 0)
2009 else if (lane != atype.index)
2011 first_error (_(type_error));
2015 else if (lane == -1)
2016 lane = NEON_INTERLEAVE_LANES;
2017 else if (lane != NEON_INTERLEAVE_LANES)
2019 first_error (_(type_error));
2024 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2026 /* No lane set by [x]. We must be interleaving structures. */
2028 lane = NEON_INTERLEAVE_LANES;
2031 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2032 || (count > 1 && reg_incr == -1))
2034 first_error (_("error parsing element/structure list"));
2038 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2040 first_error (_("expected }"));
2048 *eltype = firsttype.eltype;
2053 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2056 /* Parse an explicit relocation suffix on an expression. This is
2057 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2058 arm_reloc_hsh contains no entries, so this function can only
2059 succeed if there is no () after the word. Returns -1 on error,
2060 BFD_RELOC_UNUSED if there wasn't any suffix. */
2063 parse_reloc (char **str)
2065 struct reloc_entry *r;
2069 return BFD_RELOC_UNUSED;
2074 while (*q && *q != ')' && *q != ',')
2079 if ((r = (struct reloc_entry *)
2080 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2087 /* Directives: register aliases. */
2089 static struct reg_entry *
2090 insert_reg_alias (char *str, unsigned number, int type)
2092 struct reg_entry *new_reg;
2095 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2097 if (new_reg->builtin)
2098 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2100 /* Only warn about a redefinition if it's not defined as the
2102 else if (new_reg->number != number || new_reg->type != type)
2103 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2108 name = xstrdup (str);
2109 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2111 new_reg->name = name;
2112 new_reg->number = number;
2113 new_reg->type = type;
2114 new_reg->builtin = FALSE;
2115 new_reg->neon = NULL;
2117 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2124 insert_neon_reg_alias (char *str, int number, int type,
2125 struct neon_typed_alias *atype)
2127 struct reg_entry *reg = insert_reg_alias (str, number, type);
2131 first_error (_("attempt to redefine typed alias"));
2137 reg->neon = (struct neon_typed_alias *)
2138 xmalloc (sizeof (struct neon_typed_alias));
2139 *reg->neon = *atype;
2143 /* Look for the .req directive. This is of the form:
2145 new_register_name .req existing_register_name
2147 If we find one, or if it looks sufficiently like one that we want to
2148 handle any error here, return TRUE. Otherwise return FALSE. */
2151 create_register_alias (char * newname, char *p)
2153 struct reg_entry *old;
2154 char *oldname, *nbuf;
2157 /* The input scrubber ensures that whitespace after the mnemonic is
2158 collapsed to single spaces. */
2160 if (strncmp (oldname, " .req ", 6) != 0)
2164 if (*oldname == '\0')
2167 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2170 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2174 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2175 the desired alias name, and p points to its end. If not, then
2176 the desired alias name is in the global original_case_string. */
2177 #ifdef TC_CASE_SENSITIVE
2180 newname = original_case_string;
2181 nlen = strlen (newname);
2184 nbuf = (char *) alloca (nlen + 1);
2185 memcpy (nbuf, newname, nlen);
2188 /* Create aliases under the new name as stated; an all-lowercase
2189 version of the new name; and an all-uppercase version of the new
2191 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2193 for (p = nbuf; *p; p++)
2196 if (strncmp (nbuf, newname, nlen))
2198 /* If this attempt to create an additional alias fails, do not bother
2199 trying to create the all-lower case alias. We will fail and issue
2200 a second, duplicate error message. This situation arises when the
2201 programmer does something like:
2204 The second .req creates the "Foo" alias but then fails to create
2205 the artificial FOO alias because it has already been created by the
2207 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2211 for (p = nbuf; *p; p++)
2214 if (strncmp (nbuf, newname, nlen))
2215 insert_reg_alias (nbuf, old->number, old->type);
2221 /* Create a Neon typed/indexed register alias using directives, e.g.:
2226 These typed registers can be used instead of the types specified after the
2227 Neon mnemonic, so long as all operands given have types. Types can also be
2228 specified directly, e.g.:
2229 vadd d0.s32, d1.s32, d2.s32 */
2232 create_neon_reg_alias (char *newname, char *p)
2234 enum arm_reg_type basetype;
2235 struct reg_entry *basereg;
2236 struct reg_entry mybasereg;
2237 struct neon_type ntype;
2238 struct neon_typed_alias typeinfo;
2239 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2242 typeinfo.defined = 0;
2243 typeinfo.eltype.type = NT_invtype;
2244 typeinfo.eltype.size = -1;
2245 typeinfo.index = -1;
2249 if (strncmp (p, " .dn ", 5) == 0)
2250 basetype = REG_TYPE_VFD;
2251 else if (strncmp (p, " .qn ", 5) == 0)
2252 basetype = REG_TYPE_NQ;
2261 basereg = arm_reg_parse_multi (&p);
2263 if (basereg && basereg->type != basetype)
2265 as_bad (_("bad type for register"));
2269 if (basereg == NULL)
2272 /* Try parsing as an integer. */
2273 my_get_expression (&exp, &p, GE_NO_PREFIX);
2274 if (exp.X_op != O_constant)
2276 as_bad (_("expression must be constant"));
2279 basereg = &mybasereg;
2280 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2286 typeinfo = *basereg->neon;
2288 if (parse_neon_type (&ntype, &p) == SUCCESS)
2290 /* We got a type. */
2291 if (typeinfo.defined & NTA_HASTYPE)
2293 as_bad (_("can't redefine the type of a register alias"));
2297 typeinfo.defined |= NTA_HASTYPE;
2298 if (ntype.elems != 1)
2300 as_bad (_("you must specify a single type only"));
2303 typeinfo.eltype = ntype.el[0];
2306 if (skip_past_char (&p, '[') == SUCCESS)
2309 /* We got a scalar index. */
2311 if (typeinfo.defined & NTA_HASINDEX)
2313 as_bad (_("can't redefine the index of a scalar alias"));
2317 my_get_expression (&exp, &p, GE_NO_PREFIX);
2319 if (exp.X_op != O_constant)
2321 as_bad (_("scalar index must be constant"));
2325 typeinfo.defined |= NTA_HASINDEX;
2326 typeinfo.index = exp.X_add_number;
2328 if (skip_past_char (&p, ']') == FAIL)
2330 as_bad (_("expecting ]"));
2335 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2336 the desired alias name, and p points to its end. If not, then
2337 the desired alias name is in the global original_case_string. */
2338 #ifdef TC_CASE_SENSITIVE
2339 namelen = nameend - newname;
2341 newname = original_case_string;
2342 namelen = strlen (newname);
2345 namebuf = (char *) alloca (namelen + 1);
2346 strncpy (namebuf, newname, namelen);
2347 namebuf[namelen] = '\0';
2349 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2350 typeinfo.defined != 0 ? &typeinfo : NULL);
2352 /* Insert name in all uppercase. */
2353 for (p = namebuf; *p; p++)
2356 if (strncmp (namebuf, newname, namelen))
2357 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2358 typeinfo.defined != 0 ? &typeinfo : NULL);
2360 /* Insert name in all lowercase. */
2361 for (p = namebuf; *p; p++)
2364 if (strncmp (namebuf, newname, namelen))
2365 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2366 typeinfo.defined != 0 ? &typeinfo : NULL);
2371 /* Should never be called, as .req goes between the alias and the
2372 register name, not at the beginning of the line. */
2375 s_req (int a ATTRIBUTE_UNUSED)
2377 as_bad (_("invalid syntax for .req directive"));
2381 s_dn (int a ATTRIBUTE_UNUSED)
2383 as_bad (_("invalid syntax for .dn directive"));
2387 s_qn (int a ATTRIBUTE_UNUSED)
2389 as_bad (_("invalid syntax for .qn directive"));
2392 /* The .unreq directive deletes an alias which was previously defined
2393 by .req. For example:
2399 s_unreq (int a ATTRIBUTE_UNUSED)
2404 name = input_line_pointer;
2406 while (*input_line_pointer != 0
2407 && *input_line_pointer != ' '
2408 && *input_line_pointer != '\n')
2409 ++input_line_pointer;
2411 saved_char = *input_line_pointer;
2412 *input_line_pointer = 0;
2415 as_bad (_("invalid syntax for .unreq directive"));
2418 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2422 as_bad (_("unknown register alias '%s'"), name);
2423 else if (reg->builtin)
2424 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2431 hash_delete (arm_reg_hsh, name, FALSE);
2432 free ((char *) reg->name);
2437 /* Also locate the all upper case and all lower case versions.
2438 Do not complain if we cannot find one or the other as it
2439 was probably deleted above. */
2441 nbuf = strdup (name);
2442 for (p = nbuf; *p; p++)
2444 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2447 hash_delete (arm_reg_hsh, nbuf, FALSE);
2448 free ((char *) reg->name);
2454 for (p = nbuf; *p; p++)
2456 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2459 hash_delete (arm_reg_hsh, nbuf, FALSE);
2460 free ((char *) reg->name);
2470 *input_line_pointer = saved_char;
2471 demand_empty_rest_of_line ();
2474 /* Directives: Instruction set selection. */
2477 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2478 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2479 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2480 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2482 /* Create a new mapping symbol for the transition to STATE. */
2485 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2488 const char * symname;
2495 type = BSF_NO_FLAGS;
2499 type = BSF_NO_FLAGS;
2503 type = BSF_NO_FLAGS;
2509 symbolP = symbol_new (symname, now_seg, value, frag);
2510 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2515 THUMB_SET_FUNC (symbolP, 0);
2516 ARM_SET_THUMB (symbolP, 0);
2517 ARM_SET_INTERWORK (symbolP, support_interwork);
2521 THUMB_SET_FUNC (symbolP, 1);
2522 ARM_SET_THUMB (symbolP, 1);
2523 ARM_SET_INTERWORK (symbolP, support_interwork);
2531 /* Save the mapping symbols for future reference. Also check that
2532 we do not place two mapping symbols at the same offset within a
2533 frag. We'll handle overlap between frags in
2534 check_mapping_symbols.
2536 If .fill or other data filling directive generates zero sized data,
2537 the mapping symbol for the following code will have the same value
2538 as the one generated for the data filling directive. In this case,
2539 we replace the old symbol with the new one at the same address. */
2542 if (frag->tc_frag_data.first_map != NULL)
2544 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2545 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2547 frag->tc_frag_data.first_map = symbolP;
2549 if (frag->tc_frag_data.last_map != NULL)
2551 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2552 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2553 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2555 frag->tc_frag_data.last_map = symbolP;
2558 /* We must sometimes convert a region marked as code to data during
2559 code alignment, if an odd number of bytes have to be padded. The
2560 code mapping symbol is pushed to an aligned address. */
2563 insert_data_mapping_symbol (enum mstate state,
2564 valueT value, fragS *frag, offsetT bytes)
2566 /* If there was already a mapping symbol, remove it. */
2567 if (frag->tc_frag_data.last_map != NULL
2568 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2570 symbolS *symp = frag->tc_frag_data.last_map;
2574 know (frag->tc_frag_data.first_map == symp);
2575 frag->tc_frag_data.first_map = NULL;
2577 frag->tc_frag_data.last_map = NULL;
2578 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2581 make_mapping_symbol (MAP_DATA, value, frag);
2582 make_mapping_symbol (state, value + bytes, frag);
2585 static void mapping_state_2 (enum mstate state, int max_chars);
2587 /* Set the mapping state to STATE. Only call this when about to
2588 emit some STATE bytes to the file. */
2591 mapping_state (enum mstate state)
2593 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2595 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2597 if (mapstate == state)
2598 /* The mapping symbol has already been emitted.
2599 There is nothing else to do. */
2602 if (state == MAP_ARM || state == MAP_THUMB)
2604 All ARM instructions require 4-byte alignment.
2605 (Almost) all Thumb instructions require 2-byte alignment.
2607 When emitting instructions into any section, mark the section
2610 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2611 but themselves require 2-byte alignment; this applies to some
2612 PC- relative forms. However, these cases will invovle implicit
2613 literal pool generation or an explicit .align >=2, both of
2614 which will cause the section to me marked with sufficient
2615 alignment. Thus, we don't handle those cases here. */
2616 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2618 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2619 /* This case will be evaluated later in the next else. */
2621 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2622 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2624 /* Only add the symbol if the offset is > 0:
2625 if we're at the first frag, check it's size > 0;
2626 if we're not at the first frag, then for sure
2627 the offset is > 0. */
2628 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2629 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2632 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2635 mapping_state_2 (state, 0);
2639 /* Same as mapping_state, but MAX_CHARS bytes have already been
2640 allocated. Put the mapping symbol that far back. */
2643 mapping_state_2 (enum mstate state, int max_chars)
2645 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2647 if (!SEG_NORMAL (now_seg))
2650 if (mapstate == state)
2651 /* The mapping symbol has already been emitted.
2652 There is nothing else to do. */
2655 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2656 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2659 #define mapping_state(x) ((void)0)
2660 #define mapping_state_2(x, y) ((void)0)
2663 /* Find the real, Thumb encoded start of a Thumb function. */
2667 find_real_start (symbolS * symbolP)
2670 const char * name = S_GET_NAME (symbolP);
2671 symbolS * new_target;
2673 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2674 #define STUB_NAME ".real_start_of"
2679 /* The compiler may generate BL instructions to local labels because
2680 it needs to perform a branch to a far away location. These labels
2681 do not have a corresponding ".real_start_of" label. We check
2682 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2683 the ".real_start_of" convention for nonlocal branches. */
2684 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2687 real_start = ACONCAT ((STUB_NAME, name, NULL));
2688 new_target = symbol_find (real_start);
2690 if (new_target == NULL)
2692 as_warn (_("Failed to find real start of function: %s\n"), name);
2693 new_target = symbolP;
2701 opcode_select (int width)
2708 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2709 as_bad (_("selected processor does not support THUMB opcodes"));
2712 /* No need to force the alignment, since we will have been
2713 coming from ARM mode, which is word-aligned. */
2714 record_alignment (now_seg, 1);
2721 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2722 as_bad (_("selected processor does not support ARM opcodes"));
2727 frag_align (2, 0, 0);
2729 record_alignment (now_seg, 1);
2734 as_bad (_("invalid instruction size selected (%d)"), width);
2739 s_arm (int ignore ATTRIBUTE_UNUSED)
2742 demand_empty_rest_of_line ();
2746 s_thumb (int ignore ATTRIBUTE_UNUSED)
2749 demand_empty_rest_of_line ();
2753 s_code (int unused ATTRIBUTE_UNUSED)
2757 temp = get_absolute_expression ();
2762 opcode_select (temp);
2766 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2771 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2773 /* If we are not already in thumb mode go into it, EVEN if
2774 the target processor does not support thumb instructions.
2775 This is used by gcc/config/arm/lib1funcs.asm for example
2776 to compile interworking support functions even if the
2777 target processor should not support interworking. */
2781 record_alignment (now_seg, 1);
2784 demand_empty_rest_of_line ();
2788 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2792 /* The following label is the name/address of the start of a Thumb function.
2793 We need to know this for the interworking support. */
2794 label_is_thumb_function_name = TRUE;
2797 /* Perform a .set directive, but also mark the alias as
2798 being a thumb function. */
2801 s_thumb_set (int equiv)
2803 /* XXX the following is a duplicate of the code for s_set() in read.c
2804 We cannot just call that code as we need to get at the symbol that
2811 /* Especial apologies for the random logic:
2812 This just grew, and could be parsed much more simply!
2814 name = input_line_pointer;
2815 delim = get_symbol_end ();
2816 end_name = input_line_pointer;
2819 if (*input_line_pointer != ',')
2822 as_bad (_("expected comma after name \"%s\""), name);
2824 ignore_rest_of_line ();
2828 input_line_pointer++;
2831 if (name[0] == '.' && name[1] == '\0')
2833 /* XXX - this should not happen to .thumb_set. */
2837 if ((symbolP = symbol_find (name)) == NULL
2838 && (symbolP = md_undefined_symbol (name)) == NULL)
2841 /* When doing symbol listings, play games with dummy fragments living
2842 outside the normal fragment chain to record the file and line info
2844 if (listing & LISTING_SYMBOLS)
2846 extern struct list_info_struct * listing_tail;
2847 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2849 memset (dummy_frag, 0, sizeof (fragS));
2850 dummy_frag->fr_type = rs_fill;
2851 dummy_frag->line = listing_tail;
2852 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2853 dummy_frag->fr_symbol = symbolP;
2857 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2860 /* "set" symbols are local unless otherwise specified. */
2861 SF_SET_LOCAL (symbolP);
2862 #endif /* OBJ_COFF */
2863 } /* Make a new symbol. */
2865 symbol_table_insert (symbolP);
2870 && S_IS_DEFINED (symbolP)
2871 && S_GET_SEGMENT (symbolP) != reg_section)
2872 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2874 pseudo_set (symbolP);
2876 demand_empty_rest_of_line ();
2878 /* XXX Now we come to the Thumb specific bit of code. */
2880 THUMB_SET_FUNC (symbolP, 1);
2881 ARM_SET_THUMB (symbolP, 1);
2882 #if defined OBJ_ELF || defined OBJ_COFF
2883 ARM_SET_INTERWORK (symbolP, support_interwork);
2887 /* Directives: Mode selection. */
2889 /* .syntax [unified|divided] - choose the new unified syntax
2890 (same for Arm and Thumb encoding, modulo slight differences in what
2891 can be represented) or the old divergent syntax for each mode. */
2893 s_syntax (int unused ATTRIBUTE_UNUSED)
2897 name = input_line_pointer;
2898 delim = get_symbol_end ();
2900 if (!strcasecmp (name, "unified"))
2901 unified_syntax = TRUE;
2902 else if (!strcasecmp (name, "divided"))
2903 unified_syntax = FALSE;
2906 as_bad (_("unrecognized syntax mode \"%s\""), name);
2909 *input_line_pointer = delim;
2910 demand_empty_rest_of_line ();
2913 /* Directives: sectioning and alignment. */
2915 /* Same as s_align_ptwo but align 0 => align 2. */
2918 s_align (int unused ATTRIBUTE_UNUSED)
2923 long max_alignment = 15;
2925 temp = get_absolute_expression ();
2926 if (temp > max_alignment)
2927 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2930 as_bad (_("alignment negative. 0 assumed."));
2934 if (*input_line_pointer == ',')
2936 input_line_pointer++;
2937 temp_fill = get_absolute_expression ();
2949 /* Only make a frag if we HAVE to. */
2950 if (temp && !need_pass_2)
2952 if (!fill_p && subseg_text_p (now_seg))
2953 frag_align_code (temp, 0);
2955 frag_align (temp, (int) temp_fill, 0);
2957 demand_empty_rest_of_line ();
2959 record_alignment (now_seg, temp);
2963 s_bss (int ignore ATTRIBUTE_UNUSED)
2965 /* We don't support putting frags in the BSS segment, we fake it by
2966 marking in_bss, then looking at s_skip for clues. */
2967 subseg_set (bss_section, 0);
2968 demand_empty_rest_of_line ();
2970 #ifdef md_elf_section_change_hook
2971 md_elf_section_change_hook ();
2976 s_even (int ignore ATTRIBUTE_UNUSED)
2978 /* Never make frag if expect extra pass. */
2980 frag_align (1, 0, 0);
2982 record_alignment (now_seg, 1);
2984 demand_empty_rest_of_line ();
2987 /* Directives: Literal pools. */
2989 static literal_pool *
2990 find_literal_pool (void)
2992 literal_pool * pool;
2994 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2996 if (pool->section == now_seg
2997 && pool->sub_section == now_subseg)
3004 static literal_pool *
3005 find_or_make_literal_pool (void)
3007 /* Next literal pool ID number. */
3008 static unsigned int latest_pool_num = 1;
3009 literal_pool * pool;
3011 pool = find_literal_pool ();
3015 /* Create a new pool. */
3016 pool = (literal_pool *) xmalloc (sizeof (* pool));
3020 pool->next_free_entry = 0;
3021 pool->section = now_seg;
3022 pool->sub_section = now_subseg;
3023 pool->next = list_of_pools;
3024 pool->symbol = NULL;
3026 /* Add it to the list. */
3027 list_of_pools = pool;
3030 /* New pools, and emptied pools, will have a NULL symbol. */
3031 if (pool->symbol == NULL)
3033 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3034 (valueT) 0, &zero_address_frag);
3035 pool->id = latest_pool_num ++;
3042 /* Add the literal in the global 'inst'
3043 structure to the relevant literal pool. */
3046 add_to_lit_pool (void)
3048 literal_pool * pool;
3051 pool = find_or_make_literal_pool ();
3053 /* Check if this literal value is already in the pool. */
3054 for (entry = 0; entry < pool->next_free_entry; entry ++)
3056 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3057 && (inst.reloc.exp.X_op == O_constant)
3058 && (pool->literals[entry].X_add_number
3059 == inst.reloc.exp.X_add_number)
3060 && (pool->literals[entry].X_unsigned
3061 == inst.reloc.exp.X_unsigned))
3064 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3065 && (inst.reloc.exp.X_op == O_symbol)
3066 && (pool->literals[entry].X_add_number
3067 == inst.reloc.exp.X_add_number)
3068 && (pool->literals[entry].X_add_symbol
3069 == inst.reloc.exp.X_add_symbol)
3070 && (pool->literals[entry].X_op_symbol
3071 == inst.reloc.exp.X_op_symbol))
3075 /* Do we need to create a new entry? */
3076 if (entry == pool->next_free_entry)
3078 if (entry >= MAX_LITERAL_POOL_SIZE)
3080 inst.error = _("literal pool overflow");
3084 pool->literals[entry] = inst.reloc.exp;
3086 /* PR ld/12974: Record the location of the first source line to reference
3087 this entry in the literal pool. If it turns out during linking that the
3088 symbol does not exist we will be able to give an accurate line number for
3089 the (first use of the) missing reference. */
3090 if (debug_type == DEBUG_DWARF2)
3091 dwarf2_where (pool->locs + entry);
3093 pool->next_free_entry += 1;
3096 inst.reloc.exp.X_op = O_symbol;
3097 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3098 inst.reloc.exp.X_add_symbol = pool->symbol;
3103 /* Can't use symbol_new here, so have to create a symbol and then at
3104 a later date assign it a value. Thats what these functions do. */
3107 symbol_locate (symbolS * symbolP,
3108 const char * name, /* It is copied, the caller can modify. */
3109 segT segment, /* Segment identifier (SEG_<something>). */
3110 valueT valu, /* Symbol value. */
3111 fragS * frag) /* Associated fragment. */
3113 unsigned int name_length;
3114 char * preserved_copy_of_name;
3116 name_length = strlen (name) + 1; /* +1 for \0. */
3117 obstack_grow (¬es, name, name_length);
3118 preserved_copy_of_name = (char *) obstack_finish (¬es);
3120 #ifdef tc_canonicalize_symbol_name
3121 preserved_copy_of_name =
3122 tc_canonicalize_symbol_name (preserved_copy_of_name);
3125 S_SET_NAME (symbolP, preserved_copy_of_name);
3127 S_SET_SEGMENT (symbolP, segment);
3128 S_SET_VALUE (symbolP, valu);
3129 symbol_clear_list_pointers (symbolP);
3131 symbol_set_frag (symbolP, frag);
3133 /* Link to end of symbol chain. */
3135 extern int symbol_table_frozen;
3137 if (symbol_table_frozen)
3141 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3143 obj_symbol_new_hook (symbolP);
3145 #ifdef tc_symbol_new_hook
3146 tc_symbol_new_hook (symbolP);
3150 verify_symbol_chain (symbol_rootP, symbol_lastP);
3151 #endif /* DEBUG_SYMS */
3156 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3159 literal_pool * pool;
3162 pool = find_literal_pool ();
3164 || pool->symbol == NULL
3165 || pool->next_free_entry == 0)
3168 mapping_state (MAP_DATA);
3170 /* Align pool as you have word accesses.
3171 Only make a frag if we have to. */
3173 frag_align (2, 0, 0);
3175 record_alignment (now_seg, 2);
3177 sprintf (sym_name, "$$lit_\002%x", pool->id);
3179 symbol_locate (pool->symbol, sym_name, now_seg,
3180 (valueT) frag_now_fix (), frag_now);
3181 symbol_table_insert (pool->symbol);
3183 ARM_SET_THUMB (pool->symbol, thumb_mode);
3185 #if defined OBJ_COFF || defined OBJ_ELF
3186 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3189 for (entry = 0; entry < pool->next_free_entry; entry ++)
3192 if (debug_type == DEBUG_DWARF2)
3193 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3195 /* First output the expression in the instruction to the pool. */
3196 emit_expr (&(pool->literals[entry]), 4); /* .word */
3199 /* Mark the pool as empty. */
3200 pool->next_free_entry = 0;
3201 pool->symbol = NULL;
3205 /* Forward declarations for functions below, in the MD interface
3207 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3208 static valueT create_unwind_entry (int);
3209 static void start_unwind_section (const segT, int);
3210 static void add_unwind_opcode (valueT, int);
3211 static void flush_pending_unwind (void);
3213 /* Directives: Data. */
3216 s_arm_elf_cons (int nbytes)
3220 #ifdef md_flush_pending_output
3221 md_flush_pending_output ();
3224 if (is_it_end_of_statement ())
3226 demand_empty_rest_of_line ();
3230 #ifdef md_cons_align
3231 md_cons_align (nbytes);
3234 mapping_state (MAP_DATA);
3238 char *base = input_line_pointer;
3242 if (exp.X_op != O_symbol)
3243 emit_expr (&exp, (unsigned int) nbytes);
3246 char *before_reloc = input_line_pointer;
3247 reloc = parse_reloc (&input_line_pointer);
3250 as_bad (_("unrecognized relocation suffix"));
3251 ignore_rest_of_line ();
3254 else if (reloc == BFD_RELOC_UNUSED)
3255 emit_expr (&exp, (unsigned int) nbytes);
3258 reloc_howto_type *howto = (reloc_howto_type *)
3259 bfd_reloc_type_lookup (stdoutput,
3260 (bfd_reloc_code_real_type) reloc);
3261 int size = bfd_get_reloc_size (howto);
3263 if (reloc == BFD_RELOC_ARM_PLT32)
3265 as_bad (_("(plt) is only valid on branch targets"));
3266 reloc = BFD_RELOC_UNUSED;
3271 as_bad (_("%s relocations do not fit in %d bytes"),
3272 howto->name, nbytes);
3275 /* We've parsed an expression stopping at O_symbol.
3276 But there may be more expression left now that we
3277 have parsed the relocation marker. Parse it again.
3278 XXX Surely there is a cleaner way to do this. */
3279 char *p = input_line_pointer;
3281 char *save_buf = (char *) alloca (input_line_pointer - base);
3282 memcpy (save_buf, base, input_line_pointer - base);
3283 memmove (base + (input_line_pointer - before_reloc),
3284 base, before_reloc - base);
3286 input_line_pointer = base + (input_line_pointer-before_reloc);
3288 memcpy (base, save_buf, p - base);
3290 offset = nbytes - size;
3291 p = frag_more ((int) nbytes);
3292 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3293 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3298 while (*input_line_pointer++ == ',');
3300 /* Put terminator back into stream. */
3301 input_line_pointer --;
3302 demand_empty_rest_of_line ();
3305 /* Emit an expression containing a 32-bit thumb instruction.
3306 Implementation based on put_thumb32_insn. */
3309 emit_thumb32_expr (expressionS * exp)
3311 expressionS exp_high = *exp;
3313 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3314 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3315 exp->X_add_number &= 0xffff;
3316 emit_expr (exp, (unsigned int) THUMB_SIZE);
3319 /* Guess the instruction size based on the opcode. */
3322 thumb_insn_size (int opcode)
3324 if ((unsigned int) opcode < 0xe800u)
3326 else if ((unsigned int) opcode >= 0xe8000000u)
3333 emit_insn (expressionS *exp, int nbytes)
3337 if (exp->X_op == O_constant)
3342 size = thumb_insn_size (exp->X_add_number);
3346 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3348 as_bad (_(".inst.n operand too big. "\
3349 "Use .inst.w instead"));
3354 if (now_it.state == AUTOMATIC_IT_BLOCK)
3355 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3357 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3359 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3360 emit_thumb32_expr (exp);
3362 emit_expr (exp, (unsigned int) size);
3364 it_fsm_post_encode ();
3368 as_bad (_("cannot determine Thumb instruction size. " \
3369 "Use .inst.n/.inst.w instead"));
3372 as_bad (_("constant expression required"));
3377 /* Like s_arm_elf_cons but do not use md_cons_align and
3378 set the mapping state to MAP_ARM/MAP_THUMB. */
3381 s_arm_elf_inst (int nbytes)
3383 if (is_it_end_of_statement ())
3385 demand_empty_rest_of_line ();
3389 /* Calling mapping_state () here will not change ARM/THUMB,
3390 but will ensure not to be in DATA state. */
3393 mapping_state (MAP_THUMB);
3398 as_bad (_("width suffixes are invalid in ARM mode"));
3399 ignore_rest_of_line ();
3405 mapping_state (MAP_ARM);
3414 if (! emit_insn (& exp, nbytes))
3416 ignore_rest_of_line ();
3420 while (*input_line_pointer++ == ',');
3422 /* Put terminator back into stream. */
3423 input_line_pointer --;
3424 demand_empty_rest_of_line ();
3427 /* Parse a .rel31 directive. */
3430 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3437 if (*input_line_pointer == '1')
3438 highbit = 0x80000000;
3439 else if (*input_line_pointer != '0')
3440 as_bad (_("expected 0 or 1"));
3442 input_line_pointer++;
3443 if (*input_line_pointer != ',')
3444 as_bad (_("missing comma"));
3445 input_line_pointer++;
3447 #ifdef md_flush_pending_output
3448 md_flush_pending_output ();
3451 #ifdef md_cons_align
3455 mapping_state (MAP_DATA);
3460 md_number_to_chars (p, highbit, 4);
3461 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3462 BFD_RELOC_ARM_PREL31);
3464 demand_empty_rest_of_line ();
3467 /* Directives: AEABI stack-unwind tables. */
3469 /* Parse an unwind_fnstart directive. Simply records the current location. */
3472 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3474 demand_empty_rest_of_line ();
3475 if (unwind.proc_start)
3477 as_bad (_("duplicate .fnstart directive"));
3481 /* Mark the start of the function. */
3482 unwind.proc_start = expr_build_dot ();
3484 /* Reset the rest of the unwind info. */
3485 unwind.opcode_count = 0;
3486 unwind.table_entry = NULL;
3487 unwind.personality_routine = NULL;
3488 unwind.personality_index = -1;
3489 unwind.frame_size = 0;
3490 unwind.fp_offset = 0;
3491 unwind.fp_reg = REG_SP;
3493 unwind.sp_restored = 0;
3497 /* Parse a handlerdata directive. Creates the exception handling table entry
3498 for the function. */
3501 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3503 demand_empty_rest_of_line ();
3504 if (!unwind.proc_start)
3505 as_bad (MISSING_FNSTART);
3507 if (unwind.table_entry)
3508 as_bad (_("duplicate .handlerdata directive"));
3510 create_unwind_entry (1);
3513 /* Parse an unwind_fnend directive. Generates the index table entry. */
3516 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3521 unsigned int marked_pr_dependency;
3523 demand_empty_rest_of_line ();
3525 if (!unwind.proc_start)
3527 as_bad (_(".fnend directive without .fnstart"));
3531 /* Add eh table entry. */
3532 if (unwind.table_entry == NULL)
3533 val = create_unwind_entry (0);
3537 /* Add index table entry. This is two words. */
3538 start_unwind_section (unwind.saved_seg, 1);
3539 frag_align (2, 0, 0);
3540 record_alignment (now_seg, 2);
3542 ptr = frag_more (8);
3544 where = frag_now_fix () - 8;
3546 /* Self relative offset of the function start. */
3547 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3548 BFD_RELOC_ARM_PREL31);
3550 /* Indicate dependency on EHABI-defined personality routines to the
3551 linker, if it hasn't been done already. */
3552 marked_pr_dependency
3553 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3554 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3555 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3557 static const char *const name[] =
3559 "__aeabi_unwind_cpp_pr0",
3560 "__aeabi_unwind_cpp_pr1",
3561 "__aeabi_unwind_cpp_pr2"
3563 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3564 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3565 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3566 |= 1 << unwind.personality_index;
3570 /* Inline exception table entry. */
3571 md_number_to_chars (ptr + 4, val, 4);
3573 /* Self relative offset of the table entry. */
3574 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3575 BFD_RELOC_ARM_PREL31);
3577 /* Restore the original section. */
3578 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3580 unwind.proc_start = NULL;
3584 /* Parse an unwind_cantunwind directive. */
3587 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3589 demand_empty_rest_of_line ();
3590 if (!unwind.proc_start)
3591 as_bad (MISSING_FNSTART);
3593 if (unwind.personality_routine || unwind.personality_index != -1)
3594 as_bad (_("personality routine specified for cantunwind frame"));
3596 unwind.personality_index = -2;
3600 /* Parse a personalityindex directive. */
3603 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3607 if (!unwind.proc_start)
3608 as_bad (MISSING_FNSTART);
3610 if (unwind.personality_routine || unwind.personality_index != -1)
3611 as_bad (_("duplicate .personalityindex directive"));
3615 if (exp.X_op != O_constant
3616 || exp.X_add_number < 0 || exp.X_add_number > 15)
3618 as_bad (_("bad personality routine number"));
3619 ignore_rest_of_line ();
3623 unwind.personality_index = exp.X_add_number;
3625 demand_empty_rest_of_line ();
3629 /* Parse a personality directive. */
3632 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3636 if (!unwind.proc_start)
3637 as_bad (MISSING_FNSTART);
3639 if (unwind.personality_routine || unwind.personality_index != -1)
3640 as_bad (_("duplicate .personality directive"));
3642 name = input_line_pointer;
3643 c = get_symbol_end ();
3644 p = input_line_pointer;
3645 unwind.personality_routine = symbol_find_or_make (name);
3647 demand_empty_rest_of_line ();
3651 /* Parse a directive saving core registers. */
3654 s_arm_unwind_save_core (void)
3660 range = parse_reg_list (&input_line_pointer);
3663 as_bad (_("expected register list"));
3664 ignore_rest_of_line ();
3668 demand_empty_rest_of_line ();
3670 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3671 into .unwind_save {..., sp...}. We aren't bothered about the value of
3672 ip because it is clobbered by calls. */
3673 if (unwind.sp_restored && unwind.fp_reg == 12
3674 && (range & 0x3000) == 0x1000)
3676 unwind.opcode_count--;
3677 unwind.sp_restored = 0;
3678 range = (range | 0x2000) & ~0x1000;
3679 unwind.pending_offset = 0;
3685 /* See if we can use the short opcodes. These pop a block of up to 8
3686 registers starting with r4, plus maybe r14. */
3687 for (n = 0; n < 8; n++)
3689 /* Break at the first non-saved register. */
3690 if ((range & (1 << (n + 4))) == 0)
3693 /* See if there are any other bits set. */
3694 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3696 /* Use the long form. */
3697 op = 0x8000 | ((range >> 4) & 0xfff);
3698 add_unwind_opcode (op, 2);
3702 /* Use the short form. */
3704 op = 0xa8; /* Pop r14. */
3706 op = 0xa0; /* Do not pop r14. */
3708 add_unwind_opcode (op, 1);
3715 op = 0xb100 | (range & 0xf);
3716 add_unwind_opcode (op, 2);
3719 /* Record the number of bytes pushed. */
3720 for (n = 0; n < 16; n++)
3722 if (range & (1 << n))
3723 unwind.frame_size += 4;
3728 /* Parse a directive saving FPA registers. */
3731 s_arm_unwind_save_fpa (int reg)
3737 /* Get Number of registers to transfer. */
3738 if (skip_past_comma (&input_line_pointer) != FAIL)
3741 exp.X_op = O_illegal;
3743 if (exp.X_op != O_constant)
3745 as_bad (_("expected , <constant>"));
3746 ignore_rest_of_line ();
3750 num_regs = exp.X_add_number;
3752 if (num_regs < 1 || num_regs > 4)
3754 as_bad (_("number of registers must be in the range [1:4]"));
3755 ignore_rest_of_line ();
3759 demand_empty_rest_of_line ();
3764 op = 0xb4 | (num_regs - 1);
3765 add_unwind_opcode (op, 1);
3770 op = 0xc800 | (reg << 4) | (num_regs - 1);
3771 add_unwind_opcode (op, 2);
3773 unwind.frame_size += num_regs * 12;
3777 /* Parse a directive saving VFP registers for ARMv6 and above. */
3780 s_arm_unwind_save_vfp_armv6 (void)
3785 int num_vfpv3_regs = 0;
3786 int num_regs_below_16;
3788 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3791 as_bad (_("expected register list"));
3792 ignore_rest_of_line ();
3796 demand_empty_rest_of_line ();
3798 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3799 than FSTMX/FLDMX-style ones). */
3801 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3803 num_vfpv3_regs = count;
3804 else if (start + count > 16)
3805 num_vfpv3_regs = start + count - 16;
3807 if (num_vfpv3_regs > 0)
3809 int start_offset = start > 16 ? start - 16 : 0;
3810 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3811 add_unwind_opcode (op, 2);
3814 /* Generate opcode for registers numbered in the range 0 .. 15. */
3815 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3816 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3817 if (num_regs_below_16 > 0)
3819 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3820 add_unwind_opcode (op, 2);
3823 unwind.frame_size += count * 8;
3827 /* Parse a directive saving VFP registers for pre-ARMv6. */
3830 s_arm_unwind_save_vfp (void)
3836 count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D);
3839 as_bad (_("expected register list"));
3840 ignore_rest_of_line ();
3844 demand_empty_rest_of_line ();
3849 op = 0xb8 | (count - 1);
3850 add_unwind_opcode (op, 1);
3855 op = 0xb300 | (reg << 4) | (count - 1);
3856 add_unwind_opcode (op, 2);
3858 unwind.frame_size += count * 8 + 4;
3862 /* Parse a directive saving iWMMXt data registers. */
3865 s_arm_unwind_save_mmxwr (void)
3873 if (*input_line_pointer == '{')
3874 input_line_pointer++;
3878 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3882 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3887 as_tsktsk (_("register list not in ascending order"));
3890 if (*input_line_pointer == '-')
3892 input_line_pointer++;
3893 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3896 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3899 else if (reg >= hi_reg)
3901 as_bad (_("bad register range"));
3904 for (; reg < hi_reg; reg++)
3908 while (skip_past_comma (&input_line_pointer) != FAIL);
3910 if (*input_line_pointer == '}')
3911 input_line_pointer++;
3913 demand_empty_rest_of_line ();
3915 /* Generate any deferred opcodes because we're going to be looking at
3917 flush_pending_unwind ();
3919 for (i = 0; i < 16; i++)
3921 if (mask & (1 << i))
3922 unwind.frame_size += 8;
3925 /* Attempt to combine with a previous opcode. We do this because gcc
3926 likes to output separate unwind directives for a single block of
3928 if (unwind.opcode_count > 0)
3930 i = unwind.opcodes[unwind.opcode_count - 1];
3931 if ((i & 0xf8) == 0xc0)
3934 /* Only merge if the blocks are contiguous. */
3937 if ((mask & 0xfe00) == (1 << 9))
3939 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3940 unwind.opcode_count--;
3943 else if (i == 6 && unwind.opcode_count >= 2)
3945 i = unwind.opcodes[unwind.opcode_count - 2];
3949 op = 0xffff << (reg - 1);
3951 && ((mask & op) == (1u << (reg - 1))))
3953 op = (1 << (reg + i + 1)) - 1;
3954 op &= ~((1 << reg) - 1);
3956 unwind.opcode_count -= 2;
3963 /* We want to generate opcodes in the order the registers have been
3964 saved, ie. descending order. */
3965 for (reg = 15; reg >= -1; reg--)
3967 /* Save registers in blocks. */
3969 || !(mask & (1 << reg)))
3971 /* We found an unsaved reg. Generate opcodes to save the
3978 op = 0xc0 | (hi_reg - 10);
3979 add_unwind_opcode (op, 1);
3984 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3985 add_unwind_opcode (op, 2);
3994 ignore_rest_of_line ();
3998 s_arm_unwind_save_mmxwcg (void)
4005 if (*input_line_pointer == '{')
4006 input_line_pointer++;
4010 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4014 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4020 as_tsktsk (_("register list not in ascending order"));
4023 if (*input_line_pointer == '-')
4025 input_line_pointer++;
4026 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4029 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4032 else if (reg >= hi_reg)
4034 as_bad (_("bad register range"));
4037 for (; reg < hi_reg; reg++)
4041 while (skip_past_comma (&input_line_pointer) != FAIL);
4043 if (*input_line_pointer == '}')
4044 input_line_pointer++;
4046 demand_empty_rest_of_line ();
4048 /* Generate any deferred opcodes because we're going to be looking at
4050 flush_pending_unwind ();
4052 for (reg = 0; reg < 16; reg++)
4054 if (mask & (1 << reg))
4055 unwind.frame_size += 4;
4058 add_unwind_opcode (op, 2);
4061 ignore_rest_of_line ();
4065 /* Parse an unwind_save directive.
4066 If the argument is non-zero, this is a .vsave directive. */
4069 s_arm_unwind_save (int arch_v6)
4072 struct reg_entry *reg;
4073 bfd_boolean had_brace = FALSE;
4075 if (!unwind.proc_start)
4076 as_bad (MISSING_FNSTART);
4078 /* Figure out what sort of save we have. */
4079 peek = input_line_pointer;
4087 reg = arm_reg_parse_multi (&peek);
4091 as_bad (_("register expected"));
4092 ignore_rest_of_line ();
4101 as_bad (_("FPA .unwind_save does not take a register list"));
4102 ignore_rest_of_line ();
4105 input_line_pointer = peek;
4106 s_arm_unwind_save_fpa (reg->number);
4109 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
4112 s_arm_unwind_save_vfp_armv6 ();
4114 s_arm_unwind_save_vfp ();
4116 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4117 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4120 as_bad (_(".unwind_save does not support this kind of register"));
4121 ignore_rest_of_line ();
4126 /* Parse an unwind_movsp directive. */
4129 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4135 if (!unwind.proc_start)
4136 as_bad (MISSING_FNSTART);
4138 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4141 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4142 ignore_rest_of_line ();
4146 /* Optional constant. */
4147 if (skip_past_comma (&input_line_pointer) != FAIL)
4149 if (immediate_for_directive (&offset) == FAIL)
4155 demand_empty_rest_of_line ();
4157 if (reg == REG_SP || reg == REG_PC)
4159 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4163 if (unwind.fp_reg != REG_SP)
4164 as_bad (_("unexpected .unwind_movsp directive"));
4166 /* Generate opcode to restore the value. */
4168 add_unwind_opcode (op, 1);
4170 /* Record the information for later. */
4171 unwind.fp_reg = reg;
4172 unwind.fp_offset = unwind.frame_size - offset;
4173 unwind.sp_restored = 1;
4176 /* Parse an unwind_pad directive. */
4179 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4183 if (!unwind.proc_start)
4184 as_bad (MISSING_FNSTART);
4186 if (immediate_for_directive (&offset) == FAIL)
4191 as_bad (_("stack increment must be multiple of 4"));
4192 ignore_rest_of_line ();
4196 /* Don't generate any opcodes, just record the details for later. */
4197 unwind.frame_size += offset;
4198 unwind.pending_offset += offset;
4200 demand_empty_rest_of_line ();
4203 /* Parse an unwind_setfp directive. */
4206 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4212 if (!unwind.proc_start)
4213 as_bad (MISSING_FNSTART);
4215 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4216 if (skip_past_comma (&input_line_pointer) == FAIL)
4219 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4221 if (fp_reg == FAIL || sp_reg == FAIL)
4223 as_bad (_("expected <reg>, <reg>"));
4224 ignore_rest_of_line ();
4228 /* Optional constant. */
4229 if (skip_past_comma (&input_line_pointer) != FAIL)
4231 if (immediate_for_directive (&offset) == FAIL)
4237 demand_empty_rest_of_line ();
4239 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4241 as_bad (_("register must be either sp or set by a previous"
4242 "unwind_movsp directive"));
4246 /* Don't generate any opcodes, just record the information for later. */
4247 unwind.fp_reg = fp_reg;
4249 if (sp_reg == REG_SP)
4250 unwind.fp_offset = unwind.frame_size - offset;
4252 unwind.fp_offset -= offset;
4255 /* Parse an unwind_raw directive. */
4258 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4261 /* This is an arbitrary limit. */
4262 unsigned char op[16];
4265 if (!unwind.proc_start)
4266 as_bad (MISSING_FNSTART);
4269 if (exp.X_op == O_constant
4270 && skip_past_comma (&input_line_pointer) != FAIL)
4272 unwind.frame_size += exp.X_add_number;
4276 exp.X_op = O_illegal;
4278 if (exp.X_op != O_constant)
4280 as_bad (_("expected <offset>, <opcode>"));
4281 ignore_rest_of_line ();
4287 /* Parse the opcode. */
4292 as_bad (_("unwind opcode too long"));
4293 ignore_rest_of_line ();
4295 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4297 as_bad (_("invalid unwind opcode"));
4298 ignore_rest_of_line ();
4301 op[count++] = exp.X_add_number;
4303 /* Parse the next byte. */
4304 if (skip_past_comma (&input_line_pointer) == FAIL)
4310 /* Add the opcode bytes in reverse order. */
4312 add_unwind_opcode (op[count], 1);
4314 demand_empty_rest_of_line ();
4318 /* Parse a .eabi_attribute directive. */
4321 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4323 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4325 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4326 attributes_set_explicitly[tag] = 1;
4329 /* Emit a tls fix for the symbol. */
4332 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4336 #ifdef md_flush_pending_output
4337 md_flush_pending_output ();
4340 #ifdef md_cons_align
4344 /* Since we're just labelling the code, there's no need to define a
4347 p = obstack_next_free (&frchain_now->frch_obstack);
4348 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4349 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4350 : BFD_RELOC_ARM_TLS_DESCSEQ);
4352 #endif /* OBJ_ELF */
4354 static void s_arm_arch (int);
4355 static void s_arm_object_arch (int);
4356 static void s_arm_cpu (int);
4357 static void s_arm_fpu (int);
4358 static void s_arm_arch_extension (int);
4363 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4370 if (exp.X_op == O_symbol)
4371 exp.X_op = O_secrel;
4373 emit_expr (&exp, 4);
4375 while (*input_line_pointer++ == ',');
4377 input_line_pointer--;
4378 demand_empty_rest_of_line ();
4382 /* This table describes all the machine specific pseudo-ops the assembler
4383 has to support. The fields are:
4384 pseudo-op name without dot
4385 function to call to execute this pseudo-op
4386 Integer arg to pass to the function. */
4388 const pseudo_typeS md_pseudo_table[] =
4390 /* Never called because '.req' does not start a line. */
4391 { "req", s_req, 0 },
4392 /* Following two are likewise never called. */
4395 { "unreq", s_unreq, 0 },
4396 { "bss", s_bss, 0 },
4397 { "align", s_align, 0 },
4398 { "arm", s_arm, 0 },
4399 { "thumb", s_thumb, 0 },
4400 { "code", s_code, 0 },
4401 { "force_thumb", s_force_thumb, 0 },
4402 { "thumb_func", s_thumb_func, 0 },
4403 { "thumb_set", s_thumb_set, 0 },
4404 { "even", s_even, 0 },
4405 { "ltorg", s_ltorg, 0 },
4406 { "pool", s_ltorg, 0 },
4407 { "syntax", s_syntax, 0 },
4408 { "cpu", s_arm_cpu, 0 },
4409 { "arch", s_arm_arch, 0 },
4410 { "object_arch", s_arm_object_arch, 0 },
4411 { "fpu", s_arm_fpu, 0 },
4412 { "arch_extension", s_arm_arch_extension, 0 },
4414 { "word", s_arm_elf_cons, 4 },
4415 { "long", s_arm_elf_cons, 4 },
4416 { "inst.n", s_arm_elf_inst, 2 },
4417 { "inst.w", s_arm_elf_inst, 4 },
4418 { "inst", s_arm_elf_inst, 0 },
4419 { "rel31", s_arm_rel31, 0 },
4420 { "fnstart", s_arm_unwind_fnstart, 0 },
4421 { "fnend", s_arm_unwind_fnend, 0 },
4422 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4423 { "personality", s_arm_unwind_personality, 0 },
4424 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4425 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4426 { "save", s_arm_unwind_save, 0 },
4427 { "vsave", s_arm_unwind_save, 1 },
4428 { "movsp", s_arm_unwind_movsp, 0 },
4429 { "pad", s_arm_unwind_pad, 0 },
4430 { "setfp", s_arm_unwind_setfp, 0 },
4431 { "unwind_raw", s_arm_unwind_raw, 0 },
4432 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4433 { "tlsdescseq", s_arm_tls_descseq, 0 },
4437 /* These are used for dwarf. */
4441 /* These are used for dwarf2. */
4442 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4443 { "loc", dwarf2_directive_loc, 0 },
4444 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4446 { "extend", float_cons, 'x' },
4447 { "ldouble", float_cons, 'x' },
4448 { "packed", float_cons, 'p' },
4450 {"secrel32", pe_directive_secrel, 0},
4455 /* Parser functions used exclusively in instruction operands. */
4457 /* Generic immediate-value read function for use in insn parsing.
4458 STR points to the beginning of the immediate (the leading #);
4459 VAL receives the value; if the value is outside [MIN, MAX]
4460 issue an error. PREFIX_OPT is true if the immediate prefix is
4464 parse_immediate (char **str, int *val, int min, int max,
4465 bfd_boolean prefix_opt)
4468 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4469 if (exp.X_op != O_constant)
4471 inst.error = _("constant expression required");
4475 if (exp.X_add_number < min || exp.X_add_number > max)
4477 inst.error = _("immediate value out of range");
4481 *val = exp.X_add_number;
4485 /* Less-generic immediate-value read function with the possibility of loading a
4486 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4487 instructions. Puts the result directly in inst.operands[i]. */
4490 parse_big_immediate (char **str, int i)
4495 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4497 if (exp.X_op == O_constant)
4499 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4500 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4501 O_constant. We have to be careful not to break compilation for
4502 32-bit X_add_number, though. */
4503 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
4505 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4506 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4507 inst.operands[i].regisimm = 1;
4510 else if (exp.X_op == O_big
4511 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
4513 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4515 /* Bignums have their least significant bits in
4516 generic_bignum[0]. Make sure we put 32 bits in imm and
4517 32 bits in reg, in a (hopefully) portable way. */
4518 gas_assert (parts != 0);
4520 /* Make sure that the number is not too big.
4521 PR 11972: Bignums can now be sign-extended to the
4522 size of a .octa so check that the out of range bits
4523 are all zero or all one. */
4524 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4526 LITTLENUM_TYPE m = -1;
4528 if (generic_bignum[parts * 2] != 0
4529 && generic_bignum[parts * 2] != m)
4532 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4533 if (generic_bignum[j] != generic_bignum[j-1])
4537 inst.operands[i].imm = 0;
4538 for (j = 0; j < parts; j++, idx++)
4539 inst.operands[i].imm |= generic_bignum[idx]
4540 << (LITTLENUM_NUMBER_OF_BITS * j);
4541 inst.operands[i].reg = 0;
4542 for (j = 0; j < parts; j++, idx++)
4543 inst.operands[i].reg |= generic_bignum[idx]
4544 << (LITTLENUM_NUMBER_OF_BITS * j);
4545 inst.operands[i].regisimm = 1;
4555 /* Returns the pseudo-register number of an FPA immediate constant,
4556 or FAIL if there isn't a valid constant here. */
4559 parse_fpa_immediate (char ** str)
4561 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4567 /* First try and match exact strings, this is to guarantee
4568 that some formats will work even for cross assembly. */
4570 for (i = 0; fp_const[i]; i++)
4572 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4576 *str += strlen (fp_const[i]);
4577 if (is_end_of_line[(unsigned char) **str])
4583 /* Just because we didn't get a match doesn't mean that the constant
4584 isn't valid, just that it is in a format that we don't
4585 automatically recognize. Try parsing it with the standard
4586 expression routines. */
4588 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4590 /* Look for a raw floating point number. */
4591 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4592 && is_end_of_line[(unsigned char) *save_in])
4594 for (i = 0; i < NUM_FLOAT_VALS; i++)
4596 for (j = 0; j < MAX_LITTLENUMS; j++)
4598 if (words[j] != fp_values[i][j])
4602 if (j == MAX_LITTLENUMS)
4610 /* Try and parse a more complex expression, this will probably fail
4611 unless the code uses a floating point prefix (eg "0f"). */
4612 save_in = input_line_pointer;
4613 input_line_pointer = *str;
4614 if (expression (&exp) == absolute_section
4615 && exp.X_op == O_big
4616 && exp.X_add_number < 0)
4618 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4620 if (gen_to_words (words, 5, (long) 15) == 0)
4622 for (i = 0; i < NUM_FLOAT_VALS; i++)
4624 for (j = 0; j < MAX_LITTLENUMS; j++)
4626 if (words[j] != fp_values[i][j])
4630 if (j == MAX_LITTLENUMS)
4632 *str = input_line_pointer;
4633 input_line_pointer = save_in;
4640 *str = input_line_pointer;
4641 input_line_pointer = save_in;
4642 inst.error = _("invalid FPA immediate expression");
4646 /* Returns 1 if a number has "quarter-precision" float format
4647 0baBbbbbbc defgh000 00000000 00000000. */
4650 is_quarter_float (unsigned imm)
4652 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4653 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4656 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4657 0baBbbbbbc defgh000 00000000 00000000.
4658 The zero and minus-zero cases need special handling, since they can't be
4659 encoded in the "quarter-precision" float format, but can nonetheless be
4660 loaded as integer constants. */
4663 parse_qfloat_immediate (char **ccp, int *immed)
4667 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4668 int found_fpchar = 0;
4670 skip_past_char (&str, '#');
4672 /* We must not accidentally parse an integer as a floating-point number. Make
4673 sure that the value we parse is not an integer by checking for special
4674 characters '.' or 'e'.
4675 FIXME: This is a horrible hack, but doing better is tricky because type
4676 information isn't in a very usable state at parse time. */
4678 skip_whitespace (fpnum);
4680 if (strncmp (fpnum, "0x", 2) == 0)
4684 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4685 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4695 if ((str = atof_ieee (str, 's', words)) != NULL)
4697 unsigned fpword = 0;
4700 /* Our FP word must be 32 bits (single-precision FP). */
4701 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4703 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4707 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4720 /* Shift operands. */
4723 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4726 struct asm_shift_name
4729 enum shift_kind kind;
4732 /* Third argument to parse_shift. */
4733 enum parse_shift_mode
4735 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4736 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4737 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4738 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4739 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4742 /* Parse a <shift> specifier on an ARM data processing instruction.
4743 This has three forms:
4745 (LSL|LSR|ASL|ASR|ROR) Rs
4746 (LSL|LSR|ASL|ASR|ROR) #imm
4749 Note that ASL is assimilated to LSL in the instruction encoding, and
4750 RRX to ROR #0 (which cannot be written as such). */
4753 parse_shift (char **str, int i, enum parse_shift_mode mode)
4755 const struct asm_shift_name *shift_name;
4756 enum shift_kind shift;
4761 for (p = *str; ISALPHA (*p); p++)
4766 inst.error = _("shift expression expected");
4770 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4773 if (shift_name == NULL)
4775 inst.error = _("shift expression expected");
4779 shift = shift_name->kind;
4783 case NO_SHIFT_RESTRICT:
4784 case SHIFT_IMMEDIATE: break;
4786 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4787 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4789 inst.error = _("'LSL' or 'ASR' required");
4794 case SHIFT_LSL_IMMEDIATE:
4795 if (shift != SHIFT_LSL)
4797 inst.error = _("'LSL' required");
4802 case SHIFT_ASR_IMMEDIATE:
4803 if (shift != SHIFT_ASR)
4805 inst.error = _("'ASR' required");
4813 if (shift != SHIFT_RRX)
4815 /* Whitespace can appear here if the next thing is a bare digit. */
4816 skip_whitespace (p);
4818 if (mode == NO_SHIFT_RESTRICT
4819 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4821 inst.operands[i].imm = reg;
4822 inst.operands[i].immisreg = 1;
4824 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4827 inst.operands[i].shift_kind = shift;
4828 inst.operands[i].shifted = 1;
4833 /* Parse a <shifter_operand> for an ARM data processing instruction:
4836 #<immediate>, <rotate>
4840 where <shift> is defined by parse_shift above, and <rotate> is a
4841 multiple of 2 between 0 and 30. Validation of immediate operands
4842 is deferred to md_apply_fix. */
4845 parse_shifter_operand (char **str, int i)
4850 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4852 inst.operands[i].reg = value;
4853 inst.operands[i].isreg = 1;
4855 /* parse_shift will override this if appropriate */
4856 inst.reloc.exp.X_op = O_constant;
4857 inst.reloc.exp.X_add_number = 0;
4859 if (skip_past_comma (str) == FAIL)
4862 /* Shift operation on register. */
4863 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4866 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4869 if (skip_past_comma (str) == SUCCESS)
4871 /* #x, y -- ie explicit rotation by Y. */
4872 if (my_get_expression (&exp, str, GE_NO_PREFIX))
4875 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4877 inst.error = _("constant expression expected");
4881 value = exp.X_add_number;
4882 if (value < 0 || value > 30 || value % 2 != 0)
4884 inst.error = _("invalid rotation");
4887 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4889 inst.error = _("invalid constant");
4893 /* Encode as specified. */
4894 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
4898 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4899 inst.reloc.pc_rel = 0;
4903 /* Group relocation information. Each entry in the table contains the
4904 textual name of the relocation as may appear in assembler source
4905 and must end with a colon.
4906 Along with this textual name are the relocation codes to be used if
4907 the corresponding instruction is an ALU instruction (ADD or SUB only),
4908 an LDR, an LDRS, or an LDC. */
4910 struct group_reloc_table_entry
4921 /* Varieties of non-ALU group relocation. */
4928 static struct group_reloc_table_entry group_reloc_table[] =
4929 { /* Program counter relative: */
4931 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4936 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4937 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4938 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4939 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4941 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4946 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4947 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4948 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4949 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4951 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4952 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4953 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4954 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4955 /* Section base relative */
4957 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4962 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4963 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4964 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4965 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4967 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4972 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4973 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4974 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4975 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4977 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4978 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4979 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4980 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4982 /* Given the address of a pointer pointing to the textual name of a group
4983 relocation as may appear in assembler source, attempt to find its details
4984 in group_reloc_table. The pointer will be updated to the character after
4985 the trailing colon. On failure, FAIL will be returned; SUCCESS
4986 otherwise. On success, *entry will be updated to point at the relevant
4987 group_reloc_table entry. */
4990 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4993 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4995 int length = strlen (group_reloc_table[i].name);
4997 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4998 && (*str)[length] == ':')
5000 *out = &group_reloc_table[i];
5001 *str += (length + 1);
5009 /* Parse a <shifter_operand> for an ARM data processing instruction
5010 (as for parse_shifter_operand) where group relocations are allowed:
5013 #<immediate>, <rotate>
5014 #:<group_reloc>:<expression>
5018 where <group_reloc> is one of the strings defined in group_reloc_table.
5019 The hashes are optional.
5021 Everything else is as for parse_shifter_operand. */
5023 static parse_operand_result
5024 parse_shifter_operand_group_reloc (char **str, int i)
5026 /* Determine if we have the sequence of characters #: or just :
5027 coming next. If we do, then we check for a group relocation.
5028 If we don't, punt the whole lot to parse_shifter_operand. */
5030 if (((*str)[0] == '#' && (*str)[1] == ':')
5031 || (*str)[0] == ':')
5033 struct group_reloc_table_entry *entry;
5035 if ((*str)[0] == '#')
5040 /* Try to parse a group relocation. Anything else is an error. */
5041 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5043 inst.error = _("unknown group relocation");
5044 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5047 /* We now have the group relocation table entry corresponding to
5048 the name in the assembler source. Next, we parse the expression. */
5049 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5050 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5052 /* Record the relocation type (always the ALU variant here). */
5053 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
5054 gas_assert (inst.reloc.type != 0);
5056 return PARSE_OPERAND_SUCCESS;
5059 return parse_shifter_operand (str, i) == SUCCESS
5060 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5062 /* Never reached. */
5065 /* Parse a Neon alignment expression. Information is written to
5066 inst.operands[i]. We assume the initial ':' has been skipped.
5068 align .imm = align << 8, .immisalign=1, .preind=0 */
5069 static parse_operand_result
5070 parse_neon_alignment (char **str, int i)
5075 my_get_expression (&exp, &p, GE_NO_PREFIX);
5077 if (exp.X_op != O_constant)
5079 inst.error = _("alignment must be constant");
5080 return PARSE_OPERAND_FAIL;
5083 inst.operands[i].imm = exp.X_add_number << 8;
5084 inst.operands[i].immisalign = 1;
5085 /* Alignments are not pre-indexes. */
5086 inst.operands[i].preind = 0;
5089 return PARSE_OPERAND_SUCCESS;
5092 /* Parse all forms of an ARM address expression. Information is written
5093 to inst.operands[i] and/or inst.reloc.
5095 Preindexed addressing (.preind=1):
5097 [Rn, #offset] .reg=Rn .reloc.exp=offset
5098 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5099 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5100 .shift_kind=shift .reloc.exp=shift_imm
5102 These three may have a trailing ! which causes .writeback to be set also.
5104 Postindexed addressing (.postind=1, .writeback=1):
5106 [Rn], #offset .reg=Rn .reloc.exp=offset
5107 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5108 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5109 .shift_kind=shift .reloc.exp=shift_imm
5111 Unindexed addressing (.preind=0, .postind=0):
5113 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5117 [Rn]{!} shorthand for [Rn,#0]{!}
5118 =immediate .isreg=0 .reloc.exp=immediate
5119 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
5121 It is the caller's responsibility to check for addressing modes not
5122 supported by the instruction, and to set inst.reloc.type. */
5124 static parse_operand_result
5125 parse_address_main (char **str, int i, int group_relocations,
5126 group_reloc_type group_type)
5131 if (skip_past_char (&p, '[') == FAIL)
5133 if (skip_past_char (&p, '=') == FAIL)
5135 /* Bare address - translate to PC-relative offset. */
5136 inst.reloc.pc_rel = 1;
5137 inst.operands[i].reg = REG_PC;
5138 inst.operands[i].isreg = 1;
5139 inst.operands[i].preind = 1;
5141 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
5143 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5144 return PARSE_OPERAND_FAIL;
5147 return PARSE_OPERAND_SUCCESS;
5150 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5152 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5153 return PARSE_OPERAND_FAIL;
5155 inst.operands[i].reg = reg;
5156 inst.operands[i].isreg = 1;
5158 if (skip_past_comma (&p) == SUCCESS)
5160 inst.operands[i].preind = 1;
5163 else if (*p == '-') p++, inst.operands[i].negative = 1;
5165 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5167 inst.operands[i].imm = reg;
5168 inst.operands[i].immisreg = 1;
5170 if (skip_past_comma (&p) == SUCCESS)
5171 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5172 return PARSE_OPERAND_FAIL;
5174 else if (skip_past_char (&p, ':') == SUCCESS)
5176 /* FIXME: '@' should be used here, but it's filtered out by generic
5177 code before we get to see it here. This may be subject to
5179 parse_operand_result result = parse_neon_alignment (&p, i);
5181 if (result != PARSE_OPERAND_SUCCESS)
5186 if (inst.operands[i].negative)
5188 inst.operands[i].negative = 0;
5192 if (group_relocations
5193 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5195 struct group_reloc_table_entry *entry;
5197 /* Skip over the #: or : sequence. */
5203 /* Try to parse a group relocation. Anything else is an
5205 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5207 inst.error = _("unknown group relocation");
5208 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5211 /* We now have the group relocation table entry corresponding to
5212 the name in the assembler source. Next, we parse the
5214 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5215 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5217 /* Record the relocation type. */
5221 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5225 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5229 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5236 if (inst.reloc.type == 0)
5238 inst.error = _("this group relocation is not allowed on this instruction");
5239 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5245 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5246 return PARSE_OPERAND_FAIL;
5247 /* If the offset is 0, find out if it's a +0 or -0. */
5248 if (inst.reloc.exp.X_op == O_constant
5249 && inst.reloc.exp.X_add_number == 0)
5251 skip_whitespace (q);
5255 skip_whitespace (q);
5258 inst.operands[i].negative = 1;
5263 else if (skip_past_char (&p, ':') == SUCCESS)
5265 /* FIXME: '@' should be used here, but it's filtered out by generic code
5266 before we get to see it here. This may be subject to change. */
5267 parse_operand_result result = parse_neon_alignment (&p, i);
5269 if (result != PARSE_OPERAND_SUCCESS)
5273 if (skip_past_char (&p, ']') == FAIL)
5275 inst.error = _("']' expected");
5276 return PARSE_OPERAND_FAIL;
5279 if (skip_past_char (&p, '!') == SUCCESS)
5280 inst.operands[i].writeback = 1;
5282 else if (skip_past_comma (&p) == SUCCESS)
5284 if (skip_past_char (&p, '{') == SUCCESS)
5286 /* [Rn], {expr} - unindexed, with option */
5287 if (parse_immediate (&p, &inst.operands[i].imm,
5288 0, 255, TRUE) == FAIL)
5289 return PARSE_OPERAND_FAIL;
5291 if (skip_past_char (&p, '}') == FAIL)
5293 inst.error = _("'}' expected at end of 'option' field");
5294 return PARSE_OPERAND_FAIL;
5296 if (inst.operands[i].preind)
5298 inst.error = _("cannot combine index with option");
5299 return PARSE_OPERAND_FAIL;
5302 return PARSE_OPERAND_SUCCESS;
5306 inst.operands[i].postind = 1;
5307 inst.operands[i].writeback = 1;
5309 if (inst.operands[i].preind)
5311 inst.error = _("cannot combine pre- and post-indexing");
5312 return PARSE_OPERAND_FAIL;
5316 else if (*p == '-') p++, inst.operands[i].negative = 1;
5318 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5320 /* We might be using the immediate for alignment already. If we
5321 are, OR the register number into the low-order bits. */
5322 if (inst.operands[i].immisalign)
5323 inst.operands[i].imm |= reg;
5325 inst.operands[i].imm = reg;
5326 inst.operands[i].immisreg = 1;
5328 if (skip_past_comma (&p) == SUCCESS)
5329 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5330 return PARSE_OPERAND_FAIL;
5335 if (inst.operands[i].negative)
5337 inst.operands[i].negative = 0;
5340 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5341 return PARSE_OPERAND_FAIL;
5342 /* If the offset is 0, find out if it's a +0 or -0. */
5343 if (inst.reloc.exp.X_op == O_constant
5344 && inst.reloc.exp.X_add_number == 0)
5346 skip_whitespace (q);
5350 skip_whitespace (q);
5353 inst.operands[i].negative = 1;
5359 /* If at this point neither .preind nor .postind is set, we have a
5360 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5361 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5363 inst.operands[i].preind = 1;
5364 inst.reloc.exp.X_op = O_constant;
5365 inst.reloc.exp.X_add_number = 0;
5368 return PARSE_OPERAND_SUCCESS;
5372 parse_address (char **str, int i)
5374 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5378 static parse_operand_result
5379 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5381 return parse_address_main (str, i, 1, type);
5384 /* Parse an operand for a MOVW or MOVT instruction. */
5386 parse_half (char **str)
5391 skip_past_char (&p, '#');
5392 if (strncasecmp (p, ":lower16:", 9) == 0)
5393 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5394 else if (strncasecmp (p, ":upper16:", 9) == 0)
5395 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5397 if (inst.reloc.type != BFD_RELOC_UNUSED)
5400 skip_whitespace (p);
5403 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5406 if (inst.reloc.type == BFD_RELOC_UNUSED)
5408 if (inst.reloc.exp.X_op != O_constant)
5410 inst.error = _("constant expression expected");
5413 if (inst.reloc.exp.X_add_number < 0
5414 || inst.reloc.exp.X_add_number > 0xffff)
5416 inst.error = _("immediate value out of range");
5424 /* Miscellaneous. */
5426 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5427 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5429 parse_psr (char **str, bfd_boolean lhs)
5432 unsigned long psr_field;
5433 const struct asm_psr *psr;
5435 bfd_boolean is_apsr = FALSE;
5436 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
5438 /* PR gas/12698: If the user has specified -march=all then m_profile will
5439 be TRUE, but we want to ignore it in this case as we are building for any
5440 CPU type, including non-m variants. */
5441 if (selected_cpu.core == arm_arch_any.core)
5444 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5445 feature for ease of use and backwards compatibility. */
5447 if (strncasecmp (p, "SPSR", 4) == 0)
5450 goto unsupported_psr;
5452 psr_field = SPSR_BIT;
5454 else if (strncasecmp (p, "CPSR", 4) == 0)
5457 goto unsupported_psr;
5461 else if (strncasecmp (p, "APSR", 4) == 0)
5463 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5464 and ARMv7-R architecture CPUs. */
5473 while (ISALNUM (*p) || *p == '_');
5475 if (strncasecmp (start, "iapsr", 5) == 0
5476 || strncasecmp (start, "eapsr", 5) == 0
5477 || strncasecmp (start, "xpsr", 4) == 0
5478 || strncasecmp (start, "psr", 3) == 0)
5479 p = start + strcspn (start, "rR") + 1;
5481 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5487 /* If APSR is being written, a bitfield may be specified. Note that
5488 APSR itself is handled above. */
5489 if (psr->field <= 3)
5491 psr_field = psr->field;
5497 /* M-profile MSR instructions have the mask field set to "10", except
5498 *PSR variants which modify APSR, which may use a different mask (and
5499 have been handled already). Do that by setting the PSR_f field
5501 return psr->field | (lhs ? PSR_f : 0);
5504 goto unsupported_psr;
5510 /* A suffix follows. */
5516 while (ISALNUM (*p) || *p == '_');
5520 /* APSR uses a notation for bits, rather than fields. */
5521 unsigned int nzcvq_bits = 0;
5522 unsigned int g_bit = 0;
5525 for (bit = start; bit != p; bit++)
5527 switch (TOLOWER (*bit))
5530 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5534 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5538 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5542 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5546 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5550 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5554 inst.error = _("unexpected bit specified after APSR");
5559 if (nzcvq_bits == 0x1f)
5564 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5566 inst.error = _("selected processor does not "
5567 "support DSP extension");
5574 if ((nzcvq_bits & 0x20) != 0
5575 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5576 || (g_bit & 0x2) != 0)
5578 inst.error = _("bad bitmask specified after APSR");
5584 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5589 psr_field |= psr->field;
5595 goto error; /* Garbage after "[CS]PSR". */
5597 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5598 is deprecated, but allow it anyway. */
5602 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5605 else if (!m_profile)
5606 /* These bits are never right for M-profile devices: don't set them
5607 (only code paths which read/write APSR reach here). */
5608 psr_field |= (PSR_c | PSR_f);
5614 inst.error = _("selected processor does not support requested special "
5615 "purpose register");
5619 inst.error = _("flag for {c}psr instruction expected");
5623 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5624 value suitable for splatting into the AIF field of the instruction. */
5627 parse_cps_flags (char **str)
5636 case '\0': case ',':
5639 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5640 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5641 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5644 inst.error = _("unrecognized CPS flag");
5649 if (saw_a_flag == 0)
5651 inst.error = _("missing CPS flags");
5659 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5660 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5663 parse_endian_specifier (char **str)
5668 if (strncasecmp (s, "BE", 2))
5670 else if (strncasecmp (s, "LE", 2))
5674 inst.error = _("valid endian specifiers are be or le");
5678 if (ISALNUM (s[2]) || s[2] == '_')
5680 inst.error = _("valid endian specifiers are be or le");
5685 return little_endian;
5688 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5689 value suitable for poking into the rotate field of an sxt or sxta
5690 instruction, or FAIL on error. */
5693 parse_ror (char **str)
5698 if (strncasecmp (s, "ROR", 3) == 0)
5702 inst.error = _("missing rotation field after comma");
5706 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5711 case 0: *str = s; return 0x0;
5712 case 8: *str = s; return 0x1;
5713 case 16: *str = s; return 0x2;
5714 case 24: *str = s; return 0x3;
5717 inst.error = _("rotation can only be 0, 8, 16, or 24");
5722 /* Parse a conditional code (from conds[] below). The value returned is in the
5723 range 0 .. 14, or FAIL. */
5725 parse_cond (char **str)
5728 const struct asm_cond *c;
5730 /* Condition codes are always 2 characters, so matching up to
5731 3 characters is sufficient. */
5736 while (ISALPHA (*q) && n < 3)
5738 cond[n] = TOLOWER (*q);
5743 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
5746 inst.error = _("condition required");
5754 /* Parse an option for a barrier instruction. Returns the encoding for the
5757 parse_barrier (char **str)
5760 const struct asm_barrier_opt *o;
5763 while (ISALPHA (*q))
5766 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5775 /* Parse the operands of a table branch instruction. Similar to a memory
5778 parse_tb (char **str)
5783 if (skip_past_char (&p, '[') == FAIL)
5785 inst.error = _("'[' expected");
5789 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5791 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5794 inst.operands[0].reg = reg;
5796 if (skip_past_comma (&p) == FAIL)
5798 inst.error = _("',' expected");
5802 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5804 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5807 inst.operands[0].imm = reg;
5809 if (skip_past_comma (&p) == SUCCESS)
5811 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5813 if (inst.reloc.exp.X_add_number != 1)
5815 inst.error = _("invalid shift");
5818 inst.operands[0].shifted = 1;
5821 if (skip_past_char (&p, ']') == FAIL)
5823 inst.error = _("']' expected");
5830 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5831 information on the types the operands can take and how they are encoded.
5832 Up to four operands may be read; this function handles setting the
5833 ".present" field for each read operand itself.
5834 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5835 else returns FAIL. */
5838 parse_neon_mov (char **str, int *which_operand)
5840 int i = *which_operand, val;
5841 enum arm_reg_type rtype;
5843 struct neon_type_el optype;
5845 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5847 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5848 inst.operands[i].reg = val;
5849 inst.operands[i].isscalar = 1;
5850 inst.operands[i].vectype = optype;
5851 inst.operands[i++].present = 1;
5853 if (skip_past_comma (&ptr) == FAIL)
5856 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5859 inst.operands[i].reg = val;
5860 inst.operands[i].isreg = 1;
5861 inst.operands[i].present = 1;
5863 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5866 /* Cases 0, 1, 2, 3, 5 (D only). */
5867 if (skip_past_comma (&ptr) == FAIL)
5870 inst.operands[i].reg = val;
5871 inst.operands[i].isreg = 1;
5872 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5873 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5874 inst.operands[i].isvec = 1;
5875 inst.operands[i].vectype = optype;
5876 inst.operands[i++].present = 1;
5878 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5880 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5881 Case 13: VMOV <Sd>, <Rm> */
5882 inst.operands[i].reg = val;
5883 inst.operands[i].isreg = 1;
5884 inst.operands[i].present = 1;
5886 if (rtype == REG_TYPE_NQ)
5888 first_error (_("can't use Neon quad register here"));
5891 else if (rtype != REG_TYPE_VFS)
5894 if (skip_past_comma (&ptr) == FAIL)
5896 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5898 inst.operands[i].reg = val;
5899 inst.operands[i].isreg = 1;
5900 inst.operands[i].present = 1;
5903 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5906 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5907 Case 1: VMOV<c><q> <Dd>, <Dm>
5908 Case 8: VMOV.F32 <Sd>, <Sm>
5909 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5911 inst.operands[i].reg = val;
5912 inst.operands[i].isreg = 1;
5913 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5914 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5915 inst.operands[i].isvec = 1;
5916 inst.operands[i].vectype = optype;
5917 inst.operands[i].present = 1;
5919 if (skip_past_comma (&ptr) == SUCCESS)
5924 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5927 inst.operands[i].reg = val;
5928 inst.operands[i].isreg = 1;
5929 inst.operands[i++].present = 1;
5931 if (skip_past_comma (&ptr) == FAIL)
5934 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5937 inst.operands[i].reg = val;
5938 inst.operands[i].isreg = 1;
5939 inst.operands[i].present = 1;
5942 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5943 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5944 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5945 Case 10: VMOV.F32 <Sd>, #<imm>
5946 Case 11: VMOV.F64 <Dd>, #<imm> */
5947 inst.operands[i].immisfloat = 1;
5948 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5949 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5950 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5954 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5958 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5961 inst.operands[i].reg = val;
5962 inst.operands[i].isreg = 1;
5963 inst.operands[i++].present = 1;
5965 if (skip_past_comma (&ptr) == FAIL)
5968 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5970 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5971 inst.operands[i].reg = val;
5972 inst.operands[i].isscalar = 1;
5973 inst.operands[i].present = 1;
5974 inst.operands[i].vectype = optype;
5976 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5978 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5979 inst.operands[i].reg = val;
5980 inst.operands[i].isreg = 1;
5981 inst.operands[i++].present = 1;
5983 if (skip_past_comma (&ptr) == FAIL)
5986 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5989 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5993 inst.operands[i].reg = val;
5994 inst.operands[i].isreg = 1;
5995 inst.operands[i].isvec = 1;
5996 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5997 inst.operands[i].vectype = optype;
5998 inst.operands[i].present = 1;
6000 if (rtype == REG_TYPE_VFS)
6004 if (skip_past_comma (&ptr) == FAIL)
6006 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6009 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6012 inst.operands[i].reg = val;
6013 inst.operands[i].isreg = 1;
6014 inst.operands[i].isvec = 1;
6015 inst.operands[i].issingle = 1;
6016 inst.operands[i].vectype = optype;
6017 inst.operands[i].present = 1;
6020 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6024 inst.operands[i].reg = val;
6025 inst.operands[i].isreg = 1;
6026 inst.operands[i].isvec = 1;
6027 inst.operands[i].issingle = 1;
6028 inst.operands[i].vectype = optype;
6029 inst.operands[i].present = 1;
6034 first_error (_("parse error"));
6038 /* Successfully parsed the operands. Update args. */
6044 first_error (_("expected comma"));
6048 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6052 /* Use this macro when the operand constraints are different
6053 for ARM and THUMB (e.g. ldrd). */
6054 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6055 ((arm_operand) | ((thumb_operand) << 16))
6057 /* Matcher codes for parse_operands. */
6058 enum operand_parse_code
6060 OP_stop, /* end of line */
6062 OP_RR, /* ARM register */
6063 OP_RRnpc, /* ARM register, not r15 */
6064 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6065 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6066 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6067 optional trailing ! */
6068 OP_RRw, /* ARM register, not r15, optional trailing ! */
6069 OP_RCP, /* Coprocessor number */
6070 OP_RCN, /* Coprocessor register */
6071 OP_RF, /* FPA register */
6072 OP_RVS, /* VFP single precision register */
6073 OP_RVD, /* VFP double precision register (0..15) */
6074 OP_RND, /* Neon double precision register (0..31) */
6075 OP_RNQ, /* Neon quad precision register */
6076 OP_RVSD, /* VFP single or double precision register */
6077 OP_RNDQ, /* Neon double or quad precision register */
6078 OP_RNSDQ, /* Neon single, double or quad precision register */
6079 OP_RNSC, /* Neon scalar D[X] */
6080 OP_RVC, /* VFP control register */
6081 OP_RMF, /* Maverick F register */
6082 OP_RMD, /* Maverick D register */
6083 OP_RMFX, /* Maverick FX register */
6084 OP_RMDX, /* Maverick DX register */
6085 OP_RMAX, /* Maverick AX register */
6086 OP_RMDS, /* Maverick DSPSC register */
6087 OP_RIWR, /* iWMMXt wR register */
6088 OP_RIWC, /* iWMMXt wC register */
6089 OP_RIWG, /* iWMMXt wCG register */
6090 OP_RXA, /* XScale accumulator register */
6092 OP_REGLST, /* ARM register list */
6093 OP_VRSLST, /* VFP single-precision register list */
6094 OP_VRDLST, /* VFP double-precision register list */
6095 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
6096 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6097 OP_NSTRLST, /* Neon element/structure list */
6099 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
6100 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
6101 OP_RR_RNSC, /* ARM reg or Neon scalar. */
6102 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
6103 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6104 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6105 OP_VMOV, /* Neon VMOV operands. */
6106 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
6107 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
6108 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
6110 OP_I0, /* immediate zero */
6111 OP_I7, /* immediate value 0 .. 7 */
6112 OP_I15, /* 0 .. 15 */
6113 OP_I16, /* 1 .. 16 */
6114 OP_I16z, /* 0 .. 16 */
6115 OP_I31, /* 0 .. 31 */
6116 OP_I31w, /* 0 .. 31, optional trailing ! */
6117 OP_I32, /* 1 .. 32 */
6118 OP_I32z, /* 0 .. 32 */
6119 OP_I63, /* 0 .. 63 */
6120 OP_I63s, /* -64 .. 63 */
6121 OP_I64, /* 1 .. 64 */
6122 OP_I64z, /* 0 .. 64 */
6123 OP_I255, /* 0 .. 255 */
6125 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6126 OP_I7b, /* 0 .. 7 */
6127 OP_I15b, /* 0 .. 15 */
6128 OP_I31b, /* 0 .. 31 */
6130 OP_SH, /* shifter operand */
6131 OP_SHG, /* shifter operand with possible group relocation */
6132 OP_ADDR, /* Memory address expression (any mode) */
6133 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6134 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6135 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
6136 OP_EXP, /* arbitrary expression */
6137 OP_EXPi, /* same, with optional immediate prefix */
6138 OP_EXPr, /* same, with optional relocation suffix */
6139 OP_HALF, /* 0 .. 65535 or low/high reloc. */
6141 OP_CPSF, /* CPS flags */
6142 OP_ENDI, /* Endianness specifier */
6143 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6144 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
6145 OP_COND, /* conditional code */
6146 OP_TB, /* Table branch. */
6148 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6150 OP_RRnpc_I0, /* ARM register or literal 0 */
6151 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6152 OP_RR_EXi, /* ARM register or expression with imm prefix */
6153 OP_RF_IF, /* FPA register or immediate */
6154 OP_RIWR_RIWC, /* iWMMXt R or C reg */
6155 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
6157 /* Optional operands. */
6158 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6159 OP_oI31b, /* 0 .. 31 */
6160 OP_oI32b, /* 1 .. 32 */
6161 OP_oI32z, /* 0 .. 32 */
6162 OP_oIffffb, /* 0 .. 65535 */
6163 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6165 OP_oRR, /* ARM register */
6166 OP_oRRnpc, /* ARM register, not the PC */
6167 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
6168 OP_oRRw, /* ARM register, not r15, optional trailing ! */
6169 OP_oRND, /* Optional Neon double precision register */
6170 OP_oRNQ, /* Optional Neon quad precision register */
6171 OP_oRNDQ, /* Optional Neon double or quad precision register */
6172 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
6173 OP_oSHll, /* LSL immediate */
6174 OP_oSHar, /* ASR immediate */
6175 OP_oSHllar, /* LSL or ASR immediate */
6176 OP_oROR, /* ROR 0/8/16/24 */
6177 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
6179 /* Some pre-defined mixed (ARM/THUMB) operands. */
6180 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6181 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6182 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6184 OP_FIRST_OPTIONAL = OP_oI7b
6187 /* Generic instruction operand parser. This does no encoding and no
6188 semantic validation; it merely squirrels values away in the inst
6189 structure. Returns SUCCESS or FAIL depending on whether the
6190 specified grammar matched. */
6192 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
6194 unsigned const int *upat = pattern;
6195 char *backtrack_pos = 0;
6196 const char *backtrack_error = 0;
6197 int i, val, backtrack_index = 0;
6198 enum arm_reg_type rtype;
6199 parse_operand_result result;
6200 unsigned int op_parse_code;
6202 #define po_char_or_fail(chr) \
6205 if (skip_past_char (&str, chr) == FAIL) \
6210 #define po_reg_or_fail(regtype) \
6213 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6214 & inst.operands[i].vectype); \
6217 first_error (_(reg_expected_msgs[regtype])); \
6220 inst.operands[i].reg = val; \
6221 inst.operands[i].isreg = 1; \
6222 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6223 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6224 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6225 || rtype == REG_TYPE_VFD \
6226 || rtype == REG_TYPE_NQ); \
6230 #define po_reg_or_goto(regtype, label) \
6233 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6234 & inst.operands[i].vectype); \
6238 inst.operands[i].reg = val; \
6239 inst.operands[i].isreg = 1; \
6240 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6241 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6242 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6243 || rtype == REG_TYPE_VFD \
6244 || rtype == REG_TYPE_NQ); \
6248 #define po_imm_or_fail(min, max, popt) \
6251 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6253 inst.operands[i].imm = val; \
6257 #define po_scalar_or_goto(elsz, label) \
6260 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6263 inst.operands[i].reg = val; \
6264 inst.operands[i].isscalar = 1; \
6268 #define po_misc_or_fail(expr) \
6276 #define po_misc_or_fail_no_backtrack(expr) \
6280 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6281 backtrack_pos = 0; \
6282 if (result != PARSE_OPERAND_SUCCESS) \
6287 #define po_barrier_or_imm(str) \
6290 val = parse_barrier (&str); \
6293 if (ISALPHA (*str)) \
6300 if ((inst.instruction & 0xf0) == 0x60 \
6303 /* ISB can only take SY as an option. */ \
6304 inst.error = _("invalid barrier type"); \
6311 skip_whitespace (str);
6313 for (i = 0; upat[i] != OP_stop; i++)
6315 op_parse_code = upat[i];
6316 if (op_parse_code >= 1<<16)
6317 op_parse_code = thumb ? (op_parse_code >> 16)
6318 : (op_parse_code & ((1<<16)-1));
6320 if (op_parse_code >= OP_FIRST_OPTIONAL)
6322 /* Remember where we are in case we need to backtrack. */
6323 gas_assert (!backtrack_pos);
6324 backtrack_pos = str;
6325 backtrack_error = inst.error;
6326 backtrack_index = i;
6329 if (i > 0 && (i > 1 || inst.operands[0].present))
6330 po_char_or_fail (',');
6332 switch (op_parse_code)
6340 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6341 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6342 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6343 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6344 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6345 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6347 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6349 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6351 /* Also accept generic coprocessor regs for unknown registers. */
6353 po_reg_or_fail (REG_TYPE_CN);
6355 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6356 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6357 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6358 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6359 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6360 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6361 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6362 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6363 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6364 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6366 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6368 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6369 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6371 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6373 /* Neon scalar. Using an element size of 8 means that some invalid
6374 scalars are accepted here, so deal with those in later code. */
6375 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6379 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6382 po_imm_or_fail (0, 0, TRUE);
6387 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6392 po_scalar_or_goto (8, try_rr);
6395 po_reg_or_fail (REG_TYPE_RN);
6401 po_scalar_or_goto (8, try_nsdq);
6404 po_reg_or_fail (REG_TYPE_NSDQ);
6410 po_scalar_or_goto (8, try_ndq);
6413 po_reg_or_fail (REG_TYPE_NDQ);
6419 po_scalar_or_goto (8, try_vfd);
6422 po_reg_or_fail (REG_TYPE_VFD);
6427 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6428 not careful then bad things might happen. */
6429 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6434 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6437 /* There's a possibility of getting a 64-bit immediate here, so
6438 we need special handling. */
6439 if (parse_big_immediate (&str, i) == FAIL)
6441 inst.error = _("immediate value is out of range");
6449 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6452 po_imm_or_fail (0, 63, TRUE);
6457 po_char_or_fail ('[');
6458 po_reg_or_fail (REG_TYPE_RN);
6459 po_char_or_fail (']');
6465 po_reg_or_fail (REG_TYPE_RN);
6466 if (skip_past_char (&str, '!') == SUCCESS)
6467 inst.operands[i].writeback = 1;
6471 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6472 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6473 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6474 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6475 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6476 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6477 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6478 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6479 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6480 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6481 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6482 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6484 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6486 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6487 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6489 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6490 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6491 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
6492 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6494 /* Immediate variants */
6496 po_char_or_fail ('{');
6497 po_imm_or_fail (0, 255, TRUE);
6498 po_char_or_fail ('}');
6502 /* The expression parser chokes on a trailing !, so we have
6503 to find it first and zap it. */
6506 while (*s && *s != ',')
6511 inst.operands[i].writeback = 1;
6513 po_imm_or_fail (0, 31, TRUE);
6521 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6526 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6531 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6533 if (inst.reloc.exp.X_op == O_symbol)
6535 val = parse_reloc (&str);
6538 inst.error = _("unrecognized relocation suffix");
6541 else if (val != BFD_RELOC_UNUSED)
6543 inst.operands[i].imm = val;
6544 inst.operands[i].hasreloc = 1;
6549 /* Operand for MOVW or MOVT. */
6551 po_misc_or_fail (parse_half (&str));
6554 /* Register or expression. */
6555 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6556 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6558 /* Register or immediate. */
6559 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6560 I0: po_imm_or_fail (0, 0, FALSE); break;
6562 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6564 if (!is_immediate_prefix (*str))
6567 val = parse_fpa_immediate (&str);
6570 /* FPA immediates are encoded as registers 8-15.
6571 parse_fpa_immediate has already applied the offset. */
6572 inst.operands[i].reg = val;
6573 inst.operands[i].isreg = 1;
6576 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6577 I32z: po_imm_or_fail (0, 32, FALSE); break;
6579 /* Two kinds of register. */
6582 struct reg_entry *rege = arm_reg_parse_multi (&str);
6584 || (rege->type != REG_TYPE_MMXWR
6585 && rege->type != REG_TYPE_MMXWC
6586 && rege->type != REG_TYPE_MMXWCG))
6588 inst.error = _("iWMMXt data or control register expected");
6591 inst.operands[i].reg = rege->number;
6592 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6598 struct reg_entry *rege = arm_reg_parse_multi (&str);
6600 || (rege->type != REG_TYPE_MMXWC
6601 && rege->type != REG_TYPE_MMXWCG))
6603 inst.error = _("iWMMXt control register expected");
6606 inst.operands[i].reg = rege->number;
6607 inst.operands[i].isreg = 1;
6612 case OP_CPSF: val = parse_cps_flags (&str); break;
6613 case OP_ENDI: val = parse_endian_specifier (&str); break;
6614 case OP_oROR: val = parse_ror (&str); break;
6615 case OP_COND: val = parse_cond (&str); break;
6616 case OP_oBARRIER_I15:
6617 po_barrier_or_imm (str); break;
6619 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6625 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6626 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6628 inst.error = _("Banked registers are not available with this "
6634 val = parse_psr (&str, op_parse_code == OP_wPSR);
6638 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6641 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6643 if (strncasecmp (str, "APSR_", 5) == 0)
6650 case 'c': found = (found & 1) ? 16 : found | 1; break;
6651 case 'n': found = (found & 2) ? 16 : found | 2; break;
6652 case 'z': found = (found & 4) ? 16 : found | 4; break;
6653 case 'v': found = (found & 8) ? 16 : found | 8; break;
6654 default: found = 16;
6658 inst.operands[i].isvec = 1;
6659 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6660 inst.operands[i].reg = REG_PC;
6667 po_misc_or_fail (parse_tb (&str));
6670 /* Register lists. */
6672 val = parse_reg_list (&str);
6675 inst.operands[1].writeback = 1;
6681 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6685 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6689 /* Allow Q registers too. */
6690 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6695 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6697 inst.operands[i].issingle = 1;
6702 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6707 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6708 &inst.operands[i].vectype);
6711 /* Addressing modes */
6713 po_misc_or_fail (parse_address (&str, i));
6717 po_misc_or_fail_no_backtrack (
6718 parse_address_group_reloc (&str, i, GROUP_LDR));
6722 po_misc_or_fail_no_backtrack (
6723 parse_address_group_reloc (&str, i, GROUP_LDRS));
6727 po_misc_or_fail_no_backtrack (
6728 parse_address_group_reloc (&str, i, GROUP_LDC));
6732 po_misc_or_fail (parse_shifter_operand (&str, i));
6736 po_misc_or_fail_no_backtrack (
6737 parse_shifter_operand_group_reloc (&str, i));
6741 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6745 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6749 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6753 as_fatal (_("unhandled operand code %d"), op_parse_code);
6756 /* Various value-based sanity checks and shared operations. We
6757 do not signal immediate failures for the register constraints;
6758 this allows a syntax error to take precedence. */
6759 switch (op_parse_code)
6767 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6768 inst.error = BAD_PC;
6773 if (inst.operands[i].isreg)
6775 if (inst.operands[i].reg == REG_PC)
6776 inst.error = BAD_PC;
6777 else if (inst.operands[i].reg == REG_SP)
6778 inst.error = BAD_SP;
6783 if (inst.operands[i].isreg
6784 && inst.operands[i].reg == REG_PC
6785 && (inst.operands[i].writeback || thumb))
6786 inst.error = BAD_PC;
6795 case OP_oBARRIER_I15:
6804 inst.operands[i].imm = val;
6811 /* If we get here, this operand was successfully parsed. */
6812 inst.operands[i].present = 1;
6816 inst.error = BAD_ARGS;
6821 /* The parse routine should already have set inst.error, but set a
6822 default here just in case. */
6824 inst.error = _("syntax error");
6828 /* Do not backtrack over a trailing optional argument that
6829 absorbed some text. We will only fail again, with the
6830 'garbage following instruction' error message, which is
6831 probably less helpful than the current one. */
6832 if (backtrack_index == i && backtrack_pos != str
6833 && upat[i+1] == OP_stop)
6836 inst.error = _("syntax error");
6840 /* Try again, skipping the optional argument at backtrack_pos. */
6841 str = backtrack_pos;
6842 inst.error = backtrack_error;
6843 inst.operands[backtrack_index].present = 0;
6844 i = backtrack_index;
6848 /* Check that we have parsed all the arguments. */
6849 if (*str != '\0' && !inst.error)
6850 inst.error = _("garbage following instruction");
6852 return inst.error ? FAIL : SUCCESS;
6855 #undef po_char_or_fail
6856 #undef po_reg_or_fail
6857 #undef po_reg_or_goto
6858 #undef po_imm_or_fail
6859 #undef po_scalar_or_fail
6860 #undef po_barrier_or_imm
6862 /* Shorthand macro for instruction encoding functions issuing errors. */
6863 #define constraint(expr, err) \
6874 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6875 instructions are unpredictable if these registers are used. This
6876 is the BadReg predicate in ARM's Thumb-2 documentation. */
6877 #define reject_bad_reg(reg) \
6879 if (reg == REG_SP || reg == REG_PC) \
6881 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6886 /* If REG is R13 (the stack pointer), warn that its use is
6888 #define warn_deprecated_sp(reg) \
6890 if (warn_on_deprecated && reg == REG_SP) \
6891 as_warn (_("use of r13 is deprecated")); \
6894 /* Functions for operand encoding. ARM, then Thumb. */
6896 #define rotate_left(v, n) (v << n | v >> (32 - n))
6898 /* If VAL can be encoded in the immediate field of an ARM instruction,
6899 return the encoded form. Otherwise, return FAIL. */
6902 encode_arm_immediate (unsigned int val)
6906 for (i = 0; i < 32; i += 2)
6907 if ((a = rotate_left (val, i)) <= 0xff)
6908 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6913 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6914 return the encoded form. Otherwise, return FAIL. */
6916 encode_thumb32_immediate (unsigned int val)
6923 for (i = 1; i <= 24; i++)
6926 if ((val & ~(0xff << i)) == 0)
6927 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6931 if (val == ((a << 16) | a))
6933 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6937 if (val == ((a << 16) | a))
6938 return 0x200 | (a >> 8);
6942 /* Encode a VFP SP or DP register number into inst.instruction. */
6945 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6947 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6950 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6953 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6956 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6961 first_error (_("D register out of range for selected VFP version"));
6969 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6973 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6977 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6981 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6985 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6989 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6997 /* Encode a <shift> in an ARM-format instruction. The immediate,
6998 if any, is handled by md_apply_fix. */
7000 encode_arm_shift (int i)
7002 if (inst.operands[i].shift_kind == SHIFT_RRX)
7003 inst.instruction |= SHIFT_ROR << 5;
7006 inst.instruction |= inst.operands[i].shift_kind << 5;
7007 if (inst.operands[i].immisreg)
7009 inst.instruction |= SHIFT_BY_REG;
7010 inst.instruction |= inst.operands[i].imm << 8;
7013 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7018 encode_arm_shifter_operand (int i)
7020 if (inst.operands[i].isreg)
7022 inst.instruction |= inst.operands[i].reg;
7023 encode_arm_shift (i);
7027 inst.instruction |= INST_IMMEDIATE;
7028 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7029 inst.instruction |= inst.operands[i].imm;
7033 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
7035 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
7037 gas_assert (inst.operands[i].isreg);
7038 inst.instruction |= inst.operands[i].reg << 16;
7040 if (inst.operands[i].preind)
7044 inst.error = _("instruction does not accept preindexed addressing");
7047 inst.instruction |= PRE_INDEX;
7048 if (inst.operands[i].writeback)
7049 inst.instruction |= WRITE_BACK;
7052 else if (inst.operands[i].postind)
7054 gas_assert (inst.operands[i].writeback);
7056 inst.instruction |= WRITE_BACK;
7058 else /* unindexed - only for coprocessor */
7060 inst.error = _("instruction does not accept unindexed addressing");
7064 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7065 && (((inst.instruction & 0x000f0000) >> 16)
7066 == ((inst.instruction & 0x0000f000) >> 12)))
7067 as_warn ((inst.instruction & LOAD_BIT)
7068 ? _("destination register same as write-back base")
7069 : _("source register same as write-back base"));
7072 /* inst.operands[i] was set up by parse_address. Encode it into an
7073 ARM-format mode 2 load or store instruction. If is_t is true,
7074 reject forms that cannot be used with a T instruction (i.e. not
7077 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
7079 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7081 encode_arm_addr_mode_common (i, is_t);
7083 if (inst.operands[i].immisreg)
7085 constraint ((inst.operands[i].imm == REG_PC
7086 || (is_pc && inst.operands[i].writeback)),
7088 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7089 inst.instruction |= inst.operands[i].imm;
7090 if (!inst.operands[i].negative)
7091 inst.instruction |= INDEX_UP;
7092 if (inst.operands[i].shifted)
7094 if (inst.operands[i].shift_kind == SHIFT_RRX)
7095 inst.instruction |= SHIFT_ROR << 5;
7098 inst.instruction |= inst.operands[i].shift_kind << 5;
7099 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7103 else /* immediate offset in inst.reloc */
7105 if (is_pc && !inst.reloc.pc_rel)
7107 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
7109 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7110 cannot use PC in addressing.
7111 PC cannot be used in writeback addressing, either. */
7112 constraint ((is_t || inst.operands[i].writeback),
7115 /* Use of PC in str is deprecated for ARMv7. */
7116 if (warn_on_deprecated
7118 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7119 as_warn (_("use of PC in this instruction is deprecated"));
7122 if (inst.reloc.type == BFD_RELOC_UNUSED)
7124 /* Prefer + for zero encoded value. */
7125 if (!inst.operands[i].negative)
7126 inst.instruction |= INDEX_UP;
7127 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7132 /* inst.operands[i] was set up by parse_address. Encode it into an
7133 ARM-format mode 3 load or store instruction. Reject forms that
7134 cannot be used with such instructions. If is_t is true, reject
7135 forms that cannot be used with a T instruction (i.e. not
7138 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
7140 if (inst.operands[i].immisreg && inst.operands[i].shifted)
7142 inst.error = _("instruction does not accept scaled register index");
7146 encode_arm_addr_mode_common (i, is_t);
7148 if (inst.operands[i].immisreg)
7150 constraint ((inst.operands[i].imm == REG_PC
7151 || inst.operands[i].reg == REG_PC),
7153 inst.instruction |= inst.operands[i].imm;
7154 if (!inst.operands[i].negative)
7155 inst.instruction |= INDEX_UP;
7157 else /* immediate offset in inst.reloc */
7159 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7160 && inst.operands[i].writeback),
7162 inst.instruction |= HWOFFSET_IMM;
7163 if (inst.reloc.type == BFD_RELOC_UNUSED)
7165 /* Prefer + for zero encoded value. */
7166 if (!inst.operands[i].negative)
7167 inst.instruction |= INDEX_UP;
7169 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7174 /* inst.operands[i] was set up by parse_address. Encode it into an
7175 ARM-format instruction. Reject all forms which cannot be encoded
7176 into a coprocessor load/store instruction. If wb_ok is false,
7177 reject use of writeback; if unind_ok is false, reject use of
7178 unindexed addressing. If reloc_override is not 0, use it instead
7179 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7180 (in which case it is preserved). */
7183 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
7185 inst.instruction |= inst.operands[i].reg << 16;
7187 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
7189 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
7191 gas_assert (!inst.operands[i].writeback);
7194 inst.error = _("instruction does not support unindexed addressing");
7197 inst.instruction |= inst.operands[i].imm;
7198 inst.instruction |= INDEX_UP;
7202 if (inst.operands[i].preind)
7203 inst.instruction |= PRE_INDEX;
7205 if (inst.operands[i].writeback)
7207 if (inst.operands[i].reg == REG_PC)
7209 inst.error = _("pc may not be used with write-back");
7214 inst.error = _("instruction does not support writeback");
7217 inst.instruction |= WRITE_BACK;
7221 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
7222 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7223 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7224 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7227 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7229 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7232 /* Prefer + for zero encoded value. */
7233 if (!inst.operands[i].negative)
7234 inst.instruction |= INDEX_UP;
7239 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
7240 Determine whether it can be performed with a move instruction; if
7241 it can, convert inst.instruction to that move instruction and
7242 return TRUE; if it can't, convert inst.instruction to a literal-pool
7243 load and return FALSE. If this is not a valid thing to do in the
7244 current context, set inst.error and return TRUE.
7246 inst.operands[i] describes the destination register. */
7249 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7254 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7258 if ((inst.instruction & tbit) == 0)
7260 inst.error = _("invalid pseudo operation");
7263 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
7265 inst.error = _("constant expression expected");
7268 if (inst.reloc.exp.X_op == O_constant)
7272 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
7274 /* This can be done with a mov(1) instruction. */
7275 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7276 inst.instruction |= inst.reloc.exp.X_add_number;
7282 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7285 /* This can be done with a mov instruction. */
7286 inst.instruction &= LITERAL_MASK;
7287 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7288 inst.instruction |= value & 0xfff;
7292 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7295 /* This can be done with a mvn instruction. */
7296 inst.instruction &= LITERAL_MASK;
7297 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7298 inst.instruction |= value & 0xfff;
7304 if (add_to_lit_pool () == FAIL)
7306 inst.error = _("literal pool insertion failed");
7309 inst.operands[1].reg = REG_PC;
7310 inst.operands[1].isreg = 1;
7311 inst.operands[1].preind = 1;
7312 inst.reloc.pc_rel = 1;
7313 inst.reloc.type = (thumb_p
7314 ? BFD_RELOC_ARM_THUMB_OFFSET
7316 ? BFD_RELOC_ARM_HWLITERAL
7317 : BFD_RELOC_ARM_LITERAL));
7321 /* Functions for instruction encoding, sorted by sub-architecture.
7322 First some generics; their names are taken from the conventional
7323 bit positions for register arguments in ARM format instructions. */
7333 inst.instruction |= inst.operands[0].reg << 12;
7339 inst.instruction |= inst.operands[0].reg << 12;
7340 inst.instruction |= inst.operands[1].reg;
7346 inst.instruction |= inst.operands[0].reg << 12;
7347 inst.instruction |= inst.operands[1].reg << 16;
7353 inst.instruction |= inst.operands[0].reg << 16;
7354 inst.instruction |= inst.operands[1].reg << 12;
7360 unsigned Rn = inst.operands[2].reg;
7361 /* Enforce restrictions on SWP instruction. */
7362 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
7364 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7365 _("Rn must not overlap other operands"));
7367 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7368 if (warn_on_deprecated
7369 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7370 as_warn (_("swp{b} use is deprecated for this architecture"));
7373 inst.instruction |= inst.operands[0].reg << 12;
7374 inst.instruction |= inst.operands[1].reg;
7375 inst.instruction |= Rn << 16;
7381 inst.instruction |= inst.operands[0].reg << 12;
7382 inst.instruction |= inst.operands[1].reg << 16;
7383 inst.instruction |= inst.operands[2].reg;
7389 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7390 constraint (((inst.reloc.exp.X_op != O_constant
7391 && inst.reloc.exp.X_op != O_illegal)
7392 || inst.reloc.exp.X_add_number != 0),
7394 inst.instruction |= inst.operands[0].reg;
7395 inst.instruction |= inst.operands[1].reg << 12;
7396 inst.instruction |= inst.operands[2].reg << 16;
7402 inst.instruction |= inst.operands[0].imm;
7408 inst.instruction |= inst.operands[0].reg << 12;
7409 encode_arm_cp_address (1, TRUE, TRUE, 0);
7412 /* ARM instructions, in alphabetical order by function name (except
7413 that wrapper functions appear immediately after the function they
7416 /* This is a pseudo-op of the form "adr rd, label" to be converted
7417 into a relative address of the form "add rd, pc, #label-.-8". */
7422 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7424 /* Frag hacking will turn this into a sub instruction if the offset turns
7425 out to be negative. */
7426 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7427 inst.reloc.pc_rel = 1;
7428 inst.reloc.exp.X_add_number -= 8;
7431 /* This is a pseudo-op of the form "adrl rd, label" to be converted
7432 into a relative address of the form:
7433 add rd, pc, #low(label-.-8)"
7434 add rd, rd, #high(label-.-8)" */
7439 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7441 /* Frag hacking will turn this into a sub instruction if the offset turns
7442 out to be negative. */
7443 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
7444 inst.reloc.pc_rel = 1;
7445 inst.size = INSN_SIZE * 2;
7446 inst.reloc.exp.X_add_number -= 8;
7452 if (!inst.operands[1].present)
7453 inst.operands[1].reg = inst.operands[0].reg;
7454 inst.instruction |= inst.operands[0].reg << 12;
7455 inst.instruction |= inst.operands[1].reg << 16;
7456 encode_arm_shifter_operand (2);
7462 if (inst.operands[0].present)
7464 constraint ((inst.instruction & 0xf0) != 0x40
7465 && inst.operands[0].imm > 0xf
7466 && inst.operands[0].imm < 0x0,
7467 _("bad barrier type"));
7468 inst.instruction |= inst.operands[0].imm;
7471 inst.instruction |= 0xf;
7477 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7478 constraint (msb > 32, _("bit-field extends past end of register"));
7479 /* The instruction encoding stores the LSB and MSB,
7480 not the LSB and width. */
7481 inst.instruction |= inst.operands[0].reg << 12;
7482 inst.instruction |= inst.operands[1].imm << 7;
7483 inst.instruction |= (msb - 1) << 16;
7491 /* #0 in second position is alternative syntax for bfc, which is
7492 the same instruction but with REG_PC in the Rm field. */
7493 if (!inst.operands[1].isreg)
7494 inst.operands[1].reg = REG_PC;
7496 msb = inst.operands[2].imm + inst.operands[3].imm;
7497 constraint (msb > 32, _("bit-field extends past end of register"));
7498 /* The instruction encoding stores the LSB and MSB,
7499 not the LSB and width. */
7500 inst.instruction |= inst.operands[0].reg << 12;
7501 inst.instruction |= inst.operands[1].reg;
7502 inst.instruction |= inst.operands[2].imm << 7;
7503 inst.instruction |= (msb - 1) << 16;
7509 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7510 _("bit-field extends past end of register"));
7511 inst.instruction |= inst.operands[0].reg << 12;
7512 inst.instruction |= inst.operands[1].reg;
7513 inst.instruction |= inst.operands[2].imm << 7;
7514 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7517 /* ARM V5 breakpoint instruction (argument parse)
7518 BKPT <16 bit unsigned immediate>
7519 Instruction is not conditional.
7520 The bit pattern given in insns[] has the COND_ALWAYS condition,
7521 and it is an error if the caller tried to override that. */
7526 /* Top 12 of 16 bits to bits 19:8. */
7527 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
7529 /* Bottom 4 of 16 bits to bits 3:0. */
7530 inst.instruction |= inst.operands[0].imm & 0xf;
7534 encode_branch (int default_reloc)
7536 if (inst.operands[0].hasreloc)
7538 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7539 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7540 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7541 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7542 ? BFD_RELOC_ARM_PLT32
7543 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
7546 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
7547 inst.reloc.pc_rel = 1;
7554 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7555 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7558 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7565 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7567 if (inst.cond == COND_ALWAYS)
7568 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7570 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7574 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7577 /* ARM V5 branch-link-exchange instruction (argument parse)
7578 BLX <target_addr> ie BLX(1)
7579 BLX{<condition>} <Rm> ie BLX(2)
7580 Unfortunately, there are two different opcodes for this mnemonic.
7581 So, the insns[].value is not used, and the code here zaps values
7582 into inst.instruction.
7583 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
7588 if (inst.operands[0].isreg)
7590 /* Arg is a register; the opcode provided by insns[] is correct.
7591 It is not illegal to do "blx pc", just useless. */
7592 if (inst.operands[0].reg == REG_PC)
7593 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
7595 inst.instruction |= inst.operands[0].reg;
7599 /* Arg is an address; this instruction cannot be executed
7600 conditionally, and the opcode must be adjusted.
7601 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7602 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
7603 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7604 inst.instruction = 0xfa000000;
7605 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
7612 bfd_boolean want_reloc;
7614 if (inst.operands[0].reg == REG_PC)
7615 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
7617 inst.instruction |= inst.operands[0].reg;
7618 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7619 it is for ARMv4t or earlier. */
7620 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7621 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7625 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
7630 inst.reloc.type = BFD_RELOC_ARM_V4BX;
7634 /* ARM v5TEJ. Jump to Jazelle code. */
7639 if (inst.operands[0].reg == REG_PC)
7640 as_tsktsk (_("use of r15 in bxj is not really useful"));
7642 inst.instruction |= inst.operands[0].reg;
7645 /* Co-processor data operation:
7646 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7647 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7651 inst.instruction |= inst.operands[0].reg << 8;
7652 inst.instruction |= inst.operands[1].imm << 20;
7653 inst.instruction |= inst.operands[2].reg << 12;
7654 inst.instruction |= inst.operands[3].reg << 16;
7655 inst.instruction |= inst.operands[4].reg;
7656 inst.instruction |= inst.operands[5].imm << 5;
7662 inst.instruction |= inst.operands[0].reg << 16;
7663 encode_arm_shifter_operand (1);
7666 /* Transfer between coprocessor and ARM registers.
7667 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7672 No special properties. */
7679 Rd = inst.operands[2].reg;
7682 if (inst.instruction == 0xee000010
7683 || inst.instruction == 0xfe000010)
7685 reject_bad_reg (Rd);
7688 constraint (Rd == REG_SP, BAD_SP);
7693 if (inst.instruction == 0xe000010)
7694 constraint (Rd == REG_PC, BAD_PC);
7698 inst.instruction |= inst.operands[0].reg << 8;
7699 inst.instruction |= inst.operands[1].imm << 21;
7700 inst.instruction |= Rd << 12;
7701 inst.instruction |= inst.operands[3].reg << 16;
7702 inst.instruction |= inst.operands[4].reg;
7703 inst.instruction |= inst.operands[5].imm << 5;
7706 /* Transfer between coprocessor register and pair of ARM registers.
7707 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7712 Two XScale instructions are special cases of these:
7714 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7715 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
7717 Result unpredictable if Rd or Rn is R15. */
7724 Rd = inst.operands[2].reg;
7725 Rn = inst.operands[3].reg;
7729 reject_bad_reg (Rd);
7730 reject_bad_reg (Rn);
7734 constraint (Rd == REG_PC, BAD_PC);
7735 constraint (Rn == REG_PC, BAD_PC);
7738 inst.instruction |= inst.operands[0].reg << 8;
7739 inst.instruction |= inst.operands[1].imm << 4;
7740 inst.instruction |= Rd << 12;
7741 inst.instruction |= Rn << 16;
7742 inst.instruction |= inst.operands[4].reg;
7748 inst.instruction |= inst.operands[0].imm << 6;
7749 if (inst.operands[1].present)
7751 inst.instruction |= CPSI_MMOD;
7752 inst.instruction |= inst.operands[1].imm;
7759 inst.instruction |= inst.operands[0].imm;
7765 unsigned Rd, Rn, Rm;
7767 Rd = inst.operands[0].reg;
7768 Rn = (inst.operands[1].present
7769 ? inst.operands[1].reg : Rd);
7770 Rm = inst.operands[2].reg;
7772 constraint ((Rd == REG_PC), BAD_PC);
7773 constraint ((Rn == REG_PC), BAD_PC);
7774 constraint ((Rm == REG_PC), BAD_PC);
7776 inst.instruction |= Rd << 16;
7777 inst.instruction |= Rn << 0;
7778 inst.instruction |= Rm << 8;
7784 /* There is no IT instruction in ARM mode. We
7785 process it to do the validation as if in
7786 thumb mode, just in case the code gets
7787 assembled for thumb using the unified syntax. */
7792 set_it_insn_type (IT_INSN);
7793 now_it.mask = (inst.instruction & 0xf) | 0x10;
7794 now_it.cc = inst.operands[0].imm;
7801 int base_reg = inst.operands[0].reg;
7802 int range = inst.operands[1].imm;
7804 inst.instruction |= base_reg << 16;
7805 inst.instruction |= range;
7807 if (inst.operands[1].writeback)
7808 inst.instruction |= LDM_TYPE_2_OR_3;
7810 if (inst.operands[0].writeback)
7812 inst.instruction |= WRITE_BACK;
7813 /* Check for unpredictable uses of writeback. */
7814 if (inst.instruction & LOAD_BIT)
7816 /* Not allowed in LDM type 2. */
7817 if ((inst.instruction & LDM_TYPE_2_OR_3)
7818 && ((range & (1 << REG_PC)) == 0))
7819 as_warn (_("writeback of base register is UNPREDICTABLE"));
7820 /* Only allowed if base reg not in list for other types. */
7821 else if (range & (1 << base_reg))
7822 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7826 /* Not allowed for type 2. */
7827 if (inst.instruction & LDM_TYPE_2_OR_3)
7828 as_warn (_("writeback of base register is UNPREDICTABLE"));
7829 /* Only allowed if base reg not in list, or first in list. */
7830 else if ((range & (1 << base_reg))
7831 && (range & ((1 << base_reg) - 1)))
7832 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7837 /* ARMv5TE load-consecutive (argument parse)
7846 constraint (inst.operands[0].reg % 2 != 0,
7847 _("first transfer register must be even"));
7848 constraint (inst.operands[1].present
7849 && inst.operands[1].reg != inst.operands[0].reg + 1,
7850 _("can only transfer two consecutive registers"));
7851 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7852 constraint (!inst.operands[2].isreg, _("'[' expected"));
7854 if (!inst.operands[1].present)
7855 inst.operands[1].reg = inst.operands[0].reg + 1;
7857 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7858 register and the first register written; we have to diagnose
7859 overlap between the base and the second register written here. */
7861 if (inst.operands[2].reg == inst.operands[1].reg
7862 && (inst.operands[2].writeback || inst.operands[2].postind))
7863 as_warn (_("base register written back, and overlaps "
7864 "second transfer register"));
7866 if (!(inst.instruction & V4_STR_BIT))
7868 /* For an index-register load, the index register must not overlap the
7869 destination (even if not write-back). */
7870 if (inst.operands[2].immisreg
7871 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7872 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7873 as_warn (_("index register overlaps transfer register"));
7875 inst.instruction |= inst.operands[0].reg << 12;
7876 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
7882 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7883 || inst.operands[1].postind || inst.operands[1].writeback
7884 || inst.operands[1].immisreg || inst.operands[1].shifted
7885 || inst.operands[1].negative
7886 /* This can arise if the programmer has written
7888 or if they have mistakenly used a register name as the last
7891 It is very difficult to distinguish between these two cases
7892 because "rX" might actually be a label. ie the register
7893 name has been occluded by a symbol of the same name. So we
7894 just generate a general 'bad addressing mode' type error
7895 message and leave it up to the programmer to discover the
7896 true cause and fix their mistake. */
7897 || (inst.operands[1].reg == REG_PC),
7900 constraint (inst.reloc.exp.X_op != O_constant
7901 || inst.reloc.exp.X_add_number != 0,
7902 _("offset must be zero in ARM encoding"));
7904 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7906 inst.instruction |= inst.operands[0].reg << 12;
7907 inst.instruction |= inst.operands[1].reg << 16;
7908 inst.reloc.type = BFD_RELOC_UNUSED;
7914 constraint (inst.operands[0].reg % 2 != 0,
7915 _("even register required"));
7916 constraint (inst.operands[1].present
7917 && inst.operands[1].reg != inst.operands[0].reg + 1,
7918 _("can only load two consecutive registers"));
7919 /* If op 1 were present and equal to PC, this function wouldn't
7920 have been called in the first place. */
7921 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7923 inst.instruction |= inst.operands[0].reg << 12;
7924 inst.instruction |= inst.operands[2].reg << 16;
7927 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
7928 which is not a multiple of four is UNPREDICTABLE. */
7930 check_ldr_r15_aligned (void)
7932 constraint (!(inst.operands[1].immisreg)
7933 && (inst.operands[0].reg == REG_PC
7934 && inst.operands[1].reg == REG_PC
7935 && (inst.reloc.exp.X_add_number & 0x3)),
7936 _("ldr to register 15 must be 4-byte alligned"));
7942 inst.instruction |= inst.operands[0].reg << 12;
7943 if (!inst.operands[1].isreg)
7944 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7946 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7947 check_ldr_r15_aligned ();
7953 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7955 if (inst.operands[1].preind)
7957 constraint (inst.reloc.exp.X_op != O_constant
7958 || inst.reloc.exp.X_add_number != 0,
7959 _("this instruction requires a post-indexed address"));
7961 inst.operands[1].preind = 0;
7962 inst.operands[1].postind = 1;
7963 inst.operands[1].writeback = 1;
7965 inst.instruction |= inst.operands[0].reg << 12;
7966 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7969 /* Halfword and signed-byte load/store operations. */
7974 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7975 inst.instruction |= inst.operands[0].reg << 12;
7976 if (!inst.operands[1].isreg)
7977 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7979 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7985 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7987 if (inst.operands[1].preind)
7989 constraint (inst.reloc.exp.X_op != O_constant
7990 || inst.reloc.exp.X_add_number != 0,
7991 _("this instruction requires a post-indexed address"));
7993 inst.operands[1].preind = 0;
7994 inst.operands[1].postind = 1;
7995 inst.operands[1].writeback = 1;
7997 inst.instruction |= inst.operands[0].reg << 12;
7998 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8001 /* Co-processor register load/store.
8002 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8006 inst.instruction |= inst.operands[0].reg << 8;
8007 inst.instruction |= inst.operands[1].reg << 12;
8008 encode_arm_cp_address (2, TRUE, TRUE, 0);
8014 /* This restriction does not apply to mls (nor to mla in v6 or later). */
8015 if (inst.operands[0].reg == inst.operands[1].reg
8016 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
8017 && !(inst.instruction & 0x00400000))
8018 as_tsktsk (_("Rd and Rm should be different in mla"));
8020 inst.instruction |= inst.operands[0].reg << 16;
8021 inst.instruction |= inst.operands[1].reg;
8022 inst.instruction |= inst.operands[2].reg << 8;
8023 inst.instruction |= inst.operands[3].reg << 12;
8029 inst.instruction |= inst.operands[0].reg << 12;
8030 encode_arm_shifter_operand (1);
8033 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8040 top = (inst.instruction & 0x00400000) != 0;
8041 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8042 _(":lower16: not allowed this instruction"));
8043 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8044 _(":upper16: not allowed instruction"));
8045 inst.instruction |= inst.operands[0].reg << 12;
8046 if (inst.reloc.type == BFD_RELOC_UNUSED)
8048 imm = inst.reloc.exp.X_add_number;
8049 /* The value is in two pieces: 0:11, 16:19. */
8050 inst.instruction |= (imm & 0x00000fff);
8051 inst.instruction |= (imm & 0x0000f000) << 4;
8055 static void do_vfp_nsyn_opcode (const char *);
8058 do_vfp_nsyn_mrs (void)
8060 if (inst.operands[0].isvec)
8062 if (inst.operands[1].reg != 1)
8063 first_error (_("operand 1 must be FPSCR"));
8064 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8065 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8066 do_vfp_nsyn_opcode ("fmstat");
8068 else if (inst.operands[1].isvec)
8069 do_vfp_nsyn_opcode ("fmrx");
8077 do_vfp_nsyn_msr (void)
8079 if (inst.operands[0].isvec)
8080 do_vfp_nsyn_opcode ("fmxr");
8090 unsigned Rt = inst.operands[0].reg;
8092 if (thumb_mode && inst.operands[0].reg == REG_SP)
8094 inst.error = BAD_SP;
8098 /* APSR_ sets isvec. All other refs to PC are illegal. */
8099 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
8101 inst.error = BAD_PC;
8105 switch (inst.operands[1].reg)
8112 inst.instruction |= (inst.operands[1].reg << 16);
8115 first_error (_("operand 1 must be a VFP extension System Register"));
8118 inst.instruction |= (Rt << 12);
8124 unsigned Rt = inst.operands[1].reg;
8127 reject_bad_reg (Rt);
8128 else if (Rt == REG_PC)
8130 inst.error = BAD_PC;
8134 switch (inst.operands[0].reg)
8139 inst.instruction |= (inst.operands[0].reg << 16);
8142 first_error (_("operand 0 must be FPSID or FPSCR pr FPEXC"));
8145 inst.instruction |= (Rt << 12);
8153 if (do_vfp_nsyn_mrs () == SUCCESS)
8156 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8157 inst.instruction |= inst.operands[0].reg << 12;
8159 if (inst.operands[1].isreg)
8161 br = inst.operands[1].reg;
8162 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8163 as_bad (_("bad register for mrs"));
8167 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8168 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8170 _("'APSR', 'CPSR' or 'SPSR' expected"));
8171 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8174 inst.instruction |= br;
8177 /* Two possible forms:
8178 "{C|S}PSR_<field>, Rm",
8179 "{C|S}PSR_f, #expression". */
8184 if (do_vfp_nsyn_msr () == SUCCESS)
8187 inst.instruction |= inst.operands[0].imm;
8188 if (inst.operands[1].isreg)
8189 inst.instruction |= inst.operands[1].reg;
8192 inst.instruction |= INST_IMMEDIATE;
8193 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8194 inst.reloc.pc_rel = 0;
8201 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8203 if (!inst.operands[2].present)
8204 inst.operands[2].reg = inst.operands[0].reg;
8205 inst.instruction |= inst.operands[0].reg << 16;
8206 inst.instruction |= inst.operands[1].reg;
8207 inst.instruction |= inst.operands[2].reg << 8;
8209 if (inst.operands[0].reg == inst.operands[1].reg
8210 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8211 as_tsktsk (_("Rd and Rm should be different in mul"));
8214 /* Long Multiply Parser
8215 UMULL RdLo, RdHi, Rm, Rs
8216 SMULL RdLo, RdHi, Rm, Rs
8217 UMLAL RdLo, RdHi, Rm, Rs
8218 SMLAL RdLo, RdHi, Rm, Rs. */
8223 inst.instruction |= inst.operands[0].reg << 12;
8224 inst.instruction |= inst.operands[1].reg << 16;
8225 inst.instruction |= inst.operands[2].reg;
8226 inst.instruction |= inst.operands[3].reg << 8;
8228 /* rdhi and rdlo must be different. */
8229 if (inst.operands[0].reg == inst.operands[1].reg)
8230 as_tsktsk (_("rdhi and rdlo must be different"));
8232 /* rdhi, rdlo and rm must all be different before armv6. */
8233 if ((inst.operands[0].reg == inst.operands[2].reg
8234 || inst.operands[1].reg == inst.operands[2].reg)
8235 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8236 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8242 if (inst.operands[0].present
8243 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
8245 /* Architectural NOP hints are CPSR sets with no bits selected. */
8246 inst.instruction &= 0xf0000000;
8247 inst.instruction |= 0x0320f000;
8248 if (inst.operands[0].present)
8249 inst.instruction |= inst.operands[0].imm;
8253 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8254 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8255 Condition defaults to COND_ALWAYS.
8256 Error if Rd, Rn or Rm are R15. */
8261 inst.instruction |= inst.operands[0].reg << 12;
8262 inst.instruction |= inst.operands[1].reg << 16;
8263 inst.instruction |= inst.operands[2].reg;
8264 if (inst.operands[3].present)
8265 encode_arm_shift (3);
8268 /* ARM V6 PKHTB (Argument Parse). */
8273 if (!inst.operands[3].present)
8275 /* If the shift specifier is omitted, turn the instruction
8276 into pkhbt rd, rm, rn. */
8277 inst.instruction &= 0xfff00010;
8278 inst.instruction |= inst.operands[0].reg << 12;
8279 inst.instruction |= inst.operands[1].reg;
8280 inst.instruction |= inst.operands[2].reg << 16;
8284 inst.instruction |= inst.operands[0].reg << 12;
8285 inst.instruction |= inst.operands[1].reg << 16;
8286 inst.instruction |= inst.operands[2].reg;
8287 encode_arm_shift (3);
8291 /* ARMv5TE: Preload-Cache
8292 MP Extensions: Preload for write
8296 Syntactically, like LDR with B=1, W=0, L=1. */
8301 constraint (!inst.operands[0].isreg,
8302 _("'[' expected after PLD mnemonic"));
8303 constraint (inst.operands[0].postind,
8304 _("post-indexed expression used in preload instruction"));
8305 constraint (inst.operands[0].writeback,
8306 _("writeback used in preload instruction"));
8307 constraint (!inst.operands[0].preind,
8308 _("unindexed addressing used in preload instruction"));
8309 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8312 /* ARMv7: PLI <addr_mode> */
8316 constraint (!inst.operands[0].isreg,
8317 _("'[' expected after PLI mnemonic"));
8318 constraint (inst.operands[0].postind,
8319 _("post-indexed expression used in preload instruction"));
8320 constraint (inst.operands[0].writeback,
8321 _("writeback used in preload instruction"));
8322 constraint (!inst.operands[0].preind,
8323 _("unindexed addressing used in preload instruction"));
8324 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8325 inst.instruction &= ~PRE_INDEX;
8331 inst.operands[1] = inst.operands[0];
8332 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8333 inst.operands[0].isreg = 1;
8334 inst.operands[0].writeback = 1;
8335 inst.operands[0].reg = REG_SP;
8339 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8340 word at the specified address and the following word
8342 Unconditionally executed.
8343 Error if Rn is R15. */
8348 inst.instruction |= inst.operands[0].reg << 16;
8349 if (inst.operands[0].writeback)
8350 inst.instruction |= WRITE_BACK;
8353 /* ARM V6 ssat (argument parse). */
8358 inst.instruction |= inst.operands[0].reg << 12;
8359 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8360 inst.instruction |= inst.operands[2].reg;
8362 if (inst.operands[3].present)
8363 encode_arm_shift (3);
8366 /* ARM V6 usat (argument parse). */
8371 inst.instruction |= inst.operands[0].reg << 12;
8372 inst.instruction |= inst.operands[1].imm << 16;
8373 inst.instruction |= inst.operands[2].reg;
8375 if (inst.operands[3].present)
8376 encode_arm_shift (3);
8379 /* ARM V6 ssat16 (argument parse). */
8384 inst.instruction |= inst.operands[0].reg << 12;
8385 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8386 inst.instruction |= inst.operands[2].reg;
8392 inst.instruction |= inst.operands[0].reg << 12;
8393 inst.instruction |= inst.operands[1].imm << 16;
8394 inst.instruction |= inst.operands[2].reg;
8397 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8398 preserving the other bits.
8400 setend <endian_specifier>, where <endian_specifier> is either
8406 if (inst.operands[0].imm)
8407 inst.instruction |= 0x200;
8413 unsigned int Rm = (inst.operands[1].present
8414 ? inst.operands[1].reg
8415 : inst.operands[0].reg);
8417 inst.instruction |= inst.operands[0].reg << 12;
8418 inst.instruction |= Rm;
8419 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
8421 inst.instruction |= inst.operands[2].reg << 8;
8422 inst.instruction |= SHIFT_BY_REG;
8423 /* PR 12854: Error on extraneous shifts. */
8424 constraint (inst.operands[2].shifted,
8425 _("extraneous shift as part of operand to shift insn"));
8428 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
8434 inst.reloc.type = BFD_RELOC_ARM_SMC;
8435 inst.reloc.pc_rel = 0;
8441 inst.reloc.type = BFD_RELOC_ARM_HVC;
8442 inst.reloc.pc_rel = 0;
8448 inst.reloc.type = BFD_RELOC_ARM_SWI;
8449 inst.reloc.pc_rel = 0;
8452 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8453 SMLAxy{cond} Rd,Rm,Rs,Rn
8454 SMLAWy{cond} Rd,Rm,Rs,Rn
8455 Error if any register is R15. */
8460 inst.instruction |= inst.operands[0].reg << 16;
8461 inst.instruction |= inst.operands[1].reg;
8462 inst.instruction |= inst.operands[2].reg << 8;
8463 inst.instruction |= inst.operands[3].reg << 12;
8466 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8467 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8468 Error if any register is R15.
8469 Warning if Rdlo == Rdhi. */
8474 inst.instruction |= inst.operands[0].reg << 12;
8475 inst.instruction |= inst.operands[1].reg << 16;
8476 inst.instruction |= inst.operands[2].reg;
8477 inst.instruction |= inst.operands[3].reg << 8;
8479 if (inst.operands[0].reg == inst.operands[1].reg)
8480 as_tsktsk (_("rdhi and rdlo must be different"));
8483 /* ARM V5E (El Segundo) signed-multiply (argument parse)
8484 SMULxy{cond} Rd,Rm,Rs
8485 Error if any register is R15. */
8490 inst.instruction |= inst.operands[0].reg << 16;
8491 inst.instruction |= inst.operands[1].reg;
8492 inst.instruction |= inst.operands[2].reg << 8;
8495 /* ARM V6 srs (argument parse). The variable fields in the encoding are
8496 the same for both ARM and Thumb-2. */
8503 if (inst.operands[0].present)
8505 reg = inst.operands[0].reg;
8506 constraint (reg != REG_SP, _("SRS base register must be r13"));
8511 inst.instruction |= reg << 16;
8512 inst.instruction |= inst.operands[1].imm;
8513 if (inst.operands[0].writeback || inst.operands[1].writeback)
8514 inst.instruction |= WRITE_BACK;
8517 /* ARM V6 strex (argument parse). */
8522 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8523 || inst.operands[2].postind || inst.operands[2].writeback
8524 || inst.operands[2].immisreg || inst.operands[2].shifted
8525 || inst.operands[2].negative
8526 /* See comment in do_ldrex(). */
8527 || (inst.operands[2].reg == REG_PC),
8530 constraint (inst.operands[0].reg == inst.operands[1].reg
8531 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8533 constraint (inst.reloc.exp.X_op != O_constant
8534 || inst.reloc.exp.X_add_number != 0,
8535 _("offset must be zero in ARM encoding"));
8537 inst.instruction |= inst.operands[0].reg << 12;
8538 inst.instruction |= inst.operands[1].reg;
8539 inst.instruction |= inst.operands[2].reg << 16;
8540 inst.reloc.type = BFD_RELOC_UNUSED;
8546 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8547 || inst.operands[2].postind || inst.operands[2].writeback
8548 || inst.operands[2].immisreg || inst.operands[2].shifted
8549 || inst.operands[2].negative,
8552 constraint (inst.operands[0].reg == inst.operands[1].reg
8553 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8561 constraint (inst.operands[1].reg % 2 != 0,
8562 _("even register required"));
8563 constraint (inst.operands[2].present
8564 && inst.operands[2].reg != inst.operands[1].reg + 1,
8565 _("can only store two consecutive registers"));
8566 /* If op 2 were present and equal to PC, this function wouldn't
8567 have been called in the first place. */
8568 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
8570 constraint (inst.operands[0].reg == inst.operands[1].reg
8571 || inst.operands[0].reg == inst.operands[1].reg + 1
8572 || inst.operands[0].reg == inst.operands[3].reg,
8575 inst.instruction |= inst.operands[0].reg << 12;
8576 inst.instruction |= inst.operands[1].reg;
8577 inst.instruction |= inst.operands[3].reg << 16;
8580 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8581 extends it to 32-bits, and adds the result to a value in another
8582 register. You can specify a rotation by 0, 8, 16, or 24 bits
8583 before extracting the 16-bit value.
8584 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8585 Condition defaults to COND_ALWAYS.
8586 Error if any register uses R15. */
8591 inst.instruction |= inst.operands[0].reg << 12;
8592 inst.instruction |= inst.operands[1].reg << 16;
8593 inst.instruction |= inst.operands[2].reg;
8594 inst.instruction |= inst.operands[3].imm << 10;
8599 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8600 Condition defaults to COND_ALWAYS.
8601 Error if any register uses R15. */
8606 inst.instruction |= inst.operands[0].reg << 12;
8607 inst.instruction |= inst.operands[1].reg;
8608 inst.instruction |= inst.operands[2].imm << 10;
8611 /* VFP instructions. In a logical order: SP variant first, monad
8612 before dyad, arithmetic then move then load/store. */
8615 do_vfp_sp_monadic (void)
8617 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8618 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8622 do_vfp_sp_dyadic (void)
8624 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8625 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8626 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8630 do_vfp_sp_compare_z (void)
8632 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8636 do_vfp_dp_sp_cvt (void)
8638 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8639 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8643 do_vfp_sp_dp_cvt (void)
8645 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8646 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8650 do_vfp_reg_from_sp (void)
8652 inst.instruction |= inst.operands[0].reg << 12;
8653 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8657 do_vfp_reg2_from_sp2 (void)
8659 constraint (inst.operands[2].imm != 2,
8660 _("only two consecutive VFP SP registers allowed here"));
8661 inst.instruction |= inst.operands[0].reg << 12;
8662 inst.instruction |= inst.operands[1].reg << 16;
8663 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8667 do_vfp_sp_from_reg (void)
8669 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
8670 inst.instruction |= inst.operands[1].reg << 12;
8674 do_vfp_sp2_from_reg2 (void)
8676 constraint (inst.operands[0].imm != 2,
8677 _("only two consecutive VFP SP registers allowed here"));
8678 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
8679 inst.instruction |= inst.operands[1].reg << 12;
8680 inst.instruction |= inst.operands[2].reg << 16;
8684 do_vfp_sp_ldst (void)
8686 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8687 encode_arm_cp_address (1, FALSE, TRUE, 0);
8691 do_vfp_dp_ldst (void)
8693 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8694 encode_arm_cp_address (1, FALSE, TRUE, 0);
8699 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
8701 if (inst.operands[0].writeback)
8702 inst.instruction |= WRITE_BACK;
8704 constraint (ldstm_type != VFP_LDSTMIA,
8705 _("this addressing mode requires base-register writeback"));
8706 inst.instruction |= inst.operands[0].reg << 16;
8707 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
8708 inst.instruction |= inst.operands[1].imm;
8712 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
8716 if (inst.operands[0].writeback)
8717 inst.instruction |= WRITE_BACK;
8719 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8720 _("this addressing mode requires base-register writeback"));
8722 inst.instruction |= inst.operands[0].reg << 16;
8723 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8725 count = inst.operands[1].imm << 1;
8726 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8729 inst.instruction |= count;
8733 do_vfp_sp_ldstmia (void)
8735 vfp_sp_ldstm (VFP_LDSTMIA);
8739 do_vfp_sp_ldstmdb (void)
8741 vfp_sp_ldstm (VFP_LDSTMDB);
8745 do_vfp_dp_ldstmia (void)
8747 vfp_dp_ldstm (VFP_LDSTMIA);
8751 do_vfp_dp_ldstmdb (void)
8753 vfp_dp_ldstm (VFP_LDSTMDB);
8757 do_vfp_xp_ldstmia (void)
8759 vfp_dp_ldstm (VFP_LDSTMIAX);
8763 do_vfp_xp_ldstmdb (void)
8765 vfp_dp_ldstm (VFP_LDSTMDBX);
8769 do_vfp_dp_rd_rm (void)
8771 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8772 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8776 do_vfp_dp_rn_rd (void)
8778 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8779 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8783 do_vfp_dp_rd_rn (void)
8785 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8786 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8790 do_vfp_dp_rd_rn_rm (void)
8792 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8793 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8794 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8800 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8804 do_vfp_dp_rm_rd_rn (void)
8806 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8807 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8808 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8811 /* VFPv3 instructions. */
8813 do_vfp_sp_const (void)
8815 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8816 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8817 inst.instruction |= (inst.operands[1].imm & 0x0f);
8821 do_vfp_dp_const (void)
8823 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8824 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8825 inst.instruction |= (inst.operands[1].imm & 0x0f);
8829 vfp_conv (int srcsize)
8831 int immbits = srcsize - inst.operands[1].imm;
8833 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
8835 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
8836 i.e. immbits must be in range 0 - 16. */
8837 inst.error = _("immediate value out of range, expected range [0, 16]");
8840 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
8842 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
8843 i.e. immbits must be in range 0 - 31. */
8844 inst.error = _("immediate value out of range, expected range [1, 32]");
8848 inst.instruction |= (immbits & 1) << 5;
8849 inst.instruction |= (immbits >> 1);
8853 do_vfp_sp_conv_16 (void)
8855 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8860 do_vfp_dp_conv_16 (void)
8862 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8867 do_vfp_sp_conv_32 (void)
8869 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8874 do_vfp_dp_conv_32 (void)
8876 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8880 /* FPA instructions. Also in a logical order. */
8885 inst.instruction |= inst.operands[0].reg << 16;
8886 inst.instruction |= inst.operands[1].reg;
8890 do_fpa_ldmstm (void)
8892 inst.instruction |= inst.operands[0].reg << 12;
8893 switch (inst.operands[1].imm)
8895 case 1: inst.instruction |= CP_T_X; break;
8896 case 2: inst.instruction |= CP_T_Y; break;
8897 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8902 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8904 /* The instruction specified "ea" or "fd", so we can only accept
8905 [Rn]{!}. The instruction does not really support stacking or
8906 unstacking, so we have to emulate these by setting appropriate
8907 bits and offsets. */
8908 constraint (inst.reloc.exp.X_op != O_constant
8909 || inst.reloc.exp.X_add_number != 0,
8910 _("this instruction does not support indexing"));
8912 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8913 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
8915 if (!(inst.instruction & INDEX_UP))
8916 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
8918 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8920 inst.operands[2].preind = 0;
8921 inst.operands[2].postind = 1;
8925 encode_arm_cp_address (2, TRUE, TRUE, 0);
8928 /* iWMMXt instructions: strictly in alphabetical order. */
8931 do_iwmmxt_tandorc (void)
8933 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8937 do_iwmmxt_textrc (void)
8939 inst.instruction |= inst.operands[0].reg << 12;
8940 inst.instruction |= inst.operands[1].imm;
8944 do_iwmmxt_textrm (void)
8946 inst.instruction |= inst.operands[0].reg << 12;
8947 inst.instruction |= inst.operands[1].reg << 16;
8948 inst.instruction |= inst.operands[2].imm;
8952 do_iwmmxt_tinsr (void)
8954 inst.instruction |= inst.operands[0].reg << 16;
8955 inst.instruction |= inst.operands[1].reg << 12;
8956 inst.instruction |= inst.operands[2].imm;
8960 do_iwmmxt_tmia (void)
8962 inst.instruction |= inst.operands[0].reg << 5;
8963 inst.instruction |= inst.operands[1].reg;
8964 inst.instruction |= inst.operands[2].reg << 12;
8968 do_iwmmxt_waligni (void)
8970 inst.instruction |= inst.operands[0].reg << 12;
8971 inst.instruction |= inst.operands[1].reg << 16;
8972 inst.instruction |= inst.operands[2].reg;
8973 inst.instruction |= inst.operands[3].imm << 20;
8977 do_iwmmxt_wmerge (void)
8979 inst.instruction |= inst.operands[0].reg << 12;
8980 inst.instruction |= inst.operands[1].reg << 16;
8981 inst.instruction |= inst.operands[2].reg;
8982 inst.instruction |= inst.operands[3].imm << 21;
8986 do_iwmmxt_wmov (void)
8988 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8989 inst.instruction |= inst.operands[0].reg << 12;
8990 inst.instruction |= inst.operands[1].reg << 16;
8991 inst.instruction |= inst.operands[1].reg;
8995 do_iwmmxt_wldstbh (void)
8998 inst.instruction |= inst.operands[0].reg << 12;
9000 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9002 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9003 encode_arm_cp_address (1, TRUE, FALSE, reloc);
9007 do_iwmmxt_wldstw (void)
9009 /* RIWR_RIWC clears .isreg for a control register. */
9010 if (!inst.operands[0].isreg)
9012 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9013 inst.instruction |= 0xf0000000;
9016 inst.instruction |= inst.operands[0].reg << 12;
9017 encode_arm_cp_address (1, TRUE, TRUE, 0);
9021 do_iwmmxt_wldstd (void)
9023 inst.instruction |= inst.operands[0].reg << 12;
9024 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9025 && inst.operands[1].immisreg)
9027 inst.instruction &= ~0x1a000ff;
9028 inst.instruction |= (0xf << 28);
9029 if (inst.operands[1].preind)
9030 inst.instruction |= PRE_INDEX;
9031 if (!inst.operands[1].negative)
9032 inst.instruction |= INDEX_UP;
9033 if (inst.operands[1].writeback)
9034 inst.instruction |= WRITE_BACK;
9035 inst.instruction |= inst.operands[1].reg << 16;
9036 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9037 inst.instruction |= inst.operands[1].imm;
9040 encode_arm_cp_address (1, TRUE, FALSE, 0);
9044 do_iwmmxt_wshufh (void)
9046 inst.instruction |= inst.operands[0].reg << 12;
9047 inst.instruction |= inst.operands[1].reg << 16;
9048 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9049 inst.instruction |= (inst.operands[2].imm & 0x0f);
9053 do_iwmmxt_wzero (void)
9055 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9056 inst.instruction |= inst.operands[0].reg;
9057 inst.instruction |= inst.operands[0].reg << 12;
9058 inst.instruction |= inst.operands[0].reg << 16;
9062 do_iwmmxt_wrwrwr_or_imm5 (void)
9064 if (inst.operands[2].isreg)
9067 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9068 _("immediate operand requires iWMMXt2"));
9070 if (inst.operands[2].imm == 0)
9072 switch ((inst.instruction >> 20) & 0xf)
9078 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9079 inst.operands[2].imm = 16;
9080 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9086 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9087 inst.operands[2].imm = 32;
9088 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9095 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9097 wrn = (inst.instruction >> 16) & 0xf;
9098 inst.instruction &= 0xff0fff0f;
9099 inst.instruction |= wrn;
9100 /* Bail out here; the instruction is now assembled. */
9105 /* Map 32 -> 0, etc. */
9106 inst.operands[2].imm &= 0x1f;
9107 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9111 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9112 operations first, then control, shift, and load/store. */
9114 /* Insns like "foo X,Y,Z". */
9117 do_mav_triple (void)
9119 inst.instruction |= inst.operands[0].reg << 16;
9120 inst.instruction |= inst.operands[1].reg;
9121 inst.instruction |= inst.operands[2].reg << 12;
9124 /* Insns like "foo W,X,Y,Z".
9125 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
9130 inst.instruction |= inst.operands[0].reg << 5;
9131 inst.instruction |= inst.operands[1].reg << 12;
9132 inst.instruction |= inst.operands[2].reg << 16;
9133 inst.instruction |= inst.operands[3].reg;
9136 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9140 inst.instruction |= inst.operands[1].reg << 12;
9143 /* Maverick shift immediate instructions.
9144 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9145 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
9150 int imm = inst.operands[2].imm;
9152 inst.instruction |= inst.operands[0].reg << 12;
9153 inst.instruction |= inst.operands[1].reg << 16;
9155 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9156 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9157 Bit 4 should be 0. */
9158 imm = (imm & 0xf) | ((imm & 0x70) << 1);
9160 inst.instruction |= imm;
9163 /* XScale instructions. Also sorted arithmetic before move. */
9165 /* Xscale multiply-accumulate (argument parse)
9168 MIAxycc acc0,Rm,Rs. */
9173 inst.instruction |= inst.operands[1].reg;
9174 inst.instruction |= inst.operands[2].reg << 12;
9177 /* Xscale move-accumulator-register (argument parse)
9179 MARcc acc0,RdLo,RdHi. */
9184 inst.instruction |= inst.operands[1].reg << 12;
9185 inst.instruction |= inst.operands[2].reg << 16;
9188 /* Xscale move-register-accumulator (argument parse)
9190 MRAcc RdLo,RdHi,acc0. */
9195 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9196 inst.instruction |= inst.operands[0].reg << 12;
9197 inst.instruction |= inst.operands[1].reg << 16;
9200 /* Encoding functions relevant only to Thumb. */
9202 /* inst.operands[i] is a shifted-register operand; encode
9203 it into inst.instruction in the format used by Thumb32. */
9206 encode_thumb32_shifted_operand (int i)
9208 unsigned int value = inst.reloc.exp.X_add_number;
9209 unsigned int shift = inst.operands[i].shift_kind;
9211 constraint (inst.operands[i].immisreg,
9212 _("shift by register not allowed in thumb mode"));
9213 inst.instruction |= inst.operands[i].reg;
9214 if (shift == SHIFT_RRX)
9215 inst.instruction |= SHIFT_ROR << 4;
9218 constraint (inst.reloc.exp.X_op != O_constant,
9219 _("expression too complex"));
9221 constraint (value > 32
9222 || (value == 32 && (shift == SHIFT_LSL
9223 || shift == SHIFT_ROR)),
9224 _("shift expression is too large"));
9228 else if (value == 32)
9231 inst.instruction |= shift << 4;
9232 inst.instruction |= (value & 0x1c) << 10;
9233 inst.instruction |= (value & 0x03) << 6;
9238 /* inst.operands[i] was set up by parse_address. Encode it into a
9239 Thumb32 format load or store instruction. Reject forms that cannot
9240 be used with such instructions. If is_t is true, reject forms that
9241 cannot be used with a T instruction; if is_d is true, reject forms
9242 that cannot be used with a D instruction. If it is a store insn,
9246 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9248 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
9250 constraint (!inst.operands[i].isreg,
9251 _("Instruction does not support =N addresses"));
9253 inst.instruction |= inst.operands[i].reg << 16;
9254 if (inst.operands[i].immisreg)
9256 constraint (is_pc, BAD_PC_ADDRESSING);
9257 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9258 constraint (inst.operands[i].negative,
9259 _("Thumb does not support negative register indexing"));
9260 constraint (inst.operands[i].postind,
9261 _("Thumb does not support register post-indexing"));
9262 constraint (inst.operands[i].writeback,
9263 _("Thumb does not support register indexing with writeback"));
9264 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9265 _("Thumb supports only LSL in shifted register indexing"));
9267 inst.instruction |= inst.operands[i].imm;
9268 if (inst.operands[i].shifted)
9270 constraint (inst.reloc.exp.X_op != O_constant,
9271 _("expression too complex"));
9272 constraint (inst.reloc.exp.X_add_number < 0
9273 || inst.reloc.exp.X_add_number > 3,
9274 _("shift out of range"));
9275 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9277 inst.reloc.type = BFD_RELOC_UNUSED;
9279 else if (inst.operands[i].preind)
9281 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
9282 constraint (is_t && inst.operands[i].writeback,
9283 _("cannot use writeback with this instruction"));
9284 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9285 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
9289 inst.instruction |= 0x01000000;
9290 if (inst.operands[i].writeback)
9291 inst.instruction |= 0x00200000;
9295 inst.instruction |= 0x00000c00;
9296 if (inst.operands[i].writeback)
9297 inst.instruction |= 0x00000100;
9299 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9301 else if (inst.operands[i].postind)
9303 gas_assert (inst.operands[i].writeback);
9304 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9305 constraint (is_t, _("cannot use post-indexing with this instruction"));
9308 inst.instruction |= 0x00200000;
9310 inst.instruction |= 0x00000900;
9311 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9313 else /* unindexed - only for coprocessor */
9314 inst.error = _("instruction does not accept unindexed addressing");
9317 /* Table of Thumb instructions which exist in both 16- and 32-bit
9318 encodings (the latter only in post-V6T2 cores). The index is the
9319 value used in the insns table below. When there is more than one
9320 possible 16-bit encoding for the instruction, this table always
9322 Also contains several pseudo-instructions used during relaxation. */
9323 #define T16_32_TAB \
9324 X(_adc, 4140, eb400000), \
9325 X(_adcs, 4140, eb500000), \
9326 X(_add, 1c00, eb000000), \
9327 X(_adds, 1c00, eb100000), \
9328 X(_addi, 0000, f1000000), \
9329 X(_addis, 0000, f1100000), \
9330 X(_add_pc,000f, f20f0000), \
9331 X(_add_sp,000d, f10d0000), \
9332 X(_adr, 000f, f20f0000), \
9333 X(_and, 4000, ea000000), \
9334 X(_ands, 4000, ea100000), \
9335 X(_asr, 1000, fa40f000), \
9336 X(_asrs, 1000, fa50f000), \
9337 X(_b, e000, f000b000), \
9338 X(_bcond, d000, f0008000), \
9339 X(_bic, 4380, ea200000), \
9340 X(_bics, 4380, ea300000), \
9341 X(_cmn, 42c0, eb100f00), \
9342 X(_cmp, 2800, ebb00f00), \
9343 X(_cpsie, b660, f3af8400), \
9344 X(_cpsid, b670, f3af8600), \
9345 X(_cpy, 4600, ea4f0000), \
9346 X(_dec_sp,80dd, f1ad0d00), \
9347 X(_eor, 4040, ea800000), \
9348 X(_eors, 4040, ea900000), \
9349 X(_inc_sp,00dd, f10d0d00), \
9350 X(_ldmia, c800, e8900000), \
9351 X(_ldr, 6800, f8500000), \
9352 X(_ldrb, 7800, f8100000), \
9353 X(_ldrh, 8800, f8300000), \
9354 X(_ldrsb, 5600, f9100000), \
9355 X(_ldrsh, 5e00, f9300000), \
9356 X(_ldr_pc,4800, f85f0000), \
9357 X(_ldr_pc2,4800, f85f0000), \
9358 X(_ldr_sp,9800, f85d0000), \
9359 X(_lsl, 0000, fa00f000), \
9360 X(_lsls, 0000, fa10f000), \
9361 X(_lsr, 0800, fa20f000), \
9362 X(_lsrs, 0800, fa30f000), \
9363 X(_mov, 2000, ea4f0000), \
9364 X(_movs, 2000, ea5f0000), \
9365 X(_mul, 4340, fb00f000), \
9366 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9367 X(_mvn, 43c0, ea6f0000), \
9368 X(_mvns, 43c0, ea7f0000), \
9369 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9370 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9371 X(_orr, 4300, ea400000), \
9372 X(_orrs, 4300, ea500000), \
9373 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9374 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9375 X(_rev, ba00, fa90f080), \
9376 X(_rev16, ba40, fa90f090), \
9377 X(_revsh, bac0, fa90f0b0), \
9378 X(_ror, 41c0, fa60f000), \
9379 X(_rors, 41c0, fa70f000), \
9380 X(_sbc, 4180, eb600000), \
9381 X(_sbcs, 4180, eb700000), \
9382 X(_stmia, c000, e8800000), \
9383 X(_str, 6000, f8400000), \
9384 X(_strb, 7000, f8000000), \
9385 X(_strh, 8000, f8200000), \
9386 X(_str_sp,9000, f84d0000), \
9387 X(_sub, 1e00, eba00000), \
9388 X(_subs, 1e00, ebb00000), \
9389 X(_subi, 8000, f1a00000), \
9390 X(_subis, 8000, f1b00000), \
9391 X(_sxtb, b240, fa4ff080), \
9392 X(_sxth, b200, fa0ff080), \
9393 X(_tst, 4200, ea100f00), \
9394 X(_uxtb, b2c0, fa5ff080), \
9395 X(_uxth, b280, fa1ff080), \
9396 X(_nop, bf00, f3af8000), \
9397 X(_yield, bf10, f3af8001), \
9398 X(_wfe, bf20, f3af8002), \
9399 X(_wfi, bf30, f3af8003), \
9400 X(_sev, bf40, f3af8004),
9402 /* To catch errors in encoding functions, the codes are all offset by
9403 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9404 as 16-bit instructions. */
9405 #define X(a,b,c) T_MNEM##a
9406 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9409 #define X(a,b,c) 0x##b
9410 static const unsigned short thumb_op16[] = { T16_32_TAB };
9411 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9414 #define X(a,b,c) 0x##c
9415 static const unsigned int thumb_op32[] = { T16_32_TAB };
9416 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9417 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
9421 /* Thumb instruction encoders, in alphabetical order. */
9426 do_t_add_sub_w (void)
9430 Rd = inst.operands[0].reg;
9431 Rn = inst.operands[1].reg;
9433 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9434 is the SP-{plus,minus}-immediate form of the instruction. */
9436 constraint (Rd == REG_PC, BAD_PC);
9438 reject_bad_reg (Rd);
9440 inst.instruction |= (Rn << 16) | (Rd << 8);
9441 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9444 /* Parse an add or subtract instruction. We get here with inst.instruction
9445 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9452 Rd = inst.operands[0].reg;
9453 Rs = (inst.operands[1].present
9454 ? inst.operands[1].reg /* Rd, Rs, foo */
9455 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9458 set_it_insn_type_last ();
9466 flags = (inst.instruction == T_MNEM_adds
9467 || inst.instruction == T_MNEM_subs);
9469 narrow = !in_it_block ();
9471 narrow = in_it_block ();
9472 if (!inst.operands[2].isreg)
9476 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9478 add = (inst.instruction == T_MNEM_add
9479 || inst.instruction == T_MNEM_adds);
9481 if (inst.size_req != 4)
9483 /* Attempt to use a narrow opcode, with relaxation if
9485 if (Rd == REG_SP && Rs == REG_SP && !flags)
9486 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9487 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9488 opcode = T_MNEM_add_sp;
9489 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9490 opcode = T_MNEM_add_pc;
9491 else if (Rd <= 7 && Rs <= 7 && narrow)
9494 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9496 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9500 inst.instruction = THUMB_OP16(opcode);
9501 inst.instruction |= (Rd << 4) | Rs;
9502 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9503 if (inst.size_req != 2)
9504 inst.relax = opcode;
9507 constraint (inst.size_req == 2, BAD_HIREG);
9509 if (inst.size_req == 4
9510 || (inst.size_req != 2 && !opcode))
9514 constraint (add, BAD_PC);
9515 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9516 _("only SUBS PC, LR, #const allowed"));
9517 constraint (inst.reloc.exp.X_op != O_constant,
9518 _("expression too complex"));
9519 constraint (inst.reloc.exp.X_add_number < 0
9520 || inst.reloc.exp.X_add_number > 0xff,
9521 _("immediate value out of range"));
9522 inst.instruction = T2_SUBS_PC_LR
9523 | inst.reloc.exp.X_add_number;
9524 inst.reloc.type = BFD_RELOC_UNUSED;
9527 else if (Rs == REG_PC)
9529 /* Always use addw/subw. */
9530 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9531 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9535 inst.instruction = THUMB_OP32 (inst.instruction);
9536 inst.instruction = (inst.instruction & 0xe1ffffff)
9539 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9541 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9543 inst.instruction |= Rd << 8;
9544 inst.instruction |= Rs << 16;
9549 unsigned int value = inst.reloc.exp.X_add_number;
9550 unsigned int shift = inst.operands[2].shift_kind;
9552 Rn = inst.operands[2].reg;
9553 /* See if we can do this with a 16-bit instruction. */
9554 if (!inst.operands[2].shifted && inst.size_req != 4)
9556 if (Rd > 7 || Rs > 7 || Rn > 7)
9561 inst.instruction = ((inst.instruction == T_MNEM_adds
9562 || inst.instruction == T_MNEM_add)
9565 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9569 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
9571 /* Thumb-1 cores (except v6-M) require at least one high
9572 register in a narrow non flag setting add. */
9573 if (Rd > 7 || Rn > 7
9574 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9575 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
9582 inst.instruction = T_OPCODE_ADD_HI;
9583 inst.instruction |= (Rd & 8) << 4;
9584 inst.instruction |= (Rd & 7);
9585 inst.instruction |= Rn << 3;
9591 constraint (Rd == REG_PC, BAD_PC);
9592 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9593 constraint (Rs == REG_PC, BAD_PC);
9594 reject_bad_reg (Rn);
9596 /* If we get here, it can't be done in 16 bits. */
9597 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9598 _("shift must be constant"));
9599 inst.instruction = THUMB_OP32 (inst.instruction);
9600 inst.instruction |= Rd << 8;
9601 inst.instruction |= Rs << 16;
9602 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
9603 _("shift value over 3 not allowed in thumb mode"));
9604 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
9605 _("only LSL shift allowed in thumb mode"));
9606 encode_thumb32_shifted_operand (2);
9611 constraint (inst.instruction == T_MNEM_adds
9612 || inst.instruction == T_MNEM_subs,
9615 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
9617 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9618 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9621 inst.instruction = (inst.instruction == T_MNEM_add
9623 inst.instruction |= (Rd << 4) | Rs;
9624 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9628 Rn = inst.operands[2].reg;
9629 constraint (inst.operands[2].shifted, _("unshifted register required"));
9631 /* We now have Rd, Rs, and Rn set to registers. */
9632 if (Rd > 7 || Rs > 7 || Rn > 7)
9634 /* Can't do this for SUB. */
9635 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9636 inst.instruction = T_OPCODE_ADD_HI;
9637 inst.instruction |= (Rd & 8) << 4;
9638 inst.instruction |= (Rd & 7);
9640 inst.instruction |= Rn << 3;
9642 inst.instruction |= Rs << 3;
9644 constraint (1, _("dest must overlap one source register"));
9648 inst.instruction = (inst.instruction == T_MNEM_add
9649 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9650 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9660 Rd = inst.operands[0].reg;
9661 reject_bad_reg (Rd);
9663 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
9665 /* Defer to section relaxation. */
9666 inst.relax = inst.instruction;
9667 inst.instruction = THUMB_OP16 (inst.instruction);
9668 inst.instruction |= Rd << 4;
9670 else if (unified_syntax && inst.size_req != 2)
9672 /* Generate a 32-bit opcode. */
9673 inst.instruction = THUMB_OP32 (inst.instruction);
9674 inst.instruction |= Rd << 8;
9675 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9676 inst.reloc.pc_rel = 1;
9680 /* Generate a 16-bit opcode. */
9681 inst.instruction = THUMB_OP16 (inst.instruction);
9682 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9683 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9684 inst.reloc.pc_rel = 1;
9686 inst.instruction |= Rd << 4;
9690 /* Arithmetic instructions for which there is just one 16-bit
9691 instruction encoding, and it allows only two low registers.
9692 For maximal compatibility with ARM syntax, we allow three register
9693 operands even when Thumb-32 instructions are not available, as long
9694 as the first two are identical. For instance, both "sbc r0,r1" and
9695 "sbc r0,r0,r1" are allowed. */
9701 Rd = inst.operands[0].reg;
9702 Rs = (inst.operands[1].present
9703 ? inst.operands[1].reg /* Rd, Rs, foo */
9704 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9705 Rn = inst.operands[2].reg;
9707 reject_bad_reg (Rd);
9708 reject_bad_reg (Rs);
9709 if (inst.operands[2].isreg)
9710 reject_bad_reg (Rn);
9714 if (!inst.operands[2].isreg)
9716 /* For an immediate, we always generate a 32-bit opcode;
9717 section relaxation will shrink it later if possible. */
9718 inst.instruction = THUMB_OP32 (inst.instruction);
9719 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9720 inst.instruction |= Rd << 8;
9721 inst.instruction |= Rs << 16;
9722 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9728 /* See if we can do this with a 16-bit instruction. */
9729 if (THUMB_SETS_FLAGS (inst.instruction))
9730 narrow = !in_it_block ();
9732 narrow = in_it_block ();
9734 if (Rd > 7 || Rn > 7 || Rs > 7)
9736 if (inst.operands[2].shifted)
9738 if (inst.size_req == 4)
9744 inst.instruction = THUMB_OP16 (inst.instruction);
9745 inst.instruction |= Rd;
9746 inst.instruction |= Rn << 3;
9750 /* If we get here, it can't be done in 16 bits. */
9751 constraint (inst.operands[2].shifted
9752 && inst.operands[2].immisreg,
9753 _("shift must be constant"));
9754 inst.instruction = THUMB_OP32 (inst.instruction);
9755 inst.instruction |= Rd << 8;
9756 inst.instruction |= Rs << 16;
9757 encode_thumb32_shifted_operand (2);
9762 /* On its face this is a lie - the instruction does set the
9763 flags. However, the only supported mnemonic in this mode
9765 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9767 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9768 _("unshifted register required"));
9769 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9770 constraint (Rd != Rs,
9771 _("dest and source1 must be the same register"));
9773 inst.instruction = THUMB_OP16 (inst.instruction);
9774 inst.instruction |= Rd;
9775 inst.instruction |= Rn << 3;
9779 /* Similarly, but for instructions where the arithmetic operation is
9780 commutative, so we can allow either of them to be different from
9781 the destination operand in a 16-bit instruction. For instance, all
9782 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9789 Rd = inst.operands[0].reg;
9790 Rs = (inst.operands[1].present
9791 ? inst.operands[1].reg /* Rd, Rs, foo */
9792 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9793 Rn = inst.operands[2].reg;
9795 reject_bad_reg (Rd);
9796 reject_bad_reg (Rs);
9797 if (inst.operands[2].isreg)
9798 reject_bad_reg (Rn);
9802 if (!inst.operands[2].isreg)
9804 /* For an immediate, we always generate a 32-bit opcode;
9805 section relaxation will shrink it later if possible. */
9806 inst.instruction = THUMB_OP32 (inst.instruction);
9807 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9808 inst.instruction |= Rd << 8;
9809 inst.instruction |= Rs << 16;
9810 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9816 /* See if we can do this with a 16-bit instruction. */
9817 if (THUMB_SETS_FLAGS (inst.instruction))
9818 narrow = !in_it_block ();
9820 narrow = in_it_block ();
9822 if (Rd > 7 || Rn > 7 || Rs > 7)
9824 if (inst.operands[2].shifted)
9826 if (inst.size_req == 4)
9833 inst.instruction = THUMB_OP16 (inst.instruction);
9834 inst.instruction |= Rd;
9835 inst.instruction |= Rn << 3;
9840 inst.instruction = THUMB_OP16 (inst.instruction);
9841 inst.instruction |= Rd;
9842 inst.instruction |= Rs << 3;
9847 /* If we get here, it can't be done in 16 bits. */
9848 constraint (inst.operands[2].shifted
9849 && inst.operands[2].immisreg,
9850 _("shift must be constant"));
9851 inst.instruction = THUMB_OP32 (inst.instruction);
9852 inst.instruction |= Rd << 8;
9853 inst.instruction |= Rs << 16;
9854 encode_thumb32_shifted_operand (2);
9859 /* On its face this is a lie - the instruction does set the
9860 flags. However, the only supported mnemonic in this mode
9862 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9864 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9865 _("unshifted register required"));
9866 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9868 inst.instruction = THUMB_OP16 (inst.instruction);
9869 inst.instruction |= Rd;
9872 inst.instruction |= Rn << 3;
9874 inst.instruction |= Rs << 3;
9876 constraint (1, _("dest must overlap one source register"));
9883 if (inst.operands[0].present)
9885 constraint ((inst.instruction & 0xf0) != 0x40
9886 && inst.operands[0].imm > 0xf
9887 && inst.operands[0].imm < 0x0,
9888 _("bad barrier type"));
9889 inst.instruction |= inst.operands[0].imm;
9892 inst.instruction |= 0xf;
9899 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9900 constraint (msb > 32, _("bit-field extends past end of register"));
9901 /* The instruction encoding stores the LSB and MSB,
9902 not the LSB and width. */
9903 Rd = inst.operands[0].reg;
9904 reject_bad_reg (Rd);
9905 inst.instruction |= Rd << 8;
9906 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9907 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9908 inst.instruction |= msb - 1;
9917 Rd = inst.operands[0].reg;
9918 reject_bad_reg (Rd);
9920 /* #0 in second position is alternative syntax for bfc, which is
9921 the same instruction but with REG_PC in the Rm field. */
9922 if (!inst.operands[1].isreg)
9926 Rn = inst.operands[1].reg;
9927 reject_bad_reg (Rn);
9930 msb = inst.operands[2].imm + inst.operands[3].imm;
9931 constraint (msb > 32, _("bit-field extends past end of register"));
9932 /* The instruction encoding stores the LSB and MSB,
9933 not the LSB and width. */
9934 inst.instruction |= Rd << 8;
9935 inst.instruction |= Rn << 16;
9936 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9937 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9938 inst.instruction |= msb - 1;
9946 Rd = inst.operands[0].reg;
9947 Rn = inst.operands[1].reg;
9949 reject_bad_reg (Rd);
9950 reject_bad_reg (Rn);
9952 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9953 _("bit-field extends past end of register"));
9954 inst.instruction |= Rd << 8;
9955 inst.instruction |= Rn << 16;
9956 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9957 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9958 inst.instruction |= inst.operands[3].imm - 1;
9961 /* ARM V5 Thumb BLX (argument parse)
9962 BLX <target_addr> which is BLX(1)
9963 BLX <Rm> which is BLX(2)
9964 Unfortunately, there are two different opcodes for this mnemonic.
9965 So, the insns[].value is not used, and the code here zaps values
9966 into inst.instruction.
9968 ??? How to take advantage of the additional two bits of displacement
9969 available in Thumb32 mode? Need new relocation? */
9974 set_it_insn_type_last ();
9976 if (inst.operands[0].isreg)
9978 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9979 /* We have a register, so this is BLX(2). */
9980 inst.instruction |= inst.operands[0].reg << 3;
9984 /* No register. This must be BLX(1). */
9985 inst.instruction = 0xf000e800;
9986 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
9998 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10000 if (in_it_block ())
10002 /* Conditional branches inside IT blocks are encoded as unconditional
10004 cond = COND_ALWAYS;
10009 if (cond != COND_ALWAYS)
10010 opcode = T_MNEM_bcond;
10012 opcode = inst.instruction;
10015 && (inst.size_req == 4
10016 || (inst.size_req != 2
10017 && (inst.operands[0].hasreloc
10018 || inst.reloc.exp.X_op == O_constant))))
10020 inst.instruction = THUMB_OP32(opcode);
10021 if (cond == COND_ALWAYS)
10022 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
10025 gas_assert (cond != 0xF);
10026 inst.instruction |= cond << 22;
10027 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
10032 inst.instruction = THUMB_OP16(opcode);
10033 if (cond == COND_ALWAYS)
10034 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
10037 inst.instruction |= cond << 8;
10038 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
10040 /* Allow section relaxation. */
10041 if (unified_syntax && inst.size_req != 2)
10042 inst.relax = opcode;
10044 inst.reloc.type = reloc;
10045 inst.reloc.pc_rel = 1;
10051 constraint (inst.cond != COND_ALWAYS,
10052 _("instruction is always unconditional"));
10053 if (inst.operands[0].present)
10055 constraint (inst.operands[0].imm > 255,
10056 _("immediate value out of range"));
10057 inst.instruction |= inst.operands[0].imm;
10058 set_it_insn_type (NEUTRAL_IT_INSN);
10063 do_t_branch23 (void)
10065 set_it_insn_type_last ();
10066 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
10068 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10069 this file. We used to simply ignore the PLT reloc type here --
10070 the branch encoding is now needed to deal with TLSCALL relocs.
10071 So if we see a PLT reloc now, put it back to how it used to be to
10072 keep the preexisting behaviour. */
10073 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10074 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
10076 #if defined(OBJ_COFF)
10077 /* If the destination of the branch is a defined symbol which does not have
10078 the THUMB_FUNC attribute, then we must be calling a function which has
10079 the (interfacearm) attribute. We look for the Thumb entry point to that
10080 function and change the branch to refer to that function instead. */
10081 if ( inst.reloc.exp.X_op == O_symbol
10082 && inst.reloc.exp.X_add_symbol != NULL
10083 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10084 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10085 inst.reloc.exp.X_add_symbol =
10086 find_real_start (inst.reloc.exp.X_add_symbol);
10093 set_it_insn_type_last ();
10094 inst.instruction |= inst.operands[0].reg << 3;
10095 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10096 should cause the alignment to be checked once it is known. This is
10097 because BX PC only works if the instruction is word aligned. */
10105 set_it_insn_type_last ();
10106 Rm = inst.operands[0].reg;
10107 reject_bad_reg (Rm);
10108 inst.instruction |= Rm << 16;
10117 Rd = inst.operands[0].reg;
10118 Rm = inst.operands[1].reg;
10120 reject_bad_reg (Rd);
10121 reject_bad_reg (Rm);
10123 inst.instruction |= Rd << 8;
10124 inst.instruction |= Rm << 16;
10125 inst.instruction |= Rm;
10131 set_it_insn_type (OUTSIDE_IT_INSN);
10132 inst.instruction |= inst.operands[0].imm;
10138 set_it_insn_type (OUTSIDE_IT_INSN);
10140 && (inst.operands[1].present || inst.size_req == 4)
10141 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
10143 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10144 inst.instruction = 0xf3af8000;
10145 inst.instruction |= imod << 9;
10146 inst.instruction |= inst.operands[0].imm << 5;
10147 if (inst.operands[1].present)
10148 inst.instruction |= 0x100 | inst.operands[1].imm;
10152 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10153 && (inst.operands[0].imm & 4),
10154 _("selected processor does not support 'A' form "
10155 "of this instruction"));
10156 constraint (inst.operands[1].present || inst.size_req == 4,
10157 _("Thumb does not support the 2-argument "
10158 "form of this instruction"));
10159 inst.instruction |= inst.operands[0].imm;
10163 /* THUMB CPY instruction (argument parse). */
10168 if (inst.size_req == 4)
10170 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10171 inst.instruction |= inst.operands[0].reg << 8;
10172 inst.instruction |= inst.operands[1].reg;
10176 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10177 inst.instruction |= (inst.operands[0].reg & 0x7);
10178 inst.instruction |= inst.operands[1].reg << 3;
10185 set_it_insn_type (OUTSIDE_IT_INSN);
10186 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10187 inst.instruction |= inst.operands[0].reg;
10188 inst.reloc.pc_rel = 1;
10189 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10195 inst.instruction |= inst.operands[0].imm;
10201 unsigned Rd, Rn, Rm;
10203 Rd = inst.operands[0].reg;
10204 Rn = (inst.operands[1].present
10205 ? inst.operands[1].reg : Rd);
10206 Rm = inst.operands[2].reg;
10208 reject_bad_reg (Rd);
10209 reject_bad_reg (Rn);
10210 reject_bad_reg (Rm);
10212 inst.instruction |= Rd << 8;
10213 inst.instruction |= Rn << 16;
10214 inst.instruction |= Rm;
10220 if (unified_syntax && inst.size_req == 4)
10221 inst.instruction = THUMB_OP32 (inst.instruction);
10223 inst.instruction = THUMB_OP16 (inst.instruction);
10229 unsigned int cond = inst.operands[0].imm;
10231 set_it_insn_type (IT_INSN);
10232 now_it.mask = (inst.instruction & 0xf) | 0x10;
10235 /* If the condition is a negative condition, invert the mask. */
10236 if ((cond & 0x1) == 0x0)
10238 unsigned int mask = inst.instruction & 0x000f;
10240 if ((mask & 0x7) == 0)
10241 /* no conversion needed */;
10242 else if ((mask & 0x3) == 0)
10244 else if ((mask & 0x1) == 0)
10249 inst.instruction &= 0xfff0;
10250 inst.instruction |= mask;
10253 inst.instruction |= cond << 4;
10256 /* Helper function used for both push/pop and ldm/stm. */
10258 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10262 load = (inst.instruction & (1 << 20)) != 0;
10264 if (mask & (1 << 13))
10265 inst.error = _("SP not allowed in register list");
10267 if ((mask & (1 << base)) != 0
10269 inst.error = _("having the base register in the register list when "
10270 "using write back is UNPREDICTABLE");
10274 if (mask & (1 << 15))
10276 if (mask & (1 << 14))
10277 inst.error = _("LR and PC should not both be in register list");
10279 set_it_insn_type_last ();
10284 if (mask & (1 << 15))
10285 inst.error = _("PC not allowed in register list");
10288 if ((mask & (mask - 1)) == 0)
10290 /* Single register transfers implemented as str/ldr. */
10293 if (inst.instruction & (1 << 23))
10294 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10296 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10300 if (inst.instruction & (1 << 23))
10301 inst.instruction = 0x00800000; /* ia -> [base] */
10303 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10306 inst.instruction |= 0xf8400000;
10308 inst.instruction |= 0x00100000;
10310 mask = ffs (mask) - 1;
10313 else if (writeback)
10314 inst.instruction |= WRITE_BACK;
10316 inst.instruction |= mask;
10317 inst.instruction |= base << 16;
10323 /* This really doesn't seem worth it. */
10324 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10325 _("expression too complex"));
10326 constraint (inst.operands[1].writeback,
10327 _("Thumb load/store multiple does not support {reglist}^"));
10329 if (unified_syntax)
10331 bfd_boolean narrow;
10335 /* See if we can use a 16-bit instruction. */
10336 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10337 && inst.size_req != 4
10338 && !(inst.operands[1].imm & ~0xff))
10340 mask = 1 << inst.operands[0].reg;
10342 if (inst.operands[0].reg <= 7)
10344 if (inst.instruction == T_MNEM_stmia
10345 ? inst.operands[0].writeback
10346 : (inst.operands[0].writeback
10347 == !(inst.operands[1].imm & mask)))
10349 if (inst.instruction == T_MNEM_stmia
10350 && (inst.operands[1].imm & mask)
10351 && (inst.operands[1].imm & (mask - 1)))
10352 as_warn (_("value stored for r%d is UNKNOWN"),
10353 inst.operands[0].reg);
10355 inst.instruction = THUMB_OP16 (inst.instruction);
10356 inst.instruction |= inst.operands[0].reg << 8;
10357 inst.instruction |= inst.operands[1].imm;
10360 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10362 /* This means 1 register in reg list one of 3 situations:
10363 1. Instruction is stmia, but without writeback.
10364 2. lmdia without writeback, but with Rn not in
10366 3. ldmia with writeback, but with Rn in reglist.
10367 Case 3 is UNPREDICTABLE behaviour, so we handle
10368 case 1 and 2 which can be converted into a 16-bit
10369 str or ldr. The SP cases are handled below. */
10370 unsigned long opcode;
10371 /* First, record an error for Case 3. */
10372 if (inst.operands[1].imm & mask
10373 && inst.operands[0].writeback)
10375 _("having the base register in the register list when "
10376 "using write back is UNPREDICTABLE");
10378 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
10380 inst.instruction = THUMB_OP16 (opcode);
10381 inst.instruction |= inst.operands[0].reg << 3;
10382 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10386 else if (inst.operands[0] .reg == REG_SP)
10388 if (inst.operands[0].writeback)
10391 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10392 ? T_MNEM_push : T_MNEM_pop);
10393 inst.instruction |= inst.operands[1].imm;
10396 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10399 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10400 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10401 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10409 if (inst.instruction < 0xffff)
10410 inst.instruction = THUMB_OP32 (inst.instruction);
10412 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10413 inst.operands[0].writeback);
10418 constraint (inst.operands[0].reg > 7
10419 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
10420 constraint (inst.instruction != T_MNEM_ldmia
10421 && inst.instruction != T_MNEM_stmia,
10422 _("Thumb-2 instruction only valid in unified syntax"));
10423 if (inst.instruction == T_MNEM_stmia)
10425 if (!inst.operands[0].writeback)
10426 as_warn (_("this instruction will write back the base register"));
10427 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10428 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
10429 as_warn (_("value stored for r%d is UNKNOWN"),
10430 inst.operands[0].reg);
10434 if (!inst.operands[0].writeback
10435 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10436 as_warn (_("this instruction will write back the base register"));
10437 else if (inst.operands[0].writeback
10438 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10439 as_warn (_("this instruction will not write back the base register"));
10442 inst.instruction = THUMB_OP16 (inst.instruction);
10443 inst.instruction |= inst.operands[0].reg << 8;
10444 inst.instruction |= inst.operands[1].imm;
10451 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10452 || inst.operands[1].postind || inst.operands[1].writeback
10453 || inst.operands[1].immisreg || inst.operands[1].shifted
10454 || inst.operands[1].negative,
10457 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10459 inst.instruction |= inst.operands[0].reg << 12;
10460 inst.instruction |= inst.operands[1].reg << 16;
10461 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10467 if (!inst.operands[1].present)
10469 constraint (inst.operands[0].reg == REG_LR,
10470 _("r14 not allowed as first register "
10471 "when second register is omitted"));
10472 inst.operands[1].reg = inst.operands[0].reg + 1;
10474 constraint (inst.operands[0].reg == inst.operands[1].reg,
10477 inst.instruction |= inst.operands[0].reg << 12;
10478 inst.instruction |= inst.operands[1].reg << 8;
10479 inst.instruction |= inst.operands[2].reg << 16;
10485 unsigned long opcode;
10488 if (inst.operands[0].isreg
10489 && !inst.operands[0].preind
10490 && inst.operands[0].reg == REG_PC)
10491 set_it_insn_type_last ();
10493 opcode = inst.instruction;
10494 if (unified_syntax)
10496 if (!inst.operands[1].isreg)
10498 if (opcode <= 0xffff)
10499 inst.instruction = THUMB_OP32 (opcode);
10500 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10503 if (inst.operands[1].isreg
10504 && !inst.operands[1].writeback
10505 && !inst.operands[1].shifted && !inst.operands[1].postind
10506 && !inst.operands[1].negative && inst.operands[0].reg <= 7
10507 && opcode <= 0xffff
10508 && inst.size_req != 4)
10510 /* Insn may have a 16-bit form. */
10511 Rn = inst.operands[1].reg;
10512 if (inst.operands[1].immisreg)
10514 inst.instruction = THUMB_OP16 (opcode);
10516 if (Rn <= 7 && inst.operands[1].imm <= 7)
10518 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10519 reject_bad_reg (inst.operands[1].imm);
10521 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10522 && opcode != T_MNEM_ldrsb)
10523 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10524 || (Rn == REG_SP && opcode == T_MNEM_str))
10531 if (inst.reloc.pc_rel)
10532 opcode = T_MNEM_ldr_pc2;
10534 opcode = T_MNEM_ldr_pc;
10538 if (opcode == T_MNEM_ldr)
10539 opcode = T_MNEM_ldr_sp;
10541 opcode = T_MNEM_str_sp;
10543 inst.instruction = inst.operands[0].reg << 8;
10547 inst.instruction = inst.operands[0].reg;
10548 inst.instruction |= inst.operands[1].reg << 3;
10550 inst.instruction |= THUMB_OP16 (opcode);
10551 if (inst.size_req == 2)
10552 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10554 inst.relax = opcode;
10558 /* Definitely a 32-bit variant. */
10560 /* Warning for Erratum 752419. */
10561 if (opcode == T_MNEM_ldr
10562 && inst.operands[0].reg == REG_SP
10563 && inst.operands[1].writeback == 1
10564 && !inst.operands[1].immisreg)
10566 if (no_cpu_selected ()
10567 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10568 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10569 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10570 as_warn (_("This instruction may be unpredictable "
10571 "if executed on M-profile cores "
10572 "with interrupts enabled."));
10575 /* Do some validations regarding addressing modes. */
10576 if (inst.operands[1].immisreg)
10577 reject_bad_reg (inst.operands[1].imm);
10579 constraint (inst.operands[1].writeback == 1
10580 && inst.operands[0].reg == inst.operands[1].reg,
10583 inst.instruction = THUMB_OP32 (opcode);
10584 inst.instruction |= inst.operands[0].reg << 12;
10585 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
10586 check_ldr_r15_aligned ();
10590 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10592 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
10594 /* Only [Rn,Rm] is acceptable. */
10595 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10596 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10597 || inst.operands[1].postind || inst.operands[1].shifted
10598 || inst.operands[1].negative,
10599 _("Thumb does not support this addressing mode"));
10600 inst.instruction = THUMB_OP16 (inst.instruction);
10604 inst.instruction = THUMB_OP16 (inst.instruction);
10605 if (!inst.operands[1].isreg)
10606 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10609 constraint (!inst.operands[1].preind
10610 || inst.operands[1].shifted
10611 || inst.operands[1].writeback,
10612 _("Thumb does not support this addressing mode"));
10613 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
10615 constraint (inst.instruction & 0x0600,
10616 _("byte or halfword not valid for base register"));
10617 constraint (inst.operands[1].reg == REG_PC
10618 && !(inst.instruction & THUMB_LOAD_BIT),
10619 _("r15 based store not allowed"));
10620 constraint (inst.operands[1].immisreg,
10621 _("invalid base register for register offset"));
10623 if (inst.operands[1].reg == REG_PC)
10624 inst.instruction = T_OPCODE_LDR_PC;
10625 else if (inst.instruction & THUMB_LOAD_BIT)
10626 inst.instruction = T_OPCODE_LDR_SP;
10628 inst.instruction = T_OPCODE_STR_SP;
10630 inst.instruction |= inst.operands[0].reg << 8;
10631 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10635 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10636 if (!inst.operands[1].immisreg)
10638 /* Immediate offset. */
10639 inst.instruction |= inst.operands[0].reg;
10640 inst.instruction |= inst.operands[1].reg << 3;
10641 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10645 /* Register offset. */
10646 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10647 constraint (inst.operands[1].negative,
10648 _("Thumb does not support this addressing mode"));
10651 switch (inst.instruction)
10653 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10654 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10655 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10656 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10657 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10658 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10659 case 0x5600 /* ldrsb */:
10660 case 0x5e00 /* ldrsh */: break;
10664 inst.instruction |= inst.operands[0].reg;
10665 inst.instruction |= inst.operands[1].reg << 3;
10666 inst.instruction |= inst.operands[1].imm << 6;
10672 if (!inst.operands[1].present)
10674 inst.operands[1].reg = inst.operands[0].reg + 1;
10675 constraint (inst.operands[0].reg == REG_LR,
10676 _("r14 not allowed here"));
10677 constraint (inst.operands[0].reg == REG_R12,
10678 _("r12 not allowed here"));
10681 if (inst.operands[2].writeback
10682 && (inst.operands[0].reg == inst.operands[2].reg
10683 || inst.operands[1].reg == inst.operands[2].reg))
10684 as_warn (_("base register written back, and overlaps "
10685 "one of transfer registers"));
10687 inst.instruction |= inst.operands[0].reg << 12;
10688 inst.instruction |= inst.operands[1].reg << 8;
10689 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
10695 inst.instruction |= inst.operands[0].reg << 12;
10696 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10702 unsigned Rd, Rn, Rm, Ra;
10704 Rd = inst.operands[0].reg;
10705 Rn = inst.operands[1].reg;
10706 Rm = inst.operands[2].reg;
10707 Ra = inst.operands[3].reg;
10709 reject_bad_reg (Rd);
10710 reject_bad_reg (Rn);
10711 reject_bad_reg (Rm);
10712 reject_bad_reg (Ra);
10714 inst.instruction |= Rd << 8;
10715 inst.instruction |= Rn << 16;
10716 inst.instruction |= Rm;
10717 inst.instruction |= Ra << 12;
10723 unsigned RdLo, RdHi, Rn, Rm;
10725 RdLo = inst.operands[0].reg;
10726 RdHi = inst.operands[1].reg;
10727 Rn = inst.operands[2].reg;
10728 Rm = inst.operands[3].reg;
10730 reject_bad_reg (RdLo);
10731 reject_bad_reg (RdHi);
10732 reject_bad_reg (Rn);
10733 reject_bad_reg (Rm);
10735 inst.instruction |= RdLo << 12;
10736 inst.instruction |= RdHi << 8;
10737 inst.instruction |= Rn << 16;
10738 inst.instruction |= Rm;
10742 do_t_mov_cmp (void)
10746 Rn = inst.operands[0].reg;
10747 Rm = inst.operands[1].reg;
10750 set_it_insn_type_last ();
10752 if (unified_syntax)
10754 int r0off = (inst.instruction == T_MNEM_mov
10755 || inst.instruction == T_MNEM_movs) ? 8 : 16;
10756 unsigned long opcode;
10757 bfd_boolean narrow;
10758 bfd_boolean low_regs;
10760 low_regs = (Rn <= 7 && Rm <= 7);
10761 opcode = inst.instruction;
10762 if (in_it_block ())
10763 narrow = opcode != T_MNEM_movs;
10765 narrow = opcode != T_MNEM_movs || low_regs;
10766 if (inst.size_req == 4
10767 || inst.operands[1].shifted)
10770 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10771 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10772 && !inst.operands[1].shifted
10776 inst.instruction = T2_SUBS_PC_LR;
10780 if (opcode == T_MNEM_cmp)
10782 constraint (Rn == REG_PC, BAD_PC);
10785 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10787 warn_deprecated_sp (Rm);
10788 /* R15 was documented as a valid choice for Rm in ARMv6,
10789 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10790 tools reject R15, so we do too. */
10791 constraint (Rm == REG_PC, BAD_PC);
10794 reject_bad_reg (Rm);
10796 else if (opcode == T_MNEM_mov
10797 || opcode == T_MNEM_movs)
10799 if (inst.operands[1].isreg)
10801 if (opcode == T_MNEM_movs)
10803 reject_bad_reg (Rn);
10804 reject_bad_reg (Rm);
10808 /* This is mov.n. */
10809 if ((Rn == REG_SP || Rn == REG_PC)
10810 && (Rm == REG_SP || Rm == REG_PC))
10812 as_warn (_("Use of r%u as a source register is "
10813 "deprecated when r%u is the destination "
10814 "register."), Rm, Rn);
10819 /* This is mov.w. */
10820 constraint (Rn == REG_PC, BAD_PC);
10821 constraint (Rm == REG_PC, BAD_PC);
10822 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10826 reject_bad_reg (Rn);
10829 if (!inst.operands[1].isreg)
10831 /* Immediate operand. */
10832 if (!in_it_block () && opcode == T_MNEM_mov)
10834 if (low_regs && narrow)
10836 inst.instruction = THUMB_OP16 (opcode);
10837 inst.instruction |= Rn << 8;
10838 if (inst.size_req == 2)
10839 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10841 inst.relax = opcode;
10845 inst.instruction = THUMB_OP32 (inst.instruction);
10846 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10847 inst.instruction |= Rn << r0off;
10848 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10851 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10852 && (inst.instruction == T_MNEM_mov
10853 || inst.instruction == T_MNEM_movs))
10855 /* Register shifts are encoded as separate shift instructions. */
10856 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10858 if (in_it_block ())
10863 if (inst.size_req == 4)
10866 if (!low_regs || inst.operands[1].imm > 7)
10872 switch (inst.operands[1].shift_kind)
10875 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10878 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10881 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10884 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10890 inst.instruction = opcode;
10893 inst.instruction |= Rn;
10894 inst.instruction |= inst.operands[1].imm << 3;
10899 inst.instruction |= CONDS_BIT;
10901 inst.instruction |= Rn << 8;
10902 inst.instruction |= Rm << 16;
10903 inst.instruction |= inst.operands[1].imm;
10908 /* Some mov with immediate shift have narrow variants.
10909 Register shifts are handled above. */
10910 if (low_regs && inst.operands[1].shifted
10911 && (inst.instruction == T_MNEM_mov
10912 || inst.instruction == T_MNEM_movs))
10914 if (in_it_block ())
10915 narrow = (inst.instruction == T_MNEM_mov);
10917 narrow = (inst.instruction == T_MNEM_movs);
10922 switch (inst.operands[1].shift_kind)
10924 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10925 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10926 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10927 default: narrow = FALSE; break;
10933 inst.instruction |= Rn;
10934 inst.instruction |= Rm << 3;
10935 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10939 inst.instruction = THUMB_OP32 (inst.instruction);
10940 inst.instruction |= Rn << r0off;
10941 encode_thumb32_shifted_operand (1);
10945 switch (inst.instruction)
10948 /* In v4t or v5t a move of two lowregs produces unpredictable
10949 results. Don't allow this. */
10952 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
10953 "MOV Rd, Rs with two low registers is not "
10954 "permitted on this architecture");
10955 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
10959 inst.instruction = T_OPCODE_MOV_HR;
10960 inst.instruction |= (Rn & 0x8) << 4;
10961 inst.instruction |= (Rn & 0x7);
10962 inst.instruction |= Rm << 3;
10966 /* We know we have low registers at this point.
10967 Generate LSLS Rd, Rs, #0. */
10968 inst.instruction = T_OPCODE_LSL_I;
10969 inst.instruction |= Rn;
10970 inst.instruction |= Rm << 3;
10976 inst.instruction = T_OPCODE_CMP_LR;
10977 inst.instruction |= Rn;
10978 inst.instruction |= Rm << 3;
10982 inst.instruction = T_OPCODE_CMP_HR;
10983 inst.instruction |= (Rn & 0x8) << 4;
10984 inst.instruction |= (Rn & 0x7);
10985 inst.instruction |= Rm << 3;
10992 inst.instruction = THUMB_OP16 (inst.instruction);
10994 /* PR 10443: Do not silently ignore shifted operands. */
10995 constraint (inst.operands[1].shifted,
10996 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10998 if (inst.operands[1].isreg)
11000 if (Rn < 8 && Rm < 8)
11002 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11003 since a MOV instruction produces unpredictable results. */
11004 if (inst.instruction == T_OPCODE_MOV_I8)
11005 inst.instruction = T_OPCODE_ADD_I3;
11007 inst.instruction = T_OPCODE_CMP_LR;
11009 inst.instruction |= Rn;
11010 inst.instruction |= Rm << 3;
11014 if (inst.instruction == T_OPCODE_MOV_I8)
11015 inst.instruction = T_OPCODE_MOV_HR;
11017 inst.instruction = T_OPCODE_CMP_HR;
11023 constraint (Rn > 7,
11024 _("only lo regs allowed with immediate"));
11025 inst.instruction |= Rn << 8;
11026 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11037 top = (inst.instruction & 0x00800000) != 0;
11038 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11040 constraint (top, _(":lower16: not allowed this instruction"));
11041 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11043 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11045 constraint (!top, _(":upper16: not allowed this instruction"));
11046 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11049 Rd = inst.operands[0].reg;
11050 reject_bad_reg (Rd);
11052 inst.instruction |= Rd << 8;
11053 if (inst.reloc.type == BFD_RELOC_UNUSED)
11055 imm = inst.reloc.exp.X_add_number;
11056 inst.instruction |= (imm & 0xf000) << 4;
11057 inst.instruction |= (imm & 0x0800) << 15;
11058 inst.instruction |= (imm & 0x0700) << 4;
11059 inst.instruction |= (imm & 0x00ff);
11064 do_t_mvn_tst (void)
11068 Rn = inst.operands[0].reg;
11069 Rm = inst.operands[1].reg;
11071 if (inst.instruction == T_MNEM_cmp
11072 || inst.instruction == T_MNEM_cmn)
11073 constraint (Rn == REG_PC, BAD_PC);
11075 reject_bad_reg (Rn);
11076 reject_bad_reg (Rm);
11078 if (unified_syntax)
11080 int r0off = (inst.instruction == T_MNEM_mvn
11081 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
11082 bfd_boolean narrow;
11084 if (inst.size_req == 4
11085 || inst.instruction > 0xffff
11086 || inst.operands[1].shifted
11087 || Rn > 7 || Rm > 7)
11089 else if (inst.instruction == T_MNEM_cmn)
11091 else if (THUMB_SETS_FLAGS (inst.instruction))
11092 narrow = !in_it_block ();
11094 narrow = in_it_block ();
11096 if (!inst.operands[1].isreg)
11098 /* For an immediate, we always generate a 32-bit opcode;
11099 section relaxation will shrink it later if possible. */
11100 if (inst.instruction < 0xffff)
11101 inst.instruction = THUMB_OP32 (inst.instruction);
11102 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11103 inst.instruction |= Rn << r0off;
11104 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11108 /* See if we can do this with a 16-bit instruction. */
11111 inst.instruction = THUMB_OP16 (inst.instruction);
11112 inst.instruction |= Rn;
11113 inst.instruction |= Rm << 3;
11117 constraint (inst.operands[1].shifted
11118 && inst.operands[1].immisreg,
11119 _("shift must be constant"));
11120 if (inst.instruction < 0xffff)
11121 inst.instruction = THUMB_OP32 (inst.instruction);
11122 inst.instruction |= Rn << r0off;
11123 encode_thumb32_shifted_operand (1);
11129 constraint (inst.instruction > 0xffff
11130 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11131 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11132 _("unshifted register required"));
11133 constraint (Rn > 7 || Rm > 7,
11136 inst.instruction = THUMB_OP16 (inst.instruction);
11137 inst.instruction |= Rn;
11138 inst.instruction |= Rm << 3;
11147 if (do_vfp_nsyn_mrs () == SUCCESS)
11150 Rd = inst.operands[0].reg;
11151 reject_bad_reg (Rd);
11152 inst.instruction |= Rd << 8;
11154 if (inst.operands[1].isreg)
11156 unsigned br = inst.operands[1].reg;
11157 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11158 as_bad (_("bad register for mrs"));
11160 inst.instruction |= br & (0xf << 16);
11161 inst.instruction |= (br & 0x300) >> 4;
11162 inst.instruction |= (br & SPSR_BIT) >> 2;
11166 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11168 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11169 constraint (flags != 0, _("selected processor does not support "
11170 "requested special purpose register"));
11172 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11174 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11175 _("'APSR', 'CPSR' or 'SPSR' expected"));
11177 inst.instruction |= (flags & SPSR_BIT) >> 2;
11178 inst.instruction |= inst.operands[1].imm & 0xff;
11179 inst.instruction |= 0xf0000;
11189 if (do_vfp_nsyn_msr () == SUCCESS)
11192 constraint (!inst.operands[1].isreg,
11193 _("Thumb encoding does not support an immediate here"));
11195 if (inst.operands[0].isreg)
11196 flags = (int)(inst.operands[0].reg);
11198 flags = inst.operands[0].imm;
11200 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11202 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11204 constraint ((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11205 && (bits & ~(PSR_s | PSR_f)) != 0)
11206 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11208 _("selected processor does not support requested special "
11209 "purpose register"));
11212 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11213 "requested special purpose register"));
11215 Rn = inst.operands[1].reg;
11216 reject_bad_reg (Rn);
11218 inst.instruction |= (flags & SPSR_BIT) >> 2;
11219 inst.instruction |= (flags & 0xf0000) >> 8;
11220 inst.instruction |= (flags & 0x300) >> 4;
11221 inst.instruction |= (flags & 0xff);
11222 inst.instruction |= Rn << 16;
11228 bfd_boolean narrow;
11229 unsigned Rd, Rn, Rm;
11231 if (!inst.operands[2].present)
11232 inst.operands[2].reg = inst.operands[0].reg;
11234 Rd = inst.operands[0].reg;
11235 Rn = inst.operands[1].reg;
11236 Rm = inst.operands[2].reg;
11238 if (unified_syntax)
11240 if (inst.size_req == 4
11246 else if (inst.instruction == T_MNEM_muls)
11247 narrow = !in_it_block ();
11249 narrow = in_it_block ();
11253 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
11254 constraint (Rn > 7 || Rm > 7,
11261 /* 16-bit MULS/Conditional MUL. */
11262 inst.instruction = THUMB_OP16 (inst.instruction);
11263 inst.instruction |= Rd;
11266 inst.instruction |= Rm << 3;
11268 inst.instruction |= Rn << 3;
11270 constraint (1, _("dest must overlap one source register"));
11274 constraint (inst.instruction != T_MNEM_mul,
11275 _("Thumb-2 MUL must not set flags"));
11277 inst.instruction = THUMB_OP32 (inst.instruction);
11278 inst.instruction |= Rd << 8;
11279 inst.instruction |= Rn << 16;
11280 inst.instruction |= Rm << 0;
11282 reject_bad_reg (Rd);
11283 reject_bad_reg (Rn);
11284 reject_bad_reg (Rm);
11291 unsigned RdLo, RdHi, Rn, Rm;
11293 RdLo = inst.operands[0].reg;
11294 RdHi = inst.operands[1].reg;
11295 Rn = inst.operands[2].reg;
11296 Rm = inst.operands[3].reg;
11298 reject_bad_reg (RdLo);
11299 reject_bad_reg (RdHi);
11300 reject_bad_reg (Rn);
11301 reject_bad_reg (Rm);
11303 inst.instruction |= RdLo << 12;
11304 inst.instruction |= RdHi << 8;
11305 inst.instruction |= Rn << 16;
11306 inst.instruction |= Rm;
11309 as_tsktsk (_("rdhi and rdlo must be different"));
11315 set_it_insn_type (NEUTRAL_IT_INSN);
11317 if (unified_syntax)
11319 if (inst.size_req == 4 || inst.operands[0].imm > 15)
11321 inst.instruction = THUMB_OP32 (inst.instruction);
11322 inst.instruction |= inst.operands[0].imm;
11326 /* PR9722: Check for Thumb2 availability before
11327 generating a thumb2 nop instruction. */
11328 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
11330 inst.instruction = THUMB_OP16 (inst.instruction);
11331 inst.instruction |= inst.operands[0].imm << 4;
11334 inst.instruction = 0x46c0;
11339 constraint (inst.operands[0].present,
11340 _("Thumb does not support NOP with hints"));
11341 inst.instruction = 0x46c0;
11348 if (unified_syntax)
11350 bfd_boolean narrow;
11352 if (THUMB_SETS_FLAGS (inst.instruction))
11353 narrow = !in_it_block ();
11355 narrow = in_it_block ();
11356 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11358 if (inst.size_req == 4)
11363 inst.instruction = THUMB_OP32 (inst.instruction);
11364 inst.instruction |= inst.operands[0].reg << 8;
11365 inst.instruction |= inst.operands[1].reg << 16;
11369 inst.instruction = THUMB_OP16 (inst.instruction);
11370 inst.instruction |= inst.operands[0].reg;
11371 inst.instruction |= inst.operands[1].reg << 3;
11376 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11378 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11380 inst.instruction = THUMB_OP16 (inst.instruction);
11381 inst.instruction |= inst.operands[0].reg;
11382 inst.instruction |= inst.operands[1].reg << 3;
11391 Rd = inst.operands[0].reg;
11392 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11394 reject_bad_reg (Rd);
11395 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11396 reject_bad_reg (Rn);
11398 inst.instruction |= Rd << 8;
11399 inst.instruction |= Rn << 16;
11401 if (!inst.operands[2].isreg)
11403 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11404 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11410 Rm = inst.operands[2].reg;
11411 reject_bad_reg (Rm);
11413 constraint (inst.operands[2].shifted
11414 && inst.operands[2].immisreg,
11415 _("shift must be constant"));
11416 encode_thumb32_shifted_operand (2);
11423 unsigned Rd, Rn, Rm;
11425 Rd = inst.operands[0].reg;
11426 Rn = inst.operands[1].reg;
11427 Rm = inst.operands[2].reg;
11429 reject_bad_reg (Rd);
11430 reject_bad_reg (Rn);
11431 reject_bad_reg (Rm);
11433 inst.instruction |= Rd << 8;
11434 inst.instruction |= Rn << 16;
11435 inst.instruction |= Rm;
11436 if (inst.operands[3].present)
11438 unsigned int val = inst.reloc.exp.X_add_number;
11439 constraint (inst.reloc.exp.X_op != O_constant,
11440 _("expression too complex"));
11441 inst.instruction |= (val & 0x1c) << 10;
11442 inst.instruction |= (val & 0x03) << 6;
11449 if (!inst.operands[3].present)
11453 inst.instruction &= ~0x00000020;
11455 /* PR 10168. Swap the Rm and Rn registers. */
11456 Rtmp = inst.operands[1].reg;
11457 inst.operands[1].reg = inst.operands[2].reg;
11458 inst.operands[2].reg = Rtmp;
11466 if (inst.operands[0].immisreg)
11467 reject_bad_reg (inst.operands[0].imm);
11469 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11473 do_t_push_pop (void)
11477 constraint (inst.operands[0].writeback,
11478 _("push/pop do not support {reglist}^"));
11479 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11480 _("expression too complex"));
11482 mask = inst.operands[0].imm;
11483 if ((mask & ~0xff) == 0)
11484 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
11485 else if ((inst.instruction == T_MNEM_push
11486 && (mask & ~0xff) == 1 << REG_LR)
11487 || (inst.instruction == T_MNEM_pop
11488 && (mask & ~0xff) == 1 << REG_PC))
11490 inst.instruction = THUMB_OP16 (inst.instruction);
11491 inst.instruction |= THUMB_PP_PC_LR;
11492 inst.instruction |= mask & 0xff;
11494 else if (unified_syntax)
11496 inst.instruction = THUMB_OP32 (inst.instruction);
11497 encode_thumb2_ldmstm (13, mask, TRUE);
11501 inst.error = _("invalid register list to push/pop instruction");
11511 Rd = inst.operands[0].reg;
11512 Rm = inst.operands[1].reg;
11514 reject_bad_reg (Rd);
11515 reject_bad_reg (Rm);
11517 inst.instruction |= Rd << 8;
11518 inst.instruction |= Rm << 16;
11519 inst.instruction |= Rm;
11527 Rd = inst.operands[0].reg;
11528 Rm = inst.operands[1].reg;
11530 reject_bad_reg (Rd);
11531 reject_bad_reg (Rm);
11533 if (Rd <= 7 && Rm <= 7
11534 && inst.size_req != 4)
11536 inst.instruction = THUMB_OP16 (inst.instruction);
11537 inst.instruction |= Rd;
11538 inst.instruction |= Rm << 3;
11540 else if (unified_syntax)
11542 inst.instruction = THUMB_OP32 (inst.instruction);
11543 inst.instruction |= Rd << 8;
11544 inst.instruction |= Rm << 16;
11545 inst.instruction |= Rm;
11548 inst.error = BAD_HIREG;
11556 Rd = inst.operands[0].reg;
11557 Rm = inst.operands[1].reg;
11559 reject_bad_reg (Rd);
11560 reject_bad_reg (Rm);
11562 inst.instruction |= Rd << 8;
11563 inst.instruction |= Rm;
11571 Rd = inst.operands[0].reg;
11572 Rs = (inst.operands[1].present
11573 ? inst.operands[1].reg /* Rd, Rs, foo */
11574 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11576 reject_bad_reg (Rd);
11577 reject_bad_reg (Rs);
11578 if (inst.operands[2].isreg)
11579 reject_bad_reg (inst.operands[2].reg);
11581 inst.instruction |= Rd << 8;
11582 inst.instruction |= Rs << 16;
11583 if (!inst.operands[2].isreg)
11585 bfd_boolean narrow;
11587 if ((inst.instruction & 0x00100000) != 0)
11588 narrow = !in_it_block ();
11590 narrow = in_it_block ();
11592 if (Rd > 7 || Rs > 7)
11595 if (inst.size_req == 4 || !unified_syntax)
11598 if (inst.reloc.exp.X_op != O_constant
11599 || inst.reloc.exp.X_add_number != 0)
11602 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11603 relaxation, but it doesn't seem worth the hassle. */
11606 inst.reloc.type = BFD_RELOC_UNUSED;
11607 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11608 inst.instruction |= Rs << 3;
11609 inst.instruction |= Rd;
11613 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11614 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11618 encode_thumb32_shifted_operand (2);
11624 set_it_insn_type (OUTSIDE_IT_INSN);
11625 if (inst.operands[0].imm)
11626 inst.instruction |= 0x8;
11632 if (!inst.operands[1].present)
11633 inst.operands[1].reg = inst.operands[0].reg;
11635 if (unified_syntax)
11637 bfd_boolean narrow;
11640 switch (inst.instruction)
11643 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11645 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11647 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11649 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11653 if (THUMB_SETS_FLAGS (inst.instruction))
11654 narrow = !in_it_block ();
11656 narrow = in_it_block ();
11657 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11659 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11661 if (inst.operands[2].isreg
11662 && (inst.operands[1].reg != inst.operands[0].reg
11663 || inst.operands[2].reg > 7))
11665 if (inst.size_req == 4)
11668 reject_bad_reg (inst.operands[0].reg);
11669 reject_bad_reg (inst.operands[1].reg);
11673 if (inst.operands[2].isreg)
11675 reject_bad_reg (inst.operands[2].reg);
11676 inst.instruction = THUMB_OP32 (inst.instruction);
11677 inst.instruction |= inst.operands[0].reg << 8;
11678 inst.instruction |= inst.operands[1].reg << 16;
11679 inst.instruction |= inst.operands[2].reg;
11681 /* PR 12854: Error on extraneous shifts. */
11682 constraint (inst.operands[2].shifted,
11683 _("extraneous shift as part of operand to shift insn"));
11687 inst.operands[1].shifted = 1;
11688 inst.operands[1].shift_kind = shift_kind;
11689 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11690 ? T_MNEM_movs : T_MNEM_mov);
11691 inst.instruction |= inst.operands[0].reg << 8;
11692 encode_thumb32_shifted_operand (1);
11693 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11694 inst.reloc.type = BFD_RELOC_UNUSED;
11699 if (inst.operands[2].isreg)
11701 switch (shift_kind)
11703 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11704 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11705 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11706 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
11710 inst.instruction |= inst.operands[0].reg;
11711 inst.instruction |= inst.operands[2].reg << 3;
11713 /* PR 12854: Error on extraneous shifts. */
11714 constraint (inst.operands[2].shifted,
11715 _("extraneous shift as part of operand to shift insn"));
11719 switch (shift_kind)
11721 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11722 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11723 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11726 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11727 inst.instruction |= inst.operands[0].reg;
11728 inst.instruction |= inst.operands[1].reg << 3;
11734 constraint (inst.operands[0].reg > 7
11735 || inst.operands[1].reg > 7, BAD_HIREG);
11736 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11738 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11740 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11741 constraint (inst.operands[0].reg != inst.operands[1].reg,
11742 _("source1 and dest must be same register"));
11744 switch (inst.instruction)
11746 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11747 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11748 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11749 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11753 inst.instruction |= inst.operands[0].reg;
11754 inst.instruction |= inst.operands[2].reg << 3;
11756 /* PR 12854: Error on extraneous shifts. */
11757 constraint (inst.operands[2].shifted,
11758 _("extraneous shift as part of operand to shift insn"));
11762 switch (inst.instruction)
11764 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11765 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11766 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11767 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11770 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11771 inst.instruction |= inst.operands[0].reg;
11772 inst.instruction |= inst.operands[1].reg << 3;
11780 unsigned Rd, Rn, Rm;
11782 Rd = inst.operands[0].reg;
11783 Rn = inst.operands[1].reg;
11784 Rm = inst.operands[2].reg;
11786 reject_bad_reg (Rd);
11787 reject_bad_reg (Rn);
11788 reject_bad_reg (Rm);
11790 inst.instruction |= Rd << 8;
11791 inst.instruction |= Rn << 16;
11792 inst.instruction |= Rm;
11798 unsigned Rd, Rn, Rm;
11800 Rd = inst.operands[0].reg;
11801 Rm = inst.operands[1].reg;
11802 Rn = inst.operands[2].reg;
11804 reject_bad_reg (Rd);
11805 reject_bad_reg (Rn);
11806 reject_bad_reg (Rm);
11808 inst.instruction |= Rd << 8;
11809 inst.instruction |= Rn << 16;
11810 inst.instruction |= Rm;
11816 unsigned int value = inst.reloc.exp.X_add_number;
11817 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11818 _("SMC is not permitted on this architecture"));
11819 constraint (inst.reloc.exp.X_op != O_constant,
11820 _("expression too complex"));
11821 inst.reloc.type = BFD_RELOC_UNUSED;
11822 inst.instruction |= (value & 0xf000) >> 12;
11823 inst.instruction |= (value & 0x0ff0);
11824 inst.instruction |= (value & 0x000f) << 16;
11830 unsigned int value = inst.reloc.exp.X_add_number;
11832 inst.reloc.type = BFD_RELOC_UNUSED;
11833 inst.instruction |= (value & 0x0fff);
11834 inst.instruction |= (value & 0xf000) << 4;
11838 do_t_ssat_usat (int bias)
11842 Rd = inst.operands[0].reg;
11843 Rn = inst.operands[2].reg;
11845 reject_bad_reg (Rd);
11846 reject_bad_reg (Rn);
11848 inst.instruction |= Rd << 8;
11849 inst.instruction |= inst.operands[1].imm - bias;
11850 inst.instruction |= Rn << 16;
11852 if (inst.operands[3].present)
11854 offsetT shift_amount = inst.reloc.exp.X_add_number;
11856 inst.reloc.type = BFD_RELOC_UNUSED;
11858 constraint (inst.reloc.exp.X_op != O_constant,
11859 _("expression too complex"));
11861 if (shift_amount != 0)
11863 constraint (shift_amount > 31,
11864 _("shift expression is too large"));
11866 if (inst.operands[3].shift_kind == SHIFT_ASR)
11867 inst.instruction |= 0x00200000; /* sh bit. */
11869 inst.instruction |= (shift_amount & 0x1c) << 10;
11870 inst.instruction |= (shift_amount & 0x03) << 6;
11878 do_t_ssat_usat (1);
11886 Rd = inst.operands[0].reg;
11887 Rn = inst.operands[2].reg;
11889 reject_bad_reg (Rd);
11890 reject_bad_reg (Rn);
11892 inst.instruction |= Rd << 8;
11893 inst.instruction |= inst.operands[1].imm - 1;
11894 inst.instruction |= Rn << 16;
11900 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11901 || inst.operands[2].postind || inst.operands[2].writeback
11902 || inst.operands[2].immisreg || inst.operands[2].shifted
11903 || inst.operands[2].negative,
11906 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11908 inst.instruction |= inst.operands[0].reg << 8;
11909 inst.instruction |= inst.operands[1].reg << 12;
11910 inst.instruction |= inst.operands[2].reg << 16;
11911 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11917 if (!inst.operands[2].present)
11918 inst.operands[2].reg = inst.operands[1].reg + 1;
11920 constraint (inst.operands[0].reg == inst.operands[1].reg
11921 || inst.operands[0].reg == inst.operands[2].reg
11922 || inst.operands[0].reg == inst.operands[3].reg,
11925 inst.instruction |= inst.operands[0].reg;
11926 inst.instruction |= inst.operands[1].reg << 12;
11927 inst.instruction |= inst.operands[2].reg << 8;
11928 inst.instruction |= inst.operands[3].reg << 16;
11934 unsigned Rd, Rn, Rm;
11936 Rd = inst.operands[0].reg;
11937 Rn = inst.operands[1].reg;
11938 Rm = inst.operands[2].reg;
11940 reject_bad_reg (Rd);
11941 reject_bad_reg (Rn);
11942 reject_bad_reg (Rm);
11944 inst.instruction |= Rd << 8;
11945 inst.instruction |= Rn << 16;
11946 inst.instruction |= Rm;
11947 inst.instruction |= inst.operands[3].imm << 4;
11955 Rd = inst.operands[0].reg;
11956 Rm = inst.operands[1].reg;
11958 reject_bad_reg (Rd);
11959 reject_bad_reg (Rm);
11961 if (inst.instruction <= 0xffff
11962 && inst.size_req != 4
11963 && Rd <= 7 && Rm <= 7
11964 && (!inst.operands[2].present || inst.operands[2].imm == 0))
11966 inst.instruction = THUMB_OP16 (inst.instruction);
11967 inst.instruction |= Rd;
11968 inst.instruction |= Rm << 3;
11970 else if (unified_syntax)
11972 if (inst.instruction <= 0xffff)
11973 inst.instruction = THUMB_OP32 (inst.instruction);
11974 inst.instruction |= Rd << 8;
11975 inst.instruction |= Rm;
11976 inst.instruction |= inst.operands[2].imm << 4;
11980 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11981 _("Thumb encoding does not support rotation"));
11982 constraint (1, BAD_HIREG);
11989 /* We have to do the following check manually as ARM_EXT_OS only applies
11991 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
11993 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
11994 /* This only applies to the v6m howver, not later architectures. */
11995 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
11996 as_bad (_("SVC is not permitted on this architecture"));
11997 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12000 inst.reloc.type = BFD_RELOC_ARM_SWI;
12009 half = (inst.instruction & 0x10) != 0;
12010 set_it_insn_type_last ();
12011 constraint (inst.operands[0].immisreg,
12012 _("instruction requires register index"));
12014 Rn = inst.operands[0].reg;
12015 Rm = inst.operands[0].imm;
12017 constraint (Rn == REG_SP, BAD_SP);
12018 reject_bad_reg (Rm);
12020 constraint (!half && inst.operands[0].shifted,
12021 _("instruction does not allow shifted index"));
12022 inst.instruction |= (Rn << 16) | Rm;
12028 do_t_ssat_usat (0);
12036 Rd = inst.operands[0].reg;
12037 Rn = inst.operands[2].reg;
12039 reject_bad_reg (Rd);
12040 reject_bad_reg (Rn);
12042 inst.instruction |= Rd << 8;
12043 inst.instruction |= inst.operands[1].imm;
12044 inst.instruction |= Rn << 16;
12047 /* Neon instruction encoder helpers. */
12049 /* Encodings for the different types for various Neon opcodes. */
12051 /* An "invalid" code for the following tables. */
12054 struct neon_tab_entry
12057 unsigned float_or_poly;
12058 unsigned scalar_or_imm;
12061 /* Map overloaded Neon opcodes to their respective encodings. */
12062 #define NEON_ENC_TAB \
12063 X(vabd, 0x0000700, 0x1200d00, N_INV), \
12064 X(vmax, 0x0000600, 0x0000f00, N_INV), \
12065 X(vmin, 0x0000610, 0x0200f00, N_INV), \
12066 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
12067 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
12068 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
12069 X(vadd, 0x0000800, 0x0000d00, N_INV), \
12070 X(vsub, 0x1000800, 0x0200d00, N_INV), \
12071 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
12072 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
12073 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
12074 /* Register variants of the following two instructions are encoded as
12075 vcge / vcgt with the operands reversed. */ \
12076 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
12077 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
12078 X(vfma, N_INV, 0x0000c10, N_INV), \
12079 X(vfms, N_INV, 0x0200c10, N_INV), \
12080 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
12081 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
12082 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
12083 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
12084 X(vmlal, 0x0800800, N_INV, 0x0800240), \
12085 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
12086 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
12087 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
12088 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
12089 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
12090 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
12091 X(vshl, 0x0000400, N_INV, 0x0800510), \
12092 X(vqshl, 0x0000410, N_INV, 0x0800710), \
12093 X(vand, 0x0000110, N_INV, 0x0800030), \
12094 X(vbic, 0x0100110, N_INV, 0x0800030), \
12095 X(veor, 0x1000110, N_INV, N_INV), \
12096 X(vorn, 0x0300110, N_INV, 0x0800010), \
12097 X(vorr, 0x0200110, N_INV, 0x0800010), \
12098 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
12099 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
12100 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
12101 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
12102 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12103 X(vst1, 0x0000000, 0x0800000, N_INV), \
12104 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12105 X(vst2, 0x0000100, 0x0800100, N_INV), \
12106 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12107 X(vst3, 0x0000200, 0x0800200, N_INV), \
12108 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12109 X(vst4, 0x0000300, 0x0800300, N_INV), \
12110 X(vmovn, 0x1b20200, N_INV, N_INV), \
12111 X(vtrn, 0x1b20080, N_INV, N_INV), \
12112 X(vqmovn, 0x1b20200, N_INV, N_INV), \
12113 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12114 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
12115 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12116 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
12117 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12118 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
12119 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12120 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12121 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
12122 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
12126 #define X(OPC,I,F,S) N_MNEM_##OPC
12131 static const struct neon_tab_entry neon_enc_tab[] =
12133 #define X(OPC,I,F,S) { (I), (F), (S) }
12138 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
12139 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12140 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12141 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12142 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12143 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12144 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12145 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12146 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12147 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12148 #define NEON_ENC_SINGLE_(X) \
12149 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
12150 #define NEON_ENC_DOUBLE_(X) \
12151 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
12153 #define NEON_ENCODE(type, inst) \
12156 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12157 inst.is_neon = 1; \
12161 #define check_neon_suffixes \
12164 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12166 as_bad (_("invalid neon suffix for non neon instruction")); \
12172 /* Define shapes for instruction operands. The following mnemonic characters
12173 are used in this table:
12175 F - VFP S<n> register
12176 D - Neon D<n> register
12177 Q - Neon Q<n> register
12181 L - D<n> register list
12183 This table is used to generate various data:
12184 - enumerations of the form NS_DDR to be used as arguments to
12186 - a table classifying shapes into single, double, quad, mixed.
12187 - a table used to drive neon_select_shape. */
12189 #define NEON_SHAPE_DEF \
12190 X(3, (D, D, D), DOUBLE), \
12191 X(3, (Q, Q, Q), QUAD), \
12192 X(3, (D, D, I), DOUBLE), \
12193 X(3, (Q, Q, I), QUAD), \
12194 X(3, (D, D, S), DOUBLE), \
12195 X(3, (Q, Q, S), QUAD), \
12196 X(2, (D, D), DOUBLE), \
12197 X(2, (Q, Q), QUAD), \
12198 X(2, (D, S), DOUBLE), \
12199 X(2, (Q, S), QUAD), \
12200 X(2, (D, R), DOUBLE), \
12201 X(2, (Q, R), QUAD), \
12202 X(2, (D, I), DOUBLE), \
12203 X(2, (Q, I), QUAD), \
12204 X(3, (D, L, D), DOUBLE), \
12205 X(2, (D, Q), MIXED), \
12206 X(2, (Q, D), MIXED), \
12207 X(3, (D, Q, I), MIXED), \
12208 X(3, (Q, D, I), MIXED), \
12209 X(3, (Q, D, D), MIXED), \
12210 X(3, (D, Q, Q), MIXED), \
12211 X(3, (Q, Q, D), MIXED), \
12212 X(3, (Q, D, S), MIXED), \
12213 X(3, (D, Q, S), MIXED), \
12214 X(4, (D, D, D, I), DOUBLE), \
12215 X(4, (Q, Q, Q, I), QUAD), \
12216 X(2, (F, F), SINGLE), \
12217 X(3, (F, F, F), SINGLE), \
12218 X(2, (F, I), SINGLE), \
12219 X(2, (F, D), MIXED), \
12220 X(2, (D, F), MIXED), \
12221 X(3, (F, F, I), MIXED), \
12222 X(4, (R, R, F, F), SINGLE), \
12223 X(4, (F, F, R, R), SINGLE), \
12224 X(3, (D, R, R), DOUBLE), \
12225 X(3, (R, R, D), DOUBLE), \
12226 X(2, (S, R), SINGLE), \
12227 X(2, (R, S), SINGLE), \
12228 X(2, (F, R), SINGLE), \
12229 X(2, (R, F), SINGLE)
12231 #define S2(A,B) NS_##A##B
12232 #define S3(A,B,C) NS_##A##B##C
12233 #define S4(A,B,C,D) NS_##A##B##C##D
12235 #define X(N, L, C) S##N L
12248 enum neon_shape_class
12256 #define X(N, L, C) SC_##C
12258 static enum neon_shape_class neon_shape_class[] =
12276 /* Register widths of above. */
12277 static unsigned neon_shape_el_size[] =
12288 struct neon_shape_info
12291 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12294 #define S2(A,B) { SE_##A, SE_##B }
12295 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12296 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12298 #define X(N, L, C) { N, S##N L }
12300 static struct neon_shape_info neon_shape_tab[] =
12310 /* Bit masks used in type checking given instructions.
12311 'N_EQK' means the type must be the same as (or based on in some way) the key
12312 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12313 set, various other bits can be set as well in order to modify the meaning of
12314 the type constraint. */
12316 enum neon_type_mask
12339 N_KEY = 0x1000000, /* Key element (main type specifier). */
12340 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
12341 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
12342 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12343 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12344 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12345 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12346 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12347 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12348 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
12350 N_MAX_NONSPECIAL = N_F64
12353 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12355 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12356 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12357 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12358 #define N_SUF_32 (N_SU_32 | N_F32)
12359 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12360 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12362 /* Pass this as the first type argument to neon_check_type to ignore types
12364 #define N_IGNORE_TYPE (N_KEY | N_EQK)
12366 /* Select a "shape" for the current instruction (describing register types or
12367 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12368 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12369 function of operand parsing, so this function doesn't need to be called.
12370 Shapes should be listed in order of decreasing length. */
12372 static enum neon_shape
12373 neon_select_shape (enum neon_shape shape, ...)
12376 enum neon_shape first_shape = shape;
12378 /* Fix missing optional operands. FIXME: we don't know at this point how
12379 many arguments we should have, so this makes the assumption that we have
12380 > 1. This is true of all current Neon opcodes, I think, but may not be
12381 true in the future. */
12382 if (!inst.operands[1].present)
12383 inst.operands[1] = inst.operands[0];
12385 va_start (ap, shape);
12387 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
12392 for (j = 0; j < neon_shape_tab[shape].els; j++)
12394 if (!inst.operands[j].present)
12400 switch (neon_shape_tab[shape].el[j])
12403 if (!(inst.operands[j].isreg
12404 && inst.operands[j].isvec
12405 && inst.operands[j].issingle
12406 && !inst.operands[j].isquad))
12411 if (!(inst.operands[j].isreg
12412 && inst.operands[j].isvec
12413 && !inst.operands[j].isquad
12414 && !inst.operands[j].issingle))
12419 if (!(inst.operands[j].isreg
12420 && !inst.operands[j].isvec))
12425 if (!(inst.operands[j].isreg
12426 && inst.operands[j].isvec
12427 && inst.operands[j].isquad
12428 && !inst.operands[j].issingle))
12433 if (!(!inst.operands[j].isreg
12434 && !inst.operands[j].isscalar))
12439 if (!(!inst.operands[j].isreg
12440 && inst.operands[j].isscalar))
12450 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
12451 /* We've matched all the entries in the shape table, and we don't
12452 have any left over operands which have not been matched. */
12458 if (shape == NS_NULL && first_shape != NS_NULL)
12459 first_error (_("invalid instruction shape"));
12464 /* True if SHAPE is predominantly a quadword operation (most of the time, this
12465 means the Q bit should be set). */
12468 neon_quad (enum neon_shape shape)
12470 return neon_shape_class[shape] == SC_QUAD;
12474 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12477 /* Allow modification to be made to types which are constrained to be
12478 based on the key element, based on bits set alongside N_EQK. */
12479 if ((typebits & N_EQK) != 0)
12481 if ((typebits & N_HLF) != 0)
12483 else if ((typebits & N_DBL) != 0)
12485 if ((typebits & N_SGN) != 0)
12486 *g_type = NT_signed;
12487 else if ((typebits & N_UNS) != 0)
12488 *g_type = NT_unsigned;
12489 else if ((typebits & N_INT) != 0)
12490 *g_type = NT_integer;
12491 else if ((typebits & N_FLT) != 0)
12492 *g_type = NT_float;
12493 else if ((typebits & N_SIZ) != 0)
12494 *g_type = NT_untyped;
12498 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12499 operand type, i.e. the single type specified in a Neon instruction when it
12500 is the only one given. */
12502 static struct neon_type_el
12503 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12505 struct neon_type_el dest = *key;
12507 gas_assert ((thisarg & N_EQK) != 0);
12509 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12514 /* Convert Neon type and size into compact bitmask representation. */
12516 static enum neon_type_mask
12517 type_chk_of_el_type (enum neon_el_type type, unsigned size)
12524 case 8: return N_8;
12525 case 16: return N_16;
12526 case 32: return N_32;
12527 case 64: return N_64;
12535 case 8: return N_I8;
12536 case 16: return N_I16;
12537 case 32: return N_I32;
12538 case 64: return N_I64;
12546 case 16: return N_F16;
12547 case 32: return N_F32;
12548 case 64: return N_F64;
12556 case 8: return N_P8;
12557 case 16: return N_P16;
12565 case 8: return N_S8;
12566 case 16: return N_S16;
12567 case 32: return N_S32;
12568 case 64: return N_S64;
12576 case 8: return N_U8;
12577 case 16: return N_U16;
12578 case 32: return N_U32;
12579 case 64: return N_U64;
12590 /* Convert compact Neon bitmask type representation to a type and size. Only
12591 handles the case where a single bit is set in the mask. */
12594 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12595 enum neon_type_mask mask)
12597 if ((mask & N_EQK) != 0)
12600 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12602 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
12604 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
12606 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
12611 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12613 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
12614 *type = NT_unsigned;
12615 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
12616 *type = NT_integer;
12617 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
12618 *type = NT_untyped;
12619 else if ((mask & (N_P8 | N_P16)) != 0)
12621 else if ((mask & (N_F32 | N_F64)) != 0)
12629 /* Modify a bitmask of allowed types. This is only needed for type
12633 modify_types_allowed (unsigned allowed, unsigned mods)
12636 enum neon_el_type type;
12642 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12644 if (el_type_of_type_chk (&type, &size,
12645 (enum neon_type_mask) (allowed & i)) == SUCCESS)
12647 neon_modify_type_size (mods, &type, &size);
12648 destmask |= type_chk_of_el_type (type, size);
12655 /* Check type and return type classification.
12656 The manual states (paraphrase): If one datatype is given, it indicates the
12658 - the second operand, if there is one
12659 - the operand, if there is no second operand
12660 - the result, if there are no operands.
12661 This isn't quite good enough though, so we use a concept of a "key" datatype
12662 which is set on a per-instruction basis, which is the one which matters when
12663 only one data type is written.
12664 Note: this function has side-effects (e.g. filling in missing operands). All
12665 Neon instructions should call it before performing bit encoding. */
12667 static struct neon_type_el
12668 neon_check_type (unsigned els, enum neon_shape ns, ...)
12671 unsigned i, pass, key_el = 0;
12672 unsigned types[NEON_MAX_TYPE_ELS];
12673 enum neon_el_type k_type = NT_invtype;
12674 unsigned k_size = -1u;
12675 struct neon_type_el badtype = {NT_invtype, -1};
12676 unsigned key_allowed = 0;
12678 /* Optional registers in Neon instructions are always (not) in operand 1.
12679 Fill in the missing operand here, if it was omitted. */
12680 if (els > 1 && !inst.operands[1].present)
12681 inst.operands[1] = inst.operands[0];
12683 /* Suck up all the varargs. */
12685 for (i = 0; i < els; i++)
12687 unsigned thisarg = va_arg (ap, unsigned);
12688 if (thisarg == N_IGNORE_TYPE)
12693 types[i] = thisarg;
12694 if ((thisarg & N_KEY) != 0)
12699 if (inst.vectype.elems > 0)
12700 for (i = 0; i < els; i++)
12701 if (inst.operands[i].vectype.type != NT_invtype)
12703 first_error (_("types specified in both the mnemonic and operands"));
12707 /* Duplicate inst.vectype elements here as necessary.
12708 FIXME: No idea if this is exactly the same as the ARM assembler,
12709 particularly when an insn takes one register and one non-register
12711 if (inst.vectype.elems == 1 && els > 1)
12714 inst.vectype.elems = els;
12715 inst.vectype.el[key_el] = inst.vectype.el[0];
12716 for (j = 0; j < els; j++)
12718 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12721 else if (inst.vectype.elems == 0 && els > 0)
12724 /* No types were given after the mnemonic, so look for types specified
12725 after each operand. We allow some flexibility here; as long as the
12726 "key" operand has a type, we can infer the others. */
12727 for (j = 0; j < els; j++)
12728 if (inst.operands[j].vectype.type != NT_invtype)
12729 inst.vectype.el[j] = inst.operands[j].vectype;
12731 if (inst.operands[key_el].vectype.type != NT_invtype)
12733 for (j = 0; j < els; j++)
12734 if (inst.operands[j].vectype.type == NT_invtype)
12735 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12740 first_error (_("operand types can't be inferred"));
12744 else if (inst.vectype.elems != els)
12746 first_error (_("type specifier has the wrong number of parts"));
12750 for (pass = 0; pass < 2; pass++)
12752 for (i = 0; i < els; i++)
12754 unsigned thisarg = types[i];
12755 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12756 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12757 enum neon_el_type g_type = inst.vectype.el[i].type;
12758 unsigned g_size = inst.vectype.el[i].size;
12760 /* Decay more-specific signed & unsigned types to sign-insensitive
12761 integer types if sign-specific variants are unavailable. */
12762 if ((g_type == NT_signed || g_type == NT_unsigned)
12763 && (types_allowed & N_SU_ALL) == 0)
12764 g_type = NT_integer;
12766 /* If only untyped args are allowed, decay any more specific types to
12767 them. Some instructions only care about signs for some element
12768 sizes, so handle that properly. */
12769 if ((g_size == 8 && (types_allowed & N_8) != 0)
12770 || (g_size == 16 && (types_allowed & N_16) != 0)
12771 || (g_size == 32 && (types_allowed & N_32) != 0)
12772 || (g_size == 64 && (types_allowed & N_64) != 0))
12773 g_type = NT_untyped;
12777 if ((thisarg & N_KEY) != 0)
12781 key_allowed = thisarg & ~N_KEY;
12786 if ((thisarg & N_VFP) != 0)
12788 enum neon_shape_el regshape;
12789 unsigned regwidth, match;
12791 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12794 first_error (_("invalid instruction shape"));
12797 regshape = neon_shape_tab[ns].el[i];
12798 regwidth = neon_shape_el_size[regshape];
12800 /* In VFP mode, operands must match register widths. If we
12801 have a key operand, use its width, else use the width of
12802 the current operand. */
12808 if (regwidth != match)
12810 first_error (_("operand size must match register width"));
12815 if ((thisarg & N_EQK) == 0)
12817 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12819 if ((given_type & types_allowed) == 0)
12821 first_error (_("bad type in Neon instruction"));
12827 enum neon_el_type mod_k_type = k_type;
12828 unsigned mod_k_size = k_size;
12829 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12830 if (g_type != mod_k_type || g_size != mod_k_size)
12832 first_error (_("inconsistent types in Neon instruction"));
12840 return inst.vectype.el[key_el];
12843 /* Neon-style VFP instruction forwarding. */
12845 /* Thumb VFP instructions have 0xE in the condition field. */
12848 do_vfp_cond_or_thumb (void)
12853 inst.instruction |= 0xe0000000;
12855 inst.instruction |= inst.cond << 28;
12858 /* Look up and encode a simple mnemonic, for use as a helper function for the
12859 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12860 etc. It is assumed that operand parsing has already been done, and that the
12861 operands are in the form expected by the given opcode (this isn't necessarily
12862 the same as the form in which they were parsed, hence some massaging must
12863 take place before this function is called).
12864 Checks current arch version against that in the looked-up opcode. */
12867 do_vfp_nsyn_opcode (const char *opname)
12869 const struct asm_opcode *opcode;
12871 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
12876 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12877 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12884 inst.instruction = opcode->tvalue;
12885 opcode->tencode ();
12889 inst.instruction = (inst.cond << 28) | opcode->avalue;
12890 opcode->aencode ();
12895 do_vfp_nsyn_add_sub (enum neon_shape rs)
12897 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12902 do_vfp_nsyn_opcode ("fadds");
12904 do_vfp_nsyn_opcode ("fsubs");
12909 do_vfp_nsyn_opcode ("faddd");
12911 do_vfp_nsyn_opcode ("fsubd");
12915 /* Check operand types to see if this is a VFP instruction, and if so call
12919 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12921 enum neon_shape rs;
12922 struct neon_type_el et;
12927 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12928 et = neon_check_type (2, rs,
12929 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12933 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12934 et = neon_check_type (3, rs,
12935 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12942 if (et.type != NT_invtype)
12953 do_vfp_nsyn_mla_mls (enum neon_shape rs)
12955 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
12960 do_vfp_nsyn_opcode ("fmacs");
12962 do_vfp_nsyn_opcode ("fnmacs");
12967 do_vfp_nsyn_opcode ("fmacd");
12969 do_vfp_nsyn_opcode ("fnmacd");
12974 do_vfp_nsyn_fma_fms (enum neon_shape rs)
12976 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12981 do_vfp_nsyn_opcode ("ffmas");
12983 do_vfp_nsyn_opcode ("ffnmas");
12988 do_vfp_nsyn_opcode ("ffmad");
12990 do_vfp_nsyn_opcode ("ffnmad");
12995 do_vfp_nsyn_mul (enum neon_shape rs)
12998 do_vfp_nsyn_opcode ("fmuls");
13000 do_vfp_nsyn_opcode ("fmuld");
13004 do_vfp_nsyn_abs_neg (enum neon_shape rs)
13006 int is_neg = (inst.instruction & 0x80) != 0;
13007 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13012 do_vfp_nsyn_opcode ("fnegs");
13014 do_vfp_nsyn_opcode ("fabss");
13019 do_vfp_nsyn_opcode ("fnegd");
13021 do_vfp_nsyn_opcode ("fabsd");
13025 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13026 insns belong to Neon, and are handled elsewhere. */
13029 do_vfp_nsyn_ldm_stm (int is_dbmode)
13031 int is_ldm = (inst.instruction & (1 << 20)) != 0;
13035 do_vfp_nsyn_opcode ("fldmdbs");
13037 do_vfp_nsyn_opcode ("fldmias");
13042 do_vfp_nsyn_opcode ("fstmdbs");
13044 do_vfp_nsyn_opcode ("fstmias");
13049 do_vfp_nsyn_sqrt (void)
13051 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13052 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13055 do_vfp_nsyn_opcode ("fsqrts");
13057 do_vfp_nsyn_opcode ("fsqrtd");
13061 do_vfp_nsyn_div (void)
13063 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13064 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13065 N_F32 | N_F64 | N_KEY | N_VFP);
13068 do_vfp_nsyn_opcode ("fdivs");
13070 do_vfp_nsyn_opcode ("fdivd");
13074 do_vfp_nsyn_nmul (void)
13076 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13077 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13078 N_F32 | N_F64 | N_KEY | N_VFP);
13082 NEON_ENCODE (SINGLE, inst);
13083 do_vfp_sp_dyadic ();
13087 NEON_ENCODE (DOUBLE, inst);
13088 do_vfp_dp_rd_rn_rm ();
13090 do_vfp_cond_or_thumb ();
13094 do_vfp_nsyn_cmp (void)
13096 if (inst.operands[1].isreg)
13098 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13099 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13103 NEON_ENCODE (SINGLE, inst);
13104 do_vfp_sp_monadic ();
13108 NEON_ENCODE (DOUBLE, inst);
13109 do_vfp_dp_rd_rm ();
13114 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13115 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13117 switch (inst.instruction & 0x0fffffff)
13120 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13123 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13131 NEON_ENCODE (SINGLE, inst);
13132 do_vfp_sp_compare_z ();
13136 NEON_ENCODE (DOUBLE, inst);
13140 do_vfp_cond_or_thumb ();
13144 nsyn_insert_sp (void)
13146 inst.operands[1] = inst.operands[0];
13147 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
13148 inst.operands[0].reg = REG_SP;
13149 inst.operands[0].isreg = 1;
13150 inst.operands[0].writeback = 1;
13151 inst.operands[0].present = 1;
13155 do_vfp_nsyn_push (void)
13158 if (inst.operands[1].issingle)
13159 do_vfp_nsyn_opcode ("fstmdbs");
13161 do_vfp_nsyn_opcode ("fstmdbd");
13165 do_vfp_nsyn_pop (void)
13168 if (inst.operands[1].issingle)
13169 do_vfp_nsyn_opcode ("fldmias");
13171 do_vfp_nsyn_opcode ("fldmiad");
13174 /* Fix up Neon data-processing instructions, ORing in the correct bits for
13175 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13178 neon_dp_fixup (struct arm_it* insn)
13180 unsigned int i = insn->instruction;
13185 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13196 insn->instruction = i;
13199 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13203 neon_logbits (unsigned x)
13205 return ffs (x) - 4;
13208 #define LOW4(R) ((R) & 0xf)
13209 #define HI1(R) (((R) >> 4) & 1)
13211 /* Encode insns with bit pattern:
13213 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13214 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
13216 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13217 different meaning for some instruction. */
13220 neon_three_same (int isquad, int ubit, int size)
13222 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13223 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13224 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13225 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13226 inst.instruction |= LOW4 (inst.operands[2].reg);
13227 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13228 inst.instruction |= (isquad != 0) << 6;
13229 inst.instruction |= (ubit != 0) << 24;
13231 inst.instruction |= neon_logbits (size) << 20;
13233 neon_dp_fixup (&inst);
13236 /* Encode instructions of the form:
13238 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13239 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
13241 Don't write size if SIZE == -1. */
13244 neon_two_same (int qbit, int ubit, int size)
13246 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13247 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13248 inst.instruction |= LOW4 (inst.operands[1].reg);
13249 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13250 inst.instruction |= (qbit != 0) << 6;
13251 inst.instruction |= (ubit != 0) << 24;
13254 inst.instruction |= neon_logbits (size) << 18;
13256 neon_dp_fixup (&inst);
13259 /* Neon instruction encoders, in approximate order of appearance. */
13262 do_neon_dyadic_i_su (void)
13264 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13265 struct neon_type_el et = neon_check_type (3, rs,
13266 N_EQK, N_EQK, N_SU_32 | N_KEY);
13267 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13271 do_neon_dyadic_i64_su (void)
13273 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13274 struct neon_type_el et = neon_check_type (3, rs,
13275 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13276 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13280 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13283 unsigned size = et.size >> 3;
13284 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13285 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13286 inst.instruction |= LOW4 (inst.operands[1].reg);
13287 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13288 inst.instruction |= (isquad != 0) << 6;
13289 inst.instruction |= immbits << 16;
13290 inst.instruction |= (size >> 3) << 7;
13291 inst.instruction |= (size & 0x7) << 19;
13293 inst.instruction |= (uval != 0) << 24;
13295 neon_dp_fixup (&inst);
13299 do_neon_shl_imm (void)
13301 if (!inst.operands[2].isreg)
13303 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13304 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
13305 NEON_ENCODE (IMMED, inst);
13306 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
13310 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13311 struct neon_type_el et = neon_check_type (3, rs,
13312 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
13315 /* VSHL/VQSHL 3-register variants have syntax such as:
13317 whereas other 3-register operations encoded by neon_three_same have
13320 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13322 tmp = inst.operands[2].reg;
13323 inst.operands[2].reg = inst.operands[1].reg;
13324 inst.operands[1].reg = tmp;
13325 NEON_ENCODE (INTEGER, inst);
13326 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13331 do_neon_qshl_imm (void)
13333 if (!inst.operands[2].isreg)
13335 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13336 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13338 NEON_ENCODE (IMMED, inst);
13339 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13340 inst.operands[2].imm);
13344 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13345 struct neon_type_el et = neon_check_type (3, rs,
13346 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
13349 /* See note in do_neon_shl_imm. */
13350 tmp = inst.operands[2].reg;
13351 inst.operands[2].reg = inst.operands[1].reg;
13352 inst.operands[1].reg = tmp;
13353 NEON_ENCODE (INTEGER, inst);
13354 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13359 do_neon_rshl (void)
13361 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13362 struct neon_type_el et = neon_check_type (3, rs,
13363 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13366 tmp = inst.operands[2].reg;
13367 inst.operands[2].reg = inst.operands[1].reg;
13368 inst.operands[1].reg = tmp;
13369 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13373 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13375 /* Handle .I8 pseudo-instructions. */
13378 /* Unfortunately, this will make everything apart from zero out-of-range.
13379 FIXME is this the intended semantics? There doesn't seem much point in
13380 accepting .I8 if so. */
13381 immediate |= immediate << 8;
13387 if (immediate == (immediate & 0x000000ff))
13389 *immbits = immediate;
13392 else if (immediate == (immediate & 0x0000ff00))
13394 *immbits = immediate >> 8;
13397 else if (immediate == (immediate & 0x00ff0000))
13399 *immbits = immediate >> 16;
13402 else if (immediate == (immediate & 0xff000000))
13404 *immbits = immediate >> 24;
13407 if ((immediate & 0xffff) != (immediate >> 16))
13408 goto bad_immediate;
13409 immediate &= 0xffff;
13412 if (immediate == (immediate & 0x000000ff))
13414 *immbits = immediate;
13417 else if (immediate == (immediate & 0x0000ff00))
13419 *immbits = immediate >> 8;
13424 first_error (_("immediate value out of range"));
13428 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13432 neon_bits_same_in_bytes (unsigned imm)
13434 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13435 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13436 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13437 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13440 /* For immediate of above form, return 0bABCD. */
13443 neon_squash_bits (unsigned imm)
13445 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13446 | ((imm & 0x01000000) >> 21);
13449 /* Compress quarter-float representation to 0b...000 abcdefgh. */
13452 neon_qfloat_bits (unsigned imm)
13454 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
13457 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13458 the instruction. *OP is passed as the initial value of the op field, and
13459 may be set to a different value depending on the constant (i.e.
13460 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
13461 MVN). If the immediate looks like a repeated pattern then also
13462 try smaller element sizes. */
13465 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13466 unsigned *immbits, int *op, int size,
13467 enum neon_el_type type)
13469 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13471 if (type == NT_float && !float_p)
13474 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13476 if (size != 32 || *op == 1)
13478 *immbits = neon_qfloat_bits (immlo);
13484 if (neon_bits_same_in_bytes (immhi)
13485 && neon_bits_same_in_bytes (immlo))
13489 *immbits = (neon_squash_bits (immhi) << 4)
13490 | neon_squash_bits (immlo);
13495 if (immhi != immlo)
13501 if (immlo == (immlo & 0x000000ff))
13506 else if (immlo == (immlo & 0x0000ff00))
13508 *immbits = immlo >> 8;
13511 else if (immlo == (immlo & 0x00ff0000))
13513 *immbits = immlo >> 16;
13516 else if (immlo == (immlo & 0xff000000))
13518 *immbits = immlo >> 24;
13521 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13523 *immbits = (immlo >> 8) & 0xff;
13526 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13528 *immbits = (immlo >> 16) & 0xff;
13532 if ((immlo & 0xffff) != (immlo >> 16))
13539 if (immlo == (immlo & 0x000000ff))
13544 else if (immlo == (immlo & 0x0000ff00))
13546 *immbits = immlo >> 8;
13550 if ((immlo & 0xff) != (immlo >> 8))
13555 if (immlo == (immlo & 0x000000ff))
13557 /* Don't allow MVN with 8-bit immediate. */
13567 /* Write immediate bits [7:0] to the following locations:
13569 |28/24|23 19|18 16|15 4|3 0|
13570 | 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|
13572 This function is used by VMOV/VMVN/VORR/VBIC. */
13575 neon_write_immbits (unsigned immbits)
13577 inst.instruction |= immbits & 0xf;
13578 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13579 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13582 /* Invert low-order SIZE bits of XHI:XLO. */
13585 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13587 unsigned immlo = xlo ? *xlo : 0;
13588 unsigned immhi = xhi ? *xhi : 0;
13593 immlo = (~immlo) & 0xff;
13597 immlo = (~immlo) & 0xffff;
13601 immhi = (~immhi) & 0xffffffff;
13602 /* fall through. */
13605 immlo = (~immlo) & 0xffffffff;
13620 do_neon_logic (void)
13622 if (inst.operands[2].present && inst.operands[2].isreg)
13624 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13625 neon_check_type (3, rs, N_IGNORE_TYPE);
13626 /* U bit and size field were set as part of the bitmask. */
13627 NEON_ENCODE (INTEGER, inst);
13628 neon_three_same (neon_quad (rs), 0, -1);
13632 const int three_ops_form = (inst.operands[2].present
13633 && !inst.operands[2].isreg);
13634 const int immoperand = (three_ops_form ? 2 : 1);
13635 enum neon_shape rs = (three_ops_form
13636 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13637 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
13638 struct neon_type_el et = neon_check_type (2, rs,
13639 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13640 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
13644 if (et.type == NT_invtype)
13647 if (three_ops_form)
13648 constraint (inst.operands[0].reg != inst.operands[1].reg,
13649 _("first and second operands shall be the same register"));
13651 NEON_ENCODE (IMMED, inst);
13653 immbits = inst.operands[immoperand].imm;
13656 /* .i64 is a pseudo-op, so the immediate must be a repeating
13658 if (immbits != (inst.operands[immoperand].regisimm ?
13659 inst.operands[immoperand].reg : 0))
13661 /* Set immbits to an invalid constant. */
13662 immbits = 0xdeadbeef;
13669 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13673 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13677 /* Pseudo-instruction for VBIC. */
13678 neon_invert_size (&immbits, 0, et.size);
13679 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13683 /* Pseudo-instruction for VORR. */
13684 neon_invert_size (&immbits, 0, et.size);
13685 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13695 inst.instruction |= neon_quad (rs) << 6;
13696 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13697 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13698 inst.instruction |= cmode << 8;
13699 neon_write_immbits (immbits);
13701 neon_dp_fixup (&inst);
13706 do_neon_bitfield (void)
13708 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13709 neon_check_type (3, rs, N_IGNORE_TYPE);
13710 neon_three_same (neon_quad (rs), 0, -1);
13714 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13717 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13718 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13720 if (et.type == NT_float)
13722 NEON_ENCODE (FLOAT, inst);
13723 neon_three_same (neon_quad (rs), 0, -1);
13727 NEON_ENCODE (INTEGER, inst);
13728 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
13733 do_neon_dyadic_if_su (void)
13735 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13739 do_neon_dyadic_if_su_d (void)
13741 /* This version only allow D registers, but that constraint is enforced during
13742 operand parsing so we don't need to do anything extra here. */
13743 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13747 do_neon_dyadic_if_i_d (void)
13749 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13750 affected if we specify unsigned args. */
13751 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13754 enum vfp_or_neon_is_neon_bits
13757 NEON_CHECK_ARCH = 2
13760 /* Call this function if an instruction which may have belonged to the VFP or
13761 Neon instruction sets, but turned out to be a Neon instruction (due to the
13762 operand types involved, etc.). We have to check and/or fix-up a couple of
13765 - Make sure the user hasn't attempted to make a Neon instruction
13767 - Alter the value in the condition code field if necessary.
13768 - Make sure that the arch supports Neon instructions.
13770 Which of these operations take place depends on bits from enum
13771 vfp_or_neon_is_neon_bits.
13773 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13774 current instruction's condition is COND_ALWAYS, the condition field is
13775 changed to inst.uncond_value. This is necessary because instructions shared
13776 between VFP and Neon may be conditional for the VFP variants only, and the
13777 unconditional Neon version must have, e.g., 0xF in the condition field. */
13780 vfp_or_neon_is_neon (unsigned check)
13782 /* Conditions are always legal in Thumb mode (IT blocks). */
13783 if (!thumb_mode && (check & NEON_CHECK_CC))
13785 if (inst.cond != COND_ALWAYS)
13787 first_error (_(BAD_COND));
13790 if (inst.uncond_value != -1)
13791 inst.instruction |= inst.uncond_value << 28;
13794 if ((check & NEON_CHECK_ARCH)
13795 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13797 first_error (_(BAD_FPU));
13805 do_neon_addsub_if_i (void)
13807 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13810 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13813 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13814 affected if we specify unsigned args. */
13815 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
13818 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13820 V<op> A,B (A is operand 0, B is operand 2)
13825 so handle that case specially. */
13828 neon_exchange_operands (void)
13830 void *scratch = alloca (sizeof (inst.operands[0]));
13831 if (inst.operands[1].present)
13833 /* Swap operands[1] and operands[2]. */
13834 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13835 inst.operands[1] = inst.operands[2];
13836 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13840 inst.operands[1] = inst.operands[2];
13841 inst.operands[2] = inst.operands[0];
13846 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13848 if (inst.operands[2].isreg)
13851 neon_exchange_operands ();
13852 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
13856 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13857 struct neon_type_el et = neon_check_type (2, rs,
13858 N_EQK | N_SIZ, immtypes | N_KEY);
13860 NEON_ENCODE (IMMED, inst);
13861 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13862 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13863 inst.instruction |= LOW4 (inst.operands[1].reg);
13864 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13865 inst.instruction |= neon_quad (rs) << 6;
13866 inst.instruction |= (et.type == NT_float) << 10;
13867 inst.instruction |= neon_logbits (et.size) << 18;
13869 neon_dp_fixup (&inst);
13876 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13880 do_neon_cmp_inv (void)
13882 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13888 neon_compare (N_IF_32, N_IF_32, FALSE);
13891 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
13892 scalars, which are encoded in 5 bits, M : Rm.
13893 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13894 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13898 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13900 unsigned regno = NEON_SCALAR_REG (scalar);
13901 unsigned elno = NEON_SCALAR_INDEX (scalar);
13906 if (regno > 7 || elno > 3)
13908 return regno | (elno << 3);
13911 if (regno > 15 || elno > 1)
13913 return regno | (elno << 4);
13917 first_error (_("scalar out of range for multiply instruction"));
13923 /* Encode multiply / multiply-accumulate scalar instructions. */
13926 neon_mul_mac (struct neon_type_el et, int ubit)
13930 /* Give a more helpful error message if we have an invalid type. */
13931 if (et.type == NT_invtype)
13934 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
13935 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13936 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13937 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13938 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13939 inst.instruction |= LOW4 (scalar);
13940 inst.instruction |= HI1 (scalar) << 5;
13941 inst.instruction |= (et.type == NT_float) << 8;
13942 inst.instruction |= neon_logbits (et.size) << 20;
13943 inst.instruction |= (ubit != 0) << 24;
13945 neon_dp_fixup (&inst);
13949 do_neon_mac_maybe_scalar (void)
13951 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13954 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13957 if (inst.operands[2].isscalar)
13959 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13960 struct neon_type_el et = neon_check_type (3, rs,
13961 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
13962 NEON_ENCODE (SCALAR, inst);
13963 neon_mul_mac (et, neon_quad (rs));
13967 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13968 affected if we specify unsigned args. */
13969 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13974 do_neon_fmac (void)
13976 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13979 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13982 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13988 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13989 struct neon_type_el et = neon_check_type (3, rs,
13990 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
13991 neon_three_same (neon_quad (rs), 0, et.size);
13994 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
13995 same types as the MAC equivalents. The polynomial type for this instruction
13996 is encoded the same as the integer type. */
14001 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14004 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14007 if (inst.operands[2].isscalar)
14008 do_neon_mac_maybe_scalar ();
14010 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
14014 do_neon_qdmulh (void)
14016 if (inst.operands[2].isscalar)
14018 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
14019 struct neon_type_el et = neon_check_type (3, rs,
14020 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
14021 NEON_ENCODE (SCALAR, inst);
14022 neon_mul_mac (et, neon_quad (rs));
14026 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14027 struct neon_type_el et = neon_check_type (3, rs,
14028 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
14029 NEON_ENCODE (INTEGER, inst);
14030 /* The U bit (rounding) comes from bit mask. */
14031 neon_three_same (neon_quad (rs), 0, et.size);
14036 do_neon_fcmp_absolute (void)
14038 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14039 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14040 /* Size field comes from bit mask. */
14041 neon_three_same (neon_quad (rs), 1, -1);
14045 do_neon_fcmp_absolute_inv (void)
14047 neon_exchange_operands ();
14048 do_neon_fcmp_absolute ();
14052 do_neon_step (void)
14054 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14055 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14056 neon_three_same (neon_quad (rs), 0, -1);
14060 do_neon_abs_neg (void)
14062 enum neon_shape rs;
14063 struct neon_type_el et;
14065 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14068 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14071 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14072 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
14074 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14075 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14076 inst.instruction |= LOW4 (inst.operands[1].reg);
14077 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14078 inst.instruction |= neon_quad (rs) << 6;
14079 inst.instruction |= (et.type == NT_float) << 10;
14080 inst.instruction |= neon_logbits (et.size) << 18;
14082 neon_dp_fixup (&inst);
14088 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14089 struct neon_type_el et = neon_check_type (2, rs,
14090 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14091 int imm = inst.operands[2].imm;
14092 constraint (imm < 0 || (unsigned)imm >= et.size,
14093 _("immediate out of range for insert"));
14094 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14100 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14101 struct neon_type_el et = neon_check_type (2, rs,
14102 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14103 int imm = inst.operands[2].imm;
14104 constraint (imm < 1 || (unsigned)imm > et.size,
14105 _("immediate out of range for insert"));
14106 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
14110 do_neon_qshlu_imm (void)
14112 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14113 struct neon_type_el et = neon_check_type (2, rs,
14114 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14115 int imm = inst.operands[2].imm;
14116 constraint (imm < 0 || (unsigned)imm >= et.size,
14117 _("immediate out of range for shift"));
14118 /* Only encodes the 'U present' variant of the instruction.
14119 In this case, signed types have OP (bit 8) set to 0.
14120 Unsigned types have OP set to 1. */
14121 inst.instruction |= (et.type == NT_unsigned) << 8;
14122 /* The rest of the bits are the same as other immediate shifts. */
14123 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14127 do_neon_qmovn (void)
14129 struct neon_type_el et = neon_check_type (2, NS_DQ,
14130 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14131 /* Saturating move where operands can be signed or unsigned, and the
14132 destination has the same signedness. */
14133 NEON_ENCODE (INTEGER, inst);
14134 if (et.type == NT_unsigned)
14135 inst.instruction |= 0xc0;
14137 inst.instruction |= 0x80;
14138 neon_two_same (0, 1, et.size / 2);
14142 do_neon_qmovun (void)
14144 struct neon_type_el et = neon_check_type (2, NS_DQ,
14145 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14146 /* Saturating move with unsigned results. Operands must be signed. */
14147 NEON_ENCODE (INTEGER, inst);
14148 neon_two_same (0, 1, et.size / 2);
14152 do_neon_rshift_sat_narrow (void)
14154 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14155 or unsigned. If operands are unsigned, results must also be unsigned. */
14156 struct neon_type_el et = neon_check_type (2, NS_DQI,
14157 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14158 int imm = inst.operands[2].imm;
14159 /* This gets the bounds check, size encoding and immediate bits calculation
14163 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14164 VQMOVN.I<size> <Dd>, <Qm>. */
14167 inst.operands[2].present = 0;
14168 inst.instruction = N_MNEM_vqmovn;
14173 constraint (imm < 1 || (unsigned)imm > et.size,
14174 _("immediate out of range"));
14175 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14179 do_neon_rshift_sat_narrow_u (void)
14181 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14182 or unsigned. If operands are unsigned, results must also be unsigned. */
14183 struct neon_type_el et = neon_check_type (2, NS_DQI,
14184 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14185 int imm = inst.operands[2].imm;
14186 /* This gets the bounds check, size encoding and immediate bits calculation
14190 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14191 VQMOVUN.I<size> <Dd>, <Qm>. */
14194 inst.operands[2].present = 0;
14195 inst.instruction = N_MNEM_vqmovun;
14200 constraint (imm < 1 || (unsigned)imm > et.size,
14201 _("immediate out of range"));
14202 /* FIXME: The manual is kind of unclear about what value U should have in
14203 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14205 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14209 do_neon_movn (void)
14211 struct neon_type_el et = neon_check_type (2, NS_DQ,
14212 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14213 NEON_ENCODE (INTEGER, inst);
14214 neon_two_same (0, 1, et.size / 2);
14218 do_neon_rshift_narrow (void)
14220 struct neon_type_el et = neon_check_type (2, NS_DQI,
14221 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14222 int imm = inst.operands[2].imm;
14223 /* This gets the bounds check, size encoding and immediate bits calculation
14227 /* If immediate is zero then we are a pseudo-instruction for
14228 VMOVN.I<size> <Dd>, <Qm> */
14231 inst.operands[2].present = 0;
14232 inst.instruction = N_MNEM_vmovn;
14237 constraint (imm < 1 || (unsigned)imm > et.size,
14238 _("immediate out of range for narrowing operation"));
14239 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14243 do_neon_shll (void)
14245 /* FIXME: Type checking when lengthening. */
14246 struct neon_type_el et = neon_check_type (2, NS_QDI,
14247 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14248 unsigned imm = inst.operands[2].imm;
14250 if (imm == et.size)
14252 /* Maximum shift variant. */
14253 NEON_ENCODE (INTEGER, inst);
14254 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14255 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14256 inst.instruction |= LOW4 (inst.operands[1].reg);
14257 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14258 inst.instruction |= neon_logbits (et.size) << 18;
14260 neon_dp_fixup (&inst);
14264 /* A more-specific type check for non-max versions. */
14265 et = neon_check_type (2, NS_QDI,
14266 N_EQK | N_DBL, N_SU_32 | N_KEY);
14267 NEON_ENCODE (IMMED, inst);
14268 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14272 /* Check the various types for the VCVT instruction, and return which version
14273 the current instruction is. */
14276 neon_cvt_flavour (enum neon_shape rs)
14278 #define CVT_VAR(C,X,Y) \
14279 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
14280 if (et.type != NT_invtype) \
14282 inst.error = NULL; \
14285 struct neon_type_el et;
14286 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14287 || rs == NS_FF) ? N_VFP : 0;
14288 /* The instruction versions which take an immediate take one register
14289 argument, which is extended to the width of the full register. Thus the
14290 "source" and "destination" registers must have the same width. Hack that
14291 here by making the size equal to the key (wider, in this case) operand. */
14292 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
14294 CVT_VAR (0, N_S32, N_F32);
14295 CVT_VAR (1, N_U32, N_F32);
14296 CVT_VAR (2, N_F32, N_S32);
14297 CVT_VAR (3, N_F32, N_U32);
14298 /* Half-precision conversions. */
14299 CVT_VAR (4, N_F32, N_F16);
14300 CVT_VAR (5, N_F16, N_F32);
14304 /* VFP instructions. */
14305 CVT_VAR (6, N_F32, N_F64);
14306 CVT_VAR (7, N_F64, N_F32);
14307 CVT_VAR (8, N_S32, N_F64 | key);
14308 CVT_VAR (9, N_U32, N_F64 | key);
14309 CVT_VAR (10, N_F64 | key, N_S32);
14310 CVT_VAR (11, N_F64 | key, N_U32);
14311 /* VFP instructions with bitshift. */
14312 CVT_VAR (12, N_F32 | key, N_S16);
14313 CVT_VAR (13, N_F32 | key, N_U16);
14314 CVT_VAR (14, N_F64 | key, N_S16);
14315 CVT_VAR (15, N_F64 | key, N_U16);
14316 CVT_VAR (16, N_S16, N_F32 | key);
14317 CVT_VAR (17, N_U16, N_F32 | key);
14318 CVT_VAR (18, N_S16, N_F64 | key);
14319 CVT_VAR (19, N_U16, N_F64 | key);
14325 /* Neon-syntax VFP conversions. */
14328 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
14330 const char *opname = 0;
14332 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
14334 /* Conversions with immediate bitshift. */
14335 const char *enc[] =
14359 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14361 opname = enc[flavour];
14362 constraint (inst.operands[0].reg != inst.operands[1].reg,
14363 _("operands 0 and 1 must be the same register"));
14364 inst.operands[1] = inst.operands[2];
14365 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14370 /* Conversions without bitshift. */
14371 const char *enc[] =
14387 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14388 opname = enc[flavour];
14392 do_vfp_nsyn_opcode (opname);
14396 do_vfp_nsyn_cvtz (void)
14398 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14399 int flavour = neon_cvt_flavour (rs);
14400 const char *enc[] =
14414 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14415 do_vfp_nsyn_opcode (enc[flavour]);
14419 do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
14421 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
14422 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
14423 int flavour = neon_cvt_flavour (rs);
14425 /* PR11109: Handle round-to-zero for VCVT conversions. */
14427 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14428 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
14429 && (rs == NS_FD || rs == NS_FF))
14431 do_vfp_nsyn_cvtz ();
14435 /* VFP rather than Neon conversions. */
14438 do_vfp_nsyn_cvt (rs, flavour);
14448 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14450 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14453 /* Fixed-point conversion with #0 immediate is encoded as an
14454 integer conversion. */
14455 if (inst.operands[2].present && inst.operands[2].imm == 0)
14457 immbits = 32 - inst.operands[2].imm;
14458 NEON_ENCODE (IMMED, inst);
14460 inst.instruction |= enctab[flavour];
14461 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14462 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14463 inst.instruction |= LOW4 (inst.operands[1].reg);
14464 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14465 inst.instruction |= neon_quad (rs) << 6;
14466 inst.instruction |= 1 << 21;
14467 inst.instruction |= immbits << 16;
14469 neon_dp_fixup (&inst);
14477 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14479 NEON_ENCODE (INTEGER, inst);
14481 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14485 inst.instruction |= enctab[flavour];
14487 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14488 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14489 inst.instruction |= LOW4 (inst.operands[1].reg);
14490 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14491 inst.instruction |= neon_quad (rs) << 6;
14492 inst.instruction |= 2 << 18;
14494 neon_dp_fixup (&inst);
14498 /* Half-precision conversions for Advanced SIMD -- neon. */
14503 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14505 as_bad (_("operand size must match register width"));
14510 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14512 as_bad (_("operand size must match register width"));
14517 inst.instruction = 0x3b60600;
14519 inst.instruction = 0x3b60700;
14521 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14522 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14523 inst.instruction |= LOW4 (inst.operands[1].reg);
14524 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14525 neon_dp_fixup (&inst);
14529 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14530 do_vfp_nsyn_cvt (rs, flavour);
14535 do_neon_cvtr (void)
14537 do_neon_cvt_1 (FALSE);
14543 do_neon_cvt_1 (TRUE);
14547 do_neon_cvtb (void)
14549 inst.instruction = 0xeb20a40;
14551 /* The sizes are attached to the mnemonic. */
14552 if (inst.vectype.el[0].type != NT_invtype
14553 && inst.vectype.el[0].size == 16)
14554 inst.instruction |= 0x00010000;
14556 /* Programmer's syntax: the sizes are attached to the operands. */
14557 else if (inst.operands[0].vectype.type != NT_invtype
14558 && inst.operands[0].vectype.size == 16)
14559 inst.instruction |= 0x00010000;
14561 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14562 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14563 do_vfp_cond_or_thumb ();
14568 do_neon_cvtt (void)
14571 inst.instruction |= 0x80;
14575 neon_move_immediate (void)
14577 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14578 struct neon_type_el et = neon_check_type (2, rs,
14579 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
14580 unsigned immlo, immhi = 0, immbits;
14581 int op, cmode, float_p;
14583 constraint (et.type == NT_invtype,
14584 _("operand size must be specified for immediate VMOV"));
14586 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14587 op = (inst.instruction & (1 << 5)) != 0;
14589 immlo = inst.operands[1].imm;
14590 if (inst.operands[1].regisimm)
14591 immhi = inst.operands[1].reg;
14593 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14594 _("immediate has bits set outside the operand size"));
14596 float_p = inst.operands[1].immisfloat;
14598 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
14599 et.size, et.type)) == FAIL)
14601 /* Invert relevant bits only. */
14602 neon_invert_size (&immlo, &immhi, et.size);
14603 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14604 with one or the other; those cases are caught by
14605 neon_cmode_for_move_imm. */
14607 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14608 &op, et.size, et.type)) == FAIL)
14610 first_error (_("immediate out of range"));
14615 inst.instruction &= ~(1 << 5);
14616 inst.instruction |= op << 5;
14618 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14619 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14620 inst.instruction |= neon_quad (rs) << 6;
14621 inst.instruction |= cmode << 8;
14623 neon_write_immbits (immbits);
14629 if (inst.operands[1].isreg)
14631 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14633 NEON_ENCODE (INTEGER, inst);
14634 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14635 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14636 inst.instruction |= LOW4 (inst.operands[1].reg);
14637 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14638 inst.instruction |= neon_quad (rs) << 6;
14642 NEON_ENCODE (IMMED, inst);
14643 neon_move_immediate ();
14646 neon_dp_fixup (&inst);
14649 /* Encode instructions of form:
14651 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14652 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
14655 neon_mixed_length (struct neon_type_el et, unsigned size)
14657 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14658 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14659 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14660 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14661 inst.instruction |= LOW4 (inst.operands[2].reg);
14662 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14663 inst.instruction |= (et.type == NT_unsigned) << 24;
14664 inst.instruction |= neon_logbits (size) << 20;
14666 neon_dp_fixup (&inst);
14670 do_neon_dyadic_long (void)
14672 /* FIXME: Type checking for lengthening op. */
14673 struct neon_type_el et = neon_check_type (3, NS_QDD,
14674 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14675 neon_mixed_length (et, et.size);
14679 do_neon_abal (void)
14681 struct neon_type_el et = neon_check_type (3, NS_QDD,
14682 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14683 neon_mixed_length (et, et.size);
14687 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14689 if (inst.operands[2].isscalar)
14691 struct neon_type_el et = neon_check_type (3, NS_QDS,
14692 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
14693 NEON_ENCODE (SCALAR, inst);
14694 neon_mul_mac (et, et.type == NT_unsigned);
14698 struct neon_type_el et = neon_check_type (3, NS_QDD,
14699 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
14700 NEON_ENCODE (INTEGER, inst);
14701 neon_mixed_length (et, et.size);
14706 do_neon_mac_maybe_scalar_long (void)
14708 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14712 do_neon_dyadic_wide (void)
14714 struct neon_type_el et = neon_check_type (3, NS_QQD,
14715 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14716 neon_mixed_length (et, et.size);
14720 do_neon_dyadic_narrow (void)
14722 struct neon_type_el et = neon_check_type (3, NS_QDD,
14723 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
14724 /* Operand sign is unimportant, and the U bit is part of the opcode,
14725 so force the operand type to integer. */
14726 et.type = NT_integer;
14727 neon_mixed_length (et, et.size / 2);
14731 do_neon_mul_sat_scalar_long (void)
14733 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14737 do_neon_vmull (void)
14739 if (inst.operands[2].isscalar)
14740 do_neon_mac_maybe_scalar_long ();
14743 struct neon_type_el et = neon_check_type (3, NS_QDD,
14744 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14745 if (et.type == NT_poly)
14746 NEON_ENCODE (POLY, inst);
14748 NEON_ENCODE (INTEGER, inst);
14749 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14750 zero. Should be OK as-is. */
14751 neon_mixed_length (et, et.size);
14758 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
14759 struct neon_type_el et = neon_check_type (3, rs,
14760 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14761 unsigned imm = (inst.operands[3].imm * et.size) / 8;
14763 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14764 _("shift out of range"));
14765 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14766 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14767 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14768 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14769 inst.instruction |= LOW4 (inst.operands[2].reg);
14770 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14771 inst.instruction |= neon_quad (rs) << 6;
14772 inst.instruction |= imm << 8;
14774 neon_dp_fixup (&inst);
14780 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14781 struct neon_type_el et = neon_check_type (2, rs,
14782 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14783 unsigned op = (inst.instruction >> 7) & 3;
14784 /* N (width of reversed regions) is encoded as part of the bitmask. We
14785 extract it here to check the elements to be reversed are smaller.
14786 Otherwise we'd get a reserved instruction. */
14787 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
14788 gas_assert (elsize != 0);
14789 constraint (et.size >= elsize,
14790 _("elements must be smaller than reversal region"));
14791 neon_two_same (neon_quad (rs), 1, et.size);
14797 if (inst.operands[1].isscalar)
14799 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
14800 struct neon_type_el et = neon_check_type (2, rs,
14801 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14802 unsigned sizebits = et.size >> 3;
14803 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
14804 int logsize = neon_logbits (et.size);
14805 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
14807 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14810 NEON_ENCODE (SCALAR, inst);
14811 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14812 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14813 inst.instruction |= LOW4 (dm);
14814 inst.instruction |= HI1 (dm) << 5;
14815 inst.instruction |= neon_quad (rs) << 6;
14816 inst.instruction |= x << 17;
14817 inst.instruction |= sizebits << 16;
14819 neon_dp_fixup (&inst);
14823 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14824 struct neon_type_el et = neon_check_type (2, rs,
14825 N_8 | N_16 | N_32 | N_KEY, N_EQK);
14826 /* Duplicate ARM register to lanes of vector. */
14827 NEON_ENCODE (ARMREG, inst);
14830 case 8: inst.instruction |= 0x400000; break;
14831 case 16: inst.instruction |= 0x000020; break;
14832 case 32: inst.instruction |= 0x000000; break;
14835 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14836 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14837 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
14838 inst.instruction |= neon_quad (rs) << 21;
14839 /* The encoding for this instruction is identical for the ARM and Thumb
14840 variants, except for the condition field. */
14841 do_vfp_cond_or_thumb ();
14845 /* VMOV has particularly many variations. It can be one of:
14846 0. VMOV<c><q> <Qd>, <Qm>
14847 1. VMOV<c><q> <Dd>, <Dm>
14848 (Register operations, which are VORR with Rm = Rn.)
14849 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14850 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14852 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14853 (ARM register to scalar.)
14854 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14855 (Two ARM registers to vector.)
14856 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14857 (Scalar to ARM register.)
14858 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14859 (Vector to two ARM registers.)
14860 8. VMOV.F32 <Sd>, <Sm>
14861 9. VMOV.F64 <Dd>, <Dm>
14862 (VFP register moves.)
14863 10. VMOV.F32 <Sd>, #imm
14864 11. VMOV.F64 <Dd>, #imm
14865 (VFP float immediate load.)
14866 12. VMOV <Rd>, <Sm>
14867 (VFP single to ARM reg.)
14868 13. VMOV <Sd>, <Rm>
14869 (ARM reg to VFP single.)
14870 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14871 (Two ARM regs to two VFP singles.)
14872 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14873 (Two VFP singles to two ARM regs.)
14875 These cases can be disambiguated using neon_select_shape, except cases 1/9
14876 and 3/11 which depend on the operand type too.
14878 All the encoded bits are hardcoded by this function.
14880 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14881 Cases 5, 7 may be used with VFPv2 and above.
14883 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
14884 can specify a type where it doesn't make sense to, and is ignored). */
14889 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14890 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14892 struct neon_type_el et;
14893 const char *ldconst = 0;
14897 case NS_DD: /* case 1/9. */
14898 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14899 /* It is not an error here if no type is given. */
14901 if (et.type == NT_float && et.size == 64)
14903 do_vfp_nsyn_opcode ("fcpyd");
14906 /* fall through. */
14908 case NS_QQ: /* case 0/1. */
14910 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14912 /* The architecture manual I have doesn't explicitly state which
14913 value the U bit should have for register->register moves, but
14914 the equivalent VORR instruction has U = 0, so do that. */
14915 inst.instruction = 0x0200110;
14916 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14917 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14918 inst.instruction |= LOW4 (inst.operands[1].reg);
14919 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14920 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14921 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14922 inst.instruction |= neon_quad (rs) << 6;
14924 neon_dp_fixup (&inst);
14928 case NS_DI: /* case 3/11. */
14929 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14931 if (et.type == NT_float && et.size == 64)
14933 /* case 11 (fconstd). */
14934 ldconst = "fconstd";
14935 goto encode_fconstd;
14937 /* fall through. */
14939 case NS_QI: /* case 2/3. */
14940 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14942 inst.instruction = 0x0800010;
14943 neon_move_immediate ();
14944 neon_dp_fixup (&inst);
14947 case NS_SR: /* case 4. */
14949 unsigned bcdebits = 0;
14951 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14952 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14954 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14955 logsize = neon_logbits (et.size);
14957 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14959 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14960 && et.size != 32, _(BAD_FPU));
14961 constraint (et.type == NT_invtype, _("bad type for scalar"));
14962 constraint (x >= 64 / et.size, _("scalar index out of range"));
14966 case 8: bcdebits = 0x8; break;
14967 case 16: bcdebits = 0x1; break;
14968 case 32: bcdebits = 0x0; break;
14972 bcdebits |= x << logsize;
14974 inst.instruction = 0xe000b10;
14975 do_vfp_cond_or_thumb ();
14976 inst.instruction |= LOW4 (dn) << 16;
14977 inst.instruction |= HI1 (dn) << 7;
14978 inst.instruction |= inst.operands[1].reg << 12;
14979 inst.instruction |= (bcdebits & 3) << 5;
14980 inst.instruction |= (bcdebits >> 2) << 21;
14984 case NS_DRR: /* case 5 (fmdrr). */
14985 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14988 inst.instruction = 0xc400b10;
14989 do_vfp_cond_or_thumb ();
14990 inst.instruction |= LOW4 (inst.operands[0].reg);
14991 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14992 inst.instruction |= inst.operands[1].reg << 12;
14993 inst.instruction |= inst.operands[2].reg << 16;
14996 case NS_RS: /* case 6. */
14999 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15000 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15001 unsigned abcdebits = 0;
15003 et = neon_check_type (2, NS_NULL,
15004 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
15005 logsize = neon_logbits (et.size);
15007 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15009 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15010 && et.size != 32, _(BAD_FPU));
15011 constraint (et.type == NT_invtype, _("bad type for scalar"));
15012 constraint (x >= 64 / et.size, _("scalar index out of range"));
15016 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15017 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15018 case 32: abcdebits = 0x00; break;
15022 abcdebits |= x << logsize;
15023 inst.instruction = 0xe100b10;
15024 do_vfp_cond_or_thumb ();
15025 inst.instruction |= LOW4 (dn) << 16;
15026 inst.instruction |= HI1 (dn) << 7;
15027 inst.instruction |= inst.operands[0].reg << 12;
15028 inst.instruction |= (abcdebits & 3) << 5;
15029 inst.instruction |= (abcdebits >> 2) << 21;
15033 case NS_RRD: /* case 7 (fmrrd). */
15034 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15037 inst.instruction = 0xc500b10;
15038 do_vfp_cond_or_thumb ();
15039 inst.instruction |= inst.operands[0].reg << 12;
15040 inst.instruction |= inst.operands[1].reg << 16;
15041 inst.instruction |= LOW4 (inst.operands[2].reg);
15042 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15045 case NS_FF: /* case 8 (fcpys). */
15046 do_vfp_nsyn_opcode ("fcpys");
15049 case NS_FI: /* case 10 (fconsts). */
15050 ldconst = "fconsts";
15052 if (is_quarter_float (inst.operands[1].imm))
15054 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
15055 do_vfp_nsyn_opcode (ldconst);
15058 first_error (_("immediate out of range"));
15061 case NS_RF: /* case 12 (fmrs). */
15062 do_vfp_nsyn_opcode ("fmrs");
15065 case NS_FR: /* case 13 (fmsr). */
15066 do_vfp_nsyn_opcode ("fmsr");
15069 /* The encoders for the fmrrs and fmsrr instructions expect three operands
15070 (one of which is a list), but we have parsed four. Do some fiddling to
15071 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
15073 case NS_RRFF: /* case 14 (fmrrs). */
15074 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
15075 _("VFP registers must be adjacent"));
15076 inst.operands[2].imm = 2;
15077 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15078 do_vfp_nsyn_opcode ("fmrrs");
15081 case NS_FFRR: /* case 15 (fmsrr). */
15082 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
15083 _("VFP registers must be adjacent"));
15084 inst.operands[1] = inst.operands[2];
15085 inst.operands[2] = inst.operands[3];
15086 inst.operands[0].imm = 2;
15087 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15088 do_vfp_nsyn_opcode ("fmsrr");
15097 do_neon_rshift_round_imm (void)
15099 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15100 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15101 int imm = inst.operands[2].imm;
15103 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
15106 inst.operands[2].present = 0;
15111 constraint (imm < 1 || (unsigned)imm > et.size,
15112 _("immediate out of range for shift"));
15113 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
15118 do_neon_movl (void)
15120 struct neon_type_el et = neon_check_type (2, NS_QD,
15121 N_EQK | N_DBL, N_SU_32 | N_KEY);
15122 unsigned sizebits = et.size >> 3;
15123 inst.instruction |= sizebits << 19;
15124 neon_two_same (0, et.type == NT_unsigned, -1);
15130 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15131 struct neon_type_el et = neon_check_type (2, rs,
15132 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15133 NEON_ENCODE (INTEGER, inst);
15134 neon_two_same (neon_quad (rs), 1, et.size);
15138 do_neon_zip_uzp (void)
15140 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15141 struct neon_type_el et = neon_check_type (2, rs,
15142 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15143 if (rs == NS_DD && et.size == 32)
15145 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
15146 inst.instruction = N_MNEM_vtrn;
15150 neon_two_same (neon_quad (rs), 1, et.size);
15154 do_neon_sat_abs_neg (void)
15156 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15157 struct neon_type_el et = neon_check_type (2, rs,
15158 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
15159 neon_two_same (neon_quad (rs), 1, et.size);
15163 do_neon_pair_long (void)
15165 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15166 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15167 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15168 inst.instruction |= (et.type == NT_unsigned) << 7;
15169 neon_two_same (neon_quad (rs), 1, et.size);
15173 do_neon_recip_est (void)
15175 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15176 struct neon_type_el et = neon_check_type (2, rs,
15177 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15178 inst.instruction |= (et.type == NT_float) << 8;
15179 neon_two_same (neon_quad (rs), 1, et.size);
15185 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15186 struct neon_type_el et = neon_check_type (2, rs,
15187 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
15188 neon_two_same (neon_quad (rs), 1, et.size);
15194 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15195 struct neon_type_el et = neon_check_type (2, rs,
15196 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
15197 neon_two_same (neon_quad (rs), 1, et.size);
15203 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15204 struct neon_type_el et = neon_check_type (2, rs,
15205 N_EQK | N_INT, N_8 | N_KEY);
15206 neon_two_same (neon_quad (rs), 1, et.size);
15212 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15213 neon_two_same (neon_quad (rs), 1, -1);
15217 do_neon_tbl_tbx (void)
15219 unsigned listlenbits;
15220 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
15222 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15224 first_error (_("bad list length for table lookup"));
15228 listlenbits = inst.operands[1].imm - 1;
15229 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15230 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15231 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15232 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15233 inst.instruction |= LOW4 (inst.operands[2].reg);
15234 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15235 inst.instruction |= listlenbits << 8;
15237 neon_dp_fixup (&inst);
15241 do_neon_ldm_stm (void)
15243 /* P, U and L bits are part of bitmask. */
15244 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15245 unsigned offsetbits = inst.operands[1].imm * 2;
15247 if (inst.operands[1].issingle)
15249 do_vfp_nsyn_ldm_stm (is_dbmode);
15253 constraint (is_dbmode && !inst.operands[0].writeback,
15254 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15256 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15257 _("register list must contain at least 1 and at most 16 "
15260 inst.instruction |= inst.operands[0].reg << 16;
15261 inst.instruction |= inst.operands[0].writeback << 21;
15262 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15263 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15265 inst.instruction |= offsetbits;
15267 do_vfp_cond_or_thumb ();
15271 do_neon_ldr_str (void)
15273 int is_ldr = (inst.instruction & (1 << 20)) != 0;
15275 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15276 And is UNPREDICTABLE in thumb mode. */
15278 && inst.operands[1].reg == REG_PC
15279 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15281 if (!thumb_mode && warn_on_deprecated)
15282 as_warn (_("Use of PC here is deprecated"));
15284 inst.error = _("Use of PC here is UNPREDICTABLE");
15287 if (inst.operands[0].issingle)
15290 do_vfp_nsyn_opcode ("flds");
15292 do_vfp_nsyn_opcode ("fsts");
15297 do_vfp_nsyn_opcode ("fldd");
15299 do_vfp_nsyn_opcode ("fstd");
15303 /* "interleave" version also handles non-interleaving register VLD1/VST1
15307 do_neon_ld_st_interleave (void)
15309 struct neon_type_el et = neon_check_type (1, NS_NULL,
15310 N_8 | N_16 | N_32 | N_64);
15311 unsigned alignbits = 0;
15313 /* The bits in this table go:
15314 0: register stride of one (0) or two (1)
15315 1,2: register list length, minus one (1, 2, 3, 4).
15316 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15317 We use -1 for invalid entries. */
15318 const int typetable[] =
15320 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15321 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15322 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15323 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15327 if (et.type == NT_invtype)
15330 if (inst.operands[1].immisalign)
15331 switch (inst.operands[1].imm >> 8)
15333 case 64: alignbits = 1; break;
15335 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15336 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15337 goto bad_alignment;
15341 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15342 goto bad_alignment;
15347 first_error (_("bad alignment"));
15351 inst.instruction |= alignbits << 4;
15352 inst.instruction |= neon_logbits (et.size) << 6;
15354 /* Bits [4:6] of the immediate in a list specifier encode register stride
15355 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15356 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15357 up the right value for "type" in a table based on this value and the given
15358 list style, then stick it back. */
15359 idx = ((inst.operands[0].imm >> 4) & 7)
15360 | (((inst.instruction >> 8) & 3) << 3);
15362 typebits = typetable[idx];
15364 constraint (typebits == -1, _("bad list type for instruction"));
15366 inst.instruction &= ~0xf00;
15367 inst.instruction |= typebits << 8;
15370 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15371 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15372 otherwise. The variable arguments are a list of pairs of legal (size, align)
15373 values, terminated with -1. */
15376 neon_alignment_bit (int size, int align, int *do_align, ...)
15379 int result = FAIL, thissize, thisalign;
15381 if (!inst.operands[1].immisalign)
15387 va_start (ap, do_align);
15391 thissize = va_arg (ap, int);
15392 if (thissize == -1)
15394 thisalign = va_arg (ap, int);
15396 if (size == thissize && align == thisalign)
15399 while (result != SUCCESS);
15403 if (result == SUCCESS)
15406 first_error (_("unsupported alignment for instruction"));
15412 do_neon_ld_st_lane (void)
15414 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15415 int align_good, do_align = 0;
15416 int logsize = neon_logbits (et.size);
15417 int align = inst.operands[1].imm >> 8;
15418 int n = (inst.instruction >> 8) & 3;
15419 int max_el = 64 / et.size;
15421 if (et.type == NT_invtype)
15424 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15425 _("bad list length"));
15426 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15427 _("scalar index out of range"));
15428 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15430 _("stride of 2 unavailable when element size is 8"));
15434 case 0: /* VLD1 / VST1. */
15435 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15437 if (align_good == FAIL)
15441 unsigned alignbits = 0;
15444 case 16: alignbits = 0x1; break;
15445 case 32: alignbits = 0x3; break;
15448 inst.instruction |= alignbits << 4;
15452 case 1: /* VLD2 / VST2. */
15453 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15455 if (align_good == FAIL)
15458 inst.instruction |= 1 << 4;
15461 case 2: /* VLD3 / VST3. */
15462 constraint (inst.operands[1].immisalign,
15463 _("can't use alignment with this instruction"));
15466 case 3: /* VLD4 / VST4. */
15467 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15468 16, 64, 32, 64, 32, 128, -1);
15469 if (align_good == FAIL)
15473 unsigned alignbits = 0;
15476 case 8: alignbits = 0x1; break;
15477 case 16: alignbits = 0x1; break;
15478 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15481 inst.instruction |= alignbits << 4;
15488 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15489 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15490 inst.instruction |= 1 << (4 + logsize);
15492 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15493 inst.instruction |= logsize << 10;
15496 /* Encode single n-element structure to all lanes VLD<n> instructions. */
15499 do_neon_ld_dup (void)
15501 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15502 int align_good, do_align = 0;
15504 if (et.type == NT_invtype)
15507 switch ((inst.instruction >> 8) & 3)
15509 case 0: /* VLD1. */
15510 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
15511 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15512 &do_align, 16, 16, 32, 32, -1);
15513 if (align_good == FAIL)
15515 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15518 case 2: inst.instruction |= 1 << 5; break;
15519 default: first_error (_("bad list length")); return;
15521 inst.instruction |= neon_logbits (et.size) << 6;
15524 case 1: /* VLD2. */
15525 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15526 &do_align, 8, 16, 16, 32, 32, 64, -1);
15527 if (align_good == FAIL)
15529 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15530 _("bad list length"));
15531 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15532 inst.instruction |= 1 << 5;
15533 inst.instruction |= neon_logbits (et.size) << 6;
15536 case 2: /* VLD3. */
15537 constraint (inst.operands[1].immisalign,
15538 _("can't use alignment with this instruction"));
15539 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15540 _("bad list length"));
15541 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15542 inst.instruction |= 1 << 5;
15543 inst.instruction |= neon_logbits (et.size) << 6;
15546 case 3: /* VLD4. */
15548 int align = inst.operands[1].imm >> 8;
15549 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15550 16, 64, 32, 64, 32, 128, -1);
15551 if (align_good == FAIL)
15553 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15554 _("bad list length"));
15555 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15556 inst.instruction |= 1 << 5;
15557 if (et.size == 32 && align == 128)
15558 inst.instruction |= 0x3 << 6;
15560 inst.instruction |= neon_logbits (et.size) << 6;
15567 inst.instruction |= do_align << 4;
15570 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15571 apart from bits [11:4]. */
15574 do_neon_ldx_stx (void)
15576 if (inst.operands[1].isreg)
15577 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15579 switch (NEON_LANE (inst.operands[0].imm))
15581 case NEON_INTERLEAVE_LANES:
15582 NEON_ENCODE (INTERLV, inst);
15583 do_neon_ld_st_interleave ();
15586 case NEON_ALL_LANES:
15587 NEON_ENCODE (DUP, inst);
15592 NEON_ENCODE (LANE, inst);
15593 do_neon_ld_st_lane ();
15596 /* L bit comes from bit mask. */
15597 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15598 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15599 inst.instruction |= inst.operands[1].reg << 16;
15601 if (inst.operands[1].postind)
15603 int postreg = inst.operands[1].imm & 0xf;
15604 constraint (!inst.operands[1].immisreg,
15605 _("post-index must be a register"));
15606 constraint (postreg == 0xd || postreg == 0xf,
15607 _("bad register for post-index"));
15608 inst.instruction |= postreg;
15610 else if (inst.operands[1].writeback)
15612 inst.instruction |= 0xd;
15615 inst.instruction |= 0xf;
15618 inst.instruction |= 0xf9000000;
15620 inst.instruction |= 0xf4000000;
15623 /* Overall per-instruction processing. */
15625 /* We need to be able to fix up arbitrary expressions in some statements.
15626 This is so that we can handle symbols that are an arbitrary distance from
15627 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15628 which returns part of an address in a form which will be valid for
15629 a data instruction. We do this by pushing the expression into a symbol
15630 in the expr_section, and creating a fix for that. */
15633 fix_new_arm (fragS * frag,
15647 /* Create an absolute valued symbol, so we have something to
15648 refer to in the object file. Unfortunately for us, gas's
15649 generic expression parsing will already have folded out
15650 any use of .set foo/.type foo %function that may have
15651 been used to set type information of the target location,
15652 that's being specified symbolically. We have to presume
15653 the user knows what they are doing. */
15657 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
15659 symbol = symbol_find_or_make (name);
15660 S_SET_SEGMENT (symbol, absolute_section);
15661 symbol_set_frag (symbol, &zero_address_frag);
15662 S_SET_VALUE (symbol, exp->X_add_number);
15663 exp->X_op = O_symbol;
15664 exp->X_add_symbol = symbol;
15665 exp->X_add_number = 0;
15671 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15672 (enum bfd_reloc_code_real) reloc);
15676 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15677 pc_rel, (enum bfd_reloc_code_real) reloc);
15681 /* Mark whether the fix is to a THUMB instruction, or an ARM
15683 new_fix->tc_fix_data = thumb_mode;
15686 /* Create a frg for an instruction requiring relaxation. */
15688 output_relax_insn (void)
15694 /* The size of the instruction is unknown, so tie the debug info to the
15695 start of the instruction. */
15696 dwarf2_emit_insn (0);
15698 switch (inst.reloc.exp.X_op)
15701 sym = inst.reloc.exp.X_add_symbol;
15702 offset = inst.reloc.exp.X_add_number;
15706 offset = inst.reloc.exp.X_add_number;
15709 sym = make_expr_symbol (&inst.reloc.exp);
15713 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15714 inst.relax, sym, offset, NULL/*offset, opcode*/);
15715 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
15718 /* Write a 32-bit thumb instruction to buf. */
15720 put_thumb32_insn (char * buf, unsigned long insn)
15722 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15723 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15727 output_inst (const char * str)
15733 as_bad ("%s -- `%s'", inst.error, str);
15738 output_relax_insn ();
15741 if (inst.size == 0)
15744 to = frag_more (inst.size);
15745 /* PR 9814: Record the thumb mode into the current frag so that we know
15746 what type of NOP padding to use, if necessary. We override any previous
15747 setting so that if the mode has changed then the NOPS that we use will
15748 match the encoding of the last instruction in the frag. */
15749 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
15751 if (thumb_mode && (inst.size > THUMB_SIZE))
15753 gas_assert (inst.size == (2 * THUMB_SIZE));
15754 put_thumb32_insn (to, inst.instruction);
15756 else if (inst.size > INSN_SIZE)
15758 gas_assert (inst.size == (2 * INSN_SIZE));
15759 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15760 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
15763 md_number_to_chars (to, inst.instruction, inst.size);
15765 if (inst.reloc.type != BFD_RELOC_UNUSED)
15766 fix_new_arm (frag_now, to - frag_now->fr_literal,
15767 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15770 dwarf2_emit_insn (inst.size);
15774 output_it_inst (int cond, int mask, char * to)
15776 unsigned long instruction = 0xbf00;
15779 instruction |= mask;
15780 instruction |= cond << 4;
15784 to = frag_more (2);
15786 dwarf2_emit_insn (2);
15790 md_number_to_chars (to, instruction, 2);
15795 /* Tag values used in struct asm_opcode's tag field. */
15798 OT_unconditional, /* Instruction cannot be conditionalized.
15799 The ARM condition field is still 0xE. */
15800 OT_unconditionalF, /* Instruction cannot be conditionalized
15801 and carries 0xF in its ARM condition field. */
15802 OT_csuffix, /* Instruction takes a conditional suffix. */
15803 OT_csuffixF, /* Some forms of the instruction take a conditional
15804 suffix, others place 0xF where the condition field
15806 OT_cinfix3, /* Instruction takes a conditional infix,
15807 beginning at character index 3. (In
15808 unified mode, it becomes a suffix.) */
15809 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15810 tsts, cmps, cmns, and teqs. */
15811 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15812 character index 3, even in unified mode. Used for
15813 legacy instructions where suffix and infix forms
15814 may be ambiguous. */
15815 OT_csuf_or_in3, /* Instruction takes either a conditional
15816 suffix or an infix at character index 3. */
15817 OT_odd_infix_unc, /* This is the unconditional variant of an
15818 instruction that takes a conditional infix
15819 at an unusual position. In unified mode,
15820 this variant will accept a suffix. */
15821 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15822 are the conditional variants of instructions that
15823 take conditional infixes in unusual positions.
15824 The infix appears at character index
15825 (tag - OT_odd_infix_0). These are not accepted
15826 in unified mode. */
15829 /* Subroutine of md_assemble, responsible for looking up the primary
15830 opcode from the mnemonic the user wrote. STR points to the
15831 beginning of the mnemonic.
15833 This is not simply a hash table lookup, because of conditional
15834 variants. Most instructions have conditional variants, which are
15835 expressed with a _conditional affix_ to the mnemonic. If we were
15836 to encode each conditional variant as a literal string in the opcode
15837 table, it would have approximately 20,000 entries.
15839 Most mnemonics take this affix as a suffix, and in unified syntax,
15840 'most' is upgraded to 'all'. However, in the divided syntax, some
15841 instructions take the affix as an infix, notably the s-variants of
15842 the arithmetic instructions. Of those instructions, all but six
15843 have the infix appear after the third character of the mnemonic.
15845 Accordingly, the algorithm for looking up primary opcodes given
15848 1. Look up the identifier in the opcode table.
15849 If we find a match, go to step U.
15851 2. Look up the last two characters of the identifier in the
15852 conditions table. If we find a match, look up the first N-2
15853 characters of the identifier in the opcode table. If we
15854 find a match, go to step CE.
15856 3. Look up the fourth and fifth characters of the identifier in
15857 the conditions table. If we find a match, extract those
15858 characters from the identifier, and look up the remaining
15859 characters in the opcode table. If we find a match, go
15864 U. Examine the tag field of the opcode structure, in case this is
15865 one of the six instructions with its conditional infix in an
15866 unusual place. If it is, the tag tells us where to find the
15867 infix; look it up in the conditions table and set inst.cond
15868 accordingly. Otherwise, this is an unconditional instruction.
15869 Again set inst.cond accordingly. Return the opcode structure.
15871 CE. Examine the tag field to make sure this is an instruction that
15872 should receive a conditional suffix. If it is not, fail.
15873 Otherwise, set inst.cond from the suffix we already looked up,
15874 and return the opcode structure.
15876 CM. Examine the tag field to make sure this is an instruction that
15877 should receive a conditional infix after the third character.
15878 If it is not, fail. Otherwise, undo the edits to the current
15879 line of input and proceed as for case CE. */
15881 static const struct asm_opcode *
15882 opcode_lookup (char **str)
15886 const struct asm_opcode *opcode;
15887 const struct asm_cond *cond;
15890 /* Scan up to the end of the mnemonic, which must end in white space,
15891 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
15892 for (base = end = *str; *end != '\0'; end++)
15893 if (*end == ' ' || *end == '.')
15899 /* Handle a possible width suffix and/or Neon type suffix. */
15904 /* The .w and .n suffixes are only valid if the unified syntax is in
15906 if (unified_syntax && end[1] == 'w')
15908 else if (unified_syntax && end[1] == 'n')
15913 inst.vectype.elems = 0;
15915 *str = end + offset;
15917 if (end[offset] == '.')
15919 /* See if we have a Neon type suffix (possible in either unified or
15920 non-unified ARM syntax mode). */
15921 if (parse_neon_type (&inst.vectype, str) == FAIL)
15924 else if (end[offset] != '\0' && end[offset] != ' ')
15930 /* Look for unaffixed or special-case affixed mnemonic. */
15931 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15936 if (opcode->tag < OT_odd_infix_0)
15938 inst.cond = COND_ALWAYS;
15942 if (warn_on_deprecated && unified_syntax)
15943 as_warn (_("conditional infixes are deprecated in unified syntax"));
15944 affix = base + (opcode->tag - OT_odd_infix_0);
15945 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15948 inst.cond = cond->value;
15952 /* Cannot have a conditional suffix on a mnemonic of less than two
15954 if (end - base < 3)
15957 /* Look for suffixed mnemonic. */
15959 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15960 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15962 if (opcode && cond)
15965 switch (opcode->tag)
15967 case OT_cinfix3_legacy:
15968 /* Ignore conditional suffixes matched on infix only mnemonics. */
15972 case OT_cinfix3_deprecated:
15973 case OT_odd_infix_unc:
15974 if (!unified_syntax)
15976 /* else fall through */
15980 case OT_csuf_or_in3:
15981 inst.cond = cond->value;
15984 case OT_unconditional:
15985 case OT_unconditionalF:
15987 inst.cond = cond->value;
15990 /* Delayed diagnostic. */
15991 inst.error = BAD_COND;
15992 inst.cond = COND_ALWAYS;
16001 /* Cannot have a usual-position infix on a mnemonic of less than
16002 six characters (five would be a suffix). */
16003 if (end - base < 6)
16006 /* Look for infixed mnemonic in the usual position. */
16008 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16012 memcpy (save, affix, 2);
16013 memmove (affix, affix + 2, (end - affix) - 2);
16014 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16016 memmove (affix + 2, affix, (end - affix) - 2);
16017 memcpy (affix, save, 2);
16020 && (opcode->tag == OT_cinfix3
16021 || opcode->tag == OT_cinfix3_deprecated
16022 || opcode->tag == OT_csuf_or_in3
16023 || opcode->tag == OT_cinfix3_legacy))
16026 if (warn_on_deprecated && unified_syntax
16027 && (opcode->tag == OT_cinfix3
16028 || opcode->tag == OT_cinfix3_deprecated))
16029 as_warn (_("conditional infixes are deprecated in unified syntax"));
16031 inst.cond = cond->value;
16038 /* This function generates an initial IT instruction, leaving its block
16039 virtually open for the new instructions. Eventually,
16040 the mask will be updated by now_it_add_mask () each time
16041 a new instruction needs to be included in the IT block.
16042 Finally, the block is closed with close_automatic_it_block ().
16043 The block closure can be requested either from md_assemble (),
16044 a tencode (), or due to a label hook. */
16047 new_automatic_it_block (int cond)
16049 now_it.state = AUTOMATIC_IT_BLOCK;
16050 now_it.mask = 0x18;
16052 now_it.block_length = 1;
16053 mapping_state (MAP_THUMB);
16054 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
16057 /* Close an automatic IT block.
16058 See comments in new_automatic_it_block (). */
16061 close_automatic_it_block (void)
16063 now_it.mask = 0x10;
16064 now_it.block_length = 0;
16067 /* Update the mask of the current automatically-generated IT
16068 instruction. See comments in new_automatic_it_block (). */
16071 now_it_add_mask (int cond)
16073 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
16074 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
16075 | ((bitvalue) << (nbit)))
16076 const int resulting_bit = (cond & 1);
16078 now_it.mask &= 0xf;
16079 now_it.mask = SET_BIT_VALUE (now_it.mask,
16081 (5 - now_it.block_length));
16082 now_it.mask = SET_BIT_VALUE (now_it.mask,
16084 ((5 - now_it.block_length) - 1) );
16085 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
16088 #undef SET_BIT_VALUE
16091 /* The IT blocks handling machinery is accessed through the these functions:
16092 it_fsm_pre_encode () from md_assemble ()
16093 set_it_insn_type () optional, from the tencode functions
16094 set_it_insn_type_last () ditto
16095 in_it_block () ditto
16096 it_fsm_post_encode () from md_assemble ()
16097 force_automatic_it_block_close () from label habdling functions
16100 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
16101 initializing the IT insn type with a generic initial value depending
16102 on the inst.condition.
16103 2) During the tencode function, two things may happen:
16104 a) The tencode function overrides the IT insn type by
16105 calling either set_it_insn_type (type) or set_it_insn_type_last ().
16106 b) The tencode function queries the IT block state by
16107 calling in_it_block () (i.e. to determine narrow/not narrow mode).
16109 Both set_it_insn_type and in_it_block run the internal FSM state
16110 handling function (handle_it_state), because: a) setting the IT insn
16111 type may incur in an invalid state (exiting the function),
16112 and b) querying the state requires the FSM to be updated.
16113 Specifically we want to avoid creating an IT block for conditional
16114 branches, so it_fsm_pre_encode is actually a guess and we can't
16115 determine whether an IT block is required until the tencode () routine
16116 has decided what type of instruction this actually it.
16117 Because of this, if set_it_insn_type and in_it_block have to be used,
16118 set_it_insn_type has to be called first.
16120 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
16121 determines the insn IT type depending on the inst.cond code.
16122 When a tencode () routine encodes an instruction that can be
16123 either outside an IT block, or, in the case of being inside, has to be
16124 the last one, set_it_insn_type_last () will determine the proper
16125 IT instruction type based on the inst.cond code. Otherwise,
16126 set_it_insn_type can be called for overriding that logic or
16127 for covering other cases.
16129 Calling handle_it_state () may not transition the IT block state to
16130 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
16131 still queried. Instead, if the FSM determines that the state should
16132 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
16133 after the tencode () function: that's what it_fsm_post_encode () does.
16135 Since in_it_block () calls the state handling function to get an
16136 updated state, an error may occur (due to invalid insns combination).
16137 In that case, inst.error is set.
16138 Therefore, inst.error has to be checked after the execution of
16139 the tencode () routine.
16141 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
16142 any pending state change (if any) that didn't take place in
16143 handle_it_state () as explained above. */
16146 it_fsm_pre_encode (void)
16148 if (inst.cond != COND_ALWAYS)
16149 inst.it_insn_type = INSIDE_IT_INSN;
16151 inst.it_insn_type = OUTSIDE_IT_INSN;
16153 now_it.state_handled = 0;
16156 /* IT state FSM handling function. */
16159 handle_it_state (void)
16161 now_it.state_handled = 1;
16163 switch (now_it.state)
16165 case OUTSIDE_IT_BLOCK:
16166 switch (inst.it_insn_type)
16168 case OUTSIDE_IT_INSN:
16171 case INSIDE_IT_INSN:
16172 case INSIDE_IT_LAST_INSN:
16173 if (thumb_mode == 0)
16176 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
16177 as_tsktsk (_("Warning: conditional outside an IT block"\
16182 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
16183 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
16185 /* Automatically generate the IT instruction. */
16186 new_automatic_it_block (inst.cond);
16187 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
16188 close_automatic_it_block ();
16192 inst.error = BAD_OUT_IT;
16198 case IF_INSIDE_IT_LAST_INSN:
16199 case NEUTRAL_IT_INSN:
16203 now_it.state = MANUAL_IT_BLOCK;
16204 now_it.block_length = 0;
16209 case AUTOMATIC_IT_BLOCK:
16210 /* Three things may happen now:
16211 a) We should increment current it block size;
16212 b) We should close current it block (closing insn or 4 insns);
16213 c) We should close current it block and start a new one (due
16214 to incompatible conditions or
16215 4 insns-length block reached). */
16217 switch (inst.it_insn_type)
16219 case OUTSIDE_IT_INSN:
16220 /* The closure of the block shall happen immediatelly,
16221 so any in_it_block () call reports the block as closed. */
16222 force_automatic_it_block_close ();
16225 case INSIDE_IT_INSN:
16226 case INSIDE_IT_LAST_INSN:
16227 case IF_INSIDE_IT_LAST_INSN:
16228 now_it.block_length++;
16230 if (now_it.block_length > 4
16231 || !now_it_compatible (inst.cond))
16233 force_automatic_it_block_close ();
16234 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16235 new_automatic_it_block (inst.cond);
16239 now_it_add_mask (inst.cond);
16242 if (now_it.state == AUTOMATIC_IT_BLOCK
16243 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16244 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16245 close_automatic_it_block ();
16248 case NEUTRAL_IT_INSN:
16249 now_it.block_length++;
16251 if (now_it.block_length > 4)
16252 force_automatic_it_block_close ();
16254 now_it_add_mask (now_it.cc & 1);
16258 close_automatic_it_block ();
16259 now_it.state = MANUAL_IT_BLOCK;
16264 case MANUAL_IT_BLOCK:
16266 /* Check conditional suffixes. */
16267 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16270 now_it.mask &= 0x1f;
16271 is_last = (now_it.mask == 0x10);
16273 switch (inst.it_insn_type)
16275 case OUTSIDE_IT_INSN:
16276 inst.error = BAD_NOT_IT;
16279 case INSIDE_IT_INSN:
16280 if (cond != inst.cond)
16282 inst.error = BAD_IT_COND;
16287 case INSIDE_IT_LAST_INSN:
16288 case IF_INSIDE_IT_LAST_INSN:
16289 if (cond != inst.cond)
16291 inst.error = BAD_IT_COND;
16296 inst.error = BAD_BRANCH;
16301 case NEUTRAL_IT_INSN:
16302 /* The BKPT instruction is unconditional even in an IT block. */
16306 inst.error = BAD_IT_IT;
16317 it_fsm_post_encode (void)
16321 if (!now_it.state_handled)
16322 handle_it_state ();
16324 is_last = (now_it.mask == 0x10);
16327 now_it.state = OUTSIDE_IT_BLOCK;
16333 force_automatic_it_block_close (void)
16335 if (now_it.state == AUTOMATIC_IT_BLOCK)
16337 close_automatic_it_block ();
16338 now_it.state = OUTSIDE_IT_BLOCK;
16346 if (!now_it.state_handled)
16347 handle_it_state ();
16349 return now_it.state != OUTSIDE_IT_BLOCK;
16353 md_assemble (char *str)
16356 const struct asm_opcode * opcode;
16358 /* Align the previous label if needed. */
16359 if (last_label_seen != NULL)
16361 symbol_set_frag (last_label_seen, frag_now);
16362 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
16363 S_SET_SEGMENT (last_label_seen, now_seg);
16366 memset (&inst, '\0', sizeof (inst));
16367 inst.reloc.type = BFD_RELOC_UNUSED;
16369 opcode = opcode_lookup (&p);
16372 /* It wasn't an instruction, but it might be a register alias of
16373 the form alias .req reg, or a Neon .dn/.qn directive. */
16374 if (! create_register_alias (str, p)
16375 && ! create_neon_reg_alias (str, p))
16376 as_bad (_("bad instruction `%s'"), str);
16381 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
16382 as_warn (_("s suffix on comparison instruction is deprecated"));
16384 /* The value which unconditional instructions should have in place of the
16385 condition field. */
16386 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
16390 arm_feature_set variant;
16392 variant = cpu_variant;
16393 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
16394 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
16395 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
16396 /* Check that this instruction is supported for this CPU. */
16397 if (!opcode->tvariant
16398 || (thumb_mode == 1
16399 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
16401 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
16404 if (inst.cond != COND_ALWAYS && !unified_syntax
16405 && opcode->tencode != do_t_branch)
16407 as_bad (_("Thumb does not support conditional execution"));
16411 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
16413 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
16414 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
16415 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
16417 /* Two things are addressed here.
16418 1) Implicit require narrow instructions on Thumb-1.
16419 This avoids relaxation accidentally introducing Thumb-2
16421 2) Reject wide instructions in non Thumb-2 cores. */
16422 if (inst.size_req == 0)
16424 else if (inst.size_req == 4)
16426 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
16432 inst.instruction = opcode->tvalue;
16434 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
16436 /* Prepare the it_insn_type for those encodings that don't set
16438 it_fsm_pre_encode ();
16440 opcode->tencode ();
16442 it_fsm_post_encode ();
16445 if (!(inst.error || inst.relax))
16447 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
16448 inst.size = (inst.instruction > 0xffff ? 4 : 2);
16449 if (inst.size_req && inst.size_req != inst.size)
16451 as_bad (_("cannot honor width suffix -- `%s'"), str);
16456 /* Something has gone badly wrong if we try to relax a fixed size
16458 gas_assert (inst.size_req == 0 || !inst.relax);
16460 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16461 *opcode->tvariant);
16462 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
16463 set those bits when Thumb-2 32-bit instructions are seen. ie.
16464 anything other than bl/blx and v6-M instructions.
16465 This is overly pessimistic for relaxable instructions. */
16466 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
16468 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
16469 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
16470 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16473 check_neon_suffixes;
16477 mapping_state (MAP_THUMB);
16480 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
16484 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
16485 is_bx = (opcode->aencode == do_bx);
16487 /* Check that this instruction is supported for this CPU. */
16488 if (!(is_bx && fix_v4bx)
16489 && !(opcode->avariant &&
16490 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
16492 as_bad (_("selected processor does not support ARM mode `%s'"), str);
16497 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
16501 inst.instruction = opcode->avalue;
16502 if (opcode->tag == OT_unconditionalF)
16503 inst.instruction |= 0xF << 28;
16505 inst.instruction |= inst.cond << 28;
16506 inst.size = INSN_SIZE;
16507 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
16509 it_fsm_pre_encode ();
16510 opcode->aencode ();
16511 it_fsm_post_encode ();
16513 /* Arm mode bx is marked as both v4T and v5 because it's still required
16514 on a hypothetical non-thumb v5 core. */
16516 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
16518 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16519 *opcode->avariant);
16521 check_neon_suffixes;
16525 mapping_state (MAP_ARM);
16530 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16538 check_it_blocks_finished (void)
16543 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16544 if (seg_info (sect)->tc_segment_info_data.current_it.state
16545 == MANUAL_IT_BLOCK)
16547 as_warn (_("section '%s' finished with an open IT block."),
16551 if (now_it.state == MANUAL_IT_BLOCK)
16552 as_warn (_("file finished with an open IT block."));
16556 /* Various frobbings of labels and their addresses. */
16559 arm_start_line_hook (void)
16561 last_label_seen = NULL;
16565 arm_frob_label (symbolS * sym)
16567 last_label_seen = sym;
16569 ARM_SET_THUMB (sym, thumb_mode);
16571 #if defined OBJ_COFF || defined OBJ_ELF
16572 ARM_SET_INTERWORK (sym, support_interwork);
16575 force_automatic_it_block_close ();
16577 /* Note - do not allow local symbols (.Lxxx) to be labelled
16578 as Thumb functions. This is because these labels, whilst
16579 they exist inside Thumb code, are not the entry points for
16580 possible ARM->Thumb calls. Also, these labels can be used
16581 as part of a computed goto or switch statement. eg gcc
16582 can generate code that looks like this:
16584 ldr r2, [pc, .Laaa]
16594 The first instruction loads the address of the jump table.
16595 The second instruction converts a table index into a byte offset.
16596 The third instruction gets the jump address out of the table.
16597 The fourth instruction performs the jump.
16599 If the address stored at .Laaa is that of a symbol which has the
16600 Thumb_Func bit set, then the linker will arrange for this address
16601 to have the bottom bit set, which in turn would mean that the
16602 address computation performed by the third instruction would end
16603 up with the bottom bit set. Since the ARM is capable of unaligned
16604 word loads, the instruction would then load the incorrect address
16605 out of the jump table, and chaos would ensue. */
16606 if (label_is_thumb_function_name
16607 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16608 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
16610 /* When the address of a Thumb function is taken the bottom
16611 bit of that address should be set. This will allow
16612 interworking between Arm and Thumb functions to work
16615 THUMB_SET_FUNC (sym, 1);
16617 label_is_thumb_function_name = FALSE;
16620 dwarf2_emit_label (sym);
16624 arm_data_in_code (void)
16626 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
16628 *input_line_pointer = '/';
16629 input_line_pointer += 5;
16630 *input_line_pointer = 0;
16638 arm_canonicalize_symbol_name (char * name)
16642 if (thumb_mode && (len = strlen (name)) > 5
16643 && streq (name + len - 5, "/data"))
16644 *(name + len - 5) = 0;
16649 /* Table of all register names defined by default. The user can
16650 define additional names with .req. Note that all register names
16651 should appear in both upper and lowercase variants. Some registers
16652 also have mixed-case names. */
16654 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
16655 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
16656 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
16657 #define REGSET(p,t) \
16658 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16659 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16660 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16661 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
16662 #define REGSETH(p,t) \
16663 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16664 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16665 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16666 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16667 #define REGSET2(p,t) \
16668 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16669 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16670 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16671 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
16672 #define SPLRBANK(base,bank,t) \
16673 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
16674 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
16675 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
16676 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
16677 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
16678 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
16680 static const struct reg_entry reg_names[] =
16682 /* ARM integer registers. */
16683 REGSET(r, RN), REGSET(R, RN),
16685 /* ATPCS synonyms. */
16686 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16687 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16688 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
16690 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16691 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16692 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
16694 /* Well-known aliases. */
16695 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16696 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16698 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16699 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16701 /* Coprocessor numbers. */
16702 REGSET(p, CP), REGSET(P, CP),
16704 /* Coprocessor register numbers. The "cr" variants are for backward
16706 REGSET(c, CN), REGSET(C, CN),
16707 REGSET(cr, CN), REGSET(CR, CN),
16709 /* ARM banked registers. */
16710 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
16711 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
16712 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
16713 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
16714 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
16715 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
16716 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
16718 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
16719 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
16720 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
16721 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
16722 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
16723 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
16724 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
16725 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
16727 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
16728 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
16729 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
16730 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
16731 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
16732 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
16733 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
16734 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
16735 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
16737 /* FPA registers. */
16738 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16739 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16741 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16742 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16744 /* VFP SP registers. */
16745 REGSET(s,VFS), REGSET(S,VFS),
16746 REGSETH(s,VFS), REGSETH(S,VFS),
16748 /* VFP DP Registers. */
16749 REGSET(d,VFD), REGSET(D,VFD),
16750 /* Extra Neon DP registers. */
16751 REGSETH(d,VFD), REGSETH(D,VFD),
16753 /* Neon QP registers. */
16754 REGSET2(q,NQ), REGSET2(Q,NQ),
16756 /* VFP control registers. */
16757 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16758 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
16759 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16760 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16761 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16762 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
16764 /* Maverick DSP coprocessor registers. */
16765 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16766 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16768 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16769 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16770 REGDEF(dspsc,0,DSPSC),
16772 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16773 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16774 REGDEF(DSPSC,0,DSPSC),
16776 /* iWMMXt data registers - p0, c0-15. */
16777 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16779 /* iWMMXt control registers - p1, c0-3. */
16780 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16781 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16782 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16783 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16785 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16786 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16787 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16788 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16789 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16791 /* XScale accumulator registers. */
16792 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16798 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16799 within psr_required_here. */
16800 static const struct asm_psr psrs[] =
16802 /* Backward compatibility notation. Note that "all" is no longer
16803 truly all possible PSR bits. */
16804 {"all", PSR_c | PSR_f},
16808 /* Individual flags. */
16814 /* Combinations of flags. */
16815 {"fs", PSR_f | PSR_s},
16816 {"fx", PSR_f | PSR_x},
16817 {"fc", PSR_f | PSR_c},
16818 {"sf", PSR_s | PSR_f},
16819 {"sx", PSR_s | PSR_x},
16820 {"sc", PSR_s | PSR_c},
16821 {"xf", PSR_x | PSR_f},
16822 {"xs", PSR_x | PSR_s},
16823 {"xc", PSR_x | PSR_c},
16824 {"cf", PSR_c | PSR_f},
16825 {"cs", PSR_c | PSR_s},
16826 {"cx", PSR_c | PSR_x},
16827 {"fsx", PSR_f | PSR_s | PSR_x},
16828 {"fsc", PSR_f | PSR_s | PSR_c},
16829 {"fxs", PSR_f | PSR_x | PSR_s},
16830 {"fxc", PSR_f | PSR_x | PSR_c},
16831 {"fcs", PSR_f | PSR_c | PSR_s},
16832 {"fcx", PSR_f | PSR_c | PSR_x},
16833 {"sfx", PSR_s | PSR_f | PSR_x},
16834 {"sfc", PSR_s | PSR_f | PSR_c},
16835 {"sxf", PSR_s | PSR_x | PSR_f},
16836 {"sxc", PSR_s | PSR_x | PSR_c},
16837 {"scf", PSR_s | PSR_c | PSR_f},
16838 {"scx", PSR_s | PSR_c | PSR_x},
16839 {"xfs", PSR_x | PSR_f | PSR_s},
16840 {"xfc", PSR_x | PSR_f | PSR_c},
16841 {"xsf", PSR_x | PSR_s | PSR_f},
16842 {"xsc", PSR_x | PSR_s | PSR_c},
16843 {"xcf", PSR_x | PSR_c | PSR_f},
16844 {"xcs", PSR_x | PSR_c | PSR_s},
16845 {"cfs", PSR_c | PSR_f | PSR_s},
16846 {"cfx", PSR_c | PSR_f | PSR_x},
16847 {"csf", PSR_c | PSR_s | PSR_f},
16848 {"csx", PSR_c | PSR_s | PSR_x},
16849 {"cxf", PSR_c | PSR_x | PSR_f},
16850 {"cxs", PSR_c | PSR_x | PSR_s},
16851 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16852 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16853 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16854 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16855 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16856 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16857 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16858 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16859 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16860 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16861 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16862 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16863 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16864 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16865 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16866 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16867 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16868 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16869 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16870 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16871 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16872 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16873 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16874 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16877 /* Table of V7M psr names. */
16878 static const struct asm_psr v7m_psrs[] =
16880 {"apsr", 0 }, {"APSR", 0 },
16881 {"iapsr", 1 }, {"IAPSR", 1 },
16882 {"eapsr", 2 }, {"EAPSR", 2 },
16883 {"psr", 3 }, {"PSR", 3 },
16884 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16885 {"ipsr", 5 }, {"IPSR", 5 },
16886 {"epsr", 6 }, {"EPSR", 6 },
16887 {"iepsr", 7 }, {"IEPSR", 7 },
16888 {"msp", 8 }, {"MSP", 8 },
16889 {"psp", 9 }, {"PSP", 9 },
16890 {"primask", 16}, {"PRIMASK", 16},
16891 {"basepri", 17}, {"BASEPRI", 17},
16892 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16893 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
16894 {"faultmask", 19}, {"FAULTMASK", 19},
16895 {"control", 20}, {"CONTROL", 20}
16898 /* Table of all shift-in-operand names. */
16899 static const struct asm_shift_name shift_names [] =
16901 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16902 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16903 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16904 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16905 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16906 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16909 /* Table of all explicit relocation names. */
16911 static struct reloc_entry reloc_names[] =
16913 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16914 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16915 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16916 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16917 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16918 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16919 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16920 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16921 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16922 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
16923 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
16924 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
16925 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
16926 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
16927 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
16928 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
16929 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
16930 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
16934 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
16935 static const struct asm_cond conds[] =
16939 {"cs", 0x2}, {"hs", 0x2},
16940 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16954 static struct asm_barrier_opt barrier_opt_names[] =
16956 { "sy", 0xf }, { "SY", 0xf },
16957 { "un", 0x7 }, { "UN", 0x7 },
16958 { "st", 0xe }, { "ST", 0xe },
16959 { "unst", 0x6 }, { "UNST", 0x6 },
16960 { "ish", 0xb }, { "ISH", 0xb },
16961 { "sh", 0xb }, { "SH", 0xb },
16962 { "ishst", 0xa }, { "ISHST", 0xa },
16963 { "shst", 0xa }, { "SHST", 0xa },
16964 { "nsh", 0x7 }, { "NSH", 0x7 },
16965 { "nshst", 0x6 }, { "NSHST", 0x6 },
16966 { "osh", 0x3 }, { "OSH", 0x3 },
16967 { "oshst", 0x2 }, { "OSHST", 0x2 }
16970 /* Table of ARM-format instructions. */
16972 /* Macros for gluing together operand strings. N.B. In all cases
16973 other than OPS0, the trailing OP_stop comes from default
16974 zero-initialization of the unspecified elements of the array. */
16975 #define OPS0() { OP_stop, }
16976 #define OPS1(a) { OP_##a, }
16977 #define OPS2(a,b) { OP_##a,OP_##b, }
16978 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16979 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16980 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16981 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16983 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16984 This is useful when mixing operands for ARM and THUMB, i.e. using the
16985 MIX_ARM_THUMB_OPERANDS macro.
16986 In order to use these macros, prefix the number of operands with _
16988 #define OPS_1(a) { a, }
16989 #define OPS_2(a,b) { a,b, }
16990 #define OPS_3(a,b,c) { a,b,c, }
16991 #define OPS_4(a,b,c,d) { a,b,c,d, }
16992 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16993 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16995 /* These macros abstract out the exact format of the mnemonic table and
16996 save some repeated characters. */
16998 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16999 #define TxCE(mnem, op, top, nops, ops, ae, te) \
17000 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
17001 THUMB_VARIANT, do_##ae, do_##te }
17003 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
17004 a T_MNEM_xyz enumerator. */
17005 #define TCE(mnem, aop, top, nops, ops, ae, te) \
17006 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
17007 #define tCE(mnem, aop, top, nops, ops, ae, te) \
17008 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17010 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
17011 infix after the third character. */
17012 #define TxC3(mnem, op, top, nops, ops, ae, te) \
17013 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
17014 THUMB_VARIANT, do_##ae, do_##te }
17015 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
17016 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
17017 THUMB_VARIANT, do_##ae, do_##te }
17018 #define TC3(mnem, aop, top, nops, ops, ae, te) \
17019 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
17020 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
17021 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
17022 #define tC3(mnem, aop, top, nops, ops, ae, te) \
17023 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17024 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
17025 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17027 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
17028 appear in the condition table. */
17029 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
17030 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
17031 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
17033 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
17034 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
17035 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
17036 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
17037 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
17038 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
17039 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
17040 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
17041 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
17042 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
17043 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
17044 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
17045 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
17046 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
17047 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
17048 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
17049 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
17050 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
17051 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
17052 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
17054 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
17055 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
17056 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
17057 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
17059 /* Mnemonic that cannot be conditionalized. The ARM condition-code
17060 field is still 0xE. Many of the Thumb variants can be executed
17061 conditionally, so this is checked separately. */
17062 #define TUE(mnem, op, top, nops, ops, ae, te) \
17063 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
17064 THUMB_VARIANT, do_##ae, do_##te }
17066 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
17067 condition code field. */
17068 #define TUF(mnem, op, top, nops, ops, ae, te) \
17069 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
17070 THUMB_VARIANT, do_##ae, do_##te }
17072 /* ARM-only variants of all the above. */
17073 #define CE(mnem, op, nops, ops, ae) \
17074 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17076 #define C3(mnem, op, nops, ops, ae) \
17077 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17079 /* Legacy mnemonics that always have conditional infix after the third
17081 #define CL(mnem, op, nops, ops, ae) \
17082 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
17083 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17085 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
17086 #define cCE(mnem, op, nops, ops, ae) \
17087 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17089 /* Legacy coprocessor instructions where conditional infix and conditional
17090 suffix are ambiguous. For consistency this includes all FPA instructions,
17091 not just the potentially ambiguous ones. */
17092 #define cCL(mnem, op, nops, ops, ae) \
17093 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
17094 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17096 /* Coprocessor, takes either a suffix or a position-3 infix
17097 (for an FPA corner case). */
17098 #define C3E(mnem, op, nops, ops, ae) \
17099 { mnem, OPS##nops ops, OT_csuf_or_in3, \
17100 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17102 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
17103 { m1 #m2 m3, OPS##nops ops, \
17104 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
17105 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17107 #define CM(m1, m2, op, nops, ops, ae) \
17108 xCM_ (m1, , m2, op, nops, ops, ae), \
17109 xCM_ (m1, eq, m2, op, nops, ops, ae), \
17110 xCM_ (m1, ne, m2, op, nops, ops, ae), \
17111 xCM_ (m1, cs, m2, op, nops, ops, ae), \
17112 xCM_ (m1, hs, m2, op, nops, ops, ae), \
17113 xCM_ (m1, cc, m2, op, nops, ops, ae), \
17114 xCM_ (m1, ul, m2, op, nops, ops, ae), \
17115 xCM_ (m1, lo, m2, op, nops, ops, ae), \
17116 xCM_ (m1, mi, m2, op, nops, ops, ae), \
17117 xCM_ (m1, pl, m2, op, nops, ops, ae), \
17118 xCM_ (m1, vs, m2, op, nops, ops, ae), \
17119 xCM_ (m1, vc, m2, op, nops, ops, ae), \
17120 xCM_ (m1, hi, m2, op, nops, ops, ae), \
17121 xCM_ (m1, ls, m2, op, nops, ops, ae), \
17122 xCM_ (m1, ge, m2, op, nops, ops, ae), \
17123 xCM_ (m1, lt, m2, op, nops, ops, ae), \
17124 xCM_ (m1, gt, m2, op, nops, ops, ae), \
17125 xCM_ (m1, le, m2, op, nops, ops, ae), \
17126 xCM_ (m1, al, m2, op, nops, ops, ae)
17128 #define UE(mnem, op, nops, ops, ae) \
17129 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17131 #define UF(mnem, op, nops, ops, ae) \
17132 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17134 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
17135 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
17136 use the same encoding function for each. */
17137 #define NUF(mnem, op, nops, ops, enc) \
17138 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
17139 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17141 /* Neon data processing, version which indirects through neon_enc_tab for
17142 the various overloaded versions of opcodes. */
17143 #define nUF(mnem, op, nops, ops, enc) \
17144 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
17145 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17147 /* Neon insn with conditional suffix for the ARM version, non-overloaded
17149 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
17150 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
17151 THUMB_VARIANT, do_##enc, do_##enc }
17153 #define NCE(mnem, op, nops, ops, enc) \
17154 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
17156 #define NCEF(mnem, op, nops, ops, enc) \
17157 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
17159 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
17160 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
17161 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
17162 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17164 #define nCE(mnem, op, nops, ops, enc) \
17165 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
17167 #define nCEF(mnem, op, nops, ops, enc) \
17168 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
17172 static const struct asm_opcode insns[] =
17174 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
17175 #define THUMB_VARIANT &arm_ext_v4t
17176 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
17177 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
17178 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
17179 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
17180 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
17181 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
17182 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
17183 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
17184 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
17185 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
17186 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
17187 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
17188 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
17189 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
17190 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
17191 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
17193 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
17194 for setting PSR flag bits. They are obsolete in V6 and do not
17195 have Thumb equivalents. */
17196 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17197 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17198 CL("tstp", 110f000, 2, (RR, SH), cmp),
17199 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17200 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17201 CL("cmpp", 150f000, 2, (RR, SH), cmp),
17202 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17203 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17204 CL("cmnp", 170f000, 2, (RR, SH), cmp),
17206 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
17207 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
17208 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
17209 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
17211 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
17212 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17213 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
17215 OP_ADDRGLDR),ldst, t_ldst),
17216 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17218 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17219 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17220 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17221 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17222 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17223 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17225 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
17226 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
17227 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
17228 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
17231 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
17232 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
17233 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
17235 /* Thumb-compatibility pseudo ops. */
17236 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17237 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17238 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17239 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17240 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17241 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17242 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17243 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17244 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17245 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17246 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17247 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
17249 /* These may simplify to neg. */
17250 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17251 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
17253 #undef THUMB_VARIANT
17254 #define THUMB_VARIANT & arm_ext_v6
17256 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
17258 /* V1 instructions with no Thumb analogue prior to V6T2. */
17259 #undef THUMB_VARIANT
17260 #define THUMB_VARIANT & arm_ext_v6t2
17262 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17263 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17264 CL("teqp", 130f000, 2, (RR, SH), cmp),
17266 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17267 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17268 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
17269 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17271 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17272 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17274 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17275 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17277 /* V1 instructions with no Thumb analogue at all. */
17278 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
17279 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
17281 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
17282 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
17283 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
17284 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
17285 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
17286 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
17287 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
17288 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
17291 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
17292 #undef THUMB_VARIANT
17293 #define THUMB_VARIANT & arm_ext_v4t
17295 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17296 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17298 #undef THUMB_VARIANT
17299 #define THUMB_VARIANT & arm_ext_v6t2
17301 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17302 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
17304 /* Generic coprocessor instructions. */
17305 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17306 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17307 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17308 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17309 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17310 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17311 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
17314 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
17316 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17317 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17320 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
17321 #undef THUMB_VARIANT
17322 #define THUMB_VARIANT & arm_ext_msr
17324 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
17325 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
17328 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
17329 #undef THUMB_VARIANT
17330 #define THUMB_VARIANT & arm_ext_v6t2
17332 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17333 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17334 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17335 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17336 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17337 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17338 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17339 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17342 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
17343 #undef THUMB_VARIANT
17344 #define THUMB_VARIANT & arm_ext_v4t
17346 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17347 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17348 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17349 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17350 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17351 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17354 #define ARM_VARIANT & arm_ext_v4t_5
17356 /* ARM Architecture 4T. */
17357 /* Note: bx (and blx) are required on V5, even if the processor does
17358 not support Thumb. */
17359 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
17362 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
17363 #undef THUMB_VARIANT
17364 #define THUMB_VARIANT & arm_ext_v5t
17366 /* Note: blx has 2 variants; the .value coded here is for
17367 BLX(2). Only this variant has conditional execution. */
17368 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
17369 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
17371 #undef THUMB_VARIANT
17372 #define THUMB_VARIANT & arm_ext_v6t2
17374 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
17375 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17376 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17377 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17378 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17379 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17380 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17381 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17384 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
17385 #undef THUMB_VARIANT
17386 #define THUMB_VARIANT &arm_ext_v5exp
17388 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17389 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17390 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17391 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17393 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17394 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17396 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17397 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17398 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17399 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17401 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17402 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17403 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17404 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17406 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17407 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17409 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17410 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17411 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17412 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17415 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
17416 #undef THUMB_VARIANT
17417 #define THUMB_VARIANT &arm_ext_v6t2
17419 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
17420 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
17422 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
17423 ADDRGLDRS), ldrd, t_ldstd),
17425 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17426 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17429 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
17431 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
17434 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
17435 #undef THUMB_VARIANT
17436 #define THUMB_VARIANT & arm_ext_v6
17438 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
17439 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
17440 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17441 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17442 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17443 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17444 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17445 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17446 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17447 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
17449 #undef THUMB_VARIANT
17450 #define THUMB_VARIANT & arm_ext_v6t2
17452 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
17453 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17455 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17456 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17458 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
17459 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
17461 /* ARM V6 not included in V7M. */
17462 #undef THUMB_VARIANT
17463 #define THUMB_VARIANT & arm_ext_v6_notm
17464 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17465 UF(rfeib, 9900a00, 1, (RRw), rfe),
17466 UF(rfeda, 8100a00, 1, (RRw), rfe),
17467 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17468 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17469 UF(rfefa, 9900a00, 1, (RRw), rfe),
17470 UF(rfeea, 8100a00, 1, (RRw), rfe),
17471 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17472 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
17473 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
17474 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
17475 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
17477 /* ARM V6 not included in V7M (eg. integer SIMD). */
17478 #undef THUMB_VARIANT
17479 #define THUMB_VARIANT & arm_ext_v6_dsp
17480 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
17481 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
17482 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
17483 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17484 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17485 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17486 /* Old name for QASX. */
17487 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17488 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17489 /* Old name for QSAX. */
17490 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17491 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17492 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17493 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17494 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17495 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17496 /* Old name for SASX. */
17497 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17498 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17499 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17500 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17501 /* Old name for SHASX. */
17502 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17503 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17504 /* Old name for SHSAX. */
17505 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17506 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17507 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17508 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17509 /* Old name for SSAX. */
17510 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17511 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17512 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17513 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17514 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17515 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17516 /* Old name for UASX. */
17517 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17518 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17519 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17520 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17521 /* Old name for UHASX. */
17522 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17523 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17524 /* Old name for UHSAX. */
17525 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17526 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17527 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17528 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17529 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17530 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17531 /* Old name for UQASX. */
17532 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17533 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17534 /* Old name for UQSAX. */
17535 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17536 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17537 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17538 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17539 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17540 /* Old name for USAX. */
17541 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17542 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17543 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17544 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17545 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17546 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17547 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17548 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17549 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17550 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17551 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17552 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17553 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17554 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17555 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17556 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17557 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17558 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17559 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17560 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17561 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17562 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17563 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17564 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17565 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17566 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17567 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17568 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17569 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17570 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17571 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17572 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17573 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17574 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
17577 #define ARM_VARIANT & arm_ext_v6k
17578 #undef THUMB_VARIANT
17579 #define THUMB_VARIANT & arm_ext_v6k
17581 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17582 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17583 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17584 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
17586 #undef THUMB_VARIANT
17587 #define THUMB_VARIANT & arm_ext_v6_notm
17588 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17590 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17591 RRnpcb), strexd, t_strexd),
17593 #undef THUMB_VARIANT
17594 #define THUMB_VARIANT & arm_ext_v6t2
17595 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17597 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17599 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17601 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17603 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
17606 #define ARM_VARIANT & arm_ext_sec
17607 #undef THUMB_VARIANT
17608 #define THUMB_VARIANT & arm_ext_sec
17610 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
17613 #define ARM_VARIANT & arm_ext_virt
17614 #undef THUMB_VARIANT
17615 #define THUMB_VARIANT & arm_ext_virt
17617 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
17618 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
17621 #define ARM_VARIANT & arm_ext_v6t2
17622 #undef THUMB_VARIANT
17623 #define THUMB_VARIANT & arm_ext_v6t2
17625 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17626 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17627 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17628 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17630 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17631 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17632 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17633 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
17635 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17636 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17637 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17638 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17640 /* Thumb-only instructions. */
17642 #define ARM_VARIANT NULL
17643 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17644 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
17646 /* ARM does not really have an IT instruction, so always allow it.
17647 The opcode is copied from Thumb in order to allow warnings in
17648 -mimplicit-it=[never | arm] modes. */
17650 #define ARM_VARIANT & arm_ext_v1
17652 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17653 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17654 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17655 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17656 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17657 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17658 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17659 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17660 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17661 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17662 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17663 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17664 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17665 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17666 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
17667 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
17668 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17669 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
17671 /* Thumb2 only instructions. */
17673 #define ARM_VARIANT NULL
17675 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17676 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17677 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17678 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17679 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17680 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
17682 /* Hardware division instructions. */
17684 #define ARM_VARIANT & arm_ext_adiv
17685 #undef THUMB_VARIANT
17686 #define THUMB_VARIANT & arm_ext_div
17688 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
17689 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
17691 /* ARM V6M/V7 instructions. */
17693 #define ARM_VARIANT & arm_ext_barrier
17694 #undef THUMB_VARIANT
17695 #define THUMB_VARIANT & arm_ext_barrier
17697 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17698 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17699 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
17701 /* ARM V7 instructions. */
17703 #define ARM_VARIANT & arm_ext_v7
17704 #undef THUMB_VARIANT
17705 #define THUMB_VARIANT & arm_ext_v7
17707 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17708 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
17711 #define ARM_VARIANT & arm_ext_mp
17712 #undef THUMB_VARIANT
17713 #define THUMB_VARIANT & arm_ext_mp
17715 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17718 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17720 cCE("wfs", e200110, 1, (RR), rd),
17721 cCE("rfs", e300110, 1, (RR), rd),
17722 cCE("wfc", e400110, 1, (RR), rd),
17723 cCE("rfc", e500110, 1, (RR), rd),
17725 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17726 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17727 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17728 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17730 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17731 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17732 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17733 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17735 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17736 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17737 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17738 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17739 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17740 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17741 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17742 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17743 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17744 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17745 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17746 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17748 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17749 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17750 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17751 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17752 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17753 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17754 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17755 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17756 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17757 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17758 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17759 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17761 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17762 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17763 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17764 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17765 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17766 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17767 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17768 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17769 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17770 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17771 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17772 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17774 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17775 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17776 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17777 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17778 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17779 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17780 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17781 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17782 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17783 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17784 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17785 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17787 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17788 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17789 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17790 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17791 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17792 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17793 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17794 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17795 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17796 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17797 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17798 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17800 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17801 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17802 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17803 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17804 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17805 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17806 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17807 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17808 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17809 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17810 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17811 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17813 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17814 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17815 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17816 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17817 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17818 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17819 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17820 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17821 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17822 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17823 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17824 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17826 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17827 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17828 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17829 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17830 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17831 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17832 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17833 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17834 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17835 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17836 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17837 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17839 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17840 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17841 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17842 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17843 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17844 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17845 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17846 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17847 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17848 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17849 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17850 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17852 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17853 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17854 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17855 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17856 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17857 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17858 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17859 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17860 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17861 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17862 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17863 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17865 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17866 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17867 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17868 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17869 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17870 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17871 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17872 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17873 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17874 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17875 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17876 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17878 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17879 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17880 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17881 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17882 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17883 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17884 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17885 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17886 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17887 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17888 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17889 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17891 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17892 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17893 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17894 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17895 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17896 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17897 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17898 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17899 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17900 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17901 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17902 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17904 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17905 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17906 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17907 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17908 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17909 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17910 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17911 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17912 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17913 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17914 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17915 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17917 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17918 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17919 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17920 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17921 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17922 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17923 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17924 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17925 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17926 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17927 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17928 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17930 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17931 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17932 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17933 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17934 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17935 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17936 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17937 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17938 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17939 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17940 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17941 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17943 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17944 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17945 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17946 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17947 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17948 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17949 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17950 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17951 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17952 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17953 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17954 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17956 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17957 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17958 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17959 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17960 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17961 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17962 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17963 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17964 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17965 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17966 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17967 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17969 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17970 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17971 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17972 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17973 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17974 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17975 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17976 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17977 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17978 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17979 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17980 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17982 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17983 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17984 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17985 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17986 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17987 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17988 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17989 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17990 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17991 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17992 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17993 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17995 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17996 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17997 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17998 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17999 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
18000 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18001 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18002 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18003 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
18004 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
18005 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
18006 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
18008 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
18009 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
18010 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
18011 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
18012 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
18013 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18014 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18015 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18016 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
18017 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
18018 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
18019 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
18021 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
18022 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
18023 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
18024 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
18025 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
18026 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18027 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18028 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18029 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
18030 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
18031 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
18032 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
18034 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
18035 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
18036 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
18037 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
18038 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
18039 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18040 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18041 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18042 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
18043 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
18044 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
18045 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
18047 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
18048 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
18049 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
18050 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
18051 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
18052 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18053 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18054 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18055 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
18056 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
18057 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
18058 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
18060 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
18061 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
18062 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
18063 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
18064 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
18065 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18066 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18067 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18068 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
18069 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
18070 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
18071 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
18073 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18074 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18075 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18076 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18077 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18078 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18079 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18080 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18081 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18082 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18083 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18084 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18086 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18087 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18088 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18089 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18090 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18091 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18092 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18093 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18094 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18095 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18096 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18097 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18099 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18100 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18101 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18102 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18103 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18104 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18105 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18106 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18107 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18108 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18109 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18110 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18112 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
18113 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
18114 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
18115 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
18117 cCL("flts", e000110, 2, (RF, RR), rn_rd),
18118 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
18119 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
18120 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
18121 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
18122 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
18123 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
18124 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
18125 cCL("flte", e080110, 2, (RF, RR), rn_rd),
18126 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
18127 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
18128 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
18130 /* The implementation of the FIX instruction is broken on some
18131 assemblers, in that it accepts a precision specifier as well as a
18132 rounding specifier, despite the fact that this is meaningless.
18133 To be more compatible, we accept it as well, though of course it
18134 does not set any bits. */
18135 cCE("fix", e100110, 2, (RR, RF), rd_rm),
18136 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
18137 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
18138 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
18139 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
18140 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
18141 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
18142 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
18143 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
18144 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
18145 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
18146 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
18147 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
18149 /* Instructions that were new with the real FPA, call them V2. */
18151 #define ARM_VARIANT & fpu_fpa_ext_v2
18153 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18154 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18155 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18156 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18157 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18158 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18161 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
18163 /* Moves and type conversions. */
18164 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
18165 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
18166 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
18167 cCE("fmstat", ef1fa10, 0, (), noargs),
18168 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
18169 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
18170 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
18171 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
18172 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
18173 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18174 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
18175 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18176 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
18177 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
18179 /* Memory operations. */
18180 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
18181 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
18182 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18183 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18184 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18185 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18186 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18187 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18188 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18189 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18190 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18191 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18192 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18193 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18194 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18195 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18196 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18197 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18199 /* Monadic operations. */
18200 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
18201 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
18202 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
18204 /* Dyadic operations. */
18205 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18206 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18207 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18208 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18209 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18210 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18211 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18212 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18213 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18216 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
18217 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
18218 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
18219 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
18221 /* Double precision load/store are still present on single precision
18222 implementations. */
18223 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
18224 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
18225 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18226 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18227 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18228 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18229 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18230 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18231 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18232 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18235 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
18237 /* Moves and type conversions. */
18238 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18239 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18240 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18241 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
18242 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
18243 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
18244 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
18245 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18246 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
18247 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18248 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18249 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18250 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18252 /* Monadic operations. */
18253 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18254 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18255 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18257 /* Dyadic operations. */
18258 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18259 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18260 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18261 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18262 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18263 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18264 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18265 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18266 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18269 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18270 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
18271 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18272 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
18275 #define ARM_VARIANT & fpu_vfp_ext_v2
18277 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
18278 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
18279 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
18280 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
18282 /* Instructions which may belong to either the Neon or VFP instruction sets.
18283 Individual encoder functions perform additional architecture checks. */
18285 #define ARM_VARIANT & fpu_vfp_ext_v1xd
18286 #undef THUMB_VARIANT
18287 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
18289 /* These mnemonics are unique to VFP. */
18290 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
18291 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
18292 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18293 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18294 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18295 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18296 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18297 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
18298 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
18299 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
18301 /* Mnemonics shared by Neon and VFP. */
18302 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
18303 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18304 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18306 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18307 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18309 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18310 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18312 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18313 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18314 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18315 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18316 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18317 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18318 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18319 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18321 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
18322 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
18323 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
18324 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
18327 /* NOTE: All VMOV encoding is special-cased! */
18328 NCE(vmov, 0, 1, (VMOV), neon_mov),
18329 NCE(vmovq, 0, 1, (VMOV), neon_mov),
18331 #undef THUMB_VARIANT
18332 #define THUMB_VARIANT & fpu_neon_ext_v1
18334 #define ARM_VARIANT & fpu_neon_ext_v1
18336 /* Data processing with three registers of the same length. */
18337 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
18338 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
18339 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
18340 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18341 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18342 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18343 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18344 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18345 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18346 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
18347 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18348 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18349 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18350 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18351 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18352 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18353 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18354 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18355 /* If not immediate, fall back to neon_dyadic_i64_su.
18356 shl_imm should accept I8 I16 I32 I64,
18357 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
18358 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
18359 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
18360 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
18361 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
18362 /* Logic ops, types optional & ignored. */
18363 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18364 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18365 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18366 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18367 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18368 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18369 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18370 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18371 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
18372 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
18373 /* Bitfield ops, untyped. */
18374 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18375 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18376 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18377 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18378 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18379 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18380 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
18381 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18382 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18383 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18384 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18385 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18386 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18387 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
18388 back to neon_dyadic_if_su. */
18389 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18390 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18391 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18392 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18393 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18394 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18395 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18396 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18397 /* Comparison. Type I8 I16 I32 F32. */
18398 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
18399 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
18400 /* As above, D registers only. */
18401 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18402 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18403 /* Int and float variants, signedness unimportant. */
18404 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18405 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18406 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
18407 /* Add/sub take types I8 I16 I32 I64 F32. */
18408 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18409 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18410 /* vtst takes sizes 8, 16, 32. */
18411 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
18412 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
18413 /* VMUL takes I8 I16 I32 F32 P8. */
18414 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
18415 /* VQD{R}MULH takes S16 S32. */
18416 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18417 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18418 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18419 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18420 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18421 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18422 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18423 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18424 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18425 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18426 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18427 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18428 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18429 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18430 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18431 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18433 /* Two address, int/float. Types S8 S16 S32 F32. */
18434 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
18435 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
18437 /* Data processing with two registers and a shift amount. */
18438 /* Right shifts, and variants with rounding.
18439 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
18440 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18441 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18442 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18443 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18444 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18445 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18446 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18447 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18448 /* Shift and insert. Sizes accepted 8 16 32 64. */
18449 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
18450 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
18451 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
18452 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
18453 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
18454 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
18455 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
18456 /* Right shift immediate, saturating & narrowing, with rounding variants.
18457 Types accepted S16 S32 S64 U16 U32 U64. */
18458 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18459 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18460 /* As above, unsigned. Types accepted S16 S32 S64. */
18461 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18462 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18463 /* Right shift narrowing. Types accepted I16 I32 I64. */
18464 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18465 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18466 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
18467 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
18468 /* CVT with optional immediate for fixed-point variant. */
18469 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
18471 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
18472 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
18474 /* Data processing, three registers of different lengths. */
18475 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
18476 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
18477 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
18478 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
18479 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
18480 /* If not scalar, fall back to neon_dyadic_long.
18481 Vector types as above, scalar types S16 S32 U16 U32. */
18482 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18483 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18484 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
18485 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18486 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18487 /* Dyadic, narrowing insns. Types I16 I32 I64. */
18488 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18489 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18490 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18491 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18492 /* Saturating doubling multiplies. Types S16 S32. */
18493 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18494 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18495 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18496 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
18497 S16 S32 U16 U32. */
18498 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
18500 /* Extract. Size 8. */
18501 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
18502 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
18504 /* Two registers, miscellaneous. */
18505 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
18506 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
18507 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
18508 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
18509 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
18510 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
18511 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
18512 /* Vector replicate. Sizes 8 16 32. */
18513 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
18514 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
18515 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
18516 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
18517 /* VMOVN. Types I16 I32 I64. */
18518 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
18519 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
18520 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
18521 /* VQMOVUN. Types S16 S32 S64. */
18522 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
18523 /* VZIP / VUZP. Sizes 8 16 32. */
18524 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
18525 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
18526 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
18527 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
18528 /* VQABS / VQNEG. Types S8 S16 S32. */
18529 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18530 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
18531 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18532 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
18533 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
18534 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
18535 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
18536 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
18537 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
18538 /* Reciprocal estimates. Types U32 F32. */
18539 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
18540 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
18541 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
18542 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
18543 /* VCLS. Types S8 S16 S32. */
18544 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
18545 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
18546 /* VCLZ. Types I8 I16 I32. */
18547 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
18548 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
18549 /* VCNT. Size 8. */
18550 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18551 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18552 /* Two address, untyped. */
18553 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18554 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18555 /* VTRN. Sizes 8 16 32. */
18556 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18557 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
18559 /* Table lookup. Size 8. */
18560 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18561 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18563 #undef THUMB_VARIANT
18564 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18566 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18568 /* Neon element/structure load/store. */
18569 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18570 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18571 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18572 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18573 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18574 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18575 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18576 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18578 #undef THUMB_VARIANT
18579 #define THUMB_VARIANT &fpu_vfp_ext_v3xd
18581 #define ARM_VARIANT &fpu_vfp_ext_v3xd
18582 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18583 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18584 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18585 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18586 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18587 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18588 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18589 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18590 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18592 #undef THUMB_VARIANT
18593 #define THUMB_VARIANT & fpu_vfp_ext_v3
18595 #define ARM_VARIANT & fpu_vfp_ext_v3
18597 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
18598 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18599 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18600 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18601 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18602 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18603 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18604 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18605 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18608 #define ARM_VARIANT &fpu_vfp_ext_fma
18609 #undef THUMB_VARIANT
18610 #define THUMB_VARIANT &fpu_vfp_ext_fma
18611 /* Mnemonics shared by Neon and VFP. These are included in the
18612 VFP FMA variant; NEON and VFP FMA always includes the NEON
18613 FMA instructions. */
18614 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18615 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18616 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18617 the v form should always be used. */
18618 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18619 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18620 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18621 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18622 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18623 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18625 #undef THUMB_VARIANT
18627 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18629 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18630 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18631 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18632 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18633 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18634 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18635 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18636 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
18639 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18641 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18642 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18643 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18644 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18645 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18646 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18647 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18648 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18649 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18650 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18651 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18652 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18653 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18654 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18655 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18656 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18657 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18658 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18659 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18660 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18661 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18662 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18663 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18664 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18665 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18666 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18667 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18668 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18669 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18670 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18671 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18672 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18673 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18674 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18675 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18676 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18677 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18678 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18679 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18680 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18681 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18682 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18683 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18684 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18685 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18686 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18687 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18688 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18689 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18690 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18691 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18692 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18693 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18694 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18695 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18696 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18697 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18698 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18699 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18700 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18701 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18702 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18703 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18704 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18705 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18706 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18707 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18708 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18709 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18710 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18711 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18712 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18713 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18714 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18715 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18716 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18717 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18718 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18719 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18720 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18721 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18722 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18723 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18724 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18725 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18726 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18727 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18728 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18729 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18730 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18731 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18732 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18733 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18734 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18735 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18736 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18737 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18738 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18739 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18740 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18741 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18742 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18743 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18744 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18745 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18746 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18747 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18748 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18749 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18750 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18751 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18752 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18753 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18754 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18755 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18756 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18757 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18758 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18759 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18760 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18761 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18762 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18763 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18764 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18765 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18766 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18767 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18768 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18769 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18770 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18771 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18772 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18773 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18774 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18775 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18776 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18777 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18778 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18779 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18780 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18781 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18782 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18783 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18784 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18785 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18786 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18787 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18788 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18789 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18790 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18791 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18792 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18793 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18794 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18795 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18796 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18797 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18798 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18799 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18800 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18801 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18802 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
18805 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18807 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18808 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18809 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18810 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18811 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18812 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18813 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18814 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18815 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18816 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18817 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18818 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18819 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18820 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18821 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18822 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18823 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18824 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18825 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18826 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18827 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18828 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18829 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18830 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18831 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18832 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18833 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18834 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18835 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18836 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18837 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18838 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18839 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18840 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18841 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18842 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18843 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18844 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18845 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18846 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18847 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18848 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18849 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18850 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18851 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18852 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18853 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18854 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18855 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18856 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18857 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18858 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18859 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18860 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18861 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18862 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18863 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18866 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18868 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18869 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18870 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18871 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18872 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18873 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18874 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18875 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18876 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18877 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18878 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18879 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18880 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18881 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18882 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18883 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18884 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18885 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18886 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18887 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18888 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18889 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18890 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18891 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18892 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18893 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18894 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18895 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18896 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18897 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18898 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18899 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18900 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18901 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18902 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18903 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18904 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18905 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18906 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18907 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18908 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18909 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18910 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18911 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18912 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18913 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18914 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18915 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18916 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18917 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18918 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18919 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18920 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18921 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18922 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18923 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18924 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18925 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18926 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18927 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18928 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18929 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18930 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18931 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18932 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18933 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18934 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18935 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18936 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18937 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18938 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18939 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18940 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18941 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18942 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18943 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18946 #undef THUMB_VARIANT
18973 /* MD interface: bits in the object file. */
18975 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18976 for use in the a.out file, and stores them in the array pointed to by buf.
18977 This knows about the endian-ness of the target machine and does
18978 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18979 2 (short) and 4 (long) Floating numbers are put out as a series of
18980 LITTLENUMS (shorts, here at least). */
18983 md_number_to_chars (char * buf, valueT val, int n)
18985 if (target_big_endian)
18986 number_to_chars_bigendian (buf, val, n);
18988 number_to_chars_littleendian (buf, val, n);
18992 md_chars_to_number (char * buf, int n)
18995 unsigned char * where = (unsigned char *) buf;
18997 if (target_big_endian)
19002 result |= (*where++ & 255);
19010 result |= (where[n] & 255);
19017 /* MD interface: Sections. */
19019 /* Calculate the maximum variable size (i.e., excluding fr_fix)
19020 that an rs_machine_dependent frag may reach. */
19023 arm_frag_max_var (fragS *fragp)
19025 /* We only use rs_machine_dependent for variable-size Thumb instructions,
19026 which are either THUMB_SIZE (2) or INSN_SIZE (4).
19028 Note that we generate relaxable instructions even for cases that don't
19029 really need it, like an immediate that's a trivial constant. So we're
19030 overestimating the instruction size for some of those cases. Rather
19031 than putting more intelligence here, it would probably be better to
19032 avoid generating a relaxation frag in the first place when it can be
19033 determined up front that a short instruction will suffice. */
19035 gas_assert (fragp->fr_type == rs_machine_dependent);
19039 /* Estimate the size of a frag before relaxing. Assume everything fits in
19043 md_estimate_size_before_relax (fragS * fragp,
19044 segT segtype ATTRIBUTE_UNUSED)
19050 /* Convert a machine dependent frag. */
19053 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
19055 unsigned long insn;
19056 unsigned long old_op;
19064 buf = fragp->fr_literal + fragp->fr_fix;
19066 old_op = bfd_get_16(abfd, buf);
19067 if (fragp->fr_symbol)
19069 exp.X_op = O_symbol;
19070 exp.X_add_symbol = fragp->fr_symbol;
19074 exp.X_op = O_constant;
19076 exp.X_add_number = fragp->fr_offset;
19077 opcode = fragp->fr_subtype;
19080 case T_MNEM_ldr_pc:
19081 case T_MNEM_ldr_pc2:
19082 case T_MNEM_ldr_sp:
19083 case T_MNEM_str_sp:
19090 if (fragp->fr_var == 4)
19092 insn = THUMB_OP32 (opcode);
19093 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
19095 insn |= (old_op & 0x700) << 4;
19099 insn |= (old_op & 7) << 12;
19100 insn |= (old_op & 0x38) << 13;
19102 insn |= 0x00000c00;
19103 put_thumb32_insn (buf, insn);
19104 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
19108 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
19110 pc_rel = (opcode == T_MNEM_ldr_pc2);
19113 if (fragp->fr_var == 4)
19115 insn = THUMB_OP32 (opcode);
19116 insn |= (old_op & 0xf0) << 4;
19117 put_thumb32_insn (buf, insn);
19118 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
19122 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19123 exp.X_add_number -= 4;
19131 if (fragp->fr_var == 4)
19133 int r0off = (opcode == T_MNEM_mov
19134 || opcode == T_MNEM_movs) ? 0 : 8;
19135 insn = THUMB_OP32 (opcode);
19136 insn = (insn & 0xe1ffffff) | 0x10000000;
19137 insn |= (old_op & 0x700) << r0off;
19138 put_thumb32_insn (buf, insn);
19139 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19143 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
19148 if (fragp->fr_var == 4)
19150 insn = THUMB_OP32(opcode);
19151 put_thumb32_insn (buf, insn);
19152 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
19155 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
19159 if (fragp->fr_var == 4)
19161 insn = THUMB_OP32(opcode);
19162 insn |= (old_op & 0xf00) << 14;
19163 put_thumb32_insn (buf, insn);
19164 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
19167 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
19170 case T_MNEM_add_sp:
19171 case T_MNEM_add_pc:
19172 case T_MNEM_inc_sp:
19173 case T_MNEM_dec_sp:
19174 if (fragp->fr_var == 4)
19176 /* ??? Choose between add and addw. */
19177 insn = THUMB_OP32 (opcode);
19178 insn |= (old_op & 0xf0) << 4;
19179 put_thumb32_insn (buf, insn);
19180 if (opcode == T_MNEM_add_pc)
19181 reloc_type = BFD_RELOC_ARM_T32_IMM12;
19183 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
19186 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19194 if (fragp->fr_var == 4)
19196 insn = THUMB_OP32 (opcode);
19197 insn |= (old_op & 0xf0) << 4;
19198 insn |= (old_op & 0xf) << 16;
19199 put_thumb32_insn (buf, insn);
19200 if (insn & (1 << 20))
19201 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
19203 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19206 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19212 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
19213 (enum bfd_reloc_code_real) reloc_type);
19214 fixp->fx_file = fragp->fr_file;
19215 fixp->fx_line = fragp->fr_line;
19216 fragp->fr_fix += fragp->fr_var;
19219 /* Return the size of a relaxable immediate operand instruction.
19220 SHIFT and SIZE specify the form of the allowable immediate. */
19222 relax_immediate (fragS *fragp, int size, int shift)
19228 /* ??? Should be able to do better than this. */
19229 if (fragp->fr_symbol)
19232 low = (1 << shift) - 1;
19233 mask = (1 << (shift + size)) - (1 << shift);
19234 offset = fragp->fr_offset;
19235 /* Force misaligned offsets to 32-bit variant. */
19238 if (offset & ~mask)
19243 /* Get the address of a symbol during relaxation. */
19245 relaxed_symbol_addr (fragS *fragp, long stretch)
19251 sym = fragp->fr_symbol;
19252 sym_frag = symbol_get_frag (sym);
19253 know (S_GET_SEGMENT (sym) != absolute_section
19254 || sym_frag == &zero_address_frag);
19255 addr = S_GET_VALUE (sym) + fragp->fr_offset;
19257 /* If frag has yet to be reached on this pass, assume it will
19258 move by STRETCH just as we did. If this is not so, it will
19259 be because some frag between grows, and that will force
19263 && sym_frag->relax_marker != fragp->relax_marker)
19267 /* Adjust stretch for any alignment frag. Note that if have
19268 been expanding the earlier code, the symbol may be
19269 defined in what appears to be an earlier frag. FIXME:
19270 This doesn't handle the fr_subtype field, which specifies
19271 a maximum number of bytes to skip when doing an
19273 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
19275 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
19278 stretch = - ((- stretch)
19279 & ~ ((1 << (int) f->fr_offset) - 1));
19281 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
19293 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
19296 relax_adr (fragS *fragp, asection *sec, long stretch)
19301 /* Assume worst case for symbols not known to be in the same section. */
19302 if (fragp->fr_symbol == NULL
19303 || !S_IS_DEFINED (fragp->fr_symbol)
19304 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19305 || S_IS_WEAK (fragp->fr_symbol))
19308 val = relaxed_symbol_addr (fragp, stretch);
19309 addr = fragp->fr_address + fragp->fr_fix;
19310 addr = (addr + 4) & ~3;
19311 /* Force misaligned targets to 32-bit variant. */
19315 if (val < 0 || val > 1020)
19320 /* Return the size of a relaxable add/sub immediate instruction. */
19322 relax_addsub (fragS *fragp, asection *sec)
19327 buf = fragp->fr_literal + fragp->fr_fix;
19328 op = bfd_get_16(sec->owner, buf);
19329 if ((op & 0xf) == ((op >> 4) & 0xf))
19330 return relax_immediate (fragp, 8, 0);
19332 return relax_immediate (fragp, 3, 0);
19336 /* Return the size of a relaxable branch instruction. BITS is the
19337 size of the offset field in the narrow instruction. */
19340 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
19346 /* Assume worst case for symbols not known to be in the same section. */
19347 if (!S_IS_DEFINED (fragp->fr_symbol)
19348 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19349 || S_IS_WEAK (fragp->fr_symbol))
19353 if (S_IS_DEFINED (fragp->fr_symbol)
19354 && ARM_IS_FUNC (fragp->fr_symbol))
19357 /* PR 12532. Global symbols with default visibility might
19358 be preempted, so do not relax relocations to them. */
19359 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
19360 && (! S_IS_LOCAL (fragp->fr_symbol)))
19364 val = relaxed_symbol_addr (fragp, stretch);
19365 addr = fragp->fr_address + fragp->fr_fix + 4;
19368 /* Offset is a signed value *2 */
19370 if (val >= limit || val < -limit)
19376 /* Relax a machine dependent frag. This returns the amount by which
19377 the current size of the frag should change. */
19380 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
19385 oldsize = fragp->fr_var;
19386 switch (fragp->fr_subtype)
19388 case T_MNEM_ldr_pc2:
19389 newsize = relax_adr (fragp, sec, stretch);
19391 case T_MNEM_ldr_pc:
19392 case T_MNEM_ldr_sp:
19393 case T_MNEM_str_sp:
19394 newsize = relax_immediate (fragp, 8, 2);
19398 newsize = relax_immediate (fragp, 5, 2);
19402 newsize = relax_immediate (fragp, 5, 1);
19406 newsize = relax_immediate (fragp, 5, 0);
19409 newsize = relax_adr (fragp, sec, stretch);
19415 newsize = relax_immediate (fragp, 8, 0);
19418 newsize = relax_branch (fragp, sec, 11, stretch);
19421 newsize = relax_branch (fragp, sec, 8, stretch);
19423 case T_MNEM_add_sp:
19424 case T_MNEM_add_pc:
19425 newsize = relax_immediate (fragp, 8, 2);
19427 case T_MNEM_inc_sp:
19428 case T_MNEM_dec_sp:
19429 newsize = relax_immediate (fragp, 7, 2);
19435 newsize = relax_addsub (fragp, sec);
19441 fragp->fr_var = newsize;
19442 /* Freeze wide instructions that are at or before the same location as
19443 in the previous pass. This avoids infinite loops.
19444 Don't freeze them unconditionally because targets may be artificially
19445 misaligned by the expansion of preceding frags. */
19446 if (stretch <= 0 && newsize > 2)
19448 md_convert_frag (sec->owner, sec, fragp);
19452 return newsize - oldsize;
19455 /* Round up a section size to the appropriate boundary. */
19458 md_section_align (segT segment ATTRIBUTE_UNUSED,
19461 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
19462 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
19464 /* For a.out, force the section size to be aligned. If we don't do
19465 this, BFD will align it for us, but it will not write out the
19466 final bytes of the section. This may be a bug in BFD, but it is
19467 easier to fix it here since that is how the other a.out targets
19471 align = bfd_get_section_alignment (stdoutput, segment);
19472 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
19479 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
19480 of an rs_align_code fragment. */
19483 arm_handle_align (fragS * fragP)
19485 static char const arm_noop[2][2][4] =
19488 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
19489 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
19492 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
19493 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
19496 static char const thumb_noop[2][2][2] =
19499 {0xc0, 0x46}, /* LE */
19500 {0x46, 0xc0}, /* BE */
19503 {0x00, 0xbf}, /* LE */
19504 {0xbf, 0x00} /* BE */
19507 static char const wide_thumb_noop[2][4] =
19508 { /* Wide Thumb-2 */
19509 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
19510 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
19513 unsigned bytes, fix, noop_size;
19516 const char *narrow_noop = NULL;
19521 if (fragP->fr_type != rs_align_code)
19524 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
19525 p = fragP->fr_literal + fragP->fr_fix;
19528 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
19529 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
19531 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
19533 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
19535 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
19537 narrow_noop = thumb_noop[1][target_big_endian];
19538 noop = wide_thumb_noop[target_big_endian];
19541 noop = thumb_noop[0][target_big_endian];
19549 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
19550 [target_big_endian];
19557 fragP->fr_var = noop_size;
19559 if (bytes & (noop_size - 1))
19561 fix = bytes & (noop_size - 1);
19563 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
19565 memset (p, 0, fix);
19572 if (bytes & noop_size)
19574 /* Insert a narrow noop. */
19575 memcpy (p, narrow_noop, noop_size);
19577 bytes -= noop_size;
19581 /* Use wide noops for the remainder */
19585 while (bytes >= noop_size)
19587 memcpy (p, noop, noop_size);
19589 bytes -= noop_size;
19593 fragP->fr_fix += fix;
19596 /* Called from md_do_align. Used to create an alignment
19597 frag in a code section. */
19600 arm_frag_align_code (int n, int max)
19604 /* We assume that there will never be a requirement
19605 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
19606 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
19611 _("alignments greater than %d bytes not supported in .text sections."),
19612 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
19613 as_fatal ("%s", err_msg);
19616 p = frag_var (rs_align_code,
19617 MAX_MEM_FOR_RS_ALIGN_CODE,
19619 (relax_substateT) max,
19626 /* Perform target specific initialisation of a frag.
19627 Note - despite the name this initialisation is not done when the frag
19628 is created, but only when its type is assigned. A frag can be created
19629 and used a long time before its type is set, so beware of assuming that
19630 this initialisationis performed first. */
19634 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19636 /* Record whether this frag is in an ARM or a THUMB area. */
19637 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19640 #else /* OBJ_ELF is defined. */
19642 arm_init_frag (fragS * fragP, int max_chars)
19644 /* If the current ARM vs THUMB mode has not already
19645 been recorded into this frag then do so now. */
19646 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19648 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19650 /* Record a mapping symbol for alignment frags. We will delete this
19651 later if the alignment ends up empty. */
19652 switch (fragP->fr_type)
19655 case rs_align_test:
19657 mapping_state_2 (MAP_DATA, max_chars);
19659 case rs_align_code:
19660 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19668 /* When we change sections we need to issue a new mapping symbol. */
19671 arm_elf_change_section (void)
19673 /* Link an unlinked unwind index table section to the .text section. */
19674 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19675 && elf_linked_to_section (now_seg) == NULL)
19676 elf_linked_to_section (now_seg) = text_section;
19680 arm_elf_section_type (const char * str, size_t len)
19682 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19683 return SHT_ARM_EXIDX;
19688 /* Code to deal with unwinding tables. */
19690 static void add_unwind_adjustsp (offsetT);
19692 /* Generate any deferred unwind frame offset. */
19695 flush_pending_unwind (void)
19699 offset = unwind.pending_offset;
19700 unwind.pending_offset = 0;
19702 add_unwind_adjustsp (offset);
19705 /* Add an opcode to this list for this function. Two-byte opcodes should
19706 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19710 add_unwind_opcode (valueT op, int length)
19712 /* Add any deferred stack adjustment. */
19713 if (unwind.pending_offset)
19714 flush_pending_unwind ();
19716 unwind.sp_restored = 0;
19718 if (unwind.opcode_count + length > unwind.opcode_alloc)
19720 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19721 if (unwind.opcodes)
19722 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19723 unwind.opcode_alloc);
19725 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
19730 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19732 unwind.opcode_count++;
19736 /* Add unwind opcodes to adjust the stack pointer. */
19739 add_unwind_adjustsp (offsetT offset)
19743 if (offset > 0x200)
19745 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19750 /* Long form: 0xb2, uleb128. */
19751 /* This might not fit in a word so add the individual bytes,
19752 remembering the list is built in reverse order. */
19753 o = (valueT) ((offset - 0x204) >> 2);
19755 add_unwind_opcode (0, 1);
19757 /* Calculate the uleb128 encoding of the offset. */
19761 bytes[n] = o & 0x7f;
19767 /* Add the insn. */
19769 add_unwind_opcode (bytes[n - 1], 1);
19770 add_unwind_opcode (0xb2, 1);
19772 else if (offset > 0x100)
19774 /* Two short opcodes. */
19775 add_unwind_opcode (0x3f, 1);
19776 op = (offset - 0x104) >> 2;
19777 add_unwind_opcode (op, 1);
19779 else if (offset > 0)
19781 /* Short opcode. */
19782 op = (offset - 4) >> 2;
19783 add_unwind_opcode (op, 1);
19785 else if (offset < 0)
19788 while (offset > 0x100)
19790 add_unwind_opcode (0x7f, 1);
19793 op = ((offset - 4) >> 2) | 0x40;
19794 add_unwind_opcode (op, 1);
19798 /* Finish the list of unwind opcodes for this function. */
19800 finish_unwind_opcodes (void)
19804 if (unwind.fp_used)
19806 /* Adjust sp as necessary. */
19807 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19808 flush_pending_unwind ();
19810 /* After restoring sp from the frame pointer. */
19811 op = 0x90 | unwind.fp_reg;
19812 add_unwind_opcode (op, 1);
19815 flush_pending_unwind ();
19819 /* Start an exception table entry. If idx is nonzero this is an index table
19823 start_unwind_section (const segT text_seg, int idx)
19825 const char * text_name;
19826 const char * prefix;
19827 const char * prefix_once;
19828 const char * group_name;
19832 size_t sec_name_len;
19839 prefix = ELF_STRING_ARM_unwind;
19840 prefix_once = ELF_STRING_ARM_unwind_once;
19841 type = SHT_ARM_EXIDX;
19845 prefix = ELF_STRING_ARM_unwind_info;
19846 prefix_once = ELF_STRING_ARM_unwind_info_once;
19847 type = SHT_PROGBITS;
19850 text_name = segment_name (text_seg);
19851 if (streq (text_name, ".text"))
19854 if (strncmp (text_name, ".gnu.linkonce.t.",
19855 strlen (".gnu.linkonce.t.")) == 0)
19857 prefix = prefix_once;
19858 text_name += strlen (".gnu.linkonce.t.");
19861 prefix_len = strlen (prefix);
19862 text_len = strlen (text_name);
19863 sec_name_len = prefix_len + text_len;
19864 sec_name = (char *) xmalloc (sec_name_len + 1);
19865 memcpy (sec_name, prefix, prefix_len);
19866 memcpy (sec_name + prefix_len, text_name, text_len);
19867 sec_name[prefix_len + text_len] = '\0';
19873 /* Handle COMDAT group. */
19874 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
19876 group_name = elf_group_name (text_seg);
19877 if (group_name == NULL)
19879 as_bad (_("Group section `%s' has no group signature"),
19880 segment_name (text_seg));
19881 ignore_rest_of_line ();
19884 flags |= SHF_GROUP;
19888 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
19890 /* Set the section link for index tables. */
19892 elf_linked_to_section (now_seg) = text_seg;
19896 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19897 personality routine data. Returns zero, or the index table value for
19898 and inline entry. */
19901 create_unwind_entry (int have_data)
19906 /* The current word of data. */
19908 /* The number of bytes left in this word. */
19911 finish_unwind_opcodes ();
19913 /* Remember the current text section. */
19914 unwind.saved_seg = now_seg;
19915 unwind.saved_subseg = now_subseg;
19917 start_unwind_section (now_seg, 0);
19919 if (unwind.personality_routine == NULL)
19921 if (unwind.personality_index == -2)
19924 as_bad (_("handlerdata in cantunwind frame"));
19925 return 1; /* EXIDX_CANTUNWIND. */
19928 /* Use a default personality routine if none is specified. */
19929 if (unwind.personality_index == -1)
19931 if (unwind.opcode_count > 3)
19932 unwind.personality_index = 1;
19934 unwind.personality_index = 0;
19937 /* Space for the personality routine entry. */
19938 if (unwind.personality_index == 0)
19940 if (unwind.opcode_count > 3)
19941 as_bad (_("too many unwind opcodes for personality routine 0"));
19945 /* All the data is inline in the index table. */
19948 while (unwind.opcode_count > 0)
19950 unwind.opcode_count--;
19951 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19955 /* Pad with "finish" opcodes. */
19957 data = (data << 8) | 0xb0;
19964 /* We get two opcodes "free" in the first word. */
19965 size = unwind.opcode_count - 2;
19969 gas_assert (unwind.personality_index == -1);
19971 /* An extra byte is required for the opcode count. */
19972 size = unwind.opcode_count + 1;
19975 size = (size + 3) >> 2;
19977 as_bad (_("too many unwind opcodes"));
19979 frag_align (2, 0, 0);
19980 record_alignment (now_seg, 2);
19981 unwind.table_entry = expr_build_dot ();
19983 /* Allocate the table entry. */
19984 ptr = frag_more ((size << 2) + 4);
19985 /* PR 13449: Zero the table entries in case some of them are not used. */
19986 memset (ptr, 0, (size << 2) + 4);
19987 where = frag_now_fix () - ((size << 2) + 4);
19989 switch (unwind.personality_index)
19992 /* ??? Should this be a PLT generating relocation? */
19993 /* Custom personality routine. */
19994 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19995 BFD_RELOC_ARM_PREL31);
20000 /* Set the first byte to the number of additional words. */
20001 data = size > 0 ? size - 1 : 0;
20005 /* ABI defined personality routines. */
20007 /* Three opcodes bytes are packed into the first word. */
20014 /* The size and first two opcode bytes go in the first word. */
20015 data = ((0x80 + unwind.personality_index) << 8) | size;
20020 /* Should never happen. */
20024 /* Pack the opcodes into words (MSB first), reversing the list at the same
20026 while (unwind.opcode_count > 0)
20030 md_number_to_chars (ptr, data, 4);
20035 unwind.opcode_count--;
20037 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20040 /* Finish off the last word. */
20043 /* Pad with "finish" opcodes. */
20045 data = (data << 8) | 0xb0;
20047 md_number_to_chars (ptr, data, 4);
20052 /* Add an empty descriptor if there is no user-specified data. */
20053 ptr = frag_more (4);
20054 md_number_to_chars (ptr, 0, 4);
20061 /* Initialize the DWARF-2 unwind information for this procedure. */
20064 tc_arm_frame_initial_instructions (void)
20066 cfi_add_CFA_def_cfa (REG_SP, 0);
20068 #endif /* OBJ_ELF */
20070 /* Convert REGNAME to a DWARF-2 register number. */
20073 tc_arm_regname_to_dw2regnum (char *regname)
20075 int reg = arm_reg_parse (®name, REG_TYPE_RN);
20085 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
20089 exp.X_op = O_secrel;
20090 exp.X_add_symbol = symbol;
20091 exp.X_add_number = 0;
20092 emit_expr (&exp, size);
20096 /* MD interface: Symbol and relocation handling. */
20098 /* Return the address within the segment that a PC-relative fixup is
20099 relative to. For ARM, PC-relative fixups applied to instructions
20100 are generally relative to the location of the fixup plus 8 bytes.
20101 Thumb branches are offset by 4, and Thumb loads relative to PC
20102 require special handling. */
20105 md_pcrel_from_section (fixS * fixP, segT seg)
20107 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
20109 /* If this is pc-relative and we are going to emit a relocation
20110 then we just want to put out any pipeline compensation that the linker
20111 will need. Otherwise we want to use the calculated base.
20112 For WinCE we skip the bias for externals as well, since this
20113 is how the MS ARM-CE assembler behaves and we want to be compatible. */
20115 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
20116 || (arm_force_relocation (fixP)
20118 && !S_IS_EXTERNAL (fixP->fx_addsy)
20124 switch (fixP->fx_r_type)
20126 /* PC relative addressing on the Thumb is slightly odd as the
20127 bottom two bits of the PC are forced to zero for the
20128 calculation. This happens *after* application of the
20129 pipeline offset. However, Thumb adrl already adjusts for
20130 this, so we need not do it again. */
20131 case BFD_RELOC_ARM_THUMB_ADD:
20134 case BFD_RELOC_ARM_THUMB_OFFSET:
20135 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20136 case BFD_RELOC_ARM_T32_ADD_PC12:
20137 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
20138 return (base + 4) & ~3;
20140 /* Thumb branches are simply offset by +4. */
20141 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20142 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20143 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20144 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20145 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20148 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20150 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20151 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20152 && ARM_IS_FUNC (fixP->fx_addsy)
20153 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20154 base = fixP->fx_where + fixP->fx_frag->fr_address;
20157 /* BLX is like branches above, but forces the low two bits of PC to
20159 case BFD_RELOC_THUMB_PCREL_BLX:
20161 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20162 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20163 && THUMB_IS_FUNC (fixP->fx_addsy)
20164 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20165 base = fixP->fx_where + fixP->fx_frag->fr_address;
20166 return (base + 4) & ~3;
20168 /* ARM mode branches are offset by +8. However, the Windows CE
20169 loader expects the relocation not to take this into account. */
20170 case BFD_RELOC_ARM_PCREL_BLX:
20172 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20173 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20174 && ARM_IS_FUNC (fixP->fx_addsy)
20175 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20176 base = fixP->fx_where + fixP->fx_frag->fr_address;
20179 case BFD_RELOC_ARM_PCREL_CALL:
20181 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20182 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20183 && THUMB_IS_FUNC (fixP->fx_addsy)
20184 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20185 base = fixP->fx_where + fixP->fx_frag->fr_address;
20188 case BFD_RELOC_ARM_PCREL_BRANCH:
20189 case BFD_RELOC_ARM_PCREL_JUMP:
20190 case BFD_RELOC_ARM_PLT32:
20192 /* When handling fixups immediately, because we have already
20193 discovered the value of a symbol, or the address of the frag involved
20194 we must account for the offset by +8, as the OS loader will never see the reloc.
20195 see fixup_segment() in write.c
20196 The S_IS_EXTERNAL test handles the case of global symbols.
20197 Those need the calculated base, not just the pipe compensation the linker will need. */
20199 && fixP->fx_addsy != NULL
20200 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20201 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
20209 /* ARM mode loads relative to PC are also offset by +8. Unlike
20210 branches, the Windows CE loader *does* expect the relocation
20211 to take this into account. */
20212 case BFD_RELOC_ARM_OFFSET_IMM:
20213 case BFD_RELOC_ARM_OFFSET_IMM8:
20214 case BFD_RELOC_ARM_HWLITERAL:
20215 case BFD_RELOC_ARM_LITERAL:
20216 case BFD_RELOC_ARM_CP_OFF_IMM:
20220 /* Other PC-relative relocations are un-offset. */
20226 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
20227 Otherwise we have no need to default values of symbols. */
20230 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
20233 if (name[0] == '_' && name[1] == 'G'
20234 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
20238 if (symbol_find (name))
20239 as_bad (_("GOT already in the symbol table"));
20241 GOT_symbol = symbol_new (name, undefined_section,
20242 (valueT) 0, & zero_address_frag);
20252 /* Subroutine of md_apply_fix. Check to see if an immediate can be
20253 computed as two separate immediate values, added together. We
20254 already know that this value cannot be computed by just one ARM
20257 static unsigned int
20258 validate_immediate_twopart (unsigned int val,
20259 unsigned int * highpart)
20264 for (i = 0; i < 32; i += 2)
20265 if (((a = rotate_left (val, i)) & 0xff) != 0)
20271 * highpart = (a >> 8) | ((i + 24) << 7);
20273 else if (a & 0xff0000)
20275 if (a & 0xff000000)
20277 * highpart = (a >> 16) | ((i + 16) << 7);
20281 gas_assert (a & 0xff000000);
20282 * highpart = (a >> 24) | ((i + 8) << 7);
20285 return (a & 0xff) | (i << 7);
20292 validate_offset_imm (unsigned int val, int hwse)
20294 if ((hwse && val > 255) || val > 4095)
20299 /* Subroutine of md_apply_fix. Do those data_ops which can take a
20300 negative immediate constant by altering the instruction. A bit of
20305 by inverting the second operand, and
20308 by negating the second operand. */
20311 negate_data_op (unsigned long * instruction,
20312 unsigned long value)
20315 unsigned long negated, inverted;
20317 negated = encode_arm_immediate (-value);
20318 inverted = encode_arm_immediate (~value);
20320 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
20323 /* First negates. */
20324 case OPCODE_SUB: /* ADD <-> SUB */
20325 new_inst = OPCODE_ADD;
20330 new_inst = OPCODE_SUB;
20334 case OPCODE_CMP: /* CMP <-> CMN */
20335 new_inst = OPCODE_CMN;
20340 new_inst = OPCODE_CMP;
20344 /* Now Inverted ops. */
20345 case OPCODE_MOV: /* MOV <-> MVN */
20346 new_inst = OPCODE_MVN;
20351 new_inst = OPCODE_MOV;
20355 case OPCODE_AND: /* AND <-> BIC */
20356 new_inst = OPCODE_BIC;
20361 new_inst = OPCODE_AND;
20365 case OPCODE_ADC: /* ADC <-> SBC */
20366 new_inst = OPCODE_SBC;
20371 new_inst = OPCODE_ADC;
20375 /* We cannot do anything. */
20380 if (value == (unsigned) FAIL)
20383 *instruction &= OPCODE_MASK;
20384 *instruction |= new_inst << DATA_OP_SHIFT;
20388 /* Like negate_data_op, but for Thumb-2. */
20390 static unsigned int
20391 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
20395 unsigned int negated, inverted;
20397 negated = encode_thumb32_immediate (-value);
20398 inverted = encode_thumb32_immediate (~value);
20400 rd = (*instruction >> 8) & 0xf;
20401 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
20404 /* ADD <-> SUB. Includes CMP <-> CMN. */
20405 case T2_OPCODE_SUB:
20406 new_inst = T2_OPCODE_ADD;
20410 case T2_OPCODE_ADD:
20411 new_inst = T2_OPCODE_SUB;
20415 /* ORR <-> ORN. Includes MOV <-> MVN. */
20416 case T2_OPCODE_ORR:
20417 new_inst = T2_OPCODE_ORN;
20421 case T2_OPCODE_ORN:
20422 new_inst = T2_OPCODE_ORR;
20426 /* AND <-> BIC. TST has no inverted equivalent. */
20427 case T2_OPCODE_AND:
20428 new_inst = T2_OPCODE_BIC;
20435 case T2_OPCODE_BIC:
20436 new_inst = T2_OPCODE_AND;
20441 case T2_OPCODE_ADC:
20442 new_inst = T2_OPCODE_SBC;
20446 case T2_OPCODE_SBC:
20447 new_inst = T2_OPCODE_ADC;
20451 /* We cannot do anything. */
20456 if (value == (unsigned int)FAIL)
20459 *instruction &= T2_OPCODE_MASK;
20460 *instruction |= new_inst << T2_DATA_OP_SHIFT;
20464 /* Read a 32-bit thumb instruction from buf. */
20465 static unsigned long
20466 get_thumb32_insn (char * buf)
20468 unsigned long insn;
20469 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
20470 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20476 /* We usually want to set the low bit on the address of thumb function
20477 symbols. In particular .word foo - . should have the low bit set.
20478 Generic code tries to fold the difference of two symbols to
20479 a constant. Prevent this and force a relocation when the first symbols
20480 is a thumb function. */
20483 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
20485 if (op == O_subtract
20486 && l->X_op == O_symbol
20487 && r->X_op == O_symbol
20488 && THUMB_IS_FUNC (l->X_add_symbol))
20490 l->X_op = O_subtract;
20491 l->X_op_symbol = r->X_add_symbol;
20492 l->X_add_number -= r->X_add_number;
20496 /* Process as normal. */
20500 /* Encode Thumb2 unconditional branches and calls. The encoding
20501 for the 2 are identical for the immediate values. */
20504 encode_thumb2_b_bl_offset (char * buf, offsetT value)
20506 #define T2I1I2MASK ((1 << 13) | (1 << 11))
20509 addressT S, I1, I2, lo, hi;
20511 S = (value >> 24) & 0x01;
20512 I1 = (value >> 23) & 0x01;
20513 I2 = (value >> 22) & 0x01;
20514 hi = (value >> 12) & 0x3ff;
20515 lo = (value >> 1) & 0x7ff;
20516 newval = md_chars_to_number (buf, THUMB_SIZE);
20517 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20518 newval |= (S << 10) | hi;
20519 newval2 &= ~T2I1I2MASK;
20520 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
20521 md_number_to_chars (buf, newval, THUMB_SIZE);
20522 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20526 md_apply_fix (fixS * fixP,
20530 offsetT value = * valP;
20532 unsigned int newimm;
20533 unsigned long temp;
20535 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
20537 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
20539 /* Note whether this will delete the relocation. */
20541 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
20544 /* On a 64-bit host, silently truncate 'value' to 32 bits for
20545 consistency with the behaviour on 32-bit hosts. Remember value
20547 value &= 0xffffffff;
20548 value ^= 0x80000000;
20549 value -= 0x80000000;
20552 fixP->fx_addnumber = value;
20554 /* Same treatment for fixP->fx_offset. */
20555 fixP->fx_offset &= 0xffffffff;
20556 fixP->fx_offset ^= 0x80000000;
20557 fixP->fx_offset -= 0x80000000;
20559 switch (fixP->fx_r_type)
20561 case BFD_RELOC_NONE:
20562 /* This will need to go in the object file. */
20566 case BFD_RELOC_ARM_IMMEDIATE:
20567 /* We claim that this fixup has been processed here,
20568 even if in fact we generate an error because we do
20569 not have a reloc for it, so tc_gen_reloc will reject it. */
20572 if (fixP->fx_addsy)
20574 const char *msg = 0;
20576 if (! S_IS_DEFINED (fixP->fx_addsy))
20577 msg = _("undefined symbol %s used as an immediate value");
20578 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20579 msg = _("symbol %s is in a different section");
20580 else if (S_IS_WEAK (fixP->fx_addsy))
20581 msg = _("symbol %s is weak and may be overridden later");
20585 as_bad_where (fixP->fx_file, fixP->fx_line,
20586 msg, S_GET_NAME (fixP->fx_addsy));
20591 newimm = encode_arm_immediate (value);
20592 temp = md_chars_to_number (buf, INSN_SIZE);
20594 /* If the instruction will fail, see if we can fix things up by
20595 changing the opcode. */
20596 if (newimm == (unsigned int) FAIL
20597 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
20599 as_bad_where (fixP->fx_file, fixP->fx_line,
20600 _("invalid constant (%lx) after fixup"),
20601 (unsigned long) value);
20605 newimm |= (temp & 0xfffff000);
20606 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20609 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20611 unsigned int highpart = 0;
20612 unsigned int newinsn = 0xe1a00000; /* nop. */
20614 if (fixP->fx_addsy)
20616 const char *msg = 0;
20618 if (! S_IS_DEFINED (fixP->fx_addsy))
20619 msg = _("undefined symbol %s used as an immediate value");
20620 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20621 msg = _("symbol %s is in a different section");
20622 else if (S_IS_WEAK (fixP->fx_addsy))
20623 msg = _("symbol %s is weak and may be overridden later");
20627 as_bad_where (fixP->fx_file, fixP->fx_line,
20628 msg, S_GET_NAME (fixP->fx_addsy));
20633 newimm = encode_arm_immediate (value);
20634 temp = md_chars_to_number (buf, INSN_SIZE);
20636 /* If the instruction will fail, see if we can fix things up by
20637 changing the opcode. */
20638 if (newimm == (unsigned int) FAIL
20639 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20641 /* No ? OK - try using two ADD instructions to generate
20643 newimm = validate_immediate_twopart (value, & highpart);
20645 /* Yes - then make sure that the second instruction is
20647 if (newimm != (unsigned int) FAIL)
20649 /* Still No ? Try using a negated value. */
20650 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20651 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20652 /* Otherwise - give up. */
20655 as_bad_where (fixP->fx_file, fixP->fx_line,
20656 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20661 /* Replace the first operand in the 2nd instruction (which
20662 is the PC) with the destination register. We have
20663 already added in the PC in the first instruction and we
20664 do not want to do it again. */
20665 newinsn &= ~ 0xf0000;
20666 newinsn |= ((newinsn & 0x0f000) << 4);
20669 newimm |= (temp & 0xfffff000);
20670 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20672 highpart |= (newinsn & 0xfffff000);
20673 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20677 case BFD_RELOC_ARM_OFFSET_IMM:
20678 if (!fixP->fx_done && seg->use_rela_p)
20681 case BFD_RELOC_ARM_LITERAL:
20687 if (validate_offset_imm (value, 0) == FAIL)
20689 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20690 as_bad_where (fixP->fx_file, fixP->fx_line,
20691 _("invalid literal constant: pool needs to be closer"));
20693 as_bad_where (fixP->fx_file, fixP->fx_line,
20694 _("bad immediate value for offset (%ld)"),
20699 newval = md_chars_to_number (buf, INSN_SIZE);
20701 newval &= 0xfffff000;
20704 newval &= 0xff7ff000;
20705 newval |= value | (sign ? INDEX_UP : 0);
20707 md_number_to_chars (buf, newval, INSN_SIZE);
20710 case BFD_RELOC_ARM_OFFSET_IMM8:
20711 case BFD_RELOC_ARM_HWLITERAL:
20717 if (validate_offset_imm (value, 1) == FAIL)
20719 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20720 as_bad_where (fixP->fx_file, fixP->fx_line,
20721 _("invalid literal constant: pool needs to be closer"));
20723 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
20728 newval = md_chars_to_number (buf, INSN_SIZE);
20730 newval &= 0xfffff0f0;
20733 newval &= 0xff7ff0f0;
20734 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20736 md_number_to_chars (buf, newval, INSN_SIZE);
20739 case BFD_RELOC_ARM_T32_OFFSET_U8:
20740 if (value < 0 || value > 1020 || value % 4 != 0)
20741 as_bad_where (fixP->fx_file, fixP->fx_line,
20742 _("bad immediate value for offset (%ld)"), (long) value);
20745 newval = md_chars_to_number (buf+2, THUMB_SIZE);
20747 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20750 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20751 /* This is a complicated relocation used for all varieties of Thumb32
20752 load/store instruction with immediate offset:
20754 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20755 *4, optional writeback(W)
20756 (doubleword load/store)
20758 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20759 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20760 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20761 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20762 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20764 Uppercase letters indicate bits that are already encoded at
20765 this point. Lowercase letters are our problem. For the
20766 second block of instructions, the secondary opcode nybble
20767 (bits 8..11) is present, and bit 23 is zero, even if this is
20768 a PC-relative operation. */
20769 newval = md_chars_to_number (buf, THUMB_SIZE);
20771 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
20773 if ((newval & 0xf0000000) == 0xe0000000)
20775 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20777 newval |= (1 << 23);
20780 if (value % 4 != 0)
20782 as_bad_where (fixP->fx_file, fixP->fx_line,
20783 _("offset not a multiple of 4"));
20789 as_bad_where (fixP->fx_file, fixP->fx_line,
20790 _("offset out of range"));
20795 else if ((newval & 0x000f0000) == 0x000f0000)
20797 /* PC-relative, 12-bit offset. */
20799 newval |= (1 << 23);
20804 as_bad_where (fixP->fx_file, fixP->fx_line,
20805 _("offset out of range"));
20810 else if ((newval & 0x00000100) == 0x00000100)
20812 /* Writeback: 8-bit, +/- offset. */
20814 newval |= (1 << 9);
20819 as_bad_where (fixP->fx_file, fixP->fx_line,
20820 _("offset out of range"));
20825 else if ((newval & 0x00000f00) == 0x00000e00)
20827 /* T-instruction: positive 8-bit offset. */
20828 if (value < 0 || value > 0xff)
20830 as_bad_where (fixP->fx_file, fixP->fx_line,
20831 _("offset out of range"));
20839 /* Positive 12-bit or negative 8-bit offset. */
20843 newval |= (1 << 23);
20853 as_bad_where (fixP->fx_file, fixP->fx_line,
20854 _("offset out of range"));
20861 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20862 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20865 case BFD_RELOC_ARM_SHIFT_IMM:
20866 newval = md_chars_to_number (buf, INSN_SIZE);
20867 if (((unsigned long) value) > 32
20869 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20871 as_bad_where (fixP->fx_file, fixP->fx_line,
20872 _("shift expression is too large"));
20877 /* Shifts of zero must be done as lsl. */
20879 else if (value == 32)
20881 newval &= 0xfffff07f;
20882 newval |= (value & 0x1f) << 7;
20883 md_number_to_chars (buf, newval, INSN_SIZE);
20886 case BFD_RELOC_ARM_T32_IMMEDIATE:
20887 case BFD_RELOC_ARM_T32_ADD_IMM:
20888 case BFD_RELOC_ARM_T32_IMM12:
20889 case BFD_RELOC_ARM_T32_ADD_PC12:
20890 /* We claim that this fixup has been processed here,
20891 even if in fact we generate an error because we do
20892 not have a reloc for it, so tc_gen_reloc will reject it. */
20896 && ! S_IS_DEFINED (fixP->fx_addsy))
20898 as_bad_where (fixP->fx_file, fixP->fx_line,
20899 _("undefined symbol %s used as an immediate value"),
20900 S_GET_NAME (fixP->fx_addsy));
20904 newval = md_chars_to_number (buf, THUMB_SIZE);
20906 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
20909 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20910 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20912 newimm = encode_thumb32_immediate (value);
20913 if (newimm == (unsigned int) FAIL)
20914 newimm = thumb32_negate_data_op (&newval, value);
20916 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20917 && newimm == (unsigned int) FAIL)
20919 /* Turn add/sum into addw/subw. */
20920 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20921 newval = (newval & 0xfeffffff) | 0x02000000;
20922 /* No flat 12-bit imm encoding for addsw/subsw. */
20923 if ((newval & 0x00100000) == 0)
20925 /* 12 bit immediate for addw/subw. */
20929 newval ^= 0x00a00000;
20932 newimm = (unsigned int) FAIL;
20938 if (newimm == (unsigned int)FAIL)
20940 as_bad_where (fixP->fx_file, fixP->fx_line,
20941 _("invalid constant (%lx) after fixup"),
20942 (unsigned long) value);
20946 newval |= (newimm & 0x800) << 15;
20947 newval |= (newimm & 0x700) << 4;
20948 newval |= (newimm & 0x0ff);
20950 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20951 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20954 case BFD_RELOC_ARM_SMC:
20955 if (((unsigned long) value) > 0xffff)
20956 as_bad_where (fixP->fx_file, fixP->fx_line,
20957 _("invalid smc expression"));
20958 newval = md_chars_to_number (buf, INSN_SIZE);
20959 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20960 md_number_to_chars (buf, newval, INSN_SIZE);
20963 case BFD_RELOC_ARM_HVC:
20964 if (((unsigned long) value) > 0xffff)
20965 as_bad_where (fixP->fx_file, fixP->fx_line,
20966 _("invalid hvc expression"));
20967 newval = md_chars_to_number (buf, INSN_SIZE);
20968 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20969 md_number_to_chars (buf, newval, INSN_SIZE);
20972 case BFD_RELOC_ARM_SWI:
20973 if (fixP->tc_fix_data != 0)
20975 if (((unsigned long) value) > 0xff)
20976 as_bad_where (fixP->fx_file, fixP->fx_line,
20977 _("invalid swi expression"));
20978 newval = md_chars_to_number (buf, THUMB_SIZE);
20980 md_number_to_chars (buf, newval, THUMB_SIZE);
20984 if (((unsigned long) value) > 0x00ffffff)
20985 as_bad_where (fixP->fx_file, fixP->fx_line,
20986 _("invalid swi expression"));
20987 newval = md_chars_to_number (buf, INSN_SIZE);
20989 md_number_to_chars (buf, newval, INSN_SIZE);
20993 case BFD_RELOC_ARM_MULTI:
20994 if (((unsigned long) value) > 0xffff)
20995 as_bad_where (fixP->fx_file, fixP->fx_line,
20996 _("invalid expression in load/store multiple"));
20997 newval = value | md_chars_to_number (buf, INSN_SIZE);
20998 md_number_to_chars (buf, newval, INSN_SIZE);
21002 case BFD_RELOC_ARM_PCREL_CALL:
21004 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21006 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21007 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21008 && THUMB_IS_FUNC (fixP->fx_addsy))
21009 /* Flip the bl to blx. This is a simple flip
21010 bit here because we generate PCREL_CALL for
21011 unconditional bls. */
21013 newval = md_chars_to_number (buf, INSN_SIZE);
21014 newval = newval | 0x10000000;
21015 md_number_to_chars (buf, newval, INSN_SIZE);
21021 goto arm_branch_common;
21023 case BFD_RELOC_ARM_PCREL_JUMP:
21024 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21026 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21027 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21028 && THUMB_IS_FUNC (fixP->fx_addsy))
21030 /* This would map to a bl<cond>, b<cond>,
21031 b<always> to a Thumb function. We
21032 need to force a relocation for this particular
21034 newval = md_chars_to_number (buf, INSN_SIZE);
21038 case BFD_RELOC_ARM_PLT32:
21040 case BFD_RELOC_ARM_PCREL_BRANCH:
21042 goto arm_branch_common;
21044 case BFD_RELOC_ARM_PCREL_BLX:
21047 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21049 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21050 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21051 && ARM_IS_FUNC (fixP->fx_addsy))
21053 /* Flip the blx to a bl and warn. */
21054 const char *name = S_GET_NAME (fixP->fx_addsy);
21055 newval = 0xeb000000;
21056 as_warn_where (fixP->fx_file, fixP->fx_line,
21057 _("blx to '%s' an ARM ISA state function changed to bl"),
21059 md_number_to_chars (buf, newval, INSN_SIZE);
21065 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21066 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
21070 /* We are going to store value (shifted right by two) in the
21071 instruction, in a 24 bit, signed field. Bits 26 through 32 either
21072 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
21073 also be be clear. */
21075 as_bad_where (fixP->fx_file, fixP->fx_line,
21076 _("misaligned branch destination"));
21077 if ((value & (offsetT)0xfe000000) != (offsetT)0
21078 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
21079 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21081 if (fixP->fx_done || !seg->use_rela_p)
21083 newval = md_chars_to_number (buf, INSN_SIZE);
21084 newval |= (value >> 2) & 0x00ffffff;
21085 /* Set the H bit on BLX instructions. */
21089 newval |= 0x01000000;
21091 newval &= ~0x01000000;
21093 md_number_to_chars (buf, newval, INSN_SIZE);
21097 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
21098 /* CBZ can only branch forward. */
21100 /* Attempts to use CBZ to branch to the next instruction
21101 (which, strictly speaking, are prohibited) will be turned into
21104 FIXME: It may be better to remove the instruction completely and
21105 perform relaxation. */
21108 newval = md_chars_to_number (buf, THUMB_SIZE);
21109 newval = 0xbf00; /* NOP encoding T1 */
21110 md_number_to_chars (buf, newval, THUMB_SIZE);
21115 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21117 if (fixP->fx_done || !seg->use_rela_p)
21119 newval = md_chars_to_number (buf, THUMB_SIZE);
21120 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
21121 md_number_to_chars (buf, newval, THUMB_SIZE);
21126 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
21127 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
21128 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21130 if (fixP->fx_done || !seg->use_rela_p)
21132 newval = md_chars_to_number (buf, THUMB_SIZE);
21133 newval |= (value & 0x1ff) >> 1;
21134 md_number_to_chars (buf, newval, THUMB_SIZE);
21138 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
21139 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
21140 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21142 if (fixP->fx_done || !seg->use_rela_p)
21144 newval = md_chars_to_number (buf, THUMB_SIZE);
21145 newval |= (value & 0xfff) >> 1;
21146 md_number_to_chars (buf, newval, THUMB_SIZE);
21150 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21152 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21153 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21154 && ARM_IS_FUNC (fixP->fx_addsy)
21155 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21157 /* Force a relocation for a branch 20 bits wide. */
21160 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
21161 as_bad_where (fixP->fx_file, fixP->fx_line,
21162 _("conditional branch out of range"));
21164 if (fixP->fx_done || !seg->use_rela_p)
21167 addressT S, J1, J2, lo, hi;
21169 S = (value & 0x00100000) >> 20;
21170 J2 = (value & 0x00080000) >> 19;
21171 J1 = (value & 0x00040000) >> 18;
21172 hi = (value & 0x0003f000) >> 12;
21173 lo = (value & 0x00000ffe) >> 1;
21175 newval = md_chars_to_number (buf, THUMB_SIZE);
21176 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21177 newval |= (S << 10) | hi;
21178 newval2 |= (J1 << 13) | (J2 << 11) | lo;
21179 md_number_to_chars (buf, newval, THUMB_SIZE);
21180 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21184 case BFD_RELOC_THUMB_PCREL_BLX:
21185 /* If there is a blx from a thumb state function to
21186 another thumb function flip this to a bl and warn
21190 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21191 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21192 && THUMB_IS_FUNC (fixP->fx_addsy))
21194 const char *name = S_GET_NAME (fixP->fx_addsy);
21195 as_warn_where (fixP->fx_file, fixP->fx_line,
21196 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
21198 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21199 newval = newval | 0x1000;
21200 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21201 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21206 goto thumb_bl_common;
21208 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21209 /* A bl from Thumb state ISA to an internal ARM state function
21210 is converted to a blx. */
21212 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21213 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21214 && ARM_IS_FUNC (fixP->fx_addsy)
21215 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21217 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21218 newval = newval & ~0x1000;
21219 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21220 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
21227 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
21228 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21229 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21232 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21233 /* For a BLX instruction, make sure that the relocation is rounded up
21234 to a word boundary. This follows the semantics of the instruction
21235 which specifies that bit 1 of the target address will come from bit
21236 1 of the base address. */
21237 value = (value + 1) & ~ 1;
21239 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
21241 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
21242 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21243 else if ((value & ~0x1ffffff)
21244 && ((value & ~0x1ffffff) != ~0x1ffffff))
21245 as_bad_where (fixP->fx_file, fixP->fx_line,
21246 _("Thumb2 branch out of range"));
21249 if (fixP->fx_done || !seg->use_rela_p)
21250 encode_thumb2_b_bl_offset (buf, value);
21254 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21255 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
21256 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21258 if (fixP->fx_done || !seg->use_rela_p)
21259 encode_thumb2_b_bl_offset (buf, value);
21264 if (fixP->fx_done || !seg->use_rela_p)
21265 md_number_to_chars (buf, value, 1);
21269 if (fixP->fx_done || !seg->use_rela_p)
21270 md_number_to_chars (buf, value, 2);
21274 case BFD_RELOC_ARM_TLS_CALL:
21275 case BFD_RELOC_ARM_THM_TLS_CALL:
21276 case BFD_RELOC_ARM_TLS_DESCSEQ:
21277 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
21278 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21281 case BFD_RELOC_ARM_TLS_GOTDESC:
21282 case BFD_RELOC_ARM_TLS_GD32:
21283 case BFD_RELOC_ARM_TLS_LE32:
21284 case BFD_RELOC_ARM_TLS_IE32:
21285 case BFD_RELOC_ARM_TLS_LDM32:
21286 case BFD_RELOC_ARM_TLS_LDO32:
21287 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21290 case BFD_RELOC_ARM_GOT32:
21291 case BFD_RELOC_ARM_GOTOFF:
21292 if (fixP->fx_done || !seg->use_rela_p)
21293 md_number_to_chars (buf, 0, 4);
21296 case BFD_RELOC_ARM_GOT_PREL:
21297 if (fixP->fx_done || !seg->use_rela_p)
21298 md_number_to_chars (buf, value, 4);
21301 case BFD_RELOC_ARM_TARGET2:
21302 /* TARGET2 is not partial-inplace, so we need to write the
21303 addend here for REL targets, because it won't be written out
21304 during reloc processing later. */
21305 if (fixP->fx_done || !seg->use_rela_p)
21306 md_number_to_chars (buf, fixP->fx_offset, 4);
21310 case BFD_RELOC_RVA:
21312 case BFD_RELOC_ARM_TARGET1:
21313 case BFD_RELOC_ARM_ROSEGREL32:
21314 case BFD_RELOC_ARM_SBREL32:
21315 case BFD_RELOC_32_PCREL:
21317 case BFD_RELOC_32_SECREL:
21319 if (fixP->fx_done || !seg->use_rela_p)
21321 /* For WinCE we only do this for pcrel fixups. */
21322 if (fixP->fx_done || fixP->fx_pcrel)
21324 md_number_to_chars (buf, value, 4);
21328 case BFD_RELOC_ARM_PREL31:
21329 if (fixP->fx_done || !seg->use_rela_p)
21331 newval = md_chars_to_number (buf, 4) & 0x80000000;
21332 if ((value ^ (value >> 1)) & 0x40000000)
21334 as_bad_where (fixP->fx_file, fixP->fx_line,
21335 _("rel31 relocation overflow"));
21337 newval |= value & 0x7fffffff;
21338 md_number_to_chars (buf, newval, 4);
21343 case BFD_RELOC_ARM_CP_OFF_IMM:
21344 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
21345 if (value < -1023 || value > 1023 || (value & 3))
21346 as_bad_where (fixP->fx_file, fixP->fx_line,
21347 _("co-processor offset out of range"));
21352 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21353 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21354 newval = md_chars_to_number (buf, INSN_SIZE);
21356 newval = get_thumb32_insn (buf);
21358 newval &= 0xffffff00;
21361 newval &= 0xff7fff00;
21362 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
21364 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21365 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21366 md_number_to_chars (buf, newval, INSN_SIZE);
21368 put_thumb32_insn (buf, newval);
21371 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
21372 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
21373 if (value < -255 || value > 255)
21374 as_bad_where (fixP->fx_file, fixP->fx_line,
21375 _("co-processor offset out of range"));
21377 goto cp_off_common;
21379 case BFD_RELOC_ARM_THUMB_OFFSET:
21380 newval = md_chars_to_number (buf, THUMB_SIZE);
21381 /* Exactly what ranges, and where the offset is inserted depends
21382 on the type of instruction, we can establish this from the
21384 switch (newval >> 12)
21386 case 4: /* PC load. */
21387 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
21388 forced to zero for these loads; md_pcrel_from has already
21389 compensated for this. */
21391 as_bad_where (fixP->fx_file, fixP->fx_line,
21392 _("invalid offset, target not word aligned (0x%08lX)"),
21393 (((unsigned long) fixP->fx_frag->fr_address
21394 + (unsigned long) fixP->fx_where) & ~3)
21395 + (unsigned long) value);
21397 if (value & ~0x3fc)
21398 as_bad_where (fixP->fx_file, fixP->fx_line,
21399 _("invalid offset, value too big (0x%08lX)"),
21402 newval |= value >> 2;
21405 case 9: /* SP load/store. */
21406 if (value & ~0x3fc)
21407 as_bad_where (fixP->fx_file, fixP->fx_line,
21408 _("invalid offset, value too big (0x%08lX)"),
21410 newval |= value >> 2;
21413 case 6: /* Word load/store. */
21415 as_bad_where (fixP->fx_file, fixP->fx_line,
21416 _("invalid offset, value too big (0x%08lX)"),
21418 newval |= value << 4; /* 6 - 2. */
21421 case 7: /* Byte load/store. */
21423 as_bad_where (fixP->fx_file, fixP->fx_line,
21424 _("invalid offset, value too big (0x%08lX)"),
21426 newval |= value << 6;
21429 case 8: /* Halfword load/store. */
21431 as_bad_where (fixP->fx_file, fixP->fx_line,
21432 _("invalid offset, value too big (0x%08lX)"),
21434 newval |= value << 5; /* 6 - 1. */
21438 as_bad_where (fixP->fx_file, fixP->fx_line,
21439 "Unable to process relocation for thumb opcode: %lx",
21440 (unsigned long) newval);
21443 md_number_to_chars (buf, newval, THUMB_SIZE);
21446 case BFD_RELOC_ARM_THUMB_ADD:
21447 /* This is a complicated relocation, since we use it for all of
21448 the following immediate relocations:
21452 9bit ADD/SUB SP word-aligned
21453 10bit ADD PC/SP word-aligned
21455 The type of instruction being processed is encoded in the
21462 newval = md_chars_to_number (buf, THUMB_SIZE);
21464 int rd = (newval >> 4) & 0xf;
21465 int rs = newval & 0xf;
21466 int subtract = !!(newval & 0x8000);
21468 /* Check for HI regs, only very restricted cases allowed:
21469 Adjusting SP, and using PC or SP to get an address. */
21470 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
21471 || (rs > 7 && rs != REG_SP && rs != REG_PC))
21472 as_bad_where (fixP->fx_file, fixP->fx_line,
21473 _("invalid Hi register with immediate"));
21475 /* If value is negative, choose the opposite instruction. */
21479 subtract = !subtract;
21481 as_bad_where (fixP->fx_file, fixP->fx_line,
21482 _("immediate value out of range"));
21487 if (value & ~0x1fc)
21488 as_bad_where (fixP->fx_file, fixP->fx_line,
21489 _("invalid immediate for stack address calculation"));
21490 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
21491 newval |= value >> 2;
21493 else if (rs == REG_PC || rs == REG_SP)
21495 if (subtract || value & ~0x3fc)
21496 as_bad_where (fixP->fx_file, fixP->fx_line,
21497 _("invalid immediate for address calculation (value = 0x%08lX)"),
21498 (unsigned long) value);
21499 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
21501 newval |= value >> 2;
21506 as_bad_where (fixP->fx_file, fixP->fx_line,
21507 _("immediate value out of range"));
21508 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
21509 newval |= (rd << 8) | value;
21514 as_bad_where (fixP->fx_file, fixP->fx_line,
21515 _("immediate value out of range"));
21516 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
21517 newval |= rd | (rs << 3) | (value << 6);
21520 md_number_to_chars (buf, newval, THUMB_SIZE);
21523 case BFD_RELOC_ARM_THUMB_IMM:
21524 newval = md_chars_to_number (buf, THUMB_SIZE);
21525 if (value < 0 || value > 255)
21526 as_bad_where (fixP->fx_file, fixP->fx_line,
21527 _("invalid immediate: %ld is out of range"),
21530 md_number_to_chars (buf, newval, THUMB_SIZE);
21533 case BFD_RELOC_ARM_THUMB_SHIFT:
21534 /* 5bit shift value (0..32). LSL cannot take 32. */
21535 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
21536 temp = newval & 0xf800;
21537 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
21538 as_bad_where (fixP->fx_file, fixP->fx_line,
21539 _("invalid shift value: %ld"), (long) value);
21540 /* Shifts of zero must be encoded as LSL. */
21542 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
21543 /* Shifts of 32 are encoded as zero. */
21544 else if (value == 32)
21546 newval |= value << 6;
21547 md_number_to_chars (buf, newval, THUMB_SIZE);
21550 case BFD_RELOC_VTABLE_INHERIT:
21551 case BFD_RELOC_VTABLE_ENTRY:
21555 case BFD_RELOC_ARM_MOVW:
21556 case BFD_RELOC_ARM_MOVT:
21557 case BFD_RELOC_ARM_THUMB_MOVW:
21558 case BFD_RELOC_ARM_THUMB_MOVT:
21559 if (fixP->fx_done || !seg->use_rela_p)
21561 /* REL format relocations are limited to a 16-bit addend. */
21562 if (!fixP->fx_done)
21564 if (value < -0x8000 || value > 0x7fff)
21565 as_bad_where (fixP->fx_file, fixP->fx_line,
21566 _("offset out of range"));
21568 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21569 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21574 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21575 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21577 newval = get_thumb32_insn (buf);
21578 newval &= 0xfbf08f00;
21579 newval |= (value & 0xf000) << 4;
21580 newval |= (value & 0x0800) << 15;
21581 newval |= (value & 0x0700) << 4;
21582 newval |= (value & 0x00ff);
21583 put_thumb32_insn (buf, newval);
21587 newval = md_chars_to_number (buf, 4);
21588 newval &= 0xfff0f000;
21589 newval |= value & 0x0fff;
21590 newval |= (value & 0xf000) << 4;
21591 md_number_to_chars (buf, newval, 4);
21596 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21597 case BFD_RELOC_ARM_ALU_PC_G0:
21598 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21599 case BFD_RELOC_ARM_ALU_PC_G1:
21600 case BFD_RELOC_ARM_ALU_PC_G2:
21601 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21602 case BFD_RELOC_ARM_ALU_SB_G0:
21603 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21604 case BFD_RELOC_ARM_ALU_SB_G1:
21605 case BFD_RELOC_ARM_ALU_SB_G2:
21606 gas_assert (!fixP->fx_done);
21607 if (!seg->use_rela_p)
21610 bfd_vma encoded_addend;
21611 bfd_vma addend_abs = abs (value);
21613 /* Check that the absolute value of the addend can be
21614 expressed as an 8-bit constant plus a rotation. */
21615 encoded_addend = encode_arm_immediate (addend_abs);
21616 if (encoded_addend == (unsigned int) FAIL)
21617 as_bad_where (fixP->fx_file, fixP->fx_line,
21618 _("the offset 0x%08lX is not representable"),
21619 (unsigned long) addend_abs);
21621 /* Extract the instruction. */
21622 insn = md_chars_to_number (buf, INSN_SIZE);
21624 /* If the addend is positive, use an ADD instruction.
21625 Otherwise use a SUB. Take care not to destroy the S bit. */
21626 insn &= 0xff1fffff;
21632 /* Place the encoded addend into the first 12 bits of the
21634 insn &= 0xfffff000;
21635 insn |= encoded_addend;
21637 /* Update the instruction. */
21638 md_number_to_chars (buf, insn, INSN_SIZE);
21642 case BFD_RELOC_ARM_LDR_PC_G0:
21643 case BFD_RELOC_ARM_LDR_PC_G1:
21644 case BFD_RELOC_ARM_LDR_PC_G2:
21645 case BFD_RELOC_ARM_LDR_SB_G0:
21646 case BFD_RELOC_ARM_LDR_SB_G1:
21647 case BFD_RELOC_ARM_LDR_SB_G2:
21648 gas_assert (!fixP->fx_done);
21649 if (!seg->use_rela_p)
21652 bfd_vma addend_abs = abs (value);
21654 /* Check that the absolute value of the addend can be
21655 encoded in 12 bits. */
21656 if (addend_abs >= 0x1000)
21657 as_bad_where (fixP->fx_file, fixP->fx_line,
21658 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
21659 (unsigned long) addend_abs);
21661 /* Extract the instruction. */
21662 insn = md_chars_to_number (buf, INSN_SIZE);
21664 /* If the addend is negative, clear bit 23 of the instruction.
21665 Otherwise set it. */
21667 insn &= ~(1 << 23);
21671 /* Place the absolute value of the addend into the first 12 bits
21672 of the instruction. */
21673 insn &= 0xfffff000;
21674 insn |= addend_abs;
21676 /* Update the instruction. */
21677 md_number_to_chars (buf, insn, INSN_SIZE);
21681 case BFD_RELOC_ARM_LDRS_PC_G0:
21682 case BFD_RELOC_ARM_LDRS_PC_G1:
21683 case BFD_RELOC_ARM_LDRS_PC_G2:
21684 case BFD_RELOC_ARM_LDRS_SB_G0:
21685 case BFD_RELOC_ARM_LDRS_SB_G1:
21686 case BFD_RELOC_ARM_LDRS_SB_G2:
21687 gas_assert (!fixP->fx_done);
21688 if (!seg->use_rela_p)
21691 bfd_vma addend_abs = abs (value);
21693 /* Check that the absolute value of the addend can be
21694 encoded in 8 bits. */
21695 if (addend_abs >= 0x100)
21696 as_bad_where (fixP->fx_file, fixP->fx_line,
21697 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
21698 (unsigned long) addend_abs);
21700 /* Extract the instruction. */
21701 insn = md_chars_to_number (buf, INSN_SIZE);
21703 /* If the addend is negative, clear bit 23 of the instruction.
21704 Otherwise set it. */
21706 insn &= ~(1 << 23);
21710 /* Place the first four bits of the absolute value of the addend
21711 into the first 4 bits of the instruction, and the remaining
21712 four into bits 8 .. 11. */
21713 insn &= 0xfffff0f0;
21714 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
21716 /* Update the instruction. */
21717 md_number_to_chars (buf, insn, INSN_SIZE);
21721 case BFD_RELOC_ARM_LDC_PC_G0:
21722 case BFD_RELOC_ARM_LDC_PC_G1:
21723 case BFD_RELOC_ARM_LDC_PC_G2:
21724 case BFD_RELOC_ARM_LDC_SB_G0:
21725 case BFD_RELOC_ARM_LDC_SB_G1:
21726 case BFD_RELOC_ARM_LDC_SB_G2:
21727 gas_assert (!fixP->fx_done);
21728 if (!seg->use_rela_p)
21731 bfd_vma addend_abs = abs (value);
21733 /* Check that the absolute value of the addend is a multiple of
21734 four and, when divided by four, fits in 8 bits. */
21735 if (addend_abs & 0x3)
21736 as_bad_where (fixP->fx_file, fixP->fx_line,
21737 _("bad offset 0x%08lX (must be word-aligned)"),
21738 (unsigned long) addend_abs);
21740 if ((addend_abs >> 2) > 0xff)
21741 as_bad_where (fixP->fx_file, fixP->fx_line,
21742 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
21743 (unsigned long) addend_abs);
21745 /* Extract the instruction. */
21746 insn = md_chars_to_number (buf, INSN_SIZE);
21748 /* If the addend is negative, clear bit 23 of the instruction.
21749 Otherwise set it. */
21751 insn &= ~(1 << 23);
21755 /* Place the addend (divided by four) into the first eight
21756 bits of the instruction. */
21757 insn &= 0xfffffff0;
21758 insn |= addend_abs >> 2;
21760 /* Update the instruction. */
21761 md_number_to_chars (buf, insn, INSN_SIZE);
21765 case BFD_RELOC_ARM_V4BX:
21766 /* This will need to go in the object file. */
21770 case BFD_RELOC_UNUSED:
21772 as_bad_where (fixP->fx_file, fixP->fx_line,
21773 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21777 /* Translate internal representation of relocation info to BFD target
21781 tc_gen_reloc (asection *section, fixS *fixp)
21784 bfd_reloc_code_real_type code;
21786 reloc = (arelent *) xmalloc (sizeof (arelent));
21788 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
21789 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21790 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
21792 if (fixp->fx_pcrel)
21794 if (section->use_rela_p)
21795 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21797 fixp->fx_offset = reloc->address;
21799 reloc->addend = fixp->fx_offset;
21801 switch (fixp->fx_r_type)
21804 if (fixp->fx_pcrel)
21806 code = BFD_RELOC_8_PCREL;
21811 if (fixp->fx_pcrel)
21813 code = BFD_RELOC_16_PCREL;
21818 if (fixp->fx_pcrel)
21820 code = BFD_RELOC_32_PCREL;
21824 case BFD_RELOC_ARM_MOVW:
21825 if (fixp->fx_pcrel)
21827 code = BFD_RELOC_ARM_MOVW_PCREL;
21831 case BFD_RELOC_ARM_MOVT:
21832 if (fixp->fx_pcrel)
21834 code = BFD_RELOC_ARM_MOVT_PCREL;
21838 case BFD_RELOC_ARM_THUMB_MOVW:
21839 if (fixp->fx_pcrel)
21841 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21845 case BFD_RELOC_ARM_THUMB_MOVT:
21846 if (fixp->fx_pcrel)
21848 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21852 case BFD_RELOC_NONE:
21853 case BFD_RELOC_ARM_PCREL_BRANCH:
21854 case BFD_RELOC_ARM_PCREL_BLX:
21855 case BFD_RELOC_RVA:
21856 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21857 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21858 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21859 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21860 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21861 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21862 case BFD_RELOC_VTABLE_ENTRY:
21863 case BFD_RELOC_VTABLE_INHERIT:
21865 case BFD_RELOC_32_SECREL:
21867 code = fixp->fx_r_type;
21870 case BFD_RELOC_THUMB_PCREL_BLX:
21872 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21873 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21876 code = BFD_RELOC_THUMB_PCREL_BLX;
21879 case BFD_RELOC_ARM_LITERAL:
21880 case BFD_RELOC_ARM_HWLITERAL:
21881 /* If this is called then the a literal has
21882 been referenced across a section boundary. */
21883 as_bad_where (fixp->fx_file, fixp->fx_line,
21884 _("literal referenced across section boundary"));
21888 case BFD_RELOC_ARM_TLS_CALL:
21889 case BFD_RELOC_ARM_THM_TLS_CALL:
21890 case BFD_RELOC_ARM_TLS_DESCSEQ:
21891 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
21892 case BFD_RELOC_ARM_GOT32:
21893 case BFD_RELOC_ARM_GOTOFF:
21894 case BFD_RELOC_ARM_GOT_PREL:
21895 case BFD_RELOC_ARM_PLT32:
21896 case BFD_RELOC_ARM_TARGET1:
21897 case BFD_RELOC_ARM_ROSEGREL32:
21898 case BFD_RELOC_ARM_SBREL32:
21899 case BFD_RELOC_ARM_PREL31:
21900 case BFD_RELOC_ARM_TARGET2:
21901 case BFD_RELOC_ARM_TLS_LE32:
21902 case BFD_RELOC_ARM_TLS_LDO32:
21903 case BFD_RELOC_ARM_PCREL_CALL:
21904 case BFD_RELOC_ARM_PCREL_JUMP:
21905 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21906 case BFD_RELOC_ARM_ALU_PC_G0:
21907 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21908 case BFD_RELOC_ARM_ALU_PC_G1:
21909 case BFD_RELOC_ARM_ALU_PC_G2:
21910 case BFD_RELOC_ARM_LDR_PC_G0:
21911 case BFD_RELOC_ARM_LDR_PC_G1:
21912 case BFD_RELOC_ARM_LDR_PC_G2:
21913 case BFD_RELOC_ARM_LDRS_PC_G0:
21914 case BFD_RELOC_ARM_LDRS_PC_G1:
21915 case BFD_RELOC_ARM_LDRS_PC_G2:
21916 case BFD_RELOC_ARM_LDC_PC_G0:
21917 case BFD_RELOC_ARM_LDC_PC_G1:
21918 case BFD_RELOC_ARM_LDC_PC_G2:
21919 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21920 case BFD_RELOC_ARM_ALU_SB_G0:
21921 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21922 case BFD_RELOC_ARM_ALU_SB_G1:
21923 case BFD_RELOC_ARM_ALU_SB_G2:
21924 case BFD_RELOC_ARM_LDR_SB_G0:
21925 case BFD_RELOC_ARM_LDR_SB_G1:
21926 case BFD_RELOC_ARM_LDR_SB_G2:
21927 case BFD_RELOC_ARM_LDRS_SB_G0:
21928 case BFD_RELOC_ARM_LDRS_SB_G1:
21929 case BFD_RELOC_ARM_LDRS_SB_G2:
21930 case BFD_RELOC_ARM_LDC_SB_G0:
21931 case BFD_RELOC_ARM_LDC_SB_G1:
21932 case BFD_RELOC_ARM_LDC_SB_G2:
21933 case BFD_RELOC_ARM_V4BX:
21934 code = fixp->fx_r_type;
21937 case BFD_RELOC_ARM_TLS_GOTDESC:
21938 case BFD_RELOC_ARM_TLS_GD32:
21939 case BFD_RELOC_ARM_TLS_IE32:
21940 case BFD_RELOC_ARM_TLS_LDM32:
21941 /* BFD will include the symbol's address in the addend.
21942 But we don't want that, so subtract it out again here. */
21943 if (!S_IS_COMMON (fixp->fx_addsy))
21944 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21945 code = fixp->fx_r_type;
21949 case BFD_RELOC_ARM_IMMEDIATE:
21950 as_bad_where (fixp->fx_file, fixp->fx_line,
21951 _("internal relocation (type: IMMEDIATE) not fixed up"));
21954 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21955 as_bad_where (fixp->fx_file, fixp->fx_line,
21956 _("ADRL used for a symbol not defined in the same file"));
21959 case BFD_RELOC_ARM_OFFSET_IMM:
21960 if (section->use_rela_p)
21962 code = fixp->fx_r_type;
21966 if (fixp->fx_addsy != NULL
21967 && !S_IS_DEFINED (fixp->fx_addsy)
21968 && S_IS_LOCAL (fixp->fx_addsy))
21970 as_bad_where (fixp->fx_file, fixp->fx_line,
21971 _("undefined local label `%s'"),
21972 S_GET_NAME (fixp->fx_addsy));
21976 as_bad_where (fixp->fx_file, fixp->fx_line,
21977 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21984 switch (fixp->fx_r_type)
21986 case BFD_RELOC_NONE: type = "NONE"; break;
21987 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21988 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
21989 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
21990 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21991 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21992 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
21993 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
21994 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
21995 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21996 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21997 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21998 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21999 default: type = _("<unknown>"); break;
22001 as_bad_where (fixp->fx_file, fixp->fx_line,
22002 _("cannot represent %s relocation in this object file format"),
22009 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
22011 && fixp->fx_addsy == GOT_symbol)
22013 code = BFD_RELOC_ARM_GOTPC;
22014 reloc->addend = fixp->fx_offset = reloc->address;
22018 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
22020 if (reloc->howto == NULL)
22022 as_bad_where (fixp->fx_file, fixp->fx_line,
22023 _("cannot represent %s relocation in this object file format"),
22024 bfd_get_reloc_code_name (code));
22028 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
22029 vtable entry to be used in the relocation's section offset. */
22030 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
22031 reloc->address = fixp->fx_offset;
22036 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
22039 cons_fix_new_arm (fragS * frag,
22044 bfd_reloc_code_real_type type;
22048 FIXME: @@ Should look at CPU word size. */
22052 type = BFD_RELOC_8;
22055 type = BFD_RELOC_16;
22059 type = BFD_RELOC_32;
22062 type = BFD_RELOC_64;
22067 if (exp->X_op == O_secrel)
22069 exp->X_op = O_symbol;
22070 type = BFD_RELOC_32_SECREL;
22074 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
22077 #if defined (OBJ_COFF)
22079 arm_validate_fix (fixS * fixP)
22081 /* If the destination of the branch is a defined symbol which does not have
22082 the THUMB_FUNC attribute, then we must be calling a function which has
22083 the (interfacearm) attribute. We look for the Thumb entry point to that
22084 function and change the branch to refer to that function instead. */
22085 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
22086 && fixP->fx_addsy != NULL
22087 && S_IS_DEFINED (fixP->fx_addsy)
22088 && ! THUMB_IS_FUNC (fixP->fx_addsy))
22090 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
22097 arm_force_relocation (struct fix * fixp)
22099 #if defined (OBJ_COFF) && defined (TE_PE)
22100 if (fixp->fx_r_type == BFD_RELOC_RVA)
22104 /* In case we have a call or a branch to a function in ARM ISA mode from
22105 a thumb function or vice-versa force the relocation. These relocations
22106 are cleared off for some cores that might have blx and simple transformations
22110 switch (fixp->fx_r_type)
22112 case BFD_RELOC_ARM_PCREL_JUMP:
22113 case BFD_RELOC_ARM_PCREL_CALL:
22114 case BFD_RELOC_THUMB_PCREL_BLX:
22115 if (THUMB_IS_FUNC (fixp->fx_addsy))
22119 case BFD_RELOC_ARM_PCREL_BLX:
22120 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22121 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22122 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22123 if (ARM_IS_FUNC (fixp->fx_addsy))
22132 /* Resolve these relocations even if the symbol is extern or weak.
22133 Technically this is probably wrong due to symbol preemption.
22134 In practice these relocations do not have enough range to be useful
22135 at dynamic link time, and some code (e.g. in the Linux kernel)
22136 expects these references to be resolved. */
22137 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
22138 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
22139 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
22140 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
22141 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22142 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
22143 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
22144 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
22145 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22146 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
22147 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
22148 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
22149 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
22150 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
22153 /* Always leave these relocations for the linker. */
22154 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22155 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22156 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22159 /* Always generate relocations against function symbols. */
22160 if (fixp->fx_r_type == BFD_RELOC_32
22162 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
22165 return generic_force_reloc (fixp);
22168 #if defined (OBJ_ELF) || defined (OBJ_COFF)
22169 /* Relocations against function names must be left unadjusted,
22170 so that the linker can use this information to generate interworking
22171 stubs. The MIPS version of this function
22172 also prevents relocations that are mips-16 specific, but I do not
22173 know why it does this.
22176 There is one other problem that ought to be addressed here, but
22177 which currently is not: Taking the address of a label (rather
22178 than a function) and then later jumping to that address. Such
22179 addresses also ought to have their bottom bit set (assuming that
22180 they reside in Thumb code), but at the moment they will not. */
22183 arm_fix_adjustable (fixS * fixP)
22185 if (fixP->fx_addsy == NULL)
22188 /* Preserve relocations against symbols with function type. */
22189 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
22192 if (THUMB_IS_FUNC (fixP->fx_addsy)
22193 && fixP->fx_subsy == NULL)
22196 /* We need the symbol name for the VTABLE entries. */
22197 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
22198 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
22201 /* Don't allow symbols to be discarded on GOT related relocs. */
22202 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
22203 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
22204 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
22205 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
22206 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
22207 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
22208 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
22209 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
22210 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
22211 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
22212 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
22213 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
22214 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
22215 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
22218 /* Similarly for group relocations. */
22219 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22220 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22221 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22224 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
22225 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
22226 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22227 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
22228 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
22229 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22230 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
22231 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
22232 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
22237 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
22242 elf32_arm_target_format (void)
22245 return (target_big_endian
22246 ? "elf32-bigarm-symbian"
22247 : "elf32-littlearm-symbian");
22248 #elif defined (TE_VXWORKS)
22249 return (target_big_endian
22250 ? "elf32-bigarm-vxworks"
22251 : "elf32-littlearm-vxworks");
22253 if (target_big_endian)
22254 return "elf32-bigarm";
22256 return "elf32-littlearm";
22261 armelf_frob_symbol (symbolS * symp,
22264 elf_frob_symbol (symp, puntp);
22268 /* MD interface: Finalization. */
22273 literal_pool * pool;
22275 /* Ensure that all the IT blocks are properly closed. */
22276 check_it_blocks_finished ();
22278 for (pool = list_of_pools; pool; pool = pool->next)
22280 /* Put it at the end of the relevant section. */
22281 subseg_set (pool->section, pool->sub_section);
22283 arm_elf_change_section ();
22290 /* Remove any excess mapping symbols generated for alignment frags in
22291 SEC. We may have created a mapping symbol before a zero byte
22292 alignment; remove it if there's a mapping symbol after the
22295 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
22296 void *dummy ATTRIBUTE_UNUSED)
22298 segment_info_type *seginfo = seg_info (sec);
22301 if (seginfo == NULL || seginfo->frchainP == NULL)
22304 for (fragp = seginfo->frchainP->frch_root;
22306 fragp = fragp->fr_next)
22308 symbolS *sym = fragp->tc_frag_data.last_map;
22309 fragS *next = fragp->fr_next;
22311 /* Variable-sized frags have been converted to fixed size by
22312 this point. But if this was variable-sized to start with,
22313 there will be a fixed-size frag after it. So don't handle
22315 if (sym == NULL || next == NULL)
22318 if (S_GET_VALUE (sym) < next->fr_address)
22319 /* Not at the end of this frag. */
22321 know (S_GET_VALUE (sym) == next->fr_address);
22325 if (next->tc_frag_data.first_map != NULL)
22327 /* Next frag starts with a mapping symbol. Discard this
22329 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22333 if (next->fr_next == NULL)
22335 /* This mapping symbol is at the end of the section. Discard
22337 know (next->fr_fix == 0 && next->fr_var == 0);
22338 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22342 /* As long as we have empty frags without any mapping symbols,
22344 /* If the next frag is non-empty and does not start with a
22345 mapping symbol, then this mapping symbol is required. */
22346 if (next->fr_address != next->fr_next->fr_address)
22349 next = next->fr_next;
22351 while (next != NULL);
22356 /* Adjust the symbol table. This marks Thumb symbols as distinct from
22360 arm_adjust_symtab (void)
22365 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22367 if (ARM_IS_THUMB (sym))
22369 if (THUMB_IS_FUNC (sym))
22371 /* Mark the symbol as a Thumb function. */
22372 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
22373 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
22374 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
22376 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
22377 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
22379 as_bad (_("%s: unexpected function type: %d"),
22380 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
22382 else switch (S_GET_STORAGE_CLASS (sym))
22385 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
22388 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
22391 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
22399 if (ARM_IS_INTERWORK (sym))
22400 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
22407 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22409 if (ARM_IS_THUMB (sym))
22411 elf_symbol_type * elf_sym;
22413 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
22414 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
22416 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
22417 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
22419 /* If it's a .thumb_func, declare it as so,
22420 otherwise tag label as .code 16. */
22421 if (THUMB_IS_FUNC (sym))
22422 elf_sym->internal_elf_sym.st_target_internal
22423 = ST_BRANCH_TO_THUMB;
22424 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22425 elf_sym->internal_elf_sym.st_info =
22426 ELF_ST_INFO (bind, STT_ARM_16BIT);
22431 /* Remove any overlapping mapping symbols generated by alignment frags. */
22432 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
22433 /* Now do generic ELF adjustments. */
22434 elf_adjust_symtab ();
22438 /* MD interface: Initialization. */
22441 set_constant_flonums (void)
22445 for (i = 0; i < NUM_FLOAT_VALS; i++)
22446 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
22450 /* Auto-select Thumb mode if it's the only available instruction set for the
22451 given architecture. */
22454 autoselect_thumb_from_cpu_variant (void)
22456 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
22457 opcode_select (16);
22466 if ( (arm_ops_hsh = hash_new ()) == NULL
22467 || (arm_cond_hsh = hash_new ()) == NULL
22468 || (arm_shift_hsh = hash_new ()) == NULL
22469 || (arm_psr_hsh = hash_new ()) == NULL
22470 || (arm_v7m_psr_hsh = hash_new ()) == NULL
22471 || (arm_reg_hsh = hash_new ()) == NULL
22472 || (arm_reloc_hsh = hash_new ()) == NULL
22473 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
22474 as_fatal (_("virtual memory exhausted"));
22476 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
22477 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
22478 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
22479 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
22480 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
22481 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
22482 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
22483 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
22484 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
22485 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
22486 (void *) (v7m_psrs + i));
22487 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
22488 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
22490 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
22492 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
22493 (void *) (barrier_opt_names + i));
22495 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
22497 struct reloc_entry * entry = reloc_names + i;
22499 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
22500 /* This makes encode_branch() use the EABI versions of this relocation. */
22501 entry->reloc = BFD_RELOC_UNUSED;
22503 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
22507 set_constant_flonums ();
22509 /* Set the cpu variant based on the command-line options. We prefer
22510 -mcpu= over -march= if both are set (as for GCC); and we prefer
22511 -mfpu= over any other way of setting the floating point unit.
22512 Use of legacy options with new options are faulted. */
22515 if (mcpu_cpu_opt || march_cpu_opt)
22516 as_bad (_("use of old and new-style options to set CPU type"));
22518 mcpu_cpu_opt = legacy_cpu;
22520 else if (!mcpu_cpu_opt)
22521 mcpu_cpu_opt = march_cpu_opt;
22526 as_bad (_("use of old and new-style options to set FPU type"));
22528 mfpu_opt = legacy_fpu;
22530 else if (!mfpu_opt)
22532 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
22533 || defined (TE_NetBSD) || defined (TE_VXWORKS))
22534 /* Some environments specify a default FPU. If they don't, infer it
22535 from the processor. */
22537 mfpu_opt = mcpu_fpu_opt;
22539 mfpu_opt = march_fpu_opt;
22541 mfpu_opt = &fpu_default;
22547 if (mcpu_cpu_opt != NULL)
22548 mfpu_opt = &fpu_default;
22549 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
22550 mfpu_opt = &fpu_arch_vfp_v2;
22552 mfpu_opt = &fpu_arch_fpa;
22558 mcpu_cpu_opt = &cpu_default;
22559 selected_cpu = cpu_default;
22563 selected_cpu = *mcpu_cpu_opt;
22565 mcpu_cpu_opt = &arm_arch_any;
22568 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22570 autoselect_thumb_from_cpu_variant ();
22572 arm_arch_used = thumb_arch_used = arm_arch_none;
22574 #if defined OBJ_COFF || defined OBJ_ELF
22576 unsigned int flags = 0;
22578 #if defined OBJ_ELF
22579 flags = meabi_flags;
22581 switch (meabi_flags)
22583 case EF_ARM_EABI_UNKNOWN:
22585 /* Set the flags in the private structure. */
22586 if (uses_apcs_26) flags |= F_APCS26;
22587 if (support_interwork) flags |= F_INTERWORK;
22588 if (uses_apcs_float) flags |= F_APCS_FLOAT;
22589 if (pic_code) flags |= F_PIC;
22590 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
22591 flags |= F_SOFT_FLOAT;
22593 switch (mfloat_abi_opt)
22595 case ARM_FLOAT_ABI_SOFT:
22596 case ARM_FLOAT_ABI_SOFTFP:
22597 flags |= F_SOFT_FLOAT;
22600 case ARM_FLOAT_ABI_HARD:
22601 if (flags & F_SOFT_FLOAT)
22602 as_bad (_("hard-float conflicts with specified fpu"));
22606 /* Using pure-endian doubles (even if soft-float). */
22607 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
22608 flags |= F_VFP_FLOAT;
22610 #if defined OBJ_ELF
22611 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
22612 flags |= EF_ARM_MAVERICK_FLOAT;
22615 case EF_ARM_EABI_VER4:
22616 case EF_ARM_EABI_VER5:
22617 /* No additional flags to set. */
22624 bfd_set_private_flags (stdoutput, flags);
22626 /* We have run out flags in the COFF header to encode the
22627 status of ATPCS support, so instead we create a dummy,
22628 empty, debug section called .arm.atpcs. */
22633 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22637 bfd_set_section_flags
22638 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22639 bfd_set_section_size (stdoutput, sec, 0);
22640 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22646 /* Record the CPU type as well. */
22647 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22648 mach = bfd_mach_arm_iWMMXt2;
22649 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
22650 mach = bfd_mach_arm_iWMMXt;
22651 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
22652 mach = bfd_mach_arm_XScale;
22653 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
22654 mach = bfd_mach_arm_ep9312;
22655 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
22656 mach = bfd_mach_arm_5TE;
22657 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
22659 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
22660 mach = bfd_mach_arm_5T;
22662 mach = bfd_mach_arm_5;
22664 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
22666 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
22667 mach = bfd_mach_arm_4T;
22669 mach = bfd_mach_arm_4;
22671 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
22672 mach = bfd_mach_arm_3M;
22673 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22674 mach = bfd_mach_arm_3;
22675 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22676 mach = bfd_mach_arm_2a;
22677 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22678 mach = bfd_mach_arm_2;
22680 mach = bfd_mach_arm_unknown;
22682 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22685 /* Command line processing. */
22688 Invocation line includes a switch not recognized by the base assembler.
22689 See if it's a processor-specific option.
22691 This routine is somewhat complicated by the need for backwards
22692 compatibility (since older releases of gcc can't be changed).
22693 The new options try to make the interface as compatible as
22696 New options (supported) are:
22698 -mcpu=<cpu name> Assemble for selected processor
22699 -march=<architecture name> Assemble for selected architecture
22700 -mfpu=<fpu architecture> Assemble for selected FPU.
22701 -EB/-mbig-endian Big-endian
22702 -EL/-mlittle-endian Little-endian
22703 -k Generate PIC code
22704 -mthumb Start in Thumb mode
22705 -mthumb-interwork Code supports ARM/Thumb interworking
22707 -m[no-]warn-deprecated Warn about deprecated features
22709 For now we will also provide support for:
22711 -mapcs-32 32-bit Program counter
22712 -mapcs-26 26-bit Program counter
22713 -macps-float Floats passed in FP registers
22714 -mapcs-reentrant Reentrant code
22716 (sometime these will probably be replaced with -mapcs=<list of options>
22717 and -matpcs=<list of options>)
22719 The remaining options are only supported for back-wards compatibility.
22720 Cpu variants, the arm part is optional:
22721 -m[arm]1 Currently not supported.
22722 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22723 -m[arm]3 Arm 3 processor
22724 -m[arm]6[xx], Arm 6 processors
22725 -m[arm]7[xx][t][[d]m] Arm 7 processors
22726 -m[arm]8[10] Arm 8 processors
22727 -m[arm]9[20][tdmi] Arm 9 processors
22728 -mstrongarm[110[0]] StrongARM processors
22729 -mxscale XScale processors
22730 -m[arm]v[2345[t[e]]] Arm architectures
22731 -mall All (except the ARM1)
22733 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22734 -mfpe-old (No float load/store multiples)
22735 -mvfpxd VFP Single precision
22737 -mno-fpu Disable all floating point instructions
22739 The following CPU names are recognized:
22740 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22741 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22742 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22743 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22744 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22745 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22746 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
22750 const char * md_shortopts = "m:k";
22752 #ifdef ARM_BI_ENDIAN
22753 #define OPTION_EB (OPTION_MD_BASE + 0)
22754 #define OPTION_EL (OPTION_MD_BASE + 1)
22756 #if TARGET_BYTES_BIG_ENDIAN
22757 #define OPTION_EB (OPTION_MD_BASE + 0)
22759 #define OPTION_EL (OPTION_MD_BASE + 1)
22762 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
22764 struct option md_longopts[] =
22767 {"EB", no_argument, NULL, OPTION_EB},
22770 {"EL", no_argument, NULL, OPTION_EL},
22772 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
22773 {NULL, no_argument, NULL, 0}
22776 size_t md_longopts_size = sizeof (md_longopts);
22778 struct arm_option_table
22780 char *option; /* Option name to match. */
22781 char *help; /* Help information. */
22782 int *var; /* Variable to change. */
22783 int value; /* What to change it to. */
22784 char *deprecated; /* If non-null, print this message. */
22787 struct arm_option_table arm_opts[] =
22789 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22790 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22791 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22792 &support_interwork, 1, NULL},
22793 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22794 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22795 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22797 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22798 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22799 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22800 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22803 /* These are recognized by the assembler, but have no affect on code. */
22804 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22805 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
22807 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22808 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22809 &warn_on_deprecated, 0, NULL},
22810 {NULL, NULL, NULL, 0, NULL}
22813 struct arm_legacy_option_table
22815 char *option; /* Option name to match. */
22816 const arm_feature_set **var; /* Variable to change. */
22817 const arm_feature_set value; /* What to change it to. */
22818 char *deprecated; /* If non-null, print this message. */
22821 const struct arm_legacy_option_table arm_legacy_opts[] =
22823 /* DON'T add any new processors to this list -- we want the whole list
22824 to go away... Add them to the processors table instead. */
22825 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22826 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22827 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22828 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22829 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22830 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22831 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22832 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22833 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22834 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22835 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22836 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22837 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22838 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22839 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22840 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22841 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22842 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22843 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22844 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22845 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22846 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22847 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22848 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22849 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22850 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22851 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22852 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22853 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22854 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22855 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22856 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22857 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22858 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22859 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22860 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22861 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22862 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22863 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22864 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22865 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22866 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22867 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22868 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22869 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22870 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22871 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22872 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22873 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22874 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22875 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22876 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22877 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22878 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22879 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22880 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22881 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22882 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22883 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22884 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22885 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22886 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22887 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22888 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22889 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22890 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22891 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22892 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22893 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22894 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
22895 N_("use -mcpu=strongarm110")},
22896 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
22897 N_("use -mcpu=strongarm1100")},
22898 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
22899 N_("use -mcpu=strongarm1110")},
22900 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22901 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22902 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
22904 /* Architecture variants -- don't add any more to this list either. */
22905 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22906 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22907 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22908 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22909 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22910 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22911 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22912 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22913 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22914 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22915 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22916 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22917 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22918 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22919 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22920 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22921 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22922 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22924 /* Floating point variants -- don't add any more to this list either. */
22925 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22926 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22927 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22928 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
22929 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
22931 {NULL, NULL, ARM_ARCH_NONE, NULL}
22934 struct arm_cpu_option_table
22938 const arm_feature_set value;
22939 /* For some CPUs we assume an FPU unless the user explicitly sets
22941 const arm_feature_set default_fpu;
22942 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22944 const char *canonical_name;
22947 /* This list should, at a minimum, contain all the cpu names
22948 recognized by GCC. */
22949 #define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
22950 static const struct arm_cpu_option_table arm_cpus[] =
22952 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
22953 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
22954 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
22955 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
22956 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
22957 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22958 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22959 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22960 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22961 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22962 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22963 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
22964 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22965 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
22966 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22967 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
22968 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22969 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22970 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22971 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22972 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22973 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22974 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22975 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22976 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22977 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22978 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22979 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
22980 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22981 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22982 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22983 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
22984 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
22985 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
22986 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
22987 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
22988 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
22989 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
22990 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22991 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
22992 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22993 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22994 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22995 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
22996 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
22997 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
22998 /* For V5 or later processors we default to using VFP; but the user
22999 should really set the FPU type explicitly. */
23000 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23001 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23002 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23003 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23004 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23005 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23006 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
23007 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23008 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23009 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
23010 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23011 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23012 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23013 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23014 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23015 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
23016 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23017 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23018 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23019 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
23021 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23022 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23023 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23024 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23025 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23026 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23027 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
23028 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
23029 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
23031 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
23032 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
23033 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
23034 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
23035 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
23036 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL),
23037 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL),
23038 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
23039 FPU_NONE, "Cortex-A5"),
23040 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23041 FPU_ARCH_NEON_VFP_V4,
23043 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
23044 ARM_FEATURE (0, FPU_VFP_V3
23045 | FPU_NEON_EXT_V1),
23047 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
23048 ARM_FEATURE (0, FPU_VFP_V3
23049 | FPU_NEON_EXT_V1),
23051 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23052 FPU_ARCH_NEON_VFP_V4,
23054 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
23055 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
23057 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
23058 FPU_NONE, "Cortex-R5"),
23059 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
23060 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
23061 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
23062 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
23063 /* ??? XSCALE is really an architecture. */
23064 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
23065 /* ??? iwmmxt is not a processor. */
23066 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
23067 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
23068 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
23070 ARM_CPU_OPT ("ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
23073 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
23077 struct arm_arch_option_table
23081 const arm_feature_set value;
23082 const arm_feature_set default_fpu;
23085 /* This list should, at a minimum, contain all the architecture names
23086 recognized by GCC. */
23087 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
23088 static const struct arm_arch_option_table arm_archs[] =
23090 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
23091 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
23092 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
23093 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
23094 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
23095 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
23096 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
23097 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
23098 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
23099 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
23100 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
23101 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
23102 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
23103 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
23104 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
23105 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
23106 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
23107 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
23108 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
23109 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
23110 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
23111 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP),
23112 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
23113 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
23114 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
23115 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP),
23116 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
23117 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
23118 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
23119 /* The official spelling of the ARMv7 profile variants is the dashed form.
23120 Accept the non-dashed form for compatibility with old toolchains. */
23121 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23122 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23123 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23124 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23125 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23126 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23127 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
23128 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
23129 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
23130 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
23131 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
23133 #undef ARM_ARCH_OPT
23135 /* ISA extensions in the co-processor and main instruction set space. */
23136 struct arm_option_extension_value_table
23140 const arm_feature_set value;
23141 const arm_feature_set allowed_archs;
23144 /* The following table must be in alphabetical order with a NULL last entry.
23146 #define ARM_EXT_OPT(N, V, AA) { N, sizeof (N) - 1, V, AA }
23147 static const struct arm_option_extension_value_table arm_extensions[] =
23149 ARM_EXT_OPT ("idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
23150 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23151 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY),
23152 ARM_EXT_OPT ("iwmmxt2",
23153 ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY),
23154 ARM_EXT_OPT ("maverick",
23155 ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY),
23156 ARM_EXT_OPT ("mp", ARM_FEATURE (ARM_EXT_MP, 0),
23157 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23158 ARM_EXT_OPT ("os", ARM_FEATURE (ARM_EXT_OS, 0),
23159 ARM_FEATURE (ARM_EXT_V6M, 0)),
23160 ARM_EXT_OPT ("sec", ARM_FEATURE (ARM_EXT_SEC, 0),
23161 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)),
23162 ARM_EXT_OPT ("virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV
23164 ARM_FEATURE (ARM_EXT_V7A, 0)),
23165 ARM_EXT_OPT ("xscale",ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY),
23166 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
23170 /* ISA floating-point and Advanced SIMD extensions. */
23171 struct arm_option_fpu_value_table
23174 const arm_feature_set value;
23177 /* This list should, at a minimum, contain all the fpu names
23178 recognized by GCC. */
23179 static const struct arm_option_fpu_value_table arm_fpus[] =
23181 {"softfpa", FPU_NONE},
23182 {"fpe", FPU_ARCH_FPE},
23183 {"fpe2", FPU_ARCH_FPE},
23184 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
23185 {"fpa", FPU_ARCH_FPA},
23186 {"fpa10", FPU_ARCH_FPA},
23187 {"fpa11", FPU_ARCH_FPA},
23188 {"arm7500fe", FPU_ARCH_FPA},
23189 {"softvfp", FPU_ARCH_VFP},
23190 {"softvfp+vfp", FPU_ARCH_VFP_V2},
23191 {"vfp", FPU_ARCH_VFP_V2},
23192 {"vfp9", FPU_ARCH_VFP_V2},
23193 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
23194 {"vfp10", FPU_ARCH_VFP_V2},
23195 {"vfp10-r0", FPU_ARCH_VFP_V1},
23196 {"vfpxd", FPU_ARCH_VFP_V1xD},
23197 {"vfpv2", FPU_ARCH_VFP_V2},
23198 {"vfpv3", FPU_ARCH_VFP_V3},
23199 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
23200 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
23201 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
23202 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
23203 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
23204 {"arm1020t", FPU_ARCH_VFP_V1},
23205 {"arm1020e", FPU_ARCH_VFP_V2},
23206 {"arm1136jfs", FPU_ARCH_VFP_V2},
23207 {"arm1136jf-s", FPU_ARCH_VFP_V2},
23208 {"maverick", FPU_ARCH_MAVERICK},
23209 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
23210 {"neon-fp16", FPU_ARCH_NEON_FP16},
23211 {"vfpv4", FPU_ARCH_VFP_V4},
23212 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
23213 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
23214 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
23215 {NULL, ARM_ARCH_NONE}
23218 struct arm_option_value_table
23224 static const struct arm_option_value_table arm_float_abis[] =
23226 {"hard", ARM_FLOAT_ABI_HARD},
23227 {"softfp", ARM_FLOAT_ABI_SOFTFP},
23228 {"soft", ARM_FLOAT_ABI_SOFT},
23233 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
23234 static const struct arm_option_value_table arm_eabis[] =
23236 {"gnu", EF_ARM_EABI_UNKNOWN},
23237 {"4", EF_ARM_EABI_VER4},
23238 {"5", EF_ARM_EABI_VER5},
23243 struct arm_long_option_table
23245 char * option; /* Substring to match. */
23246 char * help; /* Help information. */
23247 int (* func) (char * subopt); /* Function to decode sub-option. */
23248 char * deprecated; /* If non-null, print this message. */
23252 arm_parse_extension (char *str, const arm_feature_set **opt_p)
23254 arm_feature_set *ext_set = (arm_feature_set *)
23255 xmalloc (sizeof (arm_feature_set));
23257 /* We insist on extensions being specified in alphabetical order, and with
23258 extensions being added before being removed. We achieve this by having
23259 the global ARM_EXTENSIONS table in alphabetical order, and using the
23260 ADDING_VALUE variable to indicate whether we are adding an extension (1)
23261 or removing it (0) and only allowing it to change in the order
23263 const struct arm_option_extension_value_table * opt = NULL;
23264 int adding_value = -1;
23266 /* Copy the feature set, so that we can modify it. */
23267 *ext_set = **opt_p;
23270 while (str != NULL && *str != 0)
23277 as_bad (_("invalid architectural extension"));
23282 ext = strchr (str, '+');
23287 len = strlen (str);
23289 if (len >= 2 && strncmp (str, "no", 2) == 0)
23291 if (adding_value != 0)
23294 opt = arm_extensions;
23302 if (adding_value == -1)
23305 opt = arm_extensions;
23307 else if (adding_value != 1)
23309 as_bad (_("must specify extensions to add before specifying "
23310 "those to remove"));
23317 as_bad (_("missing architectural extension"));
23321 gas_assert (adding_value != -1);
23322 gas_assert (opt != NULL);
23324 /* Scan over the options table trying to find an exact match. */
23325 for (; opt->name != NULL; opt++)
23326 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
23328 /* Check we can apply the extension to this architecture. */
23329 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
23331 as_bad (_("extension does not apply to the base architecture"));
23335 /* Add or remove the extension. */
23337 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
23339 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
23344 if (opt->name == NULL)
23346 /* Did we fail to find an extension because it wasn't specified in
23347 alphabetical order, or because it does not exist? */
23349 for (opt = arm_extensions; opt->name != NULL; opt++)
23350 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
23353 if (opt->name == NULL)
23354 as_bad (_("unknown architectural extension `%s'"), str);
23356 as_bad (_("architectural extensions must be specified in "
23357 "alphabetical order"));
23363 /* We should skip the extension we've just matched the next time
23375 arm_parse_cpu (char *str)
23377 const struct arm_cpu_option_table *opt;
23378 char *ext = strchr (str, '+');
23384 len = strlen (str);
23388 as_bad (_("missing cpu name `%s'"), str);
23392 for (opt = arm_cpus; opt->name != NULL; opt++)
23393 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
23395 mcpu_cpu_opt = &opt->value;
23396 mcpu_fpu_opt = &opt->default_fpu;
23397 if (opt->canonical_name)
23398 strcpy (selected_cpu_name, opt->canonical_name);
23403 for (i = 0; i < len; i++)
23404 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23405 selected_cpu_name[i] = 0;
23409 return arm_parse_extension (ext, &mcpu_cpu_opt);
23414 as_bad (_("unknown cpu `%s'"), str);
23419 arm_parse_arch (char *str)
23421 const struct arm_arch_option_table *opt;
23422 char *ext = strchr (str, '+');
23428 len = strlen (str);
23432 as_bad (_("missing architecture name `%s'"), str);
23436 for (opt = arm_archs; opt->name != NULL; opt++)
23437 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
23439 march_cpu_opt = &opt->value;
23440 march_fpu_opt = &opt->default_fpu;
23441 strcpy (selected_cpu_name, opt->name);
23444 return arm_parse_extension (ext, &march_cpu_opt);
23449 as_bad (_("unknown architecture `%s'\n"), str);
23454 arm_parse_fpu (char * str)
23456 const struct arm_option_fpu_value_table * opt;
23458 for (opt = arm_fpus; opt->name != NULL; opt++)
23459 if (streq (opt->name, str))
23461 mfpu_opt = &opt->value;
23465 as_bad (_("unknown floating point format `%s'\n"), str);
23470 arm_parse_float_abi (char * str)
23472 const struct arm_option_value_table * opt;
23474 for (opt = arm_float_abis; opt->name != NULL; opt++)
23475 if (streq (opt->name, str))
23477 mfloat_abi_opt = opt->value;
23481 as_bad (_("unknown floating point abi `%s'\n"), str);
23487 arm_parse_eabi (char * str)
23489 const struct arm_option_value_table *opt;
23491 for (opt = arm_eabis; opt->name != NULL; opt++)
23492 if (streq (opt->name, str))
23494 meabi_flags = opt->value;
23497 as_bad (_("unknown EABI `%s'\n"), str);
23503 arm_parse_it_mode (char * str)
23505 bfd_boolean ret = TRUE;
23507 if (streq ("arm", str))
23508 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
23509 else if (streq ("thumb", str))
23510 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
23511 else if (streq ("always", str))
23512 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
23513 else if (streq ("never", str))
23514 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
23517 as_bad (_("unknown implicit IT mode `%s', should be "\
23518 "arm, thumb, always, or never."), str);
23525 struct arm_long_option_table arm_long_opts[] =
23527 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
23528 arm_parse_cpu, NULL},
23529 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
23530 arm_parse_arch, NULL},
23531 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
23532 arm_parse_fpu, NULL},
23533 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
23534 arm_parse_float_abi, NULL},
23536 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
23537 arm_parse_eabi, NULL},
23539 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
23540 arm_parse_it_mode, NULL},
23541 {NULL, NULL, 0, NULL}
23545 md_parse_option (int c, char * arg)
23547 struct arm_option_table *opt;
23548 const struct arm_legacy_option_table *fopt;
23549 struct arm_long_option_table *lopt;
23555 target_big_endian = 1;
23561 target_big_endian = 0;
23565 case OPTION_FIX_V4BX:
23570 /* Listing option. Just ignore these, we don't support additional
23575 for (opt = arm_opts; opt->option != NULL; opt++)
23577 if (c == opt->option[0]
23578 && ((arg == NULL && opt->option[1] == 0)
23579 || streq (arg, opt->option + 1)))
23581 /* If the option is deprecated, tell the user. */
23582 if (warn_on_deprecated && opt->deprecated != NULL)
23583 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23584 arg ? arg : "", _(opt->deprecated));
23586 if (opt->var != NULL)
23587 *opt->var = opt->value;
23593 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
23595 if (c == fopt->option[0]
23596 && ((arg == NULL && fopt->option[1] == 0)
23597 || streq (arg, fopt->option + 1)))
23599 /* If the option is deprecated, tell the user. */
23600 if (warn_on_deprecated && fopt->deprecated != NULL)
23601 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23602 arg ? arg : "", _(fopt->deprecated));
23604 if (fopt->var != NULL)
23605 *fopt->var = &fopt->value;
23611 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23613 /* These options are expected to have an argument. */
23614 if (c == lopt->option[0]
23616 && strncmp (arg, lopt->option + 1,
23617 strlen (lopt->option + 1)) == 0)
23619 /* If the option is deprecated, tell the user. */
23620 if (warn_on_deprecated && lopt->deprecated != NULL)
23621 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
23622 _(lopt->deprecated));
23624 /* Call the sup-option parser. */
23625 return lopt->func (arg + strlen (lopt->option) - 1);
23636 md_show_usage (FILE * fp)
23638 struct arm_option_table *opt;
23639 struct arm_long_option_table *lopt;
23641 fprintf (fp, _(" ARM-specific assembler options:\n"));
23643 for (opt = arm_opts; opt->option != NULL; opt++)
23644 if (opt->help != NULL)
23645 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
23647 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23648 if (lopt->help != NULL)
23649 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
23653 -EB assemble code for a big-endian cpu\n"));
23658 -EL assemble code for a little-endian cpu\n"));
23662 --fix-v4bx Allow BX in ARMv4 code\n"));
23670 arm_feature_set flags;
23671 } cpu_arch_ver_table;
23673 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23674 least features first. */
23675 static const cpu_arch_ver_table cpu_arch_ver[] =
23681 {4, ARM_ARCH_V5TE},
23682 {5, ARM_ARCH_V5TEJ},
23686 {11, ARM_ARCH_V6M},
23687 {12, ARM_ARCH_V6SM},
23688 {8, ARM_ARCH_V6T2},
23689 {10, ARM_ARCH_V7A},
23690 {10, ARM_ARCH_V7R},
23691 {10, ARM_ARCH_V7M},
23695 /* Set an attribute if it has not already been set by the user. */
23697 aeabi_set_attribute_int (int tag, int value)
23700 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23701 || !attributes_set_explicitly[tag])
23702 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23706 aeabi_set_attribute_string (int tag, const char *value)
23709 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23710 || !attributes_set_explicitly[tag])
23711 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23714 /* Set the public EABI object attributes. */
23716 aeabi_set_public_attributes (void)
23721 arm_feature_set flags;
23722 arm_feature_set tmp;
23723 const cpu_arch_ver_table *p;
23725 /* Choose the architecture based on the capabilities of the requested cpu
23726 (if any) and/or the instructions actually used. */
23727 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23728 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23729 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
23731 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
23732 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
23734 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
23735 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
23737 /* Allow the user to override the reported architecture. */
23740 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23741 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23744 /* We need to make sure that the attributes do not identify us as v6S-M
23745 when the only v6S-M feature in use is the Operating System Extensions. */
23746 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
23747 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
23748 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
23752 for (p = cpu_arch_ver; p->val; p++)
23754 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23757 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23761 /* The table lookup above finds the last architecture to contribute
23762 a new feature. Unfortunately, Tag13 is a subset of the union of
23763 v6T2 and v7-M, so it is never seen as contributing a new feature.
23764 We can not search for the last entry which is entirely used,
23765 because if no CPU is specified we build up only those flags
23766 actually used. Perhaps we should separate out the specified
23767 and implicit cases. Avoid taking this path for -march=all by
23768 checking for contradictory v7-A / v7-M features. */
23770 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23771 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23772 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23775 /* Tag_CPU_name. */
23776 if (selected_cpu_name[0])
23780 q = selected_cpu_name;
23781 if (strncmp (q, "armv", 4) == 0)
23786 for (i = 0; q[i]; i++)
23787 q[i] = TOUPPER (q[i]);
23789 aeabi_set_attribute_string (Tag_CPU_name, q);
23792 /* Tag_CPU_arch. */
23793 aeabi_set_attribute_int (Tag_CPU_arch, arch);
23795 /* Tag_CPU_arch_profile. */
23796 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
23798 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
23800 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
23805 if (profile != '\0')
23806 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
23808 /* Tag_ARM_ISA_use. */
23809 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23811 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
23813 /* Tag_THUMB_ISA_use. */
23814 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23816 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23817 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
23819 /* Tag_VFP_arch. */
23820 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23821 aeabi_set_attribute_int (Tag_VFP_arch,
23822 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23824 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
23825 aeabi_set_attribute_int (Tag_VFP_arch, 3);
23826 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
23827 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23828 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23829 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23830 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23831 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23832 aeabi_set_attribute_int (Tag_VFP_arch, 1);
23834 /* Tag_ABI_HardFP_use. */
23835 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23836 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23837 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23839 /* Tag_WMMX_arch. */
23840 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23841 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23842 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23843 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
23845 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
23846 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
23847 aeabi_set_attribute_int
23848 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
23851 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
23852 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
23853 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
23857 We set Tag_DIV_use to two when integer divide instructions have been used
23858 in ARM state, or when Thumb integer divide instructions have been used,
23859 but we have no architecture profile set, nor have we any ARM instructions.
23861 For new architectures we will have to check these tests. */
23862 gas_assert (arch <= TAG_CPU_ARCH_V7E_M);
23863 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
23864 || (profile == '\0'
23865 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
23866 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
23867 aeabi_set_attribute_int (Tag_DIV_use, 2);
23869 /* Tag_MP_extension_use. */
23870 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
23871 aeabi_set_attribute_int (Tag_MPextension_use, 1);
23873 /* Tag Virtualization_use. */
23874 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
23876 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
23879 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
23882 /* Add the default contents for the .ARM.attributes section. */
23886 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23889 aeabi_set_public_attributes ();
23891 #endif /* OBJ_ELF */
23894 /* Parse a .cpu directive. */
23897 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
23899 const struct arm_cpu_option_table *opt;
23903 name = input_line_pointer;
23904 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23905 input_line_pointer++;
23906 saved_char = *input_line_pointer;
23907 *input_line_pointer = 0;
23909 /* Skip the first "all" entry. */
23910 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23911 if (streq (opt->name, name))
23913 mcpu_cpu_opt = &opt->value;
23914 selected_cpu = opt->value;
23915 if (opt->canonical_name)
23916 strcpy (selected_cpu_name, opt->canonical_name);
23920 for (i = 0; opt->name[i]; i++)
23921 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23923 selected_cpu_name[i] = 0;
23925 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23926 *input_line_pointer = saved_char;
23927 demand_empty_rest_of_line ();
23930 as_bad (_("unknown cpu `%s'"), name);
23931 *input_line_pointer = saved_char;
23932 ignore_rest_of_line ();
23936 /* Parse a .arch directive. */
23939 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23941 const struct arm_arch_option_table *opt;
23945 name = input_line_pointer;
23946 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23947 input_line_pointer++;
23948 saved_char = *input_line_pointer;
23949 *input_line_pointer = 0;
23951 /* Skip the first "all" entry. */
23952 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23953 if (streq (opt->name, name))
23955 mcpu_cpu_opt = &opt->value;
23956 selected_cpu = opt->value;
23957 strcpy (selected_cpu_name, opt->name);
23958 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23959 *input_line_pointer = saved_char;
23960 demand_empty_rest_of_line ();
23964 as_bad (_("unknown architecture `%s'\n"), name);
23965 *input_line_pointer = saved_char;
23966 ignore_rest_of_line ();
23970 /* Parse a .object_arch directive. */
23973 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
23975 const struct arm_arch_option_table *opt;
23979 name = input_line_pointer;
23980 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23981 input_line_pointer++;
23982 saved_char = *input_line_pointer;
23983 *input_line_pointer = 0;
23985 /* Skip the first "all" entry. */
23986 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23987 if (streq (opt->name, name))
23989 object_arch = &opt->value;
23990 *input_line_pointer = saved_char;
23991 demand_empty_rest_of_line ();
23995 as_bad (_("unknown architecture `%s'\n"), name);
23996 *input_line_pointer = saved_char;
23997 ignore_rest_of_line ();
24000 /* Parse a .arch_extension directive. */
24003 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
24005 const struct arm_option_extension_value_table *opt;
24008 int adding_value = 1;
24010 name = input_line_pointer;
24011 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24012 input_line_pointer++;
24013 saved_char = *input_line_pointer;
24014 *input_line_pointer = 0;
24016 if (strlen (name) >= 2
24017 && strncmp (name, "no", 2) == 0)
24023 for (opt = arm_extensions; opt->name != NULL; opt++)
24024 if (streq (opt->name, name))
24026 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
24028 as_bad (_("architectural extension `%s' is not allowed for the "
24029 "current base architecture"), name);
24034 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
24036 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
24038 mcpu_cpu_opt = &selected_cpu;
24039 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24040 *input_line_pointer = saved_char;
24041 demand_empty_rest_of_line ();
24045 if (opt->name == NULL)
24046 as_bad (_("unknown architecture `%s'\n"), name);
24048 *input_line_pointer = saved_char;
24049 ignore_rest_of_line ();
24052 /* Parse a .fpu directive. */
24055 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
24057 const struct arm_option_fpu_value_table *opt;
24061 name = input_line_pointer;
24062 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24063 input_line_pointer++;
24064 saved_char = *input_line_pointer;
24065 *input_line_pointer = 0;
24067 for (opt = arm_fpus; opt->name != NULL; opt++)
24068 if (streq (opt->name, name))
24070 mfpu_opt = &opt->value;
24071 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24072 *input_line_pointer = saved_char;
24073 demand_empty_rest_of_line ();
24077 as_bad (_("unknown floating point format `%s'\n"), name);
24078 *input_line_pointer = saved_char;
24079 ignore_rest_of_line ();
24082 /* Copy symbol information. */
24085 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
24087 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
24091 /* Given a symbolic attribute NAME, return the proper integer value.
24092 Returns -1 if the attribute is not known. */
24095 arm_convert_symbolic_attribute (const char *name)
24097 static const struct
24102 attribute_table[] =
24104 /* When you modify this table you should
24105 also modify the list in doc/c-arm.texi. */
24106 #define T(tag) {#tag, tag}
24107 T (Tag_CPU_raw_name),
24110 T (Tag_CPU_arch_profile),
24111 T (Tag_ARM_ISA_use),
24112 T (Tag_THUMB_ISA_use),
24116 T (Tag_Advanced_SIMD_arch),
24117 T (Tag_PCS_config),
24118 T (Tag_ABI_PCS_R9_use),
24119 T (Tag_ABI_PCS_RW_data),
24120 T (Tag_ABI_PCS_RO_data),
24121 T (Tag_ABI_PCS_GOT_use),
24122 T (Tag_ABI_PCS_wchar_t),
24123 T (Tag_ABI_FP_rounding),
24124 T (Tag_ABI_FP_denormal),
24125 T (Tag_ABI_FP_exceptions),
24126 T (Tag_ABI_FP_user_exceptions),
24127 T (Tag_ABI_FP_number_model),
24128 T (Tag_ABI_align_needed),
24129 T (Tag_ABI_align8_needed),
24130 T (Tag_ABI_align_preserved),
24131 T (Tag_ABI_align8_preserved),
24132 T (Tag_ABI_enum_size),
24133 T (Tag_ABI_HardFP_use),
24134 T (Tag_ABI_VFP_args),
24135 T (Tag_ABI_WMMX_args),
24136 T (Tag_ABI_optimization_goals),
24137 T (Tag_ABI_FP_optimization_goals),
24138 T (Tag_compatibility),
24139 T (Tag_CPU_unaligned_access),
24140 T (Tag_FP_HP_extension),
24141 T (Tag_VFP_HP_extension),
24142 T (Tag_ABI_FP_16bit_format),
24143 T (Tag_MPextension_use),
24145 T (Tag_nodefaults),
24146 T (Tag_also_compatible_with),
24147 T (Tag_conformance),
24149 T (Tag_Virtualization_use),
24150 /* We deliberately do not include Tag_MPextension_use_legacy. */
24158 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
24159 if (streq (name, attribute_table[i].name))
24160 return attribute_table[i].tag;
24166 /* Apply sym value for relocations only in the case that
24167 they are for local symbols and you have the respective
24168 architectural feature for blx and simple switches. */
24170 arm_apply_sym_value (struct fix * fixP)
24173 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24174 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
24176 switch (fixP->fx_r_type)
24178 case BFD_RELOC_ARM_PCREL_BLX:
24179 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24180 if (ARM_IS_FUNC (fixP->fx_addsy))
24184 case BFD_RELOC_ARM_PCREL_CALL:
24185 case BFD_RELOC_THUMB_PCREL_BLX:
24186 if (THUMB_IS_FUNC (fixP->fx_addsy))
24197 #endif /* OBJ_ELF */