* configure.in (TOPLEVEL_CONFIGURE_ARGUMENTS, baseargs): Fix
[binutils.git] / gas / config / tc-arm.c
blob842e72c48787221d6bc593a929b1db17cd5399fb
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005
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 2, 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 <string.h>
29 #include <limits.h>
30 #include <stdarg.h>
31 #define NO_RELOC 0
32 #include "as.h"
33 #include "safe-ctype.h"
35 /* Need TARGET_CPU. */
36 #include "config.h"
37 #include "subsegs.h"
38 #include "obstack.h"
39 #include "symbols.h"
40 #include "listing.h"
42 #include "opcode/arm.h"
44 #ifdef OBJ_ELF
45 #include "elf/arm.h"
46 #include "dwarf2dbg.h"
47 #include "dw2gencfi.h"
48 #endif
50 /* XXX Set this to 1 after the next binutils release. */
51 #define WARN_DEPRECATED 0
53 #ifdef OBJ_ELF
54 /* Must be at least the size of the largest unwind opcode (currently two). */
55 #define ARM_OPCODE_CHUNK_SIZE 8
57 /* This structure holds the unwinding state. */
59 static struct
61 symbolS * proc_start;
62 symbolS * table_entry;
63 symbolS * personality_routine;
64 int personality_index;
65 /* The segment containing the function. */
66 segT saved_seg;
67 subsegT saved_subseg;
68 /* Opcodes generated from this function. */
69 unsigned char * opcodes;
70 int opcode_count;
71 int opcode_alloc;
72 /* The number of bytes pushed to the stack. */
73 offsetT frame_size;
74 /* We don't add stack adjustment opcodes immediately so that we can merge
75 multiple adjustments. We can also omit the final adjustment
76 when using a frame pointer. */
77 offsetT pending_offset;
78 /* These two fields are set by both unwind_movsp and unwind_setfp. They
79 hold the reg+offset to use when restoring sp from a frame pointer. */
80 offsetT fp_offset;
81 int fp_reg;
82 /* Nonzero if an unwind_setfp directive has been seen. */
83 unsigned fp_used:1;
84 /* Nonzero if the last opcode restores sp from fp_reg. */
85 unsigned sp_restored:1;
86 } unwind;
88 /* Results from operand parsing worker functions. */
90 typedef enum
92 PARSE_OPERAND_SUCCESS,
93 PARSE_OPERAND_FAIL,
94 PARSE_OPERAND_FAIL_NO_BACKTRACK
95 } parse_operand_result;
97 /* Bit N indicates that an R_ARM_NONE relocation has been output for
98 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
99 emitted only once per section, to save unnecessary bloat. */
100 static unsigned int marked_pr_dependency = 0;
102 #endif /* OBJ_ELF */
104 enum arm_float_abi
106 ARM_FLOAT_ABI_HARD,
107 ARM_FLOAT_ABI_SOFTFP,
108 ARM_FLOAT_ABI_SOFT
111 /* Types of processor to assemble for. */
112 #ifndef CPU_DEFAULT
113 #if defined __XSCALE__
114 #define CPU_DEFAULT ARM_ARCH_XSCALE
115 #else
116 #if defined __thumb__
117 #define CPU_DEFAULT ARM_ARCH_V5T
118 #endif
119 #endif
120 #endif
122 #ifndef FPU_DEFAULT
123 # ifdef TE_LINUX
124 # define FPU_DEFAULT FPU_ARCH_FPA
125 # elif defined (TE_NetBSD)
126 # ifdef OBJ_ELF
127 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
128 # else
129 /* Legacy a.out format. */
130 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
131 # endif
132 # elif defined (TE_VXWORKS)
133 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
134 # else
135 /* For backwards compatibility, default to FPA. */
136 # define FPU_DEFAULT FPU_ARCH_FPA
137 # endif
138 #endif /* ifndef FPU_DEFAULT */
140 #define streq(a, b) (strcmp (a, b) == 0)
142 static arm_feature_set cpu_variant;
143 static arm_feature_set arm_arch_used;
144 static arm_feature_set thumb_arch_used;
146 /* Flags stored in private area of BFD structure. */
147 static int uses_apcs_26 = FALSE;
148 static int atpcs = FALSE;
149 static int support_interwork = FALSE;
150 static int uses_apcs_float = FALSE;
151 static int pic_code = FALSE;
153 /* Variables that we set while parsing command-line options. Once all
154 options have been read we re-process these values to set the real
155 assembly flags. */
156 static const arm_feature_set *legacy_cpu = NULL;
157 static const arm_feature_set *legacy_fpu = NULL;
159 static const arm_feature_set *mcpu_cpu_opt = NULL;
160 static const arm_feature_set *mcpu_fpu_opt = NULL;
161 static const arm_feature_set *march_cpu_opt = NULL;
162 static const arm_feature_set *march_fpu_opt = NULL;
163 static const arm_feature_set *mfpu_opt = NULL;
165 /* Constants for known architecture features. */
166 static const arm_feature_set fpu_default = FPU_DEFAULT;
167 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
168 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
169 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
170 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
171 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
172 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
173 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
174 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
176 #ifdef CPU_DEFAULT
177 static const arm_feature_set cpu_default = CPU_DEFAULT;
178 #endif
180 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
181 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
182 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
183 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
184 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
185 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
186 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
187 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
188 static const arm_feature_set arm_ext_v4t_5 =
189 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
190 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
191 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
192 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
193 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
194 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
195 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
196 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
197 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
198 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
199 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
200 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
201 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
202 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
203 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
205 static const arm_feature_set arm_arch_any = ARM_ANY;
206 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
207 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
208 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
210 static const arm_feature_set arm_cext_iwmmxt =
211 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
212 static const arm_feature_set arm_cext_xscale =
213 ARM_FEATURE (0, ARM_CEXT_XSCALE);
214 static const arm_feature_set arm_cext_maverick =
215 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
216 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
217 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
218 static const arm_feature_set fpu_vfp_ext_v1xd =
219 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
220 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
221 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
222 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
223 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
224 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
225 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
227 static int mfloat_abi_opt = -1;
228 /* Record user cpu selection for object attributes. */
229 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
230 /* Must be long enough to hold any of the names in arm_cpus. */
231 static char selected_cpu_name[16];
232 #ifdef OBJ_ELF
233 # ifdef EABI_DEFAULT
234 static int meabi_flags = EABI_DEFAULT;
235 # else
236 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
237 # endif
238 #endif
240 #ifdef OBJ_ELF
241 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
242 symbolS * GOT_symbol;
243 #endif
245 /* 0: assemble for ARM,
246 1: assemble for Thumb,
247 2: assemble for Thumb even though target CPU does not support thumb
248 instructions. */
249 static int thumb_mode = 0;
251 /* If unified_syntax is true, we are processing the new unified
252 ARM/Thumb syntax. Important differences from the old ARM mode:
254 - Immediate operands do not require a # prefix.
255 - Conditional affixes always appear at the end of the
256 instruction. (For backward compatibility, those instructions
257 that formerly had them in the middle, continue to accept them
258 there.)
259 - The IT instruction may appear, and if it does is validated
260 against subsequent conditional affixes. It does not generate
261 machine code.
263 Important differences from the old Thumb mode:
265 - Immediate operands do not require a # prefix.
266 - Most of the V6T2 instructions are only available in unified mode.
267 - The .N and .W suffixes are recognized and honored (it is an error
268 if they cannot be honored).
269 - All instructions set the flags if and only if they have an 's' affix.
270 - Conditional affixes may be used. They are validated against
271 preceding IT instructions. Unlike ARM mode, you cannot use a
272 conditional affix except in the scope of an IT instruction. */
274 static bfd_boolean unified_syntax = FALSE;
276 enum neon_el_type
278 NT_invtype,
279 NT_untyped,
280 NT_integer,
281 NT_float,
282 NT_poly,
283 NT_signed,
284 NT_unsigned
287 struct neon_type_el
289 enum neon_el_type type;
290 unsigned size;
293 #define NEON_MAX_TYPE_ELS 4
295 struct neon_type
297 struct neon_type_el el[NEON_MAX_TYPE_ELS];
298 unsigned elems;
301 struct arm_it
303 const char * error;
304 unsigned long instruction;
305 int size;
306 int size_req;
307 int cond;
308 /* "uncond_value" is set to the value in place of the conditional field in
309 unconditional versions of the instruction, or -1 if nothing is
310 appropriate. */
311 int uncond_value;
312 struct neon_type vectype;
313 /* Set to the opcode if the instruction needs relaxation.
314 Zero if the instruction is not relaxed. */
315 unsigned long relax;
316 struct
318 bfd_reloc_code_real_type type;
319 expressionS exp;
320 int pc_rel;
321 } reloc;
323 struct
325 unsigned reg;
326 signed int imm;
327 struct neon_type_el vectype;
328 unsigned present : 1; /* Operand present. */
329 unsigned isreg : 1; /* Operand was a register. */
330 unsigned immisreg : 1; /* .imm field is a second register. */
331 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
332 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
333 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
334 instructions. This allows us to disambiguate ARM <-> vector insns. */
335 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
336 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
337 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
338 unsigned issingle : 1; /* Operand is VFP single-precision register. */
339 unsigned hasreloc : 1; /* Operand has relocation suffix. */
340 unsigned writeback : 1; /* Operand has trailing ! */
341 unsigned preind : 1; /* Preindexed address. */
342 unsigned postind : 1; /* Postindexed address. */
343 unsigned negative : 1; /* Index register was negated. */
344 unsigned shifted : 1; /* Shift applied to operation. */
345 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
346 } operands[6];
349 static struct arm_it inst;
351 #define NUM_FLOAT_VALS 8
353 const char * fp_const[] =
355 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
358 /* Number of littlenums required to hold an extended precision number. */
359 #define MAX_LITTLENUMS 6
361 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
363 #define FAIL (-1)
364 #define SUCCESS (0)
366 #define SUFF_S 1
367 #define SUFF_D 2
368 #define SUFF_E 3
369 #define SUFF_P 4
371 #define CP_T_X 0x00008000
372 #define CP_T_Y 0x00400000
374 #define CONDS_BIT 0x00100000
375 #define LOAD_BIT 0x00100000
377 #define DOUBLE_LOAD_FLAG 0x00000001
379 struct asm_cond
381 const char * template;
382 unsigned long value;
385 #define COND_ALWAYS 0xE
387 struct asm_psr
389 const char *template;
390 unsigned long field;
393 struct asm_barrier_opt
395 const char *template;
396 unsigned long value;
399 /* The bit that distinguishes CPSR and SPSR. */
400 #define SPSR_BIT (1 << 22)
402 /* The individual PSR flag bits. */
403 #define PSR_c (1 << 16)
404 #define PSR_x (1 << 17)
405 #define PSR_s (1 << 18)
406 #define PSR_f (1 << 19)
408 struct reloc_entry
410 char *name;
411 bfd_reloc_code_real_type reloc;
414 enum vfp_reg_pos
416 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
417 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
420 enum vfp_ldstm_type
422 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
425 /* Bits for DEFINED field in neon_typed_alias. */
426 #define NTA_HASTYPE 1
427 #define NTA_HASINDEX 2
429 struct neon_typed_alias
431 unsigned char defined;
432 unsigned char index;
433 struct neon_type_el eltype;
436 /* ARM register categories. This includes coprocessor numbers and various
437 architecture extensions' registers. */
438 enum arm_reg_type
440 REG_TYPE_RN,
441 REG_TYPE_CP,
442 REG_TYPE_CN,
443 REG_TYPE_FN,
444 REG_TYPE_VFS,
445 REG_TYPE_VFD,
446 REG_TYPE_NQ,
447 REG_TYPE_VFSD,
448 REG_TYPE_NDQ,
449 REG_TYPE_NSDQ,
450 REG_TYPE_VFC,
451 REG_TYPE_MVF,
452 REG_TYPE_MVD,
453 REG_TYPE_MVFX,
454 REG_TYPE_MVDX,
455 REG_TYPE_MVAX,
456 REG_TYPE_DSPSC,
457 REG_TYPE_MMXWR,
458 REG_TYPE_MMXWC,
459 REG_TYPE_MMXWCG,
460 REG_TYPE_XSCALE,
463 /* Structure for a hash table entry for a register.
464 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
465 information which states whether a vector type or index is specified (for a
466 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
467 struct reg_entry
469 const char *name;
470 unsigned char number;
471 unsigned char type;
472 unsigned char builtin;
473 struct neon_typed_alias *neon;
476 /* Diagnostics used when we don't get a register of the expected type. */
477 const char *const reg_expected_msgs[] =
479 N_("ARM register expected"),
480 N_("bad or missing co-processor number"),
481 N_("co-processor register expected"),
482 N_("FPA register expected"),
483 N_("VFP single precision register expected"),
484 N_("VFP/Neon double precision register expected"),
485 N_("Neon quad precision register expected"),
486 N_("VFP single or double precision register expected"),
487 N_("Neon double or quad precision register expected"),
488 N_("VFP single, double or Neon quad precision register expected"),
489 N_("VFP system register expected"),
490 N_("Maverick MVF register expected"),
491 N_("Maverick MVD register expected"),
492 N_("Maverick MVFX register expected"),
493 N_("Maverick MVDX register expected"),
494 N_("Maverick MVAX register expected"),
495 N_("Maverick DSPSC register expected"),
496 N_("iWMMXt data register expected"),
497 N_("iWMMXt control register expected"),
498 N_("iWMMXt scalar register expected"),
499 N_("XScale accumulator register expected"),
502 /* Some well known registers that we refer to directly elsewhere. */
503 #define REG_SP 13
504 #define REG_LR 14
505 #define REG_PC 15
507 /* ARM instructions take 4bytes in the object file, Thumb instructions
508 take 2: */
509 #define INSN_SIZE 4
511 struct asm_opcode
513 /* Basic string to match. */
514 const char *template;
516 /* Parameters to instruction. */
517 unsigned char operands[8];
519 /* Conditional tag - see opcode_lookup. */
520 unsigned int tag : 4;
522 /* Basic instruction code. */
523 unsigned int avalue : 28;
525 /* Thumb-format instruction code. */
526 unsigned int tvalue;
528 /* Which architecture variant provides this instruction. */
529 const arm_feature_set *avariant;
530 const arm_feature_set *tvariant;
532 /* Function to call to encode instruction in ARM format. */
533 void (* aencode) (void);
535 /* Function to call to encode instruction in Thumb format. */
536 void (* tencode) (void);
539 /* Defines for various bits that we will want to toggle. */
540 #define INST_IMMEDIATE 0x02000000
541 #define OFFSET_REG 0x02000000
542 #define HWOFFSET_IMM 0x00400000
543 #define SHIFT_BY_REG 0x00000010
544 #define PRE_INDEX 0x01000000
545 #define INDEX_UP 0x00800000
546 #define WRITE_BACK 0x00200000
547 #define LDM_TYPE_2_OR_3 0x00400000
549 #define LITERAL_MASK 0xf000f000
550 #define OPCODE_MASK 0xfe1fffff
551 #define V4_STR_BIT 0x00000020
553 #define DATA_OP_SHIFT 21
555 #define T2_OPCODE_MASK 0xfe1fffff
556 #define T2_DATA_OP_SHIFT 21
558 /* Codes to distinguish the arithmetic instructions. */
559 #define OPCODE_AND 0
560 #define OPCODE_EOR 1
561 #define OPCODE_SUB 2
562 #define OPCODE_RSB 3
563 #define OPCODE_ADD 4
564 #define OPCODE_ADC 5
565 #define OPCODE_SBC 6
566 #define OPCODE_RSC 7
567 #define OPCODE_TST 8
568 #define OPCODE_TEQ 9
569 #define OPCODE_CMP 10
570 #define OPCODE_CMN 11
571 #define OPCODE_ORR 12
572 #define OPCODE_MOV 13
573 #define OPCODE_BIC 14
574 #define OPCODE_MVN 15
576 #define T2_OPCODE_AND 0
577 #define T2_OPCODE_BIC 1
578 #define T2_OPCODE_ORR 2
579 #define T2_OPCODE_ORN 3
580 #define T2_OPCODE_EOR 4
581 #define T2_OPCODE_ADD 8
582 #define T2_OPCODE_ADC 10
583 #define T2_OPCODE_SBC 11
584 #define T2_OPCODE_SUB 13
585 #define T2_OPCODE_RSB 14
587 #define T_OPCODE_MUL 0x4340
588 #define T_OPCODE_TST 0x4200
589 #define T_OPCODE_CMN 0x42c0
590 #define T_OPCODE_NEG 0x4240
591 #define T_OPCODE_MVN 0x43c0
593 #define T_OPCODE_ADD_R3 0x1800
594 #define T_OPCODE_SUB_R3 0x1a00
595 #define T_OPCODE_ADD_HI 0x4400
596 #define T_OPCODE_ADD_ST 0xb000
597 #define T_OPCODE_SUB_ST 0xb080
598 #define T_OPCODE_ADD_SP 0xa800
599 #define T_OPCODE_ADD_PC 0xa000
600 #define T_OPCODE_ADD_I8 0x3000
601 #define T_OPCODE_SUB_I8 0x3800
602 #define T_OPCODE_ADD_I3 0x1c00
603 #define T_OPCODE_SUB_I3 0x1e00
605 #define T_OPCODE_ASR_R 0x4100
606 #define T_OPCODE_LSL_R 0x4080
607 #define T_OPCODE_LSR_R 0x40c0
608 #define T_OPCODE_ROR_R 0x41c0
609 #define T_OPCODE_ASR_I 0x1000
610 #define T_OPCODE_LSL_I 0x0000
611 #define T_OPCODE_LSR_I 0x0800
613 #define T_OPCODE_MOV_I8 0x2000
614 #define T_OPCODE_CMP_I8 0x2800
615 #define T_OPCODE_CMP_LR 0x4280
616 #define T_OPCODE_MOV_HR 0x4600
617 #define T_OPCODE_CMP_HR 0x4500
619 #define T_OPCODE_LDR_PC 0x4800
620 #define T_OPCODE_LDR_SP 0x9800
621 #define T_OPCODE_STR_SP 0x9000
622 #define T_OPCODE_LDR_IW 0x6800
623 #define T_OPCODE_STR_IW 0x6000
624 #define T_OPCODE_LDR_IH 0x8800
625 #define T_OPCODE_STR_IH 0x8000
626 #define T_OPCODE_LDR_IB 0x7800
627 #define T_OPCODE_STR_IB 0x7000
628 #define T_OPCODE_LDR_RW 0x5800
629 #define T_OPCODE_STR_RW 0x5000
630 #define T_OPCODE_LDR_RH 0x5a00
631 #define T_OPCODE_STR_RH 0x5200
632 #define T_OPCODE_LDR_RB 0x5c00
633 #define T_OPCODE_STR_RB 0x5400
635 #define T_OPCODE_PUSH 0xb400
636 #define T_OPCODE_POP 0xbc00
638 #define T_OPCODE_BRANCH 0xe000
640 #define THUMB_SIZE 2 /* Size of thumb instruction. */
641 #define THUMB_PP_PC_LR 0x0100
642 #define THUMB_LOAD_BIT 0x0800
643 #define THUMB2_LOAD_BIT 0x00100000
645 #define BAD_ARGS _("bad arguments to instruction")
646 #define BAD_PC _("r15 not allowed here")
647 #define BAD_COND _("instruction cannot be conditional")
648 #define BAD_OVERLAP _("registers may not be the same")
649 #define BAD_HIREG _("lo register required")
650 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
651 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
652 #define BAD_BRANCH _("branch must be last instruction in IT block")
653 #define BAD_NOT_IT _("instruction not allowed in IT block")
654 #define BAD_FPU _("selected FPU does not support instruction")
656 static struct hash_control *arm_ops_hsh;
657 static struct hash_control *arm_cond_hsh;
658 static struct hash_control *arm_shift_hsh;
659 static struct hash_control *arm_psr_hsh;
660 static struct hash_control *arm_v7m_psr_hsh;
661 static struct hash_control *arm_reg_hsh;
662 static struct hash_control *arm_reloc_hsh;
663 static struct hash_control *arm_barrier_opt_hsh;
665 /* Stuff needed to resolve the label ambiguity
668 label: <insn>
669 may differ from:
671 label:
672 <insn>
675 symbolS * last_label_seen;
676 static int label_is_thumb_function_name = FALSE;
678 /* Literal pool structure. Held on a per-section
679 and per-sub-section basis. */
681 #define MAX_LITERAL_POOL_SIZE 1024
682 typedef struct literal_pool
684 expressionS literals [MAX_LITERAL_POOL_SIZE];
685 unsigned int next_free_entry;
686 unsigned int id;
687 symbolS * symbol;
688 segT section;
689 subsegT sub_section;
690 struct literal_pool * next;
691 } literal_pool;
693 /* Pointer to a linked list of literal pools. */
694 literal_pool * list_of_pools = NULL;
696 /* State variables for IT block handling. */
697 static bfd_boolean current_it_mask = 0;
698 static int current_cc;
701 /* Pure syntax. */
703 /* This array holds the chars that always start a comment. If the
704 pre-processor is disabled, these aren't very useful. */
705 const char comment_chars[] = "@";
707 /* This array holds the chars that only start a comment at the beginning of
708 a line. If the line seems to have the form '# 123 filename'
709 .line and .file directives will appear in the pre-processed output. */
710 /* Note that input_file.c hand checks for '#' at the beginning of the
711 first line of the input file. This is because the compiler outputs
712 #NO_APP at the beginning of its output. */
713 /* Also note that comments like this one will always work. */
714 const char line_comment_chars[] = "#";
716 const char line_separator_chars[] = ";";
718 /* Chars that can be used to separate mant
719 from exp in floating point numbers. */
720 const char EXP_CHARS[] = "eE";
722 /* Chars that mean this number is a floating point constant. */
723 /* As in 0f12.456 */
724 /* or 0d1.2345e12 */
726 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
728 /* Prefix characters that indicate the start of an immediate
729 value. */
730 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
732 /* Separator character handling. */
734 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
736 static inline int
737 skip_past_char (char ** str, char c)
739 if (**str == c)
741 (*str)++;
742 return SUCCESS;
744 else
745 return FAIL;
747 #define skip_past_comma(str) skip_past_char (str, ',')
749 /* Arithmetic expressions (possibly involving symbols). */
751 /* Return TRUE if anything in the expression is a bignum. */
753 static int
754 walk_no_bignums (symbolS * sp)
756 if (symbol_get_value_expression (sp)->X_op == O_big)
757 return 1;
759 if (symbol_get_value_expression (sp)->X_add_symbol)
761 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
762 || (symbol_get_value_expression (sp)->X_op_symbol
763 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
766 return 0;
769 static int in_my_get_expression = 0;
771 /* Third argument to my_get_expression. */
772 #define GE_NO_PREFIX 0
773 #define GE_IMM_PREFIX 1
774 #define GE_OPT_PREFIX 2
775 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
776 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
777 #define GE_OPT_PREFIX_BIG 3
779 static int
780 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
782 char * save_in;
783 segT seg;
785 /* In unified syntax, all prefixes are optional. */
786 if (unified_syntax)
787 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
788 : GE_OPT_PREFIX;
790 switch (prefix_mode)
792 case GE_NO_PREFIX: break;
793 case GE_IMM_PREFIX:
794 if (!is_immediate_prefix (**str))
796 inst.error = _("immediate expression requires a # prefix");
797 return FAIL;
799 (*str)++;
800 break;
801 case GE_OPT_PREFIX:
802 case GE_OPT_PREFIX_BIG:
803 if (is_immediate_prefix (**str))
804 (*str)++;
805 break;
806 default: abort ();
809 memset (ep, 0, sizeof (expressionS));
811 save_in = input_line_pointer;
812 input_line_pointer = *str;
813 in_my_get_expression = 1;
814 seg = expression (ep);
815 in_my_get_expression = 0;
817 if (ep->X_op == O_illegal)
819 /* We found a bad expression in md_operand(). */
820 *str = input_line_pointer;
821 input_line_pointer = save_in;
822 if (inst.error == NULL)
823 inst.error = _("bad expression");
824 return 1;
827 #ifdef OBJ_AOUT
828 if (seg != absolute_section
829 && seg != text_section
830 && seg != data_section
831 && seg != bss_section
832 && seg != undefined_section)
834 inst.error = _("bad segment");
835 *str = input_line_pointer;
836 input_line_pointer = save_in;
837 return 1;
839 #endif
841 /* Get rid of any bignums now, so that we don't generate an error for which
842 we can't establish a line number later on. Big numbers are never valid
843 in instructions, which is where this routine is always called. */
844 if (prefix_mode != GE_OPT_PREFIX_BIG
845 && (ep->X_op == O_big
846 || (ep->X_add_symbol
847 && (walk_no_bignums (ep->X_add_symbol)
848 || (ep->X_op_symbol
849 && walk_no_bignums (ep->X_op_symbol))))))
851 inst.error = _("invalid constant");
852 *str = input_line_pointer;
853 input_line_pointer = save_in;
854 return 1;
857 *str = input_line_pointer;
858 input_line_pointer = save_in;
859 return 0;
862 /* Turn a string in input_line_pointer into a floating point constant
863 of type TYPE, and store the appropriate bytes in *LITP. The number
864 of LITTLENUMS emitted is stored in *SIZEP. An error message is
865 returned, or NULL on OK.
867 Note that fp constants aren't represent in the normal way on the ARM.
868 In big endian mode, things are as expected. However, in little endian
869 mode fp constants are big-endian word-wise, and little-endian byte-wise
870 within the words. For example, (double) 1.1 in big endian mode is
871 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
872 the byte sequence 99 99 f1 3f 9a 99 99 99.
874 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
876 char *
877 md_atof (int type, char * litP, int * sizeP)
879 int prec;
880 LITTLENUM_TYPE words[MAX_LITTLENUMS];
881 char *t;
882 int i;
884 switch (type)
886 case 'f':
887 case 'F':
888 case 's':
889 case 'S':
890 prec = 2;
891 break;
893 case 'd':
894 case 'D':
895 case 'r':
896 case 'R':
897 prec = 4;
898 break;
900 case 'x':
901 case 'X':
902 prec = 6;
903 break;
905 case 'p':
906 case 'P':
907 prec = 6;
908 break;
910 default:
911 *sizeP = 0;
912 return _("bad call to MD_ATOF()");
915 t = atof_ieee (input_line_pointer, type, words);
916 if (t)
917 input_line_pointer = t;
918 *sizeP = prec * 2;
920 if (target_big_endian)
922 for (i = 0; i < prec; i++)
924 md_number_to_chars (litP, (valueT) words[i], 2);
925 litP += 2;
928 else
930 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
931 for (i = prec - 1; i >= 0; i--)
933 md_number_to_chars (litP, (valueT) words[i], 2);
934 litP += 2;
936 else
937 /* For a 4 byte float the order of elements in `words' is 1 0.
938 For an 8 byte float the order is 1 0 3 2. */
939 for (i = 0; i < prec; i += 2)
941 md_number_to_chars (litP, (valueT) words[i + 1], 2);
942 md_number_to_chars (litP + 2, (valueT) words[i], 2);
943 litP += 4;
947 return 0;
950 /* We handle all bad expressions here, so that we can report the faulty
951 instruction in the error message. */
952 void
953 md_operand (expressionS * expr)
955 if (in_my_get_expression)
956 expr->X_op = O_illegal;
959 /* Immediate values. */
961 /* Generic immediate-value read function for use in directives.
962 Accepts anything that 'expression' can fold to a constant.
963 *val receives the number. */
964 #ifdef OBJ_ELF
965 static int
966 immediate_for_directive (int *val)
968 expressionS exp;
969 exp.X_op = O_illegal;
971 if (is_immediate_prefix (*input_line_pointer))
973 input_line_pointer++;
974 expression (&exp);
977 if (exp.X_op != O_constant)
979 as_bad (_("expected #constant"));
980 ignore_rest_of_line ();
981 return FAIL;
983 *val = exp.X_add_number;
984 return SUCCESS;
986 #endif
988 /* Register parsing. */
990 /* Generic register parser. CCP points to what should be the
991 beginning of a register name. If it is indeed a valid register
992 name, advance CCP over it and return the reg_entry structure;
993 otherwise return NULL. Does not issue diagnostics. */
995 static struct reg_entry *
996 arm_reg_parse_multi (char **ccp)
998 char *start = *ccp;
999 char *p;
1000 struct reg_entry *reg;
1002 #ifdef REGISTER_PREFIX
1003 if (*start != REGISTER_PREFIX)
1004 return NULL;
1005 start++;
1006 #endif
1007 #ifdef OPTIONAL_REGISTER_PREFIX
1008 if (*start == OPTIONAL_REGISTER_PREFIX)
1009 start++;
1010 #endif
1012 p = start;
1013 if (!ISALPHA (*p) || !is_name_beginner (*p))
1014 return NULL;
1017 p++;
1018 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1020 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1022 if (!reg)
1023 return NULL;
1025 *ccp = p;
1026 return reg;
1029 static int
1030 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1031 enum arm_reg_type type)
1033 /* Alternative syntaxes are accepted for a few register classes. */
1034 switch (type)
1036 case REG_TYPE_MVF:
1037 case REG_TYPE_MVD:
1038 case REG_TYPE_MVFX:
1039 case REG_TYPE_MVDX:
1040 /* Generic coprocessor register names are allowed for these. */
1041 if (reg && reg->type == REG_TYPE_CN)
1042 return reg->number;
1043 break;
1045 case REG_TYPE_CP:
1046 /* For backward compatibility, a bare number is valid here. */
1048 unsigned long processor = strtoul (start, ccp, 10);
1049 if (*ccp != start && processor <= 15)
1050 return processor;
1053 case REG_TYPE_MMXWC:
1054 /* WC includes WCG. ??? I'm not sure this is true for all
1055 instructions that take WC registers. */
1056 if (reg && reg->type == REG_TYPE_MMXWCG)
1057 return reg->number;
1058 break;
1060 default:
1061 break;
1064 return FAIL;
1067 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1068 return value is the register number or FAIL. */
1070 static int
1071 arm_reg_parse (char **ccp, enum arm_reg_type type)
1073 char *start = *ccp;
1074 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1075 int ret;
1077 /* Do not allow a scalar (reg+index) to parse as a register. */
1078 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1079 return FAIL;
1081 if (reg && reg->type == type)
1082 return reg->number;
1084 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1085 return ret;
1087 *ccp = start;
1088 return FAIL;
1091 /* Parse a Neon type specifier. *STR should point at the leading '.'
1092 character. Does no verification at this stage that the type fits the opcode
1093 properly. E.g.,
1095 .i32.i32.s16
1096 .s32.f32
1097 .u16
1099 Can all be legally parsed by this function.
1101 Fills in neon_type struct pointer with parsed information, and updates STR
1102 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1103 type, FAIL if not. */
1105 static int
1106 parse_neon_type (struct neon_type *type, char **str)
1108 char *ptr = *str;
1110 if (type)
1111 type->elems = 0;
1113 while (type->elems < NEON_MAX_TYPE_ELS)
1115 enum neon_el_type thistype = NT_untyped;
1116 unsigned thissize = -1u;
1118 if (*ptr != '.')
1119 break;
1121 ptr++;
1123 /* Just a size without an explicit type. */
1124 if (ISDIGIT (*ptr))
1125 goto parsesize;
1127 switch (TOLOWER (*ptr))
1129 case 'i': thistype = NT_integer; break;
1130 case 'f': thistype = NT_float; break;
1131 case 'p': thistype = NT_poly; break;
1132 case 's': thistype = NT_signed; break;
1133 case 'u': thistype = NT_unsigned; break;
1134 case 'd':
1135 thistype = NT_float;
1136 thissize = 64;
1137 ptr++;
1138 goto done;
1139 default:
1140 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1141 return FAIL;
1144 ptr++;
1146 /* .f is an abbreviation for .f32. */
1147 if (thistype == NT_float && !ISDIGIT (*ptr))
1148 thissize = 32;
1149 else
1151 parsesize:
1152 thissize = strtoul (ptr, &ptr, 10);
1154 if (thissize != 8 && thissize != 16 && thissize != 32
1155 && thissize != 64)
1157 as_bad (_("bad size %d in type specifier"), thissize);
1158 return FAIL;
1162 done:
1163 if (type)
1165 type->el[type->elems].type = thistype;
1166 type->el[type->elems].size = thissize;
1167 type->elems++;
1171 /* Empty/missing type is not a successful parse. */
1172 if (type->elems == 0)
1173 return FAIL;
1175 *str = ptr;
1177 return SUCCESS;
1180 /* Errors may be set multiple times during parsing or bit encoding
1181 (particularly in the Neon bits), but usually the earliest error which is set
1182 will be the most meaningful. Avoid overwriting it with later (cascading)
1183 errors by calling this function. */
1185 static void
1186 first_error (const char *err)
1188 if (!inst.error)
1189 inst.error = err;
1192 /* Parse a single type, e.g. ".s32", leading period included. */
1193 static int
1194 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1196 char *str = *ccp;
1197 struct neon_type optype;
1199 if (*str == '.')
1201 if (parse_neon_type (&optype, &str) == SUCCESS)
1203 if (optype.elems == 1)
1204 *vectype = optype.el[0];
1205 else
1207 first_error (_("only one type should be specified for operand"));
1208 return FAIL;
1211 else
1213 first_error (_("vector type expected"));
1214 return FAIL;
1217 else
1218 return FAIL;
1220 *ccp = str;
1222 return SUCCESS;
1225 /* Special meanings for indices (which have a range of 0-7), which will fit into
1226 a 4-bit integer. */
1228 #define NEON_ALL_LANES 15
1229 #define NEON_INTERLEAVE_LANES 14
1231 /* Parse either a register or a scalar, with an optional type. Return the
1232 register number, and optionally fill in the actual type of the register
1233 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1234 type/index information in *TYPEINFO. */
1236 static int
1237 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1238 enum arm_reg_type *rtype,
1239 struct neon_typed_alias *typeinfo)
1241 char *str = *ccp;
1242 struct reg_entry *reg = arm_reg_parse_multi (&str);
1243 struct neon_typed_alias atype;
1244 struct neon_type_el parsetype;
1246 atype.defined = 0;
1247 atype.index = -1;
1248 atype.eltype.type = NT_invtype;
1249 atype.eltype.size = -1;
1251 /* Try alternate syntax for some types of register. Note these are mutually
1252 exclusive with the Neon syntax extensions. */
1253 if (reg == NULL)
1255 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1256 if (altreg != FAIL)
1257 *ccp = str;
1258 if (typeinfo)
1259 *typeinfo = atype;
1260 return altreg;
1263 /* Undo polymorphism when a set of register types may be accepted. */
1264 if ((type == REG_TYPE_NDQ
1265 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1266 || (type == REG_TYPE_VFSD
1267 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1268 || (type == REG_TYPE_NSDQ
1269 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1270 || reg->type == REG_TYPE_NQ)))
1271 type = reg->type;
1273 if (type != reg->type)
1274 return FAIL;
1276 if (reg->neon)
1277 atype = *reg->neon;
1279 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1281 if ((atype.defined & NTA_HASTYPE) != 0)
1283 first_error (_("can't redefine type for operand"));
1284 return FAIL;
1286 atype.defined |= NTA_HASTYPE;
1287 atype.eltype = parsetype;
1290 if (skip_past_char (&str, '[') == SUCCESS)
1292 if (type != REG_TYPE_VFD)
1294 first_error (_("only D registers may be indexed"));
1295 return FAIL;
1298 if ((atype.defined & NTA_HASINDEX) != 0)
1300 first_error (_("can't change index for operand"));
1301 return FAIL;
1304 atype.defined |= NTA_HASINDEX;
1306 if (skip_past_char (&str, ']') == SUCCESS)
1307 atype.index = NEON_ALL_LANES;
1308 else
1310 expressionS exp;
1312 my_get_expression (&exp, &str, GE_NO_PREFIX);
1314 if (exp.X_op != O_constant)
1316 first_error (_("constant expression required"));
1317 return FAIL;
1320 if (skip_past_char (&str, ']') == FAIL)
1321 return FAIL;
1323 atype.index = exp.X_add_number;
1327 if (typeinfo)
1328 *typeinfo = atype;
1330 if (rtype)
1331 *rtype = type;
1333 *ccp = str;
1335 return reg->number;
1338 /* Like arm_reg_parse, but allow allow the following extra features:
1339 - If RTYPE is non-zero, return the (possibly restricted) type of the
1340 register (e.g. Neon double or quad reg when either has been requested).
1341 - If this is a Neon vector type with additional type information, fill
1342 in the struct pointed to by VECTYPE (if non-NULL).
1343 This function will fault on encountering a scalar.
1346 static int
1347 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1348 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1350 struct neon_typed_alias atype;
1351 char *str = *ccp;
1352 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1354 if (reg == FAIL)
1355 return FAIL;
1357 /* Do not allow a scalar (reg+index) to parse as a register. */
1358 if ((atype.defined & NTA_HASINDEX) != 0)
1360 first_error (_("register operand expected, but got scalar"));
1361 return FAIL;
1364 if (vectype)
1365 *vectype = atype.eltype;
1367 *ccp = str;
1369 return reg;
1372 #define NEON_SCALAR_REG(X) ((X) >> 4)
1373 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1375 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1376 have enough information to be able to do a good job bounds-checking. So, we
1377 just do easy checks here, and do further checks later. */
1379 static int
1380 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1382 int reg;
1383 char *str = *ccp;
1384 struct neon_typed_alias atype;
1386 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1388 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1389 return FAIL;
1391 if (atype.index == NEON_ALL_LANES)
1393 first_error (_("scalar must have an index"));
1394 return FAIL;
1396 else if (atype.index >= 64 / elsize)
1398 first_error (_("scalar index out of range"));
1399 return FAIL;
1402 if (type)
1403 *type = atype.eltype;
1405 *ccp = str;
1407 return reg * 16 + atype.index;
1410 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1411 static long
1412 parse_reg_list (char ** strp)
1414 char * str = * strp;
1415 long range = 0;
1416 int another_range;
1418 /* We come back here if we get ranges concatenated by '+' or '|'. */
1421 another_range = 0;
1423 if (*str == '{')
1425 int in_range = 0;
1426 int cur_reg = -1;
1428 str++;
1431 int reg;
1433 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1435 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1436 return FAIL;
1439 if (in_range)
1441 int i;
1443 if (reg <= cur_reg)
1445 first_error (_("bad range in register list"));
1446 return FAIL;
1449 for (i = cur_reg + 1; i < reg; i++)
1451 if (range & (1 << i))
1452 as_tsktsk
1453 (_("Warning: duplicated register (r%d) in register list"),
1455 else
1456 range |= 1 << i;
1458 in_range = 0;
1461 if (range & (1 << reg))
1462 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1463 reg);
1464 else if (reg <= cur_reg)
1465 as_tsktsk (_("Warning: register range not in ascending order"));
1467 range |= 1 << reg;
1468 cur_reg = reg;
1470 while (skip_past_comma (&str) != FAIL
1471 || (in_range = 1, *str++ == '-'));
1472 str--;
1474 if (*str++ != '}')
1476 first_error (_("missing `}'"));
1477 return FAIL;
1480 else
1482 expressionS expr;
1484 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1485 return FAIL;
1487 if (expr.X_op == O_constant)
1489 if (expr.X_add_number
1490 != (expr.X_add_number & 0x0000ffff))
1492 inst.error = _("invalid register mask");
1493 return FAIL;
1496 if ((range & expr.X_add_number) != 0)
1498 int regno = range & expr.X_add_number;
1500 regno &= -regno;
1501 regno = (1 << regno) - 1;
1502 as_tsktsk
1503 (_("Warning: duplicated register (r%d) in register list"),
1504 regno);
1507 range |= expr.X_add_number;
1509 else
1511 if (inst.reloc.type != 0)
1513 inst.error = _("expression too complex");
1514 return FAIL;
1517 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1518 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1519 inst.reloc.pc_rel = 0;
1523 if (*str == '|' || *str == '+')
1525 str++;
1526 another_range = 1;
1529 while (another_range);
1531 *strp = str;
1532 return range;
1535 /* Types of registers in a list. */
1537 enum reg_list_els
1539 REGLIST_VFP_S,
1540 REGLIST_VFP_D,
1541 REGLIST_NEON_D
1544 /* Parse a VFP register list. If the string is invalid return FAIL.
1545 Otherwise return the number of registers, and set PBASE to the first
1546 register. Parses registers of type ETYPE.
1547 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1548 - Q registers can be used to specify pairs of D registers
1549 - { } can be omitted from around a singleton register list
1550 FIXME: This is not implemented, as it would require backtracking in
1551 some cases, e.g.:
1552 vtbl.8 d3,d4,d5
1553 This could be done (the meaning isn't really ambiguous), but doesn't
1554 fit in well with the current parsing framework.
1555 - 32 D registers may be used (also true for VFPv3).
1556 FIXME: Types are ignored in these register lists, which is probably a
1557 bug. */
1559 static int
1560 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1562 char *str = *ccp;
1563 int base_reg;
1564 int new_base;
1565 enum arm_reg_type regtype = 0;
1566 int max_regs = 0;
1567 int count = 0;
1568 int warned = 0;
1569 unsigned long mask = 0;
1570 int i;
1572 if (*str != '{')
1574 inst.error = _("expecting {");
1575 return FAIL;
1578 str++;
1580 switch (etype)
1582 case REGLIST_VFP_S:
1583 regtype = REG_TYPE_VFS;
1584 max_regs = 32;
1585 break;
1587 case REGLIST_VFP_D:
1588 regtype = REG_TYPE_VFD;
1589 break;
1591 case REGLIST_NEON_D:
1592 regtype = REG_TYPE_NDQ;
1593 break;
1596 if (etype != REGLIST_VFP_S)
1598 /* VFPv3 allows 32 D registers. */
1599 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1601 max_regs = 32;
1602 if (thumb_mode)
1603 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1604 fpu_vfp_ext_v3);
1605 else
1606 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1607 fpu_vfp_ext_v3);
1609 else
1610 max_regs = 16;
1613 base_reg = max_regs;
1617 int setmask = 1, addregs = 1;
1619 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1621 if (new_base == FAIL)
1623 first_error (_(reg_expected_msgs[regtype]));
1624 return FAIL;
1627 if (new_base >= max_regs)
1629 first_error (_("register out of range in list"));
1630 return FAIL;
1633 /* Note: a value of 2 * n is returned for the register Q<n>. */
1634 if (regtype == REG_TYPE_NQ)
1636 setmask = 3;
1637 addregs = 2;
1640 if (new_base < base_reg)
1641 base_reg = new_base;
1643 if (mask & (setmask << new_base))
1645 first_error (_("invalid register list"));
1646 return FAIL;
1649 if ((mask >> new_base) != 0 && ! warned)
1651 as_tsktsk (_("register list not in ascending order"));
1652 warned = 1;
1655 mask |= setmask << new_base;
1656 count += addregs;
1658 if (*str == '-') /* We have the start of a range expression */
1660 int high_range;
1662 str++;
1664 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1665 == FAIL)
1667 inst.error = gettext (reg_expected_msgs[regtype]);
1668 return FAIL;
1671 if (high_range >= max_regs)
1673 first_error (_("register out of range in list"));
1674 return FAIL;
1677 if (regtype == REG_TYPE_NQ)
1678 high_range = high_range + 1;
1680 if (high_range <= new_base)
1682 inst.error = _("register range not in ascending order");
1683 return FAIL;
1686 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1688 if (mask & (setmask << new_base))
1690 inst.error = _("invalid register list");
1691 return FAIL;
1694 mask |= setmask << new_base;
1695 count += addregs;
1699 while (skip_past_comma (&str) != FAIL);
1701 str++;
1703 /* Sanity check -- should have raised a parse error above. */
1704 if (count == 0 || count > max_regs)
1705 abort ();
1707 *pbase = base_reg;
1709 /* Final test -- the registers must be consecutive. */
1710 mask >>= base_reg;
1711 for (i = 0; i < count; i++)
1713 if ((mask & (1u << i)) == 0)
1715 inst.error = _("non-contiguous register range");
1716 return FAIL;
1720 *ccp = str;
1722 return count;
1725 /* True if two alias types are the same. */
1727 static int
1728 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1730 if (!a && !b)
1731 return 1;
1733 if (!a || !b)
1734 return 0;
1736 if (a->defined != b->defined)
1737 return 0;
1739 if ((a->defined & NTA_HASTYPE) != 0
1740 && (a->eltype.type != b->eltype.type
1741 || a->eltype.size != b->eltype.size))
1742 return 0;
1744 if ((a->defined & NTA_HASINDEX) != 0
1745 && (a->index != b->index))
1746 return 0;
1748 return 1;
1751 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1752 The base register is put in *PBASE.
1753 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1754 the return value.
1755 The register stride (minus one) is put in bit 4 of the return value.
1756 Bits [6:5] encode the list length (minus one).
1757 The type of the list elements is put in *ELTYPE, if non-NULL. */
1759 #define NEON_LANE(X) ((X) & 0xf)
1760 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1761 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1763 static int
1764 parse_neon_el_struct_list (char **str, unsigned *pbase,
1765 struct neon_type_el *eltype)
1767 char *ptr = *str;
1768 int base_reg = -1;
1769 int reg_incr = -1;
1770 int count = 0;
1771 int lane = -1;
1772 int leading_brace = 0;
1773 enum arm_reg_type rtype = REG_TYPE_NDQ;
1774 int addregs = 1;
1775 const char *const incr_error = "register stride must be 1 or 2";
1776 const char *const type_error = "mismatched element/structure types in list";
1777 struct neon_typed_alias firsttype;
1779 if (skip_past_char (&ptr, '{') == SUCCESS)
1780 leading_brace = 1;
1784 struct neon_typed_alias atype;
1785 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1787 if (getreg == FAIL)
1789 first_error (_(reg_expected_msgs[rtype]));
1790 return FAIL;
1793 if (base_reg == -1)
1795 base_reg = getreg;
1796 if (rtype == REG_TYPE_NQ)
1798 reg_incr = 1;
1799 addregs = 2;
1801 firsttype = atype;
1803 else if (reg_incr == -1)
1805 reg_incr = getreg - base_reg;
1806 if (reg_incr < 1 || reg_incr > 2)
1808 first_error (_(incr_error));
1809 return FAIL;
1812 else if (getreg != base_reg + reg_incr * count)
1814 first_error (_(incr_error));
1815 return FAIL;
1818 if (!neon_alias_types_same (&atype, &firsttype))
1820 first_error (_(type_error));
1821 return FAIL;
1824 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1825 modes. */
1826 if (ptr[0] == '-')
1828 struct neon_typed_alias htype;
1829 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1830 if (lane == -1)
1831 lane = NEON_INTERLEAVE_LANES;
1832 else if (lane != NEON_INTERLEAVE_LANES)
1834 first_error (_(type_error));
1835 return FAIL;
1837 if (reg_incr == -1)
1838 reg_incr = 1;
1839 else if (reg_incr != 1)
1841 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1842 return FAIL;
1844 ptr++;
1845 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1846 if (hireg == FAIL)
1848 first_error (_(reg_expected_msgs[rtype]));
1849 return FAIL;
1851 if (!neon_alias_types_same (&htype, &firsttype))
1853 first_error (_(type_error));
1854 return FAIL;
1856 count += hireg + dregs - getreg;
1857 continue;
1860 /* If we're using Q registers, we can't use [] or [n] syntax. */
1861 if (rtype == REG_TYPE_NQ)
1863 count += 2;
1864 continue;
1867 if ((atype.defined & NTA_HASINDEX) != 0)
1869 if (lane == -1)
1870 lane = atype.index;
1871 else if (lane != atype.index)
1873 first_error (_(type_error));
1874 return FAIL;
1877 else if (lane == -1)
1878 lane = NEON_INTERLEAVE_LANES;
1879 else if (lane != NEON_INTERLEAVE_LANES)
1881 first_error (_(type_error));
1882 return FAIL;
1884 count++;
1886 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1888 /* No lane set by [x]. We must be interleaving structures. */
1889 if (lane == -1)
1890 lane = NEON_INTERLEAVE_LANES;
1892 /* Sanity check. */
1893 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1894 || (count > 1 && reg_incr == -1))
1896 first_error (_("error parsing element/structure list"));
1897 return FAIL;
1900 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1902 first_error (_("expected }"));
1903 return FAIL;
1906 if (reg_incr == -1)
1907 reg_incr = 1;
1909 if (eltype)
1910 *eltype = firsttype.eltype;
1912 *pbase = base_reg;
1913 *str = ptr;
1915 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1918 /* Parse an explicit relocation suffix on an expression. This is
1919 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1920 arm_reloc_hsh contains no entries, so this function can only
1921 succeed if there is no () after the word. Returns -1 on error,
1922 BFD_RELOC_UNUSED if there wasn't any suffix. */
1923 static int
1924 parse_reloc (char **str)
1926 struct reloc_entry *r;
1927 char *p, *q;
1929 if (**str != '(')
1930 return BFD_RELOC_UNUSED;
1932 p = *str + 1;
1933 q = p;
1935 while (*q && *q != ')' && *q != ',')
1936 q++;
1937 if (*q != ')')
1938 return -1;
1940 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1941 return -1;
1943 *str = q + 1;
1944 return r->reloc;
1947 /* Directives: register aliases. */
1949 static struct reg_entry *
1950 insert_reg_alias (char *str, int number, int type)
1952 struct reg_entry *new;
1953 const char *name;
1955 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1957 if (new->builtin)
1958 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1960 /* Only warn about a redefinition if it's not defined as the
1961 same register. */
1962 else if (new->number != number || new->type != type)
1963 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1965 return 0;
1968 name = xstrdup (str);
1969 new = xmalloc (sizeof (struct reg_entry));
1971 new->name = name;
1972 new->number = number;
1973 new->type = type;
1974 new->builtin = FALSE;
1975 new->neon = NULL;
1977 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1978 abort ();
1980 return new;
1983 static void
1984 insert_neon_reg_alias (char *str, int number, int type,
1985 struct neon_typed_alias *atype)
1987 struct reg_entry *reg = insert_reg_alias (str, number, type);
1989 if (!reg)
1991 first_error (_("attempt to redefine typed alias"));
1992 return;
1995 if (atype)
1997 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
1998 *reg->neon = *atype;
2002 /* Look for the .req directive. This is of the form:
2004 new_register_name .req existing_register_name
2006 If we find one, or if it looks sufficiently like one that we want to
2007 handle any error here, return non-zero. Otherwise return zero. */
2009 static int
2010 create_register_alias (char * newname, char *p)
2012 struct reg_entry *old;
2013 char *oldname, *nbuf;
2014 size_t nlen;
2016 /* The input scrubber ensures that whitespace after the mnemonic is
2017 collapsed to single spaces. */
2018 oldname = p;
2019 if (strncmp (oldname, " .req ", 6) != 0)
2020 return 0;
2022 oldname += 6;
2023 if (*oldname == '\0')
2024 return 0;
2026 old = hash_find (arm_reg_hsh, oldname);
2027 if (!old)
2029 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2030 return 1;
2033 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2034 the desired alias name, and p points to its end. If not, then
2035 the desired alias name is in the global original_case_string. */
2036 #ifdef TC_CASE_SENSITIVE
2037 nlen = p - newname;
2038 #else
2039 newname = original_case_string;
2040 nlen = strlen (newname);
2041 #endif
2043 nbuf = alloca (nlen + 1);
2044 memcpy (nbuf, newname, nlen);
2045 nbuf[nlen] = '\0';
2047 /* Create aliases under the new name as stated; an all-lowercase
2048 version of the new name; and an all-uppercase version of the new
2049 name. */
2050 insert_reg_alias (nbuf, old->number, old->type);
2052 for (p = nbuf; *p; p++)
2053 *p = TOUPPER (*p);
2055 if (strncmp (nbuf, newname, nlen))
2056 insert_reg_alias (nbuf, old->number, old->type);
2058 for (p = nbuf; *p; p++)
2059 *p = TOLOWER (*p);
2061 if (strncmp (nbuf, newname, nlen))
2062 insert_reg_alias (nbuf, old->number, old->type);
2064 return 1;
2067 /* Create a Neon typed/indexed register alias using directives, e.g.:
2068 X .dn d5.s32[1]
2069 Y .qn 6.s16
2070 Z .dn d7
2071 T .dn Z[0]
2072 These typed registers can be used instead of the types specified after the
2073 Neon mnemonic, so long as all operands given have types. Types can also be
2074 specified directly, e.g.:
2075 vadd d0.s32, d1.s32, d2.s32
2078 static int
2079 create_neon_reg_alias (char *newname, char *p)
2081 enum arm_reg_type basetype;
2082 struct reg_entry *basereg;
2083 struct reg_entry mybasereg;
2084 struct neon_type ntype;
2085 struct neon_typed_alias typeinfo;
2086 char *namebuf, *nameend;
2087 int namelen;
2089 typeinfo.defined = 0;
2090 typeinfo.eltype.type = NT_invtype;
2091 typeinfo.eltype.size = -1;
2092 typeinfo.index = -1;
2094 nameend = p;
2096 if (strncmp (p, " .dn ", 5) == 0)
2097 basetype = REG_TYPE_VFD;
2098 else if (strncmp (p, " .qn ", 5) == 0)
2099 basetype = REG_TYPE_NQ;
2100 else
2101 return 0;
2103 p += 5;
2105 if (*p == '\0')
2106 return 0;
2108 basereg = arm_reg_parse_multi (&p);
2110 if (basereg && basereg->type != basetype)
2112 as_bad (_("bad type for register"));
2113 return 0;
2116 if (basereg == NULL)
2118 expressionS exp;
2119 /* Try parsing as an integer. */
2120 my_get_expression (&exp, &p, GE_NO_PREFIX);
2121 if (exp.X_op != O_constant)
2123 as_bad (_("expression must be constant"));
2124 return 0;
2126 basereg = &mybasereg;
2127 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2128 : exp.X_add_number;
2129 basereg->neon = 0;
2132 if (basereg->neon)
2133 typeinfo = *basereg->neon;
2135 if (parse_neon_type (&ntype, &p) == SUCCESS)
2137 /* We got a type. */
2138 if (typeinfo.defined & NTA_HASTYPE)
2140 as_bad (_("can't redefine the type of a register alias"));
2141 return 0;
2144 typeinfo.defined |= NTA_HASTYPE;
2145 if (ntype.elems != 1)
2147 as_bad (_("you must specify a single type only"));
2148 return 0;
2150 typeinfo.eltype = ntype.el[0];
2153 if (skip_past_char (&p, '[') == SUCCESS)
2155 expressionS exp;
2156 /* We got a scalar index. */
2158 if (typeinfo.defined & NTA_HASINDEX)
2160 as_bad (_("can't redefine the index of a scalar alias"));
2161 return 0;
2164 my_get_expression (&exp, &p, GE_NO_PREFIX);
2166 if (exp.X_op != O_constant)
2168 as_bad (_("scalar index must be constant"));
2169 return 0;
2172 typeinfo.defined |= NTA_HASINDEX;
2173 typeinfo.index = exp.X_add_number;
2175 if (skip_past_char (&p, ']') == FAIL)
2177 as_bad (_("expecting ]"));
2178 return 0;
2182 namelen = nameend - newname;
2183 namebuf = alloca (namelen + 1);
2184 strncpy (namebuf, newname, namelen);
2185 namebuf[namelen] = '\0';
2187 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2188 typeinfo.defined != 0 ? &typeinfo : NULL);
2190 /* Insert name in all uppercase. */
2191 for (p = namebuf; *p; p++)
2192 *p = TOUPPER (*p);
2194 if (strncmp (namebuf, newname, namelen))
2195 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2196 typeinfo.defined != 0 ? &typeinfo : NULL);
2198 /* Insert name in all lowercase. */
2199 for (p = namebuf; *p; p++)
2200 *p = TOLOWER (*p);
2202 if (strncmp (namebuf, newname, namelen))
2203 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2204 typeinfo.defined != 0 ? &typeinfo : NULL);
2206 return 1;
2209 /* Should never be called, as .req goes between the alias and the
2210 register name, not at the beginning of the line. */
2211 static void
2212 s_req (int a ATTRIBUTE_UNUSED)
2214 as_bad (_("invalid syntax for .req directive"));
2217 static void
2218 s_dn (int a ATTRIBUTE_UNUSED)
2220 as_bad (_("invalid syntax for .dn directive"));
2223 static void
2224 s_qn (int a ATTRIBUTE_UNUSED)
2226 as_bad (_("invalid syntax for .qn directive"));
2229 /* The .unreq directive deletes an alias which was previously defined
2230 by .req. For example:
2232 my_alias .req r11
2233 .unreq my_alias */
2235 static void
2236 s_unreq (int a ATTRIBUTE_UNUSED)
2238 char * name;
2239 char saved_char;
2241 name = input_line_pointer;
2243 while (*input_line_pointer != 0
2244 && *input_line_pointer != ' '
2245 && *input_line_pointer != '\n')
2246 ++input_line_pointer;
2248 saved_char = *input_line_pointer;
2249 *input_line_pointer = 0;
2251 if (!*name)
2252 as_bad (_("invalid syntax for .unreq directive"));
2253 else
2255 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2257 if (!reg)
2258 as_bad (_("unknown register alias '%s'"), name);
2259 else if (reg->builtin)
2260 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2261 name);
2262 else
2264 hash_delete (arm_reg_hsh, name);
2265 free ((char *) reg->name);
2266 if (reg->neon)
2267 free (reg->neon);
2268 free (reg);
2272 *input_line_pointer = saved_char;
2273 demand_empty_rest_of_line ();
2276 /* Directives: Instruction set selection. */
2278 #ifdef OBJ_ELF
2279 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2280 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2281 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2282 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2284 static enum mstate mapstate = MAP_UNDEFINED;
2286 static void
2287 mapping_state (enum mstate state)
2289 symbolS * symbolP;
2290 const char * symname;
2291 int type;
2293 if (mapstate == state)
2294 /* The mapping symbol has already been emitted.
2295 There is nothing else to do. */
2296 return;
2298 mapstate = state;
2300 switch (state)
2302 case MAP_DATA:
2303 symname = "$d";
2304 type = BSF_NO_FLAGS;
2305 break;
2306 case MAP_ARM:
2307 symname = "$a";
2308 type = BSF_NO_FLAGS;
2309 break;
2310 case MAP_THUMB:
2311 symname = "$t";
2312 type = BSF_NO_FLAGS;
2313 break;
2314 case MAP_UNDEFINED:
2315 return;
2316 default:
2317 abort ();
2320 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2322 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2323 symbol_table_insert (symbolP);
2324 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2326 switch (state)
2328 case MAP_ARM:
2329 THUMB_SET_FUNC (symbolP, 0);
2330 ARM_SET_THUMB (symbolP, 0);
2331 ARM_SET_INTERWORK (symbolP, support_interwork);
2332 break;
2334 case MAP_THUMB:
2335 THUMB_SET_FUNC (symbolP, 1);
2336 ARM_SET_THUMB (symbolP, 1);
2337 ARM_SET_INTERWORK (symbolP, support_interwork);
2338 break;
2340 case MAP_DATA:
2341 default:
2342 return;
2345 #else
2346 #define mapping_state(x) /* nothing */
2347 #endif
2349 /* Find the real, Thumb encoded start of a Thumb function. */
2351 static symbolS *
2352 find_real_start (symbolS * symbolP)
2354 char * real_start;
2355 const char * name = S_GET_NAME (symbolP);
2356 symbolS * new_target;
2358 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2359 #define STUB_NAME ".real_start_of"
2361 if (name == NULL)
2362 abort ();
2364 /* The compiler may generate BL instructions to local labels because
2365 it needs to perform a branch to a far away location. These labels
2366 do not have a corresponding ".real_start_of" label. We check
2367 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2368 the ".real_start_of" convention for nonlocal branches. */
2369 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2370 return symbolP;
2372 real_start = ACONCAT ((STUB_NAME, name, NULL));
2373 new_target = symbol_find (real_start);
2375 if (new_target == NULL)
2377 as_warn ("Failed to find real start of function: %s\n", name);
2378 new_target = symbolP;
2381 return new_target;
2384 static void
2385 opcode_select (int width)
2387 switch (width)
2389 case 16:
2390 if (! thumb_mode)
2392 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2393 as_bad (_("selected processor does not support THUMB opcodes"));
2395 thumb_mode = 1;
2396 /* No need to force the alignment, since we will have been
2397 coming from ARM mode, which is word-aligned. */
2398 record_alignment (now_seg, 1);
2400 mapping_state (MAP_THUMB);
2401 break;
2403 case 32:
2404 if (thumb_mode)
2406 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2407 as_bad (_("selected processor does not support ARM opcodes"));
2409 thumb_mode = 0;
2411 if (!need_pass_2)
2412 frag_align (2, 0, 0);
2414 record_alignment (now_seg, 1);
2416 mapping_state (MAP_ARM);
2417 break;
2419 default:
2420 as_bad (_("invalid instruction size selected (%d)"), width);
2424 static void
2425 s_arm (int ignore ATTRIBUTE_UNUSED)
2427 opcode_select (32);
2428 demand_empty_rest_of_line ();
2431 static void
2432 s_thumb (int ignore ATTRIBUTE_UNUSED)
2434 opcode_select (16);
2435 demand_empty_rest_of_line ();
2438 static void
2439 s_code (int unused ATTRIBUTE_UNUSED)
2441 int temp;
2443 temp = get_absolute_expression ();
2444 switch (temp)
2446 case 16:
2447 case 32:
2448 opcode_select (temp);
2449 break;
2451 default:
2452 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2456 static void
2457 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2459 /* If we are not already in thumb mode go into it, EVEN if
2460 the target processor does not support thumb instructions.
2461 This is used by gcc/config/arm/lib1funcs.asm for example
2462 to compile interworking support functions even if the
2463 target processor should not support interworking. */
2464 if (! thumb_mode)
2466 thumb_mode = 2;
2467 record_alignment (now_seg, 1);
2470 demand_empty_rest_of_line ();
2473 static void
2474 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2476 s_thumb (0);
2478 /* The following label is the name/address of the start of a Thumb function.
2479 We need to know this for the interworking support. */
2480 label_is_thumb_function_name = TRUE;
2483 /* Perform a .set directive, but also mark the alias as
2484 being a thumb function. */
2486 static void
2487 s_thumb_set (int equiv)
2489 /* XXX the following is a duplicate of the code for s_set() in read.c
2490 We cannot just call that code as we need to get at the symbol that
2491 is created. */
2492 char * name;
2493 char delim;
2494 char * end_name;
2495 symbolS * symbolP;
2497 /* Especial apologies for the random logic:
2498 This just grew, and could be parsed much more simply!
2499 Dean - in haste. */
2500 name = input_line_pointer;
2501 delim = get_symbol_end ();
2502 end_name = input_line_pointer;
2503 *end_name = delim;
2505 if (*input_line_pointer != ',')
2507 *end_name = 0;
2508 as_bad (_("expected comma after name \"%s\""), name);
2509 *end_name = delim;
2510 ignore_rest_of_line ();
2511 return;
2514 input_line_pointer++;
2515 *end_name = 0;
2517 if (name[0] == '.' && name[1] == '\0')
2519 /* XXX - this should not happen to .thumb_set. */
2520 abort ();
2523 if ((symbolP = symbol_find (name)) == NULL
2524 && (symbolP = md_undefined_symbol (name)) == NULL)
2526 #ifndef NO_LISTING
2527 /* When doing symbol listings, play games with dummy fragments living
2528 outside the normal fragment chain to record the file and line info
2529 for this symbol. */
2530 if (listing & LISTING_SYMBOLS)
2532 extern struct list_info_struct * listing_tail;
2533 fragS * dummy_frag = xmalloc (sizeof (fragS));
2535 memset (dummy_frag, 0, sizeof (fragS));
2536 dummy_frag->fr_type = rs_fill;
2537 dummy_frag->line = listing_tail;
2538 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2539 dummy_frag->fr_symbol = symbolP;
2541 else
2542 #endif
2543 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2545 #ifdef OBJ_COFF
2546 /* "set" symbols are local unless otherwise specified. */
2547 SF_SET_LOCAL (symbolP);
2548 #endif /* OBJ_COFF */
2549 } /* Make a new symbol. */
2551 symbol_table_insert (symbolP);
2553 * end_name = delim;
2555 if (equiv
2556 && S_IS_DEFINED (symbolP)
2557 && S_GET_SEGMENT (symbolP) != reg_section)
2558 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2560 pseudo_set (symbolP);
2562 demand_empty_rest_of_line ();
2564 /* XXX Now we come to the Thumb specific bit of code. */
2566 THUMB_SET_FUNC (symbolP, 1);
2567 ARM_SET_THUMB (symbolP, 1);
2568 #if defined OBJ_ELF || defined OBJ_COFF
2569 ARM_SET_INTERWORK (symbolP, support_interwork);
2570 #endif
2573 /* Directives: Mode selection. */
2575 /* .syntax [unified|divided] - choose the new unified syntax
2576 (same for Arm and Thumb encoding, modulo slight differences in what
2577 can be represented) or the old divergent syntax for each mode. */
2578 static void
2579 s_syntax (int unused ATTRIBUTE_UNUSED)
2581 char *name, delim;
2583 name = input_line_pointer;
2584 delim = get_symbol_end ();
2586 if (!strcasecmp (name, "unified"))
2587 unified_syntax = TRUE;
2588 else if (!strcasecmp (name, "divided"))
2589 unified_syntax = FALSE;
2590 else
2592 as_bad (_("unrecognized syntax mode \"%s\""), name);
2593 return;
2595 *input_line_pointer = delim;
2596 demand_empty_rest_of_line ();
2599 /* Directives: sectioning and alignment. */
2601 /* Same as s_align_ptwo but align 0 => align 2. */
2603 static void
2604 s_align (int unused ATTRIBUTE_UNUSED)
2606 int temp;
2607 long temp_fill;
2608 long max_alignment = 15;
2610 temp = get_absolute_expression ();
2611 if (temp > max_alignment)
2612 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2613 else if (temp < 0)
2615 as_bad (_("alignment negative. 0 assumed."));
2616 temp = 0;
2619 if (*input_line_pointer == ',')
2621 input_line_pointer++;
2622 temp_fill = get_absolute_expression ();
2624 else
2625 temp_fill = 0;
2627 if (!temp)
2628 temp = 2;
2630 /* Only make a frag if we HAVE to. */
2631 if (temp && !need_pass_2)
2632 frag_align (temp, (int) temp_fill, 0);
2633 demand_empty_rest_of_line ();
2635 record_alignment (now_seg, temp);
2638 static void
2639 s_bss (int ignore ATTRIBUTE_UNUSED)
2641 /* We don't support putting frags in the BSS segment, we fake it by
2642 marking in_bss, then looking at s_skip for clues. */
2643 subseg_set (bss_section, 0);
2644 demand_empty_rest_of_line ();
2645 mapping_state (MAP_DATA);
2648 static void
2649 s_even (int ignore ATTRIBUTE_UNUSED)
2651 /* Never make frag if expect extra pass. */
2652 if (!need_pass_2)
2653 frag_align (1, 0, 0);
2655 record_alignment (now_seg, 1);
2657 demand_empty_rest_of_line ();
2660 /* Directives: Literal pools. */
2662 static literal_pool *
2663 find_literal_pool (void)
2665 literal_pool * pool;
2667 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2669 if (pool->section == now_seg
2670 && pool->sub_section == now_subseg)
2671 break;
2674 return pool;
2677 static literal_pool *
2678 find_or_make_literal_pool (void)
2680 /* Next literal pool ID number. */
2681 static unsigned int latest_pool_num = 1;
2682 literal_pool * pool;
2684 pool = find_literal_pool ();
2686 if (pool == NULL)
2688 /* Create a new pool. */
2689 pool = xmalloc (sizeof (* pool));
2690 if (! pool)
2691 return NULL;
2693 pool->next_free_entry = 0;
2694 pool->section = now_seg;
2695 pool->sub_section = now_subseg;
2696 pool->next = list_of_pools;
2697 pool->symbol = NULL;
2699 /* Add it to the list. */
2700 list_of_pools = pool;
2703 /* New pools, and emptied pools, will have a NULL symbol. */
2704 if (pool->symbol == NULL)
2706 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2707 (valueT) 0, &zero_address_frag);
2708 pool->id = latest_pool_num ++;
2711 /* Done. */
2712 return pool;
2715 /* Add the literal in the global 'inst'
2716 structure to the relevent literal pool. */
2718 static int
2719 add_to_lit_pool (void)
2721 literal_pool * pool;
2722 unsigned int entry;
2724 pool = find_or_make_literal_pool ();
2726 /* Check if this literal value is already in the pool. */
2727 for (entry = 0; entry < pool->next_free_entry; entry ++)
2729 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2730 && (inst.reloc.exp.X_op == O_constant)
2731 && (pool->literals[entry].X_add_number
2732 == inst.reloc.exp.X_add_number)
2733 && (pool->literals[entry].X_unsigned
2734 == inst.reloc.exp.X_unsigned))
2735 break;
2737 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2738 && (inst.reloc.exp.X_op == O_symbol)
2739 && (pool->literals[entry].X_add_number
2740 == inst.reloc.exp.X_add_number)
2741 && (pool->literals[entry].X_add_symbol
2742 == inst.reloc.exp.X_add_symbol)
2743 && (pool->literals[entry].X_op_symbol
2744 == inst.reloc.exp.X_op_symbol))
2745 break;
2748 /* Do we need to create a new entry? */
2749 if (entry == pool->next_free_entry)
2751 if (entry >= MAX_LITERAL_POOL_SIZE)
2753 inst.error = _("literal pool overflow");
2754 return FAIL;
2757 pool->literals[entry] = inst.reloc.exp;
2758 pool->next_free_entry += 1;
2761 inst.reloc.exp.X_op = O_symbol;
2762 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2763 inst.reloc.exp.X_add_symbol = pool->symbol;
2765 return SUCCESS;
2768 /* Can't use symbol_new here, so have to create a symbol and then at
2769 a later date assign it a value. Thats what these functions do. */
2771 static void
2772 symbol_locate (symbolS * symbolP,
2773 const char * name, /* It is copied, the caller can modify. */
2774 segT segment, /* Segment identifier (SEG_<something>). */
2775 valueT valu, /* Symbol value. */
2776 fragS * frag) /* Associated fragment. */
2778 unsigned int name_length;
2779 char * preserved_copy_of_name;
2781 name_length = strlen (name) + 1; /* +1 for \0. */
2782 obstack_grow (&notes, name, name_length);
2783 preserved_copy_of_name = obstack_finish (&notes);
2785 #ifdef tc_canonicalize_symbol_name
2786 preserved_copy_of_name =
2787 tc_canonicalize_symbol_name (preserved_copy_of_name);
2788 #endif
2790 S_SET_NAME (symbolP, preserved_copy_of_name);
2792 S_SET_SEGMENT (symbolP, segment);
2793 S_SET_VALUE (symbolP, valu);
2794 symbol_clear_list_pointers (symbolP);
2796 symbol_set_frag (symbolP, frag);
2798 /* Link to end of symbol chain. */
2800 extern int symbol_table_frozen;
2802 if (symbol_table_frozen)
2803 abort ();
2806 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2808 obj_symbol_new_hook (symbolP);
2810 #ifdef tc_symbol_new_hook
2811 tc_symbol_new_hook (symbolP);
2812 #endif
2814 #ifdef DEBUG_SYMS
2815 verify_symbol_chain (symbol_rootP, symbol_lastP);
2816 #endif /* DEBUG_SYMS */
2820 static void
2821 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2823 unsigned int entry;
2824 literal_pool * pool;
2825 char sym_name[20];
2827 pool = find_literal_pool ();
2828 if (pool == NULL
2829 || pool->symbol == NULL
2830 || pool->next_free_entry == 0)
2831 return;
2833 mapping_state (MAP_DATA);
2835 /* Align pool as you have word accesses.
2836 Only make a frag if we have to. */
2837 if (!need_pass_2)
2838 frag_align (2, 0, 0);
2840 record_alignment (now_seg, 2);
2842 sprintf (sym_name, "$$lit_\002%x", pool->id);
2844 symbol_locate (pool->symbol, sym_name, now_seg,
2845 (valueT) frag_now_fix (), frag_now);
2846 symbol_table_insert (pool->symbol);
2848 ARM_SET_THUMB (pool->symbol, thumb_mode);
2850 #if defined OBJ_COFF || defined OBJ_ELF
2851 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2852 #endif
2854 for (entry = 0; entry < pool->next_free_entry; entry ++)
2855 /* First output the expression in the instruction to the pool. */
2856 emit_expr (&(pool->literals[entry]), 4); /* .word */
2858 /* Mark the pool as empty. */
2859 pool->next_free_entry = 0;
2860 pool->symbol = NULL;
2863 #ifdef OBJ_ELF
2864 /* Forward declarations for functions below, in the MD interface
2865 section. */
2866 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2867 static valueT create_unwind_entry (int);
2868 static void start_unwind_section (const segT, int);
2869 static void add_unwind_opcode (valueT, int);
2870 static void flush_pending_unwind (void);
2872 /* Directives: Data. */
2874 static void
2875 s_arm_elf_cons (int nbytes)
2877 expressionS exp;
2879 #ifdef md_flush_pending_output
2880 md_flush_pending_output ();
2881 #endif
2883 if (is_it_end_of_statement ())
2885 demand_empty_rest_of_line ();
2886 return;
2889 #ifdef md_cons_align
2890 md_cons_align (nbytes);
2891 #endif
2893 mapping_state (MAP_DATA);
2896 int reloc;
2897 char *base = input_line_pointer;
2899 expression (& exp);
2901 if (exp.X_op != O_symbol)
2902 emit_expr (&exp, (unsigned int) nbytes);
2903 else
2905 char *before_reloc = input_line_pointer;
2906 reloc = parse_reloc (&input_line_pointer);
2907 if (reloc == -1)
2909 as_bad (_("unrecognized relocation suffix"));
2910 ignore_rest_of_line ();
2911 return;
2913 else if (reloc == BFD_RELOC_UNUSED)
2914 emit_expr (&exp, (unsigned int) nbytes);
2915 else
2917 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2918 int size = bfd_get_reloc_size (howto);
2920 if (reloc == BFD_RELOC_ARM_PLT32)
2922 as_bad (_("(plt) is only valid on branch targets"));
2923 reloc = BFD_RELOC_UNUSED;
2924 size = 0;
2927 if (size > nbytes)
2928 as_bad (_("%s relocations do not fit in %d bytes"),
2929 howto->name, nbytes);
2930 else
2932 /* We've parsed an expression stopping at O_symbol.
2933 But there may be more expression left now that we
2934 have parsed the relocation marker. Parse it again.
2935 XXX Surely there is a cleaner way to do this. */
2936 char *p = input_line_pointer;
2937 int offset;
2938 char *save_buf = alloca (input_line_pointer - base);
2939 memcpy (save_buf, base, input_line_pointer - base);
2940 memmove (base + (input_line_pointer - before_reloc),
2941 base, before_reloc - base);
2943 input_line_pointer = base + (input_line_pointer-before_reloc);
2944 expression (&exp);
2945 memcpy (base, save_buf, p - base);
2947 offset = nbytes - size;
2948 p = frag_more ((int) nbytes);
2949 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2950 size, &exp, 0, reloc);
2955 while (*input_line_pointer++ == ',');
2957 /* Put terminator back into stream. */
2958 input_line_pointer --;
2959 demand_empty_rest_of_line ();
2963 /* Parse a .rel31 directive. */
2965 static void
2966 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2968 expressionS exp;
2969 char *p;
2970 valueT highbit;
2972 highbit = 0;
2973 if (*input_line_pointer == '1')
2974 highbit = 0x80000000;
2975 else if (*input_line_pointer != '0')
2976 as_bad (_("expected 0 or 1"));
2978 input_line_pointer++;
2979 if (*input_line_pointer != ',')
2980 as_bad (_("missing comma"));
2981 input_line_pointer++;
2983 #ifdef md_flush_pending_output
2984 md_flush_pending_output ();
2985 #endif
2987 #ifdef md_cons_align
2988 md_cons_align (4);
2989 #endif
2991 mapping_state (MAP_DATA);
2993 expression (&exp);
2995 p = frag_more (4);
2996 md_number_to_chars (p, highbit, 4);
2997 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2998 BFD_RELOC_ARM_PREL31);
3000 demand_empty_rest_of_line ();
3003 /* Directives: AEABI stack-unwind tables. */
3005 /* Parse an unwind_fnstart directive. Simply records the current location. */
3007 static void
3008 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3010 demand_empty_rest_of_line ();
3011 /* Mark the start of the function. */
3012 unwind.proc_start = expr_build_dot ();
3014 /* Reset the rest of the unwind info. */
3015 unwind.opcode_count = 0;
3016 unwind.table_entry = NULL;
3017 unwind.personality_routine = NULL;
3018 unwind.personality_index = -1;
3019 unwind.frame_size = 0;
3020 unwind.fp_offset = 0;
3021 unwind.fp_reg = 13;
3022 unwind.fp_used = 0;
3023 unwind.sp_restored = 0;
3027 /* Parse a handlerdata directive. Creates the exception handling table entry
3028 for the function. */
3030 static void
3031 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3033 demand_empty_rest_of_line ();
3034 if (unwind.table_entry)
3035 as_bad (_("dupicate .handlerdata directive"));
3037 create_unwind_entry (1);
3040 /* Parse an unwind_fnend directive. Generates the index table entry. */
3042 static void
3043 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3045 long where;
3046 char *ptr;
3047 valueT val;
3049 demand_empty_rest_of_line ();
3051 /* Add eh table entry. */
3052 if (unwind.table_entry == NULL)
3053 val = create_unwind_entry (0);
3054 else
3055 val = 0;
3057 /* Add index table entry. This is two words. */
3058 start_unwind_section (unwind.saved_seg, 1);
3059 frag_align (2, 0, 0);
3060 record_alignment (now_seg, 2);
3062 ptr = frag_more (8);
3063 where = frag_now_fix () - 8;
3065 /* Self relative offset of the function start. */
3066 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3067 BFD_RELOC_ARM_PREL31);
3069 /* Indicate dependency on EHABI-defined personality routines to the
3070 linker, if it hasn't been done already. */
3071 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3072 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3074 static const char *const name[] = {
3075 "__aeabi_unwind_cpp_pr0",
3076 "__aeabi_unwind_cpp_pr1",
3077 "__aeabi_unwind_cpp_pr2"
3079 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3080 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3081 marked_pr_dependency |= 1 << unwind.personality_index;
3082 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3083 = marked_pr_dependency;
3086 if (val)
3087 /* Inline exception table entry. */
3088 md_number_to_chars (ptr + 4, val, 4);
3089 else
3090 /* Self relative offset of the table entry. */
3091 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3092 BFD_RELOC_ARM_PREL31);
3094 /* Restore the original section. */
3095 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3099 /* Parse an unwind_cantunwind directive. */
3101 static void
3102 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3104 demand_empty_rest_of_line ();
3105 if (unwind.personality_routine || unwind.personality_index != -1)
3106 as_bad (_("personality routine specified for cantunwind frame"));
3108 unwind.personality_index = -2;
3112 /* Parse a personalityindex directive. */
3114 static void
3115 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3117 expressionS exp;
3119 if (unwind.personality_routine || unwind.personality_index != -1)
3120 as_bad (_("duplicate .personalityindex directive"));
3122 expression (&exp);
3124 if (exp.X_op != O_constant
3125 || exp.X_add_number < 0 || exp.X_add_number > 15)
3127 as_bad (_("bad personality routine number"));
3128 ignore_rest_of_line ();
3129 return;
3132 unwind.personality_index = exp.X_add_number;
3134 demand_empty_rest_of_line ();
3138 /* Parse a personality directive. */
3140 static void
3141 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3143 char *name, *p, c;
3145 if (unwind.personality_routine || unwind.personality_index != -1)
3146 as_bad (_("duplicate .personality directive"));
3148 name = input_line_pointer;
3149 c = get_symbol_end ();
3150 p = input_line_pointer;
3151 unwind.personality_routine = symbol_find_or_make (name);
3152 *p = c;
3153 demand_empty_rest_of_line ();
3157 /* Parse a directive saving core registers. */
3159 static void
3160 s_arm_unwind_save_core (void)
3162 valueT op;
3163 long range;
3164 int n;
3166 range = parse_reg_list (&input_line_pointer);
3167 if (range == FAIL)
3169 as_bad (_("expected register list"));
3170 ignore_rest_of_line ();
3171 return;
3174 demand_empty_rest_of_line ();
3176 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3177 into .unwind_save {..., sp...}. We aren't bothered about the value of
3178 ip because it is clobbered by calls. */
3179 if (unwind.sp_restored && unwind.fp_reg == 12
3180 && (range & 0x3000) == 0x1000)
3182 unwind.opcode_count--;
3183 unwind.sp_restored = 0;
3184 range = (range | 0x2000) & ~0x1000;
3185 unwind.pending_offset = 0;
3188 /* Pop r4-r15. */
3189 if (range & 0xfff0)
3191 /* See if we can use the short opcodes. These pop a block of up to 8
3192 registers starting with r4, plus maybe r14. */
3193 for (n = 0; n < 8; n++)
3195 /* Break at the first non-saved register. */
3196 if ((range & (1 << (n + 4))) == 0)
3197 break;
3199 /* See if there are any other bits set. */
3200 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3202 /* Use the long form. */
3203 op = 0x8000 | ((range >> 4) & 0xfff);
3204 add_unwind_opcode (op, 2);
3206 else
3208 /* Use the short form. */
3209 if (range & 0x4000)
3210 op = 0xa8; /* Pop r14. */
3211 else
3212 op = 0xa0; /* Do not pop r14. */
3213 op |= (n - 1);
3214 add_unwind_opcode (op, 1);
3218 /* Pop r0-r3. */
3219 if (range & 0xf)
3221 op = 0xb100 | (range & 0xf);
3222 add_unwind_opcode (op, 2);
3225 /* Record the number of bytes pushed. */
3226 for (n = 0; n < 16; n++)
3228 if (range & (1 << n))
3229 unwind.frame_size += 4;
3234 /* Parse a directive saving FPA registers. */
3236 static void
3237 s_arm_unwind_save_fpa (int reg)
3239 expressionS exp;
3240 int num_regs;
3241 valueT op;
3243 /* Get Number of registers to transfer. */
3244 if (skip_past_comma (&input_line_pointer) != FAIL)
3245 expression (&exp);
3246 else
3247 exp.X_op = O_illegal;
3249 if (exp.X_op != O_constant)
3251 as_bad (_("expected , <constant>"));
3252 ignore_rest_of_line ();
3253 return;
3256 num_regs = exp.X_add_number;
3258 if (num_regs < 1 || num_regs > 4)
3260 as_bad (_("number of registers must be in the range [1:4]"));
3261 ignore_rest_of_line ();
3262 return;
3265 demand_empty_rest_of_line ();
3267 if (reg == 4)
3269 /* Short form. */
3270 op = 0xb4 | (num_regs - 1);
3271 add_unwind_opcode (op, 1);
3273 else
3275 /* Long form. */
3276 op = 0xc800 | (reg << 4) | (num_regs - 1);
3277 add_unwind_opcode (op, 2);
3279 unwind.frame_size += num_regs * 12;
3283 /* Parse a directive saving VFP registers for ARMv6 and above. */
3285 static void
3286 s_arm_unwind_save_vfp_armv6 (void)
3288 int count;
3289 unsigned int start;
3290 valueT op;
3291 int num_vfpv3_regs = 0;
3292 int num_regs_below_16;
3294 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3295 if (count == FAIL)
3297 as_bad (_("expected register list"));
3298 ignore_rest_of_line ();
3299 return;
3302 demand_empty_rest_of_line ();
3304 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3305 than FSTMX/FLDMX-style ones). */
3307 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3308 if (start >= 16)
3309 num_vfpv3_regs = count;
3310 else if (start + count > 16)
3311 num_vfpv3_regs = start + count - 16;
3313 if (num_vfpv3_regs > 0)
3315 int start_offset = start > 16 ? start - 16 : 0;
3316 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3317 add_unwind_opcode (op, 2);
3320 /* Generate opcode for registers numbered in the range 0 .. 15. */
3321 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3322 assert (num_regs_below_16 + num_vfpv3_regs == count);
3323 if (num_regs_below_16 > 0)
3325 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3326 add_unwind_opcode (op, 2);
3329 unwind.frame_size += count * 8;
3333 /* Parse a directive saving VFP registers for pre-ARMv6. */
3335 static void
3336 s_arm_unwind_save_vfp (void)
3338 int count;
3339 unsigned int reg;
3340 valueT op;
3342 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3343 if (count == FAIL)
3345 as_bad (_("expected register list"));
3346 ignore_rest_of_line ();
3347 return;
3350 demand_empty_rest_of_line ();
3352 if (reg == 8)
3354 /* Short form. */
3355 op = 0xb8 | (count - 1);
3356 add_unwind_opcode (op, 1);
3358 else
3360 /* Long form. */
3361 op = 0xb300 | (reg << 4) | (count - 1);
3362 add_unwind_opcode (op, 2);
3364 unwind.frame_size += count * 8 + 4;
3368 /* Parse a directive saving iWMMXt data registers. */
3370 static void
3371 s_arm_unwind_save_mmxwr (void)
3373 int reg;
3374 int hi_reg;
3375 int i;
3376 unsigned mask = 0;
3377 valueT op;
3379 if (*input_line_pointer == '{')
3380 input_line_pointer++;
3384 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3386 if (reg == FAIL)
3388 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3389 goto error;
3392 if (mask >> reg)
3393 as_tsktsk (_("register list not in ascending order"));
3394 mask |= 1 << reg;
3396 if (*input_line_pointer == '-')
3398 input_line_pointer++;
3399 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3400 if (hi_reg == FAIL)
3402 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3403 goto error;
3405 else if (reg >= hi_reg)
3407 as_bad (_("bad register range"));
3408 goto error;
3410 for (; reg < hi_reg; reg++)
3411 mask |= 1 << reg;
3414 while (skip_past_comma (&input_line_pointer) != FAIL);
3416 if (*input_line_pointer == '}')
3417 input_line_pointer++;
3419 demand_empty_rest_of_line ();
3421 /* Generate any deferred opcodes becuuse we're going to be looking at
3422 the list. */
3423 flush_pending_unwind ();
3425 for (i = 0; i < 16; i++)
3427 if (mask & (1 << i))
3428 unwind.frame_size += 8;
3431 /* Attempt to combine with a previous opcode. We do this because gcc
3432 likes to output separate unwind directives for a single block of
3433 registers. */
3434 if (unwind.opcode_count > 0)
3436 i = unwind.opcodes[unwind.opcode_count - 1];
3437 if ((i & 0xf8) == 0xc0)
3439 i &= 7;
3440 /* Only merge if the blocks are contiguous. */
3441 if (i < 6)
3443 if ((mask & 0xfe00) == (1 << 9))
3445 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3446 unwind.opcode_count--;
3449 else if (i == 6 && unwind.opcode_count >= 2)
3451 i = unwind.opcodes[unwind.opcode_count - 2];
3452 reg = i >> 4;
3453 i &= 0xf;
3455 op = 0xffff << (reg - 1);
3456 if (reg > 0
3457 && ((mask & op) == (1u << (reg - 1))))
3459 op = (1 << (reg + i + 1)) - 1;
3460 op &= ~((1 << reg) - 1);
3461 mask |= op;
3462 unwind.opcode_count -= 2;
3468 hi_reg = 15;
3469 /* We want to generate opcodes in the order the registers have been
3470 saved, ie. descending order. */
3471 for (reg = 15; reg >= -1; reg--)
3473 /* Save registers in blocks. */
3474 if (reg < 0
3475 || !(mask & (1 << reg)))
3477 /* We found an unsaved reg. Generate opcodes to save the
3478 preceeding block. */
3479 if (reg != hi_reg)
3481 if (reg == 9)
3483 /* Short form. */
3484 op = 0xc0 | (hi_reg - 10);
3485 add_unwind_opcode (op, 1);
3487 else
3489 /* Long form. */
3490 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3491 add_unwind_opcode (op, 2);
3494 hi_reg = reg - 1;
3498 return;
3499 error:
3500 ignore_rest_of_line ();
3503 static void
3504 s_arm_unwind_save_mmxwcg (void)
3506 int reg;
3507 int hi_reg;
3508 unsigned mask = 0;
3509 valueT op;
3511 if (*input_line_pointer == '{')
3512 input_line_pointer++;
3516 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3518 if (reg == FAIL)
3520 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3521 goto error;
3524 reg -= 8;
3525 if (mask >> reg)
3526 as_tsktsk (_("register list not in ascending order"));
3527 mask |= 1 << reg;
3529 if (*input_line_pointer == '-')
3531 input_line_pointer++;
3532 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3533 if (hi_reg == FAIL)
3535 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3536 goto error;
3538 else if (reg >= hi_reg)
3540 as_bad (_("bad register range"));
3541 goto error;
3543 for (; reg < hi_reg; reg++)
3544 mask |= 1 << reg;
3547 while (skip_past_comma (&input_line_pointer) != FAIL);
3549 if (*input_line_pointer == '}')
3550 input_line_pointer++;
3552 demand_empty_rest_of_line ();
3554 /* Generate any deferred opcodes becuuse we're going to be looking at
3555 the list. */
3556 flush_pending_unwind ();
3558 for (reg = 0; reg < 16; reg++)
3560 if (mask & (1 << reg))
3561 unwind.frame_size += 4;
3563 op = 0xc700 | mask;
3564 add_unwind_opcode (op, 2);
3565 return;
3566 error:
3567 ignore_rest_of_line ();
3571 /* Parse an unwind_save directive.
3572 If the argument is non-zero, this is a .vsave directive. */
3574 static void
3575 s_arm_unwind_save (int arch_v6)
3577 char *peek;
3578 struct reg_entry *reg;
3579 bfd_boolean had_brace = FALSE;
3581 /* Figure out what sort of save we have. */
3582 peek = input_line_pointer;
3584 if (*peek == '{')
3586 had_brace = TRUE;
3587 peek++;
3590 reg = arm_reg_parse_multi (&peek);
3592 if (!reg)
3594 as_bad (_("register expected"));
3595 ignore_rest_of_line ();
3596 return;
3599 switch (reg->type)
3601 case REG_TYPE_FN:
3602 if (had_brace)
3604 as_bad (_("FPA .unwind_save does not take a register list"));
3605 ignore_rest_of_line ();
3606 return;
3608 s_arm_unwind_save_fpa (reg->number);
3609 return;
3611 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3612 case REG_TYPE_VFD:
3613 if (arch_v6)
3614 s_arm_unwind_save_vfp_armv6 ();
3615 else
3616 s_arm_unwind_save_vfp ();
3617 return;
3618 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3619 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3621 default:
3622 as_bad (_(".unwind_save does not support this kind of register"));
3623 ignore_rest_of_line ();
3628 /* Parse an unwind_movsp directive. */
3630 static void
3631 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3633 int reg;
3634 valueT op;
3636 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3637 if (reg == FAIL)
3639 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3640 ignore_rest_of_line ();
3641 return;
3643 demand_empty_rest_of_line ();
3645 if (reg == REG_SP || reg == REG_PC)
3647 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3648 return;
3651 if (unwind.fp_reg != REG_SP)
3652 as_bad (_("unexpected .unwind_movsp directive"));
3654 /* Generate opcode to restore the value. */
3655 op = 0x90 | reg;
3656 add_unwind_opcode (op, 1);
3658 /* Record the information for later. */
3659 unwind.fp_reg = reg;
3660 unwind.fp_offset = unwind.frame_size;
3661 unwind.sp_restored = 1;
3664 /* Parse an unwind_pad directive. */
3666 static void
3667 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3669 int offset;
3671 if (immediate_for_directive (&offset) == FAIL)
3672 return;
3674 if (offset & 3)
3676 as_bad (_("stack increment must be multiple of 4"));
3677 ignore_rest_of_line ();
3678 return;
3681 /* Don't generate any opcodes, just record the details for later. */
3682 unwind.frame_size += offset;
3683 unwind.pending_offset += offset;
3685 demand_empty_rest_of_line ();
3688 /* Parse an unwind_setfp directive. */
3690 static void
3691 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3693 int sp_reg;
3694 int fp_reg;
3695 int offset;
3697 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3698 if (skip_past_comma (&input_line_pointer) == FAIL)
3699 sp_reg = FAIL;
3700 else
3701 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3703 if (fp_reg == FAIL || sp_reg == FAIL)
3705 as_bad (_("expected <reg>, <reg>"));
3706 ignore_rest_of_line ();
3707 return;
3710 /* Optional constant. */
3711 if (skip_past_comma (&input_line_pointer) != FAIL)
3713 if (immediate_for_directive (&offset) == FAIL)
3714 return;
3716 else
3717 offset = 0;
3719 demand_empty_rest_of_line ();
3721 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
3723 as_bad (_("register must be either sp or set by a previous"
3724 "unwind_movsp directive"));
3725 return;
3728 /* Don't generate any opcodes, just record the information for later. */
3729 unwind.fp_reg = fp_reg;
3730 unwind.fp_used = 1;
3731 if (sp_reg == 13)
3732 unwind.fp_offset = unwind.frame_size - offset;
3733 else
3734 unwind.fp_offset -= offset;
3737 /* Parse an unwind_raw directive. */
3739 static void
3740 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3742 expressionS exp;
3743 /* This is an arbitary limit. */
3744 unsigned char op[16];
3745 int count;
3747 expression (&exp);
3748 if (exp.X_op == O_constant
3749 && skip_past_comma (&input_line_pointer) != FAIL)
3751 unwind.frame_size += exp.X_add_number;
3752 expression (&exp);
3754 else
3755 exp.X_op = O_illegal;
3757 if (exp.X_op != O_constant)
3759 as_bad (_("expected <offset>, <opcode>"));
3760 ignore_rest_of_line ();
3761 return;
3764 count = 0;
3766 /* Parse the opcode. */
3767 for (;;)
3769 if (count >= 16)
3771 as_bad (_("unwind opcode too long"));
3772 ignore_rest_of_line ();
3774 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3776 as_bad (_("invalid unwind opcode"));
3777 ignore_rest_of_line ();
3778 return;
3780 op[count++] = exp.X_add_number;
3782 /* Parse the next byte. */
3783 if (skip_past_comma (&input_line_pointer) == FAIL)
3784 break;
3786 expression (&exp);
3789 /* Add the opcode bytes in reverse order. */
3790 while (count--)
3791 add_unwind_opcode (op[count], 1);
3793 demand_empty_rest_of_line ();
3797 /* Parse a .eabi_attribute directive. */
3799 static void
3800 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3802 expressionS exp;
3803 bfd_boolean is_string;
3804 int tag;
3805 unsigned int i = 0;
3806 char *s = NULL;
3807 char saved_char;
3809 expression (& exp);
3810 if (exp.X_op != O_constant)
3811 goto bad;
3813 tag = exp.X_add_number;
3814 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
3815 is_string = 1;
3816 else
3817 is_string = 0;
3819 if (skip_past_comma (&input_line_pointer) == FAIL)
3820 goto bad;
3821 if (tag == 32 || !is_string)
3823 expression (& exp);
3824 if (exp.X_op != O_constant)
3826 as_bad (_("expected numeric constant"));
3827 ignore_rest_of_line ();
3828 return;
3830 i = exp.X_add_number;
3832 if (tag == Tag_compatibility
3833 && skip_past_comma (&input_line_pointer) == FAIL)
3835 as_bad (_("expected comma"));
3836 ignore_rest_of_line ();
3837 return;
3839 if (is_string)
3841 skip_whitespace(input_line_pointer);
3842 if (*input_line_pointer != '"')
3843 goto bad_string;
3844 input_line_pointer++;
3845 s = input_line_pointer;
3846 while (*input_line_pointer && *input_line_pointer != '"')
3847 input_line_pointer++;
3848 if (*input_line_pointer != '"')
3849 goto bad_string;
3850 saved_char = *input_line_pointer;
3851 *input_line_pointer = 0;
3853 else
3855 s = NULL;
3856 saved_char = 0;
3859 if (tag == Tag_compatibility)
3860 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
3861 else if (is_string)
3862 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
3863 else
3864 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
3866 if (s)
3868 *input_line_pointer = saved_char;
3869 input_line_pointer++;
3871 demand_empty_rest_of_line ();
3872 return;
3873 bad_string:
3874 as_bad (_("bad string constant"));
3875 ignore_rest_of_line ();
3876 return;
3877 bad:
3878 as_bad (_("expected <tag> , <value>"));
3879 ignore_rest_of_line ();
3882 static void s_arm_arch (int);
3883 static void s_arm_cpu (int);
3884 static void s_arm_fpu (int);
3885 #endif /* OBJ_ELF */
3887 /* This table describes all the machine specific pseudo-ops the assembler
3888 has to support. The fields are:
3889 pseudo-op name without dot
3890 function to call to execute this pseudo-op
3891 Integer arg to pass to the function. */
3893 const pseudo_typeS md_pseudo_table[] =
3895 /* Never called because '.req' does not start a line. */
3896 { "req", s_req, 0 },
3897 /* Following two are likewise never called. */
3898 { "dn", s_dn, 0 },
3899 { "qn", s_qn, 0 },
3900 { "unreq", s_unreq, 0 },
3901 { "bss", s_bss, 0 },
3902 { "align", s_align, 0 },
3903 { "arm", s_arm, 0 },
3904 { "thumb", s_thumb, 0 },
3905 { "code", s_code, 0 },
3906 { "force_thumb", s_force_thumb, 0 },
3907 { "thumb_func", s_thumb_func, 0 },
3908 { "thumb_set", s_thumb_set, 0 },
3909 { "even", s_even, 0 },
3910 { "ltorg", s_ltorg, 0 },
3911 { "pool", s_ltorg, 0 },
3912 { "syntax", s_syntax, 0 },
3913 #ifdef OBJ_ELF
3914 { "word", s_arm_elf_cons, 4 },
3915 { "long", s_arm_elf_cons, 4 },
3916 { "rel31", s_arm_rel31, 0 },
3917 { "fnstart", s_arm_unwind_fnstart, 0 },
3918 { "fnend", s_arm_unwind_fnend, 0 },
3919 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3920 { "personality", s_arm_unwind_personality, 0 },
3921 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3922 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3923 { "save", s_arm_unwind_save, 0 },
3924 { "vsave", s_arm_unwind_save, 1 },
3925 { "movsp", s_arm_unwind_movsp, 0 },
3926 { "pad", s_arm_unwind_pad, 0 },
3927 { "setfp", s_arm_unwind_setfp, 0 },
3928 { "unwind_raw", s_arm_unwind_raw, 0 },
3929 { "cpu", s_arm_cpu, 0 },
3930 { "arch", s_arm_arch, 0 },
3931 { "fpu", s_arm_fpu, 0 },
3932 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3933 #else
3934 { "word", cons, 4},
3935 #endif
3936 { "extend", float_cons, 'x' },
3937 { "ldouble", float_cons, 'x' },
3938 { "packed", float_cons, 'p' },
3939 { 0, 0, 0 }
3942 /* Parser functions used exclusively in instruction operands. */
3944 /* Generic immediate-value read function for use in insn parsing.
3945 STR points to the beginning of the immediate (the leading #);
3946 VAL receives the value; if the value is outside [MIN, MAX]
3947 issue an error. PREFIX_OPT is true if the immediate prefix is
3948 optional. */
3950 static int
3951 parse_immediate (char **str, int *val, int min, int max,
3952 bfd_boolean prefix_opt)
3954 expressionS exp;
3955 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3956 if (exp.X_op != O_constant)
3958 inst.error = _("constant expression required");
3959 return FAIL;
3962 if (exp.X_add_number < min || exp.X_add_number > max)
3964 inst.error = _("immediate value out of range");
3965 return FAIL;
3968 *val = exp.X_add_number;
3969 return SUCCESS;
3972 /* Less-generic immediate-value read function with the possibility of loading a
3973 big (64-bit) immediate, as required by Neon VMOV and VMVN immediate
3974 instructions. Puts the result directly in inst.operands[i]. */
3976 static int
3977 parse_big_immediate (char **str, int i)
3979 expressionS exp;
3980 char *ptr = *str;
3982 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
3984 if (exp.X_op == O_constant)
3985 inst.operands[i].imm = exp.X_add_number;
3986 else if (exp.X_op == O_big
3987 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
3988 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
3990 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
3991 /* Bignums have their least significant bits in
3992 generic_bignum[0]. Make sure we put 32 bits in imm and
3993 32 bits in reg, in a (hopefully) portable way. */
3994 assert (parts != 0);
3995 inst.operands[i].imm = 0;
3996 for (j = 0; j < parts; j++, idx++)
3997 inst.operands[i].imm |= generic_bignum[idx]
3998 << (LITTLENUM_NUMBER_OF_BITS * j);
3999 inst.operands[i].reg = 0;
4000 for (j = 0; j < parts; j++, idx++)
4001 inst.operands[i].reg |= generic_bignum[idx]
4002 << (LITTLENUM_NUMBER_OF_BITS * j);
4003 inst.operands[i].regisimm = 1;
4005 else
4006 return FAIL;
4008 *str = ptr;
4010 return SUCCESS;
4013 /* Returns the pseudo-register number of an FPA immediate constant,
4014 or FAIL if there isn't a valid constant here. */
4016 static int
4017 parse_fpa_immediate (char ** str)
4019 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4020 char * save_in;
4021 expressionS exp;
4022 int i;
4023 int j;
4025 /* First try and match exact strings, this is to guarantee
4026 that some formats will work even for cross assembly. */
4028 for (i = 0; fp_const[i]; i++)
4030 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4032 char *start = *str;
4034 *str += strlen (fp_const[i]);
4035 if (is_end_of_line[(unsigned char) **str])
4036 return i + 8;
4037 *str = start;
4041 /* Just because we didn't get a match doesn't mean that the constant
4042 isn't valid, just that it is in a format that we don't
4043 automatically recognize. Try parsing it with the standard
4044 expression routines. */
4046 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4048 /* Look for a raw floating point number. */
4049 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4050 && is_end_of_line[(unsigned char) *save_in])
4052 for (i = 0; i < NUM_FLOAT_VALS; i++)
4054 for (j = 0; j < MAX_LITTLENUMS; j++)
4056 if (words[j] != fp_values[i][j])
4057 break;
4060 if (j == MAX_LITTLENUMS)
4062 *str = save_in;
4063 return i + 8;
4068 /* Try and parse a more complex expression, this will probably fail
4069 unless the code uses a floating point prefix (eg "0f"). */
4070 save_in = input_line_pointer;
4071 input_line_pointer = *str;
4072 if (expression (&exp) == absolute_section
4073 && exp.X_op == O_big
4074 && exp.X_add_number < 0)
4076 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4077 Ditto for 15. */
4078 if (gen_to_words (words, 5, (long) 15) == 0)
4080 for (i = 0; i < NUM_FLOAT_VALS; i++)
4082 for (j = 0; j < MAX_LITTLENUMS; j++)
4084 if (words[j] != fp_values[i][j])
4085 break;
4088 if (j == MAX_LITTLENUMS)
4090 *str = input_line_pointer;
4091 input_line_pointer = save_in;
4092 return i + 8;
4098 *str = input_line_pointer;
4099 input_line_pointer = save_in;
4100 inst.error = _("invalid FPA immediate expression");
4101 return FAIL;
4104 /* Returns 1 if a number has "quarter-precision" float format
4105 0baBbbbbbc defgh000 00000000 00000000. */
4107 static int
4108 is_quarter_float (unsigned imm)
4110 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4111 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4114 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4115 0baBbbbbbc defgh000 00000000 00000000.
4116 The zero and minus-zero cases need special handling, since they can't be
4117 encoded in the "quarter-precision" float format, but can nonetheless be
4118 loaded as integer constants. */
4120 static unsigned
4121 parse_qfloat_immediate (char **ccp, int *immed)
4123 char *str = *ccp;
4124 char *fpnum;
4125 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4126 int found_fpchar = 0;
4128 skip_past_char (&str, '#');
4130 /* We must not accidentally parse an integer as a floating-point number. Make
4131 sure that the value we parse is not an integer by checking for special
4132 characters '.' or 'e'.
4133 FIXME: This is a horrible hack, but doing better is tricky because type
4134 information isn't in a very usable state at parse time. A better solution
4135 should be implemented as part of the fix for allowing the full range of
4136 pseudo-instructions to be used in VMOV, etc. */
4137 fpnum = str;
4138 skip_whitespace (fpnum);
4140 if (strncmp (fpnum, "0x", 2) == 0)
4141 return FAIL;
4142 else
4144 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4145 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4147 found_fpchar = 1;
4148 break;
4151 if (!found_fpchar)
4152 return FAIL;
4155 if ((str = atof_ieee (str, 's', words)) != NULL)
4157 unsigned fpword = 0;
4158 int i;
4160 /* Our FP word must be 32 bits (single-precision FP). */
4161 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4163 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4164 fpword |= words[i];
4167 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4168 *immed = fpword;
4169 else
4170 return FAIL;
4172 *ccp = str;
4174 return SUCCESS;
4177 return FAIL;
4180 /* Shift operands. */
4181 enum shift_kind
4183 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4186 struct asm_shift_name
4188 const char *name;
4189 enum shift_kind kind;
4192 /* Third argument to parse_shift. */
4193 enum parse_shift_mode
4195 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4196 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4197 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4198 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4199 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4202 /* Parse a <shift> specifier on an ARM data processing instruction.
4203 This has three forms:
4205 (LSL|LSR|ASL|ASR|ROR) Rs
4206 (LSL|LSR|ASL|ASR|ROR) #imm
4209 Note that ASL is assimilated to LSL in the instruction encoding, and
4210 RRX to ROR #0 (which cannot be written as such). */
4212 static int
4213 parse_shift (char **str, int i, enum parse_shift_mode mode)
4215 const struct asm_shift_name *shift_name;
4216 enum shift_kind shift;
4217 char *s = *str;
4218 char *p = s;
4219 int reg;
4221 for (p = *str; ISALPHA (*p); p++)
4224 if (p == *str)
4226 inst.error = _("shift expression expected");
4227 return FAIL;
4230 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4232 if (shift_name == NULL)
4234 inst.error = _("shift expression expected");
4235 return FAIL;
4238 shift = shift_name->kind;
4240 switch (mode)
4242 case NO_SHIFT_RESTRICT:
4243 case SHIFT_IMMEDIATE: break;
4245 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4246 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4248 inst.error = _("'LSL' or 'ASR' required");
4249 return FAIL;
4251 break;
4253 case SHIFT_LSL_IMMEDIATE:
4254 if (shift != SHIFT_LSL)
4256 inst.error = _("'LSL' required");
4257 return FAIL;
4259 break;
4261 case SHIFT_ASR_IMMEDIATE:
4262 if (shift != SHIFT_ASR)
4264 inst.error = _("'ASR' required");
4265 return FAIL;
4267 break;
4269 default: abort ();
4272 if (shift != SHIFT_RRX)
4274 /* Whitespace can appear here if the next thing is a bare digit. */
4275 skip_whitespace (p);
4277 if (mode == NO_SHIFT_RESTRICT
4278 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4280 inst.operands[i].imm = reg;
4281 inst.operands[i].immisreg = 1;
4283 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4284 return FAIL;
4286 inst.operands[i].shift_kind = shift;
4287 inst.operands[i].shifted = 1;
4288 *str = p;
4289 return SUCCESS;
4292 /* Parse a <shifter_operand> for an ARM data processing instruction:
4294 #<immediate>
4295 #<immediate>, <rotate>
4296 <Rm>
4297 <Rm>, <shift>
4299 where <shift> is defined by parse_shift above, and <rotate> is a
4300 multiple of 2 between 0 and 30. Validation of immediate operands
4301 is deferred to md_apply_fix. */
4303 static int
4304 parse_shifter_operand (char **str, int i)
4306 int value;
4307 expressionS expr;
4309 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4311 inst.operands[i].reg = value;
4312 inst.operands[i].isreg = 1;
4314 /* parse_shift will override this if appropriate */
4315 inst.reloc.exp.X_op = O_constant;
4316 inst.reloc.exp.X_add_number = 0;
4318 if (skip_past_comma (str) == FAIL)
4319 return SUCCESS;
4321 /* Shift operation on register. */
4322 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4325 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4326 return FAIL;
4328 if (skip_past_comma (str) == SUCCESS)
4330 /* #x, y -- ie explicit rotation by Y. */
4331 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4332 return FAIL;
4334 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4336 inst.error = _("constant expression expected");
4337 return FAIL;
4340 value = expr.X_add_number;
4341 if (value < 0 || value > 30 || value % 2 != 0)
4343 inst.error = _("invalid rotation");
4344 return FAIL;
4346 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4348 inst.error = _("invalid constant");
4349 return FAIL;
4352 /* Convert to decoded value. md_apply_fix will put it back. */
4353 inst.reloc.exp.X_add_number
4354 = (((inst.reloc.exp.X_add_number << (32 - value))
4355 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4358 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4359 inst.reloc.pc_rel = 0;
4360 return SUCCESS;
4363 /* Group relocation information. Each entry in the table contains the
4364 textual name of the relocation as may appear in assembler source
4365 and must end with a colon.
4366 Along with this textual name are the relocation codes to be used if
4367 the corresponding instruction is an ALU instruction (ADD or SUB only),
4368 an LDR, an LDRS, or an LDC. */
4370 struct group_reloc_table_entry
4372 const char *name;
4373 int alu_code;
4374 int ldr_code;
4375 int ldrs_code;
4376 int ldc_code;
4379 typedef enum
4381 /* Varieties of non-ALU group relocation. */
4383 GROUP_LDR,
4384 GROUP_LDRS,
4385 GROUP_LDC
4386 } group_reloc_type;
4388 static struct group_reloc_table_entry group_reloc_table[] =
4389 { /* Program counter relative: */
4390 { "pc_g0_nc",
4391 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4392 0, /* LDR */
4393 0, /* LDRS */
4394 0 }, /* LDC */
4395 { "pc_g0",
4396 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4397 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4398 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4399 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4400 { "pc_g1_nc",
4401 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4402 0, /* LDR */
4403 0, /* LDRS */
4404 0 }, /* LDC */
4405 { "pc_g1",
4406 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4407 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4408 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4409 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4410 { "pc_g2",
4411 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4412 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4413 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4414 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4415 /* Section base relative */
4416 { "sb_g0_nc",
4417 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4418 0, /* LDR */
4419 0, /* LDRS */
4420 0 }, /* LDC */
4421 { "sb_g0",
4422 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4423 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4424 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4425 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4426 { "sb_g1_nc",
4427 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4428 0, /* LDR */
4429 0, /* LDRS */
4430 0 }, /* LDC */
4431 { "sb_g1",
4432 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4433 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4434 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4435 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4436 { "sb_g2",
4437 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4438 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4439 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4440 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4442 /* Given the address of a pointer pointing to the textual name of a group
4443 relocation as may appear in assembler source, attempt to find its details
4444 in group_reloc_table. The pointer will be updated to the character after
4445 the trailing colon. On failure, FAIL will be returned; SUCCESS
4446 otherwise. On success, *entry will be updated to point at the relevant
4447 group_reloc_table entry. */
4449 static int
4450 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4452 unsigned int i;
4453 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4455 int length = strlen (group_reloc_table[i].name);
4457 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 &&
4458 (*str)[length] == ':')
4460 *out = &group_reloc_table[i];
4461 *str += (length + 1);
4462 return SUCCESS;
4466 return FAIL;
4469 /* Parse a <shifter_operand> for an ARM data processing instruction
4470 (as for parse_shifter_operand) where group relocations are allowed:
4472 #<immediate>
4473 #<immediate>, <rotate>
4474 #:<group_reloc>:<expression>
4475 <Rm>
4476 <Rm>, <shift>
4478 where <group_reloc> is one of the strings defined in group_reloc_table.
4479 The hashes are optional.
4481 Everything else is as for parse_shifter_operand. */
4483 static parse_operand_result
4484 parse_shifter_operand_group_reloc (char **str, int i)
4486 /* Determine if we have the sequence of characters #: or just :
4487 coming next. If we do, then we check for a group relocation.
4488 If we don't, punt the whole lot to parse_shifter_operand. */
4490 if (((*str)[0] == '#' && (*str)[1] == ':')
4491 || (*str)[0] == ':')
4493 struct group_reloc_table_entry *entry;
4495 if ((*str)[0] == '#')
4496 (*str) += 2;
4497 else
4498 (*str)++;
4500 /* Try to parse a group relocation. Anything else is an error. */
4501 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4503 inst.error = _("unknown group relocation");
4504 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4507 /* We now have the group relocation table entry corresponding to
4508 the name in the assembler source. Next, we parse the expression. */
4509 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4510 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4512 /* Record the relocation type (always the ALU variant here). */
4513 inst.reloc.type = entry->alu_code;
4514 assert (inst.reloc.type != 0);
4516 return PARSE_OPERAND_SUCCESS;
4518 else
4519 return parse_shifter_operand (str, i) == SUCCESS
4520 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4522 /* Never reached. */
4525 /* Parse all forms of an ARM address expression. Information is written
4526 to inst.operands[i] and/or inst.reloc.
4528 Preindexed addressing (.preind=1):
4530 [Rn, #offset] .reg=Rn .reloc.exp=offset
4531 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4532 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4533 .shift_kind=shift .reloc.exp=shift_imm
4535 These three may have a trailing ! which causes .writeback to be set also.
4537 Postindexed addressing (.postind=1, .writeback=1):
4539 [Rn], #offset .reg=Rn .reloc.exp=offset
4540 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4541 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4542 .shift_kind=shift .reloc.exp=shift_imm
4544 Unindexed addressing (.preind=0, .postind=0):
4546 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4548 Other:
4550 [Rn]{!} shorthand for [Rn,#0]{!}
4551 =immediate .isreg=0 .reloc.exp=immediate
4552 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4554 It is the caller's responsibility to check for addressing modes not
4555 supported by the instruction, and to set inst.reloc.type. */
4557 static parse_operand_result
4558 parse_address_main (char **str, int i, int group_relocations,
4559 group_reloc_type group_type)
4561 char *p = *str;
4562 int reg;
4564 if (skip_past_char (&p, '[') == FAIL)
4566 if (skip_past_char (&p, '=') == FAIL)
4568 /* bare address - translate to PC-relative offset */
4569 inst.reloc.pc_rel = 1;
4570 inst.operands[i].reg = REG_PC;
4571 inst.operands[i].isreg = 1;
4572 inst.operands[i].preind = 1;
4574 /* else a load-constant pseudo op, no special treatment needed here */
4576 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4577 return PARSE_OPERAND_FAIL;
4579 *str = p;
4580 return PARSE_OPERAND_SUCCESS;
4583 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4585 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4586 return PARSE_OPERAND_FAIL;
4588 inst.operands[i].reg = reg;
4589 inst.operands[i].isreg = 1;
4591 if (skip_past_comma (&p) == SUCCESS)
4593 inst.operands[i].preind = 1;
4595 if (*p == '+') p++;
4596 else if (*p == '-') p++, inst.operands[i].negative = 1;
4598 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4600 inst.operands[i].imm = reg;
4601 inst.operands[i].immisreg = 1;
4603 if (skip_past_comma (&p) == SUCCESS)
4604 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4605 return PARSE_OPERAND_FAIL;
4607 else if (skip_past_char (&p, ':') == SUCCESS)
4609 /* FIXME: '@' should be used here, but it's filtered out by generic
4610 code before we get to see it here. This may be subject to
4611 change. */
4612 expressionS exp;
4613 my_get_expression (&exp, &p, GE_NO_PREFIX);
4614 if (exp.X_op != O_constant)
4616 inst.error = _("alignment must be constant");
4617 return PARSE_OPERAND_FAIL;
4619 inst.operands[i].imm = exp.X_add_number << 8;
4620 inst.operands[i].immisalign = 1;
4621 /* Alignments are not pre-indexes. */
4622 inst.operands[i].preind = 0;
4624 else
4626 if (inst.operands[i].negative)
4628 inst.operands[i].negative = 0;
4629 p--;
4632 if (group_relocations &&
4633 ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4636 struct group_reloc_table_entry *entry;
4638 /* Skip over the #: or : sequence. */
4639 if (*p == '#')
4640 p += 2;
4641 else
4642 p++;
4644 /* Try to parse a group relocation. Anything else is an
4645 error. */
4646 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4648 inst.error = _("unknown group relocation");
4649 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4652 /* We now have the group relocation table entry corresponding to
4653 the name in the assembler source. Next, we parse the
4654 expression. */
4655 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4656 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4658 /* Record the relocation type. */
4659 switch (group_type)
4661 case GROUP_LDR:
4662 inst.reloc.type = entry->ldr_code;
4663 break;
4665 case GROUP_LDRS:
4666 inst.reloc.type = entry->ldrs_code;
4667 break;
4669 case GROUP_LDC:
4670 inst.reloc.type = entry->ldc_code;
4671 break;
4673 default:
4674 assert (0);
4677 if (inst.reloc.type == 0)
4679 inst.error = _("this group relocation is not allowed on this instruction");
4680 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4683 else
4684 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4685 return PARSE_OPERAND_FAIL;
4689 if (skip_past_char (&p, ']') == FAIL)
4691 inst.error = _("']' expected");
4692 return PARSE_OPERAND_FAIL;
4695 if (skip_past_char (&p, '!') == SUCCESS)
4696 inst.operands[i].writeback = 1;
4698 else if (skip_past_comma (&p) == SUCCESS)
4700 if (skip_past_char (&p, '{') == SUCCESS)
4702 /* [Rn], {expr} - unindexed, with option */
4703 if (parse_immediate (&p, &inst.operands[i].imm,
4704 0, 255, TRUE) == FAIL)
4705 return PARSE_OPERAND_FAIL;
4707 if (skip_past_char (&p, '}') == FAIL)
4709 inst.error = _("'}' expected at end of 'option' field");
4710 return PARSE_OPERAND_FAIL;
4712 if (inst.operands[i].preind)
4714 inst.error = _("cannot combine index with option");
4715 return PARSE_OPERAND_FAIL;
4717 *str = p;
4718 return PARSE_OPERAND_SUCCESS;
4720 else
4722 inst.operands[i].postind = 1;
4723 inst.operands[i].writeback = 1;
4725 if (inst.operands[i].preind)
4727 inst.error = _("cannot combine pre- and post-indexing");
4728 return PARSE_OPERAND_FAIL;
4731 if (*p == '+') p++;
4732 else if (*p == '-') p++, inst.operands[i].negative = 1;
4734 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4736 /* We might be using the immediate for alignment already. If we
4737 are, OR the register number into the low-order bits. */
4738 if (inst.operands[i].immisalign)
4739 inst.operands[i].imm |= reg;
4740 else
4741 inst.operands[i].imm = reg;
4742 inst.operands[i].immisreg = 1;
4744 if (skip_past_comma (&p) == SUCCESS)
4745 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4746 return PARSE_OPERAND_FAIL;
4748 else
4750 if (inst.operands[i].negative)
4752 inst.operands[i].negative = 0;
4753 p--;
4755 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4756 return PARSE_OPERAND_FAIL;
4761 /* If at this point neither .preind nor .postind is set, we have a
4762 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4763 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4765 inst.operands[i].preind = 1;
4766 inst.reloc.exp.X_op = O_constant;
4767 inst.reloc.exp.X_add_number = 0;
4769 *str = p;
4770 return PARSE_OPERAND_SUCCESS;
4773 static int
4774 parse_address (char **str, int i)
4776 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4777 ? SUCCESS : FAIL;
4780 static parse_operand_result
4781 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4783 return parse_address_main (str, i, 1, type);
4786 /* Parse an operand for a MOVW or MOVT instruction. */
4787 static int
4788 parse_half (char **str)
4790 char * p;
4792 p = *str;
4793 skip_past_char (&p, '#');
4794 if (strncasecmp (p, ":lower16:", 9) == 0)
4795 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4796 else if (strncasecmp (p, ":upper16:", 9) == 0)
4797 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4799 if (inst.reloc.type != BFD_RELOC_UNUSED)
4801 p += 9;
4802 skip_whitespace(p);
4805 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4806 return FAIL;
4808 if (inst.reloc.type == BFD_RELOC_UNUSED)
4810 if (inst.reloc.exp.X_op != O_constant)
4812 inst.error = _("constant expression expected");
4813 return FAIL;
4815 if (inst.reloc.exp.X_add_number < 0
4816 || inst.reloc.exp.X_add_number > 0xffff)
4818 inst.error = _("immediate value out of range");
4819 return FAIL;
4822 *str = p;
4823 return SUCCESS;
4826 /* Miscellaneous. */
4828 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4829 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4830 static int
4831 parse_psr (char **str)
4833 char *p;
4834 unsigned long psr_field;
4835 const struct asm_psr *psr;
4836 char *start;
4838 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4839 feature for ease of use and backwards compatibility. */
4840 p = *str;
4841 if (strncasecmp (p, "SPSR", 4) == 0)
4842 psr_field = SPSR_BIT;
4843 else if (strncasecmp (p, "CPSR", 4) == 0)
4844 psr_field = 0;
4845 else
4847 start = p;
4849 p++;
4850 while (ISALNUM (*p) || *p == '_');
4852 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4853 if (!psr)
4854 return FAIL;
4856 *str = p;
4857 return psr->field;
4860 p += 4;
4861 if (*p == '_')
4863 /* A suffix follows. */
4864 p++;
4865 start = p;
4868 p++;
4869 while (ISALNUM (*p) || *p == '_');
4871 psr = hash_find_n (arm_psr_hsh, start, p - start);
4872 if (!psr)
4873 goto error;
4875 psr_field |= psr->field;
4877 else
4879 if (ISALNUM (*p))
4880 goto error; /* Garbage after "[CS]PSR". */
4882 psr_field |= (PSR_c | PSR_f);
4884 *str = p;
4885 return psr_field;
4887 error:
4888 inst.error = _("flag for {c}psr instruction expected");
4889 return FAIL;
4892 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4893 value suitable for splatting into the AIF field of the instruction. */
4895 static int
4896 parse_cps_flags (char **str)
4898 int val = 0;
4899 int saw_a_flag = 0;
4900 char *s = *str;
4902 for (;;)
4903 switch (*s++)
4905 case '\0': case ',':
4906 goto done;
4908 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4909 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4910 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4912 default:
4913 inst.error = _("unrecognized CPS flag");
4914 return FAIL;
4917 done:
4918 if (saw_a_flag == 0)
4920 inst.error = _("missing CPS flags");
4921 return FAIL;
4924 *str = s - 1;
4925 return val;
4928 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4929 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4931 static int
4932 parse_endian_specifier (char **str)
4934 int little_endian;
4935 char *s = *str;
4937 if (strncasecmp (s, "BE", 2))
4938 little_endian = 0;
4939 else if (strncasecmp (s, "LE", 2))
4940 little_endian = 1;
4941 else
4943 inst.error = _("valid endian specifiers are be or le");
4944 return FAIL;
4947 if (ISALNUM (s[2]) || s[2] == '_')
4949 inst.error = _("valid endian specifiers are be or le");
4950 return FAIL;
4953 *str = s + 2;
4954 return little_endian;
4957 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
4958 value suitable for poking into the rotate field of an sxt or sxta
4959 instruction, or FAIL on error. */
4961 static int
4962 parse_ror (char **str)
4964 int rot;
4965 char *s = *str;
4967 if (strncasecmp (s, "ROR", 3) == 0)
4968 s += 3;
4969 else
4971 inst.error = _("missing rotation field after comma");
4972 return FAIL;
4975 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
4976 return FAIL;
4978 switch (rot)
4980 case 0: *str = s; return 0x0;
4981 case 8: *str = s; return 0x1;
4982 case 16: *str = s; return 0x2;
4983 case 24: *str = s; return 0x3;
4985 default:
4986 inst.error = _("rotation can only be 0, 8, 16, or 24");
4987 return FAIL;
4991 /* Parse a conditional code (from conds[] below). The value returned is in the
4992 range 0 .. 14, or FAIL. */
4993 static int
4994 parse_cond (char **str)
4996 char *p, *q;
4997 const struct asm_cond *c;
4999 p = q = *str;
5000 while (ISALPHA (*q))
5001 q++;
5003 c = hash_find_n (arm_cond_hsh, p, q - p);
5004 if (!c)
5006 inst.error = _("condition required");
5007 return FAIL;
5010 *str = q;
5011 return c->value;
5014 /* Parse an option for a barrier instruction. Returns the encoding for the
5015 option, or FAIL. */
5016 static int
5017 parse_barrier (char **str)
5019 char *p, *q;
5020 const struct asm_barrier_opt *o;
5022 p = q = *str;
5023 while (ISALPHA (*q))
5024 q++;
5026 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5027 if (!o)
5028 return FAIL;
5030 *str = q;
5031 return o->value;
5034 /* Parse the operands of a table branch instruction. Similar to a memory
5035 operand. */
5036 static int
5037 parse_tb (char **str)
5039 char * p = *str;
5040 int reg;
5042 if (skip_past_char (&p, '[') == FAIL)
5044 inst.error = _("'[' expected");
5045 return FAIL;
5048 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5050 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5051 return FAIL;
5053 inst.operands[0].reg = reg;
5055 if (skip_past_comma (&p) == FAIL)
5057 inst.error = _("',' expected");
5058 return FAIL;
5061 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5063 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5064 return FAIL;
5066 inst.operands[0].imm = reg;
5068 if (skip_past_comma (&p) == SUCCESS)
5070 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5071 return FAIL;
5072 if (inst.reloc.exp.X_add_number != 1)
5074 inst.error = _("invalid shift");
5075 return FAIL;
5077 inst.operands[0].shifted = 1;
5080 if (skip_past_char (&p, ']') == FAIL)
5082 inst.error = _("']' expected");
5083 return FAIL;
5085 *str = p;
5086 return SUCCESS;
5089 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5090 information on the types the operands can take and how they are encoded.
5091 Up to four operands may be read; this function handles setting the
5092 ".present" field for each read operand itself.
5093 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5094 else returns FAIL. */
5096 static int
5097 parse_neon_mov (char **str, int *which_operand)
5099 int i = *which_operand, val;
5100 enum arm_reg_type rtype;
5101 char *ptr = *str;
5102 struct neon_type_el optype;
5104 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5106 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5107 inst.operands[i].reg = val;
5108 inst.operands[i].isscalar = 1;
5109 inst.operands[i].vectype = optype;
5110 inst.operands[i++].present = 1;
5112 if (skip_past_comma (&ptr) == FAIL)
5113 goto wanted_comma;
5115 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5116 goto wanted_arm;
5118 inst.operands[i].reg = val;
5119 inst.operands[i].isreg = 1;
5120 inst.operands[i].present = 1;
5122 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5123 != FAIL)
5125 /* Cases 0, 1, 2, 3, 5 (D only). */
5126 if (skip_past_comma (&ptr) == FAIL)
5127 goto wanted_comma;
5129 inst.operands[i].reg = val;
5130 inst.operands[i].isreg = 1;
5131 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5132 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5133 inst.operands[i].isvec = 1;
5134 inst.operands[i].vectype = optype;
5135 inst.operands[i++].present = 1;
5137 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5139 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5140 Case 13: VMOV <Sd>, <Rm> */
5141 inst.operands[i].reg = val;
5142 inst.operands[i].isreg = 1;
5143 inst.operands[i].present = 1;
5145 if (rtype == REG_TYPE_NQ)
5147 first_error (_("can't use Neon quad register here"));
5148 return FAIL;
5150 else if (rtype != REG_TYPE_VFS)
5152 i++;
5153 if (skip_past_comma (&ptr) == FAIL)
5154 goto wanted_comma;
5155 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5156 goto wanted_arm;
5157 inst.operands[i].reg = val;
5158 inst.operands[i].isreg = 1;
5159 inst.operands[i].present = 1;
5162 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5163 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5164 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5165 Case 10: VMOV.F32 <Sd>, #<imm>
5166 Case 11: VMOV.F64 <Dd>, #<imm> */
5168 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5169 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5170 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5172 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5173 &optype)) != FAIL)
5175 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5176 Case 1: VMOV<c><q> <Dd>, <Dm>
5177 Case 8: VMOV.F32 <Sd>, <Sm>
5178 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5180 inst.operands[i].reg = val;
5181 inst.operands[i].isreg = 1;
5182 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5183 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5184 inst.operands[i].isvec = 1;
5185 inst.operands[i].vectype = optype;
5186 inst.operands[i].present = 1;
5188 if (skip_past_comma (&ptr) == SUCCESS)
5190 /* Case 15. */
5191 i++;
5193 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5194 goto wanted_arm;
5196 inst.operands[i].reg = val;
5197 inst.operands[i].isreg = 1;
5198 inst.operands[i++].present = 1;
5200 if (skip_past_comma (&ptr) == FAIL)
5201 goto wanted_comma;
5203 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5204 goto wanted_arm;
5206 inst.operands[i].reg = val;
5207 inst.operands[i].isreg = 1;
5208 inst.operands[i++].present = 1;
5211 else
5213 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5214 return FAIL;
5217 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5219 /* Cases 6, 7. */
5220 inst.operands[i].reg = val;
5221 inst.operands[i].isreg = 1;
5222 inst.operands[i++].present = 1;
5224 if (skip_past_comma (&ptr) == FAIL)
5225 goto wanted_comma;
5227 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5229 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5230 inst.operands[i].reg = val;
5231 inst.operands[i].isscalar = 1;
5232 inst.operands[i].present = 1;
5233 inst.operands[i].vectype = optype;
5235 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5237 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5238 inst.operands[i].reg = val;
5239 inst.operands[i].isreg = 1;
5240 inst.operands[i++].present = 1;
5242 if (skip_past_comma (&ptr) == FAIL)
5243 goto wanted_comma;
5245 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5246 == FAIL)
5248 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5249 return FAIL;
5252 inst.operands[i].reg = val;
5253 inst.operands[i].isreg = 1;
5254 inst.operands[i].isvec = 1;
5255 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5256 inst.operands[i].vectype = optype;
5257 inst.operands[i].present = 1;
5259 if (rtype == REG_TYPE_VFS)
5261 /* Case 14. */
5262 i++;
5263 if (skip_past_comma (&ptr) == FAIL)
5264 goto wanted_comma;
5265 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5266 &optype)) == FAIL)
5268 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5269 return FAIL;
5271 inst.operands[i].reg = val;
5272 inst.operands[i].isreg = 1;
5273 inst.operands[i].isvec = 1;
5274 inst.operands[i].issingle = 1;
5275 inst.operands[i].vectype = optype;
5276 inst.operands[i].present = 1;
5279 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5280 != FAIL)
5282 /* Case 13. */
5283 inst.operands[i].reg = val;
5284 inst.operands[i].isreg = 1;
5285 inst.operands[i].isvec = 1;
5286 inst.operands[i].issingle = 1;
5287 inst.operands[i].vectype = optype;
5288 inst.operands[i++].present = 1;
5291 else
5293 first_error (_("parse error"));
5294 return FAIL;
5297 /* Successfully parsed the operands. Update args. */
5298 *which_operand = i;
5299 *str = ptr;
5300 return SUCCESS;
5302 wanted_comma:
5303 first_error (_("expected comma"));
5304 return FAIL;
5306 wanted_arm:
5307 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5308 return FAIL;
5311 /* Matcher codes for parse_operands. */
5312 enum operand_parse_code
5314 OP_stop, /* end of line */
5316 OP_RR, /* ARM register */
5317 OP_RRnpc, /* ARM register, not r15 */
5318 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5319 OP_RRw, /* ARM register, not r15, optional trailing ! */
5320 OP_RCP, /* Coprocessor number */
5321 OP_RCN, /* Coprocessor register */
5322 OP_RF, /* FPA register */
5323 OP_RVS, /* VFP single precision register */
5324 OP_RVD, /* VFP double precision register (0..15) */
5325 OP_RND, /* Neon double precision register (0..31) */
5326 OP_RNQ, /* Neon quad precision register */
5327 OP_RVSD, /* VFP single or double precision register */
5328 OP_RNDQ, /* Neon double or quad precision register */
5329 OP_RNSDQ, /* Neon single, double or quad precision register */
5330 OP_RNSC, /* Neon scalar D[X] */
5331 OP_RVC, /* VFP control register */
5332 OP_RMF, /* Maverick F register */
5333 OP_RMD, /* Maverick D register */
5334 OP_RMFX, /* Maverick FX register */
5335 OP_RMDX, /* Maverick DX register */
5336 OP_RMAX, /* Maverick AX register */
5337 OP_RMDS, /* Maverick DSPSC register */
5338 OP_RIWR, /* iWMMXt wR register */
5339 OP_RIWC, /* iWMMXt wC register */
5340 OP_RIWG, /* iWMMXt wCG register */
5341 OP_RXA, /* XScale accumulator register */
5343 OP_REGLST, /* ARM register list */
5344 OP_VRSLST, /* VFP single-precision register list */
5345 OP_VRDLST, /* VFP double-precision register list */
5346 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5347 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5348 OP_NSTRLST, /* Neon element/structure list */
5350 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5351 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5352 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5353 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5354 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5355 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5356 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5357 OP_VMOV, /* Neon VMOV operands. */
5358 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5359 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5361 OP_I0, /* immediate zero */
5362 OP_I7, /* immediate value 0 .. 7 */
5363 OP_I15, /* 0 .. 15 */
5364 OP_I16, /* 1 .. 16 */
5365 OP_I16z, /* 0 .. 16 */
5366 OP_I31, /* 0 .. 31 */
5367 OP_I31w, /* 0 .. 31, optional trailing ! */
5368 OP_I32, /* 1 .. 32 */
5369 OP_I32z, /* 0 .. 32 */
5370 OP_I63, /* 0 .. 63 */
5371 OP_I63s, /* -64 .. 63 */
5372 OP_I64, /* 1 .. 64 */
5373 OP_I64z, /* 0 .. 64 */
5374 OP_I255, /* 0 .. 255 */
5376 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5377 OP_I7b, /* 0 .. 7 */
5378 OP_I15b, /* 0 .. 15 */
5379 OP_I31b, /* 0 .. 31 */
5381 OP_SH, /* shifter operand */
5382 OP_SHG, /* shifter operand with possible group relocation */
5383 OP_ADDR, /* Memory address expression (any mode) */
5384 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5385 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5386 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5387 OP_EXP, /* arbitrary expression */
5388 OP_EXPi, /* same, with optional immediate prefix */
5389 OP_EXPr, /* same, with optional relocation suffix */
5390 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5392 OP_CPSF, /* CPS flags */
5393 OP_ENDI, /* Endianness specifier */
5394 OP_PSR, /* CPSR/SPSR mask for msr */
5395 OP_COND, /* conditional code */
5396 OP_TB, /* Table branch. */
5398 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5399 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5401 OP_RRnpc_I0, /* ARM register or literal 0 */
5402 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5403 OP_RR_EXi, /* ARM register or expression with imm prefix */
5404 OP_RF_IF, /* FPA register or immediate */
5405 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5406 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5408 /* Optional operands. */
5409 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5410 OP_oI31b, /* 0 .. 31 */
5411 OP_oI32b, /* 1 .. 32 */
5412 OP_oIffffb, /* 0 .. 65535 */
5413 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5415 OP_oRR, /* ARM register */
5416 OP_oRRnpc, /* ARM register, not the PC */
5417 OP_oRND, /* Optional Neon double precision register */
5418 OP_oRNQ, /* Optional Neon quad precision register */
5419 OP_oRNDQ, /* Optional Neon double or quad precision register */
5420 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5421 OP_oSHll, /* LSL immediate */
5422 OP_oSHar, /* ASR immediate */
5423 OP_oSHllar, /* LSL or ASR immediate */
5424 OP_oROR, /* ROR 0/8/16/24 */
5425 OP_oBARRIER, /* Option argument for a barrier instruction. */
5427 OP_FIRST_OPTIONAL = OP_oI7b
5430 /* Generic instruction operand parser. This does no encoding and no
5431 semantic validation; it merely squirrels values away in the inst
5432 structure. Returns SUCCESS or FAIL depending on whether the
5433 specified grammar matched. */
5434 static int
5435 parse_operands (char *str, const unsigned char *pattern)
5437 unsigned const char *upat = pattern;
5438 char *backtrack_pos = 0;
5439 const char *backtrack_error = 0;
5440 int i, val, backtrack_index = 0;
5441 enum arm_reg_type rtype;
5442 parse_operand_result result;
5444 #define po_char_or_fail(chr) do { \
5445 if (skip_past_char (&str, chr) == FAIL) \
5446 goto bad_args; \
5447 } while (0)
5449 #define po_reg_or_fail(regtype) do { \
5450 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5451 &inst.operands[i].vectype); \
5452 if (val == FAIL) \
5454 first_error (_(reg_expected_msgs[regtype])); \
5455 goto failure; \
5457 inst.operands[i].reg = val; \
5458 inst.operands[i].isreg = 1; \
5459 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5460 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5461 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5462 || rtype == REG_TYPE_VFD \
5463 || rtype == REG_TYPE_NQ); \
5464 } while (0)
5466 #define po_reg_or_goto(regtype, label) do { \
5467 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5468 &inst.operands[i].vectype); \
5469 if (val == FAIL) \
5470 goto label; \
5472 inst.operands[i].reg = val; \
5473 inst.operands[i].isreg = 1; \
5474 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5475 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5476 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5477 || rtype == REG_TYPE_VFD \
5478 || rtype == REG_TYPE_NQ); \
5479 } while (0)
5481 #define po_imm_or_fail(min, max, popt) do { \
5482 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5483 goto failure; \
5484 inst.operands[i].imm = val; \
5485 } while (0)
5487 #define po_scalar_or_goto(elsz, label) do { \
5488 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5489 if (val == FAIL) \
5490 goto label; \
5491 inst.operands[i].reg = val; \
5492 inst.operands[i].isscalar = 1; \
5493 } while (0)
5495 #define po_misc_or_fail(expr) do { \
5496 if (expr) \
5497 goto failure; \
5498 } while (0)
5500 #define po_misc_or_fail_no_backtrack(expr) do { \
5501 result = expr; \
5502 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5503 backtrack_pos = 0; \
5504 if (result != PARSE_OPERAND_SUCCESS) \
5505 goto failure; \
5506 } while (0)
5508 skip_whitespace (str);
5510 for (i = 0; upat[i] != OP_stop; i++)
5512 if (upat[i] >= OP_FIRST_OPTIONAL)
5514 /* Remember where we are in case we need to backtrack. */
5515 assert (!backtrack_pos);
5516 backtrack_pos = str;
5517 backtrack_error = inst.error;
5518 backtrack_index = i;
5521 if (i > 0)
5522 po_char_or_fail (',');
5524 switch (upat[i])
5526 /* Registers */
5527 case OP_oRRnpc:
5528 case OP_RRnpc:
5529 case OP_oRR:
5530 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5531 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5532 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5533 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5534 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5535 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5536 case OP_oRND:
5537 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5538 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
5539 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5540 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5541 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5542 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5543 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5544 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5545 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5546 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5547 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5548 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5549 case OP_oRNQ:
5550 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5551 case OP_oRNDQ:
5552 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5553 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5554 case OP_oRNSDQ:
5555 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5557 /* Neon scalar. Using an element size of 8 means that some invalid
5558 scalars are accepted here, so deal with those in later code. */
5559 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5561 /* WARNING: We can expand to two operands here. This has the potential
5562 to totally confuse the backtracking mechanism! It will be OK at
5563 least as long as we don't try to use optional args as well,
5564 though. */
5565 case OP_NILO:
5567 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5568 inst.operands[i].present = 1;
5569 i++;
5570 skip_past_comma (&str);
5571 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5572 break;
5573 one_reg_only:
5574 /* Optional register operand was omitted. Unfortunately, it's in
5575 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5576 here (this is a bit grotty). */
5577 inst.operands[i] = inst.operands[i-1];
5578 inst.operands[i-1].present = 0;
5579 break;
5580 try_imm:
5581 /* Immediate gets verified properly later, so accept any now. */
5582 po_imm_or_fail (INT_MIN, INT_MAX, TRUE);
5584 break;
5586 case OP_RNDQ_I0:
5588 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5589 break;
5590 try_imm0:
5591 po_imm_or_fail (0, 0, TRUE);
5593 break;
5595 case OP_RVSD_I0:
5596 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5597 break;
5599 case OP_RR_RNSC:
5601 po_scalar_or_goto (8, try_rr);
5602 break;
5603 try_rr:
5604 po_reg_or_fail (REG_TYPE_RN);
5606 break;
5608 case OP_RNSDQ_RNSC:
5610 po_scalar_or_goto (8, try_nsdq);
5611 break;
5612 try_nsdq:
5613 po_reg_or_fail (REG_TYPE_NSDQ);
5615 break;
5617 case OP_RNDQ_RNSC:
5619 po_scalar_or_goto (8, try_ndq);
5620 break;
5621 try_ndq:
5622 po_reg_or_fail (REG_TYPE_NDQ);
5624 break;
5626 case OP_RND_RNSC:
5628 po_scalar_or_goto (8, try_vfd);
5629 break;
5630 try_vfd:
5631 po_reg_or_fail (REG_TYPE_VFD);
5633 break;
5635 case OP_VMOV:
5636 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5637 not careful then bad things might happen. */
5638 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5639 break;
5641 case OP_RNDQ_IMVNb:
5643 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5644 break;
5645 try_mvnimm:
5646 /* There's a possibility of getting a 64-bit immediate here, so
5647 we need special handling. */
5648 if (parse_big_immediate (&str, i) == FAIL)
5650 inst.error = _("immediate value is out of range");
5651 goto failure;
5654 break;
5656 case OP_RNDQ_I63b:
5658 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5659 break;
5660 try_shimm:
5661 po_imm_or_fail (0, 63, TRUE);
5663 break;
5665 case OP_RRnpcb:
5666 po_char_or_fail ('[');
5667 po_reg_or_fail (REG_TYPE_RN);
5668 po_char_or_fail (']');
5669 break;
5671 case OP_RRw:
5672 po_reg_or_fail (REG_TYPE_RN);
5673 if (skip_past_char (&str, '!') == SUCCESS)
5674 inst.operands[i].writeback = 1;
5675 break;
5677 /* Immediates */
5678 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5679 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5680 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5681 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5682 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5683 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5684 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5685 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5686 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5687 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5688 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5689 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5691 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5692 case OP_oI7b:
5693 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5694 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5695 case OP_oI31b:
5696 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5697 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5698 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5700 /* Immediate variants */
5701 case OP_oI255c:
5702 po_char_or_fail ('{');
5703 po_imm_or_fail (0, 255, TRUE);
5704 po_char_or_fail ('}');
5705 break;
5707 case OP_I31w:
5708 /* The expression parser chokes on a trailing !, so we have
5709 to find it first and zap it. */
5711 char *s = str;
5712 while (*s && *s != ',')
5713 s++;
5714 if (s[-1] == '!')
5716 s[-1] = '\0';
5717 inst.operands[i].writeback = 1;
5719 po_imm_or_fail (0, 31, TRUE);
5720 if (str == s - 1)
5721 str = s;
5723 break;
5725 /* Expressions */
5726 case OP_EXPi: EXPi:
5727 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5728 GE_OPT_PREFIX));
5729 break;
5731 case OP_EXP:
5732 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5733 GE_NO_PREFIX));
5734 break;
5736 case OP_EXPr: EXPr:
5737 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5738 GE_NO_PREFIX));
5739 if (inst.reloc.exp.X_op == O_symbol)
5741 val = parse_reloc (&str);
5742 if (val == -1)
5744 inst.error = _("unrecognized relocation suffix");
5745 goto failure;
5747 else if (val != BFD_RELOC_UNUSED)
5749 inst.operands[i].imm = val;
5750 inst.operands[i].hasreloc = 1;
5753 break;
5755 /* Operand for MOVW or MOVT. */
5756 case OP_HALF:
5757 po_misc_or_fail (parse_half (&str));
5758 break;
5760 /* Register or expression */
5761 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5762 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5764 /* Register or immediate */
5765 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5766 I0: po_imm_or_fail (0, 0, FALSE); break;
5768 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5770 if (!is_immediate_prefix (*str))
5771 goto bad_args;
5772 str++;
5773 val = parse_fpa_immediate (&str);
5774 if (val == FAIL)
5775 goto failure;
5776 /* FPA immediates are encoded as registers 8-15.
5777 parse_fpa_immediate has already applied the offset. */
5778 inst.operands[i].reg = val;
5779 inst.operands[i].isreg = 1;
5780 break;
5782 /* Two kinds of register */
5783 case OP_RIWR_RIWC:
5785 struct reg_entry *rege = arm_reg_parse_multi (&str);
5786 if (!rege
5787 || (rege->type != REG_TYPE_MMXWR
5788 && rege->type != REG_TYPE_MMXWC
5789 && rege->type != REG_TYPE_MMXWCG))
5791 inst.error = _("iWMMXt data or control register expected");
5792 goto failure;
5794 inst.operands[i].reg = rege->number;
5795 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5797 break;
5799 case OP_RIWC_RIWG:
5801 struct reg_entry *rege = arm_reg_parse_multi (&str);
5802 if (!rege
5803 || (rege->type != REG_TYPE_MMXWC
5804 && rege->type != REG_TYPE_MMXWCG))
5806 inst.error = _("iWMMXt control register expected");
5807 goto failure;
5809 inst.operands[i].reg = rege->number;
5810 inst.operands[i].isreg = 1;
5812 break;
5814 /* Misc */
5815 case OP_CPSF: val = parse_cps_flags (&str); break;
5816 case OP_ENDI: val = parse_endian_specifier (&str); break;
5817 case OP_oROR: val = parse_ror (&str); break;
5818 case OP_PSR: val = parse_psr (&str); break;
5819 case OP_COND: val = parse_cond (&str); break;
5820 case OP_oBARRIER:val = parse_barrier (&str); break;
5822 case OP_RVC_PSR:
5823 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5824 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5825 break;
5826 try_psr:
5827 val = parse_psr (&str);
5828 break;
5830 case OP_APSR_RR:
5831 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5832 break;
5833 try_apsr:
5834 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5835 instruction). */
5836 if (strncasecmp (str, "APSR_", 5) == 0)
5838 unsigned found = 0;
5839 str += 5;
5840 while (found < 15)
5841 switch (*str++)
5843 case 'c': found = (found & 1) ? 16 : found | 1; break;
5844 case 'n': found = (found & 2) ? 16 : found | 2; break;
5845 case 'z': found = (found & 4) ? 16 : found | 4; break;
5846 case 'v': found = (found & 8) ? 16 : found | 8; break;
5847 default: found = 16;
5849 if (found != 15)
5850 goto failure;
5851 inst.operands[i].isvec = 1;
5853 else
5854 goto failure;
5855 break;
5857 case OP_TB:
5858 po_misc_or_fail (parse_tb (&str));
5859 break;
5861 /* Register lists */
5862 case OP_REGLST:
5863 val = parse_reg_list (&str);
5864 if (*str == '^')
5866 inst.operands[1].writeback = 1;
5867 str++;
5869 break;
5871 case OP_VRSLST:
5872 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5873 break;
5875 case OP_VRDLST:
5876 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5877 break;
5879 case OP_VRSDLST:
5880 /* Allow Q registers too. */
5881 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5882 REGLIST_NEON_D);
5883 if (val == FAIL)
5885 inst.error = NULL;
5886 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5887 REGLIST_VFP_S);
5888 inst.operands[i].issingle = 1;
5890 break;
5892 case OP_NRDLST:
5893 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5894 REGLIST_NEON_D);
5895 break;
5897 case OP_NSTRLST:
5898 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5899 &inst.operands[i].vectype);
5900 break;
5902 /* Addressing modes */
5903 case OP_ADDR:
5904 po_misc_or_fail (parse_address (&str, i));
5905 break;
5907 case OP_ADDRGLDR:
5908 po_misc_or_fail_no_backtrack (
5909 parse_address_group_reloc (&str, i, GROUP_LDR));
5910 break;
5912 case OP_ADDRGLDRS:
5913 po_misc_or_fail_no_backtrack (
5914 parse_address_group_reloc (&str, i, GROUP_LDRS));
5915 break;
5917 case OP_ADDRGLDC:
5918 po_misc_or_fail_no_backtrack (
5919 parse_address_group_reloc (&str, i, GROUP_LDC));
5920 break;
5922 case OP_SH:
5923 po_misc_or_fail (parse_shifter_operand (&str, i));
5924 break;
5926 case OP_SHG:
5927 po_misc_or_fail_no_backtrack (
5928 parse_shifter_operand_group_reloc (&str, i));
5929 break;
5931 case OP_oSHll:
5932 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
5933 break;
5935 case OP_oSHar:
5936 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
5937 break;
5939 case OP_oSHllar:
5940 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
5941 break;
5943 default:
5944 as_fatal ("unhandled operand code %d", upat[i]);
5947 /* Various value-based sanity checks and shared operations. We
5948 do not signal immediate failures for the register constraints;
5949 this allows a syntax error to take precedence. */
5950 switch (upat[i])
5952 case OP_oRRnpc:
5953 case OP_RRnpc:
5954 case OP_RRnpcb:
5955 case OP_RRw:
5956 case OP_RRnpc_I0:
5957 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
5958 inst.error = BAD_PC;
5959 break;
5961 case OP_CPSF:
5962 case OP_ENDI:
5963 case OP_oROR:
5964 case OP_PSR:
5965 case OP_RVC_PSR:
5966 case OP_COND:
5967 case OP_oBARRIER:
5968 case OP_REGLST:
5969 case OP_VRSLST:
5970 case OP_VRDLST:
5971 case OP_VRSDLST:
5972 case OP_NRDLST:
5973 case OP_NSTRLST:
5974 if (val == FAIL)
5975 goto failure;
5976 inst.operands[i].imm = val;
5977 break;
5979 default:
5980 break;
5983 /* If we get here, this operand was successfully parsed. */
5984 inst.operands[i].present = 1;
5985 continue;
5987 bad_args:
5988 inst.error = BAD_ARGS;
5990 failure:
5991 if (!backtrack_pos)
5993 /* The parse routine should already have set inst.error, but set a
5994 defaut here just in case. */
5995 if (!inst.error)
5996 inst.error = _("syntax error");
5997 return FAIL;
6000 /* Do not backtrack over a trailing optional argument that
6001 absorbed some text. We will only fail again, with the
6002 'garbage following instruction' error message, which is
6003 probably less helpful than the current one. */
6004 if (backtrack_index == i && backtrack_pos != str
6005 && upat[i+1] == OP_stop)
6007 if (!inst.error)
6008 inst.error = _("syntax error");
6009 return FAIL;
6012 /* Try again, skipping the optional argument at backtrack_pos. */
6013 str = backtrack_pos;
6014 inst.error = backtrack_error;
6015 inst.operands[backtrack_index].present = 0;
6016 i = backtrack_index;
6017 backtrack_pos = 0;
6020 /* Check that we have parsed all the arguments. */
6021 if (*str != '\0' && !inst.error)
6022 inst.error = _("garbage following instruction");
6024 return inst.error ? FAIL : SUCCESS;
6027 #undef po_char_or_fail
6028 #undef po_reg_or_fail
6029 #undef po_reg_or_goto
6030 #undef po_imm_or_fail
6031 #undef po_scalar_or_fail
6033 /* Shorthand macro for instruction encoding functions issuing errors. */
6034 #define constraint(expr, err) do { \
6035 if (expr) \
6037 inst.error = err; \
6038 return; \
6040 } while (0)
6042 /* Functions for operand encoding. ARM, then Thumb. */
6044 #define rotate_left(v, n) (v << n | v >> (32 - n))
6046 /* If VAL can be encoded in the immediate field of an ARM instruction,
6047 return the encoded form. Otherwise, return FAIL. */
6049 static unsigned int
6050 encode_arm_immediate (unsigned int val)
6052 unsigned int a, i;
6054 for (i = 0; i < 32; i += 2)
6055 if ((a = rotate_left (val, i)) <= 0xff)
6056 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6058 return FAIL;
6061 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6062 return the encoded form. Otherwise, return FAIL. */
6063 static unsigned int
6064 encode_thumb32_immediate (unsigned int val)
6066 unsigned int a, i;
6068 if (val <= 0xff)
6069 return val;
6071 for (i = 1; i <= 24; i++)
6073 a = val >> i;
6074 if ((val & ~(0xff << i)) == 0)
6075 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6078 a = val & 0xff;
6079 if (val == ((a << 16) | a))
6080 return 0x100 | a;
6081 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6082 return 0x300 | a;
6084 a = val & 0xff00;
6085 if (val == ((a << 16) | a))
6086 return 0x200 | (a >> 8);
6088 return FAIL;
6090 /* Encode a VFP SP or DP register number into inst.instruction. */
6092 static void
6093 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6095 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6096 && reg > 15)
6098 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6100 if (thumb_mode)
6101 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6102 fpu_vfp_ext_v3);
6103 else
6104 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6105 fpu_vfp_ext_v3);
6107 else
6109 first_error (_("D register out of range for selected VFP version"));
6110 return;
6114 switch (pos)
6116 case VFP_REG_Sd:
6117 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6118 break;
6120 case VFP_REG_Sn:
6121 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6122 break;
6124 case VFP_REG_Sm:
6125 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6126 break;
6128 case VFP_REG_Dd:
6129 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6130 break;
6132 case VFP_REG_Dn:
6133 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6134 break;
6136 case VFP_REG_Dm:
6137 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6138 break;
6140 default:
6141 abort ();
6145 /* Encode a <shift> in an ARM-format instruction. The immediate,
6146 if any, is handled by md_apply_fix. */
6147 static void
6148 encode_arm_shift (int i)
6150 if (inst.operands[i].shift_kind == SHIFT_RRX)
6151 inst.instruction |= SHIFT_ROR << 5;
6152 else
6154 inst.instruction |= inst.operands[i].shift_kind << 5;
6155 if (inst.operands[i].immisreg)
6157 inst.instruction |= SHIFT_BY_REG;
6158 inst.instruction |= inst.operands[i].imm << 8;
6160 else
6161 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6165 static void
6166 encode_arm_shifter_operand (int i)
6168 if (inst.operands[i].isreg)
6170 inst.instruction |= inst.operands[i].reg;
6171 encode_arm_shift (i);
6173 else
6174 inst.instruction |= INST_IMMEDIATE;
6177 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6178 static void
6179 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6181 assert (inst.operands[i].isreg);
6182 inst.instruction |= inst.operands[i].reg << 16;
6184 if (inst.operands[i].preind)
6186 if (is_t)
6188 inst.error = _("instruction does not accept preindexed addressing");
6189 return;
6191 inst.instruction |= PRE_INDEX;
6192 if (inst.operands[i].writeback)
6193 inst.instruction |= WRITE_BACK;
6196 else if (inst.operands[i].postind)
6198 assert (inst.operands[i].writeback);
6199 if (is_t)
6200 inst.instruction |= WRITE_BACK;
6202 else /* unindexed - only for coprocessor */
6204 inst.error = _("instruction does not accept unindexed addressing");
6205 return;
6208 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6209 && (((inst.instruction & 0x000f0000) >> 16)
6210 == ((inst.instruction & 0x0000f000) >> 12)))
6211 as_warn ((inst.instruction & LOAD_BIT)
6212 ? _("destination register same as write-back base")
6213 : _("source register same as write-back base"));
6216 /* inst.operands[i] was set up by parse_address. Encode it into an
6217 ARM-format mode 2 load or store instruction. If is_t is true,
6218 reject forms that cannot be used with a T instruction (i.e. not
6219 post-indexed). */
6220 static void
6221 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6223 encode_arm_addr_mode_common (i, is_t);
6225 if (inst.operands[i].immisreg)
6227 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6228 inst.instruction |= inst.operands[i].imm;
6229 if (!inst.operands[i].negative)
6230 inst.instruction |= INDEX_UP;
6231 if (inst.operands[i].shifted)
6233 if (inst.operands[i].shift_kind == SHIFT_RRX)
6234 inst.instruction |= SHIFT_ROR << 5;
6235 else
6237 inst.instruction |= inst.operands[i].shift_kind << 5;
6238 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6242 else /* immediate offset in inst.reloc */
6244 if (inst.reloc.type == BFD_RELOC_UNUSED)
6245 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6249 /* inst.operands[i] was set up by parse_address. Encode it into an
6250 ARM-format mode 3 load or store instruction. Reject forms that
6251 cannot be used with such instructions. If is_t is true, reject
6252 forms that cannot be used with a T instruction (i.e. not
6253 post-indexed). */
6254 static void
6255 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6257 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6259 inst.error = _("instruction does not accept scaled register index");
6260 return;
6263 encode_arm_addr_mode_common (i, is_t);
6265 if (inst.operands[i].immisreg)
6267 inst.instruction |= inst.operands[i].imm;
6268 if (!inst.operands[i].negative)
6269 inst.instruction |= INDEX_UP;
6271 else /* immediate offset in inst.reloc */
6273 inst.instruction |= HWOFFSET_IMM;
6274 if (inst.reloc.type == BFD_RELOC_UNUSED)
6275 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6279 /* inst.operands[i] was set up by parse_address. Encode it into an
6280 ARM-format instruction. Reject all forms which cannot be encoded
6281 into a coprocessor load/store instruction. If wb_ok is false,
6282 reject use of writeback; if unind_ok is false, reject use of
6283 unindexed addressing. If reloc_override is not 0, use it instead
6284 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6285 (in which case it is preserved). */
6287 static int
6288 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6290 inst.instruction |= inst.operands[i].reg << 16;
6292 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6294 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6296 assert (!inst.operands[i].writeback);
6297 if (!unind_ok)
6299 inst.error = _("instruction does not support unindexed addressing");
6300 return FAIL;
6302 inst.instruction |= inst.operands[i].imm;
6303 inst.instruction |= INDEX_UP;
6304 return SUCCESS;
6307 if (inst.operands[i].preind)
6308 inst.instruction |= PRE_INDEX;
6310 if (inst.operands[i].writeback)
6312 if (inst.operands[i].reg == REG_PC)
6314 inst.error = _("pc may not be used with write-back");
6315 return FAIL;
6317 if (!wb_ok)
6319 inst.error = _("instruction does not support writeback");
6320 return FAIL;
6322 inst.instruction |= WRITE_BACK;
6325 if (reloc_override)
6326 inst.reloc.type = reloc_override;
6327 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6328 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6329 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6331 if (thumb_mode)
6332 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6333 else
6334 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6337 return SUCCESS;
6340 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6341 Determine whether it can be performed with a move instruction; if
6342 it can, convert inst.instruction to that move instruction and
6343 return 1; if it can't, convert inst.instruction to a literal-pool
6344 load and return 0. If this is not a valid thing to do in the
6345 current context, set inst.error and return 1.
6347 inst.operands[i] describes the destination register. */
6349 static int
6350 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6352 unsigned long tbit;
6354 if (thumb_p)
6355 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6356 else
6357 tbit = LOAD_BIT;
6359 if ((inst.instruction & tbit) == 0)
6361 inst.error = _("invalid pseudo operation");
6362 return 1;
6364 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6366 inst.error = _("constant expression expected");
6367 return 1;
6369 if (inst.reloc.exp.X_op == O_constant)
6371 if (thumb_p)
6373 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6375 /* This can be done with a mov(1) instruction. */
6376 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6377 inst.instruction |= inst.reloc.exp.X_add_number;
6378 return 1;
6381 else
6383 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6384 if (value != FAIL)
6386 /* This can be done with a mov instruction. */
6387 inst.instruction &= LITERAL_MASK;
6388 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6389 inst.instruction |= value & 0xfff;
6390 return 1;
6393 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6394 if (value != FAIL)
6396 /* This can be done with a mvn instruction. */
6397 inst.instruction &= LITERAL_MASK;
6398 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6399 inst.instruction |= value & 0xfff;
6400 return 1;
6405 if (add_to_lit_pool () == FAIL)
6407 inst.error = _("literal pool insertion failed");
6408 return 1;
6410 inst.operands[1].reg = REG_PC;
6411 inst.operands[1].isreg = 1;
6412 inst.operands[1].preind = 1;
6413 inst.reloc.pc_rel = 1;
6414 inst.reloc.type = (thumb_p
6415 ? BFD_RELOC_ARM_THUMB_OFFSET
6416 : (mode_3
6417 ? BFD_RELOC_ARM_HWLITERAL
6418 : BFD_RELOC_ARM_LITERAL));
6419 return 0;
6422 /* Functions for instruction encoding, sorted by subarchitecture.
6423 First some generics; their names are taken from the conventional
6424 bit positions for register arguments in ARM format instructions. */
6426 static void
6427 do_noargs (void)
6431 static void
6432 do_rd (void)
6434 inst.instruction |= inst.operands[0].reg << 12;
6437 static void
6438 do_rd_rm (void)
6440 inst.instruction |= inst.operands[0].reg << 12;
6441 inst.instruction |= inst.operands[1].reg;
6444 static void
6445 do_rd_rn (void)
6447 inst.instruction |= inst.operands[0].reg << 12;
6448 inst.instruction |= inst.operands[1].reg << 16;
6451 static void
6452 do_rn_rd (void)
6454 inst.instruction |= inst.operands[0].reg << 16;
6455 inst.instruction |= inst.operands[1].reg << 12;
6458 static void
6459 do_rd_rm_rn (void)
6461 unsigned Rn = inst.operands[2].reg;
6462 /* Enforce resutrictions on SWP instruction. */
6463 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6464 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6465 _("Rn must not overlap other operands"));
6466 inst.instruction |= inst.operands[0].reg << 12;
6467 inst.instruction |= inst.operands[1].reg;
6468 inst.instruction |= Rn << 16;
6471 static void
6472 do_rd_rn_rm (void)
6474 inst.instruction |= inst.operands[0].reg << 12;
6475 inst.instruction |= inst.operands[1].reg << 16;
6476 inst.instruction |= inst.operands[2].reg;
6479 static void
6480 do_rm_rd_rn (void)
6482 inst.instruction |= inst.operands[0].reg;
6483 inst.instruction |= inst.operands[1].reg << 12;
6484 inst.instruction |= inst.operands[2].reg << 16;
6487 static void
6488 do_imm0 (void)
6490 inst.instruction |= inst.operands[0].imm;
6493 static void
6494 do_rd_cpaddr (void)
6496 inst.instruction |= inst.operands[0].reg << 12;
6497 encode_arm_cp_address (1, TRUE, TRUE, 0);
6500 /* ARM instructions, in alphabetical order by function name (except
6501 that wrapper functions appear immediately after the function they
6502 wrap). */
6504 /* This is a pseudo-op of the form "adr rd, label" to be converted
6505 into a relative address of the form "add rd, pc, #label-.-8". */
6507 static void
6508 do_adr (void)
6510 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6512 /* Frag hacking will turn this into a sub instruction if the offset turns
6513 out to be negative. */
6514 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6515 inst.reloc.pc_rel = 1;
6516 inst.reloc.exp.X_add_number -= 8;
6519 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6520 into a relative address of the form:
6521 add rd, pc, #low(label-.-8)"
6522 add rd, rd, #high(label-.-8)" */
6524 static void
6525 do_adrl (void)
6527 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6529 /* Frag hacking will turn this into a sub instruction if the offset turns
6530 out to be negative. */
6531 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6532 inst.reloc.pc_rel = 1;
6533 inst.size = INSN_SIZE * 2;
6534 inst.reloc.exp.X_add_number -= 8;
6537 static void
6538 do_arit (void)
6540 if (!inst.operands[1].present)
6541 inst.operands[1].reg = inst.operands[0].reg;
6542 inst.instruction |= inst.operands[0].reg << 12;
6543 inst.instruction |= inst.operands[1].reg << 16;
6544 encode_arm_shifter_operand (2);
6547 static void
6548 do_barrier (void)
6550 if (inst.operands[0].present)
6552 constraint ((inst.instruction & 0xf0) != 0x40
6553 && inst.operands[0].imm != 0xf,
6554 "bad barrier type");
6555 inst.instruction |= inst.operands[0].imm;
6557 else
6558 inst.instruction |= 0xf;
6561 static void
6562 do_bfc (void)
6564 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6565 constraint (msb > 32, _("bit-field extends past end of register"));
6566 /* The instruction encoding stores the LSB and MSB,
6567 not the LSB and width. */
6568 inst.instruction |= inst.operands[0].reg << 12;
6569 inst.instruction |= inst.operands[1].imm << 7;
6570 inst.instruction |= (msb - 1) << 16;
6573 static void
6574 do_bfi (void)
6576 unsigned int msb;
6578 /* #0 in second position is alternative syntax for bfc, which is
6579 the same instruction but with REG_PC in the Rm field. */
6580 if (!inst.operands[1].isreg)
6581 inst.operands[1].reg = REG_PC;
6583 msb = inst.operands[2].imm + inst.operands[3].imm;
6584 constraint (msb > 32, _("bit-field extends past end of register"));
6585 /* The instruction encoding stores the LSB and MSB,
6586 not the LSB and width. */
6587 inst.instruction |= inst.operands[0].reg << 12;
6588 inst.instruction |= inst.operands[1].reg;
6589 inst.instruction |= inst.operands[2].imm << 7;
6590 inst.instruction |= (msb - 1) << 16;
6593 static void
6594 do_bfx (void)
6596 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6597 _("bit-field extends past end of register"));
6598 inst.instruction |= inst.operands[0].reg << 12;
6599 inst.instruction |= inst.operands[1].reg;
6600 inst.instruction |= inst.operands[2].imm << 7;
6601 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6604 /* ARM V5 breakpoint instruction (argument parse)
6605 BKPT <16 bit unsigned immediate>
6606 Instruction is not conditional.
6607 The bit pattern given in insns[] has the COND_ALWAYS condition,
6608 and it is an error if the caller tried to override that. */
6610 static void
6611 do_bkpt (void)
6613 /* Top 12 of 16 bits to bits 19:8. */
6614 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6616 /* Bottom 4 of 16 bits to bits 3:0. */
6617 inst.instruction |= inst.operands[0].imm & 0xf;
6620 static void
6621 encode_branch (int default_reloc)
6623 if (inst.operands[0].hasreloc)
6625 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6626 _("the only suffix valid here is '(plt)'"));
6627 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6629 else
6631 inst.reloc.type = default_reloc;
6633 inst.reloc.pc_rel = 1;
6636 static void
6637 do_branch (void)
6639 #ifdef OBJ_ELF
6640 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6641 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6642 else
6643 #endif
6644 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6647 static void
6648 do_bl (void)
6650 #ifdef OBJ_ELF
6651 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6653 if (inst.cond == COND_ALWAYS)
6654 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6655 else
6656 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6658 else
6659 #endif
6660 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6663 /* ARM V5 branch-link-exchange instruction (argument parse)
6664 BLX <target_addr> ie BLX(1)
6665 BLX{<condition>} <Rm> ie BLX(2)
6666 Unfortunately, there are two different opcodes for this mnemonic.
6667 So, the insns[].value is not used, and the code here zaps values
6668 into inst.instruction.
6669 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6671 static void
6672 do_blx (void)
6674 if (inst.operands[0].isreg)
6676 /* Arg is a register; the opcode provided by insns[] is correct.
6677 It is not illegal to do "blx pc", just useless. */
6678 if (inst.operands[0].reg == REG_PC)
6679 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6681 inst.instruction |= inst.operands[0].reg;
6683 else
6685 /* Arg is an address; this instruction cannot be executed
6686 conditionally, and the opcode must be adjusted. */
6687 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6688 inst.instruction = 0xfa000000;
6689 #ifdef OBJ_ELF
6690 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6691 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6692 else
6693 #endif
6694 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6698 static void
6699 do_bx (void)
6701 if (inst.operands[0].reg == REG_PC)
6702 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6704 inst.instruction |= inst.operands[0].reg;
6708 /* ARM v5TEJ. Jump to Jazelle code. */
6710 static void
6711 do_bxj (void)
6713 if (inst.operands[0].reg == REG_PC)
6714 as_tsktsk (_("use of r15 in bxj is not really useful"));
6716 inst.instruction |= inst.operands[0].reg;
6719 /* Co-processor data operation:
6720 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6721 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6722 static void
6723 do_cdp (void)
6725 inst.instruction |= inst.operands[0].reg << 8;
6726 inst.instruction |= inst.operands[1].imm << 20;
6727 inst.instruction |= inst.operands[2].reg << 12;
6728 inst.instruction |= inst.operands[3].reg << 16;
6729 inst.instruction |= inst.operands[4].reg;
6730 inst.instruction |= inst.operands[5].imm << 5;
6733 static void
6734 do_cmp (void)
6736 inst.instruction |= inst.operands[0].reg << 16;
6737 encode_arm_shifter_operand (1);
6740 /* Transfer between coprocessor and ARM registers.
6741 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6742 MRC2
6743 MCR{cond}
6744 MCR2
6746 No special properties. */
6748 static void
6749 do_co_reg (void)
6751 inst.instruction |= inst.operands[0].reg << 8;
6752 inst.instruction |= inst.operands[1].imm << 21;
6753 inst.instruction |= inst.operands[2].reg << 12;
6754 inst.instruction |= inst.operands[3].reg << 16;
6755 inst.instruction |= inst.operands[4].reg;
6756 inst.instruction |= inst.operands[5].imm << 5;
6759 /* Transfer between coprocessor register and pair of ARM registers.
6760 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6761 MCRR2
6762 MRRC{cond}
6763 MRRC2
6765 Two XScale instructions are special cases of these:
6767 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6768 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6770 Result unpredicatable if Rd or Rn is R15. */
6772 static void
6773 do_co_reg2c (void)
6775 inst.instruction |= inst.operands[0].reg << 8;
6776 inst.instruction |= inst.operands[1].imm << 4;
6777 inst.instruction |= inst.operands[2].reg << 12;
6778 inst.instruction |= inst.operands[3].reg << 16;
6779 inst.instruction |= inst.operands[4].reg;
6782 static void
6783 do_cpsi (void)
6785 inst.instruction |= inst.operands[0].imm << 6;
6786 inst.instruction |= inst.operands[1].imm;
6789 static void
6790 do_dbg (void)
6792 inst.instruction |= inst.operands[0].imm;
6795 static void
6796 do_it (void)
6798 /* There is no IT instruction in ARM mode. We
6799 process it but do not generate code for it. */
6800 inst.size = 0;
6803 static void
6804 do_ldmstm (void)
6806 int base_reg = inst.operands[0].reg;
6807 int range = inst.operands[1].imm;
6809 inst.instruction |= base_reg << 16;
6810 inst.instruction |= range;
6812 if (inst.operands[1].writeback)
6813 inst.instruction |= LDM_TYPE_2_OR_3;
6815 if (inst.operands[0].writeback)
6817 inst.instruction |= WRITE_BACK;
6818 /* Check for unpredictable uses of writeback. */
6819 if (inst.instruction & LOAD_BIT)
6821 /* Not allowed in LDM type 2. */
6822 if ((inst.instruction & LDM_TYPE_2_OR_3)
6823 && ((range & (1 << REG_PC)) == 0))
6824 as_warn (_("writeback of base register is UNPREDICTABLE"));
6825 /* Only allowed if base reg not in list for other types. */
6826 else if (range & (1 << base_reg))
6827 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6829 else /* STM. */
6831 /* Not allowed for type 2. */
6832 if (inst.instruction & LDM_TYPE_2_OR_3)
6833 as_warn (_("writeback of base register is UNPREDICTABLE"));
6834 /* Only allowed if base reg not in list, or first in list. */
6835 else if ((range & (1 << base_reg))
6836 && (range & ((1 << base_reg) - 1)))
6837 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
6842 /* ARMv5TE load-consecutive (argument parse)
6843 Mode is like LDRH.
6845 LDRccD R, mode
6846 STRccD R, mode. */
6848 static void
6849 do_ldrd (void)
6851 constraint (inst.operands[0].reg % 2 != 0,
6852 _("first destination register must be even"));
6853 constraint (inst.operands[1].present
6854 && inst.operands[1].reg != inst.operands[0].reg + 1,
6855 _("can only load two consecutive registers"));
6856 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6857 constraint (!inst.operands[2].isreg, _("'[' expected"));
6859 if (!inst.operands[1].present)
6860 inst.operands[1].reg = inst.operands[0].reg + 1;
6862 if (inst.instruction & LOAD_BIT)
6864 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6865 register and the first register written; we have to diagnose
6866 overlap between the base and the second register written here. */
6868 if (inst.operands[2].reg == inst.operands[1].reg
6869 && (inst.operands[2].writeback || inst.operands[2].postind))
6870 as_warn (_("base register written back, and overlaps "
6871 "second destination register"));
6873 /* For an index-register load, the index register must not overlap the
6874 destination (even if not write-back). */
6875 else if (inst.operands[2].immisreg
6876 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6877 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
6878 as_warn (_("index register overlaps destination register"));
6881 inst.instruction |= inst.operands[0].reg << 12;
6882 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
6885 static void
6886 do_ldrex (void)
6888 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6889 || inst.operands[1].postind || inst.operands[1].writeback
6890 || inst.operands[1].immisreg || inst.operands[1].shifted
6891 || inst.operands[1].negative
6892 /* This can arise if the programmer has written
6893 strex rN, rM, foo
6894 or if they have mistakenly used a register name as the last
6895 operand, eg:
6896 strex rN, rM, rX
6897 It is very difficult to distinguish between these two cases
6898 because "rX" might actually be a label. ie the register
6899 name has been occluded by a symbol of the same name. So we
6900 just generate a general 'bad addressing mode' type error
6901 message and leave it up to the programmer to discover the
6902 true cause and fix their mistake. */
6903 || (inst.operands[1].reg == REG_PC),
6904 BAD_ADDR_MODE);
6906 constraint (inst.reloc.exp.X_op != O_constant
6907 || inst.reloc.exp.X_add_number != 0,
6908 _("offset must be zero in ARM encoding"));
6910 inst.instruction |= inst.operands[0].reg << 12;
6911 inst.instruction |= inst.operands[1].reg << 16;
6912 inst.reloc.type = BFD_RELOC_UNUSED;
6915 static void
6916 do_ldrexd (void)
6918 constraint (inst.operands[0].reg % 2 != 0,
6919 _("even register required"));
6920 constraint (inst.operands[1].present
6921 && inst.operands[1].reg != inst.operands[0].reg + 1,
6922 _("can only load two consecutive registers"));
6923 /* If op 1 were present and equal to PC, this function wouldn't
6924 have been called in the first place. */
6925 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6927 inst.instruction |= inst.operands[0].reg << 12;
6928 inst.instruction |= inst.operands[2].reg << 16;
6931 static void
6932 do_ldst (void)
6934 inst.instruction |= inst.operands[0].reg << 12;
6935 if (!inst.operands[1].isreg)
6936 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
6937 return;
6938 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
6941 static void
6942 do_ldstt (void)
6944 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
6945 reject [Rn,...]. */
6946 if (inst.operands[1].preind)
6948 constraint (inst.reloc.exp.X_op != O_constant ||
6949 inst.reloc.exp.X_add_number != 0,
6950 _("this instruction requires a post-indexed address"));
6952 inst.operands[1].preind = 0;
6953 inst.operands[1].postind = 1;
6954 inst.operands[1].writeback = 1;
6956 inst.instruction |= inst.operands[0].reg << 12;
6957 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
6960 /* Halfword and signed-byte load/store operations. */
6962 static void
6963 do_ldstv4 (void)
6965 inst.instruction |= inst.operands[0].reg << 12;
6966 if (!inst.operands[1].isreg)
6967 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
6968 return;
6969 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
6972 static void
6973 do_ldsttv4 (void)
6975 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
6976 reject [Rn,...]. */
6977 if (inst.operands[1].preind)
6979 constraint (inst.reloc.exp.X_op != O_constant ||
6980 inst.reloc.exp.X_add_number != 0,
6981 _("this instruction requires a post-indexed address"));
6983 inst.operands[1].preind = 0;
6984 inst.operands[1].postind = 1;
6985 inst.operands[1].writeback = 1;
6987 inst.instruction |= inst.operands[0].reg << 12;
6988 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
6991 /* Co-processor register load/store.
6992 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
6993 static void
6994 do_lstc (void)
6996 inst.instruction |= inst.operands[0].reg << 8;
6997 inst.instruction |= inst.operands[1].reg << 12;
6998 encode_arm_cp_address (2, TRUE, TRUE, 0);
7001 static void
7002 do_mlas (void)
7004 /* This restriction does not apply to mls (nor to mla in v6, but
7005 that's hard to detect at present). */
7006 if (inst.operands[0].reg == inst.operands[1].reg
7007 && !(inst.instruction & 0x00400000))
7008 as_tsktsk (_("rd and rm should be different in mla"));
7010 inst.instruction |= inst.operands[0].reg << 16;
7011 inst.instruction |= inst.operands[1].reg;
7012 inst.instruction |= inst.operands[2].reg << 8;
7013 inst.instruction |= inst.operands[3].reg << 12;
7017 static void
7018 do_mov (void)
7020 inst.instruction |= inst.operands[0].reg << 12;
7021 encode_arm_shifter_operand (1);
7024 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7025 static void
7026 do_mov16 (void)
7028 bfd_vma imm;
7029 bfd_boolean top;
7031 top = (inst.instruction & 0x00400000) != 0;
7032 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7033 _(":lower16: not allowed this instruction"));
7034 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7035 _(":upper16: not allowed instruction"));
7036 inst.instruction |= inst.operands[0].reg << 12;
7037 if (inst.reloc.type == BFD_RELOC_UNUSED)
7039 imm = inst.reloc.exp.X_add_number;
7040 /* The value is in two pieces: 0:11, 16:19. */
7041 inst.instruction |= (imm & 0x00000fff);
7042 inst.instruction |= (imm & 0x0000f000) << 4;
7046 static void do_vfp_nsyn_opcode (const char *);
7048 static int
7049 do_vfp_nsyn_mrs (void)
7051 if (inst.operands[0].isvec)
7053 if (inst.operands[1].reg != 1)
7054 first_error (_("operand 1 must be FPSCR"));
7055 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7056 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7057 do_vfp_nsyn_opcode ("fmstat");
7059 else if (inst.operands[1].isvec)
7060 do_vfp_nsyn_opcode ("fmrx");
7061 else
7062 return FAIL;
7064 return SUCCESS;
7067 static int
7068 do_vfp_nsyn_msr (void)
7070 if (inst.operands[0].isvec)
7071 do_vfp_nsyn_opcode ("fmxr");
7072 else
7073 return FAIL;
7075 return SUCCESS;
7078 static void
7079 do_mrs (void)
7081 if (do_vfp_nsyn_mrs () == SUCCESS)
7082 return;
7084 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7085 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7086 != (PSR_c|PSR_f),
7087 _("'CPSR' or 'SPSR' expected"));
7088 inst.instruction |= inst.operands[0].reg << 12;
7089 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7092 /* Two possible forms:
7093 "{C|S}PSR_<field>, Rm",
7094 "{C|S}PSR_f, #expression". */
7096 static void
7097 do_msr (void)
7099 if (do_vfp_nsyn_msr () == SUCCESS)
7100 return;
7102 inst.instruction |= inst.operands[0].imm;
7103 if (inst.operands[1].isreg)
7104 inst.instruction |= inst.operands[1].reg;
7105 else
7107 inst.instruction |= INST_IMMEDIATE;
7108 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7109 inst.reloc.pc_rel = 0;
7113 static void
7114 do_mul (void)
7116 if (!inst.operands[2].present)
7117 inst.operands[2].reg = inst.operands[0].reg;
7118 inst.instruction |= inst.operands[0].reg << 16;
7119 inst.instruction |= inst.operands[1].reg;
7120 inst.instruction |= inst.operands[2].reg << 8;
7122 if (inst.operands[0].reg == inst.operands[1].reg)
7123 as_tsktsk (_("rd and rm should be different in mul"));
7126 /* Long Multiply Parser
7127 UMULL RdLo, RdHi, Rm, Rs
7128 SMULL RdLo, RdHi, Rm, Rs
7129 UMLAL RdLo, RdHi, Rm, Rs
7130 SMLAL RdLo, RdHi, Rm, Rs. */
7132 static void
7133 do_mull (void)
7135 inst.instruction |= inst.operands[0].reg << 12;
7136 inst.instruction |= inst.operands[1].reg << 16;
7137 inst.instruction |= inst.operands[2].reg;
7138 inst.instruction |= inst.operands[3].reg << 8;
7140 /* rdhi, rdlo and rm must all be different. */
7141 if (inst.operands[0].reg == inst.operands[1].reg
7142 || inst.operands[0].reg == inst.operands[2].reg
7143 || inst.operands[1].reg == inst.operands[2].reg)
7144 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7147 static void
7148 do_nop (void)
7150 if (inst.operands[0].present)
7152 /* Architectural NOP hints are CPSR sets with no bits selected. */
7153 inst.instruction &= 0xf0000000;
7154 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7158 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7159 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7160 Condition defaults to COND_ALWAYS.
7161 Error if Rd, Rn or Rm are R15. */
7163 static void
7164 do_pkhbt (void)
7166 inst.instruction |= inst.operands[0].reg << 12;
7167 inst.instruction |= inst.operands[1].reg << 16;
7168 inst.instruction |= inst.operands[2].reg;
7169 if (inst.operands[3].present)
7170 encode_arm_shift (3);
7173 /* ARM V6 PKHTB (Argument Parse). */
7175 static void
7176 do_pkhtb (void)
7178 if (!inst.operands[3].present)
7180 /* If the shift specifier is omitted, turn the instruction
7181 into pkhbt rd, rm, rn. */
7182 inst.instruction &= 0xfff00010;
7183 inst.instruction |= inst.operands[0].reg << 12;
7184 inst.instruction |= inst.operands[1].reg;
7185 inst.instruction |= inst.operands[2].reg << 16;
7187 else
7189 inst.instruction |= inst.operands[0].reg << 12;
7190 inst.instruction |= inst.operands[1].reg << 16;
7191 inst.instruction |= inst.operands[2].reg;
7192 encode_arm_shift (3);
7196 /* ARMv5TE: Preload-Cache
7198 PLD <addr_mode>
7200 Syntactically, like LDR with B=1, W=0, L=1. */
7202 static void
7203 do_pld (void)
7205 constraint (!inst.operands[0].isreg,
7206 _("'[' expected after PLD mnemonic"));
7207 constraint (inst.operands[0].postind,
7208 _("post-indexed expression used in preload instruction"));
7209 constraint (inst.operands[0].writeback,
7210 _("writeback used in preload instruction"));
7211 constraint (!inst.operands[0].preind,
7212 _("unindexed addressing used in preload instruction"));
7213 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7216 /* ARMv7: PLI <addr_mode> */
7217 static void
7218 do_pli (void)
7220 constraint (!inst.operands[0].isreg,
7221 _("'[' expected after PLI mnemonic"));
7222 constraint (inst.operands[0].postind,
7223 _("post-indexed expression used in preload instruction"));
7224 constraint (inst.operands[0].writeback,
7225 _("writeback used in preload instruction"));
7226 constraint (!inst.operands[0].preind,
7227 _("unindexed addressing used in preload instruction"));
7228 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7229 inst.instruction &= ~PRE_INDEX;
7232 static void
7233 do_push_pop (void)
7235 inst.operands[1] = inst.operands[0];
7236 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7237 inst.operands[0].isreg = 1;
7238 inst.operands[0].writeback = 1;
7239 inst.operands[0].reg = REG_SP;
7240 do_ldmstm ();
7243 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7244 word at the specified address and the following word
7245 respectively.
7246 Unconditionally executed.
7247 Error if Rn is R15. */
7249 static void
7250 do_rfe (void)
7252 inst.instruction |= inst.operands[0].reg << 16;
7253 if (inst.operands[0].writeback)
7254 inst.instruction |= WRITE_BACK;
7257 /* ARM V6 ssat (argument parse). */
7259 static void
7260 do_ssat (void)
7262 inst.instruction |= inst.operands[0].reg << 12;
7263 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7264 inst.instruction |= inst.operands[2].reg;
7266 if (inst.operands[3].present)
7267 encode_arm_shift (3);
7270 /* ARM V6 usat (argument parse). */
7272 static void
7273 do_usat (void)
7275 inst.instruction |= inst.operands[0].reg << 12;
7276 inst.instruction |= inst.operands[1].imm << 16;
7277 inst.instruction |= inst.operands[2].reg;
7279 if (inst.operands[3].present)
7280 encode_arm_shift (3);
7283 /* ARM V6 ssat16 (argument parse). */
7285 static void
7286 do_ssat16 (void)
7288 inst.instruction |= inst.operands[0].reg << 12;
7289 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7290 inst.instruction |= inst.operands[2].reg;
7293 static void
7294 do_usat16 (void)
7296 inst.instruction |= inst.operands[0].reg << 12;
7297 inst.instruction |= inst.operands[1].imm << 16;
7298 inst.instruction |= inst.operands[2].reg;
7301 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7302 preserving the other bits.
7304 setend <endian_specifier>, where <endian_specifier> is either
7305 BE or LE. */
7307 static void
7308 do_setend (void)
7310 if (inst.operands[0].imm)
7311 inst.instruction |= 0x200;
7314 static void
7315 do_shift (void)
7317 unsigned int Rm = (inst.operands[1].present
7318 ? inst.operands[1].reg
7319 : inst.operands[0].reg);
7321 inst.instruction |= inst.operands[0].reg << 12;
7322 inst.instruction |= Rm;
7323 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7325 inst.instruction |= inst.operands[2].reg << 8;
7326 inst.instruction |= SHIFT_BY_REG;
7328 else
7329 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7332 static void
7333 do_smc (void)
7335 inst.reloc.type = BFD_RELOC_ARM_SMC;
7336 inst.reloc.pc_rel = 0;
7339 static void
7340 do_swi (void)
7342 inst.reloc.type = BFD_RELOC_ARM_SWI;
7343 inst.reloc.pc_rel = 0;
7346 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7347 SMLAxy{cond} Rd,Rm,Rs,Rn
7348 SMLAWy{cond} Rd,Rm,Rs,Rn
7349 Error if any register is R15. */
7351 static void
7352 do_smla (void)
7354 inst.instruction |= inst.operands[0].reg << 16;
7355 inst.instruction |= inst.operands[1].reg;
7356 inst.instruction |= inst.operands[2].reg << 8;
7357 inst.instruction |= inst.operands[3].reg << 12;
7360 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7361 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7362 Error if any register is R15.
7363 Warning if Rdlo == Rdhi. */
7365 static void
7366 do_smlal (void)
7368 inst.instruction |= inst.operands[0].reg << 12;
7369 inst.instruction |= inst.operands[1].reg << 16;
7370 inst.instruction |= inst.operands[2].reg;
7371 inst.instruction |= inst.operands[3].reg << 8;
7373 if (inst.operands[0].reg == inst.operands[1].reg)
7374 as_tsktsk (_("rdhi and rdlo must be different"));
7377 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7378 SMULxy{cond} Rd,Rm,Rs
7379 Error if any register is R15. */
7381 static void
7382 do_smul (void)
7384 inst.instruction |= inst.operands[0].reg << 16;
7385 inst.instruction |= inst.operands[1].reg;
7386 inst.instruction |= inst.operands[2].reg << 8;
7389 /* ARM V6 srs (argument parse). */
7391 static void
7392 do_srs (void)
7394 inst.instruction |= inst.operands[0].imm;
7395 if (inst.operands[0].writeback)
7396 inst.instruction |= WRITE_BACK;
7399 /* ARM V6 strex (argument parse). */
7401 static void
7402 do_strex (void)
7404 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7405 || inst.operands[2].postind || inst.operands[2].writeback
7406 || inst.operands[2].immisreg || inst.operands[2].shifted
7407 || inst.operands[2].negative
7408 /* See comment in do_ldrex(). */
7409 || (inst.operands[2].reg == REG_PC),
7410 BAD_ADDR_MODE);
7412 constraint (inst.operands[0].reg == inst.operands[1].reg
7413 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7415 constraint (inst.reloc.exp.X_op != O_constant
7416 || inst.reloc.exp.X_add_number != 0,
7417 _("offset must be zero in ARM encoding"));
7419 inst.instruction |= inst.operands[0].reg << 12;
7420 inst.instruction |= inst.operands[1].reg;
7421 inst.instruction |= inst.operands[2].reg << 16;
7422 inst.reloc.type = BFD_RELOC_UNUSED;
7425 static void
7426 do_strexd (void)
7428 constraint (inst.operands[1].reg % 2 != 0,
7429 _("even register required"));
7430 constraint (inst.operands[2].present
7431 && inst.operands[2].reg != inst.operands[1].reg + 1,
7432 _("can only store two consecutive registers"));
7433 /* If op 2 were present and equal to PC, this function wouldn't
7434 have been called in the first place. */
7435 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7437 constraint (inst.operands[0].reg == inst.operands[1].reg
7438 || inst.operands[0].reg == inst.operands[1].reg + 1
7439 || inst.operands[0].reg == inst.operands[3].reg,
7440 BAD_OVERLAP);
7442 inst.instruction |= inst.operands[0].reg << 12;
7443 inst.instruction |= inst.operands[1].reg;
7444 inst.instruction |= inst.operands[3].reg << 16;
7447 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7448 extends it to 32-bits, and adds the result to a value in another
7449 register. You can specify a rotation by 0, 8, 16, or 24 bits
7450 before extracting the 16-bit value.
7451 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7452 Condition defaults to COND_ALWAYS.
7453 Error if any register uses R15. */
7455 static void
7456 do_sxtah (void)
7458 inst.instruction |= inst.operands[0].reg << 12;
7459 inst.instruction |= inst.operands[1].reg << 16;
7460 inst.instruction |= inst.operands[2].reg;
7461 inst.instruction |= inst.operands[3].imm << 10;
7464 /* ARM V6 SXTH.
7466 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7467 Condition defaults to COND_ALWAYS.
7468 Error if any register uses R15. */
7470 static void
7471 do_sxth (void)
7473 inst.instruction |= inst.operands[0].reg << 12;
7474 inst.instruction |= inst.operands[1].reg;
7475 inst.instruction |= inst.operands[2].imm << 10;
7478 /* VFP instructions. In a logical order: SP variant first, monad
7479 before dyad, arithmetic then move then load/store. */
7481 static void
7482 do_vfp_sp_monadic (void)
7484 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7485 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7488 static void
7489 do_vfp_sp_dyadic (void)
7491 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7492 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7493 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7496 static void
7497 do_vfp_sp_compare_z (void)
7499 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7502 static void
7503 do_vfp_dp_sp_cvt (void)
7505 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7506 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7509 static void
7510 do_vfp_sp_dp_cvt (void)
7512 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7513 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7516 static void
7517 do_vfp_reg_from_sp (void)
7519 inst.instruction |= inst.operands[0].reg << 12;
7520 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7523 static void
7524 do_vfp_reg2_from_sp2 (void)
7526 constraint (inst.operands[2].imm != 2,
7527 _("only two consecutive VFP SP registers allowed here"));
7528 inst.instruction |= inst.operands[0].reg << 12;
7529 inst.instruction |= inst.operands[1].reg << 16;
7530 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7533 static void
7534 do_vfp_sp_from_reg (void)
7536 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7537 inst.instruction |= inst.operands[1].reg << 12;
7540 static void
7541 do_vfp_sp2_from_reg2 (void)
7543 constraint (inst.operands[0].imm != 2,
7544 _("only two consecutive VFP SP registers allowed here"));
7545 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7546 inst.instruction |= inst.operands[1].reg << 12;
7547 inst.instruction |= inst.operands[2].reg << 16;
7550 static void
7551 do_vfp_sp_ldst (void)
7553 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7554 encode_arm_cp_address (1, FALSE, TRUE, 0);
7557 static void
7558 do_vfp_dp_ldst (void)
7560 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7561 encode_arm_cp_address (1, FALSE, TRUE, 0);
7565 static void
7566 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7568 if (inst.operands[0].writeback)
7569 inst.instruction |= WRITE_BACK;
7570 else
7571 constraint (ldstm_type != VFP_LDSTMIA,
7572 _("this addressing mode requires base-register writeback"));
7573 inst.instruction |= inst.operands[0].reg << 16;
7574 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7575 inst.instruction |= inst.operands[1].imm;
7578 static void
7579 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7581 int count;
7583 if (inst.operands[0].writeback)
7584 inst.instruction |= WRITE_BACK;
7585 else
7586 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7587 _("this addressing mode requires base-register writeback"));
7589 inst.instruction |= inst.operands[0].reg << 16;
7590 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7592 count = inst.operands[1].imm << 1;
7593 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7594 count += 1;
7596 inst.instruction |= count;
7599 static void
7600 do_vfp_sp_ldstmia (void)
7602 vfp_sp_ldstm (VFP_LDSTMIA);
7605 static void
7606 do_vfp_sp_ldstmdb (void)
7608 vfp_sp_ldstm (VFP_LDSTMDB);
7611 static void
7612 do_vfp_dp_ldstmia (void)
7614 vfp_dp_ldstm (VFP_LDSTMIA);
7617 static void
7618 do_vfp_dp_ldstmdb (void)
7620 vfp_dp_ldstm (VFP_LDSTMDB);
7623 static void
7624 do_vfp_xp_ldstmia (void)
7626 vfp_dp_ldstm (VFP_LDSTMIAX);
7629 static void
7630 do_vfp_xp_ldstmdb (void)
7632 vfp_dp_ldstm (VFP_LDSTMDBX);
7635 static void
7636 do_vfp_dp_rd_rm (void)
7638 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7639 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7642 static void
7643 do_vfp_dp_rn_rd (void)
7645 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7646 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7649 static void
7650 do_vfp_dp_rd_rn (void)
7652 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7653 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7656 static void
7657 do_vfp_dp_rd_rn_rm (void)
7659 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7660 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7661 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7664 static void
7665 do_vfp_dp_rd (void)
7667 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7670 static void
7671 do_vfp_dp_rm_rd_rn (void)
7673 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7674 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7675 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7678 /* VFPv3 instructions. */
7679 static void
7680 do_vfp_sp_const (void)
7682 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7683 inst.instruction |= (inst.operands[1].imm & 15) << 16;
7684 inst.instruction |= (inst.operands[1].imm >> 4);
7687 static void
7688 do_vfp_dp_const (void)
7690 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7691 inst.instruction |= (inst.operands[1].imm & 15) << 16;
7692 inst.instruction |= (inst.operands[1].imm >> 4);
7695 static void
7696 vfp_conv (int srcsize)
7698 unsigned immbits = srcsize - inst.operands[1].imm;
7699 inst.instruction |= (immbits & 1) << 5;
7700 inst.instruction |= (immbits >> 1);
7703 static void
7704 do_vfp_sp_conv_16 (void)
7706 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7707 vfp_conv (16);
7710 static void
7711 do_vfp_dp_conv_16 (void)
7713 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7714 vfp_conv (16);
7717 static void
7718 do_vfp_sp_conv_32 (void)
7720 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7721 vfp_conv (32);
7724 static void
7725 do_vfp_dp_conv_32 (void)
7727 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7728 vfp_conv (32);
7732 /* FPA instructions. Also in a logical order. */
7734 static void
7735 do_fpa_cmp (void)
7737 inst.instruction |= inst.operands[0].reg << 16;
7738 inst.instruction |= inst.operands[1].reg;
7741 static void
7742 do_fpa_ldmstm (void)
7744 inst.instruction |= inst.operands[0].reg << 12;
7745 switch (inst.operands[1].imm)
7747 case 1: inst.instruction |= CP_T_X; break;
7748 case 2: inst.instruction |= CP_T_Y; break;
7749 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7750 case 4: break;
7751 default: abort ();
7754 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7756 /* The instruction specified "ea" or "fd", so we can only accept
7757 [Rn]{!}. The instruction does not really support stacking or
7758 unstacking, so we have to emulate these by setting appropriate
7759 bits and offsets. */
7760 constraint (inst.reloc.exp.X_op != O_constant
7761 || inst.reloc.exp.X_add_number != 0,
7762 _("this instruction does not support indexing"));
7764 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7765 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7767 if (!(inst.instruction & INDEX_UP))
7768 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7770 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7772 inst.operands[2].preind = 0;
7773 inst.operands[2].postind = 1;
7777 encode_arm_cp_address (2, TRUE, TRUE, 0);
7781 /* iWMMXt instructions: strictly in alphabetical order. */
7783 static void
7784 do_iwmmxt_tandorc (void)
7786 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7789 static void
7790 do_iwmmxt_textrc (void)
7792 inst.instruction |= inst.operands[0].reg << 12;
7793 inst.instruction |= inst.operands[1].imm;
7796 static void
7797 do_iwmmxt_textrm (void)
7799 inst.instruction |= inst.operands[0].reg << 12;
7800 inst.instruction |= inst.operands[1].reg << 16;
7801 inst.instruction |= inst.operands[2].imm;
7804 static void
7805 do_iwmmxt_tinsr (void)
7807 inst.instruction |= inst.operands[0].reg << 16;
7808 inst.instruction |= inst.operands[1].reg << 12;
7809 inst.instruction |= inst.operands[2].imm;
7812 static void
7813 do_iwmmxt_tmia (void)
7815 inst.instruction |= inst.operands[0].reg << 5;
7816 inst.instruction |= inst.operands[1].reg;
7817 inst.instruction |= inst.operands[2].reg << 12;
7820 static void
7821 do_iwmmxt_waligni (void)
7823 inst.instruction |= inst.operands[0].reg << 12;
7824 inst.instruction |= inst.operands[1].reg << 16;
7825 inst.instruction |= inst.operands[2].reg;
7826 inst.instruction |= inst.operands[3].imm << 20;
7829 static void
7830 do_iwmmxt_wmov (void)
7832 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7833 inst.instruction |= inst.operands[0].reg << 12;
7834 inst.instruction |= inst.operands[1].reg << 16;
7835 inst.instruction |= inst.operands[1].reg;
7838 static void
7839 do_iwmmxt_wldstbh (void)
7841 int reloc;
7842 inst.instruction |= inst.operands[0].reg << 12;
7843 if (thumb_mode)
7844 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7845 else
7846 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7847 encode_arm_cp_address (1, TRUE, FALSE, reloc);
7850 static void
7851 do_iwmmxt_wldstw (void)
7853 /* RIWR_RIWC clears .isreg for a control register. */
7854 if (!inst.operands[0].isreg)
7856 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7857 inst.instruction |= 0xf0000000;
7860 inst.instruction |= inst.operands[0].reg << 12;
7861 encode_arm_cp_address (1, TRUE, TRUE, 0);
7864 static void
7865 do_iwmmxt_wldstd (void)
7867 inst.instruction |= inst.operands[0].reg << 12;
7868 encode_arm_cp_address (1, TRUE, FALSE, 0);
7871 static void
7872 do_iwmmxt_wshufh (void)
7874 inst.instruction |= inst.operands[0].reg << 12;
7875 inst.instruction |= inst.operands[1].reg << 16;
7876 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
7877 inst.instruction |= (inst.operands[2].imm & 0x0f);
7880 static void
7881 do_iwmmxt_wzero (void)
7883 /* WZERO reg is an alias for WANDN reg, reg, reg. */
7884 inst.instruction |= inst.operands[0].reg;
7885 inst.instruction |= inst.operands[0].reg << 12;
7886 inst.instruction |= inst.operands[0].reg << 16;
7889 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
7890 operations first, then control, shift, and load/store. */
7892 /* Insns like "foo X,Y,Z". */
7894 static void
7895 do_mav_triple (void)
7897 inst.instruction |= inst.operands[0].reg << 16;
7898 inst.instruction |= inst.operands[1].reg;
7899 inst.instruction |= inst.operands[2].reg << 12;
7902 /* Insns like "foo W,X,Y,Z".
7903 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
7905 static void
7906 do_mav_quad (void)
7908 inst.instruction |= inst.operands[0].reg << 5;
7909 inst.instruction |= inst.operands[1].reg << 12;
7910 inst.instruction |= inst.operands[2].reg << 16;
7911 inst.instruction |= inst.operands[3].reg;
7914 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
7915 static void
7916 do_mav_dspsc (void)
7918 inst.instruction |= inst.operands[1].reg << 12;
7921 /* Maverick shift immediate instructions.
7922 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
7923 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
7925 static void
7926 do_mav_shift (void)
7928 int imm = inst.operands[2].imm;
7930 inst.instruction |= inst.operands[0].reg << 12;
7931 inst.instruction |= inst.operands[1].reg << 16;
7933 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
7934 Bits 5-7 of the insn should have bits 4-6 of the immediate.
7935 Bit 4 should be 0. */
7936 imm = (imm & 0xf) | ((imm & 0x70) << 1);
7938 inst.instruction |= imm;
7941 /* XScale instructions. Also sorted arithmetic before move. */
7943 /* Xscale multiply-accumulate (argument parse)
7944 MIAcc acc0,Rm,Rs
7945 MIAPHcc acc0,Rm,Rs
7946 MIAxycc acc0,Rm,Rs. */
7948 static void
7949 do_xsc_mia (void)
7951 inst.instruction |= inst.operands[1].reg;
7952 inst.instruction |= inst.operands[2].reg << 12;
7955 /* Xscale move-accumulator-register (argument parse)
7957 MARcc acc0,RdLo,RdHi. */
7959 static void
7960 do_xsc_mar (void)
7962 inst.instruction |= inst.operands[1].reg << 12;
7963 inst.instruction |= inst.operands[2].reg << 16;
7966 /* Xscale move-register-accumulator (argument parse)
7968 MRAcc RdLo,RdHi,acc0. */
7970 static void
7971 do_xsc_mra (void)
7973 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
7974 inst.instruction |= inst.operands[0].reg << 12;
7975 inst.instruction |= inst.operands[1].reg << 16;
7978 /* Encoding functions relevant only to Thumb. */
7980 /* inst.operands[i] is a shifted-register operand; encode
7981 it into inst.instruction in the format used by Thumb32. */
7983 static void
7984 encode_thumb32_shifted_operand (int i)
7986 unsigned int value = inst.reloc.exp.X_add_number;
7987 unsigned int shift = inst.operands[i].shift_kind;
7989 constraint (inst.operands[i].immisreg,
7990 _("shift by register not allowed in thumb mode"));
7991 inst.instruction |= inst.operands[i].reg;
7992 if (shift == SHIFT_RRX)
7993 inst.instruction |= SHIFT_ROR << 4;
7994 else
7996 constraint (inst.reloc.exp.X_op != O_constant,
7997 _("expression too complex"));
7999 constraint (value > 32
8000 || (value == 32 && (shift == SHIFT_LSL
8001 || shift == SHIFT_ROR)),
8002 _("shift expression is too large"));
8004 if (value == 0)
8005 shift = SHIFT_LSL;
8006 else if (value == 32)
8007 value = 0;
8009 inst.instruction |= shift << 4;
8010 inst.instruction |= (value & 0x1c) << 10;
8011 inst.instruction |= (value & 0x03) << 6;
8016 /* inst.operands[i] was set up by parse_address. Encode it into a
8017 Thumb32 format load or store instruction. Reject forms that cannot
8018 be used with such instructions. If is_t is true, reject forms that
8019 cannot be used with a T instruction; if is_d is true, reject forms
8020 that cannot be used with a D instruction. */
8022 static void
8023 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8025 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8027 constraint (!inst.operands[i].isreg,
8028 _("Instruction does not support =N addresses"));
8030 inst.instruction |= inst.operands[i].reg << 16;
8031 if (inst.operands[i].immisreg)
8033 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8034 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8035 constraint (inst.operands[i].negative,
8036 _("Thumb does not support negative register indexing"));
8037 constraint (inst.operands[i].postind,
8038 _("Thumb does not support register post-indexing"));
8039 constraint (inst.operands[i].writeback,
8040 _("Thumb does not support register indexing with writeback"));
8041 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8042 _("Thumb supports only LSL in shifted register indexing"));
8044 inst.instruction |= inst.operands[i].imm;
8045 if (inst.operands[i].shifted)
8047 constraint (inst.reloc.exp.X_op != O_constant,
8048 _("expression too complex"));
8049 constraint (inst.reloc.exp.X_add_number < 0
8050 || inst.reloc.exp.X_add_number > 3,
8051 _("shift out of range"));
8052 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8054 inst.reloc.type = BFD_RELOC_UNUSED;
8056 else if (inst.operands[i].preind)
8058 constraint (is_pc && inst.operands[i].writeback,
8059 _("cannot use writeback with PC-relative addressing"));
8060 constraint (is_t && inst.operands[i].writeback,
8061 _("cannot use writeback with this instruction"));
8063 if (is_d)
8065 inst.instruction |= 0x01000000;
8066 if (inst.operands[i].writeback)
8067 inst.instruction |= 0x00200000;
8069 else
8071 inst.instruction |= 0x00000c00;
8072 if (inst.operands[i].writeback)
8073 inst.instruction |= 0x00000100;
8075 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8077 else if (inst.operands[i].postind)
8079 assert (inst.operands[i].writeback);
8080 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8081 constraint (is_t, _("cannot use post-indexing with this instruction"));
8083 if (is_d)
8084 inst.instruction |= 0x00200000;
8085 else
8086 inst.instruction |= 0x00000900;
8087 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8089 else /* unindexed - only for coprocessor */
8090 inst.error = _("instruction does not accept unindexed addressing");
8093 /* Table of Thumb instructions which exist in both 16- and 32-bit
8094 encodings (the latter only in post-V6T2 cores). The index is the
8095 value used in the insns table below. When there is more than one
8096 possible 16-bit encoding for the instruction, this table always
8097 holds variant (1).
8098 Also contains several pseudo-instructions used during relaxation. */
8099 #define T16_32_TAB \
8100 X(adc, 4140, eb400000), \
8101 X(adcs, 4140, eb500000), \
8102 X(add, 1c00, eb000000), \
8103 X(adds, 1c00, eb100000), \
8104 X(addi, 0000, f1000000), \
8105 X(addis, 0000, f1100000), \
8106 X(add_pc,000f, f20f0000), \
8107 X(add_sp,000d, f10d0000), \
8108 X(adr, 000f, f20f0000), \
8109 X(and, 4000, ea000000), \
8110 X(ands, 4000, ea100000), \
8111 X(asr, 1000, fa40f000), \
8112 X(asrs, 1000, fa50f000), \
8113 X(b, e000, f000b000), \
8114 X(bcond, d000, f0008000), \
8115 X(bic, 4380, ea200000), \
8116 X(bics, 4380, ea300000), \
8117 X(cmn, 42c0, eb100f00), \
8118 X(cmp, 2800, ebb00f00), \
8119 X(cpsie, b660, f3af8400), \
8120 X(cpsid, b670, f3af8600), \
8121 X(cpy, 4600, ea4f0000), \
8122 X(dec_sp,80dd, f1bd0d00), \
8123 X(eor, 4040, ea800000), \
8124 X(eors, 4040, ea900000), \
8125 X(inc_sp,00dd, f10d0d00), \
8126 X(ldmia, c800, e8900000), \
8127 X(ldr, 6800, f8500000), \
8128 X(ldrb, 7800, f8100000), \
8129 X(ldrh, 8800, f8300000), \
8130 X(ldrsb, 5600, f9100000), \
8131 X(ldrsh, 5e00, f9300000), \
8132 X(ldr_pc,4800, f85f0000), \
8133 X(ldr_pc2,4800, f85f0000), \
8134 X(ldr_sp,9800, f85d0000), \
8135 X(lsl, 0000, fa00f000), \
8136 X(lsls, 0000, fa10f000), \
8137 X(lsr, 0800, fa20f000), \
8138 X(lsrs, 0800, fa30f000), \
8139 X(mov, 2000, ea4f0000), \
8140 X(movs, 2000, ea5f0000), \
8141 X(mul, 4340, fb00f000), \
8142 X(muls, 4340, ffffffff), /* no 32b muls */ \
8143 X(mvn, 43c0, ea6f0000), \
8144 X(mvns, 43c0, ea7f0000), \
8145 X(neg, 4240, f1c00000), /* rsb #0 */ \
8146 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8147 X(orr, 4300, ea400000), \
8148 X(orrs, 4300, ea500000), \
8149 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8150 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8151 X(rev, ba00, fa90f080), \
8152 X(rev16, ba40, fa90f090), \
8153 X(revsh, bac0, fa90f0b0), \
8154 X(ror, 41c0, fa60f000), \
8155 X(rors, 41c0, fa70f000), \
8156 X(sbc, 4180, eb600000), \
8157 X(sbcs, 4180, eb700000), \
8158 X(stmia, c000, e8800000), \
8159 X(str, 6000, f8400000), \
8160 X(strb, 7000, f8000000), \
8161 X(strh, 8000, f8200000), \
8162 X(str_sp,9000, f84d0000), \
8163 X(sub, 1e00, eba00000), \
8164 X(subs, 1e00, ebb00000), \
8165 X(subi, 8000, f1a00000), \
8166 X(subis, 8000, f1b00000), \
8167 X(sxtb, b240, fa4ff080), \
8168 X(sxth, b200, fa0ff080), \
8169 X(tst, 4200, ea100f00), \
8170 X(uxtb, b2c0, fa5ff080), \
8171 X(uxth, b280, fa1ff080), \
8172 X(nop, bf00, f3af8000), \
8173 X(yield, bf10, f3af8001), \
8174 X(wfe, bf20, f3af8002), \
8175 X(wfi, bf30, f3af8003), \
8176 X(sev, bf40, f3af9004), /* typo, 8004? */
8178 /* To catch errors in encoding functions, the codes are all offset by
8179 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8180 as 16-bit instructions. */
8181 #define X(a,b,c) T_MNEM_##a
8182 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8183 #undef X
8185 #define X(a,b,c) 0x##b
8186 static const unsigned short thumb_op16[] = { T16_32_TAB };
8187 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8188 #undef X
8190 #define X(a,b,c) 0x##c
8191 static const unsigned int thumb_op32[] = { T16_32_TAB };
8192 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8193 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8194 #undef X
8195 #undef T16_32_TAB
8197 /* Thumb instruction encoders, in alphabetical order. */
8199 /* ADDW or SUBW. */
8200 static void
8201 do_t_add_sub_w (void)
8203 int Rd, Rn;
8205 Rd = inst.operands[0].reg;
8206 Rn = inst.operands[1].reg;
8208 constraint (Rd == 15, _("PC not allowed as destination"));
8209 inst.instruction |= (Rn << 16) | (Rd << 8);
8210 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8213 /* Parse an add or subtract instruction. We get here with inst.instruction
8214 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8216 static void
8217 do_t_add_sub (void)
8219 int Rd, Rs, Rn;
8221 Rd = inst.operands[0].reg;
8222 Rs = (inst.operands[1].present
8223 ? inst.operands[1].reg /* Rd, Rs, foo */
8224 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8226 if (unified_syntax)
8228 bfd_boolean flags;
8229 bfd_boolean narrow;
8230 int opcode;
8232 flags = (inst.instruction == T_MNEM_adds
8233 || inst.instruction == T_MNEM_subs);
8234 if (flags)
8235 narrow = (current_it_mask == 0);
8236 else
8237 narrow = (current_it_mask != 0);
8238 if (!inst.operands[2].isreg)
8240 int add;
8242 add = (inst.instruction == T_MNEM_add
8243 || inst.instruction == T_MNEM_adds);
8244 opcode = 0;
8245 if (inst.size_req != 4)
8247 /* Attempt to use a narrow opcode, with relaxation if
8248 appropriate. */
8249 if (Rd == REG_SP && Rs == REG_SP && !flags)
8250 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8251 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8252 opcode = T_MNEM_add_sp;
8253 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8254 opcode = T_MNEM_add_pc;
8255 else if (Rd <= 7 && Rs <= 7 && narrow)
8257 if (flags)
8258 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8259 else
8260 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8262 if (opcode)
8264 inst.instruction = THUMB_OP16(opcode);
8265 inst.instruction |= (Rd << 4) | Rs;
8266 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8267 if (inst.size_req != 2)
8268 inst.relax = opcode;
8270 else
8271 constraint (inst.size_req == 2, BAD_HIREG);
8273 if (inst.size_req == 4
8274 || (inst.size_req != 2 && !opcode))
8276 if (Rs == REG_PC)
8278 /* Always use addw/subw. */
8279 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8280 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8282 else
8284 inst.instruction = THUMB_OP32 (inst.instruction);
8285 inst.instruction = (inst.instruction & 0xe1ffffff)
8286 | 0x10000000;
8287 if (flags)
8288 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8289 else
8290 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8292 inst.instruction |= inst.operands[0].reg << 8;
8293 inst.instruction |= inst.operands[1].reg << 16;
8296 else
8298 Rn = inst.operands[2].reg;
8299 /* See if we can do this with a 16-bit instruction. */
8300 if (!inst.operands[2].shifted && inst.size_req != 4)
8302 if (Rd > 7 || Rs > 7 || Rn > 7)
8303 narrow = FALSE;
8305 if (narrow)
8307 inst.instruction = ((inst.instruction == T_MNEM_adds
8308 || inst.instruction == T_MNEM_add)
8309 ? T_OPCODE_ADD_R3
8310 : T_OPCODE_SUB_R3);
8311 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8312 return;
8315 if (inst.instruction == T_MNEM_add)
8317 if (Rd == Rs)
8319 inst.instruction = T_OPCODE_ADD_HI;
8320 inst.instruction |= (Rd & 8) << 4;
8321 inst.instruction |= (Rd & 7);
8322 inst.instruction |= Rn << 3;
8323 return;
8325 /* ... because addition is commutative! */
8326 else if (Rd == Rn)
8328 inst.instruction = T_OPCODE_ADD_HI;
8329 inst.instruction |= (Rd & 8) << 4;
8330 inst.instruction |= (Rd & 7);
8331 inst.instruction |= Rs << 3;
8332 return;
8336 /* If we get here, it can't be done in 16 bits. */
8337 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8338 _("shift must be constant"));
8339 inst.instruction = THUMB_OP32 (inst.instruction);
8340 inst.instruction |= Rd << 8;
8341 inst.instruction |= Rs << 16;
8342 encode_thumb32_shifted_operand (2);
8345 else
8347 constraint (inst.instruction == T_MNEM_adds
8348 || inst.instruction == T_MNEM_subs,
8349 BAD_THUMB32);
8351 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8353 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8354 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8355 BAD_HIREG);
8357 inst.instruction = (inst.instruction == T_MNEM_add
8358 ? 0x0000 : 0x8000);
8359 inst.instruction |= (Rd << 4) | Rs;
8360 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8361 return;
8364 Rn = inst.operands[2].reg;
8365 constraint (inst.operands[2].shifted, _("unshifted register required"));
8367 /* We now have Rd, Rs, and Rn set to registers. */
8368 if (Rd > 7 || Rs > 7 || Rn > 7)
8370 /* Can't do this for SUB. */
8371 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8372 inst.instruction = T_OPCODE_ADD_HI;
8373 inst.instruction |= (Rd & 8) << 4;
8374 inst.instruction |= (Rd & 7);
8375 if (Rs == Rd)
8376 inst.instruction |= Rn << 3;
8377 else if (Rn == Rd)
8378 inst.instruction |= Rs << 3;
8379 else
8380 constraint (1, _("dest must overlap one source register"));
8382 else
8384 inst.instruction = (inst.instruction == T_MNEM_add
8385 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8386 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8391 static void
8392 do_t_adr (void)
8394 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8396 /* Defer to section relaxation. */
8397 inst.relax = inst.instruction;
8398 inst.instruction = THUMB_OP16 (inst.instruction);
8399 inst.instruction |= inst.operands[0].reg << 4;
8401 else if (unified_syntax && inst.size_req != 2)
8403 /* Generate a 32-bit opcode. */
8404 inst.instruction = THUMB_OP32 (inst.instruction);
8405 inst.instruction |= inst.operands[0].reg << 8;
8406 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8407 inst.reloc.pc_rel = 1;
8409 else
8411 /* Generate a 16-bit opcode. */
8412 inst.instruction = THUMB_OP16 (inst.instruction);
8413 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8414 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8415 inst.reloc.pc_rel = 1;
8417 inst.instruction |= inst.operands[0].reg << 4;
8421 /* Arithmetic instructions for which there is just one 16-bit
8422 instruction encoding, and it allows only two low registers.
8423 For maximal compatibility with ARM syntax, we allow three register
8424 operands even when Thumb-32 instructions are not available, as long
8425 as the first two are identical. For instance, both "sbc r0,r1" and
8426 "sbc r0,r0,r1" are allowed. */
8427 static void
8428 do_t_arit3 (void)
8430 int Rd, Rs, Rn;
8432 Rd = inst.operands[0].reg;
8433 Rs = (inst.operands[1].present
8434 ? inst.operands[1].reg /* Rd, Rs, foo */
8435 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8436 Rn = inst.operands[2].reg;
8438 if (unified_syntax)
8440 if (!inst.operands[2].isreg)
8442 /* For an immediate, we always generate a 32-bit opcode;
8443 section relaxation will shrink it later if possible. */
8444 inst.instruction = THUMB_OP32 (inst.instruction);
8445 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8446 inst.instruction |= Rd << 8;
8447 inst.instruction |= Rs << 16;
8448 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8450 else
8452 bfd_boolean narrow;
8454 /* See if we can do this with a 16-bit instruction. */
8455 if (THUMB_SETS_FLAGS (inst.instruction))
8456 narrow = current_it_mask == 0;
8457 else
8458 narrow = current_it_mask != 0;
8460 if (Rd > 7 || Rn > 7 || Rs > 7)
8461 narrow = FALSE;
8462 if (inst.operands[2].shifted)
8463 narrow = FALSE;
8464 if (inst.size_req == 4)
8465 narrow = FALSE;
8467 if (narrow
8468 && Rd == Rs)
8470 inst.instruction = THUMB_OP16 (inst.instruction);
8471 inst.instruction |= Rd;
8472 inst.instruction |= Rn << 3;
8473 return;
8476 /* If we get here, it can't be done in 16 bits. */
8477 constraint (inst.operands[2].shifted
8478 && inst.operands[2].immisreg,
8479 _("shift must be constant"));
8480 inst.instruction = THUMB_OP32 (inst.instruction);
8481 inst.instruction |= Rd << 8;
8482 inst.instruction |= Rs << 16;
8483 encode_thumb32_shifted_operand (2);
8486 else
8488 /* On its face this is a lie - the instruction does set the
8489 flags. However, the only supported mnemonic in this mode
8490 says it doesn't. */
8491 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8493 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8494 _("unshifted register required"));
8495 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8496 constraint (Rd != Rs,
8497 _("dest and source1 must be the same register"));
8499 inst.instruction = THUMB_OP16 (inst.instruction);
8500 inst.instruction |= Rd;
8501 inst.instruction |= Rn << 3;
8505 /* Similarly, but for instructions where the arithmetic operation is
8506 commutative, so we can allow either of them to be different from
8507 the destination operand in a 16-bit instruction. For instance, all
8508 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8509 accepted. */
8510 static void
8511 do_t_arit3c (void)
8513 int Rd, Rs, Rn;
8515 Rd = inst.operands[0].reg;
8516 Rs = (inst.operands[1].present
8517 ? inst.operands[1].reg /* Rd, Rs, foo */
8518 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8519 Rn = inst.operands[2].reg;
8521 if (unified_syntax)
8523 if (!inst.operands[2].isreg)
8525 /* For an immediate, we always generate a 32-bit opcode;
8526 section relaxation will shrink it later if possible. */
8527 inst.instruction = THUMB_OP32 (inst.instruction);
8528 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8529 inst.instruction |= Rd << 8;
8530 inst.instruction |= Rs << 16;
8531 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8533 else
8535 bfd_boolean narrow;
8537 /* See if we can do this with a 16-bit instruction. */
8538 if (THUMB_SETS_FLAGS (inst.instruction))
8539 narrow = current_it_mask == 0;
8540 else
8541 narrow = current_it_mask != 0;
8543 if (Rd > 7 || Rn > 7 || Rs > 7)
8544 narrow = FALSE;
8545 if (inst.operands[2].shifted)
8546 narrow = FALSE;
8547 if (inst.size_req == 4)
8548 narrow = FALSE;
8550 if (narrow)
8552 if (Rd == Rs)
8554 inst.instruction = THUMB_OP16 (inst.instruction);
8555 inst.instruction |= Rd;
8556 inst.instruction |= Rn << 3;
8557 return;
8559 if (Rd == Rn)
8561 inst.instruction = THUMB_OP16 (inst.instruction);
8562 inst.instruction |= Rd;
8563 inst.instruction |= Rs << 3;
8564 return;
8568 /* If we get here, it can't be done in 16 bits. */
8569 constraint (inst.operands[2].shifted
8570 && inst.operands[2].immisreg,
8571 _("shift must be constant"));
8572 inst.instruction = THUMB_OP32 (inst.instruction);
8573 inst.instruction |= Rd << 8;
8574 inst.instruction |= Rs << 16;
8575 encode_thumb32_shifted_operand (2);
8578 else
8580 /* On its face this is a lie - the instruction does set the
8581 flags. However, the only supported mnemonic in this mode
8582 says it doesn't. */
8583 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8585 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8586 _("unshifted register required"));
8587 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8589 inst.instruction = THUMB_OP16 (inst.instruction);
8590 inst.instruction |= Rd;
8592 if (Rd == Rs)
8593 inst.instruction |= Rn << 3;
8594 else if (Rd == Rn)
8595 inst.instruction |= Rs << 3;
8596 else
8597 constraint (1, _("dest must overlap one source register"));
8601 static void
8602 do_t_barrier (void)
8604 if (inst.operands[0].present)
8606 constraint ((inst.instruction & 0xf0) != 0x40
8607 && inst.operands[0].imm != 0xf,
8608 "bad barrier type");
8609 inst.instruction |= inst.operands[0].imm;
8611 else
8612 inst.instruction |= 0xf;
8615 static void
8616 do_t_bfc (void)
8618 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8619 constraint (msb > 32, _("bit-field extends past end of register"));
8620 /* The instruction encoding stores the LSB and MSB,
8621 not the LSB and width. */
8622 inst.instruction |= inst.operands[0].reg << 8;
8623 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8624 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8625 inst.instruction |= msb - 1;
8628 static void
8629 do_t_bfi (void)
8631 unsigned int msb;
8633 /* #0 in second position is alternative syntax for bfc, which is
8634 the same instruction but with REG_PC in the Rm field. */
8635 if (!inst.operands[1].isreg)
8636 inst.operands[1].reg = REG_PC;
8638 msb = inst.operands[2].imm + inst.operands[3].imm;
8639 constraint (msb > 32, _("bit-field extends past end of register"));
8640 /* The instruction encoding stores the LSB and MSB,
8641 not the LSB and width. */
8642 inst.instruction |= inst.operands[0].reg << 8;
8643 inst.instruction |= inst.operands[1].reg << 16;
8644 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8645 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8646 inst.instruction |= msb - 1;
8649 static void
8650 do_t_bfx (void)
8652 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8653 _("bit-field extends past end of register"));
8654 inst.instruction |= inst.operands[0].reg << 8;
8655 inst.instruction |= inst.operands[1].reg << 16;
8656 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8657 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8658 inst.instruction |= inst.operands[3].imm - 1;
8661 /* ARM V5 Thumb BLX (argument parse)
8662 BLX <target_addr> which is BLX(1)
8663 BLX <Rm> which is BLX(2)
8664 Unfortunately, there are two different opcodes for this mnemonic.
8665 So, the insns[].value is not used, and the code here zaps values
8666 into inst.instruction.
8668 ??? How to take advantage of the additional two bits of displacement
8669 available in Thumb32 mode? Need new relocation? */
8671 static void
8672 do_t_blx (void)
8674 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8675 if (inst.operands[0].isreg)
8676 /* We have a register, so this is BLX(2). */
8677 inst.instruction |= inst.operands[0].reg << 3;
8678 else
8680 /* No register. This must be BLX(1). */
8681 inst.instruction = 0xf000e800;
8682 #ifdef OBJ_ELF
8683 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8684 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8685 else
8686 #endif
8687 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
8688 inst.reloc.pc_rel = 1;
8692 static void
8693 do_t_branch (void)
8695 int opcode;
8696 int cond;
8698 if (current_it_mask)
8700 /* Conditional branches inside IT blocks are encoded as unconditional
8701 branches. */
8702 cond = COND_ALWAYS;
8703 /* A branch must be the last instruction in an IT block. */
8704 constraint (current_it_mask != 0x10, BAD_BRANCH);
8706 else
8707 cond = inst.cond;
8709 if (cond != COND_ALWAYS)
8710 opcode = T_MNEM_bcond;
8711 else
8712 opcode = inst.instruction;
8714 if (unified_syntax && inst.size_req == 4)
8716 inst.instruction = THUMB_OP32(opcode);
8717 if (cond == COND_ALWAYS)
8718 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
8719 else
8721 assert (cond != 0xF);
8722 inst.instruction |= cond << 22;
8723 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8726 else
8728 inst.instruction = THUMB_OP16(opcode);
8729 if (cond == COND_ALWAYS)
8730 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8731 else
8733 inst.instruction |= cond << 8;
8734 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
8736 /* Allow section relaxation. */
8737 if (unified_syntax && inst.size_req != 2)
8738 inst.relax = opcode;
8741 inst.reloc.pc_rel = 1;
8744 static void
8745 do_t_bkpt (void)
8747 constraint (inst.cond != COND_ALWAYS,
8748 _("instruction is always unconditional"));
8749 if (inst.operands[0].present)
8751 constraint (inst.operands[0].imm > 255,
8752 _("immediate value out of range"));
8753 inst.instruction |= inst.operands[0].imm;
8757 static void
8758 do_t_branch23 (void)
8760 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8761 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8762 inst.reloc.pc_rel = 1;
8764 /* If the destination of the branch is a defined symbol which does not have
8765 the THUMB_FUNC attribute, then we must be calling a function which has
8766 the (interfacearm) attribute. We look for the Thumb entry point to that
8767 function and change the branch to refer to that function instead. */
8768 if ( inst.reloc.exp.X_op == O_symbol
8769 && inst.reloc.exp.X_add_symbol != NULL
8770 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8771 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8772 inst.reloc.exp.X_add_symbol =
8773 find_real_start (inst.reloc.exp.X_add_symbol);
8776 static void
8777 do_t_bx (void)
8779 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8780 inst.instruction |= inst.operands[0].reg << 3;
8781 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8782 should cause the alignment to be checked once it is known. This is
8783 because BX PC only works if the instruction is word aligned. */
8786 static void
8787 do_t_bxj (void)
8789 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8790 if (inst.operands[0].reg == REG_PC)
8791 as_tsktsk (_("use of r15 in bxj is not really useful"));
8793 inst.instruction |= inst.operands[0].reg << 16;
8796 static void
8797 do_t_clz (void)
8799 inst.instruction |= inst.operands[0].reg << 8;
8800 inst.instruction |= inst.operands[1].reg << 16;
8801 inst.instruction |= inst.operands[1].reg;
8804 static void
8805 do_t_cps (void)
8807 constraint (current_it_mask, BAD_NOT_IT);
8808 inst.instruction |= inst.operands[0].imm;
8811 static void
8812 do_t_cpsi (void)
8814 constraint (current_it_mask, BAD_NOT_IT);
8815 if (unified_syntax
8816 && (inst.operands[1].present || inst.size_req == 4)
8817 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
8819 unsigned int imod = (inst.instruction & 0x0030) >> 4;
8820 inst.instruction = 0xf3af8000;
8821 inst.instruction |= imod << 9;
8822 inst.instruction |= inst.operands[0].imm << 5;
8823 if (inst.operands[1].present)
8824 inst.instruction |= 0x100 | inst.operands[1].imm;
8826 else
8828 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
8829 && (inst.operands[0].imm & 4),
8830 _("selected processor does not support 'A' form "
8831 "of this instruction"));
8832 constraint (inst.operands[1].present || inst.size_req == 4,
8833 _("Thumb does not support the 2-argument "
8834 "form of this instruction"));
8835 inst.instruction |= inst.operands[0].imm;
8839 /* THUMB CPY instruction (argument parse). */
8841 static void
8842 do_t_cpy (void)
8844 if (inst.size_req == 4)
8846 inst.instruction = THUMB_OP32 (T_MNEM_mov);
8847 inst.instruction |= inst.operands[0].reg << 8;
8848 inst.instruction |= inst.operands[1].reg;
8850 else
8852 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
8853 inst.instruction |= (inst.operands[0].reg & 0x7);
8854 inst.instruction |= inst.operands[1].reg << 3;
8858 static void
8859 do_t_czb (void)
8861 constraint (current_it_mask, BAD_NOT_IT);
8862 constraint (inst.operands[0].reg > 7, BAD_HIREG);
8863 inst.instruction |= inst.operands[0].reg;
8864 inst.reloc.pc_rel = 1;
8865 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
8868 static void
8869 do_t_dbg (void)
8871 inst.instruction |= inst.operands[0].imm;
8874 static void
8875 do_t_div (void)
8877 if (!inst.operands[1].present)
8878 inst.operands[1].reg = inst.operands[0].reg;
8879 inst.instruction |= inst.operands[0].reg << 8;
8880 inst.instruction |= inst.operands[1].reg << 16;
8881 inst.instruction |= inst.operands[2].reg;
8884 static void
8885 do_t_hint (void)
8887 if (unified_syntax && inst.size_req == 4)
8888 inst.instruction = THUMB_OP32 (inst.instruction);
8889 else
8890 inst.instruction = THUMB_OP16 (inst.instruction);
8893 static void
8894 do_t_it (void)
8896 unsigned int cond = inst.operands[0].imm;
8898 constraint (current_it_mask, BAD_NOT_IT);
8899 current_it_mask = (inst.instruction & 0xf) | 0x10;
8900 current_cc = cond;
8902 /* If the condition is a negative condition, invert the mask. */
8903 if ((cond & 0x1) == 0x0)
8905 unsigned int mask = inst.instruction & 0x000f;
8907 if ((mask & 0x7) == 0)
8908 /* no conversion needed */;
8909 else if ((mask & 0x3) == 0)
8910 mask ^= 0x8;
8911 else if ((mask & 0x1) == 0)
8912 mask ^= 0xC;
8913 else
8914 mask ^= 0xE;
8916 inst.instruction &= 0xfff0;
8917 inst.instruction |= mask;
8920 inst.instruction |= cond << 4;
8923 static void
8924 do_t_ldmstm (void)
8926 /* This really doesn't seem worth it. */
8927 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
8928 _("expression too complex"));
8929 constraint (inst.operands[1].writeback,
8930 _("Thumb load/store multiple does not support {reglist}^"));
8932 if (unified_syntax)
8934 /* See if we can use a 16-bit instruction. */
8935 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
8936 && inst.size_req != 4
8937 && inst.operands[0].reg <= 7
8938 && !(inst.operands[1].imm & ~0xff)
8939 && (inst.instruction == T_MNEM_stmia
8940 ? inst.operands[0].writeback
8941 : (inst.operands[0].writeback
8942 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
8944 if (inst.instruction == T_MNEM_stmia
8945 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
8946 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
8947 as_warn (_("value stored for r%d is UNPREDICTABLE"),
8948 inst.operands[0].reg);
8950 inst.instruction = THUMB_OP16 (inst.instruction);
8951 inst.instruction |= inst.operands[0].reg << 8;
8952 inst.instruction |= inst.operands[1].imm;
8954 else
8956 if (inst.operands[1].imm & (1 << 13))
8957 as_warn (_("SP should not be in register list"));
8958 if (inst.instruction == T_MNEM_stmia)
8960 if (inst.operands[1].imm & (1 << 15))
8961 as_warn (_("PC should not be in register list"));
8962 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
8963 as_warn (_("value stored for r%d is UNPREDICTABLE"),
8964 inst.operands[0].reg);
8966 else
8968 if (inst.operands[1].imm & (1 << 14)
8969 && inst.operands[1].imm & (1 << 15))
8970 as_warn (_("LR and PC should not both be in register list"));
8971 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
8972 && inst.operands[0].writeback)
8973 as_warn (_("base register should not be in register list "
8974 "when written back"));
8976 if (inst.instruction < 0xffff)
8977 inst.instruction = THUMB_OP32 (inst.instruction);
8978 inst.instruction |= inst.operands[0].reg << 16;
8979 inst.instruction |= inst.operands[1].imm;
8980 if (inst.operands[0].writeback)
8981 inst.instruction |= WRITE_BACK;
8984 else
8986 constraint (inst.operands[0].reg > 7
8987 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
8988 if (inst.instruction == T_MNEM_stmia)
8990 if (!inst.operands[0].writeback)
8991 as_warn (_("this instruction will write back the base register"));
8992 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
8993 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
8994 as_warn (_("value stored for r%d is UNPREDICTABLE"),
8995 inst.operands[0].reg);
8997 else
8999 if (!inst.operands[0].writeback
9000 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9001 as_warn (_("this instruction will write back the base register"));
9002 else if (inst.operands[0].writeback
9003 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9004 as_warn (_("this instruction will not write back the base register"));
9007 inst.instruction = THUMB_OP16 (inst.instruction);
9008 inst.instruction |= inst.operands[0].reg << 8;
9009 inst.instruction |= inst.operands[1].imm;
9013 static void
9014 do_t_ldrex (void)
9016 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9017 || inst.operands[1].postind || inst.operands[1].writeback
9018 || inst.operands[1].immisreg || inst.operands[1].shifted
9019 || inst.operands[1].negative,
9020 BAD_ADDR_MODE);
9022 inst.instruction |= inst.operands[0].reg << 12;
9023 inst.instruction |= inst.operands[1].reg << 16;
9024 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9027 static void
9028 do_t_ldrexd (void)
9030 if (!inst.operands[1].present)
9032 constraint (inst.operands[0].reg == REG_LR,
9033 _("r14 not allowed as first register "
9034 "when second register is omitted"));
9035 inst.operands[1].reg = inst.operands[0].reg + 1;
9037 constraint (inst.operands[0].reg == inst.operands[1].reg,
9038 BAD_OVERLAP);
9040 inst.instruction |= inst.operands[0].reg << 12;
9041 inst.instruction |= inst.operands[1].reg << 8;
9042 inst.instruction |= inst.operands[2].reg << 16;
9045 static void
9046 do_t_ldst (void)
9048 unsigned long opcode;
9049 int Rn;
9051 opcode = inst.instruction;
9052 if (unified_syntax)
9054 if (!inst.operands[1].isreg)
9056 if (opcode <= 0xffff)
9057 inst.instruction = THUMB_OP32 (opcode);
9058 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9059 return;
9061 if (inst.operands[1].isreg
9062 && !inst.operands[1].writeback
9063 && !inst.operands[1].shifted && !inst.operands[1].postind
9064 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9065 && opcode <= 0xffff
9066 && inst.size_req != 4)
9068 /* Insn may have a 16-bit form. */
9069 Rn = inst.operands[1].reg;
9070 if (inst.operands[1].immisreg)
9072 inst.instruction = THUMB_OP16 (opcode);
9073 /* [Rn, Ri] */
9074 if (Rn <= 7 && inst.operands[1].imm <= 7)
9075 goto op16;
9077 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9078 && opcode != T_MNEM_ldrsb)
9079 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9080 || (Rn == REG_SP && opcode == T_MNEM_str))
9082 /* [Rn, #const] */
9083 if (Rn > 7)
9085 if (Rn == REG_PC)
9087 if (inst.reloc.pc_rel)
9088 opcode = T_MNEM_ldr_pc2;
9089 else
9090 opcode = T_MNEM_ldr_pc;
9092 else
9094 if (opcode == T_MNEM_ldr)
9095 opcode = T_MNEM_ldr_sp;
9096 else
9097 opcode = T_MNEM_str_sp;
9099 inst.instruction = inst.operands[0].reg << 8;
9101 else
9103 inst.instruction = inst.operands[0].reg;
9104 inst.instruction |= inst.operands[1].reg << 3;
9106 inst.instruction |= THUMB_OP16 (opcode);
9107 if (inst.size_req == 2)
9108 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9109 else
9110 inst.relax = opcode;
9111 return;
9114 /* Definitely a 32-bit variant. */
9115 inst.instruction = THUMB_OP32 (opcode);
9116 inst.instruction |= inst.operands[0].reg << 12;
9117 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9118 return;
9121 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9123 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9125 /* Only [Rn,Rm] is acceptable. */
9126 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9127 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9128 || inst.operands[1].postind || inst.operands[1].shifted
9129 || inst.operands[1].negative,
9130 _("Thumb does not support this addressing mode"));
9131 inst.instruction = THUMB_OP16 (inst.instruction);
9132 goto op16;
9135 inst.instruction = THUMB_OP16 (inst.instruction);
9136 if (!inst.operands[1].isreg)
9137 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9138 return;
9140 constraint (!inst.operands[1].preind
9141 || inst.operands[1].shifted
9142 || inst.operands[1].writeback,
9143 _("Thumb does not support this addressing mode"));
9144 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9146 constraint (inst.instruction & 0x0600,
9147 _("byte or halfword not valid for base register"));
9148 constraint (inst.operands[1].reg == REG_PC
9149 && !(inst.instruction & THUMB_LOAD_BIT),
9150 _("r15 based store not allowed"));
9151 constraint (inst.operands[1].immisreg,
9152 _("invalid base register for register offset"));
9154 if (inst.operands[1].reg == REG_PC)
9155 inst.instruction = T_OPCODE_LDR_PC;
9156 else if (inst.instruction & THUMB_LOAD_BIT)
9157 inst.instruction = T_OPCODE_LDR_SP;
9158 else
9159 inst.instruction = T_OPCODE_STR_SP;
9161 inst.instruction |= inst.operands[0].reg << 8;
9162 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9163 return;
9166 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9167 if (!inst.operands[1].immisreg)
9169 /* Immediate offset. */
9170 inst.instruction |= inst.operands[0].reg;
9171 inst.instruction |= inst.operands[1].reg << 3;
9172 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9173 return;
9176 /* Register offset. */
9177 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9178 constraint (inst.operands[1].negative,
9179 _("Thumb does not support this addressing mode"));
9181 op16:
9182 switch (inst.instruction)
9184 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9185 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9186 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9187 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9188 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9189 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9190 case 0x5600 /* ldrsb */:
9191 case 0x5e00 /* ldrsh */: break;
9192 default: abort ();
9195 inst.instruction |= inst.operands[0].reg;
9196 inst.instruction |= inst.operands[1].reg << 3;
9197 inst.instruction |= inst.operands[1].imm << 6;
9200 static void
9201 do_t_ldstd (void)
9203 if (!inst.operands[1].present)
9205 inst.operands[1].reg = inst.operands[0].reg + 1;
9206 constraint (inst.operands[0].reg == REG_LR,
9207 _("r14 not allowed here"));
9209 inst.instruction |= inst.operands[0].reg << 12;
9210 inst.instruction |= inst.operands[1].reg << 8;
9211 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9215 static void
9216 do_t_ldstt (void)
9218 inst.instruction |= inst.operands[0].reg << 12;
9219 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9222 static void
9223 do_t_mla (void)
9225 inst.instruction |= inst.operands[0].reg << 8;
9226 inst.instruction |= inst.operands[1].reg << 16;
9227 inst.instruction |= inst.operands[2].reg;
9228 inst.instruction |= inst.operands[3].reg << 12;
9231 static void
9232 do_t_mlal (void)
9234 inst.instruction |= inst.operands[0].reg << 12;
9235 inst.instruction |= inst.operands[1].reg << 8;
9236 inst.instruction |= inst.operands[2].reg << 16;
9237 inst.instruction |= inst.operands[3].reg;
9240 static void
9241 do_t_mov_cmp (void)
9243 if (unified_syntax)
9245 int r0off = (inst.instruction == T_MNEM_mov
9246 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9247 unsigned long opcode;
9248 bfd_boolean narrow;
9249 bfd_boolean low_regs;
9251 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
9252 opcode = inst.instruction;
9253 if (current_it_mask)
9254 narrow = opcode != T_MNEM_movs;
9255 else
9256 narrow = opcode != T_MNEM_movs || low_regs;
9257 if (inst.size_req == 4
9258 || inst.operands[1].shifted)
9259 narrow = FALSE;
9261 if (!inst.operands[1].isreg)
9263 /* Immediate operand. */
9264 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9265 narrow = 0;
9266 if (low_regs && narrow)
9268 inst.instruction = THUMB_OP16 (opcode);
9269 inst.instruction |= inst.operands[0].reg << 8;
9270 if (inst.size_req == 2)
9271 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9272 else
9273 inst.relax = opcode;
9275 else
9277 inst.instruction = THUMB_OP32 (inst.instruction);
9278 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9279 inst.instruction |= inst.operands[0].reg << r0off;
9280 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9283 else if (!narrow)
9285 inst.instruction = THUMB_OP32 (inst.instruction);
9286 inst.instruction |= inst.operands[0].reg << r0off;
9287 encode_thumb32_shifted_operand (1);
9289 else
9290 switch (inst.instruction)
9292 case T_MNEM_mov:
9293 inst.instruction = T_OPCODE_MOV_HR;
9294 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9295 inst.instruction |= (inst.operands[0].reg & 0x7);
9296 inst.instruction |= inst.operands[1].reg << 3;
9297 break;
9299 case T_MNEM_movs:
9300 /* We know we have low registers at this point.
9301 Generate ADD Rd, Rs, #0. */
9302 inst.instruction = T_OPCODE_ADD_I3;
9303 inst.instruction |= inst.operands[0].reg;
9304 inst.instruction |= inst.operands[1].reg << 3;
9305 break;
9307 case T_MNEM_cmp:
9308 if (low_regs)
9310 inst.instruction = T_OPCODE_CMP_LR;
9311 inst.instruction |= inst.operands[0].reg;
9312 inst.instruction |= inst.operands[1].reg << 3;
9314 else
9316 inst.instruction = T_OPCODE_CMP_HR;
9317 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9318 inst.instruction |= (inst.operands[0].reg & 0x7);
9319 inst.instruction |= inst.operands[1].reg << 3;
9321 break;
9323 return;
9326 inst.instruction = THUMB_OP16 (inst.instruction);
9327 if (inst.operands[1].isreg)
9329 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
9331 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9332 since a MOV instruction produces unpredictable results. */
9333 if (inst.instruction == T_OPCODE_MOV_I8)
9334 inst.instruction = T_OPCODE_ADD_I3;
9335 else
9336 inst.instruction = T_OPCODE_CMP_LR;
9338 inst.instruction |= inst.operands[0].reg;
9339 inst.instruction |= inst.operands[1].reg << 3;
9341 else
9343 if (inst.instruction == T_OPCODE_MOV_I8)
9344 inst.instruction = T_OPCODE_MOV_HR;
9345 else
9346 inst.instruction = T_OPCODE_CMP_HR;
9347 do_t_cpy ();
9350 else
9352 constraint (inst.operands[0].reg > 7,
9353 _("only lo regs allowed with immediate"));
9354 inst.instruction |= inst.operands[0].reg << 8;
9355 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9359 static void
9360 do_t_mov16 (void)
9362 bfd_vma imm;
9363 bfd_boolean top;
9365 top = (inst.instruction & 0x00800000) != 0;
9366 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9368 constraint (top, _(":lower16: not allowed this instruction"));
9369 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9371 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9373 constraint (!top, _(":upper16: not allowed this instruction"));
9374 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9377 inst.instruction |= inst.operands[0].reg << 8;
9378 if (inst.reloc.type == BFD_RELOC_UNUSED)
9380 imm = inst.reloc.exp.X_add_number;
9381 inst.instruction |= (imm & 0xf000) << 4;
9382 inst.instruction |= (imm & 0x0800) << 15;
9383 inst.instruction |= (imm & 0x0700) << 4;
9384 inst.instruction |= (imm & 0x00ff);
9388 static void
9389 do_t_mvn_tst (void)
9391 if (unified_syntax)
9393 int r0off = (inst.instruction == T_MNEM_mvn
9394 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9395 bfd_boolean narrow;
9397 if (inst.size_req == 4
9398 || inst.instruction > 0xffff
9399 || inst.operands[1].shifted
9400 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9401 narrow = FALSE;
9402 else if (inst.instruction == T_MNEM_cmn)
9403 narrow = TRUE;
9404 else if (THUMB_SETS_FLAGS (inst.instruction))
9405 narrow = (current_it_mask == 0);
9406 else
9407 narrow = (current_it_mask != 0);
9409 if (!inst.operands[1].isreg)
9411 /* For an immediate, we always generate a 32-bit opcode;
9412 section relaxation will shrink it later if possible. */
9413 if (inst.instruction < 0xffff)
9414 inst.instruction = THUMB_OP32 (inst.instruction);
9415 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9416 inst.instruction |= inst.operands[0].reg << r0off;
9417 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9419 else
9421 /* See if we can do this with a 16-bit instruction. */
9422 if (narrow)
9424 inst.instruction = THUMB_OP16 (inst.instruction);
9425 inst.instruction |= inst.operands[0].reg;
9426 inst.instruction |= inst.operands[1].reg << 3;
9428 else
9430 constraint (inst.operands[1].shifted
9431 && inst.operands[1].immisreg,
9432 _("shift must be constant"));
9433 if (inst.instruction < 0xffff)
9434 inst.instruction = THUMB_OP32 (inst.instruction);
9435 inst.instruction |= inst.operands[0].reg << r0off;
9436 encode_thumb32_shifted_operand (1);
9440 else
9442 constraint (inst.instruction > 0xffff
9443 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9444 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9445 _("unshifted register required"));
9446 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9447 BAD_HIREG);
9449 inst.instruction = THUMB_OP16 (inst.instruction);
9450 inst.instruction |= inst.operands[0].reg;
9451 inst.instruction |= inst.operands[1].reg << 3;
9455 static void
9456 do_t_mrs (void)
9458 int flags;
9460 if (do_vfp_nsyn_mrs () == SUCCESS)
9461 return;
9463 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9464 if (flags == 0)
9466 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9467 _("selected processor does not support "
9468 "requested special purpose register"));
9470 else
9472 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9473 _("selected processor does not support "
9474 "requested special purpose register %x"));
9475 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9476 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9477 _("'CPSR' or 'SPSR' expected"));
9480 inst.instruction |= inst.operands[0].reg << 8;
9481 inst.instruction |= (flags & SPSR_BIT) >> 2;
9482 inst.instruction |= inst.operands[1].imm & 0xff;
9485 static void
9486 do_t_msr (void)
9488 int flags;
9490 if (do_vfp_nsyn_msr () == SUCCESS)
9491 return;
9493 constraint (!inst.operands[1].isreg,
9494 _("Thumb encoding does not support an immediate here"));
9495 flags = inst.operands[0].imm;
9496 if (flags & ~0xff)
9498 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9499 _("selected processor does not support "
9500 "requested special purpose register"));
9502 else
9504 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9505 _("selected processor does not support "
9506 "requested special purpose register"));
9507 flags |= PSR_f;
9509 inst.instruction |= (flags & SPSR_BIT) >> 2;
9510 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9511 inst.instruction |= (flags & 0xff);
9512 inst.instruction |= inst.operands[1].reg << 16;
9515 static void
9516 do_t_mul (void)
9518 if (!inst.operands[2].present)
9519 inst.operands[2].reg = inst.operands[0].reg;
9521 /* There is no 32-bit MULS and no 16-bit MUL. */
9522 if (unified_syntax && inst.instruction == T_MNEM_mul)
9524 inst.instruction = THUMB_OP32 (inst.instruction);
9525 inst.instruction |= inst.operands[0].reg << 8;
9526 inst.instruction |= inst.operands[1].reg << 16;
9527 inst.instruction |= inst.operands[2].reg << 0;
9529 else
9531 constraint (!unified_syntax
9532 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9533 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9534 BAD_HIREG);
9536 inst.instruction = THUMB_OP16 (inst.instruction);
9537 inst.instruction |= inst.operands[0].reg;
9539 if (inst.operands[0].reg == inst.operands[1].reg)
9540 inst.instruction |= inst.operands[2].reg << 3;
9541 else if (inst.operands[0].reg == inst.operands[2].reg)
9542 inst.instruction |= inst.operands[1].reg << 3;
9543 else
9544 constraint (1, _("dest must overlap one source register"));
9548 static void
9549 do_t_mull (void)
9551 inst.instruction |= inst.operands[0].reg << 12;
9552 inst.instruction |= inst.operands[1].reg << 8;
9553 inst.instruction |= inst.operands[2].reg << 16;
9554 inst.instruction |= inst.operands[3].reg;
9556 if (inst.operands[0].reg == inst.operands[1].reg)
9557 as_tsktsk (_("rdhi and rdlo must be different"));
9560 static void
9561 do_t_nop (void)
9563 if (unified_syntax)
9565 if (inst.size_req == 4 || inst.operands[0].imm > 15)
9567 inst.instruction = THUMB_OP32 (inst.instruction);
9568 inst.instruction |= inst.operands[0].imm;
9570 else
9572 inst.instruction = THUMB_OP16 (inst.instruction);
9573 inst.instruction |= inst.operands[0].imm << 4;
9576 else
9578 constraint (inst.operands[0].present,
9579 _("Thumb does not support NOP with hints"));
9580 inst.instruction = 0x46c0;
9584 static void
9585 do_t_neg (void)
9587 if (unified_syntax)
9589 bfd_boolean narrow;
9591 if (THUMB_SETS_FLAGS (inst.instruction))
9592 narrow = (current_it_mask == 0);
9593 else
9594 narrow = (current_it_mask != 0);
9595 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9596 narrow = FALSE;
9597 if (inst.size_req == 4)
9598 narrow = FALSE;
9600 if (!narrow)
9602 inst.instruction = THUMB_OP32 (inst.instruction);
9603 inst.instruction |= inst.operands[0].reg << 8;
9604 inst.instruction |= inst.operands[1].reg << 16;
9606 else
9608 inst.instruction = THUMB_OP16 (inst.instruction);
9609 inst.instruction |= inst.operands[0].reg;
9610 inst.instruction |= inst.operands[1].reg << 3;
9613 else
9615 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9616 BAD_HIREG);
9617 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9619 inst.instruction = THUMB_OP16 (inst.instruction);
9620 inst.instruction |= inst.operands[0].reg;
9621 inst.instruction |= inst.operands[1].reg << 3;
9625 static void
9626 do_t_pkhbt (void)
9628 inst.instruction |= inst.operands[0].reg << 8;
9629 inst.instruction |= inst.operands[1].reg << 16;
9630 inst.instruction |= inst.operands[2].reg;
9631 if (inst.operands[3].present)
9633 unsigned int val = inst.reloc.exp.X_add_number;
9634 constraint (inst.reloc.exp.X_op != O_constant,
9635 _("expression too complex"));
9636 inst.instruction |= (val & 0x1c) << 10;
9637 inst.instruction |= (val & 0x03) << 6;
9641 static void
9642 do_t_pkhtb (void)
9644 if (!inst.operands[3].present)
9645 inst.instruction &= ~0x00000020;
9646 do_t_pkhbt ();
9649 static void
9650 do_t_pld (void)
9652 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
9655 static void
9656 do_t_push_pop (void)
9658 unsigned mask;
9660 constraint (inst.operands[0].writeback,
9661 _("push/pop do not support {reglist}^"));
9662 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9663 _("expression too complex"));
9665 mask = inst.operands[0].imm;
9666 if ((mask & ~0xff) == 0)
9667 inst.instruction = THUMB_OP16 (inst.instruction);
9668 else if ((inst.instruction == T_MNEM_push
9669 && (mask & ~0xff) == 1 << REG_LR)
9670 || (inst.instruction == T_MNEM_pop
9671 && (mask & ~0xff) == 1 << REG_PC))
9673 inst.instruction = THUMB_OP16 (inst.instruction);
9674 inst.instruction |= THUMB_PP_PC_LR;
9675 mask &= 0xff;
9677 else if (unified_syntax)
9679 if (mask & (1 << 13))
9680 inst.error = _("SP not allowed in register list");
9681 if (inst.instruction == T_MNEM_push)
9683 if (mask & (1 << 15))
9684 inst.error = _("PC not allowed in register list");
9686 else
9688 if (mask & (1 << 14)
9689 && mask & (1 << 15))
9690 inst.error = _("LR and PC should not both be in register list");
9692 if ((mask & (mask - 1)) == 0)
9694 /* Single register push/pop implemented as str/ldr. */
9695 if (inst.instruction == T_MNEM_push)
9696 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
9697 else
9698 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
9699 mask = ffs(mask) - 1;
9700 mask <<= 12;
9702 else
9703 inst.instruction = THUMB_OP32 (inst.instruction);
9705 else
9707 inst.error = _("invalid register list to push/pop instruction");
9708 return;
9711 inst.instruction |= mask;
9714 static void
9715 do_t_rbit (void)
9717 inst.instruction |= inst.operands[0].reg << 8;
9718 inst.instruction |= inst.operands[1].reg << 16;
9721 static void
9722 do_t_rev (void)
9724 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
9725 && inst.size_req != 4)
9727 inst.instruction = THUMB_OP16 (inst.instruction);
9728 inst.instruction |= inst.operands[0].reg;
9729 inst.instruction |= inst.operands[1].reg << 3;
9731 else if (unified_syntax)
9733 inst.instruction = THUMB_OP32 (inst.instruction);
9734 inst.instruction |= inst.operands[0].reg << 8;
9735 inst.instruction |= inst.operands[1].reg << 16;
9736 inst.instruction |= inst.operands[1].reg;
9738 else
9739 inst.error = BAD_HIREG;
9742 static void
9743 do_t_rsb (void)
9745 int Rd, Rs;
9747 Rd = inst.operands[0].reg;
9748 Rs = (inst.operands[1].present
9749 ? inst.operands[1].reg /* Rd, Rs, foo */
9750 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9752 inst.instruction |= Rd << 8;
9753 inst.instruction |= Rs << 16;
9754 if (!inst.operands[2].isreg)
9756 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9757 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9759 else
9760 encode_thumb32_shifted_operand (2);
9763 static void
9764 do_t_setend (void)
9766 constraint (current_it_mask, BAD_NOT_IT);
9767 if (inst.operands[0].imm)
9768 inst.instruction |= 0x8;
9771 static void
9772 do_t_shift (void)
9774 if (!inst.operands[1].present)
9775 inst.operands[1].reg = inst.operands[0].reg;
9777 if (unified_syntax)
9779 bfd_boolean narrow;
9780 int shift_kind;
9782 switch (inst.instruction)
9784 case T_MNEM_asr:
9785 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
9786 case T_MNEM_lsl:
9787 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
9788 case T_MNEM_lsr:
9789 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
9790 case T_MNEM_ror:
9791 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
9792 default: abort ();
9795 if (THUMB_SETS_FLAGS (inst.instruction))
9796 narrow = (current_it_mask == 0);
9797 else
9798 narrow = (current_it_mask != 0);
9799 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9800 narrow = FALSE;
9801 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
9802 narrow = FALSE;
9803 if (inst.operands[2].isreg
9804 && (inst.operands[1].reg != inst.operands[0].reg
9805 || inst.operands[2].reg > 7))
9806 narrow = FALSE;
9807 if (inst.size_req == 4)
9808 narrow = FALSE;
9810 if (!narrow)
9812 if (inst.operands[2].isreg)
9814 inst.instruction = THUMB_OP32 (inst.instruction);
9815 inst.instruction |= inst.operands[0].reg << 8;
9816 inst.instruction |= inst.operands[1].reg << 16;
9817 inst.instruction |= inst.operands[2].reg;
9819 else
9821 inst.operands[1].shifted = 1;
9822 inst.operands[1].shift_kind = shift_kind;
9823 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
9824 ? T_MNEM_movs : T_MNEM_mov);
9825 inst.instruction |= inst.operands[0].reg << 8;
9826 encode_thumb32_shifted_operand (1);
9827 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
9828 inst.reloc.type = BFD_RELOC_UNUSED;
9831 else
9833 if (inst.operands[2].isreg)
9835 switch (shift_kind)
9837 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
9838 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
9839 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
9840 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
9841 default: abort ();
9844 inst.instruction |= inst.operands[0].reg;
9845 inst.instruction |= inst.operands[2].reg << 3;
9847 else
9849 switch (shift_kind)
9851 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9852 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9853 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9854 default: abort ();
9856 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9857 inst.instruction |= inst.operands[0].reg;
9858 inst.instruction |= inst.operands[1].reg << 3;
9862 else
9864 constraint (inst.operands[0].reg > 7
9865 || inst.operands[1].reg > 7, BAD_HIREG);
9866 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9868 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
9870 constraint (inst.operands[2].reg > 7, BAD_HIREG);
9871 constraint (inst.operands[0].reg != inst.operands[1].reg,
9872 _("source1 and dest must be same register"));
9874 switch (inst.instruction)
9876 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
9877 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
9878 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
9879 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
9880 default: abort ();
9883 inst.instruction |= inst.operands[0].reg;
9884 inst.instruction |= inst.operands[2].reg << 3;
9886 else
9888 switch (inst.instruction)
9890 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
9891 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
9892 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
9893 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
9894 default: abort ();
9896 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9897 inst.instruction |= inst.operands[0].reg;
9898 inst.instruction |= inst.operands[1].reg << 3;
9903 static void
9904 do_t_simd (void)
9906 inst.instruction |= inst.operands[0].reg << 8;
9907 inst.instruction |= inst.operands[1].reg << 16;
9908 inst.instruction |= inst.operands[2].reg;
9911 static void
9912 do_t_smc (void)
9914 unsigned int value = inst.reloc.exp.X_add_number;
9915 constraint (inst.reloc.exp.X_op != O_constant,
9916 _("expression too complex"));
9917 inst.reloc.type = BFD_RELOC_UNUSED;
9918 inst.instruction |= (value & 0xf000) >> 12;
9919 inst.instruction |= (value & 0x0ff0);
9920 inst.instruction |= (value & 0x000f) << 16;
9923 static void
9924 do_t_ssat (void)
9926 inst.instruction |= inst.operands[0].reg << 8;
9927 inst.instruction |= inst.operands[1].imm - 1;
9928 inst.instruction |= inst.operands[2].reg << 16;
9930 if (inst.operands[3].present)
9932 constraint (inst.reloc.exp.X_op != O_constant,
9933 _("expression too complex"));
9935 if (inst.reloc.exp.X_add_number != 0)
9937 if (inst.operands[3].shift_kind == SHIFT_ASR)
9938 inst.instruction |= 0x00200000; /* sh bit */
9939 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
9940 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
9942 inst.reloc.type = BFD_RELOC_UNUSED;
9946 static void
9947 do_t_ssat16 (void)
9949 inst.instruction |= inst.operands[0].reg << 8;
9950 inst.instruction |= inst.operands[1].imm - 1;
9951 inst.instruction |= inst.operands[2].reg << 16;
9954 static void
9955 do_t_strex (void)
9957 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9958 || inst.operands[2].postind || inst.operands[2].writeback
9959 || inst.operands[2].immisreg || inst.operands[2].shifted
9960 || inst.operands[2].negative,
9961 BAD_ADDR_MODE);
9963 inst.instruction |= inst.operands[0].reg << 8;
9964 inst.instruction |= inst.operands[1].reg << 12;
9965 inst.instruction |= inst.operands[2].reg << 16;
9966 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9969 static void
9970 do_t_strexd (void)
9972 if (!inst.operands[2].present)
9973 inst.operands[2].reg = inst.operands[1].reg + 1;
9975 constraint (inst.operands[0].reg == inst.operands[1].reg
9976 || inst.operands[0].reg == inst.operands[2].reg
9977 || inst.operands[0].reg == inst.operands[3].reg
9978 || inst.operands[1].reg == inst.operands[2].reg,
9979 BAD_OVERLAP);
9981 inst.instruction |= inst.operands[0].reg;
9982 inst.instruction |= inst.operands[1].reg << 12;
9983 inst.instruction |= inst.operands[2].reg << 8;
9984 inst.instruction |= inst.operands[3].reg << 16;
9987 static void
9988 do_t_sxtah (void)
9990 inst.instruction |= inst.operands[0].reg << 8;
9991 inst.instruction |= inst.operands[1].reg << 16;
9992 inst.instruction |= inst.operands[2].reg;
9993 inst.instruction |= inst.operands[3].imm << 4;
9996 static void
9997 do_t_sxth (void)
9999 if (inst.instruction <= 0xffff && inst.size_req != 4
10000 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10001 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10003 inst.instruction = THUMB_OP16 (inst.instruction);
10004 inst.instruction |= inst.operands[0].reg;
10005 inst.instruction |= inst.operands[1].reg << 3;
10007 else if (unified_syntax)
10009 if (inst.instruction <= 0xffff)
10010 inst.instruction = THUMB_OP32 (inst.instruction);
10011 inst.instruction |= inst.operands[0].reg << 8;
10012 inst.instruction |= inst.operands[1].reg;
10013 inst.instruction |= inst.operands[2].imm << 4;
10015 else
10017 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10018 _("Thumb encoding does not support rotation"));
10019 constraint (1, BAD_HIREG);
10023 static void
10024 do_t_swi (void)
10026 inst.reloc.type = BFD_RELOC_ARM_SWI;
10029 static void
10030 do_t_tb (void)
10032 int half;
10034 half = (inst.instruction & 0x10) != 0;
10035 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10036 constraint (inst.operands[0].immisreg,
10037 _("instruction requires register index"));
10038 constraint (inst.operands[0].imm == 15,
10039 _("PC is not a valid index register"));
10040 constraint (!half && inst.operands[0].shifted,
10041 _("instruction does not allow shifted index"));
10042 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10045 static void
10046 do_t_usat (void)
10048 inst.instruction |= inst.operands[0].reg << 8;
10049 inst.instruction |= inst.operands[1].imm;
10050 inst.instruction |= inst.operands[2].reg << 16;
10052 if (inst.operands[3].present)
10054 constraint (inst.reloc.exp.X_op != O_constant,
10055 _("expression too complex"));
10056 if (inst.reloc.exp.X_add_number != 0)
10058 if (inst.operands[3].shift_kind == SHIFT_ASR)
10059 inst.instruction |= 0x00200000; /* sh bit */
10061 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10062 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10064 inst.reloc.type = BFD_RELOC_UNUSED;
10068 static void
10069 do_t_usat16 (void)
10071 inst.instruction |= inst.operands[0].reg << 8;
10072 inst.instruction |= inst.operands[1].imm;
10073 inst.instruction |= inst.operands[2].reg << 16;
10076 /* Neon instruction encoder helpers. */
10078 /* Encodings for the different types for various Neon opcodes. */
10080 /* An "invalid" code for the following tables. */
10081 #define N_INV -1u
10083 struct neon_tab_entry
10085 unsigned integer;
10086 unsigned float_or_poly;
10087 unsigned scalar_or_imm;
10090 /* Map overloaded Neon opcodes to their respective encodings. */
10091 #define NEON_ENC_TAB \
10092 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10093 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10094 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10095 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10096 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10097 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10098 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10099 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10100 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10101 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10102 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10103 /* Register variants of the following two instructions are encoded as
10104 vcge / vcgt with the operands reversed. */ \
10105 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10106 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
10107 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10108 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10109 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10110 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10111 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10112 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10113 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10114 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10115 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10116 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10117 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10118 X(vshl, 0x0000400, N_INV, 0x0800510), \
10119 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10120 X(vand, 0x0000110, N_INV, 0x0800030), \
10121 X(vbic, 0x0100110, N_INV, 0x0800030), \
10122 X(veor, 0x1000110, N_INV, N_INV), \
10123 X(vorn, 0x0300110, N_INV, 0x0800010), \
10124 X(vorr, 0x0200110, N_INV, 0x0800010), \
10125 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10126 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10127 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10128 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10129 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10130 X(vst1, 0x0000000, 0x0800000, N_INV), \
10131 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10132 X(vst2, 0x0000100, 0x0800100, N_INV), \
10133 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10134 X(vst3, 0x0000200, 0x0800200, N_INV), \
10135 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10136 X(vst4, 0x0000300, 0x0800300, N_INV), \
10137 X(vmovn, 0x1b20200, N_INV, N_INV), \
10138 X(vtrn, 0x1b20080, N_INV, N_INV), \
10139 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10140 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10141 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10142 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10143 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10144 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10145 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10146 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10147 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10149 enum neon_opc
10151 #define X(OPC,I,F,S) N_MNEM_##OPC
10152 NEON_ENC_TAB
10153 #undef X
10156 static const struct neon_tab_entry neon_enc_tab[] =
10158 #define X(OPC,I,F,S) { (I), (F), (S) }
10159 NEON_ENC_TAB
10160 #undef X
10163 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10164 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10165 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10166 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10167 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10168 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10169 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10170 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10171 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10172 #define NEON_ENC_SINGLE(X) \
10173 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10174 #define NEON_ENC_DOUBLE(X) \
10175 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10177 /* Define shapes for instruction operands. The following mnemonic characters
10178 are used in this table:
10180 F - VFP S<n> register
10181 D - Neon D<n> register
10182 Q - Neon Q<n> register
10183 I - Immediate
10184 S - Scalar
10185 R - ARM register
10186 L - D<n> register list
10188 This table is used to generate various data:
10189 - enumerations of the form NS_DDR to be used as arguments to
10190 neon_select_shape.
10191 - a table classifying shapes into single, double, quad, mixed.
10192 - a table used to drive neon_select_shape.
10195 #define NEON_SHAPE_DEF \
10196 X(3, (D, D, D), DOUBLE), \
10197 X(3, (Q, Q, Q), QUAD), \
10198 X(3, (D, D, I), DOUBLE), \
10199 X(3, (Q, Q, I), QUAD), \
10200 X(3, (D, D, S), DOUBLE), \
10201 X(3, (Q, Q, S), QUAD), \
10202 X(2, (D, D), DOUBLE), \
10203 X(2, (Q, Q), QUAD), \
10204 X(2, (D, S), DOUBLE), \
10205 X(2, (Q, S), QUAD), \
10206 X(2, (D, R), DOUBLE), \
10207 X(2, (Q, R), QUAD), \
10208 X(2, (D, I), DOUBLE), \
10209 X(2, (Q, I), QUAD), \
10210 X(3, (D, L, D), DOUBLE), \
10211 X(2, (D, Q), MIXED), \
10212 X(2, (Q, D), MIXED), \
10213 X(3, (D, Q, I), MIXED), \
10214 X(3, (Q, D, I), MIXED), \
10215 X(3, (Q, D, D), MIXED), \
10216 X(3, (D, Q, Q), MIXED), \
10217 X(3, (Q, Q, D), MIXED), \
10218 X(3, (Q, D, S), MIXED), \
10219 X(3, (D, Q, S), MIXED), \
10220 X(4, (D, D, D, I), DOUBLE), \
10221 X(4, (Q, Q, Q, I), QUAD), \
10222 X(2, (F, F), SINGLE), \
10223 X(3, (F, F, F), SINGLE), \
10224 X(2, (F, I), SINGLE), \
10225 X(2, (F, D), MIXED), \
10226 X(2, (D, F), MIXED), \
10227 X(3, (F, F, I), MIXED), \
10228 X(4, (R, R, F, F), SINGLE), \
10229 X(4, (F, F, R, R), SINGLE), \
10230 X(3, (D, R, R), DOUBLE), \
10231 X(3, (R, R, D), DOUBLE), \
10232 X(2, (S, R), SINGLE), \
10233 X(2, (R, S), SINGLE), \
10234 X(2, (F, R), SINGLE), \
10235 X(2, (R, F), SINGLE)
10237 #define S2(A,B) NS_##A##B
10238 #define S3(A,B,C) NS_##A##B##C
10239 #define S4(A,B,C,D) NS_##A##B##C##D
10241 #define X(N, L, C) S##N L
10243 enum neon_shape
10245 NEON_SHAPE_DEF,
10246 NS_NULL
10249 #undef X
10250 #undef S2
10251 #undef S3
10252 #undef S4
10254 enum neon_shape_class
10256 SC_SINGLE,
10257 SC_DOUBLE,
10258 SC_QUAD,
10259 SC_MIXED
10262 #define X(N, L, C) SC_##C
10264 static enum neon_shape_class neon_shape_class[] =
10266 NEON_SHAPE_DEF
10269 #undef X
10271 enum neon_shape_el
10273 SE_F,
10274 SE_D,
10275 SE_Q,
10276 SE_I,
10277 SE_S,
10278 SE_R,
10279 SE_L
10282 /* Register widths of above. */
10283 static unsigned neon_shape_el_size[] =
10287 128,
10294 struct neon_shape_info
10296 unsigned els;
10297 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10300 #define S2(A,B) { SE_##A, SE_##B }
10301 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10302 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10304 #define X(N, L, C) { N, S##N L }
10306 static struct neon_shape_info neon_shape_tab[] =
10308 NEON_SHAPE_DEF
10311 #undef X
10312 #undef S2
10313 #undef S3
10314 #undef S4
10316 /* Bit masks used in type checking given instructions.
10317 'N_EQK' means the type must be the same as (or based on in some way) the key
10318 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10319 set, various other bits can be set as well in order to modify the meaning of
10320 the type constraint. */
10322 enum neon_type_mask
10324 N_S8 = 0x000001,
10325 N_S16 = 0x000002,
10326 N_S32 = 0x000004,
10327 N_S64 = 0x000008,
10328 N_U8 = 0x000010,
10329 N_U16 = 0x000020,
10330 N_U32 = 0x000040,
10331 N_U64 = 0x000080,
10332 N_I8 = 0x000100,
10333 N_I16 = 0x000200,
10334 N_I32 = 0x000400,
10335 N_I64 = 0x000800,
10336 N_8 = 0x001000,
10337 N_16 = 0x002000,
10338 N_32 = 0x004000,
10339 N_64 = 0x008000,
10340 N_P8 = 0x010000,
10341 N_P16 = 0x020000,
10342 N_F32 = 0x040000,
10343 N_F64 = 0x080000,
10344 N_KEY = 0x100000, /* key element (main type specifier). */
10345 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10346 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
10347 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10348 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10349 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10350 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10351 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10352 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
10353 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
10354 N_UTYP = 0,
10355 N_MAX_NONSPECIAL = N_F64
10358 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10360 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10361 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10362 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10363 #define N_SUF_32 (N_SU_32 | N_F32)
10364 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10365 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10367 /* Pass this as the first type argument to neon_check_type to ignore types
10368 altogether. */
10369 #define N_IGNORE_TYPE (N_KEY | N_EQK)
10371 /* Select a "shape" for the current instruction (describing register types or
10372 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10373 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10374 function of operand parsing, so this function doesn't need to be called.
10375 Shapes should be listed in order of decreasing length. */
10377 static enum neon_shape
10378 neon_select_shape (enum neon_shape shape, ...)
10380 va_list ap;
10381 enum neon_shape first_shape = shape;
10383 /* Fix missing optional operands. FIXME: we don't know at this point how
10384 many arguments we should have, so this makes the assumption that we have
10385 > 1. This is true of all current Neon opcodes, I think, but may not be
10386 true in the future. */
10387 if (!inst.operands[1].present)
10388 inst.operands[1] = inst.operands[0];
10390 va_start (ap, shape);
10392 for (; shape != NS_NULL; shape = va_arg (ap, int))
10394 unsigned j;
10395 int matches = 1;
10397 for (j = 0; j < neon_shape_tab[shape].els; j++)
10399 if (!inst.operands[j].present)
10401 matches = 0;
10402 break;
10405 switch (neon_shape_tab[shape].el[j])
10407 case SE_F:
10408 if (!(inst.operands[j].isreg
10409 && inst.operands[j].isvec
10410 && inst.operands[j].issingle
10411 && !inst.operands[j].isquad))
10412 matches = 0;
10413 break;
10415 case SE_D:
10416 if (!(inst.operands[j].isreg
10417 && inst.operands[j].isvec
10418 && !inst.operands[j].isquad
10419 && !inst.operands[j].issingle))
10420 matches = 0;
10421 break;
10423 case SE_R:
10424 if (!(inst.operands[j].isreg
10425 && !inst.operands[j].isvec))
10426 matches = 0;
10427 break;
10429 case SE_Q:
10430 if (!(inst.operands[j].isreg
10431 && inst.operands[j].isvec
10432 && inst.operands[j].isquad
10433 && !inst.operands[j].issingle))
10434 matches = 0;
10435 break;
10437 case SE_I:
10438 if (!(!inst.operands[j].isreg
10439 && !inst.operands[j].isscalar))
10440 matches = 0;
10441 break;
10443 case SE_S:
10444 if (!(!inst.operands[j].isreg
10445 && inst.operands[j].isscalar))
10446 matches = 0;
10447 break;
10449 case SE_L:
10450 break;
10453 if (matches)
10454 break;
10457 va_end (ap);
10459 if (shape == NS_NULL && first_shape != NS_NULL)
10460 first_error (_("invalid instruction shape"));
10462 return shape;
10465 /* True if SHAPE is predominantly a quadword operation (most of the time, this
10466 means the Q bit should be set). */
10468 static int
10469 neon_quad (enum neon_shape shape)
10471 return neon_shape_class[shape] == SC_QUAD;
10474 static void
10475 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10476 unsigned *g_size)
10478 /* Allow modification to be made to types which are constrained to be
10479 based on the key element, based on bits set alongside N_EQK. */
10480 if ((typebits & N_EQK) != 0)
10482 if ((typebits & N_HLF) != 0)
10483 *g_size /= 2;
10484 else if ((typebits & N_DBL) != 0)
10485 *g_size *= 2;
10486 if ((typebits & N_SGN) != 0)
10487 *g_type = NT_signed;
10488 else if ((typebits & N_UNS) != 0)
10489 *g_type = NT_unsigned;
10490 else if ((typebits & N_INT) != 0)
10491 *g_type = NT_integer;
10492 else if ((typebits & N_FLT) != 0)
10493 *g_type = NT_float;
10494 else if ((typebits & N_SIZ) != 0)
10495 *g_type = NT_untyped;
10499 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10500 operand type, i.e. the single type specified in a Neon instruction when it
10501 is the only one given. */
10503 static struct neon_type_el
10504 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10506 struct neon_type_el dest = *key;
10508 assert ((thisarg & N_EQK) != 0);
10510 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10512 return dest;
10515 /* Convert Neon type and size into compact bitmask representation. */
10517 static enum neon_type_mask
10518 type_chk_of_el_type (enum neon_el_type type, unsigned size)
10520 switch (type)
10522 case NT_untyped:
10523 switch (size)
10525 case 8: return N_8;
10526 case 16: return N_16;
10527 case 32: return N_32;
10528 case 64: return N_64;
10529 default: ;
10531 break;
10533 case NT_integer:
10534 switch (size)
10536 case 8: return N_I8;
10537 case 16: return N_I16;
10538 case 32: return N_I32;
10539 case 64: return N_I64;
10540 default: ;
10542 break;
10544 case NT_float:
10545 switch (size)
10547 case 32: return N_F32;
10548 case 64: return N_F64;
10549 default: ;
10551 break;
10553 case NT_poly:
10554 switch (size)
10556 case 8: return N_P8;
10557 case 16: return N_P16;
10558 default: ;
10560 break;
10562 case NT_signed:
10563 switch (size)
10565 case 8: return N_S8;
10566 case 16: return N_S16;
10567 case 32: return N_S32;
10568 case 64: return N_S64;
10569 default: ;
10571 break;
10573 case NT_unsigned:
10574 switch (size)
10576 case 8: return N_U8;
10577 case 16: return N_U16;
10578 case 32: return N_U32;
10579 case 64: return N_U64;
10580 default: ;
10582 break;
10584 default: ;
10587 return N_UTYP;
10590 /* Convert compact Neon bitmask type representation to a type and size. Only
10591 handles the case where a single bit is set in the mask. */
10593 static int
10594 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10595 enum neon_type_mask mask)
10597 if ((mask & N_EQK) != 0)
10598 return FAIL;
10600 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10601 *size = 8;
10602 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
10603 *size = 16;
10604 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
10605 *size = 32;
10606 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
10607 *size = 64;
10608 else
10609 return FAIL;
10611 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10612 *type = NT_signed;
10613 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
10614 *type = NT_unsigned;
10615 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
10616 *type = NT_integer;
10617 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
10618 *type = NT_untyped;
10619 else if ((mask & (N_P8 | N_P16)) != 0)
10620 *type = NT_poly;
10621 else if ((mask & (N_F32 | N_F64)) != 0)
10622 *type = NT_float;
10623 else
10624 return FAIL;
10626 return SUCCESS;
10629 /* Modify a bitmask of allowed types. This is only needed for type
10630 relaxation. */
10632 static unsigned
10633 modify_types_allowed (unsigned allowed, unsigned mods)
10635 unsigned size;
10636 enum neon_el_type type;
10637 unsigned destmask;
10638 int i;
10640 destmask = 0;
10642 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10644 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10646 neon_modify_type_size (mods, &type, &size);
10647 destmask |= type_chk_of_el_type (type, size);
10651 return destmask;
10654 /* Check type and return type classification.
10655 The manual states (paraphrase): If one datatype is given, it indicates the
10656 type given in:
10657 - the second operand, if there is one
10658 - the operand, if there is no second operand
10659 - the result, if there are no operands.
10660 This isn't quite good enough though, so we use a concept of a "key" datatype
10661 which is set on a per-instruction basis, which is the one which matters when
10662 only one data type is written.
10663 Note: this function has side-effects (e.g. filling in missing operands). All
10664 Neon instructions should call it before performing bit encoding. */
10666 static struct neon_type_el
10667 neon_check_type (unsigned els, enum neon_shape ns, ...)
10669 va_list ap;
10670 unsigned i, pass, key_el = 0;
10671 unsigned types[NEON_MAX_TYPE_ELS];
10672 enum neon_el_type k_type = NT_invtype;
10673 unsigned k_size = -1u;
10674 struct neon_type_el badtype = {NT_invtype, -1};
10675 unsigned key_allowed = 0;
10677 /* Optional registers in Neon instructions are always (not) in operand 1.
10678 Fill in the missing operand here, if it was omitted. */
10679 if (els > 1 && !inst.operands[1].present)
10680 inst.operands[1] = inst.operands[0];
10682 /* Suck up all the varargs. */
10683 va_start (ap, ns);
10684 for (i = 0; i < els; i++)
10686 unsigned thisarg = va_arg (ap, unsigned);
10687 if (thisarg == N_IGNORE_TYPE)
10689 va_end (ap);
10690 return badtype;
10692 types[i] = thisarg;
10693 if ((thisarg & N_KEY) != 0)
10694 key_el = i;
10696 va_end (ap);
10698 if (inst.vectype.elems > 0)
10699 for (i = 0; i < els; i++)
10700 if (inst.operands[i].vectype.type != NT_invtype)
10702 first_error (_("types specified in both the mnemonic and operands"));
10703 return badtype;
10706 /* Duplicate inst.vectype elements here as necessary.
10707 FIXME: No idea if this is exactly the same as the ARM assembler,
10708 particularly when an insn takes one register and one non-register
10709 operand. */
10710 if (inst.vectype.elems == 1 && els > 1)
10712 unsigned j;
10713 inst.vectype.elems = els;
10714 inst.vectype.el[key_el] = inst.vectype.el[0];
10715 for (j = 0; j < els; j++)
10716 if (j != key_el)
10717 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
10718 types[j]);
10720 else if (inst.vectype.elems == 0 && els > 0)
10722 unsigned j;
10723 /* No types were given after the mnemonic, so look for types specified
10724 after each operand. We allow some flexibility here; as long as the
10725 "key" operand has a type, we can infer the others. */
10726 for (j = 0; j < els; j++)
10727 if (inst.operands[j].vectype.type != NT_invtype)
10728 inst.vectype.el[j] = inst.operands[j].vectype;
10730 if (inst.operands[key_el].vectype.type != NT_invtype)
10732 for (j = 0; j < els; j++)
10733 if (inst.operands[j].vectype.type == NT_invtype)
10734 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
10735 types[j]);
10737 else
10739 first_error (_("operand types can't be inferred"));
10740 return badtype;
10743 else if (inst.vectype.elems != els)
10745 first_error (_("type specifier has the wrong number of parts"));
10746 return badtype;
10749 for (pass = 0; pass < 2; pass++)
10751 for (i = 0; i < els; i++)
10753 unsigned thisarg = types[i];
10754 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
10755 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
10756 enum neon_el_type g_type = inst.vectype.el[i].type;
10757 unsigned g_size = inst.vectype.el[i].size;
10759 /* Decay more-specific signed & unsigned types to sign-insensitive
10760 integer types if sign-specific variants are unavailable. */
10761 if ((g_type == NT_signed || g_type == NT_unsigned)
10762 && (types_allowed & N_SU_ALL) == 0)
10763 g_type = NT_integer;
10765 /* If only untyped args are allowed, decay any more specific types to
10766 them. Some instructions only care about signs for some element
10767 sizes, so handle that properly. */
10768 if ((g_size == 8 && (types_allowed & N_8) != 0)
10769 || (g_size == 16 && (types_allowed & N_16) != 0)
10770 || (g_size == 32 && (types_allowed & N_32) != 0)
10771 || (g_size == 64 && (types_allowed & N_64) != 0))
10772 g_type = NT_untyped;
10774 if (pass == 0)
10776 if ((thisarg & N_KEY) != 0)
10778 k_type = g_type;
10779 k_size = g_size;
10780 key_allowed = thisarg & ~N_KEY;
10783 else
10785 if ((thisarg & N_VFP) != 0)
10787 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
10788 unsigned regwidth = neon_shape_el_size[regshape], match;
10790 /* In VFP mode, operands must match register widths. If we
10791 have a key operand, use its width, else use the width of
10792 the current operand. */
10793 if (k_size != -1u)
10794 match = k_size;
10795 else
10796 match = g_size;
10798 if (regwidth != match)
10800 first_error (_("operand size must match register width"));
10801 return badtype;
10805 if ((thisarg & N_EQK) == 0)
10807 unsigned given_type = type_chk_of_el_type (g_type, g_size);
10809 if ((given_type & types_allowed) == 0)
10811 first_error (_("bad type in Neon instruction"));
10812 return badtype;
10815 else
10817 enum neon_el_type mod_k_type = k_type;
10818 unsigned mod_k_size = k_size;
10819 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
10820 if (g_type != mod_k_type || g_size != mod_k_size)
10822 first_error (_("inconsistent types in Neon instruction"));
10823 return badtype;
10830 return inst.vectype.el[key_el];
10833 /* Neon-style VFP instruction forwarding. */
10835 /* Thumb VFP instructions have 0xE in the condition field. */
10837 static void
10838 do_vfp_cond_or_thumb (void)
10840 if (thumb_mode)
10841 inst.instruction |= 0xe0000000;
10842 else
10843 inst.instruction |= inst.cond << 28;
10846 /* Look up and encode a simple mnemonic, for use as a helper function for the
10847 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
10848 etc. It is assumed that operand parsing has already been done, and that the
10849 operands are in the form expected by the given opcode (this isn't necessarily
10850 the same as the form in which they were parsed, hence some massaging must
10851 take place before this function is called).
10852 Checks current arch version against that in the looked-up opcode. */
10854 static void
10855 do_vfp_nsyn_opcode (const char *opname)
10857 const struct asm_opcode *opcode;
10859 opcode = hash_find (arm_ops_hsh, opname);
10861 if (!opcode)
10862 abort ();
10864 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
10865 thumb_mode ? *opcode->tvariant : *opcode->avariant),
10866 _(BAD_FPU));
10868 if (thumb_mode)
10870 inst.instruction = opcode->tvalue;
10871 opcode->tencode ();
10873 else
10875 inst.instruction = (inst.cond << 28) | opcode->avalue;
10876 opcode->aencode ();
10880 static void
10881 do_vfp_nsyn_add_sub (enum neon_shape rs)
10883 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
10885 if (rs == NS_FFF)
10887 if (is_add)
10888 do_vfp_nsyn_opcode ("fadds");
10889 else
10890 do_vfp_nsyn_opcode ("fsubs");
10892 else
10894 if (is_add)
10895 do_vfp_nsyn_opcode ("faddd");
10896 else
10897 do_vfp_nsyn_opcode ("fsubd");
10901 /* Check operand types to see if this is a VFP instruction, and if so call
10902 PFN (). */
10904 static int
10905 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
10907 enum neon_shape rs;
10908 struct neon_type_el et;
10910 switch (args)
10912 case 2:
10913 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
10914 et = neon_check_type (2, rs,
10915 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
10916 break;
10918 case 3:
10919 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
10920 et = neon_check_type (3, rs,
10921 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
10922 break;
10924 default:
10925 abort ();
10928 if (et.type != NT_invtype)
10930 pfn (rs);
10931 return SUCCESS;
10933 else
10934 inst.error = NULL;
10936 return FAIL;
10939 static void
10940 do_vfp_nsyn_mla_mls (enum neon_shape rs)
10942 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
10944 if (rs == NS_FFF)
10946 if (is_mla)
10947 do_vfp_nsyn_opcode ("fmacs");
10948 else
10949 do_vfp_nsyn_opcode ("fmscs");
10951 else
10953 if (is_mla)
10954 do_vfp_nsyn_opcode ("fmacd");
10955 else
10956 do_vfp_nsyn_opcode ("fmscd");
10960 static void
10961 do_vfp_nsyn_mul (enum neon_shape rs)
10963 if (rs == NS_FFF)
10964 do_vfp_nsyn_opcode ("fmuls");
10965 else
10966 do_vfp_nsyn_opcode ("fmuld");
10969 static void
10970 do_vfp_nsyn_abs_neg (enum neon_shape rs)
10972 int is_neg = (inst.instruction & 0x80) != 0;
10973 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
10975 if (rs == NS_FF)
10977 if (is_neg)
10978 do_vfp_nsyn_opcode ("fnegs");
10979 else
10980 do_vfp_nsyn_opcode ("fabss");
10982 else
10984 if (is_neg)
10985 do_vfp_nsyn_opcode ("fnegd");
10986 else
10987 do_vfp_nsyn_opcode ("fabsd");
10991 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
10992 insns belong to Neon, and are handled elsewhere. */
10994 static void
10995 do_vfp_nsyn_ldm_stm (int is_dbmode)
10997 int is_ldm = (inst.instruction & (1 << 20)) != 0;
10998 if (is_ldm)
11000 if (is_dbmode)
11001 do_vfp_nsyn_opcode ("fldmdbs");
11002 else
11003 do_vfp_nsyn_opcode ("fldmias");
11005 else
11007 if (is_dbmode)
11008 do_vfp_nsyn_opcode ("fstmdbs");
11009 else
11010 do_vfp_nsyn_opcode ("fstmias");
11014 static void
11015 do_vfp_nsyn_sqrt (void)
11017 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11018 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11020 if (rs == NS_FF)
11021 do_vfp_nsyn_opcode ("fsqrts");
11022 else
11023 do_vfp_nsyn_opcode ("fsqrtd");
11026 static void
11027 do_vfp_nsyn_div (void)
11029 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11030 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11031 N_F32 | N_F64 | N_KEY | N_VFP);
11033 if (rs == NS_FFF)
11034 do_vfp_nsyn_opcode ("fdivs");
11035 else
11036 do_vfp_nsyn_opcode ("fdivd");
11039 static void
11040 do_vfp_nsyn_nmul (void)
11042 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11043 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11044 N_F32 | N_F64 | N_KEY | N_VFP);
11046 if (rs == NS_FFF)
11048 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11049 do_vfp_sp_dyadic ();
11051 else
11053 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11054 do_vfp_dp_rd_rn_rm ();
11056 do_vfp_cond_or_thumb ();
11059 static void
11060 do_vfp_nsyn_cmp (void)
11062 if (inst.operands[1].isreg)
11064 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11065 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11067 if (rs == NS_FF)
11069 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11070 do_vfp_sp_monadic ();
11072 else
11074 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11075 do_vfp_dp_rd_rm ();
11078 else
11080 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11081 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11083 switch (inst.instruction & 0x0fffffff)
11085 case N_MNEM_vcmp:
11086 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11087 break;
11088 case N_MNEM_vcmpe:
11089 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11090 break;
11091 default:
11092 abort ();
11095 if (rs == NS_FI)
11097 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11098 do_vfp_sp_compare_z ();
11100 else
11102 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11103 do_vfp_dp_rd ();
11106 do_vfp_cond_or_thumb ();
11109 static void
11110 nsyn_insert_sp (void)
11112 inst.operands[1] = inst.operands[0];
11113 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11114 inst.operands[0].reg = 13;
11115 inst.operands[0].isreg = 1;
11116 inst.operands[0].writeback = 1;
11117 inst.operands[0].present = 1;
11120 static void
11121 do_vfp_nsyn_push (void)
11123 nsyn_insert_sp ();
11124 if (inst.operands[1].issingle)
11125 do_vfp_nsyn_opcode ("fstmdbs");
11126 else
11127 do_vfp_nsyn_opcode ("fstmdbd");
11130 static void
11131 do_vfp_nsyn_pop (void)
11133 nsyn_insert_sp ();
11134 if (inst.operands[1].issingle)
11135 do_vfp_nsyn_opcode ("fldmdbs");
11136 else
11137 do_vfp_nsyn_opcode ("fldmdbd");
11140 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11141 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11143 static unsigned
11144 neon_dp_fixup (unsigned i)
11146 if (thumb_mode)
11148 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11149 if (i & (1 << 24))
11150 i |= 1 << 28;
11152 i &= ~(1 << 24);
11154 i |= 0xef000000;
11156 else
11157 i |= 0xf2000000;
11159 return i;
11162 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11163 (0, 1, 2, 3). */
11165 static unsigned
11166 neon_logbits (unsigned x)
11168 return ffs (x) - 4;
11171 #define LOW4(R) ((R) & 0xf)
11172 #define HI1(R) (((R) >> 4) & 1)
11174 /* Encode insns with bit pattern:
11176 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11177 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11179 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11180 different meaning for some instruction. */
11182 static void
11183 neon_three_same (int isquad, int ubit, int size)
11185 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11186 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11187 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11188 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11189 inst.instruction |= LOW4 (inst.operands[2].reg);
11190 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11191 inst.instruction |= (isquad != 0) << 6;
11192 inst.instruction |= (ubit != 0) << 24;
11193 if (size != -1)
11194 inst.instruction |= neon_logbits (size) << 20;
11196 inst.instruction = neon_dp_fixup (inst.instruction);
11199 /* Encode instructions of the form:
11201 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11202 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
11204 Don't write size if SIZE == -1. */
11206 static void
11207 neon_two_same (int qbit, int ubit, int size)
11209 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11210 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11211 inst.instruction |= LOW4 (inst.operands[1].reg);
11212 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11213 inst.instruction |= (qbit != 0) << 6;
11214 inst.instruction |= (ubit != 0) << 24;
11216 if (size != -1)
11217 inst.instruction |= neon_logbits (size) << 18;
11219 inst.instruction = neon_dp_fixup (inst.instruction);
11222 /* Neon instruction encoders, in approximate order of appearance. */
11224 static void
11225 do_neon_dyadic_i_su (void)
11227 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11228 struct neon_type_el et = neon_check_type (3, rs,
11229 N_EQK, N_EQK, N_SU_32 | N_KEY);
11230 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11233 static void
11234 do_neon_dyadic_i64_su (void)
11236 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11237 struct neon_type_el et = neon_check_type (3, rs,
11238 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11239 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11242 static void
11243 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11244 unsigned immbits)
11246 unsigned size = et.size >> 3;
11247 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11248 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11249 inst.instruction |= LOW4 (inst.operands[1].reg);
11250 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11251 inst.instruction |= (isquad != 0) << 6;
11252 inst.instruction |= immbits << 16;
11253 inst.instruction |= (size >> 3) << 7;
11254 inst.instruction |= (size & 0x7) << 19;
11255 if (write_ubit)
11256 inst.instruction |= (uval != 0) << 24;
11258 inst.instruction = neon_dp_fixup (inst.instruction);
11261 static void
11262 do_neon_shl_imm (void)
11264 if (!inst.operands[2].isreg)
11266 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11267 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11268 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11269 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
11271 else
11273 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11274 struct neon_type_el et = neon_check_type (3, rs,
11275 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11276 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11277 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11281 static void
11282 do_neon_qshl_imm (void)
11284 if (!inst.operands[2].isreg)
11286 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11287 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
11288 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11289 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
11290 inst.operands[2].imm);
11292 else
11294 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11295 struct neon_type_el et = neon_check_type (3, rs,
11296 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11297 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11298 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11302 static int
11303 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11305 /* Handle .I8 and .I64 as pseudo-instructions. */
11306 switch (size)
11308 case 8:
11309 /* Unfortunately, this will make everything apart from zero out-of-range.
11310 FIXME is this the intended semantics? There doesn't seem much point in
11311 accepting .I8 if so. */
11312 immediate |= immediate << 8;
11313 size = 16;
11314 break;
11315 case 64:
11316 /* Similarly, anything other than zero will be replicated in bits [63:32],
11317 which probably isn't want we want if we specified .I64. */
11318 if (immediate != 0)
11319 goto bad_immediate;
11320 size = 32;
11321 break;
11322 default: ;
11325 if (immediate == (immediate & 0x000000ff))
11327 *immbits = immediate;
11328 return (size == 16) ? 0x9 : 0x1;
11330 else if (immediate == (immediate & 0x0000ff00))
11332 *immbits = immediate >> 8;
11333 return (size == 16) ? 0xb : 0x3;
11335 else if (immediate == (immediate & 0x00ff0000))
11337 *immbits = immediate >> 16;
11338 return 0x5;
11340 else if (immediate == (immediate & 0xff000000))
11342 *immbits = immediate >> 24;
11343 return 0x7;
11346 bad_immediate:
11347 first_error (_("immediate value out of range"));
11348 return FAIL;
11351 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11352 A, B, C, D. */
11354 static int
11355 neon_bits_same_in_bytes (unsigned imm)
11357 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11358 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11359 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11360 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11363 /* For immediate of above form, return 0bABCD. */
11365 static unsigned
11366 neon_squash_bits (unsigned imm)
11368 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11369 | ((imm & 0x01000000) >> 21);
11372 /* Compress quarter-float representation to 0b...000 abcdefgh. */
11374 static unsigned
11375 neon_qfloat_bits (unsigned imm)
11377 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
11380 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11381 the instruction. *OP is passed as the initial value of the op field, and
11382 may be set to a different value depending on the constant (i.e.
11383 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
11384 MVN). */
11386 static int
11387 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, unsigned *immbits,
11388 int *op, int size, enum neon_el_type type)
11390 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11392 if (size != 32 || *op == 1)
11393 return FAIL;
11394 *immbits = neon_qfloat_bits (immlo);
11395 return 0xf;
11397 else if (size == 64 && neon_bits_same_in_bytes (immhi)
11398 && neon_bits_same_in_bytes (immlo))
11400 /* Check this one first so we don't have to bother with immhi in later
11401 tests. */
11402 if (*op == 1)
11403 return FAIL;
11404 *immbits = (neon_squash_bits (immhi) << 4) | neon_squash_bits (immlo);
11405 *op = 1;
11406 return 0xe;
11408 else if (immhi != 0)
11409 return FAIL;
11410 else if (immlo == (immlo & 0x000000ff))
11412 /* 64-bit case was already handled. Don't allow MVN with 8-bit
11413 immediate. */
11414 if ((size != 8 && size != 16 && size != 32)
11415 || (size == 8 && *op == 1))
11416 return FAIL;
11417 *immbits = immlo;
11418 return (size == 8) ? 0xe : (size == 16) ? 0x8 : 0x0;
11420 else if (immlo == (immlo & 0x0000ff00))
11422 if (size != 16 && size != 32)
11423 return FAIL;
11424 *immbits = immlo >> 8;
11425 return (size == 16) ? 0xa : 0x2;
11427 else if (immlo == (immlo & 0x00ff0000))
11429 if (size != 32)
11430 return FAIL;
11431 *immbits = immlo >> 16;
11432 return 0x4;
11434 else if (immlo == (immlo & 0xff000000))
11436 if (size != 32)
11437 return FAIL;
11438 *immbits = immlo >> 24;
11439 return 0x6;
11441 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11443 if (size != 32)
11444 return FAIL;
11445 *immbits = (immlo >> 8) & 0xff;
11446 return 0xc;
11448 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11450 if (size != 32)
11451 return FAIL;
11452 *immbits = (immlo >> 16) & 0xff;
11453 return 0xd;
11456 return FAIL;
11459 /* Write immediate bits [7:0] to the following locations:
11461 |28/24|23 19|18 16|15 4|3 0|
11462 | 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|
11464 This function is used by VMOV/VMVN/VORR/VBIC. */
11466 static void
11467 neon_write_immbits (unsigned immbits)
11469 inst.instruction |= immbits & 0xf;
11470 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11471 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11474 /* Invert low-order SIZE bits of XHI:XLO. */
11476 static void
11477 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11479 unsigned immlo = xlo ? *xlo : 0;
11480 unsigned immhi = xhi ? *xhi : 0;
11482 switch (size)
11484 case 8:
11485 immlo = (~immlo) & 0xff;
11486 break;
11488 case 16:
11489 immlo = (~immlo) & 0xffff;
11490 break;
11492 case 64:
11493 immhi = (~immhi) & 0xffffffff;
11494 /* fall through. */
11496 case 32:
11497 immlo = (~immlo) & 0xffffffff;
11498 break;
11500 default:
11501 abort ();
11504 if (xlo)
11505 *xlo = immlo;
11507 if (xhi)
11508 *xhi = immhi;
11511 static void
11512 do_neon_logic (void)
11514 if (inst.operands[2].present && inst.operands[2].isreg)
11516 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11517 neon_check_type (3, rs, N_IGNORE_TYPE);
11518 /* U bit and size field were set as part of the bitmask. */
11519 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11520 neon_three_same (neon_quad (rs), 0, -1);
11522 else
11524 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11525 struct neon_type_el et = neon_check_type (2, rs,
11526 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
11527 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11528 unsigned immbits;
11529 int cmode;
11531 if (et.type == NT_invtype)
11532 return;
11534 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11536 switch (opcode)
11538 case N_MNEM_vbic:
11539 cmode = neon_cmode_for_logic_imm (inst.operands[1].imm, &immbits,
11540 et.size);
11541 break;
11543 case N_MNEM_vorr:
11544 cmode = neon_cmode_for_logic_imm (inst.operands[1].imm, &immbits,
11545 et.size);
11546 break;
11548 case N_MNEM_vand:
11549 /* Pseudo-instruction for VBIC. */
11550 immbits = inst.operands[1].imm;
11551 neon_invert_size (&immbits, 0, et.size);
11552 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11553 break;
11555 case N_MNEM_vorn:
11556 /* Pseudo-instruction for VORR. */
11557 immbits = inst.operands[1].imm;
11558 neon_invert_size (&immbits, 0, et.size);
11559 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11560 break;
11562 default:
11563 abort ();
11566 if (cmode == FAIL)
11567 return;
11569 inst.instruction |= neon_quad (rs) << 6;
11570 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11571 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11572 inst.instruction |= cmode << 8;
11573 neon_write_immbits (immbits);
11575 inst.instruction = neon_dp_fixup (inst.instruction);
11579 static void
11580 do_neon_bitfield (void)
11582 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11583 neon_check_type (3, rs, N_IGNORE_TYPE);
11584 neon_three_same (neon_quad (rs), 0, -1);
11587 static void
11588 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
11589 unsigned destbits)
11591 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11592 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
11593 types | N_KEY);
11594 if (et.type == NT_float)
11596 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
11597 neon_three_same (neon_quad (rs), 0, -1);
11599 else
11601 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11602 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
11606 static void
11607 do_neon_dyadic_if_su (void)
11609 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
11612 static void
11613 do_neon_dyadic_if_su_d (void)
11615 /* This version only allow D registers, but that constraint is enforced during
11616 operand parsing so we don't need to do anything extra here. */
11617 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
11620 static void
11621 do_neon_dyadic_if_i_d (void)
11623 /* The "untyped" case can't happen. Do this to stop the "U" bit being
11624 affected if we specify unsigned args. */
11625 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
11628 enum vfp_or_neon_is_neon_bits
11630 NEON_CHECK_CC = 1,
11631 NEON_CHECK_ARCH = 2
11634 /* Call this function if an instruction which may have belonged to the VFP or
11635 Neon instruction sets, but turned out to be a Neon instruction (due to the
11636 operand types involved, etc.). We have to check and/or fix-up a couple of
11637 things:
11639 - Make sure the user hasn't attempted to make a Neon instruction
11640 conditional.
11641 - Alter the value in the condition code field if necessary.
11642 - Make sure that the arch supports Neon instructions.
11644 Which of these operations take place depends on bits from enum
11645 vfp_or_neon_is_neon_bits.
11647 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
11648 current instruction's condition is COND_ALWAYS, the condition field is
11649 changed to inst.uncond_value. This is necessary because instructions shared
11650 between VFP and Neon may be conditional for the VFP variants only, and the
11651 unconditional Neon version must have, e.g., 0xF in the condition field. */
11653 static int
11654 vfp_or_neon_is_neon (unsigned check)
11656 /* Conditions are always legal in Thumb mode (IT blocks). */
11657 if (!thumb_mode && (check & NEON_CHECK_CC))
11659 if (inst.cond != COND_ALWAYS)
11661 first_error (_(BAD_COND));
11662 return FAIL;
11664 if (inst.uncond_value != -1)
11665 inst.instruction |= inst.uncond_value << 28;
11668 if ((check & NEON_CHECK_ARCH)
11669 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
11671 first_error (_(BAD_FPU));
11672 return FAIL;
11675 return SUCCESS;
11678 static void
11679 do_neon_addsub_if_i (void)
11681 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
11682 return;
11684 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11685 return;
11687 /* The "untyped" case can't happen. Do this to stop the "U" bit being
11688 affected if we specify unsigned args. */
11689 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
11692 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
11693 result to be:
11694 V<op> A,B (A is operand 0, B is operand 2)
11695 to mean:
11696 V<op> A,B,A
11697 not:
11698 V<op> A,B,B
11699 so handle that case specially. */
11701 static void
11702 neon_exchange_operands (void)
11704 void *scratch = alloca (sizeof (inst.operands[0]));
11705 if (inst.operands[1].present)
11707 /* Swap operands[1] and operands[2]. */
11708 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
11709 inst.operands[1] = inst.operands[2];
11710 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
11712 else
11714 inst.operands[1] = inst.operands[2];
11715 inst.operands[2] = inst.operands[0];
11719 static void
11720 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
11722 if (inst.operands[2].isreg)
11724 if (invert)
11725 neon_exchange_operands ();
11726 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
11728 else
11730 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11731 struct neon_type_el et = neon_check_type (2, rs,
11732 N_EQK | N_SIZ, immtypes | N_KEY);
11734 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11735 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11736 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11737 inst.instruction |= LOW4 (inst.operands[1].reg);
11738 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11739 inst.instruction |= neon_quad (rs) << 6;
11740 inst.instruction |= (et.type == NT_float) << 10;
11741 inst.instruction |= neon_logbits (et.size) << 18;
11743 inst.instruction = neon_dp_fixup (inst.instruction);
11747 static void
11748 do_neon_cmp (void)
11750 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
11753 static void
11754 do_neon_cmp_inv (void)
11756 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
11759 static void
11760 do_neon_ceq (void)
11762 neon_compare (N_IF_32, N_IF_32, FALSE);
11765 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
11766 scalars, which are encoded in 5 bits, M : Rm.
11767 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
11768 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
11769 index in M. */
11771 static unsigned
11772 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
11774 unsigned regno = NEON_SCALAR_REG (scalar);
11775 unsigned elno = NEON_SCALAR_INDEX (scalar);
11777 switch (elsize)
11779 case 16:
11780 if (regno > 7 || elno > 3)
11781 goto bad_scalar;
11782 return regno | (elno << 3);
11784 case 32:
11785 if (regno > 15 || elno > 1)
11786 goto bad_scalar;
11787 return regno | (elno << 4);
11789 default:
11790 bad_scalar:
11791 first_error (_("scalar out of range for multiply instruction"));
11794 return 0;
11797 /* Encode multiply / multiply-accumulate scalar instructions. */
11799 static void
11800 neon_mul_mac (struct neon_type_el et, int ubit)
11802 unsigned scalar;
11804 /* Give a more helpful error message if we have an invalid type. */
11805 if (et.type == NT_invtype)
11806 return;
11808 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
11809 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11810 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11811 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11812 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11813 inst.instruction |= LOW4 (scalar);
11814 inst.instruction |= HI1 (scalar) << 5;
11815 inst.instruction |= (et.type == NT_float) << 8;
11816 inst.instruction |= neon_logbits (et.size) << 20;
11817 inst.instruction |= (ubit != 0) << 24;
11819 inst.instruction = neon_dp_fixup (inst.instruction);
11822 static void
11823 do_neon_mac_maybe_scalar (void)
11825 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
11826 return;
11828 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11829 return;
11831 if (inst.operands[2].isscalar)
11833 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
11834 struct neon_type_el et = neon_check_type (3, rs,
11835 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
11836 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
11837 neon_mul_mac (et, neon_quad (rs));
11839 else
11841 /* The "untyped" case can't happen. Do this to stop the "U" bit being
11842 affected if we specify unsigned args. */
11843 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
11847 static void
11848 do_neon_tst (void)
11850 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11851 struct neon_type_el et = neon_check_type (3, rs,
11852 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
11853 neon_three_same (neon_quad (rs), 0, et.size);
11856 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
11857 same types as the MAC equivalents. The polynomial type for this instruction
11858 is encoded the same as the integer type. */
11860 static void
11861 do_neon_mul (void)
11863 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
11864 return;
11866 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11867 return;
11869 if (inst.operands[2].isscalar)
11870 do_neon_mac_maybe_scalar ();
11871 else
11872 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
11875 static void
11876 do_neon_qdmulh (void)
11878 if (inst.operands[2].isscalar)
11880 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
11881 struct neon_type_el et = neon_check_type (3, rs,
11882 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
11883 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
11884 neon_mul_mac (et, neon_quad (rs));
11886 else
11888 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11889 struct neon_type_el et = neon_check_type (3, rs,
11890 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
11891 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11892 /* The U bit (rounding) comes from bit mask. */
11893 neon_three_same (neon_quad (rs), 0, et.size);
11897 static void
11898 do_neon_fcmp_absolute (void)
11900 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11901 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
11902 /* Size field comes from bit mask. */
11903 neon_three_same (neon_quad (rs), 1, -1);
11906 static void
11907 do_neon_fcmp_absolute_inv (void)
11909 neon_exchange_operands ();
11910 do_neon_fcmp_absolute ();
11913 static void
11914 do_neon_step (void)
11916 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11917 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
11918 neon_three_same (neon_quad (rs), 0, -1);
11921 static void
11922 do_neon_abs_neg (void)
11924 enum neon_shape rs;
11925 struct neon_type_el et;
11927 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
11928 return;
11930 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11931 return;
11933 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
11934 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
11936 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11937 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11938 inst.instruction |= LOW4 (inst.operands[1].reg);
11939 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11940 inst.instruction |= neon_quad (rs) << 6;
11941 inst.instruction |= (et.type == NT_float) << 10;
11942 inst.instruction |= neon_logbits (et.size) << 18;
11944 inst.instruction = neon_dp_fixup (inst.instruction);
11947 static void
11948 do_neon_sli (void)
11950 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11951 struct neon_type_el et = neon_check_type (2, rs,
11952 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
11953 int imm = inst.operands[2].imm;
11954 constraint (imm < 0 || (unsigned)imm >= et.size,
11955 _("immediate out of range for insert"));
11956 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
11959 static void
11960 do_neon_sri (void)
11962 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11963 struct neon_type_el et = neon_check_type (2, rs,
11964 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
11965 int imm = inst.operands[2].imm;
11966 constraint (imm < 1 || (unsigned)imm > et.size,
11967 _("immediate out of range for insert"));
11968 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
11971 static void
11972 do_neon_qshlu_imm (void)
11974 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11975 struct neon_type_el et = neon_check_type (2, rs,
11976 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
11977 int imm = inst.operands[2].imm;
11978 constraint (imm < 0 || (unsigned)imm >= et.size,
11979 _("immediate out of range for shift"));
11980 /* Only encodes the 'U present' variant of the instruction.
11981 In this case, signed types have OP (bit 8) set to 0.
11982 Unsigned types have OP set to 1. */
11983 inst.instruction |= (et.type == NT_unsigned) << 8;
11984 /* The rest of the bits are the same as other immediate shifts. */
11985 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
11988 static void
11989 do_neon_qmovn (void)
11991 struct neon_type_el et = neon_check_type (2, NS_DQ,
11992 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
11993 /* Saturating move where operands can be signed or unsigned, and the
11994 destination has the same signedness. */
11995 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11996 if (et.type == NT_unsigned)
11997 inst.instruction |= 0xc0;
11998 else
11999 inst.instruction |= 0x80;
12000 neon_two_same (0, 1, et.size / 2);
12003 static void
12004 do_neon_qmovun (void)
12006 struct neon_type_el et = neon_check_type (2, NS_DQ,
12007 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12008 /* Saturating move with unsigned results. Operands must be signed. */
12009 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12010 neon_two_same (0, 1, et.size / 2);
12013 static void
12014 do_neon_rshift_sat_narrow (void)
12016 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12017 or unsigned. If operands are unsigned, results must also be unsigned. */
12018 struct neon_type_el et = neon_check_type (2, NS_DQI,
12019 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12020 int imm = inst.operands[2].imm;
12021 /* This gets the bounds check, size encoding and immediate bits calculation
12022 right. */
12023 et.size /= 2;
12025 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12026 VQMOVN.I<size> <Dd>, <Qm>. */
12027 if (imm == 0)
12029 inst.operands[2].present = 0;
12030 inst.instruction = N_MNEM_vqmovn;
12031 do_neon_qmovn ();
12032 return;
12035 constraint (imm < 1 || (unsigned)imm > et.size,
12036 _("immediate out of range"));
12037 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12040 static void
12041 do_neon_rshift_sat_narrow_u (void)
12043 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12044 or unsigned. If operands are unsigned, results must also be unsigned. */
12045 struct neon_type_el et = neon_check_type (2, NS_DQI,
12046 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12047 int imm = inst.operands[2].imm;
12048 /* This gets the bounds check, size encoding and immediate bits calculation
12049 right. */
12050 et.size /= 2;
12052 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12053 VQMOVUN.I<size> <Dd>, <Qm>. */
12054 if (imm == 0)
12056 inst.operands[2].present = 0;
12057 inst.instruction = N_MNEM_vqmovun;
12058 do_neon_qmovun ();
12059 return;
12062 constraint (imm < 1 || (unsigned)imm > et.size,
12063 _("immediate out of range"));
12064 /* FIXME: The manual is kind of unclear about what value U should have in
12065 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12066 must be 1. */
12067 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12070 static void
12071 do_neon_movn (void)
12073 struct neon_type_el et = neon_check_type (2, NS_DQ,
12074 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12075 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12076 neon_two_same (0, 1, et.size / 2);
12079 static void
12080 do_neon_rshift_narrow (void)
12082 struct neon_type_el et = neon_check_type (2, NS_DQI,
12083 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12084 int imm = inst.operands[2].imm;
12085 /* This gets the bounds check, size encoding and immediate bits calculation
12086 right. */
12087 et.size /= 2;
12089 /* If immediate is zero then we are a pseudo-instruction for
12090 VMOVN.I<size> <Dd>, <Qm> */
12091 if (imm == 0)
12093 inst.operands[2].present = 0;
12094 inst.instruction = N_MNEM_vmovn;
12095 do_neon_movn ();
12096 return;
12099 constraint (imm < 1 || (unsigned)imm > et.size,
12100 _("immediate out of range for narrowing operation"));
12101 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12104 static void
12105 do_neon_shll (void)
12107 /* FIXME: Type checking when lengthening. */
12108 struct neon_type_el et = neon_check_type (2, NS_QDI,
12109 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12110 unsigned imm = inst.operands[2].imm;
12112 if (imm == et.size)
12114 /* Maximum shift variant. */
12115 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12116 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12117 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12118 inst.instruction |= LOW4 (inst.operands[1].reg);
12119 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12120 inst.instruction |= neon_logbits (et.size) << 18;
12122 inst.instruction = neon_dp_fixup (inst.instruction);
12124 else
12126 /* A more-specific type check for non-max versions. */
12127 et = neon_check_type (2, NS_QDI,
12128 N_EQK | N_DBL, N_SU_32 | N_KEY);
12129 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12130 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12134 /* Check the various types for the VCVT instruction, and return which version
12135 the current instruction is. */
12137 static int
12138 neon_cvt_flavour (enum neon_shape rs)
12140 #define CVT_VAR(C,X,Y) \
12141 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12142 if (et.type != NT_invtype) \
12144 inst.error = NULL; \
12145 return (C); \
12147 struct neon_type_el et;
12148 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12149 || rs == NS_FF) ? N_VFP : 0;
12150 /* The instruction versions which take an immediate take one register
12151 argument, which is extended to the width of the full register. Thus the
12152 "source" and "destination" registers must have the same width. Hack that
12153 here by making the size equal to the key (wider, in this case) operand. */
12154 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
12156 CVT_VAR (0, N_S32, N_F32);
12157 CVT_VAR (1, N_U32, N_F32);
12158 CVT_VAR (2, N_F32, N_S32);
12159 CVT_VAR (3, N_F32, N_U32);
12161 whole_reg = N_VFP;
12163 /* VFP instructions. */
12164 CVT_VAR (4, N_F32, N_F64);
12165 CVT_VAR (5, N_F64, N_F32);
12166 CVT_VAR (6, N_S32, N_F64 | key);
12167 CVT_VAR (7, N_U32, N_F64 | key);
12168 CVT_VAR (8, N_F64 | key, N_S32);
12169 CVT_VAR (9, N_F64 | key, N_U32);
12170 /* VFP instructions with bitshift. */
12171 CVT_VAR (10, N_F32 | key, N_S16);
12172 CVT_VAR (11, N_F32 | key, N_U16);
12173 CVT_VAR (12, N_F64 | key, N_S16);
12174 CVT_VAR (13, N_F64 | key, N_U16);
12175 CVT_VAR (14, N_S16, N_F32 | key);
12176 CVT_VAR (15, N_U16, N_F32 | key);
12177 CVT_VAR (16, N_S16, N_F64 | key);
12178 CVT_VAR (17, N_U16, N_F64 | key);
12180 return -1;
12181 #undef CVT_VAR
12184 /* Neon-syntax VFP conversions. */
12186 static void
12187 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
12189 const char *opname = 0;
12191 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
12193 /* Conversions with immediate bitshift. */
12194 const char *enc[] =
12196 "ftosls",
12197 "ftouls",
12198 "fsltos",
12199 "fultos",
12200 NULL,
12201 NULL,
12202 "ftosld",
12203 "ftould",
12204 "fsltod",
12205 "fultod",
12206 "fshtos",
12207 "fuhtos",
12208 "fshtod",
12209 "fuhtod",
12210 "ftoshs",
12211 "ftouhs",
12212 "ftoshd",
12213 "ftouhd"
12216 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12218 opname = enc[flavour];
12219 constraint (inst.operands[0].reg != inst.operands[1].reg,
12220 _("operands 0 and 1 must be the same register"));
12221 inst.operands[1] = inst.operands[2];
12222 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12225 else
12227 /* Conversions without bitshift. */
12228 const char *enc[] =
12230 "ftosis",
12231 "ftouis",
12232 "fsitos",
12233 "fuitos",
12234 "fcvtsd",
12235 "fcvtds",
12236 "ftosid",
12237 "ftouid",
12238 "fsitod",
12239 "fuitod"
12242 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12243 opname = enc[flavour];
12246 if (opname)
12247 do_vfp_nsyn_opcode (opname);
12250 static void
12251 do_vfp_nsyn_cvtz (void)
12253 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12254 int flavour = neon_cvt_flavour (rs);
12255 const char *enc[] =
12257 "ftosizs",
12258 "ftouizs",
12259 NULL,
12260 NULL,
12261 NULL,
12262 NULL,
12263 "ftosizd",
12264 "ftouizd"
12267 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12268 do_vfp_nsyn_opcode (enc[flavour]);
12271 static void
12272 do_neon_cvt (void)
12274 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12275 NS_FD, NS_DF, NS_FF, NS_NULL);
12276 int flavour = neon_cvt_flavour (rs);
12278 /* VFP rather than Neon conversions. */
12279 if (flavour >= 4)
12281 do_vfp_nsyn_cvt (rs, flavour);
12282 return;
12285 switch (rs)
12287 case NS_DDI:
12288 case NS_QQI:
12290 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12291 return;
12293 /* Fixed-point conversion with #0 immediate is encoded as an
12294 integer conversion. */
12295 if (inst.operands[2].present && inst.operands[2].imm == 0)
12296 goto int_encode;
12297 unsigned immbits = 32 - inst.operands[2].imm;
12298 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12299 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12300 if (flavour != -1)
12301 inst.instruction |= enctab[flavour];
12302 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12303 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12304 inst.instruction |= LOW4 (inst.operands[1].reg);
12305 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12306 inst.instruction |= neon_quad (rs) << 6;
12307 inst.instruction |= 1 << 21;
12308 inst.instruction |= immbits << 16;
12310 inst.instruction = neon_dp_fixup (inst.instruction);
12312 break;
12314 case NS_DD:
12315 case NS_QQ:
12316 int_encode:
12318 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12320 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12322 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12323 return;
12325 if (flavour != -1)
12326 inst.instruction |= enctab[flavour];
12328 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12329 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12330 inst.instruction |= LOW4 (inst.operands[1].reg);
12331 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12332 inst.instruction |= neon_quad (rs) << 6;
12333 inst.instruction |= 2 << 18;
12335 inst.instruction = neon_dp_fixup (inst.instruction);
12337 break;
12339 default:
12340 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12341 do_vfp_nsyn_cvt (rs, flavour);
12345 static void
12346 neon_move_immediate (void)
12348 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12349 struct neon_type_el et = neon_check_type (2, rs,
12350 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12351 unsigned immlo, immhi = 0, immbits;
12352 int op, cmode;
12354 constraint (et.type == NT_invtype,
12355 _("operand size must be specified for immediate VMOV"));
12357 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12358 op = (inst.instruction & (1 << 5)) != 0;
12360 immlo = inst.operands[1].imm;
12361 if (inst.operands[1].regisimm)
12362 immhi = inst.operands[1].reg;
12364 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12365 _("immediate has bits set outside the operand size"));
12367 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op,
12368 et.size, et.type)) == FAIL)
12370 /* Invert relevant bits only. */
12371 neon_invert_size (&immlo, &immhi, et.size);
12372 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12373 with one or the other; those cases are caught by
12374 neon_cmode_for_move_imm. */
12375 op = !op;
12376 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op,
12377 et.size, et.type)) == FAIL)
12379 first_error (_("immediate out of range"));
12380 return;
12384 inst.instruction &= ~(1 << 5);
12385 inst.instruction |= op << 5;
12387 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12388 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12389 inst.instruction |= neon_quad (rs) << 6;
12390 inst.instruction |= cmode << 8;
12392 neon_write_immbits (immbits);
12395 static void
12396 do_neon_mvn (void)
12398 if (inst.operands[1].isreg)
12400 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12402 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12403 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12404 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12405 inst.instruction |= LOW4 (inst.operands[1].reg);
12406 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12407 inst.instruction |= neon_quad (rs) << 6;
12409 else
12411 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12412 neon_move_immediate ();
12415 inst.instruction = neon_dp_fixup (inst.instruction);
12418 /* Encode instructions of form:
12420 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12421 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm |
12425 static void
12426 neon_mixed_length (struct neon_type_el et, unsigned size)
12428 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12429 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12430 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12431 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12432 inst.instruction |= LOW4 (inst.operands[2].reg);
12433 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12434 inst.instruction |= (et.type == NT_unsigned) << 24;
12435 inst.instruction |= neon_logbits (size) << 20;
12437 inst.instruction = neon_dp_fixup (inst.instruction);
12440 static void
12441 do_neon_dyadic_long (void)
12443 /* FIXME: Type checking for lengthening op. */
12444 struct neon_type_el et = neon_check_type (3, NS_QDD,
12445 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12446 neon_mixed_length (et, et.size);
12449 static void
12450 do_neon_abal (void)
12452 struct neon_type_el et = neon_check_type (3, NS_QDD,
12453 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12454 neon_mixed_length (et, et.size);
12457 static void
12458 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12460 if (inst.operands[2].isscalar)
12462 struct neon_type_el et = neon_check_type (3, NS_QDS,
12463 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
12464 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12465 neon_mul_mac (et, et.type == NT_unsigned);
12467 else
12469 struct neon_type_el et = neon_check_type (3, NS_QDD,
12470 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12471 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12472 neon_mixed_length (et, et.size);
12476 static void
12477 do_neon_mac_maybe_scalar_long (void)
12479 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12482 static void
12483 do_neon_dyadic_wide (void)
12485 struct neon_type_el et = neon_check_type (3, NS_QQD,
12486 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12487 neon_mixed_length (et, et.size);
12490 static void
12491 do_neon_dyadic_narrow (void)
12493 struct neon_type_el et = neon_check_type (3, NS_QDD,
12494 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
12495 /* Operand sign is unimportant, and the U bit is part of the opcode,
12496 so force the operand type to integer. */
12497 et.type = NT_integer;
12498 neon_mixed_length (et, et.size / 2);
12501 static void
12502 do_neon_mul_sat_scalar_long (void)
12504 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12507 static void
12508 do_neon_vmull (void)
12510 if (inst.operands[2].isscalar)
12511 do_neon_mac_maybe_scalar_long ();
12512 else
12514 struct neon_type_el et = neon_check_type (3, NS_QDD,
12515 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12516 if (et.type == NT_poly)
12517 inst.instruction = NEON_ENC_POLY (inst.instruction);
12518 else
12519 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12520 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12521 zero. Should be OK as-is. */
12522 neon_mixed_length (et, et.size);
12526 static void
12527 do_neon_ext (void)
12529 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
12530 struct neon_type_el et = neon_check_type (3, rs,
12531 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12532 unsigned imm = (inst.operands[3].imm * et.size) / 8;
12533 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12534 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12535 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12536 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12537 inst.instruction |= LOW4 (inst.operands[2].reg);
12538 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12539 inst.instruction |= neon_quad (rs) << 6;
12540 inst.instruction |= imm << 8;
12542 inst.instruction = neon_dp_fixup (inst.instruction);
12545 static void
12546 do_neon_rev (void)
12548 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12549 struct neon_type_el et = neon_check_type (2, rs,
12550 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12551 unsigned op = (inst.instruction >> 7) & 3;
12552 /* N (width of reversed regions) is encoded as part of the bitmask. We
12553 extract it here to check the elements to be reversed are smaller.
12554 Otherwise we'd get a reserved instruction. */
12555 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12556 assert (elsize != 0);
12557 constraint (et.size >= elsize,
12558 _("elements must be smaller than reversal region"));
12559 neon_two_same (neon_quad (rs), 1, et.size);
12562 static void
12563 do_neon_dup (void)
12565 if (inst.operands[1].isscalar)
12567 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
12568 struct neon_type_el et = neon_check_type (2, rs,
12569 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12570 unsigned sizebits = et.size >> 3;
12571 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
12572 int logsize = neon_logbits (et.size);
12573 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
12575 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
12576 return;
12578 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12579 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12580 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12581 inst.instruction |= LOW4 (dm);
12582 inst.instruction |= HI1 (dm) << 5;
12583 inst.instruction |= neon_quad (rs) << 6;
12584 inst.instruction |= x << 17;
12585 inst.instruction |= sizebits << 16;
12587 inst.instruction = neon_dp_fixup (inst.instruction);
12589 else
12591 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
12592 struct neon_type_el et = neon_check_type (2, rs,
12593 N_8 | N_16 | N_32 | N_KEY, N_EQK);
12594 /* Duplicate ARM register to lanes of vector. */
12595 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
12596 switch (et.size)
12598 case 8: inst.instruction |= 0x400000; break;
12599 case 16: inst.instruction |= 0x000020; break;
12600 case 32: inst.instruction |= 0x000000; break;
12601 default: break;
12603 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
12604 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
12605 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
12606 inst.instruction |= neon_quad (rs) << 21;
12607 /* The encoding for this instruction is identical for the ARM and Thumb
12608 variants, except for the condition field. */
12609 do_vfp_cond_or_thumb ();
12613 /* VMOV has particularly many variations. It can be one of:
12614 0. VMOV<c><q> <Qd>, <Qm>
12615 1. VMOV<c><q> <Dd>, <Dm>
12616 (Register operations, which are VORR with Rm = Rn.)
12617 2. VMOV<c><q>.<dt> <Qd>, #<imm>
12618 3. VMOV<c><q>.<dt> <Dd>, #<imm>
12619 (Immediate loads.)
12620 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
12621 (ARM register to scalar.)
12622 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
12623 (Two ARM registers to vector.)
12624 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
12625 (Scalar to ARM register.)
12626 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
12627 (Vector to two ARM registers.)
12628 8. VMOV.F32 <Sd>, <Sm>
12629 9. VMOV.F64 <Dd>, <Dm>
12630 (VFP register moves.)
12631 10. VMOV.F32 <Sd>, #imm
12632 11. VMOV.F64 <Dd>, #imm
12633 (VFP float immediate load.)
12634 12. VMOV <Rd>, <Sm>
12635 (VFP single to ARM reg.)
12636 13. VMOV <Sd>, <Rm>
12637 (ARM reg to VFP single.)
12638 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
12639 (Two ARM regs to two VFP singles.)
12640 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
12641 (Two VFP singles to two ARM regs.)
12643 These cases can be disambiguated using neon_select_shape, except cases 1/9
12644 and 3/11 which depend on the operand type too.
12646 All the encoded bits are hardcoded by this function.
12648 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
12649 Cases 5, 7 may be used with VFPv2 and above.
12651 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
12652 can specify a type where it doesn't make sense to, and is ignored).
12655 static void
12656 do_neon_mov (void)
12658 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
12659 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
12660 NS_NULL);
12661 struct neon_type_el et;
12662 const char *ldconst = 0;
12664 switch (rs)
12666 case NS_DD: /* case 1/9. */
12667 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
12668 /* It is not an error here if no type is given. */
12669 inst.error = NULL;
12670 if (et.type == NT_float && et.size == 64)
12672 do_vfp_nsyn_opcode ("fcpyd");
12673 break;
12675 /* fall through. */
12677 case NS_QQ: /* case 0/1. */
12679 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12680 return;
12681 /* The architecture manual I have doesn't explicitly state which
12682 value the U bit should have for register->register moves, but
12683 the equivalent VORR instruction has U = 0, so do that. */
12684 inst.instruction = 0x0200110;
12685 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12686 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12687 inst.instruction |= LOW4 (inst.operands[1].reg);
12688 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12689 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12690 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12691 inst.instruction |= neon_quad (rs) << 6;
12693 inst.instruction = neon_dp_fixup (inst.instruction);
12695 break;
12697 case NS_DI: /* case 3/11. */
12698 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
12699 inst.error = NULL;
12700 if (et.type == NT_float && et.size == 64)
12702 /* case 11 (fconstd). */
12703 ldconst = "fconstd";
12704 goto encode_fconstd;
12706 /* fall through. */
12708 case NS_QI: /* case 2/3. */
12709 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12710 return;
12711 inst.instruction = 0x0800010;
12712 neon_move_immediate ();
12713 inst.instruction = neon_dp_fixup (inst.instruction);
12714 break;
12716 case NS_SR: /* case 4. */
12718 unsigned bcdebits = 0;
12719 struct neon_type_el et = neon_check_type (2, NS_NULL,
12720 N_8 | N_16 | N_32 | N_KEY, N_EQK);
12721 int logsize = neon_logbits (et.size);
12722 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
12723 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
12725 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
12726 _(BAD_FPU));
12727 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
12728 && et.size != 32, _(BAD_FPU));
12729 constraint (et.type == NT_invtype, _("bad type for scalar"));
12730 constraint (x >= 64 / et.size, _("scalar index out of range"));
12732 switch (et.size)
12734 case 8: bcdebits = 0x8; break;
12735 case 16: bcdebits = 0x1; break;
12736 case 32: bcdebits = 0x0; break;
12737 default: ;
12740 bcdebits |= x << logsize;
12742 inst.instruction = 0xe000b10;
12743 do_vfp_cond_or_thumb ();
12744 inst.instruction |= LOW4 (dn) << 16;
12745 inst.instruction |= HI1 (dn) << 7;
12746 inst.instruction |= inst.operands[1].reg << 12;
12747 inst.instruction |= (bcdebits & 3) << 5;
12748 inst.instruction |= (bcdebits >> 2) << 21;
12750 break;
12752 case NS_DRR: /* case 5 (fmdrr). */
12753 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
12754 _(BAD_FPU));
12756 inst.instruction = 0xc400b10;
12757 do_vfp_cond_or_thumb ();
12758 inst.instruction |= LOW4 (inst.operands[0].reg);
12759 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
12760 inst.instruction |= inst.operands[1].reg << 12;
12761 inst.instruction |= inst.operands[2].reg << 16;
12762 break;
12764 case NS_RS: /* case 6. */
12766 struct neon_type_el et = neon_check_type (2, NS_NULL,
12767 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
12768 unsigned logsize = neon_logbits (et.size);
12769 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
12770 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
12771 unsigned abcdebits = 0;
12773 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
12774 _(BAD_FPU));
12775 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
12776 && et.size != 32, _(BAD_FPU));
12777 constraint (et.type == NT_invtype, _("bad type for scalar"));
12778 constraint (x >= 64 / et.size, _("scalar index out of range"));
12780 switch (et.size)
12782 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
12783 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
12784 case 32: abcdebits = 0x00; break;
12785 default: ;
12788 abcdebits |= x << logsize;
12789 inst.instruction = 0xe100b10;
12790 do_vfp_cond_or_thumb ();
12791 inst.instruction |= LOW4 (dn) << 16;
12792 inst.instruction |= HI1 (dn) << 7;
12793 inst.instruction |= inst.operands[0].reg << 12;
12794 inst.instruction |= (abcdebits & 3) << 5;
12795 inst.instruction |= (abcdebits >> 2) << 21;
12797 break;
12799 case NS_RRD: /* case 7 (fmrrd). */
12800 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
12801 _(BAD_FPU));
12803 inst.instruction = 0xc500b10;
12804 do_vfp_cond_or_thumb ();
12805 inst.instruction |= inst.operands[0].reg << 12;
12806 inst.instruction |= inst.operands[1].reg << 16;
12807 inst.instruction |= LOW4 (inst.operands[2].reg);
12808 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12809 break;
12811 case NS_FF: /* case 8 (fcpys). */
12812 do_vfp_nsyn_opcode ("fcpys");
12813 break;
12815 case NS_FI: /* case 10 (fconsts). */
12816 ldconst = "fconsts";
12817 encode_fconstd:
12818 if (is_quarter_float (inst.operands[1].imm))
12820 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
12821 do_vfp_nsyn_opcode (ldconst);
12823 else
12824 first_error (_("immediate out of range"));
12825 break;
12827 case NS_RF: /* case 12 (fmrs). */
12828 do_vfp_nsyn_opcode ("fmrs");
12829 break;
12831 case NS_FR: /* case 13 (fmsr). */
12832 do_vfp_nsyn_opcode ("fmsr");
12833 break;
12835 /* The encoders for the fmrrs and fmsrr instructions expect three operands
12836 (one of which is a list), but we have parsed four. Do some fiddling to
12837 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
12838 expect. */
12839 case NS_RRFF: /* case 14 (fmrrs). */
12840 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
12841 _("VFP registers must be adjacent"));
12842 inst.operands[2].imm = 2;
12843 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
12844 do_vfp_nsyn_opcode ("fmrrs");
12845 break;
12847 case NS_FFRR: /* case 15 (fmsrr). */
12848 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
12849 _("VFP registers must be adjacent"));
12850 inst.operands[1] = inst.operands[2];
12851 inst.operands[2] = inst.operands[3];
12852 inst.operands[0].imm = 2;
12853 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
12854 do_vfp_nsyn_opcode ("fmsrr");
12855 break;
12857 default:
12858 abort ();
12862 static void
12863 do_neon_rshift_round_imm (void)
12865 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12866 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12867 int imm = inst.operands[2].imm;
12869 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
12870 if (imm == 0)
12872 inst.operands[2].present = 0;
12873 do_neon_mov ();
12874 return;
12877 constraint (imm < 1 || (unsigned)imm > et.size,
12878 _("immediate out of range for shift"));
12879 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
12880 et.size - imm);
12883 static void
12884 do_neon_movl (void)
12886 struct neon_type_el et = neon_check_type (2, NS_QD,
12887 N_EQK | N_DBL, N_SU_32 | N_KEY);
12888 unsigned sizebits = et.size >> 3;
12889 inst.instruction |= sizebits << 19;
12890 neon_two_same (0, et.type == NT_unsigned, -1);
12893 static void
12894 do_neon_trn (void)
12896 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12897 struct neon_type_el et = neon_check_type (2, rs,
12898 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12899 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12900 neon_two_same (neon_quad (rs), 1, et.size);
12903 static void
12904 do_neon_zip_uzp (void)
12906 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12907 struct neon_type_el et = neon_check_type (2, rs,
12908 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12909 if (rs == NS_DD && et.size == 32)
12911 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
12912 inst.instruction = N_MNEM_vtrn;
12913 do_neon_trn ();
12914 return;
12916 neon_two_same (neon_quad (rs), 1, et.size);
12919 static void
12920 do_neon_sat_abs_neg (void)
12922 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12923 struct neon_type_el et = neon_check_type (2, rs,
12924 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
12925 neon_two_same (neon_quad (rs), 1, et.size);
12928 static void
12929 do_neon_pair_long (void)
12931 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12932 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
12933 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
12934 inst.instruction |= (et.type == NT_unsigned) << 7;
12935 neon_two_same (neon_quad (rs), 1, et.size);
12938 static void
12939 do_neon_recip_est (void)
12941 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12942 struct neon_type_el et = neon_check_type (2, rs,
12943 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
12944 inst.instruction |= (et.type == NT_float) << 8;
12945 neon_two_same (neon_quad (rs), 1, et.size);
12948 static void
12949 do_neon_cls (void)
12951 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12952 struct neon_type_el et = neon_check_type (2, rs,
12953 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
12954 neon_two_same (neon_quad (rs), 1, et.size);
12957 static void
12958 do_neon_clz (void)
12960 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12961 struct neon_type_el et = neon_check_type (2, rs,
12962 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
12963 neon_two_same (neon_quad (rs), 1, et.size);
12966 static void
12967 do_neon_cnt (void)
12969 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12970 struct neon_type_el et = neon_check_type (2, rs,
12971 N_EQK | N_INT, N_8 | N_KEY);
12972 neon_two_same (neon_quad (rs), 1, et.size);
12975 static void
12976 do_neon_swp (void)
12978 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12979 neon_two_same (neon_quad (rs), 1, -1);
12982 static void
12983 do_neon_tbl_tbx (void)
12985 unsigned listlenbits;
12986 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
12988 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
12990 first_error (_("bad list length for table lookup"));
12991 return;
12994 listlenbits = inst.operands[1].imm - 1;
12995 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12996 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12997 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12998 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12999 inst.instruction |= LOW4 (inst.operands[2].reg);
13000 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13001 inst.instruction |= listlenbits << 8;
13003 inst.instruction = neon_dp_fixup (inst.instruction);
13006 static void
13007 do_neon_ldm_stm (void)
13009 /* P, U and L bits are part of bitmask. */
13010 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13011 unsigned offsetbits = inst.operands[1].imm * 2;
13013 if (inst.operands[1].issingle)
13015 do_vfp_nsyn_ldm_stm (is_dbmode);
13016 return;
13019 constraint (is_dbmode && !inst.operands[0].writeback,
13020 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13022 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13023 _("register list must contain at least 1 and at most 16 "
13024 "registers"));
13026 inst.instruction |= inst.operands[0].reg << 16;
13027 inst.instruction |= inst.operands[0].writeback << 21;
13028 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13029 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13031 inst.instruction |= offsetbits;
13033 do_vfp_cond_or_thumb ();
13036 static void
13037 do_neon_ldr_str (void)
13039 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13041 if (inst.operands[0].issingle)
13043 if (is_ldr)
13044 do_vfp_nsyn_opcode ("flds");
13045 else
13046 do_vfp_nsyn_opcode ("fsts");
13048 else
13050 if (is_ldr)
13051 do_vfp_nsyn_opcode ("fldd");
13052 else
13053 do_vfp_nsyn_opcode ("fstd");
13057 /* "interleave" version also handles non-interleaving register VLD1/VST1
13058 instructions. */
13060 static void
13061 do_neon_ld_st_interleave (void)
13063 struct neon_type_el et = neon_check_type (1, NS_NULL,
13064 N_8 | N_16 | N_32 | N_64);
13065 unsigned alignbits = 0;
13066 unsigned idx;
13067 /* The bits in this table go:
13068 0: register stride of one (0) or two (1)
13069 1,2: register list length, minus one (1, 2, 3, 4).
13070 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13071 We use -1 for invalid entries. */
13072 const int typetable[] =
13074 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13075 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13076 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13077 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13079 int typebits;
13081 if (et.type == NT_invtype)
13082 return;
13084 if (inst.operands[1].immisalign)
13085 switch (inst.operands[1].imm >> 8)
13087 case 64: alignbits = 1; break;
13088 case 128:
13089 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13090 goto bad_alignment;
13091 alignbits = 2;
13092 break;
13093 case 256:
13094 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13095 goto bad_alignment;
13096 alignbits = 3;
13097 break;
13098 default:
13099 bad_alignment:
13100 first_error (_("bad alignment"));
13101 return;
13104 inst.instruction |= alignbits << 4;
13105 inst.instruction |= neon_logbits (et.size) << 6;
13107 /* Bits [4:6] of the immediate in a list specifier encode register stride
13108 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13109 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13110 up the right value for "type" in a table based on this value and the given
13111 list style, then stick it back. */
13112 idx = ((inst.operands[0].imm >> 4) & 7)
13113 | (((inst.instruction >> 8) & 3) << 3);
13115 typebits = typetable[idx];
13117 constraint (typebits == -1, _("bad list type for instruction"));
13119 inst.instruction &= ~0xf00;
13120 inst.instruction |= typebits << 8;
13123 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13124 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13125 otherwise. The variable arguments are a list of pairs of legal (size, align)
13126 values, terminated with -1. */
13128 static int
13129 neon_alignment_bit (int size, int align, int *do_align, ...)
13131 va_list ap;
13132 int result = FAIL, thissize, thisalign;
13134 if (!inst.operands[1].immisalign)
13136 *do_align = 0;
13137 return SUCCESS;
13140 va_start (ap, do_align);
13144 thissize = va_arg (ap, int);
13145 if (thissize == -1)
13146 break;
13147 thisalign = va_arg (ap, int);
13149 if (size == thissize && align == thisalign)
13150 result = SUCCESS;
13152 while (result != SUCCESS);
13154 va_end (ap);
13156 if (result == SUCCESS)
13157 *do_align = 1;
13158 else
13159 first_error (_("unsupported alignment for instruction"));
13161 return result;
13164 static void
13165 do_neon_ld_st_lane (void)
13167 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13168 int align_good, do_align = 0;
13169 int logsize = neon_logbits (et.size);
13170 int align = inst.operands[1].imm >> 8;
13171 int n = (inst.instruction >> 8) & 3;
13172 int max_el = 64 / et.size;
13174 if (et.type == NT_invtype)
13175 return;
13177 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13178 _("bad list length"));
13179 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13180 _("scalar index out of range"));
13181 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13182 && et.size == 8,
13183 _("stride of 2 unavailable when element size is 8"));
13185 switch (n)
13187 case 0: /* VLD1 / VST1. */
13188 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13189 32, 32, -1);
13190 if (align_good == FAIL)
13191 return;
13192 if (do_align)
13194 unsigned alignbits = 0;
13195 switch (et.size)
13197 case 16: alignbits = 0x1; break;
13198 case 32: alignbits = 0x3; break;
13199 default: ;
13201 inst.instruction |= alignbits << 4;
13203 break;
13205 case 1: /* VLD2 / VST2. */
13206 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13207 32, 64, -1);
13208 if (align_good == FAIL)
13209 return;
13210 if (do_align)
13211 inst.instruction |= 1 << 4;
13212 break;
13214 case 2: /* VLD3 / VST3. */
13215 constraint (inst.operands[1].immisalign,
13216 _("can't use alignment with this instruction"));
13217 break;
13219 case 3: /* VLD4 / VST4. */
13220 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13221 16, 64, 32, 64, 32, 128, -1);
13222 if (align_good == FAIL)
13223 return;
13224 if (do_align)
13226 unsigned alignbits = 0;
13227 switch (et.size)
13229 case 8: alignbits = 0x1; break;
13230 case 16: alignbits = 0x1; break;
13231 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13232 default: ;
13234 inst.instruction |= alignbits << 4;
13236 break;
13238 default: ;
13241 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13242 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13243 inst.instruction |= 1 << (4 + logsize);
13245 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13246 inst.instruction |= logsize << 10;
13249 /* Encode single n-element structure to all lanes VLD<n> instructions. */
13251 static void
13252 do_neon_ld_dup (void)
13254 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13255 int align_good, do_align = 0;
13257 if (et.type == NT_invtype)
13258 return;
13260 switch ((inst.instruction >> 8) & 3)
13262 case 0: /* VLD1. */
13263 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13264 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13265 &do_align, 16, 16, 32, 32, -1);
13266 if (align_good == FAIL)
13267 return;
13268 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13270 case 1: break;
13271 case 2: inst.instruction |= 1 << 5; break;
13272 default: first_error (_("bad list length")); return;
13274 inst.instruction |= neon_logbits (et.size) << 6;
13275 break;
13277 case 1: /* VLD2. */
13278 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13279 &do_align, 8, 16, 16, 32, 32, 64, -1);
13280 if (align_good == FAIL)
13281 return;
13282 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13283 _("bad list length"));
13284 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13285 inst.instruction |= 1 << 5;
13286 inst.instruction |= neon_logbits (et.size) << 6;
13287 break;
13289 case 2: /* VLD3. */
13290 constraint (inst.operands[1].immisalign,
13291 _("can't use alignment with this instruction"));
13292 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13293 _("bad list length"));
13294 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13295 inst.instruction |= 1 << 5;
13296 inst.instruction |= neon_logbits (et.size) << 6;
13297 break;
13299 case 3: /* VLD4. */
13301 int align = inst.operands[1].imm >> 8;
13302 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13303 16, 64, 32, 64, 32, 128, -1);
13304 if (align_good == FAIL)
13305 return;
13306 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13307 _("bad list length"));
13308 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13309 inst.instruction |= 1 << 5;
13310 if (et.size == 32 && align == 128)
13311 inst.instruction |= 0x3 << 6;
13312 else
13313 inst.instruction |= neon_logbits (et.size) << 6;
13315 break;
13317 default: ;
13320 inst.instruction |= do_align << 4;
13323 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13324 apart from bits [11:4]. */
13326 static void
13327 do_neon_ldx_stx (void)
13329 switch (NEON_LANE (inst.operands[0].imm))
13331 case NEON_INTERLEAVE_LANES:
13332 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13333 do_neon_ld_st_interleave ();
13334 break;
13336 case NEON_ALL_LANES:
13337 inst.instruction = NEON_ENC_DUP (inst.instruction);
13338 do_neon_ld_dup ();
13339 break;
13341 default:
13342 inst.instruction = NEON_ENC_LANE (inst.instruction);
13343 do_neon_ld_st_lane ();
13346 /* L bit comes from bit mask. */
13347 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13348 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13349 inst.instruction |= inst.operands[1].reg << 16;
13351 if (inst.operands[1].postind)
13353 int postreg = inst.operands[1].imm & 0xf;
13354 constraint (!inst.operands[1].immisreg,
13355 _("post-index must be a register"));
13356 constraint (postreg == 0xd || postreg == 0xf,
13357 _("bad register for post-index"));
13358 inst.instruction |= postreg;
13360 else if (inst.operands[1].writeback)
13362 inst.instruction |= 0xd;
13364 else
13365 inst.instruction |= 0xf;
13367 if (thumb_mode)
13368 inst.instruction |= 0xf9000000;
13369 else
13370 inst.instruction |= 0xf4000000;
13374 /* Overall per-instruction processing. */
13376 /* We need to be able to fix up arbitrary expressions in some statements.
13377 This is so that we can handle symbols that are an arbitrary distance from
13378 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13379 which returns part of an address in a form which will be valid for
13380 a data instruction. We do this by pushing the expression into a symbol
13381 in the expr_section, and creating a fix for that. */
13383 static void
13384 fix_new_arm (fragS * frag,
13385 int where,
13386 short int size,
13387 expressionS * exp,
13388 int pc_rel,
13389 int reloc)
13391 fixS * new_fix;
13393 switch (exp->X_op)
13395 case O_constant:
13396 case O_symbol:
13397 case O_add:
13398 case O_subtract:
13399 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13400 break;
13402 default:
13403 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13404 pc_rel, reloc);
13405 break;
13408 /* Mark whether the fix is to a THUMB instruction, or an ARM
13409 instruction. */
13410 new_fix->tc_fix_data = thumb_mode;
13413 /* Create a frg for an instruction requiring relaxation. */
13414 static void
13415 output_relax_insn (void)
13417 char * to;
13418 symbolS *sym;
13419 int offset;
13421 #ifdef OBJ_ELF
13422 /* The size of the instruction is unknown, so tie the debug info to the
13423 start of the instruction. */
13424 dwarf2_emit_insn (0);
13425 #endif
13427 switch (inst.reloc.exp.X_op)
13429 case O_symbol:
13430 sym = inst.reloc.exp.X_add_symbol;
13431 offset = inst.reloc.exp.X_add_number;
13432 break;
13433 case O_constant:
13434 sym = NULL;
13435 offset = inst.reloc.exp.X_add_number;
13436 break;
13437 default:
13438 sym = make_expr_symbol (&inst.reloc.exp);
13439 offset = 0;
13440 break;
13442 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13443 inst.relax, sym, offset, NULL/*offset, opcode*/);
13444 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
13447 /* Write a 32-bit thumb instruction to buf. */
13448 static void
13449 put_thumb32_insn (char * buf, unsigned long insn)
13451 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13452 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13455 static void
13456 output_inst (const char * str)
13458 char * to = NULL;
13460 if (inst.error)
13462 as_bad ("%s -- `%s'", inst.error, str);
13463 return;
13465 if (inst.relax) {
13466 output_relax_insn();
13467 return;
13469 if (inst.size == 0)
13470 return;
13472 to = frag_more (inst.size);
13474 if (thumb_mode && (inst.size > THUMB_SIZE))
13476 assert (inst.size == (2 * THUMB_SIZE));
13477 put_thumb32_insn (to, inst.instruction);
13479 else if (inst.size > INSN_SIZE)
13481 assert (inst.size == (2 * INSN_SIZE));
13482 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13483 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
13485 else
13486 md_number_to_chars (to, inst.instruction, inst.size);
13488 if (inst.reloc.type != BFD_RELOC_UNUSED)
13489 fix_new_arm (frag_now, to - frag_now->fr_literal,
13490 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13491 inst.reloc.type);
13493 #ifdef OBJ_ELF
13494 dwarf2_emit_insn (inst.size);
13495 #endif
13498 /* Tag values used in struct asm_opcode's tag field. */
13499 enum opcode_tag
13501 OT_unconditional, /* Instruction cannot be conditionalized.
13502 The ARM condition field is still 0xE. */
13503 OT_unconditionalF, /* Instruction cannot be conditionalized
13504 and carries 0xF in its ARM condition field. */
13505 OT_csuffix, /* Instruction takes a conditional suffix. */
13506 OT_csuffixF, /* Some forms of the instruction take a conditional
13507 suffix, others place 0xF where the condition field
13508 would be. */
13509 OT_cinfix3, /* Instruction takes a conditional infix,
13510 beginning at character index 3. (In
13511 unified mode, it becomes a suffix.) */
13512 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13513 character index 3, even in unified mode. Used for
13514 legacy instructions where suffix and infix forms
13515 may be ambiguous. */
13516 OT_csuf_or_in3, /* Instruction takes either a conditional
13517 suffix or an infix at character index 3. */
13518 OT_odd_infix_unc, /* This is the unconditional variant of an
13519 instruction that takes a conditional infix
13520 at an unusual position. In unified mode,
13521 this variant will accept a suffix. */
13522 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13523 are the conditional variants of instructions that
13524 take conditional infixes in unusual positions.
13525 The infix appears at character index
13526 (tag - OT_odd_infix_0). These are not accepted
13527 in unified mode. */
13530 /* Subroutine of md_assemble, responsible for looking up the primary
13531 opcode from the mnemonic the user wrote. STR points to the
13532 beginning of the mnemonic.
13534 This is not simply a hash table lookup, because of conditional
13535 variants. Most instructions have conditional variants, which are
13536 expressed with a _conditional affix_ to the mnemonic. If we were
13537 to encode each conditional variant as a literal string in the opcode
13538 table, it would have approximately 20,000 entries.
13540 Most mnemonics take this affix as a suffix, and in unified syntax,
13541 'most' is upgraded to 'all'. However, in the divided syntax, some
13542 instructions take the affix as an infix, notably the s-variants of
13543 the arithmetic instructions. Of those instructions, all but six
13544 have the infix appear after the third character of the mnemonic.
13546 Accordingly, the algorithm for looking up primary opcodes given
13547 an identifier is:
13549 1. Look up the identifier in the opcode table.
13550 If we find a match, go to step U.
13552 2. Look up the last two characters of the identifier in the
13553 conditions table. If we find a match, look up the first N-2
13554 characters of the identifier in the opcode table. If we
13555 find a match, go to step CE.
13557 3. Look up the fourth and fifth characters of the identifier in
13558 the conditions table. If we find a match, extract those
13559 characters from the identifier, and look up the remaining
13560 characters in the opcode table. If we find a match, go
13561 to step CM.
13563 4. Fail.
13565 U. Examine the tag field of the opcode structure, in case this is
13566 one of the six instructions with its conditional infix in an
13567 unusual place. If it is, the tag tells us where to find the
13568 infix; look it up in the conditions table and set inst.cond
13569 accordingly. Otherwise, this is an unconditional instruction.
13570 Again set inst.cond accordingly. Return the opcode structure.
13572 CE. Examine the tag field to make sure this is an instruction that
13573 should receive a conditional suffix. If it is not, fail.
13574 Otherwise, set inst.cond from the suffix we already looked up,
13575 and return the opcode structure.
13577 CM. Examine the tag field to make sure this is an instruction that
13578 should receive a conditional infix after the third character.
13579 If it is not, fail. Otherwise, undo the edits to the current
13580 line of input and proceed as for case CE. */
13582 static const struct asm_opcode *
13583 opcode_lookup (char **str)
13585 char *end, *base;
13586 char *affix;
13587 const struct asm_opcode *opcode;
13588 const struct asm_cond *cond;
13589 char save[2];
13590 bfd_boolean neon_supported;
13592 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
13594 /* Scan up to the end of the mnemonic, which must end in white space,
13595 '.' (in unified mode, or for Neon instructions), or end of string. */
13596 for (base = end = *str; *end != '\0'; end++)
13597 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
13598 break;
13600 if (end == base)
13601 return 0;
13603 /* Handle a possible width suffix and/or Neon type suffix. */
13604 if (end[0] == '.')
13606 int offset = 2;
13608 /* The .w and .n suffixes are only valid if the unified syntax is in
13609 use. */
13610 if (unified_syntax && end[1] == 'w')
13611 inst.size_req = 4;
13612 else if (unified_syntax && end[1] == 'n')
13613 inst.size_req = 2;
13614 else
13615 offset = 0;
13617 inst.vectype.elems = 0;
13619 *str = end + offset;
13621 if (end[offset] == '.')
13623 /* See if we have a Neon type suffix (possible in either unified or
13624 non-unified ARM syntax mode). */
13625 if (parse_neon_type (&inst.vectype, str) == FAIL)
13626 return 0;
13628 else if (end[offset] != '\0' && end[offset] != ' ')
13629 return 0;
13631 else
13632 *str = end;
13634 /* Look for unaffixed or special-case affixed mnemonic. */
13635 opcode = hash_find_n (arm_ops_hsh, base, end - base);
13636 if (opcode)
13638 /* step U */
13639 if (opcode->tag < OT_odd_infix_0)
13641 inst.cond = COND_ALWAYS;
13642 return opcode;
13645 if (unified_syntax)
13646 as_warn (_("conditional infixes are deprecated in unified syntax"));
13647 affix = base + (opcode->tag - OT_odd_infix_0);
13648 cond = hash_find_n (arm_cond_hsh, affix, 2);
13649 assert (cond);
13651 inst.cond = cond->value;
13652 return opcode;
13655 /* Cannot have a conditional suffix on a mnemonic of less than two
13656 characters. */
13657 if (end - base < 3)
13658 return 0;
13660 /* Look for suffixed mnemonic. */
13661 affix = end - 2;
13662 cond = hash_find_n (arm_cond_hsh, affix, 2);
13663 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
13664 if (opcode && cond)
13666 /* step CE */
13667 switch (opcode->tag)
13669 case OT_cinfix3_legacy:
13670 /* Ignore conditional suffixes matched on infix only mnemonics. */
13671 break;
13673 case OT_cinfix3:
13674 case OT_odd_infix_unc:
13675 if (!unified_syntax)
13676 return 0;
13677 /* else fall through */
13679 case OT_csuffix:
13680 case OT_csuffixF:
13681 case OT_csuf_or_in3:
13682 inst.cond = cond->value;
13683 return opcode;
13685 case OT_unconditional:
13686 case OT_unconditionalF:
13687 if (thumb_mode)
13689 inst.cond = cond->value;
13691 else
13693 /* delayed diagnostic */
13694 inst.error = BAD_COND;
13695 inst.cond = COND_ALWAYS;
13697 return opcode;
13699 default:
13700 return 0;
13704 /* Cannot have a usual-position infix on a mnemonic of less than
13705 six characters (five would be a suffix). */
13706 if (end - base < 6)
13707 return 0;
13709 /* Look for infixed mnemonic in the usual position. */
13710 affix = base + 3;
13711 cond = hash_find_n (arm_cond_hsh, affix, 2);
13712 if (!cond)
13713 return 0;
13715 memcpy (save, affix, 2);
13716 memmove (affix, affix + 2, (end - affix) - 2);
13717 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
13718 memmove (affix + 2, affix, (end - affix) - 2);
13719 memcpy (affix, save, 2);
13721 if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3
13722 || opcode->tag == OT_cinfix3_legacy))
13724 /* step CM */
13725 if (unified_syntax && opcode->tag == OT_cinfix3)
13726 as_warn (_("conditional infixes are deprecated in unified syntax"));
13728 inst.cond = cond->value;
13729 return opcode;
13732 return 0;
13735 void
13736 md_assemble (char *str)
13738 char *p = str;
13739 const struct asm_opcode * opcode;
13741 /* Align the previous label if needed. */
13742 if (last_label_seen != NULL)
13744 symbol_set_frag (last_label_seen, frag_now);
13745 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
13746 S_SET_SEGMENT (last_label_seen, now_seg);
13749 memset (&inst, '\0', sizeof (inst));
13750 inst.reloc.type = BFD_RELOC_UNUSED;
13752 opcode = opcode_lookup (&p);
13753 if (!opcode)
13755 /* It wasn't an instruction, but it might be a register alias of
13756 the form alias .req reg, or a Neon .dn/.qn directive. */
13757 if (!create_register_alias (str, p)
13758 && !create_neon_reg_alias (str, p))
13759 as_bad (_("bad instruction `%s'"), str);
13761 return;
13764 /* The value which unconditional instructions should have in place of the
13765 condition field. */
13766 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
13768 if (thumb_mode)
13770 arm_feature_set variant;
13772 variant = cpu_variant;
13773 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
13774 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
13775 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
13776 /* Check that this instruction is supported for this CPU. */
13777 if (!opcode->tvariant
13778 || (thumb_mode == 1
13779 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
13781 as_bad (_("selected processor does not support `%s'"), str);
13782 return;
13784 if (inst.cond != COND_ALWAYS && !unified_syntax
13785 && opcode->tencode != do_t_branch)
13787 as_bad (_("Thumb does not support conditional execution"));
13788 return;
13791 /* Check conditional suffixes. */
13792 if (current_it_mask)
13794 int cond;
13795 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
13796 current_it_mask <<= 1;
13797 current_it_mask &= 0x1f;
13798 /* The BKPT instruction is unconditional even in an IT block. */
13799 if (!inst.error
13800 && cond != inst.cond && opcode->tencode != do_t_bkpt)
13802 as_bad (_("incorrect condition in IT block"));
13803 return;
13806 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
13808 as_bad (_("thumb conditional instrunction not in IT block"));
13809 return;
13812 mapping_state (MAP_THUMB);
13813 inst.instruction = opcode->tvalue;
13815 if (!parse_operands (p, opcode->operands))
13816 opcode->tencode ();
13818 /* Clear current_it_mask at the end of an IT block. */
13819 if (current_it_mask == 0x10)
13820 current_it_mask = 0;
13822 if (!(inst.error || inst.relax))
13824 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
13825 inst.size = (inst.instruction > 0xffff ? 4 : 2);
13826 if (inst.size_req && inst.size_req != inst.size)
13828 as_bad (_("cannot honor width suffix -- `%s'"), str);
13829 return;
13832 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13833 *opcode->tvariant);
13834 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
13835 set those bits when Thumb-2 32-bit instuctions are seen. ie.
13836 anything other than bl/blx.
13837 This is overly pessimistic for relaxable instructions. */
13838 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
13839 || inst.relax)
13840 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13841 arm_ext_v6t2);
13843 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
13845 /* Check that this instruction is supported for this CPU. */
13846 if (!opcode->avariant ||
13847 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
13849 as_bad (_("selected processor does not support `%s'"), str);
13850 return;
13852 if (inst.size_req)
13854 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
13855 return;
13858 mapping_state (MAP_ARM);
13859 inst.instruction = opcode->avalue;
13860 if (opcode->tag == OT_unconditionalF)
13861 inst.instruction |= 0xF << 28;
13862 else
13863 inst.instruction |= inst.cond << 28;
13864 inst.size = INSN_SIZE;
13865 if (!parse_operands (p, opcode->operands))
13866 opcode->aencode ();
13867 /* Arm mode bx is marked as both v4T and v5 because it's still required
13868 on a hypothetical non-thumb v5 core. */
13869 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
13870 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
13871 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
13872 else
13873 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
13874 *opcode->avariant);
13876 else
13878 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
13879 "-- `%s'"), str);
13880 return;
13882 output_inst (str);
13885 /* Various frobbings of labels and their addresses. */
13887 void
13888 arm_start_line_hook (void)
13890 last_label_seen = NULL;
13893 void
13894 arm_frob_label (symbolS * sym)
13896 last_label_seen = sym;
13898 ARM_SET_THUMB (sym, thumb_mode);
13900 #if defined OBJ_COFF || defined OBJ_ELF
13901 ARM_SET_INTERWORK (sym, support_interwork);
13902 #endif
13904 /* Note - do not allow local symbols (.Lxxx) to be labeled
13905 as Thumb functions. This is because these labels, whilst
13906 they exist inside Thumb code, are not the entry points for
13907 possible ARM->Thumb calls. Also, these labels can be used
13908 as part of a computed goto or switch statement. eg gcc
13909 can generate code that looks like this:
13911 ldr r2, [pc, .Laaa]
13912 lsl r3, r3, #2
13913 ldr r2, [r3, r2]
13914 mov pc, r2
13916 .Lbbb: .word .Lxxx
13917 .Lccc: .word .Lyyy
13918 ..etc...
13919 .Laaa: .word Lbbb
13921 The first instruction loads the address of the jump table.
13922 The second instruction converts a table index into a byte offset.
13923 The third instruction gets the jump address out of the table.
13924 The fourth instruction performs the jump.
13926 If the address stored at .Laaa is that of a symbol which has the
13927 Thumb_Func bit set, then the linker will arrange for this address
13928 to have the bottom bit set, which in turn would mean that the
13929 address computation performed by the third instruction would end
13930 up with the bottom bit set. Since the ARM is capable of unaligned
13931 word loads, the instruction would then load the incorrect address
13932 out of the jump table, and chaos would ensue. */
13933 if (label_is_thumb_function_name
13934 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
13935 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13937 /* When the address of a Thumb function is taken the bottom
13938 bit of that address should be set. This will allow
13939 interworking between Arm and Thumb functions to work
13940 correctly. */
13942 THUMB_SET_FUNC (sym, 1);
13944 label_is_thumb_function_name = FALSE;
13947 #ifdef OBJ_ELF
13948 dwarf2_emit_label (sym);
13949 #endif
13953 arm_data_in_code (void)
13955 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
13957 *input_line_pointer = '/';
13958 input_line_pointer += 5;
13959 *input_line_pointer = 0;
13960 return 1;
13963 return 0;
13966 char *
13967 arm_canonicalize_symbol_name (char * name)
13969 int len;
13971 if (thumb_mode && (len = strlen (name)) > 5
13972 && streq (name + len - 5, "/data"))
13973 *(name + len - 5) = 0;
13975 return name;
13978 /* Table of all register names defined by default. The user can
13979 define additional names with .req. Note that all register names
13980 should appear in both upper and lowercase variants. Some registers
13981 also have mixed-case names. */
13983 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
13984 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
13985 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
13986 #define REGSET(p,t) \
13987 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
13988 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
13989 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
13990 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
13991 #define REGSETH(p,t) \
13992 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
13993 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
13994 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
13995 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
13996 #define REGSET2(p,t) \
13997 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
13998 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
13999 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14000 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
14002 static const struct reg_entry reg_names[] =
14004 /* ARM integer registers. */
14005 REGSET(r, RN), REGSET(R, RN),
14007 /* ATPCS synonyms. */
14008 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14009 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14010 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
14012 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14013 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14014 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
14016 /* Well-known aliases. */
14017 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14018 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14020 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14021 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14023 /* Coprocessor numbers. */
14024 REGSET(p, CP), REGSET(P, CP),
14026 /* Coprocessor register numbers. The "cr" variants are for backward
14027 compatibility. */
14028 REGSET(c, CN), REGSET(C, CN),
14029 REGSET(cr, CN), REGSET(CR, CN),
14031 /* FPA registers. */
14032 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14033 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14035 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14036 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14038 /* VFP SP registers. */
14039 REGSET(s,VFS), REGSET(S,VFS),
14040 REGSETH(s,VFS), REGSETH(S,VFS),
14042 /* VFP DP Registers. */
14043 REGSET(d,VFD), REGSET(D,VFD),
14044 /* Extra Neon DP registers. */
14045 REGSETH(d,VFD), REGSETH(D,VFD),
14047 /* Neon QP registers. */
14048 REGSET2(q,NQ), REGSET2(Q,NQ),
14050 /* VFP control registers. */
14051 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14052 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
14054 /* Maverick DSP coprocessor registers. */
14055 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14056 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14058 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14059 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14060 REGDEF(dspsc,0,DSPSC),
14062 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14063 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14064 REGDEF(DSPSC,0,DSPSC),
14066 /* iWMMXt data registers - p0, c0-15. */
14067 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14069 /* iWMMXt control registers - p1, c0-3. */
14070 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14071 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14072 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14073 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14075 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14076 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14077 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14078 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14079 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14081 /* XScale accumulator registers. */
14082 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14084 #undef REGDEF
14085 #undef REGNUM
14086 #undef REGSET
14088 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14089 within psr_required_here. */
14090 static const struct asm_psr psrs[] =
14092 /* Backward compatibility notation. Note that "all" is no longer
14093 truly all possible PSR bits. */
14094 {"all", PSR_c | PSR_f},
14095 {"flg", PSR_f},
14096 {"ctl", PSR_c},
14098 /* Individual flags. */
14099 {"f", PSR_f},
14100 {"c", PSR_c},
14101 {"x", PSR_x},
14102 {"s", PSR_s},
14103 /* Combinations of flags. */
14104 {"fs", PSR_f | PSR_s},
14105 {"fx", PSR_f | PSR_x},
14106 {"fc", PSR_f | PSR_c},
14107 {"sf", PSR_s | PSR_f},
14108 {"sx", PSR_s | PSR_x},
14109 {"sc", PSR_s | PSR_c},
14110 {"xf", PSR_x | PSR_f},
14111 {"xs", PSR_x | PSR_s},
14112 {"xc", PSR_x | PSR_c},
14113 {"cf", PSR_c | PSR_f},
14114 {"cs", PSR_c | PSR_s},
14115 {"cx", PSR_c | PSR_x},
14116 {"fsx", PSR_f | PSR_s | PSR_x},
14117 {"fsc", PSR_f | PSR_s | PSR_c},
14118 {"fxs", PSR_f | PSR_x | PSR_s},
14119 {"fxc", PSR_f | PSR_x | PSR_c},
14120 {"fcs", PSR_f | PSR_c | PSR_s},
14121 {"fcx", PSR_f | PSR_c | PSR_x},
14122 {"sfx", PSR_s | PSR_f | PSR_x},
14123 {"sfc", PSR_s | PSR_f | PSR_c},
14124 {"sxf", PSR_s | PSR_x | PSR_f},
14125 {"sxc", PSR_s | PSR_x | PSR_c},
14126 {"scf", PSR_s | PSR_c | PSR_f},
14127 {"scx", PSR_s | PSR_c | PSR_x},
14128 {"xfs", PSR_x | PSR_f | PSR_s},
14129 {"xfc", PSR_x | PSR_f | PSR_c},
14130 {"xsf", PSR_x | PSR_s | PSR_f},
14131 {"xsc", PSR_x | PSR_s | PSR_c},
14132 {"xcf", PSR_x | PSR_c | PSR_f},
14133 {"xcs", PSR_x | PSR_c | PSR_s},
14134 {"cfs", PSR_c | PSR_f | PSR_s},
14135 {"cfx", PSR_c | PSR_f | PSR_x},
14136 {"csf", PSR_c | PSR_s | PSR_f},
14137 {"csx", PSR_c | PSR_s | PSR_x},
14138 {"cxf", PSR_c | PSR_x | PSR_f},
14139 {"cxs", PSR_c | PSR_x | PSR_s},
14140 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14141 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14142 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14143 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14144 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14145 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14146 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14147 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14148 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14149 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14150 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14151 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14152 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14153 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14154 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14155 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14156 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14157 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14158 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14159 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14160 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14161 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14162 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14163 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14166 /* Table of V7M psr names. */
14167 static const struct asm_psr v7m_psrs[] =
14169 {"apsr", 0 },
14170 {"iapsr", 1 },
14171 {"eapsr", 2 },
14172 {"psr", 3 },
14173 {"ipsr", 5 },
14174 {"epsr", 6 },
14175 {"iepsr", 7 },
14176 {"msp", 8 },
14177 {"psp", 9 },
14178 {"primask", 16},
14179 {"basepri", 17},
14180 {"basepri_max", 18},
14181 {"faultmask", 19},
14182 {"control", 20}
14185 /* Table of all shift-in-operand names. */
14186 static const struct asm_shift_name shift_names [] =
14188 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14189 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14190 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14191 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14192 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14193 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14196 /* Table of all explicit relocation names. */
14197 #ifdef OBJ_ELF
14198 static struct reloc_entry reloc_names[] =
14200 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14201 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14202 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14203 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14204 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14205 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14206 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14207 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14208 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14209 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14210 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14212 #endif
14214 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
14215 static const struct asm_cond conds[] =
14217 {"eq", 0x0},
14218 {"ne", 0x1},
14219 {"cs", 0x2}, {"hs", 0x2},
14220 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14221 {"mi", 0x4},
14222 {"pl", 0x5},
14223 {"vs", 0x6},
14224 {"vc", 0x7},
14225 {"hi", 0x8},
14226 {"ls", 0x9},
14227 {"ge", 0xa},
14228 {"lt", 0xb},
14229 {"gt", 0xc},
14230 {"le", 0xd},
14231 {"al", 0xe}
14234 static struct asm_barrier_opt barrier_opt_names[] =
14236 { "sy", 0xf },
14237 { "un", 0x7 },
14238 { "st", 0xe },
14239 { "unst", 0x6 }
14242 /* Table of ARM-format instructions. */
14244 /* Macros for gluing together operand strings. N.B. In all cases
14245 other than OPS0, the trailing OP_stop comes from default
14246 zero-initialization of the unspecified elements of the array. */
14247 #define OPS0() { OP_stop, }
14248 #define OPS1(a) { OP_##a, }
14249 #define OPS2(a,b) { OP_##a,OP_##b, }
14250 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14251 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14252 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14253 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14255 /* These macros abstract out the exact format of the mnemonic table and
14256 save some repeated characters. */
14258 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14259 #define TxCE(mnem, op, top, nops, ops, ae, te) \
14260 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
14261 THUMB_VARIANT, do_##ae, do_##te }
14263 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14264 a T_MNEM_xyz enumerator. */
14265 #define TCE(mnem, aop, top, nops, ops, ae, te) \
14266 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14267 #define tCE(mnem, aop, top, nops, ops, ae, te) \
14268 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14270 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14271 infix after the third character. */
14272 #define TxC3(mnem, op, top, nops, ops, ae, te) \
14273 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
14274 THUMB_VARIANT, do_##ae, do_##te }
14275 #define TC3(mnem, aop, top, nops, ops, ae, te) \
14276 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
14277 #define tC3(mnem, aop, top, nops, ops, ae, te) \
14278 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14280 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14281 appear in the condition table. */
14282 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14283 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14284 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
14286 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14287 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14288 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14289 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14290 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14291 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14292 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14293 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14294 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14295 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14296 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14297 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14298 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14299 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14300 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14301 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14302 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14303 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14304 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14305 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14307 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14308 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14309 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14310 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14312 /* Mnemonic that cannot be conditionalized. The ARM condition-code
14313 field is still 0xE. Many of the Thumb variants can be executed
14314 conditionally, so this is checked separately. */
14315 #define TUE(mnem, op, top, nops, ops, ae, te) \
14316 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
14317 THUMB_VARIANT, do_##ae, do_##te }
14319 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14320 condition code field. */
14321 #define TUF(mnem, op, top, nops, ops, ae, te) \
14322 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
14323 THUMB_VARIANT, do_##ae, do_##te }
14325 /* ARM-only variants of all the above. */
14326 #define CE(mnem, op, nops, ops, ae) \
14327 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14329 #define C3(mnem, op, nops, ops, ae) \
14330 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14332 /* Legacy mnemonics that always have conditional infix after the third
14333 character. */
14334 #define CL(mnem, op, nops, ops, ae) \
14335 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14336 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14338 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14339 #define cCE(mnem, op, nops, ops, ae) \
14340 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14342 /* Legacy coprocessor instructions where conditional infix and conditional
14343 suffix are ambiguous. For consistency this includes all FPA instructions,
14344 not just the potentially ambiguous ones. */
14345 #define cCL(mnem, op, nops, ops, ae) \
14346 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14347 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14349 /* Coprocessor, takes either a suffix or a position-3 infix
14350 (for an FPA corner case). */
14351 #define C3E(mnem, op, nops, ops, ae) \
14352 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14353 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14355 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
14356 { #m1 #m2 #m3, OPS##nops ops, \
14357 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14358 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14360 #define CM(m1, m2, op, nops, ops, ae) \
14361 xCM_(m1, , m2, op, nops, ops, ae), \
14362 xCM_(m1, eq, m2, op, nops, ops, ae), \
14363 xCM_(m1, ne, m2, op, nops, ops, ae), \
14364 xCM_(m1, cs, m2, op, nops, ops, ae), \
14365 xCM_(m1, hs, m2, op, nops, ops, ae), \
14366 xCM_(m1, cc, m2, op, nops, ops, ae), \
14367 xCM_(m1, ul, m2, op, nops, ops, ae), \
14368 xCM_(m1, lo, m2, op, nops, ops, ae), \
14369 xCM_(m1, mi, m2, op, nops, ops, ae), \
14370 xCM_(m1, pl, m2, op, nops, ops, ae), \
14371 xCM_(m1, vs, m2, op, nops, ops, ae), \
14372 xCM_(m1, vc, m2, op, nops, ops, ae), \
14373 xCM_(m1, hi, m2, op, nops, ops, ae), \
14374 xCM_(m1, ls, m2, op, nops, ops, ae), \
14375 xCM_(m1, ge, m2, op, nops, ops, ae), \
14376 xCM_(m1, lt, m2, op, nops, ops, ae), \
14377 xCM_(m1, gt, m2, op, nops, ops, ae), \
14378 xCM_(m1, le, m2, op, nops, ops, ae), \
14379 xCM_(m1, al, m2, op, nops, ops, ae)
14381 #define UE(mnem, op, nops, ops, ae) \
14382 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14384 #define UF(mnem, op, nops, ops, ae) \
14385 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14387 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
14388 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14389 use the same encoding function for each. */
14390 #define NUF(mnem, op, nops, ops, enc) \
14391 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14392 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14394 /* Neon data processing, version which indirects through neon_enc_tab for
14395 the various overloaded versions of opcodes. */
14396 #define nUF(mnem, op, nops, ops, enc) \
14397 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14398 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14400 /* Neon insn with conditional suffix for the ARM version, non-overloaded
14401 version. */
14402 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
14403 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
14404 THUMB_VARIANT, do_##enc, do_##enc }
14406 #define NCE(mnem, op, nops, ops, enc) \
14407 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14409 #define NCEF(mnem, op, nops, ops, enc) \
14410 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14412 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
14413 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
14414 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
14415 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14417 #define nCE(mnem, op, nops, ops, enc) \
14418 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14420 #define nCEF(mnem, op, nops, ops, enc) \
14421 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14423 #define do_0 0
14425 /* Thumb-only, unconditional. */
14426 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14428 static const struct asm_opcode insns[] =
14430 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14431 #define THUMB_VARIANT &arm_ext_v4t
14432 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14433 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14434 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14435 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14436 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14437 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
14438 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14439 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
14440 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14441 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14442 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14443 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14444 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14445 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14446 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14447 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14449 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14450 for setting PSR flag bits. They are obsolete in V6 and do not
14451 have Thumb equivalents. */
14452 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14453 tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14454 CL(tstp, 110f000, 2, (RR, SH), cmp),
14455 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14456 tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14457 CL(cmpp, 150f000, 2, (RR, SH), cmp),
14458 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14459 tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14460 CL(cmnp, 170f000, 2, (RR, SH), cmp),
14462 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14463 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14464 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14465 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14467 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14468 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14469 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14470 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14472 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14473 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14474 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14475 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14476 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14477 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14479 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
14480 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
14481 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
14482 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
14484 /* Pseudo ops. */
14485 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
14486 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14487 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
14489 /* Thumb-compatibility pseudo ops. */
14490 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14491 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14492 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14493 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14494 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
14495 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
14496 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14497 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14498 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14499 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14500 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14501 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14503 #undef THUMB_VARIANT
14504 #define THUMB_VARIANT &arm_ext_v6
14505 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
14507 /* V1 instructions with no Thumb analogue prior to V6T2. */
14508 #undef THUMB_VARIANT
14509 #define THUMB_VARIANT &arm_ext_v6t2
14510 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14511 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14512 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14513 TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14514 CL(teqp, 130f000, 2, (RR, SH), cmp),
14516 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
14517 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
14518 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
14519 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
14521 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14522 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14524 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14525 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14527 /* V1 instructions with no Thumb analogue at all. */
14528 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14529 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
14531 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
14532 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
14533 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
14534 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
14535 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
14536 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
14537 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
14538 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
14540 #undef ARM_VARIANT
14541 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
14542 #undef THUMB_VARIANT
14543 #define THUMB_VARIANT &arm_ext_v4t
14544 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14545 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14547 #undef THUMB_VARIANT
14548 #define THUMB_VARIANT &arm_ext_v6t2
14549 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
14550 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
14552 /* Generic coprocessor instructions. */
14553 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
14554 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14555 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14556 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14557 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14558 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14559 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14561 #undef ARM_VARIANT
14562 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
14563 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
14564 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
14566 #undef ARM_VARIANT
14567 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
14568 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
14569 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
14571 #undef ARM_VARIANT
14572 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
14573 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14574 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14575 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14576 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14577 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14578 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14579 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14580 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14582 #undef ARM_VARIANT
14583 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
14584 #undef THUMB_VARIANT
14585 #define THUMB_VARIANT &arm_ext_v4t
14586 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14587 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14588 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14589 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14590 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14591 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14593 #undef ARM_VARIANT
14594 #define ARM_VARIANT &arm_ext_v4t_5
14595 /* ARM Architecture 4T. */
14596 /* Note: bx (and blx) are required on V5, even if the processor does
14597 not support Thumb. */
14598 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
14600 #undef ARM_VARIANT
14601 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
14602 #undef THUMB_VARIANT
14603 #define THUMB_VARIANT &arm_ext_v5t
14604 /* Note: blx has 2 variants; the .value coded here is for
14605 BLX(2). Only this variant has conditional execution. */
14606 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
14607 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
14609 #undef THUMB_VARIANT
14610 #define THUMB_VARIANT &arm_ext_v6t2
14611 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
14612 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14613 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14614 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14615 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14616 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
14617 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14618 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14620 #undef ARM_VARIANT
14621 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
14622 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14623 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14624 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14625 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14627 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14628 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14630 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14631 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14632 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14633 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14635 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14636 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14637 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14638 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14640 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14641 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14643 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14644 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14645 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14646 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14648 #undef ARM_VARIANT
14649 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
14650 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
14651 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
14652 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
14654 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14655 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14657 #undef ARM_VARIANT
14658 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
14659 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
14661 #undef ARM_VARIANT
14662 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
14663 #undef THUMB_VARIANT
14664 #define THUMB_VARIANT &arm_ext_v6
14665 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
14666 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
14667 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14668 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14669 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14670 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14671 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14672 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14673 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14674 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
14676 #undef THUMB_VARIANT
14677 #define THUMB_VARIANT &arm_ext_v6t2
14678 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
14679 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14680 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14682 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
14683 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
14685 /* ARM V6 not included in V7M (eg. integer SIMD). */
14686 #undef THUMB_VARIANT
14687 #define THUMB_VARIANT &arm_ext_v6_notm
14688 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
14689 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
14690 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
14691 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14692 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14693 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14694 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14695 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14696 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14697 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14698 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14699 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14700 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14701 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14702 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14703 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14704 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14705 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14706 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14707 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14708 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14709 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14710 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14711 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14712 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14713 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14714 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14715 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14716 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14717 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14718 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14719 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14720 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14721 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14722 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14723 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14724 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14725 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14726 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14727 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
14728 UF(rfeib, 9900a00, 1, (RRw), rfe),
14729 UF(rfeda, 8100a00, 1, (RRw), rfe),
14730 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
14731 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
14732 UF(rfefa, 9900a00, 1, (RRw), rfe),
14733 UF(rfeea, 8100a00, 1, (RRw), rfe),
14734 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
14735 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14736 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14737 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14738 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14739 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14740 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14741 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14742 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14743 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14744 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14745 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14746 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14747 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14748 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14749 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14750 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14751 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14752 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14753 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14754 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14755 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14756 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14757 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14758 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14759 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14760 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14761 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14762 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
14763 UF(srsib, 9cd0500, 1, (I31w), srs),
14764 UF(srsda, 84d0500, 1, (I31w), srs),
14765 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
14766 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
14767 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
14768 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
14769 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14770 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14771 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
14773 #undef ARM_VARIANT
14774 #define ARM_VARIANT &arm_ext_v6k
14775 #undef THUMB_VARIANT
14776 #define THUMB_VARIANT &arm_ext_v6k
14777 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
14778 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
14779 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
14780 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
14782 #undef THUMB_VARIANT
14783 #define THUMB_VARIANT &arm_ext_v6_notm
14784 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
14785 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
14787 #undef THUMB_VARIANT
14788 #define THUMB_VARIANT &arm_ext_v6t2
14789 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
14790 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
14791 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
14792 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
14793 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
14795 #undef ARM_VARIANT
14796 #define ARM_VARIANT &arm_ext_v6z
14797 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
14799 #undef ARM_VARIANT
14800 #define ARM_VARIANT &arm_ext_v6t2
14801 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
14802 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
14803 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
14804 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
14806 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
14807 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
14808 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
14809 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
14811 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14812 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14813 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14814 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14816 UT(cbnz, b900, 2, (RR, EXP), t_czb),
14817 UT(cbz, b100, 2, (RR, EXP), t_czb),
14818 /* ARM does not really have an IT instruction, so always allow it. */
14819 #undef ARM_VARIANT
14820 #define ARM_VARIANT &arm_ext_v1
14821 TUE(it, 0, bf08, 1, (COND), it, t_it),
14822 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
14823 TUE(ite, 0, bf04, 1, (COND), it, t_it),
14824 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
14825 TUE(itet, 0, bf06, 1, (COND), it, t_it),
14826 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
14827 TUE(itee, 0, bf02, 1, (COND), it, t_it),
14828 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
14829 TUE(itett, 0, bf07, 1, (COND), it, t_it),
14830 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
14831 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
14832 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
14833 TUE(itete, 0, bf05, 1, (COND), it, t_it),
14834 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
14835 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
14837 /* Thumb2 only instructions. */
14838 #undef ARM_VARIANT
14839 #define ARM_VARIANT NULL
14841 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
14842 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
14843 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
14844 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
14846 /* Thumb-2 hardware division instructions (R and M profiles only). */
14847 #undef THUMB_VARIANT
14848 #define THUMB_VARIANT &arm_ext_div
14849 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
14850 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
14852 /* ARM V7 instructions. */
14853 #undef ARM_VARIANT
14854 #define ARM_VARIANT &arm_ext_v7
14855 #undef THUMB_VARIANT
14856 #define THUMB_VARIANT &arm_ext_v7
14857 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
14858 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
14859 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
14860 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
14861 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
14863 #undef ARM_VARIANT
14864 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
14865 cCE(wfs, e200110, 1, (RR), rd),
14866 cCE(rfs, e300110, 1, (RR), rd),
14867 cCE(wfc, e400110, 1, (RR), rd),
14868 cCE(rfc, e500110, 1, (RR), rd),
14870 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
14871 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
14872 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
14873 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
14875 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
14876 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
14877 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
14878 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
14880 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
14881 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
14882 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
14883 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
14884 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
14885 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
14886 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
14887 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
14888 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
14889 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
14890 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
14891 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
14893 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
14894 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
14895 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
14896 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
14897 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
14898 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
14899 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
14900 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
14901 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
14902 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
14903 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
14904 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
14906 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
14907 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
14908 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
14909 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
14910 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
14911 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
14912 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
14913 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
14914 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
14915 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
14916 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
14917 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
14919 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
14920 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
14921 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
14922 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
14923 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
14924 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
14925 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
14926 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
14927 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
14928 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
14929 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
14930 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
14932 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
14933 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
14934 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
14935 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
14936 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
14937 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
14938 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
14939 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
14940 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
14941 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
14942 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
14943 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
14945 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
14946 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
14947 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
14948 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
14949 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
14950 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
14951 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
14952 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
14953 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
14954 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
14955 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
14956 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
14958 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
14959 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
14960 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
14961 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
14962 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
14963 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
14964 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
14965 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
14966 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
14967 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
14968 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
14969 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
14971 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
14972 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
14973 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
14974 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
14975 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
14976 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
14977 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
14978 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
14979 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
14980 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
14981 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
14982 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
14984 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
14985 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
14986 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
14987 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
14988 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
14989 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
14990 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
14991 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
14992 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
14993 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
14994 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
14995 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
14997 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
14998 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
14999 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15000 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15001 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15002 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15003 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15004 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15005 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15006 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15007 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15008 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15010 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15011 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15012 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15013 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15014 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15015 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15016 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15017 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15018 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15019 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15020 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15021 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15023 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15024 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15025 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15026 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15027 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15028 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15029 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15030 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15031 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15032 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15033 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15034 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15036 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15037 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15038 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15039 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15040 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15041 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15042 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15043 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15044 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15045 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15046 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15047 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15049 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15050 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15051 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15052 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15053 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15054 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15055 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15056 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15057 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15058 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15059 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15060 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15062 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15063 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15064 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15065 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15066 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15067 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15068 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15069 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15070 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15071 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15072 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15073 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15075 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15076 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15077 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15078 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15079 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15080 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15081 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15082 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15083 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15084 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15085 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15086 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15088 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15089 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15090 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15091 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15092 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15093 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15094 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15095 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15096 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15097 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15098 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15099 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15101 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15102 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15103 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15104 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15105 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15106 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15107 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15108 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15109 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15110 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15111 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15112 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15114 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15115 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15116 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15117 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15118 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15119 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15120 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15121 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15122 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15123 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15124 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15125 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15127 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15128 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15129 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15130 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15131 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15132 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15133 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15134 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15135 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15136 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15137 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15138 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15140 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15141 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15142 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15143 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15144 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15145 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15146 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15147 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15148 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15149 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15150 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15151 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15153 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15154 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15155 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15156 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15157 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15158 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15159 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15160 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15161 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15162 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15163 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15164 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15166 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15167 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15168 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15169 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15170 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15171 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15172 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15173 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15174 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15175 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15176 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15177 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15179 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15180 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15181 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15182 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15183 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15184 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15185 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15186 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15187 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15188 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15189 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15190 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15192 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15193 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15194 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15195 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15196 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15197 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15198 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15199 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15200 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15201 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15202 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15203 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15205 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15206 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15207 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15208 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15209 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15210 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15211 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15212 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15213 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15214 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15215 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15216 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15218 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15219 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15220 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15221 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15222 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15223 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15224 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15225 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15226 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15227 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15228 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15229 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15231 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15232 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15233 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15234 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15235 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15236 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15237 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15238 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15239 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15240 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15241 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15242 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15244 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15245 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15246 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15247 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15248 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15249 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15250 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15251 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15252 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15253 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15254 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15255 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15257 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
15258 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
15259 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
15260 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15262 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15263 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15264 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15265 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15266 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15267 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15268 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15269 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15270 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15271 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15272 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15273 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
15275 /* The implementation of the FIX instruction is broken on some
15276 assemblers, in that it accepts a precision specifier as well as a
15277 rounding specifier, despite the fact that this is meaningless.
15278 To be more compatible, we accept it as well, though of course it
15279 does not set any bits. */
15280 cCE(fix, e100110, 2, (RR, RF), rd_rm),
15281 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15282 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15283 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15284 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15285 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15286 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15287 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15288 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15289 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15290 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15291 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15292 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
15294 /* Instructions that were new with the real FPA, call them V2. */
15295 #undef ARM_VARIANT
15296 #define ARM_VARIANT &fpu_fpa_ext_v2
15297 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15298 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15299 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15300 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15301 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15302 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15304 #undef ARM_VARIANT
15305 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
15306 /* Moves and type conversions. */
15307 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15308 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15309 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15310 cCE(fmstat, ef1fa10, 0, (), noargs),
15311 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15312 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15313 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15314 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15315 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15316 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15317 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15318 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
15320 /* Memory operations. */
15321 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15322 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15323 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15324 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15325 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15326 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15327 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15328 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15329 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15330 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15331 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15332 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15333 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15334 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15335 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15336 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15337 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15338 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15340 /* Monadic operations. */
15341 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15342 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15343 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
15345 /* Dyadic operations. */
15346 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15347 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15348 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15349 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15350 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15351 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15352 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15353 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15354 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15356 /* Comparisons. */
15357 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15358 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15359 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15360 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
15362 #undef ARM_VARIANT
15363 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
15364 /* Moves and type conversions. */
15365 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15366 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15367 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15368 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15369 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15370 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15371 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
15372 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15373 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15374 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15375 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15376 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15377 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15379 /* Memory operations. */
15380 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15381 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15382 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15383 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15384 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15385 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15386 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15387 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15388 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15389 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15391 /* Monadic operations. */
15392 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15393 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15394 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15396 /* Dyadic operations. */
15397 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15398 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15399 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15400 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15401 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15402 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15403 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15404 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15405 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15407 /* Comparisons. */
15408 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15409 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15410 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15411 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
15413 #undef ARM_VARIANT
15414 #define ARM_VARIANT &fpu_vfp_ext_v2
15415 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15416 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
15417 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15418 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15420 /* Instructions which may belong to either the Neon or VFP instruction sets.
15421 Individual encoder functions perform additional architecture checks. */
15422 #undef ARM_VARIANT
15423 #define ARM_VARIANT &fpu_vfp_ext_v1xd
15424 #undef THUMB_VARIANT
15425 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
15426 /* These mnemonics are unique to VFP. */
15427 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15428 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15429 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15430 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15431 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15432 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15433 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15434 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15435 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15436 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15438 /* Mnemonics shared by Neon and VFP. */
15439 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15440 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15441 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15443 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15444 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15446 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15447 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15449 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15450 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15451 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15452 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15453 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15454 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15455 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15456 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15458 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15460 /* NOTE: All VMOV encoding is special-cased! */
15461 NCE(vmov, 0, 1, (VMOV), neon_mov),
15462 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15464 #undef THUMB_VARIANT
15465 #define THUMB_VARIANT &fpu_neon_ext_v1
15466 #undef ARM_VARIANT
15467 #define ARM_VARIANT &fpu_neon_ext_v1
15468 /* Data processing with three registers of the same length. */
15469 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15470 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15471 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15472 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15473 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15474 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15475 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15476 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15477 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15478 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15479 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15480 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15481 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15482 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15483 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15484 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15485 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15486 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15487 /* If not immediate, fall back to neon_dyadic_i64_su.
15488 shl_imm should accept I8 I16 I32 I64,
15489 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15490 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15491 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15492 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15493 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15494 /* Logic ops, types optional & ignored. */
15495 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15496 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15497 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15498 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15499 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15500 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15501 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15502 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15503 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15504 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15505 /* Bitfield ops, untyped. */
15506 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15507 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15508 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15509 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15510 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15511 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15512 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15513 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15514 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15515 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15516 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15517 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15518 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15519 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15520 back to neon_dyadic_if_su. */
15521 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15522 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15523 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15524 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15525 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15526 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15527 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15528 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15529 /* Comparison. Type I8 I16 I32 F32. */
15530 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
15531 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
15532 /* As above, D registers only. */
15533 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15534 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15535 /* Int and float variants, signedness unimportant. */
15536 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15537 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15538 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
15539 /* Add/sub take types I8 I16 I32 I64 F32. */
15540 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15541 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15542 /* vtst takes sizes 8, 16, 32. */
15543 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
15544 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
15545 /* VMUL takes I8 I16 I32 F32 P8. */
15546 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
15547 /* VQD{R}MULH takes S16 S32. */
15548 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15549 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15550 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15551 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15552 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15553 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
15554 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15555 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
15556 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15557 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
15558 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15559 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
15560 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
15561 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
15562 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
15563 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
15565 /* Two address, int/float. Types S8 S16 S32 F32. */
15566 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
15567 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
15569 /* Data processing with two registers and a shift amount. */
15570 /* Right shifts, and variants with rounding.
15571 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
15572 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
15573 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
15574 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
15575 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
15576 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
15577 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
15578 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
15579 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
15580 /* Shift and insert. Sizes accepted 8 16 32 64. */
15581 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
15582 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
15583 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
15584 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
15585 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
15586 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
15587 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
15588 /* Right shift immediate, saturating & narrowing, with rounding variants.
15589 Types accepted S16 S32 S64 U16 U32 U64. */
15590 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
15591 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
15592 /* As above, unsigned. Types accepted S16 S32 S64. */
15593 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
15594 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
15595 /* Right shift narrowing. Types accepted I16 I32 I64. */
15596 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
15597 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
15598 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
15599 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
15600 /* CVT with optional immediate for fixed-point variant. */
15601 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
15603 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
15604 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
15606 /* Data processing, three registers of different lengths. */
15607 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
15608 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
15609 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
15610 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
15611 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
15612 /* If not scalar, fall back to neon_dyadic_long.
15613 Vector types as above, scalar types S16 S32 U16 U32. */
15614 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
15615 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
15616 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
15617 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
15618 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
15619 /* Dyadic, narrowing insns. Types I16 I32 I64. */
15620 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15621 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15622 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15623 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15624 /* Saturating doubling multiplies. Types S16 S32. */
15625 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15626 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15627 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15628 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
15629 S16 S32 U16 U32. */
15630 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
15632 /* Extract. Size 8. */
15633 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I7), neon_ext),
15634 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I7), neon_ext),
15636 /* Two registers, miscellaneous. */
15637 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
15638 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
15639 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
15640 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
15641 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
15642 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
15643 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
15644 /* Vector replicate. Sizes 8 16 32. */
15645 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
15646 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
15647 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
15648 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
15649 /* VMOVN. Types I16 I32 I64. */
15650 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
15651 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
15652 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
15653 /* VQMOVUN. Types S16 S32 S64. */
15654 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
15655 /* VZIP / VUZP. Sizes 8 16 32. */
15656 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
15657 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
15658 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
15659 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
15660 /* VQABS / VQNEG. Types S8 S16 S32. */
15661 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
15662 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
15663 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
15664 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
15665 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
15666 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
15667 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
15668 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
15669 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
15670 /* Reciprocal estimates. Types U32 F32. */
15671 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
15672 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
15673 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
15674 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
15675 /* VCLS. Types S8 S16 S32. */
15676 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
15677 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
15678 /* VCLZ. Types I8 I16 I32. */
15679 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
15680 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
15681 /* VCNT. Size 8. */
15682 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
15683 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
15684 /* Two address, untyped. */
15685 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
15686 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
15687 /* VTRN. Sizes 8 16 32. */
15688 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
15689 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
15691 /* Table lookup. Size 8. */
15692 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
15693 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
15695 #undef THUMB_VARIANT
15696 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
15697 #undef ARM_VARIANT
15698 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
15699 /* Neon element/structure load/store. */
15700 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
15701 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
15702 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
15703 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
15704 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
15705 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
15706 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
15707 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
15709 #undef THUMB_VARIANT
15710 #define THUMB_VARIANT &fpu_vfp_ext_v3
15711 #undef ARM_VARIANT
15712 #define ARM_VARIANT &fpu_vfp_ext_v3
15713 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
15714 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
15715 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15716 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15717 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15718 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15719 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15720 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15721 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15722 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15723 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15724 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15725 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15726 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15727 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15728 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15729 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15730 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15732 #undef THUMB_VARIANT
15733 #undef ARM_VARIANT
15734 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
15735 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15736 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15737 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15738 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15739 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15740 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15741 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
15742 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
15744 #undef ARM_VARIANT
15745 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
15746 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
15747 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
15748 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
15749 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
15750 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
15751 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
15752 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
15753 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
15754 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
15755 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15756 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15757 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15758 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15759 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15760 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15761 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15762 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15763 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15764 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
15765 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
15766 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15767 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15768 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15769 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15770 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15771 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15772 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
15773 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
15774 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
15775 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
15776 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
15777 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
15778 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
15779 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
15780 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
15781 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
15782 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
15783 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15784 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15785 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15786 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15787 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15788 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15789 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15790 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15791 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15792 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
15793 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15794 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15795 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15796 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15797 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15798 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15799 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15800 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15801 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15802 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15803 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15804 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15805 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15806 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15807 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15808 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15809 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15810 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15811 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15812 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15813 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15814 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
15815 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
15816 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15817 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15818 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15819 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15820 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15821 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15822 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15823 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15824 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15825 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15826 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15827 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15828 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15829 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15830 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15831 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15832 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15833 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15834 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
15835 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15836 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15837 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15838 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15839 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15840 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15841 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15842 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15843 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15844 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15845 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15846 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15847 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15848 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15849 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15850 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15851 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15852 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15853 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15854 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15855 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15856 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
15857 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15858 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15859 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15860 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15861 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15862 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15863 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15864 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15865 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15866 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15867 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15868 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15869 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15870 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15871 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15872 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15873 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15874 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15875 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15876 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15877 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
15878 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
15879 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15880 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15881 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15882 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15883 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15884 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15885 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15886 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15887 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15888 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
15889 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
15890 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
15891 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
15892 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
15893 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
15894 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15895 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15896 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15897 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
15898 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
15899 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
15900 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
15901 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
15902 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
15903 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15904 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15905 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15906 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15907 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
15909 #undef ARM_VARIANT
15910 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
15911 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
15912 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
15913 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
15914 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
15915 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
15916 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
15917 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
15918 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
15919 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
15920 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
15921 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
15922 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
15923 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
15924 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
15925 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
15926 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
15927 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
15928 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
15929 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
15930 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
15931 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
15932 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
15933 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
15934 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
15935 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
15936 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
15937 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
15938 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
15939 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
15940 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
15941 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
15942 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
15943 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
15944 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
15945 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
15946 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
15947 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
15948 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
15949 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
15950 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
15951 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
15952 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
15953 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
15954 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
15955 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
15956 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
15957 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
15958 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
15959 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
15960 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
15961 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
15962 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
15963 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
15964 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
15965 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
15966 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
15967 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
15968 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
15969 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
15970 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
15971 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
15972 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
15973 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
15974 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
15975 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15976 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
15977 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15978 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
15979 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15980 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
15981 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15982 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15983 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
15984 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
15985 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
15986 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
15988 #undef ARM_VARIANT
15989 #undef THUMB_VARIANT
15990 #undef TCE
15991 #undef TCM
15992 #undef TUE
15993 #undef TUF
15994 #undef TCC
15995 #undef cCE
15996 #undef cCL
15997 #undef C3E
15998 #undef CE
15999 #undef CM
16000 #undef UE
16001 #undef UF
16002 #undef UT
16003 #undef NUF
16004 #undef nUF
16005 #undef NCE
16006 #undef nCE
16007 #undef OPS0
16008 #undef OPS1
16009 #undef OPS2
16010 #undef OPS3
16011 #undef OPS4
16012 #undef OPS5
16013 #undef OPS6
16014 #undef do_0
16016 /* MD interface: bits in the object file. */
16018 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16019 for use in the a.out file, and stores them in the array pointed to by buf.
16020 This knows about the endian-ness of the target machine and does
16021 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16022 2 (short) and 4 (long) Floating numbers are put out as a series of
16023 LITTLENUMS (shorts, here at least). */
16025 void
16026 md_number_to_chars (char * buf, valueT val, int n)
16028 if (target_big_endian)
16029 number_to_chars_bigendian (buf, val, n);
16030 else
16031 number_to_chars_littleendian (buf, val, n);
16034 static valueT
16035 md_chars_to_number (char * buf, int n)
16037 valueT result = 0;
16038 unsigned char * where = (unsigned char *) buf;
16040 if (target_big_endian)
16042 while (n--)
16044 result <<= 8;
16045 result |= (*where++ & 255);
16048 else
16050 while (n--)
16052 result <<= 8;
16053 result |= (where[n] & 255);
16057 return result;
16060 /* MD interface: Sections. */
16062 /* Estimate the size of a frag before relaxing. Assume everything fits in
16063 2 bytes. */
16066 md_estimate_size_before_relax (fragS * fragp,
16067 segT segtype ATTRIBUTE_UNUSED)
16069 fragp->fr_var = 2;
16070 return 2;
16073 /* Convert a machine dependent frag. */
16075 void
16076 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16078 unsigned long insn;
16079 unsigned long old_op;
16080 char *buf;
16081 expressionS exp;
16082 fixS *fixp;
16083 int reloc_type;
16084 int pc_rel;
16085 int opcode;
16087 buf = fragp->fr_literal + fragp->fr_fix;
16089 old_op = bfd_get_16(abfd, buf);
16090 if (fragp->fr_symbol) {
16091 exp.X_op = O_symbol;
16092 exp.X_add_symbol = fragp->fr_symbol;
16093 } else {
16094 exp.X_op = O_constant;
16096 exp.X_add_number = fragp->fr_offset;
16097 opcode = fragp->fr_subtype;
16098 switch (opcode)
16100 case T_MNEM_ldr_pc:
16101 case T_MNEM_ldr_pc2:
16102 case T_MNEM_ldr_sp:
16103 case T_MNEM_str_sp:
16104 case T_MNEM_ldr:
16105 case T_MNEM_ldrb:
16106 case T_MNEM_ldrh:
16107 case T_MNEM_str:
16108 case T_MNEM_strb:
16109 case T_MNEM_strh:
16110 if (fragp->fr_var == 4)
16112 insn = THUMB_OP32(opcode);
16113 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16115 insn |= (old_op & 0x700) << 4;
16117 else
16119 insn |= (old_op & 7) << 12;
16120 insn |= (old_op & 0x38) << 13;
16122 insn |= 0x00000c00;
16123 put_thumb32_insn (buf, insn);
16124 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16126 else
16128 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16130 pc_rel = (opcode == T_MNEM_ldr_pc2);
16131 break;
16132 case T_MNEM_adr:
16133 if (fragp->fr_var == 4)
16135 insn = THUMB_OP32 (opcode);
16136 insn |= (old_op & 0xf0) << 4;
16137 put_thumb32_insn (buf, insn);
16138 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16140 else
16142 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16143 exp.X_add_number -= 4;
16145 pc_rel = 1;
16146 break;
16147 case T_MNEM_mov:
16148 case T_MNEM_movs:
16149 case T_MNEM_cmp:
16150 case T_MNEM_cmn:
16151 if (fragp->fr_var == 4)
16153 int r0off = (opcode == T_MNEM_mov
16154 || opcode == T_MNEM_movs) ? 0 : 8;
16155 insn = THUMB_OP32 (opcode);
16156 insn = (insn & 0xe1ffffff) | 0x10000000;
16157 insn |= (old_op & 0x700) << r0off;
16158 put_thumb32_insn (buf, insn);
16159 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16161 else
16163 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16165 pc_rel = 0;
16166 break;
16167 case T_MNEM_b:
16168 if (fragp->fr_var == 4)
16170 insn = THUMB_OP32(opcode);
16171 put_thumb32_insn (buf, insn);
16172 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16174 else
16175 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16176 pc_rel = 1;
16177 break;
16178 case T_MNEM_bcond:
16179 if (fragp->fr_var == 4)
16181 insn = THUMB_OP32(opcode);
16182 insn |= (old_op & 0xf00) << 14;
16183 put_thumb32_insn (buf, insn);
16184 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16186 else
16187 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16188 pc_rel = 1;
16189 break;
16190 case T_MNEM_add_sp:
16191 case T_MNEM_add_pc:
16192 case T_MNEM_inc_sp:
16193 case T_MNEM_dec_sp:
16194 if (fragp->fr_var == 4)
16196 /* ??? Choose between add and addw. */
16197 insn = THUMB_OP32 (opcode);
16198 insn |= (old_op & 0xf0) << 4;
16199 put_thumb32_insn (buf, insn);
16200 if (opcode == T_MNEM_add_pc)
16201 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16202 else
16203 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16205 else
16206 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16207 pc_rel = 0;
16208 break;
16210 case T_MNEM_addi:
16211 case T_MNEM_addis:
16212 case T_MNEM_subi:
16213 case T_MNEM_subis:
16214 if (fragp->fr_var == 4)
16216 insn = THUMB_OP32 (opcode);
16217 insn |= (old_op & 0xf0) << 4;
16218 insn |= (old_op & 0xf) << 16;
16219 put_thumb32_insn (buf, insn);
16220 if (insn & (1 << 20))
16221 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16222 else
16223 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16225 else
16226 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16227 pc_rel = 0;
16228 break;
16229 default:
16230 abort();
16232 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16233 reloc_type);
16234 fixp->fx_file = fragp->fr_file;
16235 fixp->fx_line = fragp->fr_line;
16236 fragp->fr_fix += fragp->fr_var;
16239 /* Return the size of a relaxable immediate operand instruction.
16240 SHIFT and SIZE specify the form of the allowable immediate. */
16241 static int
16242 relax_immediate (fragS *fragp, int size, int shift)
16244 offsetT offset;
16245 offsetT mask;
16246 offsetT low;
16248 /* ??? Should be able to do better than this. */
16249 if (fragp->fr_symbol)
16250 return 4;
16252 low = (1 << shift) - 1;
16253 mask = (1 << (shift + size)) - (1 << shift);
16254 offset = fragp->fr_offset;
16255 /* Force misaligned offsets to 32-bit variant. */
16256 if (offset & low)
16257 return -4;
16258 if (offset & ~mask)
16259 return 4;
16260 return 2;
16263 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
16264 load. */
16265 static int
16266 relax_adr (fragS *fragp, asection *sec)
16268 addressT addr;
16269 offsetT val;
16271 /* Assume worst case for symbols not known to be in the same section. */
16272 if (!S_IS_DEFINED(fragp->fr_symbol)
16273 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16274 return 4;
16276 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
16277 addr = fragp->fr_address + fragp->fr_fix;
16278 addr = (addr + 4) & ~3;
16279 /* Fix the insn as the 4-byte version if the target address is not
16280 sufficiently aligned. This is prevents an infinite loop when two
16281 instructions have contradictory range/alignment requirements. */
16282 if (val & 3)
16283 return -4;
16284 val -= addr;
16285 if (val < 0 || val > 1020)
16286 return 4;
16287 return 2;
16290 /* Return the size of a relaxable add/sub immediate instruction. */
16291 static int
16292 relax_addsub (fragS *fragp, asection *sec)
16294 char *buf;
16295 int op;
16297 buf = fragp->fr_literal + fragp->fr_fix;
16298 op = bfd_get_16(sec->owner, buf);
16299 if ((op & 0xf) == ((op >> 4) & 0xf))
16300 return relax_immediate (fragp, 8, 0);
16301 else
16302 return relax_immediate (fragp, 3, 0);
16306 /* Return the size of a relaxable branch instruction. BITS is the
16307 size of the offset field in the narrow instruction. */
16309 static int
16310 relax_branch (fragS *fragp, asection *sec, int bits)
16312 addressT addr;
16313 offsetT val;
16314 offsetT limit;
16316 /* Assume worst case for symbols not known to be in the same section. */
16317 if (!S_IS_DEFINED(fragp->fr_symbol)
16318 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16319 return 4;
16321 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
16322 addr = fragp->fr_address + fragp->fr_fix + 4;
16323 val -= addr;
16325 /* Offset is a signed value *2 */
16326 limit = 1 << bits;
16327 if (val >= limit || val < -limit)
16328 return 4;
16329 return 2;
16333 /* Relax a machine dependent frag. This returns the amount by which
16334 the current size of the frag should change. */
16337 arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED)
16339 int oldsize;
16340 int newsize;
16342 oldsize = fragp->fr_var;
16343 switch (fragp->fr_subtype)
16345 case T_MNEM_ldr_pc2:
16346 newsize = relax_adr(fragp, sec);
16347 break;
16348 case T_MNEM_ldr_pc:
16349 case T_MNEM_ldr_sp:
16350 case T_MNEM_str_sp:
16351 newsize = relax_immediate(fragp, 8, 2);
16352 break;
16353 case T_MNEM_ldr:
16354 case T_MNEM_str:
16355 newsize = relax_immediate(fragp, 5, 2);
16356 break;
16357 case T_MNEM_ldrh:
16358 case T_MNEM_strh:
16359 newsize = relax_immediate(fragp, 5, 1);
16360 break;
16361 case T_MNEM_ldrb:
16362 case T_MNEM_strb:
16363 newsize = relax_immediate(fragp, 5, 0);
16364 break;
16365 case T_MNEM_adr:
16366 newsize = relax_adr(fragp, sec);
16367 break;
16368 case T_MNEM_mov:
16369 case T_MNEM_movs:
16370 case T_MNEM_cmp:
16371 case T_MNEM_cmn:
16372 newsize = relax_immediate(fragp, 8, 0);
16373 break;
16374 case T_MNEM_b:
16375 newsize = relax_branch(fragp, sec, 11);
16376 break;
16377 case T_MNEM_bcond:
16378 newsize = relax_branch(fragp, sec, 8);
16379 break;
16380 case T_MNEM_add_sp:
16381 case T_MNEM_add_pc:
16382 newsize = relax_immediate (fragp, 8, 2);
16383 break;
16384 case T_MNEM_inc_sp:
16385 case T_MNEM_dec_sp:
16386 newsize = relax_immediate (fragp, 7, 2);
16387 break;
16388 case T_MNEM_addi:
16389 case T_MNEM_addis:
16390 case T_MNEM_subi:
16391 case T_MNEM_subis:
16392 newsize = relax_addsub (fragp, sec);
16393 break;
16394 default:
16395 abort();
16397 if (newsize < 0)
16399 fragp->fr_var = -newsize;
16400 md_convert_frag (sec->owner, sec, fragp);
16401 frag_wane(fragp);
16402 return -(newsize + oldsize);
16404 fragp->fr_var = newsize;
16405 return newsize - oldsize;
16408 /* Round up a section size to the appropriate boundary. */
16410 valueT
16411 md_section_align (segT segment ATTRIBUTE_UNUSED,
16412 valueT size)
16414 #ifdef OBJ_ELF
16415 return size;
16416 #else
16417 /* Round all sects to multiple of 4. */
16418 return (size + 3) & ~3;
16419 #endif
16422 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
16423 of an rs_align_code fragment. */
16425 void
16426 arm_handle_align (fragS * fragP)
16428 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
16429 static char const thumb_noop[2] = { 0xc0, 0x46 };
16430 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
16431 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
16433 int bytes, fix, noop_size;
16434 char * p;
16435 const char * noop;
16437 if (fragP->fr_type != rs_align_code)
16438 return;
16440 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
16441 p = fragP->fr_literal + fragP->fr_fix;
16442 fix = 0;
16444 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
16445 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
16447 if (fragP->tc_frag_data)
16449 if (target_big_endian)
16450 noop = thumb_bigend_noop;
16451 else
16452 noop = thumb_noop;
16453 noop_size = sizeof (thumb_noop);
16455 else
16457 if (target_big_endian)
16458 noop = arm_bigend_noop;
16459 else
16460 noop = arm_noop;
16461 noop_size = sizeof (arm_noop);
16464 if (bytes & (noop_size - 1))
16466 fix = bytes & (noop_size - 1);
16467 memset (p, 0, fix);
16468 p += fix;
16469 bytes -= fix;
16472 while (bytes >= noop_size)
16474 memcpy (p, noop, noop_size);
16475 p += noop_size;
16476 bytes -= noop_size;
16477 fix += noop_size;
16480 fragP->fr_fix += fix;
16481 fragP->fr_var = noop_size;
16484 /* Called from md_do_align. Used to create an alignment
16485 frag in a code section. */
16487 void
16488 arm_frag_align_code (int n, int max)
16490 char * p;
16492 /* We assume that there will never be a requirement
16493 to support alignments greater than 32 bytes. */
16494 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
16495 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
16497 p = frag_var (rs_align_code,
16498 MAX_MEM_FOR_RS_ALIGN_CODE,
16500 (relax_substateT) max,
16501 (symbolS *) NULL,
16502 (offsetT) n,
16503 (char *) NULL);
16504 *p = 0;
16507 /* Perform target specific initialisation of a frag. */
16509 void
16510 arm_init_frag (fragS * fragP)
16512 /* Record whether this frag is in an ARM or a THUMB area. */
16513 fragP->tc_frag_data = thumb_mode;
16516 #ifdef OBJ_ELF
16517 /* When we change sections we need to issue a new mapping symbol. */
16519 void
16520 arm_elf_change_section (void)
16522 flagword flags;
16523 segment_info_type *seginfo;
16525 /* Link an unlinked unwind index table section to the .text section. */
16526 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
16527 && elf_linked_to_section (now_seg) == NULL)
16528 elf_linked_to_section (now_seg) = text_section;
16530 if (!SEG_NORMAL (now_seg))
16531 return;
16533 flags = bfd_get_section_flags (stdoutput, now_seg);
16535 /* We can ignore sections that only contain debug info. */
16536 if ((flags & SEC_ALLOC) == 0)
16537 return;
16539 seginfo = seg_info (now_seg);
16540 mapstate = seginfo->tc_segment_info_data.mapstate;
16541 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
16545 arm_elf_section_type (const char * str, size_t len)
16547 if (len == 5 && strncmp (str, "exidx", 5) == 0)
16548 return SHT_ARM_EXIDX;
16550 return -1;
16553 /* Code to deal with unwinding tables. */
16555 static void add_unwind_adjustsp (offsetT);
16557 /* Cenerate and deferred unwind frame offset. */
16559 static void
16560 flush_pending_unwind (void)
16562 offsetT offset;
16564 offset = unwind.pending_offset;
16565 unwind.pending_offset = 0;
16566 if (offset != 0)
16567 add_unwind_adjustsp (offset);
16570 /* Add an opcode to this list for this function. Two-byte opcodes should
16571 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
16572 order. */
16574 static void
16575 add_unwind_opcode (valueT op, int length)
16577 /* Add any deferred stack adjustment. */
16578 if (unwind.pending_offset)
16579 flush_pending_unwind ();
16581 unwind.sp_restored = 0;
16583 if (unwind.opcode_count + length > unwind.opcode_alloc)
16585 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
16586 if (unwind.opcodes)
16587 unwind.opcodes = xrealloc (unwind.opcodes,
16588 unwind.opcode_alloc);
16589 else
16590 unwind.opcodes = xmalloc (unwind.opcode_alloc);
16592 while (length > 0)
16594 length--;
16595 unwind.opcodes[unwind.opcode_count] = op & 0xff;
16596 op >>= 8;
16597 unwind.opcode_count++;
16601 /* Add unwind opcodes to adjust the stack pointer. */
16603 static void
16604 add_unwind_adjustsp (offsetT offset)
16606 valueT op;
16608 if (offset > 0x200)
16610 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
16611 char bytes[5];
16612 int n;
16613 valueT o;
16615 /* Long form: 0xb2, uleb128. */
16616 /* This might not fit in a word so add the individual bytes,
16617 remembering the list is built in reverse order. */
16618 o = (valueT) ((offset - 0x204) >> 2);
16619 if (o == 0)
16620 add_unwind_opcode (0, 1);
16622 /* Calculate the uleb128 encoding of the offset. */
16623 n = 0;
16624 while (o)
16626 bytes[n] = o & 0x7f;
16627 o >>= 7;
16628 if (o)
16629 bytes[n] |= 0x80;
16630 n++;
16632 /* Add the insn. */
16633 for (; n; n--)
16634 add_unwind_opcode (bytes[n - 1], 1);
16635 add_unwind_opcode (0xb2, 1);
16637 else if (offset > 0x100)
16639 /* Two short opcodes. */
16640 add_unwind_opcode (0x3f, 1);
16641 op = (offset - 0x104) >> 2;
16642 add_unwind_opcode (op, 1);
16644 else if (offset > 0)
16646 /* Short opcode. */
16647 op = (offset - 4) >> 2;
16648 add_unwind_opcode (op, 1);
16650 else if (offset < 0)
16652 offset = -offset;
16653 while (offset > 0x100)
16655 add_unwind_opcode (0x7f, 1);
16656 offset -= 0x100;
16658 op = ((offset - 4) >> 2) | 0x40;
16659 add_unwind_opcode (op, 1);
16663 /* Finish the list of unwind opcodes for this function. */
16664 static void
16665 finish_unwind_opcodes (void)
16667 valueT op;
16669 if (unwind.fp_used)
16671 /* Adjust sp as neccessary. */
16672 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
16673 flush_pending_unwind ();
16675 /* After restoring sp from the frame pointer. */
16676 op = 0x90 | unwind.fp_reg;
16677 add_unwind_opcode (op, 1);
16679 else
16680 flush_pending_unwind ();
16684 /* Start an exception table entry. If idx is nonzero this is an index table
16685 entry. */
16687 static void
16688 start_unwind_section (const segT text_seg, int idx)
16690 const char * text_name;
16691 const char * prefix;
16692 const char * prefix_once;
16693 const char * group_name;
16694 size_t prefix_len;
16695 size_t text_len;
16696 char * sec_name;
16697 size_t sec_name_len;
16698 int type;
16699 int flags;
16700 int linkonce;
16702 if (idx)
16704 prefix = ELF_STRING_ARM_unwind;
16705 prefix_once = ELF_STRING_ARM_unwind_once;
16706 type = SHT_ARM_EXIDX;
16708 else
16710 prefix = ELF_STRING_ARM_unwind_info;
16711 prefix_once = ELF_STRING_ARM_unwind_info_once;
16712 type = SHT_PROGBITS;
16715 text_name = segment_name (text_seg);
16716 if (streq (text_name, ".text"))
16717 text_name = "";
16719 if (strncmp (text_name, ".gnu.linkonce.t.",
16720 strlen (".gnu.linkonce.t.")) == 0)
16722 prefix = prefix_once;
16723 text_name += strlen (".gnu.linkonce.t.");
16726 prefix_len = strlen (prefix);
16727 text_len = strlen (text_name);
16728 sec_name_len = prefix_len + text_len;
16729 sec_name = xmalloc (sec_name_len + 1);
16730 memcpy (sec_name, prefix, prefix_len);
16731 memcpy (sec_name + prefix_len, text_name, text_len);
16732 sec_name[prefix_len + text_len] = '\0';
16734 flags = SHF_ALLOC;
16735 linkonce = 0;
16736 group_name = 0;
16738 /* Handle COMDAT group. */
16739 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
16741 group_name = elf_group_name (text_seg);
16742 if (group_name == NULL)
16744 as_bad ("Group section `%s' has no group signature",
16745 segment_name (text_seg));
16746 ignore_rest_of_line ();
16747 return;
16749 flags |= SHF_GROUP;
16750 linkonce = 1;
16753 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
16755 /* Set the setion link for index tables. */
16756 if (idx)
16757 elf_linked_to_section (now_seg) = text_seg;
16761 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
16762 personality routine data. Returns zero, or the index table value for
16763 and inline entry. */
16765 static valueT
16766 create_unwind_entry (int have_data)
16768 int size;
16769 addressT where;
16770 char *ptr;
16771 /* The current word of data. */
16772 valueT data;
16773 /* The number of bytes left in this word. */
16774 int n;
16776 finish_unwind_opcodes ();
16778 /* Remember the current text section. */
16779 unwind.saved_seg = now_seg;
16780 unwind.saved_subseg = now_subseg;
16782 start_unwind_section (now_seg, 0);
16784 if (unwind.personality_routine == NULL)
16786 if (unwind.personality_index == -2)
16788 if (have_data)
16789 as_bad (_("handerdata in cantunwind frame"));
16790 return 1; /* EXIDX_CANTUNWIND. */
16793 /* Use a default personality routine if none is specified. */
16794 if (unwind.personality_index == -1)
16796 if (unwind.opcode_count > 3)
16797 unwind.personality_index = 1;
16798 else
16799 unwind.personality_index = 0;
16802 /* Space for the personality routine entry. */
16803 if (unwind.personality_index == 0)
16805 if (unwind.opcode_count > 3)
16806 as_bad (_("too many unwind opcodes for personality routine 0"));
16808 if (!have_data)
16810 /* All the data is inline in the index table. */
16811 data = 0x80;
16812 n = 3;
16813 while (unwind.opcode_count > 0)
16815 unwind.opcode_count--;
16816 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
16817 n--;
16820 /* Pad with "finish" opcodes. */
16821 while (n--)
16822 data = (data << 8) | 0xb0;
16824 return data;
16826 size = 0;
16828 else
16829 /* We get two opcodes "free" in the first word. */
16830 size = unwind.opcode_count - 2;
16832 else
16833 /* An extra byte is required for the opcode count. */
16834 size = unwind.opcode_count + 1;
16836 size = (size + 3) >> 2;
16837 if (size > 0xff)
16838 as_bad (_("too many unwind opcodes"));
16840 frag_align (2, 0, 0);
16841 record_alignment (now_seg, 2);
16842 unwind.table_entry = expr_build_dot ();
16844 /* Allocate the table entry. */
16845 ptr = frag_more ((size << 2) + 4);
16846 where = frag_now_fix () - ((size << 2) + 4);
16848 switch (unwind.personality_index)
16850 case -1:
16851 /* ??? Should this be a PLT generating relocation? */
16852 /* Custom personality routine. */
16853 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
16854 BFD_RELOC_ARM_PREL31);
16856 where += 4;
16857 ptr += 4;
16859 /* Set the first byte to the number of additional words. */
16860 data = size - 1;
16861 n = 3;
16862 break;
16864 /* ABI defined personality routines. */
16865 case 0:
16866 /* Three opcodes bytes are packed into the first word. */
16867 data = 0x80;
16868 n = 3;
16869 break;
16871 case 1:
16872 case 2:
16873 /* The size and first two opcode bytes go in the first word. */
16874 data = ((0x80 + unwind.personality_index) << 8) | size;
16875 n = 2;
16876 break;
16878 default:
16879 /* Should never happen. */
16880 abort ();
16883 /* Pack the opcodes into words (MSB first), reversing the list at the same
16884 time. */
16885 while (unwind.opcode_count > 0)
16887 if (n == 0)
16889 md_number_to_chars (ptr, data, 4);
16890 ptr += 4;
16891 n = 4;
16892 data = 0;
16894 unwind.opcode_count--;
16895 n--;
16896 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
16899 /* Finish off the last word. */
16900 if (n < 4)
16902 /* Pad with "finish" opcodes. */
16903 while (n--)
16904 data = (data << 8) | 0xb0;
16906 md_number_to_chars (ptr, data, 4);
16909 if (!have_data)
16911 /* Add an empty descriptor if there is no user-specified data. */
16912 ptr = frag_more (4);
16913 md_number_to_chars (ptr, 0, 4);
16916 return 0;
16919 /* Convert REGNAME to a DWARF-2 register number. */
16922 tc_arm_regname_to_dw2regnum (const char *regname)
16924 int reg = arm_reg_parse ((char **) &regname, REG_TYPE_RN);
16926 if (reg == FAIL)
16927 return -1;
16929 return reg;
16932 /* Initialize the DWARF-2 unwind information for this procedure. */
16934 void
16935 tc_arm_frame_initial_instructions (void)
16937 cfi_add_CFA_def_cfa (REG_SP, 0);
16939 #endif /* OBJ_ELF */
16942 /* MD interface: Symbol and relocation handling. */
16944 /* Return the address within the segment that a PC-relative fixup is
16945 relative to. For ARM, PC-relative fixups applied to instructions
16946 are generally relative to the location of the fixup plus 8 bytes.
16947 Thumb branches are offset by 4, and Thumb loads relative to PC
16948 require special handling. */
16950 long
16951 md_pcrel_from_section (fixS * fixP, segT seg)
16953 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
16955 /* If this is pc-relative and we are going to emit a relocation
16956 then we just want to put out any pipeline compensation that the linker
16957 will need. Otherwise we want to use the calculated base. */
16958 if (fixP->fx_pcrel
16959 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
16960 || arm_force_relocation (fixP)))
16961 base = 0;
16963 switch (fixP->fx_r_type)
16965 /* PC relative addressing on the Thumb is slightly odd as the
16966 bottom two bits of the PC are forced to zero for the
16967 calculation. This happens *after* application of the
16968 pipeline offset. However, Thumb adrl already adjusts for
16969 this, so we need not do it again. */
16970 case BFD_RELOC_ARM_THUMB_ADD:
16971 return base & ~3;
16973 case BFD_RELOC_ARM_THUMB_OFFSET:
16974 case BFD_RELOC_ARM_T32_OFFSET_IMM:
16975 case BFD_RELOC_ARM_T32_ADD_PC12:
16976 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
16977 return (base + 4) & ~3;
16979 /* Thumb branches are simply offset by +4. */
16980 case BFD_RELOC_THUMB_PCREL_BRANCH7:
16981 case BFD_RELOC_THUMB_PCREL_BRANCH9:
16982 case BFD_RELOC_THUMB_PCREL_BRANCH12:
16983 case BFD_RELOC_THUMB_PCREL_BRANCH20:
16984 case BFD_RELOC_THUMB_PCREL_BRANCH23:
16985 case BFD_RELOC_THUMB_PCREL_BRANCH25:
16986 case BFD_RELOC_THUMB_PCREL_BLX:
16987 return base + 4;
16989 /* ARM mode branches are offset by +8. However, the Windows CE
16990 loader expects the relocation not to take this into account. */
16991 case BFD_RELOC_ARM_PCREL_BRANCH:
16992 case BFD_RELOC_ARM_PCREL_CALL:
16993 case BFD_RELOC_ARM_PCREL_JUMP:
16994 case BFD_RELOC_ARM_PCREL_BLX:
16995 case BFD_RELOC_ARM_PLT32:
16996 #ifdef TE_WINCE
16997 return base;
16998 #else
16999 return base + 8;
17000 #endif
17002 /* ARM mode loads relative to PC are also offset by +8. Unlike
17003 branches, the Windows CE loader *does* expect the relocation
17004 to take this into account. */
17005 case BFD_RELOC_ARM_OFFSET_IMM:
17006 case BFD_RELOC_ARM_OFFSET_IMM8:
17007 case BFD_RELOC_ARM_HWLITERAL:
17008 case BFD_RELOC_ARM_LITERAL:
17009 case BFD_RELOC_ARM_CP_OFF_IMM:
17010 return base + 8;
17013 /* Other PC-relative relocations are un-offset. */
17014 default:
17015 return base;
17019 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17020 Otherwise we have no need to default values of symbols. */
17022 symbolS *
17023 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
17025 #ifdef OBJ_ELF
17026 if (name[0] == '_' && name[1] == 'G'
17027 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17029 if (!GOT_symbol)
17031 if (symbol_find (name))
17032 as_bad ("GOT already in the symbol table");
17034 GOT_symbol = symbol_new (name, undefined_section,
17035 (valueT) 0, & zero_address_frag);
17038 return GOT_symbol;
17040 #endif
17042 return 0;
17045 /* Subroutine of md_apply_fix. Check to see if an immediate can be
17046 computed as two separate immediate values, added together. We
17047 already know that this value cannot be computed by just one ARM
17048 instruction. */
17050 static unsigned int
17051 validate_immediate_twopart (unsigned int val,
17052 unsigned int * highpart)
17054 unsigned int a;
17055 unsigned int i;
17057 for (i = 0; i < 32; i += 2)
17058 if (((a = rotate_left (val, i)) & 0xff) != 0)
17060 if (a & 0xff00)
17062 if (a & ~ 0xffff)
17063 continue;
17064 * highpart = (a >> 8) | ((i + 24) << 7);
17066 else if (a & 0xff0000)
17068 if (a & 0xff000000)
17069 continue;
17070 * highpart = (a >> 16) | ((i + 16) << 7);
17072 else
17074 assert (a & 0xff000000);
17075 * highpart = (a >> 24) | ((i + 8) << 7);
17078 return (a & 0xff) | (i << 7);
17081 return FAIL;
17084 static int
17085 validate_offset_imm (unsigned int val, int hwse)
17087 if ((hwse && val > 255) || val > 4095)
17088 return FAIL;
17089 return val;
17092 /* Subroutine of md_apply_fix. Do those data_ops which can take a
17093 negative immediate constant by altering the instruction. A bit of
17094 a hack really.
17095 MOV <-> MVN
17096 AND <-> BIC
17097 ADC <-> SBC
17098 by inverting the second operand, and
17099 ADD <-> SUB
17100 CMP <-> CMN
17101 by negating the second operand. */
17103 static int
17104 negate_data_op (unsigned long * instruction,
17105 unsigned long value)
17107 int op, new_inst;
17108 unsigned long negated, inverted;
17110 negated = encode_arm_immediate (-value);
17111 inverted = encode_arm_immediate (~value);
17113 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17114 switch (op)
17116 /* First negates. */
17117 case OPCODE_SUB: /* ADD <-> SUB */
17118 new_inst = OPCODE_ADD;
17119 value = negated;
17120 break;
17122 case OPCODE_ADD:
17123 new_inst = OPCODE_SUB;
17124 value = negated;
17125 break;
17127 case OPCODE_CMP: /* CMP <-> CMN */
17128 new_inst = OPCODE_CMN;
17129 value = negated;
17130 break;
17132 case OPCODE_CMN:
17133 new_inst = OPCODE_CMP;
17134 value = negated;
17135 break;
17137 /* Now Inverted ops. */
17138 case OPCODE_MOV: /* MOV <-> MVN */
17139 new_inst = OPCODE_MVN;
17140 value = inverted;
17141 break;
17143 case OPCODE_MVN:
17144 new_inst = OPCODE_MOV;
17145 value = inverted;
17146 break;
17148 case OPCODE_AND: /* AND <-> BIC */
17149 new_inst = OPCODE_BIC;
17150 value = inverted;
17151 break;
17153 case OPCODE_BIC:
17154 new_inst = OPCODE_AND;
17155 value = inverted;
17156 break;
17158 case OPCODE_ADC: /* ADC <-> SBC */
17159 new_inst = OPCODE_SBC;
17160 value = inverted;
17161 break;
17163 case OPCODE_SBC:
17164 new_inst = OPCODE_ADC;
17165 value = inverted;
17166 break;
17168 /* We cannot do anything. */
17169 default:
17170 return FAIL;
17173 if (value == (unsigned) FAIL)
17174 return FAIL;
17176 *instruction &= OPCODE_MASK;
17177 *instruction |= new_inst << DATA_OP_SHIFT;
17178 return value;
17181 /* Like negate_data_op, but for Thumb-2. */
17183 static unsigned int
17184 thumb32_negate_data_op (offsetT *instruction, offsetT value)
17186 int op, new_inst;
17187 int rd;
17188 offsetT negated, inverted;
17190 negated = encode_thumb32_immediate (-value);
17191 inverted = encode_thumb32_immediate (~value);
17193 rd = (*instruction >> 8) & 0xf;
17194 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17195 switch (op)
17197 /* ADD <-> SUB. Includes CMP <-> CMN. */
17198 case T2_OPCODE_SUB:
17199 new_inst = T2_OPCODE_ADD;
17200 value = negated;
17201 break;
17203 case T2_OPCODE_ADD:
17204 new_inst = T2_OPCODE_SUB;
17205 value = negated;
17206 break;
17208 /* ORR <-> ORN. Includes MOV <-> MVN. */
17209 case T2_OPCODE_ORR:
17210 new_inst = T2_OPCODE_ORN;
17211 value = inverted;
17212 break;
17214 case T2_OPCODE_ORN:
17215 new_inst = T2_OPCODE_ORR;
17216 value = inverted;
17217 break;
17219 /* AND <-> BIC. TST has no inverted equivalent. */
17220 case T2_OPCODE_AND:
17221 new_inst = T2_OPCODE_BIC;
17222 if (rd == 15)
17223 value = FAIL;
17224 else
17225 value = inverted;
17226 break;
17228 case T2_OPCODE_BIC:
17229 new_inst = T2_OPCODE_AND;
17230 value = inverted;
17231 break;
17233 /* ADC <-> SBC */
17234 case T2_OPCODE_ADC:
17235 new_inst = T2_OPCODE_SBC;
17236 value = inverted;
17237 break;
17239 case T2_OPCODE_SBC:
17240 new_inst = T2_OPCODE_ADC;
17241 value = inverted;
17242 break;
17244 /* We cannot do anything. */
17245 default:
17246 return FAIL;
17249 if (value == FAIL)
17250 return FAIL;
17252 *instruction &= T2_OPCODE_MASK;
17253 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17254 return value;
17257 /* Read a 32-bit thumb instruction from buf. */
17258 static unsigned long
17259 get_thumb32_insn (char * buf)
17261 unsigned long insn;
17262 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17263 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17265 return insn;
17269 /* We usually want to set the low bit on the address of thumb function
17270 symbols. In particular .word foo - . should have the low bit set.
17271 Generic code tries to fold the difference of two symbols to
17272 a constant. Prevent this and force a relocation when the first symbols
17273 is a thumb function. */
17275 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17277 if (op == O_subtract
17278 && l->X_op == O_symbol
17279 && r->X_op == O_symbol
17280 && THUMB_IS_FUNC (l->X_add_symbol))
17282 l->X_op = O_subtract;
17283 l->X_op_symbol = r->X_add_symbol;
17284 l->X_add_number -= r->X_add_number;
17285 return 1;
17287 /* Process as normal. */
17288 return 0;
17291 void
17292 md_apply_fix (fixS * fixP,
17293 valueT * valP,
17294 segT seg)
17296 offsetT value = * valP;
17297 offsetT newval;
17298 unsigned int newimm;
17299 unsigned long temp;
17300 int sign;
17301 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
17303 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
17305 /* Note whether this will delete the relocation. */
17307 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17308 fixP->fx_done = 1;
17310 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17311 consistency with the behavior on 32-bit hosts. Remember value
17312 for emit_reloc. */
17313 value &= 0xffffffff;
17314 value ^= 0x80000000;
17315 value -= 0x80000000;
17317 *valP = value;
17318 fixP->fx_addnumber = value;
17320 /* Same treatment for fixP->fx_offset. */
17321 fixP->fx_offset &= 0xffffffff;
17322 fixP->fx_offset ^= 0x80000000;
17323 fixP->fx_offset -= 0x80000000;
17325 switch (fixP->fx_r_type)
17327 case BFD_RELOC_NONE:
17328 /* This will need to go in the object file. */
17329 fixP->fx_done = 0;
17330 break;
17332 case BFD_RELOC_ARM_IMMEDIATE:
17333 /* We claim that this fixup has been processed here,
17334 even if in fact we generate an error because we do
17335 not have a reloc for it, so tc_gen_reloc will reject it. */
17336 fixP->fx_done = 1;
17338 if (fixP->fx_addsy
17339 && ! S_IS_DEFINED (fixP->fx_addsy))
17341 as_bad_where (fixP->fx_file, fixP->fx_line,
17342 _("undefined symbol %s used as an immediate value"),
17343 S_GET_NAME (fixP->fx_addsy));
17344 break;
17347 newimm = encode_arm_immediate (value);
17348 temp = md_chars_to_number (buf, INSN_SIZE);
17350 /* If the instruction will fail, see if we can fix things up by
17351 changing the opcode. */
17352 if (newimm == (unsigned int) FAIL
17353 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
17355 as_bad_where (fixP->fx_file, fixP->fx_line,
17356 _("invalid constant (%lx) after fixup"),
17357 (unsigned long) value);
17358 break;
17361 newimm |= (temp & 0xfffff000);
17362 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17363 break;
17365 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17367 unsigned int highpart = 0;
17368 unsigned int newinsn = 0xe1a00000; /* nop. */
17370 newimm = encode_arm_immediate (value);
17371 temp = md_chars_to_number (buf, INSN_SIZE);
17373 /* If the instruction will fail, see if we can fix things up by
17374 changing the opcode. */
17375 if (newimm == (unsigned int) FAIL
17376 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
17378 /* No ? OK - try using two ADD instructions to generate
17379 the value. */
17380 newimm = validate_immediate_twopart (value, & highpart);
17382 /* Yes - then make sure that the second instruction is
17383 also an add. */
17384 if (newimm != (unsigned int) FAIL)
17385 newinsn = temp;
17386 /* Still No ? Try using a negated value. */
17387 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
17388 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
17389 /* Otherwise - give up. */
17390 else
17392 as_bad_where (fixP->fx_file, fixP->fx_line,
17393 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
17394 (long) value);
17395 break;
17398 /* Replace the first operand in the 2nd instruction (which
17399 is the PC) with the destination register. We have
17400 already added in the PC in the first instruction and we
17401 do not want to do it again. */
17402 newinsn &= ~ 0xf0000;
17403 newinsn |= ((newinsn & 0x0f000) << 4);
17406 newimm |= (temp & 0xfffff000);
17407 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17409 highpart |= (newinsn & 0xfffff000);
17410 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
17412 break;
17414 case BFD_RELOC_ARM_OFFSET_IMM:
17415 if (!fixP->fx_done && seg->use_rela_p)
17416 value = 0;
17418 case BFD_RELOC_ARM_LITERAL:
17419 sign = value >= 0;
17421 if (value < 0)
17422 value = - value;
17424 if (validate_offset_imm (value, 0) == FAIL)
17426 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
17427 as_bad_where (fixP->fx_file, fixP->fx_line,
17428 _("invalid literal constant: pool needs to be closer"));
17429 else
17430 as_bad_where (fixP->fx_file, fixP->fx_line,
17431 _("bad immediate value for offset (%ld)"),
17432 (long) value);
17433 break;
17436 newval = md_chars_to_number (buf, INSN_SIZE);
17437 newval &= 0xff7ff000;
17438 newval |= value | (sign ? INDEX_UP : 0);
17439 md_number_to_chars (buf, newval, INSN_SIZE);
17440 break;
17442 case BFD_RELOC_ARM_OFFSET_IMM8:
17443 case BFD_RELOC_ARM_HWLITERAL:
17444 sign = value >= 0;
17446 if (value < 0)
17447 value = - value;
17449 if (validate_offset_imm (value, 1) == FAIL)
17451 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
17452 as_bad_where (fixP->fx_file, fixP->fx_line,
17453 _("invalid literal constant: pool needs to be closer"));
17454 else
17455 as_bad (_("bad immediate value for half-word offset (%ld)"),
17456 (long) value);
17457 break;
17460 newval = md_chars_to_number (buf, INSN_SIZE);
17461 newval &= 0xff7ff0f0;
17462 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
17463 md_number_to_chars (buf, newval, INSN_SIZE);
17464 break;
17466 case BFD_RELOC_ARM_T32_OFFSET_U8:
17467 if (value < 0 || value > 1020 || value % 4 != 0)
17468 as_bad_where (fixP->fx_file, fixP->fx_line,
17469 _("bad immediate value for offset (%ld)"), (long) value);
17470 value /= 4;
17472 newval = md_chars_to_number (buf+2, THUMB_SIZE);
17473 newval |= value;
17474 md_number_to_chars (buf+2, newval, THUMB_SIZE);
17475 break;
17477 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17478 /* This is a complicated relocation used for all varieties of Thumb32
17479 load/store instruction with immediate offset:
17481 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
17482 *4, optional writeback(W)
17483 (doubleword load/store)
17485 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
17486 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
17487 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
17488 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
17489 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
17491 Uppercase letters indicate bits that are already encoded at
17492 this point. Lowercase letters are our problem. For the
17493 second block of instructions, the secondary opcode nybble
17494 (bits 8..11) is present, and bit 23 is zero, even if this is
17495 a PC-relative operation. */
17496 newval = md_chars_to_number (buf, THUMB_SIZE);
17497 newval <<= 16;
17498 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
17500 if ((newval & 0xf0000000) == 0xe0000000)
17502 /* Doubleword load/store: 8-bit offset, scaled by 4. */
17503 if (value >= 0)
17504 newval |= (1 << 23);
17505 else
17506 value = -value;
17507 if (value % 4 != 0)
17509 as_bad_where (fixP->fx_file, fixP->fx_line,
17510 _("offset not a multiple of 4"));
17511 break;
17513 value /= 4;
17514 if (value > 0xff)
17516 as_bad_where (fixP->fx_file, fixP->fx_line,
17517 _("offset out of range"));
17518 break;
17520 newval &= ~0xff;
17522 else if ((newval & 0x000f0000) == 0x000f0000)
17524 /* PC-relative, 12-bit offset. */
17525 if (value >= 0)
17526 newval |= (1 << 23);
17527 else
17528 value = -value;
17529 if (value > 0xfff)
17531 as_bad_where (fixP->fx_file, fixP->fx_line,
17532 _("offset out of range"));
17533 break;
17535 newval &= ~0xfff;
17537 else if ((newval & 0x00000100) == 0x00000100)
17539 /* Writeback: 8-bit, +/- offset. */
17540 if (value >= 0)
17541 newval |= (1 << 9);
17542 else
17543 value = -value;
17544 if (value > 0xff)
17546 as_bad_where (fixP->fx_file, fixP->fx_line,
17547 _("offset out of range"));
17548 break;
17550 newval &= ~0xff;
17552 else if ((newval & 0x00000f00) == 0x00000e00)
17554 /* T-instruction: positive 8-bit offset. */
17555 if (value < 0 || value > 0xff)
17557 as_bad_where (fixP->fx_file, fixP->fx_line,
17558 _("offset out of range"));
17559 break;
17561 newval &= ~0xff;
17562 newval |= value;
17564 else
17566 /* Positive 12-bit or negative 8-bit offset. */
17567 int limit;
17568 if (value >= 0)
17570 newval |= (1 << 23);
17571 limit = 0xfff;
17573 else
17575 value = -value;
17576 limit = 0xff;
17578 if (value > limit)
17580 as_bad_where (fixP->fx_file, fixP->fx_line,
17581 _("offset out of range"));
17582 break;
17584 newval &= ~limit;
17587 newval |= value;
17588 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
17589 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
17590 break;
17592 case BFD_RELOC_ARM_SHIFT_IMM:
17593 newval = md_chars_to_number (buf, INSN_SIZE);
17594 if (((unsigned long) value) > 32
17595 || (value == 32
17596 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
17598 as_bad_where (fixP->fx_file, fixP->fx_line,
17599 _("shift expression is too large"));
17600 break;
17603 if (value == 0)
17604 /* Shifts of zero must be done as lsl. */
17605 newval &= ~0x60;
17606 else if (value == 32)
17607 value = 0;
17608 newval &= 0xfffff07f;
17609 newval |= (value & 0x1f) << 7;
17610 md_number_to_chars (buf, newval, INSN_SIZE);
17611 break;
17613 case BFD_RELOC_ARM_T32_IMMEDIATE:
17614 case BFD_RELOC_ARM_T32_ADD_IMM:
17615 case BFD_RELOC_ARM_T32_IMM12:
17616 case BFD_RELOC_ARM_T32_ADD_PC12:
17617 /* We claim that this fixup has been processed here,
17618 even if in fact we generate an error because we do
17619 not have a reloc for it, so tc_gen_reloc will reject it. */
17620 fixP->fx_done = 1;
17622 if (fixP->fx_addsy
17623 && ! S_IS_DEFINED (fixP->fx_addsy))
17625 as_bad_where (fixP->fx_file, fixP->fx_line,
17626 _("undefined symbol %s used as an immediate value"),
17627 S_GET_NAME (fixP->fx_addsy));
17628 break;
17631 newval = md_chars_to_number (buf, THUMB_SIZE);
17632 newval <<= 16;
17633 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
17635 newimm = FAIL;
17636 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
17637 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
17639 newimm = encode_thumb32_immediate (value);
17640 if (newimm == (unsigned int) FAIL)
17641 newimm = thumb32_negate_data_op (&newval, value);
17643 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
17644 && newimm == (unsigned int) FAIL)
17646 /* Turn add/sum into addw/subw. */
17647 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
17648 newval = (newval & 0xfeffffff) | 0x02000000;
17650 /* 12 bit immediate for addw/subw. */
17651 if (value < 0)
17653 value = -value;
17654 newval ^= 0x00a00000;
17656 if (value > 0xfff)
17657 newimm = (unsigned int) FAIL;
17658 else
17659 newimm = value;
17662 if (newimm == (unsigned int)FAIL)
17664 as_bad_where (fixP->fx_file, fixP->fx_line,
17665 _("invalid constant (%lx) after fixup"),
17666 (unsigned long) value);
17667 break;
17670 newval |= (newimm & 0x800) << 15;
17671 newval |= (newimm & 0x700) << 4;
17672 newval |= (newimm & 0x0ff);
17674 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
17675 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
17676 break;
17678 case BFD_RELOC_ARM_SMC:
17679 if (((unsigned long) value) > 0xffff)
17680 as_bad_where (fixP->fx_file, fixP->fx_line,
17681 _("invalid smc expression"));
17682 newval = md_chars_to_number (buf, INSN_SIZE);
17683 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
17684 md_number_to_chars (buf, newval, INSN_SIZE);
17685 break;
17687 case BFD_RELOC_ARM_SWI:
17688 if (fixP->tc_fix_data != 0)
17690 if (((unsigned long) value) > 0xff)
17691 as_bad_where (fixP->fx_file, fixP->fx_line,
17692 _("invalid swi expression"));
17693 newval = md_chars_to_number (buf, THUMB_SIZE);
17694 newval |= value;
17695 md_number_to_chars (buf, newval, THUMB_SIZE);
17697 else
17699 if (((unsigned long) value) > 0x00ffffff)
17700 as_bad_where (fixP->fx_file, fixP->fx_line,
17701 _("invalid swi expression"));
17702 newval = md_chars_to_number (buf, INSN_SIZE);
17703 newval |= value;
17704 md_number_to_chars (buf, newval, INSN_SIZE);
17706 break;
17708 case BFD_RELOC_ARM_MULTI:
17709 if (((unsigned long) value) > 0xffff)
17710 as_bad_where (fixP->fx_file, fixP->fx_line,
17711 _("invalid expression in load/store multiple"));
17712 newval = value | md_chars_to_number (buf, INSN_SIZE);
17713 md_number_to_chars (buf, newval, INSN_SIZE);
17714 break;
17716 #ifdef OBJ_ELF
17717 case BFD_RELOC_ARM_PCREL_CALL:
17718 newval = md_chars_to_number (buf, INSN_SIZE);
17719 if ((newval & 0xf0000000) == 0xf0000000)
17720 temp = 1;
17721 else
17722 temp = 3;
17723 goto arm_branch_common;
17725 case BFD_RELOC_ARM_PCREL_JUMP:
17726 case BFD_RELOC_ARM_PLT32:
17727 #endif
17728 case BFD_RELOC_ARM_PCREL_BRANCH:
17729 temp = 3;
17730 goto arm_branch_common;
17732 case BFD_RELOC_ARM_PCREL_BLX:
17733 temp = 1;
17734 arm_branch_common:
17735 /* We are going to store value (shifted right by two) in the
17736 instruction, in a 24 bit, signed field. Bits 26 through 32 either
17737 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
17738 also be be clear. */
17739 if (value & temp)
17740 as_bad_where (fixP->fx_file, fixP->fx_line,
17741 _("misaligned branch destination"));
17742 if ((value & (offsetT)0xfe000000) != (offsetT)0
17743 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
17744 as_bad_where (fixP->fx_file, fixP->fx_line,
17745 _("branch out of range"));
17747 if (fixP->fx_done || !seg->use_rela_p)
17749 newval = md_chars_to_number (buf, INSN_SIZE);
17750 newval |= (value >> 2) & 0x00ffffff;
17751 /* Set the H bit on BLX instructions. */
17752 if (temp == 1)
17754 if (value & 2)
17755 newval |= 0x01000000;
17756 else
17757 newval &= ~0x01000000;
17759 md_number_to_chars (buf, newval, INSN_SIZE);
17761 break;
17763 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
17764 /* CZB can only branch forward. */
17765 if (value & ~0x7e)
17766 as_bad_where (fixP->fx_file, fixP->fx_line,
17767 _("branch out of range"));
17769 if (fixP->fx_done || !seg->use_rela_p)
17771 newval = md_chars_to_number (buf, THUMB_SIZE);
17772 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
17773 md_number_to_chars (buf, newval, THUMB_SIZE);
17775 break;
17777 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
17778 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
17779 as_bad_where (fixP->fx_file, fixP->fx_line,
17780 _("branch out of range"));
17782 if (fixP->fx_done || !seg->use_rela_p)
17784 newval = md_chars_to_number (buf, THUMB_SIZE);
17785 newval |= (value & 0x1ff) >> 1;
17786 md_number_to_chars (buf, newval, THUMB_SIZE);
17788 break;
17790 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
17791 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
17792 as_bad_where (fixP->fx_file, fixP->fx_line,
17793 _("branch out of range"));
17795 if (fixP->fx_done || !seg->use_rela_p)
17797 newval = md_chars_to_number (buf, THUMB_SIZE);
17798 newval |= (value & 0xfff) >> 1;
17799 md_number_to_chars (buf, newval, THUMB_SIZE);
17801 break;
17803 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17804 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
17805 as_bad_where (fixP->fx_file, fixP->fx_line,
17806 _("conditional branch out of range"));
17808 if (fixP->fx_done || !seg->use_rela_p)
17810 offsetT newval2;
17811 addressT S, J1, J2, lo, hi;
17813 S = (value & 0x00100000) >> 20;
17814 J2 = (value & 0x00080000) >> 19;
17815 J1 = (value & 0x00040000) >> 18;
17816 hi = (value & 0x0003f000) >> 12;
17817 lo = (value & 0x00000ffe) >> 1;
17819 newval = md_chars_to_number (buf, THUMB_SIZE);
17820 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17821 newval |= (S << 10) | hi;
17822 newval2 |= (J1 << 13) | (J2 << 11) | lo;
17823 md_number_to_chars (buf, newval, THUMB_SIZE);
17824 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
17826 break;
17828 case BFD_RELOC_THUMB_PCREL_BLX:
17829 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17830 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
17831 as_bad_where (fixP->fx_file, fixP->fx_line,
17832 _("branch out of range"));
17834 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
17835 /* For a BLX instruction, make sure that the relocation is rounded up
17836 to a word boundary. This follows the semantics of the instruction
17837 which specifies that bit 1 of the target address will come from bit
17838 1 of the base address. */
17839 value = (value + 1) & ~ 1;
17841 if (fixP->fx_done || !seg->use_rela_p)
17843 offsetT newval2;
17845 newval = md_chars_to_number (buf, THUMB_SIZE);
17846 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17847 newval |= (value & 0x7fffff) >> 12;
17848 newval2 |= (value & 0xfff) >> 1;
17849 md_number_to_chars (buf, newval, THUMB_SIZE);
17850 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
17852 break;
17854 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17855 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
17856 as_bad_where (fixP->fx_file, fixP->fx_line,
17857 _("branch out of range"));
17859 if (fixP->fx_done || !seg->use_rela_p)
17861 offsetT newval2;
17862 addressT S, I1, I2, lo, hi;
17864 S = (value & 0x01000000) >> 24;
17865 I1 = (value & 0x00800000) >> 23;
17866 I2 = (value & 0x00400000) >> 22;
17867 hi = (value & 0x003ff000) >> 12;
17868 lo = (value & 0x00000ffe) >> 1;
17870 I1 = !(I1 ^ S);
17871 I2 = !(I2 ^ S);
17873 newval = md_chars_to_number (buf, THUMB_SIZE);
17874 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17875 newval |= (S << 10) | hi;
17876 newval2 |= (I1 << 13) | (I2 << 11) | lo;
17877 md_number_to_chars (buf, newval, THUMB_SIZE);
17878 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
17880 break;
17882 case BFD_RELOC_8:
17883 if (fixP->fx_done || !seg->use_rela_p)
17884 md_number_to_chars (buf, value, 1);
17885 break;
17887 case BFD_RELOC_16:
17888 if (fixP->fx_done || !seg->use_rela_p)
17889 md_number_to_chars (buf, value, 2);
17890 break;
17892 #ifdef OBJ_ELF
17893 case BFD_RELOC_ARM_TLS_GD32:
17894 case BFD_RELOC_ARM_TLS_LE32:
17895 case BFD_RELOC_ARM_TLS_IE32:
17896 case BFD_RELOC_ARM_TLS_LDM32:
17897 case BFD_RELOC_ARM_TLS_LDO32:
17898 S_SET_THREAD_LOCAL (fixP->fx_addsy);
17899 /* fall through */
17901 case BFD_RELOC_ARM_GOT32:
17902 case BFD_RELOC_ARM_GOTOFF:
17903 case BFD_RELOC_ARM_TARGET2:
17904 if (fixP->fx_done || !seg->use_rela_p)
17905 md_number_to_chars (buf, 0, 4);
17906 break;
17907 #endif
17909 case BFD_RELOC_RVA:
17910 case BFD_RELOC_32:
17911 case BFD_RELOC_ARM_TARGET1:
17912 case BFD_RELOC_ARM_ROSEGREL32:
17913 case BFD_RELOC_ARM_SBREL32:
17914 case BFD_RELOC_32_PCREL:
17915 if (fixP->fx_done || !seg->use_rela_p)
17916 md_number_to_chars (buf, value, 4);
17917 break;
17919 #ifdef OBJ_ELF
17920 case BFD_RELOC_ARM_PREL31:
17921 if (fixP->fx_done || !seg->use_rela_p)
17923 newval = md_chars_to_number (buf, 4) & 0x80000000;
17924 if ((value ^ (value >> 1)) & 0x40000000)
17926 as_bad_where (fixP->fx_file, fixP->fx_line,
17927 _("rel31 relocation overflow"));
17929 newval |= value & 0x7fffffff;
17930 md_number_to_chars (buf, newval, 4);
17932 break;
17933 #endif
17935 case BFD_RELOC_ARM_CP_OFF_IMM:
17936 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
17937 if (value < -1023 || value > 1023 || (value & 3))
17938 as_bad_where (fixP->fx_file, fixP->fx_line,
17939 _("co-processor offset out of range"));
17940 cp_off_common:
17941 sign = value >= 0;
17942 if (value < 0)
17943 value = -value;
17944 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
17945 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
17946 newval = md_chars_to_number (buf, INSN_SIZE);
17947 else
17948 newval = get_thumb32_insn (buf);
17949 newval &= 0xff7fff00;
17950 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
17951 if (value == 0)
17952 newval &= ~WRITE_BACK;
17953 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
17954 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
17955 md_number_to_chars (buf, newval, INSN_SIZE);
17956 else
17957 put_thumb32_insn (buf, newval);
17958 break;
17960 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
17961 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
17962 if (value < -255 || value > 255)
17963 as_bad_where (fixP->fx_file, fixP->fx_line,
17964 _("co-processor offset out of range"));
17965 value *= 4;
17966 goto cp_off_common;
17968 case BFD_RELOC_ARM_THUMB_OFFSET:
17969 newval = md_chars_to_number (buf, THUMB_SIZE);
17970 /* Exactly what ranges, and where the offset is inserted depends
17971 on the type of instruction, we can establish this from the
17972 top 4 bits. */
17973 switch (newval >> 12)
17975 case 4: /* PC load. */
17976 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
17977 forced to zero for these loads; md_pcrel_from has already
17978 compensated for this. */
17979 if (value & 3)
17980 as_bad_where (fixP->fx_file, fixP->fx_line,
17981 _("invalid offset, target not word aligned (0x%08lX)"),
17982 (((unsigned long) fixP->fx_frag->fr_address
17983 + (unsigned long) fixP->fx_where) & ~3)
17984 + (unsigned long) value);
17986 if (value & ~0x3fc)
17987 as_bad_where (fixP->fx_file, fixP->fx_line,
17988 _("invalid offset, value too big (0x%08lX)"),
17989 (long) value);
17991 newval |= value >> 2;
17992 break;
17994 case 9: /* SP load/store. */
17995 if (value & ~0x3fc)
17996 as_bad_where (fixP->fx_file, fixP->fx_line,
17997 _("invalid offset, value too big (0x%08lX)"),
17998 (long) value);
17999 newval |= value >> 2;
18000 break;
18002 case 6: /* Word load/store. */
18003 if (value & ~0x7c)
18004 as_bad_where (fixP->fx_file, fixP->fx_line,
18005 _("invalid offset, value too big (0x%08lX)"),
18006 (long) value);
18007 newval |= value << 4; /* 6 - 2. */
18008 break;
18010 case 7: /* Byte load/store. */
18011 if (value & ~0x1f)
18012 as_bad_where (fixP->fx_file, fixP->fx_line,
18013 _("invalid offset, value too big (0x%08lX)"),
18014 (long) value);
18015 newval |= value << 6;
18016 break;
18018 case 8: /* Halfword load/store. */
18019 if (value & ~0x3e)
18020 as_bad_where (fixP->fx_file, fixP->fx_line,
18021 _("invalid offset, value too big (0x%08lX)"),
18022 (long) value);
18023 newval |= value << 5; /* 6 - 1. */
18024 break;
18026 default:
18027 as_bad_where (fixP->fx_file, fixP->fx_line,
18028 "Unable to process relocation for thumb opcode: %lx",
18029 (unsigned long) newval);
18030 break;
18032 md_number_to_chars (buf, newval, THUMB_SIZE);
18033 break;
18035 case BFD_RELOC_ARM_THUMB_ADD:
18036 /* This is a complicated relocation, since we use it for all of
18037 the following immediate relocations:
18039 3bit ADD/SUB
18040 8bit ADD/SUB
18041 9bit ADD/SUB SP word-aligned
18042 10bit ADD PC/SP word-aligned
18044 The type of instruction being processed is encoded in the
18045 instruction field:
18047 0x8000 SUB
18048 0x00F0 Rd
18049 0x000F Rs
18051 newval = md_chars_to_number (buf, THUMB_SIZE);
18053 int rd = (newval >> 4) & 0xf;
18054 int rs = newval & 0xf;
18055 int subtract = !!(newval & 0x8000);
18057 /* Check for HI regs, only very restricted cases allowed:
18058 Adjusting SP, and using PC or SP to get an address. */
18059 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18060 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18061 as_bad_where (fixP->fx_file, fixP->fx_line,
18062 _("invalid Hi register with immediate"));
18064 /* If value is negative, choose the opposite instruction. */
18065 if (value < 0)
18067 value = -value;
18068 subtract = !subtract;
18069 if (value < 0)
18070 as_bad_where (fixP->fx_file, fixP->fx_line,
18071 _("immediate value out of range"));
18074 if (rd == REG_SP)
18076 if (value & ~0x1fc)
18077 as_bad_where (fixP->fx_file, fixP->fx_line,
18078 _("invalid immediate for stack address calculation"));
18079 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18080 newval |= value >> 2;
18082 else if (rs == REG_PC || rs == REG_SP)
18084 if (subtract || value & ~0x3fc)
18085 as_bad_where (fixP->fx_file, fixP->fx_line,
18086 _("invalid immediate for address calculation (value = 0x%08lX)"),
18087 (unsigned long) value);
18088 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18089 newval |= rd << 8;
18090 newval |= value >> 2;
18092 else if (rs == rd)
18094 if (value & ~0xff)
18095 as_bad_where (fixP->fx_file, fixP->fx_line,
18096 _("immediate value out of range"));
18097 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18098 newval |= (rd << 8) | value;
18100 else
18102 if (value & ~0x7)
18103 as_bad_where (fixP->fx_file, fixP->fx_line,
18104 _("immediate value out of range"));
18105 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18106 newval |= rd | (rs << 3) | (value << 6);
18109 md_number_to_chars (buf, newval, THUMB_SIZE);
18110 break;
18112 case BFD_RELOC_ARM_THUMB_IMM:
18113 newval = md_chars_to_number (buf, THUMB_SIZE);
18114 if (value < 0 || value > 255)
18115 as_bad_where (fixP->fx_file, fixP->fx_line,
18116 _("invalid immediate: %ld is too large"),
18117 (long) value);
18118 newval |= value;
18119 md_number_to_chars (buf, newval, THUMB_SIZE);
18120 break;
18122 case BFD_RELOC_ARM_THUMB_SHIFT:
18123 /* 5bit shift value (0..32). LSL cannot take 32. */
18124 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18125 temp = newval & 0xf800;
18126 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18127 as_bad_where (fixP->fx_file, fixP->fx_line,
18128 _("invalid shift value: %ld"), (long) value);
18129 /* Shifts of zero must be encoded as LSL. */
18130 if (value == 0)
18131 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18132 /* Shifts of 32 are encoded as zero. */
18133 else if (value == 32)
18134 value = 0;
18135 newval |= value << 6;
18136 md_number_to_chars (buf, newval, THUMB_SIZE);
18137 break;
18139 case BFD_RELOC_VTABLE_INHERIT:
18140 case BFD_RELOC_VTABLE_ENTRY:
18141 fixP->fx_done = 0;
18142 return;
18144 case BFD_RELOC_ARM_MOVW:
18145 case BFD_RELOC_ARM_MOVT:
18146 case BFD_RELOC_ARM_THUMB_MOVW:
18147 case BFD_RELOC_ARM_THUMB_MOVT:
18148 if (fixP->fx_done || !seg->use_rela_p)
18150 /* REL format relocations are limited to a 16-bit addend. */
18151 if (!fixP->fx_done)
18153 if (value < -0x1000 || value > 0xffff)
18154 as_bad_where (fixP->fx_file, fixP->fx_line,
18155 _("offset too big"));
18157 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18158 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18160 value >>= 16;
18163 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18164 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18166 newval = get_thumb32_insn (buf);
18167 newval &= 0xfbf08f00;
18168 newval |= (value & 0xf000) << 4;
18169 newval |= (value & 0x0800) << 15;
18170 newval |= (value & 0x0700) << 4;
18171 newval |= (value & 0x00ff);
18172 put_thumb32_insn (buf, newval);
18174 else
18176 newval = md_chars_to_number (buf, 4);
18177 newval &= 0xfff0f000;
18178 newval |= value & 0x0fff;
18179 newval |= (value & 0xf000) << 4;
18180 md_number_to_chars (buf, newval, 4);
18183 return;
18185 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18186 case BFD_RELOC_ARM_ALU_PC_G0:
18187 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18188 case BFD_RELOC_ARM_ALU_PC_G1:
18189 case BFD_RELOC_ARM_ALU_PC_G2:
18190 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18191 case BFD_RELOC_ARM_ALU_SB_G0:
18192 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18193 case BFD_RELOC_ARM_ALU_SB_G1:
18194 case BFD_RELOC_ARM_ALU_SB_G2:
18195 assert (!fixP->fx_done);
18196 if (!seg->use_rela_p)
18198 bfd_vma insn;
18199 bfd_vma encoded_addend;
18200 bfd_vma addend_abs = abs (value);
18202 /* Check that the absolute value of the addend can be
18203 expressed as an 8-bit constant plus a rotation. */
18204 encoded_addend = encode_arm_immediate (addend_abs);
18205 if (encoded_addend == (unsigned int) FAIL)
18206 as_bad_where (fixP->fx_file, fixP->fx_line,
18207 _("the offset 0x%08lX is not representable"),
18208 addend_abs);
18210 /* Extract the instruction. */
18211 insn = md_chars_to_number (buf, INSN_SIZE);
18213 /* If the addend is positive, use an ADD instruction.
18214 Otherwise use a SUB. Take care not to destroy the S bit. */
18215 insn &= 0xff1fffff;
18216 if (value < 0)
18217 insn |= 1 << 22;
18218 else
18219 insn |= 1 << 23;
18221 /* Place the encoded addend into the first 12 bits of the
18222 instruction. */
18223 insn &= 0xfffff000;
18224 insn |= encoded_addend;
18226 /* Update the instruction. */
18227 md_number_to_chars (buf, insn, INSN_SIZE);
18229 break;
18231 case BFD_RELOC_ARM_LDR_PC_G0:
18232 case BFD_RELOC_ARM_LDR_PC_G1:
18233 case BFD_RELOC_ARM_LDR_PC_G2:
18234 case BFD_RELOC_ARM_LDR_SB_G0:
18235 case BFD_RELOC_ARM_LDR_SB_G1:
18236 case BFD_RELOC_ARM_LDR_SB_G2:
18237 assert (!fixP->fx_done);
18238 if (!seg->use_rela_p)
18240 bfd_vma insn;
18241 bfd_vma addend_abs = abs (value);
18243 /* Check that the absolute value of the addend can be
18244 encoded in 12 bits. */
18245 if (addend_abs >= 0x1000)
18246 as_bad_where (fixP->fx_file, fixP->fx_line,
18247 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18248 addend_abs);
18250 /* Extract the instruction. */
18251 insn = md_chars_to_number (buf, INSN_SIZE);
18253 /* If the addend is negative, clear bit 23 of the instruction.
18254 Otherwise set it. */
18255 if (value < 0)
18256 insn &= ~(1 << 23);
18257 else
18258 insn |= 1 << 23;
18260 /* Place the absolute value of the addend into the first 12 bits
18261 of the instruction. */
18262 insn &= 0xfffff000;
18263 insn |= addend_abs;
18265 /* Update the instruction. */
18266 md_number_to_chars (buf, insn, INSN_SIZE);
18268 break;
18270 case BFD_RELOC_ARM_LDRS_PC_G0:
18271 case BFD_RELOC_ARM_LDRS_PC_G1:
18272 case BFD_RELOC_ARM_LDRS_PC_G2:
18273 case BFD_RELOC_ARM_LDRS_SB_G0:
18274 case BFD_RELOC_ARM_LDRS_SB_G1:
18275 case BFD_RELOC_ARM_LDRS_SB_G2:
18276 assert (!fixP->fx_done);
18277 if (!seg->use_rela_p)
18279 bfd_vma insn;
18280 bfd_vma addend_abs = abs (value);
18282 /* Check that the absolute value of the addend can be
18283 encoded in 8 bits. */
18284 if (addend_abs >= 0x100)
18285 as_bad_where (fixP->fx_file, fixP->fx_line,
18286 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18287 addend_abs);
18289 /* Extract the instruction. */
18290 insn = md_chars_to_number (buf, INSN_SIZE);
18292 /* If the addend is negative, clear bit 23 of the instruction.
18293 Otherwise set it. */
18294 if (value < 0)
18295 insn &= ~(1 << 23);
18296 else
18297 insn |= 1 << 23;
18299 /* Place the first four bits of the absolute value of the addend
18300 into the first 4 bits of the instruction, and the remaining
18301 four into bits 8 .. 11. */
18302 insn &= 0xfffff0f0;
18303 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18305 /* Update the instruction. */
18306 md_number_to_chars (buf, insn, INSN_SIZE);
18308 break;
18310 case BFD_RELOC_ARM_LDC_PC_G0:
18311 case BFD_RELOC_ARM_LDC_PC_G1:
18312 case BFD_RELOC_ARM_LDC_PC_G2:
18313 case BFD_RELOC_ARM_LDC_SB_G0:
18314 case BFD_RELOC_ARM_LDC_SB_G1:
18315 case BFD_RELOC_ARM_LDC_SB_G2:
18316 assert (!fixP->fx_done);
18317 if (!seg->use_rela_p)
18319 bfd_vma insn;
18320 bfd_vma addend_abs = abs (value);
18322 /* Check that the absolute value of the addend is a multiple of
18323 four and, when divided by four, fits in 8 bits. */
18324 if (addend_abs & 0x3)
18325 as_bad_where (fixP->fx_file, fixP->fx_line,
18326 _("bad offset 0x%08lX (must be word-aligned)"),
18327 addend_abs);
18329 if ((addend_abs >> 2) > 0xff)
18330 as_bad_where (fixP->fx_file, fixP->fx_line,
18331 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18332 addend_abs);
18334 /* Extract the instruction. */
18335 insn = md_chars_to_number (buf, INSN_SIZE);
18337 /* If the addend is negative, clear bit 23 of the instruction.
18338 Otherwise set it. */
18339 if (value < 0)
18340 insn &= ~(1 << 23);
18341 else
18342 insn |= 1 << 23;
18344 /* Place the addend (divided by four) into the first eight
18345 bits of the instruction. */
18346 insn &= 0xfffffff0;
18347 insn |= addend_abs >> 2;
18349 /* Update the instruction. */
18350 md_number_to_chars (buf, insn, INSN_SIZE);
18352 break;
18354 case BFD_RELOC_UNUSED:
18355 default:
18356 as_bad_where (fixP->fx_file, fixP->fx_line,
18357 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
18361 /* Translate internal representation of relocation info to BFD target
18362 format. */
18364 arelent *
18365 tc_gen_reloc (asection *section, fixS *fixp)
18367 arelent * reloc;
18368 bfd_reloc_code_real_type code;
18370 reloc = xmalloc (sizeof (arelent));
18372 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
18373 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18374 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
18376 if (fixp->fx_pcrel)
18378 if (section->use_rela_p)
18379 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
18380 else
18381 fixp->fx_offset = reloc->address;
18383 reloc->addend = fixp->fx_offset;
18385 switch (fixp->fx_r_type)
18387 case BFD_RELOC_8:
18388 if (fixp->fx_pcrel)
18390 code = BFD_RELOC_8_PCREL;
18391 break;
18394 case BFD_RELOC_16:
18395 if (fixp->fx_pcrel)
18397 code = BFD_RELOC_16_PCREL;
18398 break;
18401 case BFD_RELOC_32:
18402 if (fixp->fx_pcrel)
18404 code = BFD_RELOC_32_PCREL;
18405 break;
18408 case BFD_RELOC_ARM_MOVW:
18409 if (fixp->fx_pcrel)
18411 code = BFD_RELOC_ARM_MOVW_PCREL;
18412 break;
18415 case BFD_RELOC_ARM_MOVT:
18416 if (fixp->fx_pcrel)
18418 code = BFD_RELOC_ARM_MOVT_PCREL;
18419 break;
18422 case BFD_RELOC_ARM_THUMB_MOVW:
18423 if (fixp->fx_pcrel)
18425 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
18426 break;
18429 case BFD_RELOC_ARM_THUMB_MOVT:
18430 if (fixp->fx_pcrel)
18432 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
18433 break;
18436 case BFD_RELOC_NONE:
18437 case BFD_RELOC_ARM_PCREL_BRANCH:
18438 case BFD_RELOC_ARM_PCREL_BLX:
18439 case BFD_RELOC_RVA:
18440 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18441 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18442 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18443 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18444 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18445 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18446 case BFD_RELOC_THUMB_PCREL_BLX:
18447 case BFD_RELOC_VTABLE_ENTRY:
18448 case BFD_RELOC_VTABLE_INHERIT:
18449 code = fixp->fx_r_type;
18450 break;
18452 case BFD_RELOC_ARM_LITERAL:
18453 case BFD_RELOC_ARM_HWLITERAL:
18454 /* If this is called then the a literal has
18455 been referenced across a section boundary. */
18456 as_bad_where (fixp->fx_file, fixp->fx_line,
18457 _("literal referenced across section boundary"));
18458 return NULL;
18460 #ifdef OBJ_ELF
18461 case BFD_RELOC_ARM_GOT32:
18462 case BFD_RELOC_ARM_GOTOFF:
18463 case BFD_RELOC_ARM_PLT32:
18464 case BFD_RELOC_ARM_TARGET1:
18465 case BFD_RELOC_ARM_ROSEGREL32:
18466 case BFD_RELOC_ARM_SBREL32:
18467 case BFD_RELOC_ARM_PREL31:
18468 case BFD_RELOC_ARM_TARGET2:
18469 case BFD_RELOC_ARM_TLS_LE32:
18470 case BFD_RELOC_ARM_TLS_LDO32:
18471 case BFD_RELOC_ARM_PCREL_CALL:
18472 case BFD_RELOC_ARM_PCREL_JUMP:
18473 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18474 case BFD_RELOC_ARM_ALU_PC_G0:
18475 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18476 case BFD_RELOC_ARM_ALU_PC_G1:
18477 case BFD_RELOC_ARM_ALU_PC_G2:
18478 case BFD_RELOC_ARM_LDR_PC_G0:
18479 case BFD_RELOC_ARM_LDR_PC_G1:
18480 case BFD_RELOC_ARM_LDR_PC_G2:
18481 case BFD_RELOC_ARM_LDRS_PC_G0:
18482 case BFD_RELOC_ARM_LDRS_PC_G1:
18483 case BFD_RELOC_ARM_LDRS_PC_G2:
18484 case BFD_RELOC_ARM_LDC_PC_G0:
18485 case BFD_RELOC_ARM_LDC_PC_G1:
18486 case BFD_RELOC_ARM_LDC_PC_G2:
18487 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18488 case BFD_RELOC_ARM_ALU_SB_G0:
18489 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18490 case BFD_RELOC_ARM_ALU_SB_G1:
18491 case BFD_RELOC_ARM_ALU_SB_G2:
18492 case BFD_RELOC_ARM_LDR_SB_G0:
18493 case BFD_RELOC_ARM_LDR_SB_G1:
18494 case BFD_RELOC_ARM_LDR_SB_G2:
18495 case BFD_RELOC_ARM_LDRS_SB_G0:
18496 case BFD_RELOC_ARM_LDRS_SB_G1:
18497 case BFD_RELOC_ARM_LDRS_SB_G2:
18498 case BFD_RELOC_ARM_LDC_SB_G0:
18499 case BFD_RELOC_ARM_LDC_SB_G1:
18500 case BFD_RELOC_ARM_LDC_SB_G2:
18501 code = fixp->fx_r_type;
18502 break;
18504 case BFD_RELOC_ARM_TLS_GD32:
18505 case BFD_RELOC_ARM_TLS_IE32:
18506 case BFD_RELOC_ARM_TLS_LDM32:
18507 /* BFD will include the symbol's address in the addend.
18508 But we don't want that, so subtract it out again here. */
18509 if (!S_IS_COMMON (fixp->fx_addsy))
18510 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
18511 code = fixp->fx_r_type;
18512 break;
18513 #endif
18515 case BFD_RELOC_ARM_IMMEDIATE:
18516 as_bad_where (fixp->fx_file, fixp->fx_line,
18517 _("internal relocation (type: IMMEDIATE) not fixed up"));
18518 return NULL;
18520 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18521 as_bad_where (fixp->fx_file, fixp->fx_line,
18522 _("ADRL used for a symbol not defined in the same file"));
18523 return NULL;
18525 case BFD_RELOC_ARM_OFFSET_IMM:
18526 if (section->use_rela_p)
18528 code = fixp->fx_r_type;
18529 break;
18532 if (fixp->fx_addsy != NULL
18533 && !S_IS_DEFINED (fixp->fx_addsy)
18534 && S_IS_LOCAL (fixp->fx_addsy))
18536 as_bad_where (fixp->fx_file, fixp->fx_line,
18537 _("undefined local label `%s'"),
18538 S_GET_NAME (fixp->fx_addsy));
18539 return NULL;
18542 as_bad_where (fixp->fx_file, fixp->fx_line,
18543 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
18544 return NULL;
18546 default:
18548 char * type;
18550 switch (fixp->fx_r_type)
18552 case BFD_RELOC_NONE: type = "NONE"; break;
18553 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
18554 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
18555 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
18556 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
18557 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
18558 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
18559 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
18560 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
18561 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
18562 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
18563 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
18564 default: type = _("<unknown>"); break;
18566 as_bad_where (fixp->fx_file, fixp->fx_line,
18567 _("cannot represent %s relocation in this object file format"),
18568 type);
18569 return NULL;
18573 #ifdef OBJ_ELF
18574 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
18575 && GOT_symbol
18576 && fixp->fx_addsy == GOT_symbol)
18578 code = BFD_RELOC_ARM_GOTPC;
18579 reloc->addend = fixp->fx_offset = reloc->address;
18581 #endif
18583 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
18585 if (reloc->howto == NULL)
18587 as_bad_where (fixp->fx_file, fixp->fx_line,
18588 _("cannot represent %s relocation in this object file format"),
18589 bfd_get_reloc_code_name (code));
18590 return NULL;
18593 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
18594 vtable entry to be used in the relocation's section offset. */
18595 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18596 reloc->address = fixp->fx_offset;
18598 return reloc;
18601 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
18603 void
18604 cons_fix_new_arm (fragS * frag,
18605 int where,
18606 int size,
18607 expressionS * exp)
18609 bfd_reloc_code_real_type type;
18610 int pcrel = 0;
18612 /* Pick a reloc.
18613 FIXME: @@ Should look at CPU word size. */
18614 switch (size)
18616 case 1:
18617 type = BFD_RELOC_8;
18618 break;
18619 case 2:
18620 type = BFD_RELOC_16;
18621 break;
18622 case 4:
18623 default:
18624 type = BFD_RELOC_32;
18625 break;
18626 case 8:
18627 type = BFD_RELOC_64;
18628 break;
18631 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
18634 #if defined OBJ_COFF || defined OBJ_ELF
18635 void
18636 arm_validate_fix (fixS * fixP)
18638 /* If the destination of the branch is a defined symbol which does not have
18639 the THUMB_FUNC attribute, then we must be calling a function which has
18640 the (interfacearm) attribute. We look for the Thumb entry point to that
18641 function and change the branch to refer to that function instead. */
18642 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
18643 && fixP->fx_addsy != NULL
18644 && S_IS_DEFINED (fixP->fx_addsy)
18645 && ! THUMB_IS_FUNC (fixP->fx_addsy))
18647 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
18650 #endif
18653 arm_force_relocation (struct fix * fixp)
18655 #if defined (OBJ_COFF) && defined (TE_PE)
18656 if (fixp->fx_r_type == BFD_RELOC_RVA)
18657 return 1;
18658 #endif
18660 /* Resolve these relocations even if the symbol is extern or weak. */
18661 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
18662 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
18663 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
18664 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
18665 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18666 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
18667 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
18668 return 0;
18670 /* Always leave these relocations for the linker. */
18671 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
18672 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
18673 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
18674 return 1;
18676 return generic_force_reloc (fixp);
18679 #ifdef OBJ_COFF
18680 /* This is a little hack to help the gas/arm/adrl.s test. It prevents
18681 local labels from being added to the output symbol table when they
18682 are used with the ADRL pseudo op. The ADRL relocation should always
18683 be resolved before the binbary is emitted, so it is safe to say that
18684 it is adjustable. */
18686 bfd_boolean
18687 arm_fix_adjustable (fixS * fixP)
18689 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
18690 return 1;
18691 return 0;
18693 #endif
18695 #ifdef OBJ_ELF
18696 /* Relocations against function names must be left unadjusted,
18697 so that the linker can use this information to generate interworking
18698 stubs. The MIPS version of this function
18699 also prevents relocations that are mips-16 specific, but I do not
18700 know why it does this.
18702 FIXME:
18703 There is one other problem that ought to be addressed here, but
18704 which currently is not: Taking the address of a label (rather
18705 than a function) and then later jumping to that address. Such
18706 addresses also ought to have their bottom bit set (assuming that
18707 they reside in Thumb code), but at the moment they will not. */
18709 bfd_boolean
18710 arm_fix_adjustable (fixS * fixP)
18712 if (fixP->fx_addsy == NULL)
18713 return 1;
18715 /* Preserve relocations against symbols with function type. */
18716 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
18717 return 0;
18719 if (THUMB_IS_FUNC (fixP->fx_addsy)
18720 && fixP->fx_subsy == NULL)
18721 return 0;
18723 /* We need the symbol name for the VTABLE entries. */
18724 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
18725 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18726 return 0;
18728 /* Don't allow symbols to be discarded on GOT related relocs. */
18729 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
18730 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
18731 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
18732 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
18733 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
18734 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
18735 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
18736 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
18737 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
18738 return 0;
18740 /* Similarly for group relocations. */
18741 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
18742 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
18743 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
18744 return 0;
18746 return 1;
18749 const char *
18750 elf32_arm_target_format (void)
18752 #ifdef TE_SYMBIAN
18753 return (target_big_endian
18754 ? "elf32-bigarm-symbian"
18755 : "elf32-littlearm-symbian");
18756 #elif defined (TE_VXWORKS)
18757 return (target_big_endian
18758 ? "elf32-bigarm-vxworks"
18759 : "elf32-littlearm-vxworks");
18760 #else
18761 if (target_big_endian)
18762 return "elf32-bigarm";
18763 else
18764 return "elf32-littlearm";
18765 #endif
18768 void
18769 armelf_frob_symbol (symbolS * symp,
18770 int * puntp)
18772 elf_frob_symbol (symp, puntp);
18774 #endif
18776 /* MD interface: Finalization. */
18778 /* A good place to do this, although this was probably not intended
18779 for this kind of use. We need to dump the literal pool before
18780 references are made to a null symbol pointer. */
18782 void
18783 arm_cleanup (void)
18785 literal_pool * pool;
18787 for (pool = list_of_pools; pool; pool = pool->next)
18789 /* Put it at the end of the relevent section. */
18790 subseg_set (pool->section, pool->sub_section);
18791 #ifdef OBJ_ELF
18792 arm_elf_change_section ();
18793 #endif
18794 s_ltorg (0);
18798 /* Adjust the symbol table. This marks Thumb symbols as distinct from
18799 ARM ones. */
18801 void
18802 arm_adjust_symtab (void)
18804 #ifdef OBJ_COFF
18805 symbolS * sym;
18807 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
18809 if (ARM_IS_THUMB (sym))
18811 if (THUMB_IS_FUNC (sym))
18813 /* Mark the symbol as a Thumb function. */
18814 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
18815 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
18816 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
18818 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
18819 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
18820 else
18821 as_bad (_("%s: unexpected function type: %d"),
18822 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
18824 else switch (S_GET_STORAGE_CLASS (sym))
18826 case C_EXT:
18827 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
18828 break;
18829 case C_STAT:
18830 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
18831 break;
18832 case C_LABEL:
18833 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
18834 break;
18835 default:
18836 /* Do nothing. */
18837 break;
18841 if (ARM_IS_INTERWORK (sym))
18842 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
18844 #endif
18845 #ifdef OBJ_ELF
18846 symbolS * sym;
18847 char bind;
18849 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
18851 if (ARM_IS_THUMB (sym))
18853 elf_symbol_type * elf_sym;
18855 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
18856 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
18858 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
18859 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
18861 /* If it's a .thumb_func, declare it as so,
18862 otherwise tag label as .code 16. */
18863 if (THUMB_IS_FUNC (sym))
18864 elf_sym->internal_elf_sym.st_info =
18865 ELF_ST_INFO (bind, STT_ARM_TFUNC);
18866 else
18867 elf_sym->internal_elf_sym.st_info =
18868 ELF_ST_INFO (bind, STT_ARM_16BIT);
18872 #endif
18875 /* MD interface: Initialization. */
18877 static void
18878 set_constant_flonums (void)
18880 int i;
18882 for (i = 0; i < NUM_FLOAT_VALS; i++)
18883 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
18884 abort ();
18887 /* Auto-select Thumb mode if it's the only available instruction set for the
18888 given architecture. */
18890 static void
18891 autoselect_thumb_from_cpu_variant (void)
18893 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
18894 opcode_select (16);
18897 void
18898 md_begin (void)
18900 unsigned mach;
18901 unsigned int i;
18903 if ( (arm_ops_hsh = hash_new ()) == NULL
18904 || (arm_cond_hsh = hash_new ()) == NULL
18905 || (arm_shift_hsh = hash_new ()) == NULL
18906 || (arm_psr_hsh = hash_new ()) == NULL
18907 || (arm_v7m_psr_hsh = hash_new ()) == NULL
18908 || (arm_reg_hsh = hash_new ()) == NULL
18909 || (arm_reloc_hsh = hash_new ()) == NULL
18910 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
18911 as_fatal (_("virtual memory exhausted"));
18913 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
18914 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
18915 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
18916 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
18917 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
18918 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
18919 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
18920 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
18921 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
18922 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
18923 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
18924 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
18925 for (i = 0;
18926 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
18927 i++)
18928 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
18929 (PTR) (barrier_opt_names + i));
18930 #ifdef OBJ_ELF
18931 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
18932 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
18933 #endif
18935 set_constant_flonums ();
18937 /* Set the cpu variant based on the command-line options. We prefer
18938 -mcpu= over -march= if both are set (as for GCC); and we prefer
18939 -mfpu= over any other way of setting the floating point unit.
18940 Use of legacy options with new options are faulted. */
18941 if (legacy_cpu)
18943 if (mcpu_cpu_opt || march_cpu_opt)
18944 as_bad (_("use of old and new-style options to set CPU type"));
18946 mcpu_cpu_opt = legacy_cpu;
18948 else if (!mcpu_cpu_opt)
18949 mcpu_cpu_opt = march_cpu_opt;
18951 if (legacy_fpu)
18953 if (mfpu_opt)
18954 as_bad (_("use of old and new-style options to set FPU type"));
18956 mfpu_opt = legacy_fpu;
18958 else if (!mfpu_opt)
18960 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
18961 /* Some environments specify a default FPU. If they don't, infer it
18962 from the processor. */
18963 if (mcpu_fpu_opt)
18964 mfpu_opt = mcpu_fpu_opt;
18965 else
18966 mfpu_opt = march_fpu_opt;
18967 #else
18968 mfpu_opt = &fpu_default;
18969 #endif
18972 if (!mfpu_opt)
18974 if (!mcpu_cpu_opt)
18975 mfpu_opt = &fpu_default;
18976 else if (ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
18977 mfpu_opt = &fpu_arch_vfp_v2;
18978 else
18979 mfpu_opt = &fpu_arch_fpa;
18982 #ifdef CPU_DEFAULT
18983 if (!mcpu_cpu_opt)
18985 mcpu_cpu_opt = &cpu_default;
18986 selected_cpu = cpu_default;
18988 #else
18989 if (mcpu_cpu_opt)
18990 selected_cpu = *mcpu_cpu_opt;
18991 else
18992 mcpu_cpu_opt = &arm_arch_any;
18993 #endif
18995 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
18997 autoselect_thumb_from_cpu_variant ();
18999 arm_arch_used = thumb_arch_used = arm_arch_none;
19001 #if defined OBJ_COFF || defined OBJ_ELF
19003 unsigned int flags = 0;
19005 #if defined OBJ_ELF
19006 flags = meabi_flags;
19008 switch (meabi_flags)
19010 case EF_ARM_EABI_UNKNOWN:
19011 #endif
19012 /* Set the flags in the private structure. */
19013 if (uses_apcs_26) flags |= F_APCS26;
19014 if (support_interwork) flags |= F_INTERWORK;
19015 if (uses_apcs_float) flags |= F_APCS_FLOAT;
19016 if (pic_code) flags |= F_PIC;
19017 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
19018 flags |= F_SOFT_FLOAT;
19020 switch (mfloat_abi_opt)
19022 case ARM_FLOAT_ABI_SOFT:
19023 case ARM_FLOAT_ABI_SOFTFP:
19024 flags |= F_SOFT_FLOAT;
19025 break;
19027 case ARM_FLOAT_ABI_HARD:
19028 if (flags & F_SOFT_FLOAT)
19029 as_bad (_("hard-float conflicts with specified fpu"));
19030 break;
19033 /* Using pure-endian doubles (even if soft-float). */
19034 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
19035 flags |= F_VFP_FLOAT;
19037 #if defined OBJ_ELF
19038 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
19039 flags |= EF_ARM_MAVERICK_FLOAT;
19040 break;
19042 case EF_ARM_EABI_VER4:
19043 case EF_ARM_EABI_VER5:
19044 /* No additional flags to set. */
19045 break;
19047 default:
19048 abort ();
19050 #endif
19051 bfd_set_private_flags (stdoutput, flags);
19053 /* We have run out flags in the COFF header to encode the
19054 status of ATPCS support, so instead we create a dummy,
19055 empty, debug section called .arm.atpcs. */
19056 if (atpcs)
19058 asection * sec;
19060 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19062 if (sec != NULL)
19064 bfd_set_section_flags
19065 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19066 bfd_set_section_size (stdoutput, sec, 0);
19067 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19071 #endif
19073 /* Record the CPU type as well. */
19074 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
19075 mach = bfd_mach_arm_iWMMXt;
19076 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
19077 mach = bfd_mach_arm_XScale;
19078 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
19079 mach = bfd_mach_arm_ep9312;
19080 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
19081 mach = bfd_mach_arm_5TE;
19082 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
19084 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19085 mach = bfd_mach_arm_5T;
19086 else
19087 mach = bfd_mach_arm_5;
19089 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
19091 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19092 mach = bfd_mach_arm_4T;
19093 else
19094 mach = bfd_mach_arm_4;
19096 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
19097 mach = bfd_mach_arm_3M;
19098 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19099 mach = bfd_mach_arm_3;
19100 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19101 mach = bfd_mach_arm_2a;
19102 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19103 mach = bfd_mach_arm_2;
19104 else
19105 mach = bfd_mach_arm_unknown;
19107 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19110 /* Command line processing. */
19112 /* md_parse_option
19113 Invocation line includes a switch not recognized by the base assembler.
19114 See if it's a processor-specific option.
19116 This routine is somewhat complicated by the need for backwards
19117 compatibility (since older releases of gcc can't be changed).
19118 The new options try to make the interface as compatible as
19119 possible with GCC.
19121 New options (supported) are:
19123 -mcpu=<cpu name> Assemble for selected processor
19124 -march=<architecture name> Assemble for selected architecture
19125 -mfpu=<fpu architecture> Assemble for selected FPU.
19126 -EB/-mbig-endian Big-endian
19127 -EL/-mlittle-endian Little-endian
19128 -k Generate PIC code
19129 -mthumb Start in Thumb mode
19130 -mthumb-interwork Code supports ARM/Thumb interworking
19132 For now we will also provide support for:
19134 -mapcs-32 32-bit Program counter
19135 -mapcs-26 26-bit Program counter
19136 -macps-float Floats passed in FP registers
19137 -mapcs-reentrant Reentrant code
19138 -matpcs
19139 (sometime these will probably be replaced with -mapcs=<list of options>
19140 and -matpcs=<list of options>)
19142 The remaining options are only supported for back-wards compatibility.
19143 Cpu variants, the arm part is optional:
19144 -m[arm]1 Currently not supported.
19145 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19146 -m[arm]3 Arm 3 processor
19147 -m[arm]6[xx], Arm 6 processors
19148 -m[arm]7[xx][t][[d]m] Arm 7 processors
19149 -m[arm]8[10] Arm 8 processors
19150 -m[arm]9[20][tdmi] Arm 9 processors
19151 -mstrongarm[110[0]] StrongARM processors
19152 -mxscale XScale processors
19153 -m[arm]v[2345[t[e]]] Arm architectures
19154 -mall All (except the ARM1)
19155 FP variants:
19156 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19157 -mfpe-old (No float load/store multiples)
19158 -mvfpxd VFP Single precision
19159 -mvfp All VFP
19160 -mno-fpu Disable all floating point instructions
19162 The following CPU names are recognized:
19163 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19164 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19165 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19166 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19167 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19168 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19169 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
19173 const char * md_shortopts = "m:k";
19175 #ifdef ARM_BI_ENDIAN
19176 #define OPTION_EB (OPTION_MD_BASE + 0)
19177 #define OPTION_EL (OPTION_MD_BASE + 1)
19178 #else
19179 #if TARGET_BYTES_BIG_ENDIAN
19180 #define OPTION_EB (OPTION_MD_BASE + 0)
19181 #else
19182 #define OPTION_EL (OPTION_MD_BASE + 1)
19183 #endif
19184 #endif
19186 struct option md_longopts[] =
19188 #ifdef OPTION_EB
19189 {"EB", no_argument, NULL, OPTION_EB},
19190 #endif
19191 #ifdef OPTION_EL
19192 {"EL", no_argument, NULL, OPTION_EL},
19193 #endif
19194 {NULL, no_argument, NULL, 0}
19197 size_t md_longopts_size = sizeof (md_longopts);
19199 struct arm_option_table
19201 char *option; /* Option name to match. */
19202 char *help; /* Help information. */
19203 int *var; /* Variable to change. */
19204 int value; /* What to change it to. */
19205 char *deprecated; /* If non-null, print this message. */
19208 struct arm_option_table arm_opts[] =
19210 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19211 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19212 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19213 &support_interwork, 1, NULL},
19214 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19215 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19216 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19217 1, NULL},
19218 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19219 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19220 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19221 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19222 NULL},
19224 /* These are recognized by the assembler, but have no affect on code. */
19225 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19226 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
19227 {NULL, NULL, NULL, 0, NULL}
19230 struct arm_legacy_option_table
19232 char *option; /* Option name to match. */
19233 const arm_feature_set **var; /* Variable to change. */
19234 const arm_feature_set value; /* What to change it to. */
19235 char *deprecated; /* If non-null, print this message. */
19238 const struct arm_legacy_option_table arm_legacy_opts[] =
19240 /* DON'T add any new processors to this list -- we want the whole list
19241 to go away... Add them to the processors table instead. */
19242 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19243 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19244 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19245 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19246 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19247 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19248 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19249 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19250 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19251 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19252 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19253 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19254 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19255 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19256 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19257 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19258 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19259 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19260 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19261 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19262 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19263 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19264 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19265 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19266 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19267 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19268 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19269 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19270 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19271 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19272 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19273 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19274 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19275 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19276 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19277 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19278 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19279 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19280 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19281 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19282 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19283 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19284 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19285 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19286 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19287 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19288 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19289 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19290 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19291 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19292 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19293 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19294 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19295 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19296 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19297 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19298 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19299 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19300 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19301 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19302 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19303 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19304 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19305 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19306 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19307 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19308 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19309 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19310 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19311 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
19312 N_("use -mcpu=strongarm110")},
19313 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
19314 N_("use -mcpu=strongarm1100")},
19315 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
19316 N_("use -mcpu=strongarm1110")},
19317 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19318 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19319 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
19321 /* Architecture variants -- don't add any more to this list either. */
19322 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19323 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19324 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19325 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19326 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19327 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19328 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19329 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19330 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19331 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19332 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19333 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19334 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19335 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19336 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19337 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19338 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19339 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19341 /* Floating point variants -- don't add any more to this list either. */
19342 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
19343 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
19344 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
19345 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
19346 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
19348 {NULL, NULL, ARM_ARCH_NONE, NULL}
19351 struct arm_cpu_option_table
19353 char *name;
19354 const arm_feature_set value;
19355 /* For some CPUs we assume an FPU unless the user explicitly sets
19356 -mfpu=... */
19357 const arm_feature_set default_fpu;
19358 /* The canonical name of the CPU, or NULL to use NAME converted to upper
19359 case. */
19360 const char *canonical_name;
19363 /* This list should, at a minimum, contain all the cpu names
19364 recognized by GCC. */
19365 static const struct arm_cpu_option_table arm_cpus[] =
19367 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
19368 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
19369 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
19370 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19371 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19372 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19373 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19374 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19375 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19376 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19377 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19378 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19379 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19380 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19381 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19382 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19383 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19384 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19385 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19386 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19387 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19388 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19389 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19390 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19391 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19392 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19393 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19394 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19395 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19396 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19397 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19398 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19399 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19400 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19401 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19402 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19403 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19404 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19405 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19406 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
19407 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19408 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19409 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19410 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19411 /* For V5 or later processors we default to using VFP; but the user
19412 should really set the FPU type explicitly. */
19413 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19414 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19415 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
19416 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
19417 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
19418 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19419 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
19420 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19421 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19422 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
19423 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19424 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19425 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19426 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19427 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19428 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
19429 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19430 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19431 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19432 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
19433 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
19434 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
19435 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
19436 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
19437 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
19438 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
19439 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
19440 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
19441 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
19442 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
19443 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
19444 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
19445 | FPU_NEON_EXT_V1),
19446 NULL},
19447 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
19448 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
19449 /* ??? XSCALE is really an architecture. */
19450 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
19451 /* ??? iwmmxt is not a processor. */
19452 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
19453 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
19454 /* Maverick */
19455 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
19456 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
19459 struct arm_arch_option_table
19461 char *name;
19462 const arm_feature_set value;
19463 const arm_feature_set default_fpu;
19466 /* This list should, at a minimum, contain all the architecture names
19467 recognized by GCC. */
19468 static const struct arm_arch_option_table arm_archs[] =
19470 {"all", ARM_ANY, FPU_ARCH_FPA},
19471 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
19472 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
19473 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
19474 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
19475 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
19476 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
19477 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
19478 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
19479 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
19480 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
19481 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
19482 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
19483 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
19484 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
19485 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
19486 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
19487 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
19488 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
19489 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
19490 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
19491 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
19492 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
19493 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
19494 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
19495 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
19496 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
19497 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
19498 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
19499 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
19500 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
19501 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
19502 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
19505 /* ISA extensions in the co-processor space. */
19506 struct arm_option_cpu_value_table
19508 char *name;
19509 const arm_feature_set value;
19512 static const struct arm_option_cpu_value_table arm_extensions[] =
19514 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
19515 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
19516 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
19517 {NULL, ARM_ARCH_NONE}
19520 /* This list should, at a minimum, contain all the fpu names
19521 recognized by GCC. */
19522 static const struct arm_option_cpu_value_table arm_fpus[] =
19524 {"softfpa", FPU_NONE},
19525 {"fpe", FPU_ARCH_FPE},
19526 {"fpe2", FPU_ARCH_FPE},
19527 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
19528 {"fpa", FPU_ARCH_FPA},
19529 {"fpa10", FPU_ARCH_FPA},
19530 {"fpa11", FPU_ARCH_FPA},
19531 {"arm7500fe", FPU_ARCH_FPA},
19532 {"softvfp", FPU_ARCH_VFP},
19533 {"softvfp+vfp", FPU_ARCH_VFP_V2},
19534 {"vfp", FPU_ARCH_VFP_V2},
19535 {"vfp9", FPU_ARCH_VFP_V2},
19536 {"vfp3", FPU_ARCH_VFP_V3},
19537 {"vfp10", FPU_ARCH_VFP_V2},
19538 {"vfp10-r0", FPU_ARCH_VFP_V1},
19539 {"vfpxd", FPU_ARCH_VFP_V1xD},
19540 {"arm1020t", FPU_ARCH_VFP_V1},
19541 {"arm1020e", FPU_ARCH_VFP_V2},
19542 {"arm1136jfs", FPU_ARCH_VFP_V2},
19543 {"arm1136jf-s", FPU_ARCH_VFP_V2},
19544 {"maverick", FPU_ARCH_MAVERICK},
19545 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
19546 {NULL, ARM_ARCH_NONE}
19549 struct arm_option_value_table
19551 char *name;
19552 long value;
19555 static const struct arm_option_value_table arm_float_abis[] =
19557 {"hard", ARM_FLOAT_ABI_HARD},
19558 {"softfp", ARM_FLOAT_ABI_SOFTFP},
19559 {"soft", ARM_FLOAT_ABI_SOFT},
19560 {NULL, 0}
19563 #ifdef OBJ_ELF
19564 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
19565 static const struct arm_option_value_table arm_eabis[] =
19567 {"gnu", EF_ARM_EABI_UNKNOWN},
19568 {"4", EF_ARM_EABI_VER4},
19569 {"5", EF_ARM_EABI_VER5},
19570 {NULL, 0}
19572 #endif
19574 struct arm_long_option_table
19576 char * option; /* Substring to match. */
19577 char * help; /* Help information. */
19578 int (* func) (char * subopt); /* Function to decode sub-option. */
19579 char * deprecated; /* If non-null, print this message. */
19582 static int
19583 arm_parse_extension (char * str, const arm_feature_set **opt_p)
19585 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
19587 /* Copy the feature set, so that we can modify it. */
19588 *ext_set = **opt_p;
19589 *opt_p = ext_set;
19591 while (str != NULL && *str != 0)
19593 const struct arm_option_cpu_value_table * opt;
19594 char * ext;
19595 int optlen;
19597 if (*str != '+')
19599 as_bad (_("invalid architectural extension"));
19600 return 0;
19603 str++;
19604 ext = strchr (str, '+');
19606 if (ext != NULL)
19607 optlen = ext - str;
19608 else
19609 optlen = strlen (str);
19611 if (optlen == 0)
19613 as_bad (_("missing architectural extension"));
19614 return 0;
19617 for (opt = arm_extensions; opt->name != NULL; opt++)
19618 if (strncmp (opt->name, str, optlen) == 0)
19620 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
19621 break;
19624 if (opt->name == NULL)
19626 as_bad (_("unknown architectural extnsion `%s'"), str);
19627 return 0;
19630 str = ext;
19633 return 1;
19636 static int
19637 arm_parse_cpu (char * str)
19639 const struct arm_cpu_option_table * opt;
19640 char * ext = strchr (str, '+');
19641 int optlen;
19643 if (ext != NULL)
19644 optlen = ext - str;
19645 else
19646 optlen = strlen (str);
19648 if (optlen == 0)
19650 as_bad (_("missing cpu name `%s'"), str);
19651 return 0;
19654 for (opt = arm_cpus; opt->name != NULL; opt++)
19655 if (strncmp (opt->name, str, optlen) == 0)
19657 mcpu_cpu_opt = &opt->value;
19658 mcpu_fpu_opt = &opt->default_fpu;
19659 if (opt->canonical_name)
19660 strcpy(selected_cpu_name, opt->canonical_name);
19661 else
19663 int i;
19664 for (i = 0; i < optlen; i++)
19665 selected_cpu_name[i] = TOUPPER (opt->name[i]);
19666 selected_cpu_name[i] = 0;
19669 if (ext != NULL)
19670 return arm_parse_extension (ext, &mcpu_cpu_opt);
19672 return 1;
19675 as_bad (_("unknown cpu `%s'"), str);
19676 return 0;
19679 static int
19680 arm_parse_arch (char * str)
19682 const struct arm_arch_option_table *opt;
19683 char *ext = strchr (str, '+');
19684 int optlen;
19686 if (ext != NULL)
19687 optlen = ext - str;
19688 else
19689 optlen = strlen (str);
19691 if (optlen == 0)
19693 as_bad (_("missing architecture name `%s'"), str);
19694 return 0;
19697 for (opt = arm_archs; opt->name != NULL; opt++)
19698 if (streq (opt->name, str))
19700 march_cpu_opt = &opt->value;
19701 march_fpu_opt = &opt->default_fpu;
19702 strcpy(selected_cpu_name, opt->name);
19704 if (ext != NULL)
19705 return arm_parse_extension (ext, &march_cpu_opt);
19707 return 1;
19710 as_bad (_("unknown architecture `%s'\n"), str);
19711 return 0;
19714 static int
19715 arm_parse_fpu (char * str)
19717 const struct arm_option_cpu_value_table * opt;
19719 for (opt = arm_fpus; opt->name != NULL; opt++)
19720 if (streq (opt->name, str))
19722 mfpu_opt = &opt->value;
19723 return 1;
19726 as_bad (_("unknown floating point format `%s'\n"), str);
19727 return 0;
19730 static int
19731 arm_parse_float_abi (char * str)
19733 const struct arm_option_value_table * opt;
19735 for (opt = arm_float_abis; opt->name != NULL; opt++)
19736 if (streq (opt->name, str))
19738 mfloat_abi_opt = opt->value;
19739 return 1;
19742 as_bad (_("unknown floating point abi `%s'\n"), str);
19743 return 0;
19746 #ifdef OBJ_ELF
19747 static int
19748 arm_parse_eabi (char * str)
19750 const struct arm_option_value_table *opt;
19752 for (opt = arm_eabis; opt->name != NULL; opt++)
19753 if (streq (opt->name, str))
19755 meabi_flags = opt->value;
19756 return 1;
19758 as_bad (_("unknown EABI `%s'\n"), str);
19759 return 0;
19761 #endif
19763 struct arm_long_option_table arm_long_opts[] =
19765 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
19766 arm_parse_cpu, NULL},
19767 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
19768 arm_parse_arch, NULL},
19769 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
19770 arm_parse_fpu, NULL},
19771 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
19772 arm_parse_float_abi, NULL},
19773 #ifdef OBJ_ELF
19774 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
19775 arm_parse_eabi, NULL},
19776 #endif
19777 {NULL, NULL, 0, NULL}
19781 md_parse_option (int c, char * arg)
19783 struct arm_option_table *opt;
19784 const struct arm_legacy_option_table *fopt;
19785 struct arm_long_option_table *lopt;
19787 switch (c)
19789 #ifdef OPTION_EB
19790 case OPTION_EB:
19791 target_big_endian = 1;
19792 break;
19793 #endif
19795 #ifdef OPTION_EL
19796 case OPTION_EL:
19797 target_big_endian = 0;
19798 break;
19799 #endif
19801 case 'a':
19802 /* Listing option. Just ignore these, we don't support additional
19803 ones. */
19804 return 0;
19806 default:
19807 for (opt = arm_opts; opt->option != NULL; opt++)
19809 if (c == opt->option[0]
19810 && ((arg == NULL && opt->option[1] == 0)
19811 || streq (arg, opt->option + 1)))
19813 #if WARN_DEPRECATED
19814 /* If the option is deprecated, tell the user. */
19815 if (opt->deprecated != NULL)
19816 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
19817 arg ? arg : "", _(opt->deprecated));
19818 #endif
19820 if (opt->var != NULL)
19821 *opt->var = opt->value;
19823 return 1;
19827 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
19829 if (c == fopt->option[0]
19830 && ((arg == NULL && fopt->option[1] == 0)
19831 || streq (arg, fopt->option + 1)))
19833 #if WARN_DEPRECATED
19834 /* If the option is deprecated, tell the user. */
19835 if (fopt->deprecated != NULL)
19836 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
19837 arg ? arg : "", _(fopt->deprecated));
19838 #endif
19840 if (fopt->var != NULL)
19841 *fopt->var = &fopt->value;
19843 return 1;
19847 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
19849 /* These options are expected to have an argument. */
19850 if (c == lopt->option[0]
19851 && arg != NULL
19852 && strncmp (arg, lopt->option + 1,
19853 strlen (lopt->option + 1)) == 0)
19855 #if WARN_DEPRECATED
19856 /* If the option is deprecated, tell the user. */
19857 if (lopt->deprecated != NULL)
19858 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
19859 _(lopt->deprecated));
19860 #endif
19862 /* Call the sup-option parser. */
19863 return lopt->func (arg + strlen (lopt->option) - 1);
19867 return 0;
19870 return 1;
19873 void
19874 md_show_usage (FILE * fp)
19876 struct arm_option_table *opt;
19877 struct arm_long_option_table *lopt;
19879 fprintf (fp, _(" ARM-specific assembler options:\n"));
19881 for (opt = arm_opts; opt->option != NULL; opt++)
19882 if (opt->help != NULL)
19883 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
19885 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
19886 if (lopt->help != NULL)
19887 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
19889 #ifdef OPTION_EB
19890 fprintf (fp, _("\
19891 -EB assemble code for a big-endian cpu\n"));
19892 #endif
19894 #ifdef OPTION_EL
19895 fprintf (fp, _("\
19896 -EL assemble code for a little-endian cpu\n"));
19897 #endif
19901 #ifdef OBJ_ELF
19902 typedef struct
19904 int val;
19905 arm_feature_set flags;
19906 } cpu_arch_ver_table;
19908 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
19909 least features first. */
19910 static const cpu_arch_ver_table cpu_arch_ver[] =
19912 {1, ARM_ARCH_V4},
19913 {2, ARM_ARCH_V4T},
19914 {3, ARM_ARCH_V5},
19915 {4, ARM_ARCH_V5TE},
19916 {5, ARM_ARCH_V5TEJ},
19917 {6, ARM_ARCH_V6},
19918 {7, ARM_ARCH_V6Z},
19919 {8, ARM_ARCH_V6K},
19920 {9, ARM_ARCH_V6T2},
19921 {10, ARM_ARCH_V7A},
19922 {10, ARM_ARCH_V7R},
19923 {10, ARM_ARCH_V7M},
19924 {0, ARM_ARCH_NONE}
19927 /* Set the public EABI object attributes. */
19928 static void
19929 aeabi_set_public_attributes (void)
19931 int arch;
19932 arm_feature_set flags;
19933 arm_feature_set tmp;
19934 const cpu_arch_ver_table *p;
19936 /* Choose the architecture based on the capabilities of the requested cpu
19937 (if any) and/or the instructions actually used. */
19938 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
19939 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
19940 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
19942 tmp = flags;
19943 arch = 0;
19944 for (p = cpu_arch_ver; p->val; p++)
19946 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
19948 arch = p->val;
19949 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
19953 /* Tag_CPU_name. */
19954 if (selected_cpu_name[0])
19956 char *p;
19958 p = selected_cpu_name;
19959 if (strncmp(p, "armv", 4) == 0)
19961 int i;
19963 p += 4;
19964 for (i = 0; p[i]; i++)
19965 p[i] = TOUPPER (p[i]);
19967 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
19969 /* Tag_CPU_arch. */
19970 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
19971 /* Tag_CPU_arch_profile. */
19972 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
19973 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A');
19974 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
19975 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R');
19976 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
19977 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M');
19978 /* Tag_ARM_ISA_use. */
19979 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
19980 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
19981 /* Tag_THUMB_ISA_use. */
19982 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
19983 elf32_arm_add_eabi_attr_int (stdoutput, 9,
19984 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
19985 /* Tag_VFP_arch. */
19986 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
19987 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
19988 elf32_arm_add_eabi_attr_int (stdoutput, 10, 3);
19989 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
19990 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
19991 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
19992 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
19993 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
19994 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
19995 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
19996 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
19997 /* Tag_WMMX_arch. */
19998 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
19999 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
20000 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
20001 /* Tag_NEON_arch. */
20002 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20003 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20004 elf32_arm_add_eabi_attr_int (stdoutput, 12, 1);
20007 /* Add the .ARM.attributes section. */
20008 void
20009 arm_md_end (void)
20011 segT s;
20012 char *p;
20013 addressT addr;
20014 offsetT size;
20016 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20017 return;
20019 aeabi_set_public_attributes ();
20020 size = elf32_arm_eabi_attr_size (stdoutput);
20021 s = subseg_new (".ARM.attributes", 0);
20022 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
20023 addr = frag_now_fix ();
20024 p = frag_more (size);
20025 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
20029 /* Parse a .cpu directive. */
20031 static void
20032 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20034 const struct arm_cpu_option_table *opt;
20035 char *name;
20036 char saved_char;
20038 name = input_line_pointer;
20039 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20040 input_line_pointer++;
20041 saved_char = *input_line_pointer;
20042 *input_line_pointer = 0;
20044 /* Skip the first "all" entry. */
20045 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20046 if (streq (opt->name, name))
20048 mcpu_cpu_opt = &opt->value;
20049 selected_cpu = opt->value;
20050 if (opt->canonical_name)
20051 strcpy(selected_cpu_name, opt->canonical_name);
20052 else
20054 int i;
20055 for (i = 0; opt->name[i]; i++)
20056 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20057 selected_cpu_name[i] = 0;
20059 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20060 *input_line_pointer = saved_char;
20061 demand_empty_rest_of_line ();
20062 return;
20064 as_bad (_("unknown cpu `%s'"), name);
20065 *input_line_pointer = saved_char;
20066 ignore_rest_of_line ();
20070 /* Parse a .arch directive. */
20072 static void
20073 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20075 const struct arm_arch_option_table *opt;
20076 char saved_char;
20077 char *name;
20079 name = input_line_pointer;
20080 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20081 input_line_pointer++;
20082 saved_char = *input_line_pointer;
20083 *input_line_pointer = 0;
20085 /* Skip the first "all" entry. */
20086 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20087 if (streq (opt->name, name))
20089 mcpu_cpu_opt = &opt->value;
20090 selected_cpu = opt->value;
20091 strcpy(selected_cpu_name, opt->name);
20092 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20093 *input_line_pointer = saved_char;
20094 demand_empty_rest_of_line ();
20095 return;
20098 as_bad (_("unknown architecture `%s'\n"), name);
20099 *input_line_pointer = saved_char;
20100 ignore_rest_of_line ();
20104 /* Parse a .fpu directive. */
20106 static void
20107 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20109 const struct arm_option_cpu_value_table *opt;
20110 char saved_char;
20111 char *name;
20113 name = input_line_pointer;
20114 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20115 input_line_pointer++;
20116 saved_char = *input_line_pointer;
20117 *input_line_pointer = 0;
20119 for (opt = arm_fpus; opt->name != NULL; opt++)
20120 if (streq (opt->name, name))
20122 mfpu_opt = &opt->value;
20123 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20124 *input_line_pointer = saved_char;
20125 demand_empty_rest_of_line ();
20126 return;
20129 as_bad (_("unknown floating point format `%s'\n"), name);
20130 *input_line_pointer = saved_char;
20131 ignore_rest_of_line ();
20133 #endif /* OBJ_ELF */