* config/tc-arm.c (do_nop): Generate v6k nops whenever possible.
[binutils.git] / gas / config / tc-arm.c
blob78215abccc14503b795187a8685c04e2c72d0190
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
11 This file is part of GAS, the GNU Assembler.
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
16 any later version.
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
28 #include <limits.h>
29 #include <stdarg.h>
30 #define NO_RELOC 0
31 #include "as.h"
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
36 #include "opcode/arm.h"
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dw2gencfi.h"
41 #endif
43 #include "dwarf2dbg.h"
45 #ifdef OBJ_ELF
46 /* Must be at least the size of the largest unwind opcode (currently two). */
47 #define ARM_OPCODE_CHUNK_SIZE 8
49 /* This structure holds the unwinding state. */
51 static struct
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
57 /* The segment containing the function. */
58 segT saved_seg;
59 subsegT saved_subseg;
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
62 int opcode_count;
63 int opcode_alloc;
64 /* The number of bytes pushed to the stack. */
65 offsetT frame_size;
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
69 offsetT pending_offset;
70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
74 /* Nonzero if an unwind_setfp directive has been seen. */
75 unsigned fp_used:1;
76 /* Nonzero if the last opcode restores sp from fp_reg. */
77 unsigned sp_restored:1;
78 } unwind;
80 /* Bit N indicates that an R_ARM_NONE relocation has been output for
81 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
82 emitted only once per section, to save unnecessary bloat. */
83 static unsigned int marked_pr_dependency = 0;
85 #endif /* OBJ_ELF */
87 /* Results from operand parsing worker functions. */
89 typedef enum
91 PARSE_OPERAND_SUCCESS,
92 PARSE_OPERAND_FAIL,
93 PARSE_OPERAND_FAIL_NO_BACKTRACK
94 } parse_operand_result;
96 enum arm_float_abi
98 ARM_FLOAT_ABI_HARD,
99 ARM_FLOAT_ABI_SOFTFP,
100 ARM_FLOAT_ABI_SOFT
103 /* Types of processor to assemble for. */
104 #ifndef CPU_DEFAULT
105 #if defined __XSCALE__
106 #define CPU_DEFAULT ARM_ARCH_XSCALE
107 #else
108 #if defined __thumb__
109 #define CPU_DEFAULT ARM_ARCH_V5T
110 #endif
111 #endif
112 #endif
114 #ifndef FPU_DEFAULT
115 # ifdef TE_LINUX
116 # define FPU_DEFAULT FPU_ARCH_FPA
117 # elif defined (TE_NetBSD)
118 # ifdef OBJ_ELF
119 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
120 # else
121 /* Legacy a.out format. */
122 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
123 # endif
124 # elif defined (TE_VXWORKS)
125 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
126 # else
127 /* For backwards compatibility, default to FPA. */
128 # define FPU_DEFAULT FPU_ARCH_FPA
129 # endif
130 #endif /* ifndef FPU_DEFAULT */
132 #define streq(a, b) (strcmp (a, b) == 0)
134 static arm_feature_set cpu_variant;
135 static arm_feature_set arm_arch_used;
136 static arm_feature_set thumb_arch_used;
138 /* Flags stored in private area of BFD structure. */
139 static int uses_apcs_26 = FALSE;
140 static int atpcs = FALSE;
141 static int support_interwork = FALSE;
142 static int uses_apcs_float = FALSE;
143 static int pic_code = FALSE;
144 static int fix_v4bx = FALSE;
145 /* Warn on using deprecated features. */
146 static int warn_on_deprecated = TRUE;
149 /* Variables that we set while parsing command-line options. Once all
150 options have been read we re-process these values to set the real
151 assembly flags. */
152 static const arm_feature_set *legacy_cpu = NULL;
153 static const arm_feature_set *legacy_fpu = NULL;
155 static const arm_feature_set *mcpu_cpu_opt = NULL;
156 static const arm_feature_set *mcpu_fpu_opt = NULL;
157 static const arm_feature_set *march_cpu_opt = NULL;
158 static const arm_feature_set *march_fpu_opt = NULL;
159 static const arm_feature_set *mfpu_opt = NULL;
160 static const arm_feature_set *object_arch = NULL;
162 /* Constants for known architecture features. */
163 static const arm_feature_set fpu_default = FPU_DEFAULT;
164 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
165 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
166 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
167 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
168 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
169 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
170 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
171 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
173 #ifdef CPU_DEFAULT
174 static const arm_feature_set cpu_default = CPU_DEFAULT;
175 #endif
177 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
178 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
179 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
180 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
181 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
182 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
183 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
184 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
185 static const arm_feature_set arm_ext_v4t_5 =
186 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
187 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
188 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
189 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
190 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
191 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
192 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
193 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
194 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
195 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
196 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
197 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
198 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
199 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
200 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
201 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
202 static const arm_feature_set arm_ext_m =
203 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
205 static const arm_feature_set arm_arch_any = ARM_ANY;
206 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
207 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
208 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
210 static const arm_feature_set arm_cext_iwmmxt2 =
211 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
212 static const arm_feature_set arm_cext_iwmmxt =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
214 static const arm_feature_set arm_cext_xscale =
215 ARM_FEATURE (0, ARM_CEXT_XSCALE);
216 static const arm_feature_set arm_cext_maverick =
217 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
218 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
219 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
220 static const arm_feature_set fpu_vfp_ext_v1xd =
221 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
222 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
223 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
224 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
225 static const arm_feature_set fpu_vfp_ext_d32 =
226 ARM_FEATURE (0, FPU_VFP_EXT_D32);
227 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
228 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
229 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
230 static const arm_feature_set fpu_neon_fp16 = ARM_FEATURE (0, FPU_NEON_FP16);
232 static int mfloat_abi_opt = -1;
233 /* Record user cpu selection for object attributes. */
234 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
235 /* Must be long enough to hold any of the names in arm_cpus. */
236 static char selected_cpu_name[16];
237 #ifdef OBJ_ELF
238 # ifdef EABI_DEFAULT
239 static int meabi_flags = EABI_DEFAULT;
240 # else
241 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
242 # endif
244 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
246 bfd_boolean
247 arm_is_eabi (void)
249 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
251 #endif
253 #ifdef OBJ_ELF
254 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
255 symbolS * GOT_symbol;
256 #endif
258 /* 0: assemble for ARM,
259 1: assemble for Thumb,
260 2: assemble for Thumb even though target CPU does not support thumb
261 instructions. */
262 static int thumb_mode = 0;
263 /* A value distinct from the possible values for thumb_mode that we
264 can use to record whether thumb_mode has been copied into the
265 tc_frag_data field of a frag. */
266 #define MODE_RECORDED (1 << 4)
268 /* If unified_syntax is true, we are processing the new unified
269 ARM/Thumb syntax. Important differences from the old ARM mode:
271 - Immediate operands do not require a # prefix.
272 - Conditional affixes always appear at the end of the
273 instruction. (For backward compatibility, those instructions
274 that formerly had them in the middle, continue to accept them
275 there.)
276 - The IT instruction may appear, and if it does is validated
277 against subsequent conditional affixes. It does not generate
278 machine code.
280 Important differences from the old Thumb mode:
282 - Immediate operands do not require a # prefix.
283 - Most of the V6T2 instructions are only available in unified mode.
284 - The .N and .W suffixes are recognized and honored (it is an error
285 if they cannot be honored).
286 - All instructions set the flags if and only if they have an 's' affix.
287 - Conditional affixes may be used. They are validated against
288 preceding IT instructions. Unlike ARM mode, you cannot use a
289 conditional affix except in the scope of an IT instruction. */
291 static bfd_boolean unified_syntax = FALSE;
293 enum neon_el_type
295 NT_invtype,
296 NT_untyped,
297 NT_integer,
298 NT_float,
299 NT_poly,
300 NT_signed,
301 NT_unsigned
304 struct neon_type_el
306 enum neon_el_type type;
307 unsigned size;
310 #define NEON_MAX_TYPE_ELS 4
312 struct neon_type
314 struct neon_type_el el[NEON_MAX_TYPE_ELS];
315 unsigned elems;
318 struct arm_it
320 const char * error;
321 unsigned long instruction;
322 int size;
323 int size_req;
324 int cond;
325 /* "uncond_value" is set to the value in place of the conditional field in
326 unconditional versions of the instruction, or -1 if nothing is
327 appropriate. */
328 int uncond_value;
329 struct neon_type vectype;
330 /* Set to the opcode if the instruction needs relaxation.
331 Zero if the instruction is not relaxed. */
332 unsigned long relax;
333 struct
335 bfd_reloc_code_real_type type;
336 expressionS exp;
337 int pc_rel;
338 } reloc;
340 struct
342 unsigned reg;
343 signed int imm;
344 struct neon_type_el vectype;
345 unsigned present : 1; /* Operand present. */
346 unsigned isreg : 1; /* Operand was a register. */
347 unsigned immisreg : 1; /* .imm field is a second register. */
348 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
349 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
350 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
351 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
352 instructions. This allows us to disambiguate ARM <-> vector insns. */
353 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
354 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
355 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
356 unsigned issingle : 1; /* Operand is VFP single-precision register. */
357 unsigned hasreloc : 1; /* Operand has relocation suffix. */
358 unsigned writeback : 1; /* Operand has trailing ! */
359 unsigned preind : 1; /* Preindexed address. */
360 unsigned postind : 1; /* Postindexed address. */
361 unsigned negative : 1; /* Index register was negated. */
362 unsigned shifted : 1; /* Shift applied to operation. */
363 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
364 } operands[6];
367 static struct arm_it inst;
369 #define NUM_FLOAT_VALS 8
371 const char * fp_const[] =
373 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
376 /* Number of littlenums required to hold an extended precision number. */
377 #define MAX_LITTLENUMS 6
379 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
381 #define FAIL (-1)
382 #define SUCCESS (0)
384 #define SUFF_S 1
385 #define SUFF_D 2
386 #define SUFF_E 3
387 #define SUFF_P 4
389 #define CP_T_X 0x00008000
390 #define CP_T_Y 0x00400000
392 #define CONDS_BIT 0x00100000
393 #define LOAD_BIT 0x00100000
395 #define DOUBLE_LOAD_FLAG 0x00000001
397 struct asm_cond
399 const char * template;
400 unsigned long value;
403 #define COND_ALWAYS 0xE
405 struct asm_psr
407 const char *template;
408 unsigned long field;
411 struct asm_barrier_opt
413 const char *template;
414 unsigned long value;
417 /* The bit that distinguishes CPSR and SPSR. */
418 #define SPSR_BIT (1 << 22)
420 /* The individual PSR flag bits. */
421 #define PSR_c (1 << 16)
422 #define PSR_x (1 << 17)
423 #define PSR_s (1 << 18)
424 #define PSR_f (1 << 19)
426 struct reloc_entry
428 char *name;
429 bfd_reloc_code_real_type reloc;
432 enum vfp_reg_pos
434 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
435 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
438 enum vfp_ldstm_type
440 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
443 /* Bits for DEFINED field in neon_typed_alias. */
444 #define NTA_HASTYPE 1
445 #define NTA_HASINDEX 2
447 struct neon_typed_alias
449 unsigned char defined;
450 unsigned char index;
451 struct neon_type_el eltype;
454 /* ARM register categories. This includes coprocessor numbers and various
455 architecture extensions' registers. */
456 enum arm_reg_type
458 REG_TYPE_RN,
459 REG_TYPE_CP,
460 REG_TYPE_CN,
461 REG_TYPE_FN,
462 REG_TYPE_VFS,
463 REG_TYPE_VFD,
464 REG_TYPE_NQ,
465 REG_TYPE_VFSD,
466 REG_TYPE_NDQ,
467 REG_TYPE_NSDQ,
468 REG_TYPE_VFC,
469 REG_TYPE_MVF,
470 REG_TYPE_MVD,
471 REG_TYPE_MVFX,
472 REG_TYPE_MVDX,
473 REG_TYPE_MVAX,
474 REG_TYPE_DSPSC,
475 REG_TYPE_MMXWR,
476 REG_TYPE_MMXWC,
477 REG_TYPE_MMXWCG,
478 REG_TYPE_XSCALE,
481 /* Structure for a hash table entry for a register.
482 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
483 information which states whether a vector type or index is specified (for a
484 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
485 struct reg_entry
487 const char *name;
488 unsigned char number;
489 unsigned char type;
490 unsigned char builtin;
491 struct neon_typed_alias *neon;
494 /* Diagnostics used when we don't get a register of the expected type. */
495 const char *const reg_expected_msgs[] =
497 N_("ARM register expected"),
498 N_("bad or missing co-processor number"),
499 N_("co-processor register expected"),
500 N_("FPA register expected"),
501 N_("VFP single precision register expected"),
502 N_("VFP/Neon double precision register expected"),
503 N_("Neon quad precision register expected"),
504 N_("VFP single or double precision register expected"),
505 N_("Neon double or quad precision register expected"),
506 N_("VFP single, double or Neon quad precision register expected"),
507 N_("VFP system register expected"),
508 N_("Maverick MVF register expected"),
509 N_("Maverick MVD register expected"),
510 N_("Maverick MVFX register expected"),
511 N_("Maverick MVDX register expected"),
512 N_("Maverick MVAX register expected"),
513 N_("Maverick DSPSC register expected"),
514 N_("iWMMXt data register expected"),
515 N_("iWMMXt control register expected"),
516 N_("iWMMXt scalar register expected"),
517 N_("XScale accumulator register expected"),
520 /* Some well known registers that we refer to directly elsewhere. */
521 #define REG_SP 13
522 #define REG_LR 14
523 #define REG_PC 15
525 /* ARM instructions take 4bytes in the object file, Thumb instructions
526 take 2: */
527 #define INSN_SIZE 4
529 struct asm_opcode
531 /* Basic string to match. */
532 const char *template;
534 /* Parameters to instruction. */
535 unsigned char operands[8];
537 /* Conditional tag - see opcode_lookup. */
538 unsigned int tag : 4;
540 /* Basic instruction code. */
541 unsigned int avalue : 28;
543 /* Thumb-format instruction code. */
544 unsigned int tvalue;
546 /* Which architecture variant provides this instruction. */
547 const arm_feature_set *avariant;
548 const arm_feature_set *tvariant;
550 /* Function to call to encode instruction in ARM format. */
551 void (* aencode) (void);
553 /* Function to call to encode instruction in Thumb format. */
554 void (* tencode) (void);
557 /* Defines for various bits that we will want to toggle. */
558 #define INST_IMMEDIATE 0x02000000
559 #define OFFSET_REG 0x02000000
560 #define HWOFFSET_IMM 0x00400000
561 #define SHIFT_BY_REG 0x00000010
562 #define PRE_INDEX 0x01000000
563 #define INDEX_UP 0x00800000
564 #define WRITE_BACK 0x00200000
565 #define LDM_TYPE_2_OR_3 0x00400000
566 #define CPSI_MMOD 0x00020000
568 #define LITERAL_MASK 0xf000f000
569 #define OPCODE_MASK 0xfe1fffff
570 #define V4_STR_BIT 0x00000020
572 #define T2_SUBS_PC_LR 0xf3de8f00
574 #define DATA_OP_SHIFT 21
576 #define T2_OPCODE_MASK 0xfe1fffff
577 #define T2_DATA_OP_SHIFT 21
579 /* Codes to distinguish the arithmetic instructions. */
580 #define OPCODE_AND 0
581 #define OPCODE_EOR 1
582 #define OPCODE_SUB 2
583 #define OPCODE_RSB 3
584 #define OPCODE_ADD 4
585 #define OPCODE_ADC 5
586 #define OPCODE_SBC 6
587 #define OPCODE_RSC 7
588 #define OPCODE_TST 8
589 #define OPCODE_TEQ 9
590 #define OPCODE_CMP 10
591 #define OPCODE_CMN 11
592 #define OPCODE_ORR 12
593 #define OPCODE_MOV 13
594 #define OPCODE_BIC 14
595 #define OPCODE_MVN 15
597 #define T2_OPCODE_AND 0
598 #define T2_OPCODE_BIC 1
599 #define T2_OPCODE_ORR 2
600 #define T2_OPCODE_ORN 3
601 #define T2_OPCODE_EOR 4
602 #define T2_OPCODE_ADD 8
603 #define T2_OPCODE_ADC 10
604 #define T2_OPCODE_SBC 11
605 #define T2_OPCODE_SUB 13
606 #define T2_OPCODE_RSB 14
608 #define T_OPCODE_MUL 0x4340
609 #define T_OPCODE_TST 0x4200
610 #define T_OPCODE_CMN 0x42c0
611 #define T_OPCODE_NEG 0x4240
612 #define T_OPCODE_MVN 0x43c0
614 #define T_OPCODE_ADD_R3 0x1800
615 #define T_OPCODE_SUB_R3 0x1a00
616 #define T_OPCODE_ADD_HI 0x4400
617 #define T_OPCODE_ADD_ST 0xb000
618 #define T_OPCODE_SUB_ST 0xb080
619 #define T_OPCODE_ADD_SP 0xa800
620 #define T_OPCODE_ADD_PC 0xa000
621 #define T_OPCODE_ADD_I8 0x3000
622 #define T_OPCODE_SUB_I8 0x3800
623 #define T_OPCODE_ADD_I3 0x1c00
624 #define T_OPCODE_SUB_I3 0x1e00
626 #define T_OPCODE_ASR_R 0x4100
627 #define T_OPCODE_LSL_R 0x4080
628 #define T_OPCODE_LSR_R 0x40c0
629 #define T_OPCODE_ROR_R 0x41c0
630 #define T_OPCODE_ASR_I 0x1000
631 #define T_OPCODE_LSL_I 0x0000
632 #define T_OPCODE_LSR_I 0x0800
634 #define T_OPCODE_MOV_I8 0x2000
635 #define T_OPCODE_CMP_I8 0x2800
636 #define T_OPCODE_CMP_LR 0x4280
637 #define T_OPCODE_MOV_HR 0x4600
638 #define T_OPCODE_CMP_HR 0x4500
640 #define T_OPCODE_LDR_PC 0x4800
641 #define T_OPCODE_LDR_SP 0x9800
642 #define T_OPCODE_STR_SP 0x9000
643 #define T_OPCODE_LDR_IW 0x6800
644 #define T_OPCODE_STR_IW 0x6000
645 #define T_OPCODE_LDR_IH 0x8800
646 #define T_OPCODE_STR_IH 0x8000
647 #define T_OPCODE_LDR_IB 0x7800
648 #define T_OPCODE_STR_IB 0x7000
649 #define T_OPCODE_LDR_RW 0x5800
650 #define T_OPCODE_STR_RW 0x5000
651 #define T_OPCODE_LDR_RH 0x5a00
652 #define T_OPCODE_STR_RH 0x5200
653 #define T_OPCODE_LDR_RB 0x5c00
654 #define T_OPCODE_STR_RB 0x5400
656 #define T_OPCODE_PUSH 0xb400
657 #define T_OPCODE_POP 0xbc00
659 #define T_OPCODE_BRANCH 0xe000
661 #define THUMB_SIZE 2 /* Size of thumb instruction. */
662 #define THUMB_PP_PC_LR 0x0100
663 #define THUMB_LOAD_BIT 0x0800
664 #define THUMB2_LOAD_BIT 0x00100000
666 #define BAD_ARGS _("bad arguments to instruction")
667 #define BAD_SP _("r13 not allowed here")
668 #define BAD_PC _("r15 not allowed here")
669 #define BAD_COND _("instruction cannot be conditional")
670 #define BAD_OVERLAP _("registers may not be the same")
671 #define BAD_HIREG _("lo register required")
672 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
673 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
674 #define BAD_BRANCH _("branch must be last instruction in IT block")
675 #define BAD_NOT_IT _("instruction not allowed in IT block")
676 #define BAD_FPU _("selected FPU does not support instruction")
678 static struct hash_control *arm_ops_hsh;
679 static struct hash_control *arm_cond_hsh;
680 static struct hash_control *arm_shift_hsh;
681 static struct hash_control *arm_psr_hsh;
682 static struct hash_control *arm_v7m_psr_hsh;
683 static struct hash_control *arm_reg_hsh;
684 static struct hash_control *arm_reloc_hsh;
685 static struct hash_control *arm_barrier_opt_hsh;
687 /* Stuff needed to resolve the label ambiguity
690 label: <insn>
691 may differ from:
693 label:
694 <insn> */
696 symbolS * last_label_seen;
697 static int label_is_thumb_function_name = FALSE;
699 /* Literal pool structure. Held on a per-section
700 and per-sub-section basis. */
702 #define MAX_LITERAL_POOL_SIZE 1024
703 typedef struct literal_pool
705 expressionS literals [MAX_LITERAL_POOL_SIZE];
706 unsigned int next_free_entry;
707 unsigned int id;
708 symbolS * symbol;
709 segT section;
710 subsegT sub_section;
711 struct literal_pool * next;
712 } literal_pool;
714 /* Pointer to a linked list of literal pools. */
715 literal_pool * list_of_pools = NULL;
717 /* State variables for IT block handling. */
718 static bfd_boolean current_it_mask = 0;
719 static int current_cc;
721 /* Pure syntax. */
723 /* This array holds the chars that always start a comment. If the
724 pre-processor is disabled, these aren't very useful. */
725 const char comment_chars[] = "@";
727 /* This array holds the chars that only start a comment at the beginning of
728 a line. If the line seems to have the form '# 123 filename'
729 .line and .file directives will appear in the pre-processed output. */
730 /* Note that input_file.c hand checks for '#' at the beginning of the
731 first line of the input file. This is because the compiler outputs
732 #NO_APP at the beginning of its output. */
733 /* Also note that comments like this one will always work. */
734 const char line_comment_chars[] = "#";
736 const char line_separator_chars[] = ";";
738 /* Chars that can be used to separate mant
739 from exp in floating point numbers. */
740 const char EXP_CHARS[] = "eE";
742 /* Chars that mean this number is a floating point constant. */
743 /* As in 0f12.456 */
744 /* or 0d1.2345e12 */
746 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
748 /* Prefix characters that indicate the start of an immediate
749 value. */
750 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
752 /* Separator character handling. */
754 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
756 static inline int
757 skip_past_char (char ** str, char c)
759 if (**str == c)
761 (*str)++;
762 return SUCCESS;
764 else
765 return FAIL;
767 #define skip_past_comma(str) skip_past_char (str, ',')
769 /* Arithmetic expressions (possibly involving symbols). */
771 /* Return TRUE if anything in the expression is a bignum. */
773 static int
774 walk_no_bignums (symbolS * sp)
776 if (symbol_get_value_expression (sp)->X_op == O_big)
777 return 1;
779 if (symbol_get_value_expression (sp)->X_add_symbol)
781 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
782 || (symbol_get_value_expression (sp)->X_op_symbol
783 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
786 return 0;
789 static int in_my_get_expression = 0;
791 /* Third argument to my_get_expression. */
792 #define GE_NO_PREFIX 0
793 #define GE_IMM_PREFIX 1
794 #define GE_OPT_PREFIX 2
795 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
796 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
797 #define GE_OPT_PREFIX_BIG 3
799 static int
800 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
802 char * save_in;
803 segT seg;
805 /* In unified syntax, all prefixes are optional. */
806 if (unified_syntax)
807 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
808 : GE_OPT_PREFIX;
810 switch (prefix_mode)
812 case GE_NO_PREFIX: break;
813 case GE_IMM_PREFIX:
814 if (!is_immediate_prefix (**str))
816 inst.error = _("immediate expression requires a # prefix");
817 return FAIL;
819 (*str)++;
820 break;
821 case GE_OPT_PREFIX:
822 case GE_OPT_PREFIX_BIG:
823 if (is_immediate_prefix (**str))
824 (*str)++;
825 break;
826 default: abort ();
829 memset (ep, 0, sizeof (expressionS));
831 save_in = input_line_pointer;
832 input_line_pointer = *str;
833 in_my_get_expression = 1;
834 seg = expression (ep);
835 in_my_get_expression = 0;
837 if (ep->X_op == O_illegal)
839 /* We found a bad expression in md_operand(). */
840 *str = input_line_pointer;
841 input_line_pointer = save_in;
842 if (inst.error == NULL)
843 inst.error = _("bad expression");
844 return 1;
847 #ifdef OBJ_AOUT
848 if (seg != absolute_section
849 && seg != text_section
850 && seg != data_section
851 && seg != bss_section
852 && seg != undefined_section)
854 inst.error = _("bad segment");
855 *str = input_line_pointer;
856 input_line_pointer = save_in;
857 return 1;
859 #endif
861 /* Get rid of any bignums now, so that we don't generate an error for which
862 we can't establish a line number later on. Big numbers are never valid
863 in instructions, which is where this routine is always called. */
864 if (prefix_mode != GE_OPT_PREFIX_BIG
865 && (ep->X_op == O_big
866 || (ep->X_add_symbol
867 && (walk_no_bignums (ep->X_add_symbol)
868 || (ep->X_op_symbol
869 && walk_no_bignums (ep->X_op_symbol))))))
871 inst.error = _("invalid constant");
872 *str = input_line_pointer;
873 input_line_pointer = save_in;
874 return 1;
877 *str = input_line_pointer;
878 input_line_pointer = save_in;
879 return 0;
882 /* Turn a string in input_line_pointer into a floating point constant
883 of type TYPE, and store the appropriate bytes in *LITP. The number
884 of LITTLENUMS emitted is stored in *SIZEP. An error message is
885 returned, or NULL on OK.
887 Note that fp constants aren't represent in the normal way on the ARM.
888 In big endian mode, things are as expected. However, in little endian
889 mode fp constants are big-endian word-wise, and little-endian byte-wise
890 within the words. For example, (double) 1.1 in big endian mode is
891 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
892 the byte sequence 99 99 f1 3f 9a 99 99 99.
894 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
896 char *
897 md_atof (int type, char * litP, int * sizeP)
899 int prec;
900 LITTLENUM_TYPE words[MAX_LITTLENUMS];
901 char *t;
902 int i;
904 switch (type)
906 case 'f':
907 case 'F':
908 case 's':
909 case 'S':
910 prec = 2;
911 break;
913 case 'd':
914 case 'D':
915 case 'r':
916 case 'R':
917 prec = 4;
918 break;
920 case 'x':
921 case 'X':
922 prec = 5;
923 break;
925 case 'p':
926 case 'P':
927 prec = 5;
928 break;
930 default:
931 *sizeP = 0;
932 return _("Unrecognized or unsupported floating point constant");
935 t = atof_ieee (input_line_pointer, type, words);
936 if (t)
937 input_line_pointer = t;
938 *sizeP = prec * sizeof (LITTLENUM_TYPE);
940 if (target_big_endian)
942 for (i = 0; i < prec; i++)
944 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
945 litP += sizeof (LITTLENUM_TYPE);
948 else
950 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
951 for (i = prec - 1; i >= 0; i--)
953 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
954 litP += sizeof (LITTLENUM_TYPE);
956 else
957 /* For a 4 byte float the order of elements in `words' is 1 0.
958 For an 8 byte float the order is 1 0 3 2. */
959 for (i = 0; i < prec; i += 2)
961 md_number_to_chars (litP, (valueT) words[i + 1],
962 sizeof (LITTLENUM_TYPE));
963 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
964 (valueT) words[i], sizeof (LITTLENUM_TYPE));
965 litP += 2 * sizeof (LITTLENUM_TYPE);
969 return NULL;
972 /* We handle all bad expressions here, so that we can report the faulty
973 instruction in the error message. */
974 void
975 md_operand (expressionS * expr)
977 if (in_my_get_expression)
978 expr->X_op = O_illegal;
981 /* Immediate values. */
983 /* Generic immediate-value read function for use in directives.
984 Accepts anything that 'expression' can fold to a constant.
985 *val receives the number. */
986 #ifdef OBJ_ELF
987 static int
988 immediate_for_directive (int *val)
990 expressionS exp;
991 exp.X_op = O_illegal;
993 if (is_immediate_prefix (*input_line_pointer))
995 input_line_pointer++;
996 expression (&exp);
999 if (exp.X_op != O_constant)
1001 as_bad (_("expected #constant"));
1002 ignore_rest_of_line ();
1003 return FAIL;
1005 *val = exp.X_add_number;
1006 return SUCCESS;
1008 #endif
1010 /* Register parsing. */
1012 /* Generic register parser. CCP points to what should be the
1013 beginning of a register name. If it is indeed a valid register
1014 name, advance CCP over it and return the reg_entry structure;
1015 otherwise return NULL. Does not issue diagnostics. */
1017 static struct reg_entry *
1018 arm_reg_parse_multi (char **ccp)
1020 char *start = *ccp;
1021 char *p;
1022 struct reg_entry *reg;
1024 #ifdef REGISTER_PREFIX
1025 if (*start != REGISTER_PREFIX)
1026 return NULL;
1027 start++;
1028 #endif
1029 #ifdef OPTIONAL_REGISTER_PREFIX
1030 if (*start == OPTIONAL_REGISTER_PREFIX)
1031 start++;
1032 #endif
1034 p = start;
1035 if (!ISALPHA (*p) || !is_name_beginner (*p))
1036 return NULL;
1039 p++;
1040 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1042 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1044 if (!reg)
1045 return NULL;
1047 *ccp = p;
1048 return reg;
1051 static int
1052 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1053 enum arm_reg_type type)
1055 /* Alternative syntaxes are accepted for a few register classes. */
1056 switch (type)
1058 case REG_TYPE_MVF:
1059 case REG_TYPE_MVD:
1060 case REG_TYPE_MVFX:
1061 case REG_TYPE_MVDX:
1062 /* Generic coprocessor register names are allowed for these. */
1063 if (reg && reg->type == REG_TYPE_CN)
1064 return reg->number;
1065 break;
1067 case REG_TYPE_CP:
1068 /* For backward compatibility, a bare number is valid here. */
1070 unsigned long processor = strtoul (start, ccp, 10);
1071 if (*ccp != start && processor <= 15)
1072 return processor;
1075 case REG_TYPE_MMXWC:
1076 /* WC includes WCG. ??? I'm not sure this is true for all
1077 instructions that take WC registers. */
1078 if (reg && reg->type == REG_TYPE_MMXWCG)
1079 return reg->number;
1080 break;
1082 default:
1083 break;
1086 return FAIL;
1089 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1090 return value is the register number or FAIL. */
1092 static int
1093 arm_reg_parse (char **ccp, enum arm_reg_type type)
1095 char *start = *ccp;
1096 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1097 int ret;
1099 /* Do not allow a scalar (reg+index) to parse as a register. */
1100 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1101 return FAIL;
1103 if (reg && reg->type == type)
1104 return reg->number;
1106 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1107 return ret;
1109 *ccp = start;
1110 return FAIL;
1113 /* Parse a Neon type specifier. *STR should point at the leading '.'
1114 character. Does no verification at this stage that the type fits the opcode
1115 properly. E.g.,
1117 .i32.i32.s16
1118 .s32.f32
1119 .u16
1121 Can all be legally parsed by this function.
1123 Fills in neon_type struct pointer with parsed information, and updates STR
1124 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1125 type, FAIL if not. */
1127 static int
1128 parse_neon_type (struct neon_type *type, char **str)
1130 char *ptr = *str;
1132 if (type)
1133 type->elems = 0;
1135 while (type->elems < NEON_MAX_TYPE_ELS)
1137 enum neon_el_type thistype = NT_untyped;
1138 unsigned thissize = -1u;
1140 if (*ptr != '.')
1141 break;
1143 ptr++;
1145 /* Just a size without an explicit type. */
1146 if (ISDIGIT (*ptr))
1147 goto parsesize;
1149 switch (TOLOWER (*ptr))
1151 case 'i': thistype = NT_integer; break;
1152 case 'f': thistype = NT_float; break;
1153 case 'p': thistype = NT_poly; break;
1154 case 's': thistype = NT_signed; break;
1155 case 'u': thistype = NT_unsigned; break;
1156 case 'd':
1157 thistype = NT_float;
1158 thissize = 64;
1159 ptr++;
1160 goto done;
1161 default:
1162 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1163 return FAIL;
1166 ptr++;
1168 /* .f is an abbreviation for .f32. */
1169 if (thistype == NT_float && !ISDIGIT (*ptr))
1170 thissize = 32;
1171 else
1173 parsesize:
1174 thissize = strtoul (ptr, &ptr, 10);
1176 if (thissize != 8 && thissize != 16 && thissize != 32
1177 && thissize != 64)
1179 as_bad (_("bad size %d in type specifier"), thissize);
1180 return FAIL;
1184 done:
1185 if (type)
1187 type->el[type->elems].type = thistype;
1188 type->el[type->elems].size = thissize;
1189 type->elems++;
1193 /* Empty/missing type is not a successful parse. */
1194 if (type->elems == 0)
1195 return FAIL;
1197 *str = ptr;
1199 return SUCCESS;
1202 /* Errors may be set multiple times during parsing or bit encoding
1203 (particularly in the Neon bits), but usually the earliest error which is set
1204 will be the most meaningful. Avoid overwriting it with later (cascading)
1205 errors by calling this function. */
1207 static void
1208 first_error (const char *err)
1210 if (!inst.error)
1211 inst.error = err;
1214 /* Parse a single type, e.g. ".s32", leading period included. */
1215 static int
1216 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1218 char *str = *ccp;
1219 struct neon_type optype;
1221 if (*str == '.')
1223 if (parse_neon_type (&optype, &str) == SUCCESS)
1225 if (optype.elems == 1)
1226 *vectype = optype.el[0];
1227 else
1229 first_error (_("only one type should be specified for operand"));
1230 return FAIL;
1233 else
1235 first_error (_("vector type expected"));
1236 return FAIL;
1239 else
1240 return FAIL;
1242 *ccp = str;
1244 return SUCCESS;
1247 /* Special meanings for indices (which have a range of 0-7), which will fit into
1248 a 4-bit integer. */
1250 #define NEON_ALL_LANES 15
1251 #define NEON_INTERLEAVE_LANES 14
1253 /* Parse either a register or a scalar, with an optional type. Return the
1254 register number, and optionally fill in the actual type of the register
1255 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1256 type/index information in *TYPEINFO. */
1258 static int
1259 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1260 enum arm_reg_type *rtype,
1261 struct neon_typed_alias *typeinfo)
1263 char *str = *ccp;
1264 struct reg_entry *reg = arm_reg_parse_multi (&str);
1265 struct neon_typed_alias atype;
1266 struct neon_type_el parsetype;
1268 atype.defined = 0;
1269 atype.index = -1;
1270 atype.eltype.type = NT_invtype;
1271 atype.eltype.size = -1;
1273 /* Try alternate syntax for some types of register. Note these are mutually
1274 exclusive with the Neon syntax extensions. */
1275 if (reg == NULL)
1277 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1278 if (altreg != FAIL)
1279 *ccp = str;
1280 if (typeinfo)
1281 *typeinfo = atype;
1282 return altreg;
1285 /* Undo polymorphism when a set of register types may be accepted. */
1286 if ((type == REG_TYPE_NDQ
1287 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1288 || (type == REG_TYPE_VFSD
1289 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1290 || (type == REG_TYPE_NSDQ
1291 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1292 || reg->type == REG_TYPE_NQ))
1293 || (type == REG_TYPE_MMXWC
1294 && (reg->type == REG_TYPE_MMXWCG)))
1295 type = reg->type;
1297 if (type != reg->type)
1298 return FAIL;
1300 if (reg->neon)
1301 atype = *reg->neon;
1303 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1305 if ((atype.defined & NTA_HASTYPE) != 0)
1307 first_error (_("can't redefine type for operand"));
1308 return FAIL;
1310 atype.defined |= NTA_HASTYPE;
1311 atype.eltype = parsetype;
1314 if (skip_past_char (&str, '[') == SUCCESS)
1316 if (type != REG_TYPE_VFD)
1318 first_error (_("only D registers may be indexed"));
1319 return FAIL;
1322 if ((atype.defined & NTA_HASINDEX) != 0)
1324 first_error (_("can't change index for operand"));
1325 return FAIL;
1328 atype.defined |= NTA_HASINDEX;
1330 if (skip_past_char (&str, ']') == SUCCESS)
1331 atype.index = NEON_ALL_LANES;
1332 else
1334 expressionS exp;
1336 my_get_expression (&exp, &str, GE_NO_PREFIX);
1338 if (exp.X_op != O_constant)
1340 first_error (_("constant expression required"));
1341 return FAIL;
1344 if (skip_past_char (&str, ']') == FAIL)
1345 return FAIL;
1347 atype.index = exp.X_add_number;
1351 if (typeinfo)
1352 *typeinfo = atype;
1354 if (rtype)
1355 *rtype = type;
1357 *ccp = str;
1359 return reg->number;
1362 /* Like arm_reg_parse, but allow allow the following extra features:
1363 - If RTYPE is non-zero, return the (possibly restricted) type of the
1364 register (e.g. Neon double or quad reg when either has been requested).
1365 - If this is a Neon vector type with additional type information, fill
1366 in the struct pointed to by VECTYPE (if non-NULL).
1367 This function will fault on encountering a scalar. */
1369 static int
1370 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1371 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1373 struct neon_typed_alias atype;
1374 char *str = *ccp;
1375 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1377 if (reg == FAIL)
1378 return FAIL;
1380 /* Do not allow a scalar (reg+index) to parse as a register. */
1381 if ((atype.defined & NTA_HASINDEX) != 0)
1383 first_error (_("register operand expected, but got scalar"));
1384 return FAIL;
1387 if (vectype)
1388 *vectype = atype.eltype;
1390 *ccp = str;
1392 return reg;
1395 #define NEON_SCALAR_REG(X) ((X) >> 4)
1396 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1398 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1399 have enough information to be able to do a good job bounds-checking. So, we
1400 just do easy checks here, and do further checks later. */
1402 static int
1403 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1405 int reg;
1406 char *str = *ccp;
1407 struct neon_typed_alias atype;
1409 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1411 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1412 return FAIL;
1414 if (atype.index == NEON_ALL_LANES)
1416 first_error (_("scalar must have an index"));
1417 return FAIL;
1419 else if (atype.index >= 64 / elsize)
1421 first_error (_("scalar index out of range"));
1422 return FAIL;
1425 if (type)
1426 *type = atype.eltype;
1428 *ccp = str;
1430 return reg * 16 + atype.index;
1433 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1434 static long
1435 parse_reg_list (char ** strp)
1437 char * str = * strp;
1438 long range = 0;
1439 int another_range;
1441 /* We come back here if we get ranges concatenated by '+' or '|'. */
1444 another_range = 0;
1446 if (*str == '{')
1448 int in_range = 0;
1449 int cur_reg = -1;
1451 str++;
1454 int reg;
1456 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1458 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1459 return FAIL;
1462 if (in_range)
1464 int i;
1466 if (reg <= cur_reg)
1468 first_error (_("bad range in register list"));
1469 return FAIL;
1472 for (i = cur_reg + 1; i < reg; i++)
1474 if (range & (1 << i))
1475 as_tsktsk
1476 (_("Warning: duplicated register (r%d) in register list"),
1478 else
1479 range |= 1 << i;
1481 in_range = 0;
1484 if (range & (1 << reg))
1485 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1486 reg);
1487 else if (reg <= cur_reg)
1488 as_tsktsk (_("Warning: register range not in ascending order"));
1490 range |= 1 << reg;
1491 cur_reg = reg;
1493 while (skip_past_comma (&str) != FAIL
1494 || (in_range = 1, *str++ == '-'));
1495 str--;
1497 if (*str++ != '}')
1499 first_error (_("missing `}'"));
1500 return FAIL;
1503 else
1505 expressionS expr;
1507 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1508 return FAIL;
1510 if (expr.X_op == O_constant)
1512 if (expr.X_add_number
1513 != (expr.X_add_number & 0x0000ffff))
1515 inst.error = _("invalid register mask");
1516 return FAIL;
1519 if ((range & expr.X_add_number) != 0)
1521 int regno = range & expr.X_add_number;
1523 regno &= -regno;
1524 regno = (1 << regno) - 1;
1525 as_tsktsk
1526 (_("Warning: duplicated register (r%d) in register list"),
1527 regno);
1530 range |= expr.X_add_number;
1532 else
1534 if (inst.reloc.type != 0)
1536 inst.error = _("expression too complex");
1537 return FAIL;
1540 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1541 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1542 inst.reloc.pc_rel = 0;
1546 if (*str == '|' || *str == '+')
1548 str++;
1549 another_range = 1;
1552 while (another_range);
1554 *strp = str;
1555 return range;
1558 /* Types of registers in a list. */
1560 enum reg_list_els
1562 REGLIST_VFP_S,
1563 REGLIST_VFP_D,
1564 REGLIST_NEON_D
1567 /* Parse a VFP register list. If the string is invalid return FAIL.
1568 Otherwise return the number of registers, and set PBASE to the first
1569 register. Parses registers of type ETYPE.
1570 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1571 - Q registers can be used to specify pairs of D registers
1572 - { } can be omitted from around a singleton register list
1573 FIXME: This is not implemented, as it would require backtracking in
1574 some cases, e.g.:
1575 vtbl.8 d3,d4,d5
1576 This could be done (the meaning isn't really ambiguous), but doesn't
1577 fit in well with the current parsing framework.
1578 - 32 D registers may be used (also true for VFPv3).
1579 FIXME: Types are ignored in these register lists, which is probably a
1580 bug. */
1582 static int
1583 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1585 char *str = *ccp;
1586 int base_reg;
1587 int new_base;
1588 enum arm_reg_type regtype = 0;
1589 int max_regs = 0;
1590 int count = 0;
1591 int warned = 0;
1592 unsigned long mask = 0;
1593 int i;
1595 if (*str != '{')
1597 inst.error = _("expecting {");
1598 return FAIL;
1601 str++;
1603 switch (etype)
1605 case REGLIST_VFP_S:
1606 regtype = REG_TYPE_VFS;
1607 max_regs = 32;
1608 break;
1610 case REGLIST_VFP_D:
1611 regtype = REG_TYPE_VFD;
1612 break;
1614 case REGLIST_NEON_D:
1615 regtype = REG_TYPE_NDQ;
1616 break;
1619 if (etype != REGLIST_VFP_S)
1621 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1622 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1624 max_regs = 32;
1625 if (thumb_mode)
1626 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1627 fpu_vfp_ext_d32);
1628 else
1629 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1630 fpu_vfp_ext_d32);
1632 else
1633 max_regs = 16;
1636 base_reg = max_regs;
1640 int setmask = 1, addregs = 1;
1642 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1644 if (new_base == FAIL)
1646 first_error (_(reg_expected_msgs[regtype]));
1647 return FAIL;
1650 if (new_base >= max_regs)
1652 first_error (_("register out of range in list"));
1653 return FAIL;
1656 /* Note: a value of 2 * n is returned for the register Q<n>. */
1657 if (regtype == REG_TYPE_NQ)
1659 setmask = 3;
1660 addregs = 2;
1663 if (new_base < base_reg)
1664 base_reg = new_base;
1666 if (mask & (setmask << new_base))
1668 first_error (_("invalid register list"));
1669 return FAIL;
1672 if ((mask >> new_base) != 0 && ! warned)
1674 as_tsktsk (_("register list not in ascending order"));
1675 warned = 1;
1678 mask |= setmask << new_base;
1679 count += addregs;
1681 if (*str == '-') /* We have the start of a range expression */
1683 int high_range;
1685 str++;
1687 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1688 == FAIL)
1690 inst.error = gettext (reg_expected_msgs[regtype]);
1691 return FAIL;
1694 if (high_range >= max_regs)
1696 first_error (_("register out of range in list"));
1697 return FAIL;
1700 if (regtype == REG_TYPE_NQ)
1701 high_range = high_range + 1;
1703 if (high_range <= new_base)
1705 inst.error = _("register range not in ascending order");
1706 return FAIL;
1709 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1711 if (mask & (setmask << new_base))
1713 inst.error = _("invalid register list");
1714 return FAIL;
1717 mask |= setmask << new_base;
1718 count += addregs;
1722 while (skip_past_comma (&str) != FAIL);
1724 str++;
1726 /* Sanity check -- should have raised a parse error above. */
1727 if (count == 0 || count > max_regs)
1728 abort ();
1730 *pbase = base_reg;
1732 /* Final test -- the registers must be consecutive. */
1733 mask >>= base_reg;
1734 for (i = 0; i < count; i++)
1736 if ((mask & (1u << i)) == 0)
1738 inst.error = _("non-contiguous register range");
1739 return FAIL;
1743 *ccp = str;
1745 return count;
1748 /* True if two alias types are the same. */
1750 static int
1751 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1753 if (!a && !b)
1754 return 1;
1756 if (!a || !b)
1757 return 0;
1759 if (a->defined != b->defined)
1760 return 0;
1762 if ((a->defined & NTA_HASTYPE) != 0
1763 && (a->eltype.type != b->eltype.type
1764 || a->eltype.size != b->eltype.size))
1765 return 0;
1767 if ((a->defined & NTA_HASINDEX) != 0
1768 && (a->index != b->index))
1769 return 0;
1771 return 1;
1774 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1775 The base register is put in *PBASE.
1776 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1777 the return value.
1778 The register stride (minus one) is put in bit 4 of the return value.
1779 Bits [6:5] encode the list length (minus one).
1780 The type of the list elements is put in *ELTYPE, if non-NULL. */
1782 #define NEON_LANE(X) ((X) & 0xf)
1783 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1784 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1786 static int
1787 parse_neon_el_struct_list (char **str, unsigned *pbase,
1788 struct neon_type_el *eltype)
1790 char *ptr = *str;
1791 int base_reg = -1;
1792 int reg_incr = -1;
1793 int count = 0;
1794 int lane = -1;
1795 int leading_brace = 0;
1796 enum arm_reg_type rtype = REG_TYPE_NDQ;
1797 int addregs = 1;
1798 const char *const incr_error = "register stride must be 1 or 2";
1799 const char *const type_error = "mismatched element/structure types in list";
1800 struct neon_typed_alias firsttype;
1802 if (skip_past_char (&ptr, '{') == SUCCESS)
1803 leading_brace = 1;
1807 struct neon_typed_alias atype;
1808 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1810 if (getreg == FAIL)
1812 first_error (_(reg_expected_msgs[rtype]));
1813 return FAIL;
1816 if (base_reg == -1)
1818 base_reg = getreg;
1819 if (rtype == REG_TYPE_NQ)
1821 reg_incr = 1;
1822 addregs = 2;
1824 firsttype = atype;
1826 else if (reg_incr == -1)
1828 reg_incr = getreg - base_reg;
1829 if (reg_incr < 1 || reg_incr > 2)
1831 first_error (_(incr_error));
1832 return FAIL;
1835 else if (getreg != base_reg + reg_incr * count)
1837 first_error (_(incr_error));
1838 return FAIL;
1841 if (!neon_alias_types_same (&atype, &firsttype))
1843 first_error (_(type_error));
1844 return FAIL;
1847 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1848 modes. */
1849 if (ptr[0] == '-')
1851 struct neon_typed_alias htype;
1852 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1853 if (lane == -1)
1854 lane = NEON_INTERLEAVE_LANES;
1855 else if (lane != NEON_INTERLEAVE_LANES)
1857 first_error (_(type_error));
1858 return FAIL;
1860 if (reg_incr == -1)
1861 reg_incr = 1;
1862 else if (reg_incr != 1)
1864 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1865 return FAIL;
1867 ptr++;
1868 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1869 if (hireg == FAIL)
1871 first_error (_(reg_expected_msgs[rtype]));
1872 return FAIL;
1874 if (!neon_alias_types_same (&htype, &firsttype))
1876 first_error (_(type_error));
1877 return FAIL;
1879 count += hireg + dregs - getreg;
1880 continue;
1883 /* If we're using Q registers, we can't use [] or [n] syntax. */
1884 if (rtype == REG_TYPE_NQ)
1886 count += 2;
1887 continue;
1890 if ((atype.defined & NTA_HASINDEX) != 0)
1892 if (lane == -1)
1893 lane = atype.index;
1894 else if (lane != atype.index)
1896 first_error (_(type_error));
1897 return FAIL;
1900 else if (lane == -1)
1901 lane = NEON_INTERLEAVE_LANES;
1902 else if (lane != NEON_INTERLEAVE_LANES)
1904 first_error (_(type_error));
1905 return FAIL;
1907 count++;
1909 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1911 /* No lane set by [x]. We must be interleaving structures. */
1912 if (lane == -1)
1913 lane = NEON_INTERLEAVE_LANES;
1915 /* Sanity check. */
1916 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1917 || (count > 1 && reg_incr == -1))
1919 first_error (_("error parsing element/structure list"));
1920 return FAIL;
1923 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1925 first_error (_("expected }"));
1926 return FAIL;
1929 if (reg_incr == -1)
1930 reg_incr = 1;
1932 if (eltype)
1933 *eltype = firsttype.eltype;
1935 *pbase = base_reg;
1936 *str = ptr;
1938 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1941 /* Parse an explicit relocation suffix on an expression. This is
1942 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1943 arm_reloc_hsh contains no entries, so this function can only
1944 succeed if there is no () after the word. Returns -1 on error,
1945 BFD_RELOC_UNUSED if there wasn't any suffix. */
1946 static int
1947 parse_reloc (char **str)
1949 struct reloc_entry *r;
1950 char *p, *q;
1952 if (**str != '(')
1953 return BFD_RELOC_UNUSED;
1955 p = *str + 1;
1956 q = p;
1958 while (*q && *q != ')' && *q != ',')
1959 q++;
1960 if (*q != ')')
1961 return -1;
1963 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1964 return -1;
1966 *str = q + 1;
1967 return r->reloc;
1970 /* Directives: register aliases. */
1972 static struct reg_entry *
1973 insert_reg_alias (char *str, int number, int type)
1975 struct reg_entry *new;
1976 const char *name;
1978 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1980 if (new->builtin)
1981 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1983 /* Only warn about a redefinition if it's not defined as the
1984 same register. */
1985 else if (new->number != number || new->type != type)
1986 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1988 return NULL;
1991 name = xstrdup (str);
1992 new = xmalloc (sizeof (struct reg_entry));
1994 new->name = name;
1995 new->number = number;
1996 new->type = type;
1997 new->builtin = FALSE;
1998 new->neon = NULL;
2000 if (hash_insert (arm_reg_hsh, name, (void *) new))
2001 abort ();
2003 return new;
2006 static void
2007 insert_neon_reg_alias (char *str, int number, int type,
2008 struct neon_typed_alias *atype)
2010 struct reg_entry *reg = insert_reg_alias (str, number, type);
2012 if (!reg)
2014 first_error (_("attempt to redefine typed alias"));
2015 return;
2018 if (atype)
2020 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2021 *reg->neon = *atype;
2025 /* Look for the .req directive. This is of the form:
2027 new_register_name .req existing_register_name
2029 If we find one, or if it looks sufficiently like one that we want to
2030 handle any error here, return TRUE. Otherwise return FALSE. */
2032 static bfd_boolean
2033 create_register_alias (char * newname, char *p)
2035 struct reg_entry *old;
2036 char *oldname, *nbuf;
2037 size_t nlen;
2039 /* The input scrubber ensures that whitespace after the mnemonic is
2040 collapsed to single spaces. */
2041 oldname = p;
2042 if (strncmp (oldname, " .req ", 6) != 0)
2043 return FALSE;
2045 oldname += 6;
2046 if (*oldname == '\0')
2047 return FALSE;
2049 old = hash_find (arm_reg_hsh, oldname);
2050 if (!old)
2052 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2053 return TRUE;
2056 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2057 the desired alias name, and p points to its end. If not, then
2058 the desired alias name is in the global original_case_string. */
2059 #ifdef TC_CASE_SENSITIVE
2060 nlen = p - newname;
2061 #else
2062 newname = original_case_string;
2063 nlen = strlen (newname);
2064 #endif
2066 nbuf = alloca (nlen + 1);
2067 memcpy (nbuf, newname, nlen);
2068 nbuf[nlen] = '\0';
2070 /* Create aliases under the new name as stated; an all-lowercase
2071 version of the new name; and an all-uppercase version of the new
2072 name. */
2073 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2075 for (p = nbuf; *p; p++)
2076 *p = TOUPPER (*p);
2078 if (strncmp (nbuf, newname, nlen))
2080 /* If this attempt to create an additional alias fails, do not bother
2081 trying to create the all-lower case alias. We will fail and issue
2082 a second, duplicate error message. This situation arises when the
2083 programmer does something like:
2084 foo .req r0
2085 Foo .req r1
2086 The second .req creates the "Foo" alias but then fails to create
2087 the artificial FOO alias because it has already been created by the
2088 first .req. */
2089 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2090 return TRUE;
2093 for (p = nbuf; *p; p++)
2094 *p = TOLOWER (*p);
2096 if (strncmp (nbuf, newname, nlen))
2097 insert_reg_alias (nbuf, old->number, old->type);
2100 return TRUE;
2103 /* Create a Neon typed/indexed register alias using directives, e.g.:
2104 X .dn d5.s32[1]
2105 Y .qn 6.s16
2106 Z .dn d7
2107 T .dn Z[0]
2108 These typed registers can be used instead of the types specified after the
2109 Neon mnemonic, so long as all operands given have types. Types can also be
2110 specified directly, e.g.:
2111 vadd d0.s32, d1.s32, d2.s32 */
2113 static int
2114 create_neon_reg_alias (char *newname, char *p)
2116 enum arm_reg_type basetype;
2117 struct reg_entry *basereg;
2118 struct reg_entry mybasereg;
2119 struct neon_type ntype;
2120 struct neon_typed_alias typeinfo;
2121 char *namebuf, *nameend;
2122 int namelen;
2124 typeinfo.defined = 0;
2125 typeinfo.eltype.type = NT_invtype;
2126 typeinfo.eltype.size = -1;
2127 typeinfo.index = -1;
2129 nameend = p;
2131 if (strncmp (p, " .dn ", 5) == 0)
2132 basetype = REG_TYPE_VFD;
2133 else if (strncmp (p, " .qn ", 5) == 0)
2134 basetype = REG_TYPE_NQ;
2135 else
2136 return 0;
2138 p += 5;
2140 if (*p == '\0')
2141 return 0;
2143 basereg = arm_reg_parse_multi (&p);
2145 if (basereg && basereg->type != basetype)
2147 as_bad (_("bad type for register"));
2148 return 0;
2151 if (basereg == NULL)
2153 expressionS exp;
2154 /* Try parsing as an integer. */
2155 my_get_expression (&exp, &p, GE_NO_PREFIX);
2156 if (exp.X_op != O_constant)
2158 as_bad (_("expression must be constant"));
2159 return 0;
2161 basereg = &mybasereg;
2162 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2163 : exp.X_add_number;
2164 basereg->neon = 0;
2167 if (basereg->neon)
2168 typeinfo = *basereg->neon;
2170 if (parse_neon_type (&ntype, &p) == SUCCESS)
2172 /* We got a type. */
2173 if (typeinfo.defined & NTA_HASTYPE)
2175 as_bad (_("can't redefine the type of a register alias"));
2176 return 0;
2179 typeinfo.defined |= NTA_HASTYPE;
2180 if (ntype.elems != 1)
2182 as_bad (_("you must specify a single type only"));
2183 return 0;
2185 typeinfo.eltype = ntype.el[0];
2188 if (skip_past_char (&p, '[') == SUCCESS)
2190 expressionS exp;
2191 /* We got a scalar index. */
2193 if (typeinfo.defined & NTA_HASINDEX)
2195 as_bad (_("can't redefine the index of a scalar alias"));
2196 return 0;
2199 my_get_expression (&exp, &p, GE_NO_PREFIX);
2201 if (exp.X_op != O_constant)
2203 as_bad (_("scalar index must be constant"));
2204 return 0;
2207 typeinfo.defined |= NTA_HASINDEX;
2208 typeinfo.index = exp.X_add_number;
2210 if (skip_past_char (&p, ']') == FAIL)
2212 as_bad (_("expecting ]"));
2213 return 0;
2217 namelen = nameend - newname;
2218 namebuf = alloca (namelen + 1);
2219 strncpy (namebuf, newname, namelen);
2220 namebuf[namelen] = '\0';
2222 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2223 typeinfo.defined != 0 ? &typeinfo : NULL);
2225 /* Insert name in all uppercase. */
2226 for (p = namebuf; *p; p++)
2227 *p = TOUPPER (*p);
2229 if (strncmp (namebuf, newname, namelen))
2230 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2231 typeinfo.defined != 0 ? &typeinfo : NULL);
2233 /* Insert name in all lowercase. */
2234 for (p = namebuf; *p; p++)
2235 *p = TOLOWER (*p);
2237 if (strncmp (namebuf, newname, namelen))
2238 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2239 typeinfo.defined != 0 ? &typeinfo : NULL);
2241 return 1;
2244 /* Should never be called, as .req goes between the alias and the
2245 register name, not at the beginning of the line. */
2246 static void
2247 s_req (int a ATTRIBUTE_UNUSED)
2249 as_bad (_("invalid syntax for .req directive"));
2252 static void
2253 s_dn (int a ATTRIBUTE_UNUSED)
2255 as_bad (_("invalid syntax for .dn directive"));
2258 static void
2259 s_qn (int a ATTRIBUTE_UNUSED)
2261 as_bad (_("invalid syntax for .qn directive"));
2264 /* The .unreq directive deletes an alias which was previously defined
2265 by .req. For example:
2267 my_alias .req r11
2268 .unreq my_alias */
2270 static void
2271 s_unreq (int a ATTRIBUTE_UNUSED)
2273 char * name;
2274 char saved_char;
2276 name = input_line_pointer;
2278 while (*input_line_pointer != 0
2279 && *input_line_pointer != ' '
2280 && *input_line_pointer != '\n')
2281 ++input_line_pointer;
2283 saved_char = *input_line_pointer;
2284 *input_line_pointer = 0;
2286 if (!*name)
2287 as_bad (_("invalid syntax for .unreq directive"));
2288 else
2290 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2292 if (!reg)
2293 as_bad (_("unknown register alias '%s'"), name);
2294 else if (reg->builtin)
2295 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2296 name);
2297 else
2299 char * p;
2300 char * nbuf;
2302 hash_delete (arm_reg_hsh, name, FALSE);
2303 free ((char *) reg->name);
2304 if (reg->neon)
2305 free (reg->neon);
2306 free (reg);
2308 /* Also locate the all upper case and all lower case versions.
2309 Do not complain if we cannot find one or the other as it
2310 was probably deleted above. */
2312 nbuf = strdup (name);
2313 for (p = nbuf; *p; p++)
2314 *p = TOUPPER (*p);
2315 reg = hash_find (arm_reg_hsh, nbuf);
2316 if (reg)
2318 hash_delete (arm_reg_hsh, nbuf, FALSE);
2319 free ((char *) reg->name);
2320 if (reg->neon)
2321 free (reg->neon);
2322 free (reg);
2325 for (p = nbuf; *p; p++)
2326 *p = TOLOWER (*p);
2327 reg = hash_find (arm_reg_hsh, nbuf);
2328 if (reg)
2330 hash_delete (arm_reg_hsh, nbuf, FALSE);
2331 free ((char *) reg->name);
2332 if (reg->neon)
2333 free (reg->neon);
2334 free (reg);
2337 free (nbuf);
2341 *input_line_pointer = saved_char;
2342 demand_empty_rest_of_line ();
2345 /* Directives: Instruction set selection. */
2347 #ifdef OBJ_ELF
2348 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2349 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2350 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2351 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2353 static enum mstate mapstate = MAP_UNDEFINED;
2355 void
2356 mapping_state (enum mstate state)
2358 symbolS * symbolP;
2359 const char * symname;
2360 int type;
2362 if (mapstate == state)
2363 /* The mapping symbol has already been emitted.
2364 There is nothing else to do. */
2365 return;
2367 mapstate = state;
2369 switch (state)
2371 case MAP_DATA:
2372 symname = "$d";
2373 type = BSF_NO_FLAGS;
2374 break;
2375 case MAP_ARM:
2376 symname = "$a";
2377 type = BSF_NO_FLAGS;
2378 break;
2379 case MAP_THUMB:
2380 symname = "$t";
2381 type = BSF_NO_FLAGS;
2382 break;
2383 case MAP_UNDEFINED:
2384 return;
2385 default:
2386 abort ();
2389 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2391 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2392 symbol_table_insert (symbolP);
2393 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2395 switch (state)
2397 case MAP_ARM:
2398 THUMB_SET_FUNC (symbolP, 0);
2399 ARM_SET_THUMB (symbolP, 0);
2400 ARM_SET_INTERWORK (symbolP, support_interwork);
2401 break;
2403 case MAP_THUMB:
2404 THUMB_SET_FUNC (symbolP, 1);
2405 ARM_SET_THUMB (symbolP, 1);
2406 ARM_SET_INTERWORK (symbolP, support_interwork);
2407 break;
2409 case MAP_DATA:
2410 default:
2411 return;
2414 #else
2415 #define mapping_state(x) /* nothing */
2416 #endif
2418 /* Find the real, Thumb encoded start of a Thumb function. */
2420 static symbolS *
2421 find_real_start (symbolS * symbolP)
2423 char * real_start;
2424 const char * name = S_GET_NAME (symbolP);
2425 symbolS * new_target;
2427 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2428 #define STUB_NAME ".real_start_of"
2430 if (name == NULL)
2431 abort ();
2433 /* The compiler may generate BL instructions to local labels because
2434 it needs to perform a branch to a far away location. These labels
2435 do not have a corresponding ".real_start_of" label. We check
2436 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2437 the ".real_start_of" convention for nonlocal branches. */
2438 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2439 return symbolP;
2441 real_start = ACONCAT ((STUB_NAME, name, NULL));
2442 new_target = symbol_find (real_start);
2444 if (new_target == NULL)
2446 as_warn (_("Failed to find real start of function: %s\n"), name);
2447 new_target = symbolP;
2450 return new_target;
2453 static void
2454 opcode_select (int width)
2456 switch (width)
2458 case 16:
2459 if (! thumb_mode)
2461 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2462 as_bad (_("selected processor does not support THUMB opcodes"));
2464 thumb_mode = 1;
2465 /* No need to force the alignment, since we will have been
2466 coming from ARM mode, which is word-aligned. */
2467 record_alignment (now_seg, 1);
2469 mapping_state (MAP_THUMB);
2470 break;
2472 case 32:
2473 if (thumb_mode)
2475 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2476 as_bad (_("selected processor does not support ARM opcodes"));
2478 thumb_mode = 0;
2480 if (!need_pass_2)
2481 frag_align (2, 0, 0);
2483 record_alignment (now_seg, 1);
2485 mapping_state (MAP_ARM);
2486 break;
2488 default:
2489 as_bad (_("invalid instruction size selected (%d)"), width);
2493 static void
2494 s_arm (int ignore ATTRIBUTE_UNUSED)
2496 opcode_select (32);
2497 demand_empty_rest_of_line ();
2500 static void
2501 s_thumb (int ignore ATTRIBUTE_UNUSED)
2503 opcode_select (16);
2504 demand_empty_rest_of_line ();
2507 static void
2508 s_code (int unused ATTRIBUTE_UNUSED)
2510 int temp;
2512 temp = get_absolute_expression ();
2513 switch (temp)
2515 case 16:
2516 case 32:
2517 opcode_select (temp);
2518 break;
2520 default:
2521 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2525 static void
2526 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2528 /* If we are not already in thumb mode go into it, EVEN if
2529 the target processor does not support thumb instructions.
2530 This is used by gcc/config/arm/lib1funcs.asm for example
2531 to compile interworking support functions even if the
2532 target processor should not support interworking. */
2533 if (! thumb_mode)
2535 thumb_mode = 2;
2536 record_alignment (now_seg, 1);
2539 demand_empty_rest_of_line ();
2542 static void
2543 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2545 s_thumb (0);
2547 /* The following label is the name/address of the start of a Thumb function.
2548 We need to know this for the interworking support. */
2549 label_is_thumb_function_name = TRUE;
2552 /* Perform a .set directive, but also mark the alias as
2553 being a thumb function. */
2555 static void
2556 s_thumb_set (int equiv)
2558 /* XXX the following is a duplicate of the code for s_set() in read.c
2559 We cannot just call that code as we need to get at the symbol that
2560 is created. */
2561 char * name;
2562 char delim;
2563 char * end_name;
2564 symbolS * symbolP;
2566 /* Especial apologies for the random logic:
2567 This just grew, and could be parsed much more simply!
2568 Dean - in haste. */
2569 name = input_line_pointer;
2570 delim = get_symbol_end ();
2571 end_name = input_line_pointer;
2572 *end_name = delim;
2574 if (*input_line_pointer != ',')
2576 *end_name = 0;
2577 as_bad (_("expected comma after name \"%s\""), name);
2578 *end_name = delim;
2579 ignore_rest_of_line ();
2580 return;
2583 input_line_pointer++;
2584 *end_name = 0;
2586 if (name[0] == '.' && name[1] == '\0')
2588 /* XXX - this should not happen to .thumb_set. */
2589 abort ();
2592 if ((symbolP = symbol_find (name)) == NULL
2593 && (symbolP = md_undefined_symbol (name)) == NULL)
2595 #ifndef NO_LISTING
2596 /* When doing symbol listings, play games with dummy fragments living
2597 outside the normal fragment chain to record the file and line info
2598 for this symbol. */
2599 if (listing & LISTING_SYMBOLS)
2601 extern struct list_info_struct * listing_tail;
2602 fragS * dummy_frag = xmalloc (sizeof (fragS));
2604 memset (dummy_frag, 0, sizeof (fragS));
2605 dummy_frag->fr_type = rs_fill;
2606 dummy_frag->line = listing_tail;
2607 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2608 dummy_frag->fr_symbol = symbolP;
2610 else
2611 #endif
2612 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2614 #ifdef OBJ_COFF
2615 /* "set" symbols are local unless otherwise specified. */
2616 SF_SET_LOCAL (symbolP);
2617 #endif /* OBJ_COFF */
2618 } /* Make a new symbol. */
2620 symbol_table_insert (symbolP);
2622 * end_name = delim;
2624 if (equiv
2625 && S_IS_DEFINED (symbolP)
2626 && S_GET_SEGMENT (symbolP) != reg_section)
2627 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2629 pseudo_set (symbolP);
2631 demand_empty_rest_of_line ();
2633 /* XXX Now we come to the Thumb specific bit of code. */
2635 THUMB_SET_FUNC (symbolP, 1);
2636 ARM_SET_THUMB (symbolP, 1);
2637 #if defined OBJ_ELF || defined OBJ_COFF
2638 ARM_SET_INTERWORK (symbolP, support_interwork);
2639 #endif
2642 /* Directives: Mode selection. */
2644 /* .syntax [unified|divided] - choose the new unified syntax
2645 (same for Arm and Thumb encoding, modulo slight differences in what
2646 can be represented) or the old divergent syntax for each mode. */
2647 static void
2648 s_syntax (int unused ATTRIBUTE_UNUSED)
2650 char *name, delim;
2652 name = input_line_pointer;
2653 delim = get_symbol_end ();
2655 if (!strcasecmp (name, "unified"))
2656 unified_syntax = TRUE;
2657 else if (!strcasecmp (name, "divided"))
2658 unified_syntax = FALSE;
2659 else
2661 as_bad (_("unrecognized syntax mode \"%s\""), name);
2662 return;
2664 *input_line_pointer = delim;
2665 demand_empty_rest_of_line ();
2668 /* Directives: sectioning and alignment. */
2670 /* Same as s_align_ptwo but align 0 => align 2. */
2672 static void
2673 s_align (int unused ATTRIBUTE_UNUSED)
2675 int temp;
2676 bfd_boolean fill_p;
2677 long temp_fill;
2678 long max_alignment = 15;
2680 temp = get_absolute_expression ();
2681 if (temp > max_alignment)
2682 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2683 else if (temp < 0)
2685 as_bad (_("alignment negative. 0 assumed."));
2686 temp = 0;
2689 if (*input_line_pointer == ',')
2691 input_line_pointer++;
2692 temp_fill = get_absolute_expression ();
2693 fill_p = TRUE;
2695 else
2697 fill_p = FALSE;
2698 temp_fill = 0;
2701 if (!temp)
2702 temp = 2;
2704 /* Only make a frag if we HAVE to. */
2705 if (temp && !need_pass_2)
2707 if (!fill_p && subseg_text_p (now_seg))
2708 frag_align_code (temp, 0);
2709 else
2710 frag_align (temp, (int) temp_fill, 0);
2712 demand_empty_rest_of_line ();
2714 record_alignment (now_seg, temp);
2717 static void
2718 s_bss (int ignore ATTRIBUTE_UNUSED)
2720 /* We don't support putting frags in the BSS segment, we fake it by
2721 marking in_bss, then looking at s_skip for clues. */
2722 subseg_set (bss_section, 0);
2723 demand_empty_rest_of_line ();
2724 mapping_state (MAP_DATA);
2727 static void
2728 s_even (int ignore ATTRIBUTE_UNUSED)
2730 /* Never make frag if expect extra pass. */
2731 if (!need_pass_2)
2732 frag_align (1, 0, 0);
2734 record_alignment (now_seg, 1);
2736 demand_empty_rest_of_line ();
2739 /* Directives: Literal pools. */
2741 static literal_pool *
2742 find_literal_pool (void)
2744 literal_pool * pool;
2746 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2748 if (pool->section == now_seg
2749 && pool->sub_section == now_subseg)
2750 break;
2753 return pool;
2756 static literal_pool *
2757 find_or_make_literal_pool (void)
2759 /* Next literal pool ID number. */
2760 static unsigned int latest_pool_num = 1;
2761 literal_pool * pool;
2763 pool = find_literal_pool ();
2765 if (pool == NULL)
2767 /* Create a new pool. */
2768 pool = xmalloc (sizeof (* pool));
2769 if (! pool)
2770 return NULL;
2772 pool->next_free_entry = 0;
2773 pool->section = now_seg;
2774 pool->sub_section = now_subseg;
2775 pool->next = list_of_pools;
2776 pool->symbol = NULL;
2778 /* Add it to the list. */
2779 list_of_pools = pool;
2782 /* New pools, and emptied pools, will have a NULL symbol. */
2783 if (pool->symbol == NULL)
2785 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2786 (valueT) 0, &zero_address_frag);
2787 pool->id = latest_pool_num ++;
2790 /* Done. */
2791 return pool;
2794 /* Add the literal in the global 'inst'
2795 structure to the relevant literal pool. */
2797 static int
2798 add_to_lit_pool (void)
2800 literal_pool * pool;
2801 unsigned int entry;
2803 pool = find_or_make_literal_pool ();
2805 /* Check if this literal value is already in the pool. */
2806 for (entry = 0; entry < pool->next_free_entry; entry ++)
2808 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2809 && (inst.reloc.exp.X_op == O_constant)
2810 && (pool->literals[entry].X_add_number
2811 == inst.reloc.exp.X_add_number)
2812 && (pool->literals[entry].X_unsigned
2813 == inst.reloc.exp.X_unsigned))
2814 break;
2816 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2817 && (inst.reloc.exp.X_op == O_symbol)
2818 && (pool->literals[entry].X_add_number
2819 == inst.reloc.exp.X_add_number)
2820 && (pool->literals[entry].X_add_symbol
2821 == inst.reloc.exp.X_add_symbol)
2822 && (pool->literals[entry].X_op_symbol
2823 == inst.reloc.exp.X_op_symbol))
2824 break;
2827 /* Do we need to create a new entry? */
2828 if (entry == pool->next_free_entry)
2830 if (entry >= MAX_LITERAL_POOL_SIZE)
2832 inst.error = _("literal pool overflow");
2833 return FAIL;
2836 pool->literals[entry] = inst.reloc.exp;
2837 pool->next_free_entry += 1;
2840 inst.reloc.exp.X_op = O_symbol;
2841 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2842 inst.reloc.exp.X_add_symbol = pool->symbol;
2844 return SUCCESS;
2847 /* Can't use symbol_new here, so have to create a symbol and then at
2848 a later date assign it a value. Thats what these functions do. */
2850 static void
2851 symbol_locate (symbolS * symbolP,
2852 const char * name, /* It is copied, the caller can modify. */
2853 segT segment, /* Segment identifier (SEG_<something>). */
2854 valueT valu, /* Symbol value. */
2855 fragS * frag) /* Associated fragment. */
2857 unsigned int name_length;
2858 char * preserved_copy_of_name;
2860 name_length = strlen (name) + 1; /* +1 for \0. */
2861 obstack_grow (&notes, name, name_length);
2862 preserved_copy_of_name = obstack_finish (&notes);
2864 #ifdef tc_canonicalize_symbol_name
2865 preserved_copy_of_name =
2866 tc_canonicalize_symbol_name (preserved_copy_of_name);
2867 #endif
2869 S_SET_NAME (symbolP, preserved_copy_of_name);
2871 S_SET_SEGMENT (symbolP, segment);
2872 S_SET_VALUE (symbolP, valu);
2873 symbol_clear_list_pointers (symbolP);
2875 symbol_set_frag (symbolP, frag);
2877 /* Link to end of symbol chain. */
2879 extern int symbol_table_frozen;
2881 if (symbol_table_frozen)
2882 abort ();
2885 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2887 obj_symbol_new_hook (symbolP);
2889 #ifdef tc_symbol_new_hook
2890 tc_symbol_new_hook (symbolP);
2891 #endif
2893 #ifdef DEBUG_SYMS
2894 verify_symbol_chain (symbol_rootP, symbol_lastP);
2895 #endif /* DEBUG_SYMS */
2899 static void
2900 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2902 unsigned int entry;
2903 literal_pool * pool;
2904 char sym_name[20];
2906 pool = find_literal_pool ();
2907 if (pool == NULL
2908 || pool->symbol == NULL
2909 || pool->next_free_entry == 0)
2910 return;
2912 mapping_state (MAP_DATA);
2914 /* Align pool as you have word accesses.
2915 Only make a frag if we have to. */
2916 if (!need_pass_2)
2917 frag_align (2, 0, 0);
2919 record_alignment (now_seg, 2);
2921 sprintf (sym_name, "$$lit_\002%x", pool->id);
2923 symbol_locate (pool->symbol, sym_name, now_seg,
2924 (valueT) frag_now_fix (), frag_now);
2925 symbol_table_insert (pool->symbol);
2927 ARM_SET_THUMB (pool->symbol, thumb_mode);
2929 #if defined OBJ_COFF || defined OBJ_ELF
2930 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2931 #endif
2933 for (entry = 0; entry < pool->next_free_entry; entry ++)
2934 /* First output the expression in the instruction to the pool. */
2935 emit_expr (&(pool->literals[entry]), 4); /* .word */
2937 /* Mark the pool as empty. */
2938 pool->next_free_entry = 0;
2939 pool->symbol = NULL;
2942 #ifdef OBJ_ELF
2943 /* Forward declarations for functions below, in the MD interface
2944 section. */
2945 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2946 static valueT create_unwind_entry (int);
2947 static void start_unwind_section (const segT, int);
2948 static void add_unwind_opcode (valueT, int);
2949 static void flush_pending_unwind (void);
2951 /* Directives: Data. */
2953 static void
2954 s_arm_elf_cons (int nbytes)
2956 expressionS exp;
2958 #ifdef md_flush_pending_output
2959 md_flush_pending_output ();
2960 #endif
2962 if (is_it_end_of_statement ())
2964 demand_empty_rest_of_line ();
2965 return;
2968 #ifdef md_cons_align
2969 md_cons_align (nbytes);
2970 #endif
2972 mapping_state (MAP_DATA);
2975 int reloc;
2976 char *base = input_line_pointer;
2978 expression (& exp);
2980 if (exp.X_op != O_symbol)
2981 emit_expr (&exp, (unsigned int) nbytes);
2982 else
2984 char *before_reloc = input_line_pointer;
2985 reloc = parse_reloc (&input_line_pointer);
2986 if (reloc == -1)
2988 as_bad (_("unrecognized relocation suffix"));
2989 ignore_rest_of_line ();
2990 return;
2992 else if (reloc == BFD_RELOC_UNUSED)
2993 emit_expr (&exp, (unsigned int) nbytes);
2994 else
2996 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2997 int size = bfd_get_reloc_size (howto);
2999 if (reloc == BFD_RELOC_ARM_PLT32)
3001 as_bad (_("(plt) is only valid on branch targets"));
3002 reloc = BFD_RELOC_UNUSED;
3003 size = 0;
3006 if (size > nbytes)
3007 as_bad (_("%s relocations do not fit in %d bytes"),
3008 howto->name, nbytes);
3009 else
3011 /* We've parsed an expression stopping at O_symbol.
3012 But there may be more expression left now that we
3013 have parsed the relocation marker. Parse it again.
3014 XXX Surely there is a cleaner way to do this. */
3015 char *p = input_line_pointer;
3016 int offset;
3017 char *save_buf = alloca (input_line_pointer - base);
3018 memcpy (save_buf, base, input_line_pointer - base);
3019 memmove (base + (input_line_pointer - before_reloc),
3020 base, before_reloc - base);
3022 input_line_pointer = base + (input_line_pointer-before_reloc);
3023 expression (&exp);
3024 memcpy (base, save_buf, p - base);
3026 offset = nbytes - size;
3027 p = frag_more ((int) nbytes);
3028 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3029 size, &exp, 0, reloc);
3034 while (*input_line_pointer++ == ',');
3036 /* Put terminator back into stream. */
3037 input_line_pointer --;
3038 demand_empty_rest_of_line ();
3042 /* Parse a .rel31 directive. */
3044 static void
3045 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3047 expressionS exp;
3048 char *p;
3049 valueT highbit;
3051 highbit = 0;
3052 if (*input_line_pointer == '1')
3053 highbit = 0x80000000;
3054 else if (*input_line_pointer != '0')
3055 as_bad (_("expected 0 or 1"));
3057 input_line_pointer++;
3058 if (*input_line_pointer != ',')
3059 as_bad (_("missing comma"));
3060 input_line_pointer++;
3062 #ifdef md_flush_pending_output
3063 md_flush_pending_output ();
3064 #endif
3066 #ifdef md_cons_align
3067 md_cons_align (4);
3068 #endif
3070 mapping_state (MAP_DATA);
3072 expression (&exp);
3074 p = frag_more (4);
3075 md_number_to_chars (p, highbit, 4);
3076 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3077 BFD_RELOC_ARM_PREL31);
3079 demand_empty_rest_of_line ();
3082 /* Directives: AEABI stack-unwind tables. */
3084 /* Parse an unwind_fnstart directive. Simply records the current location. */
3086 static void
3087 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3089 demand_empty_rest_of_line ();
3090 /* Mark the start of the function. */
3091 unwind.proc_start = expr_build_dot ();
3093 /* Reset the rest of the unwind info. */
3094 unwind.opcode_count = 0;
3095 unwind.table_entry = NULL;
3096 unwind.personality_routine = NULL;
3097 unwind.personality_index = -1;
3098 unwind.frame_size = 0;
3099 unwind.fp_offset = 0;
3100 unwind.fp_reg = REG_SP;
3101 unwind.fp_used = 0;
3102 unwind.sp_restored = 0;
3106 /* Parse a handlerdata directive. Creates the exception handling table entry
3107 for the function. */
3109 static void
3110 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3112 demand_empty_rest_of_line ();
3113 if (unwind.table_entry)
3114 as_bad (_("duplicate .handlerdata directive"));
3116 create_unwind_entry (1);
3119 /* Parse an unwind_fnend directive. Generates the index table entry. */
3121 static void
3122 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3124 long where;
3125 char *ptr;
3126 valueT val;
3128 demand_empty_rest_of_line ();
3130 /* Add eh table entry. */
3131 if (unwind.table_entry == NULL)
3132 val = create_unwind_entry (0);
3133 else
3134 val = 0;
3136 /* Add index table entry. This is two words. */
3137 start_unwind_section (unwind.saved_seg, 1);
3138 frag_align (2, 0, 0);
3139 record_alignment (now_seg, 2);
3141 ptr = frag_more (8);
3142 where = frag_now_fix () - 8;
3144 /* Self relative offset of the function start. */
3145 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3146 BFD_RELOC_ARM_PREL31);
3148 /* Indicate dependency on EHABI-defined personality routines to the
3149 linker, if it hasn't been done already. */
3150 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3151 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3153 static const char *const name[] =
3155 "__aeabi_unwind_cpp_pr0",
3156 "__aeabi_unwind_cpp_pr1",
3157 "__aeabi_unwind_cpp_pr2"
3159 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3160 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3161 marked_pr_dependency |= 1 << unwind.personality_index;
3162 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3163 = marked_pr_dependency;
3166 if (val)
3167 /* Inline exception table entry. */
3168 md_number_to_chars (ptr + 4, val, 4);
3169 else
3170 /* Self relative offset of the table entry. */
3171 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3172 BFD_RELOC_ARM_PREL31);
3174 /* Restore the original section. */
3175 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3179 /* Parse an unwind_cantunwind directive. */
3181 static void
3182 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3184 demand_empty_rest_of_line ();
3185 if (unwind.personality_routine || unwind.personality_index != -1)
3186 as_bad (_("personality routine specified for cantunwind frame"));
3188 unwind.personality_index = -2;
3192 /* Parse a personalityindex directive. */
3194 static void
3195 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3197 expressionS exp;
3199 if (unwind.personality_routine || unwind.personality_index != -1)
3200 as_bad (_("duplicate .personalityindex directive"));
3202 expression (&exp);
3204 if (exp.X_op != O_constant
3205 || exp.X_add_number < 0 || exp.X_add_number > 15)
3207 as_bad (_("bad personality routine number"));
3208 ignore_rest_of_line ();
3209 return;
3212 unwind.personality_index = exp.X_add_number;
3214 demand_empty_rest_of_line ();
3218 /* Parse a personality directive. */
3220 static void
3221 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3223 char *name, *p, c;
3225 if (unwind.personality_routine || unwind.personality_index != -1)
3226 as_bad (_("duplicate .personality directive"));
3228 name = input_line_pointer;
3229 c = get_symbol_end ();
3230 p = input_line_pointer;
3231 unwind.personality_routine = symbol_find_or_make (name);
3232 *p = c;
3233 demand_empty_rest_of_line ();
3237 /* Parse a directive saving core registers. */
3239 static void
3240 s_arm_unwind_save_core (void)
3242 valueT op;
3243 long range;
3244 int n;
3246 range = parse_reg_list (&input_line_pointer);
3247 if (range == FAIL)
3249 as_bad (_("expected register list"));
3250 ignore_rest_of_line ();
3251 return;
3254 demand_empty_rest_of_line ();
3256 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3257 into .unwind_save {..., sp...}. We aren't bothered about the value of
3258 ip because it is clobbered by calls. */
3259 if (unwind.sp_restored && unwind.fp_reg == 12
3260 && (range & 0x3000) == 0x1000)
3262 unwind.opcode_count--;
3263 unwind.sp_restored = 0;
3264 range = (range | 0x2000) & ~0x1000;
3265 unwind.pending_offset = 0;
3268 /* Pop r4-r15. */
3269 if (range & 0xfff0)
3271 /* See if we can use the short opcodes. These pop a block of up to 8
3272 registers starting with r4, plus maybe r14. */
3273 for (n = 0; n < 8; n++)
3275 /* Break at the first non-saved register. */
3276 if ((range & (1 << (n + 4))) == 0)
3277 break;
3279 /* See if there are any other bits set. */
3280 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3282 /* Use the long form. */
3283 op = 0x8000 | ((range >> 4) & 0xfff);
3284 add_unwind_opcode (op, 2);
3286 else
3288 /* Use the short form. */
3289 if (range & 0x4000)
3290 op = 0xa8; /* Pop r14. */
3291 else
3292 op = 0xa0; /* Do not pop r14. */
3293 op |= (n - 1);
3294 add_unwind_opcode (op, 1);
3298 /* Pop r0-r3. */
3299 if (range & 0xf)
3301 op = 0xb100 | (range & 0xf);
3302 add_unwind_opcode (op, 2);
3305 /* Record the number of bytes pushed. */
3306 for (n = 0; n < 16; n++)
3308 if (range & (1 << n))
3309 unwind.frame_size += 4;
3314 /* Parse a directive saving FPA registers. */
3316 static void
3317 s_arm_unwind_save_fpa (int reg)
3319 expressionS exp;
3320 int num_regs;
3321 valueT op;
3323 /* Get Number of registers to transfer. */
3324 if (skip_past_comma (&input_line_pointer) != FAIL)
3325 expression (&exp);
3326 else
3327 exp.X_op = O_illegal;
3329 if (exp.X_op != O_constant)
3331 as_bad (_("expected , <constant>"));
3332 ignore_rest_of_line ();
3333 return;
3336 num_regs = exp.X_add_number;
3338 if (num_regs < 1 || num_regs > 4)
3340 as_bad (_("number of registers must be in the range [1:4]"));
3341 ignore_rest_of_line ();
3342 return;
3345 demand_empty_rest_of_line ();
3347 if (reg == 4)
3349 /* Short form. */
3350 op = 0xb4 | (num_regs - 1);
3351 add_unwind_opcode (op, 1);
3353 else
3355 /* Long form. */
3356 op = 0xc800 | (reg << 4) | (num_regs - 1);
3357 add_unwind_opcode (op, 2);
3359 unwind.frame_size += num_regs * 12;
3363 /* Parse a directive saving VFP registers for ARMv6 and above. */
3365 static void
3366 s_arm_unwind_save_vfp_armv6 (void)
3368 int count;
3369 unsigned int start;
3370 valueT op;
3371 int num_vfpv3_regs = 0;
3372 int num_regs_below_16;
3374 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3375 if (count == FAIL)
3377 as_bad (_("expected register list"));
3378 ignore_rest_of_line ();
3379 return;
3382 demand_empty_rest_of_line ();
3384 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3385 than FSTMX/FLDMX-style ones). */
3387 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3388 if (start >= 16)
3389 num_vfpv3_regs = count;
3390 else if (start + count > 16)
3391 num_vfpv3_regs = start + count - 16;
3393 if (num_vfpv3_regs > 0)
3395 int start_offset = start > 16 ? start - 16 : 0;
3396 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3397 add_unwind_opcode (op, 2);
3400 /* Generate opcode for registers numbered in the range 0 .. 15. */
3401 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3402 assert (num_regs_below_16 + num_vfpv3_regs == count);
3403 if (num_regs_below_16 > 0)
3405 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3406 add_unwind_opcode (op, 2);
3409 unwind.frame_size += count * 8;
3413 /* Parse a directive saving VFP registers for pre-ARMv6. */
3415 static void
3416 s_arm_unwind_save_vfp (void)
3418 int count;
3419 unsigned int reg;
3420 valueT op;
3422 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3423 if (count == FAIL)
3425 as_bad (_("expected register list"));
3426 ignore_rest_of_line ();
3427 return;
3430 demand_empty_rest_of_line ();
3432 if (reg == 8)
3434 /* Short form. */
3435 op = 0xb8 | (count - 1);
3436 add_unwind_opcode (op, 1);
3438 else
3440 /* Long form. */
3441 op = 0xb300 | (reg << 4) | (count - 1);
3442 add_unwind_opcode (op, 2);
3444 unwind.frame_size += count * 8 + 4;
3448 /* Parse a directive saving iWMMXt data registers. */
3450 static void
3451 s_arm_unwind_save_mmxwr (void)
3453 int reg;
3454 int hi_reg;
3455 int i;
3456 unsigned mask = 0;
3457 valueT op;
3459 if (*input_line_pointer == '{')
3460 input_line_pointer++;
3464 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3466 if (reg == FAIL)
3468 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3469 goto error;
3472 if (mask >> reg)
3473 as_tsktsk (_("register list not in ascending order"));
3474 mask |= 1 << reg;
3476 if (*input_line_pointer == '-')
3478 input_line_pointer++;
3479 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3480 if (hi_reg == FAIL)
3482 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3483 goto error;
3485 else if (reg >= hi_reg)
3487 as_bad (_("bad register range"));
3488 goto error;
3490 for (; reg < hi_reg; reg++)
3491 mask |= 1 << reg;
3494 while (skip_past_comma (&input_line_pointer) != FAIL);
3496 if (*input_line_pointer == '}')
3497 input_line_pointer++;
3499 demand_empty_rest_of_line ();
3501 /* Generate any deferred opcodes because we're going to be looking at
3502 the list. */
3503 flush_pending_unwind ();
3505 for (i = 0; i < 16; i++)
3507 if (mask & (1 << i))
3508 unwind.frame_size += 8;
3511 /* Attempt to combine with a previous opcode. We do this because gcc
3512 likes to output separate unwind directives for a single block of
3513 registers. */
3514 if (unwind.opcode_count > 0)
3516 i = unwind.opcodes[unwind.opcode_count - 1];
3517 if ((i & 0xf8) == 0xc0)
3519 i &= 7;
3520 /* Only merge if the blocks are contiguous. */
3521 if (i < 6)
3523 if ((mask & 0xfe00) == (1 << 9))
3525 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3526 unwind.opcode_count--;
3529 else if (i == 6 && unwind.opcode_count >= 2)
3531 i = unwind.opcodes[unwind.opcode_count - 2];
3532 reg = i >> 4;
3533 i &= 0xf;
3535 op = 0xffff << (reg - 1);
3536 if (reg > 0
3537 && ((mask & op) == (1u << (reg - 1))))
3539 op = (1 << (reg + i + 1)) - 1;
3540 op &= ~((1 << reg) - 1);
3541 mask |= op;
3542 unwind.opcode_count -= 2;
3548 hi_reg = 15;
3549 /* We want to generate opcodes in the order the registers have been
3550 saved, ie. descending order. */
3551 for (reg = 15; reg >= -1; reg--)
3553 /* Save registers in blocks. */
3554 if (reg < 0
3555 || !(mask & (1 << reg)))
3557 /* We found an unsaved reg. Generate opcodes to save the
3558 preceding block. */
3559 if (reg != hi_reg)
3561 if (reg == 9)
3563 /* Short form. */
3564 op = 0xc0 | (hi_reg - 10);
3565 add_unwind_opcode (op, 1);
3567 else
3569 /* Long form. */
3570 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3571 add_unwind_opcode (op, 2);
3574 hi_reg = reg - 1;
3578 return;
3579 error:
3580 ignore_rest_of_line ();
3583 static void
3584 s_arm_unwind_save_mmxwcg (void)
3586 int reg;
3587 int hi_reg;
3588 unsigned mask = 0;
3589 valueT op;
3591 if (*input_line_pointer == '{')
3592 input_line_pointer++;
3596 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3598 if (reg == FAIL)
3600 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3601 goto error;
3604 reg -= 8;
3605 if (mask >> reg)
3606 as_tsktsk (_("register list not in ascending order"));
3607 mask |= 1 << reg;
3609 if (*input_line_pointer == '-')
3611 input_line_pointer++;
3612 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3613 if (hi_reg == FAIL)
3615 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3616 goto error;
3618 else if (reg >= hi_reg)
3620 as_bad (_("bad register range"));
3621 goto error;
3623 for (; reg < hi_reg; reg++)
3624 mask |= 1 << reg;
3627 while (skip_past_comma (&input_line_pointer) != FAIL);
3629 if (*input_line_pointer == '}')
3630 input_line_pointer++;
3632 demand_empty_rest_of_line ();
3634 /* Generate any deferred opcodes because we're going to be looking at
3635 the list. */
3636 flush_pending_unwind ();
3638 for (reg = 0; reg < 16; reg++)
3640 if (mask & (1 << reg))
3641 unwind.frame_size += 4;
3643 op = 0xc700 | mask;
3644 add_unwind_opcode (op, 2);
3645 return;
3646 error:
3647 ignore_rest_of_line ();
3651 /* Parse an unwind_save directive.
3652 If the argument is non-zero, this is a .vsave directive. */
3654 static void
3655 s_arm_unwind_save (int arch_v6)
3657 char *peek;
3658 struct reg_entry *reg;
3659 bfd_boolean had_brace = FALSE;
3661 /* Figure out what sort of save we have. */
3662 peek = input_line_pointer;
3664 if (*peek == '{')
3666 had_brace = TRUE;
3667 peek++;
3670 reg = arm_reg_parse_multi (&peek);
3672 if (!reg)
3674 as_bad (_("register expected"));
3675 ignore_rest_of_line ();
3676 return;
3679 switch (reg->type)
3681 case REG_TYPE_FN:
3682 if (had_brace)
3684 as_bad (_("FPA .unwind_save does not take a register list"));
3685 ignore_rest_of_line ();
3686 return;
3688 input_line_pointer = peek;
3689 s_arm_unwind_save_fpa (reg->number);
3690 return;
3692 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3693 case REG_TYPE_VFD:
3694 if (arch_v6)
3695 s_arm_unwind_save_vfp_armv6 ();
3696 else
3697 s_arm_unwind_save_vfp ();
3698 return;
3699 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3700 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3702 default:
3703 as_bad (_(".unwind_save does not support this kind of register"));
3704 ignore_rest_of_line ();
3709 /* Parse an unwind_movsp directive. */
3711 static void
3712 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3714 int reg;
3715 valueT op;
3716 int offset;
3718 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3719 if (reg == FAIL)
3721 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
3722 ignore_rest_of_line ();
3723 return;
3726 /* Optional constant. */
3727 if (skip_past_comma (&input_line_pointer) != FAIL)
3729 if (immediate_for_directive (&offset) == FAIL)
3730 return;
3732 else
3733 offset = 0;
3735 demand_empty_rest_of_line ();
3737 if (reg == REG_SP || reg == REG_PC)
3739 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3740 return;
3743 if (unwind.fp_reg != REG_SP)
3744 as_bad (_("unexpected .unwind_movsp directive"));
3746 /* Generate opcode to restore the value. */
3747 op = 0x90 | reg;
3748 add_unwind_opcode (op, 1);
3750 /* Record the information for later. */
3751 unwind.fp_reg = reg;
3752 unwind.fp_offset = unwind.frame_size - offset;
3753 unwind.sp_restored = 1;
3756 /* Parse an unwind_pad directive. */
3758 static void
3759 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3761 int offset;
3763 if (immediate_for_directive (&offset) == FAIL)
3764 return;
3766 if (offset & 3)
3768 as_bad (_("stack increment must be multiple of 4"));
3769 ignore_rest_of_line ();
3770 return;
3773 /* Don't generate any opcodes, just record the details for later. */
3774 unwind.frame_size += offset;
3775 unwind.pending_offset += offset;
3777 demand_empty_rest_of_line ();
3780 /* Parse an unwind_setfp directive. */
3782 static void
3783 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3785 int sp_reg;
3786 int fp_reg;
3787 int offset;
3789 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3790 if (skip_past_comma (&input_line_pointer) == FAIL)
3791 sp_reg = FAIL;
3792 else
3793 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3795 if (fp_reg == FAIL || sp_reg == FAIL)
3797 as_bad (_("expected <reg>, <reg>"));
3798 ignore_rest_of_line ();
3799 return;
3802 /* Optional constant. */
3803 if (skip_past_comma (&input_line_pointer) != FAIL)
3805 if (immediate_for_directive (&offset) == FAIL)
3806 return;
3808 else
3809 offset = 0;
3811 demand_empty_rest_of_line ();
3813 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
3815 as_bad (_("register must be either sp or set by a previous"
3816 "unwind_movsp directive"));
3817 return;
3820 /* Don't generate any opcodes, just record the information for later. */
3821 unwind.fp_reg = fp_reg;
3822 unwind.fp_used = 1;
3823 if (sp_reg == REG_SP)
3824 unwind.fp_offset = unwind.frame_size - offset;
3825 else
3826 unwind.fp_offset -= offset;
3829 /* Parse an unwind_raw directive. */
3831 static void
3832 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3834 expressionS exp;
3835 /* This is an arbitrary limit. */
3836 unsigned char op[16];
3837 int count;
3839 expression (&exp);
3840 if (exp.X_op == O_constant
3841 && skip_past_comma (&input_line_pointer) != FAIL)
3843 unwind.frame_size += exp.X_add_number;
3844 expression (&exp);
3846 else
3847 exp.X_op = O_illegal;
3849 if (exp.X_op != O_constant)
3851 as_bad (_("expected <offset>, <opcode>"));
3852 ignore_rest_of_line ();
3853 return;
3856 count = 0;
3858 /* Parse the opcode. */
3859 for (;;)
3861 if (count >= 16)
3863 as_bad (_("unwind opcode too long"));
3864 ignore_rest_of_line ();
3866 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3868 as_bad (_("invalid unwind opcode"));
3869 ignore_rest_of_line ();
3870 return;
3872 op[count++] = exp.X_add_number;
3874 /* Parse the next byte. */
3875 if (skip_past_comma (&input_line_pointer) == FAIL)
3876 break;
3878 expression (&exp);
3881 /* Add the opcode bytes in reverse order. */
3882 while (count--)
3883 add_unwind_opcode (op[count], 1);
3885 demand_empty_rest_of_line ();
3889 /* Parse a .eabi_attribute directive. */
3891 static void
3892 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3894 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
3896 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
3897 attributes_set_explicitly[tag] = 1;
3899 #endif /* OBJ_ELF */
3901 static void s_arm_arch (int);
3902 static void s_arm_object_arch (int);
3903 static void s_arm_cpu (int);
3904 static void s_arm_fpu (int);
3906 #ifdef TE_PE
3908 static void
3909 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3911 expressionS exp;
3915 expression (&exp);
3916 if (exp.X_op == O_symbol)
3917 exp.X_op = O_secrel;
3919 emit_expr (&exp, 4);
3921 while (*input_line_pointer++ == ',');
3923 input_line_pointer--;
3924 demand_empty_rest_of_line ();
3926 #endif /* TE_PE */
3928 /* This table describes all the machine specific pseudo-ops the assembler
3929 has to support. The fields are:
3930 pseudo-op name without dot
3931 function to call to execute this pseudo-op
3932 Integer arg to pass to the function. */
3934 const pseudo_typeS md_pseudo_table[] =
3936 /* Never called because '.req' does not start a line. */
3937 { "req", s_req, 0 },
3938 /* Following two are likewise never called. */
3939 { "dn", s_dn, 0 },
3940 { "qn", s_qn, 0 },
3941 { "unreq", s_unreq, 0 },
3942 { "bss", s_bss, 0 },
3943 { "align", s_align, 0 },
3944 { "arm", s_arm, 0 },
3945 { "thumb", s_thumb, 0 },
3946 { "code", s_code, 0 },
3947 { "force_thumb", s_force_thumb, 0 },
3948 { "thumb_func", s_thumb_func, 0 },
3949 { "thumb_set", s_thumb_set, 0 },
3950 { "even", s_even, 0 },
3951 { "ltorg", s_ltorg, 0 },
3952 { "pool", s_ltorg, 0 },
3953 { "syntax", s_syntax, 0 },
3954 { "cpu", s_arm_cpu, 0 },
3955 { "arch", s_arm_arch, 0 },
3956 { "object_arch", s_arm_object_arch, 0 },
3957 { "fpu", s_arm_fpu, 0 },
3958 #ifdef OBJ_ELF
3959 { "word", s_arm_elf_cons, 4 },
3960 { "long", s_arm_elf_cons, 4 },
3961 { "rel31", s_arm_rel31, 0 },
3962 { "fnstart", s_arm_unwind_fnstart, 0 },
3963 { "fnend", s_arm_unwind_fnend, 0 },
3964 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3965 { "personality", s_arm_unwind_personality, 0 },
3966 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3967 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3968 { "save", s_arm_unwind_save, 0 },
3969 { "vsave", s_arm_unwind_save, 1 },
3970 { "movsp", s_arm_unwind_movsp, 0 },
3971 { "pad", s_arm_unwind_pad, 0 },
3972 { "setfp", s_arm_unwind_setfp, 0 },
3973 { "unwind_raw", s_arm_unwind_raw, 0 },
3974 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3975 #else
3976 { "word", cons, 4},
3978 /* These are used for dwarf. */
3979 {"2byte", cons, 2},
3980 {"4byte", cons, 4},
3981 {"8byte", cons, 8},
3982 /* These are used for dwarf2. */
3983 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3984 { "loc", dwarf2_directive_loc, 0 },
3985 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
3986 #endif
3987 { "extend", float_cons, 'x' },
3988 { "ldouble", float_cons, 'x' },
3989 { "packed", float_cons, 'p' },
3990 #ifdef TE_PE
3991 {"secrel32", pe_directive_secrel, 0},
3992 #endif
3993 { 0, 0, 0 }
3996 /* Parser functions used exclusively in instruction operands. */
3998 /* Generic immediate-value read function for use in insn parsing.
3999 STR points to the beginning of the immediate (the leading #);
4000 VAL receives the value; if the value is outside [MIN, MAX]
4001 issue an error. PREFIX_OPT is true if the immediate prefix is
4002 optional. */
4004 static int
4005 parse_immediate (char **str, int *val, int min, int max,
4006 bfd_boolean prefix_opt)
4008 expressionS exp;
4009 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4010 if (exp.X_op != O_constant)
4012 inst.error = _("constant expression required");
4013 return FAIL;
4016 if (exp.X_add_number < min || exp.X_add_number > max)
4018 inst.error = _("immediate value out of range");
4019 return FAIL;
4022 *val = exp.X_add_number;
4023 return SUCCESS;
4026 /* Less-generic immediate-value read function with the possibility of loading a
4027 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4028 instructions. Puts the result directly in inst.operands[i]. */
4030 static int
4031 parse_big_immediate (char **str, int i)
4033 expressionS exp;
4034 char *ptr = *str;
4036 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4038 if (exp.X_op == O_constant)
4040 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4041 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4042 O_constant. We have to be careful not to break compilation for
4043 32-bit X_add_number, though. */
4044 if ((exp.X_add_number & ~0xffffffffl) != 0)
4046 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4047 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4048 inst.operands[i].regisimm = 1;
4051 else if (exp.X_op == O_big
4052 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4053 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4055 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4056 /* Bignums have their least significant bits in
4057 generic_bignum[0]. Make sure we put 32 bits in imm and
4058 32 bits in reg, in a (hopefully) portable way. */
4059 assert (parts != 0);
4060 inst.operands[i].imm = 0;
4061 for (j = 0; j < parts; j++, idx++)
4062 inst.operands[i].imm |= generic_bignum[idx]
4063 << (LITTLENUM_NUMBER_OF_BITS * j);
4064 inst.operands[i].reg = 0;
4065 for (j = 0; j < parts; j++, idx++)
4066 inst.operands[i].reg |= generic_bignum[idx]
4067 << (LITTLENUM_NUMBER_OF_BITS * j);
4068 inst.operands[i].regisimm = 1;
4070 else
4071 return FAIL;
4073 *str = ptr;
4075 return SUCCESS;
4078 /* Returns the pseudo-register number of an FPA immediate constant,
4079 or FAIL if there isn't a valid constant here. */
4081 static int
4082 parse_fpa_immediate (char ** str)
4084 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4085 char * save_in;
4086 expressionS exp;
4087 int i;
4088 int j;
4090 /* First try and match exact strings, this is to guarantee
4091 that some formats will work even for cross assembly. */
4093 for (i = 0; fp_const[i]; i++)
4095 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4097 char *start = *str;
4099 *str += strlen (fp_const[i]);
4100 if (is_end_of_line[(unsigned char) **str])
4101 return i + 8;
4102 *str = start;
4106 /* Just because we didn't get a match doesn't mean that the constant
4107 isn't valid, just that it is in a format that we don't
4108 automatically recognize. Try parsing it with the standard
4109 expression routines. */
4111 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4113 /* Look for a raw floating point number. */
4114 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4115 && is_end_of_line[(unsigned char) *save_in])
4117 for (i = 0; i < NUM_FLOAT_VALS; i++)
4119 for (j = 0; j < MAX_LITTLENUMS; j++)
4121 if (words[j] != fp_values[i][j])
4122 break;
4125 if (j == MAX_LITTLENUMS)
4127 *str = save_in;
4128 return i + 8;
4133 /* Try and parse a more complex expression, this will probably fail
4134 unless the code uses a floating point prefix (eg "0f"). */
4135 save_in = input_line_pointer;
4136 input_line_pointer = *str;
4137 if (expression (&exp) == absolute_section
4138 && exp.X_op == O_big
4139 && exp.X_add_number < 0)
4141 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4142 Ditto for 15. */
4143 if (gen_to_words (words, 5, (long) 15) == 0)
4145 for (i = 0; i < NUM_FLOAT_VALS; i++)
4147 for (j = 0; j < MAX_LITTLENUMS; j++)
4149 if (words[j] != fp_values[i][j])
4150 break;
4153 if (j == MAX_LITTLENUMS)
4155 *str = input_line_pointer;
4156 input_line_pointer = save_in;
4157 return i + 8;
4163 *str = input_line_pointer;
4164 input_line_pointer = save_in;
4165 inst.error = _("invalid FPA immediate expression");
4166 return FAIL;
4169 /* Returns 1 if a number has "quarter-precision" float format
4170 0baBbbbbbc defgh000 00000000 00000000. */
4172 static int
4173 is_quarter_float (unsigned imm)
4175 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4176 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4179 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4180 0baBbbbbbc defgh000 00000000 00000000.
4181 The zero and minus-zero cases need special handling, since they can't be
4182 encoded in the "quarter-precision" float format, but can nonetheless be
4183 loaded as integer constants. */
4185 static unsigned
4186 parse_qfloat_immediate (char **ccp, int *immed)
4188 char *str = *ccp;
4189 char *fpnum;
4190 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4191 int found_fpchar = 0;
4193 skip_past_char (&str, '#');
4195 /* We must not accidentally parse an integer as a floating-point number. Make
4196 sure that the value we parse is not an integer by checking for special
4197 characters '.' or 'e'.
4198 FIXME: This is a horrible hack, but doing better is tricky because type
4199 information isn't in a very usable state at parse time. */
4200 fpnum = str;
4201 skip_whitespace (fpnum);
4203 if (strncmp (fpnum, "0x", 2) == 0)
4204 return FAIL;
4205 else
4207 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4208 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4210 found_fpchar = 1;
4211 break;
4214 if (!found_fpchar)
4215 return FAIL;
4218 if ((str = atof_ieee (str, 's', words)) != NULL)
4220 unsigned fpword = 0;
4221 int i;
4223 /* Our FP word must be 32 bits (single-precision FP). */
4224 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4226 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4227 fpword |= words[i];
4230 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4231 *immed = fpword;
4232 else
4233 return FAIL;
4235 *ccp = str;
4237 return SUCCESS;
4240 return FAIL;
4243 /* Shift operands. */
4244 enum shift_kind
4246 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4249 struct asm_shift_name
4251 const char *name;
4252 enum shift_kind kind;
4255 /* Third argument to parse_shift. */
4256 enum parse_shift_mode
4258 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4259 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4260 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4261 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4262 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4265 /* Parse a <shift> specifier on an ARM data processing instruction.
4266 This has three forms:
4268 (LSL|LSR|ASL|ASR|ROR) Rs
4269 (LSL|LSR|ASL|ASR|ROR) #imm
4272 Note that ASL is assimilated to LSL in the instruction encoding, and
4273 RRX to ROR #0 (which cannot be written as such). */
4275 static int
4276 parse_shift (char **str, int i, enum parse_shift_mode mode)
4278 const struct asm_shift_name *shift_name;
4279 enum shift_kind shift;
4280 char *s = *str;
4281 char *p = s;
4282 int reg;
4284 for (p = *str; ISALPHA (*p); p++)
4287 if (p == *str)
4289 inst.error = _("shift expression expected");
4290 return FAIL;
4293 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4295 if (shift_name == NULL)
4297 inst.error = _("shift expression expected");
4298 return FAIL;
4301 shift = shift_name->kind;
4303 switch (mode)
4305 case NO_SHIFT_RESTRICT:
4306 case SHIFT_IMMEDIATE: break;
4308 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4309 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4311 inst.error = _("'LSL' or 'ASR' required");
4312 return FAIL;
4314 break;
4316 case SHIFT_LSL_IMMEDIATE:
4317 if (shift != SHIFT_LSL)
4319 inst.error = _("'LSL' required");
4320 return FAIL;
4322 break;
4324 case SHIFT_ASR_IMMEDIATE:
4325 if (shift != SHIFT_ASR)
4327 inst.error = _("'ASR' required");
4328 return FAIL;
4330 break;
4332 default: abort ();
4335 if (shift != SHIFT_RRX)
4337 /* Whitespace can appear here if the next thing is a bare digit. */
4338 skip_whitespace (p);
4340 if (mode == NO_SHIFT_RESTRICT
4341 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4343 inst.operands[i].imm = reg;
4344 inst.operands[i].immisreg = 1;
4346 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4347 return FAIL;
4349 inst.operands[i].shift_kind = shift;
4350 inst.operands[i].shifted = 1;
4351 *str = p;
4352 return SUCCESS;
4355 /* Parse a <shifter_operand> for an ARM data processing instruction:
4357 #<immediate>
4358 #<immediate>, <rotate>
4359 <Rm>
4360 <Rm>, <shift>
4362 where <shift> is defined by parse_shift above, and <rotate> is a
4363 multiple of 2 between 0 and 30. Validation of immediate operands
4364 is deferred to md_apply_fix. */
4366 static int
4367 parse_shifter_operand (char **str, int i)
4369 int value;
4370 expressionS expr;
4372 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4374 inst.operands[i].reg = value;
4375 inst.operands[i].isreg = 1;
4377 /* parse_shift will override this if appropriate */
4378 inst.reloc.exp.X_op = O_constant;
4379 inst.reloc.exp.X_add_number = 0;
4381 if (skip_past_comma (str) == FAIL)
4382 return SUCCESS;
4384 /* Shift operation on register. */
4385 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4388 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4389 return FAIL;
4391 if (skip_past_comma (str) == SUCCESS)
4393 /* #x, y -- ie explicit rotation by Y. */
4394 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4395 return FAIL;
4397 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4399 inst.error = _("constant expression expected");
4400 return FAIL;
4403 value = expr.X_add_number;
4404 if (value < 0 || value > 30 || value % 2 != 0)
4406 inst.error = _("invalid rotation");
4407 return FAIL;
4409 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4411 inst.error = _("invalid constant");
4412 return FAIL;
4415 /* Convert to decoded value. md_apply_fix will put it back. */
4416 inst.reloc.exp.X_add_number
4417 = (((inst.reloc.exp.X_add_number << (32 - value))
4418 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4421 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4422 inst.reloc.pc_rel = 0;
4423 return SUCCESS;
4426 /* Group relocation information. Each entry in the table contains the
4427 textual name of the relocation as may appear in assembler source
4428 and must end with a colon.
4429 Along with this textual name are the relocation codes to be used if
4430 the corresponding instruction is an ALU instruction (ADD or SUB only),
4431 an LDR, an LDRS, or an LDC. */
4433 struct group_reloc_table_entry
4435 const char *name;
4436 int alu_code;
4437 int ldr_code;
4438 int ldrs_code;
4439 int ldc_code;
4442 typedef enum
4444 /* Varieties of non-ALU group relocation. */
4446 GROUP_LDR,
4447 GROUP_LDRS,
4448 GROUP_LDC
4449 } group_reloc_type;
4451 static struct group_reloc_table_entry group_reloc_table[] =
4452 { /* Program counter relative: */
4453 { "pc_g0_nc",
4454 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4455 0, /* LDR */
4456 0, /* LDRS */
4457 0 }, /* LDC */
4458 { "pc_g0",
4459 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4460 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4461 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4462 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4463 { "pc_g1_nc",
4464 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4465 0, /* LDR */
4466 0, /* LDRS */
4467 0 }, /* LDC */
4468 { "pc_g1",
4469 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4470 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4471 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4472 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4473 { "pc_g2",
4474 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4475 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4476 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4477 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4478 /* Section base relative */
4479 { "sb_g0_nc",
4480 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4481 0, /* LDR */
4482 0, /* LDRS */
4483 0 }, /* LDC */
4484 { "sb_g0",
4485 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4486 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4487 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4488 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4489 { "sb_g1_nc",
4490 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4491 0, /* LDR */
4492 0, /* LDRS */
4493 0 }, /* LDC */
4494 { "sb_g1",
4495 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4496 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4497 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4498 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4499 { "sb_g2",
4500 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4501 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4502 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4503 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4505 /* Given the address of a pointer pointing to the textual name of a group
4506 relocation as may appear in assembler source, attempt to find its details
4507 in group_reloc_table. The pointer will be updated to the character after
4508 the trailing colon. On failure, FAIL will be returned; SUCCESS
4509 otherwise. On success, *entry will be updated to point at the relevant
4510 group_reloc_table entry. */
4512 static int
4513 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4515 unsigned int i;
4516 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4518 int length = strlen (group_reloc_table[i].name);
4520 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4521 && (*str)[length] == ':')
4523 *out = &group_reloc_table[i];
4524 *str += (length + 1);
4525 return SUCCESS;
4529 return FAIL;
4532 /* Parse a <shifter_operand> for an ARM data processing instruction
4533 (as for parse_shifter_operand) where group relocations are allowed:
4535 #<immediate>
4536 #<immediate>, <rotate>
4537 #:<group_reloc>:<expression>
4538 <Rm>
4539 <Rm>, <shift>
4541 where <group_reloc> is one of the strings defined in group_reloc_table.
4542 The hashes are optional.
4544 Everything else is as for parse_shifter_operand. */
4546 static parse_operand_result
4547 parse_shifter_operand_group_reloc (char **str, int i)
4549 /* Determine if we have the sequence of characters #: or just :
4550 coming next. If we do, then we check for a group relocation.
4551 If we don't, punt the whole lot to parse_shifter_operand. */
4553 if (((*str)[0] == '#' && (*str)[1] == ':')
4554 || (*str)[0] == ':')
4556 struct group_reloc_table_entry *entry;
4558 if ((*str)[0] == '#')
4559 (*str) += 2;
4560 else
4561 (*str)++;
4563 /* Try to parse a group relocation. Anything else is an error. */
4564 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4566 inst.error = _("unknown group relocation");
4567 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4570 /* We now have the group relocation table entry corresponding to
4571 the name in the assembler source. Next, we parse the expression. */
4572 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4573 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4575 /* Record the relocation type (always the ALU variant here). */
4576 inst.reloc.type = entry->alu_code;
4577 assert (inst.reloc.type != 0);
4579 return PARSE_OPERAND_SUCCESS;
4581 else
4582 return parse_shifter_operand (str, i) == SUCCESS
4583 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4585 /* Never reached. */
4588 /* Parse all forms of an ARM address expression. Information is written
4589 to inst.operands[i] and/or inst.reloc.
4591 Preindexed addressing (.preind=1):
4593 [Rn, #offset] .reg=Rn .reloc.exp=offset
4594 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4595 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4596 .shift_kind=shift .reloc.exp=shift_imm
4598 These three may have a trailing ! which causes .writeback to be set also.
4600 Postindexed addressing (.postind=1, .writeback=1):
4602 [Rn], #offset .reg=Rn .reloc.exp=offset
4603 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4604 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4605 .shift_kind=shift .reloc.exp=shift_imm
4607 Unindexed addressing (.preind=0, .postind=0):
4609 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4611 Other:
4613 [Rn]{!} shorthand for [Rn,#0]{!}
4614 =immediate .isreg=0 .reloc.exp=immediate
4615 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4617 It is the caller's responsibility to check for addressing modes not
4618 supported by the instruction, and to set inst.reloc.type. */
4620 static parse_operand_result
4621 parse_address_main (char **str, int i, int group_relocations,
4622 group_reloc_type group_type)
4624 char *p = *str;
4625 int reg;
4627 if (skip_past_char (&p, '[') == FAIL)
4629 if (skip_past_char (&p, '=') == FAIL)
4631 /* bare address - translate to PC-relative offset */
4632 inst.reloc.pc_rel = 1;
4633 inst.operands[i].reg = REG_PC;
4634 inst.operands[i].isreg = 1;
4635 inst.operands[i].preind = 1;
4637 /* else a load-constant pseudo op, no special treatment needed here */
4639 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4640 return PARSE_OPERAND_FAIL;
4642 *str = p;
4643 return PARSE_OPERAND_SUCCESS;
4646 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4648 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4649 return PARSE_OPERAND_FAIL;
4651 inst.operands[i].reg = reg;
4652 inst.operands[i].isreg = 1;
4654 if (skip_past_comma (&p) == SUCCESS)
4656 inst.operands[i].preind = 1;
4658 if (*p == '+') p++;
4659 else if (*p == '-') p++, inst.operands[i].negative = 1;
4661 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4663 inst.operands[i].imm = reg;
4664 inst.operands[i].immisreg = 1;
4666 if (skip_past_comma (&p) == SUCCESS)
4667 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4668 return PARSE_OPERAND_FAIL;
4670 else if (skip_past_char (&p, ':') == SUCCESS)
4672 /* FIXME: '@' should be used here, but it's filtered out by generic
4673 code before we get to see it here. This may be subject to
4674 change. */
4675 expressionS exp;
4676 my_get_expression (&exp, &p, GE_NO_PREFIX);
4677 if (exp.X_op != O_constant)
4679 inst.error = _("alignment must be constant");
4680 return PARSE_OPERAND_FAIL;
4682 inst.operands[i].imm = exp.X_add_number << 8;
4683 inst.operands[i].immisalign = 1;
4684 /* Alignments are not pre-indexes. */
4685 inst.operands[i].preind = 0;
4687 else
4689 if (inst.operands[i].negative)
4691 inst.operands[i].negative = 0;
4692 p--;
4695 if (group_relocations
4696 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4698 struct group_reloc_table_entry *entry;
4700 /* Skip over the #: or : sequence. */
4701 if (*p == '#')
4702 p += 2;
4703 else
4704 p++;
4706 /* Try to parse a group relocation. Anything else is an
4707 error. */
4708 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4710 inst.error = _("unknown group relocation");
4711 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4714 /* We now have the group relocation table entry corresponding to
4715 the name in the assembler source. Next, we parse the
4716 expression. */
4717 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4718 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4720 /* Record the relocation type. */
4721 switch (group_type)
4723 case GROUP_LDR:
4724 inst.reloc.type = entry->ldr_code;
4725 break;
4727 case GROUP_LDRS:
4728 inst.reloc.type = entry->ldrs_code;
4729 break;
4731 case GROUP_LDC:
4732 inst.reloc.type = entry->ldc_code;
4733 break;
4735 default:
4736 assert (0);
4739 if (inst.reloc.type == 0)
4741 inst.error = _("this group relocation is not allowed on this instruction");
4742 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4745 else
4746 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4747 return PARSE_OPERAND_FAIL;
4751 if (skip_past_char (&p, ']') == FAIL)
4753 inst.error = _("']' expected");
4754 return PARSE_OPERAND_FAIL;
4757 if (skip_past_char (&p, '!') == SUCCESS)
4758 inst.operands[i].writeback = 1;
4760 else if (skip_past_comma (&p) == SUCCESS)
4762 if (skip_past_char (&p, '{') == SUCCESS)
4764 /* [Rn], {expr} - unindexed, with option */
4765 if (parse_immediate (&p, &inst.operands[i].imm,
4766 0, 255, TRUE) == FAIL)
4767 return PARSE_OPERAND_FAIL;
4769 if (skip_past_char (&p, '}') == FAIL)
4771 inst.error = _("'}' expected at end of 'option' field");
4772 return PARSE_OPERAND_FAIL;
4774 if (inst.operands[i].preind)
4776 inst.error = _("cannot combine index with option");
4777 return PARSE_OPERAND_FAIL;
4779 *str = p;
4780 return PARSE_OPERAND_SUCCESS;
4782 else
4784 inst.operands[i].postind = 1;
4785 inst.operands[i].writeback = 1;
4787 if (inst.operands[i].preind)
4789 inst.error = _("cannot combine pre- and post-indexing");
4790 return PARSE_OPERAND_FAIL;
4793 if (*p == '+') p++;
4794 else if (*p == '-') p++, inst.operands[i].negative = 1;
4796 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4798 /* We might be using the immediate for alignment already. If we
4799 are, OR the register number into the low-order bits. */
4800 if (inst.operands[i].immisalign)
4801 inst.operands[i].imm |= reg;
4802 else
4803 inst.operands[i].imm = reg;
4804 inst.operands[i].immisreg = 1;
4806 if (skip_past_comma (&p) == SUCCESS)
4807 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4808 return PARSE_OPERAND_FAIL;
4810 else
4812 if (inst.operands[i].negative)
4814 inst.operands[i].negative = 0;
4815 p--;
4817 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4818 return PARSE_OPERAND_FAIL;
4823 /* If at this point neither .preind nor .postind is set, we have a
4824 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4825 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4827 inst.operands[i].preind = 1;
4828 inst.reloc.exp.X_op = O_constant;
4829 inst.reloc.exp.X_add_number = 0;
4831 *str = p;
4832 return PARSE_OPERAND_SUCCESS;
4835 static int
4836 parse_address (char **str, int i)
4838 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4839 ? SUCCESS : FAIL;
4842 static parse_operand_result
4843 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4845 return parse_address_main (str, i, 1, type);
4848 /* Parse an operand for a MOVW or MOVT instruction. */
4849 static int
4850 parse_half (char **str)
4852 char * p;
4854 p = *str;
4855 skip_past_char (&p, '#');
4856 if (strncasecmp (p, ":lower16:", 9) == 0)
4857 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4858 else if (strncasecmp (p, ":upper16:", 9) == 0)
4859 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4861 if (inst.reloc.type != BFD_RELOC_UNUSED)
4863 p += 9;
4864 skip_whitespace (p);
4867 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4868 return FAIL;
4870 if (inst.reloc.type == BFD_RELOC_UNUSED)
4872 if (inst.reloc.exp.X_op != O_constant)
4874 inst.error = _("constant expression expected");
4875 return FAIL;
4877 if (inst.reloc.exp.X_add_number < 0
4878 || inst.reloc.exp.X_add_number > 0xffff)
4880 inst.error = _("immediate value out of range");
4881 return FAIL;
4884 *str = p;
4885 return SUCCESS;
4888 /* Miscellaneous. */
4890 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4891 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4892 static int
4893 parse_psr (char **str)
4895 char *p;
4896 unsigned long psr_field;
4897 const struct asm_psr *psr;
4898 char *start;
4900 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4901 feature for ease of use and backwards compatibility. */
4902 p = *str;
4903 if (strncasecmp (p, "SPSR", 4) == 0)
4904 psr_field = SPSR_BIT;
4905 else if (strncasecmp (p, "CPSR", 4) == 0)
4906 psr_field = 0;
4907 else
4909 start = p;
4911 p++;
4912 while (ISALNUM (*p) || *p == '_');
4914 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4915 if (!psr)
4916 return FAIL;
4918 *str = p;
4919 return psr->field;
4922 p += 4;
4923 if (*p == '_')
4925 /* A suffix follows. */
4926 p++;
4927 start = p;
4930 p++;
4931 while (ISALNUM (*p) || *p == '_');
4933 psr = hash_find_n (arm_psr_hsh, start, p - start);
4934 if (!psr)
4935 goto error;
4937 psr_field |= psr->field;
4939 else
4941 if (ISALNUM (*p))
4942 goto error; /* Garbage after "[CS]PSR". */
4944 psr_field |= (PSR_c | PSR_f);
4946 *str = p;
4947 return psr_field;
4949 error:
4950 inst.error = _("flag for {c}psr instruction expected");
4951 return FAIL;
4954 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4955 value suitable for splatting into the AIF field of the instruction. */
4957 static int
4958 parse_cps_flags (char **str)
4960 int val = 0;
4961 int saw_a_flag = 0;
4962 char *s = *str;
4964 for (;;)
4965 switch (*s++)
4967 case '\0': case ',':
4968 goto done;
4970 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4971 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4972 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4974 default:
4975 inst.error = _("unrecognized CPS flag");
4976 return FAIL;
4979 done:
4980 if (saw_a_flag == 0)
4982 inst.error = _("missing CPS flags");
4983 return FAIL;
4986 *str = s - 1;
4987 return val;
4990 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4991 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4993 static int
4994 parse_endian_specifier (char **str)
4996 int little_endian;
4997 char *s = *str;
4999 if (strncasecmp (s, "BE", 2))
5000 little_endian = 0;
5001 else if (strncasecmp (s, "LE", 2))
5002 little_endian = 1;
5003 else
5005 inst.error = _("valid endian specifiers are be or le");
5006 return FAIL;
5009 if (ISALNUM (s[2]) || s[2] == '_')
5011 inst.error = _("valid endian specifiers are be or le");
5012 return FAIL;
5015 *str = s + 2;
5016 return little_endian;
5019 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5020 value suitable for poking into the rotate field of an sxt or sxta
5021 instruction, or FAIL on error. */
5023 static int
5024 parse_ror (char **str)
5026 int rot;
5027 char *s = *str;
5029 if (strncasecmp (s, "ROR", 3) == 0)
5030 s += 3;
5031 else
5033 inst.error = _("missing rotation field after comma");
5034 return FAIL;
5037 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5038 return FAIL;
5040 switch (rot)
5042 case 0: *str = s; return 0x0;
5043 case 8: *str = s; return 0x1;
5044 case 16: *str = s; return 0x2;
5045 case 24: *str = s; return 0x3;
5047 default:
5048 inst.error = _("rotation can only be 0, 8, 16, or 24");
5049 return FAIL;
5053 /* Parse a conditional code (from conds[] below). The value returned is in the
5054 range 0 .. 14, or FAIL. */
5055 static int
5056 parse_cond (char **str)
5058 char *q;
5059 const struct asm_cond *c;
5060 int n;
5061 /* Condition codes are always 2 characters, so matching up to
5062 3 characters is sufficient. */
5063 char cond[3];
5065 q = *str;
5066 n = 0;
5067 while (ISALPHA (*q) && n < 3)
5069 cond[n] = TOLOWER(*q);
5070 q++;
5071 n++;
5074 c = hash_find_n (arm_cond_hsh, cond, n);
5075 if (!c)
5077 inst.error = _("condition required");
5078 return FAIL;
5081 *str = q;
5082 return c->value;
5085 /* Parse an option for a barrier instruction. Returns the encoding for the
5086 option, or FAIL. */
5087 static int
5088 parse_barrier (char **str)
5090 char *p, *q;
5091 const struct asm_barrier_opt *o;
5093 p = q = *str;
5094 while (ISALPHA (*q))
5095 q++;
5097 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5098 if (!o)
5099 return FAIL;
5101 *str = q;
5102 return o->value;
5105 /* Parse the operands of a table branch instruction. Similar to a memory
5106 operand. */
5107 static int
5108 parse_tb (char **str)
5110 char * p = *str;
5111 int reg;
5113 if (skip_past_char (&p, '[') == FAIL)
5115 inst.error = _("'[' expected");
5116 return FAIL;
5119 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5121 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5122 return FAIL;
5124 inst.operands[0].reg = reg;
5126 if (skip_past_comma (&p) == FAIL)
5128 inst.error = _("',' expected");
5129 return FAIL;
5132 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5134 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5135 return FAIL;
5137 inst.operands[0].imm = reg;
5139 if (skip_past_comma (&p) == SUCCESS)
5141 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5142 return FAIL;
5143 if (inst.reloc.exp.X_add_number != 1)
5145 inst.error = _("invalid shift");
5146 return FAIL;
5148 inst.operands[0].shifted = 1;
5151 if (skip_past_char (&p, ']') == FAIL)
5153 inst.error = _("']' expected");
5154 return FAIL;
5156 *str = p;
5157 return SUCCESS;
5160 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5161 information on the types the operands can take and how they are encoded.
5162 Up to four operands may be read; this function handles setting the
5163 ".present" field for each read operand itself.
5164 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5165 else returns FAIL. */
5167 static int
5168 parse_neon_mov (char **str, int *which_operand)
5170 int i = *which_operand, val;
5171 enum arm_reg_type rtype;
5172 char *ptr = *str;
5173 struct neon_type_el optype;
5175 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5177 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5178 inst.operands[i].reg = val;
5179 inst.operands[i].isscalar = 1;
5180 inst.operands[i].vectype = optype;
5181 inst.operands[i++].present = 1;
5183 if (skip_past_comma (&ptr) == FAIL)
5184 goto wanted_comma;
5186 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5187 goto wanted_arm;
5189 inst.operands[i].reg = val;
5190 inst.operands[i].isreg = 1;
5191 inst.operands[i].present = 1;
5193 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5194 != FAIL)
5196 /* Cases 0, 1, 2, 3, 5 (D only). */
5197 if (skip_past_comma (&ptr) == FAIL)
5198 goto wanted_comma;
5200 inst.operands[i].reg = val;
5201 inst.operands[i].isreg = 1;
5202 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5203 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5204 inst.operands[i].isvec = 1;
5205 inst.operands[i].vectype = optype;
5206 inst.operands[i++].present = 1;
5208 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5210 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5211 Case 13: VMOV <Sd>, <Rm> */
5212 inst.operands[i].reg = val;
5213 inst.operands[i].isreg = 1;
5214 inst.operands[i].present = 1;
5216 if (rtype == REG_TYPE_NQ)
5218 first_error (_("can't use Neon quad register here"));
5219 return FAIL;
5221 else if (rtype != REG_TYPE_VFS)
5223 i++;
5224 if (skip_past_comma (&ptr) == FAIL)
5225 goto wanted_comma;
5226 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5227 goto wanted_arm;
5228 inst.operands[i].reg = val;
5229 inst.operands[i].isreg = 1;
5230 inst.operands[i].present = 1;
5233 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5234 &optype)) != FAIL)
5236 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5237 Case 1: VMOV<c><q> <Dd>, <Dm>
5238 Case 8: VMOV.F32 <Sd>, <Sm>
5239 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5241 inst.operands[i].reg = val;
5242 inst.operands[i].isreg = 1;
5243 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5244 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5245 inst.operands[i].isvec = 1;
5246 inst.operands[i].vectype = optype;
5247 inst.operands[i].present = 1;
5249 if (skip_past_comma (&ptr) == SUCCESS)
5251 /* Case 15. */
5252 i++;
5254 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5255 goto wanted_arm;
5257 inst.operands[i].reg = val;
5258 inst.operands[i].isreg = 1;
5259 inst.operands[i++].present = 1;
5261 if (skip_past_comma (&ptr) == FAIL)
5262 goto wanted_comma;
5264 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5265 goto wanted_arm;
5267 inst.operands[i].reg = val;
5268 inst.operands[i].isreg = 1;
5269 inst.operands[i++].present = 1;
5272 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5273 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5274 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5275 Case 10: VMOV.F32 <Sd>, #<imm>
5276 Case 11: VMOV.F64 <Dd>, #<imm> */
5277 inst.operands[i].immisfloat = 1;
5278 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5279 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5280 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5282 else
5284 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5285 return FAIL;
5288 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5290 /* Cases 6, 7. */
5291 inst.operands[i].reg = val;
5292 inst.operands[i].isreg = 1;
5293 inst.operands[i++].present = 1;
5295 if (skip_past_comma (&ptr) == FAIL)
5296 goto wanted_comma;
5298 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5300 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5301 inst.operands[i].reg = val;
5302 inst.operands[i].isscalar = 1;
5303 inst.operands[i].present = 1;
5304 inst.operands[i].vectype = optype;
5306 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5308 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5309 inst.operands[i].reg = val;
5310 inst.operands[i].isreg = 1;
5311 inst.operands[i++].present = 1;
5313 if (skip_past_comma (&ptr) == FAIL)
5314 goto wanted_comma;
5316 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5317 == FAIL)
5319 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5320 return FAIL;
5323 inst.operands[i].reg = val;
5324 inst.operands[i].isreg = 1;
5325 inst.operands[i].isvec = 1;
5326 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5327 inst.operands[i].vectype = optype;
5328 inst.operands[i].present = 1;
5330 if (rtype == REG_TYPE_VFS)
5332 /* Case 14. */
5333 i++;
5334 if (skip_past_comma (&ptr) == FAIL)
5335 goto wanted_comma;
5336 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5337 &optype)) == FAIL)
5339 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5340 return FAIL;
5342 inst.operands[i].reg = val;
5343 inst.operands[i].isreg = 1;
5344 inst.operands[i].isvec = 1;
5345 inst.operands[i].issingle = 1;
5346 inst.operands[i].vectype = optype;
5347 inst.operands[i].present = 1;
5350 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5351 != FAIL)
5353 /* Case 13. */
5354 inst.operands[i].reg = val;
5355 inst.operands[i].isreg = 1;
5356 inst.operands[i].isvec = 1;
5357 inst.operands[i].issingle = 1;
5358 inst.operands[i].vectype = optype;
5359 inst.operands[i++].present = 1;
5362 else
5364 first_error (_("parse error"));
5365 return FAIL;
5368 /* Successfully parsed the operands. Update args. */
5369 *which_operand = i;
5370 *str = ptr;
5371 return SUCCESS;
5373 wanted_comma:
5374 first_error (_("expected comma"));
5375 return FAIL;
5377 wanted_arm:
5378 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5379 return FAIL;
5382 /* Matcher codes for parse_operands. */
5383 enum operand_parse_code
5385 OP_stop, /* end of line */
5387 OP_RR, /* ARM register */
5388 OP_RRnpc, /* ARM register, not r15 */
5389 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5390 OP_RRw, /* ARM register, not r15, optional trailing ! */
5391 OP_RCP, /* Coprocessor number */
5392 OP_RCN, /* Coprocessor register */
5393 OP_RF, /* FPA register */
5394 OP_RVS, /* VFP single precision register */
5395 OP_RVD, /* VFP double precision register (0..15) */
5396 OP_RND, /* Neon double precision register (0..31) */
5397 OP_RNQ, /* Neon quad precision register */
5398 OP_RVSD, /* VFP single or double precision register */
5399 OP_RNDQ, /* Neon double or quad precision register */
5400 OP_RNSDQ, /* Neon single, double or quad precision register */
5401 OP_RNSC, /* Neon scalar D[X] */
5402 OP_RVC, /* VFP control register */
5403 OP_RMF, /* Maverick F register */
5404 OP_RMD, /* Maverick D register */
5405 OP_RMFX, /* Maverick FX register */
5406 OP_RMDX, /* Maverick DX register */
5407 OP_RMAX, /* Maverick AX register */
5408 OP_RMDS, /* Maverick DSPSC register */
5409 OP_RIWR, /* iWMMXt wR register */
5410 OP_RIWC, /* iWMMXt wC register */
5411 OP_RIWG, /* iWMMXt wCG register */
5412 OP_RXA, /* XScale accumulator register */
5414 OP_REGLST, /* ARM register list */
5415 OP_VRSLST, /* VFP single-precision register list */
5416 OP_VRDLST, /* VFP double-precision register list */
5417 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5418 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5419 OP_NSTRLST, /* Neon element/structure list */
5421 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5422 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5423 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5424 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5425 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5426 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5427 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5428 OP_VMOV, /* Neon VMOV operands. */
5429 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5430 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5431 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5433 OP_I0, /* immediate zero */
5434 OP_I7, /* immediate value 0 .. 7 */
5435 OP_I15, /* 0 .. 15 */
5436 OP_I16, /* 1 .. 16 */
5437 OP_I16z, /* 0 .. 16 */
5438 OP_I31, /* 0 .. 31 */
5439 OP_I31w, /* 0 .. 31, optional trailing ! */
5440 OP_I32, /* 1 .. 32 */
5441 OP_I32z, /* 0 .. 32 */
5442 OP_I63, /* 0 .. 63 */
5443 OP_I63s, /* -64 .. 63 */
5444 OP_I64, /* 1 .. 64 */
5445 OP_I64z, /* 0 .. 64 */
5446 OP_I255, /* 0 .. 255 */
5448 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5449 OP_I7b, /* 0 .. 7 */
5450 OP_I15b, /* 0 .. 15 */
5451 OP_I31b, /* 0 .. 31 */
5453 OP_SH, /* shifter operand */
5454 OP_SHG, /* shifter operand with possible group relocation */
5455 OP_ADDR, /* Memory address expression (any mode) */
5456 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5457 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5458 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5459 OP_EXP, /* arbitrary expression */
5460 OP_EXPi, /* same, with optional immediate prefix */
5461 OP_EXPr, /* same, with optional relocation suffix */
5462 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5464 OP_CPSF, /* CPS flags */
5465 OP_ENDI, /* Endianness specifier */
5466 OP_PSR, /* CPSR/SPSR mask for msr */
5467 OP_COND, /* conditional code */
5468 OP_TB, /* Table branch. */
5470 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5471 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5473 OP_RRnpc_I0, /* ARM register or literal 0 */
5474 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5475 OP_RR_EXi, /* ARM register or expression with imm prefix */
5476 OP_RF_IF, /* FPA register or immediate */
5477 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5478 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5480 /* Optional operands. */
5481 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5482 OP_oI31b, /* 0 .. 31 */
5483 OP_oI32b, /* 1 .. 32 */
5484 OP_oIffffb, /* 0 .. 65535 */
5485 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5487 OP_oRR, /* ARM register */
5488 OP_oRRnpc, /* ARM register, not the PC */
5489 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5490 OP_oRND, /* Optional Neon double precision register */
5491 OP_oRNQ, /* Optional Neon quad precision register */
5492 OP_oRNDQ, /* Optional Neon double or quad precision register */
5493 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5494 OP_oSHll, /* LSL immediate */
5495 OP_oSHar, /* ASR immediate */
5496 OP_oSHllar, /* LSL or ASR immediate */
5497 OP_oROR, /* ROR 0/8/16/24 */
5498 OP_oBARRIER, /* Option argument for a barrier instruction. */
5500 OP_FIRST_OPTIONAL = OP_oI7b
5503 /* Generic instruction operand parser. This does no encoding and no
5504 semantic validation; it merely squirrels values away in the inst
5505 structure. Returns SUCCESS or FAIL depending on whether the
5506 specified grammar matched. */
5507 static int
5508 parse_operands (char *str, const unsigned char *pattern)
5510 unsigned const char *upat = pattern;
5511 char *backtrack_pos = 0;
5512 const char *backtrack_error = 0;
5513 int i, val, backtrack_index = 0;
5514 enum arm_reg_type rtype;
5515 parse_operand_result result;
5517 #define po_char_or_fail(chr) do { \
5518 if (skip_past_char (&str, chr) == FAIL) \
5519 goto bad_args; \
5520 } while (0)
5522 #define po_reg_or_fail(regtype) do { \
5523 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5524 &inst.operands[i].vectype); \
5525 if (val == FAIL) \
5527 first_error (_(reg_expected_msgs[regtype])); \
5528 goto failure; \
5530 inst.operands[i].reg = val; \
5531 inst.operands[i].isreg = 1; \
5532 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5533 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5534 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5535 || rtype == REG_TYPE_VFD \
5536 || rtype == REG_TYPE_NQ); \
5537 } while (0)
5539 #define po_reg_or_goto(regtype, label) do { \
5540 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5541 &inst.operands[i].vectype); \
5542 if (val == FAIL) \
5543 goto label; \
5545 inst.operands[i].reg = val; \
5546 inst.operands[i].isreg = 1; \
5547 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5548 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5549 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5550 || rtype == REG_TYPE_VFD \
5551 || rtype == REG_TYPE_NQ); \
5552 } while (0)
5554 #define po_imm_or_fail(min, max, popt) do { \
5555 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5556 goto failure; \
5557 inst.operands[i].imm = val; \
5558 } while (0)
5560 #define po_scalar_or_goto(elsz, label) do { \
5561 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5562 if (val == FAIL) \
5563 goto label; \
5564 inst.operands[i].reg = val; \
5565 inst.operands[i].isscalar = 1; \
5566 } while (0)
5568 #define po_misc_or_fail(expr) do { \
5569 if (expr) \
5570 goto failure; \
5571 } while (0)
5573 #define po_misc_or_fail_no_backtrack(expr) do { \
5574 result = expr; \
5575 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5576 backtrack_pos = 0; \
5577 if (result != PARSE_OPERAND_SUCCESS) \
5578 goto failure; \
5579 } while (0)
5581 skip_whitespace (str);
5583 for (i = 0; upat[i] != OP_stop; i++)
5585 if (upat[i] >= OP_FIRST_OPTIONAL)
5587 /* Remember where we are in case we need to backtrack. */
5588 assert (!backtrack_pos);
5589 backtrack_pos = str;
5590 backtrack_error = inst.error;
5591 backtrack_index = i;
5594 if (i > 0 && (i > 1 || inst.operands[0].present))
5595 po_char_or_fail (',');
5597 switch (upat[i])
5599 /* Registers */
5600 case OP_oRRnpc:
5601 case OP_RRnpc:
5602 case OP_oRR:
5603 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5604 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5605 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5606 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5607 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5608 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5609 case OP_oRND:
5610 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5611 case OP_RVC:
5612 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5613 break;
5614 /* Also accept generic coprocessor regs for unknown registers. */
5615 coproc_reg:
5616 po_reg_or_fail (REG_TYPE_CN);
5617 break;
5618 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5619 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5620 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5621 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5622 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5623 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5624 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5625 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5626 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5627 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5628 case OP_oRNQ:
5629 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5630 case OP_oRNDQ:
5631 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5632 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5633 case OP_oRNSDQ:
5634 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5636 /* Neon scalar. Using an element size of 8 means that some invalid
5637 scalars are accepted here, so deal with those in later code. */
5638 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5640 /* WARNING: We can expand to two operands here. This has the potential
5641 to totally confuse the backtracking mechanism! It will be OK at
5642 least as long as we don't try to use optional args as well,
5643 though. */
5644 case OP_NILO:
5646 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5647 inst.operands[i].present = 1;
5648 i++;
5649 skip_past_comma (&str);
5650 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5651 break;
5652 one_reg_only:
5653 /* Optional register operand was omitted. Unfortunately, it's in
5654 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5655 here (this is a bit grotty). */
5656 inst.operands[i] = inst.operands[i-1];
5657 inst.operands[i-1].present = 0;
5658 break;
5659 try_imm:
5660 /* There's a possibility of getting a 64-bit immediate here, so
5661 we need special handling. */
5662 if (parse_big_immediate (&str, i) == FAIL)
5664 inst.error = _("immediate value is out of range");
5665 goto failure;
5668 break;
5670 case OP_RNDQ_I0:
5672 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5673 break;
5674 try_imm0:
5675 po_imm_or_fail (0, 0, TRUE);
5677 break;
5679 case OP_RVSD_I0:
5680 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5681 break;
5683 case OP_RR_RNSC:
5685 po_scalar_or_goto (8, try_rr);
5686 break;
5687 try_rr:
5688 po_reg_or_fail (REG_TYPE_RN);
5690 break;
5692 case OP_RNSDQ_RNSC:
5694 po_scalar_or_goto (8, try_nsdq);
5695 break;
5696 try_nsdq:
5697 po_reg_or_fail (REG_TYPE_NSDQ);
5699 break;
5701 case OP_RNDQ_RNSC:
5703 po_scalar_or_goto (8, try_ndq);
5704 break;
5705 try_ndq:
5706 po_reg_or_fail (REG_TYPE_NDQ);
5708 break;
5710 case OP_RND_RNSC:
5712 po_scalar_or_goto (8, try_vfd);
5713 break;
5714 try_vfd:
5715 po_reg_or_fail (REG_TYPE_VFD);
5717 break;
5719 case OP_VMOV:
5720 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5721 not careful then bad things might happen. */
5722 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5723 break;
5725 case OP_RNDQ_IMVNb:
5727 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5728 break;
5729 try_mvnimm:
5730 /* There's a possibility of getting a 64-bit immediate here, so
5731 we need special handling. */
5732 if (parse_big_immediate (&str, i) == FAIL)
5734 inst.error = _("immediate value is out of range");
5735 goto failure;
5738 break;
5740 case OP_RNDQ_I63b:
5742 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5743 break;
5744 try_shimm:
5745 po_imm_or_fail (0, 63, TRUE);
5747 break;
5749 case OP_RRnpcb:
5750 po_char_or_fail ('[');
5751 po_reg_or_fail (REG_TYPE_RN);
5752 po_char_or_fail (']');
5753 break;
5755 case OP_RRw:
5756 case OP_oRRw:
5757 po_reg_or_fail (REG_TYPE_RN);
5758 if (skip_past_char (&str, '!') == SUCCESS)
5759 inst.operands[i].writeback = 1;
5760 break;
5762 /* Immediates */
5763 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5764 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5765 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5766 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5767 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5768 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5769 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5770 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5771 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5772 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5773 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5774 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5776 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5777 case OP_oI7b:
5778 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5779 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5780 case OP_oI31b:
5781 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5782 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5783 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5785 /* Immediate variants */
5786 case OP_oI255c:
5787 po_char_or_fail ('{');
5788 po_imm_or_fail (0, 255, TRUE);
5789 po_char_or_fail ('}');
5790 break;
5792 case OP_I31w:
5793 /* The expression parser chokes on a trailing !, so we have
5794 to find it first and zap it. */
5796 char *s = str;
5797 while (*s && *s != ',')
5798 s++;
5799 if (s[-1] == '!')
5801 s[-1] = '\0';
5802 inst.operands[i].writeback = 1;
5804 po_imm_or_fail (0, 31, TRUE);
5805 if (str == s - 1)
5806 str = s;
5808 break;
5810 /* Expressions */
5811 case OP_EXPi: EXPi:
5812 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5813 GE_OPT_PREFIX));
5814 break;
5816 case OP_EXP:
5817 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5818 GE_NO_PREFIX));
5819 break;
5821 case OP_EXPr: EXPr:
5822 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5823 GE_NO_PREFIX));
5824 if (inst.reloc.exp.X_op == O_symbol)
5826 val = parse_reloc (&str);
5827 if (val == -1)
5829 inst.error = _("unrecognized relocation suffix");
5830 goto failure;
5832 else if (val != BFD_RELOC_UNUSED)
5834 inst.operands[i].imm = val;
5835 inst.operands[i].hasreloc = 1;
5838 break;
5840 /* Operand for MOVW or MOVT. */
5841 case OP_HALF:
5842 po_misc_or_fail (parse_half (&str));
5843 break;
5845 /* Register or expression */
5846 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5847 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5849 /* Register or immediate */
5850 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5851 I0: po_imm_or_fail (0, 0, FALSE); break;
5853 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5855 if (!is_immediate_prefix (*str))
5856 goto bad_args;
5857 str++;
5858 val = parse_fpa_immediate (&str);
5859 if (val == FAIL)
5860 goto failure;
5861 /* FPA immediates are encoded as registers 8-15.
5862 parse_fpa_immediate has already applied the offset. */
5863 inst.operands[i].reg = val;
5864 inst.operands[i].isreg = 1;
5865 break;
5867 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5868 I32z: po_imm_or_fail (0, 32, FALSE); break;
5870 /* Two kinds of register */
5871 case OP_RIWR_RIWC:
5873 struct reg_entry *rege = arm_reg_parse_multi (&str);
5874 if (!rege
5875 || (rege->type != REG_TYPE_MMXWR
5876 && rege->type != REG_TYPE_MMXWC
5877 && rege->type != REG_TYPE_MMXWCG))
5879 inst.error = _("iWMMXt data or control register expected");
5880 goto failure;
5882 inst.operands[i].reg = rege->number;
5883 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5885 break;
5887 case OP_RIWC_RIWG:
5889 struct reg_entry *rege = arm_reg_parse_multi (&str);
5890 if (!rege
5891 || (rege->type != REG_TYPE_MMXWC
5892 && rege->type != REG_TYPE_MMXWCG))
5894 inst.error = _("iWMMXt control register expected");
5895 goto failure;
5897 inst.operands[i].reg = rege->number;
5898 inst.operands[i].isreg = 1;
5900 break;
5902 /* Misc */
5903 case OP_CPSF: val = parse_cps_flags (&str); break;
5904 case OP_ENDI: val = parse_endian_specifier (&str); break;
5905 case OP_oROR: val = parse_ror (&str); break;
5906 case OP_PSR: val = parse_psr (&str); break;
5907 case OP_COND: val = parse_cond (&str); break;
5908 case OP_oBARRIER:val = parse_barrier (&str); break;
5910 case OP_RVC_PSR:
5911 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5912 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5913 break;
5914 try_psr:
5915 val = parse_psr (&str);
5916 break;
5918 case OP_APSR_RR:
5919 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5920 break;
5921 try_apsr:
5922 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5923 instruction). */
5924 if (strncasecmp (str, "APSR_", 5) == 0)
5926 unsigned found = 0;
5927 str += 5;
5928 while (found < 15)
5929 switch (*str++)
5931 case 'c': found = (found & 1) ? 16 : found | 1; break;
5932 case 'n': found = (found & 2) ? 16 : found | 2; break;
5933 case 'z': found = (found & 4) ? 16 : found | 4; break;
5934 case 'v': found = (found & 8) ? 16 : found | 8; break;
5935 default: found = 16;
5937 if (found != 15)
5938 goto failure;
5939 inst.operands[i].isvec = 1;
5941 else
5942 goto failure;
5943 break;
5945 case OP_TB:
5946 po_misc_or_fail (parse_tb (&str));
5947 break;
5949 /* Register lists */
5950 case OP_REGLST:
5951 val = parse_reg_list (&str);
5952 if (*str == '^')
5954 inst.operands[1].writeback = 1;
5955 str++;
5957 break;
5959 case OP_VRSLST:
5960 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5961 break;
5963 case OP_VRDLST:
5964 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5965 break;
5967 case OP_VRSDLST:
5968 /* Allow Q registers too. */
5969 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5970 REGLIST_NEON_D);
5971 if (val == FAIL)
5973 inst.error = NULL;
5974 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5975 REGLIST_VFP_S);
5976 inst.operands[i].issingle = 1;
5978 break;
5980 case OP_NRDLST:
5981 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5982 REGLIST_NEON_D);
5983 break;
5985 case OP_NSTRLST:
5986 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5987 &inst.operands[i].vectype);
5988 break;
5990 /* Addressing modes */
5991 case OP_ADDR:
5992 po_misc_or_fail (parse_address (&str, i));
5993 break;
5995 case OP_ADDRGLDR:
5996 po_misc_or_fail_no_backtrack (
5997 parse_address_group_reloc (&str, i, GROUP_LDR));
5998 break;
6000 case OP_ADDRGLDRS:
6001 po_misc_or_fail_no_backtrack (
6002 parse_address_group_reloc (&str, i, GROUP_LDRS));
6003 break;
6005 case OP_ADDRGLDC:
6006 po_misc_or_fail_no_backtrack (
6007 parse_address_group_reloc (&str, i, GROUP_LDC));
6008 break;
6010 case OP_SH:
6011 po_misc_or_fail (parse_shifter_operand (&str, i));
6012 break;
6014 case OP_SHG:
6015 po_misc_or_fail_no_backtrack (
6016 parse_shifter_operand_group_reloc (&str, i));
6017 break;
6019 case OP_oSHll:
6020 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6021 break;
6023 case OP_oSHar:
6024 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6025 break;
6027 case OP_oSHllar:
6028 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6029 break;
6031 default:
6032 as_fatal (_("unhandled operand code %d"), upat[i]);
6035 /* Various value-based sanity checks and shared operations. We
6036 do not signal immediate failures for the register constraints;
6037 this allows a syntax error to take precedence. */
6038 switch (upat[i])
6040 case OP_oRRnpc:
6041 case OP_RRnpc:
6042 case OP_RRnpcb:
6043 case OP_RRw:
6044 case OP_oRRw:
6045 case OP_RRnpc_I0:
6046 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6047 inst.error = BAD_PC;
6048 break;
6050 case OP_CPSF:
6051 case OP_ENDI:
6052 case OP_oROR:
6053 case OP_PSR:
6054 case OP_RVC_PSR:
6055 case OP_COND:
6056 case OP_oBARRIER:
6057 case OP_REGLST:
6058 case OP_VRSLST:
6059 case OP_VRDLST:
6060 case OP_VRSDLST:
6061 case OP_NRDLST:
6062 case OP_NSTRLST:
6063 if (val == FAIL)
6064 goto failure;
6065 inst.operands[i].imm = val;
6066 break;
6068 default:
6069 break;
6072 /* If we get here, this operand was successfully parsed. */
6073 inst.operands[i].present = 1;
6074 continue;
6076 bad_args:
6077 inst.error = BAD_ARGS;
6079 failure:
6080 if (!backtrack_pos)
6082 /* The parse routine should already have set inst.error, but set a
6083 default here just in case. */
6084 if (!inst.error)
6085 inst.error = _("syntax error");
6086 return FAIL;
6089 /* Do not backtrack over a trailing optional argument that
6090 absorbed some text. We will only fail again, with the
6091 'garbage following instruction' error message, which is
6092 probably less helpful than the current one. */
6093 if (backtrack_index == i && backtrack_pos != str
6094 && upat[i+1] == OP_stop)
6096 if (!inst.error)
6097 inst.error = _("syntax error");
6098 return FAIL;
6101 /* Try again, skipping the optional argument at backtrack_pos. */
6102 str = backtrack_pos;
6103 inst.error = backtrack_error;
6104 inst.operands[backtrack_index].present = 0;
6105 i = backtrack_index;
6106 backtrack_pos = 0;
6109 /* Check that we have parsed all the arguments. */
6110 if (*str != '\0' && !inst.error)
6111 inst.error = _("garbage following instruction");
6113 return inst.error ? FAIL : SUCCESS;
6116 #undef po_char_or_fail
6117 #undef po_reg_or_fail
6118 #undef po_reg_or_goto
6119 #undef po_imm_or_fail
6120 #undef po_scalar_or_fail
6122 /* Shorthand macro for instruction encoding functions issuing errors. */
6123 #define constraint(expr, err) do { \
6124 if (expr) \
6126 inst.error = err; \
6127 return; \
6129 } while (0)
6131 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6132 instructions are unpredictable if these registers are used. This
6133 is the BadReg predicate in ARM's Thumb-2 documentation. */
6134 #define reject_bad_reg(reg) \
6135 do \
6136 if (reg == REG_SP || reg == REG_PC) \
6138 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6139 return; \
6141 while (0)
6143 /* If REG is R13 (the stack pointer), warn that its use is
6144 deprecated. */
6145 #define warn_deprecated_sp(reg) \
6146 do \
6147 if (warn_on_deprecated && reg == REG_SP) \
6148 as_warn (_("use of r13 is deprecated")); \
6149 while (0)
6151 /* Functions for operand encoding. ARM, then Thumb. */
6153 #define rotate_left(v, n) (v << n | v >> (32 - n))
6155 /* If VAL can be encoded in the immediate field of an ARM instruction,
6156 return the encoded form. Otherwise, return FAIL. */
6158 static unsigned int
6159 encode_arm_immediate (unsigned int val)
6161 unsigned int a, i;
6163 for (i = 0; i < 32; i += 2)
6164 if ((a = rotate_left (val, i)) <= 0xff)
6165 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6167 return FAIL;
6170 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6171 return the encoded form. Otherwise, return FAIL. */
6172 static unsigned int
6173 encode_thumb32_immediate (unsigned int val)
6175 unsigned int a, i;
6177 if (val <= 0xff)
6178 return val;
6180 for (i = 1; i <= 24; i++)
6182 a = val >> i;
6183 if ((val & ~(0xff << i)) == 0)
6184 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6187 a = val & 0xff;
6188 if (val == ((a << 16) | a))
6189 return 0x100 | a;
6190 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6191 return 0x300 | a;
6193 a = val & 0xff00;
6194 if (val == ((a << 16) | a))
6195 return 0x200 | (a >> 8);
6197 return FAIL;
6199 /* Encode a VFP SP or DP register number into inst.instruction. */
6201 static void
6202 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6204 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6205 && reg > 15)
6207 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6209 if (thumb_mode)
6210 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6211 fpu_vfp_ext_d32);
6212 else
6213 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6214 fpu_vfp_ext_d32);
6216 else
6218 first_error (_("D register out of range for selected VFP version"));
6219 return;
6223 switch (pos)
6225 case VFP_REG_Sd:
6226 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6227 break;
6229 case VFP_REG_Sn:
6230 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6231 break;
6233 case VFP_REG_Sm:
6234 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6235 break;
6237 case VFP_REG_Dd:
6238 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6239 break;
6241 case VFP_REG_Dn:
6242 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6243 break;
6245 case VFP_REG_Dm:
6246 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6247 break;
6249 default:
6250 abort ();
6254 /* Encode a <shift> in an ARM-format instruction. The immediate,
6255 if any, is handled by md_apply_fix. */
6256 static void
6257 encode_arm_shift (int i)
6259 if (inst.operands[i].shift_kind == SHIFT_RRX)
6260 inst.instruction |= SHIFT_ROR << 5;
6261 else
6263 inst.instruction |= inst.operands[i].shift_kind << 5;
6264 if (inst.operands[i].immisreg)
6266 inst.instruction |= SHIFT_BY_REG;
6267 inst.instruction |= inst.operands[i].imm << 8;
6269 else
6270 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6274 static void
6275 encode_arm_shifter_operand (int i)
6277 if (inst.operands[i].isreg)
6279 inst.instruction |= inst.operands[i].reg;
6280 encode_arm_shift (i);
6282 else
6283 inst.instruction |= INST_IMMEDIATE;
6286 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6287 static void
6288 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6290 assert (inst.operands[i].isreg);
6291 inst.instruction |= inst.operands[i].reg << 16;
6293 if (inst.operands[i].preind)
6295 if (is_t)
6297 inst.error = _("instruction does not accept preindexed addressing");
6298 return;
6300 inst.instruction |= PRE_INDEX;
6301 if (inst.operands[i].writeback)
6302 inst.instruction |= WRITE_BACK;
6305 else if (inst.operands[i].postind)
6307 assert (inst.operands[i].writeback);
6308 if (is_t)
6309 inst.instruction |= WRITE_BACK;
6311 else /* unindexed - only for coprocessor */
6313 inst.error = _("instruction does not accept unindexed addressing");
6314 return;
6317 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6318 && (((inst.instruction & 0x000f0000) >> 16)
6319 == ((inst.instruction & 0x0000f000) >> 12)))
6320 as_warn ((inst.instruction & LOAD_BIT)
6321 ? _("destination register same as write-back base")
6322 : _("source register same as write-back base"));
6325 /* inst.operands[i] was set up by parse_address. Encode it into an
6326 ARM-format mode 2 load or store instruction. If is_t is true,
6327 reject forms that cannot be used with a T instruction (i.e. not
6328 post-indexed). */
6329 static void
6330 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6332 encode_arm_addr_mode_common (i, is_t);
6334 if (inst.operands[i].immisreg)
6336 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6337 inst.instruction |= inst.operands[i].imm;
6338 if (!inst.operands[i].negative)
6339 inst.instruction |= INDEX_UP;
6340 if (inst.operands[i].shifted)
6342 if (inst.operands[i].shift_kind == SHIFT_RRX)
6343 inst.instruction |= SHIFT_ROR << 5;
6344 else
6346 inst.instruction |= inst.operands[i].shift_kind << 5;
6347 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6351 else /* immediate offset in inst.reloc */
6353 if (inst.reloc.type == BFD_RELOC_UNUSED)
6354 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6358 /* inst.operands[i] was set up by parse_address. Encode it into an
6359 ARM-format mode 3 load or store instruction. Reject forms that
6360 cannot be used with such instructions. If is_t is true, reject
6361 forms that cannot be used with a T instruction (i.e. not
6362 post-indexed). */
6363 static void
6364 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6366 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6368 inst.error = _("instruction does not accept scaled register index");
6369 return;
6372 encode_arm_addr_mode_common (i, is_t);
6374 if (inst.operands[i].immisreg)
6376 inst.instruction |= inst.operands[i].imm;
6377 if (!inst.operands[i].negative)
6378 inst.instruction |= INDEX_UP;
6380 else /* immediate offset in inst.reloc */
6382 inst.instruction |= HWOFFSET_IMM;
6383 if (inst.reloc.type == BFD_RELOC_UNUSED)
6384 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6388 /* inst.operands[i] was set up by parse_address. Encode it into an
6389 ARM-format instruction. Reject all forms which cannot be encoded
6390 into a coprocessor load/store instruction. If wb_ok is false,
6391 reject use of writeback; if unind_ok is false, reject use of
6392 unindexed addressing. If reloc_override is not 0, use it instead
6393 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6394 (in which case it is preserved). */
6396 static int
6397 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6399 inst.instruction |= inst.operands[i].reg << 16;
6401 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6403 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6405 assert (!inst.operands[i].writeback);
6406 if (!unind_ok)
6408 inst.error = _("instruction does not support unindexed addressing");
6409 return FAIL;
6411 inst.instruction |= inst.operands[i].imm;
6412 inst.instruction |= INDEX_UP;
6413 return SUCCESS;
6416 if (inst.operands[i].preind)
6417 inst.instruction |= PRE_INDEX;
6419 if (inst.operands[i].writeback)
6421 if (inst.operands[i].reg == REG_PC)
6423 inst.error = _("pc may not be used with write-back");
6424 return FAIL;
6426 if (!wb_ok)
6428 inst.error = _("instruction does not support writeback");
6429 return FAIL;
6431 inst.instruction |= WRITE_BACK;
6434 if (reloc_override)
6435 inst.reloc.type = reloc_override;
6436 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6437 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6438 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6440 if (thumb_mode)
6441 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6442 else
6443 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6446 return SUCCESS;
6449 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6450 Determine whether it can be performed with a move instruction; if
6451 it can, convert inst.instruction to that move instruction and
6452 return 1; if it can't, convert inst.instruction to a literal-pool
6453 load and return 0. If this is not a valid thing to do in the
6454 current context, set inst.error and return 1.
6456 inst.operands[i] describes the destination register. */
6458 static int
6459 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6461 unsigned long tbit;
6463 if (thumb_p)
6464 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6465 else
6466 tbit = LOAD_BIT;
6468 if ((inst.instruction & tbit) == 0)
6470 inst.error = _("invalid pseudo operation");
6471 return 1;
6473 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6475 inst.error = _("constant expression expected");
6476 return 1;
6478 if (inst.reloc.exp.X_op == O_constant)
6480 if (thumb_p)
6482 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6484 /* This can be done with a mov(1) instruction. */
6485 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6486 inst.instruction |= inst.reloc.exp.X_add_number;
6487 return 1;
6490 else
6492 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6493 if (value != FAIL)
6495 /* This can be done with a mov instruction. */
6496 inst.instruction &= LITERAL_MASK;
6497 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6498 inst.instruction |= value & 0xfff;
6499 return 1;
6502 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6503 if (value != FAIL)
6505 /* This can be done with a mvn instruction. */
6506 inst.instruction &= LITERAL_MASK;
6507 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6508 inst.instruction |= value & 0xfff;
6509 return 1;
6514 if (add_to_lit_pool () == FAIL)
6516 inst.error = _("literal pool insertion failed");
6517 return 1;
6519 inst.operands[1].reg = REG_PC;
6520 inst.operands[1].isreg = 1;
6521 inst.operands[1].preind = 1;
6522 inst.reloc.pc_rel = 1;
6523 inst.reloc.type = (thumb_p
6524 ? BFD_RELOC_ARM_THUMB_OFFSET
6525 : (mode_3
6526 ? BFD_RELOC_ARM_HWLITERAL
6527 : BFD_RELOC_ARM_LITERAL));
6528 return 0;
6531 /* Functions for instruction encoding, sorted by sub-architecture.
6532 First some generics; their names are taken from the conventional
6533 bit positions for register arguments in ARM format instructions. */
6535 static void
6536 do_noargs (void)
6540 static void
6541 do_rd (void)
6543 inst.instruction |= inst.operands[0].reg << 12;
6546 static void
6547 do_rd_rm (void)
6549 inst.instruction |= inst.operands[0].reg << 12;
6550 inst.instruction |= inst.operands[1].reg;
6553 static void
6554 do_rd_rn (void)
6556 inst.instruction |= inst.operands[0].reg << 12;
6557 inst.instruction |= inst.operands[1].reg << 16;
6560 static void
6561 do_rn_rd (void)
6563 inst.instruction |= inst.operands[0].reg << 16;
6564 inst.instruction |= inst.operands[1].reg << 12;
6567 static void
6568 do_rd_rm_rn (void)
6570 unsigned Rn = inst.operands[2].reg;
6571 /* Enforce restrictions on SWP instruction. */
6572 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6573 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6574 _("Rn must not overlap other operands"));
6575 inst.instruction |= inst.operands[0].reg << 12;
6576 inst.instruction |= inst.operands[1].reg;
6577 inst.instruction |= Rn << 16;
6580 static void
6581 do_rd_rn_rm (void)
6583 inst.instruction |= inst.operands[0].reg << 12;
6584 inst.instruction |= inst.operands[1].reg << 16;
6585 inst.instruction |= inst.operands[2].reg;
6588 static void
6589 do_rm_rd_rn (void)
6591 inst.instruction |= inst.operands[0].reg;
6592 inst.instruction |= inst.operands[1].reg << 12;
6593 inst.instruction |= inst.operands[2].reg << 16;
6596 static void
6597 do_imm0 (void)
6599 inst.instruction |= inst.operands[0].imm;
6602 static void
6603 do_rd_cpaddr (void)
6605 inst.instruction |= inst.operands[0].reg << 12;
6606 encode_arm_cp_address (1, TRUE, TRUE, 0);
6609 /* ARM instructions, in alphabetical order by function name (except
6610 that wrapper functions appear immediately after the function they
6611 wrap). */
6613 /* This is a pseudo-op of the form "adr rd, label" to be converted
6614 into a relative address of the form "add rd, pc, #label-.-8". */
6616 static void
6617 do_adr (void)
6619 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6621 /* Frag hacking will turn this into a sub instruction if the offset turns
6622 out to be negative. */
6623 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6624 inst.reloc.pc_rel = 1;
6625 inst.reloc.exp.X_add_number -= 8;
6628 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6629 into a relative address of the form:
6630 add rd, pc, #low(label-.-8)"
6631 add rd, rd, #high(label-.-8)" */
6633 static void
6634 do_adrl (void)
6636 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6638 /* Frag hacking will turn this into a sub instruction if the offset turns
6639 out to be negative. */
6640 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6641 inst.reloc.pc_rel = 1;
6642 inst.size = INSN_SIZE * 2;
6643 inst.reloc.exp.X_add_number -= 8;
6646 static void
6647 do_arit (void)
6649 if (!inst.operands[1].present)
6650 inst.operands[1].reg = inst.operands[0].reg;
6651 inst.instruction |= inst.operands[0].reg << 12;
6652 inst.instruction |= inst.operands[1].reg << 16;
6653 encode_arm_shifter_operand (2);
6656 static void
6657 do_barrier (void)
6659 if (inst.operands[0].present)
6661 constraint ((inst.instruction & 0xf0) != 0x40
6662 && inst.operands[0].imm != 0xf,
6663 _("bad barrier type"));
6664 inst.instruction |= inst.operands[0].imm;
6666 else
6667 inst.instruction |= 0xf;
6670 static void
6671 do_bfc (void)
6673 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6674 constraint (msb > 32, _("bit-field extends past end of register"));
6675 /* The instruction encoding stores the LSB and MSB,
6676 not the LSB and width. */
6677 inst.instruction |= inst.operands[0].reg << 12;
6678 inst.instruction |= inst.operands[1].imm << 7;
6679 inst.instruction |= (msb - 1) << 16;
6682 static void
6683 do_bfi (void)
6685 unsigned int msb;
6687 /* #0 in second position is alternative syntax for bfc, which is
6688 the same instruction but with REG_PC in the Rm field. */
6689 if (!inst.operands[1].isreg)
6690 inst.operands[1].reg = REG_PC;
6692 msb = inst.operands[2].imm + inst.operands[3].imm;
6693 constraint (msb > 32, _("bit-field extends past end of register"));
6694 /* The instruction encoding stores the LSB and MSB,
6695 not the LSB and width. */
6696 inst.instruction |= inst.operands[0].reg << 12;
6697 inst.instruction |= inst.operands[1].reg;
6698 inst.instruction |= inst.operands[2].imm << 7;
6699 inst.instruction |= (msb - 1) << 16;
6702 static void
6703 do_bfx (void)
6705 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6706 _("bit-field extends past end of register"));
6707 inst.instruction |= inst.operands[0].reg << 12;
6708 inst.instruction |= inst.operands[1].reg;
6709 inst.instruction |= inst.operands[2].imm << 7;
6710 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6713 /* ARM V5 breakpoint instruction (argument parse)
6714 BKPT <16 bit unsigned immediate>
6715 Instruction is not conditional.
6716 The bit pattern given in insns[] has the COND_ALWAYS condition,
6717 and it is an error if the caller tried to override that. */
6719 static void
6720 do_bkpt (void)
6722 /* Top 12 of 16 bits to bits 19:8. */
6723 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6725 /* Bottom 4 of 16 bits to bits 3:0. */
6726 inst.instruction |= inst.operands[0].imm & 0xf;
6729 static void
6730 encode_branch (int default_reloc)
6732 if (inst.operands[0].hasreloc)
6734 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6735 _("the only suffix valid here is '(plt)'"));
6736 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6738 else
6740 inst.reloc.type = default_reloc;
6742 inst.reloc.pc_rel = 1;
6745 static void
6746 do_branch (void)
6748 #ifdef OBJ_ELF
6749 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6750 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6751 else
6752 #endif
6753 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6756 static void
6757 do_bl (void)
6759 #ifdef OBJ_ELF
6760 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6762 if (inst.cond == COND_ALWAYS)
6763 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6764 else
6765 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6767 else
6768 #endif
6769 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6772 /* ARM V5 branch-link-exchange instruction (argument parse)
6773 BLX <target_addr> ie BLX(1)
6774 BLX{<condition>} <Rm> ie BLX(2)
6775 Unfortunately, there are two different opcodes for this mnemonic.
6776 So, the insns[].value is not used, and the code here zaps values
6777 into inst.instruction.
6778 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6780 static void
6781 do_blx (void)
6783 if (inst.operands[0].isreg)
6785 /* Arg is a register; the opcode provided by insns[] is correct.
6786 It is not illegal to do "blx pc", just useless. */
6787 if (inst.operands[0].reg == REG_PC)
6788 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6790 inst.instruction |= inst.operands[0].reg;
6792 else
6794 /* Arg is an address; this instruction cannot be executed
6795 conditionally, and the opcode must be adjusted. */
6796 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6797 inst.instruction = 0xfa000000;
6798 #ifdef OBJ_ELF
6799 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6800 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6801 else
6802 #endif
6803 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6807 static void
6808 do_bx (void)
6810 bfd_boolean want_reloc;
6812 if (inst.operands[0].reg == REG_PC)
6813 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6815 inst.instruction |= inst.operands[0].reg;
6816 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6817 it is for ARMv4t or earlier. */
6818 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6819 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6820 want_reloc = TRUE;
6822 #ifdef OBJ_ELF
6823 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
6824 #endif
6825 want_reloc = FALSE;
6827 if (want_reloc)
6828 inst.reloc.type = BFD_RELOC_ARM_V4BX;
6832 /* ARM v5TEJ. Jump to Jazelle code. */
6834 static void
6835 do_bxj (void)
6837 if (inst.operands[0].reg == REG_PC)
6838 as_tsktsk (_("use of r15 in bxj is not really useful"));
6840 inst.instruction |= inst.operands[0].reg;
6843 /* Co-processor data operation:
6844 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6845 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6846 static void
6847 do_cdp (void)
6849 inst.instruction |= inst.operands[0].reg << 8;
6850 inst.instruction |= inst.operands[1].imm << 20;
6851 inst.instruction |= inst.operands[2].reg << 12;
6852 inst.instruction |= inst.operands[3].reg << 16;
6853 inst.instruction |= inst.operands[4].reg;
6854 inst.instruction |= inst.operands[5].imm << 5;
6857 static void
6858 do_cmp (void)
6860 inst.instruction |= inst.operands[0].reg << 16;
6861 encode_arm_shifter_operand (1);
6864 /* Transfer between coprocessor and ARM registers.
6865 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6866 MRC2
6867 MCR{cond}
6868 MCR2
6870 No special properties. */
6872 static void
6873 do_co_reg (void)
6875 unsigned Rd;
6877 Rd = inst.operands[2].reg;
6878 if (thumb_mode)
6880 if (inst.instruction == 0xee000010
6881 || inst.instruction == 0xfe000010)
6882 /* MCR, MCR2 */
6883 reject_bad_reg (Rd);
6884 else
6885 /* MRC, MRC2 */
6886 constraint (Rd == REG_SP, BAD_SP);
6888 else
6890 /* MCR */
6891 if (inst.instruction == 0xe000010)
6892 constraint (Rd == REG_PC, BAD_PC);
6896 inst.instruction |= inst.operands[0].reg << 8;
6897 inst.instruction |= inst.operands[1].imm << 21;
6898 inst.instruction |= Rd << 12;
6899 inst.instruction |= inst.operands[3].reg << 16;
6900 inst.instruction |= inst.operands[4].reg;
6901 inst.instruction |= inst.operands[5].imm << 5;
6904 /* Transfer between coprocessor register and pair of ARM registers.
6905 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6906 MCRR2
6907 MRRC{cond}
6908 MRRC2
6910 Two XScale instructions are special cases of these:
6912 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6913 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6915 Result unpredictable if Rd or Rn is R15. */
6917 static void
6918 do_co_reg2c (void)
6920 unsigned Rd, Rn;
6922 Rd = inst.operands[2].reg;
6923 Rn = inst.operands[3].reg;
6925 if (thumb_mode)
6927 reject_bad_reg (Rd);
6928 reject_bad_reg (Rn);
6930 else
6932 constraint (Rd == REG_PC, BAD_PC);
6933 constraint (Rn == REG_PC, BAD_PC);
6936 inst.instruction |= inst.operands[0].reg << 8;
6937 inst.instruction |= inst.operands[1].imm << 4;
6938 inst.instruction |= Rd << 12;
6939 inst.instruction |= Rn << 16;
6940 inst.instruction |= inst.operands[4].reg;
6943 static void
6944 do_cpsi (void)
6946 inst.instruction |= inst.operands[0].imm << 6;
6947 if (inst.operands[1].present)
6949 inst.instruction |= CPSI_MMOD;
6950 inst.instruction |= inst.operands[1].imm;
6954 static void
6955 do_dbg (void)
6957 inst.instruction |= inst.operands[0].imm;
6960 static void
6961 do_it (void)
6963 /* There is no IT instruction in ARM mode. We
6964 process it but do not generate code for it. */
6965 inst.size = 0;
6968 static void
6969 do_ldmstm (void)
6971 int base_reg = inst.operands[0].reg;
6972 int range = inst.operands[1].imm;
6974 inst.instruction |= base_reg << 16;
6975 inst.instruction |= range;
6977 if (inst.operands[1].writeback)
6978 inst.instruction |= LDM_TYPE_2_OR_3;
6980 if (inst.operands[0].writeback)
6982 inst.instruction |= WRITE_BACK;
6983 /* Check for unpredictable uses of writeback. */
6984 if (inst.instruction & LOAD_BIT)
6986 /* Not allowed in LDM type 2. */
6987 if ((inst.instruction & LDM_TYPE_2_OR_3)
6988 && ((range & (1 << REG_PC)) == 0))
6989 as_warn (_("writeback of base register is UNPREDICTABLE"));
6990 /* Only allowed if base reg not in list for other types. */
6991 else if (range & (1 << base_reg))
6992 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6994 else /* STM. */
6996 /* Not allowed for type 2. */
6997 if (inst.instruction & LDM_TYPE_2_OR_3)
6998 as_warn (_("writeback of base register is UNPREDICTABLE"));
6999 /* Only allowed if base reg not in list, or first in list. */
7000 else if ((range & (1 << base_reg))
7001 && (range & ((1 << base_reg) - 1)))
7002 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7007 /* ARMv5TE load-consecutive (argument parse)
7008 Mode is like LDRH.
7010 LDRccD R, mode
7011 STRccD R, mode. */
7013 static void
7014 do_ldrd (void)
7016 constraint (inst.operands[0].reg % 2 != 0,
7017 _("first destination register must be even"));
7018 constraint (inst.operands[1].present
7019 && inst.operands[1].reg != inst.operands[0].reg + 1,
7020 _("can only load two consecutive registers"));
7021 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7022 constraint (!inst.operands[2].isreg, _("'[' expected"));
7024 if (!inst.operands[1].present)
7025 inst.operands[1].reg = inst.operands[0].reg + 1;
7027 if (inst.instruction & LOAD_BIT)
7029 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7030 register and the first register written; we have to diagnose
7031 overlap between the base and the second register written here. */
7033 if (inst.operands[2].reg == inst.operands[1].reg
7034 && (inst.operands[2].writeback || inst.operands[2].postind))
7035 as_warn (_("base register written back, and overlaps "
7036 "second destination register"));
7038 /* For an index-register load, the index register must not overlap the
7039 destination (even if not write-back). */
7040 else if (inst.operands[2].immisreg
7041 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7042 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7043 as_warn (_("index register overlaps destination register"));
7046 inst.instruction |= inst.operands[0].reg << 12;
7047 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
7050 static void
7051 do_ldrex (void)
7053 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7054 || inst.operands[1].postind || inst.operands[1].writeback
7055 || inst.operands[1].immisreg || inst.operands[1].shifted
7056 || inst.operands[1].negative
7057 /* This can arise if the programmer has written
7058 strex rN, rM, foo
7059 or if they have mistakenly used a register name as the last
7060 operand, eg:
7061 strex rN, rM, rX
7062 It is very difficult to distinguish between these two cases
7063 because "rX" might actually be a label. ie the register
7064 name has been occluded by a symbol of the same name. So we
7065 just generate a general 'bad addressing mode' type error
7066 message and leave it up to the programmer to discover the
7067 true cause and fix their mistake. */
7068 || (inst.operands[1].reg == REG_PC),
7069 BAD_ADDR_MODE);
7071 constraint (inst.reloc.exp.X_op != O_constant
7072 || inst.reloc.exp.X_add_number != 0,
7073 _("offset must be zero in ARM encoding"));
7075 inst.instruction |= inst.operands[0].reg << 12;
7076 inst.instruction |= inst.operands[1].reg << 16;
7077 inst.reloc.type = BFD_RELOC_UNUSED;
7080 static void
7081 do_ldrexd (void)
7083 constraint (inst.operands[0].reg % 2 != 0,
7084 _("even register required"));
7085 constraint (inst.operands[1].present
7086 && inst.operands[1].reg != inst.operands[0].reg + 1,
7087 _("can only load two consecutive registers"));
7088 /* If op 1 were present and equal to PC, this function wouldn't
7089 have been called in the first place. */
7090 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7092 inst.instruction |= inst.operands[0].reg << 12;
7093 inst.instruction |= inst.operands[2].reg << 16;
7096 static void
7097 do_ldst (void)
7099 inst.instruction |= inst.operands[0].reg << 12;
7100 if (!inst.operands[1].isreg)
7101 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7102 return;
7103 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7106 static void
7107 do_ldstt (void)
7109 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7110 reject [Rn,...]. */
7111 if (inst.operands[1].preind)
7113 constraint (inst.reloc.exp.X_op != O_constant
7114 || inst.reloc.exp.X_add_number != 0,
7115 _("this instruction requires a post-indexed address"));
7117 inst.operands[1].preind = 0;
7118 inst.operands[1].postind = 1;
7119 inst.operands[1].writeback = 1;
7121 inst.instruction |= inst.operands[0].reg << 12;
7122 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7125 /* Halfword and signed-byte load/store operations. */
7127 static void
7128 do_ldstv4 (void)
7130 inst.instruction |= inst.operands[0].reg << 12;
7131 if (!inst.operands[1].isreg)
7132 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7133 return;
7134 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7137 static void
7138 do_ldsttv4 (void)
7140 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7141 reject [Rn,...]. */
7142 if (inst.operands[1].preind)
7144 constraint (inst.reloc.exp.X_op != O_constant
7145 || inst.reloc.exp.X_add_number != 0,
7146 _("this instruction requires a post-indexed address"));
7148 inst.operands[1].preind = 0;
7149 inst.operands[1].postind = 1;
7150 inst.operands[1].writeback = 1;
7152 inst.instruction |= inst.operands[0].reg << 12;
7153 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7156 /* Co-processor register load/store.
7157 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7158 static void
7159 do_lstc (void)
7161 inst.instruction |= inst.operands[0].reg << 8;
7162 inst.instruction |= inst.operands[1].reg << 12;
7163 encode_arm_cp_address (2, TRUE, TRUE, 0);
7166 static void
7167 do_mlas (void)
7169 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7170 if (inst.operands[0].reg == inst.operands[1].reg
7171 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7172 && !(inst.instruction & 0x00400000))
7173 as_tsktsk (_("Rd and Rm should be different in mla"));
7175 inst.instruction |= inst.operands[0].reg << 16;
7176 inst.instruction |= inst.operands[1].reg;
7177 inst.instruction |= inst.operands[2].reg << 8;
7178 inst.instruction |= inst.operands[3].reg << 12;
7181 static void
7182 do_mov (void)
7184 inst.instruction |= inst.operands[0].reg << 12;
7185 encode_arm_shifter_operand (1);
7188 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7189 static void
7190 do_mov16 (void)
7192 bfd_vma imm;
7193 bfd_boolean top;
7195 top = (inst.instruction & 0x00400000) != 0;
7196 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7197 _(":lower16: not allowed this instruction"));
7198 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7199 _(":upper16: not allowed instruction"));
7200 inst.instruction |= inst.operands[0].reg << 12;
7201 if (inst.reloc.type == BFD_RELOC_UNUSED)
7203 imm = inst.reloc.exp.X_add_number;
7204 /* The value is in two pieces: 0:11, 16:19. */
7205 inst.instruction |= (imm & 0x00000fff);
7206 inst.instruction |= (imm & 0x0000f000) << 4;
7210 static void do_vfp_nsyn_opcode (const char *);
7212 static int
7213 do_vfp_nsyn_mrs (void)
7215 if (inst.operands[0].isvec)
7217 if (inst.operands[1].reg != 1)
7218 first_error (_("operand 1 must be FPSCR"));
7219 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7220 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7221 do_vfp_nsyn_opcode ("fmstat");
7223 else if (inst.operands[1].isvec)
7224 do_vfp_nsyn_opcode ("fmrx");
7225 else
7226 return FAIL;
7228 return SUCCESS;
7231 static int
7232 do_vfp_nsyn_msr (void)
7234 if (inst.operands[0].isvec)
7235 do_vfp_nsyn_opcode ("fmxr");
7236 else
7237 return FAIL;
7239 return SUCCESS;
7242 static void
7243 do_mrs (void)
7245 if (do_vfp_nsyn_mrs () == SUCCESS)
7246 return;
7248 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7249 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7250 != (PSR_c|PSR_f),
7251 _("'CPSR' or 'SPSR' expected"));
7252 inst.instruction |= inst.operands[0].reg << 12;
7253 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7256 /* Two possible forms:
7257 "{C|S}PSR_<field>, Rm",
7258 "{C|S}PSR_f, #expression". */
7260 static void
7261 do_msr (void)
7263 if (do_vfp_nsyn_msr () == SUCCESS)
7264 return;
7266 inst.instruction |= inst.operands[0].imm;
7267 if (inst.operands[1].isreg)
7268 inst.instruction |= inst.operands[1].reg;
7269 else
7271 inst.instruction |= INST_IMMEDIATE;
7272 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7273 inst.reloc.pc_rel = 0;
7277 static void
7278 do_mul (void)
7280 if (!inst.operands[2].present)
7281 inst.operands[2].reg = inst.operands[0].reg;
7282 inst.instruction |= inst.operands[0].reg << 16;
7283 inst.instruction |= inst.operands[1].reg;
7284 inst.instruction |= inst.operands[2].reg << 8;
7286 if (inst.operands[0].reg == inst.operands[1].reg
7287 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7288 as_tsktsk (_("Rd and Rm should be different in mul"));
7291 /* Long Multiply Parser
7292 UMULL RdLo, RdHi, Rm, Rs
7293 SMULL RdLo, RdHi, Rm, Rs
7294 UMLAL RdLo, RdHi, Rm, Rs
7295 SMLAL RdLo, RdHi, Rm, Rs. */
7297 static void
7298 do_mull (void)
7300 inst.instruction |= inst.operands[0].reg << 12;
7301 inst.instruction |= inst.operands[1].reg << 16;
7302 inst.instruction |= inst.operands[2].reg;
7303 inst.instruction |= inst.operands[3].reg << 8;
7305 /* rdhi and rdlo must be different. */
7306 if (inst.operands[0].reg == inst.operands[1].reg)
7307 as_tsktsk (_("rdhi and rdlo must be different"));
7309 /* rdhi, rdlo and rm must all be different before armv6. */
7310 if ((inst.operands[0].reg == inst.operands[2].reg
7311 || inst.operands[1].reg == inst.operands[2].reg)
7312 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7313 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7316 static void
7317 do_nop (void)
7319 if (inst.operands[0].present
7320 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
7322 /* Architectural NOP hints are CPSR sets with no bits selected. */
7323 inst.instruction &= 0xf0000000;
7324 inst.instruction |= 0x0320f000;
7325 if (inst.operands[0].present)
7326 inst.instruction |= inst.operands[0].imm;
7330 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7331 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7332 Condition defaults to COND_ALWAYS.
7333 Error if Rd, Rn or Rm are R15. */
7335 static void
7336 do_pkhbt (void)
7338 inst.instruction |= inst.operands[0].reg << 12;
7339 inst.instruction |= inst.operands[1].reg << 16;
7340 inst.instruction |= inst.operands[2].reg;
7341 if (inst.operands[3].present)
7342 encode_arm_shift (3);
7345 /* ARM V6 PKHTB (Argument Parse). */
7347 static void
7348 do_pkhtb (void)
7350 if (!inst.operands[3].present)
7352 /* If the shift specifier is omitted, turn the instruction
7353 into pkhbt rd, rm, rn. */
7354 inst.instruction &= 0xfff00010;
7355 inst.instruction |= inst.operands[0].reg << 12;
7356 inst.instruction |= inst.operands[1].reg;
7357 inst.instruction |= inst.operands[2].reg << 16;
7359 else
7361 inst.instruction |= inst.operands[0].reg << 12;
7362 inst.instruction |= inst.operands[1].reg << 16;
7363 inst.instruction |= inst.operands[2].reg;
7364 encode_arm_shift (3);
7368 /* ARMv5TE: Preload-Cache
7370 PLD <addr_mode>
7372 Syntactically, like LDR with B=1, W=0, L=1. */
7374 static void
7375 do_pld (void)
7377 constraint (!inst.operands[0].isreg,
7378 _("'[' expected after PLD mnemonic"));
7379 constraint (inst.operands[0].postind,
7380 _("post-indexed expression used in preload instruction"));
7381 constraint (inst.operands[0].writeback,
7382 _("writeback used in preload instruction"));
7383 constraint (!inst.operands[0].preind,
7384 _("unindexed addressing used in preload instruction"));
7385 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7388 /* ARMv7: PLI <addr_mode> */
7389 static void
7390 do_pli (void)
7392 constraint (!inst.operands[0].isreg,
7393 _("'[' expected after PLI mnemonic"));
7394 constraint (inst.operands[0].postind,
7395 _("post-indexed expression used in preload instruction"));
7396 constraint (inst.operands[0].writeback,
7397 _("writeback used in preload instruction"));
7398 constraint (!inst.operands[0].preind,
7399 _("unindexed addressing used in preload instruction"));
7400 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7401 inst.instruction &= ~PRE_INDEX;
7404 static void
7405 do_push_pop (void)
7407 inst.operands[1] = inst.operands[0];
7408 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7409 inst.operands[0].isreg = 1;
7410 inst.operands[0].writeback = 1;
7411 inst.operands[0].reg = REG_SP;
7412 do_ldmstm ();
7415 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7416 word at the specified address and the following word
7417 respectively.
7418 Unconditionally executed.
7419 Error if Rn is R15. */
7421 static void
7422 do_rfe (void)
7424 inst.instruction |= inst.operands[0].reg << 16;
7425 if (inst.operands[0].writeback)
7426 inst.instruction |= WRITE_BACK;
7429 /* ARM V6 ssat (argument parse). */
7431 static void
7432 do_ssat (void)
7434 inst.instruction |= inst.operands[0].reg << 12;
7435 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7436 inst.instruction |= inst.operands[2].reg;
7438 if (inst.operands[3].present)
7439 encode_arm_shift (3);
7442 /* ARM V6 usat (argument parse). */
7444 static void
7445 do_usat (void)
7447 inst.instruction |= inst.operands[0].reg << 12;
7448 inst.instruction |= inst.operands[1].imm << 16;
7449 inst.instruction |= inst.operands[2].reg;
7451 if (inst.operands[3].present)
7452 encode_arm_shift (3);
7455 /* ARM V6 ssat16 (argument parse). */
7457 static void
7458 do_ssat16 (void)
7460 inst.instruction |= inst.operands[0].reg << 12;
7461 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7462 inst.instruction |= inst.operands[2].reg;
7465 static void
7466 do_usat16 (void)
7468 inst.instruction |= inst.operands[0].reg << 12;
7469 inst.instruction |= inst.operands[1].imm << 16;
7470 inst.instruction |= inst.operands[2].reg;
7473 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7474 preserving the other bits.
7476 setend <endian_specifier>, where <endian_specifier> is either
7477 BE or LE. */
7479 static void
7480 do_setend (void)
7482 if (inst.operands[0].imm)
7483 inst.instruction |= 0x200;
7486 static void
7487 do_shift (void)
7489 unsigned int Rm = (inst.operands[1].present
7490 ? inst.operands[1].reg
7491 : inst.operands[0].reg);
7493 inst.instruction |= inst.operands[0].reg << 12;
7494 inst.instruction |= Rm;
7495 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7497 inst.instruction |= inst.operands[2].reg << 8;
7498 inst.instruction |= SHIFT_BY_REG;
7500 else
7501 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7504 static void
7505 do_smc (void)
7507 inst.reloc.type = BFD_RELOC_ARM_SMC;
7508 inst.reloc.pc_rel = 0;
7511 static void
7512 do_swi (void)
7514 inst.reloc.type = BFD_RELOC_ARM_SWI;
7515 inst.reloc.pc_rel = 0;
7518 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7519 SMLAxy{cond} Rd,Rm,Rs,Rn
7520 SMLAWy{cond} Rd,Rm,Rs,Rn
7521 Error if any register is R15. */
7523 static void
7524 do_smla (void)
7526 inst.instruction |= inst.operands[0].reg << 16;
7527 inst.instruction |= inst.operands[1].reg;
7528 inst.instruction |= inst.operands[2].reg << 8;
7529 inst.instruction |= inst.operands[3].reg << 12;
7532 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7533 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7534 Error if any register is R15.
7535 Warning if Rdlo == Rdhi. */
7537 static void
7538 do_smlal (void)
7540 inst.instruction |= inst.operands[0].reg << 12;
7541 inst.instruction |= inst.operands[1].reg << 16;
7542 inst.instruction |= inst.operands[2].reg;
7543 inst.instruction |= inst.operands[3].reg << 8;
7545 if (inst.operands[0].reg == inst.operands[1].reg)
7546 as_tsktsk (_("rdhi and rdlo must be different"));
7549 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7550 SMULxy{cond} Rd,Rm,Rs
7551 Error if any register is R15. */
7553 static void
7554 do_smul (void)
7556 inst.instruction |= inst.operands[0].reg << 16;
7557 inst.instruction |= inst.operands[1].reg;
7558 inst.instruction |= inst.operands[2].reg << 8;
7561 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7562 the same for both ARM and Thumb-2. */
7564 static void
7565 do_srs (void)
7567 int reg;
7569 if (inst.operands[0].present)
7571 reg = inst.operands[0].reg;
7572 constraint (reg != REG_SP, _("SRS base register must be r13"));
7574 else
7575 reg = REG_SP;
7577 inst.instruction |= reg << 16;
7578 inst.instruction |= inst.operands[1].imm;
7579 if (inst.operands[0].writeback || inst.operands[1].writeback)
7580 inst.instruction |= WRITE_BACK;
7583 /* ARM V6 strex (argument parse). */
7585 static void
7586 do_strex (void)
7588 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7589 || inst.operands[2].postind || inst.operands[2].writeback
7590 || inst.operands[2].immisreg || inst.operands[2].shifted
7591 || inst.operands[2].negative
7592 /* See comment in do_ldrex(). */
7593 || (inst.operands[2].reg == REG_PC),
7594 BAD_ADDR_MODE);
7596 constraint (inst.operands[0].reg == inst.operands[1].reg
7597 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7599 constraint (inst.reloc.exp.X_op != O_constant
7600 || inst.reloc.exp.X_add_number != 0,
7601 _("offset must be zero in ARM encoding"));
7603 inst.instruction |= inst.operands[0].reg << 12;
7604 inst.instruction |= inst.operands[1].reg;
7605 inst.instruction |= inst.operands[2].reg << 16;
7606 inst.reloc.type = BFD_RELOC_UNUSED;
7609 static void
7610 do_strexd (void)
7612 constraint (inst.operands[1].reg % 2 != 0,
7613 _("even register required"));
7614 constraint (inst.operands[2].present
7615 && inst.operands[2].reg != inst.operands[1].reg + 1,
7616 _("can only store two consecutive registers"));
7617 /* If op 2 were present and equal to PC, this function wouldn't
7618 have been called in the first place. */
7619 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7621 constraint (inst.operands[0].reg == inst.operands[1].reg
7622 || inst.operands[0].reg == inst.operands[1].reg + 1
7623 || inst.operands[0].reg == inst.operands[3].reg,
7624 BAD_OVERLAP);
7626 inst.instruction |= inst.operands[0].reg << 12;
7627 inst.instruction |= inst.operands[1].reg;
7628 inst.instruction |= inst.operands[3].reg << 16;
7631 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7632 extends it to 32-bits, and adds the result to a value in another
7633 register. You can specify a rotation by 0, 8, 16, or 24 bits
7634 before extracting the 16-bit value.
7635 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7636 Condition defaults to COND_ALWAYS.
7637 Error if any register uses R15. */
7639 static void
7640 do_sxtah (void)
7642 inst.instruction |= inst.operands[0].reg << 12;
7643 inst.instruction |= inst.operands[1].reg << 16;
7644 inst.instruction |= inst.operands[2].reg;
7645 inst.instruction |= inst.operands[3].imm << 10;
7648 /* ARM V6 SXTH.
7650 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7651 Condition defaults to COND_ALWAYS.
7652 Error if any register uses R15. */
7654 static void
7655 do_sxth (void)
7657 inst.instruction |= inst.operands[0].reg << 12;
7658 inst.instruction |= inst.operands[1].reg;
7659 inst.instruction |= inst.operands[2].imm << 10;
7662 /* VFP instructions. In a logical order: SP variant first, monad
7663 before dyad, arithmetic then move then load/store. */
7665 static void
7666 do_vfp_sp_monadic (void)
7668 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7669 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7672 static void
7673 do_vfp_sp_dyadic (void)
7675 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7676 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7677 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7680 static void
7681 do_vfp_sp_compare_z (void)
7683 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7686 static void
7687 do_vfp_dp_sp_cvt (void)
7689 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7690 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7693 static void
7694 do_vfp_sp_dp_cvt (void)
7696 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7697 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7700 static void
7701 do_vfp_reg_from_sp (void)
7703 inst.instruction |= inst.operands[0].reg << 12;
7704 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7707 static void
7708 do_vfp_reg2_from_sp2 (void)
7710 constraint (inst.operands[2].imm != 2,
7711 _("only two consecutive VFP SP registers allowed here"));
7712 inst.instruction |= inst.operands[0].reg << 12;
7713 inst.instruction |= inst.operands[1].reg << 16;
7714 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7717 static void
7718 do_vfp_sp_from_reg (void)
7720 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7721 inst.instruction |= inst.operands[1].reg << 12;
7724 static void
7725 do_vfp_sp2_from_reg2 (void)
7727 constraint (inst.operands[0].imm != 2,
7728 _("only two consecutive VFP SP registers allowed here"));
7729 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7730 inst.instruction |= inst.operands[1].reg << 12;
7731 inst.instruction |= inst.operands[2].reg << 16;
7734 static void
7735 do_vfp_sp_ldst (void)
7737 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7738 encode_arm_cp_address (1, FALSE, TRUE, 0);
7741 static void
7742 do_vfp_dp_ldst (void)
7744 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7745 encode_arm_cp_address (1, FALSE, TRUE, 0);
7749 static void
7750 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7752 if (inst.operands[0].writeback)
7753 inst.instruction |= WRITE_BACK;
7754 else
7755 constraint (ldstm_type != VFP_LDSTMIA,
7756 _("this addressing mode requires base-register writeback"));
7757 inst.instruction |= inst.operands[0].reg << 16;
7758 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7759 inst.instruction |= inst.operands[1].imm;
7762 static void
7763 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7765 int count;
7767 if (inst.operands[0].writeback)
7768 inst.instruction |= WRITE_BACK;
7769 else
7770 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7771 _("this addressing mode requires base-register writeback"));
7773 inst.instruction |= inst.operands[0].reg << 16;
7774 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7776 count = inst.operands[1].imm << 1;
7777 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7778 count += 1;
7780 inst.instruction |= count;
7783 static void
7784 do_vfp_sp_ldstmia (void)
7786 vfp_sp_ldstm (VFP_LDSTMIA);
7789 static void
7790 do_vfp_sp_ldstmdb (void)
7792 vfp_sp_ldstm (VFP_LDSTMDB);
7795 static void
7796 do_vfp_dp_ldstmia (void)
7798 vfp_dp_ldstm (VFP_LDSTMIA);
7801 static void
7802 do_vfp_dp_ldstmdb (void)
7804 vfp_dp_ldstm (VFP_LDSTMDB);
7807 static void
7808 do_vfp_xp_ldstmia (void)
7810 vfp_dp_ldstm (VFP_LDSTMIAX);
7813 static void
7814 do_vfp_xp_ldstmdb (void)
7816 vfp_dp_ldstm (VFP_LDSTMDBX);
7819 static void
7820 do_vfp_dp_rd_rm (void)
7822 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7823 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7826 static void
7827 do_vfp_dp_rn_rd (void)
7829 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7830 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7833 static void
7834 do_vfp_dp_rd_rn (void)
7836 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7837 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7840 static void
7841 do_vfp_dp_rd_rn_rm (void)
7843 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7844 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7845 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7848 static void
7849 do_vfp_dp_rd (void)
7851 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7854 static void
7855 do_vfp_dp_rm_rd_rn (void)
7857 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7858 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7859 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7862 /* VFPv3 instructions. */
7863 static void
7864 do_vfp_sp_const (void)
7866 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7867 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7868 inst.instruction |= (inst.operands[1].imm & 0x0f);
7871 static void
7872 do_vfp_dp_const (void)
7874 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7875 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7876 inst.instruction |= (inst.operands[1].imm & 0x0f);
7879 static void
7880 vfp_conv (int srcsize)
7882 unsigned immbits = srcsize - inst.operands[1].imm;
7883 inst.instruction |= (immbits & 1) << 5;
7884 inst.instruction |= (immbits >> 1);
7887 static void
7888 do_vfp_sp_conv_16 (void)
7890 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7891 vfp_conv (16);
7894 static void
7895 do_vfp_dp_conv_16 (void)
7897 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7898 vfp_conv (16);
7901 static void
7902 do_vfp_sp_conv_32 (void)
7904 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7905 vfp_conv (32);
7908 static void
7909 do_vfp_dp_conv_32 (void)
7911 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7912 vfp_conv (32);
7915 /* FPA instructions. Also in a logical order. */
7917 static void
7918 do_fpa_cmp (void)
7920 inst.instruction |= inst.operands[0].reg << 16;
7921 inst.instruction |= inst.operands[1].reg;
7924 static void
7925 do_fpa_ldmstm (void)
7927 inst.instruction |= inst.operands[0].reg << 12;
7928 switch (inst.operands[1].imm)
7930 case 1: inst.instruction |= CP_T_X; break;
7931 case 2: inst.instruction |= CP_T_Y; break;
7932 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7933 case 4: break;
7934 default: abort ();
7937 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7939 /* The instruction specified "ea" or "fd", so we can only accept
7940 [Rn]{!}. The instruction does not really support stacking or
7941 unstacking, so we have to emulate these by setting appropriate
7942 bits and offsets. */
7943 constraint (inst.reloc.exp.X_op != O_constant
7944 || inst.reloc.exp.X_add_number != 0,
7945 _("this instruction does not support indexing"));
7947 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7948 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7950 if (!(inst.instruction & INDEX_UP))
7951 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7953 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7955 inst.operands[2].preind = 0;
7956 inst.operands[2].postind = 1;
7960 encode_arm_cp_address (2, TRUE, TRUE, 0);
7963 /* iWMMXt instructions: strictly in alphabetical order. */
7965 static void
7966 do_iwmmxt_tandorc (void)
7968 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7971 static void
7972 do_iwmmxt_textrc (void)
7974 inst.instruction |= inst.operands[0].reg << 12;
7975 inst.instruction |= inst.operands[1].imm;
7978 static void
7979 do_iwmmxt_textrm (void)
7981 inst.instruction |= inst.operands[0].reg << 12;
7982 inst.instruction |= inst.operands[1].reg << 16;
7983 inst.instruction |= inst.operands[2].imm;
7986 static void
7987 do_iwmmxt_tinsr (void)
7989 inst.instruction |= inst.operands[0].reg << 16;
7990 inst.instruction |= inst.operands[1].reg << 12;
7991 inst.instruction |= inst.operands[2].imm;
7994 static void
7995 do_iwmmxt_tmia (void)
7997 inst.instruction |= inst.operands[0].reg << 5;
7998 inst.instruction |= inst.operands[1].reg;
7999 inst.instruction |= inst.operands[2].reg << 12;
8002 static void
8003 do_iwmmxt_waligni (void)
8005 inst.instruction |= inst.operands[0].reg << 12;
8006 inst.instruction |= inst.operands[1].reg << 16;
8007 inst.instruction |= inst.operands[2].reg;
8008 inst.instruction |= inst.operands[3].imm << 20;
8011 static void
8012 do_iwmmxt_wmerge (void)
8014 inst.instruction |= inst.operands[0].reg << 12;
8015 inst.instruction |= inst.operands[1].reg << 16;
8016 inst.instruction |= inst.operands[2].reg;
8017 inst.instruction |= inst.operands[3].imm << 21;
8020 static void
8021 do_iwmmxt_wmov (void)
8023 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8024 inst.instruction |= inst.operands[0].reg << 12;
8025 inst.instruction |= inst.operands[1].reg << 16;
8026 inst.instruction |= inst.operands[1].reg;
8029 static void
8030 do_iwmmxt_wldstbh (void)
8032 int reloc;
8033 inst.instruction |= inst.operands[0].reg << 12;
8034 if (thumb_mode)
8035 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8036 else
8037 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8038 encode_arm_cp_address (1, TRUE, FALSE, reloc);
8041 static void
8042 do_iwmmxt_wldstw (void)
8044 /* RIWR_RIWC clears .isreg for a control register. */
8045 if (!inst.operands[0].isreg)
8047 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8048 inst.instruction |= 0xf0000000;
8051 inst.instruction |= inst.operands[0].reg << 12;
8052 encode_arm_cp_address (1, TRUE, TRUE, 0);
8055 static void
8056 do_iwmmxt_wldstd (void)
8058 inst.instruction |= inst.operands[0].reg << 12;
8059 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8060 && inst.operands[1].immisreg)
8062 inst.instruction &= ~0x1a000ff;
8063 inst.instruction |= (0xf << 28);
8064 if (inst.operands[1].preind)
8065 inst.instruction |= PRE_INDEX;
8066 if (!inst.operands[1].negative)
8067 inst.instruction |= INDEX_UP;
8068 if (inst.operands[1].writeback)
8069 inst.instruction |= WRITE_BACK;
8070 inst.instruction |= inst.operands[1].reg << 16;
8071 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8072 inst.instruction |= inst.operands[1].imm;
8074 else
8075 encode_arm_cp_address (1, TRUE, FALSE, 0);
8078 static void
8079 do_iwmmxt_wshufh (void)
8081 inst.instruction |= inst.operands[0].reg << 12;
8082 inst.instruction |= inst.operands[1].reg << 16;
8083 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8084 inst.instruction |= (inst.operands[2].imm & 0x0f);
8087 static void
8088 do_iwmmxt_wzero (void)
8090 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8091 inst.instruction |= inst.operands[0].reg;
8092 inst.instruction |= inst.operands[0].reg << 12;
8093 inst.instruction |= inst.operands[0].reg << 16;
8096 static void
8097 do_iwmmxt_wrwrwr_or_imm5 (void)
8099 if (inst.operands[2].isreg)
8100 do_rd_rn_rm ();
8101 else {
8102 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8103 _("immediate operand requires iWMMXt2"));
8104 do_rd_rn ();
8105 if (inst.operands[2].imm == 0)
8107 switch ((inst.instruction >> 20) & 0xf)
8109 case 4:
8110 case 5:
8111 case 6:
8112 case 7:
8113 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8114 inst.operands[2].imm = 16;
8115 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8116 break;
8117 case 8:
8118 case 9:
8119 case 10:
8120 case 11:
8121 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8122 inst.operands[2].imm = 32;
8123 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8124 break;
8125 case 12:
8126 case 13:
8127 case 14:
8128 case 15:
8130 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8131 unsigned long wrn;
8132 wrn = (inst.instruction >> 16) & 0xf;
8133 inst.instruction &= 0xff0fff0f;
8134 inst.instruction |= wrn;
8135 /* Bail out here; the instruction is now assembled. */
8136 return;
8140 /* Map 32 -> 0, etc. */
8141 inst.operands[2].imm &= 0x1f;
8142 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8146 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8147 operations first, then control, shift, and load/store. */
8149 /* Insns like "foo X,Y,Z". */
8151 static void
8152 do_mav_triple (void)
8154 inst.instruction |= inst.operands[0].reg << 16;
8155 inst.instruction |= inst.operands[1].reg;
8156 inst.instruction |= inst.operands[2].reg << 12;
8159 /* Insns like "foo W,X,Y,Z".
8160 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8162 static void
8163 do_mav_quad (void)
8165 inst.instruction |= inst.operands[0].reg << 5;
8166 inst.instruction |= inst.operands[1].reg << 12;
8167 inst.instruction |= inst.operands[2].reg << 16;
8168 inst.instruction |= inst.operands[3].reg;
8171 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8172 static void
8173 do_mav_dspsc (void)
8175 inst.instruction |= inst.operands[1].reg << 12;
8178 /* Maverick shift immediate instructions.
8179 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8180 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8182 static void
8183 do_mav_shift (void)
8185 int imm = inst.operands[2].imm;
8187 inst.instruction |= inst.operands[0].reg << 12;
8188 inst.instruction |= inst.operands[1].reg << 16;
8190 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8191 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8192 Bit 4 should be 0. */
8193 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8195 inst.instruction |= imm;
8198 /* XScale instructions. Also sorted arithmetic before move. */
8200 /* Xscale multiply-accumulate (argument parse)
8201 MIAcc acc0,Rm,Rs
8202 MIAPHcc acc0,Rm,Rs
8203 MIAxycc acc0,Rm,Rs. */
8205 static void
8206 do_xsc_mia (void)
8208 inst.instruction |= inst.operands[1].reg;
8209 inst.instruction |= inst.operands[2].reg << 12;
8212 /* Xscale move-accumulator-register (argument parse)
8214 MARcc acc0,RdLo,RdHi. */
8216 static void
8217 do_xsc_mar (void)
8219 inst.instruction |= inst.operands[1].reg << 12;
8220 inst.instruction |= inst.operands[2].reg << 16;
8223 /* Xscale move-register-accumulator (argument parse)
8225 MRAcc RdLo,RdHi,acc0. */
8227 static void
8228 do_xsc_mra (void)
8230 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8231 inst.instruction |= inst.operands[0].reg << 12;
8232 inst.instruction |= inst.operands[1].reg << 16;
8235 /* Encoding functions relevant only to Thumb. */
8237 /* inst.operands[i] is a shifted-register operand; encode
8238 it into inst.instruction in the format used by Thumb32. */
8240 static void
8241 encode_thumb32_shifted_operand (int i)
8243 unsigned int value = inst.reloc.exp.X_add_number;
8244 unsigned int shift = inst.operands[i].shift_kind;
8246 constraint (inst.operands[i].immisreg,
8247 _("shift by register not allowed in thumb mode"));
8248 inst.instruction |= inst.operands[i].reg;
8249 if (shift == SHIFT_RRX)
8250 inst.instruction |= SHIFT_ROR << 4;
8251 else
8253 constraint (inst.reloc.exp.X_op != O_constant,
8254 _("expression too complex"));
8256 constraint (value > 32
8257 || (value == 32 && (shift == SHIFT_LSL
8258 || shift == SHIFT_ROR)),
8259 _("shift expression is too large"));
8261 if (value == 0)
8262 shift = SHIFT_LSL;
8263 else if (value == 32)
8264 value = 0;
8266 inst.instruction |= shift << 4;
8267 inst.instruction |= (value & 0x1c) << 10;
8268 inst.instruction |= (value & 0x03) << 6;
8273 /* inst.operands[i] was set up by parse_address. Encode it into a
8274 Thumb32 format load or store instruction. Reject forms that cannot
8275 be used with such instructions. If is_t is true, reject forms that
8276 cannot be used with a T instruction; if is_d is true, reject forms
8277 that cannot be used with a D instruction. */
8279 static void
8280 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8282 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8284 constraint (!inst.operands[i].isreg,
8285 _("Instruction does not support =N addresses"));
8287 inst.instruction |= inst.operands[i].reg << 16;
8288 if (inst.operands[i].immisreg)
8290 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8291 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8292 constraint (inst.operands[i].negative,
8293 _("Thumb does not support negative register indexing"));
8294 constraint (inst.operands[i].postind,
8295 _("Thumb does not support register post-indexing"));
8296 constraint (inst.operands[i].writeback,
8297 _("Thumb does not support register indexing with writeback"));
8298 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8299 _("Thumb supports only LSL in shifted register indexing"));
8301 inst.instruction |= inst.operands[i].imm;
8302 if (inst.operands[i].shifted)
8304 constraint (inst.reloc.exp.X_op != O_constant,
8305 _("expression too complex"));
8306 constraint (inst.reloc.exp.X_add_number < 0
8307 || inst.reloc.exp.X_add_number > 3,
8308 _("shift out of range"));
8309 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8311 inst.reloc.type = BFD_RELOC_UNUSED;
8313 else if (inst.operands[i].preind)
8315 constraint (is_pc && inst.operands[i].writeback,
8316 _("cannot use writeback with PC-relative addressing"));
8317 constraint (is_t && inst.operands[i].writeback,
8318 _("cannot use writeback with this instruction"));
8320 if (is_d)
8322 inst.instruction |= 0x01000000;
8323 if (inst.operands[i].writeback)
8324 inst.instruction |= 0x00200000;
8326 else
8328 inst.instruction |= 0x00000c00;
8329 if (inst.operands[i].writeback)
8330 inst.instruction |= 0x00000100;
8332 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8334 else if (inst.operands[i].postind)
8336 assert (inst.operands[i].writeback);
8337 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8338 constraint (is_t, _("cannot use post-indexing with this instruction"));
8340 if (is_d)
8341 inst.instruction |= 0x00200000;
8342 else
8343 inst.instruction |= 0x00000900;
8344 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8346 else /* unindexed - only for coprocessor */
8347 inst.error = _("instruction does not accept unindexed addressing");
8350 /* Table of Thumb instructions which exist in both 16- and 32-bit
8351 encodings (the latter only in post-V6T2 cores). The index is the
8352 value used in the insns table below. When there is more than one
8353 possible 16-bit encoding for the instruction, this table always
8354 holds variant (1).
8355 Also contains several pseudo-instructions used during relaxation. */
8356 #define T16_32_TAB \
8357 X(adc, 4140, eb400000), \
8358 X(adcs, 4140, eb500000), \
8359 X(add, 1c00, eb000000), \
8360 X(adds, 1c00, eb100000), \
8361 X(addi, 0000, f1000000), \
8362 X(addis, 0000, f1100000), \
8363 X(add_pc,000f, f20f0000), \
8364 X(add_sp,000d, f10d0000), \
8365 X(adr, 000f, f20f0000), \
8366 X(and, 4000, ea000000), \
8367 X(ands, 4000, ea100000), \
8368 X(asr, 1000, fa40f000), \
8369 X(asrs, 1000, fa50f000), \
8370 X(b, e000, f000b000), \
8371 X(bcond, d000, f0008000), \
8372 X(bic, 4380, ea200000), \
8373 X(bics, 4380, ea300000), \
8374 X(cmn, 42c0, eb100f00), \
8375 X(cmp, 2800, ebb00f00), \
8376 X(cpsie, b660, f3af8400), \
8377 X(cpsid, b670, f3af8600), \
8378 X(cpy, 4600, ea4f0000), \
8379 X(dec_sp,80dd, f1ad0d00), \
8380 X(eor, 4040, ea800000), \
8381 X(eors, 4040, ea900000), \
8382 X(inc_sp,00dd, f10d0d00), \
8383 X(ldmia, c800, e8900000), \
8384 X(ldr, 6800, f8500000), \
8385 X(ldrb, 7800, f8100000), \
8386 X(ldrh, 8800, f8300000), \
8387 X(ldrsb, 5600, f9100000), \
8388 X(ldrsh, 5e00, f9300000), \
8389 X(ldr_pc,4800, f85f0000), \
8390 X(ldr_pc2,4800, f85f0000), \
8391 X(ldr_sp,9800, f85d0000), \
8392 X(lsl, 0000, fa00f000), \
8393 X(lsls, 0000, fa10f000), \
8394 X(lsr, 0800, fa20f000), \
8395 X(lsrs, 0800, fa30f000), \
8396 X(mov, 2000, ea4f0000), \
8397 X(movs, 2000, ea5f0000), \
8398 X(mul, 4340, fb00f000), \
8399 X(muls, 4340, ffffffff), /* no 32b muls */ \
8400 X(mvn, 43c0, ea6f0000), \
8401 X(mvns, 43c0, ea7f0000), \
8402 X(neg, 4240, f1c00000), /* rsb #0 */ \
8403 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8404 X(orr, 4300, ea400000), \
8405 X(orrs, 4300, ea500000), \
8406 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8407 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8408 X(rev, ba00, fa90f080), \
8409 X(rev16, ba40, fa90f090), \
8410 X(revsh, bac0, fa90f0b0), \
8411 X(ror, 41c0, fa60f000), \
8412 X(rors, 41c0, fa70f000), \
8413 X(sbc, 4180, eb600000), \
8414 X(sbcs, 4180, eb700000), \
8415 X(stmia, c000, e8800000), \
8416 X(str, 6000, f8400000), \
8417 X(strb, 7000, f8000000), \
8418 X(strh, 8000, f8200000), \
8419 X(str_sp,9000, f84d0000), \
8420 X(sub, 1e00, eba00000), \
8421 X(subs, 1e00, ebb00000), \
8422 X(subi, 8000, f1a00000), \
8423 X(subis, 8000, f1b00000), \
8424 X(sxtb, b240, fa4ff080), \
8425 X(sxth, b200, fa0ff080), \
8426 X(tst, 4200, ea100f00), \
8427 X(uxtb, b2c0, fa5ff080), \
8428 X(uxth, b280, fa1ff080), \
8429 X(nop, bf00, f3af8000), \
8430 X(yield, bf10, f3af8001), \
8431 X(wfe, bf20, f3af8002), \
8432 X(wfi, bf30, f3af8003), \
8433 X(sev, bf40, f3af9004), /* typo, 8004? */
8435 /* To catch errors in encoding functions, the codes are all offset by
8436 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8437 as 16-bit instructions. */
8438 #define X(a,b,c) T_MNEM_##a
8439 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8440 #undef X
8442 #define X(a,b,c) 0x##b
8443 static const unsigned short thumb_op16[] = { T16_32_TAB };
8444 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8445 #undef X
8447 #define X(a,b,c) 0x##c
8448 static const unsigned int thumb_op32[] = { T16_32_TAB };
8449 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8450 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8451 #undef X
8452 #undef T16_32_TAB
8454 /* Thumb instruction encoders, in alphabetical order. */
8456 /* ADDW or SUBW. */
8457 static void
8458 do_t_add_sub_w (void)
8460 int Rd, Rn;
8462 Rd = inst.operands[0].reg;
8463 Rn = inst.operands[1].reg;
8465 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this is the
8466 SP-{plus,minute}-immediate form of the instruction. */
8467 reject_bad_reg (Rd);
8469 inst.instruction |= (Rn << 16) | (Rd << 8);
8470 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8473 /* Parse an add or subtract instruction. We get here with inst.instruction
8474 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8476 static void
8477 do_t_add_sub (void)
8479 int Rd, Rs, Rn;
8481 Rd = inst.operands[0].reg;
8482 Rs = (inst.operands[1].present
8483 ? inst.operands[1].reg /* Rd, Rs, foo */
8484 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8486 if (unified_syntax)
8488 bfd_boolean flags;
8489 bfd_boolean narrow;
8490 int opcode;
8492 flags = (inst.instruction == T_MNEM_adds
8493 || inst.instruction == T_MNEM_subs);
8494 if (flags)
8495 narrow = (current_it_mask == 0);
8496 else
8497 narrow = (current_it_mask != 0);
8498 if (!inst.operands[2].isreg)
8500 int add;
8502 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8504 add = (inst.instruction == T_MNEM_add
8505 || inst.instruction == T_MNEM_adds);
8506 opcode = 0;
8507 if (inst.size_req != 4)
8509 /* Attempt to use a narrow opcode, with relaxation if
8510 appropriate. */
8511 if (Rd == REG_SP && Rs == REG_SP && !flags)
8512 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8513 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8514 opcode = T_MNEM_add_sp;
8515 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8516 opcode = T_MNEM_add_pc;
8517 else if (Rd <= 7 && Rs <= 7 && narrow)
8519 if (flags)
8520 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8521 else
8522 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8524 if (opcode)
8526 inst.instruction = THUMB_OP16(opcode);
8527 inst.instruction |= (Rd << 4) | Rs;
8528 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8529 if (inst.size_req != 2)
8530 inst.relax = opcode;
8532 else
8533 constraint (inst.size_req == 2, BAD_HIREG);
8535 if (inst.size_req == 4
8536 || (inst.size_req != 2 && !opcode))
8538 if (Rd == REG_PC)
8540 constraint (add, BAD_PC);
8541 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8542 _("only SUBS PC, LR, #const allowed"));
8543 constraint (inst.reloc.exp.X_op != O_constant,
8544 _("expression too complex"));
8545 constraint (inst.reloc.exp.X_add_number < 0
8546 || inst.reloc.exp.X_add_number > 0xff,
8547 _("immediate value out of range"));
8548 inst.instruction = T2_SUBS_PC_LR
8549 | inst.reloc.exp.X_add_number;
8550 inst.reloc.type = BFD_RELOC_UNUSED;
8551 return;
8553 else if (Rs == REG_PC)
8555 /* Always use addw/subw. */
8556 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8557 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8559 else
8561 inst.instruction = THUMB_OP32 (inst.instruction);
8562 inst.instruction = (inst.instruction & 0xe1ffffff)
8563 | 0x10000000;
8564 if (flags)
8565 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8566 else
8567 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8569 inst.instruction |= Rd << 8;
8570 inst.instruction |= Rs << 16;
8573 else
8575 Rn = inst.operands[2].reg;
8576 /* See if we can do this with a 16-bit instruction. */
8577 if (!inst.operands[2].shifted && inst.size_req != 4)
8579 if (Rd > 7 || Rs > 7 || Rn > 7)
8580 narrow = FALSE;
8582 if (narrow)
8584 inst.instruction = ((inst.instruction == T_MNEM_adds
8585 || inst.instruction == T_MNEM_add)
8586 ? T_OPCODE_ADD_R3
8587 : T_OPCODE_SUB_R3);
8588 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8589 return;
8592 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
8594 /* Thumb-1 cores (except v6-M) require at least one high
8595 register in a narrow non flag setting add. */
8596 if (Rd > 7 || Rn > 7
8597 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8598 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
8600 if (Rd == Rn)
8602 Rn = Rs;
8603 Rs = Rd;
8605 inst.instruction = T_OPCODE_ADD_HI;
8606 inst.instruction |= (Rd & 8) << 4;
8607 inst.instruction |= (Rd & 7);
8608 inst.instruction |= Rn << 3;
8609 return;
8614 constraint (Rd == REG_PC, BAD_PC);
8615 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8616 constraint (Rs == REG_PC, BAD_PC);
8617 reject_bad_reg (Rn);
8619 /* If we get here, it can't be done in 16 bits. */
8620 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8621 _("shift must be constant"));
8622 inst.instruction = THUMB_OP32 (inst.instruction);
8623 inst.instruction |= Rd << 8;
8624 inst.instruction |= Rs << 16;
8625 encode_thumb32_shifted_operand (2);
8628 else
8630 constraint (inst.instruction == T_MNEM_adds
8631 || inst.instruction == T_MNEM_subs,
8632 BAD_THUMB32);
8634 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8636 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8637 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8638 BAD_HIREG);
8640 inst.instruction = (inst.instruction == T_MNEM_add
8641 ? 0x0000 : 0x8000);
8642 inst.instruction |= (Rd << 4) | Rs;
8643 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8644 return;
8647 Rn = inst.operands[2].reg;
8648 constraint (inst.operands[2].shifted, _("unshifted register required"));
8650 /* We now have Rd, Rs, and Rn set to registers. */
8651 if (Rd > 7 || Rs > 7 || Rn > 7)
8653 /* Can't do this for SUB. */
8654 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8655 inst.instruction = T_OPCODE_ADD_HI;
8656 inst.instruction |= (Rd & 8) << 4;
8657 inst.instruction |= (Rd & 7);
8658 if (Rs == Rd)
8659 inst.instruction |= Rn << 3;
8660 else if (Rn == Rd)
8661 inst.instruction |= Rs << 3;
8662 else
8663 constraint (1, _("dest must overlap one source register"));
8665 else
8667 inst.instruction = (inst.instruction == T_MNEM_add
8668 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8669 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8674 static void
8675 do_t_adr (void)
8677 unsigned Rd;
8679 Rd = inst.operands[0].reg;
8680 reject_bad_reg (Rd);
8682 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
8684 /* Defer to section relaxation. */
8685 inst.relax = inst.instruction;
8686 inst.instruction = THUMB_OP16 (inst.instruction);
8687 inst.instruction |= Rd << 4;
8689 else if (unified_syntax && inst.size_req != 2)
8691 /* Generate a 32-bit opcode. */
8692 inst.instruction = THUMB_OP32 (inst.instruction);
8693 inst.instruction |= Rd << 8;
8694 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8695 inst.reloc.pc_rel = 1;
8697 else
8699 /* Generate a 16-bit opcode. */
8700 inst.instruction = THUMB_OP16 (inst.instruction);
8701 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8702 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8703 inst.reloc.pc_rel = 1;
8705 inst.instruction |= Rd << 4;
8709 /* Arithmetic instructions for which there is just one 16-bit
8710 instruction encoding, and it allows only two low registers.
8711 For maximal compatibility with ARM syntax, we allow three register
8712 operands even when Thumb-32 instructions are not available, as long
8713 as the first two are identical. For instance, both "sbc r0,r1" and
8714 "sbc r0,r0,r1" are allowed. */
8715 static void
8716 do_t_arit3 (void)
8718 int Rd, Rs, Rn;
8720 Rd = inst.operands[0].reg;
8721 Rs = (inst.operands[1].present
8722 ? inst.operands[1].reg /* Rd, Rs, foo */
8723 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8724 Rn = inst.operands[2].reg;
8726 reject_bad_reg (Rd);
8727 reject_bad_reg (Rs);
8728 if (inst.operands[2].isreg)
8729 reject_bad_reg (Rn);
8731 if (unified_syntax)
8733 if (!inst.operands[2].isreg)
8735 /* For an immediate, we always generate a 32-bit opcode;
8736 section relaxation will shrink it later if possible. */
8737 inst.instruction = THUMB_OP32 (inst.instruction);
8738 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8739 inst.instruction |= Rd << 8;
8740 inst.instruction |= Rs << 16;
8741 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8743 else
8745 bfd_boolean narrow;
8747 /* See if we can do this with a 16-bit instruction. */
8748 if (THUMB_SETS_FLAGS (inst.instruction))
8749 narrow = current_it_mask == 0;
8750 else
8751 narrow = current_it_mask != 0;
8753 if (Rd > 7 || Rn > 7 || Rs > 7)
8754 narrow = FALSE;
8755 if (inst.operands[2].shifted)
8756 narrow = FALSE;
8757 if (inst.size_req == 4)
8758 narrow = FALSE;
8760 if (narrow
8761 && Rd == Rs)
8763 inst.instruction = THUMB_OP16 (inst.instruction);
8764 inst.instruction |= Rd;
8765 inst.instruction |= Rn << 3;
8766 return;
8769 /* If we get here, it can't be done in 16 bits. */
8770 constraint (inst.operands[2].shifted
8771 && inst.operands[2].immisreg,
8772 _("shift must be constant"));
8773 inst.instruction = THUMB_OP32 (inst.instruction);
8774 inst.instruction |= Rd << 8;
8775 inst.instruction |= Rs << 16;
8776 encode_thumb32_shifted_operand (2);
8779 else
8781 /* On its face this is a lie - the instruction does set the
8782 flags. However, the only supported mnemonic in this mode
8783 says it doesn't. */
8784 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8786 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8787 _("unshifted register required"));
8788 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8789 constraint (Rd != Rs,
8790 _("dest and source1 must be the same register"));
8792 inst.instruction = THUMB_OP16 (inst.instruction);
8793 inst.instruction |= Rd;
8794 inst.instruction |= Rn << 3;
8798 /* Similarly, but for instructions where the arithmetic operation is
8799 commutative, so we can allow either of them to be different from
8800 the destination operand in a 16-bit instruction. For instance, all
8801 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8802 accepted. */
8803 static void
8804 do_t_arit3c (void)
8806 int Rd, Rs, Rn;
8808 Rd = inst.operands[0].reg;
8809 Rs = (inst.operands[1].present
8810 ? inst.operands[1].reg /* Rd, Rs, foo */
8811 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8812 Rn = inst.operands[2].reg;
8814 reject_bad_reg (Rd);
8815 reject_bad_reg (Rs);
8816 if (inst.operands[2].isreg)
8817 reject_bad_reg (Rn);
8819 if (unified_syntax)
8821 if (!inst.operands[2].isreg)
8823 /* For an immediate, we always generate a 32-bit opcode;
8824 section relaxation will shrink it later if possible. */
8825 inst.instruction = THUMB_OP32 (inst.instruction);
8826 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8827 inst.instruction |= Rd << 8;
8828 inst.instruction |= Rs << 16;
8829 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8831 else
8833 bfd_boolean narrow;
8835 /* See if we can do this with a 16-bit instruction. */
8836 if (THUMB_SETS_FLAGS (inst.instruction))
8837 narrow = current_it_mask == 0;
8838 else
8839 narrow = current_it_mask != 0;
8841 if (Rd > 7 || Rn > 7 || Rs > 7)
8842 narrow = FALSE;
8843 if (inst.operands[2].shifted)
8844 narrow = FALSE;
8845 if (inst.size_req == 4)
8846 narrow = FALSE;
8848 if (narrow)
8850 if (Rd == Rs)
8852 inst.instruction = THUMB_OP16 (inst.instruction);
8853 inst.instruction |= Rd;
8854 inst.instruction |= Rn << 3;
8855 return;
8857 if (Rd == Rn)
8859 inst.instruction = THUMB_OP16 (inst.instruction);
8860 inst.instruction |= Rd;
8861 inst.instruction |= Rs << 3;
8862 return;
8866 /* If we get here, it can't be done in 16 bits. */
8867 constraint (inst.operands[2].shifted
8868 && inst.operands[2].immisreg,
8869 _("shift must be constant"));
8870 inst.instruction = THUMB_OP32 (inst.instruction);
8871 inst.instruction |= Rd << 8;
8872 inst.instruction |= Rs << 16;
8873 encode_thumb32_shifted_operand (2);
8876 else
8878 /* On its face this is a lie - the instruction does set the
8879 flags. However, the only supported mnemonic in this mode
8880 says it doesn't. */
8881 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8883 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8884 _("unshifted register required"));
8885 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8887 inst.instruction = THUMB_OP16 (inst.instruction);
8888 inst.instruction |= Rd;
8890 if (Rd == Rs)
8891 inst.instruction |= Rn << 3;
8892 else if (Rd == Rn)
8893 inst.instruction |= Rs << 3;
8894 else
8895 constraint (1, _("dest must overlap one source register"));
8899 static void
8900 do_t_barrier (void)
8902 if (inst.operands[0].present)
8904 constraint ((inst.instruction & 0xf0) != 0x40
8905 && inst.operands[0].imm != 0xf,
8906 _("bad barrier type"));
8907 inst.instruction |= inst.operands[0].imm;
8909 else
8910 inst.instruction |= 0xf;
8913 static void
8914 do_t_bfc (void)
8916 unsigned Rd;
8917 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8918 constraint (msb > 32, _("bit-field extends past end of register"));
8919 /* The instruction encoding stores the LSB and MSB,
8920 not the LSB and width. */
8921 Rd = inst.operands[0].reg;
8922 reject_bad_reg (Rd);
8923 inst.instruction |= Rd << 8;
8924 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8925 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8926 inst.instruction |= msb - 1;
8929 static void
8930 do_t_bfi (void)
8932 int Rd, Rn;
8933 unsigned int msb;
8935 Rd = inst.operands[0].reg;
8936 reject_bad_reg (Rd);
8938 /* #0 in second position is alternative syntax for bfc, which is
8939 the same instruction but with REG_PC in the Rm field. */
8940 if (!inst.operands[1].isreg)
8941 Rn = REG_PC;
8942 else
8944 Rn = inst.operands[1].reg;
8945 reject_bad_reg (Rn);
8948 msb = inst.operands[2].imm + inst.operands[3].imm;
8949 constraint (msb > 32, _("bit-field extends past end of register"));
8950 /* The instruction encoding stores the LSB and MSB,
8951 not the LSB and width. */
8952 inst.instruction |= Rd << 8;
8953 inst.instruction |= Rn << 16;
8954 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8955 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8956 inst.instruction |= msb - 1;
8959 static void
8960 do_t_bfx (void)
8962 unsigned Rd, Rn;
8964 Rd = inst.operands[0].reg;
8965 Rn = inst.operands[1].reg;
8967 reject_bad_reg (Rd);
8968 reject_bad_reg (Rn);
8970 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8971 _("bit-field extends past end of register"));
8972 inst.instruction |= Rd << 8;
8973 inst.instruction |= Rn << 16;
8974 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8975 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8976 inst.instruction |= inst.operands[3].imm - 1;
8979 /* ARM V5 Thumb BLX (argument parse)
8980 BLX <target_addr> which is BLX(1)
8981 BLX <Rm> which is BLX(2)
8982 Unfortunately, there are two different opcodes for this mnemonic.
8983 So, the insns[].value is not used, and the code here zaps values
8984 into inst.instruction.
8986 ??? How to take advantage of the additional two bits of displacement
8987 available in Thumb32 mode? Need new relocation? */
8989 static void
8990 do_t_blx (void)
8992 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8993 if (inst.operands[0].isreg)
8995 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8996 /* We have a register, so this is BLX(2). */
8997 inst.instruction |= inst.operands[0].reg << 3;
8999 else
9001 /* No register. This must be BLX(1). */
9002 inst.instruction = 0xf000e800;
9003 #ifdef OBJ_ELF
9004 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9005 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9006 else
9007 #endif
9008 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
9009 inst.reloc.pc_rel = 1;
9013 static void
9014 do_t_branch (void)
9016 int opcode;
9017 int cond;
9019 if (current_it_mask)
9021 /* Conditional branches inside IT blocks are encoded as unconditional
9022 branches. */
9023 cond = COND_ALWAYS;
9024 /* A branch must be the last instruction in an IT block. */
9025 constraint (current_it_mask != 0x10, BAD_BRANCH);
9027 else
9028 cond = inst.cond;
9030 if (cond != COND_ALWAYS)
9031 opcode = T_MNEM_bcond;
9032 else
9033 opcode = inst.instruction;
9035 if (unified_syntax && inst.size_req == 4)
9037 inst.instruction = THUMB_OP32(opcode);
9038 if (cond == COND_ALWAYS)
9039 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
9040 else
9042 assert (cond != 0xF);
9043 inst.instruction |= cond << 22;
9044 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9047 else
9049 inst.instruction = THUMB_OP16(opcode);
9050 if (cond == COND_ALWAYS)
9051 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9052 else
9054 inst.instruction |= cond << 8;
9055 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
9057 /* Allow section relaxation. */
9058 if (unified_syntax && inst.size_req != 2)
9059 inst.relax = opcode;
9062 inst.reloc.pc_rel = 1;
9065 static void
9066 do_t_bkpt (void)
9068 constraint (inst.cond != COND_ALWAYS,
9069 _("instruction is always unconditional"));
9070 if (inst.operands[0].present)
9072 constraint (inst.operands[0].imm > 255,
9073 _("immediate value out of range"));
9074 inst.instruction |= inst.operands[0].imm;
9078 static void
9079 do_t_branch23 (void)
9081 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
9082 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9083 inst.reloc.pc_rel = 1;
9085 /* If the destination of the branch is a defined symbol which does not have
9086 the THUMB_FUNC attribute, then we must be calling a function which has
9087 the (interfacearm) attribute. We look for the Thumb entry point to that
9088 function and change the branch to refer to that function instead. */
9089 if ( inst.reloc.exp.X_op == O_symbol
9090 && inst.reloc.exp.X_add_symbol != NULL
9091 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9092 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9093 inst.reloc.exp.X_add_symbol =
9094 find_real_start (inst.reloc.exp.X_add_symbol);
9097 static void
9098 do_t_bx (void)
9100 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
9101 inst.instruction |= inst.operands[0].reg << 3;
9102 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9103 should cause the alignment to be checked once it is known. This is
9104 because BX PC only works if the instruction is word aligned. */
9107 static void
9108 do_t_bxj (void)
9110 int Rm;
9112 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
9113 Rm = inst.operands[0].reg;
9114 reject_bad_reg (Rm);
9115 inst.instruction |= Rm << 16;
9118 static void
9119 do_t_clz (void)
9121 unsigned Rd;
9122 unsigned Rm;
9124 Rd = inst.operands[0].reg;
9125 Rm = inst.operands[1].reg;
9127 reject_bad_reg (Rd);
9128 reject_bad_reg (Rm);
9130 inst.instruction |= Rd << 8;
9131 inst.instruction |= Rm << 16;
9132 inst.instruction |= Rm;
9135 static void
9136 do_t_cps (void)
9138 constraint (current_it_mask, BAD_NOT_IT);
9139 inst.instruction |= inst.operands[0].imm;
9142 static void
9143 do_t_cpsi (void)
9145 constraint (current_it_mask, BAD_NOT_IT);
9146 if (unified_syntax
9147 && (inst.operands[1].present || inst.size_req == 4)
9148 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9150 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9151 inst.instruction = 0xf3af8000;
9152 inst.instruction |= imod << 9;
9153 inst.instruction |= inst.operands[0].imm << 5;
9154 if (inst.operands[1].present)
9155 inst.instruction |= 0x100 | inst.operands[1].imm;
9157 else
9159 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9160 && (inst.operands[0].imm & 4),
9161 _("selected processor does not support 'A' form "
9162 "of this instruction"));
9163 constraint (inst.operands[1].present || inst.size_req == 4,
9164 _("Thumb does not support the 2-argument "
9165 "form of this instruction"));
9166 inst.instruction |= inst.operands[0].imm;
9170 /* THUMB CPY instruction (argument parse). */
9172 static void
9173 do_t_cpy (void)
9175 if (inst.size_req == 4)
9177 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9178 inst.instruction |= inst.operands[0].reg << 8;
9179 inst.instruction |= inst.operands[1].reg;
9181 else
9183 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9184 inst.instruction |= (inst.operands[0].reg & 0x7);
9185 inst.instruction |= inst.operands[1].reg << 3;
9189 static void
9190 do_t_cbz (void)
9192 constraint (current_it_mask, BAD_NOT_IT);
9193 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9194 inst.instruction |= inst.operands[0].reg;
9195 inst.reloc.pc_rel = 1;
9196 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9199 static void
9200 do_t_dbg (void)
9202 inst.instruction |= inst.operands[0].imm;
9205 static void
9206 do_t_div (void)
9208 unsigned Rd, Rn, Rm;
9210 Rd = inst.operands[0].reg;
9211 Rn = (inst.operands[1].present
9212 ? inst.operands[1].reg : Rd);
9213 Rm = inst.operands[2].reg;
9215 reject_bad_reg (Rd);
9216 reject_bad_reg (Rn);
9217 reject_bad_reg (Rm);
9219 inst.instruction |= Rd << 8;
9220 inst.instruction |= Rn << 16;
9221 inst.instruction |= Rm;
9224 static void
9225 do_t_hint (void)
9227 if (unified_syntax && inst.size_req == 4)
9228 inst.instruction = THUMB_OP32 (inst.instruction);
9229 else
9230 inst.instruction = THUMB_OP16 (inst.instruction);
9233 static void
9234 do_t_it (void)
9236 unsigned int cond = inst.operands[0].imm;
9238 constraint (current_it_mask, BAD_NOT_IT);
9239 current_it_mask = (inst.instruction & 0xf) | 0x10;
9240 current_cc = cond;
9242 /* If the condition is a negative condition, invert the mask. */
9243 if ((cond & 0x1) == 0x0)
9245 unsigned int mask = inst.instruction & 0x000f;
9247 if ((mask & 0x7) == 0)
9248 /* no conversion needed */;
9249 else if ((mask & 0x3) == 0)
9250 mask ^= 0x8;
9251 else if ((mask & 0x1) == 0)
9252 mask ^= 0xC;
9253 else
9254 mask ^= 0xE;
9256 inst.instruction &= 0xfff0;
9257 inst.instruction |= mask;
9260 inst.instruction |= cond << 4;
9263 /* Helper function used for both push/pop and ldm/stm. */
9264 static void
9265 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9267 bfd_boolean load;
9269 load = (inst.instruction & (1 << 20)) != 0;
9271 if (mask & (1 << 13))
9272 inst.error = _("SP not allowed in register list");
9273 if (load)
9275 if (mask & (1 << 14)
9276 && mask & (1 << 15))
9277 inst.error = _("LR and PC should not both be in register list");
9279 if ((mask & (1 << base)) != 0
9280 && writeback)
9281 as_warn (_("base register should not be in register list "
9282 "when written back"));
9284 else
9286 if (mask & (1 << 15))
9287 inst.error = _("PC not allowed in register list");
9289 if (mask & (1 << base))
9290 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9293 if ((mask & (mask - 1)) == 0)
9295 /* Single register transfers implemented as str/ldr. */
9296 if (writeback)
9298 if (inst.instruction & (1 << 23))
9299 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9300 else
9301 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9303 else
9305 if (inst.instruction & (1 << 23))
9306 inst.instruction = 0x00800000; /* ia -> [base] */
9307 else
9308 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9311 inst.instruction |= 0xf8400000;
9312 if (load)
9313 inst.instruction |= 0x00100000;
9315 mask = ffs (mask) - 1;
9316 mask <<= 12;
9318 else if (writeback)
9319 inst.instruction |= WRITE_BACK;
9321 inst.instruction |= mask;
9322 inst.instruction |= base << 16;
9325 static void
9326 do_t_ldmstm (void)
9328 /* This really doesn't seem worth it. */
9329 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9330 _("expression too complex"));
9331 constraint (inst.operands[1].writeback,
9332 _("Thumb load/store multiple does not support {reglist}^"));
9334 if (unified_syntax)
9336 bfd_boolean narrow;
9337 unsigned mask;
9339 narrow = FALSE;
9340 /* See if we can use a 16-bit instruction. */
9341 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9342 && inst.size_req != 4
9343 && !(inst.operands[1].imm & ~0xff))
9345 mask = 1 << inst.operands[0].reg;
9347 if (inst.operands[0].reg <= 7
9348 && (inst.instruction == T_MNEM_stmia
9349 ? inst.operands[0].writeback
9350 : (inst.operands[0].writeback
9351 == !(inst.operands[1].imm & mask))))
9353 if (inst.instruction == T_MNEM_stmia
9354 && (inst.operands[1].imm & mask)
9355 && (inst.operands[1].imm & (mask - 1)))
9356 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9357 inst.operands[0].reg);
9359 inst.instruction = THUMB_OP16 (inst.instruction);
9360 inst.instruction |= inst.operands[0].reg << 8;
9361 inst.instruction |= inst.operands[1].imm;
9362 narrow = TRUE;
9364 else if (inst.operands[0] .reg == REG_SP
9365 && inst.operands[0].writeback)
9367 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9368 ? T_MNEM_push : T_MNEM_pop);
9369 inst.instruction |= inst.operands[1].imm;
9370 narrow = TRUE;
9374 if (!narrow)
9376 if (inst.instruction < 0xffff)
9377 inst.instruction = THUMB_OP32 (inst.instruction);
9379 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9380 inst.operands[0].writeback);
9383 else
9385 constraint (inst.operands[0].reg > 7
9386 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9387 constraint (inst.instruction != T_MNEM_ldmia
9388 && inst.instruction != T_MNEM_stmia,
9389 _("Thumb-2 instruction only valid in unified syntax"));
9390 if (inst.instruction == T_MNEM_stmia)
9392 if (!inst.operands[0].writeback)
9393 as_warn (_("this instruction will write back the base register"));
9394 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9395 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9396 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9397 inst.operands[0].reg);
9399 else
9401 if (!inst.operands[0].writeback
9402 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9403 as_warn (_("this instruction will write back the base register"));
9404 else if (inst.operands[0].writeback
9405 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9406 as_warn (_("this instruction will not write back the base register"));
9409 inst.instruction = THUMB_OP16 (inst.instruction);
9410 inst.instruction |= inst.operands[0].reg << 8;
9411 inst.instruction |= inst.operands[1].imm;
9415 static void
9416 do_t_ldrex (void)
9418 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9419 || inst.operands[1].postind || inst.operands[1].writeback
9420 || inst.operands[1].immisreg || inst.operands[1].shifted
9421 || inst.operands[1].negative,
9422 BAD_ADDR_MODE);
9424 inst.instruction |= inst.operands[0].reg << 12;
9425 inst.instruction |= inst.operands[1].reg << 16;
9426 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9429 static void
9430 do_t_ldrexd (void)
9432 if (!inst.operands[1].present)
9434 constraint (inst.operands[0].reg == REG_LR,
9435 _("r14 not allowed as first register "
9436 "when second register is omitted"));
9437 inst.operands[1].reg = inst.operands[0].reg + 1;
9439 constraint (inst.operands[0].reg == inst.operands[1].reg,
9440 BAD_OVERLAP);
9442 inst.instruction |= inst.operands[0].reg << 12;
9443 inst.instruction |= inst.operands[1].reg << 8;
9444 inst.instruction |= inst.operands[2].reg << 16;
9447 static void
9448 do_t_ldst (void)
9450 unsigned long opcode;
9451 int Rn;
9453 opcode = inst.instruction;
9454 if (unified_syntax)
9456 if (!inst.operands[1].isreg)
9458 if (opcode <= 0xffff)
9459 inst.instruction = THUMB_OP32 (opcode);
9460 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9461 return;
9463 if (inst.operands[1].isreg
9464 && !inst.operands[1].writeback
9465 && !inst.operands[1].shifted && !inst.operands[1].postind
9466 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9467 && opcode <= 0xffff
9468 && inst.size_req != 4)
9470 /* Insn may have a 16-bit form. */
9471 Rn = inst.operands[1].reg;
9472 if (inst.operands[1].immisreg)
9474 inst.instruction = THUMB_OP16 (opcode);
9475 /* [Rn, Rik] */
9476 if (Rn <= 7 && inst.operands[1].imm <= 7)
9477 goto op16;
9479 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9480 && opcode != T_MNEM_ldrsb)
9481 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9482 || (Rn == REG_SP && opcode == T_MNEM_str))
9484 /* [Rn, #const] */
9485 if (Rn > 7)
9487 if (Rn == REG_PC)
9489 if (inst.reloc.pc_rel)
9490 opcode = T_MNEM_ldr_pc2;
9491 else
9492 opcode = T_MNEM_ldr_pc;
9494 else
9496 if (opcode == T_MNEM_ldr)
9497 opcode = T_MNEM_ldr_sp;
9498 else
9499 opcode = T_MNEM_str_sp;
9501 inst.instruction = inst.operands[0].reg << 8;
9503 else
9505 inst.instruction = inst.operands[0].reg;
9506 inst.instruction |= inst.operands[1].reg << 3;
9508 inst.instruction |= THUMB_OP16 (opcode);
9509 if (inst.size_req == 2)
9510 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9511 else
9512 inst.relax = opcode;
9513 return;
9516 /* Definitely a 32-bit variant. */
9517 inst.instruction = THUMB_OP32 (opcode);
9518 inst.instruction |= inst.operands[0].reg << 12;
9519 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9520 return;
9523 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9525 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9527 /* Only [Rn,Rm] is acceptable. */
9528 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9529 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9530 || inst.operands[1].postind || inst.operands[1].shifted
9531 || inst.operands[1].negative,
9532 _("Thumb does not support this addressing mode"));
9533 inst.instruction = THUMB_OP16 (inst.instruction);
9534 goto op16;
9537 inst.instruction = THUMB_OP16 (inst.instruction);
9538 if (!inst.operands[1].isreg)
9539 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9540 return;
9542 constraint (!inst.operands[1].preind
9543 || inst.operands[1].shifted
9544 || inst.operands[1].writeback,
9545 _("Thumb does not support this addressing mode"));
9546 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9548 constraint (inst.instruction & 0x0600,
9549 _("byte or halfword not valid for base register"));
9550 constraint (inst.operands[1].reg == REG_PC
9551 && !(inst.instruction & THUMB_LOAD_BIT),
9552 _("r15 based store not allowed"));
9553 constraint (inst.operands[1].immisreg,
9554 _("invalid base register for register offset"));
9556 if (inst.operands[1].reg == REG_PC)
9557 inst.instruction = T_OPCODE_LDR_PC;
9558 else if (inst.instruction & THUMB_LOAD_BIT)
9559 inst.instruction = T_OPCODE_LDR_SP;
9560 else
9561 inst.instruction = T_OPCODE_STR_SP;
9563 inst.instruction |= inst.operands[0].reg << 8;
9564 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9565 return;
9568 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9569 if (!inst.operands[1].immisreg)
9571 /* Immediate offset. */
9572 inst.instruction |= inst.operands[0].reg;
9573 inst.instruction |= inst.operands[1].reg << 3;
9574 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9575 return;
9578 /* Register offset. */
9579 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9580 constraint (inst.operands[1].negative,
9581 _("Thumb does not support this addressing mode"));
9583 op16:
9584 switch (inst.instruction)
9586 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9587 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9588 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9589 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9590 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9591 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9592 case 0x5600 /* ldrsb */:
9593 case 0x5e00 /* ldrsh */: break;
9594 default: abort ();
9597 inst.instruction |= inst.operands[0].reg;
9598 inst.instruction |= inst.operands[1].reg << 3;
9599 inst.instruction |= inst.operands[1].imm << 6;
9602 static void
9603 do_t_ldstd (void)
9605 if (!inst.operands[1].present)
9607 inst.operands[1].reg = inst.operands[0].reg + 1;
9608 constraint (inst.operands[0].reg == REG_LR,
9609 _("r14 not allowed here"));
9611 inst.instruction |= inst.operands[0].reg << 12;
9612 inst.instruction |= inst.operands[1].reg << 8;
9613 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9616 static void
9617 do_t_ldstt (void)
9619 inst.instruction |= inst.operands[0].reg << 12;
9620 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9623 static void
9624 do_t_mla (void)
9626 unsigned Rd, Rn, Rm, Ra;
9628 Rd = inst.operands[0].reg;
9629 Rn = inst.operands[1].reg;
9630 Rm = inst.operands[2].reg;
9631 Ra = inst.operands[3].reg;
9633 reject_bad_reg (Rd);
9634 reject_bad_reg (Rn);
9635 reject_bad_reg (Rm);
9636 reject_bad_reg (Ra);
9638 inst.instruction |= Rd << 8;
9639 inst.instruction |= Rn << 16;
9640 inst.instruction |= Rm;
9641 inst.instruction |= Ra << 12;
9644 static void
9645 do_t_mlal (void)
9647 unsigned RdLo, RdHi, Rn, Rm;
9649 RdLo = inst.operands[0].reg;
9650 RdHi = inst.operands[1].reg;
9651 Rn = inst.operands[2].reg;
9652 Rm = inst.operands[3].reg;
9654 reject_bad_reg (RdLo);
9655 reject_bad_reg (RdHi);
9656 reject_bad_reg (Rn);
9657 reject_bad_reg (Rm);
9659 inst.instruction |= RdLo << 12;
9660 inst.instruction |= RdHi << 8;
9661 inst.instruction |= Rn << 16;
9662 inst.instruction |= Rm;
9665 static void
9666 do_t_mov_cmp (void)
9668 unsigned Rn, Rm;
9670 Rn = inst.operands[0].reg;
9671 Rm = inst.operands[1].reg;
9673 if (unified_syntax)
9675 int r0off = (inst.instruction == T_MNEM_mov
9676 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9677 unsigned long opcode;
9678 bfd_boolean narrow;
9679 bfd_boolean low_regs;
9681 low_regs = (Rn <= 7 && Rm <= 7);
9682 opcode = inst.instruction;
9683 if (current_it_mask)
9684 narrow = opcode != T_MNEM_movs;
9685 else
9686 narrow = opcode != T_MNEM_movs || low_regs;
9687 if (inst.size_req == 4
9688 || inst.operands[1].shifted)
9689 narrow = FALSE;
9691 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9692 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9693 && !inst.operands[1].shifted
9694 && Rn == REG_PC
9695 && Rm == REG_LR)
9697 inst.instruction = T2_SUBS_PC_LR;
9698 return;
9701 if (opcode == T_MNEM_cmp)
9703 constraint (Rn == REG_PC, BAD_PC);
9704 if (narrow)
9706 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
9707 but valid. */
9708 warn_deprecated_sp (Rm);
9709 /* R15 was documented as a valid choice for Rm in ARMv6,
9710 but as UNPREDICTABLE in ARMv7. ARM's proprietary
9711 tools reject R15, so we do too. */
9712 constraint (Rm == REG_PC, BAD_PC);
9714 else
9715 reject_bad_reg (Rm);
9717 else if (opcode == T_MNEM_mov
9718 || opcode == T_MNEM_movs)
9720 if (inst.operands[1].isreg)
9722 if (opcode == T_MNEM_movs)
9724 reject_bad_reg (Rn);
9725 reject_bad_reg (Rm);
9727 else if ((Rn == REG_SP || Rn == REG_PC)
9728 && (Rm == REG_SP || Rm == REG_PC))
9729 reject_bad_reg (Rm);
9731 else
9732 reject_bad_reg (Rn);
9735 if (!inst.operands[1].isreg)
9737 /* Immediate operand. */
9738 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9739 narrow = 0;
9740 if (low_regs && narrow)
9742 inst.instruction = THUMB_OP16 (opcode);
9743 inst.instruction |= Rn << 8;
9744 if (inst.size_req == 2)
9745 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9746 else
9747 inst.relax = opcode;
9749 else
9751 inst.instruction = THUMB_OP32 (inst.instruction);
9752 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9753 inst.instruction |= Rn << r0off;
9754 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9757 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9758 && (inst.instruction == T_MNEM_mov
9759 || inst.instruction == T_MNEM_movs))
9761 /* Register shifts are encoded as separate shift instructions. */
9762 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9764 if (current_it_mask)
9765 narrow = !flags;
9766 else
9767 narrow = flags;
9769 if (inst.size_req == 4)
9770 narrow = FALSE;
9772 if (!low_regs || inst.operands[1].imm > 7)
9773 narrow = FALSE;
9775 if (Rn != Rm)
9776 narrow = FALSE;
9778 switch (inst.operands[1].shift_kind)
9780 case SHIFT_LSL:
9781 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9782 break;
9783 case SHIFT_ASR:
9784 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9785 break;
9786 case SHIFT_LSR:
9787 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9788 break;
9789 case SHIFT_ROR:
9790 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9791 break;
9792 default:
9793 abort ();
9796 inst.instruction = opcode;
9797 if (narrow)
9799 inst.instruction |= Rn;
9800 inst.instruction |= inst.operands[1].imm << 3;
9802 else
9804 if (flags)
9805 inst.instruction |= CONDS_BIT;
9807 inst.instruction |= Rn << 8;
9808 inst.instruction |= Rm << 16;
9809 inst.instruction |= inst.operands[1].imm;
9812 else if (!narrow)
9814 /* Some mov with immediate shift have narrow variants.
9815 Register shifts are handled above. */
9816 if (low_regs && inst.operands[1].shifted
9817 && (inst.instruction == T_MNEM_mov
9818 || inst.instruction == T_MNEM_movs))
9820 if (current_it_mask)
9821 narrow = (inst.instruction == T_MNEM_mov);
9822 else
9823 narrow = (inst.instruction == T_MNEM_movs);
9826 if (narrow)
9828 switch (inst.operands[1].shift_kind)
9830 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9831 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9832 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9833 default: narrow = FALSE; break;
9837 if (narrow)
9839 inst.instruction |= Rn;
9840 inst.instruction |= Rm << 3;
9841 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9843 else
9845 inst.instruction = THUMB_OP32 (inst.instruction);
9846 inst.instruction |= Rn << r0off;
9847 encode_thumb32_shifted_operand (1);
9850 else
9851 switch (inst.instruction)
9853 case T_MNEM_mov:
9854 inst.instruction = T_OPCODE_MOV_HR;
9855 inst.instruction |= (Rn & 0x8) << 4;
9856 inst.instruction |= (Rn & 0x7);
9857 inst.instruction |= Rm << 3;
9858 break;
9860 case T_MNEM_movs:
9861 /* We know we have low registers at this point.
9862 Generate ADD Rd, Rs, #0. */
9863 inst.instruction = T_OPCODE_ADD_I3;
9864 inst.instruction |= Rn;
9865 inst.instruction |= Rm << 3;
9866 break;
9868 case T_MNEM_cmp:
9869 if (low_regs)
9871 inst.instruction = T_OPCODE_CMP_LR;
9872 inst.instruction |= Rn;
9873 inst.instruction |= Rm << 3;
9875 else
9877 inst.instruction = T_OPCODE_CMP_HR;
9878 inst.instruction |= (Rn & 0x8) << 4;
9879 inst.instruction |= (Rn & 0x7);
9880 inst.instruction |= Rm << 3;
9882 break;
9884 return;
9887 inst.instruction = THUMB_OP16 (inst.instruction);
9888 if (inst.operands[1].isreg)
9890 if (Rn < 8 && Rm < 8)
9892 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9893 since a MOV instruction produces unpredictable results. */
9894 if (inst.instruction == T_OPCODE_MOV_I8)
9895 inst.instruction = T_OPCODE_ADD_I3;
9896 else
9897 inst.instruction = T_OPCODE_CMP_LR;
9899 inst.instruction |= Rn;
9900 inst.instruction |= Rm << 3;
9902 else
9904 if (inst.instruction == T_OPCODE_MOV_I8)
9905 inst.instruction = T_OPCODE_MOV_HR;
9906 else
9907 inst.instruction = T_OPCODE_CMP_HR;
9908 do_t_cpy ();
9911 else
9913 constraint (Rn > 7,
9914 _("only lo regs allowed with immediate"));
9915 inst.instruction |= Rn << 8;
9916 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9920 static void
9921 do_t_mov16 (void)
9923 unsigned Rd;
9924 bfd_vma imm;
9925 bfd_boolean top;
9927 top = (inst.instruction & 0x00800000) != 0;
9928 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9930 constraint (top, _(":lower16: not allowed this instruction"));
9931 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9933 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9935 constraint (!top, _(":upper16: not allowed this instruction"));
9936 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9939 Rd = inst.operands[0].reg;
9940 reject_bad_reg (Rd);
9942 inst.instruction |= Rd << 8;
9943 if (inst.reloc.type == BFD_RELOC_UNUSED)
9945 imm = inst.reloc.exp.X_add_number;
9946 inst.instruction |= (imm & 0xf000) << 4;
9947 inst.instruction |= (imm & 0x0800) << 15;
9948 inst.instruction |= (imm & 0x0700) << 4;
9949 inst.instruction |= (imm & 0x00ff);
9953 static void
9954 do_t_mvn_tst (void)
9956 unsigned Rn, Rm;
9958 Rn = inst.operands[0].reg;
9959 Rm = inst.operands[1].reg;
9961 if (inst.instruction == T_MNEM_cmp
9962 || inst.instruction == T_MNEM_cmn)
9963 constraint (Rn == REG_PC, BAD_PC);
9964 else
9965 reject_bad_reg (Rn);
9966 reject_bad_reg (Rm);
9968 if (unified_syntax)
9970 int r0off = (inst.instruction == T_MNEM_mvn
9971 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9972 bfd_boolean narrow;
9974 if (inst.size_req == 4
9975 || inst.instruction > 0xffff
9976 || inst.operands[1].shifted
9977 || Rn > 7 || Rm > 7)
9978 narrow = FALSE;
9979 else if (inst.instruction == T_MNEM_cmn)
9980 narrow = TRUE;
9981 else if (THUMB_SETS_FLAGS (inst.instruction))
9982 narrow = (current_it_mask == 0);
9983 else
9984 narrow = (current_it_mask != 0);
9986 if (!inst.operands[1].isreg)
9988 /* For an immediate, we always generate a 32-bit opcode;
9989 section relaxation will shrink it later if possible. */
9990 if (inst.instruction < 0xffff)
9991 inst.instruction = THUMB_OP32 (inst.instruction);
9992 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9993 inst.instruction |= Rn << r0off;
9994 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9996 else
9998 /* See if we can do this with a 16-bit instruction. */
9999 if (narrow)
10001 inst.instruction = THUMB_OP16 (inst.instruction);
10002 inst.instruction |= Rn;
10003 inst.instruction |= Rm << 3;
10005 else
10007 constraint (inst.operands[1].shifted
10008 && inst.operands[1].immisreg,
10009 _("shift must be constant"));
10010 if (inst.instruction < 0xffff)
10011 inst.instruction = THUMB_OP32 (inst.instruction);
10012 inst.instruction |= Rn << r0off;
10013 encode_thumb32_shifted_operand (1);
10017 else
10019 constraint (inst.instruction > 0xffff
10020 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10021 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10022 _("unshifted register required"));
10023 constraint (Rn > 7 || Rm > 7,
10024 BAD_HIREG);
10026 inst.instruction = THUMB_OP16 (inst.instruction);
10027 inst.instruction |= Rn;
10028 inst.instruction |= Rm << 3;
10032 static void
10033 do_t_mrs (void)
10035 unsigned Rd;
10036 int flags;
10038 if (do_vfp_nsyn_mrs () == SUCCESS)
10039 return;
10041 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10042 if (flags == 0)
10044 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10045 _("selected processor does not support "
10046 "requested special purpose register"));
10048 else
10050 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10051 _("selected processor does not support "
10052 "requested special purpose register"));
10053 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10054 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10055 _("'CPSR' or 'SPSR' expected"));
10058 Rd = inst.operands[0].reg;
10059 reject_bad_reg (Rd);
10061 inst.instruction |= Rd << 8;
10062 inst.instruction |= (flags & SPSR_BIT) >> 2;
10063 inst.instruction |= inst.operands[1].imm & 0xff;
10066 static void
10067 do_t_msr (void)
10069 int flags;
10070 unsigned Rn;
10072 if (do_vfp_nsyn_msr () == SUCCESS)
10073 return;
10075 constraint (!inst.operands[1].isreg,
10076 _("Thumb encoding does not support an immediate here"));
10077 flags = inst.operands[0].imm;
10078 if (flags & ~0xff)
10080 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10081 _("selected processor does not support "
10082 "requested special purpose register"));
10084 else
10086 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10087 _("selected processor does not support "
10088 "requested special purpose register"));
10089 flags |= PSR_f;
10092 Rn = inst.operands[1].reg;
10093 reject_bad_reg (Rn);
10095 inst.instruction |= (flags & SPSR_BIT) >> 2;
10096 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10097 inst.instruction |= (flags & 0xff);
10098 inst.instruction |= Rn << 16;
10101 static void
10102 do_t_mul (void)
10104 bfd_boolean narrow;
10105 unsigned Rd, Rn, Rm;
10107 if (!inst.operands[2].present)
10108 inst.operands[2].reg = inst.operands[0].reg;
10110 Rd = inst.operands[0].reg;
10111 Rn = inst.operands[1].reg;
10112 Rm = inst.operands[2].reg;
10114 if (unified_syntax)
10116 if (inst.size_req == 4
10117 || (Rd != Rn
10118 && Rd != Rm)
10119 || Rn > 7
10120 || Rm > 7)
10121 narrow = FALSE;
10122 else if (inst.instruction == T_MNEM_muls)
10123 narrow = (current_it_mask == 0);
10124 else
10125 narrow = (current_it_mask != 0);
10127 else
10129 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
10130 constraint (Rn > 7 || Rm > 7,
10131 BAD_HIREG);
10132 narrow = TRUE;
10135 if (narrow)
10137 /* 16-bit MULS/Conditional MUL. */
10138 inst.instruction = THUMB_OP16 (inst.instruction);
10139 inst.instruction |= Rd;
10141 if (Rd == Rn)
10142 inst.instruction |= Rm << 3;
10143 else if (Rd == Rm)
10144 inst.instruction |= Rn << 3;
10145 else
10146 constraint (1, _("dest must overlap one source register"));
10148 else
10150 constraint(inst.instruction != T_MNEM_mul,
10151 _("Thumb-2 MUL must not set flags"));
10152 /* 32-bit MUL. */
10153 inst.instruction = THUMB_OP32 (inst.instruction);
10154 inst.instruction |= Rd << 8;
10155 inst.instruction |= Rn << 16;
10156 inst.instruction |= Rm << 0;
10158 reject_bad_reg (Rd);
10159 reject_bad_reg (Rn);
10160 reject_bad_reg (Rm);
10164 static void
10165 do_t_mull (void)
10167 unsigned RdLo, RdHi, Rn, Rm;
10169 RdLo = inst.operands[0].reg;
10170 RdHi = inst.operands[1].reg;
10171 Rn = inst.operands[2].reg;
10172 Rm = inst.operands[3].reg;
10174 reject_bad_reg (RdLo);
10175 reject_bad_reg (RdHi);
10176 reject_bad_reg (Rn);
10177 reject_bad_reg (Rm);
10179 inst.instruction |= RdLo << 12;
10180 inst.instruction |= RdHi << 8;
10181 inst.instruction |= Rn << 16;
10182 inst.instruction |= Rm;
10184 if (RdLo == RdHi)
10185 as_tsktsk (_("rdhi and rdlo must be different"));
10188 static void
10189 do_t_nop (void)
10191 if (unified_syntax)
10193 if (inst.size_req == 4 || inst.operands[0].imm > 15)
10195 inst.instruction = THUMB_OP32 (inst.instruction);
10196 inst.instruction |= inst.operands[0].imm;
10198 else
10200 /* PR9722: Check for Thumb2 availability before
10201 generating a thumb2 nop instruction. */
10202 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
10204 inst.instruction = THUMB_OP16 (inst.instruction);
10205 inst.instruction |= inst.operands[0].imm << 4;
10207 else
10208 inst.instruction = 0x46c0;
10211 else
10213 constraint (inst.operands[0].present,
10214 _("Thumb does not support NOP with hints"));
10215 inst.instruction = 0x46c0;
10219 static void
10220 do_t_neg (void)
10222 if (unified_syntax)
10224 bfd_boolean narrow;
10226 if (THUMB_SETS_FLAGS (inst.instruction))
10227 narrow = (current_it_mask == 0);
10228 else
10229 narrow = (current_it_mask != 0);
10230 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10231 narrow = FALSE;
10232 if (inst.size_req == 4)
10233 narrow = FALSE;
10235 if (!narrow)
10237 inst.instruction = THUMB_OP32 (inst.instruction);
10238 inst.instruction |= inst.operands[0].reg << 8;
10239 inst.instruction |= inst.operands[1].reg << 16;
10241 else
10243 inst.instruction = THUMB_OP16 (inst.instruction);
10244 inst.instruction |= inst.operands[0].reg;
10245 inst.instruction |= inst.operands[1].reg << 3;
10248 else
10250 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10251 BAD_HIREG);
10252 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10254 inst.instruction = THUMB_OP16 (inst.instruction);
10255 inst.instruction |= inst.operands[0].reg;
10256 inst.instruction |= inst.operands[1].reg << 3;
10260 static void
10261 do_t_orn (void)
10263 unsigned Rd, Rn;
10265 Rd = inst.operands[0].reg;
10266 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10268 reject_bad_reg (Rd);
10269 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10270 reject_bad_reg (Rn);
10272 inst.instruction |= Rd << 8;
10273 inst.instruction |= Rn << 16;
10275 if (!inst.operands[2].isreg)
10277 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10278 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10280 else
10282 unsigned Rm;
10284 Rm = inst.operands[2].reg;
10285 reject_bad_reg (Rm);
10287 constraint (inst.operands[2].shifted
10288 && inst.operands[2].immisreg,
10289 _("shift must be constant"));
10290 encode_thumb32_shifted_operand (2);
10294 static void
10295 do_t_pkhbt (void)
10297 unsigned Rd, Rn, Rm;
10299 Rd = inst.operands[0].reg;
10300 Rn = inst.operands[1].reg;
10301 Rm = inst.operands[2].reg;
10303 reject_bad_reg (Rd);
10304 reject_bad_reg (Rn);
10305 reject_bad_reg (Rm);
10307 inst.instruction |= Rd << 8;
10308 inst.instruction |= Rn << 16;
10309 inst.instruction |= Rm;
10310 if (inst.operands[3].present)
10312 unsigned int val = inst.reloc.exp.X_add_number;
10313 constraint (inst.reloc.exp.X_op != O_constant,
10314 _("expression too complex"));
10315 inst.instruction |= (val & 0x1c) << 10;
10316 inst.instruction |= (val & 0x03) << 6;
10320 static void
10321 do_t_pkhtb (void)
10323 if (!inst.operands[3].present)
10324 inst.instruction &= ~0x00000020;
10325 do_t_pkhbt ();
10328 static void
10329 do_t_pld (void)
10331 if (inst.operands[0].immisreg)
10332 reject_bad_reg (inst.operands[0].imm);
10334 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10337 static void
10338 do_t_push_pop (void)
10340 unsigned mask;
10342 constraint (inst.operands[0].writeback,
10343 _("push/pop do not support {reglist}^"));
10344 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10345 _("expression too complex"));
10347 mask = inst.operands[0].imm;
10348 if ((mask & ~0xff) == 0)
10349 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10350 else if ((inst.instruction == T_MNEM_push
10351 && (mask & ~0xff) == 1 << REG_LR)
10352 || (inst.instruction == T_MNEM_pop
10353 && (mask & ~0xff) == 1 << REG_PC))
10355 inst.instruction = THUMB_OP16 (inst.instruction);
10356 inst.instruction |= THUMB_PP_PC_LR;
10357 inst.instruction |= mask & 0xff;
10359 else if (unified_syntax)
10361 inst.instruction = THUMB_OP32 (inst.instruction);
10362 encode_thumb2_ldmstm (13, mask, TRUE);
10364 else
10366 inst.error = _("invalid register list to push/pop instruction");
10367 return;
10371 static void
10372 do_t_rbit (void)
10374 unsigned Rd, Rm;
10376 Rd = inst.operands[0].reg;
10377 Rm = inst.operands[1].reg;
10379 reject_bad_reg (Rd);
10380 reject_bad_reg (Rm);
10382 inst.instruction |= Rd << 8;
10383 inst.instruction |= Rm << 16;
10384 inst.instruction |= Rm;
10387 static void
10388 do_t_rev (void)
10390 unsigned Rd, Rm;
10392 Rd = inst.operands[0].reg;
10393 Rm = inst.operands[1].reg;
10395 reject_bad_reg (Rd);
10396 reject_bad_reg (Rm);
10398 if (Rd <= 7 && Rm <= 7
10399 && inst.size_req != 4)
10401 inst.instruction = THUMB_OP16 (inst.instruction);
10402 inst.instruction |= Rd;
10403 inst.instruction |= Rm << 3;
10405 else if (unified_syntax)
10407 inst.instruction = THUMB_OP32 (inst.instruction);
10408 inst.instruction |= Rd << 8;
10409 inst.instruction |= Rm << 16;
10410 inst.instruction |= Rm;
10412 else
10413 inst.error = BAD_HIREG;
10416 static void
10417 do_t_rrx (void)
10419 unsigned Rd, Rm;
10421 Rd = inst.operands[0].reg;
10422 Rm = inst.operands[1].reg;
10424 reject_bad_reg (Rd);
10425 reject_bad_reg (Rm);
10427 inst.instruction |= Rd << 8;
10428 inst.instruction |= Rm;
10431 static void
10432 do_t_rsb (void)
10434 unsigned Rd, Rs;
10436 Rd = inst.operands[0].reg;
10437 Rs = (inst.operands[1].present
10438 ? inst.operands[1].reg /* Rd, Rs, foo */
10439 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10441 reject_bad_reg (Rd);
10442 reject_bad_reg (Rs);
10443 if (inst.operands[2].isreg)
10444 reject_bad_reg (inst.operands[2].reg);
10446 inst.instruction |= Rd << 8;
10447 inst.instruction |= Rs << 16;
10448 if (!inst.operands[2].isreg)
10450 bfd_boolean narrow;
10452 if ((inst.instruction & 0x00100000) != 0)
10453 narrow = (current_it_mask == 0);
10454 else
10455 narrow = (current_it_mask != 0);
10457 if (Rd > 7 || Rs > 7)
10458 narrow = FALSE;
10460 if (inst.size_req == 4 || !unified_syntax)
10461 narrow = FALSE;
10463 if (inst.reloc.exp.X_op != O_constant
10464 || inst.reloc.exp.X_add_number != 0)
10465 narrow = FALSE;
10467 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10468 relaxation, but it doesn't seem worth the hassle. */
10469 if (narrow)
10471 inst.reloc.type = BFD_RELOC_UNUSED;
10472 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10473 inst.instruction |= Rs << 3;
10474 inst.instruction |= Rd;
10476 else
10478 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10479 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10482 else
10483 encode_thumb32_shifted_operand (2);
10486 static void
10487 do_t_setend (void)
10489 constraint (current_it_mask, BAD_NOT_IT);
10490 if (inst.operands[0].imm)
10491 inst.instruction |= 0x8;
10494 static void
10495 do_t_shift (void)
10497 if (!inst.operands[1].present)
10498 inst.operands[1].reg = inst.operands[0].reg;
10500 if (unified_syntax)
10502 bfd_boolean narrow;
10503 int shift_kind;
10505 switch (inst.instruction)
10507 case T_MNEM_asr:
10508 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10509 case T_MNEM_lsl:
10510 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10511 case T_MNEM_lsr:
10512 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10513 case T_MNEM_ror:
10514 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10515 default: abort ();
10518 if (THUMB_SETS_FLAGS (inst.instruction))
10519 narrow = (current_it_mask == 0);
10520 else
10521 narrow = (current_it_mask != 0);
10522 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10523 narrow = FALSE;
10524 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10525 narrow = FALSE;
10526 if (inst.operands[2].isreg
10527 && (inst.operands[1].reg != inst.operands[0].reg
10528 || inst.operands[2].reg > 7))
10529 narrow = FALSE;
10530 if (inst.size_req == 4)
10531 narrow = FALSE;
10533 reject_bad_reg (inst.operands[0].reg);
10534 reject_bad_reg (inst.operands[1].reg);
10536 if (!narrow)
10538 if (inst.operands[2].isreg)
10540 reject_bad_reg (inst.operands[2].reg);
10541 inst.instruction = THUMB_OP32 (inst.instruction);
10542 inst.instruction |= inst.operands[0].reg << 8;
10543 inst.instruction |= inst.operands[1].reg << 16;
10544 inst.instruction |= inst.operands[2].reg;
10546 else
10548 inst.operands[1].shifted = 1;
10549 inst.operands[1].shift_kind = shift_kind;
10550 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10551 ? T_MNEM_movs : T_MNEM_mov);
10552 inst.instruction |= inst.operands[0].reg << 8;
10553 encode_thumb32_shifted_operand (1);
10554 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10555 inst.reloc.type = BFD_RELOC_UNUSED;
10558 else
10560 if (inst.operands[2].isreg)
10562 switch (shift_kind)
10564 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10565 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10566 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10567 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
10568 default: abort ();
10571 inst.instruction |= inst.operands[0].reg;
10572 inst.instruction |= inst.operands[2].reg << 3;
10574 else
10576 switch (shift_kind)
10578 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10579 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10580 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10581 default: abort ();
10583 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10584 inst.instruction |= inst.operands[0].reg;
10585 inst.instruction |= inst.operands[1].reg << 3;
10589 else
10591 constraint (inst.operands[0].reg > 7
10592 || inst.operands[1].reg > 7, BAD_HIREG);
10593 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10595 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10597 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10598 constraint (inst.operands[0].reg != inst.operands[1].reg,
10599 _("source1 and dest must be same register"));
10601 switch (inst.instruction)
10603 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10604 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10605 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10606 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10607 default: abort ();
10610 inst.instruction |= inst.operands[0].reg;
10611 inst.instruction |= inst.operands[2].reg << 3;
10613 else
10615 switch (inst.instruction)
10617 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10618 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10619 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10620 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10621 default: abort ();
10623 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10624 inst.instruction |= inst.operands[0].reg;
10625 inst.instruction |= inst.operands[1].reg << 3;
10630 static void
10631 do_t_simd (void)
10633 unsigned Rd, Rn, Rm;
10635 Rd = inst.operands[0].reg;
10636 Rn = inst.operands[1].reg;
10637 Rm = inst.operands[2].reg;
10639 reject_bad_reg (Rd);
10640 reject_bad_reg (Rn);
10641 reject_bad_reg (Rm);
10643 inst.instruction |= Rd << 8;
10644 inst.instruction |= Rn << 16;
10645 inst.instruction |= Rm;
10648 static void
10649 do_t_smc (void)
10651 unsigned int value = inst.reloc.exp.X_add_number;
10652 constraint (inst.reloc.exp.X_op != O_constant,
10653 _("expression too complex"));
10654 inst.reloc.type = BFD_RELOC_UNUSED;
10655 inst.instruction |= (value & 0xf000) >> 12;
10656 inst.instruction |= (value & 0x0ff0);
10657 inst.instruction |= (value & 0x000f) << 16;
10660 static void
10661 do_t_ssat (void)
10663 unsigned Rd, Rn;
10665 Rd = inst.operands[0].reg;
10666 Rn = inst.operands[2].reg;
10668 reject_bad_reg (Rd);
10669 reject_bad_reg (Rn);
10671 inst.instruction |= Rd << 8;
10672 inst.instruction |= inst.operands[1].imm - 1;
10673 inst.instruction |= Rn << 16;
10675 if (inst.operands[3].present)
10677 constraint (inst.reloc.exp.X_op != O_constant,
10678 _("expression too complex"));
10680 if (inst.reloc.exp.X_add_number != 0)
10682 if (inst.operands[3].shift_kind == SHIFT_ASR)
10683 inst.instruction |= 0x00200000; /* sh bit */
10684 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10685 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10687 inst.reloc.type = BFD_RELOC_UNUSED;
10691 static void
10692 do_t_ssat16 (void)
10694 unsigned Rd, Rn;
10696 Rd = inst.operands[0].reg;
10697 Rn = inst.operands[2].reg;
10699 reject_bad_reg (Rd);
10700 reject_bad_reg (Rn);
10702 inst.instruction |= Rd << 8;
10703 inst.instruction |= inst.operands[1].imm - 1;
10704 inst.instruction |= Rn << 16;
10707 static void
10708 do_t_strex (void)
10710 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10711 || inst.operands[2].postind || inst.operands[2].writeback
10712 || inst.operands[2].immisreg || inst.operands[2].shifted
10713 || inst.operands[2].negative,
10714 BAD_ADDR_MODE);
10716 inst.instruction |= inst.operands[0].reg << 8;
10717 inst.instruction |= inst.operands[1].reg << 12;
10718 inst.instruction |= inst.operands[2].reg << 16;
10719 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10722 static void
10723 do_t_strexd (void)
10725 if (!inst.operands[2].present)
10726 inst.operands[2].reg = inst.operands[1].reg + 1;
10728 constraint (inst.operands[0].reg == inst.operands[1].reg
10729 || inst.operands[0].reg == inst.operands[2].reg
10730 || inst.operands[0].reg == inst.operands[3].reg
10731 || inst.operands[1].reg == inst.operands[2].reg,
10732 BAD_OVERLAP);
10734 inst.instruction |= inst.operands[0].reg;
10735 inst.instruction |= inst.operands[1].reg << 12;
10736 inst.instruction |= inst.operands[2].reg << 8;
10737 inst.instruction |= inst.operands[3].reg << 16;
10740 static void
10741 do_t_sxtah (void)
10743 unsigned Rd, Rn, Rm;
10745 Rd = inst.operands[0].reg;
10746 Rn = inst.operands[1].reg;
10747 Rm = inst.operands[2].reg;
10749 reject_bad_reg (Rd);
10750 reject_bad_reg (Rn);
10751 reject_bad_reg (Rm);
10753 inst.instruction |= Rd << 8;
10754 inst.instruction |= Rn << 16;
10755 inst.instruction |= Rm;
10756 inst.instruction |= inst.operands[3].imm << 4;
10759 static void
10760 do_t_sxth (void)
10762 unsigned Rd, Rm;
10764 Rd = inst.operands[0].reg;
10765 Rm = inst.operands[1].reg;
10767 reject_bad_reg (Rd);
10768 reject_bad_reg (Rm);
10770 if (inst.instruction <= 0xffff && inst.size_req != 4
10771 && Rd <= 7 && Rm <= 7
10772 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10774 inst.instruction = THUMB_OP16 (inst.instruction);
10775 inst.instruction |= Rd;
10776 inst.instruction |= Rm << 3;
10778 else if (unified_syntax)
10780 if (inst.instruction <= 0xffff)
10781 inst.instruction = THUMB_OP32 (inst.instruction);
10782 inst.instruction |= Rd << 8;
10783 inst.instruction |= Rm;
10784 inst.instruction |= inst.operands[2].imm << 4;
10786 else
10788 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10789 _("Thumb encoding does not support rotation"));
10790 constraint (1, BAD_HIREG);
10794 static void
10795 do_t_swi (void)
10797 inst.reloc.type = BFD_RELOC_ARM_SWI;
10800 static void
10801 do_t_tb (void)
10803 unsigned Rn, Rm;
10804 int half;
10806 half = (inst.instruction & 0x10) != 0;
10807 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10808 constraint (inst.operands[0].immisreg,
10809 _("instruction requires register index"));
10811 Rn = inst.operands[0].reg;
10812 Rm = inst.operands[0].imm;
10814 constraint (Rn == REG_SP, BAD_SP);
10815 reject_bad_reg (Rm);
10817 constraint (!half && inst.operands[0].shifted,
10818 _("instruction does not allow shifted index"));
10819 inst.instruction |= (Rn << 16) | Rm;
10822 static void
10823 do_t_usat (void)
10825 unsigned Rd, Rn;
10827 Rd = inst.operands[0].reg;
10828 Rn = inst.operands[2].reg;
10830 reject_bad_reg (Rd);
10831 reject_bad_reg (Rn);
10833 inst.instruction |= Rd << 8;
10834 inst.instruction |= inst.operands[1].imm;
10835 inst.instruction |= Rn << 16;
10837 if (inst.operands[3].present)
10839 constraint (inst.reloc.exp.X_op != O_constant,
10840 _("expression too complex"));
10841 if (inst.reloc.exp.X_add_number != 0)
10843 if (inst.operands[3].shift_kind == SHIFT_ASR)
10844 inst.instruction |= 0x00200000; /* sh bit */
10846 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10847 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10849 inst.reloc.type = BFD_RELOC_UNUSED;
10853 static void
10854 do_t_usat16 (void)
10856 unsigned Rd, Rn;
10858 Rd = inst.operands[0].reg;
10859 Rn = inst.operands[2].reg;
10861 reject_bad_reg (Rd);
10862 reject_bad_reg (Rn);
10864 inst.instruction |= Rd << 8;
10865 inst.instruction |= inst.operands[1].imm;
10866 inst.instruction |= Rn << 16;
10869 /* Neon instruction encoder helpers. */
10871 /* Encodings for the different types for various Neon opcodes. */
10873 /* An "invalid" code for the following tables. */
10874 #define N_INV -1u
10876 struct neon_tab_entry
10878 unsigned integer;
10879 unsigned float_or_poly;
10880 unsigned scalar_or_imm;
10883 /* Map overloaded Neon opcodes to their respective encodings. */
10884 #define NEON_ENC_TAB \
10885 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10886 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10887 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10888 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10889 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10890 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10891 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10892 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10893 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10894 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10895 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10896 /* Register variants of the following two instructions are encoded as
10897 vcge / vcgt with the operands reversed. */ \
10898 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10899 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
10900 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10901 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10902 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10903 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10904 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10905 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10906 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10907 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10908 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10909 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10910 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10911 X(vshl, 0x0000400, N_INV, 0x0800510), \
10912 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10913 X(vand, 0x0000110, N_INV, 0x0800030), \
10914 X(vbic, 0x0100110, N_INV, 0x0800030), \
10915 X(veor, 0x1000110, N_INV, N_INV), \
10916 X(vorn, 0x0300110, N_INV, 0x0800010), \
10917 X(vorr, 0x0200110, N_INV, 0x0800010), \
10918 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10919 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10920 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10921 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10922 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10923 X(vst1, 0x0000000, 0x0800000, N_INV), \
10924 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10925 X(vst2, 0x0000100, 0x0800100, N_INV), \
10926 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10927 X(vst3, 0x0000200, 0x0800200, N_INV), \
10928 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10929 X(vst4, 0x0000300, 0x0800300, N_INV), \
10930 X(vmovn, 0x1b20200, N_INV, N_INV), \
10931 X(vtrn, 0x1b20080, N_INV, N_INV), \
10932 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10933 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10934 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10935 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10936 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10937 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10938 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10939 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10940 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10942 enum neon_opc
10944 #define X(OPC,I,F,S) N_MNEM_##OPC
10945 NEON_ENC_TAB
10946 #undef X
10949 static const struct neon_tab_entry neon_enc_tab[] =
10951 #define X(OPC,I,F,S) { (I), (F), (S) }
10952 NEON_ENC_TAB
10953 #undef X
10956 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10957 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10958 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10959 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10960 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10961 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10962 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10963 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10964 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10965 #define NEON_ENC_SINGLE(X) \
10966 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10967 #define NEON_ENC_DOUBLE(X) \
10968 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10970 /* Define shapes for instruction operands. The following mnemonic characters
10971 are used in this table:
10973 F - VFP S<n> register
10974 D - Neon D<n> register
10975 Q - Neon Q<n> register
10976 I - Immediate
10977 S - Scalar
10978 R - ARM register
10979 L - D<n> register list
10981 This table is used to generate various data:
10982 - enumerations of the form NS_DDR to be used as arguments to
10983 neon_select_shape.
10984 - a table classifying shapes into single, double, quad, mixed.
10985 - a table used to drive neon_select_shape. */
10987 #define NEON_SHAPE_DEF \
10988 X(3, (D, D, D), DOUBLE), \
10989 X(3, (Q, Q, Q), QUAD), \
10990 X(3, (D, D, I), DOUBLE), \
10991 X(3, (Q, Q, I), QUAD), \
10992 X(3, (D, D, S), DOUBLE), \
10993 X(3, (Q, Q, S), QUAD), \
10994 X(2, (D, D), DOUBLE), \
10995 X(2, (Q, Q), QUAD), \
10996 X(2, (D, S), DOUBLE), \
10997 X(2, (Q, S), QUAD), \
10998 X(2, (D, R), DOUBLE), \
10999 X(2, (Q, R), QUAD), \
11000 X(2, (D, I), DOUBLE), \
11001 X(2, (Q, I), QUAD), \
11002 X(3, (D, L, D), DOUBLE), \
11003 X(2, (D, Q), MIXED), \
11004 X(2, (Q, D), MIXED), \
11005 X(3, (D, Q, I), MIXED), \
11006 X(3, (Q, D, I), MIXED), \
11007 X(3, (Q, D, D), MIXED), \
11008 X(3, (D, Q, Q), MIXED), \
11009 X(3, (Q, Q, D), MIXED), \
11010 X(3, (Q, D, S), MIXED), \
11011 X(3, (D, Q, S), MIXED), \
11012 X(4, (D, D, D, I), DOUBLE), \
11013 X(4, (Q, Q, Q, I), QUAD), \
11014 X(2, (F, F), SINGLE), \
11015 X(3, (F, F, F), SINGLE), \
11016 X(2, (F, I), SINGLE), \
11017 X(2, (F, D), MIXED), \
11018 X(2, (D, F), MIXED), \
11019 X(3, (F, F, I), MIXED), \
11020 X(4, (R, R, F, F), SINGLE), \
11021 X(4, (F, F, R, R), SINGLE), \
11022 X(3, (D, R, R), DOUBLE), \
11023 X(3, (R, R, D), DOUBLE), \
11024 X(2, (S, R), SINGLE), \
11025 X(2, (R, S), SINGLE), \
11026 X(2, (F, R), SINGLE), \
11027 X(2, (R, F), SINGLE)
11029 #define S2(A,B) NS_##A##B
11030 #define S3(A,B,C) NS_##A##B##C
11031 #define S4(A,B,C,D) NS_##A##B##C##D
11033 #define X(N, L, C) S##N L
11035 enum neon_shape
11037 NEON_SHAPE_DEF,
11038 NS_NULL
11041 #undef X
11042 #undef S2
11043 #undef S3
11044 #undef S4
11046 enum neon_shape_class
11048 SC_SINGLE,
11049 SC_DOUBLE,
11050 SC_QUAD,
11051 SC_MIXED
11054 #define X(N, L, C) SC_##C
11056 static enum neon_shape_class neon_shape_class[] =
11058 NEON_SHAPE_DEF
11061 #undef X
11063 enum neon_shape_el
11065 SE_F,
11066 SE_D,
11067 SE_Q,
11068 SE_I,
11069 SE_S,
11070 SE_R,
11071 SE_L
11074 /* Register widths of above. */
11075 static unsigned neon_shape_el_size[] =
11079 128,
11086 struct neon_shape_info
11088 unsigned els;
11089 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11092 #define S2(A,B) { SE_##A, SE_##B }
11093 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11094 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11096 #define X(N, L, C) { N, S##N L }
11098 static struct neon_shape_info neon_shape_tab[] =
11100 NEON_SHAPE_DEF
11103 #undef X
11104 #undef S2
11105 #undef S3
11106 #undef S4
11108 /* Bit masks used in type checking given instructions.
11109 'N_EQK' means the type must be the same as (or based on in some way) the key
11110 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11111 set, various other bits can be set as well in order to modify the meaning of
11112 the type constraint. */
11114 enum neon_type_mask
11116 N_S8 = 0x0000001,
11117 N_S16 = 0x0000002,
11118 N_S32 = 0x0000004,
11119 N_S64 = 0x0000008,
11120 N_U8 = 0x0000010,
11121 N_U16 = 0x0000020,
11122 N_U32 = 0x0000040,
11123 N_U64 = 0x0000080,
11124 N_I8 = 0x0000100,
11125 N_I16 = 0x0000200,
11126 N_I32 = 0x0000400,
11127 N_I64 = 0x0000800,
11128 N_8 = 0x0001000,
11129 N_16 = 0x0002000,
11130 N_32 = 0x0004000,
11131 N_64 = 0x0008000,
11132 N_P8 = 0x0010000,
11133 N_P16 = 0x0020000,
11134 N_F16 = 0x0040000,
11135 N_F32 = 0x0080000,
11136 N_F64 = 0x0100000,
11137 N_KEY = 0x1000000, /* key element (main type specifier). */
11138 N_EQK = 0x2000000, /* given operand has the same type & size as the key. */
11139 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11140 N_DBL = 0x0000001, /* if N_EQK, this operand is twice the size. */
11141 N_HLF = 0x0000002, /* if N_EQK, this operand is half the size. */
11142 N_SGN = 0x0000004, /* if N_EQK, this operand is forced to be signed. */
11143 N_UNS = 0x0000008, /* if N_EQK, this operand is forced to be unsigned. */
11144 N_INT = 0x0000010, /* if N_EQK, this operand is forced to be integer. */
11145 N_FLT = 0x0000020, /* if N_EQK, this operand is forced to be float. */
11146 N_SIZ = 0x0000040, /* if N_EQK, this operand is forced to be size-only. */
11147 N_UTYP = 0,
11148 N_MAX_NONSPECIAL = N_F64
11151 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11153 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11154 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11155 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11156 #define N_SUF_32 (N_SU_32 | N_F32)
11157 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11158 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11160 /* Pass this as the first type argument to neon_check_type to ignore types
11161 altogether. */
11162 #define N_IGNORE_TYPE (N_KEY | N_EQK)
11164 /* Select a "shape" for the current instruction (describing register types or
11165 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11166 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11167 function of operand parsing, so this function doesn't need to be called.
11168 Shapes should be listed in order of decreasing length. */
11170 static enum neon_shape
11171 neon_select_shape (enum neon_shape shape, ...)
11173 va_list ap;
11174 enum neon_shape first_shape = shape;
11176 /* Fix missing optional operands. FIXME: we don't know at this point how
11177 many arguments we should have, so this makes the assumption that we have
11178 > 1. This is true of all current Neon opcodes, I think, but may not be
11179 true in the future. */
11180 if (!inst.operands[1].present)
11181 inst.operands[1] = inst.operands[0];
11183 va_start (ap, shape);
11185 for (; shape != NS_NULL; shape = va_arg (ap, int))
11187 unsigned j;
11188 int matches = 1;
11190 for (j = 0; j < neon_shape_tab[shape].els; j++)
11192 if (!inst.operands[j].present)
11194 matches = 0;
11195 break;
11198 switch (neon_shape_tab[shape].el[j])
11200 case SE_F:
11201 if (!(inst.operands[j].isreg
11202 && inst.operands[j].isvec
11203 && inst.operands[j].issingle
11204 && !inst.operands[j].isquad))
11205 matches = 0;
11206 break;
11208 case SE_D:
11209 if (!(inst.operands[j].isreg
11210 && inst.operands[j].isvec
11211 && !inst.operands[j].isquad
11212 && !inst.operands[j].issingle))
11213 matches = 0;
11214 break;
11216 case SE_R:
11217 if (!(inst.operands[j].isreg
11218 && !inst.operands[j].isvec))
11219 matches = 0;
11220 break;
11222 case SE_Q:
11223 if (!(inst.operands[j].isreg
11224 && inst.operands[j].isvec
11225 && inst.operands[j].isquad
11226 && !inst.operands[j].issingle))
11227 matches = 0;
11228 break;
11230 case SE_I:
11231 if (!(!inst.operands[j].isreg
11232 && !inst.operands[j].isscalar))
11233 matches = 0;
11234 break;
11236 case SE_S:
11237 if (!(!inst.operands[j].isreg
11238 && inst.operands[j].isscalar))
11239 matches = 0;
11240 break;
11242 case SE_L:
11243 break;
11246 if (matches)
11247 break;
11250 va_end (ap);
11252 if (shape == NS_NULL && first_shape != NS_NULL)
11253 first_error (_("invalid instruction shape"));
11255 return shape;
11258 /* True if SHAPE is predominantly a quadword operation (most of the time, this
11259 means the Q bit should be set). */
11261 static int
11262 neon_quad (enum neon_shape shape)
11264 return neon_shape_class[shape] == SC_QUAD;
11267 static void
11268 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11269 unsigned *g_size)
11271 /* Allow modification to be made to types which are constrained to be
11272 based on the key element, based on bits set alongside N_EQK. */
11273 if ((typebits & N_EQK) != 0)
11275 if ((typebits & N_HLF) != 0)
11276 *g_size /= 2;
11277 else if ((typebits & N_DBL) != 0)
11278 *g_size *= 2;
11279 if ((typebits & N_SGN) != 0)
11280 *g_type = NT_signed;
11281 else if ((typebits & N_UNS) != 0)
11282 *g_type = NT_unsigned;
11283 else if ((typebits & N_INT) != 0)
11284 *g_type = NT_integer;
11285 else if ((typebits & N_FLT) != 0)
11286 *g_type = NT_float;
11287 else if ((typebits & N_SIZ) != 0)
11288 *g_type = NT_untyped;
11292 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11293 operand type, i.e. the single type specified in a Neon instruction when it
11294 is the only one given. */
11296 static struct neon_type_el
11297 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11299 struct neon_type_el dest = *key;
11301 assert ((thisarg & N_EQK) != 0);
11303 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11305 return dest;
11308 /* Convert Neon type and size into compact bitmask representation. */
11310 static enum neon_type_mask
11311 type_chk_of_el_type (enum neon_el_type type, unsigned size)
11313 switch (type)
11315 case NT_untyped:
11316 switch (size)
11318 case 8: return N_8;
11319 case 16: return N_16;
11320 case 32: return N_32;
11321 case 64: return N_64;
11322 default: ;
11324 break;
11326 case NT_integer:
11327 switch (size)
11329 case 8: return N_I8;
11330 case 16: return N_I16;
11331 case 32: return N_I32;
11332 case 64: return N_I64;
11333 default: ;
11335 break;
11337 case NT_float:
11338 switch (size)
11340 case 16: return N_F16;
11341 case 32: return N_F32;
11342 case 64: return N_F64;
11343 default: ;
11345 break;
11347 case NT_poly:
11348 switch (size)
11350 case 8: return N_P8;
11351 case 16: return N_P16;
11352 default: ;
11354 break;
11356 case NT_signed:
11357 switch (size)
11359 case 8: return N_S8;
11360 case 16: return N_S16;
11361 case 32: return N_S32;
11362 case 64: return N_S64;
11363 default: ;
11365 break;
11367 case NT_unsigned:
11368 switch (size)
11370 case 8: return N_U8;
11371 case 16: return N_U16;
11372 case 32: return N_U32;
11373 case 64: return N_U64;
11374 default: ;
11376 break;
11378 default: ;
11381 return N_UTYP;
11384 /* Convert compact Neon bitmask type representation to a type and size. Only
11385 handles the case where a single bit is set in the mask. */
11387 static int
11388 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11389 enum neon_type_mask mask)
11391 if ((mask & N_EQK) != 0)
11392 return FAIL;
11394 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11395 *size = 8;
11396 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
11397 *size = 16;
11398 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
11399 *size = 32;
11400 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
11401 *size = 64;
11402 else
11403 return FAIL;
11405 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11406 *type = NT_signed;
11407 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
11408 *type = NT_unsigned;
11409 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
11410 *type = NT_integer;
11411 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
11412 *type = NT_untyped;
11413 else if ((mask & (N_P8 | N_P16)) != 0)
11414 *type = NT_poly;
11415 else if ((mask & (N_F32 | N_F64)) != 0)
11416 *type = NT_float;
11417 else
11418 return FAIL;
11420 return SUCCESS;
11423 /* Modify a bitmask of allowed types. This is only needed for type
11424 relaxation. */
11426 static unsigned
11427 modify_types_allowed (unsigned allowed, unsigned mods)
11429 unsigned size;
11430 enum neon_el_type type;
11431 unsigned destmask;
11432 int i;
11434 destmask = 0;
11436 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11438 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
11440 neon_modify_type_size (mods, &type, &size);
11441 destmask |= type_chk_of_el_type (type, size);
11445 return destmask;
11448 /* Check type and return type classification.
11449 The manual states (paraphrase): If one datatype is given, it indicates the
11450 type given in:
11451 - the second operand, if there is one
11452 - the operand, if there is no second operand
11453 - the result, if there are no operands.
11454 This isn't quite good enough though, so we use a concept of a "key" datatype
11455 which is set on a per-instruction basis, which is the one which matters when
11456 only one data type is written.
11457 Note: this function has side-effects (e.g. filling in missing operands). All
11458 Neon instructions should call it before performing bit encoding. */
11460 static struct neon_type_el
11461 neon_check_type (unsigned els, enum neon_shape ns, ...)
11463 va_list ap;
11464 unsigned i, pass, key_el = 0;
11465 unsigned types[NEON_MAX_TYPE_ELS];
11466 enum neon_el_type k_type = NT_invtype;
11467 unsigned k_size = -1u;
11468 struct neon_type_el badtype = {NT_invtype, -1};
11469 unsigned key_allowed = 0;
11471 /* Optional registers in Neon instructions are always (not) in operand 1.
11472 Fill in the missing operand here, if it was omitted. */
11473 if (els > 1 && !inst.operands[1].present)
11474 inst.operands[1] = inst.operands[0];
11476 /* Suck up all the varargs. */
11477 va_start (ap, ns);
11478 for (i = 0; i < els; i++)
11480 unsigned thisarg = va_arg (ap, unsigned);
11481 if (thisarg == N_IGNORE_TYPE)
11483 va_end (ap);
11484 return badtype;
11486 types[i] = thisarg;
11487 if ((thisarg & N_KEY) != 0)
11488 key_el = i;
11490 va_end (ap);
11492 if (inst.vectype.elems > 0)
11493 for (i = 0; i < els; i++)
11494 if (inst.operands[i].vectype.type != NT_invtype)
11496 first_error (_("types specified in both the mnemonic and operands"));
11497 return badtype;
11500 /* Duplicate inst.vectype elements here as necessary.
11501 FIXME: No idea if this is exactly the same as the ARM assembler,
11502 particularly when an insn takes one register and one non-register
11503 operand. */
11504 if (inst.vectype.elems == 1 && els > 1)
11506 unsigned j;
11507 inst.vectype.elems = els;
11508 inst.vectype.el[key_el] = inst.vectype.el[0];
11509 for (j = 0; j < els; j++)
11510 if (j != key_el)
11511 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11512 types[j]);
11514 else if (inst.vectype.elems == 0 && els > 0)
11516 unsigned j;
11517 /* No types were given after the mnemonic, so look for types specified
11518 after each operand. We allow some flexibility here; as long as the
11519 "key" operand has a type, we can infer the others. */
11520 for (j = 0; j < els; j++)
11521 if (inst.operands[j].vectype.type != NT_invtype)
11522 inst.vectype.el[j] = inst.operands[j].vectype;
11524 if (inst.operands[key_el].vectype.type != NT_invtype)
11526 for (j = 0; j < els; j++)
11527 if (inst.operands[j].vectype.type == NT_invtype)
11528 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11529 types[j]);
11531 else
11533 first_error (_("operand types can't be inferred"));
11534 return badtype;
11537 else if (inst.vectype.elems != els)
11539 first_error (_("type specifier has the wrong number of parts"));
11540 return badtype;
11543 for (pass = 0; pass < 2; pass++)
11545 for (i = 0; i < els; i++)
11547 unsigned thisarg = types[i];
11548 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11549 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11550 enum neon_el_type g_type = inst.vectype.el[i].type;
11551 unsigned g_size = inst.vectype.el[i].size;
11553 /* Decay more-specific signed & unsigned types to sign-insensitive
11554 integer types if sign-specific variants are unavailable. */
11555 if ((g_type == NT_signed || g_type == NT_unsigned)
11556 && (types_allowed & N_SU_ALL) == 0)
11557 g_type = NT_integer;
11559 /* If only untyped args are allowed, decay any more specific types to
11560 them. Some instructions only care about signs for some element
11561 sizes, so handle that properly. */
11562 if ((g_size == 8 && (types_allowed & N_8) != 0)
11563 || (g_size == 16 && (types_allowed & N_16) != 0)
11564 || (g_size == 32 && (types_allowed & N_32) != 0)
11565 || (g_size == 64 && (types_allowed & N_64) != 0))
11566 g_type = NT_untyped;
11568 if (pass == 0)
11570 if ((thisarg & N_KEY) != 0)
11572 k_type = g_type;
11573 k_size = g_size;
11574 key_allowed = thisarg & ~N_KEY;
11577 else
11579 if ((thisarg & N_VFP) != 0)
11581 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11582 unsigned regwidth = neon_shape_el_size[regshape], match;
11584 /* In VFP mode, operands must match register widths. If we
11585 have a key operand, use its width, else use the width of
11586 the current operand. */
11587 if (k_size != -1u)
11588 match = k_size;
11589 else
11590 match = g_size;
11592 if (regwidth != match)
11594 first_error (_("operand size must match register width"));
11595 return badtype;
11599 if ((thisarg & N_EQK) == 0)
11601 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11603 if ((given_type & types_allowed) == 0)
11605 first_error (_("bad type in Neon instruction"));
11606 return badtype;
11609 else
11611 enum neon_el_type mod_k_type = k_type;
11612 unsigned mod_k_size = k_size;
11613 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11614 if (g_type != mod_k_type || g_size != mod_k_size)
11616 first_error (_("inconsistent types in Neon instruction"));
11617 return badtype;
11624 return inst.vectype.el[key_el];
11627 /* Neon-style VFP instruction forwarding. */
11629 /* Thumb VFP instructions have 0xE in the condition field. */
11631 static void
11632 do_vfp_cond_or_thumb (void)
11634 if (thumb_mode)
11635 inst.instruction |= 0xe0000000;
11636 else
11637 inst.instruction |= inst.cond << 28;
11640 /* Look up and encode a simple mnemonic, for use as a helper function for the
11641 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11642 etc. It is assumed that operand parsing has already been done, and that the
11643 operands are in the form expected by the given opcode (this isn't necessarily
11644 the same as the form in which they were parsed, hence some massaging must
11645 take place before this function is called).
11646 Checks current arch version against that in the looked-up opcode. */
11648 static void
11649 do_vfp_nsyn_opcode (const char *opname)
11651 const struct asm_opcode *opcode;
11653 opcode = hash_find (arm_ops_hsh, opname);
11655 if (!opcode)
11656 abort ();
11658 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11659 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11660 _(BAD_FPU));
11662 if (thumb_mode)
11664 inst.instruction = opcode->tvalue;
11665 opcode->tencode ();
11667 else
11669 inst.instruction = (inst.cond << 28) | opcode->avalue;
11670 opcode->aencode ();
11674 static void
11675 do_vfp_nsyn_add_sub (enum neon_shape rs)
11677 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11679 if (rs == NS_FFF)
11681 if (is_add)
11682 do_vfp_nsyn_opcode ("fadds");
11683 else
11684 do_vfp_nsyn_opcode ("fsubs");
11686 else
11688 if (is_add)
11689 do_vfp_nsyn_opcode ("faddd");
11690 else
11691 do_vfp_nsyn_opcode ("fsubd");
11695 /* Check operand types to see if this is a VFP instruction, and if so call
11696 PFN (). */
11698 static int
11699 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11701 enum neon_shape rs;
11702 struct neon_type_el et;
11704 switch (args)
11706 case 2:
11707 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11708 et = neon_check_type (2, rs,
11709 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11710 break;
11712 case 3:
11713 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11714 et = neon_check_type (3, rs,
11715 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11716 break;
11718 default:
11719 abort ();
11722 if (et.type != NT_invtype)
11724 pfn (rs);
11725 return SUCCESS;
11727 else
11728 inst.error = NULL;
11730 return FAIL;
11733 static void
11734 do_vfp_nsyn_mla_mls (enum neon_shape rs)
11736 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11738 if (rs == NS_FFF)
11740 if (is_mla)
11741 do_vfp_nsyn_opcode ("fmacs");
11742 else
11743 do_vfp_nsyn_opcode ("fmscs");
11745 else
11747 if (is_mla)
11748 do_vfp_nsyn_opcode ("fmacd");
11749 else
11750 do_vfp_nsyn_opcode ("fmscd");
11754 static void
11755 do_vfp_nsyn_mul (enum neon_shape rs)
11757 if (rs == NS_FFF)
11758 do_vfp_nsyn_opcode ("fmuls");
11759 else
11760 do_vfp_nsyn_opcode ("fmuld");
11763 static void
11764 do_vfp_nsyn_abs_neg (enum neon_shape rs)
11766 int is_neg = (inst.instruction & 0x80) != 0;
11767 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11769 if (rs == NS_FF)
11771 if (is_neg)
11772 do_vfp_nsyn_opcode ("fnegs");
11773 else
11774 do_vfp_nsyn_opcode ("fabss");
11776 else
11778 if (is_neg)
11779 do_vfp_nsyn_opcode ("fnegd");
11780 else
11781 do_vfp_nsyn_opcode ("fabsd");
11785 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11786 insns belong to Neon, and are handled elsewhere. */
11788 static void
11789 do_vfp_nsyn_ldm_stm (int is_dbmode)
11791 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11792 if (is_ldm)
11794 if (is_dbmode)
11795 do_vfp_nsyn_opcode ("fldmdbs");
11796 else
11797 do_vfp_nsyn_opcode ("fldmias");
11799 else
11801 if (is_dbmode)
11802 do_vfp_nsyn_opcode ("fstmdbs");
11803 else
11804 do_vfp_nsyn_opcode ("fstmias");
11808 static void
11809 do_vfp_nsyn_sqrt (void)
11811 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11812 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11814 if (rs == NS_FF)
11815 do_vfp_nsyn_opcode ("fsqrts");
11816 else
11817 do_vfp_nsyn_opcode ("fsqrtd");
11820 static void
11821 do_vfp_nsyn_div (void)
11823 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11824 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11825 N_F32 | N_F64 | N_KEY | N_VFP);
11827 if (rs == NS_FFF)
11828 do_vfp_nsyn_opcode ("fdivs");
11829 else
11830 do_vfp_nsyn_opcode ("fdivd");
11833 static void
11834 do_vfp_nsyn_nmul (void)
11836 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11837 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11838 N_F32 | N_F64 | N_KEY | N_VFP);
11840 if (rs == NS_FFF)
11842 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11843 do_vfp_sp_dyadic ();
11845 else
11847 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11848 do_vfp_dp_rd_rn_rm ();
11850 do_vfp_cond_or_thumb ();
11853 static void
11854 do_vfp_nsyn_cmp (void)
11856 if (inst.operands[1].isreg)
11858 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11859 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11861 if (rs == NS_FF)
11863 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11864 do_vfp_sp_monadic ();
11866 else
11868 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11869 do_vfp_dp_rd_rm ();
11872 else
11874 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11875 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11877 switch (inst.instruction & 0x0fffffff)
11879 case N_MNEM_vcmp:
11880 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11881 break;
11882 case N_MNEM_vcmpe:
11883 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11884 break;
11885 default:
11886 abort ();
11889 if (rs == NS_FI)
11891 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11892 do_vfp_sp_compare_z ();
11894 else
11896 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11897 do_vfp_dp_rd ();
11900 do_vfp_cond_or_thumb ();
11903 static void
11904 nsyn_insert_sp (void)
11906 inst.operands[1] = inst.operands[0];
11907 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11908 inst.operands[0].reg = REG_SP;
11909 inst.operands[0].isreg = 1;
11910 inst.operands[0].writeback = 1;
11911 inst.operands[0].present = 1;
11914 static void
11915 do_vfp_nsyn_push (void)
11917 nsyn_insert_sp ();
11918 if (inst.operands[1].issingle)
11919 do_vfp_nsyn_opcode ("fstmdbs");
11920 else
11921 do_vfp_nsyn_opcode ("fstmdbd");
11924 static void
11925 do_vfp_nsyn_pop (void)
11927 nsyn_insert_sp ();
11928 if (inst.operands[1].issingle)
11929 do_vfp_nsyn_opcode ("fldmias");
11930 else
11931 do_vfp_nsyn_opcode ("fldmiad");
11934 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11935 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11937 static unsigned
11938 neon_dp_fixup (unsigned i)
11940 if (thumb_mode)
11942 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11943 if (i & (1 << 24))
11944 i |= 1 << 28;
11946 i &= ~(1 << 24);
11948 i |= 0xef000000;
11950 else
11951 i |= 0xf2000000;
11953 return i;
11956 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11957 (0, 1, 2, 3). */
11959 static unsigned
11960 neon_logbits (unsigned x)
11962 return ffs (x) - 4;
11965 #define LOW4(R) ((R) & 0xf)
11966 #define HI1(R) (((R) >> 4) & 1)
11968 /* Encode insns with bit pattern:
11970 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11971 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11973 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11974 different meaning for some instruction. */
11976 static void
11977 neon_three_same (int isquad, int ubit, int size)
11979 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11980 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11981 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11982 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11983 inst.instruction |= LOW4 (inst.operands[2].reg);
11984 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11985 inst.instruction |= (isquad != 0) << 6;
11986 inst.instruction |= (ubit != 0) << 24;
11987 if (size != -1)
11988 inst.instruction |= neon_logbits (size) << 20;
11990 inst.instruction = neon_dp_fixup (inst.instruction);
11993 /* Encode instructions of the form:
11995 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11996 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
11998 Don't write size if SIZE == -1. */
12000 static void
12001 neon_two_same (int qbit, int ubit, int size)
12003 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12004 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12005 inst.instruction |= LOW4 (inst.operands[1].reg);
12006 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12007 inst.instruction |= (qbit != 0) << 6;
12008 inst.instruction |= (ubit != 0) << 24;
12010 if (size != -1)
12011 inst.instruction |= neon_logbits (size) << 18;
12013 inst.instruction = neon_dp_fixup (inst.instruction);
12016 /* Neon instruction encoders, in approximate order of appearance. */
12018 static void
12019 do_neon_dyadic_i_su (void)
12021 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12022 struct neon_type_el et = neon_check_type (3, rs,
12023 N_EQK, N_EQK, N_SU_32 | N_KEY);
12024 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12027 static void
12028 do_neon_dyadic_i64_su (void)
12030 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12031 struct neon_type_el et = neon_check_type (3, rs,
12032 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12033 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12036 static void
12037 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12038 unsigned immbits)
12040 unsigned size = et.size >> 3;
12041 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12042 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12043 inst.instruction |= LOW4 (inst.operands[1].reg);
12044 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12045 inst.instruction |= (isquad != 0) << 6;
12046 inst.instruction |= immbits << 16;
12047 inst.instruction |= (size >> 3) << 7;
12048 inst.instruction |= (size & 0x7) << 19;
12049 if (write_ubit)
12050 inst.instruction |= (uval != 0) << 24;
12052 inst.instruction = neon_dp_fixup (inst.instruction);
12055 static void
12056 do_neon_shl_imm (void)
12058 if (!inst.operands[2].isreg)
12060 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12061 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12062 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12063 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
12065 else
12067 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12068 struct neon_type_el et = neon_check_type (3, rs,
12069 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12070 unsigned int tmp;
12072 /* VSHL/VQSHL 3-register variants have syntax such as:
12073 vshl.xx Dd, Dm, Dn
12074 whereas other 3-register operations encoded by neon_three_same have
12075 syntax like:
12076 vadd.xx Dd, Dn, Dm
12077 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12078 here. */
12079 tmp = inst.operands[2].reg;
12080 inst.operands[2].reg = inst.operands[1].reg;
12081 inst.operands[1].reg = tmp;
12082 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12083 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12087 static void
12088 do_neon_qshl_imm (void)
12090 if (!inst.operands[2].isreg)
12092 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12093 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12095 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12096 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
12097 inst.operands[2].imm);
12099 else
12101 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12102 struct neon_type_el et = neon_check_type (3, rs,
12103 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12104 unsigned int tmp;
12106 /* See note in do_neon_shl_imm. */
12107 tmp = inst.operands[2].reg;
12108 inst.operands[2].reg = inst.operands[1].reg;
12109 inst.operands[1].reg = tmp;
12110 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12111 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12115 static void
12116 do_neon_rshl (void)
12118 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12119 struct neon_type_el et = neon_check_type (3, rs,
12120 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12121 unsigned int tmp;
12123 tmp = inst.operands[2].reg;
12124 inst.operands[2].reg = inst.operands[1].reg;
12125 inst.operands[1].reg = tmp;
12126 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12129 static int
12130 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12132 /* Handle .I8 pseudo-instructions. */
12133 if (size == 8)
12135 /* Unfortunately, this will make everything apart from zero out-of-range.
12136 FIXME is this the intended semantics? There doesn't seem much point in
12137 accepting .I8 if so. */
12138 immediate |= immediate << 8;
12139 size = 16;
12142 if (size >= 32)
12144 if (immediate == (immediate & 0x000000ff))
12146 *immbits = immediate;
12147 return 0x1;
12149 else if (immediate == (immediate & 0x0000ff00))
12151 *immbits = immediate >> 8;
12152 return 0x3;
12154 else if (immediate == (immediate & 0x00ff0000))
12156 *immbits = immediate >> 16;
12157 return 0x5;
12159 else if (immediate == (immediate & 0xff000000))
12161 *immbits = immediate >> 24;
12162 return 0x7;
12164 if ((immediate & 0xffff) != (immediate >> 16))
12165 goto bad_immediate;
12166 immediate &= 0xffff;
12169 if (immediate == (immediate & 0x000000ff))
12171 *immbits = immediate;
12172 return 0x9;
12174 else if (immediate == (immediate & 0x0000ff00))
12176 *immbits = immediate >> 8;
12177 return 0xb;
12180 bad_immediate:
12181 first_error (_("immediate value out of range"));
12182 return FAIL;
12185 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12186 A, B, C, D. */
12188 static int
12189 neon_bits_same_in_bytes (unsigned imm)
12191 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12192 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12193 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12194 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12197 /* For immediate of above form, return 0bABCD. */
12199 static unsigned
12200 neon_squash_bits (unsigned imm)
12202 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12203 | ((imm & 0x01000000) >> 21);
12206 /* Compress quarter-float representation to 0b...000 abcdefgh. */
12208 static unsigned
12209 neon_qfloat_bits (unsigned imm)
12211 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
12214 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12215 the instruction. *OP is passed as the initial value of the op field, and
12216 may be set to a different value depending on the constant (i.e.
12217 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
12218 MVN). If the immediate looks like a repeated pattern then also
12219 try smaller element sizes. */
12221 static int
12222 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12223 unsigned *immbits, int *op, int size,
12224 enum neon_el_type type)
12226 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12227 float. */
12228 if (type == NT_float && !float_p)
12229 return FAIL;
12231 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12233 if (size != 32 || *op == 1)
12234 return FAIL;
12235 *immbits = neon_qfloat_bits (immlo);
12236 return 0xf;
12239 if (size == 64)
12241 if (neon_bits_same_in_bytes (immhi)
12242 && neon_bits_same_in_bytes (immlo))
12244 if (*op == 1)
12245 return FAIL;
12246 *immbits = (neon_squash_bits (immhi) << 4)
12247 | neon_squash_bits (immlo);
12248 *op = 1;
12249 return 0xe;
12252 if (immhi != immlo)
12253 return FAIL;
12256 if (size >= 32)
12258 if (immlo == (immlo & 0x000000ff))
12260 *immbits = immlo;
12261 return 0x0;
12263 else if (immlo == (immlo & 0x0000ff00))
12265 *immbits = immlo >> 8;
12266 return 0x2;
12268 else if (immlo == (immlo & 0x00ff0000))
12270 *immbits = immlo >> 16;
12271 return 0x4;
12273 else if (immlo == (immlo & 0xff000000))
12275 *immbits = immlo >> 24;
12276 return 0x6;
12278 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12280 *immbits = (immlo >> 8) & 0xff;
12281 return 0xc;
12283 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12285 *immbits = (immlo >> 16) & 0xff;
12286 return 0xd;
12289 if ((immlo & 0xffff) != (immlo >> 16))
12290 return FAIL;
12291 immlo &= 0xffff;
12294 if (size >= 16)
12296 if (immlo == (immlo & 0x000000ff))
12298 *immbits = immlo;
12299 return 0x8;
12301 else if (immlo == (immlo & 0x0000ff00))
12303 *immbits = immlo >> 8;
12304 return 0xa;
12307 if ((immlo & 0xff) != (immlo >> 8))
12308 return FAIL;
12309 immlo &= 0xff;
12312 if (immlo == (immlo & 0x000000ff))
12314 /* Don't allow MVN with 8-bit immediate. */
12315 if (*op == 1)
12316 return FAIL;
12317 *immbits = immlo;
12318 return 0xe;
12321 return FAIL;
12324 /* Write immediate bits [7:0] to the following locations:
12326 |28/24|23 19|18 16|15 4|3 0|
12327 | 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|
12329 This function is used by VMOV/VMVN/VORR/VBIC. */
12331 static void
12332 neon_write_immbits (unsigned immbits)
12334 inst.instruction |= immbits & 0xf;
12335 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12336 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12339 /* Invert low-order SIZE bits of XHI:XLO. */
12341 static void
12342 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12344 unsigned immlo = xlo ? *xlo : 0;
12345 unsigned immhi = xhi ? *xhi : 0;
12347 switch (size)
12349 case 8:
12350 immlo = (~immlo) & 0xff;
12351 break;
12353 case 16:
12354 immlo = (~immlo) & 0xffff;
12355 break;
12357 case 64:
12358 immhi = (~immhi) & 0xffffffff;
12359 /* fall through. */
12361 case 32:
12362 immlo = (~immlo) & 0xffffffff;
12363 break;
12365 default:
12366 abort ();
12369 if (xlo)
12370 *xlo = immlo;
12372 if (xhi)
12373 *xhi = immhi;
12376 static void
12377 do_neon_logic (void)
12379 if (inst.operands[2].present && inst.operands[2].isreg)
12381 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12382 neon_check_type (3, rs, N_IGNORE_TYPE);
12383 /* U bit and size field were set as part of the bitmask. */
12384 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12385 neon_three_same (neon_quad (rs), 0, -1);
12387 else
12389 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12390 struct neon_type_el et = neon_check_type (2, rs,
12391 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12392 enum neon_opc opcode = inst.instruction & 0x0fffffff;
12393 unsigned immbits;
12394 int cmode;
12396 if (et.type == NT_invtype)
12397 return;
12399 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12401 immbits = inst.operands[1].imm;
12402 if (et.size == 64)
12404 /* .i64 is a pseudo-op, so the immediate must be a repeating
12405 pattern. */
12406 if (immbits != (inst.operands[1].regisimm ?
12407 inst.operands[1].reg : 0))
12409 /* Set immbits to an invalid constant. */
12410 immbits = 0xdeadbeef;
12414 switch (opcode)
12416 case N_MNEM_vbic:
12417 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12418 break;
12420 case N_MNEM_vorr:
12421 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12422 break;
12424 case N_MNEM_vand:
12425 /* Pseudo-instruction for VBIC. */
12426 neon_invert_size (&immbits, 0, et.size);
12427 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12428 break;
12430 case N_MNEM_vorn:
12431 /* Pseudo-instruction for VORR. */
12432 neon_invert_size (&immbits, 0, et.size);
12433 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12434 break;
12436 default:
12437 abort ();
12440 if (cmode == FAIL)
12441 return;
12443 inst.instruction |= neon_quad (rs) << 6;
12444 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12445 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12446 inst.instruction |= cmode << 8;
12447 neon_write_immbits (immbits);
12449 inst.instruction = neon_dp_fixup (inst.instruction);
12453 static void
12454 do_neon_bitfield (void)
12456 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12457 neon_check_type (3, rs, N_IGNORE_TYPE);
12458 neon_three_same (neon_quad (rs), 0, -1);
12461 static void
12462 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12463 unsigned destbits)
12465 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12466 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12467 types | N_KEY);
12468 if (et.type == NT_float)
12470 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
12471 neon_three_same (neon_quad (rs), 0, -1);
12473 else
12475 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12476 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
12480 static void
12481 do_neon_dyadic_if_su (void)
12483 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12486 static void
12487 do_neon_dyadic_if_su_d (void)
12489 /* This version only allow D registers, but that constraint is enforced during
12490 operand parsing so we don't need to do anything extra here. */
12491 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12494 static void
12495 do_neon_dyadic_if_i_d (void)
12497 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12498 affected if we specify unsigned args. */
12499 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12502 enum vfp_or_neon_is_neon_bits
12504 NEON_CHECK_CC = 1,
12505 NEON_CHECK_ARCH = 2
12508 /* Call this function if an instruction which may have belonged to the VFP or
12509 Neon instruction sets, but turned out to be a Neon instruction (due to the
12510 operand types involved, etc.). We have to check and/or fix-up a couple of
12511 things:
12513 - Make sure the user hasn't attempted to make a Neon instruction
12514 conditional.
12515 - Alter the value in the condition code field if necessary.
12516 - Make sure that the arch supports Neon instructions.
12518 Which of these operations take place depends on bits from enum
12519 vfp_or_neon_is_neon_bits.
12521 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12522 current instruction's condition is COND_ALWAYS, the condition field is
12523 changed to inst.uncond_value. This is necessary because instructions shared
12524 between VFP and Neon may be conditional for the VFP variants only, and the
12525 unconditional Neon version must have, e.g., 0xF in the condition field. */
12527 static int
12528 vfp_or_neon_is_neon (unsigned check)
12530 /* Conditions are always legal in Thumb mode (IT blocks). */
12531 if (!thumb_mode && (check & NEON_CHECK_CC))
12533 if (inst.cond != COND_ALWAYS)
12535 first_error (_(BAD_COND));
12536 return FAIL;
12538 if (inst.uncond_value != -1)
12539 inst.instruction |= inst.uncond_value << 28;
12542 if ((check & NEON_CHECK_ARCH)
12543 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12545 first_error (_(BAD_FPU));
12546 return FAIL;
12549 return SUCCESS;
12552 static void
12553 do_neon_addsub_if_i (void)
12555 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12556 return;
12558 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12559 return;
12561 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12562 affected if we specify unsigned args. */
12563 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
12566 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12567 result to be:
12568 V<op> A,B (A is operand 0, B is operand 2)
12569 to mean:
12570 V<op> A,B,A
12571 not:
12572 V<op> A,B,B
12573 so handle that case specially. */
12575 static void
12576 neon_exchange_operands (void)
12578 void *scratch = alloca (sizeof (inst.operands[0]));
12579 if (inst.operands[1].present)
12581 /* Swap operands[1] and operands[2]. */
12582 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12583 inst.operands[1] = inst.operands[2];
12584 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12586 else
12588 inst.operands[1] = inst.operands[2];
12589 inst.operands[2] = inst.operands[0];
12593 static void
12594 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12596 if (inst.operands[2].isreg)
12598 if (invert)
12599 neon_exchange_operands ();
12600 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
12602 else
12604 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12605 struct neon_type_el et = neon_check_type (2, rs,
12606 N_EQK | N_SIZ, immtypes | N_KEY);
12608 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12609 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12610 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12611 inst.instruction |= LOW4 (inst.operands[1].reg);
12612 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12613 inst.instruction |= neon_quad (rs) << 6;
12614 inst.instruction |= (et.type == NT_float) << 10;
12615 inst.instruction |= neon_logbits (et.size) << 18;
12617 inst.instruction = neon_dp_fixup (inst.instruction);
12621 static void
12622 do_neon_cmp (void)
12624 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12627 static void
12628 do_neon_cmp_inv (void)
12630 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12633 static void
12634 do_neon_ceq (void)
12636 neon_compare (N_IF_32, N_IF_32, FALSE);
12639 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
12640 scalars, which are encoded in 5 bits, M : Rm.
12641 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12642 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12643 index in M. */
12645 static unsigned
12646 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12648 unsigned regno = NEON_SCALAR_REG (scalar);
12649 unsigned elno = NEON_SCALAR_INDEX (scalar);
12651 switch (elsize)
12653 case 16:
12654 if (regno > 7 || elno > 3)
12655 goto bad_scalar;
12656 return regno | (elno << 3);
12658 case 32:
12659 if (regno > 15 || elno > 1)
12660 goto bad_scalar;
12661 return regno | (elno << 4);
12663 default:
12664 bad_scalar:
12665 first_error (_("scalar out of range for multiply instruction"));
12668 return 0;
12671 /* Encode multiply / multiply-accumulate scalar instructions. */
12673 static void
12674 neon_mul_mac (struct neon_type_el et, int ubit)
12676 unsigned scalar;
12678 /* Give a more helpful error message if we have an invalid type. */
12679 if (et.type == NT_invtype)
12680 return;
12682 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
12683 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12684 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12685 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12686 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12687 inst.instruction |= LOW4 (scalar);
12688 inst.instruction |= HI1 (scalar) << 5;
12689 inst.instruction |= (et.type == NT_float) << 8;
12690 inst.instruction |= neon_logbits (et.size) << 20;
12691 inst.instruction |= (ubit != 0) << 24;
12693 inst.instruction = neon_dp_fixup (inst.instruction);
12696 static void
12697 do_neon_mac_maybe_scalar (void)
12699 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12700 return;
12702 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12703 return;
12705 if (inst.operands[2].isscalar)
12707 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12708 struct neon_type_el et = neon_check_type (3, rs,
12709 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12710 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12711 neon_mul_mac (et, neon_quad (rs));
12713 else
12715 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12716 affected if we specify unsigned args. */
12717 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12721 static void
12722 do_neon_tst (void)
12724 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12725 struct neon_type_el et = neon_check_type (3, rs,
12726 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
12727 neon_three_same (neon_quad (rs), 0, et.size);
12730 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
12731 same types as the MAC equivalents. The polynomial type for this instruction
12732 is encoded the same as the integer type. */
12734 static void
12735 do_neon_mul (void)
12737 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12738 return;
12740 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12741 return;
12743 if (inst.operands[2].isscalar)
12744 do_neon_mac_maybe_scalar ();
12745 else
12746 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
12749 static void
12750 do_neon_qdmulh (void)
12752 if (inst.operands[2].isscalar)
12754 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12755 struct neon_type_el et = neon_check_type (3, rs,
12756 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12757 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12758 neon_mul_mac (et, neon_quad (rs));
12760 else
12762 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12763 struct neon_type_el et = neon_check_type (3, rs,
12764 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12765 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12766 /* The U bit (rounding) comes from bit mask. */
12767 neon_three_same (neon_quad (rs), 0, et.size);
12771 static void
12772 do_neon_fcmp_absolute (void)
12774 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12775 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12776 /* Size field comes from bit mask. */
12777 neon_three_same (neon_quad (rs), 1, -1);
12780 static void
12781 do_neon_fcmp_absolute_inv (void)
12783 neon_exchange_operands ();
12784 do_neon_fcmp_absolute ();
12787 static void
12788 do_neon_step (void)
12790 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12791 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12792 neon_three_same (neon_quad (rs), 0, -1);
12795 static void
12796 do_neon_abs_neg (void)
12798 enum neon_shape rs;
12799 struct neon_type_el et;
12801 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12802 return;
12804 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12805 return;
12807 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12808 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12810 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12811 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12812 inst.instruction |= LOW4 (inst.operands[1].reg);
12813 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12814 inst.instruction |= neon_quad (rs) << 6;
12815 inst.instruction |= (et.type == NT_float) << 10;
12816 inst.instruction |= neon_logbits (et.size) << 18;
12818 inst.instruction = neon_dp_fixup (inst.instruction);
12821 static void
12822 do_neon_sli (void)
12824 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12825 struct neon_type_el et = neon_check_type (2, rs,
12826 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12827 int imm = inst.operands[2].imm;
12828 constraint (imm < 0 || (unsigned)imm >= et.size,
12829 _("immediate out of range for insert"));
12830 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12833 static void
12834 do_neon_sri (void)
12836 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12837 struct neon_type_el et = neon_check_type (2, rs,
12838 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12839 int imm = inst.operands[2].imm;
12840 constraint (imm < 1 || (unsigned)imm > et.size,
12841 _("immediate out of range for insert"));
12842 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
12845 static void
12846 do_neon_qshlu_imm (void)
12848 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12849 struct neon_type_el et = neon_check_type (2, rs,
12850 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12851 int imm = inst.operands[2].imm;
12852 constraint (imm < 0 || (unsigned)imm >= et.size,
12853 _("immediate out of range for shift"));
12854 /* Only encodes the 'U present' variant of the instruction.
12855 In this case, signed types have OP (bit 8) set to 0.
12856 Unsigned types have OP set to 1. */
12857 inst.instruction |= (et.type == NT_unsigned) << 8;
12858 /* The rest of the bits are the same as other immediate shifts. */
12859 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12862 static void
12863 do_neon_qmovn (void)
12865 struct neon_type_el et = neon_check_type (2, NS_DQ,
12866 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12867 /* Saturating move where operands can be signed or unsigned, and the
12868 destination has the same signedness. */
12869 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12870 if (et.type == NT_unsigned)
12871 inst.instruction |= 0xc0;
12872 else
12873 inst.instruction |= 0x80;
12874 neon_two_same (0, 1, et.size / 2);
12877 static void
12878 do_neon_qmovun (void)
12880 struct neon_type_el et = neon_check_type (2, NS_DQ,
12881 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12882 /* Saturating move with unsigned results. Operands must be signed. */
12883 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12884 neon_two_same (0, 1, et.size / 2);
12887 static void
12888 do_neon_rshift_sat_narrow (void)
12890 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12891 or unsigned. If operands are unsigned, results must also be unsigned. */
12892 struct neon_type_el et = neon_check_type (2, NS_DQI,
12893 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12894 int imm = inst.operands[2].imm;
12895 /* This gets the bounds check, size encoding and immediate bits calculation
12896 right. */
12897 et.size /= 2;
12899 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12900 VQMOVN.I<size> <Dd>, <Qm>. */
12901 if (imm == 0)
12903 inst.operands[2].present = 0;
12904 inst.instruction = N_MNEM_vqmovn;
12905 do_neon_qmovn ();
12906 return;
12909 constraint (imm < 1 || (unsigned)imm > et.size,
12910 _("immediate out of range"));
12911 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12914 static void
12915 do_neon_rshift_sat_narrow_u (void)
12917 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12918 or unsigned. If operands are unsigned, results must also be unsigned. */
12919 struct neon_type_el et = neon_check_type (2, NS_DQI,
12920 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12921 int imm = inst.operands[2].imm;
12922 /* This gets the bounds check, size encoding and immediate bits calculation
12923 right. */
12924 et.size /= 2;
12926 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12927 VQMOVUN.I<size> <Dd>, <Qm>. */
12928 if (imm == 0)
12930 inst.operands[2].present = 0;
12931 inst.instruction = N_MNEM_vqmovun;
12932 do_neon_qmovun ();
12933 return;
12936 constraint (imm < 1 || (unsigned)imm > et.size,
12937 _("immediate out of range"));
12938 /* FIXME: The manual is kind of unclear about what value U should have in
12939 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12940 must be 1. */
12941 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12944 static void
12945 do_neon_movn (void)
12947 struct neon_type_el et = neon_check_type (2, NS_DQ,
12948 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12949 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12950 neon_two_same (0, 1, et.size / 2);
12953 static void
12954 do_neon_rshift_narrow (void)
12956 struct neon_type_el et = neon_check_type (2, NS_DQI,
12957 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12958 int imm = inst.operands[2].imm;
12959 /* This gets the bounds check, size encoding and immediate bits calculation
12960 right. */
12961 et.size /= 2;
12963 /* If immediate is zero then we are a pseudo-instruction for
12964 VMOVN.I<size> <Dd>, <Qm> */
12965 if (imm == 0)
12967 inst.operands[2].present = 0;
12968 inst.instruction = N_MNEM_vmovn;
12969 do_neon_movn ();
12970 return;
12973 constraint (imm < 1 || (unsigned)imm > et.size,
12974 _("immediate out of range for narrowing operation"));
12975 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12978 static void
12979 do_neon_shll (void)
12981 /* FIXME: Type checking when lengthening. */
12982 struct neon_type_el et = neon_check_type (2, NS_QDI,
12983 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12984 unsigned imm = inst.operands[2].imm;
12986 if (imm == et.size)
12988 /* Maximum shift variant. */
12989 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12990 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12991 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12992 inst.instruction |= LOW4 (inst.operands[1].reg);
12993 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12994 inst.instruction |= neon_logbits (et.size) << 18;
12996 inst.instruction = neon_dp_fixup (inst.instruction);
12998 else
13000 /* A more-specific type check for non-max versions. */
13001 et = neon_check_type (2, NS_QDI,
13002 N_EQK | N_DBL, N_SU_32 | N_KEY);
13003 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13004 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13008 /* Check the various types for the VCVT instruction, and return which version
13009 the current instruction is. */
13011 static int
13012 neon_cvt_flavour (enum neon_shape rs)
13014 #define CVT_VAR(C,X,Y) \
13015 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13016 if (et.type != NT_invtype) \
13018 inst.error = NULL; \
13019 return (C); \
13021 struct neon_type_el et;
13022 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13023 || rs == NS_FF) ? N_VFP : 0;
13024 /* The instruction versions which take an immediate take one register
13025 argument, which is extended to the width of the full register. Thus the
13026 "source" and "destination" registers must have the same width. Hack that
13027 here by making the size equal to the key (wider, in this case) operand. */
13028 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
13030 CVT_VAR (0, N_S32, N_F32);
13031 CVT_VAR (1, N_U32, N_F32);
13032 CVT_VAR (2, N_F32, N_S32);
13033 CVT_VAR (3, N_F32, N_U32);
13034 /* Half-precision conversions. */
13035 CVT_VAR (4, N_F32, N_F16);
13036 CVT_VAR (5, N_F16, N_F32);
13038 whole_reg = N_VFP;
13040 /* VFP instructions. */
13041 CVT_VAR (6, N_F32, N_F64);
13042 CVT_VAR (7, N_F64, N_F32);
13043 CVT_VAR (8, N_S32, N_F64 | key);
13044 CVT_VAR (9, N_U32, N_F64 | key);
13045 CVT_VAR (10, N_F64 | key, N_S32);
13046 CVT_VAR (11, N_F64 | key, N_U32);
13047 /* VFP instructions with bitshift. */
13048 CVT_VAR (12, N_F32 | key, N_S16);
13049 CVT_VAR (13, N_F32 | key, N_U16);
13050 CVT_VAR (14, N_F64 | key, N_S16);
13051 CVT_VAR (15, N_F64 | key, N_U16);
13052 CVT_VAR (16, N_S16, N_F32 | key);
13053 CVT_VAR (17, N_U16, N_F32 | key);
13054 CVT_VAR (18, N_S16, N_F64 | key);
13055 CVT_VAR (19, N_U16, N_F64 | key);
13057 return -1;
13058 #undef CVT_VAR
13061 /* Neon-syntax VFP conversions. */
13063 static void
13064 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
13066 const char *opname = 0;
13068 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
13070 /* Conversions with immediate bitshift. */
13071 const char *enc[] =
13073 "ftosls",
13074 "ftouls",
13075 "fsltos",
13076 "fultos",
13077 NULL,
13078 NULL,
13079 NULL,
13080 NULL,
13081 "ftosld",
13082 "ftould",
13083 "fsltod",
13084 "fultod",
13085 "fshtos",
13086 "fuhtos",
13087 "fshtod",
13088 "fuhtod",
13089 "ftoshs",
13090 "ftouhs",
13091 "ftoshd",
13092 "ftouhd"
13095 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13097 opname = enc[flavour];
13098 constraint (inst.operands[0].reg != inst.operands[1].reg,
13099 _("operands 0 and 1 must be the same register"));
13100 inst.operands[1] = inst.operands[2];
13101 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13104 else
13106 /* Conversions without bitshift. */
13107 const char *enc[] =
13109 "ftosis",
13110 "ftouis",
13111 "fsitos",
13112 "fuitos",
13113 "NULL",
13114 "NULL",
13115 "fcvtsd",
13116 "fcvtds",
13117 "ftosid",
13118 "ftouid",
13119 "fsitod",
13120 "fuitod"
13123 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13124 opname = enc[flavour];
13127 if (opname)
13128 do_vfp_nsyn_opcode (opname);
13131 static void
13132 do_vfp_nsyn_cvtz (void)
13134 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13135 int flavour = neon_cvt_flavour (rs);
13136 const char *enc[] =
13138 "ftosizs",
13139 "ftouizs",
13140 NULL,
13141 NULL,
13142 NULL,
13143 NULL,
13144 NULL,
13145 NULL,
13146 "ftosizd",
13147 "ftouizd"
13150 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13151 do_vfp_nsyn_opcode (enc[flavour]);
13154 static void
13155 do_neon_cvt (void)
13157 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
13158 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
13159 int flavour = neon_cvt_flavour (rs);
13161 /* VFP rather than Neon conversions. */
13162 if (flavour >= 6)
13164 do_vfp_nsyn_cvt (rs, flavour);
13165 return;
13168 switch (rs)
13170 case NS_DDI:
13171 case NS_QQI:
13173 unsigned immbits;
13174 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13176 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13177 return;
13179 /* Fixed-point conversion with #0 immediate is encoded as an
13180 integer conversion. */
13181 if (inst.operands[2].present && inst.operands[2].imm == 0)
13182 goto int_encode;
13183 immbits = 32 - inst.operands[2].imm;
13184 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13185 if (flavour != -1)
13186 inst.instruction |= enctab[flavour];
13187 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13188 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13189 inst.instruction |= LOW4 (inst.operands[1].reg);
13190 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13191 inst.instruction |= neon_quad (rs) << 6;
13192 inst.instruction |= 1 << 21;
13193 inst.instruction |= immbits << 16;
13195 inst.instruction = neon_dp_fixup (inst.instruction);
13197 break;
13199 case NS_DD:
13200 case NS_QQ:
13201 int_encode:
13203 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13205 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13207 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13208 return;
13210 if (flavour != -1)
13211 inst.instruction |= enctab[flavour];
13213 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13214 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13215 inst.instruction |= LOW4 (inst.operands[1].reg);
13216 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13217 inst.instruction |= neon_quad (rs) << 6;
13218 inst.instruction |= 2 << 18;
13220 inst.instruction = neon_dp_fixup (inst.instruction);
13222 break;
13224 /* Half-precision conversions for Advanced SIMD -- neon. */
13225 case NS_QD:
13226 case NS_DQ:
13228 if ((rs == NS_DQ)
13229 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13231 as_bad (_("operand size must match register width"));
13232 break;
13235 if ((rs == NS_QD)
13236 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13238 as_bad (_("operand size must match register width"));
13239 break;
13242 if (rs == NS_DQ)
13243 inst.instruction = 0x3b60600;
13244 else
13245 inst.instruction = 0x3b60700;
13247 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13248 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13249 inst.instruction |= LOW4 (inst.operands[1].reg);
13250 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13251 inst.instruction = neon_dp_fixup (inst.instruction);
13252 break;
13254 default:
13255 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13256 do_vfp_nsyn_cvt (rs, flavour);
13260 static void
13261 do_neon_cvtb (void)
13263 inst.instruction = 0xeb20a40;
13265 /* The sizes are attached to the mnemonic. */
13266 if (inst.vectype.el[0].type != NT_invtype
13267 && inst.vectype.el[0].size == 16)
13268 inst.instruction |= 0x00010000;
13270 /* Programmer's syntax: the sizes are attached to the operands. */
13271 else if (inst.operands[0].vectype.type != NT_invtype
13272 && inst.operands[0].vectype.size == 16)
13273 inst.instruction |= 0x00010000;
13275 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13276 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13277 do_vfp_cond_or_thumb ();
13281 static void
13282 do_neon_cvtt (void)
13284 do_neon_cvtb ();
13285 inst.instruction |= 0x80;
13288 static void
13289 neon_move_immediate (void)
13291 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13292 struct neon_type_el et = neon_check_type (2, rs,
13293 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13294 unsigned immlo, immhi = 0, immbits;
13295 int op, cmode, float_p;
13297 constraint (et.type == NT_invtype,
13298 _("operand size must be specified for immediate VMOV"));
13300 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13301 op = (inst.instruction & (1 << 5)) != 0;
13303 immlo = inst.operands[1].imm;
13304 if (inst.operands[1].regisimm)
13305 immhi = inst.operands[1].reg;
13307 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13308 _("immediate has bits set outside the operand size"));
13310 float_p = inst.operands[1].immisfloat;
13312 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
13313 et.size, et.type)) == FAIL)
13315 /* Invert relevant bits only. */
13316 neon_invert_size (&immlo, &immhi, et.size);
13317 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13318 with one or the other; those cases are caught by
13319 neon_cmode_for_move_imm. */
13320 op = !op;
13321 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13322 &op, et.size, et.type)) == FAIL)
13324 first_error (_("immediate out of range"));
13325 return;
13329 inst.instruction &= ~(1 << 5);
13330 inst.instruction |= op << 5;
13332 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13333 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13334 inst.instruction |= neon_quad (rs) << 6;
13335 inst.instruction |= cmode << 8;
13337 neon_write_immbits (immbits);
13340 static void
13341 do_neon_mvn (void)
13343 if (inst.operands[1].isreg)
13345 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13347 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13348 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13349 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13350 inst.instruction |= LOW4 (inst.operands[1].reg);
13351 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13352 inst.instruction |= neon_quad (rs) << 6;
13354 else
13356 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13357 neon_move_immediate ();
13360 inst.instruction = neon_dp_fixup (inst.instruction);
13363 /* Encode instructions of form:
13365 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13366 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
13368 static void
13369 neon_mixed_length (struct neon_type_el et, unsigned size)
13371 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13372 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13373 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13374 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13375 inst.instruction |= LOW4 (inst.operands[2].reg);
13376 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13377 inst.instruction |= (et.type == NT_unsigned) << 24;
13378 inst.instruction |= neon_logbits (size) << 20;
13380 inst.instruction = neon_dp_fixup (inst.instruction);
13383 static void
13384 do_neon_dyadic_long (void)
13386 /* FIXME: Type checking for lengthening op. */
13387 struct neon_type_el et = neon_check_type (3, NS_QDD,
13388 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
13389 neon_mixed_length (et, et.size);
13392 static void
13393 do_neon_abal (void)
13395 struct neon_type_el et = neon_check_type (3, NS_QDD,
13396 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
13397 neon_mixed_length (et, et.size);
13400 static void
13401 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13403 if (inst.operands[2].isscalar)
13405 struct neon_type_el et = neon_check_type (3, NS_QDS,
13406 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
13407 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13408 neon_mul_mac (et, et.type == NT_unsigned);
13410 else
13412 struct neon_type_el et = neon_check_type (3, NS_QDD,
13413 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
13414 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13415 neon_mixed_length (et, et.size);
13419 static void
13420 do_neon_mac_maybe_scalar_long (void)
13422 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13425 static void
13426 do_neon_dyadic_wide (void)
13428 struct neon_type_el et = neon_check_type (3, NS_QQD,
13429 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
13430 neon_mixed_length (et, et.size);
13433 static void
13434 do_neon_dyadic_narrow (void)
13436 struct neon_type_el et = neon_check_type (3, NS_QDD,
13437 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
13438 /* Operand sign is unimportant, and the U bit is part of the opcode,
13439 so force the operand type to integer. */
13440 et.type = NT_integer;
13441 neon_mixed_length (et, et.size / 2);
13444 static void
13445 do_neon_mul_sat_scalar_long (void)
13447 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13450 static void
13451 do_neon_vmull (void)
13453 if (inst.operands[2].isscalar)
13454 do_neon_mac_maybe_scalar_long ();
13455 else
13457 struct neon_type_el et = neon_check_type (3, NS_QDD,
13458 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
13459 if (et.type == NT_poly)
13460 inst.instruction = NEON_ENC_POLY (inst.instruction);
13461 else
13462 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13463 /* For polynomial encoding, size field must be 0b00 and the U bit must be
13464 zero. Should be OK as-is. */
13465 neon_mixed_length (et, et.size);
13469 static void
13470 do_neon_ext (void)
13472 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
13473 struct neon_type_el et = neon_check_type (3, rs,
13474 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13475 unsigned imm = (inst.operands[3].imm * et.size) / 8;
13477 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13478 _("shift out of range"));
13479 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13480 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13481 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13482 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13483 inst.instruction |= LOW4 (inst.operands[2].reg);
13484 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13485 inst.instruction |= neon_quad (rs) << 6;
13486 inst.instruction |= imm << 8;
13488 inst.instruction = neon_dp_fixup (inst.instruction);
13491 static void
13492 do_neon_rev (void)
13494 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13495 struct neon_type_el et = neon_check_type (2, rs,
13496 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13497 unsigned op = (inst.instruction >> 7) & 3;
13498 /* N (width of reversed regions) is encoded as part of the bitmask. We
13499 extract it here to check the elements to be reversed are smaller.
13500 Otherwise we'd get a reserved instruction. */
13501 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
13502 assert (elsize != 0);
13503 constraint (et.size >= elsize,
13504 _("elements must be smaller than reversal region"));
13505 neon_two_same (neon_quad (rs), 1, et.size);
13508 static void
13509 do_neon_dup (void)
13511 if (inst.operands[1].isscalar)
13513 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
13514 struct neon_type_el et = neon_check_type (2, rs,
13515 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13516 unsigned sizebits = et.size >> 3;
13517 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
13518 int logsize = neon_logbits (et.size);
13519 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
13521 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13522 return;
13524 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13525 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13526 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13527 inst.instruction |= LOW4 (dm);
13528 inst.instruction |= HI1 (dm) << 5;
13529 inst.instruction |= neon_quad (rs) << 6;
13530 inst.instruction |= x << 17;
13531 inst.instruction |= sizebits << 16;
13533 inst.instruction = neon_dp_fixup (inst.instruction);
13535 else
13537 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13538 struct neon_type_el et = neon_check_type (2, rs,
13539 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13540 /* Duplicate ARM register to lanes of vector. */
13541 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13542 switch (et.size)
13544 case 8: inst.instruction |= 0x400000; break;
13545 case 16: inst.instruction |= 0x000020; break;
13546 case 32: inst.instruction |= 0x000000; break;
13547 default: break;
13549 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13550 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13551 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
13552 inst.instruction |= neon_quad (rs) << 21;
13553 /* The encoding for this instruction is identical for the ARM and Thumb
13554 variants, except for the condition field. */
13555 do_vfp_cond_or_thumb ();
13559 /* VMOV has particularly many variations. It can be one of:
13560 0. VMOV<c><q> <Qd>, <Qm>
13561 1. VMOV<c><q> <Dd>, <Dm>
13562 (Register operations, which are VORR with Rm = Rn.)
13563 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13564 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13565 (Immediate loads.)
13566 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13567 (ARM register to scalar.)
13568 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13569 (Two ARM registers to vector.)
13570 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13571 (Scalar to ARM register.)
13572 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13573 (Vector to two ARM registers.)
13574 8. VMOV.F32 <Sd>, <Sm>
13575 9. VMOV.F64 <Dd>, <Dm>
13576 (VFP register moves.)
13577 10. VMOV.F32 <Sd>, #imm
13578 11. VMOV.F64 <Dd>, #imm
13579 (VFP float immediate load.)
13580 12. VMOV <Rd>, <Sm>
13581 (VFP single to ARM reg.)
13582 13. VMOV <Sd>, <Rm>
13583 (ARM reg to VFP single.)
13584 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13585 (Two ARM regs to two VFP singles.)
13586 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13587 (Two VFP singles to two ARM regs.)
13589 These cases can be disambiguated using neon_select_shape, except cases 1/9
13590 and 3/11 which depend on the operand type too.
13592 All the encoded bits are hardcoded by this function.
13594 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13595 Cases 5, 7 may be used with VFPv2 and above.
13597 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13598 can specify a type where it doesn't make sense to, and is ignored). */
13600 static void
13601 do_neon_mov (void)
13603 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13604 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13605 NS_NULL);
13606 struct neon_type_el et;
13607 const char *ldconst = 0;
13609 switch (rs)
13611 case NS_DD: /* case 1/9. */
13612 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13613 /* It is not an error here if no type is given. */
13614 inst.error = NULL;
13615 if (et.type == NT_float && et.size == 64)
13617 do_vfp_nsyn_opcode ("fcpyd");
13618 break;
13620 /* fall through. */
13622 case NS_QQ: /* case 0/1. */
13624 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13625 return;
13626 /* The architecture manual I have doesn't explicitly state which
13627 value the U bit should have for register->register moves, but
13628 the equivalent VORR instruction has U = 0, so do that. */
13629 inst.instruction = 0x0200110;
13630 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13631 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13632 inst.instruction |= LOW4 (inst.operands[1].reg);
13633 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13634 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13635 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13636 inst.instruction |= neon_quad (rs) << 6;
13638 inst.instruction = neon_dp_fixup (inst.instruction);
13640 break;
13642 case NS_DI: /* case 3/11. */
13643 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13644 inst.error = NULL;
13645 if (et.type == NT_float && et.size == 64)
13647 /* case 11 (fconstd). */
13648 ldconst = "fconstd";
13649 goto encode_fconstd;
13651 /* fall through. */
13653 case NS_QI: /* case 2/3. */
13654 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13655 return;
13656 inst.instruction = 0x0800010;
13657 neon_move_immediate ();
13658 inst.instruction = neon_dp_fixup (inst.instruction);
13659 break;
13661 case NS_SR: /* case 4. */
13663 unsigned bcdebits = 0;
13664 struct neon_type_el et = neon_check_type (2, NS_NULL,
13665 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13666 int logsize = neon_logbits (et.size);
13667 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13668 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13670 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13671 _(BAD_FPU));
13672 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13673 && et.size != 32, _(BAD_FPU));
13674 constraint (et.type == NT_invtype, _("bad type for scalar"));
13675 constraint (x >= 64 / et.size, _("scalar index out of range"));
13677 switch (et.size)
13679 case 8: bcdebits = 0x8; break;
13680 case 16: bcdebits = 0x1; break;
13681 case 32: bcdebits = 0x0; break;
13682 default: ;
13685 bcdebits |= x << logsize;
13687 inst.instruction = 0xe000b10;
13688 do_vfp_cond_or_thumb ();
13689 inst.instruction |= LOW4 (dn) << 16;
13690 inst.instruction |= HI1 (dn) << 7;
13691 inst.instruction |= inst.operands[1].reg << 12;
13692 inst.instruction |= (bcdebits & 3) << 5;
13693 inst.instruction |= (bcdebits >> 2) << 21;
13695 break;
13697 case NS_DRR: /* case 5 (fmdrr). */
13698 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13699 _(BAD_FPU));
13701 inst.instruction = 0xc400b10;
13702 do_vfp_cond_or_thumb ();
13703 inst.instruction |= LOW4 (inst.operands[0].reg);
13704 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13705 inst.instruction |= inst.operands[1].reg << 12;
13706 inst.instruction |= inst.operands[2].reg << 16;
13707 break;
13709 case NS_RS: /* case 6. */
13711 struct neon_type_el et = neon_check_type (2, NS_NULL,
13712 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13713 unsigned logsize = neon_logbits (et.size);
13714 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13715 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13716 unsigned abcdebits = 0;
13718 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13719 _(BAD_FPU));
13720 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13721 && et.size != 32, _(BAD_FPU));
13722 constraint (et.type == NT_invtype, _("bad type for scalar"));
13723 constraint (x >= 64 / et.size, _("scalar index out of range"));
13725 switch (et.size)
13727 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13728 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13729 case 32: abcdebits = 0x00; break;
13730 default: ;
13733 abcdebits |= x << logsize;
13734 inst.instruction = 0xe100b10;
13735 do_vfp_cond_or_thumb ();
13736 inst.instruction |= LOW4 (dn) << 16;
13737 inst.instruction |= HI1 (dn) << 7;
13738 inst.instruction |= inst.operands[0].reg << 12;
13739 inst.instruction |= (abcdebits & 3) << 5;
13740 inst.instruction |= (abcdebits >> 2) << 21;
13742 break;
13744 case NS_RRD: /* case 7 (fmrrd). */
13745 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13746 _(BAD_FPU));
13748 inst.instruction = 0xc500b10;
13749 do_vfp_cond_or_thumb ();
13750 inst.instruction |= inst.operands[0].reg << 12;
13751 inst.instruction |= inst.operands[1].reg << 16;
13752 inst.instruction |= LOW4 (inst.operands[2].reg);
13753 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13754 break;
13756 case NS_FF: /* case 8 (fcpys). */
13757 do_vfp_nsyn_opcode ("fcpys");
13758 break;
13760 case NS_FI: /* case 10 (fconsts). */
13761 ldconst = "fconsts";
13762 encode_fconstd:
13763 if (is_quarter_float (inst.operands[1].imm))
13765 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13766 do_vfp_nsyn_opcode (ldconst);
13768 else
13769 first_error (_("immediate out of range"));
13770 break;
13772 case NS_RF: /* case 12 (fmrs). */
13773 do_vfp_nsyn_opcode ("fmrs");
13774 break;
13776 case NS_FR: /* case 13 (fmsr). */
13777 do_vfp_nsyn_opcode ("fmsr");
13778 break;
13780 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13781 (one of which is a list), but we have parsed four. Do some fiddling to
13782 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13783 expect. */
13784 case NS_RRFF: /* case 14 (fmrrs). */
13785 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13786 _("VFP registers must be adjacent"));
13787 inst.operands[2].imm = 2;
13788 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13789 do_vfp_nsyn_opcode ("fmrrs");
13790 break;
13792 case NS_FFRR: /* case 15 (fmsrr). */
13793 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13794 _("VFP registers must be adjacent"));
13795 inst.operands[1] = inst.operands[2];
13796 inst.operands[2] = inst.operands[3];
13797 inst.operands[0].imm = 2;
13798 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13799 do_vfp_nsyn_opcode ("fmsrr");
13800 break;
13802 default:
13803 abort ();
13807 static void
13808 do_neon_rshift_round_imm (void)
13810 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13811 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13812 int imm = inst.operands[2].imm;
13814 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13815 if (imm == 0)
13817 inst.operands[2].present = 0;
13818 do_neon_mov ();
13819 return;
13822 constraint (imm < 1 || (unsigned)imm > et.size,
13823 _("immediate out of range for shift"));
13824 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13825 et.size - imm);
13828 static void
13829 do_neon_movl (void)
13831 struct neon_type_el et = neon_check_type (2, NS_QD,
13832 N_EQK | N_DBL, N_SU_32 | N_KEY);
13833 unsigned sizebits = et.size >> 3;
13834 inst.instruction |= sizebits << 19;
13835 neon_two_same (0, et.type == NT_unsigned, -1);
13838 static void
13839 do_neon_trn (void)
13841 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13842 struct neon_type_el et = neon_check_type (2, rs,
13843 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13844 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13845 neon_two_same (neon_quad (rs), 1, et.size);
13848 static void
13849 do_neon_zip_uzp (void)
13851 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13852 struct neon_type_el et = neon_check_type (2, rs,
13853 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13854 if (rs == NS_DD && et.size == 32)
13856 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13857 inst.instruction = N_MNEM_vtrn;
13858 do_neon_trn ();
13859 return;
13861 neon_two_same (neon_quad (rs), 1, et.size);
13864 static void
13865 do_neon_sat_abs_neg (void)
13867 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13868 struct neon_type_el et = neon_check_type (2, rs,
13869 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13870 neon_two_same (neon_quad (rs), 1, et.size);
13873 static void
13874 do_neon_pair_long (void)
13876 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13877 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13878 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13879 inst.instruction |= (et.type == NT_unsigned) << 7;
13880 neon_two_same (neon_quad (rs), 1, et.size);
13883 static void
13884 do_neon_recip_est (void)
13886 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13887 struct neon_type_el et = neon_check_type (2, rs,
13888 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13889 inst.instruction |= (et.type == NT_float) << 8;
13890 neon_two_same (neon_quad (rs), 1, et.size);
13893 static void
13894 do_neon_cls (void)
13896 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13897 struct neon_type_el et = neon_check_type (2, rs,
13898 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13899 neon_two_same (neon_quad (rs), 1, et.size);
13902 static void
13903 do_neon_clz (void)
13905 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13906 struct neon_type_el et = neon_check_type (2, rs,
13907 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
13908 neon_two_same (neon_quad (rs), 1, et.size);
13911 static void
13912 do_neon_cnt (void)
13914 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13915 struct neon_type_el et = neon_check_type (2, rs,
13916 N_EQK | N_INT, N_8 | N_KEY);
13917 neon_two_same (neon_quad (rs), 1, et.size);
13920 static void
13921 do_neon_swp (void)
13923 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13924 neon_two_same (neon_quad (rs), 1, -1);
13927 static void
13928 do_neon_tbl_tbx (void)
13930 unsigned listlenbits;
13931 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
13933 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13935 first_error (_("bad list length for table lookup"));
13936 return;
13939 listlenbits = inst.operands[1].imm - 1;
13940 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13941 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13942 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13943 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13944 inst.instruction |= LOW4 (inst.operands[2].reg);
13945 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13946 inst.instruction |= listlenbits << 8;
13948 inst.instruction = neon_dp_fixup (inst.instruction);
13951 static void
13952 do_neon_ldm_stm (void)
13954 /* P, U and L bits are part of bitmask. */
13955 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13956 unsigned offsetbits = inst.operands[1].imm * 2;
13958 if (inst.operands[1].issingle)
13960 do_vfp_nsyn_ldm_stm (is_dbmode);
13961 return;
13964 constraint (is_dbmode && !inst.operands[0].writeback,
13965 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13967 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13968 _("register list must contain at least 1 and at most 16 "
13969 "registers"));
13971 inst.instruction |= inst.operands[0].reg << 16;
13972 inst.instruction |= inst.operands[0].writeback << 21;
13973 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13974 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13976 inst.instruction |= offsetbits;
13978 do_vfp_cond_or_thumb ();
13981 static void
13982 do_neon_ldr_str (void)
13984 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13986 if (inst.operands[0].issingle)
13988 if (is_ldr)
13989 do_vfp_nsyn_opcode ("flds");
13990 else
13991 do_vfp_nsyn_opcode ("fsts");
13993 else
13995 if (is_ldr)
13996 do_vfp_nsyn_opcode ("fldd");
13997 else
13998 do_vfp_nsyn_opcode ("fstd");
14002 /* "interleave" version also handles non-interleaving register VLD1/VST1
14003 instructions. */
14005 static void
14006 do_neon_ld_st_interleave (void)
14008 struct neon_type_el et = neon_check_type (1, NS_NULL,
14009 N_8 | N_16 | N_32 | N_64);
14010 unsigned alignbits = 0;
14011 unsigned idx;
14012 /* The bits in this table go:
14013 0: register stride of one (0) or two (1)
14014 1,2: register list length, minus one (1, 2, 3, 4).
14015 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14016 We use -1 for invalid entries. */
14017 const int typetable[] =
14019 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14020 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14021 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14022 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14024 int typebits;
14026 if (et.type == NT_invtype)
14027 return;
14029 if (inst.operands[1].immisalign)
14030 switch (inst.operands[1].imm >> 8)
14032 case 64: alignbits = 1; break;
14033 case 128:
14034 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14035 goto bad_alignment;
14036 alignbits = 2;
14037 break;
14038 case 256:
14039 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14040 goto bad_alignment;
14041 alignbits = 3;
14042 break;
14043 default:
14044 bad_alignment:
14045 first_error (_("bad alignment"));
14046 return;
14049 inst.instruction |= alignbits << 4;
14050 inst.instruction |= neon_logbits (et.size) << 6;
14052 /* Bits [4:6] of the immediate in a list specifier encode register stride
14053 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14054 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14055 up the right value for "type" in a table based on this value and the given
14056 list style, then stick it back. */
14057 idx = ((inst.operands[0].imm >> 4) & 7)
14058 | (((inst.instruction >> 8) & 3) << 3);
14060 typebits = typetable[idx];
14062 constraint (typebits == -1, _("bad list type for instruction"));
14064 inst.instruction &= ~0xf00;
14065 inst.instruction |= typebits << 8;
14068 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14069 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14070 otherwise. The variable arguments are a list of pairs of legal (size, align)
14071 values, terminated with -1. */
14073 static int
14074 neon_alignment_bit (int size, int align, int *do_align, ...)
14076 va_list ap;
14077 int result = FAIL, thissize, thisalign;
14079 if (!inst.operands[1].immisalign)
14081 *do_align = 0;
14082 return SUCCESS;
14085 va_start (ap, do_align);
14089 thissize = va_arg (ap, int);
14090 if (thissize == -1)
14091 break;
14092 thisalign = va_arg (ap, int);
14094 if (size == thissize && align == thisalign)
14095 result = SUCCESS;
14097 while (result != SUCCESS);
14099 va_end (ap);
14101 if (result == SUCCESS)
14102 *do_align = 1;
14103 else
14104 first_error (_("unsupported alignment for instruction"));
14106 return result;
14109 static void
14110 do_neon_ld_st_lane (void)
14112 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14113 int align_good, do_align = 0;
14114 int logsize = neon_logbits (et.size);
14115 int align = inst.operands[1].imm >> 8;
14116 int n = (inst.instruction >> 8) & 3;
14117 int max_el = 64 / et.size;
14119 if (et.type == NT_invtype)
14120 return;
14122 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14123 _("bad list length"));
14124 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14125 _("scalar index out of range"));
14126 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14127 && et.size == 8,
14128 _("stride of 2 unavailable when element size is 8"));
14130 switch (n)
14132 case 0: /* VLD1 / VST1. */
14133 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14134 32, 32, -1);
14135 if (align_good == FAIL)
14136 return;
14137 if (do_align)
14139 unsigned alignbits = 0;
14140 switch (et.size)
14142 case 16: alignbits = 0x1; break;
14143 case 32: alignbits = 0x3; break;
14144 default: ;
14146 inst.instruction |= alignbits << 4;
14148 break;
14150 case 1: /* VLD2 / VST2. */
14151 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14152 32, 64, -1);
14153 if (align_good == FAIL)
14154 return;
14155 if (do_align)
14156 inst.instruction |= 1 << 4;
14157 break;
14159 case 2: /* VLD3 / VST3. */
14160 constraint (inst.operands[1].immisalign,
14161 _("can't use alignment with this instruction"));
14162 break;
14164 case 3: /* VLD4 / VST4. */
14165 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14166 16, 64, 32, 64, 32, 128, -1);
14167 if (align_good == FAIL)
14168 return;
14169 if (do_align)
14171 unsigned alignbits = 0;
14172 switch (et.size)
14174 case 8: alignbits = 0x1; break;
14175 case 16: alignbits = 0x1; break;
14176 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14177 default: ;
14179 inst.instruction |= alignbits << 4;
14181 break;
14183 default: ;
14186 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14187 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14188 inst.instruction |= 1 << (4 + logsize);
14190 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14191 inst.instruction |= logsize << 10;
14194 /* Encode single n-element structure to all lanes VLD<n> instructions. */
14196 static void
14197 do_neon_ld_dup (void)
14199 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14200 int align_good, do_align = 0;
14202 if (et.type == NT_invtype)
14203 return;
14205 switch ((inst.instruction >> 8) & 3)
14207 case 0: /* VLD1. */
14208 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
14209 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14210 &do_align, 16, 16, 32, 32, -1);
14211 if (align_good == FAIL)
14212 return;
14213 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14215 case 1: break;
14216 case 2: inst.instruction |= 1 << 5; break;
14217 default: first_error (_("bad list length")); return;
14219 inst.instruction |= neon_logbits (et.size) << 6;
14220 break;
14222 case 1: /* VLD2. */
14223 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14224 &do_align, 8, 16, 16, 32, 32, 64, -1);
14225 if (align_good == FAIL)
14226 return;
14227 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14228 _("bad list length"));
14229 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14230 inst.instruction |= 1 << 5;
14231 inst.instruction |= neon_logbits (et.size) << 6;
14232 break;
14234 case 2: /* VLD3. */
14235 constraint (inst.operands[1].immisalign,
14236 _("can't use alignment with this instruction"));
14237 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14238 _("bad list length"));
14239 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14240 inst.instruction |= 1 << 5;
14241 inst.instruction |= neon_logbits (et.size) << 6;
14242 break;
14244 case 3: /* VLD4. */
14246 int align = inst.operands[1].imm >> 8;
14247 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14248 16, 64, 32, 64, 32, 128, -1);
14249 if (align_good == FAIL)
14250 return;
14251 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14252 _("bad list length"));
14253 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14254 inst.instruction |= 1 << 5;
14255 if (et.size == 32 && align == 128)
14256 inst.instruction |= 0x3 << 6;
14257 else
14258 inst.instruction |= neon_logbits (et.size) << 6;
14260 break;
14262 default: ;
14265 inst.instruction |= do_align << 4;
14268 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14269 apart from bits [11:4]. */
14271 static void
14272 do_neon_ldx_stx (void)
14274 switch (NEON_LANE (inst.operands[0].imm))
14276 case NEON_INTERLEAVE_LANES:
14277 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
14278 do_neon_ld_st_interleave ();
14279 break;
14281 case NEON_ALL_LANES:
14282 inst.instruction = NEON_ENC_DUP (inst.instruction);
14283 do_neon_ld_dup ();
14284 break;
14286 default:
14287 inst.instruction = NEON_ENC_LANE (inst.instruction);
14288 do_neon_ld_st_lane ();
14291 /* L bit comes from bit mask. */
14292 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14293 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14294 inst.instruction |= inst.operands[1].reg << 16;
14296 if (inst.operands[1].postind)
14298 int postreg = inst.operands[1].imm & 0xf;
14299 constraint (!inst.operands[1].immisreg,
14300 _("post-index must be a register"));
14301 constraint (postreg == 0xd || postreg == 0xf,
14302 _("bad register for post-index"));
14303 inst.instruction |= postreg;
14305 else if (inst.operands[1].writeback)
14307 inst.instruction |= 0xd;
14309 else
14310 inst.instruction |= 0xf;
14312 if (thumb_mode)
14313 inst.instruction |= 0xf9000000;
14314 else
14315 inst.instruction |= 0xf4000000;
14318 /* Overall per-instruction processing. */
14320 /* We need to be able to fix up arbitrary expressions in some statements.
14321 This is so that we can handle symbols that are an arbitrary distance from
14322 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14323 which returns part of an address in a form which will be valid for
14324 a data instruction. We do this by pushing the expression into a symbol
14325 in the expr_section, and creating a fix for that. */
14327 static void
14328 fix_new_arm (fragS * frag,
14329 int where,
14330 short int size,
14331 expressionS * exp,
14332 int pc_rel,
14333 int reloc)
14335 fixS * new_fix;
14337 switch (exp->X_op)
14339 case O_constant:
14340 case O_symbol:
14341 case O_add:
14342 case O_subtract:
14343 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
14344 break;
14346 default:
14347 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
14348 pc_rel, reloc);
14349 break;
14352 /* Mark whether the fix is to a THUMB instruction, or an ARM
14353 instruction. */
14354 new_fix->tc_fix_data = thumb_mode;
14357 /* Create a frg for an instruction requiring relaxation. */
14358 static void
14359 output_relax_insn (void)
14361 char * to;
14362 symbolS *sym;
14363 int offset;
14365 /* The size of the instruction is unknown, so tie the debug info to the
14366 start of the instruction. */
14367 dwarf2_emit_insn (0);
14369 switch (inst.reloc.exp.X_op)
14371 case O_symbol:
14372 sym = inst.reloc.exp.X_add_symbol;
14373 offset = inst.reloc.exp.X_add_number;
14374 break;
14375 case O_constant:
14376 sym = NULL;
14377 offset = inst.reloc.exp.X_add_number;
14378 break;
14379 default:
14380 sym = make_expr_symbol (&inst.reloc.exp);
14381 offset = 0;
14382 break;
14384 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
14385 inst.relax, sym, offset, NULL/*offset, opcode*/);
14386 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
14389 /* Write a 32-bit thumb instruction to buf. */
14390 static void
14391 put_thumb32_insn (char * buf, unsigned long insn)
14393 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
14394 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
14397 static void
14398 output_inst (const char * str)
14400 char * to = NULL;
14402 if (inst.error)
14404 as_bad ("%s -- `%s'", inst.error, str);
14405 return;
14407 if (inst.relax)
14409 output_relax_insn ();
14410 return;
14412 if (inst.size == 0)
14413 return;
14415 to = frag_more (inst.size);
14416 /* PR 9814: Record the thumb mode into the current frag so that we know
14417 what type of NOP padding to use, if necessary. We override any previous
14418 setting so that if the mode has changed then the NOPS that we use will
14419 match the encoding of the last instruction in the frag. */
14420 frag_now->tc_frag_data = thumb_mode | MODE_RECORDED;
14422 if (thumb_mode && (inst.size > THUMB_SIZE))
14424 assert (inst.size == (2 * THUMB_SIZE));
14425 put_thumb32_insn (to, inst.instruction);
14427 else if (inst.size > INSN_SIZE)
14429 assert (inst.size == (2 * INSN_SIZE));
14430 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14431 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
14433 else
14434 md_number_to_chars (to, inst.instruction, inst.size);
14436 if (inst.reloc.type != BFD_RELOC_UNUSED)
14437 fix_new_arm (frag_now, to - frag_now->fr_literal,
14438 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
14439 inst.reloc.type);
14441 dwarf2_emit_insn (inst.size);
14444 /* Tag values used in struct asm_opcode's tag field. */
14445 enum opcode_tag
14447 OT_unconditional, /* Instruction cannot be conditionalized.
14448 The ARM condition field is still 0xE. */
14449 OT_unconditionalF, /* Instruction cannot be conditionalized
14450 and carries 0xF in its ARM condition field. */
14451 OT_csuffix, /* Instruction takes a conditional suffix. */
14452 OT_csuffixF, /* Some forms of the instruction take a conditional
14453 suffix, others place 0xF where the condition field
14454 would be. */
14455 OT_cinfix3, /* Instruction takes a conditional infix,
14456 beginning at character index 3. (In
14457 unified mode, it becomes a suffix.) */
14458 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
14459 tsts, cmps, cmns, and teqs. */
14460 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
14461 character index 3, even in unified mode. Used for
14462 legacy instructions where suffix and infix forms
14463 may be ambiguous. */
14464 OT_csuf_or_in3, /* Instruction takes either a conditional
14465 suffix or an infix at character index 3. */
14466 OT_odd_infix_unc, /* This is the unconditional variant of an
14467 instruction that takes a conditional infix
14468 at an unusual position. In unified mode,
14469 this variant will accept a suffix. */
14470 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
14471 are the conditional variants of instructions that
14472 take conditional infixes in unusual positions.
14473 The infix appears at character index
14474 (tag - OT_odd_infix_0). These are not accepted
14475 in unified mode. */
14478 /* Subroutine of md_assemble, responsible for looking up the primary
14479 opcode from the mnemonic the user wrote. STR points to the
14480 beginning of the mnemonic.
14482 This is not simply a hash table lookup, because of conditional
14483 variants. Most instructions have conditional variants, which are
14484 expressed with a _conditional affix_ to the mnemonic. If we were
14485 to encode each conditional variant as a literal string in the opcode
14486 table, it would have approximately 20,000 entries.
14488 Most mnemonics take this affix as a suffix, and in unified syntax,
14489 'most' is upgraded to 'all'. However, in the divided syntax, some
14490 instructions take the affix as an infix, notably the s-variants of
14491 the arithmetic instructions. Of those instructions, all but six
14492 have the infix appear after the third character of the mnemonic.
14494 Accordingly, the algorithm for looking up primary opcodes given
14495 an identifier is:
14497 1. Look up the identifier in the opcode table.
14498 If we find a match, go to step U.
14500 2. Look up the last two characters of the identifier in the
14501 conditions table. If we find a match, look up the first N-2
14502 characters of the identifier in the opcode table. If we
14503 find a match, go to step CE.
14505 3. Look up the fourth and fifth characters of the identifier in
14506 the conditions table. If we find a match, extract those
14507 characters from the identifier, and look up the remaining
14508 characters in the opcode table. If we find a match, go
14509 to step CM.
14511 4. Fail.
14513 U. Examine the tag field of the opcode structure, in case this is
14514 one of the six instructions with its conditional infix in an
14515 unusual place. If it is, the tag tells us where to find the
14516 infix; look it up in the conditions table and set inst.cond
14517 accordingly. Otherwise, this is an unconditional instruction.
14518 Again set inst.cond accordingly. Return the opcode structure.
14520 CE. Examine the tag field to make sure this is an instruction that
14521 should receive a conditional suffix. If it is not, fail.
14522 Otherwise, set inst.cond from the suffix we already looked up,
14523 and return the opcode structure.
14525 CM. Examine the tag field to make sure this is an instruction that
14526 should receive a conditional infix after the third character.
14527 If it is not, fail. Otherwise, undo the edits to the current
14528 line of input and proceed as for case CE. */
14530 static const struct asm_opcode *
14531 opcode_lookup (char **str)
14533 char *end, *base;
14534 char *affix;
14535 const struct asm_opcode *opcode;
14536 const struct asm_cond *cond;
14537 char save[2];
14538 bfd_boolean neon_supported;
14540 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
14542 /* Scan up to the end of the mnemonic, which must end in white space,
14543 '.' (in unified mode, or for Neon instructions), or end of string. */
14544 for (base = end = *str; *end != '\0'; end++)
14545 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
14546 break;
14548 if (end == base)
14549 return 0;
14551 /* Handle a possible width suffix and/or Neon type suffix. */
14552 if (end[0] == '.')
14554 int offset = 2;
14556 /* The .w and .n suffixes are only valid if the unified syntax is in
14557 use. */
14558 if (unified_syntax && end[1] == 'w')
14559 inst.size_req = 4;
14560 else if (unified_syntax && end[1] == 'n')
14561 inst.size_req = 2;
14562 else
14563 offset = 0;
14565 inst.vectype.elems = 0;
14567 *str = end + offset;
14569 if (end[offset] == '.')
14571 /* See if we have a Neon type suffix (possible in either unified or
14572 non-unified ARM syntax mode). */
14573 if (parse_neon_type (&inst.vectype, str) == FAIL)
14574 return 0;
14576 else if (end[offset] != '\0' && end[offset] != ' ')
14577 return 0;
14579 else
14580 *str = end;
14582 /* Look for unaffixed or special-case affixed mnemonic. */
14583 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14584 if (opcode)
14586 /* step U */
14587 if (opcode->tag < OT_odd_infix_0)
14589 inst.cond = COND_ALWAYS;
14590 return opcode;
14593 if (warn_on_deprecated && unified_syntax)
14594 as_warn (_("conditional infixes are deprecated in unified syntax"));
14595 affix = base + (opcode->tag - OT_odd_infix_0);
14596 cond = hash_find_n (arm_cond_hsh, affix, 2);
14597 assert (cond);
14599 inst.cond = cond->value;
14600 return opcode;
14603 /* Cannot have a conditional suffix on a mnemonic of less than two
14604 characters. */
14605 if (end - base < 3)
14606 return 0;
14608 /* Look for suffixed mnemonic. */
14609 affix = end - 2;
14610 cond = hash_find_n (arm_cond_hsh, affix, 2);
14611 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14612 if (opcode && cond)
14614 /* step CE */
14615 switch (opcode->tag)
14617 case OT_cinfix3_legacy:
14618 /* Ignore conditional suffixes matched on infix only mnemonics. */
14619 break;
14621 case OT_cinfix3:
14622 case OT_cinfix3_deprecated:
14623 case OT_odd_infix_unc:
14624 if (!unified_syntax)
14625 return 0;
14626 /* else fall through */
14628 case OT_csuffix:
14629 case OT_csuffixF:
14630 case OT_csuf_or_in3:
14631 inst.cond = cond->value;
14632 return opcode;
14634 case OT_unconditional:
14635 case OT_unconditionalF:
14636 if (thumb_mode)
14638 inst.cond = cond->value;
14640 else
14642 /* delayed diagnostic */
14643 inst.error = BAD_COND;
14644 inst.cond = COND_ALWAYS;
14646 return opcode;
14648 default:
14649 return 0;
14653 /* Cannot have a usual-position infix on a mnemonic of less than
14654 six characters (five would be a suffix). */
14655 if (end - base < 6)
14656 return 0;
14658 /* Look for infixed mnemonic in the usual position. */
14659 affix = base + 3;
14660 cond = hash_find_n (arm_cond_hsh, affix, 2);
14661 if (!cond)
14662 return 0;
14664 memcpy (save, affix, 2);
14665 memmove (affix, affix + 2, (end - affix) - 2);
14666 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14667 memmove (affix + 2, affix, (end - affix) - 2);
14668 memcpy (affix, save, 2);
14670 if (opcode
14671 && (opcode->tag == OT_cinfix3
14672 || opcode->tag == OT_cinfix3_deprecated
14673 || opcode->tag == OT_csuf_or_in3
14674 || opcode->tag == OT_cinfix3_legacy))
14676 /* step CM */
14677 if (warn_on_deprecated && unified_syntax
14678 && (opcode->tag == OT_cinfix3
14679 || opcode->tag == OT_cinfix3_deprecated))
14680 as_warn (_("conditional infixes are deprecated in unified syntax"));
14682 inst.cond = cond->value;
14683 return opcode;
14686 return 0;
14689 void
14690 md_assemble (char *str)
14692 char *p = str;
14693 const struct asm_opcode * opcode;
14695 /* Align the previous label if needed. */
14696 if (last_label_seen != NULL)
14698 symbol_set_frag (last_label_seen, frag_now);
14699 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14700 S_SET_SEGMENT (last_label_seen, now_seg);
14703 memset (&inst, '\0', sizeof (inst));
14704 inst.reloc.type = BFD_RELOC_UNUSED;
14706 opcode = opcode_lookup (&p);
14707 if (!opcode)
14709 /* It wasn't an instruction, but it might be a register alias of
14710 the form alias .req reg, or a Neon .dn/.qn directive. */
14711 if (!create_register_alias (str, p)
14712 && !create_neon_reg_alias (str, p))
14713 as_bad (_("bad instruction `%s'"), str);
14715 return;
14718 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
14719 as_warn (_("s suffix on comparison instruction is deprecated"));
14721 /* The value which unconditional instructions should have in place of the
14722 condition field. */
14723 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14725 if (thumb_mode)
14727 arm_feature_set variant;
14729 variant = cpu_variant;
14730 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
14731 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14732 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
14733 /* Check that this instruction is supported for this CPU. */
14734 if (!opcode->tvariant
14735 || (thumb_mode == 1
14736 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
14738 as_bad (_("selected processor does not support `%s'"), str);
14739 return;
14741 if (inst.cond != COND_ALWAYS && !unified_syntax
14742 && opcode->tencode != do_t_branch)
14744 as_bad (_("Thumb does not support conditional execution"));
14745 return;
14748 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14750 /* Implicit require narrow instructions on Thumb-1. This avoids
14751 relaxation accidentally introducing Thumb-2 instructions. */
14752 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
14753 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
14754 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
14755 inst.size_req = 2;
14758 /* Check conditional suffixes. */
14759 if (current_it_mask)
14761 int cond;
14762 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
14763 current_it_mask <<= 1;
14764 current_it_mask &= 0x1f;
14765 /* The BKPT instruction is unconditional even in an IT block. */
14766 if (!inst.error
14767 && cond != inst.cond && opcode->tencode != do_t_bkpt)
14769 as_bad (_("incorrect condition in IT block"));
14770 return;
14773 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14775 as_bad (_("thumb conditional instruction not in IT block"));
14776 return;
14779 mapping_state (MAP_THUMB);
14780 inst.instruction = opcode->tvalue;
14782 if (!parse_operands (p, opcode->operands))
14783 opcode->tencode ();
14785 /* Clear current_it_mask at the end of an IT block. */
14786 if (current_it_mask == 0x10)
14787 current_it_mask = 0;
14789 if (!(inst.error || inst.relax))
14791 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14792 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14793 if (inst.size_req && inst.size_req != inst.size)
14795 as_bad (_("cannot honor width suffix -- `%s'"), str);
14796 return;
14800 /* Something has gone badly wrong if we try to relax a fixed size
14801 instruction. */
14802 assert (inst.size_req == 0 || !inst.relax);
14804 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14805 *opcode->tvariant);
14806 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
14807 set those bits when Thumb-2 32-bit instructions are seen. ie.
14808 anything other than bl/blx and v6-M instructions.
14809 This is overly pessimistic for relaxable instructions. */
14810 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14811 || inst.relax)
14812 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
14813 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
14814 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14815 arm_ext_v6t2);
14817 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
14819 bfd_boolean is_bx;
14821 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14822 is_bx = (opcode->aencode == do_bx);
14824 /* Check that this instruction is supported for this CPU. */
14825 if (!(is_bx && fix_v4bx)
14826 && !(opcode->avariant &&
14827 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
14829 as_bad (_("selected processor does not support `%s'"), str);
14830 return;
14832 if (inst.size_req)
14834 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14835 return;
14838 mapping_state (MAP_ARM);
14839 inst.instruction = opcode->avalue;
14840 if (opcode->tag == OT_unconditionalF)
14841 inst.instruction |= 0xF << 28;
14842 else
14843 inst.instruction |= inst.cond << 28;
14844 inst.size = INSN_SIZE;
14845 if (!parse_operands (p, opcode->operands))
14846 opcode->aencode ();
14847 /* Arm mode bx is marked as both v4T and v5 because it's still required
14848 on a hypothetical non-thumb v5 core. */
14849 if (is_bx)
14850 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
14851 else
14852 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14853 *opcode->avariant);
14855 else
14857 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14858 "-- `%s'"), str);
14859 return;
14861 output_inst (str);
14864 /* Various frobbings of labels and their addresses. */
14866 void
14867 arm_start_line_hook (void)
14869 last_label_seen = NULL;
14872 void
14873 arm_frob_label (symbolS * sym)
14875 last_label_seen = sym;
14877 ARM_SET_THUMB (sym, thumb_mode);
14879 #if defined OBJ_COFF || defined OBJ_ELF
14880 ARM_SET_INTERWORK (sym, support_interwork);
14881 #endif
14883 /* Note - do not allow local symbols (.Lxxx) to be labelled
14884 as Thumb functions. This is because these labels, whilst
14885 they exist inside Thumb code, are not the entry points for
14886 possible ARM->Thumb calls. Also, these labels can be used
14887 as part of a computed goto or switch statement. eg gcc
14888 can generate code that looks like this:
14890 ldr r2, [pc, .Laaa]
14891 lsl r3, r3, #2
14892 ldr r2, [r3, r2]
14893 mov pc, r2
14895 .Lbbb: .word .Lxxx
14896 .Lccc: .word .Lyyy
14897 ..etc...
14898 .Laaa: .word Lbbb
14900 The first instruction loads the address of the jump table.
14901 The second instruction converts a table index into a byte offset.
14902 The third instruction gets the jump address out of the table.
14903 The fourth instruction performs the jump.
14905 If the address stored at .Laaa is that of a symbol which has the
14906 Thumb_Func bit set, then the linker will arrange for this address
14907 to have the bottom bit set, which in turn would mean that the
14908 address computation performed by the third instruction would end
14909 up with the bottom bit set. Since the ARM is capable of unaligned
14910 word loads, the instruction would then load the incorrect address
14911 out of the jump table, and chaos would ensue. */
14912 if (label_is_thumb_function_name
14913 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14914 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
14916 /* When the address of a Thumb function is taken the bottom
14917 bit of that address should be set. This will allow
14918 interworking between Arm and Thumb functions to work
14919 correctly. */
14921 THUMB_SET_FUNC (sym, 1);
14923 label_is_thumb_function_name = FALSE;
14926 dwarf2_emit_label (sym);
14930 arm_data_in_code (void)
14932 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
14934 *input_line_pointer = '/';
14935 input_line_pointer += 5;
14936 *input_line_pointer = 0;
14937 return 1;
14940 return 0;
14943 char *
14944 arm_canonicalize_symbol_name (char * name)
14946 int len;
14948 if (thumb_mode && (len = strlen (name)) > 5
14949 && streq (name + len - 5, "/data"))
14950 *(name + len - 5) = 0;
14952 return name;
14955 /* Table of all register names defined by default. The user can
14956 define additional names with .req. Note that all register names
14957 should appear in both upper and lowercase variants. Some registers
14958 also have mixed-case names. */
14960 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
14961 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
14962 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
14963 #define REGSET(p,t) \
14964 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14965 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14966 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14967 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
14968 #define REGSETH(p,t) \
14969 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14970 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14971 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14972 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14973 #define REGSET2(p,t) \
14974 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14975 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14976 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14977 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
14979 static const struct reg_entry reg_names[] =
14981 /* ARM integer registers. */
14982 REGSET(r, RN), REGSET(R, RN),
14984 /* ATPCS synonyms. */
14985 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14986 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14987 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
14989 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14990 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14991 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
14993 /* Well-known aliases. */
14994 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14995 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14997 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14998 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
15000 /* Coprocessor numbers. */
15001 REGSET(p, CP), REGSET(P, CP),
15003 /* Coprocessor register numbers. The "cr" variants are for backward
15004 compatibility. */
15005 REGSET(c, CN), REGSET(C, CN),
15006 REGSET(cr, CN), REGSET(CR, CN),
15008 /* FPA registers. */
15009 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
15010 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
15012 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
15013 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
15015 /* VFP SP registers. */
15016 REGSET(s,VFS), REGSET(S,VFS),
15017 REGSETH(s,VFS), REGSETH(S,VFS),
15019 /* VFP DP Registers. */
15020 REGSET(d,VFD), REGSET(D,VFD),
15021 /* Extra Neon DP registers. */
15022 REGSETH(d,VFD), REGSETH(D,VFD),
15024 /* Neon QP registers. */
15025 REGSET2(q,NQ), REGSET2(Q,NQ),
15027 /* VFP control registers. */
15028 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
15029 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
15030 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
15031 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
15032 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
15033 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
15035 /* Maverick DSP coprocessor registers. */
15036 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
15037 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
15039 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
15040 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
15041 REGDEF(dspsc,0,DSPSC),
15043 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
15044 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
15045 REGDEF(DSPSC,0,DSPSC),
15047 /* iWMMXt data registers - p0, c0-15. */
15048 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
15050 /* iWMMXt control registers - p1, c0-3. */
15051 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
15052 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
15053 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
15054 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
15056 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
15057 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
15058 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
15059 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
15060 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
15062 /* XScale accumulator registers. */
15063 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
15065 #undef REGDEF
15066 #undef REGNUM
15067 #undef REGSET
15069 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
15070 within psr_required_here. */
15071 static const struct asm_psr psrs[] =
15073 /* Backward compatibility notation. Note that "all" is no longer
15074 truly all possible PSR bits. */
15075 {"all", PSR_c | PSR_f},
15076 {"flg", PSR_f},
15077 {"ctl", PSR_c},
15079 /* Individual flags. */
15080 {"f", PSR_f},
15081 {"c", PSR_c},
15082 {"x", PSR_x},
15083 {"s", PSR_s},
15084 /* Combinations of flags. */
15085 {"fs", PSR_f | PSR_s},
15086 {"fx", PSR_f | PSR_x},
15087 {"fc", PSR_f | PSR_c},
15088 {"sf", PSR_s | PSR_f},
15089 {"sx", PSR_s | PSR_x},
15090 {"sc", PSR_s | PSR_c},
15091 {"xf", PSR_x | PSR_f},
15092 {"xs", PSR_x | PSR_s},
15093 {"xc", PSR_x | PSR_c},
15094 {"cf", PSR_c | PSR_f},
15095 {"cs", PSR_c | PSR_s},
15096 {"cx", PSR_c | PSR_x},
15097 {"fsx", PSR_f | PSR_s | PSR_x},
15098 {"fsc", PSR_f | PSR_s | PSR_c},
15099 {"fxs", PSR_f | PSR_x | PSR_s},
15100 {"fxc", PSR_f | PSR_x | PSR_c},
15101 {"fcs", PSR_f | PSR_c | PSR_s},
15102 {"fcx", PSR_f | PSR_c | PSR_x},
15103 {"sfx", PSR_s | PSR_f | PSR_x},
15104 {"sfc", PSR_s | PSR_f | PSR_c},
15105 {"sxf", PSR_s | PSR_x | PSR_f},
15106 {"sxc", PSR_s | PSR_x | PSR_c},
15107 {"scf", PSR_s | PSR_c | PSR_f},
15108 {"scx", PSR_s | PSR_c | PSR_x},
15109 {"xfs", PSR_x | PSR_f | PSR_s},
15110 {"xfc", PSR_x | PSR_f | PSR_c},
15111 {"xsf", PSR_x | PSR_s | PSR_f},
15112 {"xsc", PSR_x | PSR_s | PSR_c},
15113 {"xcf", PSR_x | PSR_c | PSR_f},
15114 {"xcs", PSR_x | PSR_c | PSR_s},
15115 {"cfs", PSR_c | PSR_f | PSR_s},
15116 {"cfx", PSR_c | PSR_f | PSR_x},
15117 {"csf", PSR_c | PSR_s | PSR_f},
15118 {"csx", PSR_c | PSR_s | PSR_x},
15119 {"cxf", PSR_c | PSR_x | PSR_f},
15120 {"cxs", PSR_c | PSR_x | PSR_s},
15121 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
15122 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
15123 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
15124 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
15125 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
15126 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
15127 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
15128 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
15129 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
15130 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
15131 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
15132 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
15133 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
15134 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
15135 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
15136 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
15137 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
15138 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
15139 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
15140 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
15141 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
15142 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
15143 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
15144 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
15147 /* Table of V7M psr names. */
15148 static const struct asm_psr v7m_psrs[] =
15150 {"apsr", 0 }, {"APSR", 0 },
15151 {"iapsr", 1 }, {"IAPSR", 1 },
15152 {"eapsr", 2 }, {"EAPSR", 2 },
15153 {"psr", 3 }, {"PSR", 3 },
15154 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
15155 {"ipsr", 5 }, {"IPSR", 5 },
15156 {"epsr", 6 }, {"EPSR", 6 },
15157 {"iepsr", 7 }, {"IEPSR", 7 },
15158 {"msp", 8 }, {"MSP", 8 },
15159 {"psp", 9 }, {"PSP", 9 },
15160 {"primask", 16}, {"PRIMASK", 16},
15161 {"basepri", 17}, {"BASEPRI", 17},
15162 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
15163 {"faultmask", 19}, {"FAULTMASK", 19},
15164 {"control", 20}, {"CONTROL", 20}
15167 /* Table of all shift-in-operand names. */
15168 static const struct asm_shift_name shift_names [] =
15170 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
15171 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
15172 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
15173 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
15174 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
15175 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
15178 /* Table of all explicit relocation names. */
15179 #ifdef OBJ_ELF
15180 static struct reloc_entry reloc_names[] =
15182 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
15183 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
15184 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
15185 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
15186 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
15187 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
15188 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
15189 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
15190 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
15191 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
15192 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
15194 #endif
15196 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
15197 static const struct asm_cond conds[] =
15199 {"eq", 0x0},
15200 {"ne", 0x1},
15201 {"cs", 0x2}, {"hs", 0x2},
15202 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
15203 {"mi", 0x4},
15204 {"pl", 0x5},
15205 {"vs", 0x6},
15206 {"vc", 0x7},
15207 {"hi", 0x8},
15208 {"ls", 0x9},
15209 {"ge", 0xa},
15210 {"lt", 0xb},
15211 {"gt", 0xc},
15212 {"le", 0xd},
15213 {"al", 0xe}
15216 static struct asm_barrier_opt barrier_opt_names[] =
15218 { "sy", 0xf },
15219 { "un", 0x7 },
15220 { "st", 0xe },
15221 { "unst", 0x6 }
15224 /* Table of ARM-format instructions. */
15226 /* Macros for gluing together operand strings. N.B. In all cases
15227 other than OPS0, the trailing OP_stop comes from default
15228 zero-initialization of the unspecified elements of the array. */
15229 #define OPS0() { OP_stop, }
15230 #define OPS1(a) { OP_##a, }
15231 #define OPS2(a,b) { OP_##a,OP_##b, }
15232 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
15233 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
15234 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
15235 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
15237 /* These macros abstract out the exact format of the mnemonic table and
15238 save some repeated characters. */
15240 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
15241 #define TxCE(mnem, op, top, nops, ops, ae, te) \
15242 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
15243 THUMB_VARIANT, do_##ae, do_##te }
15245 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
15246 a T_MNEM_xyz enumerator. */
15247 #define TCE(mnem, aop, top, nops, ops, ae, te) \
15248 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
15249 #define tCE(mnem, aop, top, nops, ops, ae, te) \
15250 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
15252 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
15253 infix after the third character. */
15254 #define TxC3(mnem, op, top, nops, ops, ae, te) \
15255 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
15256 THUMB_VARIANT, do_##ae, do_##te }
15257 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
15258 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
15259 THUMB_VARIANT, do_##ae, do_##te }
15260 #define TC3(mnem, aop, top, nops, ops, ae, te) \
15261 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
15262 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
15263 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
15264 #define tC3(mnem, aop, top, nops, ops, ae, te) \
15265 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
15266 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
15267 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
15269 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
15270 appear in the condition table. */
15271 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
15272 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
15273 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
15275 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
15276 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
15277 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
15278 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
15279 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
15280 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
15281 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
15282 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
15283 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
15284 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
15285 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
15286 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
15287 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
15288 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
15289 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
15290 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
15291 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
15292 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
15293 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
15294 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
15296 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
15297 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
15298 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
15299 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
15301 /* Mnemonic that cannot be conditionalized. The ARM condition-code
15302 field is still 0xE. Many of the Thumb variants can be executed
15303 conditionally, so this is checked separately. */
15304 #define TUE(mnem, op, top, nops, ops, ae, te) \
15305 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
15306 THUMB_VARIANT, do_##ae, do_##te }
15308 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
15309 condition code field. */
15310 #define TUF(mnem, op, top, nops, ops, ae, te) \
15311 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
15312 THUMB_VARIANT, do_##ae, do_##te }
15314 /* ARM-only variants of all the above. */
15315 #define CE(mnem, op, nops, ops, ae) \
15316 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15318 #define C3(mnem, op, nops, ops, ae) \
15319 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15321 /* Legacy mnemonics that always have conditional infix after the third
15322 character. */
15323 #define CL(mnem, op, nops, ops, ae) \
15324 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15325 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15327 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
15328 #define cCE(mnem, op, nops, ops, ae) \
15329 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15331 /* Legacy coprocessor instructions where conditional infix and conditional
15332 suffix are ambiguous. For consistency this includes all FPA instructions,
15333 not just the potentially ambiguous ones. */
15334 #define cCL(mnem, op, nops, ops, ae) \
15335 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15336 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15338 /* Coprocessor, takes either a suffix or a position-3 infix
15339 (for an FPA corner case). */
15340 #define C3E(mnem, op, nops, ops, ae) \
15341 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
15342 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15344 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
15345 { #m1 #m2 #m3, OPS##nops ops, \
15346 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
15347 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15349 #define CM(m1, m2, op, nops, ops, ae) \
15350 xCM_(m1, , m2, op, nops, ops, ae), \
15351 xCM_(m1, eq, m2, op, nops, ops, ae), \
15352 xCM_(m1, ne, m2, op, nops, ops, ae), \
15353 xCM_(m1, cs, m2, op, nops, ops, ae), \
15354 xCM_(m1, hs, m2, op, nops, ops, ae), \
15355 xCM_(m1, cc, m2, op, nops, ops, ae), \
15356 xCM_(m1, ul, m2, op, nops, ops, ae), \
15357 xCM_(m1, lo, m2, op, nops, ops, ae), \
15358 xCM_(m1, mi, m2, op, nops, ops, ae), \
15359 xCM_(m1, pl, m2, op, nops, ops, ae), \
15360 xCM_(m1, vs, m2, op, nops, ops, ae), \
15361 xCM_(m1, vc, m2, op, nops, ops, ae), \
15362 xCM_(m1, hi, m2, op, nops, ops, ae), \
15363 xCM_(m1, ls, m2, op, nops, ops, ae), \
15364 xCM_(m1, ge, m2, op, nops, ops, ae), \
15365 xCM_(m1, lt, m2, op, nops, ops, ae), \
15366 xCM_(m1, gt, m2, op, nops, ops, ae), \
15367 xCM_(m1, le, m2, op, nops, ops, ae), \
15368 xCM_(m1, al, m2, op, nops, ops, ae)
15370 #define UE(mnem, op, nops, ops, ae) \
15371 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15373 #define UF(mnem, op, nops, ops, ae) \
15374 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15376 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
15377 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
15378 use the same encoding function for each. */
15379 #define NUF(mnem, op, nops, ops, enc) \
15380 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
15381 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15383 /* Neon data processing, version which indirects through neon_enc_tab for
15384 the various overloaded versions of opcodes. */
15385 #define nUF(mnem, op, nops, ops, enc) \
15386 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
15387 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15389 /* Neon insn with conditional suffix for the ARM version, non-overloaded
15390 version. */
15391 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
15392 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
15393 THUMB_VARIANT, do_##enc, do_##enc }
15395 #define NCE(mnem, op, nops, ops, enc) \
15396 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
15398 #define NCEF(mnem, op, nops, ops, enc) \
15399 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
15401 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
15402 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
15403 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
15404 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15406 #define nCE(mnem, op, nops, ops, enc) \
15407 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
15409 #define nCEF(mnem, op, nops, ops, enc) \
15410 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
15412 #define do_0 0
15414 /* Thumb-only, unconditional. */
15415 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
15417 static const struct asm_opcode insns[] =
15419 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
15420 #define THUMB_VARIANT &arm_ext_v4t
15421 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
15422 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
15423 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
15424 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
15425 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
15426 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
15427 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
15428 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
15429 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
15430 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
15431 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
15432 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
15433 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
15434 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
15435 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
15436 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
15438 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
15439 for setting PSR flag bits. They are obsolete in V6 and do not
15440 have Thumb equivalents. */
15441 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
15442 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
15443 CL(tstp, 110f000, 2, (RR, SH), cmp),
15444 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
15445 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
15446 CL(cmpp, 150f000, 2, (RR, SH), cmp),
15447 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
15448 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
15449 CL(cmnp, 170f000, 2, (RR, SH), cmp),
15451 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
15452 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
15453 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
15454 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
15456 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
15457 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
15458 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
15459 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
15461 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15462 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15463 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15464 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15465 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15466 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15468 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
15469 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
15470 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
15471 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
15473 /* Pseudo ops. */
15474 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
15475 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
15476 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
15478 /* Thumb-compatibility pseudo ops. */
15479 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
15480 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
15481 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
15482 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
15483 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
15484 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
15485 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
15486 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
15487 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
15488 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
15489 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
15490 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
15492 /* These may simplify to neg. */
15493 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
15494 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
15496 #undef THUMB_VARIANT
15497 #define THUMB_VARIANT &arm_ext_v6
15498 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
15500 /* V1 instructions with no Thumb analogue prior to V6T2. */
15501 #undef THUMB_VARIANT
15502 #define THUMB_VARIANT &arm_ext_v6t2
15503 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
15504 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
15505 CL(teqp, 130f000, 2, (RR, SH), cmp),
15507 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
15508 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
15509 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
15510 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
15512 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15513 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15515 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15516 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15518 /* V1 instructions with no Thumb analogue at all. */
15519 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
15520 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15522 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15523 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15524 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15525 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15526 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15527 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15528 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15529 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15531 #undef ARM_VARIANT
15532 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
15533 #undef THUMB_VARIANT
15534 #define THUMB_VARIANT &arm_ext_v4t
15535 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15536 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15538 #undef THUMB_VARIANT
15539 #define THUMB_VARIANT &arm_ext_v6t2
15540 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15541 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15543 /* Generic coprocessor instructions. */
15544 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15545 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15546 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15547 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15548 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15549 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15550 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15552 #undef ARM_VARIANT
15553 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
15554 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15555 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15557 #undef ARM_VARIANT
15558 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
15559 #undef THUMB_VARIANT
15560 #define THUMB_VARIANT &arm_ext_msr
15561 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15562 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
15564 #undef ARM_VARIANT
15565 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
15566 #undef THUMB_VARIANT
15567 #define THUMB_VARIANT &arm_ext_v6t2
15568 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15569 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15570 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15571 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15572 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15573 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15574 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15575 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15577 #undef ARM_VARIANT
15578 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
15579 #undef THUMB_VARIANT
15580 #define THUMB_VARIANT &arm_ext_v4t
15581 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15582 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15583 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15584 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15585 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15586 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15588 #undef ARM_VARIANT
15589 #define ARM_VARIANT &arm_ext_v4t_5
15590 /* ARM Architecture 4T. */
15591 /* Note: bx (and blx) are required on V5, even if the processor does
15592 not support Thumb. */
15593 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15595 #undef ARM_VARIANT
15596 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
15597 #undef THUMB_VARIANT
15598 #define THUMB_VARIANT &arm_ext_v5t
15599 /* Note: blx has 2 variants; the .value coded here is for
15600 BLX(2). Only this variant has conditional execution. */
15601 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15602 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15604 #undef THUMB_VARIANT
15605 #define THUMB_VARIANT &arm_ext_v6t2
15606 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
15607 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15608 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15609 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15610 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15611 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15612 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15613 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15615 #undef ARM_VARIANT
15616 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
15617 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15618 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15619 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15620 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15622 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15623 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15625 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15626 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15627 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15628 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15630 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15631 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15632 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15633 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15635 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15636 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15638 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15639 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15640 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15641 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15643 #undef ARM_VARIANT
15644 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
15645 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
15646 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15647 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15649 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15650 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15652 #undef ARM_VARIANT
15653 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
15654 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15656 #undef ARM_VARIANT
15657 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
15658 #undef THUMB_VARIANT
15659 #define THUMB_VARIANT &arm_ext_v6
15660 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15661 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15662 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15663 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15664 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15665 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15666 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15667 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15668 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15669 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15671 #undef THUMB_VARIANT
15672 #define THUMB_VARIANT &arm_ext_v6t2
15673 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
15674 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
15675 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15676 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15678 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15679 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15681 /* ARM V6 not included in V7M (eg. integer SIMD). */
15682 #undef THUMB_VARIANT
15683 #define THUMB_VARIANT &arm_ext_v6_notm
15684 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
15685 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15686 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15687 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15688 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15689 TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15690 /* Old name for QASX. */
15691 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15692 TCE(qsax, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15693 /* Old name for QSAX. */
15694 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15695 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15696 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15697 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15698 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15699 TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15700 /* Old name for SASX. */
15701 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15702 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15703 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15704 TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15705 /* Old name for SHASX. */
15706 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15707 TCE(shsax, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15708 /* Old name for SHSAX. */
15709 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15710 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15711 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15712 TCE(ssax, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15713 /* Old name for SSAX. */
15714 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15715 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15716 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15717 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15718 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15719 TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15720 /* Old name for UASX. */
15721 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15722 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15723 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15724 TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15725 /* Old name for UHASX. */
15726 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15727 TCE(uhsax, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15728 /* Old name for UHSAX. */
15729 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15730 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15731 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15732 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15733 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15734 TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15735 /* Old name for UQASX. */
15736 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15737 TCE(uqsax, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15738 /* Old name for UQSAX. */
15739 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15740 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15741 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15742 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15743 TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15744 /* Old name for USAX. */
15745 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15746 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15747 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15748 UF(rfeib, 9900a00, 1, (RRw), rfe),
15749 UF(rfeda, 8100a00, 1, (RRw), rfe),
15750 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15751 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15752 UF(rfefa, 9900a00, 1, (RRw), rfe),
15753 UF(rfeea, 8100a00, 1, (RRw), rfe),
15754 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15755 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15756 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15757 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15758 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15759 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15760 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15761 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15762 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15763 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15764 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15765 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15766 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15767 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15768 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15769 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15770 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15771 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15772 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15773 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15774 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15775 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15776 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15777 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15778 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15779 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15780 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15781 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15782 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15783 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15784 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15785 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
15786 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
15787 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15788 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15789 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15790 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15792 #undef ARM_VARIANT
15793 #define ARM_VARIANT &arm_ext_v6k
15794 #undef THUMB_VARIANT
15795 #define THUMB_VARIANT &arm_ext_v6k
15796 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15797 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15798 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15799 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15801 #undef THUMB_VARIANT
15802 #define THUMB_VARIANT &arm_ext_v6_notm
15803 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15804 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15806 #undef THUMB_VARIANT
15807 #define THUMB_VARIANT &arm_ext_v6t2
15808 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15809 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15810 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15811 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15812 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15814 #undef ARM_VARIANT
15815 #define ARM_VARIANT &arm_ext_v6z
15816 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
15818 #undef ARM_VARIANT
15819 #define ARM_VARIANT &arm_ext_v6t2
15820 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15821 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15822 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15823 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15825 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15826 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15827 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
15828 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
15830 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15831 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15832 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15833 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15835 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15836 UT(cbz, b100, 2, (RR, EXP), t_cbz),
15837 /* ARM does not really have an IT instruction, so always allow it. */
15838 #undef ARM_VARIANT
15839 #define ARM_VARIANT &arm_ext_v1
15840 TUE(it, 0, bf08, 1, (COND), it, t_it),
15841 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15842 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15843 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15844 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15845 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15846 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15847 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15848 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15849 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15850 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15851 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15852 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15853 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15854 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15855 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
15856 TC3(rrx, 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
15857 TC3(rrxs, 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
15859 /* Thumb2 only instructions. */
15860 #undef ARM_VARIANT
15861 #define ARM_VARIANT NULL
15863 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15864 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15865 TCE(orn, 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
15866 TCE(orns, 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
15867 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15868 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15870 /* Thumb-2 hardware division instructions (R and M profiles only). */
15871 #undef THUMB_VARIANT
15872 #define THUMB_VARIANT &arm_ext_div
15873 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15874 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15876 /* ARM V6M/V7 instructions. */
15877 #undef ARM_VARIANT
15878 #define ARM_VARIANT &arm_ext_barrier
15879 #undef THUMB_VARIANT
15880 #define THUMB_VARIANT &arm_ext_barrier
15881 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15882 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15883 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15885 /* ARM V7 instructions. */
15886 #undef ARM_VARIANT
15887 #define ARM_VARIANT &arm_ext_v7
15888 #undef THUMB_VARIANT
15889 #define THUMB_VARIANT &arm_ext_v7
15890 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15891 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15893 #undef ARM_VARIANT
15894 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
15895 cCE(wfs, e200110, 1, (RR), rd),
15896 cCE(rfs, e300110, 1, (RR), rd),
15897 cCE(wfc, e400110, 1, (RR), rd),
15898 cCE(rfc, e500110, 1, (RR), rd),
15900 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15901 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15902 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15903 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
15905 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15906 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15907 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15908 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
15910 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15911 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15912 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15913 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15914 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15915 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15916 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15917 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15918 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15919 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15920 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15921 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15923 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15924 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15925 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15926 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15927 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15928 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15929 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15930 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15931 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15932 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15933 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15934 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15936 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15937 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15938 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15939 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15940 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15941 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15942 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15943 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15944 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15945 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15946 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15947 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15949 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15950 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15951 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15952 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15953 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15954 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15955 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15956 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15957 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15958 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15959 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15960 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15962 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15963 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15964 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15965 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15966 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15967 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15968 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15969 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15970 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15971 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15972 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15973 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15975 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15976 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15977 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15978 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15979 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15980 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15981 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15982 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15983 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15984 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15985 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15986 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15988 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15989 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15990 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15991 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15992 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15993 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15994 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15995 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15996 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15997 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15998 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15999 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
16001 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
16002 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
16003 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
16004 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
16005 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
16006 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
16007 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
16008 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
16009 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
16010 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
16011 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
16012 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
16014 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
16015 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
16016 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
16017 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
16018 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
16019 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
16020 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
16021 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
16022 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
16023 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
16024 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
16025 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
16027 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
16028 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
16029 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
16030 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
16031 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
16032 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
16033 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
16034 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
16035 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
16036 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
16037 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
16038 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
16040 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
16041 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
16042 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
16043 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
16044 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
16045 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
16046 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
16047 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
16048 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
16049 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
16050 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
16051 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
16053 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
16054 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
16055 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
16056 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
16057 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
16058 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
16059 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
16060 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
16061 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
16062 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
16063 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
16064 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
16066 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
16067 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
16068 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
16069 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
16070 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
16071 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
16072 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
16073 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
16074 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
16075 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
16076 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
16077 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
16079 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
16080 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
16081 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
16082 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
16083 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
16084 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
16085 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
16086 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
16087 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
16088 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
16089 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
16090 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
16092 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
16093 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
16094 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
16095 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
16096 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
16097 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
16098 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
16099 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
16100 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
16101 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
16102 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
16103 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
16105 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
16106 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
16107 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
16108 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
16109 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
16110 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
16111 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
16112 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
16113 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
16114 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
16115 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
16116 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
16118 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
16119 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
16120 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
16121 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
16122 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
16123 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16124 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16125 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16126 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
16127 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
16128 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
16129 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
16131 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
16132 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
16133 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
16134 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
16135 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
16136 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16137 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16138 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16139 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
16140 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
16141 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
16142 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
16144 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
16145 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
16146 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
16147 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
16148 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
16149 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16150 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16151 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16152 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
16153 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
16154 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
16155 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
16157 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
16158 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
16159 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
16160 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
16161 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
16162 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16163 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16164 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16165 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
16166 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
16167 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
16168 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
16170 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
16171 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
16172 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
16173 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
16174 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
16175 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16176 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16177 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16178 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
16179 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
16180 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
16181 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
16183 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
16184 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
16185 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
16186 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
16187 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
16188 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16189 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16190 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16191 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
16192 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
16193 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
16194 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
16196 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
16197 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
16198 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
16199 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
16200 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
16201 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16202 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16203 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16204 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
16205 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
16206 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
16207 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
16209 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
16210 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
16211 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
16212 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
16213 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
16214 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16215 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16216 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16217 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
16218 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
16219 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
16220 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
16222 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
16223 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
16224 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
16225 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
16226 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
16227 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16228 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16229 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16230 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
16231 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
16232 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
16233 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
16235 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
16236 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
16237 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
16238 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
16239 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
16240 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16241 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16242 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16243 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
16244 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
16245 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
16246 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
16248 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16249 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16250 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16251 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16252 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16253 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16254 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16255 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16256 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16257 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16258 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16259 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16261 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16262 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16263 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16264 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16265 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16266 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16267 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16268 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16269 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16270 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16271 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16272 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16274 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16275 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16276 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16277 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16278 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16279 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16280 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16281 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16282 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16283 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16284 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16285 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16287 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
16288 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
16289 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
16290 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
16292 cCL(flts, e000110, 2, (RF, RR), rn_rd),
16293 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
16294 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
16295 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
16296 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
16297 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
16298 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
16299 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
16300 cCL(flte, e080110, 2, (RF, RR), rn_rd),
16301 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
16302 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
16303 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
16305 /* The implementation of the FIX instruction is broken on some
16306 assemblers, in that it accepts a precision specifier as well as a
16307 rounding specifier, despite the fact that this is meaningless.
16308 To be more compatible, we accept it as well, though of course it
16309 does not set any bits. */
16310 cCE(fix, e100110, 2, (RR, RF), rd_rm),
16311 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
16312 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
16313 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
16314 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
16315 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
16316 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
16317 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
16318 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
16319 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
16320 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
16321 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
16322 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
16324 /* Instructions that were new with the real FPA, call them V2. */
16325 #undef ARM_VARIANT
16326 #define ARM_VARIANT &fpu_fpa_ext_v2
16327 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16328 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16329 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16330 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16331 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16332 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16334 #undef ARM_VARIANT
16335 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
16336 /* Moves and type conversions. */
16337 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
16338 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
16339 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
16340 cCE(fmstat, ef1fa10, 0, (), noargs),
16341 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
16342 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
16343 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
16344 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16345 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
16346 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16347 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
16348 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
16350 /* Memory operations. */
16351 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
16352 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
16353 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16354 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16355 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16356 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16357 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16358 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16359 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16360 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16361 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16362 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16363 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16364 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16365 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16366 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16367 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16368 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16370 /* Monadic operations. */
16371 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
16372 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
16373 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
16375 /* Dyadic operations. */
16376 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16377 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16378 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16379 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16380 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16381 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16382 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16383 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16384 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16386 /* Comparisons. */
16387 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
16388 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
16389 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
16390 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
16392 #undef ARM_VARIANT
16393 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
16394 /* Moves and type conversions. */
16395 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16396 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16397 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
16398 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
16399 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
16400 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
16401 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
16402 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16403 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
16404 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16405 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
16406 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16407 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
16409 /* Memory operations. */
16410 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
16411 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
16412 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16413 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16414 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16415 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16416 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16417 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16418 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16419 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16421 /* Monadic operations. */
16422 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16423 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16424 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16426 /* Dyadic operations. */
16427 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16428 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16429 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16430 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16431 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16432 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16433 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16434 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16435 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16437 /* Comparisons. */
16438 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16439 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
16440 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16441 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
16443 #undef ARM_VARIANT
16444 #define ARM_VARIANT &fpu_vfp_ext_v2
16445 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
16446 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
16447 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
16448 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
16450 /* Instructions which may belong to either the Neon or VFP instruction sets.
16451 Individual encoder functions perform additional architecture checks. */
16452 #undef ARM_VARIANT
16453 #define ARM_VARIANT &fpu_vfp_ext_v1xd
16454 #undef THUMB_VARIANT
16455 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
16456 /* These mnemonics are unique to VFP. */
16457 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
16458 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
16459 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16460 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16461 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16462 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16463 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16464 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
16465 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
16466 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
16468 /* Mnemonics shared by Neon and VFP. */
16469 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
16470 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16471 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16473 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16474 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16476 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16477 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16479 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16480 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16481 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16482 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16483 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16484 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16485 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16486 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16488 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
16489 nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb),
16490 nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt),
16493 /* NOTE: All VMOV encoding is special-cased! */
16494 NCE(vmov, 0, 1, (VMOV), neon_mov),
16495 NCE(vmovq, 0, 1, (VMOV), neon_mov),
16497 #undef THUMB_VARIANT
16498 #define THUMB_VARIANT &fpu_neon_ext_v1
16499 #undef ARM_VARIANT
16500 #define ARM_VARIANT &fpu_neon_ext_v1
16501 /* Data processing with three registers of the same length. */
16502 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
16503 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
16504 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
16505 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16506 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16507 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16508 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16509 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16510 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16511 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
16512 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
16513 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
16514 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
16515 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
16516 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
16517 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
16518 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
16519 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
16520 /* If not immediate, fall back to neon_dyadic_i64_su.
16521 shl_imm should accept I8 I16 I32 I64,
16522 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
16523 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
16524 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
16525 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
16526 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
16527 /* Logic ops, types optional & ignored. */
16528 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
16529 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
16530 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
16531 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
16532 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
16533 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
16534 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
16535 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
16536 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
16537 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
16538 /* Bitfield ops, untyped. */
16539 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16540 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16541 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16542 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16543 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16544 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16545 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
16546 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16547 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16548 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16549 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16550 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16551 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16552 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
16553 back to neon_dyadic_if_su. */
16554 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16555 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16556 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16557 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16558 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16559 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16560 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16561 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16562 /* Comparison. Type I8 I16 I32 F32. */
16563 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16564 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16565 /* As above, D registers only. */
16566 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16567 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16568 /* Int and float variants, signedness unimportant. */
16569 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16570 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16571 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16572 /* Add/sub take types I8 I16 I32 I64 F32. */
16573 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16574 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16575 /* vtst takes sizes 8, 16, 32. */
16576 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16577 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16578 /* VMUL takes I8 I16 I32 F32 P8. */
16579 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
16580 /* VQD{R}MULH takes S16 S32. */
16581 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16582 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16583 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16584 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16585 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16586 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16587 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16588 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16589 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16590 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16591 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16592 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16593 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16594 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16595 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16596 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16598 /* Two address, int/float. Types S8 S16 S32 F32. */
16599 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
16600 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16602 /* Data processing with two registers and a shift amount. */
16603 /* Right shifts, and variants with rounding.
16604 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16605 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16606 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16607 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16608 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16609 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16610 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16611 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16612 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16613 /* Shift and insert. Sizes accepted 8 16 32 64. */
16614 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16615 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16616 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16617 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16618 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16619 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16620 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16621 /* Right shift immediate, saturating & narrowing, with rounding variants.
16622 Types accepted S16 S32 S64 U16 U32 U64. */
16623 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16624 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16625 /* As above, unsigned. Types accepted S16 S32 S64. */
16626 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16627 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16628 /* Right shift narrowing. Types accepted I16 I32 I64. */
16629 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16630 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16631 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16632 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16633 /* CVT with optional immediate for fixed-point variant. */
16634 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
16636 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16637 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16639 /* Data processing, three registers of different lengths. */
16640 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16641 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16642 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16643 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16644 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16645 /* If not scalar, fall back to neon_dyadic_long.
16646 Vector types as above, scalar types S16 S32 U16 U32. */
16647 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16648 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16649 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16650 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16651 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16652 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16653 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16654 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16655 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16656 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16657 /* Saturating doubling multiplies. Types S16 S32. */
16658 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16659 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16660 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16661 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16662 S16 S32 U16 U32. */
16663 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16665 /* Extract. Size 8. */
16666 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16667 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
16669 /* Two registers, miscellaneous. */
16670 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16671 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16672 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16673 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16674 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16675 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16676 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16677 /* Vector replicate. Sizes 8 16 32. */
16678 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16679 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16680 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16681 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16682 /* VMOVN. Types I16 I32 I64. */
16683 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16684 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16685 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16686 /* VQMOVUN. Types S16 S32 S64. */
16687 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16688 /* VZIP / VUZP. Sizes 8 16 32. */
16689 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16690 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16691 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16692 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16693 /* VQABS / VQNEG. Types S8 S16 S32. */
16694 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16695 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16696 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16697 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16698 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16699 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16700 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16701 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16702 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16703 /* Reciprocal estimates. Types U32 F32. */
16704 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16705 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16706 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16707 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16708 /* VCLS. Types S8 S16 S32. */
16709 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16710 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16711 /* VCLZ. Types I8 I16 I32. */
16712 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16713 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16714 /* VCNT. Size 8. */
16715 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16716 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16717 /* Two address, untyped. */
16718 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16719 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16720 /* VTRN. Sizes 8 16 32. */
16721 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16722 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16724 /* Table lookup. Size 8. */
16725 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16726 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16728 #undef THUMB_VARIANT
16729 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16730 #undef ARM_VARIANT
16731 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
16732 /* Neon element/structure load/store. */
16733 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16734 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16735 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16736 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16737 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16738 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16739 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16740 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16742 #undef THUMB_VARIANT
16743 #define THUMB_VARIANT &fpu_vfp_ext_v3
16744 #undef ARM_VARIANT
16745 #define ARM_VARIANT &fpu_vfp_ext_v3
16746 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16747 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16748 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16749 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16750 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16751 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16752 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16753 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16754 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16755 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16756 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16757 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16758 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16759 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16760 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16761 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16762 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16763 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16765 #undef THUMB_VARIANT
16766 #undef ARM_VARIANT
16767 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
16768 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16769 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16770 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16771 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16772 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16773 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16774 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16775 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
16777 #undef ARM_VARIANT
16778 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
16779 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16780 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16781 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16782 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16783 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16784 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16785 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16786 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16787 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16788 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16789 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16790 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16791 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16792 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16793 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16794 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16795 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16796 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16797 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
16798 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16799 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16800 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16801 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16802 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16803 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16804 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16805 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16806 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16807 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
16808 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
16809 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16810 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16811 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16812 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16813 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16814 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16815 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16816 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16817 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16818 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16819 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16820 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16821 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16822 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16823 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16824 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16825 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16826 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16827 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16828 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16829 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16830 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16831 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16832 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16833 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16834 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16835 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16836 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16837 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16838 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16839 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16840 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16841 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16842 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16843 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16844 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16845 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16846 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16847 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16848 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16849 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16850 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16851 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16852 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16853 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16854 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16855 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16856 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16857 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16858 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16859 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16860 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16861 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16862 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16863 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16864 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16865 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16866 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16867 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16868 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16869 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16870 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16871 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16872 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16873 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16874 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16875 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16876 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16877 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16878 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16879 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16880 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16881 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16882 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16883 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16884 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16885 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16886 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16887 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16888 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16889 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
16890 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16891 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16892 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16893 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16894 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16895 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16896 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16897 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16898 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16899 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16900 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16901 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16902 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16903 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16904 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16905 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16906 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16907 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16908 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16909 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16910 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16911 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16912 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16913 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16914 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16915 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16916 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16917 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16918 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16919 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16920 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16921 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16922 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16923 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16924 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16925 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16926 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16927 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16928 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16929 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16930 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16931 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16932 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16933 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16934 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16935 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16936 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16937 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16938 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16939 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16940 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
16942 #undef ARM_VARIANT
16943 #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16944 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16945 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16946 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16947 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16948 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16949 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16950 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16951 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16952 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16953 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16954 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16955 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16956 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16957 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16958 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16959 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16960 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16961 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16962 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16963 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16964 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16965 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16966 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16967 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16968 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16969 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16970 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16971 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16972 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16973 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16974 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16975 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16976 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16977 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16978 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16979 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16980 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16981 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16982 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16983 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16984 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16985 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16986 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16987 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16988 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16989 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16990 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16991 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16992 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16993 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16994 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16995 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16996 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16997 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16998 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16999 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17000 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17002 #undef ARM_VARIANT
17003 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
17004 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17005 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17006 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17007 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17008 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17009 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17010 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17011 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17012 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
17013 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
17014 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
17015 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
17016 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
17017 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
17018 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
17019 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
17020 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
17021 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
17022 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
17023 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
17024 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
17025 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
17026 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
17027 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
17028 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
17029 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
17030 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
17031 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
17032 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
17033 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
17034 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
17035 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
17036 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
17037 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
17038 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
17039 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
17040 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
17041 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
17042 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
17043 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
17044 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
17045 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
17046 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
17047 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
17048 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
17049 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
17050 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
17051 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
17052 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
17053 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
17054 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
17055 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
17056 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
17057 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
17058 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
17059 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
17060 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
17061 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
17062 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
17063 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
17064 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
17065 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
17066 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
17067 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
17068 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17069 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17070 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17071 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17072 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17073 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17074 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17075 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17076 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17077 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17078 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
17079 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
17081 #undef ARM_VARIANT
17082 #undef THUMB_VARIANT
17083 #undef TCE
17084 #undef TCM
17085 #undef TUE
17086 #undef TUF
17087 #undef TCC
17088 #undef cCE
17089 #undef cCL
17090 #undef C3E
17091 #undef CE
17092 #undef CM
17093 #undef UE
17094 #undef UF
17095 #undef UT
17096 #undef NUF
17097 #undef nUF
17098 #undef NCE
17099 #undef nCE
17100 #undef OPS0
17101 #undef OPS1
17102 #undef OPS2
17103 #undef OPS3
17104 #undef OPS4
17105 #undef OPS5
17106 #undef OPS6
17107 #undef do_0
17109 /* MD interface: bits in the object file. */
17111 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
17112 for use in the a.out file, and stores them in the array pointed to by buf.
17113 This knows about the endian-ness of the target machine and does
17114 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
17115 2 (short) and 4 (long) Floating numbers are put out as a series of
17116 LITTLENUMS (shorts, here at least). */
17118 void
17119 md_number_to_chars (char * buf, valueT val, int n)
17121 if (target_big_endian)
17122 number_to_chars_bigendian (buf, val, n);
17123 else
17124 number_to_chars_littleendian (buf, val, n);
17127 static valueT
17128 md_chars_to_number (char * buf, int n)
17130 valueT result = 0;
17131 unsigned char * where = (unsigned char *) buf;
17133 if (target_big_endian)
17135 while (n--)
17137 result <<= 8;
17138 result |= (*where++ & 255);
17141 else
17143 while (n--)
17145 result <<= 8;
17146 result |= (where[n] & 255);
17150 return result;
17153 /* MD interface: Sections. */
17155 /* Estimate the size of a frag before relaxing. Assume everything fits in
17156 2 bytes. */
17159 md_estimate_size_before_relax (fragS * fragp,
17160 segT segtype ATTRIBUTE_UNUSED)
17162 fragp->fr_var = 2;
17163 return 2;
17166 /* Convert a machine dependent frag. */
17168 void
17169 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
17171 unsigned long insn;
17172 unsigned long old_op;
17173 char *buf;
17174 expressionS exp;
17175 fixS *fixp;
17176 int reloc_type;
17177 int pc_rel;
17178 int opcode;
17180 buf = fragp->fr_literal + fragp->fr_fix;
17182 old_op = bfd_get_16(abfd, buf);
17183 if (fragp->fr_symbol)
17185 exp.X_op = O_symbol;
17186 exp.X_add_symbol = fragp->fr_symbol;
17188 else
17190 exp.X_op = O_constant;
17192 exp.X_add_number = fragp->fr_offset;
17193 opcode = fragp->fr_subtype;
17194 switch (opcode)
17196 case T_MNEM_ldr_pc:
17197 case T_MNEM_ldr_pc2:
17198 case T_MNEM_ldr_sp:
17199 case T_MNEM_str_sp:
17200 case T_MNEM_ldr:
17201 case T_MNEM_ldrb:
17202 case T_MNEM_ldrh:
17203 case T_MNEM_str:
17204 case T_MNEM_strb:
17205 case T_MNEM_strh:
17206 if (fragp->fr_var == 4)
17208 insn = THUMB_OP32 (opcode);
17209 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
17211 insn |= (old_op & 0x700) << 4;
17213 else
17215 insn |= (old_op & 7) << 12;
17216 insn |= (old_op & 0x38) << 13;
17218 insn |= 0x00000c00;
17219 put_thumb32_insn (buf, insn);
17220 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
17222 else
17224 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
17226 pc_rel = (opcode == T_MNEM_ldr_pc2);
17227 break;
17228 case T_MNEM_adr:
17229 if (fragp->fr_var == 4)
17231 insn = THUMB_OP32 (opcode);
17232 insn |= (old_op & 0xf0) << 4;
17233 put_thumb32_insn (buf, insn);
17234 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
17236 else
17238 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17239 exp.X_add_number -= 4;
17241 pc_rel = 1;
17242 break;
17243 case T_MNEM_mov:
17244 case T_MNEM_movs:
17245 case T_MNEM_cmp:
17246 case T_MNEM_cmn:
17247 if (fragp->fr_var == 4)
17249 int r0off = (opcode == T_MNEM_mov
17250 || opcode == T_MNEM_movs) ? 0 : 8;
17251 insn = THUMB_OP32 (opcode);
17252 insn = (insn & 0xe1ffffff) | 0x10000000;
17253 insn |= (old_op & 0x700) << r0off;
17254 put_thumb32_insn (buf, insn);
17255 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
17257 else
17259 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
17261 pc_rel = 0;
17262 break;
17263 case T_MNEM_b:
17264 if (fragp->fr_var == 4)
17266 insn = THUMB_OP32(opcode);
17267 put_thumb32_insn (buf, insn);
17268 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
17270 else
17271 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
17272 pc_rel = 1;
17273 break;
17274 case T_MNEM_bcond:
17275 if (fragp->fr_var == 4)
17277 insn = THUMB_OP32(opcode);
17278 insn |= (old_op & 0xf00) << 14;
17279 put_thumb32_insn (buf, insn);
17280 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
17282 else
17283 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
17284 pc_rel = 1;
17285 break;
17286 case T_MNEM_add_sp:
17287 case T_MNEM_add_pc:
17288 case T_MNEM_inc_sp:
17289 case T_MNEM_dec_sp:
17290 if (fragp->fr_var == 4)
17292 /* ??? Choose between add and addw. */
17293 insn = THUMB_OP32 (opcode);
17294 insn |= (old_op & 0xf0) << 4;
17295 put_thumb32_insn (buf, insn);
17296 if (opcode == T_MNEM_add_pc)
17297 reloc_type = BFD_RELOC_ARM_T32_IMM12;
17298 else
17299 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
17301 else
17302 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17303 pc_rel = 0;
17304 break;
17306 case T_MNEM_addi:
17307 case T_MNEM_addis:
17308 case T_MNEM_subi:
17309 case T_MNEM_subis:
17310 if (fragp->fr_var == 4)
17312 insn = THUMB_OP32 (opcode);
17313 insn |= (old_op & 0xf0) << 4;
17314 insn |= (old_op & 0xf) << 16;
17315 put_thumb32_insn (buf, insn);
17316 if (insn & (1 << 20))
17317 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
17318 else
17319 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
17321 else
17322 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17323 pc_rel = 0;
17324 break;
17325 default:
17326 abort ();
17328 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
17329 reloc_type);
17330 fixp->fx_file = fragp->fr_file;
17331 fixp->fx_line = fragp->fr_line;
17332 fragp->fr_fix += fragp->fr_var;
17335 /* Return the size of a relaxable immediate operand instruction.
17336 SHIFT and SIZE specify the form of the allowable immediate. */
17337 static int
17338 relax_immediate (fragS *fragp, int size, int shift)
17340 offsetT offset;
17341 offsetT mask;
17342 offsetT low;
17344 /* ??? Should be able to do better than this. */
17345 if (fragp->fr_symbol)
17346 return 4;
17348 low = (1 << shift) - 1;
17349 mask = (1 << (shift + size)) - (1 << shift);
17350 offset = fragp->fr_offset;
17351 /* Force misaligned offsets to 32-bit variant. */
17352 if (offset & low)
17353 return 4;
17354 if (offset & ~mask)
17355 return 4;
17356 return 2;
17359 /* Get the address of a symbol during relaxation. */
17360 static addressT
17361 relaxed_symbol_addr (fragS *fragp, long stretch)
17363 fragS *sym_frag;
17364 addressT addr;
17365 symbolS *sym;
17367 sym = fragp->fr_symbol;
17368 sym_frag = symbol_get_frag (sym);
17369 know (S_GET_SEGMENT (sym) != absolute_section
17370 || sym_frag == &zero_address_frag);
17371 addr = S_GET_VALUE (sym) + fragp->fr_offset;
17373 /* If frag has yet to be reached on this pass, assume it will
17374 move by STRETCH just as we did. If this is not so, it will
17375 be because some frag between grows, and that will force
17376 another pass. */
17378 if (stretch != 0
17379 && sym_frag->relax_marker != fragp->relax_marker)
17381 fragS *f;
17383 /* Adjust stretch for any alignment frag. Note that if have
17384 been expanding the earlier code, the symbol may be
17385 defined in what appears to be an earlier frag. FIXME:
17386 This doesn't handle the fr_subtype field, which specifies
17387 a maximum number of bytes to skip when doing an
17388 alignment. */
17389 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17391 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17393 if (stretch < 0)
17394 stretch = - ((- stretch)
17395 & ~ ((1 << (int) f->fr_offset) - 1));
17396 else
17397 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17398 if (stretch == 0)
17399 break;
17402 if (f != NULL)
17403 addr += stretch;
17406 return addr;
17409 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
17410 load. */
17411 static int
17412 relax_adr (fragS *fragp, asection *sec, long stretch)
17414 addressT addr;
17415 offsetT val;
17417 /* Assume worst case for symbols not known to be in the same section. */
17418 if (!S_IS_DEFINED (fragp->fr_symbol)
17419 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17420 return 4;
17422 val = relaxed_symbol_addr (fragp, stretch);
17423 addr = fragp->fr_address + fragp->fr_fix;
17424 addr = (addr + 4) & ~3;
17425 /* Force misaligned targets to 32-bit variant. */
17426 if (val & 3)
17427 return 4;
17428 val -= addr;
17429 if (val < 0 || val > 1020)
17430 return 4;
17431 return 2;
17434 /* Return the size of a relaxable add/sub immediate instruction. */
17435 static int
17436 relax_addsub (fragS *fragp, asection *sec)
17438 char *buf;
17439 int op;
17441 buf = fragp->fr_literal + fragp->fr_fix;
17442 op = bfd_get_16(sec->owner, buf);
17443 if ((op & 0xf) == ((op >> 4) & 0xf))
17444 return relax_immediate (fragp, 8, 0);
17445 else
17446 return relax_immediate (fragp, 3, 0);
17450 /* Return the size of a relaxable branch instruction. BITS is the
17451 size of the offset field in the narrow instruction. */
17453 static int
17454 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
17456 addressT addr;
17457 offsetT val;
17458 offsetT limit;
17460 /* Assume worst case for symbols not known to be in the same section. */
17461 if (!S_IS_DEFINED (fragp->fr_symbol)
17462 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17463 return 4;
17465 val = relaxed_symbol_addr (fragp, stretch);
17466 addr = fragp->fr_address + fragp->fr_fix + 4;
17467 val -= addr;
17469 /* Offset is a signed value *2 */
17470 limit = 1 << bits;
17471 if (val >= limit || val < -limit)
17472 return 4;
17473 return 2;
17477 /* Relax a machine dependent frag. This returns the amount by which
17478 the current size of the frag should change. */
17481 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
17483 int oldsize;
17484 int newsize;
17486 oldsize = fragp->fr_var;
17487 switch (fragp->fr_subtype)
17489 case T_MNEM_ldr_pc2:
17490 newsize = relax_adr (fragp, sec, stretch);
17491 break;
17492 case T_MNEM_ldr_pc:
17493 case T_MNEM_ldr_sp:
17494 case T_MNEM_str_sp:
17495 newsize = relax_immediate (fragp, 8, 2);
17496 break;
17497 case T_MNEM_ldr:
17498 case T_MNEM_str:
17499 newsize = relax_immediate (fragp, 5, 2);
17500 break;
17501 case T_MNEM_ldrh:
17502 case T_MNEM_strh:
17503 newsize = relax_immediate (fragp, 5, 1);
17504 break;
17505 case T_MNEM_ldrb:
17506 case T_MNEM_strb:
17507 newsize = relax_immediate (fragp, 5, 0);
17508 break;
17509 case T_MNEM_adr:
17510 newsize = relax_adr (fragp, sec, stretch);
17511 break;
17512 case T_MNEM_mov:
17513 case T_MNEM_movs:
17514 case T_MNEM_cmp:
17515 case T_MNEM_cmn:
17516 newsize = relax_immediate (fragp, 8, 0);
17517 break;
17518 case T_MNEM_b:
17519 newsize = relax_branch (fragp, sec, 11, stretch);
17520 break;
17521 case T_MNEM_bcond:
17522 newsize = relax_branch (fragp, sec, 8, stretch);
17523 break;
17524 case T_MNEM_add_sp:
17525 case T_MNEM_add_pc:
17526 newsize = relax_immediate (fragp, 8, 2);
17527 break;
17528 case T_MNEM_inc_sp:
17529 case T_MNEM_dec_sp:
17530 newsize = relax_immediate (fragp, 7, 2);
17531 break;
17532 case T_MNEM_addi:
17533 case T_MNEM_addis:
17534 case T_MNEM_subi:
17535 case T_MNEM_subis:
17536 newsize = relax_addsub (fragp, sec);
17537 break;
17538 default:
17539 abort ();
17542 fragp->fr_var = newsize;
17543 /* Freeze wide instructions that are at or before the same location as
17544 in the previous pass. This avoids infinite loops.
17545 Don't freeze them unconditionally because targets may be artificially
17546 misaligned by the expansion of preceding frags. */
17547 if (stretch <= 0 && newsize > 2)
17549 md_convert_frag (sec->owner, sec, fragp);
17550 frag_wane (fragp);
17553 return newsize - oldsize;
17556 /* Round up a section size to the appropriate boundary. */
17558 valueT
17559 md_section_align (segT segment ATTRIBUTE_UNUSED,
17560 valueT size)
17562 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17563 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17565 /* For a.out, force the section size to be aligned. If we don't do
17566 this, BFD will align it for us, but it will not write out the
17567 final bytes of the section. This may be a bug in BFD, but it is
17568 easier to fix it here since that is how the other a.out targets
17569 work. */
17570 int align;
17572 align = bfd_get_section_alignment (stdoutput, segment);
17573 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17575 #endif
17577 return size;
17580 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17581 of an rs_align_code fragment. */
17583 void
17584 arm_handle_align (fragS * fragP)
17586 static char const arm_noop[2][2][4] =
17588 { /* ARMv1 */
17589 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
17590 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
17592 { /* ARMv6k */
17593 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
17594 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
17597 static char const thumb_noop[2][2][2] =
17599 { /* Thumb-1 */
17600 {0xc0, 0x46}, /* LE */
17601 {0x46, 0xc0}, /* BE */
17603 { /* Thumb-2 */
17604 {0x00, 0xbf}, /* LE */
17605 {0xbf, 0x00} /* BE */
17608 static char const wide_thumb_noop[2][4] =
17609 { /* Wide Thumb-2 */
17610 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
17611 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
17614 unsigned bytes, fix, noop_size;
17615 char * p;
17616 const char * noop;
17617 const char *narrow_noop = NULL;
17619 if (fragP->fr_type != rs_align_code)
17620 return;
17622 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17623 p = fragP->fr_literal + fragP->fr_fix;
17624 fix = 0;
17626 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17627 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
17629 assert ((fragP->tc_frag_data & MODE_RECORDED) != 0);
17631 if (fragP->tc_frag_data & (~ MODE_RECORDED))
17633 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
17635 narrow_noop = thumb_noop[1][target_big_endian];
17636 noop = wide_thumb_noop[target_big_endian];
17638 else
17639 noop = thumb_noop[0][target_big_endian];
17640 noop_size = 2;
17642 else
17644 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
17645 [target_big_endian];
17646 noop_size = 4;
17649 fragP->fr_var = noop_size;
17651 if (bytes & (noop_size - 1))
17653 fix = bytes & (noop_size - 1);
17654 memset (p, 0, fix);
17655 p += fix;
17656 bytes -= fix;
17659 if (narrow_noop)
17661 if (bytes & noop_size)
17663 /* Insert a narrow noop. */
17664 memcpy (p, narrow_noop, noop_size);
17665 p += noop_size;
17666 bytes -= noop_size;
17667 fix += noop_size;
17670 /* Use wide noops for the remainder */
17671 noop_size = 4;
17674 while (bytes >= noop_size)
17676 memcpy (p, noop, noop_size);
17677 p += noop_size;
17678 bytes -= noop_size;
17679 fix += noop_size;
17682 fragP->fr_fix += fix;
17685 /* Called from md_do_align. Used to create an alignment
17686 frag in a code section. */
17688 void
17689 arm_frag_align_code (int n, int max)
17691 char * p;
17693 /* We assume that there will never be a requirement
17694 to support alignments greater than 32 bytes. */
17695 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17696 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
17698 p = frag_var (rs_align_code,
17699 MAX_MEM_FOR_RS_ALIGN_CODE,
17701 (relax_substateT) max,
17702 (symbolS *) NULL,
17703 (offsetT) n,
17704 (char *) NULL);
17705 *p = 0;
17708 /* Perform target specific initialisation of a frag.
17709 Note - despite the name this initialisation is not done when the frag
17710 is created, but only when its type is assigned. A frag can be created
17711 and used a long time before its type is set, so beware of assuming that
17712 this initialisationis performed first. */
17714 void
17715 arm_init_frag (fragS * fragP)
17717 /* If the current ARM vs THUMB mode has not already
17718 been recorded into this frag then do so now. */
17719 if ((fragP->tc_frag_data & MODE_RECORDED) == 0)
17720 fragP->tc_frag_data = thumb_mode | MODE_RECORDED;
17723 #ifdef OBJ_ELF
17724 /* When we change sections we need to issue a new mapping symbol. */
17726 void
17727 arm_elf_change_section (void)
17729 flagword flags;
17730 segment_info_type *seginfo;
17732 /* Link an unlinked unwind index table section to the .text section. */
17733 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17734 && elf_linked_to_section (now_seg) == NULL)
17735 elf_linked_to_section (now_seg) = text_section;
17737 if (!SEG_NORMAL (now_seg))
17738 return;
17740 flags = bfd_get_section_flags (stdoutput, now_seg);
17742 /* We can ignore sections that only contain debug info. */
17743 if ((flags & SEC_ALLOC) == 0)
17744 return;
17746 seginfo = seg_info (now_seg);
17747 mapstate = seginfo->tc_segment_info_data.mapstate;
17748 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
17752 arm_elf_section_type (const char * str, size_t len)
17754 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17755 return SHT_ARM_EXIDX;
17757 return -1;
17760 /* Code to deal with unwinding tables. */
17762 static void add_unwind_adjustsp (offsetT);
17764 /* Generate any deferred unwind frame offset. */
17766 static void
17767 flush_pending_unwind (void)
17769 offsetT offset;
17771 offset = unwind.pending_offset;
17772 unwind.pending_offset = 0;
17773 if (offset != 0)
17774 add_unwind_adjustsp (offset);
17777 /* Add an opcode to this list for this function. Two-byte opcodes should
17778 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17779 order. */
17781 static void
17782 add_unwind_opcode (valueT op, int length)
17784 /* Add any deferred stack adjustment. */
17785 if (unwind.pending_offset)
17786 flush_pending_unwind ();
17788 unwind.sp_restored = 0;
17790 if (unwind.opcode_count + length > unwind.opcode_alloc)
17792 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17793 if (unwind.opcodes)
17794 unwind.opcodes = xrealloc (unwind.opcodes,
17795 unwind.opcode_alloc);
17796 else
17797 unwind.opcodes = xmalloc (unwind.opcode_alloc);
17799 while (length > 0)
17801 length--;
17802 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17803 op >>= 8;
17804 unwind.opcode_count++;
17808 /* Add unwind opcodes to adjust the stack pointer. */
17810 static void
17811 add_unwind_adjustsp (offsetT offset)
17813 valueT op;
17815 if (offset > 0x200)
17817 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17818 char bytes[5];
17819 int n;
17820 valueT o;
17822 /* Long form: 0xb2, uleb128. */
17823 /* This might not fit in a word so add the individual bytes,
17824 remembering the list is built in reverse order. */
17825 o = (valueT) ((offset - 0x204) >> 2);
17826 if (o == 0)
17827 add_unwind_opcode (0, 1);
17829 /* Calculate the uleb128 encoding of the offset. */
17830 n = 0;
17831 while (o)
17833 bytes[n] = o & 0x7f;
17834 o >>= 7;
17835 if (o)
17836 bytes[n] |= 0x80;
17837 n++;
17839 /* Add the insn. */
17840 for (; n; n--)
17841 add_unwind_opcode (bytes[n - 1], 1);
17842 add_unwind_opcode (0xb2, 1);
17844 else if (offset > 0x100)
17846 /* Two short opcodes. */
17847 add_unwind_opcode (0x3f, 1);
17848 op = (offset - 0x104) >> 2;
17849 add_unwind_opcode (op, 1);
17851 else if (offset > 0)
17853 /* Short opcode. */
17854 op = (offset - 4) >> 2;
17855 add_unwind_opcode (op, 1);
17857 else if (offset < 0)
17859 offset = -offset;
17860 while (offset > 0x100)
17862 add_unwind_opcode (0x7f, 1);
17863 offset -= 0x100;
17865 op = ((offset - 4) >> 2) | 0x40;
17866 add_unwind_opcode (op, 1);
17870 /* Finish the list of unwind opcodes for this function. */
17871 static void
17872 finish_unwind_opcodes (void)
17874 valueT op;
17876 if (unwind.fp_used)
17878 /* Adjust sp as necessary. */
17879 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17880 flush_pending_unwind ();
17882 /* After restoring sp from the frame pointer. */
17883 op = 0x90 | unwind.fp_reg;
17884 add_unwind_opcode (op, 1);
17886 else
17887 flush_pending_unwind ();
17891 /* Start an exception table entry. If idx is nonzero this is an index table
17892 entry. */
17894 static void
17895 start_unwind_section (const segT text_seg, int idx)
17897 const char * text_name;
17898 const char * prefix;
17899 const char * prefix_once;
17900 const char * group_name;
17901 size_t prefix_len;
17902 size_t text_len;
17903 char * sec_name;
17904 size_t sec_name_len;
17905 int type;
17906 int flags;
17907 int linkonce;
17909 if (idx)
17911 prefix = ELF_STRING_ARM_unwind;
17912 prefix_once = ELF_STRING_ARM_unwind_once;
17913 type = SHT_ARM_EXIDX;
17915 else
17917 prefix = ELF_STRING_ARM_unwind_info;
17918 prefix_once = ELF_STRING_ARM_unwind_info_once;
17919 type = SHT_PROGBITS;
17922 text_name = segment_name (text_seg);
17923 if (streq (text_name, ".text"))
17924 text_name = "";
17926 if (strncmp (text_name, ".gnu.linkonce.t.",
17927 strlen (".gnu.linkonce.t.")) == 0)
17929 prefix = prefix_once;
17930 text_name += strlen (".gnu.linkonce.t.");
17933 prefix_len = strlen (prefix);
17934 text_len = strlen (text_name);
17935 sec_name_len = prefix_len + text_len;
17936 sec_name = xmalloc (sec_name_len + 1);
17937 memcpy (sec_name, prefix, prefix_len);
17938 memcpy (sec_name + prefix_len, text_name, text_len);
17939 sec_name[prefix_len + text_len] = '\0';
17941 flags = SHF_ALLOC;
17942 linkonce = 0;
17943 group_name = 0;
17945 /* Handle COMDAT group. */
17946 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
17948 group_name = elf_group_name (text_seg);
17949 if (group_name == NULL)
17951 as_bad (_("Group section `%s' has no group signature"),
17952 segment_name (text_seg));
17953 ignore_rest_of_line ();
17954 return;
17956 flags |= SHF_GROUP;
17957 linkonce = 1;
17960 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
17962 /* Set the section link for index tables. */
17963 if (idx)
17964 elf_linked_to_section (now_seg) = text_seg;
17968 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17969 personality routine data. Returns zero, or the index table value for
17970 and inline entry. */
17972 static valueT
17973 create_unwind_entry (int have_data)
17975 int size;
17976 addressT where;
17977 char *ptr;
17978 /* The current word of data. */
17979 valueT data;
17980 /* The number of bytes left in this word. */
17981 int n;
17983 finish_unwind_opcodes ();
17985 /* Remember the current text section. */
17986 unwind.saved_seg = now_seg;
17987 unwind.saved_subseg = now_subseg;
17989 start_unwind_section (now_seg, 0);
17991 if (unwind.personality_routine == NULL)
17993 if (unwind.personality_index == -2)
17995 if (have_data)
17996 as_bad (_("handlerdata in cantunwind frame"));
17997 return 1; /* EXIDX_CANTUNWIND. */
18000 /* Use a default personality routine if none is specified. */
18001 if (unwind.personality_index == -1)
18003 if (unwind.opcode_count > 3)
18004 unwind.personality_index = 1;
18005 else
18006 unwind.personality_index = 0;
18009 /* Space for the personality routine entry. */
18010 if (unwind.personality_index == 0)
18012 if (unwind.opcode_count > 3)
18013 as_bad (_("too many unwind opcodes for personality routine 0"));
18015 if (!have_data)
18017 /* All the data is inline in the index table. */
18018 data = 0x80;
18019 n = 3;
18020 while (unwind.opcode_count > 0)
18022 unwind.opcode_count--;
18023 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18024 n--;
18027 /* Pad with "finish" opcodes. */
18028 while (n--)
18029 data = (data << 8) | 0xb0;
18031 return data;
18033 size = 0;
18035 else
18036 /* We get two opcodes "free" in the first word. */
18037 size = unwind.opcode_count - 2;
18039 else
18040 /* An extra byte is required for the opcode count. */
18041 size = unwind.opcode_count + 1;
18043 size = (size + 3) >> 2;
18044 if (size > 0xff)
18045 as_bad (_("too many unwind opcodes"));
18047 frag_align (2, 0, 0);
18048 record_alignment (now_seg, 2);
18049 unwind.table_entry = expr_build_dot ();
18051 /* Allocate the table entry. */
18052 ptr = frag_more ((size << 2) + 4);
18053 where = frag_now_fix () - ((size << 2) + 4);
18055 switch (unwind.personality_index)
18057 case -1:
18058 /* ??? Should this be a PLT generating relocation? */
18059 /* Custom personality routine. */
18060 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
18061 BFD_RELOC_ARM_PREL31);
18063 where += 4;
18064 ptr += 4;
18066 /* Set the first byte to the number of additional words. */
18067 data = size - 1;
18068 n = 3;
18069 break;
18071 /* ABI defined personality routines. */
18072 case 0:
18073 /* Three opcodes bytes are packed into the first word. */
18074 data = 0x80;
18075 n = 3;
18076 break;
18078 case 1:
18079 case 2:
18080 /* The size and first two opcode bytes go in the first word. */
18081 data = ((0x80 + unwind.personality_index) << 8) | size;
18082 n = 2;
18083 break;
18085 default:
18086 /* Should never happen. */
18087 abort ();
18090 /* Pack the opcodes into words (MSB first), reversing the list at the same
18091 time. */
18092 while (unwind.opcode_count > 0)
18094 if (n == 0)
18096 md_number_to_chars (ptr, data, 4);
18097 ptr += 4;
18098 n = 4;
18099 data = 0;
18101 unwind.opcode_count--;
18102 n--;
18103 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18106 /* Finish off the last word. */
18107 if (n < 4)
18109 /* Pad with "finish" opcodes. */
18110 while (n--)
18111 data = (data << 8) | 0xb0;
18113 md_number_to_chars (ptr, data, 4);
18116 if (!have_data)
18118 /* Add an empty descriptor if there is no user-specified data. */
18119 ptr = frag_more (4);
18120 md_number_to_chars (ptr, 0, 4);
18123 return 0;
18127 /* Initialize the DWARF-2 unwind information for this procedure. */
18129 void
18130 tc_arm_frame_initial_instructions (void)
18132 cfi_add_CFA_def_cfa (REG_SP, 0);
18134 #endif /* OBJ_ELF */
18136 /* Convert REGNAME to a DWARF-2 register number. */
18139 tc_arm_regname_to_dw2regnum (char *regname)
18141 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
18143 if (reg == FAIL)
18144 return -1;
18146 return reg;
18149 #ifdef TE_PE
18150 void
18151 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
18153 expressionS expr;
18155 expr.X_op = O_secrel;
18156 expr.X_add_symbol = symbol;
18157 expr.X_add_number = 0;
18158 emit_expr (&expr, size);
18160 #endif
18162 /* MD interface: Symbol and relocation handling. */
18164 /* Return the address within the segment that a PC-relative fixup is
18165 relative to. For ARM, PC-relative fixups applied to instructions
18166 are generally relative to the location of the fixup plus 8 bytes.
18167 Thumb branches are offset by 4, and Thumb loads relative to PC
18168 require special handling. */
18170 long
18171 md_pcrel_from_section (fixS * fixP, segT seg)
18173 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
18175 /* If this is pc-relative and we are going to emit a relocation
18176 then we just want to put out any pipeline compensation that the linker
18177 will need. Otherwise we want to use the calculated base.
18178 For WinCE we skip the bias for externals as well, since this
18179 is how the MS ARM-CE assembler behaves and we want to be compatible. */
18180 if (fixP->fx_pcrel
18181 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18182 || (arm_force_relocation (fixP)
18183 #ifdef TE_WINCE
18184 && !S_IS_EXTERNAL (fixP->fx_addsy)
18185 #endif
18187 base = 0;
18189 switch (fixP->fx_r_type)
18191 /* PC relative addressing on the Thumb is slightly odd as the
18192 bottom two bits of the PC are forced to zero for the
18193 calculation. This happens *after* application of the
18194 pipeline offset. However, Thumb adrl already adjusts for
18195 this, so we need not do it again. */
18196 case BFD_RELOC_ARM_THUMB_ADD:
18197 return base & ~3;
18199 case BFD_RELOC_ARM_THUMB_OFFSET:
18200 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18201 case BFD_RELOC_ARM_T32_ADD_PC12:
18202 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
18203 return (base + 4) & ~3;
18205 /* Thumb branches are simply offset by +4. */
18206 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18207 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18208 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18209 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18210 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18211 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18212 case BFD_RELOC_THUMB_PCREL_BLX:
18213 return base + 4;
18215 /* ARM mode branches are offset by +8. However, the Windows CE
18216 loader expects the relocation not to take this into account. */
18217 case BFD_RELOC_ARM_PCREL_BRANCH:
18218 case BFD_RELOC_ARM_PCREL_CALL:
18219 case BFD_RELOC_ARM_PCREL_JUMP:
18220 case BFD_RELOC_ARM_PCREL_BLX:
18221 case BFD_RELOC_ARM_PLT32:
18222 #ifdef TE_WINCE
18223 /* When handling fixups immediately, because we have already
18224 discovered the value of a symbol, or the address of the frag involved
18225 we must account for the offset by +8, as the OS loader will never see the reloc.
18226 see fixup_segment() in write.c
18227 The S_IS_EXTERNAL test handles the case of global symbols.
18228 Those need the calculated base, not just the pipe compensation the linker will need. */
18229 if (fixP->fx_pcrel
18230 && fixP->fx_addsy != NULL
18231 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
18232 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
18233 return base + 8;
18234 return base;
18235 #else
18236 return base + 8;
18237 #endif
18239 /* ARM mode loads relative to PC are also offset by +8. Unlike
18240 branches, the Windows CE loader *does* expect the relocation
18241 to take this into account. */
18242 case BFD_RELOC_ARM_OFFSET_IMM:
18243 case BFD_RELOC_ARM_OFFSET_IMM8:
18244 case BFD_RELOC_ARM_HWLITERAL:
18245 case BFD_RELOC_ARM_LITERAL:
18246 case BFD_RELOC_ARM_CP_OFF_IMM:
18247 return base + 8;
18250 /* Other PC-relative relocations are un-offset. */
18251 default:
18252 return base;
18256 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
18257 Otherwise we have no need to default values of symbols. */
18259 symbolS *
18260 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
18262 #ifdef OBJ_ELF
18263 if (name[0] == '_' && name[1] == 'G'
18264 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
18266 if (!GOT_symbol)
18268 if (symbol_find (name))
18269 as_bad (_("GOT already in the symbol table"));
18271 GOT_symbol = symbol_new (name, undefined_section,
18272 (valueT) 0, & zero_address_frag);
18275 return GOT_symbol;
18277 #endif
18279 return 0;
18282 /* Subroutine of md_apply_fix. Check to see if an immediate can be
18283 computed as two separate immediate values, added together. We
18284 already know that this value cannot be computed by just one ARM
18285 instruction. */
18287 static unsigned int
18288 validate_immediate_twopart (unsigned int val,
18289 unsigned int * highpart)
18291 unsigned int a;
18292 unsigned int i;
18294 for (i = 0; i < 32; i += 2)
18295 if (((a = rotate_left (val, i)) & 0xff) != 0)
18297 if (a & 0xff00)
18299 if (a & ~ 0xffff)
18300 continue;
18301 * highpart = (a >> 8) | ((i + 24) << 7);
18303 else if (a & 0xff0000)
18305 if (a & 0xff000000)
18306 continue;
18307 * highpart = (a >> 16) | ((i + 16) << 7);
18309 else
18311 assert (a & 0xff000000);
18312 * highpart = (a >> 24) | ((i + 8) << 7);
18315 return (a & 0xff) | (i << 7);
18318 return FAIL;
18321 static int
18322 validate_offset_imm (unsigned int val, int hwse)
18324 if ((hwse && val > 255) || val > 4095)
18325 return FAIL;
18326 return val;
18329 /* Subroutine of md_apply_fix. Do those data_ops which can take a
18330 negative immediate constant by altering the instruction. A bit of
18331 a hack really.
18332 MOV <-> MVN
18333 AND <-> BIC
18334 ADC <-> SBC
18335 by inverting the second operand, and
18336 ADD <-> SUB
18337 CMP <-> CMN
18338 by negating the second operand. */
18340 static int
18341 negate_data_op (unsigned long * instruction,
18342 unsigned long value)
18344 int op, new_inst;
18345 unsigned long negated, inverted;
18347 negated = encode_arm_immediate (-value);
18348 inverted = encode_arm_immediate (~value);
18350 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
18351 switch (op)
18353 /* First negates. */
18354 case OPCODE_SUB: /* ADD <-> SUB */
18355 new_inst = OPCODE_ADD;
18356 value = negated;
18357 break;
18359 case OPCODE_ADD:
18360 new_inst = OPCODE_SUB;
18361 value = negated;
18362 break;
18364 case OPCODE_CMP: /* CMP <-> CMN */
18365 new_inst = OPCODE_CMN;
18366 value = negated;
18367 break;
18369 case OPCODE_CMN:
18370 new_inst = OPCODE_CMP;
18371 value = negated;
18372 break;
18374 /* Now Inverted ops. */
18375 case OPCODE_MOV: /* MOV <-> MVN */
18376 new_inst = OPCODE_MVN;
18377 value = inverted;
18378 break;
18380 case OPCODE_MVN:
18381 new_inst = OPCODE_MOV;
18382 value = inverted;
18383 break;
18385 case OPCODE_AND: /* AND <-> BIC */
18386 new_inst = OPCODE_BIC;
18387 value = inverted;
18388 break;
18390 case OPCODE_BIC:
18391 new_inst = OPCODE_AND;
18392 value = inverted;
18393 break;
18395 case OPCODE_ADC: /* ADC <-> SBC */
18396 new_inst = OPCODE_SBC;
18397 value = inverted;
18398 break;
18400 case OPCODE_SBC:
18401 new_inst = OPCODE_ADC;
18402 value = inverted;
18403 break;
18405 /* We cannot do anything. */
18406 default:
18407 return FAIL;
18410 if (value == (unsigned) FAIL)
18411 return FAIL;
18413 *instruction &= OPCODE_MASK;
18414 *instruction |= new_inst << DATA_OP_SHIFT;
18415 return value;
18418 /* Like negate_data_op, but for Thumb-2. */
18420 static unsigned int
18421 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
18423 int op, new_inst;
18424 int rd;
18425 unsigned int negated, inverted;
18427 negated = encode_thumb32_immediate (-value);
18428 inverted = encode_thumb32_immediate (~value);
18430 rd = (*instruction >> 8) & 0xf;
18431 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
18432 switch (op)
18434 /* ADD <-> SUB. Includes CMP <-> CMN. */
18435 case T2_OPCODE_SUB:
18436 new_inst = T2_OPCODE_ADD;
18437 value = negated;
18438 break;
18440 case T2_OPCODE_ADD:
18441 new_inst = T2_OPCODE_SUB;
18442 value = negated;
18443 break;
18445 /* ORR <-> ORN. Includes MOV <-> MVN. */
18446 case T2_OPCODE_ORR:
18447 new_inst = T2_OPCODE_ORN;
18448 value = inverted;
18449 break;
18451 case T2_OPCODE_ORN:
18452 new_inst = T2_OPCODE_ORR;
18453 value = inverted;
18454 break;
18456 /* AND <-> BIC. TST has no inverted equivalent. */
18457 case T2_OPCODE_AND:
18458 new_inst = T2_OPCODE_BIC;
18459 if (rd == 15)
18460 value = FAIL;
18461 else
18462 value = inverted;
18463 break;
18465 case T2_OPCODE_BIC:
18466 new_inst = T2_OPCODE_AND;
18467 value = inverted;
18468 break;
18470 /* ADC <-> SBC */
18471 case T2_OPCODE_ADC:
18472 new_inst = T2_OPCODE_SBC;
18473 value = inverted;
18474 break;
18476 case T2_OPCODE_SBC:
18477 new_inst = T2_OPCODE_ADC;
18478 value = inverted;
18479 break;
18481 /* We cannot do anything. */
18482 default:
18483 return FAIL;
18486 if (value == (unsigned int)FAIL)
18487 return FAIL;
18489 *instruction &= T2_OPCODE_MASK;
18490 *instruction |= new_inst << T2_DATA_OP_SHIFT;
18491 return value;
18494 /* Read a 32-bit thumb instruction from buf. */
18495 static unsigned long
18496 get_thumb32_insn (char * buf)
18498 unsigned long insn;
18499 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
18500 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18502 return insn;
18506 /* We usually want to set the low bit on the address of thumb function
18507 symbols. In particular .word foo - . should have the low bit set.
18508 Generic code tries to fold the difference of two symbols to
18509 a constant. Prevent this and force a relocation when the first symbols
18510 is a thumb function. */
18512 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
18514 if (op == O_subtract
18515 && l->X_op == O_symbol
18516 && r->X_op == O_symbol
18517 && THUMB_IS_FUNC (l->X_add_symbol))
18519 l->X_op = O_subtract;
18520 l->X_op_symbol = r->X_add_symbol;
18521 l->X_add_number -= r->X_add_number;
18522 return 1;
18524 /* Process as normal. */
18525 return 0;
18528 void
18529 md_apply_fix (fixS * fixP,
18530 valueT * valP,
18531 segT seg)
18533 offsetT value = * valP;
18534 offsetT newval;
18535 unsigned int newimm;
18536 unsigned long temp;
18537 int sign;
18538 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
18540 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
18542 /* Note whether this will delete the relocation. */
18544 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
18545 fixP->fx_done = 1;
18547 /* On a 64-bit host, silently truncate 'value' to 32 bits for
18548 consistency with the behaviour on 32-bit hosts. Remember value
18549 for emit_reloc. */
18550 value &= 0xffffffff;
18551 value ^= 0x80000000;
18552 value -= 0x80000000;
18554 *valP = value;
18555 fixP->fx_addnumber = value;
18557 /* Same treatment for fixP->fx_offset. */
18558 fixP->fx_offset &= 0xffffffff;
18559 fixP->fx_offset ^= 0x80000000;
18560 fixP->fx_offset -= 0x80000000;
18562 switch (fixP->fx_r_type)
18564 case BFD_RELOC_NONE:
18565 /* This will need to go in the object file. */
18566 fixP->fx_done = 0;
18567 break;
18569 case BFD_RELOC_ARM_IMMEDIATE:
18570 /* We claim that this fixup has been processed here,
18571 even if in fact we generate an error because we do
18572 not have a reloc for it, so tc_gen_reloc will reject it. */
18573 fixP->fx_done = 1;
18575 if (fixP->fx_addsy
18576 && ! S_IS_DEFINED (fixP->fx_addsy))
18578 as_bad_where (fixP->fx_file, fixP->fx_line,
18579 _("undefined symbol %s used as an immediate value"),
18580 S_GET_NAME (fixP->fx_addsy));
18581 break;
18584 if (fixP->fx_addsy
18585 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18587 as_bad_where (fixP->fx_file, fixP->fx_line,
18588 _("symbol %s is in a different section"),
18589 S_GET_NAME (fixP->fx_addsy));
18590 break;
18593 newimm = encode_arm_immediate (value);
18594 temp = md_chars_to_number (buf, INSN_SIZE);
18596 /* If the instruction will fail, see if we can fix things up by
18597 changing the opcode. */
18598 if (newimm == (unsigned int) FAIL
18599 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
18601 as_bad_where (fixP->fx_file, fixP->fx_line,
18602 _("invalid constant (%lx) after fixup"),
18603 (unsigned long) value);
18604 break;
18607 newimm |= (temp & 0xfffff000);
18608 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18609 break;
18611 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18613 unsigned int highpart = 0;
18614 unsigned int newinsn = 0xe1a00000; /* nop. */
18616 if (fixP->fx_addsy
18617 && ! S_IS_DEFINED (fixP->fx_addsy))
18619 as_bad_where (fixP->fx_file, fixP->fx_line,
18620 _("undefined symbol %s used as an immediate value"),
18621 S_GET_NAME (fixP->fx_addsy));
18622 break;
18625 if (fixP->fx_addsy
18626 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18628 as_bad_where (fixP->fx_file, fixP->fx_line,
18629 _("symbol %s is in a different section"),
18630 S_GET_NAME (fixP->fx_addsy));
18631 break;
18634 newimm = encode_arm_immediate (value);
18635 temp = md_chars_to_number (buf, INSN_SIZE);
18637 /* If the instruction will fail, see if we can fix things up by
18638 changing the opcode. */
18639 if (newimm == (unsigned int) FAIL
18640 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18642 /* No ? OK - try using two ADD instructions to generate
18643 the value. */
18644 newimm = validate_immediate_twopart (value, & highpart);
18646 /* Yes - then make sure that the second instruction is
18647 also an add. */
18648 if (newimm != (unsigned int) FAIL)
18649 newinsn = temp;
18650 /* Still No ? Try using a negated value. */
18651 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18652 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18653 /* Otherwise - give up. */
18654 else
18656 as_bad_where (fixP->fx_file, fixP->fx_line,
18657 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18658 (long) value);
18659 break;
18662 /* Replace the first operand in the 2nd instruction (which
18663 is the PC) with the destination register. We have
18664 already added in the PC in the first instruction and we
18665 do not want to do it again. */
18666 newinsn &= ~ 0xf0000;
18667 newinsn |= ((newinsn & 0x0f000) << 4);
18670 newimm |= (temp & 0xfffff000);
18671 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18673 highpart |= (newinsn & 0xfffff000);
18674 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18676 break;
18678 case BFD_RELOC_ARM_OFFSET_IMM:
18679 if (!fixP->fx_done && seg->use_rela_p)
18680 value = 0;
18682 case BFD_RELOC_ARM_LITERAL:
18683 sign = value >= 0;
18685 if (value < 0)
18686 value = - value;
18688 if (validate_offset_imm (value, 0) == FAIL)
18690 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18691 as_bad_where (fixP->fx_file, fixP->fx_line,
18692 _("invalid literal constant: pool needs to be closer"));
18693 else
18694 as_bad_where (fixP->fx_file, fixP->fx_line,
18695 _("bad immediate value for offset (%ld)"),
18696 (long) value);
18697 break;
18700 newval = md_chars_to_number (buf, INSN_SIZE);
18701 newval &= 0xff7ff000;
18702 newval |= value | (sign ? INDEX_UP : 0);
18703 md_number_to_chars (buf, newval, INSN_SIZE);
18704 break;
18706 case BFD_RELOC_ARM_OFFSET_IMM8:
18707 case BFD_RELOC_ARM_HWLITERAL:
18708 sign = value >= 0;
18710 if (value < 0)
18711 value = - value;
18713 if (validate_offset_imm (value, 1) == FAIL)
18715 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18716 as_bad_where (fixP->fx_file, fixP->fx_line,
18717 _("invalid literal constant: pool needs to be closer"));
18718 else
18719 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
18720 (long) value);
18721 break;
18724 newval = md_chars_to_number (buf, INSN_SIZE);
18725 newval &= 0xff7ff0f0;
18726 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18727 md_number_to_chars (buf, newval, INSN_SIZE);
18728 break;
18730 case BFD_RELOC_ARM_T32_OFFSET_U8:
18731 if (value < 0 || value > 1020 || value % 4 != 0)
18732 as_bad_where (fixP->fx_file, fixP->fx_line,
18733 _("bad immediate value for offset (%ld)"), (long) value);
18734 value /= 4;
18736 newval = md_chars_to_number (buf+2, THUMB_SIZE);
18737 newval |= value;
18738 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18739 break;
18741 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18742 /* This is a complicated relocation used for all varieties of Thumb32
18743 load/store instruction with immediate offset:
18745 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18746 *4, optional writeback(W)
18747 (doubleword load/store)
18749 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18750 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18751 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18752 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18753 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18755 Uppercase letters indicate bits that are already encoded at
18756 this point. Lowercase letters are our problem. For the
18757 second block of instructions, the secondary opcode nybble
18758 (bits 8..11) is present, and bit 23 is zero, even if this is
18759 a PC-relative operation. */
18760 newval = md_chars_to_number (buf, THUMB_SIZE);
18761 newval <<= 16;
18762 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
18764 if ((newval & 0xf0000000) == 0xe0000000)
18766 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18767 if (value >= 0)
18768 newval |= (1 << 23);
18769 else
18770 value = -value;
18771 if (value % 4 != 0)
18773 as_bad_where (fixP->fx_file, fixP->fx_line,
18774 _("offset not a multiple of 4"));
18775 break;
18777 value /= 4;
18778 if (value > 0xff)
18780 as_bad_where (fixP->fx_file, fixP->fx_line,
18781 _("offset out of range"));
18782 break;
18784 newval &= ~0xff;
18786 else if ((newval & 0x000f0000) == 0x000f0000)
18788 /* PC-relative, 12-bit offset. */
18789 if (value >= 0)
18790 newval |= (1 << 23);
18791 else
18792 value = -value;
18793 if (value > 0xfff)
18795 as_bad_where (fixP->fx_file, fixP->fx_line,
18796 _("offset out of range"));
18797 break;
18799 newval &= ~0xfff;
18801 else if ((newval & 0x00000100) == 0x00000100)
18803 /* Writeback: 8-bit, +/- offset. */
18804 if (value >= 0)
18805 newval |= (1 << 9);
18806 else
18807 value = -value;
18808 if (value > 0xff)
18810 as_bad_where (fixP->fx_file, fixP->fx_line,
18811 _("offset out of range"));
18812 break;
18814 newval &= ~0xff;
18816 else if ((newval & 0x00000f00) == 0x00000e00)
18818 /* T-instruction: positive 8-bit offset. */
18819 if (value < 0 || value > 0xff)
18821 as_bad_where (fixP->fx_file, fixP->fx_line,
18822 _("offset out of range"));
18823 break;
18825 newval &= ~0xff;
18826 newval |= value;
18828 else
18830 /* Positive 12-bit or negative 8-bit offset. */
18831 int limit;
18832 if (value >= 0)
18834 newval |= (1 << 23);
18835 limit = 0xfff;
18837 else
18839 value = -value;
18840 limit = 0xff;
18842 if (value > limit)
18844 as_bad_where (fixP->fx_file, fixP->fx_line,
18845 _("offset out of range"));
18846 break;
18848 newval &= ~limit;
18851 newval |= value;
18852 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18853 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18854 break;
18856 case BFD_RELOC_ARM_SHIFT_IMM:
18857 newval = md_chars_to_number (buf, INSN_SIZE);
18858 if (((unsigned long) value) > 32
18859 || (value == 32
18860 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18862 as_bad_where (fixP->fx_file, fixP->fx_line,
18863 _("shift expression is too large"));
18864 break;
18867 if (value == 0)
18868 /* Shifts of zero must be done as lsl. */
18869 newval &= ~0x60;
18870 else if (value == 32)
18871 value = 0;
18872 newval &= 0xfffff07f;
18873 newval |= (value & 0x1f) << 7;
18874 md_number_to_chars (buf, newval, INSN_SIZE);
18875 break;
18877 case BFD_RELOC_ARM_T32_IMMEDIATE:
18878 case BFD_RELOC_ARM_T32_ADD_IMM:
18879 case BFD_RELOC_ARM_T32_IMM12:
18880 case BFD_RELOC_ARM_T32_ADD_PC12:
18881 /* We claim that this fixup has been processed here,
18882 even if in fact we generate an error because we do
18883 not have a reloc for it, so tc_gen_reloc will reject it. */
18884 fixP->fx_done = 1;
18886 if (fixP->fx_addsy
18887 && ! S_IS_DEFINED (fixP->fx_addsy))
18889 as_bad_where (fixP->fx_file, fixP->fx_line,
18890 _("undefined symbol %s used as an immediate value"),
18891 S_GET_NAME (fixP->fx_addsy));
18892 break;
18895 newval = md_chars_to_number (buf, THUMB_SIZE);
18896 newval <<= 16;
18897 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
18899 newimm = FAIL;
18900 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18901 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18903 newimm = encode_thumb32_immediate (value);
18904 if (newimm == (unsigned int) FAIL)
18905 newimm = thumb32_negate_data_op (&newval, value);
18907 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18908 && newimm == (unsigned int) FAIL)
18910 /* Turn add/sum into addw/subw. */
18911 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18912 newval = (newval & 0xfeffffff) | 0x02000000;
18914 /* 12 bit immediate for addw/subw. */
18915 if (value < 0)
18917 value = -value;
18918 newval ^= 0x00a00000;
18920 if (value > 0xfff)
18921 newimm = (unsigned int) FAIL;
18922 else
18923 newimm = value;
18926 if (newimm == (unsigned int)FAIL)
18928 as_bad_where (fixP->fx_file, fixP->fx_line,
18929 _("invalid constant (%lx) after fixup"),
18930 (unsigned long) value);
18931 break;
18934 newval |= (newimm & 0x800) << 15;
18935 newval |= (newimm & 0x700) << 4;
18936 newval |= (newimm & 0x0ff);
18938 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18939 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18940 break;
18942 case BFD_RELOC_ARM_SMC:
18943 if (((unsigned long) value) > 0xffff)
18944 as_bad_where (fixP->fx_file, fixP->fx_line,
18945 _("invalid smc expression"));
18946 newval = md_chars_to_number (buf, INSN_SIZE);
18947 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18948 md_number_to_chars (buf, newval, INSN_SIZE);
18949 break;
18951 case BFD_RELOC_ARM_SWI:
18952 if (fixP->tc_fix_data != 0)
18954 if (((unsigned long) value) > 0xff)
18955 as_bad_where (fixP->fx_file, fixP->fx_line,
18956 _("invalid swi expression"));
18957 newval = md_chars_to_number (buf, THUMB_SIZE);
18958 newval |= value;
18959 md_number_to_chars (buf, newval, THUMB_SIZE);
18961 else
18963 if (((unsigned long) value) > 0x00ffffff)
18964 as_bad_where (fixP->fx_file, fixP->fx_line,
18965 _("invalid swi expression"));
18966 newval = md_chars_to_number (buf, INSN_SIZE);
18967 newval |= value;
18968 md_number_to_chars (buf, newval, INSN_SIZE);
18970 break;
18972 case BFD_RELOC_ARM_MULTI:
18973 if (((unsigned long) value) > 0xffff)
18974 as_bad_where (fixP->fx_file, fixP->fx_line,
18975 _("invalid expression in load/store multiple"));
18976 newval = value | md_chars_to_number (buf, INSN_SIZE);
18977 md_number_to_chars (buf, newval, INSN_SIZE);
18978 break;
18980 #ifdef OBJ_ELF
18981 case BFD_RELOC_ARM_PCREL_CALL:
18982 newval = md_chars_to_number (buf, INSN_SIZE);
18983 if ((newval & 0xf0000000) == 0xf0000000)
18984 temp = 1;
18985 else
18986 temp = 3;
18987 goto arm_branch_common;
18989 case BFD_RELOC_ARM_PCREL_JUMP:
18990 case BFD_RELOC_ARM_PLT32:
18991 #endif
18992 case BFD_RELOC_ARM_PCREL_BRANCH:
18993 temp = 3;
18994 goto arm_branch_common;
18996 case BFD_RELOC_ARM_PCREL_BLX:
18997 temp = 1;
18998 arm_branch_common:
18999 /* We are going to store value (shifted right by two) in the
19000 instruction, in a 24 bit, signed field. Bits 26 through 32 either
19001 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
19002 also be be clear. */
19003 if (value & temp)
19004 as_bad_where (fixP->fx_file, fixP->fx_line,
19005 _("misaligned branch destination"));
19006 if ((value & (offsetT)0xfe000000) != (offsetT)0
19007 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
19008 as_bad_where (fixP->fx_file, fixP->fx_line,
19009 _("branch out of range"));
19011 if (fixP->fx_done || !seg->use_rela_p)
19013 newval = md_chars_to_number (buf, INSN_SIZE);
19014 newval |= (value >> 2) & 0x00ffffff;
19015 /* Set the H bit on BLX instructions. */
19016 if (temp == 1)
19018 if (value & 2)
19019 newval |= 0x01000000;
19020 else
19021 newval &= ~0x01000000;
19023 md_number_to_chars (buf, newval, INSN_SIZE);
19025 break;
19027 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
19028 /* CBZ can only branch forward. */
19030 /* Attempts to use CBZ to branch to the next instruction
19031 (which, strictly speaking, are prohibited) will be turned into
19032 no-ops.
19034 FIXME: It may be better to remove the instruction completely and
19035 perform relaxation. */
19036 if (value == -2)
19038 newval = md_chars_to_number (buf, THUMB_SIZE);
19039 newval = 0xbf00; /* NOP encoding T1 */
19040 md_number_to_chars (buf, newval, THUMB_SIZE);
19042 else
19044 if (value & ~0x7e)
19045 as_bad_where (fixP->fx_file, fixP->fx_line,
19046 _("branch out of range"));
19048 if (fixP->fx_done || !seg->use_rela_p)
19050 newval = md_chars_to_number (buf, THUMB_SIZE);
19051 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
19052 md_number_to_chars (buf, newval, THUMB_SIZE);
19055 break;
19057 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
19058 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
19059 as_bad_where (fixP->fx_file, fixP->fx_line,
19060 _("branch out of range"));
19062 if (fixP->fx_done || !seg->use_rela_p)
19064 newval = md_chars_to_number (buf, THUMB_SIZE);
19065 newval |= (value & 0x1ff) >> 1;
19066 md_number_to_chars (buf, newval, THUMB_SIZE);
19068 break;
19070 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
19071 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
19072 as_bad_where (fixP->fx_file, fixP->fx_line,
19073 _("branch out of range"));
19075 if (fixP->fx_done || !seg->use_rela_p)
19077 newval = md_chars_to_number (buf, THUMB_SIZE);
19078 newval |= (value & 0xfff) >> 1;
19079 md_number_to_chars (buf, newval, THUMB_SIZE);
19081 break;
19083 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19084 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
19085 as_bad_where (fixP->fx_file, fixP->fx_line,
19086 _("conditional branch out of range"));
19088 if (fixP->fx_done || !seg->use_rela_p)
19090 offsetT newval2;
19091 addressT S, J1, J2, lo, hi;
19093 S = (value & 0x00100000) >> 20;
19094 J2 = (value & 0x00080000) >> 19;
19095 J1 = (value & 0x00040000) >> 18;
19096 hi = (value & 0x0003f000) >> 12;
19097 lo = (value & 0x00000ffe) >> 1;
19099 newval = md_chars_to_number (buf, THUMB_SIZE);
19100 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19101 newval |= (S << 10) | hi;
19102 newval2 |= (J1 << 13) | (J2 << 11) | lo;
19103 md_number_to_chars (buf, newval, THUMB_SIZE);
19104 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19106 break;
19108 case BFD_RELOC_THUMB_PCREL_BLX:
19109 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19110 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
19111 as_bad_where (fixP->fx_file, fixP->fx_line,
19112 _("branch out of range"));
19114 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
19115 /* For a BLX instruction, make sure that the relocation is rounded up
19116 to a word boundary. This follows the semantics of the instruction
19117 which specifies that bit 1 of the target address will come from bit
19118 1 of the base address. */
19119 value = (value + 1) & ~ 1;
19121 if (fixP->fx_done || !seg->use_rela_p)
19123 offsetT newval2;
19125 newval = md_chars_to_number (buf, THUMB_SIZE);
19126 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19127 newval |= (value & 0x7fffff) >> 12;
19128 newval2 |= (value & 0xfff) >> 1;
19129 md_number_to_chars (buf, newval, THUMB_SIZE);
19130 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19132 break;
19134 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19135 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
19136 as_bad_where (fixP->fx_file, fixP->fx_line,
19137 _("branch out of range"));
19139 if (fixP->fx_done || !seg->use_rela_p)
19141 offsetT newval2;
19142 addressT S, I1, I2, lo, hi;
19144 S = (value & 0x01000000) >> 24;
19145 I1 = (value & 0x00800000) >> 23;
19146 I2 = (value & 0x00400000) >> 22;
19147 hi = (value & 0x003ff000) >> 12;
19148 lo = (value & 0x00000ffe) >> 1;
19150 I1 = !(I1 ^ S);
19151 I2 = !(I2 ^ S);
19153 newval = md_chars_to_number (buf, THUMB_SIZE);
19154 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19155 newval |= (S << 10) | hi;
19156 newval2 |= (I1 << 13) | (I2 << 11) | lo;
19157 md_number_to_chars (buf, newval, THUMB_SIZE);
19158 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19160 break;
19162 case BFD_RELOC_8:
19163 if (fixP->fx_done || !seg->use_rela_p)
19164 md_number_to_chars (buf, value, 1);
19165 break;
19167 case BFD_RELOC_16:
19168 if (fixP->fx_done || !seg->use_rela_p)
19169 md_number_to_chars (buf, value, 2);
19170 break;
19172 #ifdef OBJ_ELF
19173 case BFD_RELOC_ARM_TLS_GD32:
19174 case BFD_RELOC_ARM_TLS_LE32:
19175 case BFD_RELOC_ARM_TLS_IE32:
19176 case BFD_RELOC_ARM_TLS_LDM32:
19177 case BFD_RELOC_ARM_TLS_LDO32:
19178 S_SET_THREAD_LOCAL (fixP->fx_addsy);
19179 /* fall through */
19181 case BFD_RELOC_ARM_GOT32:
19182 case BFD_RELOC_ARM_GOTOFF:
19183 case BFD_RELOC_ARM_TARGET2:
19184 if (fixP->fx_done || !seg->use_rela_p)
19185 md_number_to_chars (buf, 0, 4);
19186 break;
19187 #endif
19189 case BFD_RELOC_RVA:
19190 case BFD_RELOC_32:
19191 case BFD_RELOC_ARM_TARGET1:
19192 case BFD_RELOC_ARM_ROSEGREL32:
19193 case BFD_RELOC_ARM_SBREL32:
19194 case BFD_RELOC_32_PCREL:
19195 #ifdef TE_PE
19196 case BFD_RELOC_32_SECREL:
19197 #endif
19198 if (fixP->fx_done || !seg->use_rela_p)
19199 #ifdef TE_WINCE
19200 /* For WinCE we only do this for pcrel fixups. */
19201 if (fixP->fx_done || fixP->fx_pcrel)
19202 #endif
19203 md_number_to_chars (buf, value, 4);
19204 break;
19206 #ifdef OBJ_ELF
19207 case BFD_RELOC_ARM_PREL31:
19208 if (fixP->fx_done || !seg->use_rela_p)
19210 newval = md_chars_to_number (buf, 4) & 0x80000000;
19211 if ((value ^ (value >> 1)) & 0x40000000)
19213 as_bad_where (fixP->fx_file, fixP->fx_line,
19214 _("rel31 relocation overflow"));
19216 newval |= value & 0x7fffffff;
19217 md_number_to_chars (buf, newval, 4);
19219 break;
19220 #endif
19222 case BFD_RELOC_ARM_CP_OFF_IMM:
19223 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
19224 if (value < -1023 || value > 1023 || (value & 3))
19225 as_bad_where (fixP->fx_file, fixP->fx_line,
19226 _("co-processor offset out of range"));
19227 cp_off_common:
19228 sign = value >= 0;
19229 if (value < 0)
19230 value = -value;
19231 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19232 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19233 newval = md_chars_to_number (buf, INSN_SIZE);
19234 else
19235 newval = get_thumb32_insn (buf);
19236 newval &= 0xff7fff00;
19237 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
19238 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19239 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19240 md_number_to_chars (buf, newval, INSN_SIZE);
19241 else
19242 put_thumb32_insn (buf, newval);
19243 break;
19245 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
19246 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
19247 if (value < -255 || value > 255)
19248 as_bad_where (fixP->fx_file, fixP->fx_line,
19249 _("co-processor offset out of range"));
19250 value *= 4;
19251 goto cp_off_common;
19253 case BFD_RELOC_ARM_THUMB_OFFSET:
19254 newval = md_chars_to_number (buf, THUMB_SIZE);
19255 /* Exactly what ranges, and where the offset is inserted depends
19256 on the type of instruction, we can establish this from the
19257 top 4 bits. */
19258 switch (newval >> 12)
19260 case 4: /* PC load. */
19261 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
19262 forced to zero for these loads; md_pcrel_from has already
19263 compensated for this. */
19264 if (value & 3)
19265 as_bad_where (fixP->fx_file, fixP->fx_line,
19266 _("invalid offset, target not word aligned (0x%08lX)"),
19267 (((unsigned long) fixP->fx_frag->fr_address
19268 + (unsigned long) fixP->fx_where) & ~3)
19269 + (unsigned long) value);
19271 if (value & ~0x3fc)
19272 as_bad_where (fixP->fx_file, fixP->fx_line,
19273 _("invalid offset, value too big (0x%08lX)"),
19274 (long) value);
19276 newval |= value >> 2;
19277 break;
19279 case 9: /* SP load/store. */
19280 if (value & ~0x3fc)
19281 as_bad_where (fixP->fx_file, fixP->fx_line,
19282 _("invalid offset, value too big (0x%08lX)"),
19283 (long) value);
19284 newval |= value >> 2;
19285 break;
19287 case 6: /* Word load/store. */
19288 if (value & ~0x7c)
19289 as_bad_where (fixP->fx_file, fixP->fx_line,
19290 _("invalid offset, value too big (0x%08lX)"),
19291 (long) value);
19292 newval |= value << 4; /* 6 - 2. */
19293 break;
19295 case 7: /* Byte load/store. */
19296 if (value & ~0x1f)
19297 as_bad_where (fixP->fx_file, fixP->fx_line,
19298 _("invalid offset, value too big (0x%08lX)"),
19299 (long) value);
19300 newval |= value << 6;
19301 break;
19303 case 8: /* Halfword load/store. */
19304 if (value & ~0x3e)
19305 as_bad_where (fixP->fx_file, fixP->fx_line,
19306 _("invalid offset, value too big (0x%08lX)"),
19307 (long) value);
19308 newval |= value << 5; /* 6 - 1. */
19309 break;
19311 default:
19312 as_bad_where (fixP->fx_file, fixP->fx_line,
19313 "Unable to process relocation for thumb opcode: %lx",
19314 (unsigned long) newval);
19315 break;
19317 md_number_to_chars (buf, newval, THUMB_SIZE);
19318 break;
19320 case BFD_RELOC_ARM_THUMB_ADD:
19321 /* This is a complicated relocation, since we use it for all of
19322 the following immediate relocations:
19324 3bit ADD/SUB
19325 8bit ADD/SUB
19326 9bit ADD/SUB SP word-aligned
19327 10bit ADD PC/SP word-aligned
19329 The type of instruction being processed is encoded in the
19330 instruction field:
19332 0x8000 SUB
19333 0x00F0 Rd
19334 0x000F Rs
19336 newval = md_chars_to_number (buf, THUMB_SIZE);
19338 int rd = (newval >> 4) & 0xf;
19339 int rs = newval & 0xf;
19340 int subtract = !!(newval & 0x8000);
19342 /* Check for HI regs, only very restricted cases allowed:
19343 Adjusting SP, and using PC or SP to get an address. */
19344 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
19345 || (rs > 7 && rs != REG_SP && rs != REG_PC))
19346 as_bad_where (fixP->fx_file, fixP->fx_line,
19347 _("invalid Hi register with immediate"));
19349 /* If value is negative, choose the opposite instruction. */
19350 if (value < 0)
19352 value = -value;
19353 subtract = !subtract;
19354 if (value < 0)
19355 as_bad_where (fixP->fx_file, fixP->fx_line,
19356 _("immediate value out of range"));
19359 if (rd == REG_SP)
19361 if (value & ~0x1fc)
19362 as_bad_where (fixP->fx_file, fixP->fx_line,
19363 _("invalid immediate for stack address calculation"));
19364 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
19365 newval |= value >> 2;
19367 else if (rs == REG_PC || rs == REG_SP)
19369 if (subtract || value & ~0x3fc)
19370 as_bad_where (fixP->fx_file, fixP->fx_line,
19371 _("invalid immediate for address calculation (value = 0x%08lX)"),
19372 (unsigned long) value);
19373 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
19374 newval |= rd << 8;
19375 newval |= value >> 2;
19377 else if (rs == rd)
19379 if (value & ~0xff)
19380 as_bad_where (fixP->fx_file, fixP->fx_line,
19381 _("immediate value out of range"));
19382 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
19383 newval |= (rd << 8) | value;
19385 else
19387 if (value & ~0x7)
19388 as_bad_where (fixP->fx_file, fixP->fx_line,
19389 _("immediate value out of range"));
19390 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
19391 newval |= rd | (rs << 3) | (value << 6);
19394 md_number_to_chars (buf, newval, THUMB_SIZE);
19395 break;
19397 case BFD_RELOC_ARM_THUMB_IMM:
19398 newval = md_chars_to_number (buf, THUMB_SIZE);
19399 if (value < 0 || value > 255)
19400 as_bad_where (fixP->fx_file, fixP->fx_line,
19401 _("invalid immediate: %ld is out of range"),
19402 (long) value);
19403 newval |= value;
19404 md_number_to_chars (buf, newval, THUMB_SIZE);
19405 break;
19407 case BFD_RELOC_ARM_THUMB_SHIFT:
19408 /* 5bit shift value (0..32). LSL cannot take 32. */
19409 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
19410 temp = newval & 0xf800;
19411 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
19412 as_bad_where (fixP->fx_file, fixP->fx_line,
19413 _("invalid shift value: %ld"), (long) value);
19414 /* Shifts of zero must be encoded as LSL. */
19415 if (value == 0)
19416 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
19417 /* Shifts of 32 are encoded as zero. */
19418 else if (value == 32)
19419 value = 0;
19420 newval |= value << 6;
19421 md_number_to_chars (buf, newval, THUMB_SIZE);
19422 break;
19424 case BFD_RELOC_VTABLE_INHERIT:
19425 case BFD_RELOC_VTABLE_ENTRY:
19426 fixP->fx_done = 0;
19427 return;
19429 case BFD_RELOC_ARM_MOVW:
19430 case BFD_RELOC_ARM_MOVT:
19431 case BFD_RELOC_ARM_THUMB_MOVW:
19432 case BFD_RELOC_ARM_THUMB_MOVT:
19433 if (fixP->fx_done || !seg->use_rela_p)
19435 /* REL format relocations are limited to a 16-bit addend. */
19436 if (!fixP->fx_done)
19438 if (value < -0x8000 || value > 0x7fff)
19439 as_bad_where (fixP->fx_file, fixP->fx_line,
19440 _("offset out of range"));
19442 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
19443 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
19445 value >>= 16;
19448 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
19449 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
19451 newval = get_thumb32_insn (buf);
19452 newval &= 0xfbf08f00;
19453 newval |= (value & 0xf000) << 4;
19454 newval |= (value & 0x0800) << 15;
19455 newval |= (value & 0x0700) << 4;
19456 newval |= (value & 0x00ff);
19457 put_thumb32_insn (buf, newval);
19459 else
19461 newval = md_chars_to_number (buf, 4);
19462 newval &= 0xfff0f000;
19463 newval |= value & 0x0fff;
19464 newval |= (value & 0xf000) << 4;
19465 md_number_to_chars (buf, newval, 4);
19468 return;
19470 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19471 case BFD_RELOC_ARM_ALU_PC_G0:
19472 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19473 case BFD_RELOC_ARM_ALU_PC_G1:
19474 case BFD_RELOC_ARM_ALU_PC_G2:
19475 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19476 case BFD_RELOC_ARM_ALU_SB_G0:
19477 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19478 case BFD_RELOC_ARM_ALU_SB_G1:
19479 case BFD_RELOC_ARM_ALU_SB_G2:
19480 assert (!fixP->fx_done);
19481 if (!seg->use_rela_p)
19483 bfd_vma insn;
19484 bfd_vma encoded_addend;
19485 bfd_vma addend_abs = abs (value);
19487 /* Check that the absolute value of the addend can be
19488 expressed as an 8-bit constant plus a rotation. */
19489 encoded_addend = encode_arm_immediate (addend_abs);
19490 if (encoded_addend == (unsigned int) FAIL)
19491 as_bad_where (fixP->fx_file, fixP->fx_line,
19492 _("the offset 0x%08lX is not representable"),
19493 (unsigned long) addend_abs);
19495 /* Extract the instruction. */
19496 insn = md_chars_to_number (buf, INSN_SIZE);
19498 /* If the addend is positive, use an ADD instruction.
19499 Otherwise use a SUB. Take care not to destroy the S bit. */
19500 insn &= 0xff1fffff;
19501 if (value < 0)
19502 insn |= 1 << 22;
19503 else
19504 insn |= 1 << 23;
19506 /* Place the encoded addend into the first 12 bits of the
19507 instruction. */
19508 insn &= 0xfffff000;
19509 insn |= encoded_addend;
19511 /* Update the instruction. */
19512 md_number_to_chars (buf, insn, INSN_SIZE);
19514 break;
19516 case BFD_RELOC_ARM_LDR_PC_G0:
19517 case BFD_RELOC_ARM_LDR_PC_G1:
19518 case BFD_RELOC_ARM_LDR_PC_G2:
19519 case BFD_RELOC_ARM_LDR_SB_G0:
19520 case BFD_RELOC_ARM_LDR_SB_G1:
19521 case BFD_RELOC_ARM_LDR_SB_G2:
19522 assert (!fixP->fx_done);
19523 if (!seg->use_rela_p)
19525 bfd_vma insn;
19526 bfd_vma addend_abs = abs (value);
19528 /* Check that the absolute value of the addend can be
19529 encoded in 12 bits. */
19530 if (addend_abs >= 0x1000)
19531 as_bad_where (fixP->fx_file, fixP->fx_line,
19532 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
19533 (unsigned long) addend_abs);
19535 /* Extract the instruction. */
19536 insn = md_chars_to_number (buf, INSN_SIZE);
19538 /* If the addend is negative, clear bit 23 of the instruction.
19539 Otherwise set it. */
19540 if (value < 0)
19541 insn &= ~(1 << 23);
19542 else
19543 insn |= 1 << 23;
19545 /* Place the absolute value of the addend into the first 12 bits
19546 of the instruction. */
19547 insn &= 0xfffff000;
19548 insn |= addend_abs;
19550 /* Update the instruction. */
19551 md_number_to_chars (buf, insn, INSN_SIZE);
19553 break;
19555 case BFD_RELOC_ARM_LDRS_PC_G0:
19556 case BFD_RELOC_ARM_LDRS_PC_G1:
19557 case BFD_RELOC_ARM_LDRS_PC_G2:
19558 case BFD_RELOC_ARM_LDRS_SB_G0:
19559 case BFD_RELOC_ARM_LDRS_SB_G1:
19560 case BFD_RELOC_ARM_LDRS_SB_G2:
19561 assert (!fixP->fx_done);
19562 if (!seg->use_rela_p)
19564 bfd_vma insn;
19565 bfd_vma addend_abs = abs (value);
19567 /* Check that the absolute value of the addend can be
19568 encoded in 8 bits. */
19569 if (addend_abs >= 0x100)
19570 as_bad_where (fixP->fx_file, fixP->fx_line,
19571 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
19572 (unsigned long) addend_abs);
19574 /* Extract the instruction. */
19575 insn = md_chars_to_number (buf, INSN_SIZE);
19577 /* If the addend is negative, clear bit 23 of the instruction.
19578 Otherwise set it. */
19579 if (value < 0)
19580 insn &= ~(1 << 23);
19581 else
19582 insn |= 1 << 23;
19584 /* Place the first four bits of the absolute value of the addend
19585 into the first 4 bits of the instruction, and the remaining
19586 four into bits 8 .. 11. */
19587 insn &= 0xfffff0f0;
19588 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
19590 /* Update the instruction. */
19591 md_number_to_chars (buf, insn, INSN_SIZE);
19593 break;
19595 case BFD_RELOC_ARM_LDC_PC_G0:
19596 case BFD_RELOC_ARM_LDC_PC_G1:
19597 case BFD_RELOC_ARM_LDC_PC_G2:
19598 case BFD_RELOC_ARM_LDC_SB_G0:
19599 case BFD_RELOC_ARM_LDC_SB_G1:
19600 case BFD_RELOC_ARM_LDC_SB_G2:
19601 assert (!fixP->fx_done);
19602 if (!seg->use_rela_p)
19604 bfd_vma insn;
19605 bfd_vma addend_abs = abs (value);
19607 /* Check that the absolute value of the addend is a multiple of
19608 four and, when divided by four, fits in 8 bits. */
19609 if (addend_abs & 0x3)
19610 as_bad_where (fixP->fx_file, fixP->fx_line,
19611 _("bad offset 0x%08lX (must be word-aligned)"),
19612 (unsigned long) addend_abs);
19614 if ((addend_abs >> 2) > 0xff)
19615 as_bad_where (fixP->fx_file, fixP->fx_line,
19616 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
19617 (unsigned long) addend_abs);
19619 /* Extract the instruction. */
19620 insn = md_chars_to_number (buf, INSN_SIZE);
19622 /* If the addend is negative, clear bit 23 of the instruction.
19623 Otherwise set it. */
19624 if (value < 0)
19625 insn &= ~(1 << 23);
19626 else
19627 insn |= 1 << 23;
19629 /* Place the addend (divided by four) into the first eight
19630 bits of the instruction. */
19631 insn &= 0xfffffff0;
19632 insn |= addend_abs >> 2;
19634 /* Update the instruction. */
19635 md_number_to_chars (buf, insn, INSN_SIZE);
19637 break;
19639 case BFD_RELOC_ARM_V4BX:
19640 /* This will need to go in the object file. */
19641 fixP->fx_done = 0;
19642 break;
19644 case BFD_RELOC_UNUSED:
19645 default:
19646 as_bad_where (fixP->fx_file, fixP->fx_line,
19647 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19651 /* Translate internal representation of relocation info to BFD target
19652 format. */
19654 arelent *
19655 tc_gen_reloc (asection *section, fixS *fixp)
19657 arelent * reloc;
19658 bfd_reloc_code_real_type code;
19660 reloc = xmalloc (sizeof (arelent));
19662 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19663 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19664 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
19666 if (fixp->fx_pcrel)
19668 if (section->use_rela_p)
19669 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19670 else
19671 fixp->fx_offset = reloc->address;
19673 reloc->addend = fixp->fx_offset;
19675 switch (fixp->fx_r_type)
19677 case BFD_RELOC_8:
19678 if (fixp->fx_pcrel)
19680 code = BFD_RELOC_8_PCREL;
19681 break;
19684 case BFD_RELOC_16:
19685 if (fixp->fx_pcrel)
19687 code = BFD_RELOC_16_PCREL;
19688 break;
19691 case BFD_RELOC_32:
19692 if (fixp->fx_pcrel)
19694 code = BFD_RELOC_32_PCREL;
19695 break;
19698 case BFD_RELOC_ARM_MOVW:
19699 if (fixp->fx_pcrel)
19701 code = BFD_RELOC_ARM_MOVW_PCREL;
19702 break;
19705 case BFD_RELOC_ARM_MOVT:
19706 if (fixp->fx_pcrel)
19708 code = BFD_RELOC_ARM_MOVT_PCREL;
19709 break;
19712 case BFD_RELOC_ARM_THUMB_MOVW:
19713 if (fixp->fx_pcrel)
19715 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19716 break;
19719 case BFD_RELOC_ARM_THUMB_MOVT:
19720 if (fixp->fx_pcrel)
19722 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19723 break;
19726 case BFD_RELOC_NONE:
19727 case BFD_RELOC_ARM_PCREL_BRANCH:
19728 case BFD_RELOC_ARM_PCREL_BLX:
19729 case BFD_RELOC_RVA:
19730 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19731 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19732 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19733 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19734 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19735 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19736 case BFD_RELOC_THUMB_PCREL_BLX:
19737 case BFD_RELOC_VTABLE_ENTRY:
19738 case BFD_RELOC_VTABLE_INHERIT:
19739 #ifdef TE_PE
19740 case BFD_RELOC_32_SECREL:
19741 #endif
19742 code = fixp->fx_r_type;
19743 break;
19745 case BFD_RELOC_ARM_LITERAL:
19746 case BFD_RELOC_ARM_HWLITERAL:
19747 /* If this is called then the a literal has
19748 been referenced across a section boundary. */
19749 as_bad_where (fixp->fx_file, fixp->fx_line,
19750 _("literal referenced across section boundary"));
19751 return NULL;
19753 #ifdef OBJ_ELF
19754 case BFD_RELOC_ARM_GOT32:
19755 case BFD_RELOC_ARM_GOTOFF:
19756 case BFD_RELOC_ARM_PLT32:
19757 case BFD_RELOC_ARM_TARGET1:
19758 case BFD_RELOC_ARM_ROSEGREL32:
19759 case BFD_RELOC_ARM_SBREL32:
19760 case BFD_RELOC_ARM_PREL31:
19761 case BFD_RELOC_ARM_TARGET2:
19762 case BFD_RELOC_ARM_TLS_LE32:
19763 case BFD_RELOC_ARM_TLS_LDO32:
19764 case BFD_RELOC_ARM_PCREL_CALL:
19765 case BFD_RELOC_ARM_PCREL_JUMP:
19766 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19767 case BFD_RELOC_ARM_ALU_PC_G0:
19768 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19769 case BFD_RELOC_ARM_ALU_PC_G1:
19770 case BFD_RELOC_ARM_ALU_PC_G2:
19771 case BFD_RELOC_ARM_LDR_PC_G0:
19772 case BFD_RELOC_ARM_LDR_PC_G1:
19773 case BFD_RELOC_ARM_LDR_PC_G2:
19774 case BFD_RELOC_ARM_LDRS_PC_G0:
19775 case BFD_RELOC_ARM_LDRS_PC_G1:
19776 case BFD_RELOC_ARM_LDRS_PC_G2:
19777 case BFD_RELOC_ARM_LDC_PC_G0:
19778 case BFD_RELOC_ARM_LDC_PC_G1:
19779 case BFD_RELOC_ARM_LDC_PC_G2:
19780 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19781 case BFD_RELOC_ARM_ALU_SB_G0:
19782 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19783 case BFD_RELOC_ARM_ALU_SB_G1:
19784 case BFD_RELOC_ARM_ALU_SB_G2:
19785 case BFD_RELOC_ARM_LDR_SB_G0:
19786 case BFD_RELOC_ARM_LDR_SB_G1:
19787 case BFD_RELOC_ARM_LDR_SB_G2:
19788 case BFD_RELOC_ARM_LDRS_SB_G0:
19789 case BFD_RELOC_ARM_LDRS_SB_G1:
19790 case BFD_RELOC_ARM_LDRS_SB_G2:
19791 case BFD_RELOC_ARM_LDC_SB_G0:
19792 case BFD_RELOC_ARM_LDC_SB_G1:
19793 case BFD_RELOC_ARM_LDC_SB_G2:
19794 case BFD_RELOC_ARM_V4BX:
19795 code = fixp->fx_r_type;
19796 break;
19798 case BFD_RELOC_ARM_TLS_GD32:
19799 case BFD_RELOC_ARM_TLS_IE32:
19800 case BFD_RELOC_ARM_TLS_LDM32:
19801 /* BFD will include the symbol's address in the addend.
19802 But we don't want that, so subtract it out again here. */
19803 if (!S_IS_COMMON (fixp->fx_addsy))
19804 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19805 code = fixp->fx_r_type;
19806 break;
19807 #endif
19809 case BFD_RELOC_ARM_IMMEDIATE:
19810 as_bad_where (fixp->fx_file, fixp->fx_line,
19811 _("internal relocation (type: IMMEDIATE) not fixed up"));
19812 return NULL;
19814 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19815 as_bad_where (fixp->fx_file, fixp->fx_line,
19816 _("ADRL used for a symbol not defined in the same file"));
19817 return NULL;
19819 case BFD_RELOC_ARM_OFFSET_IMM:
19820 if (section->use_rela_p)
19822 code = fixp->fx_r_type;
19823 break;
19826 if (fixp->fx_addsy != NULL
19827 && !S_IS_DEFINED (fixp->fx_addsy)
19828 && S_IS_LOCAL (fixp->fx_addsy))
19830 as_bad_where (fixp->fx_file, fixp->fx_line,
19831 _("undefined local label `%s'"),
19832 S_GET_NAME (fixp->fx_addsy));
19833 return NULL;
19836 as_bad_where (fixp->fx_file, fixp->fx_line,
19837 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19838 return NULL;
19840 default:
19842 char * type;
19844 switch (fixp->fx_r_type)
19846 case BFD_RELOC_NONE: type = "NONE"; break;
19847 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19848 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
19849 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
19850 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19851 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19852 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
19853 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
19854 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19855 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19856 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19857 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19858 default: type = _("<unknown>"); break;
19860 as_bad_where (fixp->fx_file, fixp->fx_line,
19861 _("cannot represent %s relocation in this object file format"),
19862 type);
19863 return NULL;
19867 #ifdef OBJ_ELF
19868 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19869 && GOT_symbol
19870 && fixp->fx_addsy == GOT_symbol)
19872 code = BFD_RELOC_ARM_GOTPC;
19873 reloc->addend = fixp->fx_offset = reloc->address;
19875 #endif
19877 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
19879 if (reloc->howto == NULL)
19881 as_bad_where (fixp->fx_file, fixp->fx_line,
19882 _("cannot represent %s relocation in this object file format"),
19883 bfd_get_reloc_code_name (code));
19884 return NULL;
19887 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19888 vtable entry to be used in the relocation's section offset. */
19889 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19890 reloc->address = fixp->fx_offset;
19892 return reloc;
19895 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
19897 void
19898 cons_fix_new_arm (fragS * frag,
19899 int where,
19900 int size,
19901 expressionS * exp)
19903 bfd_reloc_code_real_type type;
19904 int pcrel = 0;
19906 /* Pick a reloc.
19907 FIXME: @@ Should look at CPU word size. */
19908 switch (size)
19910 case 1:
19911 type = BFD_RELOC_8;
19912 break;
19913 case 2:
19914 type = BFD_RELOC_16;
19915 break;
19916 case 4:
19917 default:
19918 type = BFD_RELOC_32;
19919 break;
19920 case 8:
19921 type = BFD_RELOC_64;
19922 break;
19925 #ifdef TE_PE
19926 if (exp->X_op == O_secrel)
19928 exp->X_op = O_symbol;
19929 type = BFD_RELOC_32_SECREL;
19931 #endif
19933 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19936 #if defined OBJ_COFF || defined OBJ_ELF
19937 void
19938 arm_validate_fix (fixS * fixP)
19940 /* If the destination of the branch is a defined symbol which does not have
19941 the THUMB_FUNC attribute, then we must be calling a function which has
19942 the (interfacearm) attribute. We look for the Thumb entry point to that
19943 function and change the branch to refer to that function instead. */
19944 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19945 && fixP->fx_addsy != NULL
19946 && S_IS_DEFINED (fixP->fx_addsy)
19947 && ! THUMB_IS_FUNC (fixP->fx_addsy))
19949 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
19952 #endif
19955 arm_force_relocation (struct fix * fixp)
19957 #if defined (OBJ_COFF) && defined (TE_PE)
19958 if (fixp->fx_r_type == BFD_RELOC_RVA)
19959 return 1;
19960 #endif
19962 /* Resolve these relocations even if the symbol is extern or weak. */
19963 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19964 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
19965 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
19966 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
19967 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19968 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19969 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
19970 return 0;
19972 /* Always leave these relocations for the linker. */
19973 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19974 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19975 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19976 return 1;
19978 /* Always generate relocations against function symbols. */
19979 if (fixp->fx_r_type == BFD_RELOC_32
19980 && fixp->fx_addsy
19981 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19982 return 1;
19984 return generic_force_reloc (fixp);
19987 #if defined (OBJ_ELF) || defined (OBJ_COFF)
19988 /* Relocations against function names must be left unadjusted,
19989 so that the linker can use this information to generate interworking
19990 stubs. The MIPS version of this function
19991 also prevents relocations that are mips-16 specific, but I do not
19992 know why it does this.
19994 FIXME:
19995 There is one other problem that ought to be addressed here, but
19996 which currently is not: Taking the address of a label (rather
19997 than a function) and then later jumping to that address. Such
19998 addresses also ought to have their bottom bit set (assuming that
19999 they reside in Thumb code), but at the moment they will not. */
20001 bfd_boolean
20002 arm_fix_adjustable (fixS * fixP)
20004 if (fixP->fx_addsy == NULL)
20005 return 1;
20007 /* Preserve relocations against symbols with function type. */
20008 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
20009 return 0;
20011 if (THUMB_IS_FUNC (fixP->fx_addsy)
20012 && fixP->fx_subsy == NULL)
20013 return 0;
20015 /* We need the symbol name for the VTABLE entries. */
20016 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
20017 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
20018 return 0;
20020 /* Don't allow symbols to be discarded on GOT related relocs. */
20021 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
20022 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
20023 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
20024 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
20025 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
20026 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
20027 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
20028 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
20029 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
20030 return 0;
20032 /* Similarly for group relocations. */
20033 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
20034 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
20035 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
20036 return 0;
20038 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
20039 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
20040 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20041 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
20042 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
20043 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20044 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
20045 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
20046 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
20047 return 0;
20049 return 1;
20051 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
20053 #ifdef OBJ_ELF
20055 const char *
20056 elf32_arm_target_format (void)
20058 #ifdef TE_SYMBIAN
20059 return (target_big_endian
20060 ? "elf32-bigarm-symbian"
20061 : "elf32-littlearm-symbian");
20062 #elif defined (TE_VXWORKS)
20063 return (target_big_endian
20064 ? "elf32-bigarm-vxworks"
20065 : "elf32-littlearm-vxworks");
20066 #else
20067 if (target_big_endian)
20068 return "elf32-bigarm";
20069 else
20070 return "elf32-littlearm";
20071 #endif
20074 void
20075 armelf_frob_symbol (symbolS * symp,
20076 int * puntp)
20078 elf_frob_symbol (symp, puntp);
20080 #endif
20082 /* MD interface: Finalization. */
20084 /* A good place to do this, although this was probably not intended
20085 for this kind of use. We need to dump the literal pool before
20086 references are made to a null symbol pointer. */
20088 void
20089 arm_cleanup (void)
20091 literal_pool * pool;
20093 for (pool = list_of_pools; pool; pool = pool->next)
20095 /* Put it at the end of the relevant section. */
20096 subseg_set (pool->section, pool->sub_section);
20097 #ifdef OBJ_ELF
20098 arm_elf_change_section ();
20099 #endif
20100 s_ltorg (0);
20104 /* Adjust the symbol table. This marks Thumb symbols as distinct from
20105 ARM ones. */
20107 void
20108 arm_adjust_symtab (void)
20110 #ifdef OBJ_COFF
20111 symbolS * sym;
20113 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
20115 if (ARM_IS_THUMB (sym))
20117 if (THUMB_IS_FUNC (sym))
20119 /* Mark the symbol as a Thumb function. */
20120 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
20121 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
20122 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
20124 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
20125 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
20126 else
20127 as_bad (_("%s: unexpected function type: %d"),
20128 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
20130 else switch (S_GET_STORAGE_CLASS (sym))
20132 case C_EXT:
20133 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
20134 break;
20135 case C_STAT:
20136 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
20137 break;
20138 case C_LABEL:
20139 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
20140 break;
20141 default:
20142 /* Do nothing. */
20143 break;
20147 if (ARM_IS_INTERWORK (sym))
20148 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
20150 #endif
20151 #ifdef OBJ_ELF
20152 symbolS * sym;
20153 char bind;
20155 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
20157 if (ARM_IS_THUMB (sym))
20159 elf_symbol_type * elf_sym;
20161 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
20162 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
20164 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
20165 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
20167 /* If it's a .thumb_func, declare it as so,
20168 otherwise tag label as .code 16. */
20169 if (THUMB_IS_FUNC (sym))
20170 elf_sym->internal_elf_sym.st_info =
20171 ELF_ST_INFO (bind, STT_ARM_TFUNC);
20172 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20173 elf_sym->internal_elf_sym.st_info =
20174 ELF_ST_INFO (bind, STT_ARM_16BIT);
20178 #endif
20181 /* MD interface: Initialization. */
20183 static void
20184 set_constant_flonums (void)
20186 int i;
20188 for (i = 0; i < NUM_FLOAT_VALS; i++)
20189 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
20190 abort ();
20193 /* Auto-select Thumb mode if it's the only available instruction set for the
20194 given architecture. */
20196 static void
20197 autoselect_thumb_from_cpu_variant (void)
20199 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
20200 opcode_select (16);
20203 void
20204 md_begin (void)
20206 unsigned mach;
20207 unsigned int i;
20209 if ( (arm_ops_hsh = hash_new ()) == NULL
20210 || (arm_cond_hsh = hash_new ()) == NULL
20211 || (arm_shift_hsh = hash_new ()) == NULL
20212 || (arm_psr_hsh = hash_new ()) == NULL
20213 || (arm_v7m_psr_hsh = hash_new ()) == NULL
20214 || (arm_reg_hsh = hash_new ()) == NULL
20215 || (arm_reloc_hsh = hash_new ()) == NULL
20216 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
20217 as_fatal (_("virtual memory exhausted"));
20219 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
20220 hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i));
20221 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
20222 hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i));
20223 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
20224 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
20225 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
20226 hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i));
20227 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
20228 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i));
20229 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
20230 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
20231 for (i = 0;
20232 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
20233 i++)
20234 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
20235 (void *) (barrier_opt_names + i));
20236 #ifdef OBJ_ELF
20237 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
20238 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
20239 #endif
20241 set_constant_flonums ();
20243 /* Set the cpu variant based on the command-line options. We prefer
20244 -mcpu= over -march= if both are set (as for GCC); and we prefer
20245 -mfpu= over any other way of setting the floating point unit.
20246 Use of legacy options with new options are faulted. */
20247 if (legacy_cpu)
20249 if (mcpu_cpu_opt || march_cpu_opt)
20250 as_bad (_("use of old and new-style options to set CPU type"));
20252 mcpu_cpu_opt = legacy_cpu;
20254 else if (!mcpu_cpu_opt)
20255 mcpu_cpu_opt = march_cpu_opt;
20257 if (legacy_fpu)
20259 if (mfpu_opt)
20260 as_bad (_("use of old and new-style options to set FPU type"));
20262 mfpu_opt = legacy_fpu;
20264 else if (!mfpu_opt)
20266 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
20267 /* Some environments specify a default FPU. If they don't, infer it
20268 from the processor. */
20269 if (mcpu_fpu_opt)
20270 mfpu_opt = mcpu_fpu_opt;
20271 else
20272 mfpu_opt = march_fpu_opt;
20273 #else
20274 mfpu_opt = &fpu_default;
20275 #endif
20278 if (!mfpu_opt)
20280 if (mcpu_cpu_opt != NULL)
20281 mfpu_opt = &fpu_default;
20282 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
20283 mfpu_opt = &fpu_arch_vfp_v2;
20284 else
20285 mfpu_opt = &fpu_arch_fpa;
20288 #ifdef CPU_DEFAULT
20289 if (!mcpu_cpu_opt)
20291 mcpu_cpu_opt = &cpu_default;
20292 selected_cpu = cpu_default;
20294 #else
20295 if (mcpu_cpu_opt)
20296 selected_cpu = *mcpu_cpu_opt;
20297 else
20298 mcpu_cpu_opt = &arm_arch_any;
20299 #endif
20301 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20303 autoselect_thumb_from_cpu_variant ();
20305 arm_arch_used = thumb_arch_used = arm_arch_none;
20307 #if defined OBJ_COFF || defined OBJ_ELF
20309 unsigned int flags = 0;
20311 #if defined OBJ_ELF
20312 flags = meabi_flags;
20314 switch (meabi_flags)
20316 case EF_ARM_EABI_UNKNOWN:
20317 #endif
20318 /* Set the flags in the private structure. */
20319 if (uses_apcs_26) flags |= F_APCS26;
20320 if (support_interwork) flags |= F_INTERWORK;
20321 if (uses_apcs_float) flags |= F_APCS_FLOAT;
20322 if (pic_code) flags |= F_PIC;
20323 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
20324 flags |= F_SOFT_FLOAT;
20326 switch (mfloat_abi_opt)
20328 case ARM_FLOAT_ABI_SOFT:
20329 case ARM_FLOAT_ABI_SOFTFP:
20330 flags |= F_SOFT_FLOAT;
20331 break;
20333 case ARM_FLOAT_ABI_HARD:
20334 if (flags & F_SOFT_FLOAT)
20335 as_bad (_("hard-float conflicts with specified fpu"));
20336 break;
20339 /* Using pure-endian doubles (even if soft-float). */
20340 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
20341 flags |= F_VFP_FLOAT;
20343 #if defined OBJ_ELF
20344 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
20345 flags |= EF_ARM_MAVERICK_FLOAT;
20346 break;
20348 case EF_ARM_EABI_VER4:
20349 case EF_ARM_EABI_VER5:
20350 /* No additional flags to set. */
20351 break;
20353 default:
20354 abort ();
20356 #endif
20357 bfd_set_private_flags (stdoutput, flags);
20359 /* We have run out flags in the COFF header to encode the
20360 status of ATPCS support, so instead we create a dummy,
20361 empty, debug section called .arm.atpcs. */
20362 if (atpcs)
20364 asection * sec;
20366 sec = bfd_make_section (stdoutput, ".arm.atpcs");
20368 if (sec != NULL)
20370 bfd_set_section_flags
20371 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
20372 bfd_set_section_size (stdoutput, sec, 0);
20373 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
20377 #endif
20379 /* Record the CPU type as well. */
20380 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
20381 mach = bfd_mach_arm_iWMMXt2;
20382 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
20383 mach = bfd_mach_arm_iWMMXt;
20384 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
20385 mach = bfd_mach_arm_XScale;
20386 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
20387 mach = bfd_mach_arm_ep9312;
20388 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
20389 mach = bfd_mach_arm_5TE;
20390 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
20392 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
20393 mach = bfd_mach_arm_5T;
20394 else
20395 mach = bfd_mach_arm_5;
20397 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
20399 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
20400 mach = bfd_mach_arm_4T;
20401 else
20402 mach = bfd_mach_arm_4;
20404 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
20405 mach = bfd_mach_arm_3M;
20406 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
20407 mach = bfd_mach_arm_3;
20408 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
20409 mach = bfd_mach_arm_2a;
20410 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
20411 mach = bfd_mach_arm_2;
20412 else
20413 mach = bfd_mach_arm_unknown;
20415 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
20418 /* Command line processing. */
20420 /* md_parse_option
20421 Invocation line includes a switch not recognized by the base assembler.
20422 See if it's a processor-specific option.
20424 This routine is somewhat complicated by the need for backwards
20425 compatibility (since older releases of gcc can't be changed).
20426 The new options try to make the interface as compatible as
20427 possible with GCC.
20429 New options (supported) are:
20431 -mcpu=<cpu name> Assemble for selected processor
20432 -march=<architecture name> Assemble for selected architecture
20433 -mfpu=<fpu architecture> Assemble for selected FPU.
20434 -EB/-mbig-endian Big-endian
20435 -EL/-mlittle-endian Little-endian
20436 -k Generate PIC code
20437 -mthumb Start in Thumb mode
20438 -mthumb-interwork Code supports ARM/Thumb interworking
20440 -m[no-]warn-deprecated Warn about deprecated features
20442 For now we will also provide support for:
20444 -mapcs-32 32-bit Program counter
20445 -mapcs-26 26-bit Program counter
20446 -macps-float Floats passed in FP registers
20447 -mapcs-reentrant Reentrant code
20448 -matpcs
20449 (sometime these will probably be replaced with -mapcs=<list of options>
20450 and -matpcs=<list of options>)
20452 The remaining options are only supported for back-wards compatibility.
20453 Cpu variants, the arm part is optional:
20454 -m[arm]1 Currently not supported.
20455 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
20456 -m[arm]3 Arm 3 processor
20457 -m[arm]6[xx], Arm 6 processors
20458 -m[arm]7[xx][t][[d]m] Arm 7 processors
20459 -m[arm]8[10] Arm 8 processors
20460 -m[arm]9[20][tdmi] Arm 9 processors
20461 -mstrongarm[110[0]] StrongARM processors
20462 -mxscale XScale processors
20463 -m[arm]v[2345[t[e]]] Arm architectures
20464 -mall All (except the ARM1)
20465 FP variants:
20466 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
20467 -mfpe-old (No float load/store multiples)
20468 -mvfpxd VFP Single precision
20469 -mvfp All VFP
20470 -mno-fpu Disable all floating point instructions
20472 The following CPU names are recognized:
20473 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
20474 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
20475 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
20476 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
20477 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
20478 arm10t arm10e, arm1020t, arm1020e, arm10200e,
20479 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
20483 const char * md_shortopts = "m:k";
20485 #ifdef ARM_BI_ENDIAN
20486 #define OPTION_EB (OPTION_MD_BASE + 0)
20487 #define OPTION_EL (OPTION_MD_BASE + 1)
20488 #else
20489 #if TARGET_BYTES_BIG_ENDIAN
20490 #define OPTION_EB (OPTION_MD_BASE + 0)
20491 #else
20492 #define OPTION_EL (OPTION_MD_BASE + 1)
20493 #endif
20494 #endif
20495 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
20497 struct option md_longopts[] =
20499 #ifdef OPTION_EB
20500 {"EB", no_argument, NULL, OPTION_EB},
20501 #endif
20502 #ifdef OPTION_EL
20503 {"EL", no_argument, NULL, OPTION_EL},
20504 #endif
20505 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
20506 {NULL, no_argument, NULL, 0}
20509 size_t md_longopts_size = sizeof (md_longopts);
20511 struct arm_option_table
20513 char *option; /* Option name to match. */
20514 char *help; /* Help information. */
20515 int *var; /* Variable to change. */
20516 int value; /* What to change it to. */
20517 char *deprecated; /* If non-null, print this message. */
20520 struct arm_option_table arm_opts[] =
20522 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
20523 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
20524 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
20525 &support_interwork, 1, NULL},
20526 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
20527 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
20528 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
20529 1, NULL},
20530 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
20531 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
20532 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
20533 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
20534 NULL},
20536 /* These are recognized by the assembler, but have no affect on code. */
20537 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
20538 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
20540 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
20541 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
20542 &warn_on_deprecated, 0, NULL},
20543 {NULL, NULL, NULL, 0, NULL}
20546 struct arm_legacy_option_table
20548 char *option; /* Option name to match. */
20549 const arm_feature_set **var; /* Variable to change. */
20550 const arm_feature_set value; /* What to change it to. */
20551 char *deprecated; /* If non-null, print this message. */
20554 const struct arm_legacy_option_table arm_legacy_opts[] =
20556 /* DON'T add any new processors to this list -- we want the whole list
20557 to go away... Add them to the processors table instead. */
20558 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
20559 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
20560 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
20561 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
20562 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
20563 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
20564 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
20565 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
20566 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
20567 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
20568 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
20569 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
20570 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
20571 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
20572 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
20573 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
20574 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
20575 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
20576 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
20577 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
20578 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
20579 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
20580 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
20581 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
20582 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
20583 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
20584 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
20585 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
20586 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
20587 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
20588 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
20589 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
20590 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
20591 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
20592 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
20593 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
20594 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
20595 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
20596 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
20597 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
20598 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
20599 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
20600 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
20601 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
20602 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
20603 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
20604 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20605 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20606 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20607 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20608 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
20609 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
20610 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
20611 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
20612 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
20613 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
20614 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
20615 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
20616 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
20617 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
20618 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
20619 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
20620 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
20621 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
20622 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
20623 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
20624 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
20625 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
20626 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
20627 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
20628 N_("use -mcpu=strongarm110")},
20629 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
20630 N_("use -mcpu=strongarm1100")},
20631 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
20632 N_("use -mcpu=strongarm1110")},
20633 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
20634 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
20635 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
20637 /* Architecture variants -- don't add any more to this list either. */
20638 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20639 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20640 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20641 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20642 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20643 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20644 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20645 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20646 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20647 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20648 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20649 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20650 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20651 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20652 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20653 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20654 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20655 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20657 /* Floating point variants -- don't add any more to this list either. */
20658 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20659 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20660 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20661 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
20662 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
20664 {NULL, NULL, ARM_ARCH_NONE, NULL}
20667 struct arm_cpu_option_table
20669 char *name;
20670 const arm_feature_set value;
20671 /* For some CPUs we assume an FPU unless the user explicitly sets
20672 -mfpu=... */
20673 const arm_feature_set default_fpu;
20674 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20675 case. */
20676 const char *canonical_name;
20679 /* This list should, at a minimum, contain all the cpu names
20680 recognized by GCC. */
20681 static const struct arm_cpu_option_table arm_cpus[] =
20683 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20684 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20685 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20686 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20687 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20688 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20689 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20690 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20691 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20692 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20693 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20694 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20695 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20696 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20697 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20698 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20699 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20700 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20701 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20702 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20703 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20704 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20705 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20706 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20707 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20708 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20709 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20710 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20711 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20712 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20713 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20714 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20715 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20716 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20717 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20718 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20719 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20720 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20721 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20722 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20723 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20724 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20725 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20726 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20727 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20728 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20729 /* For V5 or later processors we default to using VFP; but the user
20730 should really set the FPU type explicitly. */
20731 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20732 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20733 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20734 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20735 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20736 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20737 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20738 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20739 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20740 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20741 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20742 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20743 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20744 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20745 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20746 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20747 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20748 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20749 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20750 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20751 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20752 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
20753 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20754 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20755 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20756 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20757 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20758 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20759 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20760 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20761 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20762 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20763 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
20764 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20765 | FPU_NEON_EXT_V1),
20766 NULL},
20767 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20768 | FPU_NEON_EXT_V1),
20769 NULL},
20770 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20771 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
20772 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
20773 /* ??? XSCALE is really an architecture. */
20774 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20775 /* ??? iwmmxt is not a processor. */
20776 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
20777 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
20778 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20779 /* Maverick */
20780 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20781 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
20784 struct arm_arch_option_table
20786 char *name;
20787 const arm_feature_set value;
20788 const arm_feature_set default_fpu;
20791 /* This list should, at a minimum, contain all the architecture names
20792 recognized by GCC. */
20793 static const struct arm_arch_option_table arm_archs[] =
20795 {"all", ARM_ANY, FPU_ARCH_FPA},
20796 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20797 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20798 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20799 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20800 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20801 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20802 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20803 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20804 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20805 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20806 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20807 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20808 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20809 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20810 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20811 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20812 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20813 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20814 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20815 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20816 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20817 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20818 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20819 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20820 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
20821 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
20822 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
20823 /* The official spelling of the ARMv7 profile variants is the dashed form.
20824 Accept the non-dashed form for compatibility with old toolchains. */
20825 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20826 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20827 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20828 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20829 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20830 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20831 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20832 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
20833 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
20834 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
20837 /* ISA extensions in the co-processor space. */
20838 struct arm_option_cpu_value_table
20840 char *name;
20841 const arm_feature_set value;
20844 static const struct arm_option_cpu_value_table arm_extensions[] =
20846 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20847 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20848 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
20849 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
20850 {NULL, ARM_ARCH_NONE}
20853 /* This list should, at a minimum, contain all the fpu names
20854 recognized by GCC. */
20855 static const struct arm_option_cpu_value_table arm_fpus[] =
20857 {"softfpa", FPU_NONE},
20858 {"fpe", FPU_ARCH_FPE},
20859 {"fpe2", FPU_ARCH_FPE},
20860 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20861 {"fpa", FPU_ARCH_FPA},
20862 {"fpa10", FPU_ARCH_FPA},
20863 {"fpa11", FPU_ARCH_FPA},
20864 {"arm7500fe", FPU_ARCH_FPA},
20865 {"softvfp", FPU_ARCH_VFP},
20866 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20867 {"vfp", FPU_ARCH_VFP_V2},
20868 {"vfp9", FPU_ARCH_VFP_V2},
20869 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
20870 {"vfp10", FPU_ARCH_VFP_V2},
20871 {"vfp10-r0", FPU_ARCH_VFP_V1},
20872 {"vfpxd", FPU_ARCH_VFP_V1xD},
20873 {"vfpv2", FPU_ARCH_VFP_V2},
20874 {"vfpv3", FPU_ARCH_VFP_V3},
20875 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
20876 {"arm1020t", FPU_ARCH_VFP_V1},
20877 {"arm1020e", FPU_ARCH_VFP_V2},
20878 {"arm1136jfs", FPU_ARCH_VFP_V2},
20879 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20880 {"maverick", FPU_ARCH_MAVERICK},
20881 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
20882 {"neon-fp16", FPU_ARCH_NEON_FP16},
20883 {NULL, ARM_ARCH_NONE}
20886 struct arm_option_value_table
20888 char *name;
20889 long value;
20892 static const struct arm_option_value_table arm_float_abis[] =
20894 {"hard", ARM_FLOAT_ABI_HARD},
20895 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20896 {"soft", ARM_FLOAT_ABI_SOFT},
20897 {NULL, 0}
20900 #ifdef OBJ_ELF
20901 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
20902 static const struct arm_option_value_table arm_eabis[] =
20904 {"gnu", EF_ARM_EABI_UNKNOWN},
20905 {"4", EF_ARM_EABI_VER4},
20906 {"5", EF_ARM_EABI_VER5},
20907 {NULL, 0}
20909 #endif
20911 struct arm_long_option_table
20913 char * option; /* Substring to match. */
20914 char * help; /* Help information. */
20915 int (* func) (char * subopt); /* Function to decode sub-option. */
20916 char * deprecated; /* If non-null, print this message. */
20919 static int
20920 arm_parse_extension (char * str, const arm_feature_set **opt_p)
20922 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20924 /* Copy the feature set, so that we can modify it. */
20925 *ext_set = **opt_p;
20926 *opt_p = ext_set;
20928 while (str != NULL && *str != 0)
20930 const struct arm_option_cpu_value_table * opt;
20931 char * ext;
20932 int optlen;
20934 if (*str != '+')
20936 as_bad (_("invalid architectural extension"));
20937 return 0;
20940 str++;
20941 ext = strchr (str, '+');
20943 if (ext != NULL)
20944 optlen = ext - str;
20945 else
20946 optlen = strlen (str);
20948 if (optlen == 0)
20950 as_bad (_("missing architectural extension"));
20951 return 0;
20954 for (opt = arm_extensions; opt->name != NULL; opt++)
20955 if (strncmp (opt->name, str, optlen) == 0)
20957 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
20958 break;
20961 if (opt->name == NULL)
20963 as_bad (_("unknown architectural extension `%s'"), str);
20964 return 0;
20967 str = ext;
20970 return 1;
20973 static int
20974 arm_parse_cpu (char * str)
20976 const struct arm_cpu_option_table * opt;
20977 char * ext = strchr (str, '+');
20978 int optlen;
20980 if (ext != NULL)
20981 optlen = ext - str;
20982 else
20983 optlen = strlen (str);
20985 if (optlen == 0)
20987 as_bad (_("missing cpu name `%s'"), str);
20988 return 0;
20991 for (opt = arm_cpus; opt->name != NULL; opt++)
20992 if (strncmp (opt->name, str, optlen) == 0)
20994 mcpu_cpu_opt = &opt->value;
20995 mcpu_fpu_opt = &opt->default_fpu;
20996 if (opt->canonical_name)
20997 strcpy (selected_cpu_name, opt->canonical_name);
20998 else
21000 int i;
21001 for (i = 0; i < optlen; i++)
21002 selected_cpu_name[i] = TOUPPER (opt->name[i]);
21003 selected_cpu_name[i] = 0;
21006 if (ext != NULL)
21007 return arm_parse_extension (ext, &mcpu_cpu_opt);
21009 return 1;
21012 as_bad (_("unknown cpu `%s'"), str);
21013 return 0;
21016 static int
21017 arm_parse_arch (char * str)
21019 const struct arm_arch_option_table *opt;
21020 char *ext = strchr (str, '+');
21021 int optlen;
21023 if (ext != NULL)
21024 optlen = ext - str;
21025 else
21026 optlen = strlen (str);
21028 if (optlen == 0)
21030 as_bad (_("missing architecture name `%s'"), str);
21031 return 0;
21034 for (opt = arm_archs; opt->name != NULL; opt++)
21035 if (streq (opt->name, str))
21037 march_cpu_opt = &opt->value;
21038 march_fpu_opt = &opt->default_fpu;
21039 strcpy (selected_cpu_name, opt->name);
21041 if (ext != NULL)
21042 return arm_parse_extension (ext, &march_cpu_opt);
21044 return 1;
21047 as_bad (_("unknown architecture `%s'\n"), str);
21048 return 0;
21051 static int
21052 arm_parse_fpu (char * str)
21054 const struct arm_option_cpu_value_table * opt;
21056 for (opt = arm_fpus; opt->name != NULL; opt++)
21057 if (streq (opt->name, str))
21059 mfpu_opt = &opt->value;
21060 return 1;
21063 as_bad (_("unknown floating point format `%s'\n"), str);
21064 return 0;
21067 static int
21068 arm_parse_float_abi (char * str)
21070 const struct arm_option_value_table * opt;
21072 for (opt = arm_float_abis; opt->name != NULL; opt++)
21073 if (streq (opt->name, str))
21075 mfloat_abi_opt = opt->value;
21076 return 1;
21079 as_bad (_("unknown floating point abi `%s'\n"), str);
21080 return 0;
21083 #ifdef OBJ_ELF
21084 static int
21085 arm_parse_eabi (char * str)
21087 const struct arm_option_value_table *opt;
21089 for (opt = arm_eabis; opt->name != NULL; opt++)
21090 if (streq (opt->name, str))
21092 meabi_flags = opt->value;
21093 return 1;
21095 as_bad (_("unknown EABI `%s'\n"), str);
21096 return 0;
21098 #endif
21100 struct arm_long_option_table arm_long_opts[] =
21102 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
21103 arm_parse_cpu, NULL},
21104 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
21105 arm_parse_arch, NULL},
21106 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
21107 arm_parse_fpu, NULL},
21108 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
21109 arm_parse_float_abi, NULL},
21110 #ifdef OBJ_ELF
21111 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
21112 arm_parse_eabi, NULL},
21113 #endif
21114 {NULL, NULL, 0, NULL}
21118 md_parse_option (int c, char * arg)
21120 struct arm_option_table *opt;
21121 const struct arm_legacy_option_table *fopt;
21122 struct arm_long_option_table *lopt;
21124 switch (c)
21126 #ifdef OPTION_EB
21127 case OPTION_EB:
21128 target_big_endian = 1;
21129 break;
21130 #endif
21132 #ifdef OPTION_EL
21133 case OPTION_EL:
21134 target_big_endian = 0;
21135 break;
21136 #endif
21138 case OPTION_FIX_V4BX:
21139 fix_v4bx = TRUE;
21140 break;
21142 case 'a':
21143 /* Listing option. Just ignore these, we don't support additional
21144 ones. */
21145 return 0;
21147 default:
21148 for (opt = arm_opts; opt->option != NULL; opt++)
21150 if (c == opt->option[0]
21151 && ((arg == NULL && opt->option[1] == 0)
21152 || streq (arg, opt->option + 1)))
21154 /* If the option is deprecated, tell the user. */
21155 if (warn_on_deprecated && opt->deprecated != NULL)
21156 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21157 arg ? arg : "", _(opt->deprecated));
21159 if (opt->var != NULL)
21160 *opt->var = opt->value;
21162 return 1;
21166 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
21168 if (c == fopt->option[0]
21169 && ((arg == NULL && fopt->option[1] == 0)
21170 || streq (arg, fopt->option + 1)))
21172 /* If the option is deprecated, tell the user. */
21173 if (warn_on_deprecated && fopt->deprecated != NULL)
21174 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21175 arg ? arg : "", _(fopt->deprecated));
21177 if (fopt->var != NULL)
21178 *fopt->var = &fopt->value;
21180 return 1;
21184 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21186 /* These options are expected to have an argument. */
21187 if (c == lopt->option[0]
21188 && arg != NULL
21189 && strncmp (arg, lopt->option + 1,
21190 strlen (lopt->option + 1)) == 0)
21192 /* If the option is deprecated, tell the user. */
21193 if (warn_on_deprecated && lopt->deprecated != NULL)
21194 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
21195 _(lopt->deprecated));
21197 /* Call the sup-option parser. */
21198 return lopt->func (arg + strlen (lopt->option) - 1);
21202 return 0;
21205 return 1;
21208 void
21209 md_show_usage (FILE * fp)
21211 struct arm_option_table *opt;
21212 struct arm_long_option_table *lopt;
21214 fprintf (fp, _(" ARM-specific assembler options:\n"));
21216 for (opt = arm_opts; opt->option != NULL; opt++)
21217 if (opt->help != NULL)
21218 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
21220 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21221 if (lopt->help != NULL)
21222 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
21224 #ifdef OPTION_EB
21225 fprintf (fp, _("\
21226 -EB assemble code for a big-endian cpu\n"));
21227 #endif
21229 #ifdef OPTION_EL
21230 fprintf (fp, _("\
21231 -EL assemble code for a little-endian cpu\n"));
21232 #endif
21234 fprintf (fp, _("\
21235 --fix-v4bx Allow BX in ARMv4 code\n"));
21239 #ifdef OBJ_ELF
21240 typedef struct
21242 int val;
21243 arm_feature_set flags;
21244 } cpu_arch_ver_table;
21246 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
21247 least features first. */
21248 static const cpu_arch_ver_table cpu_arch_ver[] =
21250 {1, ARM_ARCH_V4},
21251 {2, ARM_ARCH_V4T},
21252 {3, ARM_ARCH_V5},
21253 {3, ARM_ARCH_V5T},
21254 {4, ARM_ARCH_V5TE},
21255 {5, ARM_ARCH_V5TEJ},
21256 {6, ARM_ARCH_V6},
21257 {7, ARM_ARCH_V6Z},
21258 {9, ARM_ARCH_V6K},
21259 {11, ARM_ARCH_V6M},
21260 {8, ARM_ARCH_V6T2},
21261 {10, ARM_ARCH_V7A},
21262 {10, ARM_ARCH_V7R},
21263 {10, ARM_ARCH_V7M},
21264 {0, ARM_ARCH_NONE}
21267 /* Set an attribute if it has not already been set by the user. */
21268 static void
21269 aeabi_set_attribute_int (int tag, int value)
21271 if (tag < 1
21272 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21273 || !attributes_set_explicitly[tag])
21274 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
21277 static void
21278 aeabi_set_attribute_string (int tag, const char *value)
21280 if (tag < 1
21281 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21282 || !attributes_set_explicitly[tag])
21283 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
21286 /* Set the public EABI object attributes. */
21287 static void
21288 aeabi_set_public_attributes (void)
21290 int arch;
21291 arm_feature_set flags;
21292 arm_feature_set tmp;
21293 const cpu_arch_ver_table *p;
21295 /* Choose the architecture based on the capabilities of the requested cpu
21296 (if any) and/or the instructions actually used. */
21297 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
21298 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
21299 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
21300 /*Allow the user to override the reported architecture. */
21301 if (object_arch)
21303 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
21304 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
21307 tmp = flags;
21308 arch = 0;
21309 for (p = cpu_arch_ver; p->val; p++)
21311 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
21313 arch = p->val;
21314 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
21318 /* Tag_CPU_name. */
21319 if (selected_cpu_name[0])
21321 char *p;
21323 p = selected_cpu_name;
21324 if (strncmp (p, "armv", 4) == 0)
21326 int i;
21328 p += 4;
21329 for (i = 0; p[i]; i++)
21330 p[i] = TOUPPER (p[i]);
21332 aeabi_set_attribute_string (Tag_CPU_name, p);
21334 /* Tag_CPU_arch. */
21335 aeabi_set_attribute_int (Tag_CPU_arch, arch);
21336 /* Tag_CPU_arch_profile. */
21337 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
21338 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
21339 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
21340 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
21341 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
21342 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
21343 /* Tag_ARM_ISA_use. */
21344 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
21345 || arch == 0)
21346 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
21347 /* Tag_THUMB_ISA_use. */
21348 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
21349 || arch == 0)
21350 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
21351 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
21352 /* Tag_VFP_arch. */
21353 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
21354 aeabi_set_attribute_int (Tag_VFP_arch, 3);
21355 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3))
21356 aeabi_set_attribute_int (Tag_VFP_arch, 4);
21357 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
21358 aeabi_set_attribute_int (Tag_VFP_arch, 2);
21359 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
21360 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
21361 aeabi_set_attribute_int (Tag_VFP_arch, 1);
21362 /* Tag_WMMX_arch. */
21363 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
21364 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
21365 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
21366 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
21367 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
21368 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
21369 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
21370 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
21371 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16))
21372 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
21375 /* Add the default contents for the .ARM.attributes section. */
21376 void
21377 arm_md_end (void)
21379 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
21380 return;
21382 aeabi_set_public_attributes ();
21384 #endif /* OBJ_ELF */
21387 /* Parse a .cpu directive. */
21389 static void
21390 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
21392 const struct arm_cpu_option_table *opt;
21393 char *name;
21394 char saved_char;
21396 name = input_line_pointer;
21397 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
21398 input_line_pointer++;
21399 saved_char = *input_line_pointer;
21400 *input_line_pointer = 0;
21402 /* Skip the first "all" entry. */
21403 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
21404 if (streq (opt->name, name))
21406 mcpu_cpu_opt = &opt->value;
21407 selected_cpu = opt->value;
21408 if (opt->canonical_name)
21409 strcpy (selected_cpu_name, opt->canonical_name);
21410 else
21412 int i;
21413 for (i = 0; opt->name[i]; i++)
21414 selected_cpu_name[i] = TOUPPER (opt->name[i]);
21415 selected_cpu_name[i] = 0;
21417 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
21418 *input_line_pointer = saved_char;
21419 demand_empty_rest_of_line ();
21420 return;
21422 as_bad (_("unknown cpu `%s'"), name);
21423 *input_line_pointer = saved_char;
21424 ignore_rest_of_line ();
21428 /* Parse a .arch directive. */
21430 static void
21431 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
21433 const struct arm_arch_option_table *opt;
21434 char saved_char;
21435 char *name;
21437 name = input_line_pointer;
21438 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
21439 input_line_pointer++;
21440 saved_char = *input_line_pointer;
21441 *input_line_pointer = 0;
21443 /* Skip the first "all" entry. */
21444 for (opt = arm_archs + 1; opt->name != NULL; opt++)
21445 if (streq (opt->name, name))
21447 mcpu_cpu_opt = &opt->value;
21448 selected_cpu = opt->value;
21449 strcpy (selected_cpu_name, opt->name);
21450 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
21451 *input_line_pointer = saved_char;
21452 demand_empty_rest_of_line ();
21453 return;
21456 as_bad (_("unknown architecture `%s'\n"), name);
21457 *input_line_pointer = saved_char;
21458 ignore_rest_of_line ();
21462 /* Parse a .object_arch directive. */
21464 static void
21465 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
21467 const struct arm_arch_option_table *opt;
21468 char saved_char;
21469 char *name;
21471 name = input_line_pointer;
21472 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
21473 input_line_pointer++;
21474 saved_char = *input_line_pointer;
21475 *input_line_pointer = 0;
21477 /* Skip the first "all" entry. */
21478 for (opt = arm_archs + 1; opt->name != NULL; opt++)
21479 if (streq (opt->name, name))
21481 object_arch = &opt->value;
21482 *input_line_pointer = saved_char;
21483 demand_empty_rest_of_line ();
21484 return;
21487 as_bad (_("unknown architecture `%s'\n"), name);
21488 *input_line_pointer = saved_char;
21489 ignore_rest_of_line ();
21492 /* Parse a .fpu directive. */
21494 static void
21495 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
21497 const struct arm_option_cpu_value_table *opt;
21498 char saved_char;
21499 char *name;
21501 name = input_line_pointer;
21502 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
21503 input_line_pointer++;
21504 saved_char = *input_line_pointer;
21505 *input_line_pointer = 0;
21507 for (opt = arm_fpus; opt->name != NULL; opt++)
21508 if (streq (opt->name, name))
21510 mfpu_opt = &opt->value;
21511 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
21512 *input_line_pointer = saved_char;
21513 demand_empty_rest_of_line ();
21514 return;
21517 as_bad (_("unknown floating point format `%s'\n"), name);
21518 *input_line_pointer = saved_char;
21519 ignore_rest_of_line ();
21522 /* Copy symbol information. */
21524 void
21525 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
21527 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
21530 #ifdef OBJ_ELF
21531 /* Given a symbolic attribute NAME, return the proper integer value.
21532 Returns -1 if the attribute is not known. */
21535 arm_convert_symbolic_attribute (const char *name)
21537 static const struct
21539 const char * name;
21540 const int tag;
21542 attribute_table[] =
21544 /* When you modify this table you should
21545 also modify the list in doc/c-arm.texi. */
21546 #define T(tag) {#tag, tag}
21547 T (Tag_CPU_raw_name),
21548 T (Tag_CPU_name),
21549 T (Tag_CPU_arch),
21550 T (Tag_CPU_arch_profile),
21551 T (Tag_ARM_ISA_use),
21552 T (Tag_THUMB_ISA_use),
21553 T (Tag_VFP_arch),
21554 T (Tag_WMMX_arch),
21555 T (Tag_Advanced_SIMD_arch),
21556 T (Tag_PCS_config),
21557 T (Tag_ABI_PCS_R9_use),
21558 T (Tag_ABI_PCS_RW_data),
21559 T (Tag_ABI_PCS_RO_data),
21560 T (Tag_ABI_PCS_GOT_use),
21561 T (Tag_ABI_PCS_wchar_t),
21562 T (Tag_ABI_FP_rounding),
21563 T (Tag_ABI_FP_denormal),
21564 T (Tag_ABI_FP_exceptions),
21565 T (Tag_ABI_FP_user_exceptions),
21566 T (Tag_ABI_FP_number_model),
21567 T (Tag_ABI_align8_needed),
21568 T (Tag_ABI_align8_preserved),
21569 T (Tag_ABI_enum_size),
21570 T (Tag_ABI_HardFP_use),
21571 T (Tag_ABI_VFP_args),
21572 T (Tag_ABI_WMMX_args),
21573 T (Tag_ABI_optimization_goals),
21574 T (Tag_ABI_FP_optimization_goals),
21575 T (Tag_compatibility),
21576 T (Tag_CPU_unaligned_access),
21577 T (Tag_VFP_HP_extension),
21578 T (Tag_ABI_FP_16bit_format),
21579 T (Tag_nodefaults),
21580 T (Tag_also_compatible_with),
21581 T (Tag_conformance),
21582 T (Tag_T2EE_use),
21583 T (Tag_Virtualization_use),
21584 T (Tag_MPextension_use)
21585 #undef T
21587 unsigned int i;
21589 if (name == NULL)
21590 return -1;
21592 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
21593 if (strcmp (name, attribute_table[i].name) == 0)
21594 return attribute_table[i].tag;
21596 return -1;
21598 #endif /* OBJ_ELF */