PR gas/12848
[binutils.git] / gas / config / tc-arm.c
blobfca5483ceb8afca656c3bbb4f9186abe08ae267f
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
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
11 This file is part of GAS, the GNU Assembler.
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
16 any later version.
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
28 #include "as.h"
29 #include <limits.h>
30 #include <stdarg.h>
31 #define NO_RELOC 0
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
36 #include "opcode/arm.h"
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dw2gencfi.h"
41 #endif
43 #include "dwarf2dbg.h"
45 #ifdef OBJ_ELF
46 /* Must be at least the size of the largest unwind opcode (currently two). */
47 #define ARM_OPCODE_CHUNK_SIZE 8
49 /* This structure holds the unwinding state. */
51 static struct
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
57 /* The segment containing the function. */
58 segT saved_seg;
59 subsegT saved_subseg;
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
62 int opcode_count;
63 int opcode_alloc;
64 /* The number of bytes pushed to the stack. */
65 offsetT frame_size;
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
69 offsetT pending_offset;
70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
74 /* Nonzero if an unwind_setfp directive has been seen. */
75 unsigned fp_used:1;
76 /* Nonzero if the last opcode restores sp from fp_reg. */
77 unsigned sp_restored:1;
78 } unwind;
80 #endif /* OBJ_ELF */
82 /* Results from operand parsing worker functions. */
84 typedef enum
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89 } parse_operand_result;
91 enum arm_float_abi
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
98 /* Types of processor to assemble for. */
99 #ifndef CPU_DEFAULT
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. */
106 #endif
108 #ifndef FPU_DEFAULT
109 # ifdef TE_LINUX
110 # define FPU_DEFAULT FPU_ARCH_FPA
111 # elif defined (TE_NetBSD)
112 # ifdef OBJ_ELF
113 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114 # else
115 /* Legacy a.out format. */
116 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117 # endif
118 # elif defined (TE_VXWORKS)
119 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
120 # else
121 /* For backwards compatibility, default to FPA. */
122 # define FPU_DEFAULT FPU_ARCH_FPA
123 # endif
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
145 assembly flags. */
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;
167 #ifdef CPU_DEFAULT
168 static const arm_feature_set cpu_default = CPU_DEFAULT;
169 #endif
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. */
244 static bfd_boolean
245 no_cpu_selected (void)
247 return selected_cpu.core == arm_arch_none.core
248 && selected_cpu.coproc == arm_arch_none.coproc;
251 #ifdef OBJ_ELF
252 # ifdef EABI_DEFAULT
253 static int meabi_flags = EABI_DEFAULT;
254 # else
255 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
256 # endif
258 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
260 bfd_boolean
261 arm_is_eabi (void)
263 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
265 #endif
267 #ifdef OBJ_ELF
268 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
269 symbolS * GOT_symbol;
270 #endif
272 /* 0: assemble for ARM,
273 1: assemble for Thumb,
274 2: assemble for Thumb even though target CPU does not support thumb
275 instructions. */
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
299 there.)
300 - The IT instruction may appear, and if it does is validated
301 against subsequent conditional affixes. It does not generate
302 machine code.
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;
317 enum neon_el_type
319 NT_invtype,
320 NT_untyped,
321 NT_integer,
322 NT_float,
323 NT_poly,
324 NT_signed,
325 NT_unsigned
328 struct neon_type_el
330 enum neon_el_type type;
331 unsigned size;
334 #define NEON_MAX_TYPE_ELS 4
336 struct neon_type
338 struct neon_type_el el[NEON_MAX_TYPE_ELS];
339 unsigned elems;
342 enum it_instruction_type
344 OUTSIDE_IT_INSN,
345 INSIDE_IT_INSN,
346 INSIDE_IT_LAST_INSN,
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 struct arm_it
356 const char * error;
357 unsigned long instruction;
358 int size;
359 int size_req;
360 int cond;
361 /* "uncond_value" is set to the value in place of the conditional field in
362 unconditional versions of the instruction, or -1 if nothing is
363 appropriate. */
364 int uncond_value;
365 struct neon_type vectype;
366 /* This does not indicate an actual NEON instruction, only that
367 the mnemonic accepts neon-style type suffixes. */
368 int is_neon;
369 /* Set to the opcode if the instruction needs relaxation.
370 Zero if the instruction is not relaxed. */
371 unsigned long relax;
372 struct
374 bfd_reloc_code_real_type type;
375 expressionS exp;
376 int pc_rel;
377 } reloc;
379 enum it_instruction_type it_insn_type;
381 struct
383 unsigned reg;
384 signed int imm;
385 struct neon_type_el vectype;
386 unsigned present : 1; /* Operand present. */
387 unsigned isreg : 1; /* Operand was a register. */
388 unsigned immisreg : 1; /* .imm field is a second register. */
389 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
390 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
391 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
392 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
393 instructions. This allows us to disambiguate ARM <-> vector insns. */
394 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
395 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
396 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
397 unsigned issingle : 1; /* Operand is VFP single-precision register. */
398 unsigned hasreloc : 1; /* Operand has relocation suffix. */
399 unsigned writeback : 1; /* Operand has trailing ! */
400 unsigned preind : 1; /* Preindexed address. */
401 unsigned postind : 1; /* Postindexed address. */
402 unsigned negative : 1; /* Index register was negated. */
403 unsigned shifted : 1; /* Shift applied to operation. */
404 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
405 } operands[6];
408 static struct arm_it inst;
410 #define NUM_FLOAT_VALS 8
412 const char * fp_const[] =
414 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
417 /* Number of littlenums required to hold an extended precision number. */
418 #define MAX_LITTLENUMS 6
420 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
422 #define FAIL (-1)
423 #define SUCCESS (0)
425 #define SUFF_S 1
426 #define SUFF_D 2
427 #define SUFF_E 3
428 #define SUFF_P 4
430 #define CP_T_X 0x00008000
431 #define CP_T_Y 0x00400000
433 #define CONDS_BIT 0x00100000
434 #define LOAD_BIT 0x00100000
436 #define DOUBLE_LOAD_FLAG 0x00000001
438 struct asm_cond
440 const char * template_name;
441 unsigned long value;
444 #define COND_ALWAYS 0xE
446 struct asm_psr
448 const char * template_name;
449 unsigned long field;
452 struct asm_barrier_opt
454 const char * template_name;
455 unsigned long value;
458 /* The bit that distinguishes CPSR and SPSR. */
459 #define SPSR_BIT (1 << 22)
461 /* The individual PSR flag bits. */
462 #define PSR_c (1 << 16)
463 #define PSR_x (1 << 17)
464 #define PSR_s (1 << 18)
465 #define PSR_f (1 << 19)
467 struct reloc_entry
469 char * name;
470 bfd_reloc_code_real_type reloc;
473 enum vfp_reg_pos
475 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
476 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
479 enum vfp_ldstm_type
481 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
484 /* Bits for DEFINED field in neon_typed_alias. */
485 #define NTA_HASTYPE 1
486 #define NTA_HASINDEX 2
488 struct neon_typed_alias
490 unsigned char defined;
491 unsigned char index;
492 struct neon_type_el eltype;
495 /* ARM register categories. This includes coprocessor numbers and various
496 architecture extensions' registers. */
497 enum arm_reg_type
499 REG_TYPE_RN,
500 REG_TYPE_CP,
501 REG_TYPE_CN,
502 REG_TYPE_FN,
503 REG_TYPE_VFS,
504 REG_TYPE_VFD,
505 REG_TYPE_NQ,
506 REG_TYPE_VFSD,
507 REG_TYPE_NDQ,
508 REG_TYPE_NSDQ,
509 REG_TYPE_VFC,
510 REG_TYPE_MVF,
511 REG_TYPE_MVD,
512 REG_TYPE_MVFX,
513 REG_TYPE_MVDX,
514 REG_TYPE_MVAX,
515 REG_TYPE_DSPSC,
516 REG_TYPE_MMXWR,
517 REG_TYPE_MMXWC,
518 REG_TYPE_MMXWCG,
519 REG_TYPE_XSCALE,
520 REG_TYPE_RNB
523 /* Structure for a hash table entry for a register.
524 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
525 information which states whether a vector type or index is specified (for a
526 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
527 struct reg_entry
529 const char * name;
530 unsigned int number;
531 unsigned char type;
532 unsigned char builtin;
533 struct neon_typed_alias * neon;
536 /* Diagnostics used when we don't get a register of the expected type. */
537 const char * const reg_expected_msgs[] =
539 N_("ARM register expected"),
540 N_("bad or missing co-processor number"),
541 N_("co-processor register expected"),
542 N_("FPA register expected"),
543 N_("VFP single precision register expected"),
544 N_("VFP/Neon double precision register expected"),
545 N_("Neon quad precision register expected"),
546 N_("VFP single or double precision register expected"),
547 N_("Neon double or quad precision register expected"),
548 N_("VFP single, double or Neon quad precision register expected"),
549 N_("VFP system register expected"),
550 N_("Maverick MVF register expected"),
551 N_("Maverick MVD register expected"),
552 N_("Maverick MVFX register expected"),
553 N_("Maverick MVDX register expected"),
554 N_("Maverick MVAX register expected"),
555 N_("Maverick DSPSC register expected"),
556 N_("iWMMXt data register expected"),
557 N_("iWMMXt control register expected"),
558 N_("iWMMXt scalar register expected"),
559 N_("XScale accumulator register expected"),
562 /* Some well known registers that we refer to directly elsewhere. */
563 #define REG_SP 13
564 #define REG_LR 14
565 #define REG_PC 15
567 /* ARM instructions take 4bytes in the object file, Thumb instructions
568 take 2: */
569 #define INSN_SIZE 4
571 struct asm_opcode
573 /* Basic string to match. */
574 const char * template_name;
576 /* Parameters to instruction. */
577 unsigned int operands[8];
579 /* Conditional tag - see opcode_lookup. */
580 unsigned int tag : 4;
582 /* Basic instruction code. */
583 unsigned int avalue : 28;
585 /* Thumb-format instruction code. */
586 unsigned int tvalue;
588 /* Which architecture variant provides this instruction. */
589 const arm_feature_set * avariant;
590 const arm_feature_set * tvariant;
592 /* Function to call to encode instruction in ARM format. */
593 void (* aencode) (void);
595 /* Function to call to encode instruction in Thumb format. */
596 void (* tencode) (void);
599 /* Defines for various bits that we will want to toggle. */
600 #define INST_IMMEDIATE 0x02000000
601 #define OFFSET_REG 0x02000000
602 #define HWOFFSET_IMM 0x00400000
603 #define SHIFT_BY_REG 0x00000010
604 #define PRE_INDEX 0x01000000
605 #define INDEX_UP 0x00800000
606 #define WRITE_BACK 0x00200000
607 #define LDM_TYPE_2_OR_3 0x00400000
608 #define CPSI_MMOD 0x00020000
610 #define LITERAL_MASK 0xf000f000
611 #define OPCODE_MASK 0xfe1fffff
612 #define V4_STR_BIT 0x00000020
614 #define T2_SUBS_PC_LR 0xf3de8f00
616 #define DATA_OP_SHIFT 21
618 #define T2_OPCODE_MASK 0xfe1fffff
619 #define T2_DATA_OP_SHIFT 21
621 /* Codes to distinguish the arithmetic instructions. */
622 #define OPCODE_AND 0
623 #define OPCODE_EOR 1
624 #define OPCODE_SUB 2
625 #define OPCODE_RSB 3
626 #define OPCODE_ADD 4
627 #define OPCODE_ADC 5
628 #define OPCODE_SBC 6
629 #define OPCODE_RSC 7
630 #define OPCODE_TST 8
631 #define OPCODE_TEQ 9
632 #define OPCODE_CMP 10
633 #define OPCODE_CMN 11
634 #define OPCODE_ORR 12
635 #define OPCODE_MOV 13
636 #define OPCODE_BIC 14
637 #define OPCODE_MVN 15
639 #define T2_OPCODE_AND 0
640 #define T2_OPCODE_BIC 1
641 #define T2_OPCODE_ORR 2
642 #define T2_OPCODE_ORN 3
643 #define T2_OPCODE_EOR 4
644 #define T2_OPCODE_ADD 8
645 #define T2_OPCODE_ADC 10
646 #define T2_OPCODE_SBC 11
647 #define T2_OPCODE_SUB 13
648 #define T2_OPCODE_RSB 14
650 #define T_OPCODE_MUL 0x4340
651 #define T_OPCODE_TST 0x4200
652 #define T_OPCODE_CMN 0x42c0
653 #define T_OPCODE_NEG 0x4240
654 #define T_OPCODE_MVN 0x43c0
656 #define T_OPCODE_ADD_R3 0x1800
657 #define T_OPCODE_SUB_R3 0x1a00
658 #define T_OPCODE_ADD_HI 0x4400
659 #define T_OPCODE_ADD_ST 0xb000
660 #define T_OPCODE_SUB_ST 0xb080
661 #define T_OPCODE_ADD_SP 0xa800
662 #define T_OPCODE_ADD_PC 0xa000
663 #define T_OPCODE_ADD_I8 0x3000
664 #define T_OPCODE_SUB_I8 0x3800
665 #define T_OPCODE_ADD_I3 0x1c00
666 #define T_OPCODE_SUB_I3 0x1e00
668 #define T_OPCODE_ASR_R 0x4100
669 #define T_OPCODE_LSL_R 0x4080
670 #define T_OPCODE_LSR_R 0x40c0
671 #define T_OPCODE_ROR_R 0x41c0
672 #define T_OPCODE_ASR_I 0x1000
673 #define T_OPCODE_LSL_I 0x0000
674 #define T_OPCODE_LSR_I 0x0800
676 #define T_OPCODE_MOV_I8 0x2000
677 #define T_OPCODE_CMP_I8 0x2800
678 #define T_OPCODE_CMP_LR 0x4280
679 #define T_OPCODE_MOV_HR 0x4600
680 #define T_OPCODE_CMP_HR 0x4500
682 #define T_OPCODE_LDR_PC 0x4800
683 #define T_OPCODE_LDR_SP 0x9800
684 #define T_OPCODE_STR_SP 0x9000
685 #define T_OPCODE_LDR_IW 0x6800
686 #define T_OPCODE_STR_IW 0x6000
687 #define T_OPCODE_LDR_IH 0x8800
688 #define T_OPCODE_STR_IH 0x8000
689 #define T_OPCODE_LDR_IB 0x7800
690 #define T_OPCODE_STR_IB 0x7000
691 #define T_OPCODE_LDR_RW 0x5800
692 #define T_OPCODE_STR_RW 0x5000
693 #define T_OPCODE_LDR_RH 0x5a00
694 #define T_OPCODE_STR_RH 0x5200
695 #define T_OPCODE_LDR_RB 0x5c00
696 #define T_OPCODE_STR_RB 0x5400
698 #define T_OPCODE_PUSH 0xb400
699 #define T_OPCODE_POP 0xbc00
701 #define T_OPCODE_BRANCH 0xe000
703 #define THUMB_SIZE 2 /* Size of thumb instruction. */
704 #define THUMB_PP_PC_LR 0x0100
705 #define THUMB_LOAD_BIT 0x0800
706 #define THUMB2_LOAD_BIT 0x00100000
708 #define BAD_ARGS _("bad arguments to instruction")
709 #define BAD_SP _("r13 not allowed here")
710 #define BAD_PC _("r15 not allowed here")
711 #define BAD_COND _("instruction cannot be conditional")
712 #define BAD_OVERLAP _("registers may not be the same")
713 #define BAD_HIREG _("lo register required")
714 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
715 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
716 #define BAD_BRANCH _("branch must be last instruction in IT block")
717 #define BAD_NOT_IT _("instruction not allowed in IT block")
718 #define BAD_FPU _("selected FPU does not support instruction")
719 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
720 #define BAD_IT_COND _("incorrect condition in IT block")
721 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
722 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
723 #define BAD_PC_ADDRESSING \
724 _("cannot use register index with PC-relative addressing")
725 #define BAD_PC_WRITEBACK \
726 _("cannot use writeback with PC-relative addressing")
727 #define BAD_RANGE _("branch out of range")
729 static struct hash_control * arm_ops_hsh;
730 static struct hash_control * arm_cond_hsh;
731 static struct hash_control * arm_shift_hsh;
732 static struct hash_control * arm_psr_hsh;
733 static struct hash_control * arm_v7m_psr_hsh;
734 static struct hash_control * arm_reg_hsh;
735 static struct hash_control * arm_reloc_hsh;
736 static struct hash_control * arm_barrier_opt_hsh;
738 /* Stuff needed to resolve the label ambiguity
741 label: <insn>
742 may differ from:
744 label:
745 <insn> */
747 symbolS * last_label_seen;
748 static int label_is_thumb_function_name = FALSE;
750 /* Literal pool structure. Held on a per-section
751 and per-sub-section basis. */
753 #define MAX_LITERAL_POOL_SIZE 1024
754 typedef struct literal_pool
756 expressionS literals [MAX_LITERAL_POOL_SIZE];
757 unsigned int next_free_entry;
758 unsigned int id;
759 symbolS * symbol;
760 segT section;
761 subsegT sub_section;
762 struct literal_pool * next;
763 } literal_pool;
765 /* Pointer to a linked list of literal pools. */
766 literal_pool * list_of_pools = NULL;
768 #ifdef OBJ_ELF
769 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
770 #else
771 static struct current_it now_it;
772 #endif
774 static inline int
775 now_it_compatible (int cond)
777 return (cond & ~1) == (now_it.cc & ~1);
780 static inline int
781 conditional_insn (void)
783 return inst.cond != COND_ALWAYS;
786 static int in_it_block (void);
788 static int handle_it_state (void);
790 static void force_automatic_it_block_close (void);
792 static void it_fsm_post_encode (void);
794 #define set_it_insn_type(type) \
795 do \
797 inst.it_insn_type = type; \
798 if (handle_it_state () == FAIL) \
799 return; \
801 while (0)
803 #define set_it_insn_type_nonvoid(type, failret) \
804 do \
806 inst.it_insn_type = type; \
807 if (handle_it_state () == FAIL) \
808 return failret; \
810 while(0)
812 #define set_it_insn_type_last() \
813 do \
815 if (inst.cond == COND_ALWAYS) \
816 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
817 else \
818 set_it_insn_type (INSIDE_IT_LAST_INSN); \
820 while (0)
822 /* Pure syntax. */
824 /* This array holds the chars that always start a comment. If the
825 pre-processor is disabled, these aren't very useful. */
826 const char comment_chars[] = "@";
828 /* This array holds the chars that only start a comment at the beginning of
829 a line. If the line seems to have the form '# 123 filename'
830 .line and .file directives will appear in the pre-processed output. */
831 /* Note that input_file.c hand checks for '#' at the beginning of the
832 first line of the input file. This is because the compiler outputs
833 #NO_APP at the beginning of its output. */
834 /* Also note that comments like this one will always work. */
835 const char line_comment_chars[] = "#";
837 const char line_separator_chars[] = ";";
839 /* Chars that can be used to separate mant
840 from exp in floating point numbers. */
841 const char EXP_CHARS[] = "eE";
843 /* Chars that mean this number is a floating point constant. */
844 /* As in 0f12.456 */
845 /* or 0d1.2345e12 */
847 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
849 /* Prefix characters that indicate the start of an immediate
850 value. */
851 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
853 /* Separator character handling. */
855 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
857 static inline int
858 skip_past_char (char ** str, char c)
860 if (**str == c)
862 (*str)++;
863 return SUCCESS;
865 else
866 return FAIL;
869 #define skip_past_comma(str) skip_past_char (str, ',')
871 /* Arithmetic expressions (possibly involving symbols). */
873 /* Return TRUE if anything in the expression is a bignum. */
875 static int
876 walk_no_bignums (symbolS * sp)
878 if (symbol_get_value_expression (sp)->X_op == O_big)
879 return 1;
881 if (symbol_get_value_expression (sp)->X_add_symbol)
883 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
884 || (symbol_get_value_expression (sp)->X_op_symbol
885 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
888 return 0;
891 static int in_my_get_expression = 0;
893 /* Third argument to my_get_expression. */
894 #define GE_NO_PREFIX 0
895 #define GE_IMM_PREFIX 1
896 #define GE_OPT_PREFIX 2
897 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
898 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
899 #define GE_OPT_PREFIX_BIG 3
901 static int
902 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
904 char * save_in;
905 segT seg;
907 /* In unified syntax, all prefixes are optional. */
908 if (unified_syntax)
909 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
910 : GE_OPT_PREFIX;
912 switch (prefix_mode)
914 case GE_NO_PREFIX: break;
915 case GE_IMM_PREFIX:
916 if (!is_immediate_prefix (**str))
918 inst.error = _("immediate expression requires a # prefix");
919 return FAIL;
921 (*str)++;
922 break;
923 case GE_OPT_PREFIX:
924 case GE_OPT_PREFIX_BIG:
925 if (is_immediate_prefix (**str))
926 (*str)++;
927 break;
928 default: abort ();
931 memset (ep, 0, sizeof (expressionS));
933 save_in = input_line_pointer;
934 input_line_pointer = *str;
935 in_my_get_expression = 1;
936 seg = expression (ep);
937 in_my_get_expression = 0;
939 if (ep->X_op == O_illegal || ep->X_op == O_absent)
941 /* We found a bad or missing expression in md_operand(). */
942 *str = input_line_pointer;
943 input_line_pointer = save_in;
944 if (inst.error == NULL)
945 inst.error = (ep->X_op == O_absent
946 ? _("missing expression") :_("bad expression"));
947 return 1;
950 #ifdef OBJ_AOUT
951 if (seg != absolute_section
952 && seg != text_section
953 && seg != data_section
954 && seg != bss_section
955 && seg != undefined_section)
957 inst.error = _("bad segment");
958 *str = input_line_pointer;
959 input_line_pointer = save_in;
960 return 1;
962 #else
963 (void) seg;
964 #endif
966 /* Get rid of any bignums now, so that we don't generate an error for which
967 we can't establish a line number later on. Big numbers are never valid
968 in instructions, which is where this routine is always called. */
969 if (prefix_mode != GE_OPT_PREFIX_BIG
970 && (ep->X_op == O_big
971 || (ep->X_add_symbol
972 && (walk_no_bignums (ep->X_add_symbol)
973 || (ep->X_op_symbol
974 && walk_no_bignums (ep->X_op_symbol))))))
976 inst.error = _("invalid constant");
977 *str = input_line_pointer;
978 input_line_pointer = save_in;
979 return 1;
982 *str = input_line_pointer;
983 input_line_pointer = save_in;
984 return 0;
987 /* Turn a string in input_line_pointer into a floating point constant
988 of type TYPE, and store the appropriate bytes in *LITP. The number
989 of LITTLENUMS emitted is stored in *SIZEP. An error message is
990 returned, or NULL on OK.
992 Note that fp constants aren't represent in the normal way on the ARM.
993 In big endian mode, things are as expected. However, in little endian
994 mode fp constants are big-endian word-wise, and little-endian byte-wise
995 within the words. For example, (double) 1.1 in big endian mode is
996 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
997 the byte sequence 99 99 f1 3f 9a 99 99 99.
999 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1001 char *
1002 md_atof (int type, char * litP, int * sizeP)
1004 int prec;
1005 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1006 char *t;
1007 int i;
1009 switch (type)
1011 case 'f':
1012 case 'F':
1013 case 's':
1014 case 'S':
1015 prec = 2;
1016 break;
1018 case 'd':
1019 case 'D':
1020 case 'r':
1021 case 'R':
1022 prec = 4;
1023 break;
1025 case 'x':
1026 case 'X':
1027 prec = 5;
1028 break;
1030 case 'p':
1031 case 'P':
1032 prec = 5;
1033 break;
1035 default:
1036 *sizeP = 0;
1037 return _("Unrecognized or unsupported floating point constant");
1040 t = atof_ieee (input_line_pointer, type, words);
1041 if (t)
1042 input_line_pointer = t;
1043 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1045 if (target_big_endian)
1047 for (i = 0; i < prec; i++)
1049 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1050 litP += sizeof (LITTLENUM_TYPE);
1053 else
1055 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1056 for (i = prec - 1; i >= 0; i--)
1058 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1059 litP += sizeof (LITTLENUM_TYPE);
1061 else
1062 /* For a 4 byte float the order of elements in `words' is 1 0.
1063 For an 8 byte float the order is 1 0 3 2. */
1064 for (i = 0; i < prec; i += 2)
1066 md_number_to_chars (litP, (valueT) words[i + 1],
1067 sizeof (LITTLENUM_TYPE));
1068 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1069 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1070 litP += 2 * sizeof (LITTLENUM_TYPE);
1074 return NULL;
1077 /* We handle all bad expressions here, so that we can report the faulty
1078 instruction in the error message. */
1079 void
1080 md_operand (expressionS * exp)
1082 if (in_my_get_expression)
1083 exp->X_op = O_illegal;
1086 /* Immediate values. */
1088 /* Generic immediate-value read function for use in directives.
1089 Accepts anything that 'expression' can fold to a constant.
1090 *val receives the number. */
1091 #ifdef OBJ_ELF
1092 static int
1093 immediate_for_directive (int *val)
1095 expressionS exp;
1096 exp.X_op = O_illegal;
1098 if (is_immediate_prefix (*input_line_pointer))
1100 input_line_pointer++;
1101 expression (&exp);
1104 if (exp.X_op != O_constant)
1106 as_bad (_("expected #constant"));
1107 ignore_rest_of_line ();
1108 return FAIL;
1110 *val = exp.X_add_number;
1111 return SUCCESS;
1113 #endif
1115 /* Register parsing. */
1117 /* Generic register parser. CCP points to what should be the
1118 beginning of a register name. If it is indeed a valid register
1119 name, advance CCP over it and return the reg_entry structure;
1120 otherwise return NULL. Does not issue diagnostics. */
1122 static struct reg_entry *
1123 arm_reg_parse_multi (char **ccp)
1125 char *start = *ccp;
1126 char *p;
1127 struct reg_entry *reg;
1129 #ifdef REGISTER_PREFIX
1130 if (*start != REGISTER_PREFIX)
1131 return NULL;
1132 start++;
1133 #endif
1134 #ifdef OPTIONAL_REGISTER_PREFIX
1135 if (*start == OPTIONAL_REGISTER_PREFIX)
1136 start++;
1137 #endif
1139 p = start;
1140 if (!ISALPHA (*p) || !is_name_beginner (*p))
1141 return NULL;
1144 p++;
1145 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1147 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1149 if (!reg)
1150 return NULL;
1152 *ccp = p;
1153 return reg;
1156 static int
1157 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1158 enum arm_reg_type type)
1160 /* Alternative syntaxes are accepted for a few register classes. */
1161 switch (type)
1163 case REG_TYPE_MVF:
1164 case REG_TYPE_MVD:
1165 case REG_TYPE_MVFX:
1166 case REG_TYPE_MVDX:
1167 /* Generic coprocessor register names are allowed for these. */
1168 if (reg && reg->type == REG_TYPE_CN)
1169 return reg->number;
1170 break;
1172 case REG_TYPE_CP:
1173 /* For backward compatibility, a bare number is valid here. */
1175 unsigned long processor = strtoul (start, ccp, 10);
1176 if (*ccp != start && processor <= 15)
1177 return processor;
1180 case REG_TYPE_MMXWC:
1181 /* WC includes WCG. ??? I'm not sure this is true for all
1182 instructions that take WC registers. */
1183 if (reg && reg->type == REG_TYPE_MMXWCG)
1184 return reg->number;
1185 break;
1187 default:
1188 break;
1191 return FAIL;
1194 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1195 return value is the register number or FAIL. */
1197 static int
1198 arm_reg_parse (char **ccp, enum arm_reg_type type)
1200 char *start = *ccp;
1201 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1202 int ret;
1204 /* Do not allow a scalar (reg+index) to parse as a register. */
1205 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1206 return FAIL;
1208 if (reg && reg->type == type)
1209 return reg->number;
1211 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1212 return ret;
1214 *ccp = start;
1215 return FAIL;
1218 /* Parse a Neon type specifier. *STR should point at the leading '.'
1219 character. Does no verification at this stage that the type fits the opcode
1220 properly. E.g.,
1222 .i32.i32.s16
1223 .s32.f32
1224 .u16
1226 Can all be legally parsed by this function.
1228 Fills in neon_type struct pointer with parsed information, and updates STR
1229 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1230 type, FAIL if not. */
1232 static int
1233 parse_neon_type (struct neon_type *type, char **str)
1235 char *ptr = *str;
1237 if (type)
1238 type->elems = 0;
1240 while (type->elems < NEON_MAX_TYPE_ELS)
1242 enum neon_el_type thistype = NT_untyped;
1243 unsigned thissize = -1u;
1245 if (*ptr != '.')
1246 break;
1248 ptr++;
1250 /* Just a size without an explicit type. */
1251 if (ISDIGIT (*ptr))
1252 goto parsesize;
1254 switch (TOLOWER (*ptr))
1256 case 'i': thistype = NT_integer; break;
1257 case 'f': thistype = NT_float; break;
1258 case 'p': thistype = NT_poly; break;
1259 case 's': thistype = NT_signed; break;
1260 case 'u': thistype = NT_unsigned; break;
1261 case 'd':
1262 thistype = NT_float;
1263 thissize = 64;
1264 ptr++;
1265 goto done;
1266 default:
1267 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1268 return FAIL;
1271 ptr++;
1273 /* .f is an abbreviation for .f32. */
1274 if (thistype == NT_float && !ISDIGIT (*ptr))
1275 thissize = 32;
1276 else
1278 parsesize:
1279 thissize = strtoul (ptr, &ptr, 10);
1281 if (thissize != 8 && thissize != 16 && thissize != 32
1282 && thissize != 64)
1284 as_bad (_("bad size %d in type specifier"), thissize);
1285 return FAIL;
1289 done:
1290 if (type)
1292 type->el[type->elems].type = thistype;
1293 type->el[type->elems].size = thissize;
1294 type->elems++;
1298 /* Empty/missing type is not a successful parse. */
1299 if (type->elems == 0)
1300 return FAIL;
1302 *str = ptr;
1304 return SUCCESS;
1307 /* Errors may be set multiple times during parsing or bit encoding
1308 (particularly in the Neon bits), but usually the earliest error which is set
1309 will be the most meaningful. Avoid overwriting it with later (cascading)
1310 errors by calling this function. */
1312 static void
1313 first_error (const char *err)
1315 if (!inst.error)
1316 inst.error = err;
1319 /* Parse a single type, e.g. ".s32", leading period included. */
1320 static int
1321 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1323 char *str = *ccp;
1324 struct neon_type optype;
1326 if (*str == '.')
1328 if (parse_neon_type (&optype, &str) == SUCCESS)
1330 if (optype.elems == 1)
1331 *vectype = optype.el[0];
1332 else
1334 first_error (_("only one type should be specified for operand"));
1335 return FAIL;
1338 else
1340 first_error (_("vector type expected"));
1341 return FAIL;
1344 else
1345 return FAIL;
1347 *ccp = str;
1349 return SUCCESS;
1352 /* Special meanings for indices (which have a range of 0-7), which will fit into
1353 a 4-bit integer. */
1355 #define NEON_ALL_LANES 15
1356 #define NEON_INTERLEAVE_LANES 14
1358 /* Parse either a register or a scalar, with an optional type. Return the
1359 register number, and optionally fill in the actual type of the register
1360 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1361 type/index information in *TYPEINFO. */
1363 static int
1364 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1365 enum arm_reg_type *rtype,
1366 struct neon_typed_alias *typeinfo)
1368 char *str = *ccp;
1369 struct reg_entry *reg = arm_reg_parse_multi (&str);
1370 struct neon_typed_alias atype;
1371 struct neon_type_el parsetype;
1373 atype.defined = 0;
1374 atype.index = -1;
1375 atype.eltype.type = NT_invtype;
1376 atype.eltype.size = -1;
1378 /* Try alternate syntax for some types of register. Note these are mutually
1379 exclusive with the Neon syntax extensions. */
1380 if (reg == NULL)
1382 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1383 if (altreg != FAIL)
1384 *ccp = str;
1385 if (typeinfo)
1386 *typeinfo = atype;
1387 return altreg;
1390 /* Undo polymorphism when a set of register types may be accepted. */
1391 if ((type == REG_TYPE_NDQ
1392 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1393 || (type == REG_TYPE_VFSD
1394 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1395 || (type == REG_TYPE_NSDQ
1396 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1397 || reg->type == REG_TYPE_NQ))
1398 || (type == REG_TYPE_MMXWC
1399 && (reg->type == REG_TYPE_MMXWCG)))
1400 type = (enum arm_reg_type) reg->type;
1402 if (type != reg->type)
1403 return FAIL;
1405 if (reg->neon)
1406 atype = *reg->neon;
1408 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1410 if ((atype.defined & NTA_HASTYPE) != 0)
1412 first_error (_("can't redefine type for operand"));
1413 return FAIL;
1415 atype.defined |= NTA_HASTYPE;
1416 atype.eltype = parsetype;
1419 if (skip_past_char (&str, '[') == SUCCESS)
1421 if (type != REG_TYPE_VFD)
1423 first_error (_("only D registers may be indexed"));
1424 return FAIL;
1427 if ((atype.defined & NTA_HASINDEX) != 0)
1429 first_error (_("can't change index for operand"));
1430 return FAIL;
1433 atype.defined |= NTA_HASINDEX;
1435 if (skip_past_char (&str, ']') == SUCCESS)
1436 atype.index = NEON_ALL_LANES;
1437 else
1439 expressionS exp;
1441 my_get_expression (&exp, &str, GE_NO_PREFIX);
1443 if (exp.X_op != O_constant)
1445 first_error (_("constant expression required"));
1446 return FAIL;
1449 if (skip_past_char (&str, ']') == FAIL)
1450 return FAIL;
1452 atype.index = exp.X_add_number;
1456 if (typeinfo)
1457 *typeinfo = atype;
1459 if (rtype)
1460 *rtype = type;
1462 *ccp = str;
1464 return reg->number;
1467 /* Like arm_reg_parse, but allow allow the following extra features:
1468 - If RTYPE is non-zero, return the (possibly restricted) type of the
1469 register (e.g. Neon double or quad reg when either has been requested).
1470 - If this is a Neon vector type with additional type information, fill
1471 in the struct pointed to by VECTYPE (if non-NULL).
1472 This function will fault on encountering a scalar. */
1474 static int
1475 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1476 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1478 struct neon_typed_alias atype;
1479 char *str = *ccp;
1480 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1482 if (reg == FAIL)
1483 return FAIL;
1485 /* Do not allow regname(... to parse as a register. */
1486 if (*str == '(')
1487 return FAIL;
1489 /* Do not allow a scalar (reg+index) to parse as a register. */
1490 if ((atype.defined & NTA_HASINDEX) != 0)
1492 first_error (_("register operand expected, but got scalar"));
1493 return FAIL;
1496 if (vectype)
1497 *vectype = atype.eltype;
1499 *ccp = str;
1501 return reg;
1504 #define NEON_SCALAR_REG(X) ((X) >> 4)
1505 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1507 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1508 have enough information to be able to do a good job bounds-checking. So, we
1509 just do easy checks here, and do further checks later. */
1511 static int
1512 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1514 int reg;
1515 char *str = *ccp;
1516 struct neon_typed_alias atype;
1518 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1520 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1521 return FAIL;
1523 if (atype.index == NEON_ALL_LANES)
1525 first_error (_("scalar must have an index"));
1526 return FAIL;
1528 else if (atype.index >= 64 / elsize)
1530 first_error (_("scalar index out of range"));
1531 return FAIL;
1534 if (type)
1535 *type = atype.eltype;
1537 *ccp = str;
1539 return reg * 16 + atype.index;
1542 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1544 static long
1545 parse_reg_list (char ** strp)
1547 char * str = * strp;
1548 long range = 0;
1549 int another_range;
1551 /* We come back here if we get ranges concatenated by '+' or '|'. */
1554 another_range = 0;
1556 if (*str == '{')
1558 int in_range = 0;
1559 int cur_reg = -1;
1561 str++;
1564 int reg;
1566 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1568 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1569 return FAIL;
1572 if (in_range)
1574 int i;
1576 if (reg <= cur_reg)
1578 first_error (_("bad range in register list"));
1579 return FAIL;
1582 for (i = cur_reg + 1; i < reg; i++)
1584 if (range & (1 << i))
1585 as_tsktsk
1586 (_("Warning: duplicated register (r%d) in register list"),
1588 else
1589 range |= 1 << i;
1591 in_range = 0;
1594 if (range & (1 << reg))
1595 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1596 reg);
1597 else if (reg <= cur_reg)
1598 as_tsktsk (_("Warning: register range not in ascending order"));
1600 range |= 1 << reg;
1601 cur_reg = reg;
1603 while (skip_past_comma (&str) != FAIL
1604 || (in_range = 1, *str++ == '-'));
1605 str--;
1607 if (*str++ != '}')
1609 first_error (_("missing `}'"));
1610 return FAIL;
1613 else
1615 expressionS exp;
1617 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1618 return FAIL;
1620 if (exp.X_op == O_constant)
1622 if (exp.X_add_number
1623 != (exp.X_add_number & 0x0000ffff))
1625 inst.error = _("invalid register mask");
1626 return FAIL;
1629 if ((range & exp.X_add_number) != 0)
1631 int regno = range & exp.X_add_number;
1633 regno &= -regno;
1634 regno = (1 << regno) - 1;
1635 as_tsktsk
1636 (_("Warning: duplicated register (r%d) in register list"),
1637 regno);
1640 range |= exp.X_add_number;
1642 else
1644 if (inst.reloc.type != 0)
1646 inst.error = _("expression too complex");
1647 return FAIL;
1650 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1651 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1652 inst.reloc.pc_rel = 0;
1656 if (*str == '|' || *str == '+')
1658 str++;
1659 another_range = 1;
1662 while (another_range);
1664 *strp = str;
1665 return range;
1668 /* Types of registers in a list. */
1670 enum reg_list_els
1672 REGLIST_VFP_S,
1673 REGLIST_VFP_D,
1674 REGLIST_NEON_D
1677 /* Parse a VFP register list. If the string is invalid return FAIL.
1678 Otherwise return the number of registers, and set PBASE to the first
1679 register. Parses registers of type ETYPE.
1680 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1681 - Q registers can be used to specify pairs of D registers
1682 - { } can be omitted from around a singleton register list
1683 FIXME: This is not implemented, as it would require backtracking in
1684 some cases, e.g.:
1685 vtbl.8 d3,d4,d5
1686 This could be done (the meaning isn't really ambiguous), but doesn't
1687 fit in well with the current parsing framework.
1688 - 32 D registers may be used (also true for VFPv3).
1689 FIXME: Types are ignored in these register lists, which is probably a
1690 bug. */
1692 static int
1693 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1695 char *str = *ccp;
1696 int base_reg;
1697 int new_base;
1698 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1699 int max_regs = 0;
1700 int count = 0;
1701 int warned = 0;
1702 unsigned long mask = 0;
1703 int i;
1705 if (*str != '{')
1707 inst.error = _("expecting {");
1708 return FAIL;
1711 str++;
1713 switch (etype)
1715 case REGLIST_VFP_S:
1716 regtype = REG_TYPE_VFS;
1717 max_regs = 32;
1718 break;
1720 case REGLIST_VFP_D:
1721 regtype = REG_TYPE_VFD;
1722 break;
1724 case REGLIST_NEON_D:
1725 regtype = REG_TYPE_NDQ;
1726 break;
1729 if (etype != REGLIST_VFP_S)
1731 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1732 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1734 max_regs = 32;
1735 if (thumb_mode)
1736 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1737 fpu_vfp_ext_d32);
1738 else
1739 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1740 fpu_vfp_ext_d32);
1742 else
1743 max_regs = 16;
1746 base_reg = max_regs;
1750 int setmask = 1, addregs = 1;
1752 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1754 if (new_base == FAIL)
1756 first_error (_(reg_expected_msgs[regtype]));
1757 return FAIL;
1760 if (new_base >= max_regs)
1762 first_error (_("register out of range in list"));
1763 return FAIL;
1766 /* Note: a value of 2 * n is returned for the register Q<n>. */
1767 if (regtype == REG_TYPE_NQ)
1769 setmask = 3;
1770 addregs = 2;
1773 if (new_base < base_reg)
1774 base_reg = new_base;
1776 if (mask & (setmask << new_base))
1778 first_error (_("invalid register list"));
1779 return FAIL;
1782 if ((mask >> new_base) != 0 && ! warned)
1784 as_tsktsk (_("register list not in ascending order"));
1785 warned = 1;
1788 mask |= setmask << new_base;
1789 count += addregs;
1791 if (*str == '-') /* We have the start of a range expression */
1793 int high_range;
1795 str++;
1797 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1798 == FAIL)
1800 inst.error = gettext (reg_expected_msgs[regtype]);
1801 return FAIL;
1804 if (high_range >= max_regs)
1806 first_error (_("register out of range in list"));
1807 return FAIL;
1810 if (regtype == REG_TYPE_NQ)
1811 high_range = high_range + 1;
1813 if (high_range <= new_base)
1815 inst.error = _("register range not in ascending order");
1816 return FAIL;
1819 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1821 if (mask & (setmask << new_base))
1823 inst.error = _("invalid register list");
1824 return FAIL;
1827 mask |= setmask << new_base;
1828 count += addregs;
1832 while (skip_past_comma (&str) != FAIL);
1834 str++;
1836 /* Sanity check -- should have raised a parse error above. */
1837 if (count == 0 || count > max_regs)
1838 abort ();
1840 *pbase = base_reg;
1842 /* Final test -- the registers must be consecutive. */
1843 mask >>= base_reg;
1844 for (i = 0; i < count; i++)
1846 if ((mask & (1u << i)) == 0)
1848 inst.error = _("non-contiguous register range");
1849 return FAIL;
1853 *ccp = str;
1855 return count;
1858 /* True if two alias types are the same. */
1860 static bfd_boolean
1861 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1863 if (!a && !b)
1864 return TRUE;
1866 if (!a || !b)
1867 return FALSE;
1869 if (a->defined != b->defined)
1870 return FALSE;
1872 if ((a->defined & NTA_HASTYPE) != 0
1873 && (a->eltype.type != b->eltype.type
1874 || a->eltype.size != b->eltype.size))
1875 return FALSE;
1877 if ((a->defined & NTA_HASINDEX) != 0
1878 && (a->index != b->index))
1879 return FALSE;
1881 return TRUE;
1884 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1885 The base register is put in *PBASE.
1886 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1887 the return value.
1888 The register stride (minus one) is put in bit 4 of the return value.
1889 Bits [6:5] encode the list length (minus one).
1890 The type of the list elements is put in *ELTYPE, if non-NULL. */
1892 #define NEON_LANE(X) ((X) & 0xf)
1893 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1894 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1896 static int
1897 parse_neon_el_struct_list (char **str, unsigned *pbase,
1898 struct neon_type_el *eltype)
1900 char *ptr = *str;
1901 int base_reg = -1;
1902 int reg_incr = -1;
1903 int count = 0;
1904 int lane = -1;
1905 int leading_brace = 0;
1906 enum arm_reg_type rtype = REG_TYPE_NDQ;
1907 const char *const incr_error = _("register stride must be 1 or 2");
1908 const char *const type_error = _("mismatched element/structure types in list");
1909 struct neon_typed_alias firsttype;
1911 if (skip_past_char (&ptr, '{') == SUCCESS)
1912 leading_brace = 1;
1916 struct neon_typed_alias atype;
1917 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1919 if (getreg == FAIL)
1921 first_error (_(reg_expected_msgs[rtype]));
1922 return FAIL;
1925 if (base_reg == -1)
1927 base_reg = getreg;
1928 if (rtype == REG_TYPE_NQ)
1930 reg_incr = 1;
1932 firsttype = atype;
1934 else if (reg_incr == -1)
1936 reg_incr = getreg - base_reg;
1937 if (reg_incr < 1 || reg_incr > 2)
1939 first_error (_(incr_error));
1940 return FAIL;
1943 else if (getreg != base_reg + reg_incr * count)
1945 first_error (_(incr_error));
1946 return FAIL;
1949 if (! neon_alias_types_same (&atype, &firsttype))
1951 first_error (_(type_error));
1952 return FAIL;
1955 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1956 modes. */
1957 if (ptr[0] == '-')
1959 struct neon_typed_alias htype;
1960 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1961 if (lane == -1)
1962 lane = NEON_INTERLEAVE_LANES;
1963 else if (lane != NEON_INTERLEAVE_LANES)
1965 first_error (_(type_error));
1966 return FAIL;
1968 if (reg_incr == -1)
1969 reg_incr = 1;
1970 else if (reg_incr != 1)
1972 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1973 return FAIL;
1975 ptr++;
1976 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1977 if (hireg == FAIL)
1979 first_error (_(reg_expected_msgs[rtype]));
1980 return FAIL;
1982 if (! neon_alias_types_same (&htype, &firsttype))
1984 first_error (_(type_error));
1985 return FAIL;
1987 count += hireg + dregs - getreg;
1988 continue;
1991 /* If we're using Q registers, we can't use [] or [n] syntax. */
1992 if (rtype == REG_TYPE_NQ)
1994 count += 2;
1995 continue;
1998 if ((atype.defined & NTA_HASINDEX) != 0)
2000 if (lane == -1)
2001 lane = atype.index;
2002 else if (lane != atype.index)
2004 first_error (_(type_error));
2005 return FAIL;
2008 else if (lane == -1)
2009 lane = NEON_INTERLEAVE_LANES;
2010 else if (lane != NEON_INTERLEAVE_LANES)
2012 first_error (_(type_error));
2013 return FAIL;
2015 count++;
2017 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2019 /* No lane set by [x]. We must be interleaving structures. */
2020 if (lane == -1)
2021 lane = NEON_INTERLEAVE_LANES;
2023 /* Sanity check. */
2024 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2025 || (count > 1 && reg_incr == -1))
2027 first_error (_("error parsing element/structure list"));
2028 return FAIL;
2031 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2033 first_error (_("expected }"));
2034 return FAIL;
2037 if (reg_incr == -1)
2038 reg_incr = 1;
2040 if (eltype)
2041 *eltype = firsttype.eltype;
2043 *pbase = base_reg;
2044 *str = ptr;
2046 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2049 /* Parse an explicit relocation suffix on an expression. This is
2050 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2051 arm_reloc_hsh contains no entries, so this function can only
2052 succeed if there is no () after the word. Returns -1 on error,
2053 BFD_RELOC_UNUSED if there wasn't any suffix. */
2054 static int
2055 parse_reloc (char **str)
2057 struct reloc_entry *r;
2058 char *p, *q;
2060 if (**str != '(')
2061 return BFD_RELOC_UNUSED;
2063 p = *str + 1;
2064 q = p;
2066 while (*q && *q != ')' && *q != ',')
2067 q++;
2068 if (*q != ')')
2069 return -1;
2071 if ((r = (struct reloc_entry *)
2072 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2073 return -1;
2075 *str = q + 1;
2076 return r->reloc;
2079 /* Directives: register aliases. */
2081 static struct reg_entry *
2082 insert_reg_alias (char *str, unsigned number, int type)
2084 struct reg_entry *new_reg;
2085 const char *name;
2087 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2089 if (new_reg->builtin)
2090 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2092 /* Only warn about a redefinition if it's not defined as the
2093 same register. */
2094 else if (new_reg->number != number || new_reg->type != type)
2095 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2097 return NULL;
2100 name = xstrdup (str);
2101 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2103 new_reg->name = name;
2104 new_reg->number = number;
2105 new_reg->type = type;
2106 new_reg->builtin = FALSE;
2107 new_reg->neon = NULL;
2109 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2110 abort ();
2112 return new_reg;
2115 static void
2116 insert_neon_reg_alias (char *str, int number, int type,
2117 struct neon_typed_alias *atype)
2119 struct reg_entry *reg = insert_reg_alias (str, number, type);
2121 if (!reg)
2123 first_error (_("attempt to redefine typed alias"));
2124 return;
2127 if (atype)
2129 reg->neon = (struct neon_typed_alias *)
2130 xmalloc (sizeof (struct neon_typed_alias));
2131 *reg->neon = *atype;
2135 /* Look for the .req directive. This is of the form:
2137 new_register_name .req existing_register_name
2139 If we find one, or if it looks sufficiently like one that we want to
2140 handle any error here, return TRUE. Otherwise return FALSE. */
2142 static bfd_boolean
2143 create_register_alias (char * newname, char *p)
2145 struct reg_entry *old;
2146 char *oldname, *nbuf;
2147 size_t nlen;
2149 /* The input scrubber ensures that whitespace after the mnemonic is
2150 collapsed to single spaces. */
2151 oldname = p;
2152 if (strncmp (oldname, " .req ", 6) != 0)
2153 return FALSE;
2155 oldname += 6;
2156 if (*oldname == '\0')
2157 return FALSE;
2159 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2160 if (!old)
2162 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2163 return TRUE;
2166 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2167 the desired alias name, and p points to its end. If not, then
2168 the desired alias name is in the global original_case_string. */
2169 #ifdef TC_CASE_SENSITIVE
2170 nlen = p - newname;
2171 #else
2172 newname = original_case_string;
2173 nlen = strlen (newname);
2174 #endif
2176 nbuf = (char *) alloca (nlen + 1);
2177 memcpy (nbuf, newname, nlen);
2178 nbuf[nlen] = '\0';
2180 /* Create aliases under the new name as stated; an all-lowercase
2181 version of the new name; and an all-uppercase version of the new
2182 name. */
2183 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2185 for (p = nbuf; *p; p++)
2186 *p = TOUPPER (*p);
2188 if (strncmp (nbuf, newname, nlen))
2190 /* If this attempt to create an additional alias fails, do not bother
2191 trying to create the all-lower case alias. We will fail and issue
2192 a second, duplicate error message. This situation arises when the
2193 programmer does something like:
2194 foo .req r0
2195 Foo .req r1
2196 The second .req creates the "Foo" alias but then fails to create
2197 the artificial FOO alias because it has already been created by the
2198 first .req. */
2199 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2200 return TRUE;
2203 for (p = nbuf; *p; p++)
2204 *p = TOLOWER (*p);
2206 if (strncmp (nbuf, newname, nlen))
2207 insert_reg_alias (nbuf, old->number, old->type);
2210 return TRUE;
2213 /* Create a Neon typed/indexed register alias using directives, e.g.:
2214 X .dn d5.s32[1]
2215 Y .qn 6.s16
2216 Z .dn d7
2217 T .dn Z[0]
2218 These typed registers can be used instead of the types specified after the
2219 Neon mnemonic, so long as all operands given have types. Types can also be
2220 specified directly, e.g.:
2221 vadd d0.s32, d1.s32, d2.s32 */
2223 static bfd_boolean
2224 create_neon_reg_alias (char *newname, char *p)
2226 enum arm_reg_type basetype;
2227 struct reg_entry *basereg;
2228 struct reg_entry mybasereg;
2229 struct neon_type ntype;
2230 struct neon_typed_alias typeinfo;
2231 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2232 int namelen;
2234 typeinfo.defined = 0;
2235 typeinfo.eltype.type = NT_invtype;
2236 typeinfo.eltype.size = -1;
2237 typeinfo.index = -1;
2239 nameend = p;
2241 if (strncmp (p, " .dn ", 5) == 0)
2242 basetype = REG_TYPE_VFD;
2243 else if (strncmp (p, " .qn ", 5) == 0)
2244 basetype = REG_TYPE_NQ;
2245 else
2246 return FALSE;
2248 p += 5;
2250 if (*p == '\0')
2251 return FALSE;
2253 basereg = arm_reg_parse_multi (&p);
2255 if (basereg && basereg->type != basetype)
2257 as_bad (_("bad type for register"));
2258 return FALSE;
2261 if (basereg == NULL)
2263 expressionS exp;
2264 /* Try parsing as an integer. */
2265 my_get_expression (&exp, &p, GE_NO_PREFIX);
2266 if (exp.X_op != O_constant)
2268 as_bad (_("expression must be constant"));
2269 return FALSE;
2271 basereg = &mybasereg;
2272 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2273 : exp.X_add_number;
2274 basereg->neon = 0;
2277 if (basereg->neon)
2278 typeinfo = *basereg->neon;
2280 if (parse_neon_type (&ntype, &p) == SUCCESS)
2282 /* We got a type. */
2283 if (typeinfo.defined & NTA_HASTYPE)
2285 as_bad (_("can't redefine the type of a register alias"));
2286 return FALSE;
2289 typeinfo.defined |= NTA_HASTYPE;
2290 if (ntype.elems != 1)
2292 as_bad (_("you must specify a single type only"));
2293 return FALSE;
2295 typeinfo.eltype = ntype.el[0];
2298 if (skip_past_char (&p, '[') == SUCCESS)
2300 expressionS exp;
2301 /* We got a scalar index. */
2303 if (typeinfo.defined & NTA_HASINDEX)
2305 as_bad (_("can't redefine the index of a scalar alias"));
2306 return FALSE;
2309 my_get_expression (&exp, &p, GE_NO_PREFIX);
2311 if (exp.X_op != O_constant)
2313 as_bad (_("scalar index must be constant"));
2314 return FALSE;
2317 typeinfo.defined |= NTA_HASINDEX;
2318 typeinfo.index = exp.X_add_number;
2320 if (skip_past_char (&p, ']') == FAIL)
2322 as_bad (_("expecting ]"));
2323 return FALSE;
2327 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2328 the desired alias name, and p points to its end. If not, then
2329 the desired alias name is in the global original_case_string. */
2330 #ifdef TC_CASE_SENSITIVE
2331 namelen = nameend - newname;
2332 #else
2333 newname = original_case_string;
2334 namelen = strlen (newname);
2335 #endif
2337 namebuf = (char *) alloca (namelen + 1);
2338 strncpy (namebuf, newname, namelen);
2339 namebuf[namelen] = '\0';
2341 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2342 typeinfo.defined != 0 ? &typeinfo : NULL);
2344 /* Insert name in all uppercase. */
2345 for (p = namebuf; *p; p++)
2346 *p = TOUPPER (*p);
2348 if (strncmp (namebuf, newname, namelen))
2349 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2350 typeinfo.defined != 0 ? &typeinfo : NULL);
2352 /* Insert name in all lowercase. */
2353 for (p = namebuf; *p; p++)
2354 *p = TOLOWER (*p);
2356 if (strncmp (namebuf, newname, namelen))
2357 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2358 typeinfo.defined != 0 ? &typeinfo : NULL);
2360 return TRUE;
2363 /* Should never be called, as .req goes between the alias and the
2364 register name, not at the beginning of the line. */
2366 static void
2367 s_req (int a ATTRIBUTE_UNUSED)
2369 as_bad (_("invalid syntax for .req directive"));
2372 static void
2373 s_dn (int a ATTRIBUTE_UNUSED)
2375 as_bad (_("invalid syntax for .dn directive"));
2378 static void
2379 s_qn (int a ATTRIBUTE_UNUSED)
2381 as_bad (_("invalid syntax for .qn directive"));
2384 /* The .unreq directive deletes an alias which was previously defined
2385 by .req. For example:
2387 my_alias .req r11
2388 .unreq my_alias */
2390 static void
2391 s_unreq (int a ATTRIBUTE_UNUSED)
2393 char * name;
2394 char saved_char;
2396 name = input_line_pointer;
2398 while (*input_line_pointer != 0
2399 && *input_line_pointer != ' '
2400 && *input_line_pointer != '\n')
2401 ++input_line_pointer;
2403 saved_char = *input_line_pointer;
2404 *input_line_pointer = 0;
2406 if (!*name)
2407 as_bad (_("invalid syntax for .unreq directive"));
2408 else
2410 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2411 name);
2413 if (!reg)
2414 as_bad (_("unknown register alias '%s'"), name);
2415 else if (reg->builtin)
2416 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2417 name);
2418 else
2420 char * p;
2421 char * nbuf;
2423 hash_delete (arm_reg_hsh, name, FALSE);
2424 free ((char *) reg->name);
2425 if (reg->neon)
2426 free (reg->neon);
2427 free (reg);
2429 /* Also locate the all upper case and all lower case versions.
2430 Do not complain if we cannot find one or the other as it
2431 was probably deleted above. */
2433 nbuf = strdup (name);
2434 for (p = nbuf; *p; p++)
2435 *p = TOUPPER (*p);
2436 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2437 if (reg)
2439 hash_delete (arm_reg_hsh, nbuf, FALSE);
2440 free ((char *) reg->name);
2441 if (reg->neon)
2442 free (reg->neon);
2443 free (reg);
2446 for (p = nbuf; *p; p++)
2447 *p = TOLOWER (*p);
2448 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2449 if (reg)
2451 hash_delete (arm_reg_hsh, nbuf, FALSE);
2452 free ((char *) reg->name);
2453 if (reg->neon)
2454 free (reg->neon);
2455 free (reg);
2458 free (nbuf);
2462 *input_line_pointer = saved_char;
2463 demand_empty_rest_of_line ();
2466 /* Directives: Instruction set selection. */
2468 #ifdef OBJ_ELF
2469 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2470 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2471 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2472 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2474 /* Create a new mapping symbol for the transition to STATE. */
2476 static void
2477 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2479 symbolS * symbolP;
2480 const char * symname;
2481 int type;
2483 switch (state)
2485 case MAP_DATA:
2486 symname = "$d";
2487 type = BSF_NO_FLAGS;
2488 break;
2489 case MAP_ARM:
2490 symname = "$a";
2491 type = BSF_NO_FLAGS;
2492 break;
2493 case MAP_THUMB:
2494 symname = "$t";
2495 type = BSF_NO_FLAGS;
2496 break;
2497 default:
2498 abort ();
2501 symbolP = symbol_new (symname, now_seg, value, frag);
2502 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2504 switch (state)
2506 case MAP_ARM:
2507 THUMB_SET_FUNC (symbolP, 0);
2508 ARM_SET_THUMB (symbolP, 0);
2509 ARM_SET_INTERWORK (symbolP, support_interwork);
2510 break;
2512 case MAP_THUMB:
2513 THUMB_SET_FUNC (symbolP, 1);
2514 ARM_SET_THUMB (symbolP, 1);
2515 ARM_SET_INTERWORK (symbolP, support_interwork);
2516 break;
2518 case MAP_DATA:
2519 default:
2520 break;
2523 /* Save the mapping symbols for future reference. Also check that
2524 we do not place two mapping symbols at the same offset within a
2525 frag. We'll handle overlap between frags in
2526 check_mapping_symbols.
2528 If .fill or other data filling directive generates zero sized data,
2529 the mapping symbol for the following code will have the same value
2530 as the one generated for the data filling directive. In this case,
2531 we replace the old symbol with the new one at the same address. */
2532 if (value == 0)
2534 if (frag->tc_frag_data.first_map != NULL)
2536 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2537 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2539 frag->tc_frag_data.first_map = symbolP;
2541 if (frag->tc_frag_data.last_map != NULL)
2543 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2544 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2545 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2547 frag->tc_frag_data.last_map = symbolP;
2550 /* We must sometimes convert a region marked as code to data during
2551 code alignment, if an odd number of bytes have to be padded. The
2552 code mapping symbol is pushed to an aligned address. */
2554 static void
2555 insert_data_mapping_symbol (enum mstate state,
2556 valueT value, fragS *frag, offsetT bytes)
2558 /* If there was already a mapping symbol, remove it. */
2559 if (frag->tc_frag_data.last_map != NULL
2560 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2562 symbolS *symp = frag->tc_frag_data.last_map;
2564 if (value == 0)
2566 know (frag->tc_frag_data.first_map == symp);
2567 frag->tc_frag_data.first_map = NULL;
2569 frag->tc_frag_data.last_map = NULL;
2570 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2573 make_mapping_symbol (MAP_DATA, value, frag);
2574 make_mapping_symbol (state, value + bytes, frag);
2577 static void mapping_state_2 (enum mstate state, int max_chars);
2579 /* Set the mapping state to STATE. Only call this when about to
2580 emit some STATE bytes to the file. */
2582 void
2583 mapping_state (enum mstate state)
2585 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2587 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2589 if (mapstate == state)
2590 /* The mapping symbol has already been emitted.
2591 There is nothing else to do. */
2592 return;
2594 if (state == MAP_ARM || state == MAP_THUMB)
2595 /* PR gas/12931
2596 All ARM instructions require 4-byte alignment.
2597 (Almost) all Thumb instructions require 2-byte alignment.
2599 When emitting instructions into any section, mark the section
2600 appropriately.
2602 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2603 but themselves require 2-byte alignment; this applies to some
2604 PC- relative forms. However, these cases will invovle implicit
2605 literal pool generation or an explicit .align >=2, both of
2606 which will cause the section to me marked with sufficient
2607 alignment. Thus, we don't handle those cases here. */
2608 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2610 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2611 /* This case will be evaluated later in the next else. */
2612 return;
2613 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2614 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2616 /* Only add the symbol if the offset is > 0:
2617 if we're at the first frag, check it's size > 0;
2618 if we're not at the first frag, then for sure
2619 the offset is > 0. */
2620 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2621 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2623 if (add_symbol)
2624 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2627 mapping_state_2 (state, 0);
2628 #undef TRANSITION
2631 /* Same as mapping_state, but MAX_CHARS bytes have already been
2632 allocated. Put the mapping symbol that far back. */
2634 static void
2635 mapping_state_2 (enum mstate state, int max_chars)
2637 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2639 if (!SEG_NORMAL (now_seg))
2640 return;
2642 if (mapstate == state)
2643 /* The mapping symbol has already been emitted.
2644 There is nothing else to do. */
2645 return;
2647 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2648 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2650 #else
2651 #define mapping_state(x) ((void)0)
2652 #define mapping_state_2(x, y) ((void)0)
2653 #endif
2655 /* Find the real, Thumb encoded start of a Thumb function. */
2657 #ifdef OBJ_COFF
2658 static symbolS *
2659 find_real_start (symbolS * symbolP)
2661 char * real_start;
2662 const char * name = S_GET_NAME (symbolP);
2663 symbolS * new_target;
2665 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2666 #define STUB_NAME ".real_start_of"
2668 if (name == NULL)
2669 abort ();
2671 /* The compiler may generate BL instructions to local labels because
2672 it needs to perform a branch to a far away location. These labels
2673 do not have a corresponding ".real_start_of" label. We check
2674 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2675 the ".real_start_of" convention for nonlocal branches. */
2676 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2677 return symbolP;
2679 real_start = ACONCAT ((STUB_NAME, name, NULL));
2680 new_target = symbol_find (real_start);
2682 if (new_target == NULL)
2684 as_warn (_("Failed to find real start of function: %s\n"), name);
2685 new_target = symbolP;
2688 return new_target;
2690 #endif
2692 static void
2693 opcode_select (int width)
2695 switch (width)
2697 case 16:
2698 if (! thumb_mode)
2700 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2701 as_bad (_("selected processor does not support THUMB opcodes"));
2703 thumb_mode = 1;
2704 /* No need to force the alignment, since we will have been
2705 coming from ARM mode, which is word-aligned. */
2706 record_alignment (now_seg, 1);
2708 break;
2710 case 32:
2711 if (thumb_mode)
2713 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2714 as_bad (_("selected processor does not support ARM opcodes"));
2716 thumb_mode = 0;
2718 if (!need_pass_2)
2719 frag_align (2, 0, 0);
2721 record_alignment (now_seg, 1);
2723 break;
2725 default:
2726 as_bad (_("invalid instruction size selected (%d)"), width);
2730 static void
2731 s_arm (int ignore ATTRIBUTE_UNUSED)
2733 opcode_select (32);
2734 demand_empty_rest_of_line ();
2737 static void
2738 s_thumb (int ignore ATTRIBUTE_UNUSED)
2740 opcode_select (16);
2741 demand_empty_rest_of_line ();
2744 static void
2745 s_code (int unused ATTRIBUTE_UNUSED)
2747 int temp;
2749 temp = get_absolute_expression ();
2750 switch (temp)
2752 case 16:
2753 case 32:
2754 opcode_select (temp);
2755 break;
2757 default:
2758 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2762 static void
2763 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2765 /* If we are not already in thumb mode go into it, EVEN if
2766 the target processor does not support thumb instructions.
2767 This is used by gcc/config/arm/lib1funcs.asm for example
2768 to compile interworking support functions even if the
2769 target processor should not support interworking. */
2770 if (! thumb_mode)
2772 thumb_mode = 2;
2773 record_alignment (now_seg, 1);
2776 demand_empty_rest_of_line ();
2779 static void
2780 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2782 s_thumb (0);
2784 /* The following label is the name/address of the start of a Thumb function.
2785 We need to know this for the interworking support. */
2786 label_is_thumb_function_name = TRUE;
2789 /* Perform a .set directive, but also mark the alias as
2790 being a thumb function. */
2792 static void
2793 s_thumb_set (int equiv)
2795 /* XXX the following is a duplicate of the code for s_set() in read.c
2796 We cannot just call that code as we need to get at the symbol that
2797 is created. */
2798 char * name;
2799 char delim;
2800 char * end_name;
2801 symbolS * symbolP;
2803 /* Especial apologies for the random logic:
2804 This just grew, and could be parsed much more simply!
2805 Dean - in haste. */
2806 name = input_line_pointer;
2807 delim = get_symbol_end ();
2808 end_name = input_line_pointer;
2809 *end_name = delim;
2811 if (*input_line_pointer != ',')
2813 *end_name = 0;
2814 as_bad (_("expected comma after name \"%s\""), name);
2815 *end_name = delim;
2816 ignore_rest_of_line ();
2817 return;
2820 input_line_pointer++;
2821 *end_name = 0;
2823 if (name[0] == '.' && name[1] == '\0')
2825 /* XXX - this should not happen to .thumb_set. */
2826 abort ();
2829 if ((symbolP = symbol_find (name)) == NULL
2830 && (symbolP = md_undefined_symbol (name)) == NULL)
2832 #ifndef NO_LISTING
2833 /* When doing symbol listings, play games with dummy fragments living
2834 outside the normal fragment chain to record the file and line info
2835 for this symbol. */
2836 if (listing & LISTING_SYMBOLS)
2838 extern struct list_info_struct * listing_tail;
2839 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2841 memset (dummy_frag, 0, sizeof (fragS));
2842 dummy_frag->fr_type = rs_fill;
2843 dummy_frag->line = listing_tail;
2844 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2845 dummy_frag->fr_symbol = symbolP;
2847 else
2848 #endif
2849 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2851 #ifdef OBJ_COFF
2852 /* "set" symbols are local unless otherwise specified. */
2853 SF_SET_LOCAL (symbolP);
2854 #endif /* OBJ_COFF */
2855 } /* Make a new symbol. */
2857 symbol_table_insert (symbolP);
2859 * end_name = delim;
2861 if (equiv
2862 && S_IS_DEFINED (symbolP)
2863 && S_GET_SEGMENT (symbolP) != reg_section)
2864 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2866 pseudo_set (symbolP);
2868 demand_empty_rest_of_line ();
2870 /* XXX Now we come to the Thumb specific bit of code. */
2872 THUMB_SET_FUNC (symbolP, 1);
2873 ARM_SET_THUMB (symbolP, 1);
2874 #if defined OBJ_ELF || defined OBJ_COFF
2875 ARM_SET_INTERWORK (symbolP, support_interwork);
2876 #endif
2879 /* Directives: Mode selection. */
2881 /* .syntax [unified|divided] - choose the new unified syntax
2882 (same for Arm and Thumb encoding, modulo slight differences in what
2883 can be represented) or the old divergent syntax for each mode. */
2884 static void
2885 s_syntax (int unused ATTRIBUTE_UNUSED)
2887 char *name, delim;
2889 name = input_line_pointer;
2890 delim = get_symbol_end ();
2892 if (!strcasecmp (name, "unified"))
2893 unified_syntax = TRUE;
2894 else if (!strcasecmp (name, "divided"))
2895 unified_syntax = FALSE;
2896 else
2898 as_bad (_("unrecognized syntax mode \"%s\""), name);
2899 return;
2901 *input_line_pointer = delim;
2902 demand_empty_rest_of_line ();
2905 /* Directives: sectioning and alignment. */
2907 /* Same as s_align_ptwo but align 0 => align 2. */
2909 static void
2910 s_align (int unused ATTRIBUTE_UNUSED)
2912 int temp;
2913 bfd_boolean fill_p;
2914 long temp_fill;
2915 long max_alignment = 15;
2917 temp = get_absolute_expression ();
2918 if (temp > max_alignment)
2919 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2920 else if (temp < 0)
2922 as_bad (_("alignment negative. 0 assumed."));
2923 temp = 0;
2926 if (*input_line_pointer == ',')
2928 input_line_pointer++;
2929 temp_fill = get_absolute_expression ();
2930 fill_p = TRUE;
2932 else
2934 fill_p = FALSE;
2935 temp_fill = 0;
2938 if (!temp)
2939 temp = 2;
2941 /* Only make a frag if we HAVE to. */
2942 if (temp && !need_pass_2)
2944 if (!fill_p && subseg_text_p (now_seg))
2945 frag_align_code (temp, 0);
2946 else
2947 frag_align (temp, (int) temp_fill, 0);
2949 demand_empty_rest_of_line ();
2951 record_alignment (now_seg, temp);
2954 static void
2955 s_bss (int ignore ATTRIBUTE_UNUSED)
2957 /* We don't support putting frags in the BSS segment, we fake it by
2958 marking in_bss, then looking at s_skip for clues. */
2959 subseg_set (bss_section, 0);
2960 demand_empty_rest_of_line ();
2962 #ifdef md_elf_section_change_hook
2963 md_elf_section_change_hook ();
2964 #endif
2967 static void
2968 s_even (int ignore ATTRIBUTE_UNUSED)
2970 /* Never make frag if expect extra pass. */
2971 if (!need_pass_2)
2972 frag_align (1, 0, 0);
2974 record_alignment (now_seg, 1);
2976 demand_empty_rest_of_line ();
2979 /* Directives: Literal pools. */
2981 static literal_pool *
2982 find_literal_pool (void)
2984 literal_pool * pool;
2986 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2988 if (pool->section == now_seg
2989 && pool->sub_section == now_subseg)
2990 break;
2993 return pool;
2996 static literal_pool *
2997 find_or_make_literal_pool (void)
2999 /* Next literal pool ID number. */
3000 static unsigned int latest_pool_num = 1;
3001 literal_pool * pool;
3003 pool = find_literal_pool ();
3005 if (pool == NULL)
3007 /* Create a new pool. */
3008 pool = (literal_pool *) xmalloc (sizeof (* pool));
3009 if (! pool)
3010 return NULL;
3012 pool->next_free_entry = 0;
3013 pool->section = now_seg;
3014 pool->sub_section = now_subseg;
3015 pool->next = list_of_pools;
3016 pool->symbol = NULL;
3018 /* Add it to the list. */
3019 list_of_pools = pool;
3022 /* New pools, and emptied pools, will have a NULL symbol. */
3023 if (pool->symbol == NULL)
3025 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3026 (valueT) 0, &zero_address_frag);
3027 pool->id = latest_pool_num ++;
3030 /* Done. */
3031 return pool;
3034 /* Add the literal in the global 'inst'
3035 structure to the relevant literal pool. */
3037 static int
3038 add_to_lit_pool (void)
3040 literal_pool * pool;
3041 unsigned int entry;
3043 pool = find_or_make_literal_pool ();
3045 /* Check if this literal value is already in the pool. */
3046 for (entry = 0; entry < pool->next_free_entry; entry ++)
3048 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3049 && (inst.reloc.exp.X_op == O_constant)
3050 && (pool->literals[entry].X_add_number
3051 == inst.reloc.exp.X_add_number)
3052 && (pool->literals[entry].X_unsigned
3053 == inst.reloc.exp.X_unsigned))
3054 break;
3056 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3057 && (inst.reloc.exp.X_op == O_symbol)
3058 && (pool->literals[entry].X_add_number
3059 == inst.reloc.exp.X_add_number)
3060 && (pool->literals[entry].X_add_symbol
3061 == inst.reloc.exp.X_add_symbol)
3062 && (pool->literals[entry].X_op_symbol
3063 == inst.reloc.exp.X_op_symbol))
3064 break;
3067 /* Do we need to create a new entry? */
3068 if (entry == pool->next_free_entry)
3070 if (entry >= MAX_LITERAL_POOL_SIZE)
3072 inst.error = _("literal pool overflow");
3073 return FAIL;
3076 pool->literals[entry] = inst.reloc.exp;
3077 pool->next_free_entry += 1;
3080 inst.reloc.exp.X_op = O_symbol;
3081 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3082 inst.reloc.exp.X_add_symbol = pool->symbol;
3084 return SUCCESS;
3087 /* Can't use symbol_new here, so have to create a symbol and then at
3088 a later date assign it a value. Thats what these functions do. */
3090 static void
3091 symbol_locate (symbolS * symbolP,
3092 const char * name, /* It is copied, the caller can modify. */
3093 segT segment, /* Segment identifier (SEG_<something>). */
3094 valueT valu, /* Symbol value. */
3095 fragS * frag) /* Associated fragment. */
3097 unsigned int name_length;
3098 char * preserved_copy_of_name;
3100 name_length = strlen (name) + 1; /* +1 for \0. */
3101 obstack_grow (&notes, name, name_length);
3102 preserved_copy_of_name = (char *) obstack_finish (&notes);
3104 #ifdef tc_canonicalize_symbol_name
3105 preserved_copy_of_name =
3106 tc_canonicalize_symbol_name (preserved_copy_of_name);
3107 #endif
3109 S_SET_NAME (symbolP, preserved_copy_of_name);
3111 S_SET_SEGMENT (symbolP, segment);
3112 S_SET_VALUE (symbolP, valu);
3113 symbol_clear_list_pointers (symbolP);
3115 symbol_set_frag (symbolP, frag);
3117 /* Link to end of symbol chain. */
3119 extern int symbol_table_frozen;
3121 if (symbol_table_frozen)
3122 abort ();
3125 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3127 obj_symbol_new_hook (symbolP);
3129 #ifdef tc_symbol_new_hook
3130 tc_symbol_new_hook (symbolP);
3131 #endif
3133 #ifdef DEBUG_SYMS
3134 verify_symbol_chain (symbol_rootP, symbol_lastP);
3135 #endif /* DEBUG_SYMS */
3139 static void
3140 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3142 unsigned int entry;
3143 literal_pool * pool;
3144 char sym_name[20];
3146 pool = find_literal_pool ();
3147 if (pool == NULL
3148 || pool->symbol == NULL
3149 || pool->next_free_entry == 0)
3150 return;
3152 mapping_state (MAP_DATA);
3154 /* Align pool as you have word accesses.
3155 Only make a frag if we have to. */
3156 if (!need_pass_2)
3157 frag_align (2, 0, 0);
3159 record_alignment (now_seg, 2);
3161 sprintf (sym_name, "$$lit_\002%x", pool->id);
3163 symbol_locate (pool->symbol, sym_name, now_seg,
3164 (valueT) frag_now_fix (), frag_now);
3165 symbol_table_insert (pool->symbol);
3167 ARM_SET_THUMB (pool->symbol, thumb_mode);
3169 #if defined OBJ_COFF || defined OBJ_ELF
3170 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3171 #endif
3173 for (entry = 0; entry < pool->next_free_entry; entry ++)
3174 /* First output the expression in the instruction to the pool. */
3175 emit_expr (&(pool->literals[entry]), 4); /* .word */
3177 /* Mark the pool as empty. */
3178 pool->next_free_entry = 0;
3179 pool->symbol = NULL;
3182 #ifdef OBJ_ELF
3183 /* Forward declarations for functions below, in the MD interface
3184 section. */
3185 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3186 static valueT create_unwind_entry (int);
3187 static void start_unwind_section (const segT, int);
3188 static void add_unwind_opcode (valueT, int);
3189 static void flush_pending_unwind (void);
3191 /* Directives: Data. */
3193 static void
3194 s_arm_elf_cons (int nbytes)
3196 expressionS exp;
3198 #ifdef md_flush_pending_output
3199 md_flush_pending_output ();
3200 #endif
3202 if (is_it_end_of_statement ())
3204 demand_empty_rest_of_line ();
3205 return;
3208 #ifdef md_cons_align
3209 md_cons_align (nbytes);
3210 #endif
3212 mapping_state (MAP_DATA);
3215 int reloc;
3216 char *base = input_line_pointer;
3218 expression (& exp);
3220 if (exp.X_op != O_symbol)
3221 emit_expr (&exp, (unsigned int) nbytes);
3222 else
3224 char *before_reloc = input_line_pointer;
3225 reloc = parse_reloc (&input_line_pointer);
3226 if (reloc == -1)
3228 as_bad (_("unrecognized relocation suffix"));
3229 ignore_rest_of_line ();
3230 return;
3232 else if (reloc == BFD_RELOC_UNUSED)
3233 emit_expr (&exp, (unsigned int) nbytes);
3234 else
3236 reloc_howto_type *howto = (reloc_howto_type *)
3237 bfd_reloc_type_lookup (stdoutput,
3238 (bfd_reloc_code_real_type) reloc);
3239 int size = bfd_get_reloc_size (howto);
3241 if (reloc == BFD_RELOC_ARM_PLT32)
3243 as_bad (_("(plt) is only valid on branch targets"));
3244 reloc = BFD_RELOC_UNUSED;
3245 size = 0;
3248 if (size > nbytes)
3249 as_bad (_("%s relocations do not fit in %d bytes"),
3250 howto->name, nbytes);
3251 else
3253 /* We've parsed an expression stopping at O_symbol.
3254 But there may be more expression left now that we
3255 have parsed the relocation marker. Parse it again.
3256 XXX Surely there is a cleaner way to do this. */
3257 char *p = input_line_pointer;
3258 int offset;
3259 char *save_buf = (char *) alloca (input_line_pointer - base);
3260 memcpy (save_buf, base, input_line_pointer - base);
3261 memmove (base + (input_line_pointer - before_reloc),
3262 base, before_reloc - base);
3264 input_line_pointer = base + (input_line_pointer-before_reloc);
3265 expression (&exp);
3266 memcpy (base, save_buf, p - base);
3268 offset = nbytes - size;
3269 p = frag_more ((int) nbytes);
3270 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3271 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3276 while (*input_line_pointer++ == ',');
3278 /* Put terminator back into stream. */
3279 input_line_pointer --;
3280 demand_empty_rest_of_line ();
3283 /* Emit an expression containing a 32-bit thumb instruction.
3284 Implementation based on put_thumb32_insn. */
3286 static void
3287 emit_thumb32_expr (expressionS * exp)
3289 expressionS exp_high = *exp;
3291 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3292 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3293 exp->X_add_number &= 0xffff;
3294 emit_expr (exp, (unsigned int) THUMB_SIZE);
3297 /* Guess the instruction size based on the opcode. */
3299 static int
3300 thumb_insn_size (int opcode)
3302 if ((unsigned int) opcode < 0xe800u)
3303 return 2;
3304 else if ((unsigned int) opcode >= 0xe8000000u)
3305 return 4;
3306 else
3307 return 0;
3310 static bfd_boolean
3311 emit_insn (expressionS *exp, int nbytes)
3313 int size = 0;
3315 if (exp->X_op == O_constant)
3317 size = nbytes;
3319 if (size == 0)
3320 size = thumb_insn_size (exp->X_add_number);
3322 if (size != 0)
3324 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3326 as_bad (_(".inst.n operand too big. "\
3327 "Use .inst.w instead"));
3328 size = 0;
3330 else
3332 if (now_it.state == AUTOMATIC_IT_BLOCK)
3333 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3334 else
3335 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3337 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3338 emit_thumb32_expr (exp);
3339 else
3340 emit_expr (exp, (unsigned int) size);
3342 it_fsm_post_encode ();
3345 else
3346 as_bad (_("cannot determine Thumb instruction size. " \
3347 "Use .inst.n/.inst.w instead"));
3349 else
3350 as_bad (_("constant expression required"));
3352 return (size != 0);
3355 /* Like s_arm_elf_cons but do not use md_cons_align and
3356 set the mapping state to MAP_ARM/MAP_THUMB. */
3358 static void
3359 s_arm_elf_inst (int nbytes)
3361 if (is_it_end_of_statement ())
3363 demand_empty_rest_of_line ();
3364 return;
3367 /* Calling mapping_state () here will not change ARM/THUMB,
3368 but will ensure not to be in DATA state. */
3370 if (thumb_mode)
3371 mapping_state (MAP_THUMB);
3372 else
3374 if (nbytes != 0)
3376 as_bad (_("width suffixes are invalid in ARM mode"));
3377 ignore_rest_of_line ();
3378 return;
3381 nbytes = 4;
3383 mapping_state (MAP_ARM);
3388 expressionS exp;
3390 expression (& exp);
3392 if (! emit_insn (& exp, nbytes))
3394 ignore_rest_of_line ();
3395 return;
3398 while (*input_line_pointer++ == ',');
3400 /* Put terminator back into stream. */
3401 input_line_pointer --;
3402 demand_empty_rest_of_line ();
3405 /* Parse a .rel31 directive. */
3407 static void
3408 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3410 expressionS exp;
3411 char *p;
3412 valueT highbit;
3414 highbit = 0;
3415 if (*input_line_pointer == '1')
3416 highbit = 0x80000000;
3417 else if (*input_line_pointer != '0')
3418 as_bad (_("expected 0 or 1"));
3420 input_line_pointer++;
3421 if (*input_line_pointer != ',')
3422 as_bad (_("missing comma"));
3423 input_line_pointer++;
3425 #ifdef md_flush_pending_output
3426 md_flush_pending_output ();
3427 #endif
3429 #ifdef md_cons_align
3430 md_cons_align (4);
3431 #endif
3433 mapping_state (MAP_DATA);
3435 expression (&exp);
3437 p = frag_more (4);
3438 md_number_to_chars (p, highbit, 4);
3439 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3440 BFD_RELOC_ARM_PREL31);
3442 demand_empty_rest_of_line ();
3445 /* Directives: AEABI stack-unwind tables. */
3447 /* Parse an unwind_fnstart directive. Simply records the current location. */
3449 static void
3450 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3452 demand_empty_rest_of_line ();
3453 if (unwind.proc_start)
3455 as_bad (_("duplicate .fnstart directive"));
3456 return;
3459 /* Mark the start of the function. */
3460 unwind.proc_start = expr_build_dot ();
3462 /* Reset the rest of the unwind info. */
3463 unwind.opcode_count = 0;
3464 unwind.table_entry = NULL;
3465 unwind.personality_routine = NULL;
3466 unwind.personality_index = -1;
3467 unwind.frame_size = 0;
3468 unwind.fp_offset = 0;
3469 unwind.fp_reg = REG_SP;
3470 unwind.fp_used = 0;
3471 unwind.sp_restored = 0;
3475 /* Parse a handlerdata directive. Creates the exception handling table entry
3476 for the function. */
3478 static void
3479 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3481 demand_empty_rest_of_line ();
3482 if (!unwind.proc_start)
3483 as_bad (MISSING_FNSTART);
3485 if (unwind.table_entry)
3486 as_bad (_("duplicate .handlerdata directive"));
3488 create_unwind_entry (1);
3491 /* Parse an unwind_fnend directive. Generates the index table entry. */
3493 static void
3494 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3496 long where;
3497 char *ptr;
3498 valueT val;
3499 unsigned int marked_pr_dependency;
3501 demand_empty_rest_of_line ();
3503 if (!unwind.proc_start)
3505 as_bad (_(".fnend directive without .fnstart"));
3506 return;
3509 /* Add eh table entry. */
3510 if (unwind.table_entry == NULL)
3511 val = create_unwind_entry (0);
3512 else
3513 val = 0;
3515 /* Add index table entry. This is two words. */
3516 start_unwind_section (unwind.saved_seg, 1);
3517 frag_align (2, 0, 0);
3518 record_alignment (now_seg, 2);
3520 ptr = frag_more (8);
3521 where = frag_now_fix () - 8;
3523 /* Self relative offset of the function start. */
3524 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3525 BFD_RELOC_ARM_PREL31);
3527 /* Indicate dependency on EHABI-defined personality routines to the
3528 linker, if it hasn't been done already. */
3529 marked_pr_dependency
3530 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3531 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3532 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3534 static const char *const name[] =
3536 "__aeabi_unwind_cpp_pr0",
3537 "__aeabi_unwind_cpp_pr1",
3538 "__aeabi_unwind_cpp_pr2"
3540 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3541 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3542 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3543 |= 1 << unwind.personality_index;
3546 if (val)
3547 /* Inline exception table entry. */
3548 md_number_to_chars (ptr + 4, val, 4);
3549 else
3550 /* Self relative offset of the table entry. */
3551 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3552 BFD_RELOC_ARM_PREL31);
3554 /* Restore the original section. */
3555 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3557 unwind.proc_start = NULL;
3561 /* Parse an unwind_cantunwind directive. */
3563 static void
3564 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3566 demand_empty_rest_of_line ();
3567 if (!unwind.proc_start)
3568 as_bad (MISSING_FNSTART);
3570 if (unwind.personality_routine || unwind.personality_index != -1)
3571 as_bad (_("personality routine specified for cantunwind frame"));
3573 unwind.personality_index = -2;
3577 /* Parse a personalityindex directive. */
3579 static void
3580 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3582 expressionS exp;
3584 if (!unwind.proc_start)
3585 as_bad (MISSING_FNSTART);
3587 if (unwind.personality_routine || unwind.personality_index != -1)
3588 as_bad (_("duplicate .personalityindex directive"));
3590 expression (&exp);
3592 if (exp.X_op != O_constant
3593 || exp.X_add_number < 0 || exp.X_add_number > 15)
3595 as_bad (_("bad personality routine number"));
3596 ignore_rest_of_line ();
3597 return;
3600 unwind.personality_index = exp.X_add_number;
3602 demand_empty_rest_of_line ();
3606 /* Parse a personality directive. */
3608 static void
3609 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3611 char *name, *p, c;
3613 if (!unwind.proc_start)
3614 as_bad (MISSING_FNSTART);
3616 if (unwind.personality_routine || unwind.personality_index != -1)
3617 as_bad (_("duplicate .personality directive"));
3619 name = input_line_pointer;
3620 c = get_symbol_end ();
3621 p = input_line_pointer;
3622 unwind.personality_routine = symbol_find_or_make (name);
3623 *p = c;
3624 demand_empty_rest_of_line ();
3628 /* Parse a directive saving core registers. */
3630 static void
3631 s_arm_unwind_save_core (void)
3633 valueT op;
3634 long range;
3635 int n;
3637 range = parse_reg_list (&input_line_pointer);
3638 if (range == FAIL)
3640 as_bad (_("expected register list"));
3641 ignore_rest_of_line ();
3642 return;
3645 demand_empty_rest_of_line ();
3647 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3648 into .unwind_save {..., sp...}. We aren't bothered about the value of
3649 ip because it is clobbered by calls. */
3650 if (unwind.sp_restored && unwind.fp_reg == 12
3651 && (range & 0x3000) == 0x1000)
3653 unwind.opcode_count--;
3654 unwind.sp_restored = 0;
3655 range = (range | 0x2000) & ~0x1000;
3656 unwind.pending_offset = 0;
3659 /* Pop r4-r15. */
3660 if (range & 0xfff0)
3662 /* See if we can use the short opcodes. These pop a block of up to 8
3663 registers starting with r4, plus maybe r14. */
3664 for (n = 0; n < 8; n++)
3666 /* Break at the first non-saved register. */
3667 if ((range & (1 << (n + 4))) == 0)
3668 break;
3670 /* See if there are any other bits set. */
3671 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3673 /* Use the long form. */
3674 op = 0x8000 | ((range >> 4) & 0xfff);
3675 add_unwind_opcode (op, 2);
3677 else
3679 /* Use the short form. */
3680 if (range & 0x4000)
3681 op = 0xa8; /* Pop r14. */
3682 else
3683 op = 0xa0; /* Do not pop r14. */
3684 op |= (n - 1);
3685 add_unwind_opcode (op, 1);
3689 /* Pop r0-r3. */
3690 if (range & 0xf)
3692 op = 0xb100 | (range & 0xf);
3693 add_unwind_opcode (op, 2);
3696 /* Record the number of bytes pushed. */
3697 for (n = 0; n < 16; n++)
3699 if (range & (1 << n))
3700 unwind.frame_size += 4;
3705 /* Parse a directive saving FPA registers. */
3707 static void
3708 s_arm_unwind_save_fpa (int reg)
3710 expressionS exp;
3711 int num_regs;
3712 valueT op;
3714 /* Get Number of registers to transfer. */
3715 if (skip_past_comma (&input_line_pointer) != FAIL)
3716 expression (&exp);
3717 else
3718 exp.X_op = O_illegal;
3720 if (exp.X_op != O_constant)
3722 as_bad (_("expected , <constant>"));
3723 ignore_rest_of_line ();
3724 return;
3727 num_regs = exp.X_add_number;
3729 if (num_regs < 1 || num_regs > 4)
3731 as_bad (_("number of registers must be in the range [1:4]"));
3732 ignore_rest_of_line ();
3733 return;
3736 demand_empty_rest_of_line ();
3738 if (reg == 4)
3740 /* Short form. */
3741 op = 0xb4 | (num_regs - 1);
3742 add_unwind_opcode (op, 1);
3744 else
3746 /* Long form. */
3747 op = 0xc800 | (reg << 4) | (num_regs - 1);
3748 add_unwind_opcode (op, 2);
3750 unwind.frame_size += num_regs * 12;
3754 /* Parse a directive saving VFP registers for ARMv6 and above. */
3756 static void
3757 s_arm_unwind_save_vfp_armv6 (void)
3759 int count;
3760 unsigned int start;
3761 valueT op;
3762 int num_vfpv3_regs = 0;
3763 int num_regs_below_16;
3765 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3766 if (count == FAIL)
3768 as_bad (_("expected register list"));
3769 ignore_rest_of_line ();
3770 return;
3773 demand_empty_rest_of_line ();
3775 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3776 than FSTMX/FLDMX-style ones). */
3778 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3779 if (start >= 16)
3780 num_vfpv3_regs = count;
3781 else if (start + count > 16)
3782 num_vfpv3_regs = start + count - 16;
3784 if (num_vfpv3_regs > 0)
3786 int start_offset = start > 16 ? start - 16 : 0;
3787 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3788 add_unwind_opcode (op, 2);
3791 /* Generate opcode for registers numbered in the range 0 .. 15. */
3792 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3793 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3794 if (num_regs_below_16 > 0)
3796 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3797 add_unwind_opcode (op, 2);
3800 unwind.frame_size += count * 8;
3804 /* Parse a directive saving VFP registers for pre-ARMv6. */
3806 static void
3807 s_arm_unwind_save_vfp (void)
3809 int count;
3810 unsigned int reg;
3811 valueT op;
3813 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3814 if (count == FAIL)
3816 as_bad (_("expected register list"));
3817 ignore_rest_of_line ();
3818 return;
3821 demand_empty_rest_of_line ();
3823 if (reg == 8)
3825 /* Short form. */
3826 op = 0xb8 | (count - 1);
3827 add_unwind_opcode (op, 1);
3829 else
3831 /* Long form. */
3832 op = 0xb300 | (reg << 4) | (count - 1);
3833 add_unwind_opcode (op, 2);
3835 unwind.frame_size += count * 8 + 4;
3839 /* Parse a directive saving iWMMXt data registers. */
3841 static void
3842 s_arm_unwind_save_mmxwr (void)
3844 int reg;
3845 int hi_reg;
3846 int i;
3847 unsigned mask = 0;
3848 valueT op;
3850 if (*input_line_pointer == '{')
3851 input_line_pointer++;
3855 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3857 if (reg == FAIL)
3859 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3860 goto error;
3863 if (mask >> reg)
3864 as_tsktsk (_("register list not in ascending order"));
3865 mask |= 1 << reg;
3867 if (*input_line_pointer == '-')
3869 input_line_pointer++;
3870 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3871 if (hi_reg == FAIL)
3873 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3874 goto error;
3876 else if (reg >= hi_reg)
3878 as_bad (_("bad register range"));
3879 goto error;
3881 for (; reg < hi_reg; reg++)
3882 mask |= 1 << reg;
3885 while (skip_past_comma (&input_line_pointer) != FAIL);
3887 if (*input_line_pointer == '}')
3888 input_line_pointer++;
3890 demand_empty_rest_of_line ();
3892 /* Generate any deferred opcodes because we're going to be looking at
3893 the list. */
3894 flush_pending_unwind ();
3896 for (i = 0; i < 16; i++)
3898 if (mask & (1 << i))
3899 unwind.frame_size += 8;
3902 /* Attempt to combine with a previous opcode. We do this because gcc
3903 likes to output separate unwind directives for a single block of
3904 registers. */
3905 if (unwind.opcode_count > 0)
3907 i = unwind.opcodes[unwind.opcode_count - 1];
3908 if ((i & 0xf8) == 0xc0)
3910 i &= 7;
3911 /* Only merge if the blocks are contiguous. */
3912 if (i < 6)
3914 if ((mask & 0xfe00) == (1 << 9))
3916 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3917 unwind.opcode_count--;
3920 else if (i == 6 && unwind.opcode_count >= 2)
3922 i = unwind.opcodes[unwind.opcode_count - 2];
3923 reg = i >> 4;
3924 i &= 0xf;
3926 op = 0xffff << (reg - 1);
3927 if (reg > 0
3928 && ((mask & op) == (1u << (reg - 1))))
3930 op = (1 << (reg + i + 1)) - 1;
3931 op &= ~((1 << reg) - 1);
3932 mask |= op;
3933 unwind.opcode_count -= 2;
3939 hi_reg = 15;
3940 /* We want to generate opcodes in the order the registers have been
3941 saved, ie. descending order. */
3942 for (reg = 15; reg >= -1; reg--)
3944 /* Save registers in blocks. */
3945 if (reg < 0
3946 || !(mask & (1 << reg)))
3948 /* We found an unsaved reg. Generate opcodes to save the
3949 preceding block. */
3950 if (reg != hi_reg)
3952 if (reg == 9)
3954 /* Short form. */
3955 op = 0xc0 | (hi_reg - 10);
3956 add_unwind_opcode (op, 1);
3958 else
3960 /* Long form. */
3961 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3962 add_unwind_opcode (op, 2);
3965 hi_reg = reg - 1;
3969 return;
3970 error:
3971 ignore_rest_of_line ();
3974 static void
3975 s_arm_unwind_save_mmxwcg (void)
3977 int reg;
3978 int hi_reg;
3979 unsigned mask = 0;
3980 valueT op;
3982 if (*input_line_pointer == '{')
3983 input_line_pointer++;
3987 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3989 if (reg == FAIL)
3991 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3992 goto error;
3995 reg -= 8;
3996 if (mask >> reg)
3997 as_tsktsk (_("register list not in ascending order"));
3998 mask |= 1 << reg;
4000 if (*input_line_pointer == '-')
4002 input_line_pointer++;
4003 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4004 if (hi_reg == FAIL)
4006 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4007 goto error;
4009 else if (reg >= hi_reg)
4011 as_bad (_("bad register range"));
4012 goto error;
4014 for (; reg < hi_reg; reg++)
4015 mask |= 1 << reg;
4018 while (skip_past_comma (&input_line_pointer) != FAIL);
4020 if (*input_line_pointer == '}')
4021 input_line_pointer++;
4023 demand_empty_rest_of_line ();
4025 /* Generate any deferred opcodes because we're going to be looking at
4026 the list. */
4027 flush_pending_unwind ();
4029 for (reg = 0; reg < 16; reg++)
4031 if (mask & (1 << reg))
4032 unwind.frame_size += 4;
4034 op = 0xc700 | mask;
4035 add_unwind_opcode (op, 2);
4036 return;
4037 error:
4038 ignore_rest_of_line ();
4042 /* Parse an unwind_save directive.
4043 If the argument is non-zero, this is a .vsave directive. */
4045 static void
4046 s_arm_unwind_save (int arch_v6)
4048 char *peek;
4049 struct reg_entry *reg;
4050 bfd_boolean had_brace = FALSE;
4052 if (!unwind.proc_start)
4053 as_bad (MISSING_FNSTART);
4055 /* Figure out what sort of save we have. */
4056 peek = input_line_pointer;
4058 if (*peek == '{')
4060 had_brace = TRUE;
4061 peek++;
4064 reg = arm_reg_parse_multi (&peek);
4066 if (!reg)
4068 as_bad (_("register expected"));
4069 ignore_rest_of_line ();
4070 return;
4073 switch (reg->type)
4075 case REG_TYPE_FN:
4076 if (had_brace)
4078 as_bad (_("FPA .unwind_save does not take a register list"));
4079 ignore_rest_of_line ();
4080 return;
4082 input_line_pointer = peek;
4083 s_arm_unwind_save_fpa (reg->number);
4084 return;
4086 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
4087 case REG_TYPE_VFD:
4088 if (arch_v6)
4089 s_arm_unwind_save_vfp_armv6 ();
4090 else
4091 s_arm_unwind_save_vfp ();
4092 return;
4093 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4094 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4096 default:
4097 as_bad (_(".unwind_save does not support this kind of register"));
4098 ignore_rest_of_line ();
4103 /* Parse an unwind_movsp directive. */
4105 static void
4106 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4108 int reg;
4109 valueT op;
4110 int offset;
4112 if (!unwind.proc_start)
4113 as_bad (MISSING_FNSTART);
4115 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4116 if (reg == FAIL)
4118 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4119 ignore_rest_of_line ();
4120 return;
4123 /* Optional constant. */
4124 if (skip_past_comma (&input_line_pointer) != FAIL)
4126 if (immediate_for_directive (&offset) == FAIL)
4127 return;
4129 else
4130 offset = 0;
4132 demand_empty_rest_of_line ();
4134 if (reg == REG_SP || reg == REG_PC)
4136 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4137 return;
4140 if (unwind.fp_reg != REG_SP)
4141 as_bad (_("unexpected .unwind_movsp directive"));
4143 /* Generate opcode to restore the value. */
4144 op = 0x90 | reg;
4145 add_unwind_opcode (op, 1);
4147 /* Record the information for later. */
4148 unwind.fp_reg = reg;
4149 unwind.fp_offset = unwind.frame_size - offset;
4150 unwind.sp_restored = 1;
4153 /* Parse an unwind_pad directive. */
4155 static void
4156 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4158 int offset;
4160 if (!unwind.proc_start)
4161 as_bad (MISSING_FNSTART);
4163 if (immediate_for_directive (&offset) == FAIL)
4164 return;
4166 if (offset & 3)
4168 as_bad (_("stack increment must be multiple of 4"));
4169 ignore_rest_of_line ();
4170 return;
4173 /* Don't generate any opcodes, just record the details for later. */
4174 unwind.frame_size += offset;
4175 unwind.pending_offset += offset;
4177 demand_empty_rest_of_line ();
4180 /* Parse an unwind_setfp directive. */
4182 static void
4183 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4185 int sp_reg;
4186 int fp_reg;
4187 int offset;
4189 if (!unwind.proc_start)
4190 as_bad (MISSING_FNSTART);
4192 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4193 if (skip_past_comma (&input_line_pointer) == FAIL)
4194 sp_reg = FAIL;
4195 else
4196 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4198 if (fp_reg == FAIL || sp_reg == FAIL)
4200 as_bad (_("expected <reg>, <reg>"));
4201 ignore_rest_of_line ();
4202 return;
4205 /* Optional constant. */
4206 if (skip_past_comma (&input_line_pointer) != FAIL)
4208 if (immediate_for_directive (&offset) == FAIL)
4209 return;
4211 else
4212 offset = 0;
4214 demand_empty_rest_of_line ();
4216 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4218 as_bad (_("register must be either sp or set by a previous"
4219 "unwind_movsp directive"));
4220 return;
4223 /* Don't generate any opcodes, just record the information for later. */
4224 unwind.fp_reg = fp_reg;
4225 unwind.fp_used = 1;
4226 if (sp_reg == REG_SP)
4227 unwind.fp_offset = unwind.frame_size - offset;
4228 else
4229 unwind.fp_offset -= offset;
4232 /* Parse an unwind_raw directive. */
4234 static void
4235 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4237 expressionS exp;
4238 /* This is an arbitrary limit. */
4239 unsigned char op[16];
4240 int count;
4242 if (!unwind.proc_start)
4243 as_bad (MISSING_FNSTART);
4245 expression (&exp);
4246 if (exp.X_op == O_constant
4247 && skip_past_comma (&input_line_pointer) != FAIL)
4249 unwind.frame_size += exp.X_add_number;
4250 expression (&exp);
4252 else
4253 exp.X_op = O_illegal;
4255 if (exp.X_op != O_constant)
4257 as_bad (_("expected <offset>, <opcode>"));
4258 ignore_rest_of_line ();
4259 return;
4262 count = 0;
4264 /* Parse the opcode. */
4265 for (;;)
4267 if (count >= 16)
4269 as_bad (_("unwind opcode too long"));
4270 ignore_rest_of_line ();
4272 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4274 as_bad (_("invalid unwind opcode"));
4275 ignore_rest_of_line ();
4276 return;
4278 op[count++] = exp.X_add_number;
4280 /* Parse the next byte. */
4281 if (skip_past_comma (&input_line_pointer) == FAIL)
4282 break;
4284 expression (&exp);
4287 /* Add the opcode bytes in reverse order. */
4288 while (count--)
4289 add_unwind_opcode (op[count], 1);
4291 demand_empty_rest_of_line ();
4295 /* Parse a .eabi_attribute directive. */
4297 static void
4298 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4300 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4302 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4303 attributes_set_explicitly[tag] = 1;
4306 /* Emit a tls fix for the symbol. */
4308 static void
4309 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4311 char *p;
4312 expressionS exp;
4313 #ifdef md_flush_pending_output
4314 md_flush_pending_output ();
4315 #endif
4317 #ifdef md_cons_align
4318 md_cons_align (4);
4319 #endif
4321 /* Since we're just labelling the code, there's no need to define a
4322 mapping symbol. */
4323 expression (&exp);
4324 p = obstack_next_free (&frchain_now->frch_obstack);
4325 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4326 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4327 : BFD_RELOC_ARM_TLS_DESCSEQ);
4329 #endif /* OBJ_ELF */
4331 static void s_arm_arch (int);
4332 static void s_arm_object_arch (int);
4333 static void s_arm_cpu (int);
4334 static void s_arm_fpu (int);
4335 static void s_arm_arch_extension (int);
4337 #ifdef TE_PE
4339 static void
4340 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4342 expressionS exp;
4346 expression (&exp);
4347 if (exp.X_op == O_symbol)
4348 exp.X_op = O_secrel;
4350 emit_expr (&exp, 4);
4352 while (*input_line_pointer++ == ',');
4354 input_line_pointer--;
4355 demand_empty_rest_of_line ();
4357 #endif /* TE_PE */
4359 /* This table describes all the machine specific pseudo-ops the assembler
4360 has to support. The fields are:
4361 pseudo-op name without dot
4362 function to call to execute this pseudo-op
4363 Integer arg to pass to the function. */
4365 const pseudo_typeS md_pseudo_table[] =
4367 /* Never called because '.req' does not start a line. */
4368 { "req", s_req, 0 },
4369 /* Following two are likewise never called. */
4370 { "dn", s_dn, 0 },
4371 { "qn", s_qn, 0 },
4372 { "unreq", s_unreq, 0 },
4373 { "bss", s_bss, 0 },
4374 { "align", s_align, 0 },
4375 { "arm", s_arm, 0 },
4376 { "thumb", s_thumb, 0 },
4377 { "code", s_code, 0 },
4378 { "force_thumb", s_force_thumb, 0 },
4379 { "thumb_func", s_thumb_func, 0 },
4380 { "thumb_set", s_thumb_set, 0 },
4381 { "even", s_even, 0 },
4382 { "ltorg", s_ltorg, 0 },
4383 { "pool", s_ltorg, 0 },
4384 { "syntax", s_syntax, 0 },
4385 { "cpu", s_arm_cpu, 0 },
4386 { "arch", s_arm_arch, 0 },
4387 { "object_arch", s_arm_object_arch, 0 },
4388 { "fpu", s_arm_fpu, 0 },
4389 { "arch_extension", s_arm_arch_extension, 0 },
4390 #ifdef OBJ_ELF
4391 { "word", s_arm_elf_cons, 4 },
4392 { "long", s_arm_elf_cons, 4 },
4393 { "inst.n", s_arm_elf_inst, 2 },
4394 { "inst.w", s_arm_elf_inst, 4 },
4395 { "inst", s_arm_elf_inst, 0 },
4396 { "rel31", s_arm_rel31, 0 },
4397 { "fnstart", s_arm_unwind_fnstart, 0 },
4398 { "fnend", s_arm_unwind_fnend, 0 },
4399 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4400 { "personality", s_arm_unwind_personality, 0 },
4401 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4402 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4403 { "save", s_arm_unwind_save, 0 },
4404 { "vsave", s_arm_unwind_save, 1 },
4405 { "movsp", s_arm_unwind_movsp, 0 },
4406 { "pad", s_arm_unwind_pad, 0 },
4407 { "setfp", s_arm_unwind_setfp, 0 },
4408 { "unwind_raw", s_arm_unwind_raw, 0 },
4409 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4410 { "tlsdescseq", s_arm_tls_descseq, 0 },
4411 #else
4412 { "word", cons, 4},
4414 /* These are used for dwarf. */
4415 {"2byte", cons, 2},
4416 {"4byte", cons, 4},
4417 {"8byte", cons, 8},
4418 /* These are used for dwarf2. */
4419 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4420 { "loc", dwarf2_directive_loc, 0 },
4421 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4422 #endif
4423 { "extend", float_cons, 'x' },
4424 { "ldouble", float_cons, 'x' },
4425 { "packed", float_cons, 'p' },
4426 #ifdef TE_PE
4427 {"secrel32", pe_directive_secrel, 0},
4428 #endif
4429 { 0, 0, 0 }
4432 /* Parser functions used exclusively in instruction operands. */
4434 /* Generic immediate-value read function for use in insn parsing.
4435 STR points to the beginning of the immediate (the leading #);
4436 VAL receives the value; if the value is outside [MIN, MAX]
4437 issue an error. PREFIX_OPT is true if the immediate prefix is
4438 optional. */
4440 static int
4441 parse_immediate (char **str, int *val, int min, int max,
4442 bfd_boolean prefix_opt)
4444 expressionS exp;
4445 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4446 if (exp.X_op != O_constant)
4448 inst.error = _("constant expression required");
4449 return FAIL;
4452 if (exp.X_add_number < min || exp.X_add_number > max)
4454 inst.error = _("immediate value out of range");
4455 return FAIL;
4458 *val = exp.X_add_number;
4459 return SUCCESS;
4462 /* Less-generic immediate-value read function with the possibility of loading a
4463 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4464 instructions. Puts the result directly in inst.operands[i]. */
4466 static int
4467 parse_big_immediate (char **str, int i)
4469 expressionS exp;
4470 char *ptr = *str;
4472 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4474 if (exp.X_op == O_constant)
4476 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4477 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4478 O_constant. We have to be careful not to break compilation for
4479 32-bit X_add_number, though. */
4480 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
4482 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4483 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4484 inst.operands[i].regisimm = 1;
4487 else if (exp.X_op == O_big
4488 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
4490 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4492 /* Bignums have their least significant bits in
4493 generic_bignum[0]. Make sure we put 32 bits in imm and
4494 32 bits in reg, in a (hopefully) portable way. */
4495 gas_assert (parts != 0);
4497 /* Make sure that the number is not too big.
4498 PR 11972: Bignums can now be sign-extended to the
4499 size of a .octa so check that the out of range bits
4500 are all zero or all one. */
4501 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4503 LITTLENUM_TYPE m = -1;
4505 if (generic_bignum[parts * 2] != 0
4506 && generic_bignum[parts * 2] != m)
4507 return FAIL;
4509 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4510 if (generic_bignum[j] != generic_bignum[j-1])
4511 return FAIL;
4514 inst.operands[i].imm = 0;
4515 for (j = 0; j < parts; j++, idx++)
4516 inst.operands[i].imm |= generic_bignum[idx]
4517 << (LITTLENUM_NUMBER_OF_BITS * j);
4518 inst.operands[i].reg = 0;
4519 for (j = 0; j < parts; j++, idx++)
4520 inst.operands[i].reg |= generic_bignum[idx]
4521 << (LITTLENUM_NUMBER_OF_BITS * j);
4522 inst.operands[i].regisimm = 1;
4524 else
4525 return FAIL;
4527 *str = ptr;
4529 return SUCCESS;
4532 /* Returns the pseudo-register number of an FPA immediate constant,
4533 or FAIL if there isn't a valid constant here. */
4535 static int
4536 parse_fpa_immediate (char ** str)
4538 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4539 char * save_in;
4540 expressionS exp;
4541 int i;
4542 int j;
4544 /* First try and match exact strings, this is to guarantee
4545 that some formats will work even for cross assembly. */
4547 for (i = 0; fp_const[i]; i++)
4549 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4551 char *start = *str;
4553 *str += strlen (fp_const[i]);
4554 if (is_end_of_line[(unsigned char) **str])
4555 return i + 8;
4556 *str = start;
4560 /* Just because we didn't get a match doesn't mean that the constant
4561 isn't valid, just that it is in a format that we don't
4562 automatically recognize. Try parsing it with the standard
4563 expression routines. */
4565 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4567 /* Look for a raw floating point number. */
4568 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4569 && is_end_of_line[(unsigned char) *save_in])
4571 for (i = 0; i < NUM_FLOAT_VALS; i++)
4573 for (j = 0; j < MAX_LITTLENUMS; j++)
4575 if (words[j] != fp_values[i][j])
4576 break;
4579 if (j == MAX_LITTLENUMS)
4581 *str = save_in;
4582 return i + 8;
4587 /* Try and parse a more complex expression, this will probably fail
4588 unless the code uses a floating point prefix (eg "0f"). */
4589 save_in = input_line_pointer;
4590 input_line_pointer = *str;
4591 if (expression (&exp) == absolute_section
4592 && exp.X_op == O_big
4593 && exp.X_add_number < 0)
4595 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4596 Ditto for 15. */
4597 if (gen_to_words (words, 5, (long) 15) == 0)
4599 for (i = 0; i < NUM_FLOAT_VALS; i++)
4601 for (j = 0; j < MAX_LITTLENUMS; j++)
4603 if (words[j] != fp_values[i][j])
4604 break;
4607 if (j == MAX_LITTLENUMS)
4609 *str = input_line_pointer;
4610 input_line_pointer = save_in;
4611 return i + 8;
4617 *str = input_line_pointer;
4618 input_line_pointer = save_in;
4619 inst.error = _("invalid FPA immediate expression");
4620 return FAIL;
4623 /* Returns 1 if a number has "quarter-precision" float format
4624 0baBbbbbbc defgh000 00000000 00000000. */
4626 static int
4627 is_quarter_float (unsigned imm)
4629 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4630 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4633 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4634 0baBbbbbbc defgh000 00000000 00000000.
4635 The zero and minus-zero cases need special handling, since they can't be
4636 encoded in the "quarter-precision" float format, but can nonetheless be
4637 loaded as integer constants. */
4639 static unsigned
4640 parse_qfloat_immediate (char **ccp, int *immed)
4642 char *str = *ccp;
4643 char *fpnum;
4644 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4645 int found_fpchar = 0;
4647 skip_past_char (&str, '#');
4649 /* We must not accidentally parse an integer as a floating-point number. Make
4650 sure that the value we parse is not an integer by checking for special
4651 characters '.' or 'e'.
4652 FIXME: This is a horrible hack, but doing better is tricky because type
4653 information isn't in a very usable state at parse time. */
4654 fpnum = str;
4655 skip_whitespace (fpnum);
4657 if (strncmp (fpnum, "0x", 2) == 0)
4658 return FAIL;
4659 else
4661 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4662 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4664 found_fpchar = 1;
4665 break;
4668 if (!found_fpchar)
4669 return FAIL;
4672 if ((str = atof_ieee (str, 's', words)) != NULL)
4674 unsigned fpword = 0;
4675 int i;
4677 /* Our FP word must be 32 bits (single-precision FP). */
4678 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4680 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4681 fpword |= words[i];
4684 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4685 *immed = fpword;
4686 else
4687 return FAIL;
4689 *ccp = str;
4691 return SUCCESS;
4694 return FAIL;
4697 /* Shift operands. */
4698 enum shift_kind
4700 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4703 struct asm_shift_name
4705 const char *name;
4706 enum shift_kind kind;
4709 /* Third argument to parse_shift. */
4710 enum parse_shift_mode
4712 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4713 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4714 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4715 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4716 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4719 /* Parse a <shift> specifier on an ARM data processing instruction.
4720 This has three forms:
4722 (LSL|LSR|ASL|ASR|ROR) Rs
4723 (LSL|LSR|ASL|ASR|ROR) #imm
4726 Note that ASL is assimilated to LSL in the instruction encoding, and
4727 RRX to ROR #0 (which cannot be written as such). */
4729 static int
4730 parse_shift (char **str, int i, enum parse_shift_mode mode)
4732 const struct asm_shift_name *shift_name;
4733 enum shift_kind shift;
4734 char *s = *str;
4735 char *p = s;
4736 int reg;
4738 for (p = *str; ISALPHA (*p); p++)
4741 if (p == *str)
4743 inst.error = _("shift expression expected");
4744 return FAIL;
4747 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4748 p - *str);
4750 if (shift_name == NULL)
4752 inst.error = _("shift expression expected");
4753 return FAIL;
4756 shift = shift_name->kind;
4758 switch (mode)
4760 case NO_SHIFT_RESTRICT:
4761 case SHIFT_IMMEDIATE: break;
4763 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4764 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4766 inst.error = _("'LSL' or 'ASR' required");
4767 return FAIL;
4769 break;
4771 case SHIFT_LSL_IMMEDIATE:
4772 if (shift != SHIFT_LSL)
4774 inst.error = _("'LSL' required");
4775 return FAIL;
4777 break;
4779 case SHIFT_ASR_IMMEDIATE:
4780 if (shift != SHIFT_ASR)
4782 inst.error = _("'ASR' required");
4783 return FAIL;
4785 break;
4787 default: abort ();
4790 if (shift != SHIFT_RRX)
4792 /* Whitespace can appear here if the next thing is a bare digit. */
4793 skip_whitespace (p);
4795 if (mode == NO_SHIFT_RESTRICT
4796 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4798 inst.operands[i].imm = reg;
4799 inst.operands[i].immisreg = 1;
4801 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4802 return FAIL;
4804 inst.operands[i].shift_kind = shift;
4805 inst.operands[i].shifted = 1;
4806 *str = p;
4807 return SUCCESS;
4810 /* Parse a <shifter_operand> for an ARM data processing instruction:
4812 #<immediate>
4813 #<immediate>, <rotate>
4814 <Rm>
4815 <Rm>, <shift>
4817 where <shift> is defined by parse_shift above, and <rotate> is a
4818 multiple of 2 between 0 and 30. Validation of immediate operands
4819 is deferred to md_apply_fix. */
4821 static int
4822 parse_shifter_operand (char **str, int i)
4824 int value;
4825 expressionS exp;
4827 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4829 inst.operands[i].reg = value;
4830 inst.operands[i].isreg = 1;
4832 /* parse_shift will override this if appropriate */
4833 inst.reloc.exp.X_op = O_constant;
4834 inst.reloc.exp.X_add_number = 0;
4836 if (skip_past_comma (str) == FAIL)
4837 return SUCCESS;
4839 /* Shift operation on register. */
4840 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4843 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4844 return FAIL;
4846 if (skip_past_comma (str) == SUCCESS)
4848 /* #x, y -- ie explicit rotation by Y. */
4849 if (my_get_expression (&exp, str, GE_NO_PREFIX))
4850 return FAIL;
4852 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4854 inst.error = _("constant expression expected");
4855 return FAIL;
4858 value = exp.X_add_number;
4859 if (value < 0 || value > 30 || value % 2 != 0)
4861 inst.error = _("invalid rotation");
4862 return FAIL;
4864 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4866 inst.error = _("invalid constant");
4867 return FAIL;
4870 /* Convert to decoded value. md_apply_fix will put it back. */
4871 inst.reloc.exp.X_add_number
4872 = (((inst.reloc.exp.X_add_number << (32 - value))
4873 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4876 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4877 inst.reloc.pc_rel = 0;
4878 return SUCCESS;
4881 /* Group relocation information. Each entry in the table contains the
4882 textual name of the relocation as may appear in assembler source
4883 and must end with a colon.
4884 Along with this textual name are the relocation codes to be used if
4885 the corresponding instruction is an ALU instruction (ADD or SUB only),
4886 an LDR, an LDRS, or an LDC. */
4888 struct group_reloc_table_entry
4890 const char *name;
4891 int alu_code;
4892 int ldr_code;
4893 int ldrs_code;
4894 int ldc_code;
4897 typedef enum
4899 /* Varieties of non-ALU group relocation. */
4901 GROUP_LDR,
4902 GROUP_LDRS,
4903 GROUP_LDC
4904 } group_reloc_type;
4906 static struct group_reloc_table_entry group_reloc_table[] =
4907 { /* Program counter relative: */
4908 { "pc_g0_nc",
4909 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4910 0, /* LDR */
4911 0, /* LDRS */
4912 0 }, /* LDC */
4913 { "pc_g0",
4914 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4915 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4916 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4917 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4918 { "pc_g1_nc",
4919 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4920 0, /* LDR */
4921 0, /* LDRS */
4922 0 }, /* LDC */
4923 { "pc_g1",
4924 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4925 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4926 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4927 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4928 { "pc_g2",
4929 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4930 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4931 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4932 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4933 /* Section base relative */
4934 { "sb_g0_nc",
4935 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4936 0, /* LDR */
4937 0, /* LDRS */
4938 0 }, /* LDC */
4939 { "sb_g0",
4940 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4941 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4942 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4943 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4944 { "sb_g1_nc",
4945 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4946 0, /* LDR */
4947 0, /* LDRS */
4948 0 }, /* LDC */
4949 { "sb_g1",
4950 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4951 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4952 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4953 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4954 { "sb_g2",
4955 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4956 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4957 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4958 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4960 /* Given the address of a pointer pointing to the textual name of a group
4961 relocation as may appear in assembler source, attempt to find its details
4962 in group_reloc_table. The pointer will be updated to the character after
4963 the trailing colon. On failure, FAIL will be returned; SUCCESS
4964 otherwise. On success, *entry will be updated to point at the relevant
4965 group_reloc_table entry. */
4967 static int
4968 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4970 unsigned int i;
4971 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4973 int length = strlen (group_reloc_table[i].name);
4975 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4976 && (*str)[length] == ':')
4978 *out = &group_reloc_table[i];
4979 *str += (length + 1);
4980 return SUCCESS;
4984 return FAIL;
4987 /* Parse a <shifter_operand> for an ARM data processing instruction
4988 (as for parse_shifter_operand) where group relocations are allowed:
4990 #<immediate>
4991 #<immediate>, <rotate>
4992 #:<group_reloc>:<expression>
4993 <Rm>
4994 <Rm>, <shift>
4996 where <group_reloc> is one of the strings defined in group_reloc_table.
4997 The hashes are optional.
4999 Everything else is as for parse_shifter_operand. */
5001 static parse_operand_result
5002 parse_shifter_operand_group_reloc (char **str, int i)
5004 /* Determine if we have the sequence of characters #: or just :
5005 coming next. If we do, then we check for a group relocation.
5006 If we don't, punt the whole lot to parse_shifter_operand. */
5008 if (((*str)[0] == '#' && (*str)[1] == ':')
5009 || (*str)[0] == ':')
5011 struct group_reloc_table_entry *entry;
5013 if ((*str)[0] == '#')
5014 (*str) += 2;
5015 else
5016 (*str)++;
5018 /* Try to parse a group relocation. Anything else is an error. */
5019 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5021 inst.error = _("unknown group relocation");
5022 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5025 /* We now have the group relocation table entry corresponding to
5026 the name in the assembler source. Next, we parse the expression. */
5027 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5028 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5030 /* Record the relocation type (always the ALU variant here). */
5031 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
5032 gas_assert (inst.reloc.type != 0);
5034 return PARSE_OPERAND_SUCCESS;
5036 else
5037 return parse_shifter_operand (str, i) == SUCCESS
5038 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5040 /* Never reached. */
5043 /* Parse a Neon alignment expression. Information is written to
5044 inst.operands[i]. We assume the initial ':' has been skipped.
5046 align .imm = align << 8, .immisalign=1, .preind=0 */
5047 static parse_operand_result
5048 parse_neon_alignment (char **str, int i)
5050 char *p = *str;
5051 expressionS exp;
5053 my_get_expression (&exp, &p, GE_NO_PREFIX);
5055 if (exp.X_op != O_constant)
5057 inst.error = _("alignment must be constant");
5058 return PARSE_OPERAND_FAIL;
5061 inst.operands[i].imm = exp.X_add_number << 8;
5062 inst.operands[i].immisalign = 1;
5063 /* Alignments are not pre-indexes. */
5064 inst.operands[i].preind = 0;
5066 *str = p;
5067 return PARSE_OPERAND_SUCCESS;
5070 /* Parse all forms of an ARM address expression. Information is written
5071 to inst.operands[i] and/or inst.reloc.
5073 Preindexed addressing (.preind=1):
5075 [Rn, #offset] .reg=Rn .reloc.exp=offset
5076 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5077 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5078 .shift_kind=shift .reloc.exp=shift_imm
5080 These three may have a trailing ! which causes .writeback to be set also.
5082 Postindexed addressing (.postind=1, .writeback=1):
5084 [Rn], #offset .reg=Rn .reloc.exp=offset
5085 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5086 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5087 .shift_kind=shift .reloc.exp=shift_imm
5089 Unindexed addressing (.preind=0, .postind=0):
5091 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5093 Other:
5095 [Rn]{!} shorthand for [Rn,#0]{!}
5096 =immediate .isreg=0 .reloc.exp=immediate
5097 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
5099 It is the caller's responsibility to check for addressing modes not
5100 supported by the instruction, and to set inst.reloc.type. */
5102 static parse_operand_result
5103 parse_address_main (char **str, int i, int group_relocations,
5104 group_reloc_type group_type)
5106 char *p = *str;
5107 int reg;
5109 if (skip_past_char (&p, '[') == FAIL)
5111 if (skip_past_char (&p, '=') == FAIL)
5113 /* Bare address - translate to PC-relative offset. */
5114 inst.reloc.pc_rel = 1;
5115 inst.operands[i].reg = REG_PC;
5116 inst.operands[i].isreg = 1;
5117 inst.operands[i].preind = 1;
5119 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
5121 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5122 return PARSE_OPERAND_FAIL;
5124 *str = p;
5125 return PARSE_OPERAND_SUCCESS;
5128 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5130 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5131 return PARSE_OPERAND_FAIL;
5133 inst.operands[i].reg = reg;
5134 inst.operands[i].isreg = 1;
5136 if (skip_past_comma (&p) == SUCCESS)
5138 inst.operands[i].preind = 1;
5140 if (*p == '+') p++;
5141 else if (*p == '-') p++, inst.operands[i].negative = 1;
5143 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5145 inst.operands[i].imm = reg;
5146 inst.operands[i].immisreg = 1;
5148 if (skip_past_comma (&p) == SUCCESS)
5149 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5150 return PARSE_OPERAND_FAIL;
5152 else if (skip_past_char (&p, ':') == SUCCESS)
5154 /* FIXME: '@' should be used here, but it's filtered out by generic
5155 code before we get to see it here. This may be subject to
5156 change. */
5157 parse_operand_result result = parse_neon_alignment (&p, i);
5159 if (result != PARSE_OPERAND_SUCCESS)
5160 return result;
5162 else
5164 if (inst.operands[i].negative)
5166 inst.operands[i].negative = 0;
5167 p--;
5170 if (group_relocations
5171 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5173 struct group_reloc_table_entry *entry;
5175 /* Skip over the #: or : sequence. */
5176 if (*p == '#')
5177 p += 2;
5178 else
5179 p++;
5181 /* Try to parse a group relocation. Anything else is an
5182 error. */
5183 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5185 inst.error = _("unknown group relocation");
5186 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5189 /* We now have the group relocation table entry corresponding to
5190 the name in the assembler source. Next, we parse the
5191 expression. */
5192 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5193 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5195 /* Record the relocation type. */
5196 switch (group_type)
5198 case GROUP_LDR:
5199 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5200 break;
5202 case GROUP_LDRS:
5203 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5204 break;
5206 case GROUP_LDC:
5207 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5208 break;
5210 default:
5211 gas_assert (0);
5214 if (inst.reloc.type == 0)
5216 inst.error = _("this group relocation is not allowed on this instruction");
5217 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5220 else
5222 char *q = p;
5223 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5224 return PARSE_OPERAND_FAIL;
5225 /* If the offset is 0, find out if it's a +0 or -0. */
5226 if (inst.reloc.exp.X_op == O_constant
5227 && inst.reloc.exp.X_add_number == 0)
5229 skip_whitespace (q);
5230 if (*q == '#')
5232 q++;
5233 skip_whitespace (q);
5235 if (*q == '-')
5236 inst.operands[i].negative = 1;
5241 else if (skip_past_char (&p, ':') == SUCCESS)
5243 /* FIXME: '@' should be used here, but it's filtered out by generic code
5244 before we get to see it here. This may be subject to change. */
5245 parse_operand_result result = parse_neon_alignment (&p, i);
5247 if (result != PARSE_OPERAND_SUCCESS)
5248 return result;
5251 if (skip_past_char (&p, ']') == FAIL)
5253 inst.error = _("']' expected");
5254 return PARSE_OPERAND_FAIL;
5257 if (skip_past_char (&p, '!') == SUCCESS)
5258 inst.operands[i].writeback = 1;
5260 else if (skip_past_comma (&p) == SUCCESS)
5262 if (skip_past_char (&p, '{') == SUCCESS)
5264 /* [Rn], {expr} - unindexed, with option */
5265 if (parse_immediate (&p, &inst.operands[i].imm,
5266 0, 255, TRUE) == FAIL)
5267 return PARSE_OPERAND_FAIL;
5269 if (skip_past_char (&p, '}') == FAIL)
5271 inst.error = _("'}' expected at end of 'option' field");
5272 return PARSE_OPERAND_FAIL;
5274 if (inst.operands[i].preind)
5276 inst.error = _("cannot combine index with option");
5277 return PARSE_OPERAND_FAIL;
5279 *str = p;
5280 return PARSE_OPERAND_SUCCESS;
5282 else
5284 inst.operands[i].postind = 1;
5285 inst.operands[i].writeback = 1;
5287 if (inst.operands[i].preind)
5289 inst.error = _("cannot combine pre- and post-indexing");
5290 return PARSE_OPERAND_FAIL;
5293 if (*p == '+') p++;
5294 else if (*p == '-') p++, inst.operands[i].negative = 1;
5296 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5298 /* We might be using the immediate for alignment already. If we
5299 are, OR the register number into the low-order bits. */
5300 if (inst.operands[i].immisalign)
5301 inst.operands[i].imm |= reg;
5302 else
5303 inst.operands[i].imm = reg;
5304 inst.operands[i].immisreg = 1;
5306 if (skip_past_comma (&p) == SUCCESS)
5307 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5308 return PARSE_OPERAND_FAIL;
5310 else
5312 char *q = p;
5313 if (inst.operands[i].negative)
5315 inst.operands[i].negative = 0;
5316 p--;
5318 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5319 return PARSE_OPERAND_FAIL;
5320 /* If the offset is 0, find out if it's a +0 or -0. */
5321 if (inst.reloc.exp.X_op == O_constant
5322 && inst.reloc.exp.X_add_number == 0)
5324 skip_whitespace (q);
5325 if (*q == '#')
5327 q++;
5328 skip_whitespace (q);
5330 if (*q == '-')
5331 inst.operands[i].negative = 1;
5337 /* If at this point neither .preind nor .postind is set, we have a
5338 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5339 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5341 inst.operands[i].preind = 1;
5342 inst.reloc.exp.X_op = O_constant;
5343 inst.reloc.exp.X_add_number = 0;
5345 *str = p;
5346 return PARSE_OPERAND_SUCCESS;
5349 static int
5350 parse_address (char **str, int i)
5352 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5353 ? SUCCESS : FAIL;
5356 static parse_operand_result
5357 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5359 return parse_address_main (str, i, 1, type);
5362 /* Parse an operand for a MOVW or MOVT instruction. */
5363 static int
5364 parse_half (char **str)
5366 char * p;
5368 p = *str;
5369 skip_past_char (&p, '#');
5370 if (strncasecmp (p, ":lower16:", 9) == 0)
5371 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5372 else if (strncasecmp (p, ":upper16:", 9) == 0)
5373 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5375 if (inst.reloc.type != BFD_RELOC_UNUSED)
5377 p += 9;
5378 skip_whitespace (p);
5381 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5382 return FAIL;
5384 if (inst.reloc.type == BFD_RELOC_UNUSED)
5386 if (inst.reloc.exp.X_op != O_constant)
5388 inst.error = _("constant expression expected");
5389 return FAIL;
5391 if (inst.reloc.exp.X_add_number < 0
5392 || inst.reloc.exp.X_add_number > 0xffff)
5394 inst.error = _("immediate value out of range");
5395 return FAIL;
5398 *str = p;
5399 return SUCCESS;
5402 /* Miscellaneous. */
5404 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5405 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5406 static int
5407 parse_psr (char **str, bfd_boolean lhs)
5409 char *p;
5410 unsigned long psr_field;
5411 const struct asm_psr *psr;
5412 char *start;
5413 bfd_boolean is_apsr = FALSE;
5414 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
5416 /* PR gas/12698: If the user has specified -march=all then m_profile will
5417 be TRUE, but we want to ignore it in this case as we are building for any
5418 CPU type, including non-m variants. */
5419 if (selected_cpu.core == arm_arch_any.core)
5420 m_profile = FALSE;
5422 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5423 feature for ease of use and backwards compatibility. */
5424 p = *str;
5425 if (strncasecmp (p, "SPSR", 4) == 0)
5427 if (m_profile)
5428 goto unsupported_psr;
5430 psr_field = SPSR_BIT;
5432 else if (strncasecmp (p, "CPSR", 4) == 0)
5434 if (m_profile)
5435 goto unsupported_psr;
5437 psr_field = 0;
5439 else if (strncasecmp (p, "APSR", 4) == 0)
5441 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5442 and ARMv7-R architecture CPUs. */
5443 is_apsr = TRUE;
5444 psr_field = 0;
5446 else if (m_profile)
5448 start = p;
5450 p++;
5451 while (ISALNUM (*p) || *p == '_');
5453 if (strncasecmp (start, "iapsr", 5) == 0
5454 || strncasecmp (start, "eapsr", 5) == 0
5455 || strncasecmp (start, "xpsr", 4) == 0
5456 || strncasecmp (start, "psr", 3) == 0)
5457 p = start + strcspn (start, "rR") + 1;
5459 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5460 p - start);
5462 if (!psr)
5463 return FAIL;
5465 /* If APSR is being written, a bitfield may be specified. Note that
5466 APSR itself is handled above. */
5467 if (psr->field <= 3)
5469 psr_field = psr->field;
5470 is_apsr = TRUE;
5471 goto check_suffix;
5474 *str = p;
5475 /* M-profile MSR instructions have the mask field set to "10", except
5476 *PSR variants which modify APSR, which may use a different mask (and
5477 have been handled already). Do that by setting the PSR_f field
5478 here. */
5479 return psr->field | (lhs ? PSR_f : 0);
5481 else
5482 goto unsupported_psr;
5484 p += 4;
5485 check_suffix:
5486 if (*p == '_')
5488 /* A suffix follows. */
5489 p++;
5490 start = p;
5493 p++;
5494 while (ISALNUM (*p) || *p == '_');
5496 if (is_apsr)
5498 /* APSR uses a notation for bits, rather than fields. */
5499 unsigned int nzcvq_bits = 0;
5500 unsigned int g_bit = 0;
5501 char *bit;
5503 for (bit = start; bit != p; bit++)
5505 switch (TOLOWER (*bit))
5507 case 'n':
5508 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5509 break;
5511 case 'z':
5512 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5513 break;
5515 case 'c':
5516 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5517 break;
5519 case 'v':
5520 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5521 break;
5523 case 'q':
5524 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5525 break;
5527 case 'g':
5528 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5529 break;
5531 default:
5532 inst.error = _("unexpected bit specified after APSR");
5533 return FAIL;
5537 if (nzcvq_bits == 0x1f)
5538 psr_field |= PSR_f;
5540 if (g_bit == 0x1)
5542 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5544 inst.error = _("selected processor does not "
5545 "support DSP extension");
5546 return FAIL;
5549 psr_field |= PSR_s;
5552 if ((nzcvq_bits & 0x20) != 0
5553 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5554 || (g_bit & 0x2) != 0)
5556 inst.error = _("bad bitmask specified after APSR");
5557 return FAIL;
5560 else
5562 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5563 p - start);
5564 if (!psr)
5565 goto error;
5567 psr_field |= psr->field;
5570 else
5572 if (ISALNUM (*p))
5573 goto error; /* Garbage after "[CS]PSR". */
5575 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5576 is deprecated, but allow it anyway. */
5577 if (is_apsr && lhs)
5579 psr_field |= PSR_f;
5580 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5581 "deprecated"));
5583 else if (!m_profile)
5584 /* These bits are never right for M-profile devices: don't set them
5585 (only code paths which read/write APSR reach here). */
5586 psr_field |= (PSR_c | PSR_f);
5588 *str = p;
5589 return psr_field;
5591 unsupported_psr:
5592 inst.error = _("selected processor does not support requested special "
5593 "purpose register");
5594 return FAIL;
5596 error:
5597 inst.error = _("flag for {c}psr instruction expected");
5598 return FAIL;
5601 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5602 value suitable for splatting into the AIF field of the instruction. */
5604 static int
5605 parse_cps_flags (char **str)
5607 int val = 0;
5608 int saw_a_flag = 0;
5609 char *s = *str;
5611 for (;;)
5612 switch (*s++)
5614 case '\0': case ',':
5615 goto done;
5617 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5618 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5619 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5621 default:
5622 inst.error = _("unrecognized CPS flag");
5623 return FAIL;
5626 done:
5627 if (saw_a_flag == 0)
5629 inst.error = _("missing CPS flags");
5630 return FAIL;
5633 *str = s - 1;
5634 return val;
5637 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5638 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5640 static int
5641 parse_endian_specifier (char **str)
5643 int little_endian;
5644 char *s = *str;
5646 if (strncasecmp (s, "BE", 2))
5647 little_endian = 0;
5648 else if (strncasecmp (s, "LE", 2))
5649 little_endian = 1;
5650 else
5652 inst.error = _("valid endian specifiers are be or le");
5653 return FAIL;
5656 if (ISALNUM (s[2]) || s[2] == '_')
5658 inst.error = _("valid endian specifiers are be or le");
5659 return FAIL;
5662 *str = s + 2;
5663 return little_endian;
5666 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5667 value suitable for poking into the rotate field of an sxt or sxta
5668 instruction, or FAIL on error. */
5670 static int
5671 parse_ror (char **str)
5673 int rot;
5674 char *s = *str;
5676 if (strncasecmp (s, "ROR", 3) == 0)
5677 s += 3;
5678 else
5680 inst.error = _("missing rotation field after comma");
5681 return FAIL;
5684 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5685 return FAIL;
5687 switch (rot)
5689 case 0: *str = s; return 0x0;
5690 case 8: *str = s; return 0x1;
5691 case 16: *str = s; return 0x2;
5692 case 24: *str = s; return 0x3;
5694 default:
5695 inst.error = _("rotation can only be 0, 8, 16, or 24");
5696 return FAIL;
5700 /* Parse a conditional code (from conds[] below). The value returned is in the
5701 range 0 .. 14, or FAIL. */
5702 static int
5703 parse_cond (char **str)
5705 char *q;
5706 const struct asm_cond *c;
5707 int n;
5708 /* Condition codes are always 2 characters, so matching up to
5709 3 characters is sufficient. */
5710 char cond[3];
5712 q = *str;
5713 n = 0;
5714 while (ISALPHA (*q) && n < 3)
5716 cond[n] = TOLOWER (*q);
5717 q++;
5718 n++;
5721 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
5722 if (!c)
5724 inst.error = _("condition required");
5725 return FAIL;
5728 *str = q;
5729 return c->value;
5732 /* Parse an option for a barrier instruction. Returns the encoding for the
5733 option, or FAIL. */
5734 static int
5735 parse_barrier (char **str)
5737 char *p, *q;
5738 const struct asm_barrier_opt *o;
5740 p = q = *str;
5741 while (ISALPHA (*q))
5742 q++;
5744 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5745 q - p);
5746 if (!o)
5747 return FAIL;
5749 *str = q;
5750 return o->value;
5753 /* Parse the operands of a table branch instruction. Similar to a memory
5754 operand. */
5755 static int
5756 parse_tb (char **str)
5758 char * p = *str;
5759 int reg;
5761 if (skip_past_char (&p, '[') == FAIL)
5763 inst.error = _("'[' expected");
5764 return FAIL;
5767 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5769 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5770 return FAIL;
5772 inst.operands[0].reg = reg;
5774 if (skip_past_comma (&p) == FAIL)
5776 inst.error = _("',' expected");
5777 return FAIL;
5780 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5782 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5783 return FAIL;
5785 inst.operands[0].imm = reg;
5787 if (skip_past_comma (&p) == SUCCESS)
5789 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5790 return FAIL;
5791 if (inst.reloc.exp.X_add_number != 1)
5793 inst.error = _("invalid shift");
5794 return FAIL;
5796 inst.operands[0].shifted = 1;
5799 if (skip_past_char (&p, ']') == FAIL)
5801 inst.error = _("']' expected");
5802 return FAIL;
5804 *str = p;
5805 return SUCCESS;
5808 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5809 information on the types the operands can take and how they are encoded.
5810 Up to four operands may be read; this function handles setting the
5811 ".present" field for each read operand itself.
5812 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5813 else returns FAIL. */
5815 static int
5816 parse_neon_mov (char **str, int *which_operand)
5818 int i = *which_operand, val;
5819 enum arm_reg_type rtype;
5820 char *ptr = *str;
5821 struct neon_type_el optype;
5823 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5825 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5826 inst.operands[i].reg = val;
5827 inst.operands[i].isscalar = 1;
5828 inst.operands[i].vectype = optype;
5829 inst.operands[i++].present = 1;
5831 if (skip_past_comma (&ptr) == FAIL)
5832 goto wanted_comma;
5834 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5835 goto wanted_arm;
5837 inst.operands[i].reg = val;
5838 inst.operands[i].isreg = 1;
5839 inst.operands[i].present = 1;
5841 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5842 != FAIL)
5844 /* Cases 0, 1, 2, 3, 5 (D only). */
5845 if (skip_past_comma (&ptr) == FAIL)
5846 goto wanted_comma;
5848 inst.operands[i].reg = val;
5849 inst.operands[i].isreg = 1;
5850 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5851 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5852 inst.operands[i].isvec = 1;
5853 inst.operands[i].vectype = optype;
5854 inst.operands[i++].present = 1;
5856 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5858 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5859 Case 13: VMOV <Sd>, <Rm> */
5860 inst.operands[i].reg = val;
5861 inst.operands[i].isreg = 1;
5862 inst.operands[i].present = 1;
5864 if (rtype == REG_TYPE_NQ)
5866 first_error (_("can't use Neon quad register here"));
5867 return FAIL;
5869 else if (rtype != REG_TYPE_VFS)
5871 i++;
5872 if (skip_past_comma (&ptr) == FAIL)
5873 goto wanted_comma;
5874 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5875 goto wanted_arm;
5876 inst.operands[i].reg = val;
5877 inst.operands[i].isreg = 1;
5878 inst.operands[i].present = 1;
5881 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5882 &optype)) != FAIL)
5884 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5885 Case 1: VMOV<c><q> <Dd>, <Dm>
5886 Case 8: VMOV.F32 <Sd>, <Sm>
5887 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5889 inst.operands[i].reg = val;
5890 inst.operands[i].isreg = 1;
5891 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5892 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5893 inst.operands[i].isvec = 1;
5894 inst.operands[i].vectype = optype;
5895 inst.operands[i].present = 1;
5897 if (skip_past_comma (&ptr) == SUCCESS)
5899 /* Case 15. */
5900 i++;
5902 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5903 goto wanted_arm;
5905 inst.operands[i].reg = val;
5906 inst.operands[i].isreg = 1;
5907 inst.operands[i++].present = 1;
5909 if (skip_past_comma (&ptr) == FAIL)
5910 goto wanted_comma;
5912 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5913 goto wanted_arm;
5915 inst.operands[i].reg = val;
5916 inst.operands[i].isreg = 1;
5917 inst.operands[i++].present = 1;
5920 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5921 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5922 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5923 Case 10: VMOV.F32 <Sd>, #<imm>
5924 Case 11: VMOV.F64 <Dd>, #<imm> */
5925 inst.operands[i].immisfloat = 1;
5926 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5927 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5928 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5930 else
5932 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5933 return FAIL;
5936 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5938 /* Cases 6, 7. */
5939 inst.operands[i].reg = val;
5940 inst.operands[i].isreg = 1;
5941 inst.operands[i++].present = 1;
5943 if (skip_past_comma (&ptr) == FAIL)
5944 goto wanted_comma;
5946 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5948 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5949 inst.operands[i].reg = val;
5950 inst.operands[i].isscalar = 1;
5951 inst.operands[i].present = 1;
5952 inst.operands[i].vectype = optype;
5954 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5956 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5957 inst.operands[i].reg = val;
5958 inst.operands[i].isreg = 1;
5959 inst.operands[i++].present = 1;
5961 if (skip_past_comma (&ptr) == FAIL)
5962 goto wanted_comma;
5964 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5965 == FAIL)
5967 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5968 return FAIL;
5971 inst.operands[i].reg = val;
5972 inst.operands[i].isreg = 1;
5973 inst.operands[i].isvec = 1;
5974 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5975 inst.operands[i].vectype = optype;
5976 inst.operands[i].present = 1;
5978 if (rtype == REG_TYPE_VFS)
5980 /* Case 14. */
5981 i++;
5982 if (skip_past_comma (&ptr) == FAIL)
5983 goto wanted_comma;
5984 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5985 &optype)) == FAIL)
5987 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5988 return FAIL;
5990 inst.operands[i].reg = val;
5991 inst.operands[i].isreg = 1;
5992 inst.operands[i].isvec = 1;
5993 inst.operands[i].issingle = 1;
5994 inst.operands[i].vectype = optype;
5995 inst.operands[i].present = 1;
5998 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5999 != FAIL)
6001 /* Case 13. */
6002 inst.operands[i].reg = val;
6003 inst.operands[i].isreg = 1;
6004 inst.operands[i].isvec = 1;
6005 inst.operands[i].issingle = 1;
6006 inst.operands[i].vectype = optype;
6007 inst.operands[i++].present = 1;
6010 else
6012 first_error (_("parse error"));
6013 return FAIL;
6016 /* Successfully parsed the operands. Update args. */
6017 *which_operand = i;
6018 *str = ptr;
6019 return SUCCESS;
6021 wanted_comma:
6022 first_error (_("expected comma"));
6023 return FAIL;
6025 wanted_arm:
6026 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6027 return FAIL;
6030 /* Use this macro when the operand constraints are different
6031 for ARM and THUMB (e.g. ldrd). */
6032 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6033 ((arm_operand) | ((thumb_operand) << 16))
6035 /* Matcher codes for parse_operands. */
6036 enum operand_parse_code
6038 OP_stop, /* end of line */
6040 OP_RR, /* ARM register */
6041 OP_RRnpc, /* ARM register, not r15 */
6042 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6043 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6044 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6045 optional trailing ! */
6046 OP_RRw, /* ARM register, not r15, optional trailing ! */
6047 OP_RCP, /* Coprocessor number */
6048 OP_RCN, /* Coprocessor register */
6049 OP_RF, /* FPA register */
6050 OP_RVS, /* VFP single precision register */
6051 OP_RVD, /* VFP double precision register (0..15) */
6052 OP_RND, /* Neon double precision register (0..31) */
6053 OP_RNQ, /* Neon quad precision register */
6054 OP_RVSD, /* VFP single or double precision register */
6055 OP_RNDQ, /* Neon double or quad precision register */
6056 OP_RNSDQ, /* Neon single, double or quad precision register */
6057 OP_RNSC, /* Neon scalar D[X] */
6058 OP_RVC, /* VFP control register */
6059 OP_RMF, /* Maverick F register */
6060 OP_RMD, /* Maverick D register */
6061 OP_RMFX, /* Maverick FX register */
6062 OP_RMDX, /* Maverick DX register */
6063 OP_RMAX, /* Maverick AX register */
6064 OP_RMDS, /* Maverick DSPSC register */
6065 OP_RIWR, /* iWMMXt wR register */
6066 OP_RIWC, /* iWMMXt wC register */
6067 OP_RIWG, /* iWMMXt wCG register */
6068 OP_RXA, /* XScale accumulator register */
6070 OP_REGLST, /* ARM register list */
6071 OP_VRSLST, /* VFP single-precision register list */
6072 OP_VRDLST, /* VFP double-precision register list */
6073 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
6074 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6075 OP_NSTRLST, /* Neon element/structure list */
6077 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
6078 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
6079 OP_RR_RNSC, /* ARM reg or Neon scalar. */
6080 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
6081 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6082 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6083 OP_VMOV, /* Neon VMOV operands. */
6084 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
6085 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
6086 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
6088 OP_I0, /* immediate zero */
6089 OP_I7, /* immediate value 0 .. 7 */
6090 OP_I15, /* 0 .. 15 */
6091 OP_I16, /* 1 .. 16 */
6092 OP_I16z, /* 0 .. 16 */
6093 OP_I31, /* 0 .. 31 */
6094 OP_I31w, /* 0 .. 31, optional trailing ! */
6095 OP_I32, /* 1 .. 32 */
6096 OP_I32z, /* 0 .. 32 */
6097 OP_I63, /* 0 .. 63 */
6098 OP_I63s, /* -64 .. 63 */
6099 OP_I64, /* 1 .. 64 */
6100 OP_I64z, /* 0 .. 64 */
6101 OP_I255, /* 0 .. 255 */
6103 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6104 OP_I7b, /* 0 .. 7 */
6105 OP_I15b, /* 0 .. 15 */
6106 OP_I31b, /* 0 .. 31 */
6108 OP_SH, /* shifter operand */
6109 OP_SHG, /* shifter operand with possible group relocation */
6110 OP_ADDR, /* Memory address expression (any mode) */
6111 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6112 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6113 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
6114 OP_EXP, /* arbitrary expression */
6115 OP_EXPi, /* same, with optional immediate prefix */
6116 OP_EXPr, /* same, with optional relocation suffix */
6117 OP_HALF, /* 0 .. 65535 or low/high reloc. */
6119 OP_CPSF, /* CPS flags */
6120 OP_ENDI, /* Endianness specifier */
6121 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6122 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
6123 OP_COND, /* conditional code */
6124 OP_TB, /* Table branch. */
6126 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6128 OP_RRnpc_I0, /* ARM register or literal 0 */
6129 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6130 OP_RR_EXi, /* ARM register or expression with imm prefix */
6131 OP_RF_IF, /* FPA register or immediate */
6132 OP_RIWR_RIWC, /* iWMMXt R or C reg */
6133 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
6135 /* Optional operands. */
6136 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6137 OP_oI31b, /* 0 .. 31 */
6138 OP_oI32b, /* 1 .. 32 */
6139 OP_oI32z, /* 0 .. 32 */
6140 OP_oIffffb, /* 0 .. 65535 */
6141 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6143 OP_oRR, /* ARM register */
6144 OP_oRRnpc, /* ARM register, not the PC */
6145 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
6146 OP_oRRw, /* ARM register, not r15, optional trailing ! */
6147 OP_oRND, /* Optional Neon double precision register */
6148 OP_oRNQ, /* Optional Neon quad precision register */
6149 OP_oRNDQ, /* Optional Neon double or quad precision register */
6150 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
6151 OP_oSHll, /* LSL immediate */
6152 OP_oSHar, /* ASR immediate */
6153 OP_oSHllar, /* LSL or ASR immediate */
6154 OP_oROR, /* ROR 0/8/16/24 */
6155 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
6157 /* Some pre-defined mixed (ARM/THUMB) operands. */
6158 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6159 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6160 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6162 OP_FIRST_OPTIONAL = OP_oI7b
6165 /* Generic instruction operand parser. This does no encoding and no
6166 semantic validation; it merely squirrels values away in the inst
6167 structure. Returns SUCCESS or FAIL depending on whether the
6168 specified grammar matched. */
6169 static int
6170 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
6172 unsigned const int *upat = pattern;
6173 char *backtrack_pos = 0;
6174 const char *backtrack_error = 0;
6175 int i, val, backtrack_index = 0;
6176 enum arm_reg_type rtype;
6177 parse_operand_result result;
6178 unsigned int op_parse_code;
6180 #define po_char_or_fail(chr) \
6181 do \
6183 if (skip_past_char (&str, chr) == FAIL) \
6184 goto bad_args; \
6186 while (0)
6188 #define po_reg_or_fail(regtype) \
6189 do \
6191 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6192 & inst.operands[i].vectype); \
6193 if (val == FAIL) \
6195 first_error (_(reg_expected_msgs[regtype])); \
6196 goto failure; \
6198 inst.operands[i].reg = val; \
6199 inst.operands[i].isreg = 1; \
6200 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6201 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6202 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6203 || rtype == REG_TYPE_VFD \
6204 || rtype == REG_TYPE_NQ); \
6206 while (0)
6208 #define po_reg_or_goto(regtype, label) \
6209 do \
6211 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6212 & inst.operands[i].vectype); \
6213 if (val == FAIL) \
6214 goto label; \
6216 inst.operands[i].reg = val; \
6217 inst.operands[i].isreg = 1; \
6218 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6219 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6220 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6221 || rtype == REG_TYPE_VFD \
6222 || rtype == REG_TYPE_NQ); \
6224 while (0)
6226 #define po_imm_or_fail(min, max, popt) \
6227 do \
6229 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6230 goto failure; \
6231 inst.operands[i].imm = val; \
6233 while (0)
6235 #define po_scalar_or_goto(elsz, label) \
6236 do \
6238 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6239 if (val == FAIL) \
6240 goto label; \
6241 inst.operands[i].reg = val; \
6242 inst.operands[i].isscalar = 1; \
6244 while (0)
6246 #define po_misc_or_fail(expr) \
6247 do \
6249 if (expr) \
6250 goto failure; \
6252 while (0)
6254 #define po_misc_or_fail_no_backtrack(expr) \
6255 do \
6257 result = expr; \
6258 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6259 backtrack_pos = 0; \
6260 if (result != PARSE_OPERAND_SUCCESS) \
6261 goto failure; \
6263 while (0)
6265 #define po_barrier_or_imm(str) \
6266 do \
6268 val = parse_barrier (&str); \
6269 if (val == FAIL) \
6271 if (ISALPHA (*str)) \
6272 goto failure; \
6273 else \
6274 goto immediate; \
6276 else \
6278 if ((inst.instruction & 0xf0) == 0x60 \
6279 && val != 0xf) \
6281 /* ISB can only take SY as an option. */ \
6282 inst.error = _("invalid barrier type"); \
6283 goto failure; \
6287 while (0)
6289 skip_whitespace (str);
6291 for (i = 0; upat[i] != OP_stop; i++)
6293 op_parse_code = upat[i];
6294 if (op_parse_code >= 1<<16)
6295 op_parse_code = thumb ? (op_parse_code >> 16)
6296 : (op_parse_code & ((1<<16)-1));
6298 if (op_parse_code >= OP_FIRST_OPTIONAL)
6300 /* Remember where we are in case we need to backtrack. */
6301 gas_assert (!backtrack_pos);
6302 backtrack_pos = str;
6303 backtrack_error = inst.error;
6304 backtrack_index = i;
6307 if (i > 0 && (i > 1 || inst.operands[0].present))
6308 po_char_or_fail (',');
6310 switch (op_parse_code)
6312 /* Registers */
6313 case OP_oRRnpc:
6314 case OP_oRRnpcsp:
6315 case OP_RRnpc:
6316 case OP_RRnpcsp:
6317 case OP_oRR:
6318 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6319 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6320 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6321 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6322 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6323 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6324 case OP_oRND:
6325 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6326 case OP_RVC:
6327 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6328 break;
6329 /* Also accept generic coprocessor regs for unknown registers. */
6330 coproc_reg:
6331 po_reg_or_fail (REG_TYPE_CN);
6332 break;
6333 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6334 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6335 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6336 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6337 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6338 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6339 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6340 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6341 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6342 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6343 case OP_oRNQ:
6344 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6345 case OP_oRNDQ:
6346 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6347 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6348 case OP_oRNSDQ:
6349 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6351 /* Neon scalar. Using an element size of 8 means that some invalid
6352 scalars are accepted here, so deal with those in later code. */
6353 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6355 case OP_RNDQ_I0:
6357 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6358 break;
6359 try_imm0:
6360 po_imm_or_fail (0, 0, TRUE);
6362 break;
6364 case OP_RVSD_I0:
6365 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6366 break;
6368 case OP_RR_RNSC:
6370 po_scalar_or_goto (8, try_rr);
6371 break;
6372 try_rr:
6373 po_reg_or_fail (REG_TYPE_RN);
6375 break;
6377 case OP_RNSDQ_RNSC:
6379 po_scalar_or_goto (8, try_nsdq);
6380 break;
6381 try_nsdq:
6382 po_reg_or_fail (REG_TYPE_NSDQ);
6384 break;
6386 case OP_RNDQ_RNSC:
6388 po_scalar_or_goto (8, try_ndq);
6389 break;
6390 try_ndq:
6391 po_reg_or_fail (REG_TYPE_NDQ);
6393 break;
6395 case OP_RND_RNSC:
6397 po_scalar_or_goto (8, try_vfd);
6398 break;
6399 try_vfd:
6400 po_reg_or_fail (REG_TYPE_VFD);
6402 break;
6404 case OP_VMOV:
6405 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6406 not careful then bad things might happen. */
6407 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6408 break;
6410 case OP_RNDQ_Ibig:
6412 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6413 break;
6414 try_immbig:
6415 /* There's a possibility of getting a 64-bit immediate here, so
6416 we need special handling. */
6417 if (parse_big_immediate (&str, i) == FAIL)
6419 inst.error = _("immediate value is out of range");
6420 goto failure;
6423 break;
6425 case OP_RNDQ_I63b:
6427 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6428 break;
6429 try_shimm:
6430 po_imm_or_fail (0, 63, TRUE);
6432 break;
6434 case OP_RRnpcb:
6435 po_char_or_fail ('[');
6436 po_reg_or_fail (REG_TYPE_RN);
6437 po_char_or_fail (']');
6438 break;
6440 case OP_RRnpctw:
6441 case OP_RRw:
6442 case OP_oRRw:
6443 po_reg_or_fail (REG_TYPE_RN);
6444 if (skip_past_char (&str, '!') == SUCCESS)
6445 inst.operands[i].writeback = 1;
6446 break;
6448 /* Immediates */
6449 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6450 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6451 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6452 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6453 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6454 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6455 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6456 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6457 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6458 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6459 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6460 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6462 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6463 case OP_oI7b:
6464 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6465 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6466 case OP_oI31b:
6467 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6468 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6469 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
6470 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6472 /* Immediate variants */
6473 case OP_oI255c:
6474 po_char_or_fail ('{');
6475 po_imm_or_fail (0, 255, TRUE);
6476 po_char_or_fail ('}');
6477 break;
6479 case OP_I31w:
6480 /* The expression parser chokes on a trailing !, so we have
6481 to find it first and zap it. */
6483 char *s = str;
6484 while (*s && *s != ',')
6485 s++;
6486 if (s[-1] == '!')
6488 s[-1] = '\0';
6489 inst.operands[i].writeback = 1;
6491 po_imm_or_fail (0, 31, TRUE);
6492 if (str == s - 1)
6493 str = s;
6495 break;
6497 /* Expressions */
6498 case OP_EXPi: EXPi:
6499 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6500 GE_OPT_PREFIX));
6501 break;
6503 case OP_EXP:
6504 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6505 GE_NO_PREFIX));
6506 break;
6508 case OP_EXPr: EXPr:
6509 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6510 GE_NO_PREFIX));
6511 if (inst.reloc.exp.X_op == O_symbol)
6513 val = parse_reloc (&str);
6514 if (val == -1)
6516 inst.error = _("unrecognized relocation suffix");
6517 goto failure;
6519 else if (val != BFD_RELOC_UNUSED)
6521 inst.operands[i].imm = val;
6522 inst.operands[i].hasreloc = 1;
6525 break;
6527 /* Operand for MOVW or MOVT. */
6528 case OP_HALF:
6529 po_misc_or_fail (parse_half (&str));
6530 break;
6532 /* Register or expression. */
6533 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6534 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6536 /* Register or immediate. */
6537 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6538 I0: po_imm_or_fail (0, 0, FALSE); break;
6540 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6542 if (!is_immediate_prefix (*str))
6543 goto bad_args;
6544 str++;
6545 val = parse_fpa_immediate (&str);
6546 if (val == FAIL)
6547 goto failure;
6548 /* FPA immediates are encoded as registers 8-15.
6549 parse_fpa_immediate has already applied the offset. */
6550 inst.operands[i].reg = val;
6551 inst.operands[i].isreg = 1;
6552 break;
6554 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6555 I32z: po_imm_or_fail (0, 32, FALSE); break;
6557 /* Two kinds of register. */
6558 case OP_RIWR_RIWC:
6560 struct reg_entry *rege = arm_reg_parse_multi (&str);
6561 if (!rege
6562 || (rege->type != REG_TYPE_MMXWR
6563 && rege->type != REG_TYPE_MMXWC
6564 && rege->type != REG_TYPE_MMXWCG))
6566 inst.error = _("iWMMXt data or control register expected");
6567 goto failure;
6569 inst.operands[i].reg = rege->number;
6570 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6572 break;
6574 case OP_RIWC_RIWG:
6576 struct reg_entry *rege = arm_reg_parse_multi (&str);
6577 if (!rege
6578 || (rege->type != REG_TYPE_MMXWC
6579 && rege->type != REG_TYPE_MMXWCG))
6581 inst.error = _("iWMMXt control register expected");
6582 goto failure;
6584 inst.operands[i].reg = rege->number;
6585 inst.operands[i].isreg = 1;
6587 break;
6589 /* Misc */
6590 case OP_CPSF: val = parse_cps_flags (&str); break;
6591 case OP_ENDI: val = parse_endian_specifier (&str); break;
6592 case OP_oROR: val = parse_ror (&str); break;
6593 case OP_COND: val = parse_cond (&str); break;
6594 case OP_oBARRIER_I15:
6595 po_barrier_or_imm (str); break;
6596 immediate:
6597 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6598 goto failure;
6599 break;
6601 case OP_wPSR:
6602 case OP_rPSR:
6603 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6604 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6606 inst.error = _("Banked registers are not available with this "
6607 "architecture.");
6608 goto failure;
6610 break;
6611 try_psr:
6612 val = parse_psr (&str, op_parse_code == OP_wPSR);
6613 break;
6615 case OP_APSR_RR:
6616 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6617 break;
6618 try_apsr:
6619 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6620 instruction). */
6621 if (strncasecmp (str, "APSR_", 5) == 0)
6623 unsigned found = 0;
6624 str += 5;
6625 while (found < 15)
6626 switch (*str++)
6628 case 'c': found = (found & 1) ? 16 : found | 1; break;
6629 case 'n': found = (found & 2) ? 16 : found | 2; break;
6630 case 'z': found = (found & 4) ? 16 : found | 4; break;
6631 case 'v': found = (found & 8) ? 16 : found | 8; break;
6632 default: found = 16;
6634 if (found != 15)
6635 goto failure;
6636 inst.operands[i].isvec = 1;
6637 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6638 inst.operands[i].reg = REG_PC;
6640 else
6641 goto failure;
6642 break;
6644 case OP_TB:
6645 po_misc_or_fail (parse_tb (&str));
6646 break;
6648 /* Register lists. */
6649 case OP_REGLST:
6650 val = parse_reg_list (&str);
6651 if (*str == '^')
6653 inst.operands[1].writeback = 1;
6654 str++;
6656 break;
6658 case OP_VRSLST:
6659 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6660 break;
6662 case OP_VRDLST:
6663 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6664 break;
6666 case OP_VRSDLST:
6667 /* Allow Q registers too. */
6668 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6669 REGLIST_NEON_D);
6670 if (val == FAIL)
6672 inst.error = NULL;
6673 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6674 REGLIST_VFP_S);
6675 inst.operands[i].issingle = 1;
6677 break;
6679 case OP_NRDLST:
6680 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6681 REGLIST_NEON_D);
6682 break;
6684 case OP_NSTRLST:
6685 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6686 &inst.operands[i].vectype);
6687 break;
6689 /* Addressing modes */
6690 case OP_ADDR:
6691 po_misc_or_fail (parse_address (&str, i));
6692 break;
6694 case OP_ADDRGLDR:
6695 po_misc_or_fail_no_backtrack (
6696 parse_address_group_reloc (&str, i, GROUP_LDR));
6697 break;
6699 case OP_ADDRGLDRS:
6700 po_misc_or_fail_no_backtrack (
6701 parse_address_group_reloc (&str, i, GROUP_LDRS));
6702 break;
6704 case OP_ADDRGLDC:
6705 po_misc_or_fail_no_backtrack (
6706 parse_address_group_reloc (&str, i, GROUP_LDC));
6707 break;
6709 case OP_SH:
6710 po_misc_or_fail (parse_shifter_operand (&str, i));
6711 break;
6713 case OP_SHG:
6714 po_misc_or_fail_no_backtrack (
6715 parse_shifter_operand_group_reloc (&str, i));
6716 break;
6718 case OP_oSHll:
6719 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6720 break;
6722 case OP_oSHar:
6723 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6724 break;
6726 case OP_oSHllar:
6727 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6728 break;
6730 default:
6731 as_fatal (_("unhandled operand code %d"), op_parse_code);
6734 /* Various value-based sanity checks and shared operations. We
6735 do not signal immediate failures for the register constraints;
6736 this allows a syntax error to take precedence. */
6737 switch (op_parse_code)
6739 case OP_oRRnpc:
6740 case OP_RRnpc:
6741 case OP_RRnpcb:
6742 case OP_RRw:
6743 case OP_oRRw:
6744 case OP_RRnpc_I0:
6745 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6746 inst.error = BAD_PC;
6747 break;
6749 case OP_oRRnpcsp:
6750 case OP_RRnpcsp:
6751 if (inst.operands[i].isreg)
6753 if (inst.operands[i].reg == REG_PC)
6754 inst.error = BAD_PC;
6755 else if (inst.operands[i].reg == REG_SP)
6756 inst.error = BAD_SP;
6758 break;
6760 case OP_RRnpctw:
6761 if (inst.operands[i].isreg
6762 && inst.operands[i].reg == REG_PC
6763 && (inst.operands[i].writeback || thumb))
6764 inst.error = BAD_PC;
6765 break;
6767 case OP_CPSF:
6768 case OP_ENDI:
6769 case OP_oROR:
6770 case OP_wPSR:
6771 case OP_rPSR:
6772 case OP_COND:
6773 case OP_oBARRIER_I15:
6774 case OP_REGLST:
6775 case OP_VRSLST:
6776 case OP_VRDLST:
6777 case OP_VRSDLST:
6778 case OP_NRDLST:
6779 case OP_NSTRLST:
6780 if (val == FAIL)
6781 goto failure;
6782 inst.operands[i].imm = val;
6783 break;
6785 default:
6786 break;
6789 /* If we get here, this operand was successfully parsed. */
6790 inst.operands[i].present = 1;
6791 continue;
6793 bad_args:
6794 inst.error = BAD_ARGS;
6796 failure:
6797 if (!backtrack_pos)
6799 /* The parse routine should already have set inst.error, but set a
6800 default here just in case. */
6801 if (!inst.error)
6802 inst.error = _("syntax error");
6803 return FAIL;
6806 /* Do not backtrack over a trailing optional argument that
6807 absorbed some text. We will only fail again, with the
6808 'garbage following instruction' error message, which is
6809 probably less helpful than the current one. */
6810 if (backtrack_index == i && backtrack_pos != str
6811 && upat[i+1] == OP_stop)
6813 if (!inst.error)
6814 inst.error = _("syntax error");
6815 return FAIL;
6818 /* Try again, skipping the optional argument at backtrack_pos. */
6819 str = backtrack_pos;
6820 inst.error = backtrack_error;
6821 inst.operands[backtrack_index].present = 0;
6822 i = backtrack_index;
6823 backtrack_pos = 0;
6826 /* Check that we have parsed all the arguments. */
6827 if (*str != '\0' && !inst.error)
6828 inst.error = _("garbage following instruction");
6830 return inst.error ? FAIL : SUCCESS;
6833 #undef po_char_or_fail
6834 #undef po_reg_or_fail
6835 #undef po_reg_or_goto
6836 #undef po_imm_or_fail
6837 #undef po_scalar_or_fail
6838 #undef po_barrier_or_imm
6840 /* Shorthand macro for instruction encoding functions issuing errors. */
6841 #define constraint(expr, err) \
6842 do \
6844 if (expr) \
6846 inst.error = err; \
6847 return; \
6850 while (0)
6852 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6853 instructions are unpredictable if these registers are used. This
6854 is the BadReg predicate in ARM's Thumb-2 documentation. */
6855 #define reject_bad_reg(reg) \
6856 do \
6857 if (reg == REG_SP || reg == REG_PC) \
6859 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6860 return; \
6862 while (0)
6864 /* If REG is R13 (the stack pointer), warn that its use is
6865 deprecated. */
6866 #define warn_deprecated_sp(reg) \
6867 do \
6868 if (warn_on_deprecated && reg == REG_SP) \
6869 as_warn (_("use of r13 is deprecated")); \
6870 while (0)
6872 /* Functions for operand encoding. ARM, then Thumb. */
6874 #define rotate_left(v, n) (v << n | v >> (32 - n))
6876 /* If VAL can be encoded in the immediate field of an ARM instruction,
6877 return the encoded form. Otherwise, return FAIL. */
6879 static unsigned int
6880 encode_arm_immediate (unsigned int val)
6882 unsigned int a, i;
6884 for (i = 0; i < 32; i += 2)
6885 if ((a = rotate_left (val, i)) <= 0xff)
6886 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6888 return FAIL;
6891 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6892 return the encoded form. Otherwise, return FAIL. */
6893 static unsigned int
6894 encode_thumb32_immediate (unsigned int val)
6896 unsigned int a, i;
6898 if (val <= 0xff)
6899 return val;
6901 for (i = 1; i <= 24; i++)
6903 a = val >> i;
6904 if ((val & ~(0xff << i)) == 0)
6905 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6908 a = val & 0xff;
6909 if (val == ((a << 16) | a))
6910 return 0x100 | a;
6911 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6912 return 0x300 | a;
6914 a = val & 0xff00;
6915 if (val == ((a << 16) | a))
6916 return 0x200 | (a >> 8);
6918 return FAIL;
6920 /* Encode a VFP SP or DP register number into inst.instruction. */
6922 static void
6923 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6925 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6926 && reg > 15)
6928 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6930 if (thumb_mode)
6931 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6932 fpu_vfp_ext_d32);
6933 else
6934 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6935 fpu_vfp_ext_d32);
6937 else
6939 first_error (_("D register out of range for selected VFP version"));
6940 return;
6944 switch (pos)
6946 case VFP_REG_Sd:
6947 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6948 break;
6950 case VFP_REG_Sn:
6951 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6952 break;
6954 case VFP_REG_Sm:
6955 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6956 break;
6958 case VFP_REG_Dd:
6959 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6960 break;
6962 case VFP_REG_Dn:
6963 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6964 break;
6966 case VFP_REG_Dm:
6967 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6968 break;
6970 default:
6971 abort ();
6975 /* Encode a <shift> in an ARM-format instruction. The immediate,
6976 if any, is handled by md_apply_fix. */
6977 static void
6978 encode_arm_shift (int i)
6980 if (inst.operands[i].shift_kind == SHIFT_RRX)
6981 inst.instruction |= SHIFT_ROR << 5;
6982 else
6984 inst.instruction |= inst.operands[i].shift_kind << 5;
6985 if (inst.operands[i].immisreg)
6987 inst.instruction |= SHIFT_BY_REG;
6988 inst.instruction |= inst.operands[i].imm << 8;
6990 else
6991 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6995 static void
6996 encode_arm_shifter_operand (int i)
6998 if (inst.operands[i].isreg)
7000 inst.instruction |= inst.operands[i].reg;
7001 encode_arm_shift (i);
7003 else
7004 inst.instruction |= INST_IMMEDIATE;
7007 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
7008 static void
7009 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
7011 gas_assert (inst.operands[i].isreg);
7012 inst.instruction |= inst.operands[i].reg << 16;
7014 if (inst.operands[i].preind)
7016 if (is_t)
7018 inst.error = _("instruction does not accept preindexed addressing");
7019 return;
7021 inst.instruction |= PRE_INDEX;
7022 if (inst.operands[i].writeback)
7023 inst.instruction |= WRITE_BACK;
7026 else if (inst.operands[i].postind)
7028 gas_assert (inst.operands[i].writeback);
7029 if (is_t)
7030 inst.instruction |= WRITE_BACK;
7032 else /* unindexed - only for coprocessor */
7034 inst.error = _("instruction does not accept unindexed addressing");
7035 return;
7038 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7039 && (((inst.instruction & 0x000f0000) >> 16)
7040 == ((inst.instruction & 0x0000f000) >> 12)))
7041 as_warn ((inst.instruction & LOAD_BIT)
7042 ? _("destination register same as write-back base")
7043 : _("source register same as write-back base"));
7046 /* inst.operands[i] was set up by parse_address. Encode it into an
7047 ARM-format mode 2 load or store instruction. If is_t is true,
7048 reject forms that cannot be used with a T instruction (i.e. not
7049 post-indexed). */
7050 static void
7051 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
7053 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7055 encode_arm_addr_mode_common (i, is_t);
7057 if (inst.operands[i].immisreg)
7059 constraint ((inst.operands[i].imm == REG_PC
7060 || (is_pc && inst.operands[i].writeback)),
7061 BAD_PC_ADDRESSING);
7062 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7063 inst.instruction |= inst.operands[i].imm;
7064 if (!inst.operands[i].negative)
7065 inst.instruction |= INDEX_UP;
7066 if (inst.operands[i].shifted)
7068 if (inst.operands[i].shift_kind == SHIFT_RRX)
7069 inst.instruction |= SHIFT_ROR << 5;
7070 else
7072 inst.instruction |= inst.operands[i].shift_kind << 5;
7073 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7077 else /* immediate offset in inst.reloc */
7079 if (is_pc && !inst.reloc.pc_rel)
7081 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
7083 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7084 cannot use PC in addressing.
7085 PC cannot be used in writeback addressing, either. */
7086 constraint ((is_t || inst.operands[i].writeback),
7087 BAD_PC_ADDRESSING);
7089 /* Use of PC in str is deprecated for ARMv7. */
7090 if (warn_on_deprecated
7091 && !is_load
7092 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7093 as_warn (_("use of PC in this instruction is deprecated"));
7096 if (inst.reloc.type == BFD_RELOC_UNUSED)
7098 /* Prefer + for zero encoded value. */
7099 if (!inst.operands[i].negative)
7100 inst.instruction |= INDEX_UP;
7101 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7106 /* inst.operands[i] was set up by parse_address. Encode it into an
7107 ARM-format mode 3 load or store instruction. Reject forms that
7108 cannot be used with such instructions. If is_t is true, reject
7109 forms that cannot be used with a T instruction (i.e. not
7110 post-indexed). */
7111 static void
7112 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
7114 if (inst.operands[i].immisreg && inst.operands[i].shifted)
7116 inst.error = _("instruction does not accept scaled register index");
7117 return;
7120 encode_arm_addr_mode_common (i, is_t);
7122 if (inst.operands[i].immisreg)
7124 constraint ((inst.operands[i].imm == REG_PC
7125 || inst.operands[i].reg == REG_PC),
7126 BAD_PC_ADDRESSING);
7127 inst.instruction |= inst.operands[i].imm;
7128 if (!inst.operands[i].negative)
7129 inst.instruction |= INDEX_UP;
7131 else /* immediate offset in inst.reloc */
7133 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7134 && inst.operands[i].writeback),
7135 BAD_PC_WRITEBACK);
7136 inst.instruction |= HWOFFSET_IMM;
7137 if (inst.reloc.type == BFD_RELOC_UNUSED)
7139 /* Prefer + for zero encoded value. */
7140 if (!inst.operands[i].negative)
7141 inst.instruction |= INDEX_UP;
7143 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7148 /* inst.operands[i] was set up by parse_address. Encode it into an
7149 ARM-format instruction. Reject all forms which cannot be encoded
7150 into a coprocessor load/store instruction. If wb_ok is false,
7151 reject use of writeback; if unind_ok is false, reject use of
7152 unindexed addressing. If reloc_override is not 0, use it instead
7153 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7154 (in which case it is preserved). */
7156 static int
7157 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
7159 inst.instruction |= inst.operands[i].reg << 16;
7161 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
7163 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
7165 gas_assert (!inst.operands[i].writeback);
7166 if (!unind_ok)
7168 inst.error = _("instruction does not support unindexed addressing");
7169 return FAIL;
7171 inst.instruction |= inst.operands[i].imm;
7172 inst.instruction |= INDEX_UP;
7173 return SUCCESS;
7176 if (inst.operands[i].preind)
7177 inst.instruction |= PRE_INDEX;
7179 if (inst.operands[i].writeback)
7181 if (inst.operands[i].reg == REG_PC)
7183 inst.error = _("pc may not be used with write-back");
7184 return FAIL;
7186 if (!wb_ok)
7188 inst.error = _("instruction does not support writeback");
7189 return FAIL;
7191 inst.instruction |= WRITE_BACK;
7194 if (reloc_override)
7195 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
7196 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7197 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7198 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7200 if (thumb_mode)
7201 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7202 else
7203 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7206 /* Prefer + for zero encoded value. */
7207 if (!inst.operands[i].negative)
7208 inst.instruction |= INDEX_UP;
7210 return SUCCESS;
7213 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
7214 Determine whether it can be performed with a move instruction; if
7215 it can, convert inst.instruction to that move instruction and
7216 return TRUE; if it can't, convert inst.instruction to a literal-pool
7217 load and return FALSE. If this is not a valid thing to do in the
7218 current context, set inst.error and return TRUE.
7220 inst.operands[i] describes the destination register. */
7222 static bfd_boolean
7223 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7225 unsigned long tbit;
7227 if (thumb_p)
7228 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7229 else
7230 tbit = LOAD_BIT;
7232 if ((inst.instruction & tbit) == 0)
7234 inst.error = _("invalid pseudo operation");
7235 return TRUE;
7237 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
7239 inst.error = _("constant expression expected");
7240 return TRUE;
7242 if (inst.reloc.exp.X_op == O_constant)
7244 if (thumb_p)
7246 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
7248 /* This can be done with a mov(1) instruction. */
7249 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7250 inst.instruction |= inst.reloc.exp.X_add_number;
7251 return TRUE;
7254 else
7256 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7257 if (value != FAIL)
7259 /* This can be done with a mov instruction. */
7260 inst.instruction &= LITERAL_MASK;
7261 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7262 inst.instruction |= value & 0xfff;
7263 return TRUE;
7266 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7267 if (value != FAIL)
7269 /* This can be done with a mvn instruction. */
7270 inst.instruction &= LITERAL_MASK;
7271 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7272 inst.instruction |= value & 0xfff;
7273 return TRUE;
7278 if (add_to_lit_pool () == FAIL)
7280 inst.error = _("literal pool insertion failed");
7281 return TRUE;
7283 inst.operands[1].reg = REG_PC;
7284 inst.operands[1].isreg = 1;
7285 inst.operands[1].preind = 1;
7286 inst.reloc.pc_rel = 1;
7287 inst.reloc.type = (thumb_p
7288 ? BFD_RELOC_ARM_THUMB_OFFSET
7289 : (mode_3
7290 ? BFD_RELOC_ARM_HWLITERAL
7291 : BFD_RELOC_ARM_LITERAL));
7292 return FALSE;
7295 /* Functions for instruction encoding, sorted by sub-architecture.
7296 First some generics; their names are taken from the conventional
7297 bit positions for register arguments in ARM format instructions. */
7299 static void
7300 do_noargs (void)
7304 static void
7305 do_rd (void)
7307 inst.instruction |= inst.operands[0].reg << 12;
7310 static void
7311 do_rd_rm (void)
7313 inst.instruction |= inst.operands[0].reg << 12;
7314 inst.instruction |= inst.operands[1].reg;
7317 static void
7318 do_rd_rn (void)
7320 inst.instruction |= inst.operands[0].reg << 12;
7321 inst.instruction |= inst.operands[1].reg << 16;
7324 static void
7325 do_rn_rd (void)
7327 inst.instruction |= inst.operands[0].reg << 16;
7328 inst.instruction |= inst.operands[1].reg << 12;
7331 static void
7332 do_rd_rm_rn (void)
7334 unsigned Rn = inst.operands[2].reg;
7335 /* Enforce restrictions on SWP instruction. */
7336 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
7338 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7339 _("Rn must not overlap other operands"));
7341 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7342 if (warn_on_deprecated
7343 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7344 as_warn (_("swp{b} use is deprecated for this architecture"));
7347 inst.instruction |= inst.operands[0].reg << 12;
7348 inst.instruction |= inst.operands[1].reg;
7349 inst.instruction |= Rn << 16;
7352 static void
7353 do_rd_rn_rm (void)
7355 inst.instruction |= inst.operands[0].reg << 12;
7356 inst.instruction |= inst.operands[1].reg << 16;
7357 inst.instruction |= inst.operands[2].reg;
7360 static void
7361 do_rm_rd_rn (void)
7363 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7364 constraint (((inst.reloc.exp.X_op != O_constant
7365 && inst.reloc.exp.X_op != O_illegal)
7366 || inst.reloc.exp.X_add_number != 0),
7367 BAD_ADDR_MODE);
7368 inst.instruction |= inst.operands[0].reg;
7369 inst.instruction |= inst.operands[1].reg << 12;
7370 inst.instruction |= inst.operands[2].reg << 16;
7373 static void
7374 do_imm0 (void)
7376 inst.instruction |= inst.operands[0].imm;
7379 static void
7380 do_rd_cpaddr (void)
7382 inst.instruction |= inst.operands[0].reg << 12;
7383 encode_arm_cp_address (1, TRUE, TRUE, 0);
7386 /* ARM instructions, in alphabetical order by function name (except
7387 that wrapper functions appear immediately after the function they
7388 wrap). */
7390 /* This is a pseudo-op of the form "adr rd, label" to be converted
7391 into a relative address of the form "add rd, pc, #label-.-8". */
7393 static void
7394 do_adr (void)
7396 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7398 /* Frag hacking will turn this into a sub instruction if the offset turns
7399 out to be negative. */
7400 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7401 inst.reloc.pc_rel = 1;
7402 inst.reloc.exp.X_add_number -= 8;
7405 /* This is a pseudo-op of the form "adrl rd, label" to be converted
7406 into a relative address of the form:
7407 add rd, pc, #low(label-.-8)"
7408 add rd, rd, #high(label-.-8)" */
7410 static void
7411 do_adrl (void)
7413 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7415 /* Frag hacking will turn this into a sub instruction if the offset turns
7416 out to be negative. */
7417 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
7418 inst.reloc.pc_rel = 1;
7419 inst.size = INSN_SIZE * 2;
7420 inst.reloc.exp.X_add_number -= 8;
7423 static void
7424 do_arit (void)
7426 if (!inst.operands[1].present)
7427 inst.operands[1].reg = inst.operands[0].reg;
7428 inst.instruction |= inst.operands[0].reg << 12;
7429 inst.instruction |= inst.operands[1].reg << 16;
7430 encode_arm_shifter_operand (2);
7433 static void
7434 do_barrier (void)
7436 if (inst.operands[0].present)
7438 constraint ((inst.instruction & 0xf0) != 0x40
7439 && inst.operands[0].imm > 0xf
7440 && inst.operands[0].imm < 0x0,
7441 _("bad barrier type"));
7442 inst.instruction |= inst.operands[0].imm;
7444 else
7445 inst.instruction |= 0xf;
7448 static void
7449 do_bfc (void)
7451 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7452 constraint (msb > 32, _("bit-field extends past end of register"));
7453 /* The instruction encoding stores the LSB and MSB,
7454 not the LSB and width. */
7455 inst.instruction |= inst.operands[0].reg << 12;
7456 inst.instruction |= inst.operands[1].imm << 7;
7457 inst.instruction |= (msb - 1) << 16;
7460 static void
7461 do_bfi (void)
7463 unsigned int msb;
7465 /* #0 in second position is alternative syntax for bfc, which is
7466 the same instruction but with REG_PC in the Rm field. */
7467 if (!inst.operands[1].isreg)
7468 inst.operands[1].reg = REG_PC;
7470 msb = inst.operands[2].imm + inst.operands[3].imm;
7471 constraint (msb > 32, _("bit-field extends past end of register"));
7472 /* The instruction encoding stores the LSB and MSB,
7473 not the LSB and width. */
7474 inst.instruction |= inst.operands[0].reg << 12;
7475 inst.instruction |= inst.operands[1].reg;
7476 inst.instruction |= inst.operands[2].imm << 7;
7477 inst.instruction |= (msb - 1) << 16;
7480 static void
7481 do_bfx (void)
7483 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7484 _("bit-field extends past end of register"));
7485 inst.instruction |= inst.operands[0].reg << 12;
7486 inst.instruction |= inst.operands[1].reg;
7487 inst.instruction |= inst.operands[2].imm << 7;
7488 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7491 /* ARM V5 breakpoint instruction (argument parse)
7492 BKPT <16 bit unsigned immediate>
7493 Instruction is not conditional.
7494 The bit pattern given in insns[] has the COND_ALWAYS condition,
7495 and it is an error if the caller tried to override that. */
7497 static void
7498 do_bkpt (void)
7500 /* Top 12 of 16 bits to bits 19:8. */
7501 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
7503 /* Bottom 4 of 16 bits to bits 3:0. */
7504 inst.instruction |= inst.operands[0].imm & 0xf;
7507 static void
7508 encode_branch (int default_reloc)
7510 if (inst.operands[0].hasreloc)
7512 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7513 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7514 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7515 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7516 ? BFD_RELOC_ARM_PLT32
7517 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
7519 else
7520 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
7521 inst.reloc.pc_rel = 1;
7524 static void
7525 do_branch (void)
7527 #ifdef OBJ_ELF
7528 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7529 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7530 else
7531 #endif
7532 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7535 static void
7536 do_bl (void)
7538 #ifdef OBJ_ELF
7539 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7541 if (inst.cond == COND_ALWAYS)
7542 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7543 else
7544 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7546 else
7547 #endif
7548 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7551 /* ARM V5 branch-link-exchange instruction (argument parse)
7552 BLX <target_addr> ie BLX(1)
7553 BLX{<condition>} <Rm> ie BLX(2)
7554 Unfortunately, there are two different opcodes for this mnemonic.
7555 So, the insns[].value is not used, and the code here zaps values
7556 into inst.instruction.
7557 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
7559 static void
7560 do_blx (void)
7562 if (inst.operands[0].isreg)
7564 /* Arg is a register; the opcode provided by insns[] is correct.
7565 It is not illegal to do "blx pc", just useless. */
7566 if (inst.operands[0].reg == REG_PC)
7567 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
7569 inst.instruction |= inst.operands[0].reg;
7571 else
7573 /* Arg is an address; this instruction cannot be executed
7574 conditionally, and the opcode must be adjusted.
7575 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7576 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
7577 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7578 inst.instruction = 0xfa000000;
7579 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
7583 static void
7584 do_bx (void)
7586 bfd_boolean want_reloc;
7588 if (inst.operands[0].reg == REG_PC)
7589 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
7591 inst.instruction |= inst.operands[0].reg;
7592 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7593 it is for ARMv4t or earlier. */
7594 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7595 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7596 want_reloc = TRUE;
7598 #ifdef OBJ_ELF
7599 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
7600 #endif
7601 want_reloc = FALSE;
7603 if (want_reloc)
7604 inst.reloc.type = BFD_RELOC_ARM_V4BX;
7608 /* ARM v5TEJ. Jump to Jazelle code. */
7610 static void
7611 do_bxj (void)
7613 if (inst.operands[0].reg == REG_PC)
7614 as_tsktsk (_("use of r15 in bxj is not really useful"));
7616 inst.instruction |= inst.operands[0].reg;
7619 /* Co-processor data operation:
7620 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7621 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7622 static void
7623 do_cdp (void)
7625 inst.instruction |= inst.operands[0].reg << 8;
7626 inst.instruction |= inst.operands[1].imm << 20;
7627 inst.instruction |= inst.operands[2].reg << 12;
7628 inst.instruction |= inst.operands[3].reg << 16;
7629 inst.instruction |= inst.operands[4].reg;
7630 inst.instruction |= inst.operands[5].imm << 5;
7633 static void
7634 do_cmp (void)
7636 inst.instruction |= inst.operands[0].reg << 16;
7637 encode_arm_shifter_operand (1);
7640 /* Transfer between coprocessor and ARM registers.
7641 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7642 MRC2
7643 MCR{cond}
7644 MCR2
7646 No special properties. */
7648 static void
7649 do_co_reg (void)
7651 unsigned Rd;
7653 Rd = inst.operands[2].reg;
7654 if (thumb_mode)
7656 if (inst.instruction == 0xee000010
7657 || inst.instruction == 0xfe000010)
7658 /* MCR, MCR2 */
7659 reject_bad_reg (Rd);
7660 else
7661 /* MRC, MRC2 */
7662 constraint (Rd == REG_SP, BAD_SP);
7664 else
7666 /* MCR */
7667 if (inst.instruction == 0xe000010)
7668 constraint (Rd == REG_PC, BAD_PC);
7672 inst.instruction |= inst.operands[0].reg << 8;
7673 inst.instruction |= inst.operands[1].imm << 21;
7674 inst.instruction |= Rd << 12;
7675 inst.instruction |= inst.operands[3].reg << 16;
7676 inst.instruction |= inst.operands[4].reg;
7677 inst.instruction |= inst.operands[5].imm << 5;
7680 /* Transfer between coprocessor register and pair of ARM registers.
7681 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7682 MCRR2
7683 MRRC{cond}
7684 MRRC2
7686 Two XScale instructions are special cases of these:
7688 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7689 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
7691 Result unpredictable if Rd or Rn is R15. */
7693 static void
7694 do_co_reg2c (void)
7696 unsigned Rd, Rn;
7698 Rd = inst.operands[2].reg;
7699 Rn = inst.operands[3].reg;
7701 if (thumb_mode)
7703 reject_bad_reg (Rd);
7704 reject_bad_reg (Rn);
7706 else
7708 constraint (Rd == REG_PC, BAD_PC);
7709 constraint (Rn == REG_PC, BAD_PC);
7712 inst.instruction |= inst.operands[0].reg << 8;
7713 inst.instruction |= inst.operands[1].imm << 4;
7714 inst.instruction |= Rd << 12;
7715 inst.instruction |= Rn << 16;
7716 inst.instruction |= inst.operands[4].reg;
7719 static void
7720 do_cpsi (void)
7722 inst.instruction |= inst.operands[0].imm << 6;
7723 if (inst.operands[1].present)
7725 inst.instruction |= CPSI_MMOD;
7726 inst.instruction |= inst.operands[1].imm;
7730 static void
7731 do_dbg (void)
7733 inst.instruction |= inst.operands[0].imm;
7736 static void
7737 do_div (void)
7739 unsigned Rd, Rn, Rm;
7741 Rd = inst.operands[0].reg;
7742 Rn = (inst.operands[1].present
7743 ? inst.operands[1].reg : Rd);
7744 Rm = inst.operands[2].reg;
7746 constraint ((Rd == REG_PC), BAD_PC);
7747 constraint ((Rn == REG_PC), BAD_PC);
7748 constraint ((Rm == REG_PC), BAD_PC);
7750 inst.instruction |= Rd << 16;
7751 inst.instruction |= Rn << 0;
7752 inst.instruction |= Rm << 8;
7755 static void
7756 do_it (void)
7758 /* There is no IT instruction in ARM mode. We
7759 process it to do the validation as if in
7760 thumb mode, just in case the code gets
7761 assembled for thumb using the unified syntax. */
7763 inst.size = 0;
7764 if (unified_syntax)
7766 set_it_insn_type (IT_INSN);
7767 now_it.mask = (inst.instruction & 0xf) | 0x10;
7768 now_it.cc = inst.operands[0].imm;
7772 static void
7773 do_ldmstm (void)
7775 int base_reg = inst.operands[0].reg;
7776 int range = inst.operands[1].imm;
7778 inst.instruction |= base_reg << 16;
7779 inst.instruction |= range;
7781 if (inst.operands[1].writeback)
7782 inst.instruction |= LDM_TYPE_2_OR_3;
7784 if (inst.operands[0].writeback)
7786 inst.instruction |= WRITE_BACK;
7787 /* Check for unpredictable uses of writeback. */
7788 if (inst.instruction & LOAD_BIT)
7790 /* Not allowed in LDM type 2. */
7791 if ((inst.instruction & LDM_TYPE_2_OR_3)
7792 && ((range & (1 << REG_PC)) == 0))
7793 as_warn (_("writeback of base register is UNPREDICTABLE"));
7794 /* Only allowed if base reg not in list for other types. */
7795 else if (range & (1 << base_reg))
7796 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7798 else /* STM. */
7800 /* Not allowed for type 2. */
7801 if (inst.instruction & LDM_TYPE_2_OR_3)
7802 as_warn (_("writeback of base register is UNPREDICTABLE"));
7803 /* Only allowed if base reg not in list, or first in list. */
7804 else if ((range & (1 << base_reg))
7805 && (range & ((1 << base_reg) - 1)))
7806 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7811 /* ARMv5TE load-consecutive (argument parse)
7812 Mode is like LDRH.
7814 LDRccD R, mode
7815 STRccD R, mode. */
7817 static void
7818 do_ldrd (void)
7820 constraint (inst.operands[0].reg % 2 != 0,
7821 _("first transfer register must be even"));
7822 constraint (inst.operands[1].present
7823 && inst.operands[1].reg != inst.operands[0].reg + 1,
7824 _("can only transfer two consecutive registers"));
7825 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7826 constraint (!inst.operands[2].isreg, _("'[' expected"));
7828 if (!inst.operands[1].present)
7829 inst.operands[1].reg = inst.operands[0].reg + 1;
7831 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7832 register and the first register written; we have to diagnose
7833 overlap between the base and the second register written here. */
7835 if (inst.operands[2].reg == inst.operands[1].reg
7836 && (inst.operands[2].writeback || inst.operands[2].postind))
7837 as_warn (_("base register written back, and overlaps "
7838 "second transfer register"));
7840 if (!(inst.instruction & V4_STR_BIT))
7842 /* For an index-register load, the index register must not overlap the
7843 destination (even if not write-back). */
7844 if (inst.operands[2].immisreg
7845 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7846 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7847 as_warn (_("index register overlaps transfer register"));
7849 inst.instruction |= inst.operands[0].reg << 12;
7850 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
7853 static void
7854 do_ldrex (void)
7856 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7857 || inst.operands[1].postind || inst.operands[1].writeback
7858 || inst.operands[1].immisreg || inst.operands[1].shifted
7859 || inst.operands[1].negative
7860 /* This can arise if the programmer has written
7861 strex rN, rM, foo
7862 or if they have mistakenly used a register name as the last
7863 operand, eg:
7864 strex rN, rM, rX
7865 It is very difficult to distinguish between these two cases
7866 because "rX" might actually be a label. ie the register
7867 name has been occluded by a symbol of the same name. So we
7868 just generate a general 'bad addressing mode' type error
7869 message and leave it up to the programmer to discover the
7870 true cause and fix their mistake. */
7871 || (inst.operands[1].reg == REG_PC),
7872 BAD_ADDR_MODE);
7874 constraint (inst.reloc.exp.X_op != O_constant
7875 || inst.reloc.exp.X_add_number != 0,
7876 _("offset must be zero in ARM encoding"));
7878 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7880 inst.instruction |= inst.operands[0].reg << 12;
7881 inst.instruction |= inst.operands[1].reg << 16;
7882 inst.reloc.type = BFD_RELOC_UNUSED;
7885 static void
7886 do_ldrexd (void)
7888 constraint (inst.operands[0].reg % 2 != 0,
7889 _("even register required"));
7890 constraint (inst.operands[1].present
7891 && inst.operands[1].reg != inst.operands[0].reg + 1,
7892 _("can only load two consecutive registers"));
7893 /* If op 1 were present and equal to PC, this function wouldn't
7894 have been called in the first place. */
7895 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7897 inst.instruction |= inst.operands[0].reg << 12;
7898 inst.instruction |= inst.operands[2].reg << 16;
7901 static void
7902 do_ldst (void)
7904 inst.instruction |= inst.operands[0].reg << 12;
7905 if (!inst.operands[1].isreg)
7906 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7907 return;
7908 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7911 static void
7912 do_ldstt (void)
7914 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7915 reject [Rn,...]. */
7916 if (inst.operands[1].preind)
7918 constraint (inst.reloc.exp.X_op != O_constant
7919 || inst.reloc.exp.X_add_number != 0,
7920 _("this instruction requires a post-indexed address"));
7922 inst.operands[1].preind = 0;
7923 inst.operands[1].postind = 1;
7924 inst.operands[1].writeback = 1;
7926 inst.instruction |= inst.operands[0].reg << 12;
7927 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7930 /* Halfword and signed-byte load/store operations. */
7932 static void
7933 do_ldstv4 (void)
7935 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7936 inst.instruction |= inst.operands[0].reg << 12;
7937 if (!inst.operands[1].isreg)
7938 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7939 return;
7940 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7943 static void
7944 do_ldsttv4 (void)
7946 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7947 reject [Rn,...]. */
7948 if (inst.operands[1].preind)
7950 constraint (inst.reloc.exp.X_op != O_constant
7951 || inst.reloc.exp.X_add_number != 0,
7952 _("this instruction requires a post-indexed address"));
7954 inst.operands[1].preind = 0;
7955 inst.operands[1].postind = 1;
7956 inst.operands[1].writeback = 1;
7958 inst.instruction |= inst.operands[0].reg << 12;
7959 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7962 /* Co-processor register load/store.
7963 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7964 static void
7965 do_lstc (void)
7967 inst.instruction |= inst.operands[0].reg << 8;
7968 inst.instruction |= inst.operands[1].reg << 12;
7969 encode_arm_cp_address (2, TRUE, TRUE, 0);
7972 static void
7973 do_mlas (void)
7975 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7976 if (inst.operands[0].reg == inst.operands[1].reg
7977 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7978 && !(inst.instruction & 0x00400000))
7979 as_tsktsk (_("Rd and Rm should be different in mla"));
7981 inst.instruction |= inst.operands[0].reg << 16;
7982 inst.instruction |= inst.operands[1].reg;
7983 inst.instruction |= inst.operands[2].reg << 8;
7984 inst.instruction |= inst.operands[3].reg << 12;
7987 static void
7988 do_mov (void)
7990 inst.instruction |= inst.operands[0].reg << 12;
7991 encode_arm_shifter_operand (1);
7994 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7995 static void
7996 do_mov16 (void)
7998 bfd_vma imm;
7999 bfd_boolean top;
8001 top = (inst.instruction & 0x00400000) != 0;
8002 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8003 _(":lower16: not allowed this instruction"));
8004 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8005 _(":upper16: not allowed instruction"));
8006 inst.instruction |= inst.operands[0].reg << 12;
8007 if (inst.reloc.type == BFD_RELOC_UNUSED)
8009 imm = inst.reloc.exp.X_add_number;
8010 /* The value is in two pieces: 0:11, 16:19. */
8011 inst.instruction |= (imm & 0x00000fff);
8012 inst.instruction |= (imm & 0x0000f000) << 4;
8016 static void do_vfp_nsyn_opcode (const char *);
8018 static int
8019 do_vfp_nsyn_mrs (void)
8021 if (inst.operands[0].isvec)
8023 if (inst.operands[1].reg != 1)
8024 first_error (_("operand 1 must be FPSCR"));
8025 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8026 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8027 do_vfp_nsyn_opcode ("fmstat");
8029 else if (inst.operands[1].isvec)
8030 do_vfp_nsyn_opcode ("fmrx");
8031 else
8032 return FAIL;
8034 return SUCCESS;
8037 static int
8038 do_vfp_nsyn_msr (void)
8040 if (inst.operands[0].isvec)
8041 do_vfp_nsyn_opcode ("fmxr");
8042 else
8043 return FAIL;
8045 return SUCCESS;
8048 static void
8049 do_vmrs (void)
8051 unsigned Rt = inst.operands[0].reg;
8053 if (thumb_mode && inst.operands[0].reg == REG_SP)
8055 inst.error = BAD_SP;
8056 return;
8059 /* APSR_ sets isvec. All other refs to PC are illegal. */
8060 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
8062 inst.error = BAD_PC;
8063 return;
8066 if (inst.operands[1].reg != 1)
8067 first_error (_("operand 1 must be FPSCR"));
8069 inst.instruction |= (Rt << 12);
8072 static void
8073 do_vmsr (void)
8075 unsigned Rt = inst.operands[1].reg;
8077 if (thumb_mode)
8078 reject_bad_reg (Rt);
8079 else if (Rt == REG_PC)
8081 inst.error = BAD_PC;
8082 return;
8085 if (inst.operands[0].reg != 1)
8086 first_error (_("operand 0 must be FPSCR"));
8088 inst.instruction |= (Rt << 12);
8091 static void
8092 do_mrs (void)
8094 unsigned br;
8096 if (do_vfp_nsyn_mrs () == SUCCESS)
8097 return;
8099 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8100 inst.instruction |= inst.operands[0].reg << 12;
8102 if (inst.operands[1].isreg)
8104 br = inst.operands[1].reg;
8105 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8106 as_bad (_("bad register for mrs"));
8108 else
8110 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8111 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8112 != (PSR_c|PSR_f),
8113 _("'APSR', 'CPSR' or 'SPSR' expected"));
8114 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8117 inst.instruction |= br;
8120 /* Two possible forms:
8121 "{C|S}PSR_<field>, Rm",
8122 "{C|S}PSR_f, #expression". */
8124 static void
8125 do_msr (void)
8127 if (do_vfp_nsyn_msr () == SUCCESS)
8128 return;
8130 inst.instruction |= inst.operands[0].imm;
8131 if (inst.operands[1].isreg)
8132 inst.instruction |= inst.operands[1].reg;
8133 else
8135 inst.instruction |= INST_IMMEDIATE;
8136 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8137 inst.reloc.pc_rel = 0;
8141 static void
8142 do_mul (void)
8144 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8146 if (!inst.operands[2].present)
8147 inst.operands[2].reg = inst.operands[0].reg;
8148 inst.instruction |= inst.operands[0].reg << 16;
8149 inst.instruction |= inst.operands[1].reg;
8150 inst.instruction |= inst.operands[2].reg << 8;
8152 if (inst.operands[0].reg == inst.operands[1].reg
8153 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8154 as_tsktsk (_("Rd and Rm should be different in mul"));
8157 /* Long Multiply Parser
8158 UMULL RdLo, RdHi, Rm, Rs
8159 SMULL RdLo, RdHi, Rm, Rs
8160 UMLAL RdLo, RdHi, Rm, Rs
8161 SMLAL RdLo, RdHi, Rm, Rs. */
8163 static void
8164 do_mull (void)
8166 inst.instruction |= inst.operands[0].reg << 12;
8167 inst.instruction |= inst.operands[1].reg << 16;
8168 inst.instruction |= inst.operands[2].reg;
8169 inst.instruction |= inst.operands[3].reg << 8;
8171 /* rdhi and rdlo must be different. */
8172 if (inst.operands[0].reg == inst.operands[1].reg)
8173 as_tsktsk (_("rdhi and rdlo must be different"));
8175 /* rdhi, rdlo and rm must all be different before armv6. */
8176 if ((inst.operands[0].reg == inst.operands[2].reg
8177 || inst.operands[1].reg == inst.operands[2].reg)
8178 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8179 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8182 static void
8183 do_nop (void)
8185 if (inst.operands[0].present
8186 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
8188 /* Architectural NOP hints are CPSR sets with no bits selected. */
8189 inst.instruction &= 0xf0000000;
8190 inst.instruction |= 0x0320f000;
8191 if (inst.operands[0].present)
8192 inst.instruction |= inst.operands[0].imm;
8196 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8197 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8198 Condition defaults to COND_ALWAYS.
8199 Error if Rd, Rn or Rm are R15. */
8201 static void
8202 do_pkhbt (void)
8204 inst.instruction |= inst.operands[0].reg << 12;
8205 inst.instruction |= inst.operands[1].reg << 16;
8206 inst.instruction |= inst.operands[2].reg;
8207 if (inst.operands[3].present)
8208 encode_arm_shift (3);
8211 /* ARM V6 PKHTB (Argument Parse). */
8213 static void
8214 do_pkhtb (void)
8216 if (!inst.operands[3].present)
8218 /* If the shift specifier is omitted, turn the instruction
8219 into pkhbt rd, rm, rn. */
8220 inst.instruction &= 0xfff00010;
8221 inst.instruction |= inst.operands[0].reg << 12;
8222 inst.instruction |= inst.operands[1].reg;
8223 inst.instruction |= inst.operands[2].reg << 16;
8225 else
8227 inst.instruction |= inst.operands[0].reg << 12;
8228 inst.instruction |= inst.operands[1].reg << 16;
8229 inst.instruction |= inst.operands[2].reg;
8230 encode_arm_shift (3);
8234 /* ARMv5TE: Preload-Cache
8235 MP Extensions: Preload for write
8237 PLD(W) <addr_mode>
8239 Syntactically, like LDR with B=1, W=0, L=1. */
8241 static void
8242 do_pld (void)
8244 constraint (!inst.operands[0].isreg,
8245 _("'[' expected after PLD mnemonic"));
8246 constraint (inst.operands[0].postind,
8247 _("post-indexed expression used in preload instruction"));
8248 constraint (inst.operands[0].writeback,
8249 _("writeback used in preload instruction"));
8250 constraint (!inst.operands[0].preind,
8251 _("unindexed addressing used in preload instruction"));
8252 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8255 /* ARMv7: PLI <addr_mode> */
8256 static void
8257 do_pli (void)
8259 constraint (!inst.operands[0].isreg,
8260 _("'[' expected after PLI mnemonic"));
8261 constraint (inst.operands[0].postind,
8262 _("post-indexed expression used in preload instruction"));
8263 constraint (inst.operands[0].writeback,
8264 _("writeback used in preload instruction"));
8265 constraint (!inst.operands[0].preind,
8266 _("unindexed addressing used in preload instruction"));
8267 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8268 inst.instruction &= ~PRE_INDEX;
8271 static void
8272 do_push_pop (void)
8274 inst.operands[1] = inst.operands[0];
8275 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8276 inst.operands[0].isreg = 1;
8277 inst.operands[0].writeback = 1;
8278 inst.operands[0].reg = REG_SP;
8279 do_ldmstm ();
8282 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8283 word at the specified address and the following word
8284 respectively.
8285 Unconditionally executed.
8286 Error if Rn is R15. */
8288 static void
8289 do_rfe (void)
8291 inst.instruction |= inst.operands[0].reg << 16;
8292 if (inst.operands[0].writeback)
8293 inst.instruction |= WRITE_BACK;
8296 /* ARM V6 ssat (argument parse). */
8298 static void
8299 do_ssat (void)
8301 inst.instruction |= inst.operands[0].reg << 12;
8302 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8303 inst.instruction |= inst.operands[2].reg;
8305 if (inst.operands[3].present)
8306 encode_arm_shift (3);
8309 /* ARM V6 usat (argument parse). */
8311 static void
8312 do_usat (void)
8314 inst.instruction |= inst.operands[0].reg << 12;
8315 inst.instruction |= inst.operands[1].imm << 16;
8316 inst.instruction |= inst.operands[2].reg;
8318 if (inst.operands[3].present)
8319 encode_arm_shift (3);
8322 /* ARM V6 ssat16 (argument parse). */
8324 static void
8325 do_ssat16 (void)
8327 inst.instruction |= inst.operands[0].reg << 12;
8328 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8329 inst.instruction |= inst.operands[2].reg;
8332 static void
8333 do_usat16 (void)
8335 inst.instruction |= inst.operands[0].reg << 12;
8336 inst.instruction |= inst.operands[1].imm << 16;
8337 inst.instruction |= inst.operands[2].reg;
8340 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8341 preserving the other bits.
8343 setend <endian_specifier>, where <endian_specifier> is either
8344 BE or LE. */
8346 static void
8347 do_setend (void)
8349 if (inst.operands[0].imm)
8350 inst.instruction |= 0x200;
8353 static void
8354 do_shift (void)
8356 unsigned int Rm = (inst.operands[1].present
8357 ? inst.operands[1].reg
8358 : inst.operands[0].reg);
8360 inst.instruction |= inst.operands[0].reg << 12;
8361 inst.instruction |= Rm;
8362 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
8364 inst.instruction |= inst.operands[2].reg << 8;
8365 inst.instruction |= SHIFT_BY_REG;
8366 /* PR 12854: Error on extraneous shifts. */
8367 constraint (inst.operands[2].shifted,
8368 _("extraneous shift as part of operand to shift insn"));
8370 else
8371 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
8374 static void
8375 do_smc (void)
8377 inst.reloc.type = BFD_RELOC_ARM_SMC;
8378 inst.reloc.pc_rel = 0;
8381 static void
8382 do_hvc (void)
8384 inst.reloc.type = BFD_RELOC_ARM_HVC;
8385 inst.reloc.pc_rel = 0;
8388 static void
8389 do_swi (void)
8391 inst.reloc.type = BFD_RELOC_ARM_SWI;
8392 inst.reloc.pc_rel = 0;
8395 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8396 SMLAxy{cond} Rd,Rm,Rs,Rn
8397 SMLAWy{cond} Rd,Rm,Rs,Rn
8398 Error if any register is R15. */
8400 static void
8401 do_smla (void)
8403 inst.instruction |= inst.operands[0].reg << 16;
8404 inst.instruction |= inst.operands[1].reg;
8405 inst.instruction |= inst.operands[2].reg << 8;
8406 inst.instruction |= inst.operands[3].reg << 12;
8409 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8410 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8411 Error if any register is R15.
8412 Warning if Rdlo == Rdhi. */
8414 static void
8415 do_smlal (void)
8417 inst.instruction |= inst.operands[0].reg << 12;
8418 inst.instruction |= inst.operands[1].reg << 16;
8419 inst.instruction |= inst.operands[2].reg;
8420 inst.instruction |= inst.operands[3].reg << 8;
8422 if (inst.operands[0].reg == inst.operands[1].reg)
8423 as_tsktsk (_("rdhi and rdlo must be different"));
8426 /* ARM V5E (El Segundo) signed-multiply (argument parse)
8427 SMULxy{cond} Rd,Rm,Rs
8428 Error if any register is R15. */
8430 static void
8431 do_smul (void)
8433 inst.instruction |= inst.operands[0].reg << 16;
8434 inst.instruction |= inst.operands[1].reg;
8435 inst.instruction |= inst.operands[2].reg << 8;
8438 /* ARM V6 srs (argument parse). The variable fields in the encoding are
8439 the same for both ARM and Thumb-2. */
8441 static void
8442 do_srs (void)
8444 int reg;
8446 if (inst.operands[0].present)
8448 reg = inst.operands[0].reg;
8449 constraint (reg != REG_SP, _("SRS base register must be r13"));
8451 else
8452 reg = REG_SP;
8454 inst.instruction |= reg << 16;
8455 inst.instruction |= inst.operands[1].imm;
8456 if (inst.operands[0].writeback || inst.operands[1].writeback)
8457 inst.instruction |= WRITE_BACK;
8460 /* ARM V6 strex (argument parse). */
8462 static void
8463 do_strex (void)
8465 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8466 || inst.operands[2].postind || inst.operands[2].writeback
8467 || inst.operands[2].immisreg || inst.operands[2].shifted
8468 || inst.operands[2].negative
8469 /* See comment in do_ldrex(). */
8470 || (inst.operands[2].reg == REG_PC),
8471 BAD_ADDR_MODE);
8473 constraint (inst.operands[0].reg == inst.operands[1].reg
8474 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8476 constraint (inst.reloc.exp.X_op != O_constant
8477 || inst.reloc.exp.X_add_number != 0,
8478 _("offset must be zero in ARM encoding"));
8480 inst.instruction |= inst.operands[0].reg << 12;
8481 inst.instruction |= inst.operands[1].reg;
8482 inst.instruction |= inst.operands[2].reg << 16;
8483 inst.reloc.type = BFD_RELOC_UNUSED;
8486 static void
8487 do_strexd (void)
8489 constraint (inst.operands[1].reg % 2 != 0,
8490 _("even register required"));
8491 constraint (inst.operands[2].present
8492 && inst.operands[2].reg != inst.operands[1].reg + 1,
8493 _("can only store two consecutive registers"));
8494 /* If op 2 were present and equal to PC, this function wouldn't
8495 have been called in the first place. */
8496 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
8498 constraint (inst.operands[0].reg == inst.operands[1].reg
8499 || inst.operands[0].reg == inst.operands[1].reg + 1
8500 || inst.operands[0].reg == inst.operands[3].reg,
8501 BAD_OVERLAP);
8503 inst.instruction |= inst.operands[0].reg << 12;
8504 inst.instruction |= inst.operands[1].reg;
8505 inst.instruction |= inst.operands[3].reg << 16;
8508 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8509 extends it to 32-bits, and adds the result to a value in another
8510 register. You can specify a rotation by 0, 8, 16, or 24 bits
8511 before extracting the 16-bit value.
8512 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8513 Condition defaults to COND_ALWAYS.
8514 Error if any register uses R15. */
8516 static void
8517 do_sxtah (void)
8519 inst.instruction |= inst.operands[0].reg << 12;
8520 inst.instruction |= inst.operands[1].reg << 16;
8521 inst.instruction |= inst.operands[2].reg;
8522 inst.instruction |= inst.operands[3].imm << 10;
8525 /* ARM V6 SXTH.
8527 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8528 Condition defaults to COND_ALWAYS.
8529 Error if any register uses R15. */
8531 static void
8532 do_sxth (void)
8534 inst.instruction |= inst.operands[0].reg << 12;
8535 inst.instruction |= inst.operands[1].reg;
8536 inst.instruction |= inst.operands[2].imm << 10;
8539 /* VFP instructions. In a logical order: SP variant first, monad
8540 before dyad, arithmetic then move then load/store. */
8542 static void
8543 do_vfp_sp_monadic (void)
8545 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8546 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8549 static void
8550 do_vfp_sp_dyadic (void)
8552 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8553 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8554 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8557 static void
8558 do_vfp_sp_compare_z (void)
8560 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8563 static void
8564 do_vfp_dp_sp_cvt (void)
8566 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8567 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8570 static void
8571 do_vfp_sp_dp_cvt (void)
8573 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8574 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8577 static void
8578 do_vfp_reg_from_sp (void)
8580 inst.instruction |= inst.operands[0].reg << 12;
8581 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8584 static void
8585 do_vfp_reg2_from_sp2 (void)
8587 constraint (inst.operands[2].imm != 2,
8588 _("only two consecutive VFP SP registers allowed here"));
8589 inst.instruction |= inst.operands[0].reg << 12;
8590 inst.instruction |= inst.operands[1].reg << 16;
8591 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8594 static void
8595 do_vfp_sp_from_reg (void)
8597 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
8598 inst.instruction |= inst.operands[1].reg << 12;
8601 static void
8602 do_vfp_sp2_from_reg2 (void)
8604 constraint (inst.operands[0].imm != 2,
8605 _("only two consecutive VFP SP registers allowed here"));
8606 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
8607 inst.instruction |= inst.operands[1].reg << 12;
8608 inst.instruction |= inst.operands[2].reg << 16;
8611 static void
8612 do_vfp_sp_ldst (void)
8614 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8615 encode_arm_cp_address (1, FALSE, TRUE, 0);
8618 static void
8619 do_vfp_dp_ldst (void)
8621 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8622 encode_arm_cp_address (1, FALSE, TRUE, 0);
8626 static void
8627 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
8629 if (inst.operands[0].writeback)
8630 inst.instruction |= WRITE_BACK;
8631 else
8632 constraint (ldstm_type != VFP_LDSTMIA,
8633 _("this addressing mode requires base-register writeback"));
8634 inst.instruction |= inst.operands[0].reg << 16;
8635 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
8636 inst.instruction |= inst.operands[1].imm;
8639 static void
8640 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
8642 int count;
8644 if (inst.operands[0].writeback)
8645 inst.instruction |= WRITE_BACK;
8646 else
8647 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8648 _("this addressing mode requires base-register writeback"));
8650 inst.instruction |= inst.operands[0].reg << 16;
8651 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8653 count = inst.operands[1].imm << 1;
8654 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8655 count += 1;
8657 inst.instruction |= count;
8660 static void
8661 do_vfp_sp_ldstmia (void)
8663 vfp_sp_ldstm (VFP_LDSTMIA);
8666 static void
8667 do_vfp_sp_ldstmdb (void)
8669 vfp_sp_ldstm (VFP_LDSTMDB);
8672 static void
8673 do_vfp_dp_ldstmia (void)
8675 vfp_dp_ldstm (VFP_LDSTMIA);
8678 static void
8679 do_vfp_dp_ldstmdb (void)
8681 vfp_dp_ldstm (VFP_LDSTMDB);
8684 static void
8685 do_vfp_xp_ldstmia (void)
8687 vfp_dp_ldstm (VFP_LDSTMIAX);
8690 static void
8691 do_vfp_xp_ldstmdb (void)
8693 vfp_dp_ldstm (VFP_LDSTMDBX);
8696 static void
8697 do_vfp_dp_rd_rm (void)
8699 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8700 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8703 static void
8704 do_vfp_dp_rn_rd (void)
8706 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8707 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8710 static void
8711 do_vfp_dp_rd_rn (void)
8713 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8714 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8717 static void
8718 do_vfp_dp_rd_rn_rm (void)
8720 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8721 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8722 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8725 static void
8726 do_vfp_dp_rd (void)
8728 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8731 static void
8732 do_vfp_dp_rm_rd_rn (void)
8734 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8735 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8736 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8739 /* VFPv3 instructions. */
8740 static void
8741 do_vfp_sp_const (void)
8743 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8744 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8745 inst.instruction |= (inst.operands[1].imm & 0x0f);
8748 static void
8749 do_vfp_dp_const (void)
8751 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8752 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8753 inst.instruction |= (inst.operands[1].imm & 0x0f);
8756 static void
8757 vfp_conv (int srcsize)
8759 int immbits = srcsize - inst.operands[1].imm;
8761 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
8763 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
8764 i.e. immbits must be in range 0 - 16. */
8765 inst.error = _("immediate value out of range, expected range [0, 16]");
8766 return;
8768 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
8770 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
8771 i.e. immbits must be in range 0 - 31. */
8772 inst.error = _("immediate value out of range, expected range [1, 32]");
8773 return;
8776 inst.instruction |= (immbits & 1) << 5;
8777 inst.instruction |= (immbits >> 1);
8780 static void
8781 do_vfp_sp_conv_16 (void)
8783 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8784 vfp_conv (16);
8787 static void
8788 do_vfp_dp_conv_16 (void)
8790 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8791 vfp_conv (16);
8794 static void
8795 do_vfp_sp_conv_32 (void)
8797 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8798 vfp_conv (32);
8801 static void
8802 do_vfp_dp_conv_32 (void)
8804 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8805 vfp_conv (32);
8808 /* FPA instructions. Also in a logical order. */
8810 static void
8811 do_fpa_cmp (void)
8813 inst.instruction |= inst.operands[0].reg << 16;
8814 inst.instruction |= inst.operands[1].reg;
8817 static void
8818 do_fpa_ldmstm (void)
8820 inst.instruction |= inst.operands[0].reg << 12;
8821 switch (inst.operands[1].imm)
8823 case 1: inst.instruction |= CP_T_X; break;
8824 case 2: inst.instruction |= CP_T_Y; break;
8825 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8826 case 4: break;
8827 default: abort ();
8830 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8832 /* The instruction specified "ea" or "fd", so we can only accept
8833 [Rn]{!}. The instruction does not really support stacking or
8834 unstacking, so we have to emulate these by setting appropriate
8835 bits and offsets. */
8836 constraint (inst.reloc.exp.X_op != O_constant
8837 || inst.reloc.exp.X_add_number != 0,
8838 _("this instruction does not support indexing"));
8840 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8841 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
8843 if (!(inst.instruction & INDEX_UP))
8844 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
8846 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8848 inst.operands[2].preind = 0;
8849 inst.operands[2].postind = 1;
8853 encode_arm_cp_address (2, TRUE, TRUE, 0);
8856 /* iWMMXt instructions: strictly in alphabetical order. */
8858 static void
8859 do_iwmmxt_tandorc (void)
8861 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8864 static void
8865 do_iwmmxt_textrc (void)
8867 inst.instruction |= inst.operands[0].reg << 12;
8868 inst.instruction |= inst.operands[1].imm;
8871 static void
8872 do_iwmmxt_textrm (void)
8874 inst.instruction |= inst.operands[0].reg << 12;
8875 inst.instruction |= inst.operands[1].reg << 16;
8876 inst.instruction |= inst.operands[2].imm;
8879 static void
8880 do_iwmmxt_tinsr (void)
8882 inst.instruction |= inst.operands[0].reg << 16;
8883 inst.instruction |= inst.operands[1].reg << 12;
8884 inst.instruction |= inst.operands[2].imm;
8887 static void
8888 do_iwmmxt_tmia (void)
8890 inst.instruction |= inst.operands[0].reg << 5;
8891 inst.instruction |= inst.operands[1].reg;
8892 inst.instruction |= inst.operands[2].reg << 12;
8895 static void
8896 do_iwmmxt_waligni (void)
8898 inst.instruction |= inst.operands[0].reg << 12;
8899 inst.instruction |= inst.operands[1].reg << 16;
8900 inst.instruction |= inst.operands[2].reg;
8901 inst.instruction |= inst.operands[3].imm << 20;
8904 static void
8905 do_iwmmxt_wmerge (void)
8907 inst.instruction |= inst.operands[0].reg << 12;
8908 inst.instruction |= inst.operands[1].reg << 16;
8909 inst.instruction |= inst.operands[2].reg;
8910 inst.instruction |= inst.operands[3].imm << 21;
8913 static void
8914 do_iwmmxt_wmov (void)
8916 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8917 inst.instruction |= inst.operands[0].reg << 12;
8918 inst.instruction |= inst.operands[1].reg << 16;
8919 inst.instruction |= inst.operands[1].reg;
8922 static void
8923 do_iwmmxt_wldstbh (void)
8925 int reloc;
8926 inst.instruction |= inst.operands[0].reg << 12;
8927 if (thumb_mode)
8928 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8929 else
8930 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8931 encode_arm_cp_address (1, TRUE, FALSE, reloc);
8934 static void
8935 do_iwmmxt_wldstw (void)
8937 /* RIWR_RIWC clears .isreg for a control register. */
8938 if (!inst.operands[0].isreg)
8940 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8941 inst.instruction |= 0xf0000000;
8944 inst.instruction |= inst.operands[0].reg << 12;
8945 encode_arm_cp_address (1, TRUE, TRUE, 0);
8948 static void
8949 do_iwmmxt_wldstd (void)
8951 inst.instruction |= inst.operands[0].reg << 12;
8952 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8953 && inst.operands[1].immisreg)
8955 inst.instruction &= ~0x1a000ff;
8956 inst.instruction |= (0xf << 28);
8957 if (inst.operands[1].preind)
8958 inst.instruction |= PRE_INDEX;
8959 if (!inst.operands[1].negative)
8960 inst.instruction |= INDEX_UP;
8961 if (inst.operands[1].writeback)
8962 inst.instruction |= WRITE_BACK;
8963 inst.instruction |= inst.operands[1].reg << 16;
8964 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8965 inst.instruction |= inst.operands[1].imm;
8967 else
8968 encode_arm_cp_address (1, TRUE, FALSE, 0);
8971 static void
8972 do_iwmmxt_wshufh (void)
8974 inst.instruction |= inst.operands[0].reg << 12;
8975 inst.instruction |= inst.operands[1].reg << 16;
8976 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8977 inst.instruction |= (inst.operands[2].imm & 0x0f);
8980 static void
8981 do_iwmmxt_wzero (void)
8983 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8984 inst.instruction |= inst.operands[0].reg;
8985 inst.instruction |= inst.operands[0].reg << 12;
8986 inst.instruction |= inst.operands[0].reg << 16;
8989 static void
8990 do_iwmmxt_wrwrwr_or_imm5 (void)
8992 if (inst.operands[2].isreg)
8993 do_rd_rn_rm ();
8994 else {
8995 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8996 _("immediate operand requires iWMMXt2"));
8997 do_rd_rn ();
8998 if (inst.operands[2].imm == 0)
9000 switch ((inst.instruction >> 20) & 0xf)
9002 case 4:
9003 case 5:
9004 case 6:
9005 case 7:
9006 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9007 inst.operands[2].imm = 16;
9008 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9009 break;
9010 case 8:
9011 case 9:
9012 case 10:
9013 case 11:
9014 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9015 inst.operands[2].imm = 32;
9016 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9017 break;
9018 case 12:
9019 case 13:
9020 case 14:
9021 case 15:
9023 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9024 unsigned long wrn;
9025 wrn = (inst.instruction >> 16) & 0xf;
9026 inst.instruction &= 0xff0fff0f;
9027 inst.instruction |= wrn;
9028 /* Bail out here; the instruction is now assembled. */
9029 return;
9033 /* Map 32 -> 0, etc. */
9034 inst.operands[2].imm &= 0x1f;
9035 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9039 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9040 operations first, then control, shift, and load/store. */
9042 /* Insns like "foo X,Y,Z". */
9044 static void
9045 do_mav_triple (void)
9047 inst.instruction |= inst.operands[0].reg << 16;
9048 inst.instruction |= inst.operands[1].reg;
9049 inst.instruction |= inst.operands[2].reg << 12;
9052 /* Insns like "foo W,X,Y,Z".
9053 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
9055 static void
9056 do_mav_quad (void)
9058 inst.instruction |= inst.operands[0].reg << 5;
9059 inst.instruction |= inst.operands[1].reg << 12;
9060 inst.instruction |= inst.operands[2].reg << 16;
9061 inst.instruction |= inst.operands[3].reg;
9064 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9065 static void
9066 do_mav_dspsc (void)
9068 inst.instruction |= inst.operands[1].reg << 12;
9071 /* Maverick shift immediate instructions.
9072 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9073 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
9075 static void
9076 do_mav_shift (void)
9078 int imm = inst.operands[2].imm;
9080 inst.instruction |= inst.operands[0].reg << 12;
9081 inst.instruction |= inst.operands[1].reg << 16;
9083 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9084 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9085 Bit 4 should be 0. */
9086 imm = (imm & 0xf) | ((imm & 0x70) << 1);
9088 inst.instruction |= imm;
9091 /* XScale instructions. Also sorted arithmetic before move. */
9093 /* Xscale multiply-accumulate (argument parse)
9094 MIAcc acc0,Rm,Rs
9095 MIAPHcc acc0,Rm,Rs
9096 MIAxycc acc0,Rm,Rs. */
9098 static void
9099 do_xsc_mia (void)
9101 inst.instruction |= inst.operands[1].reg;
9102 inst.instruction |= inst.operands[2].reg << 12;
9105 /* Xscale move-accumulator-register (argument parse)
9107 MARcc acc0,RdLo,RdHi. */
9109 static void
9110 do_xsc_mar (void)
9112 inst.instruction |= inst.operands[1].reg << 12;
9113 inst.instruction |= inst.operands[2].reg << 16;
9116 /* Xscale move-register-accumulator (argument parse)
9118 MRAcc RdLo,RdHi,acc0. */
9120 static void
9121 do_xsc_mra (void)
9123 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9124 inst.instruction |= inst.operands[0].reg << 12;
9125 inst.instruction |= inst.operands[1].reg << 16;
9128 /* Encoding functions relevant only to Thumb. */
9130 /* inst.operands[i] is a shifted-register operand; encode
9131 it into inst.instruction in the format used by Thumb32. */
9133 static void
9134 encode_thumb32_shifted_operand (int i)
9136 unsigned int value = inst.reloc.exp.X_add_number;
9137 unsigned int shift = inst.operands[i].shift_kind;
9139 constraint (inst.operands[i].immisreg,
9140 _("shift by register not allowed in thumb mode"));
9141 inst.instruction |= inst.operands[i].reg;
9142 if (shift == SHIFT_RRX)
9143 inst.instruction |= SHIFT_ROR << 4;
9144 else
9146 constraint (inst.reloc.exp.X_op != O_constant,
9147 _("expression too complex"));
9149 constraint (value > 32
9150 || (value == 32 && (shift == SHIFT_LSL
9151 || shift == SHIFT_ROR)),
9152 _("shift expression is too large"));
9154 if (value == 0)
9155 shift = SHIFT_LSL;
9156 else if (value == 32)
9157 value = 0;
9159 inst.instruction |= shift << 4;
9160 inst.instruction |= (value & 0x1c) << 10;
9161 inst.instruction |= (value & 0x03) << 6;
9166 /* inst.operands[i] was set up by parse_address. Encode it into a
9167 Thumb32 format load or store instruction. Reject forms that cannot
9168 be used with such instructions. If is_t is true, reject forms that
9169 cannot be used with a T instruction; if is_d is true, reject forms
9170 that cannot be used with a D instruction. If it is a store insn,
9171 reject PC in Rn. */
9173 static void
9174 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9176 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
9178 constraint (!inst.operands[i].isreg,
9179 _("Instruction does not support =N addresses"));
9181 inst.instruction |= inst.operands[i].reg << 16;
9182 if (inst.operands[i].immisreg)
9184 constraint (is_pc, BAD_PC_ADDRESSING);
9185 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9186 constraint (inst.operands[i].negative,
9187 _("Thumb does not support negative register indexing"));
9188 constraint (inst.operands[i].postind,
9189 _("Thumb does not support register post-indexing"));
9190 constraint (inst.operands[i].writeback,
9191 _("Thumb does not support register indexing with writeback"));
9192 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9193 _("Thumb supports only LSL in shifted register indexing"));
9195 inst.instruction |= inst.operands[i].imm;
9196 if (inst.operands[i].shifted)
9198 constraint (inst.reloc.exp.X_op != O_constant,
9199 _("expression too complex"));
9200 constraint (inst.reloc.exp.X_add_number < 0
9201 || inst.reloc.exp.X_add_number > 3,
9202 _("shift out of range"));
9203 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9205 inst.reloc.type = BFD_RELOC_UNUSED;
9207 else if (inst.operands[i].preind)
9209 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
9210 constraint (is_t && inst.operands[i].writeback,
9211 _("cannot use writeback with this instruction"));
9212 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9213 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
9215 if (is_d)
9217 inst.instruction |= 0x01000000;
9218 if (inst.operands[i].writeback)
9219 inst.instruction |= 0x00200000;
9221 else
9223 inst.instruction |= 0x00000c00;
9224 if (inst.operands[i].writeback)
9225 inst.instruction |= 0x00000100;
9227 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9229 else if (inst.operands[i].postind)
9231 gas_assert (inst.operands[i].writeback);
9232 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9233 constraint (is_t, _("cannot use post-indexing with this instruction"));
9235 if (is_d)
9236 inst.instruction |= 0x00200000;
9237 else
9238 inst.instruction |= 0x00000900;
9239 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9241 else /* unindexed - only for coprocessor */
9242 inst.error = _("instruction does not accept unindexed addressing");
9245 /* Table of Thumb instructions which exist in both 16- and 32-bit
9246 encodings (the latter only in post-V6T2 cores). The index is the
9247 value used in the insns table below. When there is more than one
9248 possible 16-bit encoding for the instruction, this table always
9249 holds variant (1).
9250 Also contains several pseudo-instructions used during relaxation. */
9251 #define T16_32_TAB \
9252 X(_adc, 4140, eb400000), \
9253 X(_adcs, 4140, eb500000), \
9254 X(_add, 1c00, eb000000), \
9255 X(_adds, 1c00, eb100000), \
9256 X(_addi, 0000, f1000000), \
9257 X(_addis, 0000, f1100000), \
9258 X(_add_pc,000f, f20f0000), \
9259 X(_add_sp,000d, f10d0000), \
9260 X(_adr, 000f, f20f0000), \
9261 X(_and, 4000, ea000000), \
9262 X(_ands, 4000, ea100000), \
9263 X(_asr, 1000, fa40f000), \
9264 X(_asrs, 1000, fa50f000), \
9265 X(_b, e000, f000b000), \
9266 X(_bcond, d000, f0008000), \
9267 X(_bic, 4380, ea200000), \
9268 X(_bics, 4380, ea300000), \
9269 X(_cmn, 42c0, eb100f00), \
9270 X(_cmp, 2800, ebb00f00), \
9271 X(_cpsie, b660, f3af8400), \
9272 X(_cpsid, b670, f3af8600), \
9273 X(_cpy, 4600, ea4f0000), \
9274 X(_dec_sp,80dd, f1ad0d00), \
9275 X(_eor, 4040, ea800000), \
9276 X(_eors, 4040, ea900000), \
9277 X(_inc_sp,00dd, f10d0d00), \
9278 X(_ldmia, c800, e8900000), \
9279 X(_ldr, 6800, f8500000), \
9280 X(_ldrb, 7800, f8100000), \
9281 X(_ldrh, 8800, f8300000), \
9282 X(_ldrsb, 5600, f9100000), \
9283 X(_ldrsh, 5e00, f9300000), \
9284 X(_ldr_pc,4800, f85f0000), \
9285 X(_ldr_pc2,4800, f85f0000), \
9286 X(_ldr_sp,9800, f85d0000), \
9287 X(_lsl, 0000, fa00f000), \
9288 X(_lsls, 0000, fa10f000), \
9289 X(_lsr, 0800, fa20f000), \
9290 X(_lsrs, 0800, fa30f000), \
9291 X(_mov, 2000, ea4f0000), \
9292 X(_movs, 2000, ea5f0000), \
9293 X(_mul, 4340, fb00f000), \
9294 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9295 X(_mvn, 43c0, ea6f0000), \
9296 X(_mvns, 43c0, ea7f0000), \
9297 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9298 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9299 X(_orr, 4300, ea400000), \
9300 X(_orrs, 4300, ea500000), \
9301 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9302 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9303 X(_rev, ba00, fa90f080), \
9304 X(_rev16, ba40, fa90f090), \
9305 X(_revsh, bac0, fa90f0b0), \
9306 X(_ror, 41c0, fa60f000), \
9307 X(_rors, 41c0, fa70f000), \
9308 X(_sbc, 4180, eb600000), \
9309 X(_sbcs, 4180, eb700000), \
9310 X(_stmia, c000, e8800000), \
9311 X(_str, 6000, f8400000), \
9312 X(_strb, 7000, f8000000), \
9313 X(_strh, 8000, f8200000), \
9314 X(_str_sp,9000, f84d0000), \
9315 X(_sub, 1e00, eba00000), \
9316 X(_subs, 1e00, ebb00000), \
9317 X(_subi, 8000, f1a00000), \
9318 X(_subis, 8000, f1b00000), \
9319 X(_sxtb, b240, fa4ff080), \
9320 X(_sxth, b200, fa0ff080), \
9321 X(_tst, 4200, ea100f00), \
9322 X(_uxtb, b2c0, fa5ff080), \
9323 X(_uxth, b280, fa1ff080), \
9324 X(_nop, bf00, f3af8000), \
9325 X(_yield, bf10, f3af8001), \
9326 X(_wfe, bf20, f3af8002), \
9327 X(_wfi, bf30, f3af8003), \
9328 X(_sev, bf40, f3af8004),
9330 /* To catch errors in encoding functions, the codes are all offset by
9331 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9332 as 16-bit instructions. */
9333 #define X(a,b,c) T_MNEM##a
9334 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9335 #undef X
9337 #define X(a,b,c) 0x##b
9338 static const unsigned short thumb_op16[] = { T16_32_TAB };
9339 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9340 #undef X
9342 #define X(a,b,c) 0x##c
9343 static const unsigned int thumb_op32[] = { T16_32_TAB };
9344 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9345 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
9346 #undef X
9347 #undef T16_32_TAB
9349 /* Thumb instruction encoders, in alphabetical order. */
9351 /* ADDW or SUBW. */
9353 static void
9354 do_t_add_sub_w (void)
9356 int Rd, Rn;
9358 Rd = inst.operands[0].reg;
9359 Rn = inst.operands[1].reg;
9361 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9362 is the SP-{plus,minus}-immediate form of the instruction. */
9363 if (Rn == REG_SP)
9364 constraint (Rd == REG_PC, BAD_PC);
9365 else
9366 reject_bad_reg (Rd);
9368 inst.instruction |= (Rn << 16) | (Rd << 8);
9369 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9372 /* Parse an add or subtract instruction. We get here with inst.instruction
9373 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9375 static void
9376 do_t_add_sub (void)
9378 int Rd, Rs, Rn;
9380 Rd = inst.operands[0].reg;
9381 Rs = (inst.operands[1].present
9382 ? inst.operands[1].reg /* Rd, Rs, foo */
9383 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9385 if (Rd == REG_PC)
9386 set_it_insn_type_last ();
9388 if (unified_syntax)
9390 bfd_boolean flags;
9391 bfd_boolean narrow;
9392 int opcode;
9394 flags = (inst.instruction == T_MNEM_adds
9395 || inst.instruction == T_MNEM_subs);
9396 if (flags)
9397 narrow = !in_it_block ();
9398 else
9399 narrow = in_it_block ();
9400 if (!inst.operands[2].isreg)
9402 int add;
9404 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9406 add = (inst.instruction == T_MNEM_add
9407 || inst.instruction == T_MNEM_adds);
9408 opcode = 0;
9409 if (inst.size_req != 4)
9411 /* Attempt to use a narrow opcode, with relaxation if
9412 appropriate. */
9413 if (Rd == REG_SP && Rs == REG_SP && !flags)
9414 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9415 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9416 opcode = T_MNEM_add_sp;
9417 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9418 opcode = T_MNEM_add_pc;
9419 else if (Rd <= 7 && Rs <= 7 && narrow)
9421 if (flags)
9422 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9423 else
9424 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9426 if (opcode)
9428 inst.instruction = THUMB_OP16(opcode);
9429 inst.instruction |= (Rd << 4) | Rs;
9430 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9431 if (inst.size_req != 2)
9432 inst.relax = opcode;
9434 else
9435 constraint (inst.size_req == 2, BAD_HIREG);
9437 if (inst.size_req == 4
9438 || (inst.size_req != 2 && !opcode))
9440 if (Rd == REG_PC)
9442 constraint (add, BAD_PC);
9443 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9444 _("only SUBS PC, LR, #const allowed"));
9445 constraint (inst.reloc.exp.X_op != O_constant,
9446 _("expression too complex"));
9447 constraint (inst.reloc.exp.X_add_number < 0
9448 || inst.reloc.exp.X_add_number > 0xff,
9449 _("immediate value out of range"));
9450 inst.instruction = T2_SUBS_PC_LR
9451 | inst.reloc.exp.X_add_number;
9452 inst.reloc.type = BFD_RELOC_UNUSED;
9453 return;
9455 else if (Rs == REG_PC)
9457 /* Always use addw/subw. */
9458 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9459 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9461 else
9463 inst.instruction = THUMB_OP32 (inst.instruction);
9464 inst.instruction = (inst.instruction & 0xe1ffffff)
9465 | 0x10000000;
9466 if (flags)
9467 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9468 else
9469 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9471 inst.instruction |= Rd << 8;
9472 inst.instruction |= Rs << 16;
9475 else
9477 Rn = inst.operands[2].reg;
9478 /* See if we can do this with a 16-bit instruction. */
9479 if (!inst.operands[2].shifted && inst.size_req != 4)
9481 if (Rd > 7 || Rs > 7 || Rn > 7)
9482 narrow = FALSE;
9484 if (narrow)
9486 inst.instruction = ((inst.instruction == T_MNEM_adds
9487 || inst.instruction == T_MNEM_add)
9488 ? T_OPCODE_ADD_R3
9489 : T_OPCODE_SUB_R3);
9490 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9491 return;
9494 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
9496 /* Thumb-1 cores (except v6-M) require at least one high
9497 register in a narrow non flag setting add. */
9498 if (Rd > 7 || Rn > 7
9499 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9500 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
9502 if (Rd == Rn)
9504 Rn = Rs;
9505 Rs = Rd;
9507 inst.instruction = T_OPCODE_ADD_HI;
9508 inst.instruction |= (Rd & 8) << 4;
9509 inst.instruction |= (Rd & 7);
9510 inst.instruction |= Rn << 3;
9511 return;
9516 constraint (Rd == REG_PC, BAD_PC);
9517 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9518 constraint (Rs == REG_PC, BAD_PC);
9519 reject_bad_reg (Rn);
9521 /* If we get here, it can't be done in 16 bits. */
9522 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9523 _("shift must be constant"));
9524 inst.instruction = THUMB_OP32 (inst.instruction);
9525 inst.instruction |= Rd << 8;
9526 inst.instruction |= Rs << 16;
9527 encode_thumb32_shifted_operand (2);
9530 else
9532 constraint (inst.instruction == T_MNEM_adds
9533 || inst.instruction == T_MNEM_subs,
9534 BAD_THUMB32);
9536 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
9538 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9539 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9540 BAD_HIREG);
9542 inst.instruction = (inst.instruction == T_MNEM_add
9543 ? 0x0000 : 0x8000);
9544 inst.instruction |= (Rd << 4) | Rs;
9545 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9546 return;
9549 Rn = inst.operands[2].reg;
9550 constraint (inst.operands[2].shifted, _("unshifted register required"));
9552 /* We now have Rd, Rs, and Rn set to registers. */
9553 if (Rd > 7 || Rs > 7 || Rn > 7)
9555 /* Can't do this for SUB. */
9556 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9557 inst.instruction = T_OPCODE_ADD_HI;
9558 inst.instruction |= (Rd & 8) << 4;
9559 inst.instruction |= (Rd & 7);
9560 if (Rs == Rd)
9561 inst.instruction |= Rn << 3;
9562 else if (Rn == Rd)
9563 inst.instruction |= Rs << 3;
9564 else
9565 constraint (1, _("dest must overlap one source register"));
9567 else
9569 inst.instruction = (inst.instruction == T_MNEM_add
9570 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9571 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9576 static void
9577 do_t_adr (void)
9579 unsigned Rd;
9581 Rd = inst.operands[0].reg;
9582 reject_bad_reg (Rd);
9584 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
9586 /* Defer to section relaxation. */
9587 inst.relax = inst.instruction;
9588 inst.instruction = THUMB_OP16 (inst.instruction);
9589 inst.instruction |= Rd << 4;
9591 else if (unified_syntax && inst.size_req != 2)
9593 /* Generate a 32-bit opcode. */
9594 inst.instruction = THUMB_OP32 (inst.instruction);
9595 inst.instruction |= Rd << 8;
9596 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9597 inst.reloc.pc_rel = 1;
9599 else
9601 /* Generate a 16-bit opcode. */
9602 inst.instruction = THUMB_OP16 (inst.instruction);
9603 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9604 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9605 inst.reloc.pc_rel = 1;
9607 inst.instruction |= Rd << 4;
9611 /* Arithmetic instructions for which there is just one 16-bit
9612 instruction encoding, and it allows only two low registers.
9613 For maximal compatibility with ARM syntax, we allow three register
9614 operands even when Thumb-32 instructions are not available, as long
9615 as the first two are identical. For instance, both "sbc r0,r1" and
9616 "sbc r0,r0,r1" are allowed. */
9617 static void
9618 do_t_arit3 (void)
9620 int Rd, Rs, Rn;
9622 Rd = inst.operands[0].reg;
9623 Rs = (inst.operands[1].present
9624 ? inst.operands[1].reg /* Rd, Rs, foo */
9625 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9626 Rn = inst.operands[2].reg;
9628 reject_bad_reg (Rd);
9629 reject_bad_reg (Rs);
9630 if (inst.operands[2].isreg)
9631 reject_bad_reg (Rn);
9633 if (unified_syntax)
9635 if (!inst.operands[2].isreg)
9637 /* For an immediate, we always generate a 32-bit opcode;
9638 section relaxation will shrink it later if possible. */
9639 inst.instruction = THUMB_OP32 (inst.instruction);
9640 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9641 inst.instruction |= Rd << 8;
9642 inst.instruction |= Rs << 16;
9643 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9645 else
9647 bfd_boolean narrow;
9649 /* See if we can do this with a 16-bit instruction. */
9650 if (THUMB_SETS_FLAGS (inst.instruction))
9651 narrow = !in_it_block ();
9652 else
9653 narrow = in_it_block ();
9655 if (Rd > 7 || Rn > 7 || Rs > 7)
9656 narrow = FALSE;
9657 if (inst.operands[2].shifted)
9658 narrow = FALSE;
9659 if (inst.size_req == 4)
9660 narrow = FALSE;
9662 if (narrow
9663 && Rd == Rs)
9665 inst.instruction = THUMB_OP16 (inst.instruction);
9666 inst.instruction |= Rd;
9667 inst.instruction |= Rn << 3;
9668 return;
9671 /* If we get here, it can't be done in 16 bits. */
9672 constraint (inst.operands[2].shifted
9673 && inst.operands[2].immisreg,
9674 _("shift must be constant"));
9675 inst.instruction = THUMB_OP32 (inst.instruction);
9676 inst.instruction |= Rd << 8;
9677 inst.instruction |= Rs << 16;
9678 encode_thumb32_shifted_operand (2);
9681 else
9683 /* On its face this is a lie - the instruction does set the
9684 flags. However, the only supported mnemonic in this mode
9685 says it doesn't. */
9686 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9688 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9689 _("unshifted register required"));
9690 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9691 constraint (Rd != Rs,
9692 _("dest and source1 must be the same register"));
9694 inst.instruction = THUMB_OP16 (inst.instruction);
9695 inst.instruction |= Rd;
9696 inst.instruction |= Rn << 3;
9700 /* Similarly, but for instructions where the arithmetic operation is
9701 commutative, so we can allow either of them to be different from
9702 the destination operand in a 16-bit instruction. For instance, all
9703 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9704 accepted. */
9705 static void
9706 do_t_arit3c (void)
9708 int Rd, Rs, Rn;
9710 Rd = inst.operands[0].reg;
9711 Rs = (inst.operands[1].present
9712 ? inst.operands[1].reg /* Rd, Rs, foo */
9713 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9714 Rn = inst.operands[2].reg;
9716 reject_bad_reg (Rd);
9717 reject_bad_reg (Rs);
9718 if (inst.operands[2].isreg)
9719 reject_bad_reg (Rn);
9721 if (unified_syntax)
9723 if (!inst.operands[2].isreg)
9725 /* For an immediate, we always generate a 32-bit opcode;
9726 section relaxation will shrink it later if possible. */
9727 inst.instruction = THUMB_OP32 (inst.instruction);
9728 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9729 inst.instruction |= Rd << 8;
9730 inst.instruction |= Rs << 16;
9731 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9733 else
9735 bfd_boolean narrow;
9737 /* See if we can do this with a 16-bit instruction. */
9738 if (THUMB_SETS_FLAGS (inst.instruction))
9739 narrow = !in_it_block ();
9740 else
9741 narrow = in_it_block ();
9743 if (Rd > 7 || Rn > 7 || Rs > 7)
9744 narrow = FALSE;
9745 if (inst.operands[2].shifted)
9746 narrow = FALSE;
9747 if (inst.size_req == 4)
9748 narrow = FALSE;
9750 if (narrow)
9752 if (Rd == Rs)
9754 inst.instruction = THUMB_OP16 (inst.instruction);
9755 inst.instruction |= Rd;
9756 inst.instruction |= Rn << 3;
9757 return;
9759 if (Rd == Rn)
9761 inst.instruction = THUMB_OP16 (inst.instruction);
9762 inst.instruction |= Rd;
9763 inst.instruction |= Rs << 3;
9764 return;
9768 /* If we get here, it can't be done in 16 bits. */
9769 constraint (inst.operands[2].shifted
9770 && inst.operands[2].immisreg,
9771 _("shift must be constant"));
9772 inst.instruction = THUMB_OP32 (inst.instruction);
9773 inst.instruction |= Rd << 8;
9774 inst.instruction |= Rs << 16;
9775 encode_thumb32_shifted_operand (2);
9778 else
9780 /* On its face this is a lie - the instruction does set the
9781 flags. However, the only supported mnemonic in this mode
9782 says it doesn't. */
9783 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9785 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9786 _("unshifted register required"));
9787 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9789 inst.instruction = THUMB_OP16 (inst.instruction);
9790 inst.instruction |= Rd;
9792 if (Rd == Rs)
9793 inst.instruction |= Rn << 3;
9794 else if (Rd == Rn)
9795 inst.instruction |= Rs << 3;
9796 else
9797 constraint (1, _("dest must overlap one source register"));
9801 static void
9802 do_t_barrier (void)
9804 if (inst.operands[0].present)
9806 constraint ((inst.instruction & 0xf0) != 0x40
9807 && inst.operands[0].imm > 0xf
9808 && inst.operands[0].imm < 0x0,
9809 _("bad barrier type"));
9810 inst.instruction |= inst.operands[0].imm;
9812 else
9813 inst.instruction |= 0xf;
9816 static void
9817 do_t_bfc (void)
9819 unsigned Rd;
9820 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9821 constraint (msb > 32, _("bit-field extends past end of register"));
9822 /* The instruction encoding stores the LSB and MSB,
9823 not the LSB and width. */
9824 Rd = inst.operands[0].reg;
9825 reject_bad_reg (Rd);
9826 inst.instruction |= Rd << 8;
9827 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9828 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9829 inst.instruction |= msb - 1;
9832 static void
9833 do_t_bfi (void)
9835 int Rd, Rn;
9836 unsigned int msb;
9838 Rd = inst.operands[0].reg;
9839 reject_bad_reg (Rd);
9841 /* #0 in second position is alternative syntax for bfc, which is
9842 the same instruction but with REG_PC in the Rm field. */
9843 if (!inst.operands[1].isreg)
9844 Rn = REG_PC;
9845 else
9847 Rn = inst.operands[1].reg;
9848 reject_bad_reg (Rn);
9851 msb = inst.operands[2].imm + inst.operands[3].imm;
9852 constraint (msb > 32, _("bit-field extends past end of register"));
9853 /* The instruction encoding stores the LSB and MSB,
9854 not the LSB and width. */
9855 inst.instruction |= Rd << 8;
9856 inst.instruction |= Rn << 16;
9857 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9858 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9859 inst.instruction |= msb - 1;
9862 static void
9863 do_t_bfx (void)
9865 unsigned Rd, Rn;
9867 Rd = inst.operands[0].reg;
9868 Rn = inst.operands[1].reg;
9870 reject_bad_reg (Rd);
9871 reject_bad_reg (Rn);
9873 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9874 _("bit-field extends past end of register"));
9875 inst.instruction |= Rd << 8;
9876 inst.instruction |= Rn << 16;
9877 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9878 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9879 inst.instruction |= inst.operands[3].imm - 1;
9882 /* ARM V5 Thumb BLX (argument parse)
9883 BLX <target_addr> which is BLX(1)
9884 BLX <Rm> which is BLX(2)
9885 Unfortunately, there are two different opcodes for this mnemonic.
9886 So, the insns[].value is not used, and the code here zaps values
9887 into inst.instruction.
9889 ??? How to take advantage of the additional two bits of displacement
9890 available in Thumb32 mode? Need new relocation? */
9892 static void
9893 do_t_blx (void)
9895 set_it_insn_type_last ();
9897 if (inst.operands[0].isreg)
9899 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9900 /* We have a register, so this is BLX(2). */
9901 inst.instruction |= inst.operands[0].reg << 3;
9903 else
9905 /* No register. This must be BLX(1). */
9906 inst.instruction = 0xf000e800;
9907 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
9911 static void
9912 do_t_branch (void)
9914 int opcode;
9915 int cond;
9916 int reloc;
9918 cond = inst.cond;
9919 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9921 if (in_it_block ())
9923 /* Conditional branches inside IT blocks are encoded as unconditional
9924 branches. */
9925 cond = COND_ALWAYS;
9927 else
9928 cond = inst.cond;
9930 if (cond != COND_ALWAYS)
9931 opcode = T_MNEM_bcond;
9932 else
9933 opcode = inst.instruction;
9935 if (unified_syntax
9936 && (inst.size_req == 4
9937 || (inst.size_req != 2
9938 && (inst.operands[0].hasreloc
9939 || inst.reloc.exp.X_op == O_constant))))
9941 inst.instruction = THUMB_OP32(opcode);
9942 if (cond == COND_ALWAYS)
9943 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
9944 else
9946 gas_assert (cond != 0xF);
9947 inst.instruction |= cond << 22;
9948 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
9951 else
9953 inst.instruction = THUMB_OP16(opcode);
9954 if (cond == COND_ALWAYS)
9955 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
9956 else
9958 inst.instruction |= cond << 8;
9959 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
9961 /* Allow section relaxation. */
9962 if (unified_syntax && inst.size_req != 2)
9963 inst.relax = opcode;
9965 inst.reloc.type = reloc;
9966 inst.reloc.pc_rel = 1;
9969 static void
9970 do_t_bkpt (void)
9972 constraint (inst.cond != COND_ALWAYS,
9973 _("instruction is always unconditional"));
9974 if (inst.operands[0].present)
9976 constraint (inst.operands[0].imm > 255,
9977 _("immediate value out of range"));
9978 inst.instruction |= inst.operands[0].imm;
9979 set_it_insn_type (NEUTRAL_IT_INSN);
9983 static void
9984 do_t_branch23 (void)
9986 set_it_insn_type_last ();
9987 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
9989 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
9990 this file. We used to simply ignore the PLT reloc type here --
9991 the branch encoding is now needed to deal with TLSCALL relocs.
9992 So if we see a PLT reloc now, put it back to how it used to be to
9993 keep the preexisting behaviour. */
9994 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
9995 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9997 #if defined(OBJ_COFF)
9998 /* If the destination of the branch is a defined symbol which does not have
9999 the THUMB_FUNC attribute, then we must be calling a function which has
10000 the (interfacearm) attribute. We look for the Thumb entry point to that
10001 function and change the branch to refer to that function instead. */
10002 if ( inst.reloc.exp.X_op == O_symbol
10003 && inst.reloc.exp.X_add_symbol != NULL
10004 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10005 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10006 inst.reloc.exp.X_add_symbol =
10007 find_real_start (inst.reloc.exp.X_add_symbol);
10008 #endif
10011 static void
10012 do_t_bx (void)
10014 set_it_insn_type_last ();
10015 inst.instruction |= inst.operands[0].reg << 3;
10016 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10017 should cause the alignment to be checked once it is known. This is
10018 because BX PC only works if the instruction is word aligned. */
10021 static void
10022 do_t_bxj (void)
10024 int Rm;
10026 set_it_insn_type_last ();
10027 Rm = inst.operands[0].reg;
10028 reject_bad_reg (Rm);
10029 inst.instruction |= Rm << 16;
10032 static void
10033 do_t_clz (void)
10035 unsigned Rd;
10036 unsigned Rm;
10038 Rd = inst.operands[0].reg;
10039 Rm = inst.operands[1].reg;
10041 reject_bad_reg (Rd);
10042 reject_bad_reg (Rm);
10044 inst.instruction |= Rd << 8;
10045 inst.instruction |= Rm << 16;
10046 inst.instruction |= Rm;
10049 static void
10050 do_t_cps (void)
10052 set_it_insn_type (OUTSIDE_IT_INSN);
10053 inst.instruction |= inst.operands[0].imm;
10056 static void
10057 do_t_cpsi (void)
10059 set_it_insn_type (OUTSIDE_IT_INSN);
10060 if (unified_syntax
10061 && (inst.operands[1].present || inst.size_req == 4)
10062 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
10064 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10065 inst.instruction = 0xf3af8000;
10066 inst.instruction |= imod << 9;
10067 inst.instruction |= inst.operands[0].imm << 5;
10068 if (inst.operands[1].present)
10069 inst.instruction |= 0x100 | inst.operands[1].imm;
10071 else
10073 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10074 && (inst.operands[0].imm & 4),
10075 _("selected processor does not support 'A' form "
10076 "of this instruction"));
10077 constraint (inst.operands[1].present || inst.size_req == 4,
10078 _("Thumb does not support the 2-argument "
10079 "form of this instruction"));
10080 inst.instruction |= inst.operands[0].imm;
10084 /* THUMB CPY instruction (argument parse). */
10086 static void
10087 do_t_cpy (void)
10089 if (inst.size_req == 4)
10091 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10092 inst.instruction |= inst.operands[0].reg << 8;
10093 inst.instruction |= inst.operands[1].reg;
10095 else
10097 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10098 inst.instruction |= (inst.operands[0].reg & 0x7);
10099 inst.instruction |= inst.operands[1].reg << 3;
10103 static void
10104 do_t_cbz (void)
10106 set_it_insn_type (OUTSIDE_IT_INSN);
10107 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10108 inst.instruction |= inst.operands[0].reg;
10109 inst.reloc.pc_rel = 1;
10110 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10113 static void
10114 do_t_dbg (void)
10116 inst.instruction |= inst.operands[0].imm;
10119 static void
10120 do_t_div (void)
10122 unsigned Rd, Rn, Rm;
10124 Rd = inst.operands[0].reg;
10125 Rn = (inst.operands[1].present
10126 ? inst.operands[1].reg : Rd);
10127 Rm = inst.operands[2].reg;
10129 reject_bad_reg (Rd);
10130 reject_bad_reg (Rn);
10131 reject_bad_reg (Rm);
10133 inst.instruction |= Rd << 8;
10134 inst.instruction |= Rn << 16;
10135 inst.instruction |= Rm;
10138 static void
10139 do_t_hint (void)
10141 if (unified_syntax && inst.size_req == 4)
10142 inst.instruction = THUMB_OP32 (inst.instruction);
10143 else
10144 inst.instruction = THUMB_OP16 (inst.instruction);
10147 static void
10148 do_t_it (void)
10150 unsigned int cond = inst.operands[0].imm;
10152 set_it_insn_type (IT_INSN);
10153 now_it.mask = (inst.instruction & 0xf) | 0x10;
10154 now_it.cc = cond;
10156 /* If the condition is a negative condition, invert the mask. */
10157 if ((cond & 0x1) == 0x0)
10159 unsigned int mask = inst.instruction & 0x000f;
10161 if ((mask & 0x7) == 0)
10162 /* no conversion needed */;
10163 else if ((mask & 0x3) == 0)
10164 mask ^= 0x8;
10165 else if ((mask & 0x1) == 0)
10166 mask ^= 0xC;
10167 else
10168 mask ^= 0xE;
10170 inst.instruction &= 0xfff0;
10171 inst.instruction |= mask;
10174 inst.instruction |= cond << 4;
10177 /* Helper function used for both push/pop and ldm/stm. */
10178 static void
10179 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10181 bfd_boolean load;
10183 load = (inst.instruction & (1 << 20)) != 0;
10185 if (mask & (1 << 13))
10186 inst.error = _("SP not allowed in register list");
10188 if ((mask & (1 << base)) != 0
10189 && writeback)
10190 inst.error = _("having the base register in the register list when "
10191 "using write back is UNPREDICTABLE");
10193 if (load)
10195 if (mask & (1 << 15))
10197 if (mask & (1 << 14))
10198 inst.error = _("LR and PC should not both be in register list");
10199 else
10200 set_it_insn_type_last ();
10203 else
10205 if (mask & (1 << 15))
10206 inst.error = _("PC not allowed in register list");
10209 if ((mask & (mask - 1)) == 0)
10211 /* Single register transfers implemented as str/ldr. */
10212 if (writeback)
10214 if (inst.instruction & (1 << 23))
10215 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10216 else
10217 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10219 else
10221 if (inst.instruction & (1 << 23))
10222 inst.instruction = 0x00800000; /* ia -> [base] */
10223 else
10224 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10227 inst.instruction |= 0xf8400000;
10228 if (load)
10229 inst.instruction |= 0x00100000;
10231 mask = ffs (mask) - 1;
10232 mask <<= 12;
10234 else if (writeback)
10235 inst.instruction |= WRITE_BACK;
10237 inst.instruction |= mask;
10238 inst.instruction |= base << 16;
10241 static void
10242 do_t_ldmstm (void)
10244 /* This really doesn't seem worth it. */
10245 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10246 _("expression too complex"));
10247 constraint (inst.operands[1].writeback,
10248 _("Thumb load/store multiple does not support {reglist}^"));
10250 if (unified_syntax)
10252 bfd_boolean narrow;
10253 unsigned mask;
10255 narrow = FALSE;
10256 /* See if we can use a 16-bit instruction. */
10257 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10258 && inst.size_req != 4
10259 && !(inst.operands[1].imm & ~0xff))
10261 mask = 1 << inst.operands[0].reg;
10263 if (inst.operands[0].reg <= 7)
10265 if (inst.instruction == T_MNEM_stmia
10266 ? inst.operands[0].writeback
10267 : (inst.operands[0].writeback
10268 == !(inst.operands[1].imm & mask)))
10270 if (inst.instruction == T_MNEM_stmia
10271 && (inst.operands[1].imm & mask)
10272 && (inst.operands[1].imm & (mask - 1)))
10273 as_warn (_("value stored for r%d is UNKNOWN"),
10274 inst.operands[0].reg);
10276 inst.instruction = THUMB_OP16 (inst.instruction);
10277 inst.instruction |= inst.operands[0].reg << 8;
10278 inst.instruction |= inst.operands[1].imm;
10279 narrow = TRUE;
10281 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10283 /* This means 1 register in reg list one of 3 situations:
10284 1. Instruction is stmia, but without writeback.
10285 2. lmdia without writeback, but with Rn not in
10286 reglist.
10287 3. ldmia with writeback, but with Rn in reglist.
10288 Case 3 is UNPREDICTABLE behaviour, so we handle
10289 case 1 and 2 which can be converted into a 16-bit
10290 str or ldr. The SP cases are handled below. */
10291 unsigned long opcode;
10292 /* First, record an error for Case 3. */
10293 if (inst.operands[1].imm & mask
10294 && inst.operands[0].writeback)
10295 inst.error =
10296 _("having the base register in the register list when "
10297 "using write back is UNPREDICTABLE");
10299 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
10300 : T_MNEM_ldr);
10301 inst.instruction = THUMB_OP16 (opcode);
10302 inst.instruction |= inst.operands[0].reg << 3;
10303 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10304 narrow = TRUE;
10307 else if (inst.operands[0] .reg == REG_SP)
10309 if (inst.operands[0].writeback)
10311 inst.instruction =
10312 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10313 ? T_MNEM_push : T_MNEM_pop);
10314 inst.instruction |= inst.operands[1].imm;
10315 narrow = TRUE;
10317 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10319 inst.instruction =
10320 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10321 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10322 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10323 narrow = TRUE;
10328 if (!narrow)
10330 if (inst.instruction < 0xffff)
10331 inst.instruction = THUMB_OP32 (inst.instruction);
10333 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10334 inst.operands[0].writeback);
10337 else
10339 constraint (inst.operands[0].reg > 7
10340 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
10341 constraint (inst.instruction != T_MNEM_ldmia
10342 && inst.instruction != T_MNEM_stmia,
10343 _("Thumb-2 instruction only valid in unified syntax"));
10344 if (inst.instruction == T_MNEM_stmia)
10346 if (!inst.operands[0].writeback)
10347 as_warn (_("this instruction will write back the base register"));
10348 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10349 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
10350 as_warn (_("value stored for r%d is UNKNOWN"),
10351 inst.operands[0].reg);
10353 else
10355 if (!inst.operands[0].writeback
10356 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10357 as_warn (_("this instruction will write back the base register"));
10358 else if (inst.operands[0].writeback
10359 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10360 as_warn (_("this instruction will not write back the base register"));
10363 inst.instruction = THUMB_OP16 (inst.instruction);
10364 inst.instruction |= inst.operands[0].reg << 8;
10365 inst.instruction |= inst.operands[1].imm;
10369 static void
10370 do_t_ldrex (void)
10372 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10373 || inst.operands[1].postind || inst.operands[1].writeback
10374 || inst.operands[1].immisreg || inst.operands[1].shifted
10375 || inst.operands[1].negative,
10376 BAD_ADDR_MODE);
10378 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10380 inst.instruction |= inst.operands[0].reg << 12;
10381 inst.instruction |= inst.operands[1].reg << 16;
10382 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10385 static void
10386 do_t_ldrexd (void)
10388 if (!inst.operands[1].present)
10390 constraint (inst.operands[0].reg == REG_LR,
10391 _("r14 not allowed as first register "
10392 "when second register is omitted"));
10393 inst.operands[1].reg = inst.operands[0].reg + 1;
10395 constraint (inst.operands[0].reg == inst.operands[1].reg,
10396 BAD_OVERLAP);
10398 inst.instruction |= inst.operands[0].reg << 12;
10399 inst.instruction |= inst.operands[1].reg << 8;
10400 inst.instruction |= inst.operands[2].reg << 16;
10403 static void
10404 do_t_ldst (void)
10406 unsigned long opcode;
10407 int Rn;
10409 if (inst.operands[0].isreg
10410 && !inst.operands[0].preind
10411 && inst.operands[0].reg == REG_PC)
10412 set_it_insn_type_last ();
10414 opcode = inst.instruction;
10415 if (unified_syntax)
10417 if (!inst.operands[1].isreg)
10419 if (opcode <= 0xffff)
10420 inst.instruction = THUMB_OP32 (opcode);
10421 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10422 return;
10424 if (inst.operands[1].isreg
10425 && !inst.operands[1].writeback
10426 && !inst.operands[1].shifted && !inst.operands[1].postind
10427 && !inst.operands[1].negative && inst.operands[0].reg <= 7
10428 && opcode <= 0xffff
10429 && inst.size_req != 4)
10431 /* Insn may have a 16-bit form. */
10432 Rn = inst.operands[1].reg;
10433 if (inst.operands[1].immisreg)
10435 inst.instruction = THUMB_OP16 (opcode);
10436 /* [Rn, Rik] */
10437 if (Rn <= 7 && inst.operands[1].imm <= 7)
10438 goto op16;
10439 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10440 reject_bad_reg (inst.operands[1].imm);
10442 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10443 && opcode != T_MNEM_ldrsb)
10444 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10445 || (Rn == REG_SP && opcode == T_MNEM_str))
10447 /* [Rn, #const] */
10448 if (Rn > 7)
10450 if (Rn == REG_PC)
10452 if (inst.reloc.pc_rel)
10453 opcode = T_MNEM_ldr_pc2;
10454 else
10455 opcode = T_MNEM_ldr_pc;
10457 else
10459 if (opcode == T_MNEM_ldr)
10460 opcode = T_MNEM_ldr_sp;
10461 else
10462 opcode = T_MNEM_str_sp;
10464 inst.instruction = inst.operands[0].reg << 8;
10466 else
10468 inst.instruction = inst.operands[0].reg;
10469 inst.instruction |= inst.operands[1].reg << 3;
10471 inst.instruction |= THUMB_OP16 (opcode);
10472 if (inst.size_req == 2)
10473 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10474 else
10475 inst.relax = opcode;
10476 return;
10479 /* Definitely a 32-bit variant. */
10481 /* Warning for Erratum 752419. */
10482 if (opcode == T_MNEM_ldr
10483 && inst.operands[0].reg == REG_SP
10484 && inst.operands[1].writeback == 1
10485 && !inst.operands[1].immisreg)
10487 if (no_cpu_selected ()
10488 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10489 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10490 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10491 as_warn (_("This instruction may be unpredictable "
10492 "if executed on M-profile cores "
10493 "with interrupts enabled."));
10496 /* Do some validations regarding addressing modes. */
10497 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10498 && opcode != T_MNEM_str)
10499 reject_bad_reg (inst.operands[1].imm);
10501 inst.instruction = THUMB_OP32 (opcode);
10502 inst.instruction |= inst.operands[0].reg << 12;
10503 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
10504 return;
10507 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10509 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
10511 /* Only [Rn,Rm] is acceptable. */
10512 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10513 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10514 || inst.operands[1].postind || inst.operands[1].shifted
10515 || inst.operands[1].negative,
10516 _("Thumb does not support this addressing mode"));
10517 inst.instruction = THUMB_OP16 (inst.instruction);
10518 goto op16;
10521 inst.instruction = THUMB_OP16 (inst.instruction);
10522 if (!inst.operands[1].isreg)
10523 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10524 return;
10526 constraint (!inst.operands[1].preind
10527 || inst.operands[1].shifted
10528 || inst.operands[1].writeback,
10529 _("Thumb does not support this addressing mode"));
10530 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
10532 constraint (inst.instruction & 0x0600,
10533 _("byte or halfword not valid for base register"));
10534 constraint (inst.operands[1].reg == REG_PC
10535 && !(inst.instruction & THUMB_LOAD_BIT),
10536 _("r15 based store not allowed"));
10537 constraint (inst.operands[1].immisreg,
10538 _("invalid base register for register offset"));
10540 if (inst.operands[1].reg == REG_PC)
10541 inst.instruction = T_OPCODE_LDR_PC;
10542 else if (inst.instruction & THUMB_LOAD_BIT)
10543 inst.instruction = T_OPCODE_LDR_SP;
10544 else
10545 inst.instruction = T_OPCODE_STR_SP;
10547 inst.instruction |= inst.operands[0].reg << 8;
10548 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10549 return;
10552 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10553 if (!inst.operands[1].immisreg)
10555 /* Immediate offset. */
10556 inst.instruction |= inst.operands[0].reg;
10557 inst.instruction |= inst.operands[1].reg << 3;
10558 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10559 return;
10562 /* Register offset. */
10563 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10564 constraint (inst.operands[1].negative,
10565 _("Thumb does not support this addressing mode"));
10567 op16:
10568 switch (inst.instruction)
10570 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10571 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10572 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10573 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10574 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10575 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10576 case 0x5600 /* ldrsb */:
10577 case 0x5e00 /* ldrsh */: break;
10578 default: abort ();
10581 inst.instruction |= inst.operands[0].reg;
10582 inst.instruction |= inst.operands[1].reg << 3;
10583 inst.instruction |= inst.operands[1].imm << 6;
10586 static void
10587 do_t_ldstd (void)
10589 if (!inst.operands[1].present)
10591 inst.operands[1].reg = inst.operands[0].reg + 1;
10592 constraint (inst.operands[0].reg == REG_LR,
10593 _("r14 not allowed here"));
10595 inst.instruction |= inst.operands[0].reg << 12;
10596 inst.instruction |= inst.operands[1].reg << 8;
10597 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
10600 static void
10601 do_t_ldstt (void)
10603 inst.instruction |= inst.operands[0].reg << 12;
10604 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10607 static void
10608 do_t_mla (void)
10610 unsigned Rd, Rn, Rm, Ra;
10612 Rd = inst.operands[0].reg;
10613 Rn = inst.operands[1].reg;
10614 Rm = inst.operands[2].reg;
10615 Ra = inst.operands[3].reg;
10617 reject_bad_reg (Rd);
10618 reject_bad_reg (Rn);
10619 reject_bad_reg (Rm);
10620 reject_bad_reg (Ra);
10622 inst.instruction |= Rd << 8;
10623 inst.instruction |= Rn << 16;
10624 inst.instruction |= Rm;
10625 inst.instruction |= Ra << 12;
10628 static void
10629 do_t_mlal (void)
10631 unsigned RdLo, RdHi, Rn, Rm;
10633 RdLo = inst.operands[0].reg;
10634 RdHi = inst.operands[1].reg;
10635 Rn = inst.operands[2].reg;
10636 Rm = inst.operands[3].reg;
10638 reject_bad_reg (RdLo);
10639 reject_bad_reg (RdHi);
10640 reject_bad_reg (Rn);
10641 reject_bad_reg (Rm);
10643 inst.instruction |= RdLo << 12;
10644 inst.instruction |= RdHi << 8;
10645 inst.instruction |= Rn << 16;
10646 inst.instruction |= Rm;
10649 static void
10650 do_t_mov_cmp (void)
10652 unsigned Rn, Rm;
10654 Rn = inst.operands[0].reg;
10655 Rm = inst.operands[1].reg;
10657 if (Rn == REG_PC)
10658 set_it_insn_type_last ();
10660 if (unified_syntax)
10662 int r0off = (inst.instruction == T_MNEM_mov
10663 || inst.instruction == T_MNEM_movs) ? 8 : 16;
10664 unsigned long opcode;
10665 bfd_boolean narrow;
10666 bfd_boolean low_regs;
10668 low_regs = (Rn <= 7 && Rm <= 7);
10669 opcode = inst.instruction;
10670 if (in_it_block ())
10671 narrow = opcode != T_MNEM_movs;
10672 else
10673 narrow = opcode != T_MNEM_movs || low_regs;
10674 if (inst.size_req == 4
10675 || inst.operands[1].shifted)
10676 narrow = FALSE;
10678 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10679 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10680 && !inst.operands[1].shifted
10681 && Rn == REG_PC
10682 && Rm == REG_LR)
10684 inst.instruction = T2_SUBS_PC_LR;
10685 return;
10688 if (opcode == T_MNEM_cmp)
10690 constraint (Rn == REG_PC, BAD_PC);
10691 if (narrow)
10693 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10694 but valid. */
10695 warn_deprecated_sp (Rm);
10696 /* R15 was documented as a valid choice for Rm in ARMv6,
10697 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10698 tools reject R15, so we do too. */
10699 constraint (Rm == REG_PC, BAD_PC);
10701 else
10702 reject_bad_reg (Rm);
10704 else if (opcode == T_MNEM_mov
10705 || opcode == T_MNEM_movs)
10707 if (inst.operands[1].isreg)
10709 if (opcode == T_MNEM_movs)
10711 reject_bad_reg (Rn);
10712 reject_bad_reg (Rm);
10714 else if (narrow)
10716 /* This is mov.n. */
10717 if ((Rn == REG_SP || Rn == REG_PC)
10718 && (Rm == REG_SP || Rm == REG_PC))
10720 as_warn (_("Use of r%u as a source register is "
10721 "deprecated when r%u is the destination "
10722 "register."), Rm, Rn);
10725 else
10727 /* This is mov.w. */
10728 constraint (Rn == REG_PC, BAD_PC);
10729 constraint (Rm == REG_PC, BAD_PC);
10730 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10733 else
10734 reject_bad_reg (Rn);
10737 if (!inst.operands[1].isreg)
10739 /* Immediate operand. */
10740 if (!in_it_block () && opcode == T_MNEM_mov)
10741 narrow = 0;
10742 if (low_regs && narrow)
10744 inst.instruction = THUMB_OP16 (opcode);
10745 inst.instruction |= Rn << 8;
10746 if (inst.size_req == 2)
10747 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10748 else
10749 inst.relax = opcode;
10751 else
10753 inst.instruction = THUMB_OP32 (inst.instruction);
10754 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10755 inst.instruction |= Rn << r0off;
10756 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10759 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10760 && (inst.instruction == T_MNEM_mov
10761 || inst.instruction == T_MNEM_movs))
10763 /* Register shifts are encoded as separate shift instructions. */
10764 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10766 if (in_it_block ())
10767 narrow = !flags;
10768 else
10769 narrow = flags;
10771 if (inst.size_req == 4)
10772 narrow = FALSE;
10774 if (!low_regs || inst.operands[1].imm > 7)
10775 narrow = FALSE;
10777 if (Rn != Rm)
10778 narrow = FALSE;
10780 switch (inst.operands[1].shift_kind)
10782 case SHIFT_LSL:
10783 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10784 break;
10785 case SHIFT_ASR:
10786 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10787 break;
10788 case SHIFT_LSR:
10789 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10790 break;
10791 case SHIFT_ROR:
10792 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10793 break;
10794 default:
10795 abort ();
10798 inst.instruction = opcode;
10799 if (narrow)
10801 inst.instruction |= Rn;
10802 inst.instruction |= inst.operands[1].imm << 3;
10804 else
10806 if (flags)
10807 inst.instruction |= CONDS_BIT;
10809 inst.instruction |= Rn << 8;
10810 inst.instruction |= Rm << 16;
10811 inst.instruction |= inst.operands[1].imm;
10814 else if (!narrow)
10816 /* Some mov with immediate shift have narrow variants.
10817 Register shifts are handled above. */
10818 if (low_regs && inst.operands[1].shifted
10819 && (inst.instruction == T_MNEM_mov
10820 || inst.instruction == T_MNEM_movs))
10822 if (in_it_block ())
10823 narrow = (inst.instruction == T_MNEM_mov);
10824 else
10825 narrow = (inst.instruction == T_MNEM_movs);
10828 if (narrow)
10830 switch (inst.operands[1].shift_kind)
10832 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10833 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10834 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10835 default: narrow = FALSE; break;
10839 if (narrow)
10841 inst.instruction |= Rn;
10842 inst.instruction |= Rm << 3;
10843 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10845 else
10847 inst.instruction = THUMB_OP32 (inst.instruction);
10848 inst.instruction |= Rn << r0off;
10849 encode_thumb32_shifted_operand (1);
10852 else
10853 switch (inst.instruction)
10855 case T_MNEM_mov:
10856 inst.instruction = T_OPCODE_MOV_HR;
10857 inst.instruction |= (Rn & 0x8) << 4;
10858 inst.instruction |= (Rn & 0x7);
10859 inst.instruction |= Rm << 3;
10860 break;
10862 case T_MNEM_movs:
10863 /* We know we have low registers at this point.
10864 Generate LSLS Rd, Rs, #0. */
10865 inst.instruction = T_OPCODE_LSL_I;
10866 inst.instruction |= Rn;
10867 inst.instruction |= Rm << 3;
10868 break;
10870 case T_MNEM_cmp:
10871 if (low_regs)
10873 inst.instruction = T_OPCODE_CMP_LR;
10874 inst.instruction |= Rn;
10875 inst.instruction |= Rm << 3;
10877 else
10879 inst.instruction = T_OPCODE_CMP_HR;
10880 inst.instruction |= (Rn & 0x8) << 4;
10881 inst.instruction |= (Rn & 0x7);
10882 inst.instruction |= Rm << 3;
10884 break;
10886 return;
10889 inst.instruction = THUMB_OP16 (inst.instruction);
10891 /* PR 10443: Do not silently ignore shifted operands. */
10892 constraint (inst.operands[1].shifted,
10893 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10895 if (inst.operands[1].isreg)
10897 if (Rn < 8 && Rm < 8)
10899 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10900 since a MOV instruction produces unpredictable results. */
10901 if (inst.instruction == T_OPCODE_MOV_I8)
10902 inst.instruction = T_OPCODE_ADD_I3;
10903 else
10904 inst.instruction = T_OPCODE_CMP_LR;
10906 inst.instruction |= Rn;
10907 inst.instruction |= Rm << 3;
10909 else
10911 if (inst.instruction == T_OPCODE_MOV_I8)
10912 inst.instruction = T_OPCODE_MOV_HR;
10913 else
10914 inst.instruction = T_OPCODE_CMP_HR;
10915 do_t_cpy ();
10918 else
10920 constraint (Rn > 7,
10921 _("only lo regs allowed with immediate"));
10922 inst.instruction |= Rn << 8;
10923 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10927 static void
10928 do_t_mov16 (void)
10930 unsigned Rd;
10931 bfd_vma imm;
10932 bfd_boolean top;
10934 top = (inst.instruction & 0x00800000) != 0;
10935 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10937 constraint (top, _(":lower16: not allowed this instruction"));
10938 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10940 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10942 constraint (!top, _(":upper16: not allowed this instruction"));
10943 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10946 Rd = inst.operands[0].reg;
10947 reject_bad_reg (Rd);
10949 inst.instruction |= Rd << 8;
10950 if (inst.reloc.type == BFD_RELOC_UNUSED)
10952 imm = inst.reloc.exp.X_add_number;
10953 inst.instruction |= (imm & 0xf000) << 4;
10954 inst.instruction |= (imm & 0x0800) << 15;
10955 inst.instruction |= (imm & 0x0700) << 4;
10956 inst.instruction |= (imm & 0x00ff);
10960 static void
10961 do_t_mvn_tst (void)
10963 unsigned Rn, Rm;
10965 Rn = inst.operands[0].reg;
10966 Rm = inst.operands[1].reg;
10968 if (inst.instruction == T_MNEM_cmp
10969 || inst.instruction == T_MNEM_cmn)
10970 constraint (Rn == REG_PC, BAD_PC);
10971 else
10972 reject_bad_reg (Rn);
10973 reject_bad_reg (Rm);
10975 if (unified_syntax)
10977 int r0off = (inst.instruction == T_MNEM_mvn
10978 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
10979 bfd_boolean narrow;
10981 if (inst.size_req == 4
10982 || inst.instruction > 0xffff
10983 || inst.operands[1].shifted
10984 || Rn > 7 || Rm > 7)
10985 narrow = FALSE;
10986 else if (inst.instruction == T_MNEM_cmn)
10987 narrow = TRUE;
10988 else if (THUMB_SETS_FLAGS (inst.instruction))
10989 narrow = !in_it_block ();
10990 else
10991 narrow = in_it_block ();
10993 if (!inst.operands[1].isreg)
10995 /* For an immediate, we always generate a 32-bit opcode;
10996 section relaxation will shrink it later if possible. */
10997 if (inst.instruction < 0xffff)
10998 inst.instruction = THUMB_OP32 (inst.instruction);
10999 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11000 inst.instruction |= Rn << r0off;
11001 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11003 else
11005 /* See if we can do this with a 16-bit instruction. */
11006 if (narrow)
11008 inst.instruction = THUMB_OP16 (inst.instruction);
11009 inst.instruction |= Rn;
11010 inst.instruction |= Rm << 3;
11012 else
11014 constraint (inst.operands[1].shifted
11015 && inst.operands[1].immisreg,
11016 _("shift must be constant"));
11017 if (inst.instruction < 0xffff)
11018 inst.instruction = THUMB_OP32 (inst.instruction);
11019 inst.instruction |= Rn << r0off;
11020 encode_thumb32_shifted_operand (1);
11024 else
11026 constraint (inst.instruction > 0xffff
11027 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11028 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11029 _("unshifted register required"));
11030 constraint (Rn > 7 || Rm > 7,
11031 BAD_HIREG);
11033 inst.instruction = THUMB_OP16 (inst.instruction);
11034 inst.instruction |= Rn;
11035 inst.instruction |= Rm << 3;
11039 static void
11040 do_t_mrs (void)
11042 unsigned Rd;
11044 if (do_vfp_nsyn_mrs () == SUCCESS)
11045 return;
11047 Rd = inst.operands[0].reg;
11048 reject_bad_reg (Rd);
11049 inst.instruction |= Rd << 8;
11051 if (inst.operands[1].isreg)
11053 unsigned br = inst.operands[1].reg;
11054 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11055 as_bad (_("bad register for mrs"));
11057 inst.instruction |= br & (0xf << 16);
11058 inst.instruction |= (br & 0x300) >> 4;
11059 inst.instruction |= (br & SPSR_BIT) >> 2;
11061 else
11063 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11065 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11066 constraint (flags != 0, _("selected processor does not support "
11067 "requested special purpose register"));
11068 else
11069 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11070 devices). */
11071 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11072 _("'APSR', 'CPSR' or 'SPSR' expected"));
11074 inst.instruction |= (flags & SPSR_BIT) >> 2;
11075 inst.instruction |= inst.operands[1].imm & 0xff;
11076 inst.instruction |= 0xf0000;
11080 static void
11081 do_t_msr (void)
11083 int flags;
11084 unsigned Rn;
11086 if (do_vfp_nsyn_msr () == SUCCESS)
11087 return;
11089 constraint (!inst.operands[1].isreg,
11090 _("Thumb encoding does not support an immediate here"));
11092 if (inst.operands[0].isreg)
11093 flags = (int)(inst.operands[0].reg);
11094 else
11095 flags = inst.operands[0].imm;
11097 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11099 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11101 constraint ((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11102 && (bits & ~(PSR_s | PSR_f)) != 0)
11103 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11104 && bits != PSR_f),
11105 _("selected processor does not support requested special "
11106 "purpose register"));
11108 else
11109 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11110 "requested special purpose register"));
11112 Rn = inst.operands[1].reg;
11113 reject_bad_reg (Rn);
11115 inst.instruction |= (flags & SPSR_BIT) >> 2;
11116 inst.instruction |= (flags & 0xf0000) >> 8;
11117 inst.instruction |= (flags & 0x300) >> 4;
11118 inst.instruction |= (flags & 0xff);
11119 inst.instruction |= Rn << 16;
11122 static void
11123 do_t_mul (void)
11125 bfd_boolean narrow;
11126 unsigned Rd, Rn, Rm;
11128 if (!inst.operands[2].present)
11129 inst.operands[2].reg = inst.operands[0].reg;
11131 Rd = inst.operands[0].reg;
11132 Rn = inst.operands[1].reg;
11133 Rm = inst.operands[2].reg;
11135 if (unified_syntax)
11137 if (inst.size_req == 4
11138 || (Rd != Rn
11139 && Rd != Rm)
11140 || Rn > 7
11141 || Rm > 7)
11142 narrow = FALSE;
11143 else if (inst.instruction == T_MNEM_muls)
11144 narrow = !in_it_block ();
11145 else
11146 narrow = in_it_block ();
11148 else
11150 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
11151 constraint (Rn > 7 || Rm > 7,
11152 BAD_HIREG);
11153 narrow = TRUE;
11156 if (narrow)
11158 /* 16-bit MULS/Conditional MUL. */
11159 inst.instruction = THUMB_OP16 (inst.instruction);
11160 inst.instruction |= Rd;
11162 if (Rd == Rn)
11163 inst.instruction |= Rm << 3;
11164 else if (Rd == Rm)
11165 inst.instruction |= Rn << 3;
11166 else
11167 constraint (1, _("dest must overlap one source register"));
11169 else
11171 constraint (inst.instruction != T_MNEM_mul,
11172 _("Thumb-2 MUL must not set flags"));
11173 /* 32-bit MUL. */
11174 inst.instruction = THUMB_OP32 (inst.instruction);
11175 inst.instruction |= Rd << 8;
11176 inst.instruction |= Rn << 16;
11177 inst.instruction |= Rm << 0;
11179 reject_bad_reg (Rd);
11180 reject_bad_reg (Rn);
11181 reject_bad_reg (Rm);
11185 static void
11186 do_t_mull (void)
11188 unsigned RdLo, RdHi, Rn, Rm;
11190 RdLo = inst.operands[0].reg;
11191 RdHi = inst.operands[1].reg;
11192 Rn = inst.operands[2].reg;
11193 Rm = inst.operands[3].reg;
11195 reject_bad_reg (RdLo);
11196 reject_bad_reg (RdHi);
11197 reject_bad_reg (Rn);
11198 reject_bad_reg (Rm);
11200 inst.instruction |= RdLo << 12;
11201 inst.instruction |= RdHi << 8;
11202 inst.instruction |= Rn << 16;
11203 inst.instruction |= Rm;
11205 if (RdLo == RdHi)
11206 as_tsktsk (_("rdhi and rdlo must be different"));
11209 static void
11210 do_t_nop (void)
11212 set_it_insn_type (NEUTRAL_IT_INSN);
11214 if (unified_syntax)
11216 if (inst.size_req == 4 || inst.operands[0].imm > 15)
11218 inst.instruction = THUMB_OP32 (inst.instruction);
11219 inst.instruction |= inst.operands[0].imm;
11221 else
11223 /* PR9722: Check for Thumb2 availability before
11224 generating a thumb2 nop instruction. */
11225 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
11227 inst.instruction = THUMB_OP16 (inst.instruction);
11228 inst.instruction |= inst.operands[0].imm << 4;
11230 else
11231 inst.instruction = 0x46c0;
11234 else
11236 constraint (inst.operands[0].present,
11237 _("Thumb does not support NOP with hints"));
11238 inst.instruction = 0x46c0;
11242 static void
11243 do_t_neg (void)
11245 if (unified_syntax)
11247 bfd_boolean narrow;
11249 if (THUMB_SETS_FLAGS (inst.instruction))
11250 narrow = !in_it_block ();
11251 else
11252 narrow = in_it_block ();
11253 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11254 narrow = FALSE;
11255 if (inst.size_req == 4)
11256 narrow = FALSE;
11258 if (!narrow)
11260 inst.instruction = THUMB_OP32 (inst.instruction);
11261 inst.instruction |= inst.operands[0].reg << 8;
11262 inst.instruction |= inst.operands[1].reg << 16;
11264 else
11266 inst.instruction = THUMB_OP16 (inst.instruction);
11267 inst.instruction |= inst.operands[0].reg;
11268 inst.instruction |= inst.operands[1].reg << 3;
11271 else
11273 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11274 BAD_HIREG);
11275 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11277 inst.instruction = THUMB_OP16 (inst.instruction);
11278 inst.instruction |= inst.operands[0].reg;
11279 inst.instruction |= inst.operands[1].reg << 3;
11283 static void
11284 do_t_orn (void)
11286 unsigned Rd, Rn;
11288 Rd = inst.operands[0].reg;
11289 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11291 reject_bad_reg (Rd);
11292 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11293 reject_bad_reg (Rn);
11295 inst.instruction |= Rd << 8;
11296 inst.instruction |= Rn << 16;
11298 if (!inst.operands[2].isreg)
11300 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11301 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11303 else
11305 unsigned Rm;
11307 Rm = inst.operands[2].reg;
11308 reject_bad_reg (Rm);
11310 constraint (inst.operands[2].shifted
11311 && inst.operands[2].immisreg,
11312 _("shift must be constant"));
11313 encode_thumb32_shifted_operand (2);
11317 static void
11318 do_t_pkhbt (void)
11320 unsigned Rd, Rn, Rm;
11322 Rd = inst.operands[0].reg;
11323 Rn = inst.operands[1].reg;
11324 Rm = inst.operands[2].reg;
11326 reject_bad_reg (Rd);
11327 reject_bad_reg (Rn);
11328 reject_bad_reg (Rm);
11330 inst.instruction |= Rd << 8;
11331 inst.instruction |= Rn << 16;
11332 inst.instruction |= Rm;
11333 if (inst.operands[3].present)
11335 unsigned int val = inst.reloc.exp.X_add_number;
11336 constraint (inst.reloc.exp.X_op != O_constant,
11337 _("expression too complex"));
11338 inst.instruction |= (val & 0x1c) << 10;
11339 inst.instruction |= (val & 0x03) << 6;
11343 static void
11344 do_t_pkhtb (void)
11346 if (!inst.operands[3].present)
11348 unsigned Rtmp;
11350 inst.instruction &= ~0x00000020;
11352 /* PR 10168. Swap the Rm and Rn registers. */
11353 Rtmp = inst.operands[1].reg;
11354 inst.operands[1].reg = inst.operands[2].reg;
11355 inst.operands[2].reg = Rtmp;
11357 do_t_pkhbt ();
11360 static void
11361 do_t_pld (void)
11363 if (inst.operands[0].immisreg)
11364 reject_bad_reg (inst.operands[0].imm);
11366 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11369 static void
11370 do_t_push_pop (void)
11372 unsigned mask;
11374 constraint (inst.operands[0].writeback,
11375 _("push/pop do not support {reglist}^"));
11376 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11377 _("expression too complex"));
11379 mask = inst.operands[0].imm;
11380 if ((mask & ~0xff) == 0)
11381 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
11382 else if ((inst.instruction == T_MNEM_push
11383 && (mask & ~0xff) == 1 << REG_LR)
11384 || (inst.instruction == T_MNEM_pop
11385 && (mask & ~0xff) == 1 << REG_PC))
11387 inst.instruction = THUMB_OP16 (inst.instruction);
11388 inst.instruction |= THUMB_PP_PC_LR;
11389 inst.instruction |= mask & 0xff;
11391 else if (unified_syntax)
11393 inst.instruction = THUMB_OP32 (inst.instruction);
11394 encode_thumb2_ldmstm (13, mask, TRUE);
11396 else
11398 inst.error = _("invalid register list to push/pop instruction");
11399 return;
11403 static void
11404 do_t_rbit (void)
11406 unsigned Rd, Rm;
11408 Rd = inst.operands[0].reg;
11409 Rm = inst.operands[1].reg;
11411 reject_bad_reg (Rd);
11412 reject_bad_reg (Rm);
11414 inst.instruction |= Rd << 8;
11415 inst.instruction |= Rm << 16;
11416 inst.instruction |= Rm;
11419 static void
11420 do_t_rev (void)
11422 unsigned Rd, Rm;
11424 Rd = inst.operands[0].reg;
11425 Rm = inst.operands[1].reg;
11427 reject_bad_reg (Rd);
11428 reject_bad_reg (Rm);
11430 if (Rd <= 7 && Rm <= 7
11431 && inst.size_req != 4)
11433 inst.instruction = THUMB_OP16 (inst.instruction);
11434 inst.instruction |= Rd;
11435 inst.instruction |= Rm << 3;
11437 else if (unified_syntax)
11439 inst.instruction = THUMB_OP32 (inst.instruction);
11440 inst.instruction |= Rd << 8;
11441 inst.instruction |= Rm << 16;
11442 inst.instruction |= Rm;
11444 else
11445 inst.error = BAD_HIREG;
11448 static void
11449 do_t_rrx (void)
11451 unsigned Rd, Rm;
11453 Rd = inst.operands[0].reg;
11454 Rm = inst.operands[1].reg;
11456 reject_bad_reg (Rd);
11457 reject_bad_reg (Rm);
11459 inst.instruction |= Rd << 8;
11460 inst.instruction |= Rm;
11463 static void
11464 do_t_rsb (void)
11466 unsigned Rd, Rs;
11468 Rd = inst.operands[0].reg;
11469 Rs = (inst.operands[1].present
11470 ? inst.operands[1].reg /* Rd, Rs, foo */
11471 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11473 reject_bad_reg (Rd);
11474 reject_bad_reg (Rs);
11475 if (inst.operands[2].isreg)
11476 reject_bad_reg (inst.operands[2].reg);
11478 inst.instruction |= Rd << 8;
11479 inst.instruction |= Rs << 16;
11480 if (!inst.operands[2].isreg)
11482 bfd_boolean narrow;
11484 if ((inst.instruction & 0x00100000) != 0)
11485 narrow = !in_it_block ();
11486 else
11487 narrow = in_it_block ();
11489 if (Rd > 7 || Rs > 7)
11490 narrow = FALSE;
11492 if (inst.size_req == 4 || !unified_syntax)
11493 narrow = FALSE;
11495 if (inst.reloc.exp.X_op != O_constant
11496 || inst.reloc.exp.X_add_number != 0)
11497 narrow = FALSE;
11499 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11500 relaxation, but it doesn't seem worth the hassle. */
11501 if (narrow)
11503 inst.reloc.type = BFD_RELOC_UNUSED;
11504 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11505 inst.instruction |= Rs << 3;
11506 inst.instruction |= Rd;
11508 else
11510 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11511 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11514 else
11515 encode_thumb32_shifted_operand (2);
11518 static void
11519 do_t_setend (void)
11521 set_it_insn_type (OUTSIDE_IT_INSN);
11522 if (inst.operands[0].imm)
11523 inst.instruction |= 0x8;
11526 static void
11527 do_t_shift (void)
11529 if (!inst.operands[1].present)
11530 inst.operands[1].reg = inst.operands[0].reg;
11532 if (unified_syntax)
11534 bfd_boolean narrow;
11535 int shift_kind;
11537 switch (inst.instruction)
11539 case T_MNEM_asr:
11540 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11541 case T_MNEM_lsl:
11542 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11543 case T_MNEM_lsr:
11544 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11545 case T_MNEM_ror:
11546 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11547 default: abort ();
11550 if (THUMB_SETS_FLAGS (inst.instruction))
11551 narrow = !in_it_block ();
11552 else
11553 narrow = in_it_block ();
11554 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11555 narrow = FALSE;
11556 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11557 narrow = FALSE;
11558 if (inst.operands[2].isreg
11559 && (inst.operands[1].reg != inst.operands[0].reg
11560 || inst.operands[2].reg > 7))
11561 narrow = FALSE;
11562 if (inst.size_req == 4)
11563 narrow = FALSE;
11565 reject_bad_reg (inst.operands[0].reg);
11566 reject_bad_reg (inst.operands[1].reg);
11568 if (!narrow)
11570 if (inst.operands[2].isreg)
11572 reject_bad_reg (inst.operands[2].reg);
11573 inst.instruction = THUMB_OP32 (inst.instruction);
11574 inst.instruction |= inst.operands[0].reg << 8;
11575 inst.instruction |= inst.operands[1].reg << 16;
11576 inst.instruction |= inst.operands[2].reg;
11578 /* PR 12854: Error on extraneous shifts. */
11579 constraint (inst.operands[2].shifted,
11580 _("extraneous shift as part of operand to shift insn"));
11582 else
11584 inst.operands[1].shifted = 1;
11585 inst.operands[1].shift_kind = shift_kind;
11586 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11587 ? T_MNEM_movs : T_MNEM_mov);
11588 inst.instruction |= inst.operands[0].reg << 8;
11589 encode_thumb32_shifted_operand (1);
11590 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11591 inst.reloc.type = BFD_RELOC_UNUSED;
11594 else
11596 if (inst.operands[2].isreg)
11598 switch (shift_kind)
11600 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11601 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11602 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11603 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
11604 default: abort ();
11607 inst.instruction |= inst.operands[0].reg;
11608 inst.instruction |= inst.operands[2].reg << 3;
11610 /* PR 12854: Error on extraneous shifts. */
11611 constraint (inst.operands[2].shifted,
11612 _("extraneous shift as part of operand to shift insn"));
11614 else
11616 switch (shift_kind)
11618 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11619 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11620 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11621 default: abort ();
11623 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11624 inst.instruction |= inst.operands[0].reg;
11625 inst.instruction |= inst.operands[1].reg << 3;
11629 else
11631 constraint (inst.operands[0].reg > 7
11632 || inst.operands[1].reg > 7, BAD_HIREG);
11633 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11635 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11637 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11638 constraint (inst.operands[0].reg != inst.operands[1].reg,
11639 _("source1 and dest must be same register"));
11641 switch (inst.instruction)
11643 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11644 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11645 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11646 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11647 default: abort ();
11650 inst.instruction |= inst.operands[0].reg;
11651 inst.instruction |= inst.operands[2].reg << 3;
11653 /* PR 12854: Error on extraneous shifts. */
11654 constraint (inst.operands[2].shifted,
11655 _("extraneous shift as part of operand to shift insn"));
11657 else
11659 switch (inst.instruction)
11661 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11662 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11663 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11664 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11665 default: abort ();
11667 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11668 inst.instruction |= inst.operands[0].reg;
11669 inst.instruction |= inst.operands[1].reg << 3;
11674 static void
11675 do_t_simd (void)
11677 unsigned Rd, Rn, Rm;
11679 Rd = inst.operands[0].reg;
11680 Rn = inst.operands[1].reg;
11681 Rm = inst.operands[2].reg;
11683 reject_bad_reg (Rd);
11684 reject_bad_reg (Rn);
11685 reject_bad_reg (Rm);
11687 inst.instruction |= Rd << 8;
11688 inst.instruction |= Rn << 16;
11689 inst.instruction |= Rm;
11692 static void
11693 do_t_simd2 (void)
11695 unsigned Rd, Rn, Rm;
11697 Rd = inst.operands[0].reg;
11698 Rm = inst.operands[1].reg;
11699 Rn = inst.operands[2].reg;
11701 reject_bad_reg (Rd);
11702 reject_bad_reg (Rn);
11703 reject_bad_reg (Rm);
11705 inst.instruction |= Rd << 8;
11706 inst.instruction |= Rn << 16;
11707 inst.instruction |= Rm;
11710 static void
11711 do_t_smc (void)
11713 unsigned int value = inst.reloc.exp.X_add_number;
11714 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11715 _("SMC is not permitted on this architecture"));
11716 constraint (inst.reloc.exp.X_op != O_constant,
11717 _("expression too complex"));
11718 inst.reloc.type = BFD_RELOC_UNUSED;
11719 inst.instruction |= (value & 0xf000) >> 12;
11720 inst.instruction |= (value & 0x0ff0);
11721 inst.instruction |= (value & 0x000f) << 16;
11724 static void
11725 do_t_hvc (void)
11727 unsigned int value = inst.reloc.exp.X_add_number;
11729 inst.reloc.type = BFD_RELOC_UNUSED;
11730 inst.instruction |= (value & 0x0fff);
11731 inst.instruction |= (value & 0xf000) << 4;
11734 static void
11735 do_t_ssat_usat (int bias)
11737 unsigned Rd, Rn;
11739 Rd = inst.operands[0].reg;
11740 Rn = inst.operands[2].reg;
11742 reject_bad_reg (Rd);
11743 reject_bad_reg (Rn);
11745 inst.instruction |= Rd << 8;
11746 inst.instruction |= inst.operands[1].imm - bias;
11747 inst.instruction |= Rn << 16;
11749 if (inst.operands[3].present)
11751 offsetT shift_amount = inst.reloc.exp.X_add_number;
11753 inst.reloc.type = BFD_RELOC_UNUSED;
11755 constraint (inst.reloc.exp.X_op != O_constant,
11756 _("expression too complex"));
11758 if (shift_amount != 0)
11760 constraint (shift_amount > 31,
11761 _("shift expression is too large"));
11763 if (inst.operands[3].shift_kind == SHIFT_ASR)
11764 inst.instruction |= 0x00200000; /* sh bit. */
11766 inst.instruction |= (shift_amount & 0x1c) << 10;
11767 inst.instruction |= (shift_amount & 0x03) << 6;
11772 static void
11773 do_t_ssat (void)
11775 do_t_ssat_usat (1);
11778 static void
11779 do_t_ssat16 (void)
11781 unsigned Rd, Rn;
11783 Rd = inst.operands[0].reg;
11784 Rn = inst.operands[2].reg;
11786 reject_bad_reg (Rd);
11787 reject_bad_reg (Rn);
11789 inst.instruction |= Rd << 8;
11790 inst.instruction |= inst.operands[1].imm - 1;
11791 inst.instruction |= Rn << 16;
11794 static void
11795 do_t_strex (void)
11797 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11798 || inst.operands[2].postind || inst.operands[2].writeback
11799 || inst.operands[2].immisreg || inst.operands[2].shifted
11800 || inst.operands[2].negative,
11801 BAD_ADDR_MODE);
11803 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11805 inst.instruction |= inst.operands[0].reg << 8;
11806 inst.instruction |= inst.operands[1].reg << 12;
11807 inst.instruction |= inst.operands[2].reg << 16;
11808 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11811 static void
11812 do_t_strexd (void)
11814 if (!inst.operands[2].present)
11815 inst.operands[2].reg = inst.operands[1].reg + 1;
11817 constraint (inst.operands[0].reg == inst.operands[1].reg
11818 || inst.operands[0].reg == inst.operands[2].reg
11819 || inst.operands[0].reg == inst.operands[3].reg,
11820 BAD_OVERLAP);
11822 inst.instruction |= inst.operands[0].reg;
11823 inst.instruction |= inst.operands[1].reg << 12;
11824 inst.instruction |= inst.operands[2].reg << 8;
11825 inst.instruction |= inst.operands[3].reg << 16;
11828 static void
11829 do_t_sxtah (void)
11831 unsigned Rd, Rn, Rm;
11833 Rd = inst.operands[0].reg;
11834 Rn = inst.operands[1].reg;
11835 Rm = inst.operands[2].reg;
11837 reject_bad_reg (Rd);
11838 reject_bad_reg (Rn);
11839 reject_bad_reg (Rm);
11841 inst.instruction |= Rd << 8;
11842 inst.instruction |= Rn << 16;
11843 inst.instruction |= Rm;
11844 inst.instruction |= inst.operands[3].imm << 4;
11847 static void
11848 do_t_sxth (void)
11850 unsigned Rd, Rm;
11852 Rd = inst.operands[0].reg;
11853 Rm = inst.operands[1].reg;
11855 reject_bad_reg (Rd);
11856 reject_bad_reg (Rm);
11858 if (inst.instruction <= 0xffff
11859 && inst.size_req != 4
11860 && Rd <= 7 && Rm <= 7
11861 && (!inst.operands[2].present || inst.operands[2].imm == 0))
11863 inst.instruction = THUMB_OP16 (inst.instruction);
11864 inst.instruction |= Rd;
11865 inst.instruction |= Rm << 3;
11867 else if (unified_syntax)
11869 if (inst.instruction <= 0xffff)
11870 inst.instruction = THUMB_OP32 (inst.instruction);
11871 inst.instruction |= Rd << 8;
11872 inst.instruction |= Rm;
11873 inst.instruction |= inst.operands[2].imm << 4;
11875 else
11877 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11878 _("Thumb encoding does not support rotation"));
11879 constraint (1, BAD_HIREG);
11883 static void
11884 do_t_swi (void)
11886 /* We have to do the following check manually as ARM_EXT_OS only applies
11887 to ARM_EXT_V6M. */
11888 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
11890 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
11891 /* This only applies to the v6m howver, not later architectures. */
11892 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
11893 as_bad (_("SVC is not permitted on this architecture"));
11894 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
11897 inst.reloc.type = BFD_RELOC_ARM_SWI;
11900 static void
11901 do_t_tb (void)
11903 unsigned Rn, Rm;
11904 int half;
11906 half = (inst.instruction & 0x10) != 0;
11907 set_it_insn_type_last ();
11908 constraint (inst.operands[0].immisreg,
11909 _("instruction requires register index"));
11911 Rn = inst.operands[0].reg;
11912 Rm = inst.operands[0].imm;
11914 constraint (Rn == REG_SP, BAD_SP);
11915 reject_bad_reg (Rm);
11917 constraint (!half && inst.operands[0].shifted,
11918 _("instruction does not allow shifted index"));
11919 inst.instruction |= (Rn << 16) | Rm;
11922 static void
11923 do_t_usat (void)
11925 do_t_ssat_usat (0);
11928 static void
11929 do_t_usat16 (void)
11931 unsigned Rd, Rn;
11933 Rd = inst.operands[0].reg;
11934 Rn = inst.operands[2].reg;
11936 reject_bad_reg (Rd);
11937 reject_bad_reg (Rn);
11939 inst.instruction |= Rd << 8;
11940 inst.instruction |= inst.operands[1].imm;
11941 inst.instruction |= Rn << 16;
11944 /* Neon instruction encoder helpers. */
11946 /* Encodings for the different types for various Neon opcodes. */
11948 /* An "invalid" code for the following tables. */
11949 #define N_INV -1u
11951 struct neon_tab_entry
11953 unsigned integer;
11954 unsigned float_or_poly;
11955 unsigned scalar_or_imm;
11958 /* Map overloaded Neon opcodes to their respective encodings. */
11959 #define NEON_ENC_TAB \
11960 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11961 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11962 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11963 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11964 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11965 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11966 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11967 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11968 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11969 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11970 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11971 /* Register variants of the following two instructions are encoded as
11972 vcge / vcgt with the operands reversed. */ \
11973 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11974 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
11975 X(vfma, N_INV, 0x0000c10, N_INV), \
11976 X(vfms, N_INV, 0x0200c10, N_INV), \
11977 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11978 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11979 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11980 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11981 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11982 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11983 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11984 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11985 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11986 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11987 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11988 X(vshl, 0x0000400, N_INV, 0x0800510), \
11989 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11990 X(vand, 0x0000110, N_INV, 0x0800030), \
11991 X(vbic, 0x0100110, N_INV, 0x0800030), \
11992 X(veor, 0x1000110, N_INV, N_INV), \
11993 X(vorn, 0x0300110, N_INV, 0x0800010), \
11994 X(vorr, 0x0200110, N_INV, 0x0800010), \
11995 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11996 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11997 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11998 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11999 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12000 X(vst1, 0x0000000, 0x0800000, N_INV), \
12001 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12002 X(vst2, 0x0000100, 0x0800100, N_INV), \
12003 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12004 X(vst3, 0x0000200, 0x0800200, N_INV), \
12005 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12006 X(vst4, 0x0000300, 0x0800300, N_INV), \
12007 X(vmovn, 0x1b20200, N_INV, N_INV), \
12008 X(vtrn, 0x1b20080, N_INV, N_INV), \
12009 X(vqmovn, 0x1b20200, N_INV, N_INV), \
12010 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12011 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
12012 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12013 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
12014 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12015 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
12016 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12017 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12018 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
12019 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
12021 enum neon_opc
12023 #define X(OPC,I,F,S) N_MNEM_##OPC
12024 NEON_ENC_TAB
12025 #undef X
12028 static const struct neon_tab_entry neon_enc_tab[] =
12030 #define X(OPC,I,F,S) { (I), (F), (S) }
12031 NEON_ENC_TAB
12032 #undef X
12035 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
12036 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12037 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12038 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12039 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12040 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12041 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12042 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12043 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12044 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12045 #define NEON_ENC_SINGLE_(X) \
12046 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
12047 #define NEON_ENC_DOUBLE_(X) \
12048 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
12050 #define NEON_ENCODE(type, inst) \
12051 do \
12053 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12054 inst.is_neon = 1; \
12056 while (0)
12058 #define check_neon_suffixes \
12059 do \
12061 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12063 as_bad (_("invalid neon suffix for non neon instruction")); \
12064 return; \
12067 while (0)
12069 /* Define shapes for instruction operands. The following mnemonic characters
12070 are used in this table:
12072 F - VFP S<n> register
12073 D - Neon D<n> register
12074 Q - Neon Q<n> register
12075 I - Immediate
12076 S - Scalar
12077 R - ARM register
12078 L - D<n> register list
12080 This table is used to generate various data:
12081 - enumerations of the form NS_DDR to be used as arguments to
12082 neon_select_shape.
12083 - a table classifying shapes into single, double, quad, mixed.
12084 - a table used to drive neon_select_shape. */
12086 #define NEON_SHAPE_DEF \
12087 X(3, (D, D, D), DOUBLE), \
12088 X(3, (Q, Q, Q), QUAD), \
12089 X(3, (D, D, I), DOUBLE), \
12090 X(3, (Q, Q, I), QUAD), \
12091 X(3, (D, D, S), DOUBLE), \
12092 X(3, (Q, Q, S), QUAD), \
12093 X(2, (D, D), DOUBLE), \
12094 X(2, (Q, Q), QUAD), \
12095 X(2, (D, S), DOUBLE), \
12096 X(2, (Q, S), QUAD), \
12097 X(2, (D, R), DOUBLE), \
12098 X(2, (Q, R), QUAD), \
12099 X(2, (D, I), DOUBLE), \
12100 X(2, (Q, I), QUAD), \
12101 X(3, (D, L, D), DOUBLE), \
12102 X(2, (D, Q), MIXED), \
12103 X(2, (Q, D), MIXED), \
12104 X(3, (D, Q, I), MIXED), \
12105 X(3, (Q, D, I), MIXED), \
12106 X(3, (Q, D, D), MIXED), \
12107 X(3, (D, Q, Q), MIXED), \
12108 X(3, (Q, Q, D), MIXED), \
12109 X(3, (Q, D, S), MIXED), \
12110 X(3, (D, Q, S), MIXED), \
12111 X(4, (D, D, D, I), DOUBLE), \
12112 X(4, (Q, Q, Q, I), QUAD), \
12113 X(2, (F, F), SINGLE), \
12114 X(3, (F, F, F), SINGLE), \
12115 X(2, (F, I), SINGLE), \
12116 X(2, (F, D), MIXED), \
12117 X(2, (D, F), MIXED), \
12118 X(3, (F, F, I), MIXED), \
12119 X(4, (R, R, F, F), SINGLE), \
12120 X(4, (F, F, R, R), SINGLE), \
12121 X(3, (D, R, R), DOUBLE), \
12122 X(3, (R, R, D), DOUBLE), \
12123 X(2, (S, R), SINGLE), \
12124 X(2, (R, S), SINGLE), \
12125 X(2, (F, R), SINGLE), \
12126 X(2, (R, F), SINGLE)
12128 #define S2(A,B) NS_##A##B
12129 #define S3(A,B,C) NS_##A##B##C
12130 #define S4(A,B,C,D) NS_##A##B##C##D
12132 #define X(N, L, C) S##N L
12134 enum neon_shape
12136 NEON_SHAPE_DEF,
12137 NS_NULL
12140 #undef X
12141 #undef S2
12142 #undef S3
12143 #undef S4
12145 enum neon_shape_class
12147 SC_SINGLE,
12148 SC_DOUBLE,
12149 SC_QUAD,
12150 SC_MIXED
12153 #define X(N, L, C) SC_##C
12155 static enum neon_shape_class neon_shape_class[] =
12157 NEON_SHAPE_DEF
12160 #undef X
12162 enum neon_shape_el
12164 SE_F,
12165 SE_D,
12166 SE_Q,
12167 SE_I,
12168 SE_S,
12169 SE_R,
12170 SE_L
12173 /* Register widths of above. */
12174 static unsigned neon_shape_el_size[] =
12178 128,
12185 struct neon_shape_info
12187 unsigned els;
12188 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12191 #define S2(A,B) { SE_##A, SE_##B }
12192 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12193 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12195 #define X(N, L, C) { N, S##N L }
12197 static struct neon_shape_info neon_shape_tab[] =
12199 NEON_SHAPE_DEF
12202 #undef X
12203 #undef S2
12204 #undef S3
12205 #undef S4
12207 /* Bit masks used in type checking given instructions.
12208 'N_EQK' means the type must be the same as (or based on in some way) the key
12209 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12210 set, various other bits can be set as well in order to modify the meaning of
12211 the type constraint. */
12213 enum neon_type_mask
12215 N_S8 = 0x0000001,
12216 N_S16 = 0x0000002,
12217 N_S32 = 0x0000004,
12218 N_S64 = 0x0000008,
12219 N_U8 = 0x0000010,
12220 N_U16 = 0x0000020,
12221 N_U32 = 0x0000040,
12222 N_U64 = 0x0000080,
12223 N_I8 = 0x0000100,
12224 N_I16 = 0x0000200,
12225 N_I32 = 0x0000400,
12226 N_I64 = 0x0000800,
12227 N_8 = 0x0001000,
12228 N_16 = 0x0002000,
12229 N_32 = 0x0004000,
12230 N_64 = 0x0008000,
12231 N_P8 = 0x0010000,
12232 N_P16 = 0x0020000,
12233 N_F16 = 0x0040000,
12234 N_F32 = 0x0080000,
12235 N_F64 = 0x0100000,
12236 N_KEY = 0x1000000, /* Key element (main type specifier). */
12237 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
12238 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
12239 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12240 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12241 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12242 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12243 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12244 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12245 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
12246 N_UTYP = 0,
12247 N_MAX_NONSPECIAL = N_F64
12250 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12252 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12253 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12254 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12255 #define N_SUF_32 (N_SU_32 | N_F32)
12256 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12257 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12259 /* Pass this as the first type argument to neon_check_type to ignore types
12260 altogether. */
12261 #define N_IGNORE_TYPE (N_KEY | N_EQK)
12263 /* Select a "shape" for the current instruction (describing register types or
12264 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12265 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12266 function of operand parsing, so this function doesn't need to be called.
12267 Shapes should be listed in order of decreasing length. */
12269 static enum neon_shape
12270 neon_select_shape (enum neon_shape shape, ...)
12272 va_list ap;
12273 enum neon_shape first_shape = shape;
12275 /* Fix missing optional operands. FIXME: we don't know at this point how
12276 many arguments we should have, so this makes the assumption that we have
12277 > 1. This is true of all current Neon opcodes, I think, but may not be
12278 true in the future. */
12279 if (!inst.operands[1].present)
12280 inst.operands[1] = inst.operands[0];
12282 va_start (ap, shape);
12284 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
12286 unsigned j;
12287 int matches = 1;
12289 for (j = 0; j < neon_shape_tab[shape].els; j++)
12291 if (!inst.operands[j].present)
12293 matches = 0;
12294 break;
12297 switch (neon_shape_tab[shape].el[j])
12299 case SE_F:
12300 if (!(inst.operands[j].isreg
12301 && inst.operands[j].isvec
12302 && inst.operands[j].issingle
12303 && !inst.operands[j].isquad))
12304 matches = 0;
12305 break;
12307 case SE_D:
12308 if (!(inst.operands[j].isreg
12309 && inst.operands[j].isvec
12310 && !inst.operands[j].isquad
12311 && !inst.operands[j].issingle))
12312 matches = 0;
12313 break;
12315 case SE_R:
12316 if (!(inst.operands[j].isreg
12317 && !inst.operands[j].isvec))
12318 matches = 0;
12319 break;
12321 case SE_Q:
12322 if (!(inst.operands[j].isreg
12323 && inst.operands[j].isvec
12324 && inst.operands[j].isquad
12325 && !inst.operands[j].issingle))
12326 matches = 0;
12327 break;
12329 case SE_I:
12330 if (!(!inst.operands[j].isreg
12331 && !inst.operands[j].isscalar))
12332 matches = 0;
12333 break;
12335 case SE_S:
12336 if (!(!inst.operands[j].isreg
12337 && inst.operands[j].isscalar))
12338 matches = 0;
12339 break;
12341 case SE_L:
12342 break;
12344 if (!matches)
12345 break;
12347 if (matches)
12348 break;
12351 va_end (ap);
12353 if (shape == NS_NULL && first_shape != NS_NULL)
12354 first_error (_("invalid instruction shape"));
12356 return shape;
12359 /* True if SHAPE is predominantly a quadword operation (most of the time, this
12360 means the Q bit should be set). */
12362 static int
12363 neon_quad (enum neon_shape shape)
12365 return neon_shape_class[shape] == SC_QUAD;
12368 static void
12369 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12370 unsigned *g_size)
12372 /* Allow modification to be made to types which are constrained to be
12373 based on the key element, based on bits set alongside N_EQK. */
12374 if ((typebits & N_EQK) != 0)
12376 if ((typebits & N_HLF) != 0)
12377 *g_size /= 2;
12378 else if ((typebits & N_DBL) != 0)
12379 *g_size *= 2;
12380 if ((typebits & N_SGN) != 0)
12381 *g_type = NT_signed;
12382 else if ((typebits & N_UNS) != 0)
12383 *g_type = NT_unsigned;
12384 else if ((typebits & N_INT) != 0)
12385 *g_type = NT_integer;
12386 else if ((typebits & N_FLT) != 0)
12387 *g_type = NT_float;
12388 else if ((typebits & N_SIZ) != 0)
12389 *g_type = NT_untyped;
12393 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12394 operand type, i.e. the single type specified in a Neon instruction when it
12395 is the only one given. */
12397 static struct neon_type_el
12398 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12400 struct neon_type_el dest = *key;
12402 gas_assert ((thisarg & N_EQK) != 0);
12404 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12406 return dest;
12409 /* Convert Neon type and size into compact bitmask representation. */
12411 static enum neon_type_mask
12412 type_chk_of_el_type (enum neon_el_type type, unsigned size)
12414 switch (type)
12416 case NT_untyped:
12417 switch (size)
12419 case 8: return N_8;
12420 case 16: return N_16;
12421 case 32: return N_32;
12422 case 64: return N_64;
12423 default: ;
12425 break;
12427 case NT_integer:
12428 switch (size)
12430 case 8: return N_I8;
12431 case 16: return N_I16;
12432 case 32: return N_I32;
12433 case 64: return N_I64;
12434 default: ;
12436 break;
12438 case NT_float:
12439 switch (size)
12441 case 16: return N_F16;
12442 case 32: return N_F32;
12443 case 64: return N_F64;
12444 default: ;
12446 break;
12448 case NT_poly:
12449 switch (size)
12451 case 8: return N_P8;
12452 case 16: return N_P16;
12453 default: ;
12455 break;
12457 case NT_signed:
12458 switch (size)
12460 case 8: return N_S8;
12461 case 16: return N_S16;
12462 case 32: return N_S32;
12463 case 64: return N_S64;
12464 default: ;
12466 break;
12468 case NT_unsigned:
12469 switch (size)
12471 case 8: return N_U8;
12472 case 16: return N_U16;
12473 case 32: return N_U32;
12474 case 64: return N_U64;
12475 default: ;
12477 break;
12479 default: ;
12482 return N_UTYP;
12485 /* Convert compact Neon bitmask type representation to a type and size. Only
12486 handles the case where a single bit is set in the mask. */
12488 static int
12489 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12490 enum neon_type_mask mask)
12492 if ((mask & N_EQK) != 0)
12493 return FAIL;
12495 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12496 *size = 8;
12497 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
12498 *size = 16;
12499 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
12500 *size = 32;
12501 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
12502 *size = 64;
12503 else
12504 return FAIL;
12506 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12507 *type = NT_signed;
12508 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
12509 *type = NT_unsigned;
12510 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
12511 *type = NT_integer;
12512 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
12513 *type = NT_untyped;
12514 else if ((mask & (N_P8 | N_P16)) != 0)
12515 *type = NT_poly;
12516 else if ((mask & (N_F32 | N_F64)) != 0)
12517 *type = NT_float;
12518 else
12519 return FAIL;
12521 return SUCCESS;
12524 /* Modify a bitmask of allowed types. This is only needed for type
12525 relaxation. */
12527 static unsigned
12528 modify_types_allowed (unsigned allowed, unsigned mods)
12530 unsigned size;
12531 enum neon_el_type type;
12532 unsigned destmask;
12533 int i;
12535 destmask = 0;
12537 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12539 if (el_type_of_type_chk (&type, &size,
12540 (enum neon_type_mask) (allowed & i)) == SUCCESS)
12542 neon_modify_type_size (mods, &type, &size);
12543 destmask |= type_chk_of_el_type (type, size);
12547 return destmask;
12550 /* Check type and return type classification.
12551 The manual states (paraphrase): If one datatype is given, it indicates the
12552 type given in:
12553 - the second operand, if there is one
12554 - the operand, if there is no second operand
12555 - the result, if there are no operands.
12556 This isn't quite good enough though, so we use a concept of a "key" datatype
12557 which is set on a per-instruction basis, which is the one which matters when
12558 only one data type is written.
12559 Note: this function has side-effects (e.g. filling in missing operands). All
12560 Neon instructions should call it before performing bit encoding. */
12562 static struct neon_type_el
12563 neon_check_type (unsigned els, enum neon_shape ns, ...)
12565 va_list ap;
12566 unsigned i, pass, key_el = 0;
12567 unsigned types[NEON_MAX_TYPE_ELS];
12568 enum neon_el_type k_type = NT_invtype;
12569 unsigned k_size = -1u;
12570 struct neon_type_el badtype = {NT_invtype, -1};
12571 unsigned key_allowed = 0;
12573 /* Optional registers in Neon instructions are always (not) in operand 1.
12574 Fill in the missing operand here, if it was omitted. */
12575 if (els > 1 && !inst.operands[1].present)
12576 inst.operands[1] = inst.operands[0];
12578 /* Suck up all the varargs. */
12579 va_start (ap, ns);
12580 for (i = 0; i < els; i++)
12582 unsigned thisarg = va_arg (ap, unsigned);
12583 if (thisarg == N_IGNORE_TYPE)
12585 va_end (ap);
12586 return badtype;
12588 types[i] = thisarg;
12589 if ((thisarg & N_KEY) != 0)
12590 key_el = i;
12592 va_end (ap);
12594 if (inst.vectype.elems > 0)
12595 for (i = 0; i < els; i++)
12596 if (inst.operands[i].vectype.type != NT_invtype)
12598 first_error (_("types specified in both the mnemonic and operands"));
12599 return badtype;
12602 /* Duplicate inst.vectype elements here as necessary.
12603 FIXME: No idea if this is exactly the same as the ARM assembler,
12604 particularly when an insn takes one register and one non-register
12605 operand. */
12606 if (inst.vectype.elems == 1 && els > 1)
12608 unsigned j;
12609 inst.vectype.elems = els;
12610 inst.vectype.el[key_el] = inst.vectype.el[0];
12611 for (j = 0; j < els; j++)
12612 if (j != key_el)
12613 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12614 types[j]);
12616 else if (inst.vectype.elems == 0 && els > 0)
12618 unsigned j;
12619 /* No types were given after the mnemonic, so look for types specified
12620 after each operand. We allow some flexibility here; as long as the
12621 "key" operand has a type, we can infer the others. */
12622 for (j = 0; j < els; j++)
12623 if (inst.operands[j].vectype.type != NT_invtype)
12624 inst.vectype.el[j] = inst.operands[j].vectype;
12626 if (inst.operands[key_el].vectype.type != NT_invtype)
12628 for (j = 0; j < els; j++)
12629 if (inst.operands[j].vectype.type == NT_invtype)
12630 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12631 types[j]);
12633 else
12635 first_error (_("operand types can't be inferred"));
12636 return badtype;
12639 else if (inst.vectype.elems != els)
12641 first_error (_("type specifier has the wrong number of parts"));
12642 return badtype;
12645 for (pass = 0; pass < 2; pass++)
12647 for (i = 0; i < els; i++)
12649 unsigned thisarg = types[i];
12650 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12651 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12652 enum neon_el_type g_type = inst.vectype.el[i].type;
12653 unsigned g_size = inst.vectype.el[i].size;
12655 /* Decay more-specific signed & unsigned types to sign-insensitive
12656 integer types if sign-specific variants are unavailable. */
12657 if ((g_type == NT_signed || g_type == NT_unsigned)
12658 && (types_allowed & N_SU_ALL) == 0)
12659 g_type = NT_integer;
12661 /* If only untyped args are allowed, decay any more specific types to
12662 them. Some instructions only care about signs for some element
12663 sizes, so handle that properly. */
12664 if ((g_size == 8 && (types_allowed & N_8) != 0)
12665 || (g_size == 16 && (types_allowed & N_16) != 0)
12666 || (g_size == 32 && (types_allowed & N_32) != 0)
12667 || (g_size == 64 && (types_allowed & N_64) != 0))
12668 g_type = NT_untyped;
12670 if (pass == 0)
12672 if ((thisarg & N_KEY) != 0)
12674 k_type = g_type;
12675 k_size = g_size;
12676 key_allowed = thisarg & ~N_KEY;
12679 else
12681 if ((thisarg & N_VFP) != 0)
12683 enum neon_shape_el regshape;
12684 unsigned regwidth, match;
12686 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12687 if (ns == NS_NULL)
12689 first_error (_("invalid instruction shape"));
12690 return badtype;
12692 regshape = neon_shape_tab[ns].el[i];
12693 regwidth = neon_shape_el_size[regshape];
12695 /* In VFP mode, operands must match register widths. If we
12696 have a key operand, use its width, else use the width of
12697 the current operand. */
12698 if (k_size != -1u)
12699 match = k_size;
12700 else
12701 match = g_size;
12703 if (regwidth != match)
12705 first_error (_("operand size must match register width"));
12706 return badtype;
12710 if ((thisarg & N_EQK) == 0)
12712 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12714 if ((given_type & types_allowed) == 0)
12716 first_error (_("bad type in Neon instruction"));
12717 return badtype;
12720 else
12722 enum neon_el_type mod_k_type = k_type;
12723 unsigned mod_k_size = k_size;
12724 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12725 if (g_type != mod_k_type || g_size != mod_k_size)
12727 first_error (_("inconsistent types in Neon instruction"));
12728 return badtype;
12735 return inst.vectype.el[key_el];
12738 /* Neon-style VFP instruction forwarding. */
12740 /* Thumb VFP instructions have 0xE in the condition field. */
12742 static void
12743 do_vfp_cond_or_thumb (void)
12745 inst.is_neon = 1;
12747 if (thumb_mode)
12748 inst.instruction |= 0xe0000000;
12749 else
12750 inst.instruction |= inst.cond << 28;
12753 /* Look up and encode a simple mnemonic, for use as a helper function for the
12754 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12755 etc. It is assumed that operand parsing has already been done, and that the
12756 operands are in the form expected by the given opcode (this isn't necessarily
12757 the same as the form in which they were parsed, hence some massaging must
12758 take place before this function is called).
12759 Checks current arch version against that in the looked-up opcode. */
12761 static void
12762 do_vfp_nsyn_opcode (const char *opname)
12764 const struct asm_opcode *opcode;
12766 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
12768 if (!opcode)
12769 abort ();
12771 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12772 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12773 _(BAD_FPU));
12775 inst.is_neon = 1;
12777 if (thumb_mode)
12779 inst.instruction = opcode->tvalue;
12780 opcode->tencode ();
12782 else
12784 inst.instruction = (inst.cond << 28) | opcode->avalue;
12785 opcode->aencode ();
12789 static void
12790 do_vfp_nsyn_add_sub (enum neon_shape rs)
12792 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12794 if (rs == NS_FFF)
12796 if (is_add)
12797 do_vfp_nsyn_opcode ("fadds");
12798 else
12799 do_vfp_nsyn_opcode ("fsubs");
12801 else
12803 if (is_add)
12804 do_vfp_nsyn_opcode ("faddd");
12805 else
12806 do_vfp_nsyn_opcode ("fsubd");
12810 /* Check operand types to see if this is a VFP instruction, and if so call
12811 PFN (). */
12813 static int
12814 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12816 enum neon_shape rs;
12817 struct neon_type_el et;
12819 switch (args)
12821 case 2:
12822 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12823 et = neon_check_type (2, rs,
12824 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12825 break;
12827 case 3:
12828 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12829 et = neon_check_type (3, rs,
12830 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12831 break;
12833 default:
12834 abort ();
12837 if (et.type != NT_invtype)
12839 pfn (rs);
12840 return SUCCESS;
12843 inst.error = NULL;
12844 return FAIL;
12847 static void
12848 do_vfp_nsyn_mla_mls (enum neon_shape rs)
12850 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
12852 if (rs == NS_FFF)
12854 if (is_mla)
12855 do_vfp_nsyn_opcode ("fmacs");
12856 else
12857 do_vfp_nsyn_opcode ("fnmacs");
12859 else
12861 if (is_mla)
12862 do_vfp_nsyn_opcode ("fmacd");
12863 else
12864 do_vfp_nsyn_opcode ("fnmacd");
12868 static void
12869 do_vfp_nsyn_fma_fms (enum neon_shape rs)
12871 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12873 if (rs == NS_FFF)
12875 if (is_fma)
12876 do_vfp_nsyn_opcode ("ffmas");
12877 else
12878 do_vfp_nsyn_opcode ("ffnmas");
12880 else
12882 if (is_fma)
12883 do_vfp_nsyn_opcode ("ffmad");
12884 else
12885 do_vfp_nsyn_opcode ("ffnmad");
12889 static void
12890 do_vfp_nsyn_mul (enum neon_shape rs)
12892 if (rs == NS_FFF)
12893 do_vfp_nsyn_opcode ("fmuls");
12894 else
12895 do_vfp_nsyn_opcode ("fmuld");
12898 static void
12899 do_vfp_nsyn_abs_neg (enum neon_shape rs)
12901 int is_neg = (inst.instruction & 0x80) != 0;
12902 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12904 if (rs == NS_FF)
12906 if (is_neg)
12907 do_vfp_nsyn_opcode ("fnegs");
12908 else
12909 do_vfp_nsyn_opcode ("fabss");
12911 else
12913 if (is_neg)
12914 do_vfp_nsyn_opcode ("fnegd");
12915 else
12916 do_vfp_nsyn_opcode ("fabsd");
12920 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12921 insns belong to Neon, and are handled elsewhere. */
12923 static void
12924 do_vfp_nsyn_ldm_stm (int is_dbmode)
12926 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12927 if (is_ldm)
12929 if (is_dbmode)
12930 do_vfp_nsyn_opcode ("fldmdbs");
12931 else
12932 do_vfp_nsyn_opcode ("fldmias");
12934 else
12936 if (is_dbmode)
12937 do_vfp_nsyn_opcode ("fstmdbs");
12938 else
12939 do_vfp_nsyn_opcode ("fstmias");
12943 static void
12944 do_vfp_nsyn_sqrt (void)
12946 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12947 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12949 if (rs == NS_FF)
12950 do_vfp_nsyn_opcode ("fsqrts");
12951 else
12952 do_vfp_nsyn_opcode ("fsqrtd");
12955 static void
12956 do_vfp_nsyn_div (void)
12958 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12959 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12960 N_F32 | N_F64 | N_KEY | N_VFP);
12962 if (rs == NS_FFF)
12963 do_vfp_nsyn_opcode ("fdivs");
12964 else
12965 do_vfp_nsyn_opcode ("fdivd");
12968 static void
12969 do_vfp_nsyn_nmul (void)
12971 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12972 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12973 N_F32 | N_F64 | N_KEY | N_VFP);
12975 if (rs == NS_FFF)
12977 NEON_ENCODE (SINGLE, inst);
12978 do_vfp_sp_dyadic ();
12980 else
12982 NEON_ENCODE (DOUBLE, inst);
12983 do_vfp_dp_rd_rn_rm ();
12985 do_vfp_cond_or_thumb ();
12988 static void
12989 do_vfp_nsyn_cmp (void)
12991 if (inst.operands[1].isreg)
12993 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12994 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12996 if (rs == NS_FF)
12998 NEON_ENCODE (SINGLE, inst);
12999 do_vfp_sp_monadic ();
13001 else
13003 NEON_ENCODE (DOUBLE, inst);
13004 do_vfp_dp_rd_rm ();
13007 else
13009 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13010 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13012 switch (inst.instruction & 0x0fffffff)
13014 case N_MNEM_vcmp:
13015 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13016 break;
13017 case N_MNEM_vcmpe:
13018 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13019 break;
13020 default:
13021 abort ();
13024 if (rs == NS_FI)
13026 NEON_ENCODE (SINGLE, inst);
13027 do_vfp_sp_compare_z ();
13029 else
13031 NEON_ENCODE (DOUBLE, inst);
13032 do_vfp_dp_rd ();
13035 do_vfp_cond_or_thumb ();
13038 static void
13039 nsyn_insert_sp (void)
13041 inst.operands[1] = inst.operands[0];
13042 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
13043 inst.operands[0].reg = REG_SP;
13044 inst.operands[0].isreg = 1;
13045 inst.operands[0].writeback = 1;
13046 inst.operands[0].present = 1;
13049 static void
13050 do_vfp_nsyn_push (void)
13052 nsyn_insert_sp ();
13053 if (inst.operands[1].issingle)
13054 do_vfp_nsyn_opcode ("fstmdbs");
13055 else
13056 do_vfp_nsyn_opcode ("fstmdbd");
13059 static void
13060 do_vfp_nsyn_pop (void)
13062 nsyn_insert_sp ();
13063 if (inst.operands[1].issingle)
13064 do_vfp_nsyn_opcode ("fldmias");
13065 else
13066 do_vfp_nsyn_opcode ("fldmiad");
13069 /* Fix up Neon data-processing instructions, ORing in the correct bits for
13070 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13072 static void
13073 neon_dp_fixup (struct arm_it* insn)
13075 unsigned int i = insn->instruction;
13076 insn->is_neon = 1;
13078 if (thumb_mode)
13080 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13081 if (i & (1 << 24))
13082 i |= 1 << 28;
13084 i &= ~(1 << 24);
13086 i |= 0xef000000;
13088 else
13089 i |= 0xf2000000;
13091 insn->instruction = i;
13094 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13095 (0, 1, 2, 3). */
13097 static unsigned
13098 neon_logbits (unsigned x)
13100 return ffs (x) - 4;
13103 #define LOW4(R) ((R) & 0xf)
13104 #define HI1(R) (((R) >> 4) & 1)
13106 /* Encode insns with bit pattern:
13108 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13109 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
13111 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13112 different meaning for some instruction. */
13114 static void
13115 neon_three_same (int isquad, int ubit, int size)
13117 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13118 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13119 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13120 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13121 inst.instruction |= LOW4 (inst.operands[2].reg);
13122 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13123 inst.instruction |= (isquad != 0) << 6;
13124 inst.instruction |= (ubit != 0) << 24;
13125 if (size != -1)
13126 inst.instruction |= neon_logbits (size) << 20;
13128 neon_dp_fixup (&inst);
13131 /* Encode instructions of the form:
13133 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13134 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
13136 Don't write size if SIZE == -1. */
13138 static void
13139 neon_two_same (int qbit, int ubit, int size)
13141 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13142 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13143 inst.instruction |= LOW4 (inst.operands[1].reg);
13144 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13145 inst.instruction |= (qbit != 0) << 6;
13146 inst.instruction |= (ubit != 0) << 24;
13148 if (size != -1)
13149 inst.instruction |= neon_logbits (size) << 18;
13151 neon_dp_fixup (&inst);
13154 /* Neon instruction encoders, in approximate order of appearance. */
13156 static void
13157 do_neon_dyadic_i_su (void)
13159 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13160 struct neon_type_el et = neon_check_type (3, rs,
13161 N_EQK, N_EQK, N_SU_32 | N_KEY);
13162 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13165 static void
13166 do_neon_dyadic_i64_su (void)
13168 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13169 struct neon_type_el et = neon_check_type (3, rs,
13170 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13171 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13174 static void
13175 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13176 unsigned immbits)
13178 unsigned size = et.size >> 3;
13179 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13180 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13181 inst.instruction |= LOW4 (inst.operands[1].reg);
13182 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13183 inst.instruction |= (isquad != 0) << 6;
13184 inst.instruction |= immbits << 16;
13185 inst.instruction |= (size >> 3) << 7;
13186 inst.instruction |= (size & 0x7) << 19;
13187 if (write_ubit)
13188 inst.instruction |= (uval != 0) << 24;
13190 neon_dp_fixup (&inst);
13193 static void
13194 do_neon_shl_imm (void)
13196 if (!inst.operands[2].isreg)
13198 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13199 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
13200 NEON_ENCODE (IMMED, inst);
13201 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
13203 else
13205 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13206 struct neon_type_el et = neon_check_type (3, rs,
13207 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
13208 unsigned int tmp;
13210 /* VSHL/VQSHL 3-register variants have syntax such as:
13211 vshl.xx Dd, Dm, Dn
13212 whereas other 3-register operations encoded by neon_three_same have
13213 syntax like:
13214 vadd.xx Dd, Dn, Dm
13215 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13216 here. */
13217 tmp = inst.operands[2].reg;
13218 inst.operands[2].reg = inst.operands[1].reg;
13219 inst.operands[1].reg = tmp;
13220 NEON_ENCODE (INTEGER, inst);
13221 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13225 static void
13226 do_neon_qshl_imm (void)
13228 if (!inst.operands[2].isreg)
13230 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13231 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13233 NEON_ENCODE (IMMED, inst);
13234 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13235 inst.operands[2].imm);
13237 else
13239 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13240 struct neon_type_el et = neon_check_type (3, rs,
13241 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
13242 unsigned int tmp;
13244 /* See note in do_neon_shl_imm. */
13245 tmp = inst.operands[2].reg;
13246 inst.operands[2].reg = inst.operands[1].reg;
13247 inst.operands[1].reg = tmp;
13248 NEON_ENCODE (INTEGER, inst);
13249 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13253 static void
13254 do_neon_rshl (void)
13256 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13257 struct neon_type_el et = neon_check_type (3, rs,
13258 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13259 unsigned int tmp;
13261 tmp = inst.operands[2].reg;
13262 inst.operands[2].reg = inst.operands[1].reg;
13263 inst.operands[1].reg = tmp;
13264 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13267 static int
13268 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13270 /* Handle .I8 pseudo-instructions. */
13271 if (size == 8)
13273 /* Unfortunately, this will make everything apart from zero out-of-range.
13274 FIXME is this the intended semantics? There doesn't seem much point in
13275 accepting .I8 if so. */
13276 immediate |= immediate << 8;
13277 size = 16;
13280 if (size >= 32)
13282 if (immediate == (immediate & 0x000000ff))
13284 *immbits = immediate;
13285 return 0x1;
13287 else if (immediate == (immediate & 0x0000ff00))
13289 *immbits = immediate >> 8;
13290 return 0x3;
13292 else if (immediate == (immediate & 0x00ff0000))
13294 *immbits = immediate >> 16;
13295 return 0x5;
13297 else if (immediate == (immediate & 0xff000000))
13299 *immbits = immediate >> 24;
13300 return 0x7;
13302 if ((immediate & 0xffff) != (immediate >> 16))
13303 goto bad_immediate;
13304 immediate &= 0xffff;
13307 if (immediate == (immediate & 0x000000ff))
13309 *immbits = immediate;
13310 return 0x9;
13312 else if (immediate == (immediate & 0x0000ff00))
13314 *immbits = immediate >> 8;
13315 return 0xb;
13318 bad_immediate:
13319 first_error (_("immediate value out of range"));
13320 return FAIL;
13323 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13324 A, B, C, D. */
13326 static int
13327 neon_bits_same_in_bytes (unsigned imm)
13329 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13330 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13331 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13332 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13335 /* For immediate of above form, return 0bABCD. */
13337 static unsigned
13338 neon_squash_bits (unsigned imm)
13340 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13341 | ((imm & 0x01000000) >> 21);
13344 /* Compress quarter-float representation to 0b...000 abcdefgh. */
13346 static unsigned
13347 neon_qfloat_bits (unsigned imm)
13349 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
13352 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13353 the instruction. *OP is passed as the initial value of the op field, and
13354 may be set to a different value depending on the constant (i.e.
13355 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
13356 MVN). If the immediate looks like a repeated pattern then also
13357 try smaller element sizes. */
13359 static int
13360 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13361 unsigned *immbits, int *op, int size,
13362 enum neon_el_type type)
13364 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13365 float. */
13366 if (type == NT_float && !float_p)
13367 return FAIL;
13369 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13371 if (size != 32 || *op == 1)
13372 return FAIL;
13373 *immbits = neon_qfloat_bits (immlo);
13374 return 0xf;
13377 if (size == 64)
13379 if (neon_bits_same_in_bytes (immhi)
13380 && neon_bits_same_in_bytes (immlo))
13382 if (*op == 1)
13383 return FAIL;
13384 *immbits = (neon_squash_bits (immhi) << 4)
13385 | neon_squash_bits (immlo);
13386 *op = 1;
13387 return 0xe;
13390 if (immhi != immlo)
13391 return FAIL;
13394 if (size >= 32)
13396 if (immlo == (immlo & 0x000000ff))
13398 *immbits = immlo;
13399 return 0x0;
13401 else if (immlo == (immlo & 0x0000ff00))
13403 *immbits = immlo >> 8;
13404 return 0x2;
13406 else if (immlo == (immlo & 0x00ff0000))
13408 *immbits = immlo >> 16;
13409 return 0x4;
13411 else if (immlo == (immlo & 0xff000000))
13413 *immbits = immlo >> 24;
13414 return 0x6;
13416 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13418 *immbits = (immlo >> 8) & 0xff;
13419 return 0xc;
13421 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13423 *immbits = (immlo >> 16) & 0xff;
13424 return 0xd;
13427 if ((immlo & 0xffff) != (immlo >> 16))
13428 return FAIL;
13429 immlo &= 0xffff;
13432 if (size >= 16)
13434 if (immlo == (immlo & 0x000000ff))
13436 *immbits = immlo;
13437 return 0x8;
13439 else if (immlo == (immlo & 0x0000ff00))
13441 *immbits = immlo >> 8;
13442 return 0xa;
13445 if ((immlo & 0xff) != (immlo >> 8))
13446 return FAIL;
13447 immlo &= 0xff;
13450 if (immlo == (immlo & 0x000000ff))
13452 /* Don't allow MVN with 8-bit immediate. */
13453 if (*op == 1)
13454 return FAIL;
13455 *immbits = immlo;
13456 return 0xe;
13459 return FAIL;
13462 /* Write immediate bits [7:0] to the following locations:
13464 |28/24|23 19|18 16|15 4|3 0|
13465 | 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|
13467 This function is used by VMOV/VMVN/VORR/VBIC. */
13469 static void
13470 neon_write_immbits (unsigned immbits)
13472 inst.instruction |= immbits & 0xf;
13473 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13474 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13477 /* Invert low-order SIZE bits of XHI:XLO. */
13479 static void
13480 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13482 unsigned immlo = xlo ? *xlo : 0;
13483 unsigned immhi = xhi ? *xhi : 0;
13485 switch (size)
13487 case 8:
13488 immlo = (~immlo) & 0xff;
13489 break;
13491 case 16:
13492 immlo = (~immlo) & 0xffff;
13493 break;
13495 case 64:
13496 immhi = (~immhi) & 0xffffffff;
13497 /* fall through. */
13499 case 32:
13500 immlo = (~immlo) & 0xffffffff;
13501 break;
13503 default:
13504 abort ();
13507 if (xlo)
13508 *xlo = immlo;
13510 if (xhi)
13511 *xhi = immhi;
13514 static void
13515 do_neon_logic (void)
13517 if (inst.operands[2].present && inst.operands[2].isreg)
13519 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13520 neon_check_type (3, rs, N_IGNORE_TYPE);
13521 /* U bit and size field were set as part of the bitmask. */
13522 NEON_ENCODE (INTEGER, inst);
13523 neon_three_same (neon_quad (rs), 0, -1);
13525 else
13527 const int three_ops_form = (inst.operands[2].present
13528 && !inst.operands[2].isreg);
13529 const int immoperand = (three_ops_form ? 2 : 1);
13530 enum neon_shape rs = (three_ops_form
13531 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13532 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
13533 struct neon_type_el et = neon_check_type (2, rs,
13534 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13535 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
13536 unsigned immbits;
13537 int cmode;
13539 if (et.type == NT_invtype)
13540 return;
13542 if (three_ops_form)
13543 constraint (inst.operands[0].reg != inst.operands[1].reg,
13544 _("first and second operands shall be the same register"));
13546 NEON_ENCODE (IMMED, inst);
13548 immbits = inst.operands[immoperand].imm;
13549 if (et.size == 64)
13551 /* .i64 is a pseudo-op, so the immediate must be a repeating
13552 pattern. */
13553 if (immbits != (inst.operands[immoperand].regisimm ?
13554 inst.operands[immoperand].reg : 0))
13556 /* Set immbits to an invalid constant. */
13557 immbits = 0xdeadbeef;
13561 switch (opcode)
13563 case N_MNEM_vbic:
13564 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13565 break;
13567 case N_MNEM_vorr:
13568 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13569 break;
13571 case N_MNEM_vand:
13572 /* Pseudo-instruction for VBIC. */
13573 neon_invert_size (&immbits, 0, et.size);
13574 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13575 break;
13577 case N_MNEM_vorn:
13578 /* Pseudo-instruction for VORR. */
13579 neon_invert_size (&immbits, 0, et.size);
13580 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13581 break;
13583 default:
13584 abort ();
13587 if (cmode == FAIL)
13588 return;
13590 inst.instruction |= neon_quad (rs) << 6;
13591 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13592 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13593 inst.instruction |= cmode << 8;
13594 neon_write_immbits (immbits);
13596 neon_dp_fixup (&inst);
13600 static void
13601 do_neon_bitfield (void)
13603 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13604 neon_check_type (3, rs, N_IGNORE_TYPE);
13605 neon_three_same (neon_quad (rs), 0, -1);
13608 static void
13609 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13610 unsigned destbits)
13612 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13613 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13614 types | N_KEY);
13615 if (et.type == NT_float)
13617 NEON_ENCODE (FLOAT, inst);
13618 neon_three_same (neon_quad (rs), 0, -1);
13620 else
13622 NEON_ENCODE (INTEGER, inst);
13623 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
13627 static void
13628 do_neon_dyadic_if_su (void)
13630 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13633 static void
13634 do_neon_dyadic_if_su_d (void)
13636 /* This version only allow D registers, but that constraint is enforced during
13637 operand parsing so we don't need to do anything extra here. */
13638 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13641 static void
13642 do_neon_dyadic_if_i_d (void)
13644 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13645 affected if we specify unsigned args. */
13646 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13649 enum vfp_or_neon_is_neon_bits
13651 NEON_CHECK_CC = 1,
13652 NEON_CHECK_ARCH = 2
13655 /* Call this function if an instruction which may have belonged to the VFP or
13656 Neon instruction sets, but turned out to be a Neon instruction (due to the
13657 operand types involved, etc.). We have to check and/or fix-up a couple of
13658 things:
13660 - Make sure the user hasn't attempted to make a Neon instruction
13661 conditional.
13662 - Alter the value in the condition code field if necessary.
13663 - Make sure that the arch supports Neon instructions.
13665 Which of these operations take place depends on bits from enum
13666 vfp_or_neon_is_neon_bits.
13668 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13669 current instruction's condition is COND_ALWAYS, the condition field is
13670 changed to inst.uncond_value. This is necessary because instructions shared
13671 between VFP and Neon may be conditional for the VFP variants only, and the
13672 unconditional Neon version must have, e.g., 0xF in the condition field. */
13674 static int
13675 vfp_or_neon_is_neon (unsigned check)
13677 /* Conditions are always legal in Thumb mode (IT blocks). */
13678 if (!thumb_mode && (check & NEON_CHECK_CC))
13680 if (inst.cond != COND_ALWAYS)
13682 first_error (_(BAD_COND));
13683 return FAIL;
13685 if (inst.uncond_value != -1)
13686 inst.instruction |= inst.uncond_value << 28;
13689 if ((check & NEON_CHECK_ARCH)
13690 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13692 first_error (_(BAD_FPU));
13693 return FAIL;
13696 return SUCCESS;
13699 static void
13700 do_neon_addsub_if_i (void)
13702 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13703 return;
13705 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13706 return;
13708 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13709 affected if we specify unsigned args. */
13710 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
13713 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13714 result to be:
13715 V<op> A,B (A is operand 0, B is operand 2)
13716 to mean:
13717 V<op> A,B,A
13718 not:
13719 V<op> A,B,B
13720 so handle that case specially. */
13722 static void
13723 neon_exchange_operands (void)
13725 void *scratch = alloca (sizeof (inst.operands[0]));
13726 if (inst.operands[1].present)
13728 /* Swap operands[1] and operands[2]. */
13729 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13730 inst.operands[1] = inst.operands[2];
13731 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13733 else
13735 inst.operands[1] = inst.operands[2];
13736 inst.operands[2] = inst.operands[0];
13740 static void
13741 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13743 if (inst.operands[2].isreg)
13745 if (invert)
13746 neon_exchange_operands ();
13747 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
13749 else
13751 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13752 struct neon_type_el et = neon_check_type (2, rs,
13753 N_EQK | N_SIZ, immtypes | N_KEY);
13755 NEON_ENCODE (IMMED, inst);
13756 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13757 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13758 inst.instruction |= LOW4 (inst.operands[1].reg);
13759 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13760 inst.instruction |= neon_quad (rs) << 6;
13761 inst.instruction |= (et.type == NT_float) << 10;
13762 inst.instruction |= neon_logbits (et.size) << 18;
13764 neon_dp_fixup (&inst);
13768 static void
13769 do_neon_cmp (void)
13771 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13774 static void
13775 do_neon_cmp_inv (void)
13777 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13780 static void
13781 do_neon_ceq (void)
13783 neon_compare (N_IF_32, N_IF_32, FALSE);
13786 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
13787 scalars, which are encoded in 5 bits, M : Rm.
13788 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13789 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13790 index in M. */
13792 static unsigned
13793 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13795 unsigned regno = NEON_SCALAR_REG (scalar);
13796 unsigned elno = NEON_SCALAR_INDEX (scalar);
13798 switch (elsize)
13800 case 16:
13801 if (regno > 7 || elno > 3)
13802 goto bad_scalar;
13803 return regno | (elno << 3);
13805 case 32:
13806 if (regno > 15 || elno > 1)
13807 goto bad_scalar;
13808 return regno | (elno << 4);
13810 default:
13811 bad_scalar:
13812 first_error (_("scalar out of range for multiply instruction"));
13815 return 0;
13818 /* Encode multiply / multiply-accumulate scalar instructions. */
13820 static void
13821 neon_mul_mac (struct neon_type_el et, int ubit)
13823 unsigned scalar;
13825 /* Give a more helpful error message if we have an invalid type. */
13826 if (et.type == NT_invtype)
13827 return;
13829 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
13830 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13831 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13832 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13833 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13834 inst.instruction |= LOW4 (scalar);
13835 inst.instruction |= HI1 (scalar) << 5;
13836 inst.instruction |= (et.type == NT_float) << 8;
13837 inst.instruction |= neon_logbits (et.size) << 20;
13838 inst.instruction |= (ubit != 0) << 24;
13840 neon_dp_fixup (&inst);
13843 static void
13844 do_neon_mac_maybe_scalar (void)
13846 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13847 return;
13849 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13850 return;
13852 if (inst.operands[2].isscalar)
13854 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13855 struct neon_type_el et = neon_check_type (3, rs,
13856 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
13857 NEON_ENCODE (SCALAR, inst);
13858 neon_mul_mac (et, neon_quad (rs));
13860 else
13862 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13863 affected if we specify unsigned args. */
13864 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13868 static void
13869 do_neon_fmac (void)
13871 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13872 return;
13874 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13875 return;
13877 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13880 static void
13881 do_neon_tst (void)
13883 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13884 struct neon_type_el et = neon_check_type (3, rs,
13885 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
13886 neon_three_same (neon_quad (rs), 0, et.size);
13889 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
13890 same types as the MAC equivalents. The polynomial type for this instruction
13891 is encoded the same as the integer type. */
13893 static void
13894 do_neon_mul (void)
13896 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13897 return;
13899 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13900 return;
13902 if (inst.operands[2].isscalar)
13903 do_neon_mac_maybe_scalar ();
13904 else
13905 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
13908 static void
13909 do_neon_qdmulh (void)
13911 if (inst.operands[2].isscalar)
13913 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13914 struct neon_type_el et = neon_check_type (3, rs,
13915 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13916 NEON_ENCODE (SCALAR, inst);
13917 neon_mul_mac (et, neon_quad (rs));
13919 else
13921 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13922 struct neon_type_el et = neon_check_type (3, rs,
13923 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13924 NEON_ENCODE (INTEGER, inst);
13925 /* The U bit (rounding) comes from bit mask. */
13926 neon_three_same (neon_quad (rs), 0, et.size);
13930 static void
13931 do_neon_fcmp_absolute (void)
13933 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13934 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13935 /* Size field comes from bit mask. */
13936 neon_three_same (neon_quad (rs), 1, -1);
13939 static void
13940 do_neon_fcmp_absolute_inv (void)
13942 neon_exchange_operands ();
13943 do_neon_fcmp_absolute ();
13946 static void
13947 do_neon_step (void)
13949 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13950 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13951 neon_three_same (neon_quad (rs), 0, -1);
13954 static void
13955 do_neon_abs_neg (void)
13957 enum neon_shape rs;
13958 struct neon_type_el et;
13960 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13961 return;
13963 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13964 return;
13966 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13967 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
13969 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13970 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13971 inst.instruction |= LOW4 (inst.operands[1].reg);
13972 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13973 inst.instruction |= neon_quad (rs) << 6;
13974 inst.instruction |= (et.type == NT_float) << 10;
13975 inst.instruction |= neon_logbits (et.size) << 18;
13977 neon_dp_fixup (&inst);
13980 static void
13981 do_neon_sli (void)
13983 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13984 struct neon_type_el et = neon_check_type (2, rs,
13985 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13986 int imm = inst.operands[2].imm;
13987 constraint (imm < 0 || (unsigned)imm >= et.size,
13988 _("immediate out of range for insert"));
13989 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13992 static void
13993 do_neon_sri (void)
13995 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13996 struct neon_type_el et = neon_check_type (2, rs,
13997 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13998 int imm = inst.operands[2].imm;
13999 constraint (imm < 1 || (unsigned)imm > et.size,
14000 _("immediate out of range for insert"));
14001 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
14004 static void
14005 do_neon_qshlu_imm (void)
14007 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14008 struct neon_type_el et = neon_check_type (2, rs,
14009 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14010 int imm = inst.operands[2].imm;
14011 constraint (imm < 0 || (unsigned)imm >= et.size,
14012 _("immediate out of range for shift"));
14013 /* Only encodes the 'U present' variant of the instruction.
14014 In this case, signed types have OP (bit 8) set to 0.
14015 Unsigned types have OP set to 1. */
14016 inst.instruction |= (et.type == NT_unsigned) << 8;
14017 /* The rest of the bits are the same as other immediate shifts. */
14018 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14021 static void
14022 do_neon_qmovn (void)
14024 struct neon_type_el et = neon_check_type (2, NS_DQ,
14025 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14026 /* Saturating move where operands can be signed or unsigned, and the
14027 destination has the same signedness. */
14028 NEON_ENCODE (INTEGER, inst);
14029 if (et.type == NT_unsigned)
14030 inst.instruction |= 0xc0;
14031 else
14032 inst.instruction |= 0x80;
14033 neon_two_same (0, 1, et.size / 2);
14036 static void
14037 do_neon_qmovun (void)
14039 struct neon_type_el et = neon_check_type (2, NS_DQ,
14040 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14041 /* Saturating move with unsigned results. Operands must be signed. */
14042 NEON_ENCODE (INTEGER, inst);
14043 neon_two_same (0, 1, et.size / 2);
14046 static void
14047 do_neon_rshift_sat_narrow (void)
14049 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14050 or unsigned. If operands are unsigned, results must also be unsigned. */
14051 struct neon_type_el et = neon_check_type (2, NS_DQI,
14052 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14053 int imm = inst.operands[2].imm;
14054 /* This gets the bounds check, size encoding and immediate bits calculation
14055 right. */
14056 et.size /= 2;
14058 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14059 VQMOVN.I<size> <Dd>, <Qm>. */
14060 if (imm == 0)
14062 inst.operands[2].present = 0;
14063 inst.instruction = N_MNEM_vqmovn;
14064 do_neon_qmovn ();
14065 return;
14068 constraint (imm < 1 || (unsigned)imm > et.size,
14069 _("immediate out of range"));
14070 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14073 static void
14074 do_neon_rshift_sat_narrow_u (void)
14076 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14077 or unsigned. If operands are unsigned, results must also be unsigned. */
14078 struct neon_type_el et = neon_check_type (2, NS_DQI,
14079 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14080 int imm = inst.operands[2].imm;
14081 /* This gets the bounds check, size encoding and immediate bits calculation
14082 right. */
14083 et.size /= 2;
14085 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14086 VQMOVUN.I<size> <Dd>, <Qm>. */
14087 if (imm == 0)
14089 inst.operands[2].present = 0;
14090 inst.instruction = N_MNEM_vqmovun;
14091 do_neon_qmovun ();
14092 return;
14095 constraint (imm < 1 || (unsigned)imm > et.size,
14096 _("immediate out of range"));
14097 /* FIXME: The manual is kind of unclear about what value U should have in
14098 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14099 must be 1. */
14100 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14103 static void
14104 do_neon_movn (void)
14106 struct neon_type_el et = neon_check_type (2, NS_DQ,
14107 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14108 NEON_ENCODE (INTEGER, inst);
14109 neon_two_same (0, 1, et.size / 2);
14112 static void
14113 do_neon_rshift_narrow (void)
14115 struct neon_type_el et = neon_check_type (2, NS_DQI,
14116 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14117 int imm = inst.operands[2].imm;
14118 /* This gets the bounds check, size encoding and immediate bits calculation
14119 right. */
14120 et.size /= 2;
14122 /* If immediate is zero then we are a pseudo-instruction for
14123 VMOVN.I<size> <Dd>, <Qm> */
14124 if (imm == 0)
14126 inst.operands[2].present = 0;
14127 inst.instruction = N_MNEM_vmovn;
14128 do_neon_movn ();
14129 return;
14132 constraint (imm < 1 || (unsigned)imm > et.size,
14133 _("immediate out of range for narrowing operation"));
14134 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14137 static void
14138 do_neon_shll (void)
14140 /* FIXME: Type checking when lengthening. */
14141 struct neon_type_el et = neon_check_type (2, NS_QDI,
14142 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14143 unsigned imm = inst.operands[2].imm;
14145 if (imm == et.size)
14147 /* Maximum shift variant. */
14148 NEON_ENCODE (INTEGER, inst);
14149 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14150 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14151 inst.instruction |= LOW4 (inst.operands[1].reg);
14152 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14153 inst.instruction |= neon_logbits (et.size) << 18;
14155 neon_dp_fixup (&inst);
14157 else
14159 /* A more-specific type check for non-max versions. */
14160 et = neon_check_type (2, NS_QDI,
14161 N_EQK | N_DBL, N_SU_32 | N_KEY);
14162 NEON_ENCODE (IMMED, inst);
14163 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14167 /* Check the various types for the VCVT instruction, and return which version
14168 the current instruction is. */
14170 static int
14171 neon_cvt_flavour (enum neon_shape rs)
14173 #define CVT_VAR(C,X,Y) \
14174 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
14175 if (et.type != NT_invtype) \
14177 inst.error = NULL; \
14178 return (C); \
14180 struct neon_type_el et;
14181 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14182 || rs == NS_FF) ? N_VFP : 0;
14183 /* The instruction versions which take an immediate take one register
14184 argument, which is extended to the width of the full register. Thus the
14185 "source" and "destination" registers must have the same width. Hack that
14186 here by making the size equal to the key (wider, in this case) operand. */
14187 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
14189 CVT_VAR (0, N_S32, N_F32);
14190 CVT_VAR (1, N_U32, N_F32);
14191 CVT_VAR (2, N_F32, N_S32);
14192 CVT_VAR (3, N_F32, N_U32);
14193 /* Half-precision conversions. */
14194 CVT_VAR (4, N_F32, N_F16);
14195 CVT_VAR (5, N_F16, N_F32);
14197 whole_reg = N_VFP;
14199 /* VFP instructions. */
14200 CVT_VAR (6, N_F32, N_F64);
14201 CVT_VAR (7, N_F64, N_F32);
14202 CVT_VAR (8, N_S32, N_F64 | key);
14203 CVT_VAR (9, N_U32, N_F64 | key);
14204 CVT_VAR (10, N_F64 | key, N_S32);
14205 CVT_VAR (11, N_F64 | key, N_U32);
14206 /* VFP instructions with bitshift. */
14207 CVT_VAR (12, N_F32 | key, N_S16);
14208 CVT_VAR (13, N_F32 | key, N_U16);
14209 CVT_VAR (14, N_F64 | key, N_S16);
14210 CVT_VAR (15, N_F64 | key, N_U16);
14211 CVT_VAR (16, N_S16, N_F32 | key);
14212 CVT_VAR (17, N_U16, N_F32 | key);
14213 CVT_VAR (18, N_S16, N_F64 | key);
14214 CVT_VAR (19, N_U16, N_F64 | key);
14216 return -1;
14217 #undef CVT_VAR
14220 /* Neon-syntax VFP conversions. */
14222 static void
14223 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
14225 const char *opname = 0;
14227 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
14229 /* Conversions with immediate bitshift. */
14230 const char *enc[] =
14232 "ftosls",
14233 "ftouls",
14234 "fsltos",
14235 "fultos",
14236 NULL,
14237 NULL,
14238 NULL,
14239 NULL,
14240 "ftosld",
14241 "ftould",
14242 "fsltod",
14243 "fultod",
14244 "fshtos",
14245 "fuhtos",
14246 "fshtod",
14247 "fuhtod",
14248 "ftoshs",
14249 "ftouhs",
14250 "ftoshd",
14251 "ftouhd"
14254 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14256 opname = enc[flavour];
14257 constraint (inst.operands[0].reg != inst.operands[1].reg,
14258 _("operands 0 and 1 must be the same register"));
14259 inst.operands[1] = inst.operands[2];
14260 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14263 else
14265 /* Conversions without bitshift. */
14266 const char *enc[] =
14268 "ftosis",
14269 "ftouis",
14270 "fsitos",
14271 "fuitos",
14272 "NULL",
14273 "NULL",
14274 "fcvtsd",
14275 "fcvtds",
14276 "ftosid",
14277 "ftouid",
14278 "fsitod",
14279 "fuitod"
14282 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14283 opname = enc[flavour];
14286 if (opname)
14287 do_vfp_nsyn_opcode (opname);
14290 static void
14291 do_vfp_nsyn_cvtz (void)
14293 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14294 int flavour = neon_cvt_flavour (rs);
14295 const char *enc[] =
14297 "ftosizs",
14298 "ftouizs",
14299 NULL,
14300 NULL,
14301 NULL,
14302 NULL,
14303 NULL,
14304 NULL,
14305 "ftosizd",
14306 "ftouizd"
14309 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14310 do_vfp_nsyn_opcode (enc[flavour]);
14313 static void
14314 do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
14316 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
14317 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
14318 int flavour = neon_cvt_flavour (rs);
14320 /* PR11109: Handle round-to-zero for VCVT conversions. */
14321 if (round_to_zero
14322 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14323 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
14324 && (rs == NS_FD || rs == NS_FF))
14326 do_vfp_nsyn_cvtz ();
14327 return;
14330 /* VFP rather than Neon conversions. */
14331 if (flavour >= 6)
14333 do_vfp_nsyn_cvt (rs, flavour);
14334 return;
14337 switch (rs)
14339 case NS_DDI:
14340 case NS_QQI:
14342 unsigned immbits;
14343 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14345 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14346 return;
14348 /* Fixed-point conversion with #0 immediate is encoded as an
14349 integer conversion. */
14350 if (inst.operands[2].present && inst.operands[2].imm == 0)
14351 goto int_encode;
14352 immbits = 32 - inst.operands[2].imm;
14353 NEON_ENCODE (IMMED, inst);
14354 if (flavour != -1)
14355 inst.instruction |= enctab[flavour];
14356 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14357 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14358 inst.instruction |= LOW4 (inst.operands[1].reg);
14359 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14360 inst.instruction |= neon_quad (rs) << 6;
14361 inst.instruction |= 1 << 21;
14362 inst.instruction |= immbits << 16;
14364 neon_dp_fixup (&inst);
14366 break;
14368 case NS_DD:
14369 case NS_QQ:
14370 int_encode:
14372 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14374 NEON_ENCODE (INTEGER, inst);
14376 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14377 return;
14379 if (flavour != -1)
14380 inst.instruction |= enctab[flavour];
14382 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14383 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14384 inst.instruction |= LOW4 (inst.operands[1].reg);
14385 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14386 inst.instruction |= neon_quad (rs) << 6;
14387 inst.instruction |= 2 << 18;
14389 neon_dp_fixup (&inst);
14391 break;
14393 /* Half-precision conversions for Advanced SIMD -- neon. */
14394 case NS_QD:
14395 case NS_DQ:
14397 if ((rs == NS_DQ)
14398 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14400 as_bad (_("operand size must match register width"));
14401 break;
14404 if ((rs == NS_QD)
14405 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14407 as_bad (_("operand size must match register width"));
14408 break;
14411 if (rs == NS_DQ)
14412 inst.instruction = 0x3b60600;
14413 else
14414 inst.instruction = 0x3b60700;
14416 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14417 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14418 inst.instruction |= LOW4 (inst.operands[1].reg);
14419 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14420 neon_dp_fixup (&inst);
14421 break;
14423 default:
14424 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14425 do_vfp_nsyn_cvt (rs, flavour);
14429 static void
14430 do_neon_cvtr (void)
14432 do_neon_cvt_1 (FALSE);
14435 static void
14436 do_neon_cvt (void)
14438 do_neon_cvt_1 (TRUE);
14441 static void
14442 do_neon_cvtb (void)
14444 inst.instruction = 0xeb20a40;
14446 /* The sizes are attached to the mnemonic. */
14447 if (inst.vectype.el[0].type != NT_invtype
14448 && inst.vectype.el[0].size == 16)
14449 inst.instruction |= 0x00010000;
14451 /* Programmer's syntax: the sizes are attached to the operands. */
14452 else if (inst.operands[0].vectype.type != NT_invtype
14453 && inst.operands[0].vectype.size == 16)
14454 inst.instruction |= 0x00010000;
14456 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14457 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14458 do_vfp_cond_or_thumb ();
14462 static void
14463 do_neon_cvtt (void)
14465 do_neon_cvtb ();
14466 inst.instruction |= 0x80;
14469 static void
14470 neon_move_immediate (void)
14472 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14473 struct neon_type_el et = neon_check_type (2, rs,
14474 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
14475 unsigned immlo, immhi = 0, immbits;
14476 int op, cmode, float_p;
14478 constraint (et.type == NT_invtype,
14479 _("operand size must be specified for immediate VMOV"));
14481 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14482 op = (inst.instruction & (1 << 5)) != 0;
14484 immlo = inst.operands[1].imm;
14485 if (inst.operands[1].regisimm)
14486 immhi = inst.operands[1].reg;
14488 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14489 _("immediate has bits set outside the operand size"));
14491 float_p = inst.operands[1].immisfloat;
14493 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
14494 et.size, et.type)) == FAIL)
14496 /* Invert relevant bits only. */
14497 neon_invert_size (&immlo, &immhi, et.size);
14498 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14499 with one or the other; those cases are caught by
14500 neon_cmode_for_move_imm. */
14501 op = !op;
14502 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14503 &op, et.size, et.type)) == FAIL)
14505 first_error (_("immediate out of range"));
14506 return;
14510 inst.instruction &= ~(1 << 5);
14511 inst.instruction |= op << 5;
14513 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14514 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14515 inst.instruction |= neon_quad (rs) << 6;
14516 inst.instruction |= cmode << 8;
14518 neon_write_immbits (immbits);
14521 static void
14522 do_neon_mvn (void)
14524 if (inst.operands[1].isreg)
14526 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14528 NEON_ENCODE (INTEGER, inst);
14529 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14530 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14531 inst.instruction |= LOW4 (inst.operands[1].reg);
14532 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14533 inst.instruction |= neon_quad (rs) << 6;
14535 else
14537 NEON_ENCODE (IMMED, inst);
14538 neon_move_immediate ();
14541 neon_dp_fixup (&inst);
14544 /* Encode instructions of form:
14546 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14547 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
14549 static void
14550 neon_mixed_length (struct neon_type_el et, unsigned size)
14552 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14553 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14554 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14555 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14556 inst.instruction |= LOW4 (inst.operands[2].reg);
14557 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14558 inst.instruction |= (et.type == NT_unsigned) << 24;
14559 inst.instruction |= neon_logbits (size) << 20;
14561 neon_dp_fixup (&inst);
14564 static void
14565 do_neon_dyadic_long (void)
14567 /* FIXME: Type checking for lengthening op. */
14568 struct neon_type_el et = neon_check_type (3, NS_QDD,
14569 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14570 neon_mixed_length (et, et.size);
14573 static void
14574 do_neon_abal (void)
14576 struct neon_type_el et = neon_check_type (3, NS_QDD,
14577 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14578 neon_mixed_length (et, et.size);
14581 static void
14582 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14584 if (inst.operands[2].isscalar)
14586 struct neon_type_el et = neon_check_type (3, NS_QDS,
14587 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
14588 NEON_ENCODE (SCALAR, inst);
14589 neon_mul_mac (et, et.type == NT_unsigned);
14591 else
14593 struct neon_type_el et = neon_check_type (3, NS_QDD,
14594 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
14595 NEON_ENCODE (INTEGER, inst);
14596 neon_mixed_length (et, et.size);
14600 static void
14601 do_neon_mac_maybe_scalar_long (void)
14603 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14606 static void
14607 do_neon_dyadic_wide (void)
14609 struct neon_type_el et = neon_check_type (3, NS_QQD,
14610 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14611 neon_mixed_length (et, et.size);
14614 static void
14615 do_neon_dyadic_narrow (void)
14617 struct neon_type_el et = neon_check_type (3, NS_QDD,
14618 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
14619 /* Operand sign is unimportant, and the U bit is part of the opcode,
14620 so force the operand type to integer. */
14621 et.type = NT_integer;
14622 neon_mixed_length (et, et.size / 2);
14625 static void
14626 do_neon_mul_sat_scalar_long (void)
14628 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14631 static void
14632 do_neon_vmull (void)
14634 if (inst.operands[2].isscalar)
14635 do_neon_mac_maybe_scalar_long ();
14636 else
14638 struct neon_type_el et = neon_check_type (3, NS_QDD,
14639 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14640 if (et.type == NT_poly)
14641 NEON_ENCODE (POLY, inst);
14642 else
14643 NEON_ENCODE (INTEGER, inst);
14644 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14645 zero. Should be OK as-is. */
14646 neon_mixed_length (et, et.size);
14650 static void
14651 do_neon_ext (void)
14653 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
14654 struct neon_type_el et = neon_check_type (3, rs,
14655 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14656 unsigned imm = (inst.operands[3].imm * et.size) / 8;
14658 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14659 _("shift out of range"));
14660 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14661 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14662 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14663 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14664 inst.instruction |= LOW4 (inst.operands[2].reg);
14665 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14666 inst.instruction |= neon_quad (rs) << 6;
14667 inst.instruction |= imm << 8;
14669 neon_dp_fixup (&inst);
14672 static void
14673 do_neon_rev (void)
14675 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14676 struct neon_type_el et = neon_check_type (2, rs,
14677 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14678 unsigned op = (inst.instruction >> 7) & 3;
14679 /* N (width of reversed regions) is encoded as part of the bitmask. We
14680 extract it here to check the elements to be reversed are smaller.
14681 Otherwise we'd get a reserved instruction. */
14682 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
14683 gas_assert (elsize != 0);
14684 constraint (et.size >= elsize,
14685 _("elements must be smaller than reversal region"));
14686 neon_two_same (neon_quad (rs), 1, et.size);
14689 static void
14690 do_neon_dup (void)
14692 if (inst.operands[1].isscalar)
14694 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
14695 struct neon_type_el et = neon_check_type (2, rs,
14696 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14697 unsigned sizebits = et.size >> 3;
14698 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
14699 int logsize = neon_logbits (et.size);
14700 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
14702 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14703 return;
14705 NEON_ENCODE (SCALAR, inst);
14706 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14707 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14708 inst.instruction |= LOW4 (dm);
14709 inst.instruction |= HI1 (dm) << 5;
14710 inst.instruction |= neon_quad (rs) << 6;
14711 inst.instruction |= x << 17;
14712 inst.instruction |= sizebits << 16;
14714 neon_dp_fixup (&inst);
14716 else
14718 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14719 struct neon_type_el et = neon_check_type (2, rs,
14720 N_8 | N_16 | N_32 | N_KEY, N_EQK);
14721 /* Duplicate ARM register to lanes of vector. */
14722 NEON_ENCODE (ARMREG, inst);
14723 switch (et.size)
14725 case 8: inst.instruction |= 0x400000; break;
14726 case 16: inst.instruction |= 0x000020; break;
14727 case 32: inst.instruction |= 0x000000; break;
14728 default: break;
14730 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14731 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14732 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
14733 inst.instruction |= neon_quad (rs) << 21;
14734 /* The encoding for this instruction is identical for the ARM and Thumb
14735 variants, except for the condition field. */
14736 do_vfp_cond_or_thumb ();
14740 /* VMOV has particularly many variations. It can be one of:
14741 0. VMOV<c><q> <Qd>, <Qm>
14742 1. VMOV<c><q> <Dd>, <Dm>
14743 (Register operations, which are VORR with Rm = Rn.)
14744 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14745 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14746 (Immediate loads.)
14747 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14748 (ARM register to scalar.)
14749 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14750 (Two ARM registers to vector.)
14751 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14752 (Scalar to ARM register.)
14753 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14754 (Vector to two ARM registers.)
14755 8. VMOV.F32 <Sd>, <Sm>
14756 9. VMOV.F64 <Dd>, <Dm>
14757 (VFP register moves.)
14758 10. VMOV.F32 <Sd>, #imm
14759 11. VMOV.F64 <Dd>, #imm
14760 (VFP float immediate load.)
14761 12. VMOV <Rd>, <Sm>
14762 (VFP single to ARM reg.)
14763 13. VMOV <Sd>, <Rm>
14764 (ARM reg to VFP single.)
14765 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14766 (Two ARM regs to two VFP singles.)
14767 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14768 (Two VFP singles to two ARM regs.)
14770 These cases can be disambiguated using neon_select_shape, except cases 1/9
14771 and 3/11 which depend on the operand type too.
14773 All the encoded bits are hardcoded by this function.
14775 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14776 Cases 5, 7 may be used with VFPv2 and above.
14778 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
14779 can specify a type where it doesn't make sense to, and is ignored). */
14781 static void
14782 do_neon_mov (void)
14784 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14785 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14786 NS_NULL);
14787 struct neon_type_el et;
14788 const char *ldconst = 0;
14790 switch (rs)
14792 case NS_DD: /* case 1/9. */
14793 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14794 /* It is not an error here if no type is given. */
14795 inst.error = NULL;
14796 if (et.type == NT_float && et.size == 64)
14798 do_vfp_nsyn_opcode ("fcpyd");
14799 break;
14801 /* fall through. */
14803 case NS_QQ: /* case 0/1. */
14805 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14806 return;
14807 /* The architecture manual I have doesn't explicitly state which
14808 value the U bit should have for register->register moves, but
14809 the equivalent VORR instruction has U = 0, so do that. */
14810 inst.instruction = 0x0200110;
14811 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14812 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14813 inst.instruction |= LOW4 (inst.operands[1].reg);
14814 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14815 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14816 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14817 inst.instruction |= neon_quad (rs) << 6;
14819 neon_dp_fixup (&inst);
14821 break;
14823 case NS_DI: /* case 3/11. */
14824 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14825 inst.error = NULL;
14826 if (et.type == NT_float && et.size == 64)
14828 /* case 11 (fconstd). */
14829 ldconst = "fconstd";
14830 goto encode_fconstd;
14832 /* fall through. */
14834 case NS_QI: /* case 2/3. */
14835 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14836 return;
14837 inst.instruction = 0x0800010;
14838 neon_move_immediate ();
14839 neon_dp_fixup (&inst);
14840 break;
14842 case NS_SR: /* case 4. */
14844 unsigned bcdebits = 0;
14845 int logsize;
14846 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14847 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14849 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14850 logsize = neon_logbits (et.size);
14852 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14853 _(BAD_FPU));
14854 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14855 && et.size != 32, _(BAD_FPU));
14856 constraint (et.type == NT_invtype, _("bad type for scalar"));
14857 constraint (x >= 64 / et.size, _("scalar index out of range"));
14859 switch (et.size)
14861 case 8: bcdebits = 0x8; break;
14862 case 16: bcdebits = 0x1; break;
14863 case 32: bcdebits = 0x0; break;
14864 default: ;
14867 bcdebits |= x << logsize;
14869 inst.instruction = 0xe000b10;
14870 do_vfp_cond_or_thumb ();
14871 inst.instruction |= LOW4 (dn) << 16;
14872 inst.instruction |= HI1 (dn) << 7;
14873 inst.instruction |= inst.operands[1].reg << 12;
14874 inst.instruction |= (bcdebits & 3) << 5;
14875 inst.instruction |= (bcdebits >> 2) << 21;
14877 break;
14879 case NS_DRR: /* case 5 (fmdrr). */
14880 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14881 _(BAD_FPU));
14883 inst.instruction = 0xc400b10;
14884 do_vfp_cond_or_thumb ();
14885 inst.instruction |= LOW4 (inst.operands[0].reg);
14886 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14887 inst.instruction |= inst.operands[1].reg << 12;
14888 inst.instruction |= inst.operands[2].reg << 16;
14889 break;
14891 case NS_RS: /* case 6. */
14893 unsigned logsize;
14894 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14895 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14896 unsigned abcdebits = 0;
14898 et = neon_check_type (2, NS_NULL,
14899 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14900 logsize = neon_logbits (et.size);
14902 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14903 _(BAD_FPU));
14904 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14905 && et.size != 32, _(BAD_FPU));
14906 constraint (et.type == NT_invtype, _("bad type for scalar"));
14907 constraint (x >= 64 / et.size, _("scalar index out of range"));
14909 switch (et.size)
14911 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14912 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14913 case 32: abcdebits = 0x00; break;
14914 default: ;
14917 abcdebits |= x << logsize;
14918 inst.instruction = 0xe100b10;
14919 do_vfp_cond_or_thumb ();
14920 inst.instruction |= LOW4 (dn) << 16;
14921 inst.instruction |= HI1 (dn) << 7;
14922 inst.instruction |= inst.operands[0].reg << 12;
14923 inst.instruction |= (abcdebits & 3) << 5;
14924 inst.instruction |= (abcdebits >> 2) << 21;
14926 break;
14928 case NS_RRD: /* case 7 (fmrrd). */
14929 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14930 _(BAD_FPU));
14932 inst.instruction = 0xc500b10;
14933 do_vfp_cond_or_thumb ();
14934 inst.instruction |= inst.operands[0].reg << 12;
14935 inst.instruction |= inst.operands[1].reg << 16;
14936 inst.instruction |= LOW4 (inst.operands[2].reg);
14937 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14938 break;
14940 case NS_FF: /* case 8 (fcpys). */
14941 do_vfp_nsyn_opcode ("fcpys");
14942 break;
14944 case NS_FI: /* case 10 (fconsts). */
14945 ldconst = "fconsts";
14946 encode_fconstd:
14947 if (is_quarter_float (inst.operands[1].imm))
14949 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14950 do_vfp_nsyn_opcode (ldconst);
14952 else
14953 first_error (_("immediate out of range"));
14954 break;
14956 case NS_RF: /* case 12 (fmrs). */
14957 do_vfp_nsyn_opcode ("fmrs");
14958 break;
14960 case NS_FR: /* case 13 (fmsr). */
14961 do_vfp_nsyn_opcode ("fmsr");
14962 break;
14964 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14965 (one of which is a list), but we have parsed four. Do some fiddling to
14966 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14967 expect. */
14968 case NS_RRFF: /* case 14 (fmrrs). */
14969 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14970 _("VFP registers must be adjacent"));
14971 inst.operands[2].imm = 2;
14972 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14973 do_vfp_nsyn_opcode ("fmrrs");
14974 break;
14976 case NS_FFRR: /* case 15 (fmsrr). */
14977 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14978 _("VFP registers must be adjacent"));
14979 inst.operands[1] = inst.operands[2];
14980 inst.operands[2] = inst.operands[3];
14981 inst.operands[0].imm = 2;
14982 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14983 do_vfp_nsyn_opcode ("fmsrr");
14984 break;
14986 default:
14987 abort ();
14991 static void
14992 do_neon_rshift_round_imm (void)
14994 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14995 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14996 int imm = inst.operands[2].imm;
14998 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14999 if (imm == 0)
15001 inst.operands[2].present = 0;
15002 do_neon_mov ();
15003 return;
15006 constraint (imm < 1 || (unsigned)imm > et.size,
15007 _("immediate out of range for shift"));
15008 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
15009 et.size - imm);
15012 static void
15013 do_neon_movl (void)
15015 struct neon_type_el et = neon_check_type (2, NS_QD,
15016 N_EQK | N_DBL, N_SU_32 | N_KEY);
15017 unsigned sizebits = et.size >> 3;
15018 inst.instruction |= sizebits << 19;
15019 neon_two_same (0, et.type == NT_unsigned, -1);
15022 static void
15023 do_neon_trn (void)
15025 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15026 struct neon_type_el et = neon_check_type (2, rs,
15027 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15028 NEON_ENCODE (INTEGER, inst);
15029 neon_two_same (neon_quad (rs), 1, et.size);
15032 static void
15033 do_neon_zip_uzp (void)
15035 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15036 struct neon_type_el et = neon_check_type (2, rs,
15037 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15038 if (rs == NS_DD && et.size == 32)
15040 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
15041 inst.instruction = N_MNEM_vtrn;
15042 do_neon_trn ();
15043 return;
15045 neon_two_same (neon_quad (rs), 1, et.size);
15048 static void
15049 do_neon_sat_abs_neg (void)
15051 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15052 struct neon_type_el et = neon_check_type (2, rs,
15053 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
15054 neon_two_same (neon_quad (rs), 1, et.size);
15057 static void
15058 do_neon_pair_long (void)
15060 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15061 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15062 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15063 inst.instruction |= (et.type == NT_unsigned) << 7;
15064 neon_two_same (neon_quad (rs), 1, et.size);
15067 static void
15068 do_neon_recip_est (void)
15070 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15071 struct neon_type_el et = neon_check_type (2, rs,
15072 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15073 inst.instruction |= (et.type == NT_float) << 8;
15074 neon_two_same (neon_quad (rs), 1, et.size);
15077 static void
15078 do_neon_cls (void)
15080 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15081 struct neon_type_el et = neon_check_type (2, rs,
15082 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
15083 neon_two_same (neon_quad (rs), 1, et.size);
15086 static void
15087 do_neon_clz (void)
15089 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15090 struct neon_type_el et = neon_check_type (2, rs,
15091 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
15092 neon_two_same (neon_quad (rs), 1, et.size);
15095 static void
15096 do_neon_cnt (void)
15098 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15099 struct neon_type_el et = neon_check_type (2, rs,
15100 N_EQK | N_INT, N_8 | N_KEY);
15101 neon_two_same (neon_quad (rs), 1, et.size);
15104 static void
15105 do_neon_swp (void)
15107 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15108 neon_two_same (neon_quad (rs), 1, -1);
15111 static void
15112 do_neon_tbl_tbx (void)
15114 unsigned listlenbits;
15115 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
15117 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15119 first_error (_("bad list length for table lookup"));
15120 return;
15123 listlenbits = inst.operands[1].imm - 1;
15124 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15125 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15126 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15127 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15128 inst.instruction |= LOW4 (inst.operands[2].reg);
15129 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15130 inst.instruction |= listlenbits << 8;
15132 neon_dp_fixup (&inst);
15135 static void
15136 do_neon_ldm_stm (void)
15138 /* P, U and L bits are part of bitmask. */
15139 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15140 unsigned offsetbits = inst.operands[1].imm * 2;
15142 if (inst.operands[1].issingle)
15144 do_vfp_nsyn_ldm_stm (is_dbmode);
15145 return;
15148 constraint (is_dbmode && !inst.operands[0].writeback,
15149 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15151 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15152 _("register list must contain at least 1 and at most 16 "
15153 "registers"));
15155 inst.instruction |= inst.operands[0].reg << 16;
15156 inst.instruction |= inst.operands[0].writeback << 21;
15157 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15158 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15160 inst.instruction |= offsetbits;
15162 do_vfp_cond_or_thumb ();
15165 static void
15166 do_neon_ldr_str (void)
15168 int is_ldr = (inst.instruction & (1 << 20)) != 0;
15170 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15171 And is UNPREDICTABLE in thumb mode. */
15172 if (!is_ldr
15173 && inst.operands[1].reg == REG_PC
15174 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15176 if (!thumb_mode && warn_on_deprecated)
15177 as_warn (_("Use of PC here is deprecated"));
15178 else
15179 inst.error = _("Use of PC here is UNPREDICTABLE");
15182 if (inst.operands[0].issingle)
15184 if (is_ldr)
15185 do_vfp_nsyn_opcode ("flds");
15186 else
15187 do_vfp_nsyn_opcode ("fsts");
15189 else
15191 if (is_ldr)
15192 do_vfp_nsyn_opcode ("fldd");
15193 else
15194 do_vfp_nsyn_opcode ("fstd");
15198 /* "interleave" version also handles non-interleaving register VLD1/VST1
15199 instructions. */
15201 static void
15202 do_neon_ld_st_interleave (void)
15204 struct neon_type_el et = neon_check_type (1, NS_NULL,
15205 N_8 | N_16 | N_32 | N_64);
15206 unsigned alignbits = 0;
15207 unsigned idx;
15208 /* The bits in this table go:
15209 0: register stride of one (0) or two (1)
15210 1,2: register list length, minus one (1, 2, 3, 4).
15211 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15212 We use -1 for invalid entries. */
15213 const int typetable[] =
15215 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15216 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15217 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15218 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15220 int typebits;
15222 if (et.type == NT_invtype)
15223 return;
15225 if (inst.operands[1].immisalign)
15226 switch (inst.operands[1].imm >> 8)
15228 case 64: alignbits = 1; break;
15229 case 128:
15230 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15231 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15232 goto bad_alignment;
15233 alignbits = 2;
15234 break;
15235 case 256:
15236 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15237 goto bad_alignment;
15238 alignbits = 3;
15239 break;
15240 default:
15241 bad_alignment:
15242 first_error (_("bad alignment"));
15243 return;
15246 inst.instruction |= alignbits << 4;
15247 inst.instruction |= neon_logbits (et.size) << 6;
15249 /* Bits [4:6] of the immediate in a list specifier encode register stride
15250 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15251 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15252 up the right value for "type" in a table based on this value and the given
15253 list style, then stick it back. */
15254 idx = ((inst.operands[0].imm >> 4) & 7)
15255 | (((inst.instruction >> 8) & 3) << 3);
15257 typebits = typetable[idx];
15259 constraint (typebits == -1, _("bad list type for instruction"));
15261 inst.instruction &= ~0xf00;
15262 inst.instruction |= typebits << 8;
15265 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15266 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15267 otherwise. The variable arguments are a list of pairs of legal (size, align)
15268 values, terminated with -1. */
15270 static int
15271 neon_alignment_bit (int size, int align, int *do_align, ...)
15273 va_list ap;
15274 int result = FAIL, thissize, thisalign;
15276 if (!inst.operands[1].immisalign)
15278 *do_align = 0;
15279 return SUCCESS;
15282 va_start (ap, do_align);
15286 thissize = va_arg (ap, int);
15287 if (thissize == -1)
15288 break;
15289 thisalign = va_arg (ap, int);
15291 if (size == thissize && align == thisalign)
15292 result = SUCCESS;
15294 while (result != SUCCESS);
15296 va_end (ap);
15298 if (result == SUCCESS)
15299 *do_align = 1;
15300 else
15301 first_error (_("unsupported alignment for instruction"));
15303 return result;
15306 static void
15307 do_neon_ld_st_lane (void)
15309 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15310 int align_good, do_align = 0;
15311 int logsize = neon_logbits (et.size);
15312 int align = inst.operands[1].imm >> 8;
15313 int n = (inst.instruction >> 8) & 3;
15314 int max_el = 64 / et.size;
15316 if (et.type == NT_invtype)
15317 return;
15319 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15320 _("bad list length"));
15321 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15322 _("scalar index out of range"));
15323 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15324 && et.size == 8,
15325 _("stride of 2 unavailable when element size is 8"));
15327 switch (n)
15329 case 0: /* VLD1 / VST1. */
15330 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15331 32, 32, -1);
15332 if (align_good == FAIL)
15333 return;
15334 if (do_align)
15336 unsigned alignbits = 0;
15337 switch (et.size)
15339 case 16: alignbits = 0x1; break;
15340 case 32: alignbits = 0x3; break;
15341 default: ;
15343 inst.instruction |= alignbits << 4;
15345 break;
15347 case 1: /* VLD2 / VST2. */
15348 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15349 32, 64, -1);
15350 if (align_good == FAIL)
15351 return;
15352 if (do_align)
15353 inst.instruction |= 1 << 4;
15354 break;
15356 case 2: /* VLD3 / VST3. */
15357 constraint (inst.operands[1].immisalign,
15358 _("can't use alignment with this instruction"));
15359 break;
15361 case 3: /* VLD4 / VST4. */
15362 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15363 16, 64, 32, 64, 32, 128, -1);
15364 if (align_good == FAIL)
15365 return;
15366 if (do_align)
15368 unsigned alignbits = 0;
15369 switch (et.size)
15371 case 8: alignbits = 0x1; break;
15372 case 16: alignbits = 0x1; break;
15373 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15374 default: ;
15376 inst.instruction |= alignbits << 4;
15378 break;
15380 default: ;
15383 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15384 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15385 inst.instruction |= 1 << (4 + logsize);
15387 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15388 inst.instruction |= logsize << 10;
15391 /* Encode single n-element structure to all lanes VLD<n> instructions. */
15393 static void
15394 do_neon_ld_dup (void)
15396 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15397 int align_good, do_align = 0;
15399 if (et.type == NT_invtype)
15400 return;
15402 switch ((inst.instruction >> 8) & 3)
15404 case 0: /* VLD1. */
15405 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
15406 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15407 &do_align, 16, 16, 32, 32, -1);
15408 if (align_good == FAIL)
15409 return;
15410 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15412 case 1: break;
15413 case 2: inst.instruction |= 1 << 5; break;
15414 default: first_error (_("bad list length")); return;
15416 inst.instruction |= neon_logbits (et.size) << 6;
15417 break;
15419 case 1: /* VLD2. */
15420 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15421 &do_align, 8, 16, 16, 32, 32, 64, -1);
15422 if (align_good == FAIL)
15423 return;
15424 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15425 _("bad list length"));
15426 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15427 inst.instruction |= 1 << 5;
15428 inst.instruction |= neon_logbits (et.size) << 6;
15429 break;
15431 case 2: /* VLD3. */
15432 constraint (inst.operands[1].immisalign,
15433 _("can't use alignment with this instruction"));
15434 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15435 _("bad list length"));
15436 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15437 inst.instruction |= 1 << 5;
15438 inst.instruction |= neon_logbits (et.size) << 6;
15439 break;
15441 case 3: /* VLD4. */
15443 int align = inst.operands[1].imm >> 8;
15444 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15445 16, 64, 32, 64, 32, 128, -1);
15446 if (align_good == FAIL)
15447 return;
15448 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15449 _("bad list length"));
15450 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15451 inst.instruction |= 1 << 5;
15452 if (et.size == 32 && align == 128)
15453 inst.instruction |= 0x3 << 6;
15454 else
15455 inst.instruction |= neon_logbits (et.size) << 6;
15457 break;
15459 default: ;
15462 inst.instruction |= do_align << 4;
15465 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15466 apart from bits [11:4]. */
15468 static void
15469 do_neon_ldx_stx (void)
15471 if (inst.operands[1].isreg)
15472 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15474 switch (NEON_LANE (inst.operands[0].imm))
15476 case NEON_INTERLEAVE_LANES:
15477 NEON_ENCODE (INTERLV, inst);
15478 do_neon_ld_st_interleave ();
15479 break;
15481 case NEON_ALL_LANES:
15482 NEON_ENCODE (DUP, inst);
15483 do_neon_ld_dup ();
15484 break;
15486 default:
15487 NEON_ENCODE (LANE, inst);
15488 do_neon_ld_st_lane ();
15491 /* L bit comes from bit mask. */
15492 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15493 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15494 inst.instruction |= inst.operands[1].reg << 16;
15496 if (inst.operands[1].postind)
15498 int postreg = inst.operands[1].imm & 0xf;
15499 constraint (!inst.operands[1].immisreg,
15500 _("post-index must be a register"));
15501 constraint (postreg == 0xd || postreg == 0xf,
15502 _("bad register for post-index"));
15503 inst.instruction |= postreg;
15505 else if (inst.operands[1].writeback)
15507 inst.instruction |= 0xd;
15509 else
15510 inst.instruction |= 0xf;
15512 if (thumb_mode)
15513 inst.instruction |= 0xf9000000;
15514 else
15515 inst.instruction |= 0xf4000000;
15518 /* Overall per-instruction processing. */
15520 /* We need to be able to fix up arbitrary expressions in some statements.
15521 This is so that we can handle symbols that are an arbitrary distance from
15522 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15523 which returns part of an address in a form which will be valid for
15524 a data instruction. We do this by pushing the expression into a symbol
15525 in the expr_section, and creating a fix for that. */
15527 static void
15528 fix_new_arm (fragS * frag,
15529 int where,
15530 short int size,
15531 expressionS * exp,
15532 int pc_rel,
15533 int reloc)
15535 fixS * new_fix;
15537 switch (exp->X_op)
15539 case O_constant:
15540 if (pc_rel)
15542 /* Create an absolute valued symbol, so we have something to
15543 refer to in the object file. Unfortunately for us, gas's
15544 generic expression parsing will already have folded out
15545 any use of .set foo/.type foo %function that may have
15546 been used to set type information of the target location,
15547 that's being specified symbolically. We have to presume
15548 the user knows what they are doing. */
15549 char name[16 + 8];
15550 symbolS *symbol;
15552 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
15554 symbol = symbol_find_or_make (name);
15555 S_SET_SEGMENT (symbol, absolute_section);
15556 symbol_set_frag (symbol, &zero_address_frag);
15557 S_SET_VALUE (symbol, exp->X_add_number);
15558 exp->X_op = O_symbol;
15559 exp->X_add_symbol = symbol;
15560 exp->X_add_number = 0;
15562 /* FALLTHROUGH */
15563 case O_symbol:
15564 case O_add:
15565 case O_subtract:
15566 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15567 (enum bfd_reloc_code_real) reloc);
15568 break;
15570 default:
15571 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15572 pc_rel, (enum bfd_reloc_code_real) reloc);
15573 break;
15576 /* Mark whether the fix is to a THUMB instruction, or an ARM
15577 instruction. */
15578 new_fix->tc_fix_data = thumb_mode;
15581 /* Create a frg for an instruction requiring relaxation. */
15582 static void
15583 output_relax_insn (void)
15585 char * to;
15586 symbolS *sym;
15587 int offset;
15589 /* The size of the instruction is unknown, so tie the debug info to the
15590 start of the instruction. */
15591 dwarf2_emit_insn (0);
15593 switch (inst.reloc.exp.X_op)
15595 case O_symbol:
15596 sym = inst.reloc.exp.X_add_symbol;
15597 offset = inst.reloc.exp.X_add_number;
15598 break;
15599 case O_constant:
15600 sym = NULL;
15601 offset = inst.reloc.exp.X_add_number;
15602 break;
15603 default:
15604 sym = make_expr_symbol (&inst.reloc.exp);
15605 offset = 0;
15606 break;
15608 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15609 inst.relax, sym, offset, NULL/*offset, opcode*/);
15610 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
15613 /* Write a 32-bit thumb instruction to buf. */
15614 static void
15615 put_thumb32_insn (char * buf, unsigned long insn)
15617 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15618 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15621 static void
15622 output_inst (const char * str)
15624 char * to = NULL;
15626 if (inst.error)
15628 as_bad ("%s -- `%s'", inst.error, str);
15629 return;
15631 if (inst.relax)
15633 output_relax_insn ();
15634 return;
15636 if (inst.size == 0)
15637 return;
15639 to = frag_more (inst.size);
15640 /* PR 9814: Record the thumb mode into the current frag so that we know
15641 what type of NOP padding to use, if necessary. We override any previous
15642 setting so that if the mode has changed then the NOPS that we use will
15643 match the encoding of the last instruction in the frag. */
15644 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
15646 if (thumb_mode && (inst.size > THUMB_SIZE))
15648 gas_assert (inst.size == (2 * THUMB_SIZE));
15649 put_thumb32_insn (to, inst.instruction);
15651 else if (inst.size > INSN_SIZE)
15653 gas_assert (inst.size == (2 * INSN_SIZE));
15654 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15655 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
15657 else
15658 md_number_to_chars (to, inst.instruction, inst.size);
15660 if (inst.reloc.type != BFD_RELOC_UNUSED)
15661 fix_new_arm (frag_now, to - frag_now->fr_literal,
15662 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15663 inst.reloc.type);
15665 dwarf2_emit_insn (inst.size);
15668 static char *
15669 output_it_inst (int cond, int mask, char * to)
15671 unsigned long instruction = 0xbf00;
15673 mask &= 0xf;
15674 instruction |= mask;
15675 instruction |= cond << 4;
15677 if (to == NULL)
15679 to = frag_more (2);
15680 #ifdef OBJ_ELF
15681 dwarf2_emit_insn (2);
15682 #endif
15685 md_number_to_chars (to, instruction, 2);
15687 return to;
15690 /* Tag values used in struct asm_opcode's tag field. */
15691 enum opcode_tag
15693 OT_unconditional, /* Instruction cannot be conditionalized.
15694 The ARM condition field is still 0xE. */
15695 OT_unconditionalF, /* Instruction cannot be conditionalized
15696 and carries 0xF in its ARM condition field. */
15697 OT_csuffix, /* Instruction takes a conditional suffix. */
15698 OT_csuffixF, /* Some forms of the instruction take a conditional
15699 suffix, others place 0xF where the condition field
15700 would be. */
15701 OT_cinfix3, /* Instruction takes a conditional infix,
15702 beginning at character index 3. (In
15703 unified mode, it becomes a suffix.) */
15704 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15705 tsts, cmps, cmns, and teqs. */
15706 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15707 character index 3, even in unified mode. Used for
15708 legacy instructions where suffix and infix forms
15709 may be ambiguous. */
15710 OT_csuf_or_in3, /* Instruction takes either a conditional
15711 suffix or an infix at character index 3. */
15712 OT_odd_infix_unc, /* This is the unconditional variant of an
15713 instruction that takes a conditional infix
15714 at an unusual position. In unified mode,
15715 this variant will accept a suffix. */
15716 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15717 are the conditional variants of instructions that
15718 take conditional infixes in unusual positions.
15719 The infix appears at character index
15720 (tag - OT_odd_infix_0). These are not accepted
15721 in unified mode. */
15724 /* Subroutine of md_assemble, responsible for looking up the primary
15725 opcode from the mnemonic the user wrote. STR points to the
15726 beginning of the mnemonic.
15728 This is not simply a hash table lookup, because of conditional
15729 variants. Most instructions have conditional variants, which are
15730 expressed with a _conditional affix_ to the mnemonic. If we were
15731 to encode each conditional variant as a literal string in the opcode
15732 table, it would have approximately 20,000 entries.
15734 Most mnemonics take this affix as a suffix, and in unified syntax,
15735 'most' is upgraded to 'all'. However, in the divided syntax, some
15736 instructions take the affix as an infix, notably the s-variants of
15737 the arithmetic instructions. Of those instructions, all but six
15738 have the infix appear after the third character of the mnemonic.
15740 Accordingly, the algorithm for looking up primary opcodes given
15741 an identifier is:
15743 1. Look up the identifier in the opcode table.
15744 If we find a match, go to step U.
15746 2. Look up the last two characters of the identifier in the
15747 conditions table. If we find a match, look up the first N-2
15748 characters of the identifier in the opcode table. If we
15749 find a match, go to step CE.
15751 3. Look up the fourth and fifth characters of the identifier in
15752 the conditions table. If we find a match, extract those
15753 characters from the identifier, and look up the remaining
15754 characters in the opcode table. If we find a match, go
15755 to step CM.
15757 4. Fail.
15759 U. Examine the tag field of the opcode structure, in case this is
15760 one of the six instructions with its conditional infix in an
15761 unusual place. If it is, the tag tells us where to find the
15762 infix; look it up in the conditions table and set inst.cond
15763 accordingly. Otherwise, this is an unconditional instruction.
15764 Again set inst.cond accordingly. Return the opcode structure.
15766 CE. Examine the tag field to make sure this is an instruction that
15767 should receive a conditional suffix. If it is not, fail.
15768 Otherwise, set inst.cond from the suffix we already looked up,
15769 and return the opcode structure.
15771 CM. Examine the tag field to make sure this is an instruction that
15772 should receive a conditional infix after the third character.
15773 If it is not, fail. Otherwise, undo the edits to the current
15774 line of input and proceed as for case CE. */
15776 static const struct asm_opcode *
15777 opcode_lookup (char **str)
15779 char *end, *base;
15780 char *affix;
15781 const struct asm_opcode *opcode;
15782 const struct asm_cond *cond;
15783 char save[2];
15785 /* Scan up to the end of the mnemonic, which must end in white space,
15786 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
15787 for (base = end = *str; *end != '\0'; end++)
15788 if (*end == ' ' || *end == '.')
15789 break;
15791 if (end == base)
15792 return NULL;
15794 /* Handle a possible width suffix and/or Neon type suffix. */
15795 if (end[0] == '.')
15797 int offset = 2;
15799 /* The .w and .n suffixes are only valid if the unified syntax is in
15800 use. */
15801 if (unified_syntax && end[1] == 'w')
15802 inst.size_req = 4;
15803 else if (unified_syntax && end[1] == 'n')
15804 inst.size_req = 2;
15805 else
15806 offset = 0;
15808 inst.vectype.elems = 0;
15810 *str = end + offset;
15812 if (end[offset] == '.')
15814 /* See if we have a Neon type suffix (possible in either unified or
15815 non-unified ARM syntax mode). */
15816 if (parse_neon_type (&inst.vectype, str) == FAIL)
15817 return NULL;
15819 else if (end[offset] != '\0' && end[offset] != ' ')
15820 return NULL;
15822 else
15823 *str = end;
15825 /* Look for unaffixed or special-case affixed mnemonic. */
15826 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15827 end - base);
15828 if (opcode)
15830 /* step U */
15831 if (opcode->tag < OT_odd_infix_0)
15833 inst.cond = COND_ALWAYS;
15834 return opcode;
15837 if (warn_on_deprecated && unified_syntax)
15838 as_warn (_("conditional infixes are deprecated in unified syntax"));
15839 affix = base + (opcode->tag - OT_odd_infix_0);
15840 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15841 gas_assert (cond);
15843 inst.cond = cond->value;
15844 return opcode;
15847 /* Cannot have a conditional suffix on a mnemonic of less than two
15848 characters. */
15849 if (end - base < 3)
15850 return NULL;
15852 /* Look for suffixed mnemonic. */
15853 affix = end - 2;
15854 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15855 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15856 affix - base);
15857 if (opcode && cond)
15859 /* step CE */
15860 switch (opcode->tag)
15862 case OT_cinfix3_legacy:
15863 /* Ignore conditional suffixes matched on infix only mnemonics. */
15864 break;
15866 case OT_cinfix3:
15867 case OT_cinfix3_deprecated:
15868 case OT_odd_infix_unc:
15869 if (!unified_syntax)
15870 return 0;
15871 /* else fall through */
15873 case OT_csuffix:
15874 case OT_csuffixF:
15875 case OT_csuf_or_in3:
15876 inst.cond = cond->value;
15877 return opcode;
15879 case OT_unconditional:
15880 case OT_unconditionalF:
15881 if (thumb_mode)
15882 inst.cond = cond->value;
15883 else
15885 /* Delayed diagnostic. */
15886 inst.error = BAD_COND;
15887 inst.cond = COND_ALWAYS;
15889 return opcode;
15891 default:
15892 return NULL;
15896 /* Cannot have a usual-position infix on a mnemonic of less than
15897 six characters (five would be a suffix). */
15898 if (end - base < 6)
15899 return NULL;
15901 /* Look for infixed mnemonic in the usual position. */
15902 affix = base + 3;
15903 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15904 if (!cond)
15905 return NULL;
15907 memcpy (save, affix, 2);
15908 memmove (affix, affix + 2, (end - affix) - 2);
15909 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15910 (end - base) - 2);
15911 memmove (affix + 2, affix, (end - affix) - 2);
15912 memcpy (affix, save, 2);
15914 if (opcode
15915 && (opcode->tag == OT_cinfix3
15916 || opcode->tag == OT_cinfix3_deprecated
15917 || opcode->tag == OT_csuf_or_in3
15918 || opcode->tag == OT_cinfix3_legacy))
15920 /* Step CM. */
15921 if (warn_on_deprecated && unified_syntax
15922 && (opcode->tag == OT_cinfix3
15923 || opcode->tag == OT_cinfix3_deprecated))
15924 as_warn (_("conditional infixes are deprecated in unified syntax"));
15926 inst.cond = cond->value;
15927 return opcode;
15930 return NULL;
15933 /* This function generates an initial IT instruction, leaving its block
15934 virtually open for the new instructions. Eventually,
15935 the mask will be updated by now_it_add_mask () each time
15936 a new instruction needs to be included in the IT block.
15937 Finally, the block is closed with close_automatic_it_block ().
15938 The block closure can be requested either from md_assemble (),
15939 a tencode (), or due to a label hook. */
15941 static void
15942 new_automatic_it_block (int cond)
15944 now_it.state = AUTOMATIC_IT_BLOCK;
15945 now_it.mask = 0x18;
15946 now_it.cc = cond;
15947 now_it.block_length = 1;
15948 mapping_state (MAP_THUMB);
15949 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15952 /* Close an automatic IT block.
15953 See comments in new_automatic_it_block (). */
15955 static void
15956 close_automatic_it_block (void)
15958 now_it.mask = 0x10;
15959 now_it.block_length = 0;
15962 /* Update the mask of the current automatically-generated IT
15963 instruction. See comments in new_automatic_it_block (). */
15965 static void
15966 now_it_add_mask (int cond)
15968 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15969 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15970 | ((bitvalue) << (nbit)))
15971 const int resulting_bit = (cond & 1);
15973 now_it.mask &= 0xf;
15974 now_it.mask = SET_BIT_VALUE (now_it.mask,
15975 resulting_bit,
15976 (5 - now_it.block_length));
15977 now_it.mask = SET_BIT_VALUE (now_it.mask,
15979 ((5 - now_it.block_length) - 1) );
15980 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15982 #undef CLEAR_BIT
15983 #undef SET_BIT_VALUE
15986 /* The IT blocks handling machinery is accessed through the these functions:
15987 it_fsm_pre_encode () from md_assemble ()
15988 set_it_insn_type () optional, from the tencode functions
15989 set_it_insn_type_last () ditto
15990 in_it_block () ditto
15991 it_fsm_post_encode () from md_assemble ()
15992 force_automatic_it_block_close () from label habdling functions
15994 Rationale:
15995 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15996 initializing the IT insn type with a generic initial value depending
15997 on the inst.condition.
15998 2) During the tencode function, two things may happen:
15999 a) The tencode function overrides the IT insn type by
16000 calling either set_it_insn_type (type) or set_it_insn_type_last ().
16001 b) The tencode function queries the IT block state by
16002 calling in_it_block () (i.e. to determine narrow/not narrow mode).
16004 Both set_it_insn_type and in_it_block run the internal FSM state
16005 handling function (handle_it_state), because: a) setting the IT insn
16006 type may incur in an invalid state (exiting the function),
16007 and b) querying the state requires the FSM to be updated.
16008 Specifically we want to avoid creating an IT block for conditional
16009 branches, so it_fsm_pre_encode is actually a guess and we can't
16010 determine whether an IT block is required until the tencode () routine
16011 has decided what type of instruction this actually it.
16012 Because of this, if set_it_insn_type and in_it_block have to be used,
16013 set_it_insn_type has to be called first.
16015 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
16016 determines the insn IT type depending on the inst.cond code.
16017 When a tencode () routine encodes an instruction that can be
16018 either outside an IT block, or, in the case of being inside, has to be
16019 the last one, set_it_insn_type_last () will determine the proper
16020 IT instruction type based on the inst.cond code. Otherwise,
16021 set_it_insn_type can be called for overriding that logic or
16022 for covering other cases.
16024 Calling handle_it_state () may not transition the IT block state to
16025 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
16026 still queried. Instead, if the FSM determines that the state should
16027 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
16028 after the tencode () function: that's what it_fsm_post_encode () does.
16030 Since in_it_block () calls the state handling function to get an
16031 updated state, an error may occur (due to invalid insns combination).
16032 In that case, inst.error is set.
16033 Therefore, inst.error has to be checked after the execution of
16034 the tencode () routine.
16036 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
16037 any pending state change (if any) that didn't take place in
16038 handle_it_state () as explained above. */
16040 static void
16041 it_fsm_pre_encode (void)
16043 if (inst.cond != COND_ALWAYS)
16044 inst.it_insn_type = INSIDE_IT_INSN;
16045 else
16046 inst.it_insn_type = OUTSIDE_IT_INSN;
16048 now_it.state_handled = 0;
16051 /* IT state FSM handling function. */
16053 static int
16054 handle_it_state (void)
16056 now_it.state_handled = 1;
16058 switch (now_it.state)
16060 case OUTSIDE_IT_BLOCK:
16061 switch (inst.it_insn_type)
16063 case OUTSIDE_IT_INSN:
16064 break;
16066 case INSIDE_IT_INSN:
16067 case INSIDE_IT_LAST_INSN:
16068 if (thumb_mode == 0)
16070 if (unified_syntax
16071 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
16072 as_tsktsk (_("Warning: conditional outside an IT block"\
16073 " for Thumb."));
16075 else
16077 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
16078 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
16080 /* Automatically generate the IT instruction. */
16081 new_automatic_it_block (inst.cond);
16082 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
16083 close_automatic_it_block ();
16085 else
16087 inst.error = BAD_OUT_IT;
16088 return FAIL;
16091 break;
16093 case IF_INSIDE_IT_LAST_INSN:
16094 case NEUTRAL_IT_INSN:
16095 break;
16097 case IT_INSN:
16098 now_it.state = MANUAL_IT_BLOCK;
16099 now_it.block_length = 0;
16100 break;
16102 break;
16104 case AUTOMATIC_IT_BLOCK:
16105 /* Three things may happen now:
16106 a) We should increment current it block size;
16107 b) We should close current it block (closing insn or 4 insns);
16108 c) We should close current it block and start a new one (due
16109 to incompatible conditions or
16110 4 insns-length block reached). */
16112 switch (inst.it_insn_type)
16114 case OUTSIDE_IT_INSN:
16115 /* The closure of the block shall happen immediatelly,
16116 so any in_it_block () call reports the block as closed. */
16117 force_automatic_it_block_close ();
16118 break;
16120 case INSIDE_IT_INSN:
16121 case INSIDE_IT_LAST_INSN:
16122 case IF_INSIDE_IT_LAST_INSN:
16123 now_it.block_length++;
16125 if (now_it.block_length > 4
16126 || !now_it_compatible (inst.cond))
16128 force_automatic_it_block_close ();
16129 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16130 new_automatic_it_block (inst.cond);
16132 else
16134 now_it_add_mask (inst.cond);
16137 if (now_it.state == AUTOMATIC_IT_BLOCK
16138 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16139 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16140 close_automatic_it_block ();
16141 break;
16143 case NEUTRAL_IT_INSN:
16144 now_it.block_length++;
16146 if (now_it.block_length > 4)
16147 force_automatic_it_block_close ();
16148 else
16149 now_it_add_mask (now_it.cc & 1);
16150 break;
16152 case IT_INSN:
16153 close_automatic_it_block ();
16154 now_it.state = MANUAL_IT_BLOCK;
16155 break;
16157 break;
16159 case MANUAL_IT_BLOCK:
16161 /* Check conditional suffixes. */
16162 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16163 int is_last;
16164 now_it.mask <<= 1;
16165 now_it.mask &= 0x1f;
16166 is_last = (now_it.mask == 0x10);
16168 switch (inst.it_insn_type)
16170 case OUTSIDE_IT_INSN:
16171 inst.error = BAD_NOT_IT;
16172 return FAIL;
16174 case INSIDE_IT_INSN:
16175 if (cond != inst.cond)
16177 inst.error = BAD_IT_COND;
16178 return FAIL;
16180 break;
16182 case INSIDE_IT_LAST_INSN:
16183 case IF_INSIDE_IT_LAST_INSN:
16184 if (cond != inst.cond)
16186 inst.error = BAD_IT_COND;
16187 return FAIL;
16189 if (!is_last)
16191 inst.error = BAD_BRANCH;
16192 return FAIL;
16194 break;
16196 case NEUTRAL_IT_INSN:
16197 /* The BKPT instruction is unconditional even in an IT block. */
16198 break;
16200 case IT_INSN:
16201 inst.error = BAD_IT_IT;
16202 return FAIL;
16205 break;
16208 return SUCCESS;
16211 static void
16212 it_fsm_post_encode (void)
16214 int is_last;
16216 if (!now_it.state_handled)
16217 handle_it_state ();
16219 is_last = (now_it.mask == 0x10);
16220 if (is_last)
16222 now_it.state = OUTSIDE_IT_BLOCK;
16223 now_it.mask = 0;
16227 static void
16228 force_automatic_it_block_close (void)
16230 if (now_it.state == AUTOMATIC_IT_BLOCK)
16232 close_automatic_it_block ();
16233 now_it.state = OUTSIDE_IT_BLOCK;
16234 now_it.mask = 0;
16238 static int
16239 in_it_block (void)
16241 if (!now_it.state_handled)
16242 handle_it_state ();
16244 return now_it.state != OUTSIDE_IT_BLOCK;
16247 void
16248 md_assemble (char *str)
16250 char *p = str;
16251 const struct asm_opcode * opcode;
16253 /* Align the previous label if needed. */
16254 if (last_label_seen != NULL)
16256 symbol_set_frag (last_label_seen, frag_now);
16257 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
16258 S_SET_SEGMENT (last_label_seen, now_seg);
16261 memset (&inst, '\0', sizeof (inst));
16262 inst.reloc.type = BFD_RELOC_UNUSED;
16264 opcode = opcode_lookup (&p);
16265 if (!opcode)
16267 /* It wasn't an instruction, but it might be a register alias of
16268 the form alias .req reg, or a Neon .dn/.qn directive. */
16269 if (! create_register_alias (str, p)
16270 && ! create_neon_reg_alias (str, p))
16271 as_bad (_("bad instruction `%s'"), str);
16273 return;
16276 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
16277 as_warn (_("s suffix on comparison instruction is deprecated"));
16279 /* The value which unconditional instructions should have in place of the
16280 condition field. */
16281 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
16283 if (thumb_mode)
16285 arm_feature_set variant;
16287 variant = cpu_variant;
16288 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
16289 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
16290 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
16291 /* Check that this instruction is supported for this CPU. */
16292 if (!opcode->tvariant
16293 || (thumb_mode == 1
16294 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
16296 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
16297 return;
16299 if (inst.cond != COND_ALWAYS && !unified_syntax
16300 && opcode->tencode != do_t_branch)
16302 as_bad (_("Thumb does not support conditional execution"));
16303 return;
16306 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
16308 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
16309 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
16310 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
16312 /* Two things are addressed here.
16313 1) Implicit require narrow instructions on Thumb-1.
16314 This avoids relaxation accidentally introducing Thumb-2
16315 instructions.
16316 2) Reject wide instructions in non Thumb-2 cores. */
16317 if (inst.size_req == 0)
16318 inst.size_req = 2;
16319 else if (inst.size_req == 4)
16321 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
16322 return;
16327 inst.instruction = opcode->tvalue;
16329 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
16331 /* Prepare the it_insn_type for those encodings that don't set
16332 it. */
16333 it_fsm_pre_encode ();
16335 opcode->tencode ();
16337 it_fsm_post_encode ();
16340 if (!(inst.error || inst.relax))
16342 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
16343 inst.size = (inst.instruction > 0xffff ? 4 : 2);
16344 if (inst.size_req && inst.size_req != inst.size)
16346 as_bad (_("cannot honor width suffix -- `%s'"), str);
16347 return;
16351 /* Something has gone badly wrong if we try to relax a fixed size
16352 instruction. */
16353 gas_assert (inst.size_req == 0 || !inst.relax);
16355 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16356 *opcode->tvariant);
16357 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
16358 set those bits when Thumb-2 32-bit instructions are seen. ie.
16359 anything other than bl/blx and v6-M instructions.
16360 This is overly pessimistic for relaxable instructions. */
16361 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
16362 || inst.relax)
16363 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
16364 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
16365 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16366 arm_ext_v6t2);
16368 check_neon_suffixes;
16370 if (!inst.error)
16372 mapping_state (MAP_THUMB);
16375 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
16377 bfd_boolean is_bx;
16379 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
16380 is_bx = (opcode->aencode == do_bx);
16382 /* Check that this instruction is supported for this CPU. */
16383 if (!(is_bx && fix_v4bx)
16384 && !(opcode->avariant &&
16385 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
16387 as_bad (_("selected processor does not support ARM mode `%s'"), str);
16388 return;
16390 if (inst.size_req)
16392 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
16393 return;
16396 inst.instruction = opcode->avalue;
16397 if (opcode->tag == OT_unconditionalF)
16398 inst.instruction |= 0xF << 28;
16399 else
16400 inst.instruction |= inst.cond << 28;
16401 inst.size = INSN_SIZE;
16402 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
16404 it_fsm_pre_encode ();
16405 opcode->aencode ();
16406 it_fsm_post_encode ();
16408 /* Arm mode bx is marked as both v4T and v5 because it's still required
16409 on a hypothetical non-thumb v5 core. */
16410 if (is_bx)
16411 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
16412 else
16413 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16414 *opcode->avariant);
16416 check_neon_suffixes;
16418 if (!inst.error)
16420 mapping_state (MAP_ARM);
16423 else
16425 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16426 "-- `%s'"), str);
16427 return;
16429 output_inst (str);
16432 static void
16433 check_it_blocks_finished (void)
16435 #ifdef OBJ_ELF
16436 asection *sect;
16438 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16439 if (seg_info (sect)->tc_segment_info_data.current_it.state
16440 == MANUAL_IT_BLOCK)
16442 as_warn (_("section '%s' finished with an open IT block."),
16443 sect->name);
16445 #else
16446 if (now_it.state == MANUAL_IT_BLOCK)
16447 as_warn (_("file finished with an open IT block."));
16448 #endif
16451 /* Various frobbings of labels and their addresses. */
16453 void
16454 arm_start_line_hook (void)
16456 last_label_seen = NULL;
16459 void
16460 arm_frob_label (symbolS * sym)
16462 last_label_seen = sym;
16464 ARM_SET_THUMB (sym, thumb_mode);
16466 #if defined OBJ_COFF || defined OBJ_ELF
16467 ARM_SET_INTERWORK (sym, support_interwork);
16468 #endif
16470 force_automatic_it_block_close ();
16472 /* Note - do not allow local symbols (.Lxxx) to be labelled
16473 as Thumb functions. This is because these labels, whilst
16474 they exist inside Thumb code, are not the entry points for
16475 possible ARM->Thumb calls. Also, these labels can be used
16476 as part of a computed goto or switch statement. eg gcc
16477 can generate code that looks like this:
16479 ldr r2, [pc, .Laaa]
16480 lsl r3, r3, #2
16481 ldr r2, [r3, r2]
16482 mov pc, r2
16484 .Lbbb: .word .Lxxx
16485 .Lccc: .word .Lyyy
16486 ..etc...
16487 .Laaa: .word Lbbb
16489 The first instruction loads the address of the jump table.
16490 The second instruction converts a table index into a byte offset.
16491 The third instruction gets the jump address out of the table.
16492 The fourth instruction performs the jump.
16494 If the address stored at .Laaa is that of a symbol which has the
16495 Thumb_Func bit set, then the linker will arrange for this address
16496 to have the bottom bit set, which in turn would mean that the
16497 address computation performed by the third instruction would end
16498 up with the bottom bit set. Since the ARM is capable of unaligned
16499 word loads, the instruction would then load the incorrect address
16500 out of the jump table, and chaos would ensue. */
16501 if (label_is_thumb_function_name
16502 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16503 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
16505 /* When the address of a Thumb function is taken the bottom
16506 bit of that address should be set. This will allow
16507 interworking between Arm and Thumb functions to work
16508 correctly. */
16510 THUMB_SET_FUNC (sym, 1);
16512 label_is_thumb_function_name = FALSE;
16515 dwarf2_emit_label (sym);
16518 bfd_boolean
16519 arm_data_in_code (void)
16521 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
16523 *input_line_pointer = '/';
16524 input_line_pointer += 5;
16525 *input_line_pointer = 0;
16526 return TRUE;
16529 return FALSE;
16532 char *
16533 arm_canonicalize_symbol_name (char * name)
16535 int len;
16537 if (thumb_mode && (len = strlen (name)) > 5
16538 && streq (name + len - 5, "/data"))
16539 *(name + len - 5) = 0;
16541 return name;
16544 /* Table of all register names defined by default. The user can
16545 define additional names with .req. Note that all register names
16546 should appear in both upper and lowercase variants. Some registers
16547 also have mixed-case names. */
16549 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
16550 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
16551 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
16552 #define REGSET(p,t) \
16553 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16554 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16555 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16556 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
16557 #define REGSETH(p,t) \
16558 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16559 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16560 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16561 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16562 #define REGSET2(p,t) \
16563 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16564 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16565 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16566 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
16567 #define SPLRBANK(base,bank,t) \
16568 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
16569 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
16570 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
16571 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
16572 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
16573 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
16575 static const struct reg_entry reg_names[] =
16577 /* ARM integer registers. */
16578 REGSET(r, RN), REGSET(R, RN),
16580 /* ATPCS synonyms. */
16581 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16582 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16583 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
16585 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16586 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16587 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
16589 /* Well-known aliases. */
16590 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16591 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16593 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16594 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16596 /* Coprocessor numbers. */
16597 REGSET(p, CP), REGSET(P, CP),
16599 /* Coprocessor register numbers. The "cr" variants are for backward
16600 compatibility. */
16601 REGSET(c, CN), REGSET(C, CN),
16602 REGSET(cr, CN), REGSET(CR, CN),
16604 /* ARM banked registers. */
16605 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
16606 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
16607 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
16608 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
16609 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
16610 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
16611 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
16613 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
16614 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
16615 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
16616 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
16617 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
16618 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
16619 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
16620 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
16622 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
16623 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
16624 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
16625 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
16626 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
16627 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
16628 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
16629 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
16630 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
16632 /* FPA registers. */
16633 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16634 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16636 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16637 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16639 /* VFP SP registers. */
16640 REGSET(s,VFS), REGSET(S,VFS),
16641 REGSETH(s,VFS), REGSETH(S,VFS),
16643 /* VFP DP Registers. */
16644 REGSET(d,VFD), REGSET(D,VFD),
16645 /* Extra Neon DP registers. */
16646 REGSETH(d,VFD), REGSETH(D,VFD),
16648 /* Neon QP registers. */
16649 REGSET2(q,NQ), REGSET2(Q,NQ),
16651 /* VFP control registers. */
16652 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16653 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
16654 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16655 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16656 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16657 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
16659 /* Maverick DSP coprocessor registers. */
16660 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16661 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16663 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16664 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16665 REGDEF(dspsc,0,DSPSC),
16667 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16668 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16669 REGDEF(DSPSC,0,DSPSC),
16671 /* iWMMXt data registers - p0, c0-15. */
16672 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16674 /* iWMMXt control registers - p1, c0-3. */
16675 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16676 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16677 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16678 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16680 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16681 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16682 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16683 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16684 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16686 /* XScale accumulator registers. */
16687 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16689 #undef REGDEF
16690 #undef REGNUM
16691 #undef REGSET
16693 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16694 within psr_required_here. */
16695 static const struct asm_psr psrs[] =
16697 /* Backward compatibility notation. Note that "all" is no longer
16698 truly all possible PSR bits. */
16699 {"all", PSR_c | PSR_f},
16700 {"flg", PSR_f},
16701 {"ctl", PSR_c},
16703 /* Individual flags. */
16704 {"f", PSR_f},
16705 {"c", PSR_c},
16706 {"x", PSR_x},
16707 {"s", PSR_s},
16709 /* Combinations of flags. */
16710 {"fs", PSR_f | PSR_s},
16711 {"fx", PSR_f | PSR_x},
16712 {"fc", PSR_f | PSR_c},
16713 {"sf", PSR_s | PSR_f},
16714 {"sx", PSR_s | PSR_x},
16715 {"sc", PSR_s | PSR_c},
16716 {"xf", PSR_x | PSR_f},
16717 {"xs", PSR_x | PSR_s},
16718 {"xc", PSR_x | PSR_c},
16719 {"cf", PSR_c | PSR_f},
16720 {"cs", PSR_c | PSR_s},
16721 {"cx", PSR_c | PSR_x},
16722 {"fsx", PSR_f | PSR_s | PSR_x},
16723 {"fsc", PSR_f | PSR_s | PSR_c},
16724 {"fxs", PSR_f | PSR_x | PSR_s},
16725 {"fxc", PSR_f | PSR_x | PSR_c},
16726 {"fcs", PSR_f | PSR_c | PSR_s},
16727 {"fcx", PSR_f | PSR_c | PSR_x},
16728 {"sfx", PSR_s | PSR_f | PSR_x},
16729 {"sfc", PSR_s | PSR_f | PSR_c},
16730 {"sxf", PSR_s | PSR_x | PSR_f},
16731 {"sxc", PSR_s | PSR_x | PSR_c},
16732 {"scf", PSR_s | PSR_c | PSR_f},
16733 {"scx", PSR_s | PSR_c | PSR_x},
16734 {"xfs", PSR_x | PSR_f | PSR_s},
16735 {"xfc", PSR_x | PSR_f | PSR_c},
16736 {"xsf", PSR_x | PSR_s | PSR_f},
16737 {"xsc", PSR_x | PSR_s | PSR_c},
16738 {"xcf", PSR_x | PSR_c | PSR_f},
16739 {"xcs", PSR_x | PSR_c | PSR_s},
16740 {"cfs", PSR_c | PSR_f | PSR_s},
16741 {"cfx", PSR_c | PSR_f | PSR_x},
16742 {"csf", PSR_c | PSR_s | PSR_f},
16743 {"csx", PSR_c | PSR_s | PSR_x},
16744 {"cxf", PSR_c | PSR_x | PSR_f},
16745 {"cxs", PSR_c | PSR_x | PSR_s},
16746 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16747 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16748 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16749 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16750 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16751 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16752 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16753 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16754 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16755 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16756 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16757 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16758 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16759 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16760 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16761 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16762 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16763 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16764 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16765 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16766 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16767 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16768 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16769 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16772 /* Table of V7M psr names. */
16773 static const struct asm_psr v7m_psrs[] =
16775 {"apsr", 0 }, {"APSR", 0 },
16776 {"iapsr", 1 }, {"IAPSR", 1 },
16777 {"eapsr", 2 }, {"EAPSR", 2 },
16778 {"psr", 3 }, {"PSR", 3 },
16779 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16780 {"ipsr", 5 }, {"IPSR", 5 },
16781 {"epsr", 6 }, {"EPSR", 6 },
16782 {"iepsr", 7 }, {"IEPSR", 7 },
16783 {"msp", 8 }, {"MSP", 8 },
16784 {"psp", 9 }, {"PSP", 9 },
16785 {"primask", 16}, {"PRIMASK", 16},
16786 {"basepri", 17}, {"BASEPRI", 17},
16787 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16788 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
16789 {"faultmask", 19}, {"FAULTMASK", 19},
16790 {"control", 20}, {"CONTROL", 20}
16793 /* Table of all shift-in-operand names. */
16794 static const struct asm_shift_name shift_names [] =
16796 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16797 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16798 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16799 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16800 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16801 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16804 /* Table of all explicit relocation names. */
16805 #ifdef OBJ_ELF
16806 static struct reloc_entry reloc_names[] =
16808 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16809 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16810 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16811 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16812 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16813 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16814 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16815 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16816 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16817 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
16818 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
16819 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
16820 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
16821 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
16822 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
16823 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
16824 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
16825 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
16827 #endif
16829 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
16830 static const struct asm_cond conds[] =
16832 {"eq", 0x0},
16833 {"ne", 0x1},
16834 {"cs", 0x2}, {"hs", 0x2},
16835 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16836 {"mi", 0x4},
16837 {"pl", 0x5},
16838 {"vs", 0x6},
16839 {"vc", 0x7},
16840 {"hi", 0x8},
16841 {"ls", 0x9},
16842 {"ge", 0xa},
16843 {"lt", 0xb},
16844 {"gt", 0xc},
16845 {"le", 0xd},
16846 {"al", 0xe}
16849 static struct asm_barrier_opt barrier_opt_names[] =
16851 { "sy", 0xf }, { "SY", 0xf },
16852 { "un", 0x7 }, { "UN", 0x7 },
16853 { "st", 0xe }, { "ST", 0xe },
16854 { "unst", 0x6 }, { "UNST", 0x6 },
16855 { "ish", 0xb }, { "ISH", 0xb },
16856 { "sh", 0xb }, { "SH", 0xb },
16857 { "ishst", 0xa }, { "ISHST", 0xa },
16858 { "shst", 0xa }, { "SHST", 0xa },
16859 { "nsh", 0x7 }, { "NSH", 0x7 },
16860 { "nshst", 0x6 }, { "NSHST", 0x6 },
16861 { "osh", 0x3 }, { "OSH", 0x3 },
16862 { "oshst", 0x2 }, { "OSHST", 0x2 }
16865 /* Table of ARM-format instructions. */
16867 /* Macros for gluing together operand strings. N.B. In all cases
16868 other than OPS0, the trailing OP_stop comes from default
16869 zero-initialization of the unspecified elements of the array. */
16870 #define OPS0() { OP_stop, }
16871 #define OPS1(a) { OP_##a, }
16872 #define OPS2(a,b) { OP_##a,OP_##b, }
16873 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16874 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16875 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16876 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16878 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16879 This is useful when mixing operands for ARM and THUMB, i.e. using the
16880 MIX_ARM_THUMB_OPERANDS macro.
16881 In order to use these macros, prefix the number of operands with _
16882 e.g. _3. */
16883 #define OPS_1(a) { a, }
16884 #define OPS_2(a,b) { a,b, }
16885 #define OPS_3(a,b,c) { a,b,c, }
16886 #define OPS_4(a,b,c,d) { a,b,c,d, }
16887 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16888 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16890 /* These macros abstract out the exact format of the mnemonic table and
16891 save some repeated characters. */
16893 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16894 #define TxCE(mnem, op, top, nops, ops, ae, te) \
16895 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
16896 THUMB_VARIANT, do_##ae, do_##te }
16898 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16899 a T_MNEM_xyz enumerator. */
16900 #define TCE(mnem, aop, top, nops, ops, ae, te) \
16901 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
16902 #define tCE(mnem, aop, top, nops, ops, ae, te) \
16903 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16905 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16906 infix after the third character. */
16907 #define TxC3(mnem, op, top, nops, ops, ae, te) \
16908 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
16909 THUMB_VARIANT, do_##ae, do_##te }
16910 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
16911 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
16912 THUMB_VARIANT, do_##ae, do_##te }
16913 #define TC3(mnem, aop, top, nops, ops, ae, te) \
16914 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
16915 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
16916 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
16917 #define tC3(mnem, aop, top, nops, ops, ae, te) \
16918 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16919 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
16920 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16922 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16923 appear in the condition table. */
16924 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
16925 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16926 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
16928 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
16929 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16930 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16931 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16932 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16933 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16934 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16935 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16936 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16937 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16938 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16939 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16940 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16941 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16942 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16943 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16944 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16945 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16946 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16947 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
16949 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
16950 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16951 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
16952 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
16954 /* Mnemonic that cannot be conditionalized. The ARM condition-code
16955 field is still 0xE. Many of the Thumb variants can be executed
16956 conditionally, so this is checked separately. */
16957 #define TUE(mnem, op, top, nops, ops, ae, te) \
16958 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
16959 THUMB_VARIANT, do_##ae, do_##te }
16961 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16962 condition code field. */
16963 #define TUF(mnem, op, top, nops, ops, ae, te) \
16964 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
16965 THUMB_VARIANT, do_##ae, do_##te }
16967 /* ARM-only variants of all the above. */
16968 #define CE(mnem, op, nops, ops, ae) \
16969 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16971 #define C3(mnem, op, nops, ops, ae) \
16972 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16974 /* Legacy mnemonics that always have conditional infix after the third
16975 character. */
16976 #define CL(mnem, op, nops, ops, ae) \
16977 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16978 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16980 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16981 #define cCE(mnem, op, nops, ops, ae) \
16982 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16984 /* Legacy coprocessor instructions where conditional infix and conditional
16985 suffix are ambiguous. For consistency this includes all FPA instructions,
16986 not just the potentially ambiguous ones. */
16987 #define cCL(mnem, op, nops, ops, ae) \
16988 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16989 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16991 /* Coprocessor, takes either a suffix or a position-3 infix
16992 (for an FPA corner case). */
16993 #define C3E(mnem, op, nops, ops, ae) \
16994 { mnem, OPS##nops ops, OT_csuf_or_in3, \
16995 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16997 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
16998 { m1 #m2 m3, OPS##nops ops, \
16999 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
17000 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17002 #define CM(m1, m2, op, nops, ops, ae) \
17003 xCM_ (m1, , m2, op, nops, ops, ae), \
17004 xCM_ (m1, eq, m2, op, nops, ops, ae), \
17005 xCM_ (m1, ne, m2, op, nops, ops, ae), \
17006 xCM_ (m1, cs, m2, op, nops, ops, ae), \
17007 xCM_ (m1, hs, m2, op, nops, ops, ae), \
17008 xCM_ (m1, cc, m2, op, nops, ops, ae), \
17009 xCM_ (m1, ul, m2, op, nops, ops, ae), \
17010 xCM_ (m1, lo, m2, op, nops, ops, ae), \
17011 xCM_ (m1, mi, m2, op, nops, ops, ae), \
17012 xCM_ (m1, pl, m2, op, nops, ops, ae), \
17013 xCM_ (m1, vs, m2, op, nops, ops, ae), \
17014 xCM_ (m1, vc, m2, op, nops, ops, ae), \
17015 xCM_ (m1, hi, m2, op, nops, ops, ae), \
17016 xCM_ (m1, ls, m2, op, nops, ops, ae), \
17017 xCM_ (m1, ge, m2, op, nops, ops, ae), \
17018 xCM_ (m1, lt, m2, op, nops, ops, ae), \
17019 xCM_ (m1, gt, m2, op, nops, ops, ae), \
17020 xCM_ (m1, le, m2, op, nops, ops, ae), \
17021 xCM_ (m1, al, m2, op, nops, ops, ae)
17023 #define UE(mnem, op, nops, ops, ae) \
17024 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17026 #define UF(mnem, op, nops, ops, ae) \
17027 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17029 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
17030 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
17031 use the same encoding function for each. */
17032 #define NUF(mnem, op, nops, ops, enc) \
17033 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
17034 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17036 /* Neon data processing, version which indirects through neon_enc_tab for
17037 the various overloaded versions of opcodes. */
17038 #define nUF(mnem, op, nops, ops, enc) \
17039 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
17040 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17042 /* Neon insn with conditional suffix for the ARM version, non-overloaded
17043 version. */
17044 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
17045 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
17046 THUMB_VARIANT, do_##enc, do_##enc }
17048 #define NCE(mnem, op, nops, ops, enc) \
17049 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
17051 #define NCEF(mnem, op, nops, ops, enc) \
17052 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
17054 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
17055 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
17056 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
17057 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17059 #define nCE(mnem, op, nops, ops, enc) \
17060 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
17062 #define nCEF(mnem, op, nops, ops, enc) \
17063 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
17065 #define do_0 0
17067 static const struct asm_opcode insns[] =
17069 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
17070 #define THUMB_VARIANT &arm_ext_v4t
17071 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
17072 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
17073 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
17074 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
17075 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
17076 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
17077 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
17078 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
17079 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
17080 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
17081 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
17082 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
17083 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
17084 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
17085 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
17086 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
17088 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
17089 for setting PSR flag bits. They are obsolete in V6 and do not
17090 have Thumb equivalents. */
17091 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17092 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17093 CL("tstp", 110f000, 2, (RR, SH), cmp),
17094 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17095 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17096 CL("cmpp", 150f000, 2, (RR, SH), cmp),
17097 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17098 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17099 CL("cmnp", 170f000, 2, (RR, SH), cmp),
17101 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
17102 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
17103 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
17104 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
17106 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
17107 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17108 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
17109 OP_RRnpc),
17110 OP_ADDRGLDR),ldst, t_ldst),
17111 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17113 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17114 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17115 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17116 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17117 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17118 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17120 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
17121 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
17122 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
17123 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
17125 /* Pseudo ops. */
17126 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
17127 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
17128 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
17130 /* Thumb-compatibility pseudo ops. */
17131 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17132 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17133 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17134 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17135 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17136 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17137 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17138 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17139 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17140 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17141 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17142 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
17144 /* These may simplify to neg. */
17145 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17146 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
17148 #undef THUMB_VARIANT
17149 #define THUMB_VARIANT & arm_ext_v6
17151 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
17153 /* V1 instructions with no Thumb analogue prior to V6T2. */
17154 #undef THUMB_VARIANT
17155 #define THUMB_VARIANT & arm_ext_v6t2
17157 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17158 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17159 CL("teqp", 130f000, 2, (RR, SH), cmp),
17161 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17162 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17163 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
17164 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17166 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17167 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17169 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17170 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17172 /* V1 instructions with no Thumb analogue at all. */
17173 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
17174 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
17176 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
17177 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
17178 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
17179 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
17180 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
17181 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
17182 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
17183 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
17185 #undef ARM_VARIANT
17186 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
17187 #undef THUMB_VARIANT
17188 #define THUMB_VARIANT & arm_ext_v4t
17190 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17191 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17193 #undef THUMB_VARIANT
17194 #define THUMB_VARIANT & arm_ext_v6t2
17196 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17197 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
17199 /* Generic coprocessor instructions. */
17200 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17201 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17202 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17203 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17204 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17205 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17206 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
17208 #undef ARM_VARIANT
17209 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
17211 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17212 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17214 #undef ARM_VARIANT
17215 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
17216 #undef THUMB_VARIANT
17217 #define THUMB_VARIANT & arm_ext_msr
17219 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
17220 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
17222 #undef ARM_VARIANT
17223 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
17224 #undef THUMB_VARIANT
17225 #define THUMB_VARIANT & arm_ext_v6t2
17227 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17228 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17229 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17230 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17231 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17232 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17233 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17234 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17236 #undef ARM_VARIANT
17237 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
17238 #undef THUMB_VARIANT
17239 #define THUMB_VARIANT & arm_ext_v4t
17241 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17242 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17243 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17244 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17245 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17246 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17248 #undef ARM_VARIANT
17249 #define ARM_VARIANT & arm_ext_v4t_5
17251 /* ARM Architecture 4T. */
17252 /* Note: bx (and blx) are required on V5, even if the processor does
17253 not support Thumb. */
17254 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
17256 #undef ARM_VARIANT
17257 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
17258 #undef THUMB_VARIANT
17259 #define THUMB_VARIANT & arm_ext_v5t
17261 /* Note: blx has 2 variants; the .value coded here is for
17262 BLX(2). Only this variant has conditional execution. */
17263 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
17264 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
17266 #undef THUMB_VARIANT
17267 #define THUMB_VARIANT & arm_ext_v6t2
17269 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
17270 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17271 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17272 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17273 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17274 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17275 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17276 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17278 #undef ARM_VARIANT
17279 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
17280 #undef THUMB_VARIANT
17281 #define THUMB_VARIANT &arm_ext_v5exp
17283 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17284 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17285 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17286 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17288 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17289 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17291 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17292 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17293 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17294 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17296 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17297 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17298 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17299 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17301 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17302 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17304 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17305 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17306 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17307 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17309 #undef ARM_VARIANT
17310 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
17311 #undef THUMB_VARIANT
17312 #define THUMB_VARIANT &arm_ext_v6t2
17314 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
17315 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
17316 ldrd, t_ldstd),
17317 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
17318 ADDRGLDRS), ldrd, t_ldstd),
17320 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17321 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17323 #undef ARM_VARIANT
17324 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
17326 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
17328 #undef ARM_VARIANT
17329 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
17330 #undef THUMB_VARIANT
17331 #define THUMB_VARIANT & arm_ext_v6
17333 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
17334 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
17335 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17336 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17337 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17338 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17339 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17340 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17341 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17342 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
17344 #undef THUMB_VARIANT
17345 #define THUMB_VARIANT & arm_ext_v6t2
17347 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
17348 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17349 strex, t_strex),
17350 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17351 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17353 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
17354 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
17356 /* ARM V6 not included in V7M. */
17357 #undef THUMB_VARIANT
17358 #define THUMB_VARIANT & arm_ext_v6_notm
17359 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17360 UF(rfeib, 9900a00, 1, (RRw), rfe),
17361 UF(rfeda, 8100a00, 1, (RRw), rfe),
17362 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17363 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17364 UF(rfefa, 9900a00, 1, (RRw), rfe),
17365 UF(rfeea, 8100a00, 1, (RRw), rfe),
17366 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17367 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
17368 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
17369 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
17370 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
17372 /* ARM V6 not included in V7M (eg. integer SIMD). */
17373 #undef THUMB_VARIANT
17374 #define THUMB_VARIANT & arm_ext_v6_dsp
17375 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
17376 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
17377 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
17378 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17379 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17380 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17381 /* Old name for QASX. */
17382 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17383 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17384 /* Old name for QSAX. */
17385 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17386 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17387 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17388 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17389 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17390 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17391 /* Old name for SASX. */
17392 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17393 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17394 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17395 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17396 /* Old name for SHASX. */
17397 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17398 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17399 /* Old name for SHSAX. */
17400 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17401 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17402 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17403 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17404 /* Old name for SSAX. */
17405 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17406 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17407 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17408 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17409 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17410 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17411 /* Old name for UASX. */
17412 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17413 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17414 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17415 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17416 /* Old name for UHASX. */
17417 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17418 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17419 /* Old name for UHSAX. */
17420 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17421 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17422 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17423 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17424 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17425 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17426 /* Old name for UQASX. */
17427 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17428 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17429 /* Old name for UQSAX. */
17430 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17431 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17432 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17433 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17434 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17435 /* Old name for USAX. */
17436 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17437 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17438 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17439 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17440 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17441 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17442 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17443 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17444 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17445 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17446 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17447 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17448 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17449 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17450 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17451 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17452 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17453 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17454 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17455 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17456 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17457 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17458 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17459 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17460 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17461 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17462 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17463 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17464 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17465 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17466 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17467 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17468 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17469 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
17471 #undef ARM_VARIANT
17472 #define ARM_VARIANT & arm_ext_v6k
17473 #undef THUMB_VARIANT
17474 #define THUMB_VARIANT & arm_ext_v6k
17476 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17477 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17478 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17479 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
17481 #undef THUMB_VARIANT
17482 #define THUMB_VARIANT & arm_ext_v6_notm
17483 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17484 ldrexd, t_ldrexd),
17485 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17486 RRnpcb), strexd, t_strexd),
17488 #undef THUMB_VARIANT
17489 #define THUMB_VARIANT & arm_ext_v6t2
17490 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17491 rd_rn, rd_rn),
17492 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17493 rd_rn, rd_rn),
17494 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17495 strex, rm_rd_rn),
17496 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17497 strex, rm_rd_rn),
17498 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
17500 #undef ARM_VARIANT
17501 #define ARM_VARIANT & arm_ext_sec
17502 #undef THUMB_VARIANT
17503 #define THUMB_VARIANT & arm_ext_sec
17505 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
17507 #undef ARM_VARIANT
17508 #define ARM_VARIANT & arm_ext_virt
17509 #undef THUMB_VARIANT
17510 #define THUMB_VARIANT & arm_ext_virt
17512 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
17513 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
17515 #undef ARM_VARIANT
17516 #define ARM_VARIANT & arm_ext_v6t2
17517 #undef THUMB_VARIANT
17518 #define THUMB_VARIANT & arm_ext_v6t2
17520 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17521 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17522 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17523 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17525 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17526 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17527 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17528 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
17530 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17531 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17532 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17533 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17535 /* Thumb-only instructions. */
17536 #undef ARM_VARIANT
17537 #define ARM_VARIANT NULL
17538 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17539 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
17541 /* ARM does not really have an IT instruction, so always allow it.
17542 The opcode is copied from Thumb in order to allow warnings in
17543 -mimplicit-it=[never | arm] modes. */
17544 #undef ARM_VARIANT
17545 #define ARM_VARIANT & arm_ext_v1
17547 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17548 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17549 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17550 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17551 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17552 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17553 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17554 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17555 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17556 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17557 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17558 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17559 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17560 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17561 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
17562 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
17563 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17564 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
17566 /* Thumb2 only instructions. */
17567 #undef ARM_VARIANT
17568 #define ARM_VARIANT NULL
17570 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17571 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17572 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17573 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17574 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17575 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
17577 /* Hardware division instructions. */
17578 #undef ARM_VARIANT
17579 #define ARM_VARIANT & arm_ext_adiv
17580 #undef THUMB_VARIANT
17581 #define THUMB_VARIANT & arm_ext_div
17583 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
17584 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
17586 /* ARM V6M/V7 instructions. */
17587 #undef ARM_VARIANT
17588 #define ARM_VARIANT & arm_ext_barrier
17589 #undef THUMB_VARIANT
17590 #define THUMB_VARIANT & arm_ext_barrier
17592 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17593 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17594 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
17596 /* ARM V7 instructions. */
17597 #undef ARM_VARIANT
17598 #define ARM_VARIANT & arm_ext_v7
17599 #undef THUMB_VARIANT
17600 #define THUMB_VARIANT & arm_ext_v7
17602 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17603 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
17605 #undef ARM_VARIANT
17606 #define ARM_VARIANT & arm_ext_mp
17607 #undef THUMB_VARIANT
17608 #define THUMB_VARIANT & arm_ext_mp
17610 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17612 #undef ARM_VARIANT
17613 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17615 cCE("wfs", e200110, 1, (RR), rd),
17616 cCE("rfs", e300110, 1, (RR), rd),
17617 cCE("wfc", e400110, 1, (RR), rd),
17618 cCE("rfc", e500110, 1, (RR), rd),
17620 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17621 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17622 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17623 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17625 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17626 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17627 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17628 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17630 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17631 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17632 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17633 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17634 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17635 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17636 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17637 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17638 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17639 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17640 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17641 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17643 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17644 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17645 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17646 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17647 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17648 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17649 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17650 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17651 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17652 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17653 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17654 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17656 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17657 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17658 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17659 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17660 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17661 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17662 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17663 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17664 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17665 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17666 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17667 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17669 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17670 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17671 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17672 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17673 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17674 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17675 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17676 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17677 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17678 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17679 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17680 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17682 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17683 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17684 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17685 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17686 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17687 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17688 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17689 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17690 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17691 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17692 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17693 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17695 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17696 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17697 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17698 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17699 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17700 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17701 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17702 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17703 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17704 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17705 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17706 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17708 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17709 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17710 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17711 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17712 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17713 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17714 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17715 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17716 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17717 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17718 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17719 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17721 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17722 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17723 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17724 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17725 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17726 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17727 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17728 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17729 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17730 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17731 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17732 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17734 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17735 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17736 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17737 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17738 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17739 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17740 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17741 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17742 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17743 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17744 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17745 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17747 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17748 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17749 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17750 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17751 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17752 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17753 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17754 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17755 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17756 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17757 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17758 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17760 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17761 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17762 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17763 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17764 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17765 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17766 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17767 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17768 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17769 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17770 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17771 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17773 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17774 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17775 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17776 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17777 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17778 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17779 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17780 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17781 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17782 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17783 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17784 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17786 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17787 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17788 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17789 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17790 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17791 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17792 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17793 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17794 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17795 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17796 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17797 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17799 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17800 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17801 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17802 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17803 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17804 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17805 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17806 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17807 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17808 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17809 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17810 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17812 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17813 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17814 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17815 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17816 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17817 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17818 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17819 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17820 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17821 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17822 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17823 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17825 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17826 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17827 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17828 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17829 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17830 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17831 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17832 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17833 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17834 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17835 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17836 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17838 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17839 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17840 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17841 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17842 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17843 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17844 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17845 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17846 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17847 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17848 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17849 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17851 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17852 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17853 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17854 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17855 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17856 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17857 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17858 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17859 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17860 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17861 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17862 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17864 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17865 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17866 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17867 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17868 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17869 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17870 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17871 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17872 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17873 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17874 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17875 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17877 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17878 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17879 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17880 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17881 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17882 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17883 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17884 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17885 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17886 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17887 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17888 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17890 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17891 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17892 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17893 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17894 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17895 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17896 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17897 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17898 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17899 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17900 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17901 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17903 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17904 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17905 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17906 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17907 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17908 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17909 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17910 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17911 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17912 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17913 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17914 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17916 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17917 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17918 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17919 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17920 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17921 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17922 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17923 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17924 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17925 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17926 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17927 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17929 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17930 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17931 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17932 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17933 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17934 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17935 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17936 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17937 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17938 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17939 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17940 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17942 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17943 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17944 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17945 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17946 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17947 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17948 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17949 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17950 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17951 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17952 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17953 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17955 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17956 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17957 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17958 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17959 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17960 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17961 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17962 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17963 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17964 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17965 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17966 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17968 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17969 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17970 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17971 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17972 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17973 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17974 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17975 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17976 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17977 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17978 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17979 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17981 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17982 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17983 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17984 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17985 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17986 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17987 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17988 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17989 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17990 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17991 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17992 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17994 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17995 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17996 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17997 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17998 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17999 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18000 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18001 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18002 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18003 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18004 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18005 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18007 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
18008 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
18009 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
18010 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
18012 cCL("flts", e000110, 2, (RF, RR), rn_rd),
18013 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
18014 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
18015 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
18016 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
18017 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
18018 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
18019 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
18020 cCL("flte", e080110, 2, (RF, RR), rn_rd),
18021 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
18022 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
18023 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
18025 /* The implementation of the FIX instruction is broken on some
18026 assemblers, in that it accepts a precision specifier as well as a
18027 rounding specifier, despite the fact that this is meaningless.
18028 To be more compatible, we accept it as well, though of course it
18029 does not set any bits. */
18030 cCE("fix", e100110, 2, (RR, RF), rd_rm),
18031 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
18032 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
18033 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
18034 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
18035 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
18036 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
18037 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
18038 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
18039 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
18040 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
18041 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
18042 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
18044 /* Instructions that were new with the real FPA, call them V2. */
18045 #undef ARM_VARIANT
18046 #define ARM_VARIANT & fpu_fpa_ext_v2
18048 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18049 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18050 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18051 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18052 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18053 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18055 #undef ARM_VARIANT
18056 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
18058 /* Moves and type conversions. */
18059 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
18060 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
18061 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
18062 cCE("fmstat", ef1fa10, 0, (), noargs),
18063 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
18064 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
18065 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
18066 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
18067 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
18068 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18069 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
18070 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18071 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
18072 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
18074 /* Memory operations. */
18075 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
18076 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
18077 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18078 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18079 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18080 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18081 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18082 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18083 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18084 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18085 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18086 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18087 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18088 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18089 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18090 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18091 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18092 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18094 /* Monadic operations. */
18095 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
18096 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
18097 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
18099 /* Dyadic operations. */
18100 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18101 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18102 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18103 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18104 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18105 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18106 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18107 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18108 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18110 /* Comparisons. */
18111 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
18112 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
18113 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
18114 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
18116 /* Double precision load/store are still present on single precision
18117 implementations. */
18118 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
18119 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
18120 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18121 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18122 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18123 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18124 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18125 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18126 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18127 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18129 #undef ARM_VARIANT
18130 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
18132 /* Moves and type conversions. */
18133 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18134 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18135 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18136 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
18137 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
18138 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
18139 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
18140 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18141 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
18142 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18143 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18144 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18145 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18147 /* Monadic operations. */
18148 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18149 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18150 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18152 /* Dyadic operations. */
18153 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18154 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18155 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18156 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18157 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18158 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18159 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18160 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18161 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18163 /* Comparisons. */
18164 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18165 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
18166 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18167 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
18169 #undef ARM_VARIANT
18170 #define ARM_VARIANT & fpu_vfp_ext_v2
18172 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
18173 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
18174 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
18175 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
18177 /* Instructions which may belong to either the Neon or VFP instruction sets.
18178 Individual encoder functions perform additional architecture checks. */
18179 #undef ARM_VARIANT
18180 #define ARM_VARIANT & fpu_vfp_ext_v1xd
18181 #undef THUMB_VARIANT
18182 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
18184 /* These mnemonics are unique to VFP. */
18185 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
18186 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
18187 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18188 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18189 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18190 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18191 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18192 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
18193 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
18194 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
18196 /* Mnemonics shared by Neon and VFP. */
18197 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
18198 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18199 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18201 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18202 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18204 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18205 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18207 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18208 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18209 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18210 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18211 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18212 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18213 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18214 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18216 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
18217 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
18218 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
18219 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
18222 /* NOTE: All VMOV encoding is special-cased! */
18223 NCE(vmov, 0, 1, (VMOV), neon_mov),
18224 NCE(vmovq, 0, 1, (VMOV), neon_mov),
18226 #undef THUMB_VARIANT
18227 #define THUMB_VARIANT & fpu_neon_ext_v1
18228 #undef ARM_VARIANT
18229 #define ARM_VARIANT & fpu_neon_ext_v1
18231 /* Data processing with three registers of the same length. */
18232 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
18233 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
18234 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
18235 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18236 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18237 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18238 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18239 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18240 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18241 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
18242 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18243 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18244 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18245 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18246 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18247 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18248 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18249 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18250 /* If not immediate, fall back to neon_dyadic_i64_su.
18251 shl_imm should accept I8 I16 I32 I64,
18252 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
18253 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
18254 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
18255 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
18256 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
18257 /* Logic ops, types optional & ignored. */
18258 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18259 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18260 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18261 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18262 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18263 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18264 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18265 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18266 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
18267 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
18268 /* Bitfield ops, untyped. */
18269 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18270 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18271 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18272 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18273 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18274 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18275 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
18276 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18277 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18278 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18279 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18280 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18281 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18282 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
18283 back to neon_dyadic_if_su. */
18284 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18285 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18286 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18287 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18288 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18289 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18290 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18291 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18292 /* Comparison. Type I8 I16 I32 F32. */
18293 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
18294 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
18295 /* As above, D registers only. */
18296 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18297 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18298 /* Int and float variants, signedness unimportant. */
18299 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18300 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18301 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
18302 /* Add/sub take types I8 I16 I32 I64 F32. */
18303 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18304 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18305 /* vtst takes sizes 8, 16, 32. */
18306 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
18307 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
18308 /* VMUL takes I8 I16 I32 F32 P8. */
18309 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
18310 /* VQD{R}MULH takes S16 S32. */
18311 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18312 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18313 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18314 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18315 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18316 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18317 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18318 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18319 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18320 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18321 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18322 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18323 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18324 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18325 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18326 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18328 /* Two address, int/float. Types S8 S16 S32 F32. */
18329 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
18330 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
18332 /* Data processing with two registers and a shift amount. */
18333 /* Right shifts, and variants with rounding.
18334 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
18335 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18336 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18337 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18338 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18339 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18340 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18341 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18342 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18343 /* Shift and insert. Sizes accepted 8 16 32 64. */
18344 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
18345 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
18346 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
18347 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
18348 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
18349 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
18350 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
18351 /* Right shift immediate, saturating & narrowing, with rounding variants.
18352 Types accepted S16 S32 S64 U16 U32 U64. */
18353 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18354 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18355 /* As above, unsigned. Types accepted S16 S32 S64. */
18356 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18357 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18358 /* Right shift narrowing. Types accepted I16 I32 I64. */
18359 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18360 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18361 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
18362 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
18363 /* CVT with optional immediate for fixed-point variant. */
18364 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
18366 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
18367 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
18369 /* Data processing, three registers of different lengths. */
18370 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
18371 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
18372 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
18373 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
18374 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
18375 /* If not scalar, fall back to neon_dyadic_long.
18376 Vector types as above, scalar types S16 S32 U16 U32. */
18377 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18378 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18379 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
18380 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18381 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18382 /* Dyadic, narrowing insns. Types I16 I32 I64. */
18383 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18384 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18385 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18386 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18387 /* Saturating doubling multiplies. Types S16 S32. */
18388 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18389 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18390 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18391 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
18392 S16 S32 U16 U32. */
18393 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
18395 /* Extract. Size 8. */
18396 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
18397 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
18399 /* Two registers, miscellaneous. */
18400 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
18401 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
18402 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
18403 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
18404 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
18405 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
18406 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
18407 /* Vector replicate. Sizes 8 16 32. */
18408 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
18409 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
18410 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
18411 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
18412 /* VMOVN. Types I16 I32 I64. */
18413 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
18414 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
18415 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
18416 /* VQMOVUN. Types S16 S32 S64. */
18417 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
18418 /* VZIP / VUZP. Sizes 8 16 32. */
18419 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
18420 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
18421 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
18422 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
18423 /* VQABS / VQNEG. Types S8 S16 S32. */
18424 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18425 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
18426 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18427 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
18428 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
18429 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
18430 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
18431 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
18432 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
18433 /* Reciprocal estimates. Types U32 F32. */
18434 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
18435 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
18436 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
18437 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
18438 /* VCLS. Types S8 S16 S32. */
18439 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
18440 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
18441 /* VCLZ. Types I8 I16 I32. */
18442 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
18443 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
18444 /* VCNT. Size 8. */
18445 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18446 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18447 /* Two address, untyped. */
18448 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18449 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18450 /* VTRN. Sizes 8 16 32. */
18451 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18452 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
18454 /* Table lookup. Size 8. */
18455 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18456 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18458 #undef THUMB_VARIANT
18459 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18460 #undef ARM_VARIANT
18461 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18463 /* Neon element/structure load/store. */
18464 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18465 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18466 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18467 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18468 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18469 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18470 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18471 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18473 #undef THUMB_VARIANT
18474 #define THUMB_VARIANT &fpu_vfp_ext_v3xd
18475 #undef ARM_VARIANT
18476 #define ARM_VARIANT &fpu_vfp_ext_v3xd
18477 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18478 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18479 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18480 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18481 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18482 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18483 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18484 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18485 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18487 #undef THUMB_VARIANT
18488 #define THUMB_VARIANT & fpu_vfp_ext_v3
18489 #undef ARM_VARIANT
18490 #define ARM_VARIANT & fpu_vfp_ext_v3
18492 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
18493 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18494 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18495 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18496 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18497 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18498 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18499 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18500 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18502 #undef ARM_VARIANT
18503 #define ARM_VARIANT &fpu_vfp_ext_fma
18504 #undef THUMB_VARIANT
18505 #define THUMB_VARIANT &fpu_vfp_ext_fma
18506 /* Mnemonics shared by Neon and VFP. These are included in the
18507 VFP FMA variant; NEON and VFP FMA always includes the NEON
18508 FMA instructions. */
18509 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18510 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18511 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18512 the v form should always be used. */
18513 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18514 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18515 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18516 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18517 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18518 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18520 #undef THUMB_VARIANT
18521 #undef ARM_VARIANT
18522 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18524 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18525 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18526 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18527 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18528 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18529 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18530 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18531 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
18533 #undef ARM_VARIANT
18534 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18536 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18537 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18538 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18539 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18540 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18541 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18542 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18543 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18544 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18545 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18546 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18547 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18548 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18549 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18550 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18551 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18552 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18553 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18554 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18555 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18556 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18557 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18558 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18559 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18560 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18561 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18562 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18563 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18564 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18565 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18566 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18567 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18568 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18569 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18570 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18571 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18572 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18573 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18574 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18575 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18576 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18577 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18578 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18579 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18580 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18581 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18582 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18583 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18584 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18585 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18586 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18587 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18588 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18589 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18590 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18591 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18592 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18593 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18594 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18595 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18596 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18597 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18598 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18599 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18600 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18601 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18602 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18603 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18604 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18605 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18606 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18607 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18608 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18609 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18610 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18611 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18612 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18613 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18614 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18615 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18616 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18617 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18618 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18619 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18620 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18621 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18622 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18623 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18624 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18625 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18626 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18627 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18628 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18629 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18630 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18631 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18632 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18633 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18634 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18635 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18636 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18637 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18638 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18639 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18640 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18641 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18642 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18643 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18644 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18645 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18646 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18647 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18648 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18649 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18650 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18651 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18652 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18653 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18654 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18655 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18656 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18657 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18658 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18659 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18660 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18661 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18662 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18663 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18664 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18665 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18666 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18667 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18668 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18669 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18670 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18671 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18672 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18673 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18674 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18675 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18676 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18677 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18678 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18679 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18680 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18681 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18682 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18683 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18684 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18685 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18686 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18687 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18688 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18689 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18690 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18691 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18692 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18693 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18694 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18695 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18696 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18697 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
18699 #undef ARM_VARIANT
18700 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18702 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18703 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18704 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18705 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18706 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18707 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18708 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18709 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18710 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18711 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18712 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18713 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18714 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18715 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18716 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18717 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18718 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18719 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18720 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18721 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18722 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18723 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18724 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18725 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18726 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18727 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18728 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18729 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18730 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18731 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18732 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18733 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18734 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18735 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18736 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18737 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18738 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18739 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18740 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18741 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18742 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18743 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18744 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18745 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18746 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18747 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18748 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18749 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18750 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18751 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18752 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18753 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18754 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18755 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18756 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18757 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18758 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18760 #undef ARM_VARIANT
18761 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18763 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18764 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18765 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18766 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18767 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18768 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18769 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18770 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18771 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18772 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18773 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18774 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18775 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18776 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18777 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18778 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18779 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18780 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18781 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18782 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18783 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18784 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18785 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18786 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18787 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18788 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18789 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18790 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18791 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18792 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18793 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18794 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18795 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18796 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18797 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18798 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18799 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18800 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18801 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18802 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18803 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18804 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18805 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18806 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18807 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18808 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18809 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18810 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18811 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18812 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18813 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18814 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18815 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18816 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18817 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18818 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18819 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18820 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18821 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18822 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18823 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18824 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18825 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18826 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18827 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18828 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18829 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18830 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18831 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18832 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18833 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18834 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18835 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18836 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18837 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18838 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18840 #undef ARM_VARIANT
18841 #undef THUMB_VARIANT
18842 #undef TCE
18843 #undef TCM
18844 #undef TUE
18845 #undef TUF
18846 #undef TCC
18847 #undef cCE
18848 #undef cCL
18849 #undef C3E
18850 #undef CE
18851 #undef CM
18852 #undef UE
18853 #undef UF
18854 #undef UT
18855 #undef NUF
18856 #undef nUF
18857 #undef NCE
18858 #undef nCE
18859 #undef OPS0
18860 #undef OPS1
18861 #undef OPS2
18862 #undef OPS3
18863 #undef OPS4
18864 #undef OPS5
18865 #undef OPS6
18866 #undef do_0
18868 /* MD interface: bits in the object file. */
18870 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18871 for use in the a.out file, and stores them in the array pointed to by buf.
18872 This knows about the endian-ness of the target machine and does
18873 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18874 2 (short) and 4 (long) Floating numbers are put out as a series of
18875 LITTLENUMS (shorts, here at least). */
18877 void
18878 md_number_to_chars (char * buf, valueT val, int n)
18880 if (target_big_endian)
18881 number_to_chars_bigendian (buf, val, n);
18882 else
18883 number_to_chars_littleendian (buf, val, n);
18886 static valueT
18887 md_chars_to_number (char * buf, int n)
18889 valueT result = 0;
18890 unsigned char * where = (unsigned char *) buf;
18892 if (target_big_endian)
18894 while (n--)
18896 result <<= 8;
18897 result |= (*where++ & 255);
18900 else
18902 while (n--)
18904 result <<= 8;
18905 result |= (where[n] & 255);
18909 return result;
18912 /* MD interface: Sections. */
18914 /* Estimate the size of a frag before relaxing. Assume everything fits in
18915 2 bytes. */
18918 md_estimate_size_before_relax (fragS * fragp,
18919 segT segtype ATTRIBUTE_UNUSED)
18921 fragp->fr_var = 2;
18922 return 2;
18925 /* Convert a machine dependent frag. */
18927 void
18928 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18930 unsigned long insn;
18931 unsigned long old_op;
18932 char *buf;
18933 expressionS exp;
18934 fixS *fixp;
18935 int reloc_type;
18936 int pc_rel;
18937 int opcode;
18939 buf = fragp->fr_literal + fragp->fr_fix;
18941 old_op = bfd_get_16(abfd, buf);
18942 if (fragp->fr_symbol)
18944 exp.X_op = O_symbol;
18945 exp.X_add_symbol = fragp->fr_symbol;
18947 else
18949 exp.X_op = O_constant;
18951 exp.X_add_number = fragp->fr_offset;
18952 opcode = fragp->fr_subtype;
18953 switch (opcode)
18955 case T_MNEM_ldr_pc:
18956 case T_MNEM_ldr_pc2:
18957 case T_MNEM_ldr_sp:
18958 case T_MNEM_str_sp:
18959 case T_MNEM_ldr:
18960 case T_MNEM_ldrb:
18961 case T_MNEM_ldrh:
18962 case T_MNEM_str:
18963 case T_MNEM_strb:
18964 case T_MNEM_strh:
18965 if (fragp->fr_var == 4)
18967 insn = THUMB_OP32 (opcode);
18968 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18970 insn |= (old_op & 0x700) << 4;
18972 else
18974 insn |= (old_op & 7) << 12;
18975 insn |= (old_op & 0x38) << 13;
18977 insn |= 0x00000c00;
18978 put_thumb32_insn (buf, insn);
18979 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18981 else
18983 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18985 pc_rel = (opcode == T_MNEM_ldr_pc2);
18986 break;
18987 case T_MNEM_adr:
18988 if (fragp->fr_var == 4)
18990 insn = THUMB_OP32 (opcode);
18991 insn |= (old_op & 0xf0) << 4;
18992 put_thumb32_insn (buf, insn);
18993 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18995 else
18997 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18998 exp.X_add_number -= 4;
19000 pc_rel = 1;
19001 break;
19002 case T_MNEM_mov:
19003 case T_MNEM_movs:
19004 case T_MNEM_cmp:
19005 case T_MNEM_cmn:
19006 if (fragp->fr_var == 4)
19008 int r0off = (opcode == T_MNEM_mov
19009 || opcode == T_MNEM_movs) ? 0 : 8;
19010 insn = THUMB_OP32 (opcode);
19011 insn = (insn & 0xe1ffffff) | 0x10000000;
19012 insn |= (old_op & 0x700) << r0off;
19013 put_thumb32_insn (buf, insn);
19014 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19016 else
19018 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
19020 pc_rel = 0;
19021 break;
19022 case T_MNEM_b:
19023 if (fragp->fr_var == 4)
19025 insn = THUMB_OP32(opcode);
19026 put_thumb32_insn (buf, insn);
19027 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
19029 else
19030 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
19031 pc_rel = 1;
19032 break;
19033 case T_MNEM_bcond:
19034 if (fragp->fr_var == 4)
19036 insn = THUMB_OP32(opcode);
19037 insn |= (old_op & 0xf00) << 14;
19038 put_thumb32_insn (buf, insn);
19039 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
19041 else
19042 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
19043 pc_rel = 1;
19044 break;
19045 case T_MNEM_add_sp:
19046 case T_MNEM_add_pc:
19047 case T_MNEM_inc_sp:
19048 case T_MNEM_dec_sp:
19049 if (fragp->fr_var == 4)
19051 /* ??? Choose between add and addw. */
19052 insn = THUMB_OP32 (opcode);
19053 insn |= (old_op & 0xf0) << 4;
19054 put_thumb32_insn (buf, insn);
19055 if (opcode == T_MNEM_add_pc)
19056 reloc_type = BFD_RELOC_ARM_T32_IMM12;
19057 else
19058 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
19060 else
19061 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19062 pc_rel = 0;
19063 break;
19065 case T_MNEM_addi:
19066 case T_MNEM_addis:
19067 case T_MNEM_subi:
19068 case T_MNEM_subis:
19069 if (fragp->fr_var == 4)
19071 insn = THUMB_OP32 (opcode);
19072 insn |= (old_op & 0xf0) << 4;
19073 insn |= (old_op & 0xf) << 16;
19074 put_thumb32_insn (buf, insn);
19075 if (insn & (1 << 20))
19076 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
19077 else
19078 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19080 else
19081 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19082 pc_rel = 0;
19083 break;
19084 default:
19085 abort ();
19087 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
19088 (enum bfd_reloc_code_real) reloc_type);
19089 fixp->fx_file = fragp->fr_file;
19090 fixp->fx_line = fragp->fr_line;
19091 fragp->fr_fix += fragp->fr_var;
19094 /* Return the size of a relaxable immediate operand instruction.
19095 SHIFT and SIZE specify the form of the allowable immediate. */
19096 static int
19097 relax_immediate (fragS *fragp, int size, int shift)
19099 offsetT offset;
19100 offsetT mask;
19101 offsetT low;
19103 /* ??? Should be able to do better than this. */
19104 if (fragp->fr_symbol)
19105 return 4;
19107 low = (1 << shift) - 1;
19108 mask = (1 << (shift + size)) - (1 << shift);
19109 offset = fragp->fr_offset;
19110 /* Force misaligned offsets to 32-bit variant. */
19111 if (offset & low)
19112 return 4;
19113 if (offset & ~mask)
19114 return 4;
19115 return 2;
19118 /* Get the address of a symbol during relaxation. */
19119 static addressT
19120 relaxed_symbol_addr (fragS *fragp, long stretch)
19122 fragS *sym_frag;
19123 addressT addr;
19124 symbolS *sym;
19126 sym = fragp->fr_symbol;
19127 sym_frag = symbol_get_frag (sym);
19128 know (S_GET_SEGMENT (sym) != absolute_section
19129 || sym_frag == &zero_address_frag);
19130 addr = S_GET_VALUE (sym) + fragp->fr_offset;
19132 /* If frag has yet to be reached on this pass, assume it will
19133 move by STRETCH just as we did. If this is not so, it will
19134 be because some frag between grows, and that will force
19135 another pass. */
19137 if (stretch != 0
19138 && sym_frag->relax_marker != fragp->relax_marker)
19140 fragS *f;
19142 /* Adjust stretch for any alignment frag. Note that if have
19143 been expanding the earlier code, the symbol may be
19144 defined in what appears to be an earlier frag. FIXME:
19145 This doesn't handle the fr_subtype field, which specifies
19146 a maximum number of bytes to skip when doing an
19147 alignment. */
19148 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
19150 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
19152 if (stretch < 0)
19153 stretch = - ((- stretch)
19154 & ~ ((1 << (int) f->fr_offset) - 1));
19155 else
19156 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
19157 if (stretch == 0)
19158 break;
19161 if (f != NULL)
19162 addr += stretch;
19165 return addr;
19168 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
19169 load. */
19170 static int
19171 relax_adr (fragS *fragp, asection *sec, long stretch)
19173 addressT addr;
19174 offsetT val;
19176 /* Assume worst case for symbols not known to be in the same section. */
19177 if (fragp->fr_symbol == NULL
19178 || !S_IS_DEFINED (fragp->fr_symbol)
19179 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19180 || S_IS_WEAK (fragp->fr_symbol))
19181 return 4;
19183 val = relaxed_symbol_addr (fragp, stretch);
19184 addr = fragp->fr_address + fragp->fr_fix;
19185 addr = (addr + 4) & ~3;
19186 /* Force misaligned targets to 32-bit variant. */
19187 if (val & 3)
19188 return 4;
19189 val -= addr;
19190 if (val < 0 || val > 1020)
19191 return 4;
19192 return 2;
19195 /* Return the size of a relaxable add/sub immediate instruction. */
19196 static int
19197 relax_addsub (fragS *fragp, asection *sec)
19199 char *buf;
19200 int op;
19202 buf = fragp->fr_literal + fragp->fr_fix;
19203 op = bfd_get_16(sec->owner, buf);
19204 if ((op & 0xf) == ((op >> 4) & 0xf))
19205 return relax_immediate (fragp, 8, 0);
19206 else
19207 return relax_immediate (fragp, 3, 0);
19211 /* Return the size of a relaxable branch instruction. BITS is the
19212 size of the offset field in the narrow instruction. */
19214 static int
19215 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
19217 addressT addr;
19218 offsetT val;
19219 offsetT limit;
19221 /* Assume worst case for symbols not known to be in the same section. */
19222 if (!S_IS_DEFINED (fragp->fr_symbol)
19223 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19224 || S_IS_WEAK (fragp->fr_symbol))
19225 return 4;
19227 #ifdef OBJ_ELF
19228 if (S_IS_DEFINED (fragp->fr_symbol)
19229 && ARM_IS_FUNC (fragp->fr_symbol))
19230 return 4;
19232 /* PR 12532. Global symbols with default visibility might
19233 be preempted, so do not relax relocations to them. */
19234 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
19235 && (! S_IS_LOCAL (fragp->fr_symbol)))
19236 return 4;
19237 #endif
19239 val = relaxed_symbol_addr (fragp, stretch);
19240 addr = fragp->fr_address + fragp->fr_fix + 4;
19241 val -= addr;
19243 /* Offset is a signed value *2 */
19244 limit = 1 << bits;
19245 if (val >= limit || val < -limit)
19246 return 4;
19247 return 2;
19251 /* Relax a machine dependent frag. This returns the amount by which
19252 the current size of the frag should change. */
19255 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
19257 int oldsize;
19258 int newsize;
19260 oldsize = fragp->fr_var;
19261 switch (fragp->fr_subtype)
19263 case T_MNEM_ldr_pc2:
19264 newsize = relax_adr (fragp, sec, stretch);
19265 break;
19266 case T_MNEM_ldr_pc:
19267 case T_MNEM_ldr_sp:
19268 case T_MNEM_str_sp:
19269 newsize = relax_immediate (fragp, 8, 2);
19270 break;
19271 case T_MNEM_ldr:
19272 case T_MNEM_str:
19273 newsize = relax_immediate (fragp, 5, 2);
19274 break;
19275 case T_MNEM_ldrh:
19276 case T_MNEM_strh:
19277 newsize = relax_immediate (fragp, 5, 1);
19278 break;
19279 case T_MNEM_ldrb:
19280 case T_MNEM_strb:
19281 newsize = relax_immediate (fragp, 5, 0);
19282 break;
19283 case T_MNEM_adr:
19284 newsize = relax_adr (fragp, sec, stretch);
19285 break;
19286 case T_MNEM_mov:
19287 case T_MNEM_movs:
19288 case T_MNEM_cmp:
19289 case T_MNEM_cmn:
19290 newsize = relax_immediate (fragp, 8, 0);
19291 break;
19292 case T_MNEM_b:
19293 newsize = relax_branch (fragp, sec, 11, stretch);
19294 break;
19295 case T_MNEM_bcond:
19296 newsize = relax_branch (fragp, sec, 8, stretch);
19297 break;
19298 case T_MNEM_add_sp:
19299 case T_MNEM_add_pc:
19300 newsize = relax_immediate (fragp, 8, 2);
19301 break;
19302 case T_MNEM_inc_sp:
19303 case T_MNEM_dec_sp:
19304 newsize = relax_immediate (fragp, 7, 2);
19305 break;
19306 case T_MNEM_addi:
19307 case T_MNEM_addis:
19308 case T_MNEM_subi:
19309 case T_MNEM_subis:
19310 newsize = relax_addsub (fragp, sec);
19311 break;
19312 default:
19313 abort ();
19316 fragp->fr_var = newsize;
19317 /* Freeze wide instructions that are at or before the same location as
19318 in the previous pass. This avoids infinite loops.
19319 Don't freeze them unconditionally because targets may be artificially
19320 misaligned by the expansion of preceding frags. */
19321 if (stretch <= 0 && newsize > 2)
19323 md_convert_frag (sec->owner, sec, fragp);
19324 frag_wane (fragp);
19327 return newsize - oldsize;
19330 /* Round up a section size to the appropriate boundary. */
19332 valueT
19333 md_section_align (segT segment ATTRIBUTE_UNUSED,
19334 valueT size)
19336 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
19337 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
19339 /* For a.out, force the section size to be aligned. If we don't do
19340 this, BFD will align it for us, but it will not write out the
19341 final bytes of the section. This may be a bug in BFD, but it is
19342 easier to fix it here since that is how the other a.out targets
19343 work. */
19344 int align;
19346 align = bfd_get_section_alignment (stdoutput, segment);
19347 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
19349 #endif
19351 return size;
19354 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
19355 of an rs_align_code fragment. */
19357 void
19358 arm_handle_align (fragS * fragP)
19360 static char const arm_noop[2][2][4] =
19362 { /* ARMv1 */
19363 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
19364 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
19366 { /* ARMv6k */
19367 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
19368 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
19371 static char const thumb_noop[2][2][2] =
19373 { /* Thumb-1 */
19374 {0xc0, 0x46}, /* LE */
19375 {0x46, 0xc0}, /* BE */
19377 { /* Thumb-2 */
19378 {0x00, 0xbf}, /* LE */
19379 {0xbf, 0x00} /* BE */
19382 static char const wide_thumb_noop[2][4] =
19383 { /* Wide Thumb-2 */
19384 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
19385 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
19388 unsigned bytes, fix, noop_size;
19389 char * p;
19390 const char * noop;
19391 const char *narrow_noop = NULL;
19392 #ifdef OBJ_ELF
19393 enum mstate state;
19394 #endif
19396 if (fragP->fr_type != rs_align_code)
19397 return;
19399 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
19400 p = fragP->fr_literal + fragP->fr_fix;
19401 fix = 0;
19403 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
19404 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
19406 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
19408 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
19410 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
19412 narrow_noop = thumb_noop[1][target_big_endian];
19413 noop = wide_thumb_noop[target_big_endian];
19415 else
19416 noop = thumb_noop[0][target_big_endian];
19417 noop_size = 2;
19418 #ifdef OBJ_ELF
19419 state = MAP_THUMB;
19420 #endif
19422 else
19424 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
19425 [target_big_endian];
19426 noop_size = 4;
19427 #ifdef OBJ_ELF
19428 state = MAP_ARM;
19429 #endif
19432 fragP->fr_var = noop_size;
19434 if (bytes & (noop_size - 1))
19436 fix = bytes & (noop_size - 1);
19437 #ifdef OBJ_ELF
19438 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
19439 #endif
19440 memset (p, 0, fix);
19441 p += fix;
19442 bytes -= fix;
19445 if (narrow_noop)
19447 if (bytes & noop_size)
19449 /* Insert a narrow noop. */
19450 memcpy (p, narrow_noop, noop_size);
19451 p += noop_size;
19452 bytes -= noop_size;
19453 fix += noop_size;
19456 /* Use wide noops for the remainder */
19457 noop_size = 4;
19460 while (bytes >= noop_size)
19462 memcpy (p, noop, noop_size);
19463 p += noop_size;
19464 bytes -= noop_size;
19465 fix += noop_size;
19468 fragP->fr_fix += fix;
19471 /* Called from md_do_align. Used to create an alignment
19472 frag in a code section. */
19474 void
19475 arm_frag_align_code (int n, int max)
19477 char * p;
19479 /* We assume that there will never be a requirement
19480 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
19481 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
19483 char err_msg[128];
19485 sprintf (err_msg,
19486 _("alignments greater than %d bytes not supported in .text sections."),
19487 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
19488 as_fatal ("%s", err_msg);
19491 p = frag_var (rs_align_code,
19492 MAX_MEM_FOR_RS_ALIGN_CODE,
19494 (relax_substateT) max,
19495 (symbolS *) NULL,
19496 (offsetT) n,
19497 (char *) NULL);
19498 *p = 0;
19501 /* Perform target specific initialisation of a frag.
19502 Note - despite the name this initialisation is not done when the frag
19503 is created, but only when its type is assigned. A frag can be created
19504 and used a long time before its type is set, so beware of assuming that
19505 this initialisationis performed first. */
19507 #ifndef OBJ_ELF
19508 void
19509 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19511 /* Record whether this frag is in an ARM or a THUMB area. */
19512 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19515 #else /* OBJ_ELF is defined. */
19516 void
19517 arm_init_frag (fragS * fragP, int max_chars)
19519 /* If the current ARM vs THUMB mode has not already
19520 been recorded into this frag then do so now. */
19521 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19523 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19525 /* Record a mapping symbol for alignment frags. We will delete this
19526 later if the alignment ends up empty. */
19527 switch (fragP->fr_type)
19529 case rs_align:
19530 case rs_align_test:
19531 case rs_fill:
19532 mapping_state_2 (MAP_DATA, max_chars);
19533 break;
19534 case rs_align_code:
19535 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19536 break;
19537 default:
19538 break;
19543 /* When we change sections we need to issue a new mapping symbol. */
19545 void
19546 arm_elf_change_section (void)
19548 /* Link an unlinked unwind index table section to the .text section. */
19549 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19550 && elf_linked_to_section (now_seg) == NULL)
19551 elf_linked_to_section (now_seg) = text_section;
19555 arm_elf_section_type (const char * str, size_t len)
19557 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19558 return SHT_ARM_EXIDX;
19560 return -1;
19563 /* Code to deal with unwinding tables. */
19565 static void add_unwind_adjustsp (offsetT);
19567 /* Generate any deferred unwind frame offset. */
19569 static void
19570 flush_pending_unwind (void)
19572 offsetT offset;
19574 offset = unwind.pending_offset;
19575 unwind.pending_offset = 0;
19576 if (offset != 0)
19577 add_unwind_adjustsp (offset);
19580 /* Add an opcode to this list for this function. Two-byte opcodes should
19581 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19582 order. */
19584 static void
19585 add_unwind_opcode (valueT op, int length)
19587 /* Add any deferred stack adjustment. */
19588 if (unwind.pending_offset)
19589 flush_pending_unwind ();
19591 unwind.sp_restored = 0;
19593 if (unwind.opcode_count + length > unwind.opcode_alloc)
19595 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19596 if (unwind.opcodes)
19597 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19598 unwind.opcode_alloc);
19599 else
19600 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
19602 while (length > 0)
19604 length--;
19605 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19606 op >>= 8;
19607 unwind.opcode_count++;
19611 /* Add unwind opcodes to adjust the stack pointer. */
19613 static void
19614 add_unwind_adjustsp (offsetT offset)
19616 valueT op;
19618 if (offset > 0x200)
19620 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19621 char bytes[5];
19622 int n;
19623 valueT o;
19625 /* Long form: 0xb2, uleb128. */
19626 /* This might not fit in a word so add the individual bytes,
19627 remembering the list is built in reverse order. */
19628 o = (valueT) ((offset - 0x204) >> 2);
19629 if (o == 0)
19630 add_unwind_opcode (0, 1);
19632 /* Calculate the uleb128 encoding of the offset. */
19633 n = 0;
19634 while (o)
19636 bytes[n] = o & 0x7f;
19637 o >>= 7;
19638 if (o)
19639 bytes[n] |= 0x80;
19640 n++;
19642 /* Add the insn. */
19643 for (; n; n--)
19644 add_unwind_opcode (bytes[n - 1], 1);
19645 add_unwind_opcode (0xb2, 1);
19647 else if (offset > 0x100)
19649 /* Two short opcodes. */
19650 add_unwind_opcode (0x3f, 1);
19651 op = (offset - 0x104) >> 2;
19652 add_unwind_opcode (op, 1);
19654 else if (offset > 0)
19656 /* Short opcode. */
19657 op = (offset - 4) >> 2;
19658 add_unwind_opcode (op, 1);
19660 else if (offset < 0)
19662 offset = -offset;
19663 while (offset > 0x100)
19665 add_unwind_opcode (0x7f, 1);
19666 offset -= 0x100;
19668 op = ((offset - 4) >> 2) | 0x40;
19669 add_unwind_opcode (op, 1);
19673 /* Finish the list of unwind opcodes for this function. */
19674 static void
19675 finish_unwind_opcodes (void)
19677 valueT op;
19679 if (unwind.fp_used)
19681 /* Adjust sp as necessary. */
19682 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19683 flush_pending_unwind ();
19685 /* After restoring sp from the frame pointer. */
19686 op = 0x90 | unwind.fp_reg;
19687 add_unwind_opcode (op, 1);
19689 else
19690 flush_pending_unwind ();
19694 /* Start an exception table entry. If idx is nonzero this is an index table
19695 entry. */
19697 static void
19698 start_unwind_section (const segT text_seg, int idx)
19700 const char * text_name;
19701 const char * prefix;
19702 const char * prefix_once;
19703 const char * group_name;
19704 size_t prefix_len;
19705 size_t text_len;
19706 char * sec_name;
19707 size_t sec_name_len;
19708 int type;
19709 int flags;
19710 int linkonce;
19712 if (idx)
19714 prefix = ELF_STRING_ARM_unwind;
19715 prefix_once = ELF_STRING_ARM_unwind_once;
19716 type = SHT_ARM_EXIDX;
19718 else
19720 prefix = ELF_STRING_ARM_unwind_info;
19721 prefix_once = ELF_STRING_ARM_unwind_info_once;
19722 type = SHT_PROGBITS;
19725 text_name = segment_name (text_seg);
19726 if (streq (text_name, ".text"))
19727 text_name = "";
19729 if (strncmp (text_name, ".gnu.linkonce.t.",
19730 strlen (".gnu.linkonce.t.")) == 0)
19732 prefix = prefix_once;
19733 text_name += strlen (".gnu.linkonce.t.");
19736 prefix_len = strlen (prefix);
19737 text_len = strlen (text_name);
19738 sec_name_len = prefix_len + text_len;
19739 sec_name = (char *) xmalloc (sec_name_len + 1);
19740 memcpy (sec_name, prefix, prefix_len);
19741 memcpy (sec_name + prefix_len, text_name, text_len);
19742 sec_name[prefix_len + text_len] = '\0';
19744 flags = SHF_ALLOC;
19745 linkonce = 0;
19746 group_name = 0;
19748 /* Handle COMDAT group. */
19749 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
19751 group_name = elf_group_name (text_seg);
19752 if (group_name == NULL)
19754 as_bad (_("Group section `%s' has no group signature"),
19755 segment_name (text_seg));
19756 ignore_rest_of_line ();
19757 return;
19759 flags |= SHF_GROUP;
19760 linkonce = 1;
19763 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
19765 /* Set the section link for index tables. */
19766 if (idx)
19767 elf_linked_to_section (now_seg) = text_seg;
19771 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19772 personality routine data. Returns zero, or the index table value for
19773 and inline entry. */
19775 static valueT
19776 create_unwind_entry (int have_data)
19778 int size;
19779 addressT where;
19780 char *ptr;
19781 /* The current word of data. */
19782 valueT data;
19783 /* The number of bytes left in this word. */
19784 int n;
19786 finish_unwind_opcodes ();
19788 /* Remember the current text section. */
19789 unwind.saved_seg = now_seg;
19790 unwind.saved_subseg = now_subseg;
19792 start_unwind_section (now_seg, 0);
19794 if (unwind.personality_routine == NULL)
19796 if (unwind.personality_index == -2)
19798 if (have_data)
19799 as_bad (_("handlerdata in cantunwind frame"));
19800 return 1; /* EXIDX_CANTUNWIND. */
19803 /* Use a default personality routine if none is specified. */
19804 if (unwind.personality_index == -1)
19806 if (unwind.opcode_count > 3)
19807 unwind.personality_index = 1;
19808 else
19809 unwind.personality_index = 0;
19812 /* Space for the personality routine entry. */
19813 if (unwind.personality_index == 0)
19815 if (unwind.opcode_count > 3)
19816 as_bad (_("too many unwind opcodes for personality routine 0"));
19818 if (!have_data)
19820 /* All the data is inline in the index table. */
19821 data = 0x80;
19822 n = 3;
19823 while (unwind.opcode_count > 0)
19825 unwind.opcode_count--;
19826 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19827 n--;
19830 /* Pad with "finish" opcodes. */
19831 while (n--)
19832 data = (data << 8) | 0xb0;
19834 return data;
19836 size = 0;
19838 else
19839 /* We get two opcodes "free" in the first word. */
19840 size = unwind.opcode_count - 2;
19842 else
19843 /* An extra byte is required for the opcode count. */
19844 size = unwind.opcode_count + 1;
19846 size = (size + 3) >> 2;
19847 if (size > 0xff)
19848 as_bad (_("too many unwind opcodes"));
19850 frag_align (2, 0, 0);
19851 record_alignment (now_seg, 2);
19852 unwind.table_entry = expr_build_dot ();
19854 /* Allocate the table entry. */
19855 ptr = frag_more ((size << 2) + 4);
19856 where = frag_now_fix () - ((size << 2) + 4);
19858 switch (unwind.personality_index)
19860 case -1:
19861 /* ??? Should this be a PLT generating relocation? */
19862 /* Custom personality routine. */
19863 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19864 BFD_RELOC_ARM_PREL31);
19866 where += 4;
19867 ptr += 4;
19869 /* Set the first byte to the number of additional words. */
19870 data = size - 1;
19871 n = 3;
19872 break;
19874 /* ABI defined personality routines. */
19875 case 0:
19876 /* Three opcodes bytes are packed into the first word. */
19877 data = 0x80;
19878 n = 3;
19879 break;
19881 case 1:
19882 case 2:
19883 /* The size and first two opcode bytes go in the first word. */
19884 data = ((0x80 + unwind.personality_index) << 8) | size;
19885 n = 2;
19886 break;
19888 default:
19889 /* Should never happen. */
19890 abort ();
19893 /* Pack the opcodes into words (MSB first), reversing the list at the same
19894 time. */
19895 while (unwind.opcode_count > 0)
19897 if (n == 0)
19899 md_number_to_chars (ptr, data, 4);
19900 ptr += 4;
19901 n = 4;
19902 data = 0;
19904 unwind.opcode_count--;
19905 n--;
19906 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19909 /* Finish off the last word. */
19910 if (n < 4)
19912 /* Pad with "finish" opcodes. */
19913 while (n--)
19914 data = (data << 8) | 0xb0;
19916 md_number_to_chars (ptr, data, 4);
19919 if (!have_data)
19921 /* Add an empty descriptor if there is no user-specified data. */
19922 ptr = frag_more (4);
19923 md_number_to_chars (ptr, 0, 4);
19926 return 0;
19930 /* Initialize the DWARF-2 unwind information for this procedure. */
19932 void
19933 tc_arm_frame_initial_instructions (void)
19935 cfi_add_CFA_def_cfa (REG_SP, 0);
19937 #endif /* OBJ_ELF */
19939 /* Convert REGNAME to a DWARF-2 register number. */
19942 tc_arm_regname_to_dw2regnum (char *regname)
19944 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
19946 if (reg == FAIL)
19947 return -1;
19949 return reg;
19952 #ifdef TE_PE
19953 void
19954 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
19956 expressionS exp;
19958 exp.X_op = O_secrel;
19959 exp.X_add_symbol = symbol;
19960 exp.X_add_number = 0;
19961 emit_expr (&exp, size);
19963 #endif
19965 /* MD interface: Symbol and relocation handling. */
19967 /* Return the address within the segment that a PC-relative fixup is
19968 relative to. For ARM, PC-relative fixups applied to instructions
19969 are generally relative to the location of the fixup plus 8 bytes.
19970 Thumb branches are offset by 4, and Thumb loads relative to PC
19971 require special handling. */
19973 long
19974 md_pcrel_from_section (fixS * fixP, segT seg)
19976 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19978 /* If this is pc-relative and we are going to emit a relocation
19979 then we just want to put out any pipeline compensation that the linker
19980 will need. Otherwise we want to use the calculated base.
19981 For WinCE we skip the bias for externals as well, since this
19982 is how the MS ARM-CE assembler behaves and we want to be compatible. */
19983 if (fixP->fx_pcrel
19984 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19985 || (arm_force_relocation (fixP)
19986 #ifdef TE_WINCE
19987 && !S_IS_EXTERNAL (fixP->fx_addsy)
19988 #endif
19990 base = 0;
19993 switch (fixP->fx_r_type)
19995 /* PC relative addressing on the Thumb is slightly odd as the
19996 bottom two bits of the PC are forced to zero for the
19997 calculation. This happens *after* application of the
19998 pipeline offset. However, Thumb adrl already adjusts for
19999 this, so we need not do it again. */
20000 case BFD_RELOC_ARM_THUMB_ADD:
20001 return base & ~3;
20003 case BFD_RELOC_ARM_THUMB_OFFSET:
20004 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20005 case BFD_RELOC_ARM_T32_ADD_PC12:
20006 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
20007 return (base + 4) & ~3;
20009 /* Thumb branches are simply offset by +4. */
20010 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20011 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20012 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20013 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20014 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20015 return base + 4;
20017 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20018 if (fixP->fx_addsy
20019 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20020 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20021 && ARM_IS_FUNC (fixP->fx_addsy)
20022 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20023 base = fixP->fx_where + fixP->fx_frag->fr_address;
20024 return base + 4;
20026 /* BLX is like branches above, but forces the low two bits of PC to
20027 zero. */
20028 case BFD_RELOC_THUMB_PCREL_BLX:
20029 if (fixP->fx_addsy
20030 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20031 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20032 && THUMB_IS_FUNC (fixP->fx_addsy)
20033 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20034 base = fixP->fx_where + fixP->fx_frag->fr_address;
20035 return (base + 4) & ~3;
20037 /* ARM mode branches are offset by +8. However, the Windows CE
20038 loader expects the relocation not to take this into account. */
20039 case BFD_RELOC_ARM_PCREL_BLX:
20040 if (fixP->fx_addsy
20041 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20042 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20043 && ARM_IS_FUNC (fixP->fx_addsy)
20044 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20045 base = fixP->fx_where + fixP->fx_frag->fr_address;
20046 return base + 8;
20048 case BFD_RELOC_ARM_PCREL_CALL:
20049 if (fixP->fx_addsy
20050 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20051 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20052 && THUMB_IS_FUNC (fixP->fx_addsy)
20053 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20054 base = fixP->fx_where + fixP->fx_frag->fr_address;
20055 return base + 8;
20057 case BFD_RELOC_ARM_PCREL_BRANCH:
20058 case BFD_RELOC_ARM_PCREL_JUMP:
20059 case BFD_RELOC_ARM_PLT32:
20060 #ifdef TE_WINCE
20061 /* When handling fixups immediately, because we have already
20062 discovered the value of a symbol, or the address of the frag involved
20063 we must account for the offset by +8, as the OS loader will never see the reloc.
20064 see fixup_segment() in write.c
20065 The S_IS_EXTERNAL test handles the case of global symbols.
20066 Those need the calculated base, not just the pipe compensation the linker will need. */
20067 if (fixP->fx_pcrel
20068 && fixP->fx_addsy != NULL
20069 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20070 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
20071 return base + 8;
20072 return base;
20073 #else
20074 return base + 8;
20075 #endif
20078 /* ARM mode loads relative to PC are also offset by +8. Unlike
20079 branches, the Windows CE loader *does* expect the relocation
20080 to take this into account. */
20081 case BFD_RELOC_ARM_OFFSET_IMM:
20082 case BFD_RELOC_ARM_OFFSET_IMM8:
20083 case BFD_RELOC_ARM_HWLITERAL:
20084 case BFD_RELOC_ARM_LITERAL:
20085 case BFD_RELOC_ARM_CP_OFF_IMM:
20086 return base + 8;
20089 /* Other PC-relative relocations are un-offset. */
20090 default:
20091 return base;
20095 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
20096 Otherwise we have no need to default values of symbols. */
20098 symbolS *
20099 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
20101 #ifdef OBJ_ELF
20102 if (name[0] == '_' && name[1] == 'G'
20103 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
20105 if (!GOT_symbol)
20107 if (symbol_find (name))
20108 as_bad (_("GOT already in the symbol table"));
20110 GOT_symbol = symbol_new (name, undefined_section,
20111 (valueT) 0, & zero_address_frag);
20114 return GOT_symbol;
20116 #endif
20118 return NULL;
20121 /* Subroutine of md_apply_fix. Check to see if an immediate can be
20122 computed as two separate immediate values, added together. We
20123 already know that this value cannot be computed by just one ARM
20124 instruction. */
20126 static unsigned int
20127 validate_immediate_twopart (unsigned int val,
20128 unsigned int * highpart)
20130 unsigned int a;
20131 unsigned int i;
20133 for (i = 0; i < 32; i += 2)
20134 if (((a = rotate_left (val, i)) & 0xff) != 0)
20136 if (a & 0xff00)
20138 if (a & ~ 0xffff)
20139 continue;
20140 * highpart = (a >> 8) | ((i + 24) << 7);
20142 else if (a & 0xff0000)
20144 if (a & 0xff000000)
20145 continue;
20146 * highpart = (a >> 16) | ((i + 16) << 7);
20148 else
20150 gas_assert (a & 0xff000000);
20151 * highpart = (a >> 24) | ((i + 8) << 7);
20154 return (a & 0xff) | (i << 7);
20157 return FAIL;
20160 static int
20161 validate_offset_imm (unsigned int val, int hwse)
20163 if ((hwse && val > 255) || val > 4095)
20164 return FAIL;
20165 return val;
20168 /* Subroutine of md_apply_fix. Do those data_ops which can take a
20169 negative immediate constant by altering the instruction. A bit of
20170 a hack really.
20171 MOV <-> MVN
20172 AND <-> BIC
20173 ADC <-> SBC
20174 by inverting the second operand, and
20175 ADD <-> SUB
20176 CMP <-> CMN
20177 by negating the second operand. */
20179 static int
20180 negate_data_op (unsigned long * instruction,
20181 unsigned long value)
20183 int op, new_inst;
20184 unsigned long negated, inverted;
20186 negated = encode_arm_immediate (-value);
20187 inverted = encode_arm_immediate (~value);
20189 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
20190 switch (op)
20192 /* First negates. */
20193 case OPCODE_SUB: /* ADD <-> SUB */
20194 new_inst = OPCODE_ADD;
20195 value = negated;
20196 break;
20198 case OPCODE_ADD:
20199 new_inst = OPCODE_SUB;
20200 value = negated;
20201 break;
20203 case OPCODE_CMP: /* CMP <-> CMN */
20204 new_inst = OPCODE_CMN;
20205 value = negated;
20206 break;
20208 case OPCODE_CMN:
20209 new_inst = OPCODE_CMP;
20210 value = negated;
20211 break;
20213 /* Now Inverted ops. */
20214 case OPCODE_MOV: /* MOV <-> MVN */
20215 new_inst = OPCODE_MVN;
20216 value = inverted;
20217 break;
20219 case OPCODE_MVN:
20220 new_inst = OPCODE_MOV;
20221 value = inverted;
20222 break;
20224 case OPCODE_AND: /* AND <-> BIC */
20225 new_inst = OPCODE_BIC;
20226 value = inverted;
20227 break;
20229 case OPCODE_BIC:
20230 new_inst = OPCODE_AND;
20231 value = inverted;
20232 break;
20234 case OPCODE_ADC: /* ADC <-> SBC */
20235 new_inst = OPCODE_SBC;
20236 value = inverted;
20237 break;
20239 case OPCODE_SBC:
20240 new_inst = OPCODE_ADC;
20241 value = inverted;
20242 break;
20244 /* We cannot do anything. */
20245 default:
20246 return FAIL;
20249 if (value == (unsigned) FAIL)
20250 return FAIL;
20252 *instruction &= OPCODE_MASK;
20253 *instruction |= new_inst << DATA_OP_SHIFT;
20254 return value;
20257 /* Like negate_data_op, but for Thumb-2. */
20259 static unsigned int
20260 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
20262 int op, new_inst;
20263 int rd;
20264 unsigned int negated, inverted;
20266 negated = encode_thumb32_immediate (-value);
20267 inverted = encode_thumb32_immediate (~value);
20269 rd = (*instruction >> 8) & 0xf;
20270 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
20271 switch (op)
20273 /* ADD <-> SUB. Includes CMP <-> CMN. */
20274 case T2_OPCODE_SUB:
20275 new_inst = T2_OPCODE_ADD;
20276 value = negated;
20277 break;
20279 case T2_OPCODE_ADD:
20280 new_inst = T2_OPCODE_SUB;
20281 value = negated;
20282 break;
20284 /* ORR <-> ORN. Includes MOV <-> MVN. */
20285 case T2_OPCODE_ORR:
20286 new_inst = T2_OPCODE_ORN;
20287 value = inverted;
20288 break;
20290 case T2_OPCODE_ORN:
20291 new_inst = T2_OPCODE_ORR;
20292 value = inverted;
20293 break;
20295 /* AND <-> BIC. TST has no inverted equivalent. */
20296 case T2_OPCODE_AND:
20297 new_inst = T2_OPCODE_BIC;
20298 if (rd == 15)
20299 value = FAIL;
20300 else
20301 value = inverted;
20302 break;
20304 case T2_OPCODE_BIC:
20305 new_inst = T2_OPCODE_AND;
20306 value = inverted;
20307 break;
20309 /* ADC <-> SBC */
20310 case T2_OPCODE_ADC:
20311 new_inst = T2_OPCODE_SBC;
20312 value = inverted;
20313 break;
20315 case T2_OPCODE_SBC:
20316 new_inst = T2_OPCODE_ADC;
20317 value = inverted;
20318 break;
20320 /* We cannot do anything. */
20321 default:
20322 return FAIL;
20325 if (value == (unsigned int)FAIL)
20326 return FAIL;
20328 *instruction &= T2_OPCODE_MASK;
20329 *instruction |= new_inst << T2_DATA_OP_SHIFT;
20330 return value;
20333 /* Read a 32-bit thumb instruction from buf. */
20334 static unsigned long
20335 get_thumb32_insn (char * buf)
20337 unsigned long insn;
20338 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
20339 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20341 return insn;
20345 /* We usually want to set the low bit on the address of thumb function
20346 symbols. In particular .word foo - . should have the low bit set.
20347 Generic code tries to fold the difference of two symbols to
20348 a constant. Prevent this and force a relocation when the first symbols
20349 is a thumb function. */
20351 bfd_boolean
20352 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
20354 if (op == O_subtract
20355 && l->X_op == O_symbol
20356 && r->X_op == O_symbol
20357 && THUMB_IS_FUNC (l->X_add_symbol))
20359 l->X_op = O_subtract;
20360 l->X_op_symbol = r->X_add_symbol;
20361 l->X_add_number -= r->X_add_number;
20362 return TRUE;
20365 /* Process as normal. */
20366 return FALSE;
20369 /* Encode Thumb2 unconditional branches and calls. The encoding
20370 for the 2 are identical for the immediate values. */
20372 static void
20373 encode_thumb2_b_bl_offset (char * buf, offsetT value)
20375 #define T2I1I2MASK ((1 << 13) | (1 << 11))
20376 offsetT newval;
20377 offsetT newval2;
20378 addressT S, I1, I2, lo, hi;
20380 S = (value >> 24) & 0x01;
20381 I1 = (value >> 23) & 0x01;
20382 I2 = (value >> 22) & 0x01;
20383 hi = (value >> 12) & 0x3ff;
20384 lo = (value >> 1) & 0x7ff;
20385 newval = md_chars_to_number (buf, THUMB_SIZE);
20386 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20387 newval |= (S << 10) | hi;
20388 newval2 &= ~T2I1I2MASK;
20389 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
20390 md_number_to_chars (buf, newval, THUMB_SIZE);
20391 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20394 void
20395 md_apply_fix (fixS * fixP,
20396 valueT * valP,
20397 segT seg)
20399 offsetT value = * valP;
20400 offsetT newval;
20401 unsigned int newimm;
20402 unsigned long temp;
20403 int sign;
20404 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
20406 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
20408 /* Note whether this will delete the relocation. */
20410 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
20411 fixP->fx_done = 1;
20413 /* On a 64-bit host, silently truncate 'value' to 32 bits for
20414 consistency with the behaviour on 32-bit hosts. Remember value
20415 for emit_reloc. */
20416 value &= 0xffffffff;
20417 value ^= 0x80000000;
20418 value -= 0x80000000;
20420 *valP = value;
20421 fixP->fx_addnumber = value;
20423 /* Same treatment for fixP->fx_offset. */
20424 fixP->fx_offset &= 0xffffffff;
20425 fixP->fx_offset ^= 0x80000000;
20426 fixP->fx_offset -= 0x80000000;
20428 switch (fixP->fx_r_type)
20430 case BFD_RELOC_NONE:
20431 /* This will need to go in the object file. */
20432 fixP->fx_done = 0;
20433 break;
20435 case BFD_RELOC_ARM_IMMEDIATE:
20436 /* We claim that this fixup has been processed here,
20437 even if in fact we generate an error because we do
20438 not have a reloc for it, so tc_gen_reloc will reject it. */
20439 fixP->fx_done = 1;
20441 if (fixP->fx_addsy)
20443 const char *msg = 0;
20445 if (! S_IS_DEFINED (fixP->fx_addsy))
20446 msg = _("undefined symbol %s used as an immediate value");
20447 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20448 msg = _("symbol %s is in a different section");
20449 else if (S_IS_WEAK (fixP->fx_addsy))
20450 msg = _("symbol %s is weak and may be overridden later");
20452 if (msg)
20454 as_bad_where (fixP->fx_file, fixP->fx_line,
20455 msg, S_GET_NAME (fixP->fx_addsy));
20456 break;
20460 newimm = encode_arm_immediate (value);
20461 temp = md_chars_to_number (buf, INSN_SIZE);
20463 /* If the instruction will fail, see if we can fix things up by
20464 changing the opcode. */
20465 if (newimm == (unsigned int) FAIL
20466 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
20468 as_bad_where (fixP->fx_file, fixP->fx_line,
20469 _("invalid constant (%lx) after fixup"),
20470 (unsigned long) value);
20471 break;
20474 newimm |= (temp & 0xfffff000);
20475 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20476 break;
20478 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20480 unsigned int highpart = 0;
20481 unsigned int newinsn = 0xe1a00000; /* nop. */
20483 if (fixP->fx_addsy)
20485 const char *msg = 0;
20487 if (! S_IS_DEFINED (fixP->fx_addsy))
20488 msg = _("undefined symbol %s used as an immediate value");
20489 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20490 msg = _("symbol %s is in a different section");
20491 else if (S_IS_WEAK (fixP->fx_addsy))
20492 msg = _("symbol %s is weak and may be overridden later");
20494 if (msg)
20496 as_bad_where (fixP->fx_file, fixP->fx_line,
20497 msg, S_GET_NAME (fixP->fx_addsy));
20498 break;
20502 newimm = encode_arm_immediate (value);
20503 temp = md_chars_to_number (buf, INSN_SIZE);
20505 /* If the instruction will fail, see if we can fix things up by
20506 changing the opcode. */
20507 if (newimm == (unsigned int) FAIL
20508 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20510 /* No ? OK - try using two ADD instructions to generate
20511 the value. */
20512 newimm = validate_immediate_twopart (value, & highpart);
20514 /* Yes - then make sure that the second instruction is
20515 also an add. */
20516 if (newimm != (unsigned int) FAIL)
20517 newinsn = temp;
20518 /* Still No ? Try using a negated value. */
20519 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20520 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20521 /* Otherwise - give up. */
20522 else
20524 as_bad_where (fixP->fx_file, fixP->fx_line,
20525 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20526 (long) value);
20527 break;
20530 /* Replace the first operand in the 2nd instruction (which
20531 is the PC) with the destination register. We have
20532 already added in the PC in the first instruction and we
20533 do not want to do it again. */
20534 newinsn &= ~ 0xf0000;
20535 newinsn |= ((newinsn & 0x0f000) << 4);
20538 newimm |= (temp & 0xfffff000);
20539 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20541 highpart |= (newinsn & 0xfffff000);
20542 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20544 break;
20546 case BFD_RELOC_ARM_OFFSET_IMM:
20547 if (!fixP->fx_done && seg->use_rela_p)
20548 value = 0;
20550 case BFD_RELOC_ARM_LITERAL:
20551 sign = value > 0;
20553 if (value < 0)
20554 value = - value;
20556 if (validate_offset_imm (value, 0) == FAIL)
20558 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20559 as_bad_where (fixP->fx_file, fixP->fx_line,
20560 _("invalid literal constant: pool needs to be closer"));
20561 else
20562 as_bad_where (fixP->fx_file, fixP->fx_line,
20563 _("bad immediate value for offset (%ld)"),
20564 (long) value);
20565 break;
20568 newval = md_chars_to_number (buf, INSN_SIZE);
20569 if (value == 0)
20570 newval &= 0xfffff000;
20571 else
20573 newval &= 0xff7ff000;
20574 newval |= value | (sign ? INDEX_UP : 0);
20576 md_number_to_chars (buf, newval, INSN_SIZE);
20577 break;
20579 case BFD_RELOC_ARM_OFFSET_IMM8:
20580 case BFD_RELOC_ARM_HWLITERAL:
20581 sign = value > 0;
20583 if (value < 0)
20584 value = - value;
20586 if (validate_offset_imm (value, 1) == FAIL)
20588 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20589 as_bad_where (fixP->fx_file, fixP->fx_line,
20590 _("invalid literal constant: pool needs to be closer"));
20591 else
20592 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
20593 (long) value);
20594 break;
20597 newval = md_chars_to_number (buf, INSN_SIZE);
20598 if (value == 0)
20599 newval &= 0xfffff0f0;
20600 else
20602 newval &= 0xff7ff0f0;
20603 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20605 md_number_to_chars (buf, newval, INSN_SIZE);
20606 break;
20608 case BFD_RELOC_ARM_T32_OFFSET_U8:
20609 if (value < 0 || value > 1020 || value % 4 != 0)
20610 as_bad_where (fixP->fx_file, fixP->fx_line,
20611 _("bad immediate value for offset (%ld)"), (long) value);
20612 value /= 4;
20614 newval = md_chars_to_number (buf+2, THUMB_SIZE);
20615 newval |= value;
20616 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20617 break;
20619 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20620 /* This is a complicated relocation used for all varieties of Thumb32
20621 load/store instruction with immediate offset:
20623 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20624 *4, optional writeback(W)
20625 (doubleword load/store)
20627 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20628 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20629 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20630 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20631 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20633 Uppercase letters indicate bits that are already encoded at
20634 this point. Lowercase letters are our problem. For the
20635 second block of instructions, the secondary opcode nybble
20636 (bits 8..11) is present, and bit 23 is zero, even if this is
20637 a PC-relative operation. */
20638 newval = md_chars_to_number (buf, THUMB_SIZE);
20639 newval <<= 16;
20640 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
20642 if ((newval & 0xf0000000) == 0xe0000000)
20644 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20645 if (value >= 0)
20646 newval |= (1 << 23);
20647 else
20648 value = -value;
20649 if (value % 4 != 0)
20651 as_bad_where (fixP->fx_file, fixP->fx_line,
20652 _("offset not a multiple of 4"));
20653 break;
20655 value /= 4;
20656 if (value > 0xff)
20658 as_bad_where (fixP->fx_file, fixP->fx_line,
20659 _("offset out of range"));
20660 break;
20662 newval &= ~0xff;
20664 else if ((newval & 0x000f0000) == 0x000f0000)
20666 /* PC-relative, 12-bit offset. */
20667 if (value >= 0)
20668 newval |= (1 << 23);
20669 else
20670 value = -value;
20671 if (value > 0xfff)
20673 as_bad_where (fixP->fx_file, fixP->fx_line,
20674 _("offset out of range"));
20675 break;
20677 newval &= ~0xfff;
20679 else if ((newval & 0x00000100) == 0x00000100)
20681 /* Writeback: 8-bit, +/- offset. */
20682 if (value >= 0)
20683 newval |= (1 << 9);
20684 else
20685 value = -value;
20686 if (value > 0xff)
20688 as_bad_where (fixP->fx_file, fixP->fx_line,
20689 _("offset out of range"));
20690 break;
20692 newval &= ~0xff;
20694 else if ((newval & 0x00000f00) == 0x00000e00)
20696 /* T-instruction: positive 8-bit offset. */
20697 if (value < 0 || value > 0xff)
20699 as_bad_where (fixP->fx_file, fixP->fx_line,
20700 _("offset out of range"));
20701 break;
20703 newval &= ~0xff;
20704 newval |= value;
20706 else
20708 /* Positive 12-bit or negative 8-bit offset. */
20709 int limit;
20710 if (value >= 0)
20712 newval |= (1 << 23);
20713 limit = 0xfff;
20715 else
20717 value = -value;
20718 limit = 0xff;
20720 if (value > limit)
20722 as_bad_where (fixP->fx_file, fixP->fx_line,
20723 _("offset out of range"));
20724 break;
20726 newval &= ~limit;
20729 newval |= value;
20730 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20731 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20732 break;
20734 case BFD_RELOC_ARM_SHIFT_IMM:
20735 newval = md_chars_to_number (buf, INSN_SIZE);
20736 if (((unsigned long) value) > 32
20737 || (value == 32
20738 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20740 as_bad_where (fixP->fx_file, fixP->fx_line,
20741 _("shift expression is too large"));
20742 break;
20745 if (value == 0)
20746 /* Shifts of zero must be done as lsl. */
20747 newval &= ~0x60;
20748 else if (value == 32)
20749 value = 0;
20750 newval &= 0xfffff07f;
20751 newval |= (value & 0x1f) << 7;
20752 md_number_to_chars (buf, newval, INSN_SIZE);
20753 break;
20755 case BFD_RELOC_ARM_T32_IMMEDIATE:
20756 case BFD_RELOC_ARM_T32_ADD_IMM:
20757 case BFD_RELOC_ARM_T32_IMM12:
20758 case BFD_RELOC_ARM_T32_ADD_PC12:
20759 /* We claim that this fixup has been processed here,
20760 even if in fact we generate an error because we do
20761 not have a reloc for it, so tc_gen_reloc will reject it. */
20762 fixP->fx_done = 1;
20764 if (fixP->fx_addsy
20765 && ! S_IS_DEFINED (fixP->fx_addsy))
20767 as_bad_where (fixP->fx_file, fixP->fx_line,
20768 _("undefined symbol %s used as an immediate value"),
20769 S_GET_NAME (fixP->fx_addsy));
20770 break;
20773 newval = md_chars_to_number (buf, THUMB_SIZE);
20774 newval <<= 16;
20775 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
20777 newimm = FAIL;
20778 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20779 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20781 newimm = encode_thumb32_immediate (value);
20782 if (newimm == (unsigned int) FAIL)
20783 newimm = thumb32_negate_data_op (&newval, value);
20785 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20786 && newimm == (unsigned int) FAIL)
20788 /* Turn add/sum into addw/subw. */
20789 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20790 newval = (newval & 0xfeffffff) | 0x02000000;
20791 /* No flat 12-bit imm encoding for addsw/subsw. */
20792 if ((newval & 0x00100000) == 0)
20794 /* 12 bit immediate for addw/subw. */
20795 if (value < 0)
20797 value = -value;
20798 newval ^= 0x00a00000;
20800 if (value > 0xfff)
20801 newimm = (unsigned int) FAIL;
20802 else
20803 newimm = value;
20807 if (newimm == (unsigned int)FAIL)
20809 as_bad_where (fixP->fx_file, fixP->fx_line,
20810 _("invalid constant (%lx) after fixup"),
20811 (unsigned long) value);
20812 break;
20815 newval |= (newimm & 0x800) << 15;
20816 newval |= (newimm & 0x700) << 4;
20817 newval |= (newimm & 0x0ff);
20819 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20820 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20821 break;
20823 case BFD_RELOC_ARM_SMC:
20824 if (((unsigned long) value) > 0xffff)
20825 as_bad_where (fixP->fx_file, fixP->fx_line,
20826 _("invalid smc expression"));
20827 newval = md_chars_to_number (buf, INSN_SIZE);
20828 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20829 md_number_to_chars (buf, newval, INSN_SIZE);
20830 break;
20832 case BFD_RELOC_ARM_HVC:
20833 if (((unsigned long) value) > 0xffff)
20834 as_bad_where (fixP->fx_file, fixP->fx_line,
20835 _("invalid hvc expression"));
20836 newval = md_chars_to_number (buf, INSN_SIZE);
20837 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20838 md_number_to_chars (buf, newval, INSN_SIZE);
20839 break;
20841 case BFD_RELOC_ARM_SWI:
20842 if (fixP->tc_fix_data != 0)
20844 if (((unsigned long) value) > 0xff)
20845 as_bad_where (fixP->fx_file, fixP->fx_line,
20846 _("invalid swi expression"));
20847 newval = md_chars_to_number (buf, THUMB_SIZE);
20848 newval |= value;
20849 md_number_to_chars (buf, newval, THUMB_SIZE);
20851 else
20853 if (((unsigned long) value) > 0x00ffffff)
20854 as_bad_where (fixP->fx_file, fixP->fx_line,
20855 _("invalid swi expression"));
20856 newval = md_chars_to_number (buf, INSN_SIZE);
20857 newval |= value;
20858 md_number_to_chars (buf, newval, INSN_SIZE);
20860 break;
20862 case BFD_RELOC_ARM_MULTI:
20863 if (((unsigned long) value) > 0xffff)
20864 as_bad_where (fixP->fx_file, fixP->fx_line,
20865 _("invalid expression in load/store multiple"));
20866 newval = value | md_chars_to_number (buf, INSN_SIZE);
20867 md_number_to_chars (buf, newval, INSN_SIZE);
20868 break;
20870 #ifdef OBJ_ELF
20871 case BFD_RELOC_ARM_PCREL_CALL:
20873 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20874 && fixP->fx_addsy
20875 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20876 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20877 && THUMB_IS_FUNC (fixP->fx_addsy))
20878 /* Flip the bl to blx. This is a simple flip
20879 bit here because we generate PCREL_CALL for
20880 unconditional bls. */
20882 newval = md_chars_to_number (buf, INSN_SIZE);
20883 newval = newval | 0x10000000;
20884 md_number_to_chars (buf, newval, INSN_SIZE);
20885 temp = 1;
20886 fixP->fx_done = 1;
20888 else
20889 temp = 3;
20890 goto arm_branch_common;
20892 case BFD_RELOC_ARM_PCREL_JUMP:
20893 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20894 && fixP->fx_addsy
20895 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20896 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20897 && THUMB_IS_FUNC (fixP->fx_addsy))
20899 /* This would map to a bl<cond>, b<cond>,
20900 b<always> to a Thumb function. We
20901 need to force a relocation for this particular
20902 case. */
20903 newval = md_chars_to_number (buf, INSN_SIZE);
20904 fixP->fx_done = 0;
20907 case BFD_RELOC_ARM_PLT32:
20908 #endif
20909 case BFD_RELOC_ARM_PCREL_BRANCH:
20910 temp = 3;
20911 goto arm_branch_common;
20913 case BFD_RELOC_ARM_PCREL_BLX:
20915 temp = 1;
20916 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20917 && fixP->fx_addsy
20918 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20919 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20920 && ARM_IS_FUNC (fixP->fx_addsy))
20922 /* Flip the blx to a bl and warn. */
20923 const char *name = S_GET_NAME (fixP->fx_addsy);
20924 newval = 0xeb000000;
20925 as_warn_where (fixP->fx_file, fixP->fx_line,
20926 _("blx to '%s' an ARM ISA state function changed to bl"),
20927 name);
20928 md_number_to_chars (buf, newval, INSN_SIZE);
20929 temp = 3;
20930 fixP->fx_done = 1;
20933 #ifdef OBJ_ELF
20934 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20935 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20936 #endif
20938 arm_branch_common:
20939 /* We are going to store value (shifted right by two) in the
20940 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20941 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20942 also be be clear. */
20943 if (value & temp)
20944 as_bad_where (fixP->fx_file, fixP->fx_line,
20945 _("misaligned branch destination"));
20946 if ((value & (offsetT)0xfe000000) != (offsetT)0
20947 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20948 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
20950 if (fixP->fx_done || !seg->use_rela_p)
20952 newval = md_chars_to_number (buf, INSN_SIZE);
20953 newval |= (value >> 2) & 0x00ffffff;
20954 /* Set the H bit on BLX instructions. */
20955 if (temp == 1)
20957 if (value & 2)
20958 newval |= 0x01000000;
20959 else
20960 newval &= ~0x01000000;
20962 md_number_to_chars (buf, newval, INSN_SIZE);
20964 break;
20966 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20967 /* CBZ can only branch forward. */
20969 /* Attempts to use CBZ to branch to the next instruction
20970 (which, strictly speaking, are prohibited) will be turned into
20971 no-ops.
20973 FIXME: It may be better to remove the instruction completely and
20974 perform relaxation. */
20975 if (value == -2)
20977 newval = md_chars_to_number (buf, THUMB_SIZE);
20978 newval = 0xbf00; /* NOP encoding T1 */
20979 md_number_to_chars (buf, newval, THUMB_SIZE);
20981 else
20983 if (value & ~0x7e)
20984 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
20986 if (fixP->fx_done || !seg->use_rela_p)
20988 newval = md_chars_to_number (buf, THUMB_SIZE);
20989 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20990 md_number_to_chars (buf, newval, THUMB_SIZE);
20993 break;
20995 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
20996 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20997 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
20999 if (fixP->fx_done || !seg->use_rela_p)
21001 newval = md_chars_to_number (buf, THUMB_SIZE);
21002 newval |= (value & 0x1ff) >> 1;
21003 md_number_to_chars (buf, newval, THUMB_SIZE);
21005 break;
21007 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
21008 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
21009 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21011 if (fixP->fx_done || !seg->use_rela_p)
21013 newval = md_chars_to_number (buf, THUMB_SIZE);
21014 newval |= (value & 0xfff) >> 1;
21015 md_number_to_chars (buf, newval, THUMB_SIZE);
21017 break;
21019 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21020 if (fixP->fx_addsy
21021 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21022 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21023 && ARM_IS_FUNC (fixP->fx_addsy)
21024 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21026 /* Force a relocation for a branch 20 bits wide. */
21027 fixP->fx_done = 0;
21029 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
21030 as_bad_where (fixP->fx_file, fixP->fx_line,
21031 _("conditional branch out of range"));
21033 if (fixP->fx_done || !seg->use_rela_p)
21035 offsetT newval2;
21036 addressT S, J1, J2, lo, hi;
21038 S = (value & 0x00100000) >> 20;
21039 J2 = (value & 0x00080000) >> 19;
21040 J1 = (value & 0x00040000) >> 18;
21041 hi = (value & 0x0003f000) >> 12;
21042 lo = (value & 0x00000ffe) >> 1;
21044 newval = md_chars_to_number (buf, THUMB_SIZE);
21045 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21046 newval |= (S << 10) | hi;
21047 newval2 |= (J1 << 13) | (J2 << 11) | lo;
21048 md_number_to_chars (buf, newval, THUMB_SIZE);
21049 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21051 break;
21053 case BFD_RELOC_THUMB_PCREL_BLX:
21054 /* If there is a blx from a thumb state function to
21055 another thumb function flip this to a bl and warn
21056 about it. */
21058 if (fixP->fx_addsy
21059 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21060 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21061 && THUMB_IS_FUNC (fixP->fx_addsy))
21063 const char *name = S_GET_NAME (fixP->fx_addsy);
21064 as_warn_where (fixP->fx_file, fixP->fx_line,
21065 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
21066 name);
21067 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21068 newval = newval | 0x1000;
21069 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21070 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21071 fixP->fx_done = 1;
21075 goto thumb_bl_common;
21077 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21078 /* A bl from Thumb state ISA to an internal ARM state function
21079 is converted to a blx. */
21080 if (fixP->fx_addsy
21081 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21082 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21083 && ARM_IS_FUNC (fixP->fx_addsy)
21084 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21086 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21087 newval = newval & ~0x1000;
21088 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21089 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
21090 fixP->fx_done = 1;
21093 thumb_bl_common:
21095 #ifdef OBJ_ELF
21096 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
21097 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21098 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21099 #endif
21101 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21102 /* For a BLX instruction, make sure that the relocation is rounded up
21103 to a word boundary. This follows the semantics of the instruction
21104 which specifies that bit 1 of the target address will come from bit
21105 1 of the base address. */
21106 value = (value + 1) & ~ 1;
21108 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
21110 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
21111 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21112 else if ((value & ~0x1ffffff)
21113 && ((value & ~0x1ffffff) != ~0x1ffffff))
21114 as_bad_where (fixP->fx_file, fixP->fx_line,
21115 _("Thumb2 branch out of range"));
21118 if (fixP->fx_done || !seg->use_rela_p)
21119 encode_thumb2_b_bl_offset (buf, value);
21121 break;
21123 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21124 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
21125 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21127 if (fixP->fx_done || !seg->use_rela_p)
21128 encode_thumb2_b_bl_offset (buf, value);
21130 break;
21132 case BFD_RELOC_8:
21133 if (fixP->fx_done || !seg->use_rela_p)
21134 md_number_to_chars (buf, value, 1);
21135 break;
21137 case BFD_RELOC_16:
21138 if (fixP->fx_done || !seg->use_rela_p)
21139 md_number_to_chars (buf, value, 2);
21140 break;
21142 #ifdef OBJ_ELF
21143 case BFD_RELOC_ARM_TLS_CALL:
21144 case BFD_RELOC_ARM_THM_TLS_CALL:
21145 case BFD_RELOC_ARM_TLS_DESCSEQ:
21146 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
21147 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21148 break;
21150 case BFD_RELOC_ARM_TLS_GOTDESC:
21151 case BFD_RELOC_ARM_TLS_GD32:
21152 case BFD_RELOC_ARM_TLS_LE32:
21153 case BFD_RELOC_ARM_TLS_IE32:
21154 case BFD_RELOC_ARM_TLS_LDM32:
21155 case BFD_RELOC_ARM_TLS_LDO32:
21156 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21157 /* fall through */
21159 case BFD_RELOC_ARM_GOT32:
21160 case BFD_RELOC_ARM_GOTOFF:
21161 if (fixP->fx_done || !seg->use_rela_p)
21162 md_number_to_chars (buf, 0, 4);
21163 break;
21165 case BFD_RELOC_ARM_GOT_PREL:
21166 if (fixP->fx_done || !seg->use_rela_p)
21167 md_number_to_chars (buf, value, 4);
21168 break;
21170 case BFD_RELOC_ARM_TARGET2:
21171 /* TARGET2 is not partial-inplace, so we need to write the
21172 addend here for REL targets, because it won't be written out
21173 during reloc processing later. */
21174 if (fixP->fx_done || !seg->use_rela_p)
21175 md_number_to_chars (buf, fixP->fx_offset, 4);
21176 break;
21177 #endif
21179 case BFD_RELOC_RVA:
21180 case BFD_RELOC_32:
21181 case BFD_RELOC_ARM_TARGET1:
21182 case BFD_RELOC_ARM_ROSEGREL32:
21183 case BFD_RELOC_ARM_SBREL32:
21184 case BFD_RELOC_32_PCREL:
21185 #ifdef TE_PE
21186 case BFD_RELOC_32_SECREL:
21187 #endif
21188 if (fixP->fx_done || !seg->use_rela_p)
21189 #ifdef TE_WINCE
21190 /* For WinCE we only do this for pcrel fixups. */
21191 if (fixP->fx_done || fixP->fx_pcrel)
21192 #endif
21193 md_number_to_chars (buf, value, 4);
21194 break;
21196 #ifdef OBJ_ELF
21197 case BFD_RELOC_ARM_PREL31:
21198 if (fixP->fx_done || !seg->use_rela_p)
21200 newval = md_chars_to_number (buf, 4) & 0x80000000;
21201 if ((value ^ (value >> 1)) & 0x40000000)
21203 as_bad_where (fixP->fx_file, fixP->fx_line,
21204 _("rel31 relocation overflow"));
21206 newval |= value & 0x7fffffff;
21207 md_number_to_chars (buf, newval, 4);
21209 break;
21210 #endif
21212 case BFD_RELOC_ARM_CP_OFF_IMM:
21213 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
21214 if (value < -1023 || value > 1023 || (value & 3))
21215 as_bad_where (fixP->fx_file, fixP->fx_line,
21216 _("co-processor offset out of range"));
21217 cp_off_common:
21218 sign = value > 0;
21219 if (value < 0)
21220 value = -value;
21221 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21222 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21223 newval = md_chars_to_number (buf, INSN_SIZE);
21224 else
21225 newval = get_thumb32_insn (buf);
21226 if (value == 0)
21227 newval &= 0xffffff00;
21228 else
21230 newval &= 0xff7fff00;
21231 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
21233 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21234 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21235 md_number_to_chars (buf, newval, INSN_SIZE);
21236 else
21237 put_thumb32_insn (buf, newval);
21238 break;
21240 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
21241 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
21242 if (value < -255 || value > 255)
21243 as_bad_where (fixP->fx_file, fixP->fx_line,
21244 _("co-processor offset out of range"));
21245 value *= 4;
21246 goto cp_off_common;
21248 case BFD_RELOC_ARM_THUMB_OFFSET:
21249 newval = md_chars_to_number (buf, THUMB_SIZE);
21250 /* Exactly what ranges, and where the offset is inserted depends
21251 on the type of instruction, we can establish this from the
21252 top 4 bits. */
21253 switch (newval >> 12)
21255 case 4: /* PC load. */
21256 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
21257 forced to zero for these loads; md_pcrel_from has already
21258 compensated for this. */
21259 if (value & 3)
21260 as_bad_where (fixP->fx_file, fixP->fx_line,
21261 _("invalid offset, target not word aligned (0x%08lX)"),
21262 (((unsigned long) fixP->fx_frag->fr_address
21263 + (unsigned long) fixP->fx_where) & ~3)
21264 + (unsigned long) value);
21266 if (value & ~0x3fc)
21267 as_bad_where (fixP->fx_file, fixP->fx_line,
21268 _("invalid offset, value too big (0x%08lX)"),
21269 (long) value);
21271 newval |= value >> 2;
21272 break;
21274 case 9: /* SP load/store. */
21275 if (value & ~0x3fc)
21276 as_bad_where (fixP->fx_file, fixP->fx_line,
21277 _("invalid offset, value too big (0x%08lX)"),
21278 (long) value);
21279 newval |= value >> 2;
21280 break;
21282 case 6: /* Word load/store. */
21283 if (value & ~0x7c)
21284 as_bad_where (fixP->fx_file, fixP->fx_line,
21285 _("invalid offset, value too big (0x%08lX)"),
21286 (long) value);
21287 newval |= value << 4; /* 6 - 2. */
21288 break;
21290 case 7: /* Byte load/store. */
21291 if (value & ~0x1f)
21292 as_bad_where (fixP->fx_file, fixP->fx_line,
21293 _("invalid offset, value too big (0x%08lX)"),
21294 (long) value);
21295 newval |= value << 6;
21296 break;
21298 case 8: /* Halfword load/store. */
21299 if (value & ~0x3e)
21300 as_bad_where (fixP->fx_file, fixP->fx_line,
21301 _("invalid offset, value too big (0x%08lX)"),
21302 (long) value);
21303 newval |= value << 5; /* 6 - 1. */
21304 break;
21306 default:
21307 as_bad_where (fixP->fx_file, fixP->fx_line,
21308 "Unable to process relocation for thumb opcode: %lx",
21309 (unsigned long) newval);
21310 break;
21312 md_number_to_chars (buf, newval, THUMB_SIZE);
21313 break;
21315 case BFD_RELOC_ARM_THUMB_ADD:
21316 /* This is a complicated relocation, since we use it for all of
21317 the following immediate relocations:
21319 3bit ADD/SUB
21320 8bit ADD/SUB
21321 9bit ADD/SUB SP word-aligned
21322 10bit ADD PC/SP word-aligned
21324 The type of instruction being processed is encoded in the
21325 instruction field:
21327 0x8000 SUB
21328 0x00F0 Rd
21329 0x000F Rs
21331 newval = md_chars_to_number (buf, THUMB_SIZE);
21333 int rd = (newval >> 4) & 0xf;
21334 int rs = newval & 0xf;
21335 int subtract = !!(newval & 0x8000);
21337 /* Check for HI regs, only very restricted cases allowed:
21338 Adjusting SP, and using PC or SP to get an address. */
21339 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
21340 || (rs > 7 && rs != REG_SP && rs != REG_PC))
21341 as_bad_where (fixP->fx_file, fixP->fx_line,
21342 _("invalid Hi register with immediate"));
21344 /* If value is negative, choose the opposite instruction. */
21345 if (value < 0)
21347 value = -value;
21348 subtract = !subtract;
21349 if (value < 0)
21350 as_bad_where (fixP->fx_file, fixP->fx_line,
21351 _("immediate value out of range"));
21354 if (rd == REG_SP)
21356 if (value & ~0x1fc)
21357 as_bad_where (fixP->fx_file, fixP->fx_line,
21358 _("invalid immediate for stack address calculation"));
21359 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
21360 newval |= value >> 2;
21362 else if (rs == REG_PC || rs == REG_SP)
21364 if (subtract || value & ~0x3fc)
21365 as_bad_where (fixP->fx_file, fixP->fx_line,
21366 _("invalid immediate for address calculation (value = 0x%08lX)"),
21367 (unsigned long) value);
21368 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
21369 newval |= rd << 8;
21370 newval |= value >> 2;
21372 else if (rs == rd)
21374 if (value & ~0xff)
21375 as_bad_where (fixP->fx_file, fixP->fx_line,
21376 _("immediate value out of range"));
21377 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
21378 newval |= (rd << 8) | value;
21380 else
21382 if (value & ~0x7)
21383 as_bad_where (fixP->fx_file, fixP->fx_line,
21384 _("immediate value out of range"));
21385 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
21386 newval |= rd | (rs << 3) | (value << 6);
21389 md_number_to_chars (buf, newval, THUMB_SIZE);
21390 break;
21392 case BFD_RELOC_ARM_THUMB_IMM:
21393 newval = md_chars_to_number (buf, THUMB_SIZE);
21394 if (value < 0 || value > 255)
21395 as_bad_where (fixP->fx_file, fixP->fx_line,
21396 _("invalid immediate: %ld is out of range"),
21397 (long) value);
21398 newval |= value;
21399 md_number_to_chars (buf, newval, THUMB_SIZE);
21400 break;
21402 case BFD_RELOC_ARM_THUMB_SHIFT:
21403 /* 5bit shift value (0..32). LSL cannot take 32. */
21404 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
21405 temp = newval & 0xf800;
21406 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
21407 as_bad_where (fixP->fx_file, fixP->fx_line,
21408 _("invalid shift value: %ld"), (long) value);
21409 /* Shifts of zero must be encoded as LSL. */
21410 if (value == 0)
21411 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
21412 /* Shifts of 32 are encoded as zero. */
21413 else if (value == 32)
21414 value = 0;
21415 newval |= value << 6;
21416 md_number_to_chars (buf, newval, THUMB_SIZE);
21417 break;
21419 case BFD_RELOC_VTABLE_INHERIT:
21420 case BFD_RELOC_VTABLE_ENTRY:
21421 fixP->fx_done = 0;
21422 return;
21424 case BFD_RELOC_ARM_MOVW:
21425 case BFD_RELOC_ARM_MOVT:
21426 case BFD_RELOC_ARM_THUMB_MOVW:
21427 case BFD_RELOC_ARM_THUMB_MOVT:
21428 if (fixP->fx_done || !seg->use_rela_p)
21430 /* REL format relocations are limited to a 16-bit addend. */
21431 if (!fixP->fx_done)
21433 if (value < -0x8000 || value > 0x7fff)
21434 as_bad_where (fixP->fx_file, fixP->fx_line,
21435 _("offset out of range"));
21437 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21438 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21440 value >>= 16;
21443 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21444 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21446 newval = get_thumb32_insn (buf);
21447 newval &= 0xfbf08f00;
21448 newval |= (value & 0xf000) << 4;
21449 newval |= (value & 0x0800) << 15;
21450 newval |= (value & 0x0700) << 4;
21451 newval |= (value & 0x00ff);
21452 put_thumb32_insn (buf, newval);
21454 else
21456 newval = md_chars_to_number (buf, 4);
21457 newval &= 0xfff0f000;
21458 newval |= value & 0x0fff;
21459 newval |= (value & 0xf000) << 4;
21460 md_number_to_chars (buf, newval, 4);
21463 return;
21465 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21466 case BFD_RELOC_ARM_ALU_PC_G0:
21467 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21468 case BFD_RELOC_ARM_ALU_PC_G1:
21469 case BFD_RELOC_ARM_ALU_PC_G2:
21470 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21471 case BFD_RELOC_ARM_ALU_SB_G0:
21472 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21473 case BFD_RELOC_ARM_ALU_SB_G1:
21474 case BFD_RELOC_ARM_ALU_SB_G2:
21475 gas_assert (!fixP->fx_done);
21476 if (!seg->use_rela_p)
21478 bfd_vma insn;
21479 bfd_vma encoded_addend;
21480 bfd_vma addend_abs = abs (value);
21482 /* Check that the absolute value of the addend can be
21483 expressed as an 8-bit constant plus a rotation. */
21484 encoded_addend = encode_arm_immediate (addend_abs);
21485 if (encoded_addend == (unsigned int) FAIL)
21486 as_bad_where (fixP->fx_file, fixP->fx_line,
21487 _("the offset 0x%08lX is not representable"),
21488 (unsigned long) addend_abs);
21490 /* Extract the instruction. */
21491 insn = md_chars_to_number (buf, INSN_SIZE);
21493 /* If the addend is positive, use an ADD instruction.
21494 Otherwise use a SUB. Take care not to destroy the S bit. */
21495 insn &= 0xff1fffff;
21496 if (value < 0)
21497 insn |= 1 << 22;
21498 else
21499 insn |= 1 << 23;
21501 /* Place the encoded addend into the first 12 bits of the
21502 instruction. */
21503 insn &= 0xfffff000;
21504 insn |= encoded_addend;
21506 /* Update the instruction. */
21507 md_number_to_chars (buf, insn, INSN_SIZE);
21509 break;
21511 case BFD_RELOC_ARM_LDR_PC_G0:
21512 case BFD_RELOC_ARM_LDR_PC_G1:
21513 case BFD_RELOC_ARM_LDR_PC_G2:
21514 case BFD_RELOC_ARM_LDR_SB_G0:
21515 case BFD_RELOC_ARM_LDR_SB_G1:
21516 case BFD_RELOC_ARM_LDR_SB_G2:
21517 gas_assert (!fixP->fx_done);
21518 if (!seg->use_rela_p)
21520 bfd_vma insn;
21521 bfd_vma addend_abs = abs (value);
21523 /* Check that the absolute value of the addend can be
21524 encoded in 12 bits. */
21525 if (addend_abs >= 0x1000)
21526 as_bad_where (fixP->fx_file, fixP->fx_line,
21527 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
21528 (unsigned long) addend_abs);
21530 /* Extract the instruction. */
21531 insn = md_chars_to_number (buf, INSN_SIZE);
21533 /* If the addend is negative, clear bit 23 of the instruction.
21534 Otherwise set it. */
21535 if (value < 0)
21536 insn &= ~(1 << 23);
21537 else
21538 insn |= 1 << 23;
21540 /* Place the absolute value of the addend into the first 12 bits
21541 of the instruction. */
21542 insn &= 0xfffff000;
21543 insn |= addend_abs;
21545 /* Update the instruction. */
21546 md_number_to_chars (buf, insn, INSN_SIZE);
21548 break;
21550 case BFD_RELOC_ARM_LDRS_PC_G0:
21551 case BFD_RELOC_ARM_LDRS_PC_G1:
21552 case BFD_RELOC_ARM_LDRS_PC_G2:
21553 case BFD_RELOC_ARM_LDRS_SB_G0:
21554 case BFD_RELOC_ARM_LDRS_SB_G1:
21555 case BFD_RELOC_ARM_LDRS_SB_G2:
21556 gas_assert (!fixP->fx_done);
21557 if (!seg->use_rela_p)
21559 bfd_vma insn;
21560 bfd_vma addend_abs = abs (value);
21562 /* Check that the absolute value of the addend can be
21563 encoded in 8 bits. */
21564 if (addend_abs >= 0x100)
21565 as_bad_where (fixP->fx_file, fixP->fx_line,
21566 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
21567 (unsigned long) addend_abs);
21569 /* Extract the instruction. */
21570 insn = md_chars_to_number (buf, INSN_SIZE);
21572 /* If the addend is negative, clear bit 23 of the instruction.
21573 Otherwise set it. */
21574 if (value < 0)
21575 insn &= ~(1 << 23);
21576 else
21577 insn |= 1 << 23;
21579 /* Place the first four bits of the absolute value of the addend
21580 into the first 4 bits of the instruction, and the remaining
21581 four into bits 8 .. 11. */
21582 insn &= 0xfffff0f0;
21583 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
21585 /* Update the instruction. */
21586 md_number_to_chars (buf, insn, INSN_SIZE);
21588 break;
21590 case BFD_RELOC_ARM_LDC_PC_G0:
21591 case BFD_RELOC_ARM_LDC_PC_G1:
21592 case BFD_RELOC_ARM_LDC_PC_G2:
21593 case BFD_RELOC_ARM_LDC_SB_G0:
21594 case BFD_RELOC_ARM_LDC_SB_G1:
21595 case BFD_RELOC_ARM_LDC_SB_G2:
21596 gas_assert (!fixP->fx_done);
21597 if (!seg->use_rela_p)
21599 bfd_vma insn;
21600 bfd_vma addend_abs = abs (value);
21602 /* Check that the absolute value of the addend is a multiple of
21603 four and, when divided by four, fits in 8 bits. */
21604 if (addend_abs & 0x3)
21605 as_bad_where (fixP->fx_file, fixP->fx_line,
21606 _("bad offset 0x%08lX (must be word-aligned)"),
21607 (unsigned long) addend_abs);
21609 if ((addend_abs >> 2) > 0xff)
21610 as_bad_where (fixP->fx_file, fixP->fx_line,
21611 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
21612 (unsigned long) addend_abs);
21614 /* Extract the instruction. */
21615 insn = md_chars_to_number (buf, INSN_SIZE);
21617 /* If the addend is negative, clear bit 23 of the instruction.
21618 Otherwise set it. */
21619 if (value < 0)
21620 insn &= ~(1 << 23);
21621 else
21622 insn |= 1 << 23;
21624 /* Place the addend (divided by four) into the first eight
21625 bits of the instruction. */
21626 insn &= 0xfffffff0;
21627 insn |= addend_abs >> 2;
21629 /* Update the instruction. */
21630 md_number_to_chars (buf, insn, INSN_SIZE);
21632 break;
21634 case BFD_RELOC_ARM_V4BX:
21635 /* This will need to go in the object file. */
21636 fixP->fx_done = 0;
21637 break;
21639 case BFD_RELOC_UNUSED:
21640 default:
21641 as_bad_where (fixP->fx_file, fixP->fx_line,
21642 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21646 /* Translate internal representation of relocation info to BFD target
21647 format. */
21649 arelent *
21650 tc_gen_reloc (asection *section, fixS *fixp)
21652 arelent * reloc;
21653 bfd_reloc_code_real_type code;
21655 reloc = (arelent *) xmalloc (sizeof (arelent));
21657 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
21658 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21659 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
21661 if (fixp->fx_pcrel)
21663 if (section->use_rela_p)
21664 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21665 else
21666 fixp->fx_offset = reloc->address;
21668 reloc->addend = fixp->fx_offset;
21670 switch (fixp->fx_r_type)
21672 case BFD_RELOC_8:
21673 if (fixp->fx_pcrel)
21675 code = BFD_RELOC_8_PCREL;
21676 break;
21679 case BFD_RELOC_16:
21680 if (fixp->fx_pcrel)
21682 code = BFD_RELOC_16_PCREL;
21683 break;
21686 case BFD_RELOC_32:
21687 if (fixp->fx_pcrel)
21689 code = BFD_RELOC_32_PCREL;
21690 break;
21693 case BFD_RELOC_ARM_MOVW:
21694 if (fixp->fx_pcrel)
21696 code = BFD_RELOC_ARM_MOVW_PCREL;
21697 break;
21700 case BFD_RELOC_ARM_MOVT:
21701 if (fixp->fx_pcrel)
21703 code = BFD_RELOC_ARM_MOVT_PCREL;
21704 break;
21707 case BFD_RELOC_ARM_THUMB_MOVW:
21708 if (fixp->fx_pcrel)
21710 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21711 break;
21714 case BFD_RELOC_ARM_THUMB_MOVT:
21715 if (fixp->fx_pcrel)
21717 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21718 break;
21721 case BFD_RELOC_NONE:
21722 case BFD_RELOC_ARM_PCREL_BRANCH:
21723 case BFD_RELOC_ARM_PCREL_BLX:
21724 case BFD_RELOC_RVA:
21725 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21726 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21727 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21728 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21729 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21730 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21731 case BFD_RELOC_VTABLE_ENTRY:
21732 case BFD_RELOC_VTABLE_INHERIT:
21733 #ifdef TE_PE
21734 case BFD_RELOC_32_SECREL:
21735 #endif
21736 code = fixp->fx_r_type;
21737 break;
21739 case BFD_RELOC_THUMB_PCREL_BLX:
21740 #ifdef OBJ_ELF
21741 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21742 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21743 else
21744 #endif
21745 code = BFD_RELOC_THUMB_PCREL_BLX;
21746 break;
21748 case BFD_RELOC_ARM_LITERAL:
21749 case BFD_RELOC_ARM_HWLITERAL:
21750 /* If this is called then the a literal has
21751 been referenced across a section boundary. */
21752 as_bad_where (fixp->fx_file, fixp->fx_line,
21753 _("literal referenced across section boundary"));
21754 return NULL;
21756 #ifdef OBJ_ELF
21757 case BFD_RELOC_ARM_TLS_CALL:
21758 case BFD_RELOC_ARM_THM_TLS_CALL:
21759 case BFD_RELOC_ARM_TLS_DESCSEQ:
21760 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
21761 case BFD_RELOC_ARM_GOT32:
21762 case BFD_RELOC_ARM_GOTOFF:
21763 case BFD_RELOC_ARM_GOT_PREL:
21764 case BFD_RELOC_ARM_PLT32:
21765 case BFD_RELOC_ARM_TARGET1:
21766 case BFD_RELOC_ARM_ROSEGREL32:
21767 case BFD_RELOC_ARM_SBREL32:
21768 case BFD_RELOC_ARM_PREL31:
21769 case BFD_RELOC_ARM_TARGET2:
21770 case BFD_RELOC_ARM_TLS_LE32:
21771 case BFD_RELOC_ARM_TLS_LDO32:
21772 case BFD_RELOC_ARM_PCREL_CALL:
21773 case BFD_RELOC_ARM_PCREL_JUMP:
21774 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21775 case BFD_RELOC_ARM_ALU_PC_G0:
21776 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21777 case BFD_RELOC_ARM_ALU_PC_G1:
21778 case BFD_RELOC_ARM_ALU_PC_G2:
21779 case BFD_RELOC_ARM_LDR_PC_G0:
21780 case BFD_RELOC_ARM_LDR_PC_G1:
21781 case BFD_RELOC_ARM_LDR_PC_G2:
21782 case BFD_RELOC_ARM_LDRS_PC_G0:
21783 case BFD_RELOC_ARM_LDRS_PC_G1:
21784 case BFD_RELOC_ARM_LDRS_PC_G2:
21785 case BFD_RELOC_ARM_LDC_PC_G0:
21786 case BFD_RELOC_ARM_LDC_PC_G1:
21787 case BFD_RELOC_ARM_LDC_PC_G2:
21788 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21789 case BFD_RELOC_ARM_ALU_SB_G0:
21790 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21791 case BFD_RELOC_ARM_ALU_SB_G1:
21792 case BFD_RELOC_ARM_ALU_SB_G2:
21793 case BFD_RELOC_ARM_LDR_SB_G0:
21794 case BFD_RELOC_ARM_LDR_SB_G1:
21795 case BFD_RELOC_ARM_LDR_SB_G2:
21796 case BFD_RELOC_ARM_LDRS_SB_G0:
21797 case BFD_RELOC_ARM_LDRS_SB_G1:
21798 case BFD_RELOC_ARM_LDRS_SB_G2:
21799 case BFD_RELOC_ARM_LDC_SB_G0:
21800 case BFD_RELOC_ARM_LDC_SB_G1:
21801 case BFD_RELOC_ARM_LDC_SB_G2:
21802 case BFD_RELOC_ARM_V4BX:
21803 code = fixp->fx_r_type;
21804 break;
21806 case BFD_RELOC_ARM_TLS_GOTDESC:
21807 case BFD_RELOC_ARM_TLS_GD32:
21808 case BFD_RELOC_ARM_TLS_IE32:
21809 case BFD_RELOC_ARM_TLS_LDM32:
21810 /* BFD will include the symbol's address in the addend.
21811 But we don't want that, so subtract it out again here. */
21812 if (!S_IS_COMMON (fixp->fx_addsy))
21813 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21814 code = fixp->fx_r_type;
21815 break;
21816 #endif
21818 case BFD_RELOC_ARM_IMMEDIATE:
21819 as_bad_where (fixp->fx_file, fixp->fx_line,
21820 _("internal relocation (type: IMMEDIATE) not fixed up"));
21821 return NULL;
21823 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21824 as_bad_where (fixp->fx_file, fixp->fx_line,
21825 _("ADRL used for a symbol not defined in the same file"));
21826 return NULL;
21828 case BFD_RELOC_ARM_OFFSET_IMM:
21829 if (section->use_rela_p)
21831 code = fixp->fx_r_type;
21832 break;
21835 if (fixp->fx_addsy != NULL
21836 && !S_IS_DEFINED (fixp->fx_addsy)
21837 && S_IS_LOCAL (fixp->fx_addsy))
21839 as_bad_where (fixp->fx_file, fixp->fx_line,
21840 _("undefined local label `%s'"),
21841 S_GET_NAME (fixp->fx_addsy));
21842 return NULL;
21845 as_bad_where (fixp->fx_file, fixp->fx_line,
21846 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21847 return NULL;
21849 default:
21851 char * type;
21853 switch (fixp->fx_r_type)
21855 case BFD_RELOC_NONE: type = "NONE"; break;
21856 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21857 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
21858 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
21859 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21860 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21861 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
21862 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
21863 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
21864 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21865 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21866 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21867 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21868 default: type = _("<unknown>"); break;
21870 as_bad_where (fixp->fx_file, fixp->fx_line,
21871 _("cannot represent %s relocation in this object file format"),
21872 type);
21873 return NULL;
21877 #ifdef OBJ_ELF
21878 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21879 && GOT_symbol
21880 && fixp->fx_addsy == GOT_symbol)
21882 code = BFD_RELOC_ARM_GOTPC;
21883 reloc->addend = fixp->fx_offset = reloc->address;
21885 #endif
21887 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
21889 if (reloc->howto == NULL)
21891 as_bad_where (fixp->fx_file, fixp->fx_line,
21892 _("cannot represent %s relocation in this object file format"),
21893 bfd_get_reloc_code_name (code));
21894 return NULL;
21897 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21898 vtable entry to be used in the relocation's section offset. */
21899 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21900 reloc->address = fixp->fx_offset;
21902 return reloc;
21905 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
21907 void
21908 cons_fix_new_arm (fragS * frag,
21909 int where,
21910 int size,
21911 expressionS * exp)
21913 bfd_reloc_code_real_type type;
21914 int pcrel = 0;
21916 /* Pick a reloc.
21917 FIXME: @@ Should look at CPU word size. */
21918 switch (size)
21920 case 1:
21921 type = BFD_RELOC_8;
21922 break;
21923 case 2:
21924 type = BFD_RELOC_16;
21925 break;
21926 case 4:
21927 default:
21928 type = BFD_RELOC_32;
21929 break;
21930 case 8:
21931 type = BFD_RELOC_64;
21932 break;
21935 #ifdef TE_PE
21936 if (exp->X_op == O_secrel)
21938 exp->X_op = O_symbol;
21939 type = BFD_RELOC_32_SECREL;
21941 #endif
21943 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21946 #if defined (OBJ_COFF)
21947 void
21948 arm_validate_fix (fixS * fixP)
21950 /* If the destination of the branch is a defined symbol which does not have
21951 the THUMB_FUNC attribute, then we must be calling a function which has
21952 the (interfacearm) attribute. We look for the Thumb entry point to that
21953 function and change the branch to refer to that function instead. */
21954 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21955 && fixP->fx_addsy != NULL
21956 && S_IS_DEFINED (fixP->fx_addsy)
21957 && ! THUMB_IS_FUNC (fixP->fx_addsy))
21959 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
21962 #endif
21966 arm_force_relocation (struct fix * fixp)
21968 #if defined (OBJ_COFF) && defined (TE_PE)
21969 if (fixp->fx_r_type == BFD_RELOC_RVA)
21970 return 1;
21971 #endif
21973 /* In case we have a call or a branch to a function in ARM ISA mode from
21974 a thumb function or vice-versa force the relocation. These relocations
21975 are cleared off for some cores that might have blx and simple transformations
21976 are possible. */
21978 #ifdef OBJ_ELF
21979 switch (fixp->fx_r_type)
21981 case BFD_RELOC_ARM_PCREL_JUMP:
21982 case BFD_RELOC_ARM_PCREL_CALL:
21983 case BFD_RELOC_THUMB_PCREL_BLX:
21984 if (THUMB_IS_FUNC (fixp->fx_addsy))
21985 return 1;
21986 break;
21988 case BFD_RELOC_ARM_PCREL_BLX:
21989 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21990 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21991 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21992 if (ARM_IS_FUNC (fixp->fx_addsy))
21993 return 1;
21994 break;
21996 default:
21997 break;
21999 #endif
22001 /* Resolve these relocations even if the symbol is extern or weak.
22002 Technically this is probably wrong due to symbol preemption.
22003 In practice these relocations do not have enough range to be useful
22004 at dynamic link time, and some code (e.g. in the Linux kernel)
22005 expects these references to be resolved. */
22006 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
22007 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
22008 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
22009 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
22010 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22011 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
22012 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
22013 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
22014 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22015 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
22016 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
22017 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
22018 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
22019 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
22020 return 0;
22022 /* Always leave these relocations for the linker. */
22023 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22024 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22025 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22026 return 1;
22028 /* Always generate relocations against function symbols. */
22029 if (fixp->fx_r_type == BFD_RELOC_32
22030 && fixp->fx_addsy
22031 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
22032 return 1;
22034 return generic_force_reloc (fixp);
22037 #if defined (OBJ_ELF) || defined (OBJ_COFF)
22038 /* Relocations against function names must be left unadjusted,
22039 so that the linker can use this information to generate interworking
22040 stubs. The MIPS version of this function
22041 also prevents relocations that are mips-16 specific, but I do not
22042 know why it does this.
22044 FIXME:
22045 There is one other problem that ought to be addressed here, but
22046 which currently is not: Taking the address of a label (rather
22047 than a function) and then later jumping to that address. Such
22048 addresses also ought to have their bottom bit set (assuming that
22049 they reside in Thumb code), but at the moment they will not. */
22051 bfd_boolean
22052 arm_fix_adjustable (fixS * fixP)
22054 if (fixP->fx_addsy == NULL)
22055 return 1;
22057 /* Preserve relocations against symbols with function type. */
22058 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
22059 return FALSE;
22061 if (THUMB_IS_FUNC (fixP->fx_addsy)
22062 && fixP->fx_subsy == NULL)
22063 return FALSE;
22065 /* We need the symbol name for the VTABLE entries. */
22066 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
22067 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
22068 return FALSE;
22070 /* Don't allow symbols to be discarded on GOT related relocs. */
22071 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
22072 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
22073 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
22074 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
22075 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
22076 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
22077 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
22078 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
22079 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
22080 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
22081 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
22082 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
22083 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
22084 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
22085 return FALSE;
22087 /* Similarly for group relocations. */
22088 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22089 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22090 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22091 return FALSE;
22093 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
22094 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
22095 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22096 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
22097 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
22098 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22099 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
22100 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
22101 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
22102 return FALSE;
22104 return TRUE;
22106 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
22108 #ifdef OBJ_ELF
22110 const char *
22111 elf32_arm_target_format (void)
22113 #ifdef TE_SYMBIAN
22114 return (target_big_endian
22115 ? "elf32-bigarm-symbian"
22116 : "elf32-littlearm-symbian");
22117 #elif defined (TE_VXWORKS)
22118 return (target_big_endian
22119 ? "elf32-bigarm-vxworks"
22120 : "elf32-littlearm-vxworks");
22121 #else
22122 if (target_big_endian)
22123 return "elf32-bigarm";
22124 else
22125 return "elf32-littlearm";
22126 #endif
22129 void
22130 armelf_frob_symbol (symbolS * symp,
22131 int * puntp)
22133 elf_frob_symbol (symp, puntp);
22135 #endif
22137 /* MD interface: Finalization. */
22139 void
22140 arm_cleanup (void)
22142 literal_pool * pool;
22144 /* Ensure that all the IT blocks are properly closed. */
22145 check_it_blocks_finished ();
22147 for (pool = list_of_pools; pool; pool = pool->next)
22149 /* Put it at the end of the relevant section. */
22150 subseg_set (pool->section, pool->sub_section);
22151 #ifdef OBJ_ELF
22152 arm_elf_change_section ();
22153 #endif
22154 s_ltorg (0);
22158 #ifdef OBJ_ELF
22159 /* Remove any excess mapping symbols generated for alignment frags in
22160 SEC. We may have created a mapping symbol before a zero byte
22161 alignment; remove it if there's a mapping symbol after the
22162 alignment. */
22163 static void
22164 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
22165 void *dummy ATTRIBUTE_UNUSED)
22167 segment_info_type *seginfo = seg_info (sec);
22168 fragS *fragp;
22170 if (seginfo == NULL || seginfo->frchainP == NULL)
22171 return;
22173 for (fragp = seginfo->frchainP->frch_root;
22174 fragp != NULL;
22175 fragp = fragp->fr_next)
22177 symbolS *sym = fragp->tc_frag_data.last_map;
22178 fragS *next = fragp->fr_next;
22180 /* Variable-sized frags have been converted to fixed size by
22181 this point. But if this was variable-sized to start with,
22182 there will be a fixed-size frag after it. So don't handle
22183 next == NULL. */
22184 if (sym == NULL || next == NULL)
22185 continue;
22187 if (S_GET_VALUE (sym) < next->fr_address)
22188 /* Not at the end of this frag. */
22189 continue;
22190 know (S_GET_VALUE (sym) == next->fr_address);
22194 if (next->tc_frag_data.first_map != NULL)
22196 /* Next frag starts with a mapping symbol. Discard this
22197 one. */
22198 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22199 break;
22202 if (next->fr_next == NULL)
22204 /* This mapping symbol is at the end of the section. Discard
22205 it. */
22206 know (next->fr_fix == 0 && next->fr_var == 0);
22207 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22208 break;
22211 /* As long as we have empty frags without any mapping symbols,
22212 keep looking. */
22213 /* If the next frag is non-empty and does not start with a
22214 mapping symbol, then this mapping symbol is required. */
22215 if (next->fr_address != next->fr_next->fr_address)
22216 break;
22218 next = next->fr_next;
22220 while (next != NULL);
22223 #endif
22225 /* Adjust the symbol table. This marks Thumb symbols as distinct from
22226 ARM ones. */
22228 void
22229 arm_adjust_symtab (void)
22231 #ifdef OBJ_COFF
22232 symbolS * sym;
22234 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22236 if (ARM_IS_THUMB (sym))
22238 if (THUMB_IS_FUNC (sym))
22240 /* Mark the symbol as a Thumb function. */
22241 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
22242 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
22243 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
22245 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
22246 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
22247 else
22248 as_bad (_("%s: unexpected function type: %d"),
22249 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
22251 else switch (S_GET_STORAGE_CLASS (sym))
22253 case C_EXT:
22254 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
22255 break;
22256 case C_STAT:
22257 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
22258 break;
22259 case C_LABEL:
22260 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
22261 break;
22262 default:
22263 /* Do nothing. */
22264 break;
22268 if (ARM_IS_INTERWORK (sym))
22269 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
22271 #endif
22272 #ifdef OBJ_ELF
22273 symbolS * sym;
22274 char bind;
22276 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22278 if (ARM_IS_THUMB (sym))
22280 elf_symbol_type * elf_sym;
22282 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
22283 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
22285 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
22286 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
22288 /* If it's a .thumb_func, declare it as so,
22289 otherwise tag label as .code 16. */
22290 if (THUMB_IS_FUNC (sym))
22291 elf_sym->internal_elf_sym.st_target_internal
22292 = ST_BRANCH_TO_THUMB;
22293 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22294 elf_sym->internal_elf_sym.st_info =
22295 ELF_ST_INFO (bind, STT_ARM_16BIT);
22300 /* Remove any overlapping mapping symbols generated by alignment frags. */
22301 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
22302 /* Now do generic ELF adjustments. */
22303 elf_adjust_symtab ();
22304 #endif
22307 /* MD interface: Initialization. */
22309 static void
22310 set_constant_flonums (void)
22312 int i;
22314 for (i = 0; i < NUM_FLOAT_VALS; i++)
22315 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
22316 abort ();
22319 /* Auto-select Thumb mode if it's the only available instruction set for the
22320 given architecture. */
22322 static void
22323 autoselect_thumb_from_cpu_variant (void)
22325 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
22326 opcode_select (16);
22329 void
22330 md_begin (void)
22332 unsigned mach;
22333 unsigned int i;
22335 if ( (arm_ops_hsh = hash_new ()) == NULL
22336 || (arm_cond_hsh = hash_new ()) == NULL
22337 || (arm_shift_hsh = hash_new ()) == NULL
22338 || (arm_psr_hsh = hash_new ()) == NULL
22339 || (arm_v7m_psr_hsh = hash_new ()) == NULL
22340 || (arm_reg_hsh = hash_new ()) == NULL
22341 || (arm_reloc_hsh = hash_new ()) == NULL
22342 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
22343 as_fatal (_("virtual memory exhausted"));
22345 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
22346 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
22347 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
22348 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
22349 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
22350 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
22351 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
22352 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
22353 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
22354 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
22355 (void *) (v7m_psrs + i));
22356 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
22357 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
22358 for (i = 0;
22359 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
22360 i++)
22361 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
22362 (void *) (barrier_opt_names + i));
22363 #ifdef OBJ_ELF
22364 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
22365 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
22366 #endif
22368 set_constant_flonums ();
22370 /* Set the cpu variant based on the command-line options. We prefer
22371 -mcpu= over -march= if both are set (as for GCC); and we prefer
22372 -mfpu= over any other way of setting the floating point unit.
22373 Use of legacy options with new options are faulted. */
22374 if (legacy_cpu)
22376 if (mcpu_cpu_opt || march_cpu_opt)
22377 as_bad (_("use of old and new-style options to set CPU type"));
22379 mcpu_cpu_opt = legacy_cpu;
22381 else if (!mcpu_cpu_opt)
22382 mcpu_cpu_opt = march_cpu_opt;
22384 if (legacy_fpu)
22386 if (mfpu_opt)
22387 as_bad (_("use of old and new-style options to set FPU type"));
22389 mfpu_opt = legacy_fpu;
22391 else if (!mfpu_opt)
22393 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
22394 || defined (TE_NetBSD) || defined (TE_VXWORKS))
22395 /* Some environments specify a default FPU. If they don't, infer it
22396 from the processor. */
22397 if (mcpu_fpu_opt)
22398 mfpu_opt = mcpu_fpu_opt;
22399 else
22400 mfpu_opt = march_fpu_opt;
22401 #else
22402 mfpu_opt = &fpu_default;
22403 #endif
22406 if (!mfpu_opt)
22408 if (mcpu_cpu_opt != NULL)
22409 mfpu_opt = &fpu_default;
22410 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
22411 mfpu_opt = &fpu_arch_vfp_v2;
22412 else
22413 mfpu_opt = &fpu_arch_fpa;
22416 #ifdef CPU_DEFAULT
22417 if (!mcpu_cpu_opt)
22419 mcpu_cpu_opt = &cpu_default;
22420 selected_cpu = cpu_default;
22422 #else
22423 if (mcpu_cpu_opt)
22424 selected_cpu = *mcpu_cpu_opt;
22425 else
22426 mcpu_cpu_opt = &arm_arch_any;
22427 #endif
22429 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22431 autoselect_thumb_from_cpu_variant ();
22433 arm_arch_used = thumb_arch_used = arm_arch_none;
22435 #if defined OBJ_COFF || defined OBJ_ELF
22437 unsigned int flags = 0;
22439 #if defined OBJ_ELF
22440 flags = meabi_flags;
22442 switch (meabi_flags)
22444 case EF_ARM_EABI_UNKNOWN:
22445 #endif
22446 /* Set the flags in the private structure. */
22447 if (uses_apcs_26) flags |= F_APCS26;
22448 if (support_interwork) flags |= F_INTERWORK;
22449 if (uses_apcs_float) flags |= F_APCS_FLOAT;
22450 if (pic_code) flags |= F_PIC;
22451 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
22452 flags |= F_SOFT_FLOAT;
22454 switch (mfloat_abi_opt)
22456 case ARM_FLOAT_ABI_SOFT:
22457 case ARM_FLOAT_ABI_SOFTFP:
22458 flags |= F_SOFT_FLOAT;
22459 break;
22461 case ARM_FLOAT_ABI_HARD:
22462 if (flags & F_SOFT_FLOAT)
22463 as_bad (_("hard-float conflicts with specified fpu"));
22464 break;
22467 /* Using pure-endian doubles (even if soft-float). */
22468 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
22469 flags |= F_VFP_FLOAT;
22471 #if defined OBJ_ELF
22472 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
22473 flags |= EF_ARM_MAVERICK_FLOAT;
22474 break;
22476 case EF_ARM_EABI_VER4:
22477 case EF_ARM_EABI_VER5:
22478 /* No additional flags to set. */
22479 break;
22481 default:
22482 abort ();
22484 #endif
22485 bfd_set_private_flags (stdoutput, flags);
22487 /* We have run out flags in the COFF header to encode the
22488 status of ATPCS support, so instead we create a dummy,
22489 empty, debug section called .arm.atpcs. */
22490 if (atpcs)
22492 asection * sec;
22494 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22496 if (sec != NULL)
22498 bfd_set_section_flags
22499 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22500 bfd_set_section_size (stdoutput, sec, 0);
22501 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22505 #endif
22507 /* Record the CPU type as well. */
22508 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22509 mach = bfd_mach_arm_iWMMXt2;
22510 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
22511 mach = bfd_mach_arm_iWMMXt;
22512 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
22513 mach = bfd_mach_arm_XScale;
22514 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
22515 mach = bfd_mach_arm_ep9312;
22516 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
22517 mach = bfd_mach_arm_5TE;
22518 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
22520 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
22521 mach = bfd_mach_arm_5T;
22522 else
22523 mach = bfd_mach_arm_5;
22525 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
22527 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
22528 mach = bfd_mach_arm_4T;
22529 else
22530 mach = bfd_mach_arm_4;
22532 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
22533 mach = bfd_mach_arm_3M;
22534 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22535 mach = bfd_mach_arm_3;
22536 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22537 mach = bfd_mach_arm_2a;
22538 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22539 mach = bfd_mach_arm_2;
22540 else
22541 mach = bfd_mach_arm_unknown;
22543 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22546 /* Command line processing. */
22548 /* md_parse_option
22549 Invocation line includes a switch not recognized by the base assembler.
22550 See if it's a processor-specific option.
22552 This routine is somewhat complicated by the need for backwards
22553 compatibility (since older releases of gcc can't be changed).
22554 The new options try to make the interface as compatible as
22555 possible with GCC.
22557 New options (supported) are:
22559 -mcpu=<cpu name> Assemble for selected processor
22560 -march=<architecture name> Assemble for selected architecture
22561 -mfpu=<fpu architecture> Assemble for selected FPU.
22562 -EB/-mbig-endian Big-endian
22563 -EL/-mlittle-endian Little-endian
22564 -k Generate PIC code
22565 -mthumb Start in Thumb mode
22566 -mthumb-interwork Code supports ARM/Thumb interworking
22568 -m[no-]warn-deprecated Warn about deprecated features
22570 For now we will also provide support for:
22572 -mapcs-32 32-bit Program counter
22573 -mapcs-26 26-bit Program counter
22574 -macps-float Floats passed in FP registers
22575 -mapcs-reentrant Reentrant code
22576 -matpcs
22577 (sometime these will probably be replaced with -mapcs=<list of options>
22578 and -matpcs=<list of options>)
22580 The remaining options are only supported for back-wards compatibility.
22581 Cpu variants, the arm part is optional:
22582 -m[arm]1 Currently not supported.
22583 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22584 -m[arm]3 Arm 3 processor
22585 -m[arm]6[xx], Arm 6 processors
22586 -m[arm]7[xx][t][[d]m] Arm 7 processors
22587 -m[arm]8[10] Arm 8 processors
22588 -m[arm]9[20][tdmi] Arm 9 processors
22589 -mstrongarm[110[0]] StrongARM processors
22590 -mxscale XScale processors
22591 -m[arm]v[2345[t[e]]] Arm architectures
22592 -mall All (except the ARM1)
22593 FP variants:
22594 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22595 -mfpe-old (No float load/store multiples)
22596 -mvfpxd VFP Single precision
22597 -mvfp All VFP
22598 -mno-fpu Disable all floating point instructions
22600 The following CPU names are recognized:
22601 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22602 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22603 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22604 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22605 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22606 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22607 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
22611 const char * md_shortopts = "m:k";
22613 #ifdef ARM_BI_ENDIAN
22614 #define OPTION_EB (OPTION_MD_BASE + 0)
22615 #define OPTION_EL (OPTION_MD_BASE + 1)
22616 #else
22617 #if TARGET_BYTES_BIG_ENDIAN
22618 #define OPTION_EB (OPTION_MD_BASE + 0)
22619 #else
22620 #define OPTION_EL (OPTION_MD_BASE + 1)
22621 #endif
22622 #endif
22623 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
22625 struct option md_longopts[] =
22627 #ifdef OPTION_EB
22628 {"EB", no_argument, NULL, OPTION_EB},
22629 #endif
22630 #ifdef OPTION_EL
22631 {"EL", no_argument, NULL, OPTION_EL},
22632 #endif
22633 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
22634 {NULL, no_argument, NULL, 0}
22637 size_t md_longopts_size = sizeof (md_longopts);
22639 struct arm_option_table
22641 char *option; /* Option name to match. */
22642 char *help; /* Help information. */
22643 int *var; /* Variable to change. */
22644 int value; /* What to change it to. */
22645 char *deprecated; /* If non-null, print this message. */
22648 struct arm_option_table arm_opts[] =
22650 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22651 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22652 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22653 &support_interwork, 1, NULL},
22654 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22655 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22656 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22657 1, NULL},
22658 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22659 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22660 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22661 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22662 NULL},
22664 /* These are recognized by the assembler, but have no affect on code. */
22665 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22666 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
22668 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22669 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22670 &warn_on_deprecated, 0, NULL},
22671 {NULL, NULL, NULL, 0, NULL}
22674 struct arm_legacy_option_table
22676 char *option; /* Option name to match. */
22677 const arm_feature_set **var; /* Variable to change. */
22678 const arm_feature_set value; /* What to change it to. */
22679 char *deprecated; /* If non-null, print this message. */
22682 const struct arm_legacy_option_table arm_legacy_opts[] =
22684 /* DON'T add any new processors to this list -- we want the whole list
22685 to go away... Add them to the processors table instead. */
22686 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22687 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22688 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22689 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22690 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22691 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22692 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22693 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22694 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22695 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22696 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22697 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22698 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22699 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22700 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22701 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22702 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22703 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22704 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22705 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22706 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22707 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22708 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22709 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22710 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22711 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22712 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22713 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22714 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22715 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22716 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22717 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22718 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22719 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22720 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22721 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22722 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22723 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22724 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22725 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22726 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22727 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22728 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22729 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22730 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22731 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22732 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22733 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22734 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22735 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22736 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22737 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22738 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22739 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22740 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22741 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22742 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22743 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22744 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22745 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22746 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22747 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22748 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22749 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22750 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22751 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22752 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22753 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22754 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22755 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
22756 N_("use -mcpu=strongarm110")},
22757 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
22758 N_("use -mcpu=strongarm1100")},
22759 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
22760 N_("use -mcpu=strongarm1110")},
22761 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22762 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22763 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
22765 /* Architecture variants -- don't add any more to this list either. */
22766 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22767 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22768 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22769 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22770 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22771 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22772 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22773 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22774 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22775 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22776 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22777 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22778 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22779 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22780 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22781 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22782 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22783 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22785 /* Floating point variants -- don't add any more to this list either. */
22786 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22787 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22788 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22789 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
22790 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
22792 {NULL, NULL, ARM_ARCH_NONE, NULL}
22795 struct arm_cpu_option_table
22797 char *name;
22798 const arm_feature_set value;
22799 /* For some CPUs we assume an FPU unless the user explicitly sets
22800 -mfpu=... */
22801 const arm_feature_set default_fpu;
22802 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22803 case. */
22804 const char *canonical_name;
22807 /* This list should, at a minimum, contain all the cpu names
22808 recognized by GCC. */
22809 static const struct arm_cpu_option_table arm_cpus[] =
22811 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22812 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22813 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22814 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22815 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22816 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22817 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22818 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22819 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22820 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22821 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22822 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22823 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22824 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22825 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22826 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22827 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22828 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22829 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22830 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22831 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22832 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22833 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22834 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22835 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22836 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22837 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22838 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22839 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22840 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22841 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22842 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22843 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22844 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22845 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22846 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22847 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22848 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22849 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22850 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22851 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22852 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22853 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22854 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22855 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22856 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22857 /* For V5 or later processors we default to using VFP; but the user
22858 should really set the FPU type explicitly. */
22859 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22860 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22861 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22862 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22863 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22864 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22865 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22866 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22867 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22868 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22869 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22870 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22871 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22872 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22873 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22874 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22875 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22876 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22877 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22878 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22879 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22880 {"fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22881 {"fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22882 {"fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22883 {"fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22884 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22885 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22886 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22887 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22888 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
22889 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"},
22890 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"},
22891 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22892 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22893 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22894 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
22895 {"cortex-a5", ARM_ARCH_V7A_MP_SEC,
22896 FPU_NONE, "Cortex-A5"},
22897 {"cortex-a8", ARM_ARCH_V7A_SEC,
22898 ARM_FEATURE (0, FPU_VFP_V3
22899 | FPU_NEON_EXT_V1),
22900 "Cortex-A8"},
22901 {"cortex-a9", ARM_ARCH_V7A_MP_SEC,
22902 ARM_FEATURE (0, FPU_VFP_V3
22903 | FPU_NEON_EXT_V1),
22904 "Cortex-A9"},
22905 {"cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
22906 FPU_ARCH_NEON_VFP_V4,
22907 "Cortex-A15"},
22908 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"},
22909 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
22910 "Cortex-R4F"},
22911 {"cortex-r5", ARM_ARCH_V7R_IDIV,
22912 FPU_NONE, "Cortex-R5"},
22913 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"},
22914 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"},
22915 {"cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"},
22916 {"cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"},
22917 /* ??? XSCALE is really an architecture. */
22918 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22919 /* ??? iwmmxt is not a processor. */
22920 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
22921 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
22922 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22923 /* Maverick */
22924 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
22925 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
22928 struct arm_arch_option_table
22930 char *name;
22931 const arm_feature_set value;
22932 const arm_feature_set default_fpu;
22935 /* This list should, at a minimum, contain all the architecture names
22936 recognized by GCC. */
22937 static const struct arm_arch_option_table arm_archs[] =
22939 {"all", ARM_ANY, FPU_ARCH_FPA},
22940 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22941 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22942 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22943 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22944 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22945 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22946 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22947 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22948 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22949 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22950 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22951 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22952 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22953 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22954 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22955 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22956 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22957 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22958 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22959 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22960 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22961 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22962 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22963 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22964 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
22965 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
22966 {"armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP},
22967 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
22968 /* The official spelling of the ARMv7 profile variants is the dashed form.
22969 Accept the non-dashed form for compatibility with old toolchains. */
22970 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22971 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22972 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22973 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22974 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22975 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22976 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
22977 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22978 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
22979 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
22980 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
22983 /* ISA extensions in the co-processor and main instruction set space. */
22984 struct arm_option_extension_value_table
22986 char *name;
22987 const arm_feature_set value;
22988 const arm_feature_set allowed_archs;
22991 /* The following table must be in alphabetical order with a NULL last entry.
22993 static const struct arm_option_extension_value_table arm_extensions[] =
22995 {"idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
22996 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)},
22997 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY},
22998 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY},
22999 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY},
23000 {"mp", ARM_FEATURE (ARM_EXT_MP, 0),
23001 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)},
23002 {"os", ARM_FEATURE (ARM_EXT_OS, 0),
23003 ARM_FEATURE (ARM_EXT_V6M, 0)},
23004 {"sec", ARM_FEATURE (ARM_EXT_SEC, 0),
23005 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)},
23006 {"virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV | ARM_EXT_DIV, 0),
23007 ARM_FEATURE (ARM_EXT_V7A, 0)},
23008 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY},
23009 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
23012 /* ISA floating-point and Advanced SIMD extensions. */
23013 struct arm_option_fpu_value_table
23015 char *name;
23016 const arm_feature_set value;
23019 /* This list should, at a minimum, contain all the fpu names
23020 recognized by GCC. */
23021 static const struct arm_option_fpu_value_table arm_fpus[] =
23023 {"softfpa", FPU_NONE},
23024 {"fpe", FPU_ARCH_FPE},
23025 {"fpe2", FPU_ARCH_FPE},
23026 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
23027 {"fpa", FPU_ARCH_FPA},
23028 {"fpa10", FPU_ARCH_FPA},
23029 {"fpa11", FPU_ARCH_FPA},
23030 {"arm7500fe", FPU_ARCH_FPA},
23031 {"softvfp", FPU_ARCH_VFP},
23032 {"softvfp+vfp", FPU_ARCH_VFP_V2},
23033 {"vfp", FPU_ARCH_VFP_V2},
23034 {"vfp9", FPU_ARCH_VFP_V2},
23035 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
23036 {"vfp10", FPU_ARCH_VFP_V2},
23037 {"vfp10-r0", FPU_ARCH_VFP_V1},
23038 {"vfpxd", FPU_ARCH_VFP_V1xD},
23039 {"vfpv2", FPU_ARCH_VFP_V2},
23040 {"vfpv3", FPU_ARCH_VFP_V3},
23041 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
23042 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
23043 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
23044 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
23045 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
23046 {"arm1020t", FPU_ARCH_VFP_V1},
23047 {"arm1020e", FPU_ARCH_VFP_V2},
23048 {"arm1136jfs", FPU_ARCH_VFP_V2},
23049 {"arm1136jf-s", FPU_ARCH_VFP_V2},
23050 {"maverick", FPU_ARCH_MAVERICK},
23051 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
23052 {"neon-fp16", FPU_ARCH_NEON_FP16},
23053 {"vfpv4", FPU_ARCH_VFP_V4},
23054 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
23055 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
23056 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
23057 {NULL, ARM_ARCH_NONE}
23060 struct arm_option_value_table
23062 char *name;
23063 long value;
23066 static const struct arm_option_value_table arm_float_abis[] =
23068 {"hard", ARM_FLOAT_ABI_HARD},
23069 {"softfp", ARM_FLOAT_ABI_SOFTFP},
23070 {"soft", ARM_FLOAT_ABI_SOFT},
23071 {NULL, 0}
23074 #ifdef OBJ_ELF
23075 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
23076 static const struct arm_option_value_table arm_eabis[] =
23078 {"gnu", EF_ARM_EABI_UNKNOWN},
23079 {"4", EF_ARM_EABI_VER4},
23080 {"5", EF_ARM_EABI_VER5},
23081 {NULL, 0}
23083 #endif
23085 struct arm_long_option_table
23087 char * option; /* Substring to match. */
23088 char * help; /* Help information. */
23089 int (* func) (char * subopt); /* Function to decode sub-option. */
23090 char * deprecated; /* If non-null, print this message. */
23093 static bfd_boolean
23094 arm_parse_extension (char * str, const arm_feature_set **opt_p)
23096 arm_feature_set *ext_set = (arm_feature_set *)
23097 xmalloc (sizeof (arm_feature_set));
23099 /* We insist on extensions being specified in alphabetical order, and with
23100 extensions being added before being removed. We achieve this by having
23101 the global ARM_EXTENSIONS table in alphabetical order, and using the
23102 ADDING_VALUE variable to indicate whether we are adding an extension (1)
23103 or removing it (0) and only allowing it to change in the order
23104 -1 -> 1 -> 0. */
23105 const struct arm_option_extension_value_table * opt = NULL;
23106 int adding_value = -1;
23108 /* Copy the feature set, so that we can modify it. */
23109 *ext_set = **opt_p;
23110 *opt_p = ext_set;
23112 while (str != NULL && *str != 0)
23114 char * ext;
23115 size_t optlen;
23117 if (*str != '+')
23119 as_bad (_("invalid architectural extension"));
23120 return FALSE;
23123 str++;
23124 ext = strchr (str, '+');
23126 if (ext != NULL)
23127 optlen = ext - str;
23128 else
23129 optlen = strlen (str);
23131 if (optlen >= 2
23132 && strncmp (str, "no", 2) == 0)
23134 if (adding_value != 0)
23136 adding_value = 0;
23137 opt = arm_extensions;
23140 optlen -= 2;
23141 str += 2;
23143 else if (optlen > 0)
23145 if (adding_value == -1)
23147 adding_value = 1;
23148 opt = arm_extensions;
23150 else if (adding_value != 1)
23152 as_bad (_("must specify extensions to add before specifying "
23153 "those to remove"));
23154 return FALSE;
23158 if (optlen == 0)
23160 as_bad (_("missing architectural extension"));
23161 return FALSE;
23164 gas_assert (adding_value != -1);
23165 gas_assert (opt != NULL);
23167 /* Scan over the options table trying to find an exact match. */
23168 for (; opt->name != NULL; opt++)
23169 if (strncmp (opt->name, str, optlen) == 0
23170 && strlen (opt->name) == optlen)
23172 /* Check we can apply the extension to this architecture. */
23173 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
23175 as_bad (_("extension does not apply to the base architecture"));
23176 return FALSE;
23179 /* Add or remove the extension. */
23180 if (adding_value)
23181 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
23182 else
23183 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
23185 break;
23188 if (opt->name == NULL)
23190 /* Did we fail to find an extension because it wasn't specified in
23191 alphabetical order, or because it does not exist? */
23193 for (opt = arm_extensions; opt->name != NULL; opt++)
23194 if (strncmp (opt->name, str, optlen) == 0)
23195 break;
23197 if (opt->name == NULL)
23198 as_bad (_("unknown architectural extension `%s'"), str);
23199 else
23200 as_bad (_("architectural extensions must be specified in "
23201 "alphabetical order"));
23203 return FALSE;
23205 else
23207 /* We should skip the extension we've just matched the next time
23208 round. */
23209 opt++;
23212 str = ext;
23215 return TRUE;
23218 static bfd_boolean
23219 arm_parse_cpu (char * str)
23221 const struct arm_cpu_option_table * opt;
23222 char * ext = strchr (str, '+');
23223 int optlen;
23225 if (ext != NULL)
23226 optlen = ext - str;
23227 else
23228 optlen = strlen (str);
23230 if (optlen == 0)
23232 as_bad (_("missing cpu name `%s'"), str);
23233 return FALSE;
23236 for (opt = arm_cpus; opt->name != NULL; opt++)
23237 if (strncmp (opt->name, str, optlen) == 0)
23239 mcpu_cpu_opt = &opt->value;
23240 mcpu_fpu_opt = &opt->default_fpu;
23241 if (opt->canonical_name)
23242 strcpy (selected_cpu_name, opt->canonical_name);
23243 else
23245 int i;
23247 for (i = 0; i < optlen; i++)
23248 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23249 selected_cpu_name[i] = 0;
23252 if (ext != NULL)
23253 return arm_parse_extension (ext, &mcpu_cpu_opt);
23255 return TRUE;
23258 as_bad (_("unknown cpu `%s'"), str);
23259 return FALSE;
23262 static bfd_boolean
23263 arm_parse_arch (char * str)
23265 const struct arm_arch_option_table *opt;
23266 char *ext = strchr (str, '+');
23267 int optlen;
23269 if (ext != NULL)
23270 optlen = ext - str;
23271 else
23272 optlen = strlen (str);
23274 if (optlen == 0)
23276 as_bad (_("missing architecture name `%s'"), str);
23277 return FALSE;
23280 for (opt = arm_archs; opt->name != NULL; opt++)
23281 if (strncmp (opt->name, str, optlen) == 0)
23283 march_cpu_opt = &opt->value;
23284 march_fpu_opt = &opt->default_fpu;
23285 strcpy (selected_cpu_name, opt->name);
23287 if (ext != NULL)
23288 return arm_parse_extension (ext, &march_cpu_opt);
23290 return TRUE;
23293 as_bad (_("unknown architecture `%s'\n"), str);
23294 return FALSE;
23297 static bfd_boolean
23298 arm_parse_fpu (char * str)
23300 const struct arm_option_fpu_value_table * opt;
23302 for (opt = arm_fpus; opt->name != NULL; opt++)
23303 if (streq (opt->name, str))
23305 mfpu_opt = &opt->value;
23306 return TRUE;
23309 as_bad (_("unknown floating point format `%s'\n"), str);
23310 return FALSE;
23313 static bfd_boolean
23314 arm_parse_float_abi (char * str)
23316 const struct arm_option_value_table * opt;
23318 for (opt = arm_float_abis; opt->name != NULL; opt++)
23319 if (streq (opt->name, str))
23321 mfloat_abi_opt = opt->value;
23322 return TRUE;
23325 as_bad (_("unknown floating point abi `%s'\n"), str);
23326 return FALSE;
23329 #ifdef OBJ_ELF
23330 static bfd_boolean
23331 arm_parse_eabi (char * str)
23333 const struct arm_option_value_table *opt;
23335 for (opt = arm_eabis; opt->name != NULL; opt++)
23336 if (streq (opt->name, str))
23338 meabi_flags = opt->value;
23339 return TRUE;
23341 as_bad (_("unknown EABI `%s'\n"), str);
23342 return FALSE;
23344 #endif
23346 static bfd_boolean
23347 arm_parse_it_mode (char * str)
23349 bfd_boolean ret = TRUE;
23351 if (streq ("arm", str))
23352 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
23353 else if (streq ("thumb", str))
23354 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
23355 else if (streq ("always", str))
23356 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
23357 else if (streq ("never", str))
23358 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
23359 else
23361 as_bad (_("unknown implicit IT mode `%s', should be "\
23362 "arm, thumb, always, or never."), str);
23363 ret = FALSE;
23366 return ret;
23369 struct arm_long_option_table arm_long_opts[] =
23371 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
23372 arm_parse_cpu, NULL},
23373 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
23374 arm_parse_arch, NULL},
23375 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
23376 arm_parse_fpu, NULL},
23377 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
23378 arm_parse_float_abi, NULL},
23379 #ifdef OBJ_ELF
23380 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
23381 arm_parse_eabi, NULL},
23382 #endif
23383 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
23384 arm_parse_it_mode, NULL},
23385 {NULL, NULL, 0, NULL}
23389 md_parse_option (int c, char * arg)
23391 struct arm_option_table *opt;
23392 const struct arm_legacy_option_table *fopt;
23393 struct arm_long_option_table *lopt;
23395 switch (c)
23397 #ifdef OPTION_EB
23398 case OPTION_EB:
23399 target_big_endian = 1;
23400 break;
23401 #endif
23403 #ifdef OPTION_EL
23404 case OPTION_EL:
23405 target_big_endian = 0;
23406 break;
23407 #endif
23409 case OPTION_FIX_V4BX:
23410 fix_v4bx = TRUE;
23411 break;
23413 case 'a':
23414 /* Listing option. Just ignore these, we don't support additional
23415 ones. */
23416 return 0;
23418 default:
23419 for (opt = arm_opts; opt->option != NULL; opt++)
23421 if (c == opt->option[0]
23422 && ((arg == NULL && opt->option[1] == 0)
23423 || streq (arg, opt->option + 1)))
23425 /* If the option is deprecated, tell the user. */
23426 if (warn_on_deprecated && opt->deprecated != NULL)
23427 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23428 arg ? arg : "", _(opt->deprecated));
23430 if (opt->var != NULL)
23431 *opt->var = opt->value;
23433 return 1;
23437 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
23439 if (c == fopt->option[0]
23440 && ((arg == NULL && fopt->option[1] == 0)
23441 || streq (arg, fopt->option + 1)))
23443 /* If the option is deprecated, tell the user. */
23444 if (warn_on_deprecated && fopt->deprecated != NULL)
23445 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23446 arg ? arg : "", _(fopt->deprecated));
23448 if (fopt->var != NULL)
23449 *fopt->var = &fopt->value;
23451 return 1;
23455 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23457 /* These options are expected to have an argument. */
23458 if (c == lopt->option[0]
23459 && arg != NULL
23460 && strncmp (arg, lopt->option + 1,
23461 strlen (lopt->option + 1)) == 0)
23463 /* If the option is deprecated, tell the user. */
23464 if (warn_on_deprecated && lopt->deprecated != NULL)
23465 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
23466 _(lopt->deprecated));
23468 /* Call the sup-option parser. */
23469 return lopt->func (arg + strlen (lopt->option) - 1);
23473 return 0;
23476 return 1;
23479 void
23480 md_show_usage (FILE * fp)
23482 struct arm_option_table *opt;
23483 struct arm_long_option_table *lopt;
23485 fprintf (fp, _(" ARM-specific assembler options:\n"));
23487 for (opt = arm_opts; opt->option != NULL; opt++)
23488 if (opt->help != NULL)
23489 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
23491 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23492 if (lopt->help != NULL)
23493 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
23495 #ifdef OPTION_EB
23496 fprintf (fp, _("\
23497 -EB assemble code for a big-endian cpu\n"));
23498 #endif
23500 #ifdef OPTION_EL
23501 fprintf (fp, _("\
23502 -EL assemble code for a little-endian cpu\n"));
23503 #endif
23505 fprintf (fp, _("\
23506 --fix-v4bx Allow BX in ARMv4 code\n"));
23510 #ifdef OBJ_ELF
23511 typedef struct
23513 int val;
23514 arm_feature_set flags;
23515 } cpu_arch_ver_table;
23517 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23518 least features first. */
23519 static const cpu_arch_ver_table cpu_arch_ver[] =
23521 {1, ARM_ARCH_V4},
23522 {2, ARM_ARCH_V4T},
23523 {3, ARM_ARCH_V5},
23524 {3, ARM_ARCH_V5T},
23525 {4, ARM_ARCH_V5TE},
23526 {5, ARM_ARCH_V5TEJ},
23527 {6, ARM_ARCH_V6},
23528 {9, ARM_ARCH_V6K},
23529 {7, ARM_ARCH_V6Z},
23530 {11, ARM_ARCH_V6M},
23531 {12, ARM_ARCH_V6SM},
23532 {8, ARM_ARCH_V6T2},
23533 {10, ARM_ARCH_V7A},
23534 {10, ARM_ARCH_V7R},
23535 {10, ARM_ARCH_V7M},
23536 {0, ARM_ARCH_NONE}
23539 /* Set an attribute if it has not already been set by the user. */
23540 static void
23541 aeabi_set_attribute_int (int tag, int value)
23543 if (tag < 1
23544 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23545 || !attributes_set_explicitly[tag])
23546 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23549 static void
23550 aeabi_set_attribute_string (int tag, const char *value)
23552 if (tag < 1
23553 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23554 || !attributes_set_explicitly[tag])
23555 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23558 /* Set the public EABI object attributes. */
23559 static void
23560 aeabi_set_public_attributes (void)
23562 int arch;
23563 int virt_sec = 0;
23564 arm_feature_set flags;
23565 arm_feature_set tmp;
23566 const cpu_arch_ver_table *p;
23568 /* Choose the architecture based on the capabilities of the requested cpu
23569 (if any) and/or the instructions actually used. */
23570 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23571 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23572 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
23573 /*Allow the user to override the reported architecture. */
23574 if (object_arch)
23576 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23577 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23580 /* We need to make sure that the attributes do not identify us as v6S-M
23581 when the only v6S-M feature in use is the Operating System Extensions. */
23582 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
23583 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
23584 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
23586 tmp = flags;
23587 arch = 0;
23588 for (p = cpu_arch_ver; p->val; p++)
23590 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23592 arch = p->val;
23593 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23597 /* The table lookup above finds the last architecture to contribute
23598 a new feature. Unfortunately, Tag13 is a subset of the union of
23599 v6T2 and v7-M, so it is never seen as contributing a new feature.
23600 We can not search for the last entry which is entirely used,
23601 because if no CPU is specified we build up only those flags
23602 actually used. Perhaps we should separate out the specified
23603 and implicit cases. Avoid taking this path for -march=all by
23604 checking for contradictory v7-A / v7-M features. */
23605 if (arch == 10
23606 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23607 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23608 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23609 arch = 13;
23611 /* Tag_CPU_name. */
23612 if (selected_cpu_name[0])
23614 char *q;
23616 q = selected_cpu_name;
23617 if (strncmp (q, "armv", 4) == 0)
23619 int i;
23621 q += 4;
23622 for (i = 0; q[i]; i++)
23623 q[i] = TOUPPER (q[i]);
23625 aeabi_set_attribute_string (Tag_CPU_name, q);
23628 /* Tag_CPU_arch. */
23629 aeabi_set_attribute_int (Tag_CPU_arch, arch);
23631 /* Tag_CPU_arch_profile. */
23632 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
23633 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
23634 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
23635 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
23636 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
23637 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
23639 /* Tag_ARM_ISA_use. */
23640 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23641 || arch == 0)
23642 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
23644 /* Tag_THUMB_ISA_use. */
23645 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23646 || arch == 0)
23647 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23648 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
23650 /* Tag_VFP_arch. */
23651 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23652 aeabi_set_attribute_int (Tag_VFP_arch,
23653 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23654 ? 5 : 6);
23655 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
23656 aeabi_set_attribute_int (Tag_VFP_arch, 3);
23657 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
23658 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23659 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23660 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23661 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23662 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23663 aeabi_set_attribute_int (Tag_VFP_arch, 1);
23665 /* Tag_ABI_HardFP_use. */
23666 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23667 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23668 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23670 /* Tag_WMMX_arch. */
23671 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23672 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23673 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23674 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
23676 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
23677 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
23678 aeabi_set_attribute_int
23679 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
23680 ? 2 : 1));
23682 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
23683 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
23684 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
23686 /* Tag_DIV_use. */
23687 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv))
23688 aeabi_set_attribute_int (Tag_DIV_use, 2);
23689 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
23690 aeabi_set_attribute_int (Tag_DIV_use, 0);
23691 else
23692 aeabi_set_attribute_int (Tag_DIV_use, 1);
23694 /* Tag_MP_extension_use. */
23695 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
23696 aeabi_set_attribute_int (Tag_MPextension_use, 1);
23698 /* Tag Virtualization_use. */
23699 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
23700 virt_sec |= 1;
23701 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
23702 virt_sec |= 2;
23703 if (virt_sec != 0)
23704 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
23707 /* Add the default contents for the .ARM.attributes section. */
23708 void
23709 arm_md_end (void)
23711 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23712 return;
23714 aeabi_set_public_attributes ();
23716 #endif /* OBJ_ELF */
23719 /* Parse a .cpu directive. */
23721 static void
23722 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
23724 const struct arm_cpu_option_table *opt;
23725 char *name;
23726 char saved_char;
23728 name = input_line_pointer;
23729 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23730 input_line_pointer++;
23731 saved_char = *input_line_pointer;
23732 *input_line_pointer = 0;
23734 /* Skip the first "all" entry. */
23735 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23736 if (streq (opt->name, name))
23738 mcpu_cpu_opt = &opt->value;
23739 selected_cpu = opt->value;
23740 if (opt->canonical_name)
23741 strcpy (selected_cpu_name, opt->canonical_name);
23742 else
23744 int i;
23745 for (i = 0; opt->name[i]; i++)
23746 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23747 selected_cpu_name[i] = 0;
23749 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23750 *input_line_pointer = saved_char;
23751 demand_empty_rest_of_line ();
23752 return;
23754 as_bad (_("unknown cpu `%s'"), name);
23755 *input_line_pointer = saved_char;
23756 ignore_rest_of_line ();
23760 /* Parse a .arch directive. */
23762 static void
23763 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23765 const struct arm_arch_option_table *opt;
23766 char saved_char;
23767 char *name;
23769 name = input_line_pointer;
23770 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23771 input_line_pointer++;
23772 saved_char = *input_line_pointer;
23773 *input_line_pointer = 0;
23775 /* Skip the first "all" entry. */
23776 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23777 if (streq (opt->name, name))
23779 mcpu_cpu_opt = &opt->value;
23780 selected_cpu = opt->value;
23781 strcpy (selected_cpu_name, opt->name);
23782 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23783 *input_line_pointer = saved_char;
23784 demand_empty_rest_of_line ();
23785 return;
23788 as_bad (_("unknown architecture `%s'\n"), name);
23789 *input_line_pointer = saved_char;
23790 ignore_rest_of_line ();
23794 /* Parse a .object_arch directive. */
23796 static void
23797 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
23799 const struct arm_arch_option_table *opt;
23800 char saved_char;
23801 char *name;
23803 name = input_line_pointer;
23804 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23805 input_line_pointer++;
23806 saved_char = *input_line_pointer;
23807 *input_line_pointer = 0;
23809 /* Skip the first "all" entry. */
23810 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23811 if (streq (opt->name, name))
23813 object_arch = &opt->value;
23814 *input_line_pointer = saved_char;
23815 demand_empty_rest_of_line ();
23816 return;
23819 as_bad (_("unknown architecture `%s'\n"), name);
23820 *input_line_pointer = saved_char;
23821 ignore_rest_of_line ();
23824 /* Parse a .arch_extension directive. */
23826 static void
23827 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
23829 const struct arm_option_extension_value_table *opt;
23830 char saved_char;
23831 char *name;
23832 int adding_value = 1;
23834 name = input_line_pointer;
23835 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23836 input_line_pointer++;
23837 saved_char = *input_line_pointer;
23838 *input_line_pointer = 0;
23840 if (strlen (name) >= 2
23841 && strncmp (name, "no", 2) == 0)
23843 adding_value = 0;
23844 name += 2;
23847 for (opt = arm_extensions; opt->name != NULL; opt++)
23848 if (streq (opt->name, name))
23850 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
23852 as_bad (_("architectural extension `%s' is not allowed for the "
23853 "current base architecture"), name);
23854 break;
23857 if (adding_value)
23858 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
23859 else
23860 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
23862 mcpu_cpu_opt = &selected_cpu;
23863 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23864 *input_line_pointer = saved_char;
23865 demand_empty_rest_of_line ();
23866 return;
23869 if (opt->name == NULL)
23870 as_bad (_("unknown architecture `%s'\n"), name);
23872 *input_line_pointer = saved_char;
23873 ignore_rest_of_line ();
23876 /* Parse a .fpu directive. */
23878 static void
23879 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23881 const struct arm_option_fpu_value_table *opt;
23882 char saved_char;
23883 char *name;
23885 name = input_line_pointer;
23886 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23887 input_line_pointer++;
23888 saved_char = *input_line_pointer;
23889 *input_line_pointer = 0;
23891 for (opt = arm_fpus; opt->name != NULL; opt++)
23892 if (streq (opt->name, name))
23894 mfpu_opt = &opt->value;
23895 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23896 *input_line_pointer = saved_char;
23897 demand_empty_rest_of_line ();
23898 return;
23901 as_bad (_("unknown floating point format `%s'\n"), name);
23902 *input_line_pointer = saved_char;
23903 ignore_rest_of_line ();
23906 /* Copy symbol information. */
23908 void
23909 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23911 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23914 #ifdef OBJ_ELF
23915 /* Given a symbolic attribute NAME, return the proper integer value.
23916 Returns -1 if the attribute is not known. */
23919 arm_convert_symbolic_attribute (const char *name)
23921 static const struct
23923 const char * name;
23924 const int tag;
23926 attribute_table[] =
23928 /* When you modify this table you should
23929 also modify the list in doc/c-arm.texi. */
23930 #define T(tag) {#tag, tag}
23931 T (Tag_CPU_raw_name),
23932 T (Tag_CPU_name),
23933 T (Tag_CPU_arch),
23934 T (Tag_CPU_arch_profile),
23935 T (Tag_ARM_ISA_use),
23936 T (Tag_THUMB_ISA_use),
23937 T (Tag_FP_arch),
23938 T (Tag_VFP_arch),
23939 T (Tag_WMMX_arch),
23940 T (Tag_Advanced_SIMD_arch),
23941 T (Tag_PCS_config),
23942 T (Tag_ABI_PCS_R9_use),
23943 T (Tag_ABI_PCS_RW_data),
23944 T (Tag_ABI_PCS_RO_data),
23945 T (Tag_ABI_PCS_GOT_use),
23946 T (Tag_ABI_PCS_wchar_t),
23947 T (Tag_ABI_FP_rounding),
23948 T (Tag_ABI_FP_denormal),
23949 T (Tag_ABI_FP_exceptions),
23950 T (Tag_ABI_FP_user_exceptions),
23951 T (Tag_ABI_FP_number_model),
23952 T (Tag_ABI_align_needed),
23953 T (Tag_ABI_align8_needed),
23954 T (Tag_ABI_align_preserved),
23955 T (Tag_ABI_align8_preserved),
23956 T (Tag_ABI_enum_size),
23957 T (Tag_ABI_HardFP_use),
23958 T (Tag_ABI_VFP_args),
23959 T (Tag_ABI_WMMX_args),
23960 T (Tag_ABI_optimization_goals),
23961 T (Tag_ABI_FP_optimization_goals),
23962 T (Tag_compatibility),
23963 T (Tag_CPU_unaligned_access),
23964 T (Tag_FP_HP_extension),
23965 T (Tag_VFP_HP_extension),
23966 T (Tag_ABI_FP_16bit_format),
23967 T (Tag_MPextension_use),
23968 T (Tag_DIV_use),
23969 T (Tag_nodefaults),
23970 T (Tag_also_compatible_with),
23971 T (Tag_conformance),
23972 T (Tag_T2EE_use),
23973 T (Tag_Virtualization_use),
23974 /* We deliberately do not include Tag_MPextension_use_legacy. */
23975 #undef T
23977 unsigned int i;
23979 if (name == NULL)
23980 return -1;
23982 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
23983 if (streq (name, attribute_table[i].name))
23984 return attribute_table[i].tag;
23986 return -1;
23990 /* Apply sym value for relocations only in the case that
23991 they are for local symbols and you have the respective
23992 architectural feature for blx and simple switches. */
23994 arm_apply_sym_value (struct fix * fixP)
23996 if (fixP->fx_addsy
23997 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23998 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
24000 switch (fixP->fx_r_type)
24002 case BFD_RELOC_ARM_PCREL_BLX:
24003 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24004 if (ARM_IS_FUNC (fixP->fx_addsy))
24005 return 1;
24006 break;
24008 case BFD_RELOC_ARM_PCREL_CALL:
24009 case BFD_RELOC_THUMB_PCREL_BLX:
24010 if (THUMB_IS_FUNC (fixP->fx_addsy))
24011 return 1;
24012 break;
24014 default:
24015 break;
24019 return 0;
24021 #endif /* OBJ_ELF */