2008-03-09 Paul Brook <paul@codesourcery.com>
[binutils.git] / gas / config / tc-arm.c
blob59a1d77d552d69844c409b27779da29b6bff9f0c
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
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 #define WARN_DEPRECATED 1
47 #ifdef OBJ_ELF
48 /* Must be at least the size of the largest unwind opcode (currently two). */
49 #define ARM_OPCODE_CHUNK_SIZE 8
51 /* This structure holds the unwinding state. */
53 static struct
55 symbolS * proc_start;
56 symbolS * table_entry;
57 symbolS * personality_routine;
58 int personality_index;
59 /* The segment containing the function. */
60 segT saved_seg;
61 subsegT saved_subseg;
62 /* Opcodes generated from this function. */
63 unsigned char * opcodes;
64 int opcode_count;
65 int opcode_alloc;
66 /* The number of bytes pushed to the stack. */
67 offsetT frame_size;
68 /* We don't add stack adjustment opcodes immediately so that we can merge
69 multiple adjustments. We can also omit the final adjustment
70 when using a frame pointer. */
71 offsetT pending_offset;
72 /* These two fields are set by both unwind_movsp and unwind_setfp. They
73 hold the reg+offset to use when restoring sp from a frame pointer. */
74 offsetT fp_offset;
75 int fp_reg;
76 /* Nonzero if an unwind_setfp directive has been seen. */
77 unsigned fp_used:1;
78 /* Nonzero if the last opcode restores sp from fp_reg. */
79 unsigned sp_restored:1;
80 } unwind;
82 /* Bit N indicates that an R_ARM_NONE relocation has been output for
83 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
84 emitted only once per section, to save unnecessary bloat. */
85 static unsigned int marked_pr_dependency = 0;
87 #endif /* OBJ_ELF */
89 /* Results from operand parsing worker functions. */
91 typedef enum
93 PARSE_OPERAND_SUCCESS,
94 PARSE_OPERAND_FAIL,
95 PARSE_OPERAND_FAIL_NO_BACKTRACK
96 } parse_operand_result;
98 enum arm_float_abi
100 ARM_FLOAT_ABI_HARD,
101 ARM_FLOAT_ABI_SOFTFP,
102 ARM_FLOAT_ABI_SOFT
105 /* Types of processor to assemble for. */
106 #ifndef CPU_DEFAULT
107 #if defined __XSCALE__
108 #define CPU_DEFAULT ARM_ARCH_XSCALE
109 #else
110 #if defined __thumb__
111 #define CPU_DEFAULT ARM_ARCH_V5T
112 #endif
113 #endif
114 #endif
116 #ifndef FPU_DEFAULT
117 # ifdef TE_LINUX
118 # define FPU_DEFAULT FPU_ARCH_FPA
119 # elif defined (TE_NetBSD)
120 # ifdef OBJ_ELF
121 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
122 # else
123 /* Legacy a.out format. */
124 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
125 # endif
126 # elif defined (TE_VXWORKS)
127 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
128 # else
129 /* For backwards compatibility, default to FPA. */
130 # define FPU_DEFAULT FPU_ARCH_FPA
131 # endif
132 #endif /* ifndef FPU_DEFAULT */
134 #define streq(a, b) (strcmp (a, b) == 0)
136 static arm_feature_set cpu_variant;
137 static arm_feature_set arm_arch_used;
138 static arm_feature_set thumb_arch_used;
140 /* Flags stored in private area of BFD structure. */
141 static int uses_apcs_26 = FALSE;
142 static int atpcs = FALSE;
143 static int support_interwork = FALSE;
144 static int uses_apcs_float = FALSE;
145 static int pic_code = FALSE;
146 static int fix_v4bx = FALSE;
148 /* Variables that we set while parsing command-line options. Once all
149 options have been read we re-process these values to set the real
150 assembly flags. */
151 static const arm_feature_set *legacy_cpu = NULL;
152 static const arm_feature_set *legacy_fpu = NULL;
154 static const arm_feature_set *mcpu_cpu_opt = NULL;
155 static const arm_feature_set *mcpu_fpu_opt = NULL;
156 static const arm_feature_set *march_cpu_opt = NULL;
157 static const arm_feature_set *march_fpu_opt = NULL;
158 static const arm_feature_set *mfpu_opt = NULL;
159 static const arm_feature_set *object_arch = NULL;
161 /* Constants for known architecture features. */
162 static const arm_feature_set fpu_default = FPU_DEFAULT;
163 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
164 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
165 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
166 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
167 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
168 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
169 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
170 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
172 #ifdef CPU_DEFAULT
173 static const arm_feature_set cpu_default = CPU_DEFAULT;
174 #endif
176 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
177 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
178 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
179 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
180 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
181 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
182 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
183 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
184 static const arm_feature_set arm_ext_v4t_5 =
185 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
186 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
187 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
188 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
189 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
190 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
191 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
192 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
193 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
194 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
195 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
196 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
197 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
198 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
199 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
200 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
201 static const arm_feature_set arm_ext_m =
202 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
204 static const arm_feature_set arm_arch_any = ARM_ANY;
205 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
206 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
207 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
209 static const arm_feature_set arm_cext_iwmmxt2 =
210 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
211 static const arm_feature_set arm_cext_iwmmxt =
212 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
213 static const arm_feature_set arm_cext_xscale =
214 ARM_FEATURE (0, ARM_CEXT_XSCALE);
215 static const arm_feature_set arm_cext_maverick =
216 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
217 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
218 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
219 static const arm_feature_set fpu_vfp_ext_v1xd =
220 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
221 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
222 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
223 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
224 static const arm_feature_set fpu_vfp_ext_d32 =
225 ARM_FEATURE (0, FPU_VFP_EXT_D32);
226 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
227 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
228 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
230 static int mfloat_abi_opt = -1;
231 /* Record user cpu selection for object attributes. */
232 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
233 /* Must be long enough to hold any of the names in arm_cpus. */
234 static char selected_cpu_name[16];
235 #ifdef OBJ_ELF
236 # ifdef EABI_DEFAULT
237 static int meabi_flags = EABI_DEFAULT;
238 # else
239 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
240 # endif
242 bfd_boolean
243 arm_is_eabi (void)
245 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
247 #endif
249 #ifdef OBJ_ELF
250 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
251 symbolS * GOT_symbol;
252 #endif
254 /* 0: assemble for ARM,
255 1: assemble for Thumb,
256 2: assemble for Thumb even though target CPU does not support thumb
257 instructions. */
258 static int thumb_mode = 0;
260 /* If unified_syntax is true, we are processing the new unified
261 ARM/Thumb syntax. Important differences from the old ARM mode:
263 - Immediate operands do not require a # prefix.
264 - Conditional affixes always appear at the end of the
265 instruction. (For backward compatibility, those instructions
266 that formerly had them in the middle, continue to accept them
267 there.)
268 - The IT instruction may appear, and if it does is validated
269 against subsequent conditional affixes. It does not generate
270 machine code.
272 Important differences from the old Thumb mode:
274 - Immediate operands do not require a # prefix.
275 - Most of the V6T2 instructions are only available in unified mode.
276 - The .N and .W suffixes are recognized and honored (it is an error
277 if they cannot be honored).
278 - All instructions set the flags if and only if they have an 's' affix.
279 - Conditional affixes may be used. They are validated against
280 preceding IT instructions. Unlike ARM mode, you cannot use a
281 conditional affix except in the scope of an IT instruction. */
283 static bfd_boolean unified_syntax = FALSE;
285 enum neon_el_type
287 NT_invtype,
288 NT_untyped,
289 NT_integer,
290 NT_float,
291 NT_poly,
292 NT_signed,
293 NT_unsigned
296 struct neon_type_el
298 enum neon_el_type type;
299 unsigned size;
302 #define NEON_MAX_TYPE_ELS 4
304 struct neon_type
306 struct neon_type_el el[NEON_MAX_TYPE_ELS];
307 unsigned elems;
310 struct arm_it
312 const char * error;
313 unsigned long instruction;
314 int size;
315 int size_req;
316 int cond;
317 /* "uncond_value" is set to the value in place of the conditional field in
318 unconditional versions of the instruction, or -1 if nothing is
319 appropriate. */
320 int uncond_value;
321 struct neon_type vectype;
322 /* Set to the opcode if the instruction needs relaxation.
323 Zero if the instruction is not relaxed. */
324 unsigned long relax;
325 struct
327 bfd_reloc_code_real_type type;
328 expressionS exp;
329 int pc_rel;
330 } reloc;
332 struct
334 unsigned reg;
335 signed int imm;
336 struct neon_type_el vectype;
337 unsigned present : 1; /* Operand present. */
338 unsigned isreg : 1; /* Operand was a register. */
339 unsigned immisreg : 1; /* .imm field is a second register. */
340 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
341 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
342 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
343 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
344 instructions. This allows us to disambiguate ARM <-> vector insns. */
345 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
346 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
347 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
348 unsigned issingle : 1; /* Operand is VFP single-precision register. */
349 unsigned hasreloc : 1; /* Operand has relocation suffix. */
350 unsigned writeback : 1; /* Operand has trailing ! */
351 unsigned preind : 1; /* Preindexed address. */
352 unsigned postind : 1; /* Postindexed address. */
353 unsigned negative : 1; /* Index register was negated. */
354 unsigned shifted : 1; /* Shift applied to operation. */
355 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
356 } operands[6];
359 static struct arm_it inst;
361 #define NUM_FLOAT_VALS 8
363 const char * fp_const[] =
365 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
368 /* Number of littlenums required to hold an extended precision number. */
369 #define MAX_LITTLENUMS 6
371 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
373 #define FAIL (-1)
374 #define SUCCESS (0)
376 #define SUFF_S 1
377 #define SUFF_D 2
378 #define SUFF_E 3
379 #define SUFF_P 4
381 #define CP_T_X 0x00008000
382 #define CP_T_Y 0x00400000
384 #define CONDS_BIT 0x00100000
385 #define LOAD_BIT 0x00100000
387 #define DOUBLE_LOAD_FLAG 0x00000001
389 struct asm_cond
391 const char * template;
392 unsigned long value;
395 #define COND_ALWAYS 0xE
397 struct asm_psr
399 const char *template;
400 unsigned long field;
403 struct asm_barrier_opt
405 const char *template;
406 unsigned long value;
409 /* The bit that distinguishes CPSR and SPSR. */
410 #define SPSR_BIT (1 << 22)
412 /* The individual PSR flag bits. */
413 #define PSR_c (1 << 16)
414 #define PSR_x (1 << 17)
415 #define PSR_s (1 << 18)
416 #define PSR_f (1 << 19)
418 struct reloc_entry
420 char *name;
421 bfd_reloc_code_real_type reloc;
424 enum vfp_reg_pos
426 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
427 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
430 enum vfp_ldstm_type
432 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
435 /* Bits for DEFINED field in neon_typed_alias. */
436 #define NTA_HASTYPE 1
437 #define NTA_HASINDEX 2
439 struct neon_typed_alias
441 unsigned char defined;
442 unsigned char index;
443 struct neon_type_el eltype;
446 /* ARM register categories. This includes coprocessor numbers and various
447 architecture extensions' registers. */
448 enum arm_reg_type
450 REG_TYPE_RN,
451 REG_TYPE_CP,
452 REG_TYPE_CN,
453 REG_TYPE_FN,
454 REG_TYPE_VFS,
455 REG_TYPE_VFD,
456 REG_TYPE_NQ,
457 REG_TYPE_VFSD,
458 REG_TYPE_NDQ,
459 REG_TYPE_NSDQ,
460 REG_TYPE_VFC,
461 REG_TYPE_MVF,
462 REG_TYPE_MVD,
463 REG_TYPE_MVFX,
464 REG_TYPE_MVDX,
465 REG_TYPE_MVAX,
466 REG_TYPE_DSPSC,
467 REG_TYPE_MMXWR,
468 REG_TYPE_MMXWC,
469 REG_TYPE_MMXWCG,
470 REG_TYPE_XSCALE,
473 /* Structure for a hash table entry for a register.
474 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
475 information which states whether a vector type or index is specified (for a
476 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
477 struct reg_entry
479 const char *name;
480 unsigned char number;
481 unsigned char type;
482 unsigned char builtin;
483 struct neon_typed_alias *neon;
486 /* Diagnostics used when we don't get a register of the expected type. */
487 const char *const reg_expected_msgs[] =
489 N_("ARM register expected"),
490 N_("bad or missing co-processor number"),
491 N_("co-processor register expected"),
492 N_("FPA register expected"),
493 N_("VFP single precision register expected"),
494 N_("VFP/Neon double precision register expected"),
495 N_("Neon quad precision register expected"),
496 N_("VFP single or double precision register expected"),
497 N_("Neon double or quad precision register expected"),
498 N_("VFP single, double or Neon quad precision register expected"),
499 N_("VFP system register expected"),
500 N_("Maverick MVF register expected"),
501 N_("Maverick MVD register expected"),
502 N_("Maverick MVFX register expected"),
503 N_("Maverick MVDX register expected"),
504 N_("Maverick MVAX register expected"),
505 N_("Maverick DSPSC register expected"),
506 N_("iWMMXt data register expected"),
507 N_("iWMMXt control register expected"),
508 N_("iWMMXt scalar register expected"),
509 N_("XScale accumulator register expected"),
512 /* Some well known registers that we refer to directly elsewhere. */
513 #define REG_SP 13
514 #define REG_LR 14
515 #define REG_PC 15
517 /* ARM instructions take 4bytes in the object file, Thumb instructions
518 take 2: */
519 #define INSN_SIZE 4
521 struct asm_opcode
523 /* Basic string to match. */
524 const char *template;
526 /* Parameters to instruction. */
527 unsigned char operands[8];
529 /* Conditional tag - see opcode_lookup. */
530 unsigned int tag : 4;
532 /* Basic instruction code. */
533 unsigned int avalue : 28;
535 /* Thumb-format instruction code. */
536 unsigned int tvalue;
538 /* Which architecture variant provides this instruction. */
539 const arm_feature_set *avariant;
540 const arm_feature_set *tvariant;
542 /* Function to call to encode instruction in ARM format. */
543 void (* aencode) (void);
545 /* Function to call to encode instruction in Thumb format. */
546 void (* tencode) (void);
549 /* Defines for various bits that we will want to toggle. */
550 #define INST_IMMEDIATE 0x02000000
551 #define OFFSET_REG 0x02000000
552 #define HWOFFSET_IMM 0x00400000
553 #define SHIFT_BY_REG 0x00000010
554 #define PRE_INDEX 0x01000000
555 #define INDEX_UP 0x00800000
556 #define WRITE_BACK 0x00200000
557 #define LDM_TYPE_2_OR_3 0x00400000
558 #define CPSI_MMOD 0x00020000
560 #define LITERAL_MASK 0xf000f000
561 #define OPCODE_MASK 0xfe1fffff
562 #define V4_STR_BIT 0x00000020
564 #define T2_SUBS_PC_LR 0xf3de8f00
566 #define DATA_OP_SHIFT 21
568 #define T2_OPCODE_MASK 0xfe1fffff
569 #define T2_DATA_OP_SHIFT 21
571 /* Codes to distinguish the arithmetic instructions. */
572 #define OPCODE_AND 0
573 #define OPCODE_EOR 1
574 #define OPCODE_SUB 2
575 #define OPCODE_RSB 3
576 #define OPCODE_ADD 4
577 #define OPCODE_ADC 5
578 #define OPCODE_SBC 6
579 #define OPCODE_RSC 7
580 #define OPCODE_TST 8
581 #define OPCODE_TEQ 9
582 #define OPCODE_CMP 10
583 #define OPCODE_CMN 11
584 #define OPCODE_ORR 12
585 #define OPCODE_MOV 13
586 #define OPCODE_BIC 14
587 #define OPCODE_MVN 15
589 #define T2_OPCODE_AND 0
590 #define T2_OPCODE_BIC 1
591 #define T2_OPCODE_ORR 2
592 #define T2_OPCODE_ORN 3
593 #define T2_OPCODE_EOR 4
594 #define T2_OPCODE_ADD 8
595 #define T2_OPCODE_ADC 10
596 #define T2_OPCODE_SBC 11
597 #define T2_OPCODE_SUB 13
598 #define T2_OPCODE_RSB 14
600 #define T_OPCODE_MUL 0x4340
601 #define T_OPCODE_TST 0x4200
602 #define T_OPCODE_CMN 0x42c0
603 #define T_OPCODE_NEG 0x4240
604 #define T_OPCODE_MVN 0x43c0
606 #define T_OPCODE_ADD_R3 0x1800
607 #define T_OPCODE_SUB_R3 0x1a00
608 #define T_OPCODE_ADD_HI 0x4400
609 #define T_OPCODE_ADD_ST 0xb000
610 #define T_OPCODE_SUB_ST 0xb080
611 #define T_OPCODE_ADD_SP 0xa800
612 #define T_OPCODE_ADD_PC 0xa000
613 #define T_OPCODE_ADD_I8 0x3000
614 #define T_OPCODE_SUB_I8 0x3800
615 #define T_OPCODE_ADD_I3 0x1c00
616 #define T_OPCODE_SUB_I3 0x1e00
618 #define T_OPCODE_ASR_R 0x4100
619 #define T_OPCODE_LSL_R 0x4080
620 #define T_OPCODE_LSR_R 0x40c0
621 #define T_OPCODE_ROR_R 0x41c0
622 #define T_OPCODE_ASR_I 0x1000
623 #define T_OPCODE_LSL_I 0x0000
624 #define T_OPCODE_LSR_I 0x0800
626 #define T_OPCODE_MOV_I8 0x2000
627 #define T_OPCODE_CMP_I8 0x2800
628 #define T_OPCODE_CMP_LR 0x4280
629 #define T_OPCODE_MOV_HR 0x4600
630 #define T_OPCODE_CMP_HR 0x4500
632 #define T_OPCODE_LDR_PC 0x4800
633 #define T_OPCODE_LDR_SP 0x9800
634 #define T_OPCODE_STR_SP 0x9000
635 #define T_OPCODE_LDR_IW 0x6800
636 #define T_OPCODE_STR_IW 0x6000
637 #define T_OPCODE_LDR_IH 0x8800
638 #define T_OPCODE_STR_IH 0x8000
639 #define T_OPCODE_LDR_IB 0x7800
640 #define T_OPCODE_STR_IB 0x7000
641 #define T_OPCODE_LDR_RW 0x5800
642 #define T_OPCODE_STR_RW 0x5000
643 #define T_OPCODE_LDR_RH 0x5a00
644 #define T_OPCODE_STR_RH 0x5200
645 #define T_OPCODE_LDR_RB 0x5c00
646 #define T_OPCODE_STR_RB 0x5400
648 #define T_OPCODE_PUSH 0xb400
649 #define T_OPCODE_POP 0xbc00
651 #define T_OPCODE_BRANCH 0xe000
653 #define THUMB_SIZE 2 /* Size of thumb instruction. */
654 #define THUMB_PP_PC_LR 0x0100
655 #define THUMB_LOAD_BIT 0x0800
656 #define THUMB2_LOAD_BIT 0x00100000
658 #define BAD_ARGS _("bad arguments to instruction")
659 #define BAD_PC _("r15 not allowed here")
660 #define BAD_COND _("instruction cannot be conditional")
661 #define BAD_OVERLAP _("registers may not be the same")
662 #define BAD_HIREG _("lo register required")
663 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
664 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
665 #define BAD_BRANCH _("branch must be last instruction in IT block")
666 #define BAD_NOT_IT _("instruction not allowed in IT block")
667 #define BAD_FPU _("selected FPU does not support instruction")
669 static struct hash_control *arm_ops_hsh;
670 static struct hash_control *arm_cond_hsh;
671 static struct hash_control *arm_shift_hsh;
672 static struct hash_control *arm_psr_hsh;
673 static struct hash_control *arm_v7m_psr_hsh;
674 static struct hash_control *arm_reg_hsh;
675 static struct hash_control *arm_reloc_hsh;
676 static struct hash_control *arm_barrier_opt_hsh;
678 /* Stuff needed to resolve the label ambiguity
681 label: <insn>
682 may differ from:
684 label:
685 <insn> */
687 symbolS * last_label_seen;
688 static int label_is_thumb_function_name = FALSE;
690 /* Literal pool structure. Held on a per-section
691 and per-sub-section basis. */
693 #define MAX_LITERAL_POOL_SIZE 1024
694 typedef struct literal_pool
696 expressionS literals [MAX_LITERAL_POOL_SIZE];
697 unsigned int next_free_entry;
698 unsigned int id;
699 symbolS * symbol;
700 segT section;
701 subsegT sub_section;
702 struct literal_pool * next;
703 } literal_pool;
705 /* Pointer to a linked list of literal pools. */
706 literal_pool * list_of_pools = NULL;
708 /* State variables for IT block handling. */
709 static bfd_boolean current_it_mask = 0;
710 static int current_cc;
712 /* Pure syntax. */
714 /* This array holds the chars that always start a comment. If the
715 pre-processor is disabled, these aren't very useful. */
716 const char comment_chars[] = "@";
718 /* This array holds the chars that only start a comment at the beginning of
719 a line. If the line seems to have the form '# 123 filename'
720 .line and .file directives will appear in the pre-processed output. */
721 /* Note that input_file.c hand checks for '#' at the beginning of the
722 first line of the input file. This is because the compiler outputs
723 #NO_APP at the beginning of its output. */
724 /* Also note that comments like this one will always work. */
725 const char line_comment_chars[] = "#";
727 const char line_separator_chars[] = ";";
729 /* Chars that can be used to separate mant
730 from exp in floating point numbers. */
731 const char EXP_CHARS[] = "eE";
733 /* Chars that mean this number is a floating point constant. */
734 /* As in 0f12.456 */
735 /* or 0d1.2345e12 */
737 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
739 /* Prefix characters that indicate the start of an immediate
740 value. */
741 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
743 /* Separator character handling. */
745 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
747 static inline int
748 skip_past_char (char ** str, char c)
750 if (**str == c)
752 (*str)++;
753 return SUCCESS;
755 else
756 return FAIL;
758 #define skip_past_comma(str) skip_past_char (str, ',')
760 /* Arithmetic expressions (possibly involving symbols). */
762 /* Return TRUE if anything in the expression is a bignum. */
764 static int
765 walk_no_bignums (symbolS * sp)
767 if (symbol_get_value_expression (sp)->X_op == O_big)
768 return 1;
770 if (symbol_get_value_expression (sp)->X_add_symbol)
772 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
773 || (symbol_get_value_expression (sp)->X_op_symbol
774 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
777 return 0;
780 static int in_my_get_expression = 0;
782 /* Third argument to my_get_expression. */
783 #define GE_NO_PREFIX 0
784 #define GE_IMM_PREFIX 1
785 #define GE_OPT_PREFIX 2
786 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
787 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
788 #define GE_OPT_PREFIX_BIG 3
790 static int
791 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
793 char * save_in;
794 segT seg;
796 /* In unified syntax, all prefixes are optional. */
797 if (unified_syntax)
798 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
799 : GE_OPT_PREFIX;
801 switch (prefix_mode)
803 case GE_NO_PREFIX: break;
804 case GE_IMM_PREFIX:
805 if (!is_immediate_prefix (**str))
807 inst.error = _("immediate expression requires a # prefix");
808 return FAIL;
810 (*str)++;
811 break;
812 case GE_OPT_PREFIX:
813 case GE_OPT_PREFIX_BIG:
814 if (is_immediate_prefix (**str))
815 (*str)++;
816 break;
817 default: abort ();
820 memset (ep, 0, sizeof (expressionS));
822 save_in = input_line_pointer;
823 input_line_pointer = *str;
824 in_my_get_expression = 1;
825 seg = expression (ep);
826 in_my_get_expression = 0;
828 if (ep->X_op == O_illegal)
830 /* We found a bad expression in md_operand(). */
831 *str = input_line_pointer;
832 input_line_pointer = save_in;
833 if (inst.error == NULL)
834 inst.error = _("bad expression");
835 return 1;
838 #ifdef OBJ_AOUT
839 if (seg != absolute_section
840 && seg != text_section
841 && seg != data_section
842 && seg != bss_section
843 && seg != undefined_section)
845 inst.error = _("bad segment");
846 *str = input_line_pointer;
847 input_line_pointer = save_in;
848 return 1;
850 #endif
852 /* Get rid of any bignums now, so that we don't generate an error for which
853 we can't establish a line number later on. Big numbers are never valid
854 in instructions, which is where this routine is always called. */
855 if (prefix_mode != GE_OPT_PREFIX_BIG
856 && (ep->X_op == O_big
857 || (ep->X_add_symbol
858 && (walk_no_bignums (ep->X_add_symbol)
859 || (ep->X_op_symbol
860 && walk_no_bignums (ep->X_op_symbol))))))
862 inst.error = _("invalid constant");
863 *str = input_line_pointer;
864 input_line_pointer = save_in;
865 return 1;
868 *str = input_line_pointer;
869 input_line_pointer = save_in;
870 return 0;
873 /* Turn a string in input_line_pointer into a floating point constant
874 of type TYPE, and store the appropriate bytes in *LITP. The number
875 of LITTLENUMS emitted is stored in *SIZEP. An error message is
876 returned, or NULL on OK.
878 Note that fp constants aren't represent in the normal way on the ARM.
879 In big endian mode, things are as expected. However, in little endian
880 mode fp constants are big-endian word-wise, and little-endian byte-wise
881 within the words. For example, (double) 1.1 in big endian mode is
882 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
883 the byte sequence 99 99 f1 3f 9a 99 99 99.
885 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
887 char *
888 md_atof (int type, char * litP, int * sizeP)
890 int prec;
891 LITTLENUM_TYPE words[MAX_LITTLENUMS];
892 char *t;
893 int i;
895 switch (type)
897 case 'f':
898 case 'F':
899 case 's':
900 case 'S':
901 prec = 2;
902 break;
904 case 'd':
905 case 'D':
906 case 'r':
907 case 'R':
908 prec = 4;
909 break;
911 case 'x':
912 case 'X':
913 prec = 5;
914 break;
916 case 'p':
917 case 'P':
918 prec = 5;
919 break;
921 default:
922 *sizeP = 0;
923 return _("Unrecognized or unsupported floating point constant");
926 t = atof_ieee (input_line_pointer, type, words);
927 if (t)
928 input_line_pointer = t;
929 *sizeP = prec * sizeof (LITTLENUM_TYPE);
931 if (target_big_endian)
933 for (i = 0; i < prec; i++)
935 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
936 litP += sizeof (LITTLENUM_TYPE);
939 else
941 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
942 for (i = prec - 1; i >= 0; i--)
944 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
945 litP += sizeof (LITTLENUM_TYPE);
947 else
948 /* For a 4 byte float the order of elements in `words' is 1 0.
949 For an 8 byte float the order is 1 0 3 2. */
950 for (i = 0; i < prec; i += 2)
952 md_number_to_chars (litP, (valueT) words[i + 1],
953 sizeof (LITTLENUM_TYPE));
954 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
955 (valueT) words[i], sizeof (LITTLENUM_TYPE));
956 litP += 2 * sizeof (LITTLENUM_TYPE);
960 return NULL;
963 /* We handle all bad expressions here, so that we can report the faulty
964 instruction in the error message. */
965 void
966 md_operand (expressionS * expr)
968 if (in_my_get_expression)
969 expr->X_op = O_illegal;
972 /* Immediate values. */
974 /* Generic immediate-value read function for use in directives.
975 Accepts anything that 'expression' can fold to a constant.
976 *val receives the number. */
977 #ifdef OBJ_ELF
978 static int
979 immediate_for_directive (int *val)
981 expressionS exp;
982 exp.X_op = O_illegal;
984 if (is_immediate_prefix (*input_line_pointer))
986 input_line_pointer++;
987 expression (&exp);
990 if (exp.X_op != O_constant)
992 as_bad (_("expected #constant"));
993 ignore_rest_of_line ();
994 return FAIL;
996 *val = exp.X_add_number;
997 return SUCCESS;
999 #endif
1001 /* Register parsing. */
1003 /* Generic register parser. CCP points to what should be the
1004 beginning of a register name. If it is indeed a valid register
1005 name, advance CCP over it and return the reg_entry structure;
1006 otherwise return NULL. Does not issue diagnostics. */
1008 static struct reg_entry *
1009 arm_reg_parse_multi (char **ccp)
1011 char *start = *ccp;
1012 char *p;
1013 struct reg_entry *reg;
1015 #ifdef REGISTER_PREFIX
1016 if (*start != REGISTER_PREFIX)
1017 return NULL;
1018 start++;
1019 #endif
1020 #ifdef OPTIONAL_REGISTER_PREFIX
1021 if (*start == OPTIONAL_REGISTER_PREFIX)
1022 start++;
1023 #endif
1025 p = start;
1026 if (!ISALPHA (*p) || !is_name_beginner (*p))
1027 return NULL;
1030 p++;
1031 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1033 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1035 if (!reg)
1036 return NULL;
1038 *ccp = p;
1039 return reg;
1042 static int
1043 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1044 enum arm_reg_type type)
1046 /* Alternative syntaxes are accepted for a few register classes. */
1047 switch (type)
1049 case REG_TYPE_MVF:
1050 case REG_TYPE_MVD:
1051 case REG_TYPE_MVFX:
1052 case REG_TYPE_MVDX:
1053 /* Generic coprocessor register names are allowed for these. */
1054 if (reg && reg->type == REG_TYPE_CN)
1055 return reg->number;
1056 break;
1058 case REG_TYPE_CP:
1059 /* For backward compatibility, a bare number is valid here. */
1061 unsigned long processor = strtoul (start, ccp, 10);
1062 if (*ccp != start && processor <= 15)
1063 return processor;
1066 case REG_TYPE_MMXWC:
1067 /* WC includes WCG. ??? I'm not sure this is true for all
1068 instructions that take WC registers. */
1069 if (reg && reg->type == REG_TYPE_MMXWCG)
1070 return reg->number;
1071 break;
1073 default:
1074 break;
1077 return FAIL;
1080 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1081 return value is the register number or FAIL. */
1083 static int
1084 arm_reg_parse (char **ccp, enum arm_reg_type type)
1086 char *start = *ccp;
1087 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1088 int ret;
1090 /* Do not allow a scalar (reg+index) to parse as a register. */
1091 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1092 return FAIL;
1094 if (reg && reg->type == type)
1095 return reg->number;
1097 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1098 return ret;
1100 *ccp = start;
1101 return FAIL;
1104 /* Parse a Neon type specifier. *STR should point at the leading '.'
1105 character. Does no verification at this stage that the type fits the opcode
1106 properly. E.g.,
1108 .i32.i32.s16
1109 .s32.f32
1110 .u16
1112 Can all be legally parsed by this function.
1114 Fills in neon_type struct pointer with parsed information, and updates STR
1115 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1116 type, FAIL if not. */
1118 static int
1119 parse_neon_type (struct neon_type *type, char **str)
1121 char *ptr = *str;
1123 if (type)
1124 type->elems = 0;
1126 while (type->elems < NEON_MAX_TYPE_ELS)
1128 enum neon_el_type thistype = NT_untyped;
1129 unsigned thissize = -1u;
1131 if (*ptr != '.')
1132 break;
1134 ptr++;
1136 /* Just a size without an explicit type. */
1137 if (ISDIGIT (*ptr))
1138 goto parsesize;
1140 switch (TOLOWER (*ptr))
1142 case 'i': thistype = NT_integer; break;
1143 case 'f': thistype = NT_float; break;
1144 case 'p': thistype = NT_poly; break;
1145 case 's': thistype = NT_signed; break;
1146 case 'u': thistype = NT_unsigned; break;
1147 case 'd':
1148 thistype = NT_float;
1149 thissize = 64;
1150 ptr++;
1151 goto done;
1152 default:
1153 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1154 return FAIL;
1157 ptr++;
1159 /* .f is an abbreviation for .f32. */
1160 if (thistype == NT_float && !ISDIGIT (*ptr))
1161 thissize = 32;
1162 else
1164 parsesize:
1165 thissize = strtoul (ptr, &ptr, 10);
1167 if (thissize != 8 && thissize != 16 && thissize != 32
1168 && thissize != 64)
1170 as_bad (_("bad size %d in type specifier"), thissize);
1171 return FAIL;
1175 done:
1176 if (type)
1178 type->el[type->elems].type = thistype;
1179 type->el[type->elems].size = thissize;
1180 type->elems++;
1184 /* Empty/missing type is not a successful parse. */
1185 if (type->elems == 0)
1186 return FAIL;
1188 *str = ptr;
1190 return SUCCESS;
1193 /* Errors may be set multiple times during parsing or bit encoding
1194 (particularly in the Neon bits), but usually the earliest error which is set
1195 will be the most meaningful. Avoid overwriting it with later (cascading)
1196 errors by calling this function. */
1198 static void
1199 first_error (const char *err)
1201 if (!inst.error)
1202 inst.error = err;
1205 /* Parse a single type, e.g. ".s32", leading period included. */
1206 static int
1207 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1209 char *str = *ccp;
1210 struct neon_type optype;
1212 if (*str == '.')
1214 if (parse_neon_type (&optype, &str) == SUCCESS)
1216 if (optype.elems == 1)
1217 *vectype = optype.el[0];
1218 else
1220 first_error (_("only one type should be specified for operand"));
1221 return FAIL;
1224 else
1226 first_error (_("vector type expected"));
1227 return FAIL;
1230 else
1231 return FAIL;
1233 *ccp = str;
1235 return SUCCESS;
1238 /* Special meanings for indices (which have a range of 0-7), which will fit into
1239 a 4-bit integer. */
1241 #define NEON_ALL_LANES 15
1242 #define NEON_INTERLEAVE_LANES 14
1244 /* Parse either a register or a scalar, with an optional type. Return the
1245 register number, and optionally fill in the actual type of the register
1246 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1247 type/index information in *TYPEINFO. */
1249 static int
1250 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1251 enum arm_reg_type *rtype,
1252 struct neon_typed_alias *typeinfo)
1254 char *str = *ccp;
1255 struct reg_entry *reg = arm_reg_parse_multi (&str);
1256 struct neon_typed_alias atype;
1257 struct neon_type_el parsetype;
1259 atype.defined = 0;
1260 atype.index = -1;
1261 atype.eltype.type = NT_invtype;
1262 atype.eltype.size = -1;
1264 /* Try alternate syntax for some types of register. Note these are mutually
1265 exclusive with the Neon syntax extensions. */
1266 if (reg == NULL)
1268 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1269 if (altreg != FAIL)
1270 *ccp = str;
1271 if (typeinfo)
1272 *typeinfo = atype;
1273 return altreg;
1276 /* Undo polymorphism when a set of register types may be accepted. */
1277 if ((type == REG_TYPE_NDQ
1278 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1279 || (type == REG_TYPE_VFSD
1280 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1281 || (type == REG_TYPE_NSDQ
1282 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1283 || reg->type == REG_TYPE_NQ))
1284 || (type == REG_TYPE_MMXWC
1285 && (reg->type == REG_TYPE_MMXWCG)))
1286 type = reg->type;
1288 if (type != reg->type)
1289 return FAIL;
1291 if (reg->neon)
1292 atype = *reg->neon;
1294 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1296 if ((atype.defined & NTA_HASTYPE) != 0)
1298 first_error (_("can't redefine type for operand"));
1299 return FAIL;
1301 atype.defined |= NTA_HASTYPE;
1302 atype.eltype = parsetype;
1305 if (skip_past_char (&str, '[') == SUCCESS)
1307 if (type != REG_TYPE_VFD)
1309 first_error (_("only D registers may be indexed"));
1310 return FAIL;
1313 if ((atype.defined & NTA_HASINDEX) != 0)
1315 first_error (_("can't change index for operand"));
1316 return FAIL;
1319 atype.defined |= NTA_HASINDEX;
1321 if (skip_past_char (&str, ']') == SUCCESS)
1322 atype.index = NEON_ALL_LANES;
1323 else
1325 expressionS exp;
1327 my_get_expression (&exp, &str, GE_NO_PREFIX);
1329 if (exp.X_op != O_constant)
1331 first_error (_("constant expression required"));
1332 return FAIL;
1335 if (skip_past_char (&str, ']') == FAIL)
1336 return FAIL;
1338 atype.index = exp.X_add_number;
1342 if (typeinfo)
1343 *typeinfo = atype;
1345 if (rtype)
1346 *rtype = type;
1348 *ccp = str;
1350 return reg->number;
1353 /* Like arm_reg_parse, but allow allow the following extra features:
1354 - If RTYPE is non-zero, return the (possibly restricted) type of the
1355 register (e.g. Neon double or quad reg when either has been requested).
1356 - If this is a Neon vector type with additional type information, fill
1357 in the struct pointed to by VECTYPE (if non-NULL).
1358 This function will fault on encountering a scalar. */
1360 static int
1361 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1362 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1364 struct neon_typed_alias atype;
1365 char *str = *ccp;
1366 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1368 if (reg == FAIL)
1369 return FAIL;
1371 /* Do not allow a scalar (reg+index) to parse as a register. */
1372 if ((atype.defined & NTA_HASINDEX) != 0)
1374 first_error (_("register operand expected, but got scalar"));
1375 return FAIL;
1378 if (vectype)
1379 *vectype = atype.eltype;
1381 *ccp = str;
1383 return reg;
1386 #define NEON_SCALAR_REG(X) ((X) >> 4)
1387 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1389 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1390 have enough information to be able to do a good job bounds-checking. So, we
1391 just do easy checks here, and do further checks later. */
1393 static int
1394 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1396 int reg;
1397 char *str = *ccp;
1398 struct neon_typed_alias atype;
1400 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1402 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1403 return FAIL;
1405 if (atype.index == NEON_ALL_LANES)
1407 first_error (_("scalar must have an index"));
1408 return FAIL;
1410 else if (atype.index >= 64 / elsize)
1412 first_error (_("scalar index out of range"));
1413 return FAIL;
1416 if (type)
1417 *type = atype.eltype;
1419 *ccp = str;
1421 return reg * 16 + atype.index;
1424 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1425 static long
1426 parse_reg_list (char ** strp)
1428 char * str = * strp;
1429 long range = 0;
1430 int another_range;
1432 /* We come back here if we get ranges concatenated by '+' or '|'. */
1435 another_range = 0;
1437 if (*str == '{')
1439 int in_range = 0;
1440 int cur_reg = -1;
1442 str++;
1445 int reg;
1447 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1449 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1450 return FAIL;
1453 if (in_range)
1455 int i;
1457 if (reg <= cur_reg)
1459 first_error (_("bad range in register list"));
1460 return FAIL;
1463 for (i = cur_reg + 1; i < reg; i++)
1465 if (range & (1 << i))
1466 as_tsktsk
1467 (_("Warning: duplicated register (r%d) in register list"),
1469 else
1470 range |= 1 << i;
1472 in_range = 0;
1475 if (range & (1 << reg))
1476 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1477 reg);
1478 else if (reg <= cur_reg)
1479 as_tsktsk (_("Warning: register range not in ascending order"));
1481 range |= 1 << reg;
1482 cur_reg = reg;
1484 while (skip_past_comma (&str) != FAIL
1485 || (in_range = 1, *str++ == '-'));
1486 str--;
1488 if (*str++ != '}')
1490 first_error (_("missing `}'"));
1491 return FAIL;
1494 else
1496 expressionS expr;
1498 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1499 return FAIL;
1501 if (expr.X_op == O_constant)
1503 if (expr.X_add_number
1504 != (expr.X_add_number & 0x0000ffff))
1506 inst.error = _("invalid register mask");
1507 return FAIL;
1510 if ((range & expr.X_add_number) != 0)
1512 int regno = range & expr.X_add_number;
1514 regno &= -regno;
1515 regno = (1 << regno) - 1;
1516 as_tsktsk
1517 (_("Warning: duplicated register (r%d) in register list"),
1518 regno);
1521 range |= expr.X_add_number;
1523 else
1525 if (inst.reloc.type != 0)
1527 inst.error = _("expression too complex");
1528 return FAIL;
1531 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1532 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1533 inst.reloc.pc_rel = 0;
1537 if (*str == '|' || *str == '+')
1539 str++;
1540 another_range = 1;
1543 while (another_range);
1545 *strp = str;
1546 return range;
1549 /* Types of registers in a list. */
1551 enum reg_list_els
1553 REGLIST_VFP_S,
1554 REGLIST_VFP_D,
1555 REGLIST_NEON_D
1558 /* Parse a VFP register list. If the string is invalid return FAIL.
1559 Otherwise return the number of registers, and set PBASE to the first
1560 register. Parses registers of type ETYPE.
1561 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1562 - Q registers can be used to specify pairs of D registers
1563 - { } can be omitted from around a singleton register list
1564 FIXME: This is not implemented, as it would require backtracking in
1565 some cases, e.g.:
1566 vtbl.8 d3,d4,d5
1567 This could be done (the meaning isn't really ambiguous), but doesn't
1568 fit in well with the current parsing framework.
1569 - 32 D registers may be used (also true for VFPv3).
1570 FIXME: Types are ignored in these register lists, which is probably a
1571 bug. */
1573 static int
1574 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1576 char *str = *ccp;
1577 int base_reg;
1578 int new_base;
1579 enum arm_reg_type regtype = 0;
1580 int max_regs = 0;
1581 int count = 0;
1582 int warned = 0;
1583 unsigned long mask = 0;
1584 int i;
1586 if (*str != '{')
1588 inst.error = _("expecting {");
1589 return FAIL;
1592 str++;
1594 switch (etype)
1596 case REGLIST_VFP_S:
1597 regtype = REG_TYPE_VFS;
1598 max_regs = 32;
1599 break;
1601 case REGLIST_VFP_D:
1602 regtype = REG_TYPE_VFD;
1603 break;
1605 case REGLIST_NEON_D:
1606 regtype = REG_TYPE_NDQ;
1607 break;
1610 if (etype != REGLIST_VFP_S)
1612 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1613 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1615 max_regs = 32;
1616 if (thumb_mode)
1617 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1618 fpu_vfp_ext_d32);
1619 else
1620 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1621 fpu_vfp_ext_d32);
1623 else
1624 max_regs = 16;
1627 base_reg = max_regs;
1631 int setmask = 1, addregs = 1;
1633 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1635 if (new_base == FAIL)
1637 first_error (_(reg_expected_msgs[regtype]));
1638 return FAIL;
1641 if (new_base >= max_regs)
1643 first_error (_("register out of range in list"));
1644 return FAIL;
1647 /* Note: a value of 2 * n is returned for the register Q<n>. */
1648 if (regtype == REG_TYPE_NQ)
1650 setmask = 3;
1651 addregs = 2;
1654 if (new_base < base_reg)
1655 base_reg = new_base;
1657 if (mask & (setmask << new_base))
1659 first_error (_("invalid register list"));
1660 return FAIL;
1663 if ((mask >> new_base) != 0 && ! warned)
1665 as_tsktsk (_("register list not in ascending order"));
1666 warned = 1;
1669 mask |= setmask << new_base;
1670 count += addregs;
1672 if (*str == '-') /* We have the start of a range expression */
1674 int high_range;
1676 str++;
1678 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1679 == FAIL)
1681 inst.error = gettext (reg_expected_msgs[regtype]);
1682 return FAIL;
1685 if (high_range >= max_regs)
1687 first_error (_("register out of range in list"));
1688 return FAIL;
1691 if (regtype == REG_TYPE_NQ)
1692 high_range = high_range + 1;
1694 if (high_range <= new_base)
1696 inst.error = _("register range not in ascending order");
1697 return FAIL;
1700 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1702 if (mask & (setmask << new_base))
1704 inst.error = _("invalid register list");
1705 return FAIL;
1708 mask |= setmask << new_base;
1709 count += addregs;
1713 while (skip_past_comma (&str) != FAIL);
1715 str++;
1717 /* Sanity check -- should have raised a parse error above. */
1718 if (count == 0 || count > max_regs)
1719 abort ();
1721 *pbase = base_reg;
1723 /* Final test -- the registers must be consecutive. */
1724 mask >>= base_reg;
1725 for (i = 0; i < count; i++)
1727 if ((mask & (1u << i)) == 0)
1729 inst.error = _("non-contiguous register range");
1730 return FAIL;
1734 *ccp = str;
1736 return count;
1739 /* True if two alias types are the same. */
1741 static int
1742 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1744 if (!a && !b)
1745 return 1;
1747 if (!a || !b)
1748 return 0;
1750 if (a->defined != b->defined)
1751 return 0;
1753 if ((a->defined & NTA_HASTYPE) != 0
1754 && (a->eltype.type != b->eltype.type
1755 || a->eltype.size != b->eltype.size))
1756 return 0;
1758 if ((a->defined & NTA_HASINDEX) != 0
1759 && (a->index != b->index))
1760 return 0;
1762 return 1;
1765 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1766 The base register is put in *PBASE.
1767 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1768 the return value.
1769 The register stride (minus one) is put in bit 4 of the return value.
1770 Bits [6:5] encode the list length (minus one).
1771 The type of the list elements is put in *ELTYPE, if non-NULL. */
1773 #define NEON_LANE(X) ((X) & 0xf)
1774 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1775 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1777 static int
1778 parse_neon_el_struct_list (char **str, unsigned *pbase,
1779 struct neon_type_el *eltype)
1781 char *ptr = *str;
1782 int base_reg = -1;
1783 int reg_incr = -1;
1784 int count = 0;
1785 int lane = -1;
1786 int leading_brace = 0;
1787 enum arm_reg_type rtype = REG_TYPE_NDQ;
1788 int addregs = 1;
1789 const char *const incr_error = "register stride must be 1 or 2";
1790 const char *const type_error = "mismatched element/structure types in list";
1791 struct neon_typed_alias firsttype;
1793 if (skip_past_char (&ptr, '{') == SUCCESS)
1794 leading_brace = 1;
1798 struct neon_typed_alias atype;
1799 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1801 if (getreg == FAIL)
1803 first_error (_(reg_expected_msgs[rtype]));
1804 return FAIL;
1807 if (base_reg == -1)
1809 base_reg = getreg;
1810 if (rtype == REG_TYPE_NQ)
1812 reg_incr = 1;
1813 addregs = 2;
1815 firsttype = atype;
1817 else if (reg_incr == -1)
1819 reg_incr = getreg - base_reg;
1820 if (reg_incr < 1 || reg_incr > 2)
1822 first_error (_(incr_error));
1823 return FAIL;
1826 else if (getreg != base_reg + reg_incr * count)
1828 first_error (_(incr_error));
1829 return FAIL;
1832 if (!neon_alias_types_same (&atype, &firsttype))
1834 first_error (_(type_error));
1835 return FAIL;
1838 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1839 modes. */
1840 if (ptr[0] == '-')
1842 struct neon_typed_alias htype;
1843 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1844 if (lane == -1)
1845 lane = NEON_INTERLEAVE_LANES;
1846 else if (lane != NEON_INTERLEAVE_LANES)
1848 first_error (_(type_error));
1849 return FAIL;
1851 if (reg_incr == -1)
1852 reg_incr = 1;
1853 else if (reg_incr != 1)
1855 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1856 return FAIL;
1858 ptr++;
1859 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1860 if (hireg == FAIL)
1862 first_error (_(reg_expected_msgs[rtype]));
1863 return FAIL;
1865 if (!neon_alias_types_same (&htype, &firsttype))
1867 first_error (_(type_error));
1868 return FAIL;
1870 count += hireg + dregs - getreg;
1871 continue;
1874 /* If we're using Q registers, we can't use [] or [n] syntax. */
1875 if (rtype == REG_TYPE_NQ)
1877 count += 2;
1878 continue;
1881 if ((atype.defined & NTA_HASINDEX) != 0)
1883 if (lane == -1)
1884 lane = atype.index;
1885 else if (lane != atype.index)
1887 first_error (_(type_error));
1888 return FAIL;
1891 else if (lane == -1)
1892 lane = NEON_INTERLEAVE_LANES;
1893 else if (lane != NEON_INTERLEAVE_LANES)
1895 first_error (_(type_error));
1896 return FAIL;
1898 count++;
1900 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1902 /* No lane set by [x]. We must be interleaving structures. */
1903 if (lane == -1)
1904 lane = NEON_INTERLEAVE_LANES;
1906 /* Sanity check. */
1907 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1908 || (count > 1 && reg_incr == -1))
1910 first_error (_("error parsing element/structure list"));
1911 return FAIL;
1914 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1916 first_error (_("expected }"));
1917 return FAIL;
1920 if (reg_incr == -1)
1921 reg_incr = 1;
1923 if (eltype)
1924 *eltype = firsttype.eltype;
1926 *pbase = base_reg;
1927 *str = ptr;
1929 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1932 /* Parse an explicit relocation suffix on an expression. This is
1933 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1934 arm_reloc_hsh contains no entries, so this function can only
1935 succeed if there is no () after the word. Returns -1 on error,
1936 BFD_RELOC_UNUSED if there wasn't any suffix. */
1937 static int
1938 parse_reloc (char **str)
1940 struct reloc_entry *r;
1941 char *p, *q;
1943 if (**str != '(')
1944 return BFD_RELOC_UNUSED;
1946 p = *str + 1;
1947 q = p;
1949 while (*q && *q != ')' && *q != ',')
1950 q++;
1951 if (*q != ')')
1952 return -1;
1954 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1955 return -1;
1957 *str = q + 1;
1958 return r->reloc;
1961 /* Directives: register aliases. */
1963 static struct reg_entry *
1964 insert_reg_alias (char *str, int number, int type)
1966 struct reg_entry *new;
1967 const char *name;
1969 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1971 if (new->builtin)
1972 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1974 /* Only warn about a redefinition if it's not defined as the
1975 same register. */
1976 else if (new->number != number || new->type != type)
1977 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1979 return NULL;
1982 name = xstrdup (str);
1983 new = xmalloc (sizeof (struct reg_entry));
1985 new->name = name;
1986 new->number = number;
1987 new->type = type;
1988 new->builtin = FALSE;
1989 new->neon = NULL;
1991 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1992 abort ();
1994 return new;
1997 static void
1998 insert_neon_reg_alias (char *str, int number, int type,
1999 struct neon_typed_alias *atype)
2001 struct reg_entry *reg = insert_reg_alias (str, number, type);
2003 if (!reg)
2005 first_error (_("attempt to redefine typed alias"));
2006 return;
2009 if (atype)
2011 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2012 *reg->neon = *atype;
2016 /* Look for the .req directive. This is of the form:
2018 new_register_name .req existing_register_name
2020 If we find one, or if it looks sufficiently like one that we want to
2021 handle any error here, return TRUE. Otherwise return FALSE. */
2023 static bfd_boolean
2024 create_register_alias (char * newname, char *p)
2026 struct reg_entry *old;
2027 char *oldname, *nbuf;
2028 size_t nlen;
2030 /* The input scrubber ensures that whitespace after the mnemonic is
2031 collapsed to single spaces. */
2032 oldname = p;
2033 if (strncmp (oldname, " .req ", 6) != 0)
2034 return FALSE;
2036 oldname += 6;
2037 if (*oldname == '\0')
2038 return FALSE;
2040 old = hash_find (arm_reg_hsh, oldname);
2041 if (!old)
2043 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2044 return TRUE;
2047 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2048 the desired alias name, and p points to its end. If not, then
2049 the desired alias name is in the global original_case_string. */
2050 #ifdef TC_CASE_SENSITIVE
2051 nlen = p - newname;
2052 #else
2053 newname = original_case_string;
2054 nlen = strlen (newname);
2055 #endif
2057 nbuf = alloca (nlen + 1);
2058 memcpy (nbuf, newname, nlen);
2059 nbuf[nlen] = '\0';
2061 /* Create aliases under the new name as stated; an all-lowercase
2062 version of the new name; and an all-uppercase version of the new
2063 name. */
2064 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2066 for (p = nbuf; *p; p++)
2067 *p = TOUPPER (*p);
2069 if (strncmp (nbuf, newname, nlen))
2071 /* If this attempt to create an additional alias fails, do not bother
2072 trying to create the all-lower case alias. We will fail and issue
2073 a second, duplicate error message. This situation arises when the
2074 programmer does something like:
2075 foo .req r0
2076 Foo .req r1
2077 The second .req creates the "Foo" alias but then fails to create
2078 the artificial FOO alias because it has already been created by the
2079 first .req. */
2080 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2081 return TRUE;
2084 for (p = nbuf; *p; p++)
2085 *p = TOLOWER (*p);
2087 if (strncmp (nbuf, newname, nlen))
2088 insert_reg_alias (nbuf, old->number, old->type);
2091 return TRUE;
2094 /* Create a Neon typed/indexed register alias using directives, e.g.:
2095 X .dn d5.s32[1]
2096 Y .qn 6.s16
2097 Z .dn d7
2098 T .dn Z[0]
2099 These typed registers can be used instead of the types specified after the
2100 Neon mnemonic, so long as all operands given have types. Types can also be
2101 specified directly, e.g.:
2102 vadd d0.s32, d1.s32, d2.s32 */
2104 static int
2105 create_neon_reg_alias (char *newname, char *p)
2107 enum arm_reg_type basetype;
2108 struct reg_entry *basereg;
2109 struct reg_entry mybasereg;
2110 struct neon_type ntype;
2111 struct neon_typed_alias typeinfo;
2112 char *namebuf, *nameend;
2113 int namelen;
2115 typeinfo.defined = 0;
2116 typeinfo.eltype.type = NT_invtype;
2117 typeinfo.eltype.size = -1;
2118 typeinfo.index = -1;
2120 nameend = p;
2122 if (strncmp (p, " .dn ", 5) == 0)
2123 basetype = REG_TYPE_VFD;
2124 else if (strncmp (p, " .qn ", 5) == 0)
2125 basetype = REG_TYPE_NQ;
2126 else
2127 return 0;
2129 p += 5;
2131 if (*p == '\0')
2132 return 0;
2134 basereg = arm_reg_parse_multi (&p);
2136 if (basereg && basereg->type != basetype)
2138 as_bad (_("bad type for register"));
2139 return 0;
2142 if (basereg == NULL)
2144 expressionS exp;
2145 /* Try parsing as an integer. */
2146 my_get_expression (&exp, &p, GE_NO_PREFIX);
2147 if (exp.X_op != O_constant)
2149 as_bad (_("expression must be constant"));
2150 return 0;
2152 basereg = &mybasereg;
2153 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2154 : exp.X_add_number;
2155 basereg->neon = 0;
2158 if (basereg->neon)
2159 typeinfo = *basereg->neon;
2161 if (parse_neon_type (&ntype, &p) == SUCCESS)
2163 /* We got a type. */
2164 if (typeinfo.defined & NTA_HASTYPE)
2166 as_bad (_("can't redefine the type of a register alias"));
2167 return 0;
2170 typeinfo.defined |= NTA_HASTYPE;
2171 if (ntype.elems != 1)
2173 as_bad (_("you must specify a single type only"));
2174 return 0;
2176 typeinfo.eltype = ntype.el[0];
2179 if (skip_past_char (&p, '[') == SUCCESS)
2181 expressionS exp;
2182 /* We got a scalar index. */
2184 if (typeinfo.defined & NTA_HASINDEX)
2186 as_bad (_("can't redefine the index of a scalar alias"));
2187 return 0;
2190 my_get_expression (&exp, &p, GE_NO_PREFIX);
2192 if (exp.X_op != O_constant)
2194 as_bad (_("scalar index must be constant"));
2195 return 0;
2198 typeinfo.defined |= NTA_HASINDEX;
2199 typeinfo.index = exp.X_add_number;
2201 if (skip_past_char (&p, ']') == FAIL)
2203 as_bad (_("expecting ]"));
2204 return 0;
2208 namelen = nameend - newname;
2209 namebuf = alloca (namelen + 1);
2210 strncpy (namebuf, newname, namelen);
2211 namebuf[namelen] = '\0';
2213 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2214 typeinfo.defined != 0 ? &typeinfo : NULL);
2216 /* Insert name in all uppercase. */
2217 for (p = namebuf; *p; p++)
2218 *p = TOUPPER (*p);
2220 if (strncmp (namebuf, newname, namelen))
2221 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2222 typeinfo.defined != 0 ? &typeinfo : NULL);
2224 /* Insert name in all lowercase. */
2225 for (p = namebuf; *p; p++)
2226 *p = TOLOWER (*p);
2228 if (strncmp (namebuf, newname, namelen))
2229 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2230 typeinfo.defined != 0 ? &typeinfo : NULL);
2232 return 1;
2235 /* Should never be called, as .req goes between the alias and the
2236 register name, not at the beginning of the line. */
2237 static void
2238 s_req (int a ATTRIBUTE_UNUSED)
2240 as_bad (_("invalid syntax for .req directive"));
2243 static void
2244 s_dn (int a ATTRIBUTE_UNUSED)
2246 as_bad (_("invalid syntax for .dn directive"));
2249 static void
2250 s_qn (int a ATTRIBUTE_UNUSED)
2252 as_bad (_("invalid syntax for .qn directive"));
2255 /* The .unreq directive deletes an alias which was previously defined
2256 by .req. For example:
2258 my_alias .req r11
2259 .unreq my_alias */
2261 static void
2262 s_unreq (int a ATTRIBUTE_UNUSED)
2264 char * name;
2265 char saved_char;
2267 name = input_line_pointer;
2269 while (*input_line_pointer != 0
2270 && *input_line_pointer != ' '
2271 && *input_line_pointer != '\n')
2272 ++input_line_pointer;
2274 saved_char = *input_line_pointer;
2275 *input_line_pointer = 0;
2277 if (!*name)
2278 as_bad (_("invalid syntax for .unreq directive"));
2279 else
2281 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2283 if (!reg)
2284 as_bad (_("unknown register alias '%s'"), name);
2285 else if (reg->builtin)
2286 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2287 name);
2288 else
2290 char * p;
2291 char * nbuf;
2293 hash_delete (arm_reg_hsh, name);
2294 free ((char *) reg->name);
2295 if (reg->neon)
2296 free (reg->neon);
2297 free (reg);
2299 /* Also locate the all upper case and all lower case versions.
2300 Do not complain if we cannot find one or the other as it
2301 was probably deleted above. */
2303 nbuf = strdup (name);
2304 for (p = nbuf; *p; p++)
2305 *p = TOUPPER (*p);
2306 reg = hash_find (arm_reg_hsh, nbuf);
2307 if (reg)
2309 hash_delete (arm_reg_hsh, nbuf);
2310 free ((char *) reg->name);
2311 if (reg->neon)
2312 free (reg->neon);
2313 free (reg);
2316 for (p = nbuf; *p; p++)
2317 *p = TOLOWER (*p);
2318 reg = hash_find (arm_reg_hsh, nbuf);
2319 if (reg)
2321 hash_delete (arm_reg_hsh, nbuf);
2322 free ((char *) reg->name);
2323 if (reg->neon)
2324 free (reg->neon);
2325 free (reg);
2328 free (nbuf);
2332 *input_line_pointer = saved_char;
2333 demand_empty_rest_of_line ();
2336 /* Directives: Instruction set selection. */
2338 #ifdef OBJ_ELF
2339 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2340 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2341 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2342 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2344 static enum mstate mapstate = MAP_UNDEFINED;
2346 void
2347 mapping_state (enum mstate state)
2349 symbolS * symbolP;
2350 const char * symname;
2351 int type;
2353 if (mapstate == state)
2354 /* The mapping symbol has already been emitted.
2355 There is nothing else to do. */
2356 return;
2358 mapstate = state;
2360 switch (state)
2362 case MAP_DATA:
2363 symname = "$d";
2364 type = BSF_NO_FLAGS;
2365 break;
2366 case MAP_ARM:
2367 symname = "$a";
2368 type = BSF_NO_FLAGS;
2369 break;
2370 case MAP_THUMB:
2371 symname = "$t";
2372 type = BSF_NO_FLAGS;
2373 break;
2374 case MAP_UNDEFINED:
2375 return;
2376 default:
2377 abort ();
2380 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2382 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2383 symbol_table_insert (symbolP);
2384 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2386 switch (state)
2388 case MAP_ARM:
2389 THUMB_SET_FUNC (symbolP, 0);
2390 ARM_SET_THUMB (symbolP, 0);
2391 ARM_SET_INTERWORK (symbolP, support_interwork);
2392 break;
2394 case MAP_THUMB:
2395 THUMB_SET_FUNC (symbolP, 1);
2396 ARM_SET_THUMB (symbolP, 1);
2397 ARM_SET_INTERWORK (symbolP, support_interwork);
2398 break;
2400 case MAP_DATA:
2401 default:
2402 return;
2405 #else
2406 #define mapping_state(x) /* nothing */
2407 #endif
2409 /* Find the real, Thumb encoded start of a Thumb function. */
2411 static symbolS *
2412 find_real_start (symbolS * symbolP)
2414 char * real_start;
2415 const char * name = S_GET_NAME (symbolP);
2416 symbolS * new_target;
2418 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2419 #define STUB_NAME ".real_start_of"
2421 if (name == NULL)
2422 abort ();
2424 /* The compiler may generate BL instructions to local labels because
2425 it needs to perform a branch to a far away location. These labels
2426 do not have a corresponding ".real_start_of" label. We check
2427 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2428 the ".real_start_of" convention for nonlocal branches. */
2429 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2430 return symbolP;
2432 real_start = ACONCAT ((STUB_NAME, name, NULL));
2433 new_target = symbol_find (real_start);
2435 if (new_target == NULL)
2437 as_warn (_("Failed to find real start of function: %s\n"), name);
2438 new_target = symbolP;
2441 return new_target;
2444 static void
2445 opcode_select (int width)
2447 switch (width)
2449 case 16:
2450 if (! thumb_mode)
2452 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2453 as_bad (_("selected processor does not support THUMB opcodes"));
2455 thumb_mode = 1;
2456 /* No need to force the alignment, since we will have been
2457 coming from ARM mode, which is word-aligned. */
2458 record_alignment (now_seg, 1);
2460 mapping_state (MAP_THUMB);
2461 break;
2463 case 32:
2464 if (thumb_mode)
2466 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2467 as_bad (_("selected processor does not support ARM opcodes"));
2469 thumb_mode = 0;
2471 if (!need_pass_2)
2472 frag_align (2, 0, 0);
2474 record_alignment (now_seg, 1);
2476 mapping_state (MAP_ARM);
2477 break;
2479 default:
2480 as_bad (_("invalid instruction size selected (%d)"), width);
2484 static void
2485 s_arm (int ignore ATTRIBUTE_UNUSED)
2487 opcode_select (32);
2488 demand_empty_rest_of_line ();
2491 static void
2492 s_thumb (int ignore ATTRIBUTE_UNUSED)
2494 opcode_select (16);
2495 demand_empty_rest_of_line ();
2498 static void
2499 s_code (int unused ATTRIBUTE_UNUSED)
2501 int temp;
2503 temp = get_absolute_expression ();
2504 switch (temp)
2506 case 16:
2507 case 32:
2508 opcode_select (temp);
2509 break;
2511 default:
2512 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2516 static void
2517 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2519 /* If we are not already in thumb mode go into it, EVEN if
2520 the target processor does not support thumb instructions.
2521 This is used by gcc/config/arm/lib1funcs.asm for example
2522 to compile interworking support functions even if the
2523 target processor should not support interworking. */
2524 if (! thumb_mode)
2526 thumb_mode = 2;
2527 record_alignment (now_seg, 1);
2530 demand_empty_rest_of_line ();
2533 static void
2534 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2536 s_thumb (0);
2538 /* The following label is the name/address of the start of a Thumb function.
2539 We need to know this for the interworking support. */
2540 label_is_thumb_function_name = TRUE;
2543 /* Perform a .set directive, but also mark the alias as
2544 being a thumb function. */
2546 static void
2547 s_thumb_set (int equiv)
2549 /* XXX the following is a duplicate of the code for s_set() in read.c
2550 We cannot just call that code as we need to get at the symbol that
2551 is created. */
2552 char * name;
2553 char delim;
2554 char * end_name;
2555 symbolS * symbolP;
2557 /* Especial apologies for the random logic:
2558 This just grew, and could be parsed much more simply!
2559 Dean - in haste. */
2560 name = input_line_pointer;
2561 delim = get_symbol_end ();
2562 end_name = input_line_pointer;
2563 *end_name = delim;
2565 if (*input_line_pointer != ',')
2567 *end_name = 0;
2568 as_bad (_("expected comma after name \"%s\""), name);
2569 *end_name = delim;
2570 ignore_rest_of_line ();
2571 return;
2574 input_line_pointer++;
2575 *end_name = 0;
2577 if (name[0] == '.' && name[1] == '\0')
2579 /* XXX - this should not happen to .thumb_set. */
2580 abort ();
2583 if ((symbolP = symbol_find (name)) == NULL
2584 && (symbolP = md_undefined_symbol (name)) == NULL)
2586 #ifndef NO_LISTING
2587 /* When doing symbol listings, play games with dummy fragments living
2588 outside the normal fragment chain to record the file and line info
2589 for this symbol. */
2590 if (listing & LISTING_SYMBOLS)
2592 extern struct list_info_struct * listing_tail;
2593 fragS * dummy_frag = xmalloc (sizeof (fragS));
2595 memset (dummy_frag, 0, sizeof (fragS));
2596 dummy_frag->fr_type = rs_fill;
2597 dummy_frag->line = listing_tail;
2598 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2599 dummy_frag->fr_symbol = symbolP;
2601 else
2602 #endif
2603 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2605 #ifdef OBJ_COFF
2606 /* "set" symbols are local unless otherwise specified. */
2607 SF_SET_LOCAL (symbolP);
2608 #endif /* OBJ_COFF */
2609 } /* Make a new symbol. */
2611 symbol_table_insert (symbolP);
2613 * end_name = delim;
2615 if (equiv
2616 && S_IS_DEFINED (symbolP)
2617 && S_GET_SEGMENT (symbolP) != reg_section)
2618 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2620 pseudo_set (symbolP);
2622 demand_empty_rest_of_line ();
2624 /* XXX Now we come to the Thumb specific bit of code. */
2626 THUMB_SET_FUNC (symbolP, 1);
2627 ARM_SET_THUMB (symbolP, 1);
2628 #if defined OBJ_ELF || defined OBJ_COFF
2629 ARM_SET_INTERWORK (symbolP, support_interwork);
2630 #endif
2633 /* Directives: Mode selection. */
2635 /* .syntax [unified|divided] - choose the new unified syntax
2636 (same for Arm and Thumb encoding, modulo slight differences in what
2637 can be represented) or the old divergent syntax for each mode. */
2638 static void
2639 s_syntax (int unused ATTRIBUTE_UNUSED)
2641 char *name, delim;
2643 name = input_line_pointer;
2644 delim = get_symbol_end ();
2646 if (!strcasecmp (name, "unified"))
2647 unified_syntax = TRUE;
2648 else if (!strcasecmp (name, "divided"))
2649 unified_syntax = FALSE;
2650 else
2652 as_bad (_("unrecognized syntax mode \"%s\""), name);
2653 return;
2655 *input_line_pointer = delim;
2656 demand_empty_rest_of_line ();
2659 /* Directives: sectioning and alignment. */
2661 /* Same as s_align_ptwo but align 0 => align 2. */
2663 static void
2664 s_align (int unused ATTRIBUTE_UNUSED)
2666 int temp;
2667 bfd_boolean fill_p;
2668 long temp_fill;
2669 long max_alignment = 15;
2671 temp = get_absolute_expression ();
2672 if (temp > max_alignment)
2673 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2674 else if (temp < 0)
2676 as_bad (_("alignment negative. 0 assumed."));
2677 temp = 0;
2680 if (*input_line_pointer == ',')
2682 input_line_pointer++;
2683 temp_fill = get_absolute_expression ();
2684 fill_p = TRUE;
2686 else
2688 fill_p = FALSE;
2689 temp_fill = 0;
2692 if (!temp)
2693 temp = 2;
2695 /* Only make a frag if we HAVE to. */
2696 if (temp && !need_pass_2)
2698 if (!fill_p && subseg_text_p (now_seg))
2699 frag_align_code (temp, 0);
2700 else
2701 frag_align (temp, (int) temp_fill, 0);
2703 demand_empty_rest_of_line ();
2705 record_alignment (now_seg, temp);
2708 static void
2709 s_bss (int ignore ATTRIBUTE_UNUSED)
2711 /* We don't support putting frags in the BSS segment, we fake it by
2712 marking in_bss, then looking at s_skip for clues. */
2713 subseg_set (bss_section, 0);
2714 demand_empty_rest_of_line ();
2715 mapping_state (MAP_DATA);
2718 static void
2719 s_even (int ignore ATTRIBUTE_UNUSED)
2721 /* Never make frag if expect extra pass. */
2722 if (!need_pass_2)
2723 frag_align (1, 0, 0);
2725 record_alignment (now_seg, 1);
2727 demand_empty_rest_of_line ();
2730 /* Directives: Literal pools. */
2732 static literal_pool *
2733 find_literal_pool (void)
2735 literal_pool * pool;
2737 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2739 if (pool->section == now_seg
2740 && pool->sub_section == now_subseg)
2741 break;
2744 return pool;
2747 static literal_pool *
2748 find_or_make_literal_pool (void)
2750 /* Next literal pool ID number. */
2751 static unsigned int latest_pool_num = 1;
2752 literal_pool * pool;
2754 pool = find_literal_pool ();
2756 if (pool == NULL)
2758 /* Create a new pool. */
2759 pool = xmalloc (sizeof (* pool));
2760 if (! pool)
2761 return NULL;
2763 pool->next_free_entry = 0;
2764 pool->section = now_seg;
2765 pool->sub_section = now_subseg;
2766 pool->next = list_of_pools;
2767 pool->symbol = NULL;
2769 /* Add it to the list. */
2770 list_of_pools = pool;
2773 /* New pools, and emptied pools, will have a NULL symbol. */
2774 if (pool->symbol == NULL)
2776 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2777 (valueT) 0, &zero_address_frag);
2778 pool->id = latest_pool_num ++;
2781 /* Done. */
2782 return pool;
2785 /* Add the literal in the global 'inst'
2786 structure to the relevant literal pool. */
2788 static int
2789 add_to_lit_pool (void)
2791 literal_pool * pool;
2792 unsigned int entry;
2794 pool = find_or_make_literal_pool ();
2796 /* Check if this literal value is already in the pool. */
2797 for (entry = 0; entry < pool->next_free_entry; entry ++)
2799 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2800 && (inst.reloc.exp.X_op == O_constant)
2801 && (pool->literals[entry].X_add_number
2802 == inst.reloc.exp.X_add_number)
2803 && (pool->literals[entry].X_unsigned
2804 == inst.reloc.exp.X_unsigned))
2805 break;
2807 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2808 && (inst.reloc.exp.X_op == O_symbol)
2809 && (pool->literals[entry].X_add_number
2810 == inst.reloc.exp.X_add_number)
2811 && (pool->literals[entry].X_add_symbol
2812 == inst.reloc.exp.X_add_symbol)
2813 && (pool->literals[entry].X_op_symbol
2814 == inst.reloc.exp.X_op_symbol))
2815 break;
2818 /* Do we need to create a new entry? */
2819 if (entry == pool->next_free_entry)
2821 if (entry >= MAX_LITERAL_POOL_SIZE)
2823 inst.error = _("literal pool overflow");
2824 return FAIL;
2827 pool->literals[entry] = inst.reloc.exp;
2828 pool->next_free_entry += 1;
2831 inst.reloc.exp.X_op = O_symbol;
2832 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2833 inst.reloc.exp.X_add_symbol = pool->symbol;
2835 return SUCCESS;
2838 /* Can't use symbol_new here, so have to create a symbol and then at
2839 a later date assign it a value. Thats what these functions do. */
2841 static void
2842 symbol_locate (symbolS * symbolP,
2843 const char * name, /* It is copied, the caller can modify. */
2844 segT segment, /* Segment identifier (SEG_<something>). */
2845 valueT valu, /* Symbol value. */
2846 fragS * frag) /* Associated fragment. */
2848 unsigned int name_length;
2849 char * preserved_copy_of_name;
2851 name_length = strlen (name) + 1; /* +1 for \0. */
2852 obstack_grow (&notes, name, name_length);
2853 preserved_copy_of_name = obstack_finish (&notes);
2855 #ifdef tc_canonicalize_symbol_name
2856 preserved_copy_of_name =
2857 tc_canonicalize_symbol_name (preserved_copy_of_name);
2858 #endif
2860 S_SET_NAME (symbolP, preserved_copy_of_name);
2862 S_SET_SEGMENT (symbolP, segment);
2863 S_SET_VALUE (symbolP, valu);
2864 symbol_clear_list_pointers (symbolP);
2866 symbol_set_frag (symbolP, frag);
2868 /* Link to end of symbol chain. */
2870 extern int symbol_table_frozen;
2872 if (symbol_table_frozen)
2873 abort ();
2876 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2878 obj_symbol_new_hook (symbolP);
2880 #ifdef tc_symbol_new_hook
2881 tc_symbol_new_hook (symbolP);
2882 #endif
2884 #ifdef DEBUG_SYMS
2885 verify_symbol_chain (symbol_rootP, symbol_lastP);
2886 #endif /* DEBUG_SYMS */
2890 static void
2891 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2893 unsigned int entry;
2894 literal_pool * pool;
2895 char sym_name[20];
2897 pool = find_literal_pool ();
2898 if (pool == NULL
2899 || pool->symbol == NULL
2900 || pool->next_free_entry == 0)
2901 return;
2903 mapping_state (MAP_DATA);
2905 /* Align pool as you have word accesses.
2906 Only make a frag if we have to. */
2907 if (!need_pass_2)
2908 frag_align (2, 0, 0);
2910 record_alignment (now_seg, 2);
2912 sprintf (sym_name, "$$lit_\002%x", pool->id);
2914 symbol_locate (pool->symbol, sym_name, now_seg,
2915 (valueT) frag_now_fix (), frag_now);
2916 symbol_table_insert (pool->symbol);
2918 ARM_SET_THUMB (pool->symbol, thumb_mode);
2920 #if defined OBJ_COFF || defined OBJ_ELF
2921 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2922 #endif
2924 for (entry = 0; entry < pool->next_free_entry; entry ++)
2925 /* First output the expression in the instruction to the pool. */
2926 emit_expr (&(pool->literals[entry]), 4); /* .word */
2928 /* Mark the pool as empty. */
2929 pool->next_free_entry = 0;
2930 pool->symbol = NULL;
2933 #ifdef OBJ_ELF
2934 /* Forward declarations for functions below, in the MD interface
2935 section. */
2936 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2937 static valueT create_unwind_entry (int);
2938 static void start_unwind_section (const segT, int);
2939 static void add_unwind_opcode (valueT, int);
2940 static void flush_pending_unwind (void);
2942 /* Directives: Data. */
2944 static void
2945 s_arm_elf_cons (int nbytes)
2947 expressionS exp;
2949 #ifdef md_flush_pending_output
2950 md_flush_pending_output ();
2951 #endif
2953 if (is_it_end_of_statement ())
2955 demand_empty_rest_of_line ();
2956 return;
2959 #ifdef md_cons_align
2960 md_cons_align (nbytes);
2961 #endif
2963 mapping_state (MAP_DATA);
2966 int reloc;
2967 char *base = input_line_pointer;
2969 expression (& exp);
2971 if (exp.X_op != O_symbol)
2972 emit_expr (&exp, (unsigned int) nbytes);
2973 else
2975 char *before_reloc = input_line_pointer;
2976 reloc = parse_reloc (&input_line_pointer);
2977 if (reloc == -1)
2979 as_bad (_("unrecognized relocation suffix"));
2980 ignore_rest_of_line ();
2981 return;
2983 else if (reloc == BFD_RELOC_UNUSED)
2984 emit_expr (&exp, (unsigned int) nbytes);
2985 else
2987 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2988 int size = bfd_get_reloc_size (howto);
2990 if (reloc == BFD_RELOC_ARM_PLT32)
2992 as_bad (_("(plt) is only valid on branch targets"));
2993 reloc = BFD_RELOC_UNUSED;
2994 size = 0;
2997 if (size > nbytes)
2998 as_bad (_("%s relocations do not fit in %d bytes"),
2999 howto->name, nbytes);
3000 else
3002 /* We've parsed an expression stopping at O_symbol.
3003 But there may be more expression left now that we
3004 have parsed the relocation marker. Parse it again.
3005 XXX Surely there is a cleaner way to do this. */
3006 char *p = input_line_pointer;
3007 int offset;
3008 char *save_buf = alloca (input_line_pointer - base);
3009 memcpy (save_buf, base, input_line_pointer - base);
3010 memmove (base + (input_line_pointer - before_reloc),
3011 base, before_reloc - base);
3013 input_line_pointer = base + (input_line_pointer-before_reloc);
3014 expression (&exp);
3015 memcpy (base, save_buf, p - base);
3017 offset = nbytes - size;
3018 p = frag_more ((int) nbytes);
3019 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3020 size, &exp, 0, reloc);
3025 while (*input_line_pointer++ == ',');
3027 /* Put terminator back into stream. */
3028 input_line_pointer --;
3029 demand_empty_rest_of_line ();
3033 /* Parse a .rel31 directive. */
3035 static void
3036 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3038 expressionS exp;
3039 char *p;
3040 valueT highbit;
3042 highbit = 0;
3043 if (*input_line_pointer == '1')
3044 highbit = 0x80000000;
3045 else if (*input_line_pointer != '0')
3046 as_bad (_("expected 0 or 1"));
3048 input_line_pointer++;
3049 if (*input_line_pointer != ',')
3050 as_bad (_("missing comma"));
3051 input_line_pointer++;
3053 #ifdef md_flush_pending_output
3054 md_flush_pending_output ();
3055 #endif
3057 #ifdef md_cons_align
3058 md_cons_align (4);
3059 #endif
3061 mapping_state (MAP_DATA);
3063 expression (&exp);
3065 p = frag_more (4);
3066 md_number_to_chars (p, highbit, 4);
3067 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3068 BFD_RELOC_ARM_PREL31);
3070 demand_empty_rest_of_line ();
3073 /* Directives: AEABI stack-unwind tables. */
3075 /* Parse an unwind_fnstart directive. Simply records the current location. */
3077 static void
3078 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3080 demand_empty_rest_of_line ();
3081 /* Mark the start of the function. */
3082 unwind.proc_start = expr_build_dot ();
3084 /* Reset the rest of the unwind info. */
3085 unwind.opcode_count = 0;
3086 unwind.table_entry = NULL;
3087 unwind.personality_routine = NULL;
3088 unwind.personality_index = -1;
3089 unwind.frame_size = 0;
3090 unwind.fp_offset = 0;
3091 unwind.fp_reg = 13;
3092 unwind.fp_used = 0;
3093 unwind.sp_restored = 0;
3097 /* Parse a handlerdata directive. Creates the exception handling table entry
3098 for the function. */
3100 static void
3101 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3103 demand_empty_rest_of_line ();
3104 if (unwind.table_entry)
3105 as_bad (_("duplicate .handlerdata directive"));
3107 create_unwind_entry (1);
3110 /* Parse an unwind_fnend directive. Generates the index table entry. */
3112 static void
3113 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3115 long where;
3116 char *ptr;
3117 valueT val;
3119 demand_empty_rest_of_line ();
3121 /* Add eh table entry. */
3122 if (unwind.table_entry == NULL)
3123 val = create_unwind_entry (0);
3124 else
3125 val = 0;
3127 /* Add index table entry. This is two words. */
3128 start_unwind_section (unwind.saved_seg, 1);
3129 frag_align (2, 0, 0);
3130 record_alignment (now_seg, 2);
3132 ptr = frag_more (8);
3133 where = frag_now_fix () - 8;
3135 /* Self relative offset of the function start. */
3136 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3137 BFD_RELOC_ARM_PREL31);
3139 /* Indicate dependency on EHABI-defined personality routines to the
3140 linker, if it hasn't been done already. */
3141 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3142 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3144 static const char *const name[] =
3146 "__aeabi_unwind_cpp_pr0",
3147 "__aeabi_unwind_cpp_pr1",
3148 "__aeabi_unwind_cpp_pr2"
3150 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3151 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3152 marked_pr_dependency |= 1 << unwind.personality_index;
3153 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3154 = marked_pr_dependency;
3157 if (val)
3158 /* Inline exception table entry. */
3159 md_number_to_chars (ptr + 4, val, 4);
3160 else
3161 /* Self relative offset of the table entry. */
3162 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3163 BFD_RELOC_ARM_PREL31);
3165 /* Restore the original section. */
3166 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3170 /* Parse an unwind_cantunwind directive. */
3172 static void
3173 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3175 demand_empty_rest_of_line ();
3176 if (unwind.personality_routine || unwind.personality_index != -1)
3177 as_bad (_("personality routine specified for cantunwind frame"));
3179 unwind.personality_index = -2;
3183 /* Parse a personalityindex directive. */
3185 static void
3186 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3188 expressionS exp;
3190 if (unwind.personality_routine || unwind.personality_index != -1)
3191 as_bad (_("duplicate .personalityindex directive"));
3193 expression (&exp);
3195 if (exp.X_op != O_constant
3196 || exp.X_add_number < 0 || exp.X_add_number > 15)
3198 as_bad (_("bad personality routine number"));
3199 ignore_rest_of_line ();
3200 return;
3203 unwind.personality_index = exp.X_add_number;
3205 demand_empty_rest_of_line ();
3209 /* Parse a personality directive. */
3211 static void
3212 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3214 char *name, *p, c;
3216 if (unwind.personality_routine || unwind.personality_index != -1)
3217 as_bad (_("duplicate .personality directive"));
3219 name = input_line_pointer;
3220 c = get_symbol_end ();
3221 p = input_line_pointer;
3222 unwind.personality_routine = symbol_find_or_make (name);
3223 *p = c;
3224 demand_empty_rest_of_line ();
3228 /* Parse a directive saving core registers. */
3230 static void
3231 s_arm_unwind_save_core (void)
3233 valueT op;
3234 long range;
3235 int n;
3237 range = parse_reg_list (&input_line_pointer);
3238 if (range == FAIL)
3240 as_bad (_("expected register list"));
3241 ignore_rest_of_line ();
3242 return;
3245 demand_empty_rest_of_line ();
3247 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3248 into .unwind_save {..., sp...}. We aren't bothered about the value of
3249 ip because it is clobbered by calls. */
3250 if (unwind.sp_restored && unwind.fp_reg == 12
3251 && (range & 0x3000) == 0x1000)
3253 unwind.opcode_count--;
3254 unwind.sp_restored = 0;
3255 range = (range | 0x2000) & ~0x1000;
3256 unwind.pending_offset = 0;
3259 /* Pop r4-r15. */
3260 if (range & 0xfff0)
3262 /* See if we can use the short opcodes. These pop a block of up to 8
3263 registers starting with r4, plus maybe r14. */
3264 for (n = 0; n < 8; n++)
3266 /* Break at the first non-saved register. */
3267 if ((range & (1 << (n + 4))) == 0)
3268 break;
3270 /* See if there are any other bits set. */
3271 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3273 /* Use the long form. */
3274 op = 0x8000 | ((range >> 4) & 0xfff);
3275 add_unwind_opcode (op, 2);
3277 else
3279 /* Use the short form. */
3280 if (range & 0x4000)
3281 op = 0xa8; /* Pop r14. */
3282 else
3283 op = 0xa0; /* Do not pop r14. */
3284 op |= (n - 1);
3285 add_unwind_opcode (op, 1);
3289 /* Pop r0-r3. */
3290 if (range & 0xf)
3292 op = 0xb100 | (range & 0xf);
3293 add_unwind_opcode (op, 2);
3296 /* Record the number of bytes pushed. */
3297 for (n = 0; n < 16; n++)
3299 if (range & (1 << n))
3300 unwind.frame_size += 4;
3305 /* Parse a directive saving FPA registers. */
3307 static void
3308 s_arm_unwind_save_fpa (int reg)
3310 expressionS exp;
3311 int num_regs;
3312 valueT op;
3314 /* Get Number of registers to transfer. */
3315 if (skip_past_comma (&input_line_pointer) != FAIL)
3316 expression (&exp);
3317 else
3318 exp.X_op = O_illegal;
3320 if (exp.X_op != O_constant)
3322 as_bad (_("expected , <constant>"));
3323 ignore_rest_of_line ();
3324 return;
3327 num_regs = exp.X_add_number;
3329 if (num_regs < 1 || num_regs > 4)
3331 as_bad (_("number of registers must be in the range [1:4]"));
3332 ignore_rest_of_line ();
3333 return;
3336 demand_empty_rest_of_line ();
3338 if (reg == 4)
3340 /* Short form. */
3341 op = 0xb4 | (num_regs - 1);
3342 add_unwind_opcode (op, 1);
3344 else
3346 /* Long form. */
3347 op = 0xc800 | (reg << 4) | (num_regs - 1);
3348 add_unwind_opcode (op, 2);
3350 unwind.frame_size += num_regs * 12;
3354 /* Parse a directive saving VFP registers for ARMv6 and above. */
3356 static void
3357 s_arm_unwind_save_vfp_armv6 (void)
3359 int count;
3360 unsigned int start;
3361 valueT op;
3362 int num_vfpv3_regs = 0;
3363 int num_regs_below_16;
3365 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3366 if (count == FAIL)
3368 as_bad (_("expected register list"));
3369 ignore_rest_of_line ();
3370 return;
3373 demand_empty_rest_of_line ();
3375 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3376 than FSTMX/FLDMX-style ones). */
3378 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3379 if (start >= 16)
3380 num_vfpv3_regs = count;
3381 else if (start + count > 16)
3382 num_vfpv3_regs = start + count - 16;
3384 if (num_vfpv3_regs > 0)
3386 int start_offset = start > 16 ? start - 16 : 0;
3387 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3388 add_unwind_opcode (op, 2);
3391 /* Generate opcode for registers numbered in the range 0 .. 15. */
3392 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3393 assert (num_regs_below_16 + num_vfpv3_regs == count);
3394 if (num_regs_below_16 > 0)
3396 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3397 add_unwind_opcode (op, 2);
3400 unwind.frame_size += count * 8;
3404 /* Parse a directive saving VFP registers for pre-ARMv6. */
3406 static void
3407 s_arm_unwind_save_vfp (void)
3409 int count;
3410 unsigned int reg;
3411 valueT op;
3413 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3414 if (count == FAIL)
3416 as_bad (_("expected register list"));
3417 ignore_rest_of_line ();
3418 return;
3421 demand_empty_rest_of_line ();
3423 if (reg == 8)
3425 /* Short form. */
3426 op = 0xb8 | (count - 1);
3427 add_unwind_opcode (op, 1);
3429 else
3431 /* Long form. */
3432 op = 0xb300 | (reg << 4) | (count - 1);
3433 add_unwind_opcode (op, 2);
3435 unwind.frame_size += count * 8 + 4;
3439 /* Parse a directive saving iWMMXt data registers. */
3441 static void
3442 s_arm_unwind_save_mmxwr (void)
3444 int reg;
3445 int hi_reg;
3446 int i;
3447 unsigned mask = 0;
3448 valueT op;
3450 if (*input_line_pointer == '{')
3451 input_line_pointer++;
3455 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3457 if (reg == FAIL)
3459 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3460 goto error;
3463 if (mask >> reg)
3464 as_tsktsk (_("register list not in ascending order"));
3465 mask |= 1 << reg;
3467 if (*input_line_pointer == '-')
3469 input_line_pointer++;
3470 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3471 if (hi_reg == FAIL)
3473 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3474 goto error;
3476 else if (reg >= hi_reg)
3478 as_bad (_("bad register range"));
3479 goto error;
3481 for (; reg < hi_reg; reg++)
3482 mask |= 1 << reg;
3485 while (skip_past_comma (&input_line_pointer) != FAIL);
3487 if (*input_line_pointer == '}')
3488 input_line_pointer++;
3490 demand_empty_rest_of_line ();
3492 /* Generate any deferred opcodes because we're going to be looking at
3493 the list. */
3494 flush_pending_unwind ();
3496 for (i = 0; i < 16; i++)
3498 if (mask & (1 << i))
3499 unwind.frame_size += 8;
3502 /* Attempt to combine with a previous opcode. We do this because gcc
3503 likes to output separate unwind directives for a single block of
3504 registers. */
3505 if (unwind.opcode_count > 0)
3507 i = unwind.opcodes[unwind.opcode_count - 1];
3508 if ((i & 0xf8) == 0xc0)
3510 i &= 7;
3511 /* Only merge if the blocks are contiguous. */
3512 if (i < 6)
3514 if ((mask & 0xfe00) == (1 << 9))
3516 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3517 unwind.opcode_count--;
3520 else if (i == 6 && unwind.opcode_count >= 2)
3522 i = unwind.opcodes[unwind.opcode_count - 2];
3523 reg = i >> 4;
3524 i &= 0xf;
3526 op = 0xffff << (reg - 1);
3527 if (reg > 0
3528 && ((mask & op) == (1u << (reg - 1))))
3530 op = (1 << (reg + i + 1)) - 1;
3531 op &= ~((1 << reg) - 1);
3532 mask |= op;
3533 unwind.opcode_count -= 2;
3539 hi_reg = 15;
3540 /* We want to generate opcodes in the order the registers have been
3541 saved, ie. descending order. */
3542 for (reg = 15; reg >= -1; reg--)
3544 /* Save registers in blocks. */
3545 if (reg < 0
3546 || !(mask & (1 << reg)))
3548 /* We found an unsaved reg. Generate opcodes to save the
3549 preceding block. */
3550 if (reg != hi_reg)
3552 if (reg == 9)
3554 /* Short form. */
3555 op = 0xc0 | (hi_reg - 10);
3556 add_unwind_opcode (op, 1);
3558 else
3560 /* Long form. */
3561 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3562 add_unwind_opcode (op, 2);
3565 hi_reg = reg - 1;
3569 return;
3570 error:
3571 ignore_rest_of_line ();
3574 static void
3575 s_arm_unwind_save_mmxwcg (void)
3577 int reg;
3578 int hi_reg;
3579 unsigned mask = 0;
3580 valueT op;
3582 if (*input_line_pointer == '{')
3583 input_line_pointer++;
3587 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3589 if (reg == FAIL)
3591 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3592 goto error;
3595 reg -= 8;
3596 if (mask >> reg)
3597 as_tsktsk (_("register list not in ascending order"));
3598 mask |= 1 << reg;
3600 if (*input_line_pointer == '-')
3602 input_line_pointer++;
3603 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3604 if (hi_reg == FAIL)
3606 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3607 goto error;
3609 else if (reg >= hi_reg)
3611 as_bad (_("bad register range"));
3612 goto error;
3614 for (; reg < hi_reg; reg++)
3615 mask |= 1 << reg;
3618 while (skip_past_comma (&input_line_pointer) != FAIL);
3620 if (*input_line_pointer == '}')
3621 input_line_pointer++;
3623 demand_empty_rest_of_line ();
3625 /* Generate any deferred opcodes because we're going to be looking at
3626 the list. */
3627 flush_pending_unwind ();
3629 for (reg = 0; reg < 16; reg++)
3631 if (mask & (1 << reg))
3632 unwind.frame_size += 4;
3634 op = 0xc700 | mask;
3635 add_unwind_opcode (op, 2);
3636 return;
3637 error:
3638 ignore_rest_of_line ();
3642 /* Parse an unwind_save directive.
3643 If the argument is non-zero, this is a .vsave directive. */
3645 static void
3646 s_arm_unwind_save (int arch_v6)
3648 char *peek;
3649 struct reg_entry *reg;
3650 bfd_boolean had_brace = FALSE;
3652 /* Figure out what sort of save we have. */
3653 peek = input_line_pointer;
3655 if (*peek == '{')
3657 had_brace = TRUE;
3658 peek++;
3661 reg = arm_reg_parse_multi (&peek);
3663 if (!reg)
3665 as_bad (_("register expected"));
3666 ignore_rest_of_line ();
3667 return;
3670 switch (reg->type)
3672 case REG_TYPE_FN:
3673 if (had_brace)
3675 as_bad (_("FPA .unwind_save does not take a register list"));
3676 ignore_rest_of_line ();
3677 return;
3679 input_line_pointer = peek;
3680 s_arm_unwind_save_fpa (reg->number);
3681 return;
3683 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3684 case REG_TYPE_VFD:
3685 if (arch_v6)
3686 s_arm_unwind_save_vfp_armv6 ();
3687 else
3688 s_arm_unwind_save_vfp ();
3689 return;
3690 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3691 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3693 default:
3694 as_bad (_(".unwind_save does not support this kind of register"));
3695 ignore_rest_of_line ();
3700 /* Parse an unwind_movsp directive. */
3702 static void
3703 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3705 int reg;
3706 valueT op;
3707 int offset;
3709 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3710 if (reg == FAIL)
3712 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3713 ignore_rest_of_line ();
3714 return;
3717 /* Optional constant. */
3718 if (skip_past_comma (&input_line_pointer) != FAIL)
3720 if (immediate_for_directive (&offset) == FAIL)
3721 return;
3723 else
3724 offset = 0;
3726 demand_empty_rest_of_line ();
3728 if (reg == REG_SP || reg == REG_PC)
3730 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3731 return;
3734 if (unwind.fp_reg != REG_SP)
3735 as_bad (_("unexpected .unwind_movsp directive"));
3737 /* Generate opcode to restore the value. */
3738 op = 0x90 | reg;
3739 add_unwind_opcode (op, 1);
3741 /* Record the information for later. */
3742 unwind.fp_reg = reg;
3743 unwind.fp_offset = unwind.frame_size - offset;
3744 unwind.sp_restored = 1;
3747 /* Parse an unwind_pad directive. */
3749 static void
3750 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3752 int offset;
3754 if (immediate_for_directive (&offset) == FAIL)
3755 return;
3757 if (offset & 3)
3759 as_bad (_("stack increment must be multiple of 4"));
3760 ignore_rest_of_line ();
3761 return;
3764 /* Don't generate any opcodes, just record the details for later. */
3765 unwind.frame_size += offset;
3766 unwind.pending_offset += offset;
3768 demand_empty_rest_of_line ();
3771 /* Parse an unwind_setfp directive. */
3773 static void
3774 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3776 int sp_reg;
3777 int fp_reg;
3778 int offset;
3780 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3781 if (skip_past_comma (&input_line_pointer) == FAIL)
3782 sp_reg = FAIL;
3783 else
3784 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3786 if (fp_reg == FAIL || sp_reg == FAIL)
3788 as_bad (_("expected <reg>, <reg>"));
3789 ignore_rest_of_line ();
3790 return;
3793 /* Optional constant. */
3794 if (skip_past_comma (&input_line_pointer) != FAIL)
3796 if (immediate_for_directive (&offset) == FAIL)
3797 return;
3799 else
3800 offset = 0;
3802 demand_empty_rest_of_line ();
3804 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
3806 as_bad (_("register must be either sp or set by a previous"
3807 "unwind_movsp directive"));
3808 return;
3811 /* Don't generate any opcodes, just record the information for later. */
3812 unwind.fp_reg = fp_reg;
3813 unwind.fp_used = 1;
3814 if (sp_reg == 13)
3815 unwind.fp_offset = unwind.frame_size - offset;
3816 else
3817 unwind.fp_offset -= offset;
3820 /* Parse an unwind_raw directive. */
3822 static void
3823 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3825 expressionS exp;
3826 /* This is an arbitrary limit. */
3827 unsigned char op[16];
3828 int count;
3830 expression (&exp);
3831 if (exp.X_op == O_constant
3832 && skip_past_comma (&input_line_pointer) != FAIL)
3834 unwind.frame_size += exp.X_add_number;
3835 expression (&exp);
3837 else
3838 exp.X_op = O_illegal;
3840 if (exp.X_op != O_constant)
3842 as_bad (_("expected <offset>, <opcode>"));
3843 ignore_rest_of_line ();
3844 return;
3847 count = 0;
3849 /* Parse the opcode. */
3850 for (;;)
3852 if (count >= 16)
3854 as_bad (_("unwind opcode too long"));
3855 ignore_rest_of_line ();
3857 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3859 as_bad (_("invalid unwind opcode"));
3860 ignore_rest_of_line ();
3861 return;
3863 op[count++] = exp.X_add_number;
3865 /* Parse the next byte. */
3866 if (skip_past_comma (&input_line_pointer) == FAIL)
3867 break;
3869 expression (&exp);
3872 /* Add the opcode bytes in reverse order. */
3873 while (count--)
3874 add_unwind_opcode (op[count], 1);
3876 demand_empty_rest_of_line ();
3880 /* Parse a .eabi_attribute directive. */
3882 static void
3883 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3885 s_vendor_attribute (OBJ_ATTR_PROC);
3887 #endif /* OBJ_ELF */
3889 static void s_arm_arch (int);
3890 static void s_arm_object_arch (int);
3891 static void s_arm_cpu (int);
3892 static void s_arm_fpu (int);
3894 #ifdef TE_PE
3896 static void
3897 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3899 expressionS exp;
3903 expression (&exp);
3904 if (exp.X_op == O_symbol)
3905 exp.X_op = O_secrel;
3907 emit_expr (&exp, 4);
3909 while (*input_line_pointer++ == ',');
3911 input_line_pointer--;
3912 demand_empty_rest_of_line ();
3914 #endif /* TE_PE */
3916 /* This table describes all the machine specific pseudo-ops the assembler
3917 has to support. The fields are:
3918 pseudo-op name without dot
3919 function to call to execute this pseudo-op
3920 Integer arg to pass to the function. */
3922 const pseudo_typeS md_pseudo_table[] =
3924 /* Never called because '.req' does not start a line. */
3925 { "req", s_req, 0 },
3926 /* Following two are likewise never called. */
3927 { "dn", s_dn, 0 },
3928 { "qn", s_qn, 0 },
3929 { "unreq", s_unreq, 0 },
3930 { "bss", s_bss, 0 },
3931 { "align", s_align, 0 },
3932 { "arm", s_arm, 0 },
3933 { "thumb", s_thumb, 0 },
3934 { "code", s_code, 0 },
3935 { "force_thumb", s_force_thumb, 0 },
3936 { "thumb_func", s_thumb_func, 0 },
3937 { "thumb_set", s_thumb_set, 0 },
3938 { "even", s_even, 0 },
3939 { "ltorg", s_ltorg, 0 },
3940 { "pool", s_ltorg, 0 },
3941 { "syntax", s_syntax, 0 },
3942 { "cpu", s_arm_cpu, 0 },
3943 { "arch", s_arm_arch, 0 },
3944 { "object_arch", s_arm_object_arch, 0 },
3945 { "fpu", s_arm_fpu, 0 },
3946 #ifdef OBJ_ELF
3947 { "word", s_arm_elf_cons, 4 },
3948 { "long", s_arm_elf_cons, 4 },
3949 { "rel31", s_arm_rel31, 0 },
3950 { "fnstart", s_arm_unwind_fnstart, 0 },
3951 { "fnend", s_arm_unwind_fnend, 0 },
3952 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3953 { "personality", s_arm_unwind_personality, 0 },
3954 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3955 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3956 { "save", s_arm_unwind_save, 0 },
3957 { "vsave", s_arm_unwind_save, 1 },
3958 { "movsp", s_arm_unwind_movsp, 0 },
3959 { "pad", s_arm_unwind_pad, 0 },
3960 { "setfp", s_arm_unwind_setfp, 0 },
3961 { "unwind_raw", s_arm_unwind_raw, 0 },
3962 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3963 #else
3964 { "word", cons, 4},
3966 /* These are used for dwarf. */
3967 {"2byte", cons, 2},
3968 {"4byte", cons, 4},
3969 {"8byte", cons, 8},
3970 /* These are used for dwarf2. */
3971 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3972 { "loc", dwarf2_directive_loc, 0 },
3973 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
3974 #endif
3975 { "extend", float_cons, 'x' },
3976 { "ldouble", float_cons, 'x' },
3977 { "packed", float_cons, 'p' },
3978 #ifdef TE_PE
3979 {"secrel32", pe_directive_secrel, 0},
3980 #endif
3981 { 0, 0, 0 }
3984 /* Parser functions used exclusively in instruction operands. */
3986 /* Generic immediate-value read function for use in insn parsing.
3987 STR points to the beginning of the immediate (the leading #);
3988 VAL receives the value; if the value is outside [MIN, MAX]
3989 issue an error. PREFIX_OPT is true if the immediate prefix is
3990 optional. */
3992 static int
3993 parse_immediate (char **str, int *val, int min, int max,
3994 bfd_boolean prefix_opt)
3996 expressionS exp;
3997 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3998 if (exp.X_op != O_constant)
4000 inst.error = _("constant expression required");
4001 return FAIL;
4004 if (exp.X_add_number < min || exp.X_add_number > max)
4006 inst.error = _("immediate value out of range");
4007 return FAIL;
4010 *val = exp.X_add_number;
4011 return SUCCESS;
4014 /* Less-generic immediate-value read function with the possibility of loading a
4015 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4016 instructions. Puts the result directly in inst.operands[i]. */
4018 static int
4019 parse_big_immediate (char **str, int i)
4021 expressionS exp;
4022 char *ptr = *str;
4024 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4026 if (exp.X_op == O_constant)
4028 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4029 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4030 O_constant. We have to be careful not to break compilation for
4031 32-bit X_add_number, though. */
4032 if ((exp.X_add_number & ~0xffffffffl) != 0)
4034 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4035 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4036 inst.operands[i].regisimm = 1;
4039 else if (exp.X_op == O_big
4040 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4041 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4043 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4044 /* Bignums have their least significant bits in
4045 generic_bignum[0]. Make sure we put 32 bits in imm and
4046 32 bits in reg, in a (hopefully) portable way. */
4047 assert (parts != 0);
4048 inst.operands[i].imm = 0;
4049 for (j = 0; j < parts; j++, idx++)
4050 inst.operands[i].imm |= generic_bignum[idx]
4051 << (LITTLENUM_NUMBER_OF_BITS * j);
4052 inst.operands[i].reg = 0;
4053 for (j = 0; j < parts; j++, idx++)
4054 inst.operands[i].reg |= generic_bignum[idx]
4055 << (LITTLENUM_NUMBER_OF_BITS * j);
4056 inst.operands[i].regisimm = 1;
4058 else
4059 return FAIL;
4061 *str = ptr;
4063 return SUCCESS;
4066 /* Returns the pseudo-register number of an FPA immediate constant,
4067 or FAIL if there isn't a valid constant here. */
4069 static int
4070 parse_fpa_immediate (char ** str)
4072 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4073 char * save_in;
4074 expressionS exp;
4075 int i;
4076 int j;
4078 /* First try and match exact strings, this is to guarantee
4079 that some formats will work even for cross assembly. */
4081 for (i = 0; fp_const[i]; i++)
4083 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4085 char *start = *str;
4087 *str += strlen (fp_const[i]);
4088 if (is_end_of_line[(unsigned char) **str])
4089 return i + 8;
4090 *str = start;
4094 /* Just because we didn't get a match doesn't mean that the constant
4095 isn't valid, just that it is in a format that we don't
4096 automatically recognize. Try parsing it with the standard
4097 expression routines. */
4099 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4101 /* Look for a raw floating point number. */
4102 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4103 && is_end_of_line[(unsigned char) *save_in])
4105 for (i = 0; i < NUM_FLOAT_VALS; i++)
4107 for (j = 0; j < MAX_LITTLENUMS; j++)
4109 if (words[j] != fp_values[i][j])
4110 break;
4113 if (j == MAX_LITTLENUMS)
4115 *str = save_in;
4116 return i + 8;
4121 /* Try and parse a more complex expression, this will probably fail
4122 unless the code uses a floating point prefix (eg "0f"). */
4123 save_in = input_line_pointer;
4124 input_line_pointer = *str;
4125 if (expression (&exp) == absolute_section
4126 && exp.X_op == O_big
4127 && exp.X_add_number < 0)
4129 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4130 Ditto for 15. */
4131 if (gen_to_words (words, 5, (long) 15) == 0)
4133 for (i = 0; i < NUM_FLOAT_VALS; i++)
4135 for (j = 0; j < MAX_LITTLENUMS; j++)
4137 if (words[j] != fp_values[i][j])
4138 break;
4141 if (j == MAX_LITTLENUMS)
4143 *str = input_line_pointer;
4144 input_line_pointer = save_in;
4145 return i + 8;
4151 *str = input_line_pointer;
4152 input_line_pointer = save_in;
4153 inst.error = _("invalid FPA immediate expression");
4154 return FAIL;
4157 /* Returns 1 if a number has "quarter-precision" float format
4158 0baBbbbbbc defgh000 00000000 00000000. */
4160 static int
4161 is_quarter_float (unsigned imm)
4163 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4164 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4167 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4168 0baBbbbbbc defgh000 00000000 00000000.
4169 The zero and minus-zero cases need special handling, since they can't be
4170 encoded in the "quarter-precision" float format, but can nonetheless be
4171 loaded as integer constants. */
4173 static unsigned
4174 parse_qfloat_immediate (char **ccp, int *immed)
4176 char *str = *ccp;
4177 char *fpnum;
4178 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4179 int found_fpchar = 0;
4181 skip_past_char (&str, '#');
4183 /* We must not accidentally parse an integer as a floating-point number. Make
4184 sure that the value we parse is not an integer by checking for special
4185 characters '.' or 'e'.
4186 FIXME: This is a horrible hack, but doing better is tricky because type
4187 information isn't in a very usable state at parse time. */
4188 fpnum = str;
4189 skip_whitespace (fpnum);
4191 if (strncmp (fpnum, "0x", 2) == 0)
4192 return FAIL;
4193 else
4195 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4196 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4198 found_fpchar = 1;
4199 break;
4202 if (!found_fpchar)
4203 return FAIL;
4206 if ((str = atof_ieee (str, 's', words)) != NULL)
4208 unsigned fpword = 0;
4209 int i;
4211 /* Our FP word must be 32 bits (single-precision FP). */
4212 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4214 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4215 fpword |= words[i];
4218 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4219 *immed = fpword;
4220 else
4221 return FAIL;
4223 *ccp = str;
4225 return SUCCESS;
4228 return FAIL;
4231 /* Shift operands. */
4232 enum shift_kind
4234 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4237 struct asm_shift_name
4239 const char *name;
4240 enum shift_kind kind;
4243 /* Third argument to parse_shift. */
4244 enum parse_shift_mode
4246 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4247 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4248 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4249 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4250 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4253 /* Parse a <shift> specifier on an ARM data processing instruction.
4254 This has three forms:
4256 (LSL|LSR|ASL|ASR|ROR) Rs
4257 (LSL|LSR|ASL|ASR|ROR) #imm
4260 Note that ASL is assimilated to LSL in the instruction encoding, and
4261 RRX to ROR #0 (which cannot be written as such). */
4263 static int
4264 parse_shift (char **str, int i, enum parse_shift_mode mode)
4266 const struct asm_shift_name *shift_name;
4267 enum shift_kind shift;
4268 char *s = *str;
4269 char *p = s;
4270 int reg;
4272 for (p = *str; ISALPHA (*p); p++)
4275 if (p == *str)
4277 inst.error = _("shift expression expected");
4278 return FAIL;
4281 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4283 if (shift_name == NULL)
4285 inst.error = _("shift expression expected");
4286 return FAIL;
4289 shift = shift_name->kind;
4291 switch (mode)
4293 case NO_SHIFT_RESTRICT:
4294 case SHIFT_IMMEDIATE: break;
4296 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4297 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4299 inst.error = _("'LSL' or 'ASR' required");
4300 return FAIL;
4302 break;
4304 case SHIFT_LSL_IMMEDIATE:
4305 if (shift != SHIFT_LSL)
4307 inst.error = _("'LSL' required");
4308 return FAIL;
4310 break;
4312 case SHIFT_ASR_IMMEDIATE:
4313 if (shift != SHIFT_ASR)
4315 inst.error = _("'ASR' required");
4316 return FAIL;
4318 break;
4320 default: abort ();
4323 if (shift != SHIFT_RRX)
4325 /* Whitespace can appear here if the next thing is a bare digit. */
4326 skip_whitespace (p);
4328 if (mode == NO_SHIFT_RESTRICT
4329 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4331 inst.operands[i].imm = reg;
4332 inst.operands[i].immisreg = 1;
4334 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4335 return FAIL;
4337 inst.operands[i].shift_kind = shift;
4338 inst.operands[i].shifted = 1;
4339 *str = p;
4340 return SUCCESS;
4343 /* Parse a <shifter_operand> for an ARM data processing instruction:
4345 #<immediate>
4346 #<immediate>, <rotate>
4347 <Rm>
4348 <Rm>, <shift>
4350 where <shift> is defined by parse_shift above, and <rotate> is a
4351 multiple of 2 between 0 and 30. Validation of immediate operands
4352 is deferred to md_apply_fix. */
4354 static int
4355 parse_shifter_operand (char **str, int i)
4357 int value;
4358 expressionS expr;
4360 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4362 inst.operands[i].reg = value;
4363 inst.operands[i].isreg = 1;
4365 /* parse_shift will override this if appropriate */
4366 inst.reloc.exp.X_op = O_constant;
4367 inst.reloc.exp.X_add_number = 0;
4369 if (skip_past_comma (str) == FAIL)
4370 return SUCCESS;
4372 /* Shift operation on register. */
4373 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4376 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4377 return FAIL;
4379 if (skip_past_comma (str) == SUCCESS)
4381 /* #x, y -- ie explicit rotation by Y. */
4382 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4383 return FAIL;
4385 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4387 inst.error = _("constant expression expected");
4388 return FAIL;
4391 value = expr.X_add_number;
4392 if (value < 0 || value > 30 || value % 2 != 0)
4394 inst.error = _("invalid rotation");
4395 return FAIL;
4397 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4399 inst.error = _("invalid constant");
4400 return FAIL;
4403 /* Convert to decoded value. md_apply_fix will put it back. */
4404 inst.reloc.exp.X_add_number
4405 = (((inst.reloc.exp.X_add_number << (32 - value))
4406 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4409 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4410 inst.reloc.pc_rel = 0;
4411 return SUCCESS;
4414 /* Group relocation information. Each entry in the table contains the
4415 textual name of the relocation as may appear in assembler source
4416 and must end with a colon.
4417 Along with this textual name are the relocation codes to be used if
4418 the corresponding instruction is an ALU instruction (ADD or SUB only),
4419 an LDR, an LDRS, or an LDC. */
4421 struct group_reloc_table_entry
4423 const char *name;
4424 int alu_code;
4425 int ldr_code;
4426 int ldrs_code;
4427 int ldc_code;
4430 typedef enum
4432 /* Varieties of non-ALU group relocation. */
4434 GROUP_LDR,
4435 GROUP_LDRS,
4436 GROUP_LDC
4437 } group_reloc_type;
4439 static struct group_reloc_table_entry group_reloc_table[] =
4440 { /* Program counter relative: */
4441 { "pc_g0_nc",
4442 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4443 0, /* LDR */
4444 0, /* LDRS */
4445 0 }, /* LDC */
4446 { "pc_g0",
4447 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4448 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4449 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4450 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4451 { "pc_g1_nc",
4452 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4453 0, /* LDR */
4454 0, /* LDRS */
4455 0 }, /* LDC */
4456 { "pc_g1",
4457 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4458 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4459 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4460 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4461 { "pc_g2",
4462 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4463 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4464 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4465 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4466 /* Section base relative */
4467 { "sb_g0_nc",
4468 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4469 0, /* LDR */
4470 0, /* LDRS */
4471 0 }, /* LDC */
4472 { "sb_g0",
4473 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4474 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4475 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4476 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4477 { "sb_g1_nc",
4478 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4479 0, /* LDR */
4480 0, /* LDRS */
4481 0 }, /* LDC */
4482 { "sb_g1",
4483 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4484 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4485 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4486 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4487 { "sb_g2",
4488 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4489 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4490 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4491 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4493 /* Given the address of a pointer pointing to the textual name of a group
4494 relocation as may appear in assembler source, attempt to find its details
4495 in group_reloc_table. The pointer will be updated to the character after
4496 the trailing colon. On failure, FAIL will be returned; SUCCESS
4497 otherwise. On success, *entry will be updated to point at the relevant
4498 group_reloc_table entry. */
4500 static int
4501 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4503 unsigned int i;
4504 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4506 int length = strlen (group_reloc_table[i].name);
4508 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4509 && (*str)[length] == ':')
4511 *out = &group_reloc_table[i];
4512 *str += (length + 1);
4513 return SUCCESS;
4517 return FAIL;
4520 /* Parse a <shifter_operand> for an ARM data processing instruction
4521 (as for parse_shifter_operand) where group relocations are allowed:
4523 #<immediate>
4524 #<immediate>, <rotate>
4525 #:<group_reloc>:<expression>
4526 <Rm>
4527 <Rm>, <shift>
4529 where <group_reloc> is one of the strings defined in group_reloc_table.
4530 The hashes are optional.
4532 Everything else is as for parse_shifter_operand. */
4534 static parse_operand_result
4535 parse_shifter_operand_group_reloc (char **str, int i)
4537 /* Determine if we have the sequence of characters #: or just :
4538 coming next. If we do, then we check for a group relocation.
4539 If we don't, punt the whole lot to parse_shifter_operand. */
4541 if (((*str)[0] == '#' && (*str)[1] == ':')
4542 || (*str)[0] == ':')
4544 struct group_reloc_table_entry *entry;
4546 if ((*str)[0] == '#')
4547 (*str) += 2;
4548 else
4549 (*str)++;
4551 /* Try to parse a group relocation. Anything else is an error. */
4552 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4554 inst.error = _("unknown group relocation");
4555 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4558 /* We now have the group relocation table entry corresponding to
4559 the name in the assembler source. Next, we parse the expression. */
4560 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4561 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4563 /* Record the relocation type (always the ALU variant here). */
4564 inst.reloc.type = entry->alu_code;
4565 assert (inst.reloc.type != 0);
4567 return PARSE_OPERAND_SUCCESS;
4569 else
4570 return parse_shifter_operand (str, i) == SUCCESS
4571 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4573 /* Never reached. */
4576 /* Parse all forms of an ARM address expression. Information is written
4577 to inst.operands[i] and/or inst.reloc.
4579 Preindexed addressing (.preind=1):
4581 [Rn, #offset] .reg=Rn .reloc.exp=offset
4582 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4583 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4584 .shift_kind=shift .reloc.exp=shift_imm
4586 These three may have a trailing ! which causes .writeback to be set also.
4588 Postindexed addressing (.postind=1, .writeback=1):
4590 [Rn], #offset .reg=Rn .reloc.exp=offset
4591 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4592 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4593 .shift_kind=shift .reloc.exp=shift_imm
4595 Unindexed addressing (.preind=0, .postind=0):
4597 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4599 Other:
4601 [Rn]{!} shorthand for [Rn,#0]{!}
4602 =immediate .isreg=0 .reloc.exp=immediate
4603 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4605 It is the caller's responsibility to check for addressing modes not
4606 supported by the instruction, and to set inst.reloc.type. */
4608 static parse_operand_result
4609 parse_address_main (char **str, int i, int group_relocations,
4610 group_reloc_type group_type)
4612 char *p = *str;
4613 int reg;
4615 if (skip_past_char (&p, '[') == FAIL)
4617 if (skip_past_char (&p, '=') == FAIL)
4619 /* bare address - translate to PC-relative offset */
4620 inst.reloc.pc_rel = 1;
4621 inst.operands[i].reg = REG_PC;
4622 inst.operands[i].isreg = 1;
4623 inst.operands[i].preind = 1;
4625 /* else a load-constant pseudo op, no special treatment needed here */
4627 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4628 return PARSE_OPERAND_FAIL;
4630 *str = p;
4631 return PARSE_OPERAND_SUCCESS;
4634 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4636 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4637 return PARSE_OPERAND_FAIL;
4639 inst.operands[i].reg = reg;
4640 inst.operands[i].isreg = 1;
4642 if (skip_past_comma (&p) == SUCCESS)
4644 inst.operands[i].preind = 1;
4646 if (*p == '+') p++;
4647 else if (*p == '-') p++, inst.operands[i].negative = 1;
4649 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4651 inst.operands[i].imm = reg;
4652 inst.operands[i].immisreg = 1;
4654 if (skip_past_comma (&p) == SUCCESS)
4655 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4656 return PARSE_OPERAND_FAIL;
4658 else if (skip_past_char (&p, ':') == SUCCESS)
4660 /* FIXME: '@' should be used here, but it's filtered out by generic
4661 code before we get to see it here. This may be subject to
4662 change. */
4663 expressionS exp;
4664 my_get_expression (&exp, &p, GE_NO_PREFIX);
4665 if (exp.X_op != O_constant)
4667 inst.error = _("alignment must be constant");
4668 return PARSE_OPERAND_FAIL;
4670 inst.operands[i].imm = exp.X_add_number << 8;
4671 inst.operands[i].immisalign = 1;
4672 /* Alignments are not pre-indexes. */
4673 inst.operands[i].preind = 0;
4675 else
4677 if (inst.operands[i].negative)
4679 inst.operands[i].negative = 0;
4680 p--;
4683 if (group_relocations
4684 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4686 struct group_reloc_table_entry *entry;
4688 /* Skip over the #: or : sequence. */
4689 if (*p == '#')
4690 p += 2;
4691 else
4692 p++;
4694 /* Try to parse a group relocation. Anything else is an
4695 error. */
4696 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4698 inst.error = _("unknown group relocation");
4699 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4702 /* We now have the group relocation table entry corresponding to
4703 the name in the assembler source. Next, we parse the
4704 expression. */
4705 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4706 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4708 /* Record the relocation type. */
4709 switch (group_type)
4711 case GROUP_LDR:
4712 inst.reloc.type = entry->ldr_code;
4713 break;
4715 case GROUP_LDRS:
4716 inst.reloc.type = entry->ldrs_code;
4717 break;
4719 case GROUP_LDC:
4720 inst.reloc.type = entry->ldc_code;
4721 break;
4723 default:
4724 assert (0);
4727 if (inst.reloc.type == 0)
4729 inst.error = _("this group relocation is not allowed on this instruction");
4730 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4733 else
4734 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4735 return PARSE_OPERAND_FAIL;
4739 if (skip_past_char (&p, ']') == FAIL)
4741 inst.error = _("']' expected");
4742 return PARSE_OPERAND_FAIL;
4745 if (skip_past_char (&p, '!') == SUCCESS)
4746 inst.operands[i].writeback = 1;
4748 else if (skip_past_comma (&p) == SUCCESS)
4750 if (skip_past_char (&p, '{') == SUCCESS)
4752 /* [Rn], {expr} - unindexed, with option */
4753 if (parse_immediate (&p, &inst.operands[i].imm,
4754 0, 255, TRUE) == FAIL)
4755 return PARSE_OPERAND_FAIL;
4757 if (skip_past_char (&p, '}') == FAIL)
4759 inst.error = _("'}' expected at end of 'option' field");
4760 return PARSE_OPERAND_FAIL;
4762 if (inst.operands[i].preind)
4764 inst.error = _("cannot combine index with option");
4765 return PARSE_OPERAND_FAIL;
4767 *str = p;
4768 return PARSE_OPERAND_SUCCESS;
4770 else
4772 inst.operands[i].postind = 1;
4773 inst.operands[i].writeback = 1;
4775 if (inst.operands[i].preind)
4777 inst.error = _("cannot combine pre- and post-indexing");
4778 return PARSE_OPERAND_FAIL;
4781 if (*p == '+') p++;
4782 else if (*p == '-') p++, inst.operands[i].negative = 1;
4784 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4786 /* We might be using the immediate for alignment already. If we
4787 are, OR the register number into the low-order bits. */
4788 if (inst.operands[i].immisalign)
4789 inst.operands[i].imm |= reg;
4790 else
4791 inst.operands[i].imm = reg;
4792 inst.operands[i].immisreg = 1;
4794 if (skip_past_comma (&p) == SUCCESS)
4795 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4796 return PARSE_OPERAND_FAIL;
4798 else
4800 if (inst.operands[i].negative)
4802 inst.operands[i].negative = 0;
4803 p--;
4805 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4806 return PARSE_OPERAND_FAIL;
4811 /* If at this point neither .preind nor .postind is set, we have a
4812 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4813 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4815 inst.operands[i].preind = 1;
4816 inst.reloc.exp.X_op = O_constant;
4817 inst.reloc.exp.X_add_number = 0;
4819 *str = p;
4820 return PARSE_OPERAND_SUCCESS;
4823 static int
4824 parse_address (char **str, int i)
4826 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4827 ? SUCCESS : FAIL;
4830 static parse_operand_result
4831 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4833 return parse_address_main (str, i, 1, type);
4836 /* Parse an operand for a MOVW or MOVT instruction. */
4837 static int
4838 parse_half (char **str)
4840 char * p;
4842 p = *str;
4843 skip_past_char (&p, '#');
4844 if (strncasecmp (p, ":lower16:", 9) == 0)
4845 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4846 else if (strncasecmp (p, ":upper16:", 9) == 0)
4847 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4849 if (inst.reloc.type != BFD_RELOC_UNUSED)
4851 p += 9;
4852 skip_whitespace (p);
4855 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4856 return FAIL;
4858 if (inst.reloc.type == BFD_RELOC_UNUSED)
4860 if (inst.reloc.exp.X_op != O_constant)
4862 inst.error = _("constant expression expected");
4863 return FAIL;
4865 if (inst.reloc.exp.X_add_number < 0
4866 || inst.reloc.exp.X_add_number > 0xffff)
4868 inst.error = _("immediate value out of range");
4869 return FAIL;
4872 *str = p;
4873 return SUCCESS;
4876 /* Miscellaneous. */
4878 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4879 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4880 static int
4881 parse_psr (char **str)
4883 char *p;
4884 unsigned long psr_field;
4885 const struct asm_psr *psr;
4886 char *start;
4888 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4889 feature for ease of use and backwards compatibility. */
4890 p = *str;
4891 if (strncasecmp (p, "SPSR", 4) == 0)
4892 psr_field = SPSR_BIT;
4893 else if (strncasecmp (p, "CPSR", 4) == 0)
4894 psr_field = 0;
4895 else
4897 start = p;
4899 p++;
4900 while (ISALNUM (*p) || *p == '_');
4902 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4903 if (!psr)
4904 return FAIL;
4906 *str = p;
4907 return psr->field;
4910 p += 4;
4911 if (*p == '_')
4913 /* A suffix follows. */
4914 p++;
4915 start = p;
4918 p++;
4919 while (ISALNUM (*p) || *p == '_');
4921 psr = hash_find_n (arm_psr_hsh, start, p - start);
4922 if (!psr)
4923 goto error;
4925 psr_field |= psr->field;
4927 else
4929 if (ISALNUM (*p))
4930 goto error; /* Garbage after "[CS]PSR". */
4932 psr_field |= (PSR_c | PSR_f);
4934 *str = p;
4935 return psr_field;
4937 error:
4938 inst.error = _("flag for {c}psr instruction expected");
4939 return FAIL;
4942 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4943 value suitable for splatting into the AIF field of the instruction. */
4945 static int
4946 parse_cps_flags (char **str)
4948 int val = 0;
4949 int saw_a_flag = 0;
4950 char *s = *str;
4952 for (;;)
4953 switch (*s++)
4955 case '\0': case ',':
4956 goto done;
4958 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4959 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4960 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4962 default:
4963 inst.error = _("unrecognized CPS flag");
4964 return FAIL;
4967 done:
4968 if (saw_a_flag == 0)
4970 inst.error = _("missing CPS flags");
4971 return FAIL;
4974 *str = s - 1;
4975 return val;
4978 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4979 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4981 static int
4982 parse_endian_specifier (char **str)
4984 int little_endian;
4985 char *s = *str;
4987 if (strncasecmp (s, "BE", 2))
4988 little_endian = 0;
4989 else if (strncasecmp (s, "LE", 2))
4990 little_endian = 1;
4991 else
4993 inst.error = _("valid endian specifiers are be or le");
4994 return FAIL;
4997 if (ISALNUM (s[2]) || s[2] == '_')
4999 inst.error = _("valid endian specifiers are be or le");
5000 return FAIL;
5003 *str = s + 2;
5004 return little_endian;
5007 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5008 value suitable for poking into the rotate field of an sxt or sxta
5009 instruction, or FAIL on error. */
5011 static int
5012 parse_ror (char **str)
5014 int rot;
5015 char *s = *str;
5017 if (strncasecmp (s, "ROR", 3) == 0)
5018 s += 3;
5019 else
5021 inst.error = _("missing rotation field after comma");
5022 return FAIL;
5025 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5026 return FAIL;
5028 switch (rot)
5030 case 0: *str = s; return 0x0;
5031 case 8: *str = s; return 0x1;
5032 case 16: *str = s; return 0x2;
5033 case 24: *str = s; return 0x3;
5035 default:
5036 inst.error = _("rotation can only be 0, 8, 16, or 24");
5037 return FAIL;
5041 /* Parse a conditional code (from conds[] below). The value returned is in the
5042 range 0 .. 14, or FAIL. */
5043 static int
5044 parse_cond (char **str)
5046 char *p, *q;
5047 const struct asm_cond *c;
5049 p = q = *str;
5050 while (ISALPHA (*q))
5051 q++;
5053 c = hash_find_n (arm_cond_hsh, p, q - p);
5054 if (!c)
5056 inst.error = _("condition required");
5057 return FAIL;
5060 *str = q;
5061 return c->value;
5064 /* Parse an option for a barrier instruction. Returns the encoding for the
5065 option, or FAIL. */
5066 static int
5067 parse_barrier (char **str)
5069 char *p, *q;
5070 const struct asm_barrier_opt *o;
5072 p = q = *str;
5073 while (ISALPHA (*q))
5074 q++;
5076 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5077 if (!o)
5078 return FAIL;
5080 *str = q;
5081 return o->value;
5084 /* Parse the operands of a table branch instruction. Similar to a memory
5085 operand. */
5086 static int
5087 parse_tb (char **str)
5089 char * p = *str;
5090 int reg;
5092 if (skip_past_char (&p, '[') == FAIL)
5094 inst.error = _("'[' expected");
5095 return FAIL;
5098 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5100 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5101 return FAIL;
5103 inst.operands[0].reg = reg;
5105 if (skip_past_comma (&p) == FAIL)
5107 inst.error = _("',' expected");
5108 return FAIL;
5111 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5113 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5114 return FAIL;
5116 inst.operands[0].imm = reg;
5118 if (skip_past_comma (&p) == SUCCESS)
5120 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5121 return FAIL;
5122 if (inst.reloc.exp.X_add_number != 1)
5124 inst.error = _("invalid shift");
5125 return FAIL;
5127 inst.operands[0].shifted = 1;
5130 if (skip_past_char (&p, ']') == FAIL)
5132 inst.error = _("']' expected");
5133 return FAIL;
5135 *str = p;
5136 return SUCCESS;
5139 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5140 information on the types the operands can take and how they are encoded.
5141 Up to four operands may be read; this function handles setting the
5142 ".present" field for each read operand itself.
5143 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5144 else returns FAIL. */
5146 static int
5147 parse_neon_mov (char **str, int *which_operand)
5149 int i = *which_operand, val;
5150 enum arm_reg_type rtype;
5151 char *ptr = *str;
5152 struct neon_type_el optype;
5154 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5156 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5157 inst.operands[i].reg = val;
5158 inst.operands[i].isscalar = 1;
5159 inst.operands[i].vectype = optype;
5160 inst.operands[i++].present = 1;
5162 if (skip_past_comma (&ptr) == FAIL)
5163 goto wanted_comma;
5165 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5166 goto wanted_arm;
5168 inst.operands[i].reg = val;
5169 inst.operands[i].isreg = 1;
5170 inst.operands[i].present = 1;
5172 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5173 != FAIL)
5175 /* Cases 0, 1, 2, 3, 5 (D only). */
5176 if (skip_past_comma (&ptr) == FAIL)
5177 goto wanted_comma;
5179 inst.operands[i].reg = val;
5180 inst.operands[i].isreg = 1;
5181 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5182 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5183 inst.operands[i].isvec = 1;
5184 inst.operands[i].vectype = optype;
5185 inst.operands[i++].present = 1;
5187 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5189 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5190 Case 13: VMOV <Sd>, <Rm> */
5191 inst.operands[i].reg = val;
5192 inst.operands[i].isreg = 1;
5193 inst.operands[i].present = 1;
5195 if (rtype == REG_TYPE_NQ)
5197 first_error (_("can't use Neon quad register here"));
5198 return FAIL;
5200 else if (rtype != REG_TYPE_VFS)
5202 i++;
5203 if (skip_past_comma (&ptr) == FAIL)
5204 goto wanted_comma;
5205 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5206 goto wanted_arm;
5207 inst.operands[i].reg = val;
5208 inst.operands[i].isreg = 1;
5209 inst.operands[i].present = 1;
5212 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5213 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5214 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5215 Case 10: VMOV.F32 <Sd>, #<imm>
5216 Case 11: VMOV.F64 <Dd>, #<imm> */
5217 inst.operands[i].immisfloat = 1;
5218 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5219 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5220 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5222 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5223 &optype)) != FAIL)
5225 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5226 Case 1: VMOV<c><q> <Dd>, <Dm>
5227 Case 8: VMOV.F32 <Sd>, <Sm>
5228 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5230 inst.operands[i].reg = val;
5231 inst.operands[i].isreg = 1;
5232 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5233 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5234 inst.operands[i].isvec = 1;
5235 inst.operands[i].vectype = optype;
5236 inst.operands[i].present = 1;
5238 if (skip_past_comma (&ptr) == SUCCESS)
5240 /* Case 15. */
5241 i++;
5243 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5244 goto wanted_arm;
5246 inst.operands[i].reg = val;
5247 inst.operands[i].isreg = 1;
5248 inst.operands[i++].present = 1;
5250 if (skip_past_comma (&ptr) == FAIL)
5251 goto wanted_comma;
5253 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5254 goto wanted_arm;
5256 inst.operands[i].reg = val;
5257 inst.operands[i].isreg = 1;
5258 inst.operands[i++].present = 1;
5261 else
5263 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5264 return FAIL;
5267 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5269 /* Cases 6, 7. */
5270 inst.operands[i].reg = val;
5271 inst.operands[i].isreg = 1;
5272 inst.operands[i++].present = 1;
5274 if (skip_past_comma (&ptr) == FAIL)
5275 goto wanted_comma;
5277 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5279 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5280 inst.operands[i].reg = val;
5281 inst.operands[i].isscalar = 1;
5282 inst.operands[i].present = 1;
5283 inst.operands[i].vectype = optype;
5285 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5288 inst.operands[i].reg = val;
5289 inst.operands[i].isreg = 1;
5290 inst.operands[i++].present = 1;
5292 if (skip_past_comma (&ptr) == FAIL)
5293 goto wanted_comma;
5295 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5296 == FAIL)
5298 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5299 return FAIL;
5302 inst.operands[i].reg = val;
5303 inst.operands[i].isreg = 1;
5304 inst.operands[i].isvec = 1;
5305 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5306 inst.operands[i].vectype = optype;
5307 inst.operands[i].present = 1;
5309 if (rtype == REG_TYPE_VFS)
5311 /* Case 14. */
5312 i++;
5313 if (skip_past_comma (&ptr) == FAIL)
5314 goto wanted_comma;
5315 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5316 &optype)) == FAIL)
5318 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5319 return FAIL;
5321 inst.operands[i].reg = val;
5322 inst.operands[i].isreg = 1;
5323 inst.operands[i].isvec = 1;
5324 inst.operands[i].issingle = 1;
5325 inst.operands[i].vectype = optype;
5326 inst.operands[i].present = 1;
5329 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5330 != FAIL)
5332 /* Case 13. */
5333 inst.operands[i].reg = val;
5334 inst.operands[i].isreg = 1;
5335 inst.operands[i].isvec = 1;
5336 inst.operands[i].issingle = 1;
5337 inst.operands[i].vectype = optype;
5338 inst.operands[i++].present = 1;
5341 else
5343 first_error (_("parse error"));
5344 return FAIL;
5347 /* Successfully parsed the operands. Update args. */
5348 *which_operand = i;
5349 *str = ptr;
5350 return SUCCESS;
5352 wanted_comma:
5353 first_error (_("expected comma"));
5354 return FAIL;
5356 wanted_arm:
5357 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5358 return FAIL;
5361 /* Matcher codes for parse_operands. */
5362 enum operand_parse_code
5364 OP_stop, /* end of line */
5366 OP_RR, /* ARM register */
5367 OP_RRnpc, /* ARM register, not r15 */
5368 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5369 OP_RRw, /* ARM register, not r15, optional trailing ! */
5370 OP_RCP, /* Coprocessor number */
5371 OP_RCN, /* Coprocessor register */
5372 OP_RF, /* FPA register */
5373 OP_RVS, /* VFP single precision register */
5374 OP_RVD, /* VFP double precision register (0..15) */
5375 OP_RND, /* Neon double precision register (0..31) */
5376 OP_RNQ, /* Neon quad precision register */
5377 OP_RVSD, /* VFP single or double precision register */
5378 OP_RNDQ, /* Neon double or quad precision register */
5379 OP_RNSDQ, /* Neon single, double or quad precision register */
5380 OP_RNSC, /* Neon scalar D[X] */
5381 OP_RVC, /* VFP control register */
5382 OP_RMF, /* Maverick F register */
5383 OP_RMD, /* Maverick D register */
5384 OP_RMFX, /* Maverick FX register */
5385 OP_RMDX, /* Maverick DX register */
5386 OP_RMAX, /* Maverick AX register */
5387 OP_RMDS, /* Maverick DSPSC register */
5388 OP_RIWR, /* iWMMXt wR register */
5389 OP_RIWC, /* iWMMXt wC register */
5390 OP_RIWG, /* iWMMXt wCG register */
5391 OP_RXA, /* XScale accumulator register */
5393 OP_REGLST, /* ARM register list */
5394 OP_VRSLST, /* VFP single-precision register list */
5395 OP_VRDLST, /* VFP double-precision register list */
5396 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5397 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5398 OP_NSTRLST, /* Neon element/structure list */
5400 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5401 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5402 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5403 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5404 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5405 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5406 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5407 OP_VMOV, /* Neon VMOV operands. */
5408 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5409 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5410 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5412 OP_I0, /* immediate zero */
5413 OP_I7, /* immediate value 0 .. 7 */
5414 OP_I15, /* 0 .. 15 */
5415 OP_I16, /* 1 .. 16 */
5416 OP_I16z, /* 0 .. 16 */
5417 OP_I31, /* 0 .. 31 */
5418 OP_I31w, /* 0 .. 31, optional trailing ! */
5419 OP_I32, /* 1 .. 32 */
5420 OP_I32z, /* 0 .. 32 */
5421 OP_I63, /* 0 .. 63 */
5422 OP_I63s, /* -64 .. 63 */
5423 OP_I64, /* 1 .. 64 */
5424 OP_I64z, /* 0 .. 64 */
5425 OP_I255, /* 0 .. 255 */
5427 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5428 OP_I7b, /* 0 .. 7 */
5429 OP_I15b, /* 0 .. 15 */
5430 OP_I31b, /* 0 .. 31 */
5432 OP_SH, /* shifter operand */
5433 OP_SHG, /* shifter operand with possible group relocation */
5434 OP_ADDR, /* Memory address expression (any mode) */
5435 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5436 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5437 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5438 OP_EXP, /* arbitrary expression */
5439 OP_EXPi, /* same, with optional immediate prefix */
5440 OP_EXPr, /* same, with optional relocation suffix */
5441 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5443 OP_CPSF, /* CPS flags */
5444 OP_ENDI, /* Endianness specifier */
5445 OP_PSR, /* CPSR/SPSR mask for msr */
5446 OP_COND, /* conditional code */
5447 OP_TB, /* Table branch. */
5449 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5450 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5452 OP_RRnpc_I0, /* ARM register or literal 0 */
5453 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5454 OP_RR_EXi, /* ARM register or expression with imm prefix */
5455 OP_RF_IF, /* FPA register or immediate */
5456 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5457 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5459 /* Optional operands. */
5460 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5461 OP_oI31b, /* 0 .. 31 */
5462 OP_oI32b, /* 1 .. 32 */
5463 OP_oIffffb, /* 0 .. 65535 */
5464 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5466 OP_oRR, /* ARM register */
5467 OP_oRRnpc, /* ARM register, not the PC */
5468 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5469 OP_oRND, /* Optional Neon double precision register */
5470 OP_oRNQ, /* Optional Neon quad precision register */
5471 OP_oRNDQ, /* Optional Neon double or quad precision register */
5472 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5473 OP_oSHll, /* LSL immediate */
5474 OP_oSHar, /* ASR immediate */
5475 OP_oSHllar, /* LSL or ASR immediate */
5476 OP_oROR, /* ROR 0/8/16/24 */
5477 OP_oBARRIER, /* Option argument for a barrier instruction. */
5479 OP_FIRST_OPTIONAL = OP_oI7b
5482 /* Generic instruction operand parser. This does no encoding and no
5483 semantic validation; it merely squirrels values away in the inst
5484 structure. Returns SUCCESS or FAIL depending on whether the
5485 specified grammar matched. */
5486 static int
5487 parse_operands (char *str, const unsigned char *pattern)
5489 unsigned const char *upat = pattern;
5490 char *backtrack_pos = 0;
5491 const char *backtrack_error = 0;
5492 int i, val, backtrack_index = 0;
5493 enum arm_reg_type rtype;
5494 parse_operand_result result;
5496 #define po_char_or_fail(chr) do { \
5497 if (skip_past_char (&str, chr) == FAIL) \
5498 goto bad_args; \
5499 } while (0)
5501 #define po_reg_or_fail(regtype) do { \
5502 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5503 &inst.operands[i].vectype); \
5504 if (val == FAIL) \
5506 first_error (_(reg_expected_msgs[regtype])); \
5507 goto failure; \
5509 inst.operands[i].reg = val; \
5510 inst.operands[i].isreg = 1; \
5511 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5512 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5513 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5514 || rtype == REG_TYPE_VFD \
5515 || rtype == REG_TYPE_NQ); \
5516 } while (0)
5518 #define po_reg_or_goto(regtype, label) do { \
5519 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5520 &inst.operands[i].vectype); \
5521 if (val == FAIL) \
5522 goto label; \
5524 inst.operands[i].reg = val; \
5525 inst.operands[i].isreg = 1; \
5526 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5527 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5528 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5529 || rtype == REG_TYPE_VFD \
5530 || rtype == REG_TYPE_NQ); \
5531 } while (0)
5533 #define po_imm_or_fail(min, max, popt) do { \
5534 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5535 goto failure; \
5536 inst.operands[i].imm = val; \
5537 } while (0)
5539 #define po_scalar_or_goto(elsz, label) do { \
5540 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5541 if (val == FAIL) \
5542 goto label; \
5543 inst.operands[i].reg = val; \
5544 inst.operands[i].isscalar = 1; \
5545 } while (0)
5547 #define po_misc_or_fail(expr) do { \
5548 if (expr) \
5549 goto failure; \
5550 } while (0)
5552 #define po_misc_or_fail_no_backtrack(expr) do { \
5553 result = expr; \
5554 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5555 backtrack_pos = 0; \
5556 if (result != PARSE_OPERAND_SUCCESS) \
5557 goto failure; \
5558 } while (0)
5560 skip_whitespace (str);
5562 for (i = 0; upat[i] != OP_stop; i++)
5564 if (upat[i] >= OP_FIRST_OPTIONAL)
5566 /* Remember where we are in case we need to backtrack. */
5567 assert (!backtrack_pos);
5568 backtrack_pos = str;
5569 backtrack_error = inst.error;
5570 backtrack_index = i;
5573 if (i > 0 && (i > 1 || inst.operands[0].present))
5574 po_char_or_fail (',');
5576 switch (upat[i])
5578 /* Registers */
5579 case OP_oRRnpc:
5580 case OP_RRnpc:
5581 case OP_oRR:
5582 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5583 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5584 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5585 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5586 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5587 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5588 case OP_oRND:
5589 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5590 case OP_RVC:
5591 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5592 break;
5593 /* Also accept generic coprocessor regs for unknown registers. */
5594 coproc_reg:
5595 po_reg_or_fail (REG_TYPE_CN);
5596 break;
5597 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5598 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5599 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5600 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5601 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5602 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5603 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5604 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5605 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5606 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5607 case OP_oRNQ:
5608 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5609 case OP_oRNDQ:
5610 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5611 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5612 case OP_oRNSDQ:
5613 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5615 /* Neon scalar. Using an element size of 8 means that some invalid
5616 scalars are accepted here, so deal with those in later code. */
5617 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5619 /* WARNING: We can expand to two operands here. This has the potential
5620 to totally confuse the backtracking mechanism! It will be OK at
5621 least as long as we don't try to use optional args as well,
5622 though. */
5623 case OP_NILO:
5625 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5626 inst.operands[i].present = 1;
5627 i++;
5628 skip_past_comma (&str);
5629 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5630 break;
5631 one_reg_only:
5632 /* Optional register operand was omitted. Unfortunately, it's in
5633 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5634 here (this is a bit grotty). */
5635 inst.operands[i] = inst.operands[i-1];
5636 inst.operands[i-1].present = 0;
5637 break;
5638 try_imm:
5639 /* There's a possibility of getting a 64-bit immediate here, so
5640 we need special handling. */
5641 if (parse_big_immediate (&str, i) == FAIL)
5643 inst.error = _("immediate value is out of range");
5644 goto failure;
5647 break;
5649 case OP_RNDQ_I0:
5651 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5652 break;
5653 try_imm0:
5654 po_imm_or_fail (0, 0, TRUE);
5656 break;
5658 case OP_RVSD_I0:
5659 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5660 break;
5662 case OP_RR_RNSC:
5664 po_scalar_or_goto (8, try_rr);
5665 break;
5666 try_rr:
5667 po_reg_or_fail (REG_TYPE_RN);
5669 break;
5671 case OP_RNSDQ_RNSC:
5673 po_scalar_or_goto (8, try_nsdq);
5674 break;
5675 try_nsdq:
5676 po_reg_or_fail (REG_TYPE_NSDQ);
5678 break;
5680 case OP_RNDQ_RNSC:
5682 po_scalar_or_goto (8, try_ndq);
5683 break;
5684 try_ndq:
5685 po_reg_or_fail (REG_TYPE_NDQ);
5687 break;
5689 case OP_RND_RNSC:
5691 po_scalar_or_goto (8, try_vfd);
5692 break;
5693 try_vfd:
5694 po_reg_or_fail (REG_TYPE_VFD);
5696 break;
5698 case OP_VMOV:
5699 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5700 not careful then bad things might happen. */
5701 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5702 break;
5704 case OP_RNDQ_IMVNb:
5706 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5707 break;
5708 try_mvnimm:
5709 /* There's a possibility of getting a 64-bit immediate here, so
5710 we need special handling. */
5711 if (parse_big_immediate (&str, i) == FAIL)
5713 inst.error = _("immediate value is out of range");
5714 goto failure;
5717 break;
5719 case OP_RNDQ_I63b:
5721 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5722 break;
5723 try_shimm:
5724 po_imm_or_fail (0, 63, TRUE);
5726 break;
5728 case OP_RRnpcb:
5729 po_char_or_fail ('[');
5730 po_reg_or_fail (REG_TYPE_RN);
5731 po_char_or_fail (']');
5732 break;
5734 case OP_RRw:
5735 case OP_oRRw:
5736 po_reg_or_fail (REG_TYPE_RN);
5737 if (skip_past_char (&str, '!') == SUCCESS)
5738 inst.operands[i].writeback = 1;
5739 break;
5741 /* Immediates */
5742 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5743 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5744 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5745 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5746 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5747 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5748 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5749 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5750 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5751 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5752 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5753 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5755 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5756 case OP_oI7b:
5757 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5758 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5759 case OP_oI31b:
5760 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5761 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5762 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5764 /* Immediate variants */
5765 case OP_oI255c:
5766 po_char_or_fail ('{');
5767 po_imm_or_fail (0, 255, TRUE);
5768 po_char_or_fail ('}');
5769 break;
5771 case OP_I31w:
5772 /* The expression parser chokes on a trailing !, so we have
5773 to find it first and zap it. */
5775 char *s = str;
5776 while (*s && *s != ',')
5777 s++;
5778 if (s[-1] == '!')
5780 s[-1] = '\0';
5781 inst.operands[i].writeback = 1;
5783 po_imm_or_fail (0, 31, TRUE);
5784 if (str == s - 1)
5785 str = s;
5787 break;
5789 /* Expressions */
5790 case OP_EXPi: EXPi:
5791 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5792 GE_OPT_PREFIX));
5793 break;
5795 case OP_EXP:
5796 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5797 GE_NO_PREFIX));
5798 break;
5800 case OP_EXPr: EXPr:
5801 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5802 GE_NO_PREFIX));
5803 if (inst.reloc.exp.X_op == O_symbol)
5805 val = parse_reloc (&str);
5806 if (val == -1)
5808 inst.error = _("unrecognized relocation suffix");
5809 goto failure;
5811 else if (val != BFD_RELOC_UNUSED)
5813 inst.operands[i].imm = val;
5814 inst.operands[i].hasreloc = 1;
5817 break;
5819 /* Operand for MOVW or MOVT. */
5820 case OP_HALF:
5821 po_misc_or_fail (parse_half (&str));
5822 break;
5824 /* Register or expression */
5825 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5826 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5828 /* Register or immediate */
5829 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5830 I0: po_imm_or_fail (0, 0, FALSE); break;
5832 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5834 if (!is_immediate_prefix (*str))
5835 goto bad_args;
5836 str++;
5837 val = parse_fpa_immediate (&str);
5838 if (val == FAIL)
5839 goto failure;
5840 /* FPA immediates are encoded as registers 8-15.
5841 parse_fpa_immediate has already applied the offset. */
5842 inst.operands[i].reg = val;
5843 inst.operands[i].isreg = 1;
5844 break;
5846 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5847 I32z: po_imm_or_fail (0, 32, FALSE); break;
5849 /* Two kinds of register */
5850 case OP_RIWR_RIWC:
5852 struct reg_entry *rege = arm_reg_parse_multi (&str);
5853 if (!rege
5854 || (rege->type != REG_TYPE_MMXWR
5855 && rege->type != REG_TYPE_MMXWC
5856 && rege->type != REG_TYPE_MMXWCG))
5858 inst.error = _("iWMMXt data or control register expected");
5859 goto failure;
5861 inst.operands[i].reg = rege->number;
5862 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5864 break;
5866 case OP_RIWC_RIWG:
5868 struct reg_entry *rege = arm_reg_parse_multi (&str);
5869 if (!rege
5870 || (rege->type != REG_TYPE_MMXWC
5871 && rege->type != REG_TYPE_MMXWCG))
5873 inst.error = _("iWMMXt control register expected");
5874 goto failure;
5876 inst.operands[i].reg = rege->number;
5877 inst.operands[i].isreg = 1;
5879 break;
5881 /* Misc */
5882 case OP_CPSF: val = parse_cps_flags (&str); break;
5883 case OP_ENDI: val = parse_endian_specifier (&str); break;
5884 case OP_oROR: val = parse_ror (&str); break;
5885 case OP_PSR: val = parse_psr (&str); break;
5886 case OP_COND: val = parse_cond (&str); break;
5887 case OP_oBARRIER:val = parse_barrier (&str); break;
5889 case OP_RVC_PSR:
5890 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5891 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5892 break;
5893 try_psr:
5894 val = parse_psr (&str);
5895 break;
5897 case OP_APSR_RR:
5898 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5899 break;
5900 try_apsr:
5901 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5902 instruction). */
5903 if (strncasecmp (str, "APSR_", 5) == 0)
5905 unsigned found = 0;
5906 str += 5;
5907 while (found < 15)
5908 switch (*str++)
5910 case 'c': found = (found & 1) ? 16 : found | 1; break;
5911 case 'n': found = (found & 2) ? 16 : found | 2; break;
5912 case 'z': found = (found & 4) ? 16 : found | 4; break;
5913 case 'v': found = (found & 8) ? 16 : found | 8; break;
5914 default: found = 16;
5916 if (found != 15)
5917 goto failure;
5918 inst.operands[i].isvec = 1;
5920 else
5921 goto failure;
5922 break;
5924 case OP_TB:
5925 po_misc_or_fail (parse_tb (&str));
5926 break;
5928 /* Register lists */
5929 case OP_REGLST:
5930 val = parse_reg_list (&str);
5931 if (*str == '^')
5933 inst.operands[1].writeback = 1;
5934 str++;
5936 break;
5938 case OP_VRSLST:
5939 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5940 break;
5942 case OP_VRDLST:
5943 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5944 break;
5946 case OP_VRSDLST:
5947 /* Allow Q registers too. */
5948 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5949 REGLIST_NEON_D);
5950 if (val == FAIL)
5952 inst.error = NULL;
5953 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5954 REGLIST_VFP_S);
5955 inst.operands[i].issingle = 1;
5957 break;
5959 case OP_NRDLST:
5960 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5961 REGLIST_NEON_D);
5962 break;
5964 case OP_NSTRLST:
5965 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5966 &inst.operands[i].vectype);
5967 break;
5969 /* Addressing modes */
5970 case OP_ADDR:
5971 po_misc_or_fail (parse_address (&str, i));
5972 break;
5974 case OP_ADDRGLDR:
5975 po_misc_or_fail_no_backtrack (
5976 parse_address_group_reloc (&str, i, GROUP_LDR));
5977 break;
5979 case OP_ADDRGLDRS:
5980 po_misc_or_fail_no_backtrack (
5981 parse_address_group_reloc (&str, i, GROUP_LDRS));
5982 break;
5984 case OP_ADDRGLDC:
5985 po_misc_or_fail_no_backtrack (
5986 parse_address_group_reloc (&str, i, GROUP_LDC));
5987 break;
5989 case OP_SH:
5990 po_misc_or_fail (parse_shifter_operand (&str, i));
5991 break;
5993 case OP_SHG:
5994 po_misc_or_fail_no_backtrack (
5995 parse_shifter_operand_group_reloc (&str, i));
5996 break;
5998 case OP_oSHll:
5999 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6000 break;
6002 case OP_oSHar:
6003 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6004 break;
6006 case OP_oSHllar:
6007 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6008 break;
6010 default:
6011 as_fatal (_("unhandled operand code %d"), upat[i]);
6014 /* Various value-based sanity checks and shared operations. We
6015 do not signal immediate failures for the register constraints;
6016 this allows a syntax error to take precedence. */
6017 switch (upat[i])
6019 case OP_oRRnpc:
6020 case OP_RRnpc:
6021 case OP_RRnpcb:
6022 case OP_RRw:
6023 case OP_oRRw:
6024 case OP_RRnpc_I0:
6025 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6026 inst.error = BAD_PC;
6027 break;
6029 case OP_CPSF:
6030 case OP_ENDI:
6031 case OP_oROR:
6032 case OP_PSR:
6033 case OP_RVC_PSR:
6034 case OP_COND:
6035 case OP_oBARRIER:
6036 case OP_REGLST:
6037 case OP_VRSLST:
6038 case OP_VRDLST:
6039 case OP_VRSDLST:
6040 case OP_NRDLST:
6041 case OP_NSTRLST:
6042 if (val == FAIL)
6043 goto failure;
6044 inst.operands[i].imm = val;
6045 break;
6047 default:
6048 break;
6051 /* If we get here, this operand was successfully parsed. */
6052 inst.operands[i].present = 1;
6053 continue;
6055 bad_args:
6056 inst.error = BAD_ARGS;
6058 failure:
6059 if (!backtrack_pos)
6061 /* The parse routine should already have set inst.error, but set a
6062 default here just in case. */
6063 if (!inst.error)
6064 inst.error = _("syntax error");
6065 return FAIL;
6068 /* Do not backtrack over a trailing optional argument that
6069 absorbed some text. We will only fail again, with the
6070 'garbage following instruction' error message, which is
6071 probably less helpful than the current one. */
6072 if (backtrack_index == i && backtrack_pos != str
6073 && upat[i+1] == OP_stop)
6075 if (!inst.error)
6076 inst.error = _("syntax error");
6077 return FAIL;
6080 /* Try again, skipping the optional argument at backtrack_pos. */
6081 str = backtrack_pos;
6082 inst.error = backtrack_error;
6083 inst.operands[backtrack_index].present = 0;
6084 i = backtrack_index;
6085 backtrack_pos = 0;
6088 /* Check that we have parsed all the arguments. */
6089 if (*str != '\0' && !inst.error)
6090 inst.error = _("garbage following instruction");
6092 return inst.error ? FAIL : SUCCESS;
6095 #undef po_char_or_fail
6096 #undef po_reg_or_fail
6097 #undef po_reg_or_goto
6098 #undef po_imm_or_fail
6099 #undef po_scalar_or_fail
6101 /* Shorthand macro for instruction encoding functions issuing errors. */
6102 #define constraint(expr, err) do { \
6103 if (expr) \
6105 inst.error = err; \
6106 return; \
6108 } while (0)
6110 /* Functions for operand encoding. ARM, then Thumb. */
6112 #define rotate_left(v, n) (v << n | v >> (32 - n))
6114 /* If VAL can be encoded in the immediate field of an ARM instruction,
6115 return the encoded form. Otherwise, return FAIL. */
6117 static unsigned int
6118 encode_arm_immediate (unsigned int val)
6120 unsigned int a, i;
6122 for (i = 0; i < 32; i += 2)
6123 if ((a = rotate_left (val, i)) <= 0xff)
6124 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6126 return FAIL;
6129 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6130 return the encoded form. Otherwise, return FAIL. */
6131 static unsigned int
6132 encode_thumb32_immediate (unsigned int val)
6134 unsigned int a, i;
6136 if (val <= 0xff)
6137 return val;
6139 for (i = 1; i <= 24; i++)
6141 a = val >> i;
6142 if ((val & ~(0xff << i)) == 0)
6143 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6146 a = val & 0xff;
6147 if (val == ((a << 16) | a))
6148 return 0x100 | a;
6149 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6150 return 0x300 | a;
6152 a = val & 0xff00;
6153 if (val == ((a << 16) | a))
6154 return 0x200 | (a >> 8);
6156 return FAIL;
6158 /* Encode a VFP SP or DP register number into inst.instruction. */
6160 static void
6161 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6163 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6164 && reg > 15)
6166 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6168 if (thumb_mode)
6169 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6170 fpu_vfp_ext_d32);
6171 else
6172 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6173 fpu_vfp_ext_d32);
6175 else
6177 first_error (_("D register out of range for selected VFP version"));
6178 return;
6182 switch (pos)
6184 case VFP_REG_Sd:
6185 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6186 break;
6188 case VFP_REG_Sn:
6189 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6190 break;
6192 case VFP_REG_Sm:
6193 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6194 break;
6196 case VFP_REG_Dd:
6197 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6198 break;
6200 case VFP_REG_Dn:
6201 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6202 break;
6204 case VFP_REG_Dm:
6205 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6206 break;
6208 default:
6209 abort ();
6213 /* Encode a <shift> in an ARM-format instruction. The immediate,
6214 if any, is handled by md_apply_fix. */
6215 static void
6216 encode_arm_shift (int i)
6218 if (inst.operands[i].shift_kind == SHIFT_RRX)
6219 inst.instruction |= SHIFT_ROR << 5;
6220 else
6222 inst.instruction |= inst.operands[i].shift_kind << 5;
6223 if (inst.operands[i].immisreg)
6225 inst.instruction |= SHIFT_BY_REG;
6226 inst.instruction |= inst.operands[i].imm << 8;
6228 else
6229 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6233 static void
6234 encode_arm_shifter_operand (int i)
6236 if (inst.operands[i].isreg)
6238 inst.instruction |= inst.operands[i].reg;
6239 encode_arm_shift (i);
6241 else
6242 inst.instruction |= INST_IMMEDIATE;
6245 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6246 static void
6247 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6249 assert (inst.operands[i].isreg);
6250 inst.instruction |= inst.operands[i].reg << 16;
6252 if (inst.operands[i].preind)
6254 if (is_t)
6256 inst.error = _("instruction does not accept preindexed addressing");
6257 return;
6259 inst.instruction |= PRE_INDEX;
6260 if (inst.operands[i].writeback)
6261 inst.instruction |= WRITE_BACK;
6264 else if (inst.operands[i].postind)
6266 assert (inst.operands[i].writeback);
6267 if (is_t)
6268 inst.instruction |= WRITE_BACK;
6270 else /* unindexed - only for coprocessor */
6272 inst.error = _("instruction does not accept unindexed addressing");
6273 return;
6276 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6277 && (((inst.instruction & 0x000f0000) >> 16)
6278 == ((inst.instruction & 0x0000f000) >> 12)))
6279 as_warn ((inst.instruction & LOAD_BIT)
6280 ? _("destination register same as write-back base")
6281 : _("source register same as write-back base"));
6284 /* inst.operands[i] was set up by parse_address. Encode it into an
6285 ARM-format mode 2 load or store instruction. If is_t is true,
6286 reject forms that cannot be used with a T instruction (i.e. not
6287 post-indexed). */
6288 static void
6289 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6291 encode_arm_addr_mode_common (i, is_t);
6293 if (inst.operands[i].immisreg)
6295 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6296 inst.instruction |= inst.operands[i].imm;
6297 if (!inst.operands[i].negative)
6298 inst.instruction |= INDEX_UP;
6299 if (inst.operands[i].shifted)
6301 if (inst.operands[i].shift_kind == SHIFT_RRX)
6302 inst.instruction |= SHIFT_ROR << 5;
6303 else
6305 inst.instruction |= inst.operands[i].shift_kind << 5;
6306 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6310 else /* immediate offset in inst.reloc */
6312 if (inst.reloc.type == BFD_RELOC_UNUSED)
6313 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6317 /* inst.operands[i] was set up by parse_address. Encode it into an
6318 ARM-format mode 3 load or store instruction. Reject forms that
6319 cannot be used with such instructions. If is_t is true, reject
6320 forms that cannot be used with a T instruction (i.e. not
6321 post-indexed). */
6322 static void
6323 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6325 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6327 inst.error = _("instruction does not accept scaled register index");
6328 return;
6331 encode_arm_addr_mode_common (i, is_t);
6333 if (inst.operands[i].immisreg)
6335 inst.instruction |= inst.operands[i].imm;
6336 if (!inst.operands[i].negative)
6337 inst.instruction |= INDEX_UP;
6339 else /* immediate offset in inst.reloc */
6341 inst.instruction |= HWOFFSET_IMM;
6342 if (inst.reloc.type == BFD_RELOC_UNUSED)
6343 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6347 /* inst.operands[i] was set up by parse_address. Encode it into an
6348 ARM-format instruction. Reject all forms which cannot be encoded
6349 into a coprocessor load/store instruction. If wb_ok is false,
6350 reject use of writeback; if unind_ok is false, reject use of
6351 unindexed addressing. If reloc_override is not 0, use it instead
6352 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6353 (in which case it is preserved). */
6355 static int
6356 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6358 inst.instruction |= inst.operands[i].reg << 16;
6360 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6362 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6364 assert (!inst.operands[i].writeback);
6365 if (!unind_ok)
6367 inst.error = _("instruction does not support unindexed addressing");
6368 return FAIL;
6370 inst.instruction |= inst.operands[i].imm;
6371 inst.instruction |= INDEX_UP;
6372 return SUCCESS;
6375 if (inst.operands[i].preind)
6376 inst.instruction |= PRE_INDEX;
6378 if (inst.operands[i].writeback)
6380 if (inst.operands[i].reg == REG_PC)
6382 inst.error = _("pc may not be used with write-back");
6383 return FAIL;
6385 if (!wb_ok)
6387 inst.error = _("instruction does not support writeback");
6388 return FAIL;
6390 inst.instruction |= WRITE_BACK;
6393 if (reloc_override)
6394 inst.reloc.type = reloc_override;
6395 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6396 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6397 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6399 if (thumb_mode)
6400 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6401 else
6402 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6405 return SUCCESS;
6408 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6409 Determine whether it can be performed with a move instruction; if
6410 it can, convert inst.instruction to that move instruction and
6411 return 1; if it can't, convert inst.instruction to a literal-pool
6412 load and return 0. If this is not a valid thing to do in the
6413 current context, set inst.error and return 1.
6415 inst.operands[i] describes the destination register. */
6417 static int
6418 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6420 unsigned long tbit;
6422 if (thumb_p)
6423 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6424 else
6425 tbit = LOAD_BIT;
6427 if ((inst.instruction & tbit) == 0)
6429 inst.error = _("invalid pseudo operation");
6430 return 1;
6432 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6434 inst.error = _("constant expression expected");
6435 return 1;
6437 if (inst.reloc.exp.X_op == O_constant)
6439 if (thumb_p)
6441 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6443 /* This can be done with a mov(1) instruction. */
6444 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6445 inst.instruction |= inst.reloc.exp.X_add_number;
6446 return 1;
6449 else
6451 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6452 if (value != FAIL)
6454 /* This can be done with a mov instruction. */
6455 inst.instruction &= LITERAL_MASK;
6456 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6457 inst.instruction |= value & 0xfff;
6458 return 1;
6461 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6462 if (value != FAIL)
6464 /* This can be done with a mvn instruction. */
6465 inst.instruction &= LITERAL_MASK;
6466 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6467 inst.instruction |= value & 0xfff;
6468 return 1;
6473 if (add_to_lit_pool () == FAIL)
6475 inst.error = _("literal pool insertion failed");
6476 return 1;
6478 inst.operands[1].reg = REG_PC;
6479 inst.operands[1].isreg = 1;
6480 inst.operands[1].preind = 1;
6481 inst.reloc.pc_rel = 1;
6482 inst.reloc.type = (thumb_p
6483 ? BFD_RELOC_ARM_THUMB_OFFSET
6484 : (mode_3
6485 ? BFD_RELOC_ARM_HWLITERAL
6486 : BFD_RELOC_ARM_LITERAL));
6487 return 0;
6490 /* Functions for instruction encoding, sorted by sub-architecture.
6491 First some generics; their names are taken from the conventional
6492 bit positions for register arguments in ARM format instructions. */
6494 static void
6495 do_noargs (void)
6499 static void
6500 do_rd (void)
6502 inst.instruction |= inst.operands[0].reg << 12;
6505 static void
6506 do_rd_rm (void)
6508 inst.instruction |= inst.operands[0].reg << 12;
6509 inst.instruction |= inst.operands[1].reg;
6512 static void
6513 do_rd_rn (void)
6515 inst.instruction |= inst.operands[0].reg << 12;
6516 inst.instruction |= inst.operands[1].reg << 16;
6519 static void
6520 do_rn_rd (void)
6522 inst.instruction |= inst.operands[0].reg << 16;
6523 inst.instruction |= inst.operands[1].reg << 12;
6526 static void
6527 do_rd_rm_rn (void)
6529 unsigned Rn = inst.operands[2].reg;
6530 /* Enforce restrictions on SWP instruction. */
6531 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6532 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6533 _("Rn must not overlap other operands"));
6534 inst.instruction |= inst.operands[0].reg << 12;
6535 inst.instruction |= inst.operands[1].reg;
6536 inst.instruction |= Rn << 16;
6539 static void
6540 do_rd_rn_rm (void)
6542 inst.instruction |= inst.operands[0].reg << 12;
6543 inst.instruction |= inst.operands[1].reg << 16;
6544 inst.instruction |= inst.operands[2].reg;
6547 static void
6548 do_rm_rd_rn (void)
6550 inst.instruction |= inst.operands[0].reg;
6551 inst.instruction |= inst.operands[1].reg << 12;
6552 inst.instruction |= inst.operands[2].reg << 16;
6555 static void
6556 do_imm0 (void)
6558 inst.instruction |= inst.operands[0].imm;
6561 static void
6562 do_rd_cpaddr (void)
6564 inst.instruction |= inst.operands[0].reg << 12;
6565 encode_arm_cp_address (1, TRUE, TRUE, 0);
6568 /* ARM instructions, in alphabetical order by function name (except
6569 that wrapper functions appear immediately after the function they
6570 wrap). */
6572 /* This is a pseudo-op of the form "adr rd, label" to be converted
6573 into a relative address of the form "add rd, pc, #label-.-8". */
6575 static void
6576 do_adr (void)
6578 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6580 /* Frag hacking will turn this into a sub instruction if the offset turns
6581 out to be negative. */
6582 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6583 inst.reloc.pc_rel = 1;
6584 inst.reloc.exp.X_add_number -= 8;
6587 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6588 into a relative address of the form:
6589 add rd, pc, #low(label-.-8)"
6590 add rd, rd, #high(label-.-8)" */
6592 static void
6593 do_adrl (void)
6595 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6597 /* Frag hacking will turn this into a sub instruction if the offset turns
6598 out to be negative. */
6599 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6600 inst.reloc.pc_rel = 1;
6601 inst.size = INSN_SIZE * 2;
6602 inst.reloc.exp.X_add_number -= 8;
6605 static void
6606 do_arit (void)
6608 if (!inst.operands[1].present)
6609 inst.operands[1].reg = inst.operands[0].reg;
6610 inst.instruction |= inst.operands[0].reg << 12;
6611 inst.instruction |= inst.operands[1].reg << 16;
6612 encode_arm_shifter_operand (2);
6615 static void
6616 do_barrier (void)
6618 if (inst.operands[0].present)
6620 constraint ((inst.instruction & 0xf0) != 0x40
6621 && inst.operands[0].imm != 0xf,
6622 _("bad barrier type"));
6623 inst.instruction |= inst.operands[0].imm;
6625 else
6626 inst.instruction |= 0xf;
6629 static void
6630 do_bfc (void)
6632 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6633 constraint (msb > 32, _("bit-field extends past end of register"));
6634 /* The instruction encoding stores the LSB and MSB,
6635 not the LSB and width. */
6636 inst.instruction |= inst.operands[0].reg << 12;
6637 inst.instruction |= inst.operands[1].imm << 7;
6638 inst.instruction |= (msb - 1) << 16;
6641 static void
6642 do_bfi (void)
6644 unsigned int msb;
6646 /* #0 in second position is alternative syntax for bfc, which is
6647 the same instruction but with REG_PC in the Rm field. */
6648 if (!inst.operands[1].isreg)
6649 inst.operands[1].reg = REG_PC;
6651 msb = inst.operands[2].imm + inst.operands[3].imm;
6652 constraint (msb > 32, _("bit-field extends past end of register"));
6653 /* The instruction encoding stores the LSB and MSB,
6654 not the LSB and width. */
6655 inst.instruction |= inst.operands[0].reg << 12;
6656 inst.instruction |= inst.operands[1].reg;
6657 inst.instruction |= inst.operands[2].imm << 7;
6658 inst.instruction |= (msb - 1) << 16;
6661 static void
6662 do_bfx (void)
6664 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6665 _("bit-field extends past end of register"));
6666 inst.instruction |= inst.operands[0].reg << 12;
6667 inst.instruction |= inst.operands[1].reg;
6668 inst.instruction |= inst.operands[2].imm << 7;
6669 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6672 /* ARM V5 breakpoint instruction (argument parse)
6673 BKPT <16 bit unsigned immediate>
6674 Instruction is not conditional.
6675 The bit pattern given in insns[] has the COND_ALWAYS condition,
6676 and it is an error if the caller tried to override that. */
6678 static void
6679 do_bkpt (void)
6681 /* Top 12 of 16 bits to bits 19:8. */
6682 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6684 /* Bottom 4 of 16 bits to bits 3:0. */
6685 inst.instruction |= inst.operands[0].imm & 0xf;
6688 static void
6689 encode_branch (int default_reloc)
6691 if (inst.operands[0].hasreloc)
6693 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6694 _("the only suffix valid here is '(plt)'"));
6695 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6697 else
6699 inst.reloc.type = default_reloc;
6701 inst.reloc.pc_rel = 1;
6704 static void
6705 do_branch (void)
6707 #ifdef OBJ_ELF
6708 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6709 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6710 else
6711 #endif
6712 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6715 static void
6716 do_bl (void)
6718 #ifdef OBJ_ELF
6719 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6721 if (inst.cond == COND_ALWAYS)
6722 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6723 else
6724 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6726 else
6727 #endif
6728 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6731 /* ARM V5 branch-link-exchange instruction (argument parse)
6732 BLX <target_addr> ie BLX(1)
6733 BLX{<condition>} <Rm> ie BLX(2)
6734 Unfortunately, there are two different opcodes for this mnemonic.
6735 So, the insns[].value is not used, and the code here zaps values
6736 into inst.instruction.
6737 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6739 static void
6740 do_blx (void)
6742 if (inst.operands[0].isreg)
6744 /* Arg is a register; the opcode provided by insns[] is correct.
6745 It is not illegal to do "blx pc", just useless. */
6746 if (inst.operands[0].reg == REG_PC)
6747 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6749 inst.instruction |= inst.operands[0].reg;
6751 else
6753 /* Arg is an address; this instruction cannot be executed
6754 conditionally, and the opcode must be adjusted. */
6755 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6756 inst.instruction = 0xfa000000;
6757 #ifdef OBJ_ELF
6758 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6759 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6760 else
6761 #endif
6762 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6766 static void
6767 do_bx (void)
6769 bfd_boolean want_reloc;
6771 if (inst.operands[0].reg == REG_PC)
6772 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6774 inst.instruction |= inst.operands[0].reg;
6775 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6776 it is for ARMv4t or earlier. */
6777 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6778 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6779 want_reloc = TRUE;
6781 #ifdef OBJ_ELF
6782 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
6783 #endif
6784 want_reloc = FALSE;
6786 if (want_reloc)
6787 inst.reloc.type = BFD_RELOC_ARM_V4BX;
6791 /* ARM v5TEJ. Jump to Jazelle code. */
6793 static void
6794 do_bxj (void)
6796 if (inst.operands[0].reg == REG_PC)
6797 as_tsktsk (_("use of r15 in bxj is not really useful"));
6799 inst.instruction |= inst.operands[0].reg;
6802 /* Co-processor data operation:
6803 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6804 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6805 static void
6806 do_cdp (void)
6808 inst.instruction |= inst.operands[0].reg << 8;
6809 inst.instruction |= inst.operands[1].imm << 20;
6810 inst.instruction |= inst.operands[2].reg << 12;
6811 inst.instruction |= inst.operands[3].reg << 16;
6812 inst.instruction |= inst.operands[4].reg;
6813 inst.instruction |= inst.operands[5].imm << 5;
6816 static void
6817 do_cmp (void)
6819 inst.instruction |= inst.operands[0].reg << 16;
6820 encode_arm_shifter_operand (1);
6823 /* Transfer between coprocessor and ARM registers.
6824 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6825 MRC2
6826 MCR{cond}
6827 MCR2
6829 No special properties. */
6831 static void
6832 do_co_reg (void)
6834 inst.instruction |= inst.operands[0].reg << 8;
6835 inst.instruction |= inst.operands[1].imm << 21;
6836 inst.instruction |= inst.operands[2].reg << 12;
6837 inst.instruction |= inst.operands[3].reg << 16;
6838 inst.instruction |= inst.operands[4].reg;
6839 inst.instruction |= inst.operands[5].imm << 5;
6842 /* Transfer between coprocessor register and pair of ARM registers.
6843 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6844 MCRR2
6845 MRRC{cond}
6846 MRRC2
6848 Two XScale instructions are special cases of these:
6850 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6851 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6853 Result unpredictable if Rd or Rn is R15. */
6855 static void
6856 do_co_reg2c (void)
6858 inst.instruction |= inst.operands[0].reg << 8;
6859 inst.instruction |= inst.operands[1].imm << 4;
6860 inst.instruction |= inst.operands[2].reg << 12;
6861 inst.instruction |= inst.operands[3].reg << 16;
6862 inst.instruction |= inst.operands[4].reg;
6865 static void
6866 do_cpsi (void)
6868 inst.instruction |= inst.operands[0].imm << 6;
6869 if (inst.operands[1].present)
6871 inst.instruction |= CPSI_MMOD;
6872 inst.instruction |= inst.operands[1].imm;
6876 static void
6877 do_dbg (void)
6879 inst.instruction |= inst.operands[0].imm;
6882 static void
6883 do_it (void)
6885 /* There is no IT instruction in ARM mode. We
6886 process it but do not generate code for it. */
6887 inst.size = 0;
6890 static void
6891 do_ldmstm (void)
6893 int base_reg = inst.operands[0].reg;
6894 int range = inst.operands[1].imm;
6896 inst.instruction |= base_reg << 16;
6897 inst.instruction |= range;
6899 if (inst.operands[1].writeback)
6900 inst.instruction |= LDM_TYPE_2_OR_3;
6902 if (inst.operands[0].writeback)
6904 inst.instruction |= WRITE_BACK;
6905 /* Check for unpredictable uses of writeback. */
6906 if (inst.instruction & LOAD_BIT)
6908 /* Not allowed in LDM type 2. */
6909 if ((inst.instruction & LDM_TYPE_2_OR_3)
6910 && ((range & (1 << REG_PC)) == 0))
6911 as_warn (_("writeback of base register is UNPREDICTABLE"));
6912 /* Only allowed if base reg not in list for other types. */
6913 else if (range & (1 << base_reg))
6914 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6916 else /* STM. */
6918 /* Not allowed for type 2. */
6919 if (inst.instruction & LDM_TYPE_2_OR_3)
6920 as_warn (_("writeback of base register is UNPREDICTABLE"));
6921 /* Only allowed if base reg not in list, or first in list. */
6922 else if ((range & (1 << base_reg))
6923 && (range & ((1 << base_reg) - 1)))
6924 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
6929 /* ARMv5TE load-consecutive (argument parse)
6930 Mode is like LDRH.
6932 LDRccD R, mode
6933 STRccD R, mode. */
6935 static void
6936 do_ldrd (void)
6938 constraint (inst.operands[0].reg % 2 != 0,
6939 _("first destination register must be even"));
6940 constraint (inst.operands[1].present
6941 && inst.operands[1].reg != inst.operands[0].reg + 1,
6942 _("can only load two consecutive registers"));
6943 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6944 constraint (!inst.operands[2].isreg, _("'[' expected"));
6946 if (!inst.operands[1].present)
6947 inst.operands[1].reg = inst.operands[0].reg + 1;
6949 if (inst.instruction & LOAD_BIT)
6951 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6952 register and the first register written; we have to diagnose
6953 overlap between the base and the second register written here. */
6955 if (inst.operands[2].reg == inst.operands[1].reg
6956 && (inst.operands[2].writeback || inst.operands[2].postind))
6957 as_warn (_("base register written back, and overlaps "
6958 "second destination register"));
6960 /* For an index-register load, the index register must not overlap the
6961 destination (even if not write-back). */
6962 else if (inst.operands[2].immisreg
6963 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6964 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
6965 as_warn (_("index register overlaps destination register"));
6968 inst.instruction |= inst.operands[0].reg << 12;
6969 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
6972 static void
6973 do_ldrex (void)
6975 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6976 || inst.operands[1].postind || inst.operands[1].writeback
6977 || inst.operands[1].immisreg || inst.operands[1].shifted
6978 || inst.operands[1].negative
6979 /* This can arise if the programmer has written
6980 strex rN, rM, foo
6981 or if they have mistakenly used a register name as the last
6982 operand, eg:
6983 strex rN, rM, rX
6984 It is very difficult to distinguish between these two cases
6985 because "rX" might actually be a label. ie the register
6986 name has been occluded by a symbol of the same name. So we
6987 just generate a general 'bad addressing mode' type error
6988 message and leave it up to the programmer to discover the
6989 true cause and fix their mistake. */
6990 || (inst.operands[1].reg == REG_PC),
6991 BAD_ADDR_MODE);
6993 constraint (inst.reloc.exp.X_op != O_constant
6994 || inst.reloc.exp.X_add_number != 0,
6995 _("offset must be zero in ARM encoding"));
6997 inst.instruction |= inst.operands[0].reg << 12;
6998 inst.instruction |= inst.operands[1].reg << 16;
6999 inst.reloc.type = BFD_RELOC_UNUSED;
7002 static void
7003 do_ldrexd (void)
7005 constraint (inst.operands[0].reg % 2 != 0,
7006 _("even register required"));
7007 constraint (inst.operands[1].present
7008 && inst.operands[1].reg != inst.operands[0].reg + 1,
7009 _("can only load two consecutive registers"));
7010 /* If op 1 were present and equal to PC, this function wouldn't
7011 have been called in the first place. */
7012 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7014 inst.instruction |= inst.operands[0].reg << 12;
7015 inst.instruction |= inst.operands[2].reg << 16;
7018 static void
7019 do_ldst (void)
7021 inst.instruction |= inst.operands[0].reg << 12;
7022 if (!inst.operands[1].isreg)
7023 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7024 return;
7025 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7028 static void
7029 do_ldstt (void)
7031 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7032 reject [Rn,...]. */
7033 if (inst.operands[1].preind)
7035 constraint (inst.reloc.exp.X_op != O_constant
7036 || inst.reloc.exp.X_add_number != 0,
7037 _("this instruction requires a post-indexed address"));
7039 inst.operands[1].preind = 0;
7040 inst.operands[1].postind = 1;
7041 inst.operands[1].writeback = 1;
7043 inst.instruction |= inst.operands[0].reg << 12;
7044 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7047 /* Halfword and signed-byte load/store operations. */
7049 static void
7050 do_ldstv4 (void)
7052 inst.instruction |= inst.operands[0].reg << 12;
7053 if (!inst.operands[1].isreg)
7054 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7055 return;
7056 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7059 static void
7060 do_ldsttv4 (void)
7062 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7063 reject [Rn,...]. */
7064 if (inst.operands[1].preind)
7066 constraint (inst.reloc.exp.X_op != O_constant
7067 || inst.reloc.exp.X_add_number != 0,
7068 _("this instruction requires a post-indexed address"));
7070 inst.operands[1].preind = 0;
7071 inst.operands[1].postind = 1;
7072 inst.operands[1].writeback = 1;
7074 inst.instruction |= inst.operands[0].reg << 12;
7075 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7078 /* Co-processor register load/store.
7079 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7080 static void
7081 do_lstc (void)
7083 inst.instruction |= inst.operands[0].reg << 8;
7084 inst.instruction |= inst.operands[1].reg << 12;
7085 encode_arm_cp_address (2, TRUE, TRUE, 0);
7088 static void
7089 do_mlas (void)
7091 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7092 if (inst.operands[0].reg == inst.operands[1].reg
7093 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7094 && !(inst.instruction & 0x00400000))
7095 as_tsktsk (_("Rd and Rm should be different in mla"));
7097 inst.instruction |= inst.operands[0].reg << 16;
7098 inst.instruction |= inst.operands[1].reg;
7099 inst.instruction |= inst.operands[2].reg << 8;
7100 inst.instruction |= inst.operands[3].reg << 12;
7103 static void
7104 do_mov (void)
7106 inst.instruction |= inst.operands[0].reg << 12;
7107 encode_arm_shifter_operand (1);
7110 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7111 static void
7112 do_mov16 (void)
7114 bfd_vma imm;
7115 bfd_boolean top;
7117 top = (inst.instruction & 0x00400000) != 0;
7118 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7119 _(":lower16: not allowed this instruction"));
7120 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7121 _(":upper16: not allowed instruction"));
7122 inst.instruction |= inst.operands[0].reg << 12;
7123 if (inst.reloc.type == BFD_RELOC_UNUSED)
7125 imm = inst.reloc.exp.X_add_number;
7126 /* The value is in two pieces: 0:11, 16:19. */
7127 inst.instruction |= (imm & 0x00000fff);
7128 inst.instruction |= (imm & 0x0000f000) << 4;
7132 static void do_vfp_nsyn_opcode (const char *);
7134 static int
7135 do_vfp_nsyn_mrs (void)
7137 if (inst.operands[0].isvec)
7139 if (inst.operands[1].reg != 1)
7140 first_error (_("operand 1 must be FPSCR"));
7141 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7142 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7143 do_vfp_nsyn_opcode ("fmstat");
7145 else if (inst.operands[1].isvec)
7146 do_vfp_nsyn_opcode ("fmrx");
7147 else
7148 return FAIL;
7150 return SUCCESS;
7153 static int
7154 do_vfp_nsyn_msr (void)
7156 if (inst.operands[0].isvec)
7157 do_vfp_nsyn_opcode ("fmxr");
7158 else
7159 return FAIL;
7161 return SUCCESS;
7164 static void
7165 do_mrs (void)
7167 if (do_vfp_nsyn_mrs () == SUCCESS)
7168 return;
7170 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7171 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7172 != (PSR_c|PSR_f),
7173 _("'CPSR' or 'SPSR' expected"));
7174 inst.instruction |= inst.operands[0].reg << 12;
7175 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7178 /* Two possible forms:
7179 "{C|S}PSR_<field>, Rm",
7180 "{C|S}PSR_f, #expression". */
7182 static void
7183 do_msr (void)
7185 if (do_vfp_nsyn_msr () == SUCCESS)
7186 return;
7188 inst.instruction |= inst.operands[0].imm;
7189 if (inst.operands[1].isreg)
7190 inst.instruction |= inst.operands[1].reg;
7191 else
7193 inst.instruction |= INST_IMMEDIATE;
7194 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7195 inst.reloc.pc_rel = 0;
7199 static void
7200 do_mul (void)
7202 if (!inst.operands[2].present)
7203 inst.operands[2].reg = inst.operands[0].reg;
7204 inst.instruction |= inst.operands[0].reg << 16;
7205 inst.instruction |= inst.operands[1].reg;
7206 inst.instruction |= inst.operands[2].reg << 8;
7208 if (inst.operands[0].reg == inst.operands[1].reg
7209 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7210 as_tsktsk (_("Rd and Rm should be different in mul"));
7213 /* Long Multiply Parser
7214 UMULL RdLo, RdHi, Rm, Rs
7215 SMULL RdLo, RdHi, Rm, Rs
7216 UMLAL RdLo, RdHi, Rm, Rs
7217 SMLAL RdLo, RdHi, Rm, Rs. */
7219 static void
7220 do_mull (void)
7222 inst.instruction |= inst.operands[0].reg << 12;
7223 inst.instruction |= inst.operands[1].reg << 16;
7224 inst.instruction |= inst.operands[2].reg;
7225 inst.instruction |= inst.operands[3].reg << 8;
7227 /* rdhi and rdlo must be different. */
7228 if (inst.operands[0].reg == inst.operands[1].reg)
7229 as_tsktsk (_("rdhi and rdlo must be different"));
7231 /* rdhi, rdlo and rm must all be different before armv6. */
7232 if ((inst.operands[0].reg == inst.operands[2].reg
7233 || inst.operands[1].reg == inst.operands[2].reg)
7234 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7235 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7238 static void
7239 do_nop (void)
7241 if (inst.operands[0].present)
7243 /* Architectural NOP hints are CPSR sets with no bits selected. */
7244 inst.instruction &= 0xf0000000;
7245 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7249 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7250 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7251 Condition defaults to COND_ALWAYS.
7252 Error if Rd, Rn or Rm are R15. */
7254 static void
7255 do_pkhbt (void)
7257 inst.instruction |= inst.operands[0].reg << 12;
7258 inst.instruction |= inst.operands[1].reg << 16;
7259 inst.instruction |= inst.operands[2].reg;
7260 if (inst.operands[3].present)
7261 encode_arm_shift (3);
7264 /* ARM V6 PKHTB (Argument Parse). */
7266 static void
7267 do_pkhtb (void)
7269 if (!inst.operands[3].present)
7271 /* If the shift specifier is omitted, turn the instruction
7272 into pkhbt rd, rm, rn. */
7273 inst.instruction &= 0xfff00010;
7274 inst.instruction |= inst.operands[0].reg << 12;
7275 inst.instruction |= inst.operands[1].reg;
7276 inst.instruction |= inst.operands[2].reg << 16;
7278 else
7280 inst.instruction |= inst.operands[0].reg << 12;
7281 inst.instruction |= inst.operands[1].reg << 16;
7282 inst.instruction |= inst.operands[2].reg;
7283 encode_arm_shift (3);
7287 /* ARMv5TE: Preload-Cache
7289 PLD <addr_mode>
7291 Syntactically, like LDR with B=1, W=0, L=1. */
7293 static void
7294 do_pld (void)
7296 constraint (!inst.operands[0].isreg,
7297 _("'[' expected after PLD mnemonic"));
7298 constraint (inst.operands[0].postind,
7299 _("post-indexed expression used in preload instruction"));
7300 constraint (inst.operands[0].writeback,
7301 _("writeback used in preload instruction"));
7302 constraint (!inst.operands[0].preind,
7303 _("unindexed addressing used in preload instruction"));
7304 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7307 /* ARMv7: PLI <addr_mode> */
7308 static void
7309 do_pli (void)
7311 constraint (!inst.operands[0].isreg,
7312 _("'[' expected after PLI mnemonic"));
7313 constraint (inst.operands[0].postind,
7314 _("post-indexed expression used in preload instruction"));
7315 constraint (inst.operands[0].writeback,
7316 _("writeback used in preload instruction"));
7317 constraint (!inst.operands[0].preind,
7318 _("unindexed addressing used in preload instruction"));
7319 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7320 inst.instruction &= ~PRE_INDEX;
7323 static void
7324 do_push_pop (void)
7326 inst.operands[1] = inst.operands[0];
7327 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7328 inst.operands[0].isreg = 1;
7329 inst.operands[0].writeback = 1;
7330 inst.operands[0].reg = REG_SP;
7331 do_ldmstm ();
7334 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7335 word at the specified address and the following word
7336 respectively.
7337 Unconditionally executed.
7338 Error if Rn is R15. */
7340 static void
7341 do_rfe (void)
7343 inst.instruction |= inst.operands[0].reg << 16;
7344 if (inst.operands[0].writeback)
7345 inst.instruction |= WRITE_BACK;
7348 /* ARM V6 ssat (argument parse). */
7350 static void
7351 do_ssat (void)
7353 inst.instruction |= inst.operands[0].reg << 12;
7354 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7355 inst.instruction |= inst.operands[2].reg;
7357 if (inst.operands[3].present)
7358 encode_arm_shift (3);
7361 /* ARM V6 usat (argument parse). */
7363 static void
7364 do_usat (void)
7366 inst.instruction |= inst.operands[0].reg << 12;
7367 inst.instruction |= inst.operands[1].imm << 16;
7368 inst.instruction |= inst.operands[2].reg;
7370 if (inst.operands[3].present)
7371 encode_arm_shift (3);
7374 /* ARM V6 ssat16 (argument parse). */
7376 static void
7377 do_ssat16 (void)
7379 inst.instruction |= inst.operands[0].reg << 12;
7380 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7381 inst.instruction |= inst.operands[2].reg;
7384 static void
7385 do_usat16 (void)
7387 inst.instruction |= inst.operands[0].reg << 12;
7388 inst.instruction |= inst.operands[1].imm << 16;
7389 inst.instruction |= inst.operands[2].reg;
7392 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7393 preserving the other bits.
7395 setend <endian_specifier>, where <endian_specifier> is either
7396 BE or LE. */
7398 static void
7399 do_setend (void)
7401 if (inst.operands[0].imm)
7402 inst.instruction |= 0x200;
7405 static void
7406 do_shift (void)
7408 unsigned int Rm = (inst.operands[1].present
7409 ? inst.operands[1].reg
7410 : inst.operands[0].reg);
7412 inst.instruction |= inst.operands[0].reg << 12;
7413 inst.instruction |= Rm;
7414 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7416 inst.instruction |= inst.operands[2].reg << 8;
7417 inst.instruction |= SHIFT_BY_REG;
7419 else
7420 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7423 static void
7424 do_smc (void)
7426 inst.reloc.type = BFD_RELOC_ARM_SMC;
7427 inst.reloc.pc_rel = 0;
7430 static void
7431 do_swi (void)
7433 inst.reloc.type = BFD_RELOC_ARM_SWI;
7434 inst.reloc.pc_rel = 0;
7437 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7438 SMLAxy{cond} Rd,Rm,Rs,Rn
7439 SMLAWy{cond} Rd,Rm,Rs,Rn
7440 Error if any register is R15. */
7442 static void
7443 do_smla (void)
7445 inst.instruction |= inst.operands[0].reg << 16;
7446 inst.instruction |= inst.operands[1].reg;
7447 inst.instruction |= inst.operands[2].reg << 8;
7448 inst.instruction |= inst.operands[3].reg << 12;
7451 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7452 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7453 Error if any register is R15.
7454 Warning if Rdlo == Rdhi. */
7456 static void
7457 do_smlal (void)
7459 inst.instruction |= inst.operands[0].reg << 12;
7460 inst.instruction |= inst.operands[1].reg << 16;
7461 inst.instruction |= inst.operands[2].reg;
7462 inst.instruction |= inst.operands[3].reg << 8;
7464 if (inst.operands[0].reg == inst.operands[1].reg)
7465 as_tsktsk (_("rdhi and rdlo must be different"));
7468 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7469 SMULxy{cond} Rd,Rm,Rs
7470 Error if any register is R15. */
7472 static void
7473 do_smul (void)
7475 inst.instruction |= inst.operands[0].reg << 16;
7476 inst.instruction |= inst.operands[1].reg;
7477 inst.instruction |= inst.operands[2].reg << 8;
7480 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7481 the same for both ARM and Thumb-2. */
7483 static void
7484 do_srs (void)
7486 int reg;
7488 if (inst.operands[0].present)
7490 reg = inst.operands[0].reg;
7491 constraint (reg != 13, _("SRS base register must be r13"));
7493 else
7494 reg = 13;
7496 inst.instruction |= reg << 16;
7497 inst.instruction |= inst.operands[1].imm;
7498 if (inst.operands[0].writeback || inst.operands[1].writeback)
7499 inst.instruction |= WRITE_BACK;
7502 /* ARM V6 strex (argument parse). */
7504 static void
7505 do_strex (void)
7507 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7508 || inst.operands[2].postind || inst.operands[2].writeback
7509 || inst.operands[2].immisreg || inst.operands[2].shifted
7510 || inst.operands[2].negative
7511 /* See comment in do_ldrex(). */
7512 || (inst.operands[2].reg == REG_PC),
7513 BAD_ADDR_MODE);
7515 constraint (inst.operands[0].reg == inst.operands[1].reg
7516 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7518 constraint (inst.reloc.exp.X_op != O_constant
7519 || inst.reloc.exp.X_add_number != 0,
7520 _("offset must be zero in ARM encoding"));
7522 inst.instruction |= inst.operands[0].reg << 12;
7523 inst.instruction |= inst.operands[1].reg;
7524 inst.instruction |= inst.operands[2].reg << 16;
7525 inst.reloc.type = BFD_RELOC_UNUSED;
7528 static void
7529 do_strexd (void)
7531 constraint (inst.operands[1].reg % 2 != 0,
7532 _("even register required"));
7533 constraint (inst.operands[2].present
7534 && inst.operands[2].reg != inst.operands[1].reg + 1,
7535 _("can only store two consecutive registers"));
7536 /* If op 2 were present and equal to PC, this function wouldn't
7537 have been called in the first place. */
7538 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7540 constraint (inst.operands[0].reg == inst.operands[1].reg
7541 || inst.operands[0].reg == inst.operands[1].reg + 1
7542 || inst.operands[0].reg == inst.operands[3].reg,
7543 BAD_OVERLAP);
7545 inst.instruction |= inst.operands[0].reg << 12;
7546 inst.instruction |= inst.operands[1].reg;
7547 inst.instruction |= inst.operands[3].reg << 16;
7550 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7551 extends it to 32-bits, and adds the result to a value in another
7552 register. You can specify a rotation by 0, 8, 16, or 24 bits
7553 before extracting the 16-bit value.
7554 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7555 Condition defaults to COND_ALWAYS.
7556 Error if any register uses R15. */
7558 static void
7559 do_sxtah (void)
7561 inst.instruction |= inst.operands[0].reg << 12;
7562 inst.instruction |= inst.operands[1].reg << 16;
7563 inst.instruction |= inst.operands[2].reg;
7564 inst.instruction |= inst.operands[3].imm << 10;
7567 /* ARM V6 SXTH.
7569 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7570 Condition defaults to COND_ALWAYS.
7571 Error if any register uses R15. */
7573 static void
7574 do_sxth (void)
7576 inst.instruction |= inst.operands[0].reg << 12;
7577 inst.instruction |= inst.operands[1].reg;
7578 inst.instruction |= inst.operands[2].imm << 10;
7581 /* VFP instructions. In a logical order: SP variant first, monad
7582 before dyad, arithmetic then move then load/store. */
7584 static void
7585 do_vfp_sp_monadic (void)
7587 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7588 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7591 static void
7592 do_vfp_sp_dyadic (void)
7594 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7595 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7596 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7599 static void
7600 do_vfp_sp_compare_z (void)
7602 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7605 static void
7606 do_vfp_dp_sp_cvt (void)
7608 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7609 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7612 static void
7613 do_vfp_sp_dp_cvt (void)
7615 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7616 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7619 static void
7620 do_vfp_reg_from_sp (void)
7622 inst.instruction |= inst.operands[0].reg << 12;
7623 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7626 static void
7627 do_vfp_reg2_from_sp2 (void)
7629 constraint (inst.operands[2].imm != 2,
7630 _("only two consecutive VFP SP registers allowed here"));
7631 inst.instruction |= inst.operands[0].reg << 12;
7632 inst.instruction |= inst.operands[1].reg << 16;
7633 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7636 static void
7637 do_vfp_sp_from_reg (void)
7639 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7640 inst.instruction |= inst.operands[1].reg << 12;
7643 static void
7644 do_vfp_sp2_from_reg2 (void)
7646 constraint (inst.operands[0].imm != 2,
7647 _("only two consecutive VFP SP registers allowed here"));
7648 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7649 inst.instruction |= inst.operands[1].reg << 12;
7650 inst.instruction |= inst.operands[2].reg << 16;
7653 static void
7654 do_vfp_sp_ldst (void)
7656 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7657 encode_arm_cp_address (1, FALSE, TRUE, 0);
7660 static void
7661 do_vfp_dp_ldst (void)
7663 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7664 encode_arm_cp_address (1, FALSE, TRUE, 0);
7668 static void
7669 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7671 if (inst.operands[0].writeback)
7672 inst.instruction |= WRITE_BACK;
7673 else
7674 constraint (ldstm_type != VFP_LDSTMIA,
7675 _("this addressing mode requires base-register writeback"));
7676 inst.instruction |= inst.operands[0].reg << 16;
7677 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7678 inst.instruction |= inst.operands[1].imm;
7681 static void
7682 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7684 int count;
7686 if (inst.operands[0].writeback)
7687 inst.instruction |= WRITE_BACK;
7688 else
7689 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7690 _("this addressing mode requires base-register writeback"));
7692 inst.instruction |= inst.operands[0].reg << 16;
7693 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7695 count = inst.operands[1].imm << 1;
7696 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7697 count += 1;
7699 inst.instruction |= count;
7702 static void
7703 do_vfp_sp_ldstmia (void)
7705 vfp_sp_ldstm (VFP_LDSTMIA);
7708 static void
7709 do_vfp_sp_ldstmdb (void)
7711 vfp_sp_ldstm (VFP_LDSTMDB);
7714 static void
7715 do_vfp_dp_ldstmia (void)
7717 vfp_dp_ldstm (VFP_LDSTMIA);
7720 static void
7721 do_vfp_dp_ldstmdb (void)
7723 vfp_dp_ldstm (VFP_LDSTMDB);
7726 static void
7727 do_vfp_xp_ldstmia (void)
7729 vfp_dp_ldstm (VFP_LDSTMIAX);
7732 static void
7733 do_vfp_xp_ldstmdb (void)
7735 vfp_dp_ldstm (VFP_LDSTMDBX);
7738 static void
7739 do_vfp_dp_rd_rm (void)
7741 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7742 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7745 static void
7746 do_vfp_dp_rn_rd (void)
7748 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7749 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7752 static void
7753 do_vfp_dp_rd_rn (void)
7755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7756 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7759 static void
7760 do_vfp_dp_rd_rn_rm (void)
7762 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7763 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7764 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7767 static void
7768 do_vfp_dp_rd (void)
7770 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7773 static void
7774 do_vfp_dp_rm_rd_rn (void)
7776 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7777 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7778 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7781 /* VFPv3 instructions. */
7782 static void
7783 do_vfp_sp_const (void)
7785 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7786 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7787 inst.instruction |= (inst.operands[1].imm & 0x0f);
7790 static void
7791 do_vfp_dp_const (void)
7793 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7794 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7795 inst.instruction |= (inst.operands[1].imm & 0x0f);
7798 static void
7799 vfp_conv (int srcsize)
7801 unsigned immbits = srcsize - inst.operands[1].imm;
7802 inst.instruction |= (immbits & 1) << 5;
7803 inst.instruction |= (immbits >> 1);
7806 static void
7807 do_vfp_sp_conv_16 (void)
7809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7810 vfp_conv (16);
7813 static void
7814 do_vfp_dp_conv_16 (void)
7816 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7817 vfp_conv (16);
7820 static void
7821 do_vfp_sp_conv_32 (void)
7823 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7824 vfp_conv (32);
7827 static void
7828 do_vfp_dp_conv_32 (void)
7830 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7831 vfp_conv (32);
7834 /* FPA instructions. Also in a logical order. */
7836 static void
7837 do_fpa_cmp (void)
7839 inst.instruction |= inst.operands[0].reg << 16;
7840 inst.instruction |= inst.operands[1].reg;
7843 static void
7844 do_fpa_ldmstm (void)
7846 inst.instruction |= inst.operands[0].reg << 12;
7847 switch (inst.operands[1].imm)
7849 case 1: inst.instruction |= CP_T_X; break;
7850 case 2: inst.instruction |= CP_T_Y; break;
7851 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7852 case 4: break;
7853 default: abort ();
7856 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7858 /* The instruction specified "ea" or "fd", so we can only accept
7859 [Rn]{!}. The instruction does not really support stacking or
7860 unstacking, so we have to emulate these by setting appropriate
7861 bits and offsets. */
7862 constraint (inst.reloc.exp.X_op != O_constant
7863 || inst.reloc.exp.X_add_number != 0,
7864 _("this instruction does not support indexing"));
7866 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7867 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7869 if (!(inst.instruction & INDEX_UP))
7870 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7872 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7874 inst.operands[2].preind = 0;
7875 inst.operands[2].postind = 1;
7879 encode_arm_cp_address (2, TRUE, TRUE, 0);
7882 /* iWMMXt instructions: strictly in alphabetical order. */
7884 static void
7885 do_iwmmxt_tandorc (void)
7887 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7890 static void
7891 do_iwmmxt_textrc (void)
7893 inst.instruction |= inst.operands[0].reg << 12;
7894 inst.instruction |= inst.operands[1].imm;
7897 static void
7898 do_iwmmxt_textrm (void)
7900 inst.instruction |= inst.operands[0].reg << 12;
7901 inst.instruction |= inst.operands[1].reg << 16;
7902 inst.instruction |= inst.operands[2].imm;
7905 static void
7906 do_iwmmxt_tinsr (void)
7908 inst.instruction |= inst.operands[0].reg << 16;
7909 inst.instruction |= inst.operands[1].reg << 12;
7910 inst.instruction |= inst.operands[2].imm;
7913 static void
7914 do_iwmmxt_tmia (void)
7916 inst.instruction |= inst.operands[0].reg << 5;
7917 inst.instruction |= inst.operands[1].reg;
7918 inst.instruction |= inst.operands[2].reg << 12;
7921 static void
7922 do_iwmmxt_waligni (void)
7924 inst.instruction |= inst.operands[0].reg << 12;
7925 inst.instruction |= inst.operands[1].reg << 16;
7926 inst.instruction |= inst.operands[2].reg;
7927 inst.instruction |= inst.operands[3].imm << 20;
7930 static void
7931 do_iwmmxt_wmerge (void)
7933 inst.instruction |= inst.operands[0].reg << 12;
7934 inst.instruction |= inst.operands[1].reg << 16;
7935 inst.instruction |= inst.operands[2].reg;
7936 inst.instruction |= inst.operands[3].imm << 21;
7939 static void
7940 do_iwmmxt_wmov (void)
7942 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7943 inst.instruction |= inst.operands[0].reg << 12;
7944 inst.instruction |= inst.operands[1].reg << 16;
7945 inst.instruction |= inst.operands[1].reg;
7948 static void
7949 do_iwmmxt_wldstbh (void)
7951 int reloc;
7952 inst.instruction |= inst.operands[0].reg << 12;
7953 if (thumb_mode)
7954 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7955 else
7956 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7957 encode_arm_cp_address (1, TRUE, FALSE, reloc);
7960 static void
7961 do_iwmmxt_wldstw (void)
7963 /* RIWR_RIWC clears .isreg for a control register. */
7964 if (!inst.operands[0].isreg)
7966 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7967 inst.instruction |= 0xf0000000;
7970 inst.instruction |= inst.operands[0].reg << 12;
7971 encode_arm_cp_address (1, TRUE, TRUE, 0);
7974 static void
7975 do_iwmmxt_wldstd (void)
7977 inst.instruction |= inst.operands[0].reg << 12;
7978 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7979 && inst.operands[1].immisreg)
7981 inst.instruction &= ~0x1a000ff;
7982 inst.instruction |= (0xf << 28);
7983 if (inst.operands[1].preind)
7984 inst.instruction |= PRE_INDEX;
7985 if (!inst.operands[1].negative)
7986 inst.instruction |= INDEX_UP;
7987 if (inst.operands[1].writeback)
7988 inst.instruction |= WRITE_BACK;
7989 inst.instruction |= inst.operands[1].reg << 16;
7990 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7991 inst.instruction |= inst.operands[1].imm;
7993 else
7994 encode_arm_cp_address (1, TRUE, FALSE, 0);
7997 static void
7998 do_iwmmxt_wshufh (void)
8000 inst.instruction |= inst.operands[0].reg << 12;
8001 inst.instruction |= inst.operands[1].reg << 16;
8002 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8003 inst.instruction |= (inst.operands[2].imm & 0x0f);
8006 static void
8007 do_iwmmxt_wzero (void)
8009 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8010 inst.instruction |= inst.operands[0].reg;
8011 inst.instruction |= inst.operands[0].reg << 12;
8012 inst.instruction |= inst.operands[0].reg << 16;
8015 static void
8016 do_iwmmxt_wrwrwr_or_imm5 (void)
8018 if (inst.operands[2].isreg)
8019 do_rd_rn_rm ();
8020 else {
8021 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8022 _("immediate operand requires iWMMXt2"));
8023 do_rd_rn ();
8024 if (inst.operands[2].imm == 0)
8026 switch ((inst.instruction >> 20) & 0xf)
8028 case 4:
8029 case 5:
8030 case 6:
8031 case 7:
8032 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8033 inst.operands[2].imm = 16;
8034 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8035 break;
8036 case 8:
8037 case 9:
8038 case 10:
8039 case 11:
8040 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8041 inst.operands[2].imm = 32;
8042 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8043 break;
8044 case 12:
8045 case 13:
8046 case 14:
8047 case 15:
8049 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8050 unsigned long wrn;
8051 wrn = (inst.instruction >> 16) & 0xf;
8052 inst.instruction &= 0xff0fff0f;
8053 inst.instruction |= wrn;
8054 /* Bail out here; the instruction is now assembled. */
8055 return;
8059 /* Map 32 -> 0, etc. */
8060 inst.operands[2].imm &= 0x1f;
8061 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8065 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8066 operations first, then control, shift, and load/store. */
8068 /* Insns like "foo X,Y,Z". */
8070 static void
8071 do_mav_triple (void)
8073 inst.instruction |= inst.operands[0].reg << 16;
8074 inst.instruction |= inst.operands[1].reg;
8075 inst.instruction |= inst.operands[2].reg << 12;
8078 /* Insns like "foo W,X,Y,Z".
8079 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8081 static void
8082 do_mav_quad (void)
8084 inst.instruction |= inst.operands[0].reg << 5;
8085 inst.instruction |= inst.operands[1].reg << 12;
8086 inst.instruction |= inst.operands[2].reg << 16;
8087 inst.instruction |= inst.operands[3].reg;
8090 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8091 static void
8092 do_mav_dspsc (void)
8094 inst.instruction |= inst.operands[1].reg << 12;
8097 /* Maverick shift immediate instructions.
8098 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8099 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8101 static void
8102 do_mav_shift (void)
8104 int imm = inst.operands[2].imm;
8106 inst.instruction |= inst.operands[0].reg << 12;
8107 inst.instruction |= inst.operands[1].reg << 16;
8109 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8110 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8111 Bit 4 should be 0. */
8112 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8114 inst.instruction |= imm;
8117 /* XScale instructions. Also sorted arithmetic before move. */
8119 /* Xscale multiply-accumulate (argument parse)
8120 MIAcc acc0,Rm,Rs
8121 MIAPHcc acc0,Rm,Rs
8122 MIAxycc acc0,Rm,Rs. */
8124 static void
8125 do_xsc_mia (void)
8127 inst.instruction |= inst.operands[1].reg;
8128 inst.instruction |= inst.operands[2].reg << 12;
8131 /* Xscale move-accumulator-register (argument parse)
8133 MARcc acc0,RdLo,RdHi. */
8135 static void
8136 do_xsc_mar (void)
8138 inst.instruction |= inst.operands[1].reg << 12;
8139 inst.instruction |= inst.operands[2].reg << 16;
8142 /* Xscale move-register-accumulator (argument parse)
8144 MRAcc RdLo,RdHi,acc0. */
8146 static void
8147 do_xsc_mra (void)
8149 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8150 inst.instruction |= inst.operands[0].reg << 12;
8151 inst.instruction |= inst.operands[1].reg << 16;
8154 /* Encoding functions relevant only to Thumb. */
8156 /* inst.operands[i] is a shifted-register operand; encode
8157 it into inst.instruction in the format used by Thumb32. */
8159 static void
8160 encode_thumb32_shifted_operand (int i)
8162 unsigned int value = inst.reloc.exp.X_add_number;
8163 unsigned int shift = inst.operands[i].shift_kind;
8165 constraint (inst.operands[i].immisreg,
8166 _("shift by register not allowed in thumb mode"));
8167 inst.instruction |= inst.operands[i].reg;
8168 if (shift == SHIFT_RRX)
8169 inst.instruction |= SHIFT_ROR << 4;
8170 else
8172 constraint (inst.reloc.exp.X_op != O_constant,
8173 _("expression too complex"));
8175 constraint (value > 32
8176 || (value == 32 && (shift == SHIFT_LSL
8177 || shift == SHIFT_ROR)),
8178 _("shift expression is too large"));
8180 if (value == 0)
8181 shift = SHIFT_LSL;
8182 else if (value == 32)
8183 value = 0;
8185 inst.instruction |= shift << 4;
8186 inst.instruction |= (value & 0x1c) << 10;
8187 inst.instruction |= (value & 0x03) << 6;
8192 /* inst.operands[i] was set up by parse_address. Encode it into a
8193 Thumb32 format load or store instruction. Reject forms that cannot
8194 be used with such instructions. If is_t is true, reject forms that
8195 cannot be used with a T instruction; if is_d is true, reject forms
8196 that cannot be used with a D instruction. */
8198 static void
8199 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8201 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8203 constraint (!inst.operands[i].isreg,
8204 _("Instruction does not support =N addresses"));
8206 inst.instruction |= inst.operands[i].reg << 16;
8207 if (inst.operands[i].immisreg)
8209 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8210 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8211 constraint (inst.operands[i].negative,
8212 _("Thumb does not support negative register indexing"));
8213 constraint (inst.operands[i].postind,
8214 _("Thumb does not support register post-indexing"));
8215 constraint (inst.operands[i].writeback,
8216 _("Thumb does not support register indexing with writeback"));
8217 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8218 _("Thumb supports only LSL in shifted register indexing"));
8220 inst.instruction |= inst.operands[i].imm;
8221 if (inst.operands[i].shifted)
8223 constraint (inst.reloc.exp.X_op != O_constant,
8224 _("expression too complex"));
8225 constraint (inst.reloc.exp.X_add_number < 0
8226 || inst.reloc.exp.X_add_number > 3,
8227 _("shift out of range"));
8228 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8230 inst.reloc.type = BFD_RELOC_UNUSED;
8232 else if (inst.operands[i].preind)
8234 constraint (is_pc && inst.operands[i].writeback,
8235 _("cannot use writeback with PC-relative addressing"));
8236 constraint (is_t && inst.operands[i].writeback,
8237 _("cannot use writeback with this instruction"));
8239 if (is_d)
8241 inst.instruction |= 0x01000000;
8242 if (inst.operands[i].writeback)
8243 inst.instruction |= 0x00200000;
8245 else
8247 inst.instruction |= 0x00000c00;
8248 if (inst.operands[i].writeback)
8249 inst.instruction |= 0x00000100;
8251 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8253 else if (inst.operands[i].postind)
8255 assert (inst.operands[i].writeback);
8256 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8257 constraint (is_t, _("cannot use post-indexing with this instruction"));
8259 if (is_d)
8260 inst.instruction |= 0x00200000;
8261 else
8262 inst.instruction |= 0x00000900;
8263 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8265 else /* unindexed - only for coprocessor */
8266 inst.error = _("instruction does not accept unindexed addressing");
8269 /* Table of Thumb instructions which exist in both 16- and 32-bit
8270 encodings (the latter only in post-V6T2 cores). The index is the
8271 value used in the insns table below. When there is more than one
8272 possible 16-bit encoding for the instruction, this table always
8273 holds variant (1).
8274 Also contains several pseudo-instructions used during relaxation. */
8275 #define T16_32_TAB \
8276 X(adc, 4140, eb400000), \
8277 X(adcs, 4140, eb500000), \
8278 X(add, 1c00, eb000000), \
8279 X(adds, 1c00, eb100000), \
8280 X(addi, 0000, f1000000), \
8281 X(addis, 0000, f1100000), \
8282 X(add_pc,000f, f20f0000), \
8283 X(add_sp,000d, f10d0000), \
8284 X(adr, 000f, f20f0000), \
8285 X(and, 4000, ea000000), \
8286 X(ands, 4000, ea100000), \
8287 X(asr, 1000, fa40f000), \
8288 X(asrs, 1000, fa50f000), \
8289 X(b, e000, f000b000), \
8290 X(bcond, d000, f0008000), \
8291 X(bic, 4380, ea200000), \
8292 X(bics, 4380, ea300000), \
8293 X(cmn, 42c0, eb100f00), \
8294 X(cmp, 2800, ebb00f00), \
8295 X(cpsie, b660, f3af8400), \
8296 X(cpsid, b670, f3af8600), \
8297 X(cpy, 4600, ea4f0000), \
8298 X(dec_sp,80dd, f1ad0d00), \
8299 X(eor, 4040, ea800000), \
8300 X(eors, 4040, ea900000), \
8301 X(inc_sp,00dd, f10d0d00), \
8302 X(ldmia, c800, e8900000), \
8303 X(ldr, 6800, f8500000), \
8304 X(ldrb, 7800, f8100000), \
8305 X(ldrh, 8800, f8300000), \
8306 X(ldrsb, 5600, f9100000), \
8307 X(ldrsh, 5e00, f9300000), \
8308 X(ldr_pc,4800, f85f0000), \
8309 X(ldr_pc2,4800, f85f0000), \
8310 X(ldr_sp,9800, f85d0000), \
8311 X(lsl, 0000, fa00f000), \
8312 X(lsls, 0000, fa10f000), \
8313 X(lsr, 0800, fa20f000), \
8314 X(lsrs, 0800, fa30f000), \
8315 X(mov, 2000, ea4f0000), \
8316 X(movs, 2000, ea5f0000), \
8317 X(mul, 4340, fb00f000), \
8318 X(muls, 4340, ffffffff), /* no 32b muls */ \
8319 X(mvn, 43c0, ea6f0000), \
8320 X(mvns, 43c0, ea7f0000), \
8321 X(neg, 4240, f1c00000), /* rsb #0 */ \
8322 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8323 X(orr, 4300, ea400000), \
8324 X(orrs, 4300, ea500000), \
8325 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8326 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8327 X(rev, ba00, fa90f080), \
8328 X(rev16, ba40, fa90f090), \
8329 X(revsh, bac0, fa90f0b0), \
8330 X(ror, 41c0, fa60f000), \
8331 X(rors, 41c0, fa70f000), \
8332 X(sbc, 4180, eb600000), \
8333 X(sbcs, 4180, eb700000), \
8334 X(stmia, c000, e8800000), \
8335 X(str, 6000, f8400000), \
8336 X(strb, 7000, f8000000), \
8337 X(strh, 8000, f8200000), \
8338 X(str_sp,9000, f84d0000), \
8339 X(sub, 1e00, eba00000), \
8340 X(subs, 1e00, ebb00000), \
8341 X(subi, 8000, f1a00000), \
8342 X(subis, 8000, f1b00000), \
8343 X(sxtb, b240, fa4ff080), \
8344 X(sxth, b200, fa0ff080), \
8345 X(tst, 4200, ea100f00), \
8346 X(uxtb, b2c0, fa5ff080), \
8347 X(uxth, b280, fa1ff080), \
8348 X(nop, bf00, f3af8000), \
8349 X(yield, bf10, f3af8001), \
8350 X(wfe, bf20, f3af8002), \
8351 X(wfi, bf30, f3af8003), \
8352 X(sev, bf40, f3af9004), /* typo, 8004? */
8354 /* To catch errors in encoding functions, the codes are all offset by
8355 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8356 as 16-bit instructions. */
8357 #define X(a,b,c) T_MNEM_##a
8358 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8359 #undef X
8361 #define X(a,b,c) 0x##b
8362 static const unsigned short thumb_op16[] = { T16_32_TAB };
8363 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8364 #undef X
8366 #define X(a,b,c) 0x##c
8367 static const unsigned int thumb_op32[] = { T16_32_TAB };
8368 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8369 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8370 #undef X
8371 #undef T16_32_TAB
8373 /* Thumb instruction encoders, in alphabetical order. */
8375 /* ADDW or SUBW. */
8376 static void
8377 do_t_add_sub_w (void)
8379 int Rd, Rn;
8381 Rd = inst.operands[0].reg;
8382 Rn = inst.operands[1].reg;
8384 constraint (Rd == 15, _("PC not allowed as destination"));
8385 inst.instruction |= (Rn << 16) | (Rd << 8);
8386 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8389 /* Parse an add or subtract instruction. We get here with inst.instruction
8390 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8392 static void
8393 do_t_add_sub (void)
8395 int Rd, Rs, Rn;
8397 Rd = inst.operands[0].reg;
8398 Rs = (inst.operands[1].present
8399 ? inst.operands[1].reg /* Rd, Rs, foo */
8400 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8402 if (unified_syntax)
8404 bfd_boolean flags;
8405 bfd_boolean narrow;
8406 int opcode;
8408 flags = (inst.instruction == T_MNEM_adds
8409 || inst.instruction == T_MNEM_subs);
8410 if (flags)
8411 narrow = (current_it_mask == 0);
8412 else
8413 narrow = (current_it_mask != 0);
8414 if (!inst.operands[2].isreg)
8416 int add;
8418 add = (inst.instruction == T_MNEM_add
8419 || inst.instruction == T_MNEM_adds);
8420 opcode = 0;
8421 if (inst.size_req != 4)
8423 /* Attempt to use a narrow opcode, with relaxation if
8424 appropriate. */
8425 if (Rd == REG_SP && Rs == REG_SP && !flags)
8426 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8427 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8428 opcode = T_MNEM_add_sp;
8429 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8430 opcode = T_MNEM_add_pc;
8431 else if (Rd <= 7 && Rs <= 7 && narrow)
8433 if (flags)
8434 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8435 else
8436 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8438 if (opcode)
8440 inst.instruction = THUMB_OP16(opcode);
8441 inst.instruction |= (Rd << 4) | Rs;
8442 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8443 if (inst.size_req != 2)
8444 inst.relax = opcode;
8446 else
8447 constraint (inst.size_req == 2, BAD_HIREG);
8449 if (inst.size_req == 4
8450 || (inst.size_req != 2 && !opcode))
8452 if (Rd == REG_PC)
8454 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8455 _("only SUBS PC, LR, #const allowed"));
8456 constraint (inst.reloc.exp.X_op != O_constant,
8457 _("expression too complex"));
8458 constraint (inst.reloc.exp.X_add_number < 0
8459 || inst.reloc.exp.X_add_number > 0xff,
8460 _("immediate value out of range"));
8461 inst.instruction = T2_SUBS_PC_LR
8462 | inst.reloc.exp.X_add_number;
8463 inst.reloc.type = BFD_RELOC_UNUSED;
8464 return;
8466 else if (Rs == REG_PC)
8468 /* Always use addw/subw. */
8469 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8470 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8472 else
8474 inst.instruction = THUMB_OP32 (inst.instruction);
8475 inst.instruction = (inst.instruction & 0xe1ffffff)
8476 | 0x10000000;
8477 if (flags)
8478 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8479 else
8480 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8482 inst.instruction |= Rd << 8;
8483 inst.instruction |= Rs << 16;
8486 else
8488 Rn = inst.operands[2].reg;
8489 /* See if we can do this with a 16-bit instruction. */
8490 if (!inst.operands[2].shifted && inst.size_req != 4)
8492 if (Rd > 7 || Rs > 7 || Rn > 7)
8493 narrow = FALSE;
8495 if (narrow)
8497 inst.instruction = ((inst.instruction == T_MNEM_adds
8498 || inst.instruction == T_MNEM_add)
8499 ? T_OPCODE_ADD_R3
8500 : T_OPCODE_SUB_R3);
8501 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8502 return;
8505 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
8507 /* Thumb-1 cores (except v6-M) require at least one high
8508 register in a narrow non flag setting add. */
8509 if (Rd > 7 || Rn > 7
8510 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8511 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
8513 if (Rd == Rn)
8515 Rn = Rs;
8516 Rs = Rd;
8518 inst.instruction = T_OPCODE_ADD_HI;
8519 inst.instruction |= (Rd & 8) << 4;
8520 inst.instruction |= (Rd & 7);
8521 inst.instruction |= Rn << 3;
8522 return;
8526 /* If we get here, it can't be done in 16 bits. */
8527 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8528 _("shift must be constant"));
8529 inst.instruction = THUMB_OP32 (inst.instruction);
8530 inst.instruction |= Rd << 8;
8531 inst.instruction |= Rs << 16;
8532 encode_thumb32_shifted_operand (2);
8535 else
8537 constraint (inst.instruction == T_MNEM_adds
8538 || inst.instruction == T_MNEM_subs,
8539 BAD_THUMB32);
8541 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8543 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8544 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8545 BAD_HIREG);
8547 inst.instruction = (inst.instruction == T_MNEM_add
8548 ? 0x0000 : 0x8000);
8549 inst.instruction |= (Rd << 4) | Rs;
8550 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8551 return;
8554 Rn = inst.operands[2].reg;
8555 constraint (inst.operands[2].shifted, _("unshifted register required"));
8557 /* We now have Rd, Rs, and Rn set to registers. */
8558 if (Rd > 7 || Rs > 7 || Rn > 7)
8560 /* Can't do this for SUB. */
8561 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8562 inst.instruction = T_OPCODE_ADD_HI;
8563 inst.instruction |= (Rd & 8) << 4;
8564 inst.instruction |= (Rd & 7);
8565 if (Rs == Rd)
8566 inst.instruction |= Rn << 3;
8567 else if (Rn == Rd)
8568 inst.instruction |= Rs << 3;
8569 else
8570 constraint (1, _("dest must overlap one source register"));
8572 else
8574 inst.instruction = (inst.instruction == T_MNEM_add
8575 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8576 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8581 static void
8582 do_t_adr (void)
8584 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8586 /* Defer to section relaxation. */
8587 inst.relax = inst.instruction;
8588 inst.instruction = THUMB_OP16 (inst.instruction);
8589 inst.instruction |= inst.operands[0].reg << 4;
8591 else if (unified_syntax && inst.size_req != 2)
8593 /* Generate a 32-bit opcode. */
8594 inst.instruction = THUMB_OP32 (inst.instruction);
8595 inst.instruction |= inst.operands[0].reg << 8;
8596 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8597 inst.reloc.pc_rel = 1;
8599 else
8601 /* Generate a 16-bit opcode. */
8602 inst.instruction = THUMB_OP16 (inst.instruction);
8603 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8604 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8605 inst.reloc.pc_rel = 1;
8607 inst.instruction |= inst.operands[0].reg << 4;
8611 /* Arithmetic instructions for which there is just one 16-bit
8612 instruction encoding, and it allows only two low registers.
8613 For maximal compatibility with ARM syntax, we allow three register
8614 operands even when Thumb-32 instructions are not available, as long
8615 as the first two are identical. For instance, both "sbc r0,r1" and
8616 "sbc r0,r0,r1" are allowed. */
8617 static void
8618 do_t_arit3 (void)
8620 int Rd, Rs, Rn;
8622 Rd = inst.operands[0].reg;
8623 Rs = (inst.operands[1].present
8624 ? inst.operands[1].reg /* Rd, Rs, foo */
8625 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8626 Rn = inst.operands[2].reg;
8628 if (unified_syntax)
8630 if (!inst.operands[2].isreg)
8632 /* For an immediate, we always generate a 32-bit opcode;
8633 section relaxation will shrink it later if possible. */
8634 inst.instruction = THUMB_OP32 (inst.instruction);
8635 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8636 inst.instruction |= Rd << 8;
8637 inst.instruction |= Rs << 16;
8638 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8640 else
8642 bfd_boolean narrow;
8644 /* See if we can do this with a 16-bit instruction. */
8645 if (THUMB_SETS_FLAGS (inst.instruction))
8646 narrow = current_it_mask == 0;
8647 else
8648 narrow = current_it_mask != 0;
8650 if (Rd > 7 || Rn > 7 || Rs > 7)
8651 narrow = FALSE;
8652 if (inst.operands[2].shifted)
8653 narrow = FALSE;
8654 if (inst.size_req == 4)
8655 narrow = FALSE;
8657 if (narrow
8658 && Rd == Rs)
8660 inst.instruction = THUMB_OP16 (inst.instruction);
8661 inst.instruction |= Rd;
8662 inst.instruction |= Rn << 3;
8663 return;
8666 /* If we get here, it can't be done in 16 bits. */
8667 constraint (inst.operands[2].shifted
8668 && inst.operands[2].immisreg,
8669 _("shift must be constant"));
8670 inst.instruction = THUMB_OP32 (inst.instruction);
8671 inst.instruction |= Rd << 8;
8672 inst.instruction |= Rs << 16;
8673 encode_thumb32_shifted_operand (2);
8676 else
8678 /* On its face this is a lie - the instruction does set the
8679 flags. However, the only supported mnemonic in this mode
8680 says it doesn't. */
8681 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8683 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8684 _("unshifted register required"));
8685 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8686 constraint (Rd != Rs,
8687 _("dest and source1 must be the same register"));
8689 inst.instruction = THUMB_OP16 (inst.instruction);
8690 inst.instruction |= Rd;
8691 inst.instruction |= Rn << 3;
8695 /* Similarly, but for instructions where the arithmetic operation is
8696 commutative, so we can allow either of them to be different from
8697 the destination operand in a 16-bit instruction. For instance, all
8698 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8699 accepted. */
8700 static void
8701 do_t_arit3c (void)
8703 int Rd, Rs, Rn;
8705 Rd = inst.operands[0].reg;
8706 Rs = (inst.operands[1].present
8707 ? inst.operands[1].reg /* Rd, Rs, foo */
8708 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8709 Rn = inst.operands[2].reg;
8711 if (unified_syntax)
8713 if (!inst.operands[2].isreg)
8715 /* For an immediate, we always generate a 32-bit opcode;
8716 section relaxation will shrink it later if possible. */
8717 inst.instruction = THUMB_OP32 (inst.instruction);
8718 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8719 inst.instruction |= Rd << 8;
8720 inst.instruction |= Rs << 16;
8721 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8723 else
8725 bfd_boolean narrow;
8727 /* See if we can do this with a 16-bit instruction. */
8728 if (THUMB_SETS_FLAGS (inst.instruction))
8729 narrow = current_it_mask == 0;
8730 else
8731 narrow = current_it_mask != 0;
8733 if (Rd > 7 || Rn > 7 || Rs > 7)
8734 narrow = FALSE;
8735 if (inst.operands[2].shifted)
8736 narrow = FALSE;
8737 if (inst.size_req == 4)
8738 narrow = FALSE;
8740 if (narrow)
8742 if (Rd == Rs)
8744 inst.instruction = THUMB_OP16 (inst.instruction);
8745 inst.instruction |= Rd;
8746 inst.instruction |= Rn << 3;
8747 return;
8749 if (Rd == Rn)
8751 inst.instruction = THUMB_OP16 (inst.instruction);
8752 inst.instruction |= Rd;
8753 inst.instruction |= Rs << 3;
8754 return;
8758 /* If we get here, it can't be done in 16 bits. */
8759 constraint (inst.operands[2].shifted
8760 && inst.operands[2].immisreg,
8761 _("shift must be constant"));
8762 inst.instruction = THUMB_OP32 (inst.instruction);
8763 inst.instruction |= Rd << 8;
8764 inst.instruction |= Rs << 16;
8765 encode_thumb32_shifted_operand (2);
8768 else
8770 /* On its face this is a lie - the instruction does set the
8771 flags. However, the only supported mnemonic in this mode
8772 says it doesn't. */
8773 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8775 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8776 _("unshifted register required"));
8777 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8779 inst.instruction = THUMB_OP16 (inst.instruction);
8780 inst.instruction |= Rd;
8782 if (Rd == Rs)
8783 inst.instruction |= Rn << 3;
8784 else if (Rd == Rn)
8785 inst.instruction |= Rs << 3;
8786 else
8787 constraint (1, _("dest must overlap one source register"));
8791 static void
8792 do_t_barrier (void)
8794 if (inst.operands[0].present)
8796 constraint ((inst.instruction & 0xf0) != 0x40
8797 && inst.operands[0].imm != 0xf,
8798 _("bad barrier type"));
8799 inst.instruction |= inst.operands[0].imm;
8801 else
8802 inst.instruction |= 0xf;
8805 static void
8806 do_t_bfc (void)
8808 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8809 constraint (msb > 32, _("bit-field extends past end of register"));
8810 /* The instruction encoding stores the LSB and MSB,
8811 not the LSB and width. */
8812 inst.instruction |= inst.operands[0].reg << 8;
8813 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8814 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8815 inst.instruction |= msb - 1;
8818 static void
8819 do_t_bfi (void)
8821 unsigned int msb;
8823 /* #0 in second position is alternative syntax for bfc, which is
8824 the same instruction but with REG_PC in the Rm field. */
8825 if (!inst.operands[1].isreg)
8826 inst.operands[1].reg = REG_PC;
8828 msb = inst.operands[2].imm + inst.operands[3].imm;
8829 constraint (msb > 32, _("bit-field extends past end of register"));
8830 /* The instruction encoding stores the LSB and MSB,
8831 not the LSB and width. */
8832 inst.instruction |= inst.operands[0].reg << 8;
8833 inst.instruction |= inst.operands[1].reg << 16;
8834 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8835 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8836 inst.instruction |= msb - 1;
8839 static void
8840 do_t_bfx (void)
8842 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8843 _("bit-field extends past end of register"));
8844 inst.instruction |= inst.operands[0].reg << 8;
8845 inst.instruction |= inst.operands[1].reg << 16;
8846 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8847 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8848 inst.instruction |= inst.operands[3].imm - 1;
8851 /* ARM V5 Thumb BLX (argument parse)
8852 BLX <target_addr> which is BLX(1)
8853 BLX <Rm> which is BLX(2)
8854 Unfortunately, there are two different opcodes for this mnemonic.
8855 So, the insns[].value is not used, and the code here zaps values
8856 into inst.instruction.
8858 ??? How to take advantage of the additional two bits of displacement
8859 available in Thumb32 mode? Need new relocation? */
8861 static void
8862 do_t_blx (void)
8864 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8865 if (inst.operands[0].isreg)
8866 /* We have a register, so this is BLX(2). */
8867 inst.instruction |= inst.operands[0].reg << 3;
8868 else
8870 /* No register. This must be BLX(1). */
8871 inst.instruction = 0xf000e800;
8872 #ifdef OBJ_ELF
8873 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8874 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8875 else
8876 #endif
8877 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
8878 inst.reloc.pc_rel = 1;
8882 static void
8883 do_t_branch (void)
8885 int opcode;
8886 int cond;
8888 if (current_it_mask)
8890 /* Conditional branches inside IT blocks are encoded as unconditional
8891 branches. */
8892 cond = COND_ALWAYS;
8893 /* A branch must be the last instruction in an IT block. */
8894 constraint (current_it_mask != 0x10, BAD_BRANCH);
8896 else
8897 cond = inst.cond;
8899 if (cond != COND_ALWAYS)
8900 opcode = T_MNEM_bcond;
8901 else
8902 opcode = inst.instruction;
8904 if (unified_syntax && inst.size_req == 4)
8906 inst.instruction = THUMB_OP32(opcode);
8907 if (cond == COND_ALWAYS)
8908 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
8909 else
8911 assert (cond != 0xF);
8912 inst.instruction |= cond << 22;
8913 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8916 else
8918 inst.instruction = THUMB_OP16(opcode);
8919 if (cond == COND_ALWAYS)
8920 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8921 else
8923 inst.instruction |= cond << 8;
8924 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
8926 /* Allow section relaxation. */
8927 if (unified_syntax && inst.size_req != 2)
8928 inst.relax = opcode;
8931 inst.reloc.pc_rel = 1;
8934 static void
8935 do_t_bkpt (void)
8937 constraint (inst.cond != COND_ALWAYS,
8938 _("instruction is always unconditional"));
8939 if (inst.operands[0].present)
8941 constraint (inst.operands[0].imm > 255,
8942 _("immediate value out of range"));
8943 inst.instruction |= inst.operands[0].imm;
8947 static void
8948 do_t_branch23 (void)
8950 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8951 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8952 inst.reloc.pc_rel = 1;
8954 /* If the destination of the branch is a defined symbol which does not have
8955 the THUMB_FUNC attribute, then we must be calling a function which has
8956 the (interfacearm) attribute. We look for the Thumb entry point to that
8957 function and change the branch to refer to that function instead. */
8958 if ( inst.reloc.exp.X_op == O_symbol
8959 && inst.reloc.exp.X_add_symbol != NULL
8960 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8961 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8962 inst.reloc.exp.X_add_symbol =
8963 find_real_start (inst.reloc.exp.X_add_symbol);
8966 static void
8967 do_t_bx (void)
8969 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8970 inst.instruction |= inst.operands[0].reg << 3;
8971 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8972 should cause the alignment to be checked once it is known. This is
8973 because BX PC only works if the instruction is word aligned. */
8976 static void
8977 do_t_bxj (void)
8979 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8980 if (inst.operands[0].reg == REG_PC)
8981 as_tsktsk (_("use of r15 in bxj is not really useful"));
8983 inst.instruction |= inst.operands[0].reg << 16;
8986 static void
8987 do_t_clz (void)
8989 inst.instruction |= inst.operands[0].reg << 8;
8990 inst.instruction |= inst.operands[1].reg << 16;
8991 inst.instruction |= inst.operands[1].reg;
8994 static void
8995 do_t_cps (void)
8997 constraint (current_it_mask, BAD_NOT_IT);
8998 inst.instruction |= inst.operands[0].imm;
9001 static void
9002 do_t_cpsi (void)
9004 constraint (current_it_mask, BAD_NOT_IT);
9005 if (unified_syntax
9006 && (inst.operands[1].present || inst.size_req == 4)
9007 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9009 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9010 inst.instruction = 0xf3af8000;
9011 inst.instruction |= imod << 9;
9012 inst.instruction |= inst.operands[0].imm << 5;
9013 if (inst.operands[1].present)
9014 inst.instruction |= 0x100 | inst.operands[1].imm;
9016 else
9018 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9019 && (inst.operands[0].imm & 4),
9020 _("selected processor does not support 'A' form "
9021 "of this instruction"));
9022 constraint (inst.operands[1].present || inst.size_req == 4,
9023 _("Thumb does not support the 2-argument "
9024 "form of this instruction"));
9025 inst.instruction |= inst.operands[0].imm;
9029 /* THUMB CPY instruction (argument parse). */
9031 static void
9032 do_t_cpy (void)
9034 if (inst.size_req == 4)
9036 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9037 inst.instruction |= inst.operands[0].reg << 8;
9038 inst.instruction |= inst.operands[1].reg;
9040 else
9042 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9043 inst.instruction |= (inst.operands[0].reg & 0x7);
9044 inst.instruction |= inst.operands[1].reg << 3;
9048 static void
9049 do_t_cbz (void)
9051 constraint (current_it_mask, BAD_NOT_IT);
9052 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9053 inst.instruction |= inst.operands[0].reg;
9054 inst.reloc.pc_rel = 1;
9055 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9058 static void
9059 do_t_dbg (void)
9061 inst.instruction |= inst.operands[0].imm;
9064 static void
9065 do_t_div (void)
9067 if (!inst.operands[1].present)
9068 inst.operands[1].reg = inst.operands[0].reg;
9069 inst.instruction |= inst.operands[0].reg << 8;
9070 inst.instruction |= inst.operands[1].reg << 16;
9071 inst.instruction |= inst.operands[2].reg;
9074 static void
9075 do_t_hint (void)
9077 if (unified_syntax && inst.size_req == 4)
9078 inst.instruction = THUMB_OP32 (inst.instruction);
9079 else
9080 inst.instruction = THUMB_OP16 (inst.instruction);
9083 static void
9084 do_t_it (void)
9086 unsigned int cond = inst.operands[0].imm;
9088 constraint (current_it_mask, BAD_NOT_IT);
9089 current_it_mask = (inst.instruction & 0xf) | 0x10;
9090 current_cc = cond;
9092 /* If the condition is a negative condition, invert the mask. */
9093 if ((cond & 0x1) == 0x0)
9095 unsigned int mask = inst.instruction & 0x000f;
9097 if ((mask & 0x7) == 0)
9098 /* no conversion needed */;
9099 else if ((mask & 0x3) == 0)
9100 mask ^= 0x8;
9101 else if ((mask & 0x1) == 0)
9102 mask ^= 0xC;
9103 else
9104 mask ^= 0xE;
9106 inst.instruction &= 0xfff0;
9107 inst.instruction |= mask;
9110 inst.instruction |= cond << 4;
9113 /* Helper function used for both push/pop and ldm/stm. */
9114 static void
9115 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9117 bfd_boolean load;
9119 load = (inst.instruction & (1 << 20)) != 0;
9121 if (mask & (1 << 13))
9122 inst.error = _("SP not allowed in register list");
9123 if (load)
9125 if (mask & (1 << 14)
9126 && mask & (1 << 15))
9127 inst.error = _("LR and PC should not both be in register list");
9129 if ((mask & (1 << base)) != 0
9130 && writeback)
9131 as_warn (_("base register should not be in register list "
9132 "when written back"));
9134 else
9136 if (mask & (1 << 15))
9137 inst.error = _("PC not allowed in register list");
9139 if (mask & (1 << base))
9140 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9143 if ((mask & (mask - 1)) == 0)
9145 /* Single register transfers implemented as str/ldr. */
9146 if (writeback)
9148 if (inst.instruction & (1 << 23))
9149 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9150 else
9151 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9153 else
9155 if (inst.instruction & (1 << 23))
9156 inst.instruction = 0x00800000; /* ia -> [base] */
9157 else
9158 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9161 inst.instruction |= 0xf8400000;
9162 if (load)
9163 inst.instruction |= 0x00100000;
9165 mask = ffs (mask) - 1;
9166 mask <<= 12;
9168 else if (writeback)
9169 inst.instruction |= WRITE_BACK;
9171 inst.instruction |= mask;
9172 inst.instruction |= base << 16;
9175 static void
9176 do_t_ldmstm (void)
9178 /* This really doesn't seem worth it. */
9179 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9180 _("expression too complex"));
9181 constraint (inst.operands[1].writeback,
9182 _("Thumb load/store multiple does not support {reglist}^"));
9184 if (unified_syntax)
9186 bfd_boolean narrow;
9187 unsigned mask;
9189 narrow = FALSE;
9190 /* See if we can use a 16-bit instruction. */
9191 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9192 && inst.size_req != 4
9193 && !(inst.operands[1].imm & ~0xff))
9195 mask = 1 << inst.operands[0].reg;
9197 if (inst.operands[0].reg <= 7
9198 && (inst.instruction == T_MNEM_stmia
9199 ? inst.operands[0].writeback
9200 : (inst.operands[0].writeback
9201 == !(inst.operands[1].imm & mask))))
9203 if (inst.instruction == T_MNEM_stmia
9204 && (inst.operands[1].imm & mask)
9205 && (inst.operands[1].imm & (mask - 1)))
9206 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9207 inst.operands[0].reg);
9209 inst.instruction = THUMB_OP16 (inst.instruction);
9210 inst.instruction |= inst.operands[0].reg << 8;
9211 inst.instruction |= inst.operands[1].imm;
9212 narrow = TRUE;
9214 else if (inst.operands[0] .reg == REG_SP
9215 && inst.operands[0].writeback)
9217 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9218 ? T_MNEM_push : T_MNEM_pop);
9219 inst.instruction |= inst.operands[1].imm;
9220 narrow = TRUE;
9224 if (!narrow)
9226 if (inst.instruction < 0xffff)
9227 inst.instruction = THUMB_OP32 (inst.instruction);
9229 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9230 inst.operands[0].writeback);
9233 else
9235 constraint (inst.operands[0].reg > 7
9236 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9237 constraint (inst.instruction != T_MNEM_ldmia
9238 && inst.instruction != T_MNEM_stmia,
9239 _("Thumb-2 instruction only valid in unified syntax"));
9240 if (inst.instruction == T_MNEM_stmia)
9242 if (!inst.operands[0].writeback)
9243 as_warn (_("this instruction will write back the base register"));
9244 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9245 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9246 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9247 inst.operands[0].reg);
9249 else
9251 if (!inst.operands[0].writeback
9252 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9253 as_warn (_("this instruction will write back the base register"));
9254 else if (inst.operands[0].writeback
9255 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9256 as_warn (_("this instruction will not write back the base register"));
9259 inst.instruction = THUMB_OP16 (inst.instruction);
9260 inst.instruction |= inst.operands[0].reg << 8;
9261 inst.instruction |= inst.operands[1].imm;
9265 static void
9266 do_t_ldrex (void)
9268 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9269 || inst.operands[1].postind || inst.operands[1].writeback
9270 || inst.operands[1].immisreg || inst.operands[1].shifted
9271 || inst.operands[1].negative,
9272 BAD_ADDR_MODE);
9274 inst.instruction |= inst.operands[0].reg << 12;
9275 inst.instruction |= inst.operands[1].reg << 16;
9276 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9279 static void
9280 do_t_ldrexd (void)
9282 if (!inst.operands[1].present)
9284 constraint (inst.operands[0].reg == REG_LR,
9285 _("r14 not allowed as first register "
9286 "when second register is omitted"));
9287 inst.operands[1].reg = inst.operands[0].reg + 1;
9289 constraint (inst.operands[0].reg == inst.operands[1].reg,
9290 BAD_OVERLAP);
9292 inst.instruction |= inst.operands[0].reg << 12;
9293 inst.instruction |= inst.operands[1].reg << 8;
9294 inst.instruction |= inst.operands[2].reg << 16;
9297 static void
9298 do_t_ldst (void)
9300 unsigned long opcode;
9301 int Rn;
9303 opcode = inst.instruction;
9304 if (unified_syntax)
9306 if (!inst.operands[1].isreg)
9308 if (opcode <= 0xffff)
9309 inst.instruction = THUMB_OP32 (opcode);
9310 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9311 return;
9313 if (inst.operands[1].isreg
9314 && !inst.operands[1].writeback
9315 && !inst.operands[1].shifted && !inst.operands[1].postind
9316 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9317 && opcode <= 0xffff
9318 && inst.size_req != 4)
9320 /* Insn may have a 16-bit form. */
9321 Rn = inst.operands[1].reg;
9322 if (inst.operands[1].immisreg)
9324 inst.instruction = THUMB_OP16 (opcode);
9325 /* [Rn, Rik] */
9326 if (Rn <= 7 && inst.operands[1].imm <= 7)
9327 goto op16;
9329 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9330 && opcode != T_MNEM_ldrsb)
9331 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9332 || (Rn == REG_SP && opcode == T_MNEM_str))
9334 /* [Rn, #const] */
9335 if (Rn > 7)
9337 if (Rn == REG_PC)
9339 if (inst.reloc.pc_rel)
9340 opcode = T_MNEM_ldr_pc2;
9341 else
9342 opcode = T_MNEM_ldr_pc;
9344 else
9346 if (opcode == T_MNEM_ldr)
9347 opcode = T_MNEM_ldr_sp;
9348 else
9349 opcode = T_MNEM_str_sp;
9351 inst.instruction = inst.operands[0].reg << 8;
9353 else
9355 inst.instruction = inst.operands[0].reg;
9356 inst.instruction |= inst.operands[1].reg << 3;
9358 inst.instruction |= THUMB_OP16 (opcode);
9359 if (inst.size_req == 2)
9360 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9361 else
9362 inst.relax = opcode;
9363 return;
9366 /* Definitely a 32-bit variant. */
9367 inst.instruction = THUMB_OP32 (opcode);
9368 inst.instruction |= inst.operands[0].reg << 12;
9369 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9370 return;
9373 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9375 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9377 /* Only [Rn,Rm] is acceptable. */
9378 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9379 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9380 || inst.operands[1].postind || inst.operands[1].shifted
9381 || inst.operands[1].negative,
9382 _("Thumb does not support this addressing mode"));
9383 inst.instruction = THUMB_OP16 (inst.instruction);
9384 goto op16;
9387 inst.instruction = THUMB_OP16 (inst.instruction);
9388 if (!inst.operands[1].isreg)
9389 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9390 return;
9392 constraint (!inst.operands[1].preind
9393 || inst.operands[1].shifted
9394 || inst.operands[1].writeback,
9395 _("Thumb does not support this addressing mode"));
9396 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9398 constraint (inst.instruction & 0x0600,
9399 _("byte or halfword not valid for base register"));
9400 constraint (inst.operands[1].reg == REG_PC
9401 && !(inst.instruction & THUMB_LOAD_BIT),
9402 _("r15 based store not allowed"));
9403 constraint (inst.operands[1].immisreg,
9404 _("invalid base register for register offset"));
9406 if (inst.operands[1].reg == REG_PC)
9407 inst.instruction = T_OPCODE_LDR_PC;
9408 else if (inst.instruction & THUMB_LOAD_BIT)
9409 inst.instruction = T_OPCODE_LDR_SP;
9410 else
9411 inst.instruction = T_OPCODE_STR_SP;
9413 inst.instruction |= inst.operands[0].reg << 8;
9414 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9415 return;
9418 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9419 if (!inst.operands[1].immisreg)
9421 /* Immediate offset. */
9422 inst.instruction |= inst.operands[0].reg;
9423 inst.instruction |= inst.operands[1].reg << 3;
9424 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9425 return;
9428 /* Register offset. */
9429 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9430 constraint (inst.operands[1].negative,
9431 _("Thumb does not support this addressing mode"));
9433 op16:
9434 switch (inst.instruction)
9436 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9437 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9438 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9439 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9440 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9441 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9442 case 0x5600 /* ldrsb */:
9443 case 0x5e00 /* ldrsh */: break;
9444 default: abort ();
9447 inst.instruction |= inst.operands[0].reg;
9448 inst.instruction |= inst.operands[1].reg << 3;
9449 inst.instruction |= inst.operands[1].imm << 6;
9452 static void
9453 do_t_ldstd (void)
9455 if (!inst.operands[1].present)
9457 inst.operands[1].reg = inst.operands[0].reg + 1;
9458 constraint (inst.operands[0].reg == REG_LR,
9459 _("r14 not allowed here"));
9461 inst.instruction |= inst.operands[0].reg << 12;
9462 inst.instruction |= inst.operands[1].reg << 8;
9463 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9466 static void
9467 do_t_ldstt (void)
9469 inst.instruction |= inst.operands[0].reg << 12;
9470 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9473 static void
9474 do_t_mla (void)
9476 inst.instruction |= inst.operands[0].reg << 8;
9477 inst.instruction |= inst.operands[1].reg << 16;
9478 inst.instruction |= inst.operands[2].reg;
9479 inst.instruction |= inst.operands[3].reg << 12;
9482 static void
9483 do_t_mlal (void)
9485 inst.instruction |= inst.operands[0].reg << 12;
9486 inst.instruction |= inst.operands[1].reg << 8;
9487 inst.instruction |= inst.operands[2].reg << 16;
9488 inst.instruction |= inst.operands[3].reg;
9491 static void
9492 do_t_mov_cmp (void)
9494 if (unified_syntax)
9496 int r0off = (inst.instruction == T_MNEM_mov
9497 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9498 unsigned long opcode;
9499 bfd_boolean narrow;
9500 bfd_boolean low_regs;
9502 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
9503 opcode = inst.instruction;
9504 if (current_it_mask)
9505 narrow = opcode != T_MNEM_movs;
9506 else
9507 narrow = opcode != T_MNEM_movs || low_regs;
9508 if (inst.size_req == 4
9509 || inst.operands[1].shifted)
9510 narrow = FALSE;
9512 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9513 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9514 && !inst.operands[1].shifted
9515 && inst.operands[0].reg == REG_PC
9516 && inst.operands[1].reg == REG_LR)
9518 inst.instruction = T2_SUBS_PC_LR;
9519 return;
9522 if (!inst.operands[1].isreg)
9524 /* Immediate operand. */
9525 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9526 narrow = 0;
9527 if (low_regs && narrow)
9529 inst.instruction = THUMB_OP16 (opcode);
9530 inst.instruction |= inst.operands[0].reg << 8;
9531 if (inst.size_req == 2)
9532 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9533 else
9534 inst.relax = opcode;
9536 else
9538 inst.instruction = THUMB_OP32 (inst.instruction);
9539 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9540 inst.instruction |= inst.operands[0].reg << r0off;
9541 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9544 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9545 && (inst.instruction == T_MNEM_mov
9546 || inst.instruction == T_MNEM_movs))
9548 /* Register shifts are encoded as separate shift instructions. */
9549 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9551 if (current_it_mask)
9552 narrow = !flags;
9553 else
9554 narrow = flags;
9556 if (inst.size_req == 4)
9557 narrow = FALSE;
9559 if (!low_regs || inst.operands[1].imm > 7)
9560 narrow = FALSE;
9562 if (inst.operands[0].reg != inst.operands[1].reg)
9563 narrow = FALSE;
9565 switch (inst.operands[1].shift_kind)
9567 case SHIFT_LSL:
9568 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9569 break;
9570 case SHIFT_ASR:
9571 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9572 break;
9573 case SHIFT_LSR:
9574 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9575 break;
9576 case SHIFT_ROR:
9577 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9578 break;
9579 default:
9580 abort ();
9583 inst.instruction = opcode;
9584 if (narrow)
9586 inst.instruction |= inst.operands[0].reg;
9587 inst.instruction |= inst.operands[1].imm << 3;
9589 else
9591 if (flags)
9592 inst.instruction |= CONDS_BIT;
9594 inst.instruction |= inst.operands[0].reg << 8;
9595 inst.instruction |= inst.operands[1].reg << 16;
9596 inst.instruction |= inst.operands[1].imm;
9599 else if (!narrow)
9601 /* Some mov with immediate shift have narrow variants.
9602 Register shifts are handled above. */
9603 if (low_regs && inst.operands[1].shifted
9604 && (inst.instruction == T_MNEM_mov
9605 || inst.instruction == T_MNEM_movs))
9607 if (current_it_mask)
9608 narrow = (inst.instruction == T_MNEM_mov);
9609 else
9610 narrow = (inst.instruction == T_MNEM_movs);
9613 if (narrow)
9615 switch (inst.operands[1].shift_kind)
9617 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9618 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9619 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9620 default: narrow = FALSE; break;
9624 if (narrow)
9626 inst.instruction |= inst.operands[0].reg;
9627 inst.instruction |= inst.operands[1].reg << 3;
9628 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9630 else
9632 inst.instruction = THUMB_OP32 (inst.instruction);
9633 inst.instruction |= inst.operands[0].reg << r0off;
9634 encode_thumb32_shifted_operand (1);
9637 else
9638 switch (inst.instruction)
9640 case T_MNEM_mov:
9641 inst.instruction = T_OPCODE_MOV_HR;
9642 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9643 inst.instruction |= (inst.operands[0].reg & 0x7);
9644 inst.instruction |= inst.operands[1].reg << 3;
9645 break;
9647 case T_MNEM_movs:
9648 /* We know we have low registers at this point.
9649 Generate ADD Rd, Rs, #0. */
9650 inst.instruction = T_OPCODE_ADD_I3;
9651 inst.instruction |= inst.operands[0].reg;
9652 inst.instruction |= inst.operands[1].reg << 3;
9653 break;
9655 case T_MNEM_cmp:
9656 if (low_regs)
9658 inst.instruction = T_OPCODE_CMP_LR;
9659 inst.instruction |= inst.operands[0].reg;
9660 inst.instruction |= inst.operands[1].reg << 3;
9662 else
9664 inst.instruction = T_OPCODE_CMP_HR;
9665 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9666 inst.instruction |= (inst.operands[0].reg & 0x7);
9667 inst.instruction |= inst.operands[1].reg << 3;
9669 break;
9671 return;
9674 inst.instruction = THUMB_OP16 (inst.instruction);
9675 if (inst.operands[1].isreg)
9677 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
9679 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9680 since a MOV instruction produces unpredictable results. */
9681 if (inst.instruction == T_OPCODE_MOV_I8)
9682 inst.instruction = T_OPCODE_ADD_I3;
9683 else
9684 inst.instruction = T_OPCODE_CMP_LR;
9686 inst.instruction |= inst.operands[0].reg;
9687 inst.instruction |= inst.operands[1].reg << 3;
9689 else
9691 if (inst.instruction == T_OPCODE_MOV_I8)
9692 inst.instruction = T_OPCODE_MOV_HR;
9693 else
9694 inst.instruction = T_OPCODE_CMP_HR;
9695 do_t_cpy ();
9698 else
9700 constraint (inst.operands[0].reg > 7,
9701 _("only lo regs allowed with immediate"));
9702 inst.instruction |= inst.operands[0].reg << 8;
9703 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9707 static void
9708 do_t_mov16 (void)
9710 bfd_vma imm;
9711 bfd_boolean top;
9713 top = (inst.instruction & 0x00800000) != 0;
9714 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9716 constraint (top, _(":lower16: not allowed this instruction"));
9717 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9719 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9721 constraint (!top, _(":upper16: not allowed this instruction"));
9722 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9725 inst.instruction |= inst.operands[0].reg << 8;
9726 if (inst.reloc.type == BFD_RELOC_UNUSED)
9728 imm = inst.reloc.exp.X_add_number;
9729 inst.instruction |= (imm & 0xf000) << 4;
9730 inst.instruction |= (imm & 0x0800) << 15;
9731 inst.instruction |= (imm & 0x0700) << 4;
9732 inst.instruction |= (imm & 0x00ff);
9736 static void
9737 do_t_mvn_tst (void)
9739 if (unified_syntax)
9741 int r0off = (inst.instruction == T_MNEM_mvn
9742 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9743 bfd_boolean narrow;
9745 if (inst.size_req == 4
9746 || inst.instruction > 0xffff
9747 || inst.operands[1].shifted
9748 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9749 narrow = FALSE;
9750 else if (inst.instruction == T_MNEM_cmn)
9751 narrow = TRUE;
9752 else if (THUMB_SETS_FLAGS (inst.instruction))
9753 narrow = (current_it_mask == 0);
9754 else
9755 narrow = (current_it_mask != 0);
9757 if (!inst.operands[1].isreg)
9759 /* For an immediate, we always generate a 32-bit opcode;
9760 section relaxation will shrink it later if possible. */
9761 if (inst.instruction < 0xffff)
9762 inst.instruction = THUMB_OP32 (inst.instruction);
9763 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9764 inst.instruction |= inst.operands[0].reg << r0off;
9765 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9767 else
9769 /* See if we can do this with a 16-bit instruction. */
9770 if (narrow)
9772 inst.instruction = THUMB_OP16 (inst.instruction);
9773 inst.instruction |= inst.operands[0].reg;
9774 inst.instruction |= inst.operands[1].reg << 3;
9776 else
9778 constraint (inst.operands[1].shifted
9779 && inst.operands[1].immisreg,
9780 _("shift must be constant"));
9781 if (inst.instruction < 0xffff)
9782 inst.instruction = THUMB_OP32 (inst.instruction);
9783 inst.instruction |= inst.operands[0].reg << r0off;
9784 encode_thumb32_shifted_operand (1);
9788 else
9790 constraint (inst.instruction > 0xffff
9791 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9792 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9793 _("unshifted register required"));
9794 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9795 BAD_HIREG);
9797 inst.instruction = THUMB_OP16 (inst.instruction);
9798 inst.instruction |= inst.operands[0].reg;
9799 inst.instruction |= inst.operands[1].reg << 3;
9803 static void
9804 do_t_mrs (void)
9806 int flags;
9808 if (do_vfp_nsyn_mrs () == SUCCESS)
9809 return;
9811 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9812 if (flags == 0)
9814 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
9815 _("selected processor does not support "
9816 "requested special purpose register"));
9818 else
9820 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9821 _("selected processor does not support "
9822 "requested special purpose register %x"));
9823 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9824 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9825 _("'CPSR' or 'SPSR' expected"));
9828 inst.instruction |= inst.operands[0].reg << 8;
9829 inst.instruction |= (flags & SPSR_BIT) >> 2;
9830 inst.instruction |= inst.operands[1].imm & 0xff;
9833 static void
9834 do_t_msr (void)
9836 int flags;
9838 if (do_vfp_nsyn_msr () == SUCCESS)
9839 return;
9841 constraint (!inst.operands[1].isreg,
9842 _("Thumb encoding does not support an immediate here"));
9843 flags = inst.operands[0].imm;
9844 if (flags & ~0xff)
9846 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9847 _("selected processor does not support "
9848 "requested special purpose register"));
9850 else
9852 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
9853 _("selected processor does not support "
9854 "requested special purpose register"));
9855 flags |= PSR_f;
9857 inst.instruction |= (flags & SPSR_BIT) >> 2;
9858 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9859 inst.instruction |= (flags & 0xff);
9860 inst.instruction |= inst.operands[1].reg << 16;
9863 static void
9864 do_t_mul (void)
9866 if (!inst.operands[2].present)
9867 inst.operands[2].reg = inst.operands[0].reg;
9869 /* There is no 32-bit MULS and no 16-bit MUL. */
9870 if (unified_syntax && inst.instruction == T_MNEM_mul)
9872 inst.instruction = THUMB_OP32 (inst.instruction);
9873 inst.instruction |= inst.operands[0].reg << 8;
9874 inst.instruction |= inst.operands[1].reg << 16;
9875 inst.instruction |= inst.operands[2].reg << 0;
9877 else
9879 constraint (!unified_syntax
9880 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9881 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9882 BAD_HIREG);
9884 inst.instruction = THUMB_OP16 (inst.instruction);
9885 inst.instruction |= inst.operands[0].reg;
9887 if (inst.operands[0].reg == inst.operands[1].reg)
9888 inst.instruction |= inst.operands[2].reg << 3;
9889 else if (inst.operands[0].reg == inst.operands[2].reg)
9890 inst.instruction |= inst.operands[1].reg << 3;
9891 else
9892 constraint (1, _("dest must overlap one source register"));
9896 static void
9897 do_t_mull (void)
9899 inst.instruction |= inst.operands[0].reg << 12;
9900 inst.instruction |= inst.operands[1].reg << 8;
9901 inst.instruction |= inst.operands[2].reg << 16;
9902 inst.instruction |= inst.operands[3].reg;
9904 if (inst.operands[0].reg == inst.operands[1].reg)
9905 as_tsktsk (_("rdhi and rdlo must be different"));
9908 static void
9909 do_t_nop (void)
9911 if (unified_syntax)
9913 if (inst.size_req == 4 || inst.operands[0].imm > 15)
9915 inst.instruction = THUMB_OP32 (inst.instruction);
9916 inst.instruction |= inst.operands[0].imm;
9918 else
9920 inst.instruction = THUMB_OP16 (inst.instruction);
9921 inst.instruction |= inst.operands[0].imm << 4;
9924 else
9926 constraint (inst.operands[0].present,
9927 _("Thumb does not support NOP with hints"));
9928 inst.instruction = 0x46c0;
9932 static void
9933 do_t_neg (void)
9935 if (unified_syntax)
9937 bfd_boolean narrow;
9939 if (THUMB_SETS_FLAGS (inst.instruction))
9940 narrow = (current_it_mask == 0);
9941 else
9942 narrow = (current_it_mask != 0);
9943 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9944 narrow = FALSE;
9945 if (inst.size_req == 4)
9946 narrow = FALSE;
9948 if (!narrow)
9950 inst.instruction = THUMB_OP32 (inst.instruction);
9951 inst.instruction |= inst.operands[0].reg << 8;
9952 inst.instruction |= inst.operands[1].reg << 16;
9954 else
9956 inst.instruction = THUMB_OP16 (inst.instruction);
9957 inst.instruction |= inst.operands[0].reg;
9958 inst.instruction |= inst.operands[1].reg << 3;
9961 else
9963 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9964 BAD_HIREG);
9965 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9967 inst.instruction = THUMB_OP16 (inst.instruction);
9968 inst.instruction |= inst.operands[0].reg;
9969 inst.instruction |= inst.operands[1].reg << 3;
9973 static void
9974 do_t_pkhbt (void)
9976 inst.instruction |= inst.operands[0].reg << 8;
9977 inst.instruction |= inst.operands[1].reg << 16;
9978 inst.instruction |= inst.operands[2].reg;
9979 if (inst.operands[3].present)
9981 unsigned int val = inst.reloc.exp.X_add_number;
9982 constraint (inst.reloc.exp.X_op != O_constant,
9983 _("expression too complex"));
9984 inst.instruction |= (val & 0x1c) << 10;
9985 inst.instruction |= (val & 0x03) << 6;
9989 static void
9990 do_t_pkhtb (void)
9992 if (!inst.operands[3].present)
9993 inst.instruction &= ~0x00000020;
9994 do_t_pkhbt ();
9997 static void
9998 do_t_pld (void)
10000 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10003 static void
10004 do_t_push_pop (void)
10006 unsigned mask;
10008 constraint (inst.operands[0].writeback,
10009 _("push/pop do not support {reglist}^"));
10010 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10011 _("expression too complex"));
10013 mask = inst.operands[0].imm;
10014 if ((mask & ~0xff) == 0)
10015 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10016 else if ((inst.instruction == T_MNEM_push
10017 && (mask & ~0xff) == 1 << REG_LR)
10018 || (inst.instruction == T_MNEM_pop
10019 && (mask & ~0xff) == 1 << REG_PC))
10021 inst.instruction = THUMB_OP16 (inst.instruction);
10022 inst.instruction |= THUMB_PP_PC_LR;
10023 inst.instruction |= mask & 0xff;
10025 else if (unified_syntax)
10027 inst.instruction = THUMB_OP32 (inst.instruction);
10028 encode_thumb2_ldmstm (13, mask, TRUE);
10030 else
10032 inst.error = _("invalid register list to push/pop instruction");
10033 return;
10037 static void
10038 do_t_rbit (void)
10040 inst.instruction |= inst.operands[0].reg << 8;
10041 inst.instruction |= inst.operands[1].reg << 16;
10044 static void
10045 do_t_rev (void)
10047 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10048 && inst.size_req != 4)
10050 inst.instruction = THUMB_OP16 (inst.instruction);
10051 inst.instruction |= inst.operands[0].reg;
10052 inst.instruction |= inst.operands[1].reg << 3;
10054 else if (unified_syntax)
10056 inst.instruction = THUMB_OP32 (inst.instruction);
10057 inst.instruction |= inst.operands[0].reg << 8;
10058 inst.instruction |= inst.operands[1].reg << 16;
10059 inst.instruction |= inst.operands[1].reg;
10061 else
10062 inst.error = BAD_HIREG;
10065 static void
10066 do_t_rsb (void)
10068 int Rd, Rs;
10070 Rd = inst.operands[0].reg;
10071 Rs = (inst.operands[1].present
10072 ? inst.operands[1].reg /* Rd, Rs, foo */
10073 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10075 inst.instruction |= Rd << 8;
10076 inst.instruction |= Rs << 16;
10077 if (!inst.operands[2].isreg)
10079 bfd_boolean narrow;
10081 if ((inst.instruction & 0x00100000) != 0)
10082 narrow = (current_it_mask == 0);
10083 else
10084 narrow = (current_it_mask != 0);
10086 if (Rd > 7 || Rs > 7)
10087 narrow = FALSE;
10089 if (inst.size_req == 4 || !unified_syntax)
10090 narrow = FALSE;
10092 if (inst.reloc.exp.X_op != O_constant
10093 || inst.reloc.exp.X_add_number != 0)
10094 narrow = FALSE;
10096 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10097 relaxation, but it doesn't seem worth the hassle. */
10098 if (narrow)
10100 inst.reloc.type = BFD_RELOC_UNUSED;
10101 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10102 inst.instruction |= Rs << 3;
10103 inst.instruction |= Rd;
10105 else
10107 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10108 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10111 else
10112 encode_thumb32_shifted_operand (2);
10115 static void
10116 do_t_setend (void)
10118 constraint (current_it_mask, BAD_NOT_IT);
10119 if (inst.operands[0].imm)
10120 inst.instruction |= 0x8;
10123 static void
10124 do_t_shift (void)
10126 if (!inst.operands[1].present)
10127 inst.operands[1].reg = inst.operands[0].reg;
10129 if (unified_syntax)
10131 bfd_boolean narrow;
10132 int shift_kind;
10134 switch (inst.instruction)
10136 case T_MNEM_asr:
10137 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10138 case T_MNEM_lsl:
10139 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10140 case T_MNEM_lsr:
10141 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10142 case T_MNEM_ror:
10143 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10144 default: abort ();
10147 if (THUMB_SETS_FLAGS (inst.instruction))
10148 narrow = (current_it_mask == 0);
10149 else
10150 narrow = (current_it_mask != 0);
10151 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10152 narrow = FALSE;
10153 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10154 narrow = FALSE;
10155 if (inst.operands[2].isreg
10156 && (inst.operands[1].reg != inst.operands[0].reg
10157 || inst.operands[2].reg > 7))
10158 narrow = FALSE;
10159 if (inst.size_req == 4)
10160 narrow = FALSE;
10162 if (!narrow)
10164 if (inst.operands[2].isreg)
10166 inst.instruction = THUMB_OP32 (inst.instruction);
10167 inst.instruction |= inst.operands[0].reg << 8;
10168 inst.instruction |= inst.operands[1].reg << 16;
10169 inst.instruction |= inst.operands[2].reg;
10171 else
10173 inst.operands[1].shifted = 1;
10174 inst.operands[1].shift_kind = shift_kind;
10175 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10176 ? T_MNEM_movs : T_MNEM_mov);
10177 inst.instruction |= inst.operands[0].reg << 8;
10178 encode_thumb32_shifted_operand (1);
10179 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10180 inst.reloc.type = BFD_RELOC_UNUSED;
10183 else
10185 if (inst.operands[2].isreg)
10187 switch (shift_kind)
10189 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10190 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10191 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10192 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
10193 default: abort ();
10196 inst.instruction |= inst.operands[0].reg;
10197 inst.instruction |= inst.operands[2].reg << 3;
10199 else
10201 switch (shift_kind)
10203 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10204 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10205 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10206 default: abort ();
10208 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10209 inst.instruction |= inst.operands[0].reg;
10210 inst.instruction |= inst.operands[1].reg << 3;
10214 else
10216 constraint (inst.operands[0].reg > 7
10217 || inst.operands[1].reg > 7, BAD_HIREG);
10218 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10220 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10222 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10223 constraint (inst.operands[0].reg != inst.operands[1].reg,
10224 _("source1 and dest must be same register"));
10226 switch (inst.instruction)
10228 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10229 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10230 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10231 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10232 default: abort ();
10235 inst.instruction |= inst.operands[0].reg;
10236 inst.instruction |= inst.operands[2].reg << 3;
10238 else
10240 switch (inst.instruction)
10242 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10243 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10244 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10245 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10246 default: abort ();
10248 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10249 inst.instruction |= inst.operands[0].reg;
10250 inst.instruction |= inst.operands[1].reg << 3;
10255 static void
10256 do_t_simd (void)
10258 inst.instruction |= inst.operands[0].reg << 8;
10259 inst.instruction |= inst.operands[1].reg << 16;
10260 inst.instruction |= inst.operands[2].reg;
10263 static void
10264 do_t_smc (void)
10266 unsigned int value = inst.reloc.exp.X_add_number;
10267 constraint (inst.reloc.exp.X_op != O_constant,
10268 _("expression too complex"));
10269 inst.reloc.type = BFD_RELOC_UNUSED;
10270 inst.instruction |= (value & 0xf000) >> 12;
10271 inst.instruction |= (value & 0x0ff0);
10272 inst.instruction |= (value & 0x000f) << 16;
10275 static void
10276 do_t_ssat (void)
10278 inst.instruction |= inst.operands[0].reg << 8;
10279 inst.instruction |= inst.operands[1].imm - 1;
10280 inst.instruction |= inst.operands[2].reg << 16;
10282 if (inst.operands[3].present)
10284 constraint (inst.reloc.exp.X_op != O_constant,
10285 _("expression too complex"));
10287 if (inst.reloc.exp.X_add_number != 0)
10289 if (inst.operands[3].shift_kind == SHIFT_ASR)
10290 inst.instruction |= 0x00200000; /* sh bit */
10291 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10292 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10294 inst.reloc.type = BFD_RELOC_UNUSED;
10298 static void
10299 do_t_ssat16 (void)
10301 inst.instruction |= inst.operands[0].reg << 8;
10302 inst.instruction |= inst.operands[1].imm - 1;
10303 inst.instruction |= inst.operands[2].reg << 16;
10306 static void
10307 do_t_strex (void)
10309 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10310 || inst.operands[2].postind || inst.operands[2].writeback
10311 || inst.operands[2].immisreg || inst.operands[2].shifted
10312 || inst.operands[2].negative,
10313 BAD_ADDR_MODE);
10315 inst.instruction |= inst.operands[0].reg << 8;
10316 inst.instruction |= inst.operands[1].reg << 12;
10317 inst.instruction |= inst.operands[2].reg << 16;
10318 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10321 static void
10322 do_t_strexd (void)
10324 if (!inst.operands[2].present)
10325 inst.operands[2].reg = inst.operands[1].reg + 1;
10327 constraint (inst.operands[0].reg == inst.operands[1].reg
10328 || inst.operands[0].reg == inst.operands[2].reg
10329 || inst.operands[0].reg == inst.operands[3].reg
10330 || inst.operands[1].reg == inst.operands[2].reg,
10331 BAD_OVERLAP);
10333 inst.instruction |= inst.operands[0].reg;
10334 inst.instruction |= inst.operands[1].reg << 12;
10335 inst.instruction |= inst.operands[2].reg << 8;
10336 inst.instruction |= inst.operands[3].reg << 16;
10339 static void
10340 do_t_sxtah (void)
10342 inst.instruction |= inst.operands[0].reg << 8;
10343 inst.instruction |= inst.operands[1].reg << 16;
10344 inst.instruction |= inst.operands[2].reg;
10345 inst.instruction |= inst.operands[3].imm << 4;
10348 static void
10349 do_t_sxth (void)
10351 if (inst.instruction <= 0xffff && inst.size_req != 4
10352 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10353 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10355 inst.instruction = THUMB_OP16 (inst.instruction);
10356 inst.instruction |= inst.operands[0].reg;
10357 inst.instruction |= inst.operands[1].reg << 3;
10359 else if (unified_syntax)
10361 if (inst.instruction <= 0xffff)
10362 inst.instruction = THUMB_OP32 (inst.instruction);
10363 inst.instruction |= inst.operands[0].reg << 8;
10364 inst.instruction |= inst.operands[1].reg;
10365 inst.instruction |= inst.operands[2].imm << 4;
10367 else
10369 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10370 _("Thumb encoding does not support rotation"));
10371 constraint (1, BAD_HIREG);
10375 static void
10376 do_t_swi (void)
10378 inst.reloc.type = BFD_RELOC_ARM_SWI;
10381 static void
10382 do_t_tb (void)
10384 int half;
10386 half = (inst.instruction & 0x10) != 0;
10387 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10388 constraint (inst.operands[0].immisreg,
10389 _("instruction requires register index"));
10390 constraint (inst.operands[0].imm == 15,
10391 _("PC is not a valid index register"));
10392 constraint (!half && inst.operands[0].shifted,
10393 _("instruction does not allow shifted index"));
10394 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10397 static void
10398 do_t_usat (void)
10400 inst.instruction |= inst.operands[0].reg << 8;
10401 inst.instruction |= inst.operands[1].imm;
10402 inst.instruction |= inst.operands[2].reg << 16;
10404 if (inst.operands[3].present)
10406 constraint (inst.reloc.exp.X_op != O_constant,
10407 _("expression too complex"));
10408 if (inst.reloc.exp.X_add_number != 0)
10410 if (inst.operands[3].shift_kind == SHIFT_ASR)
10411 inst.instruction |= 0x00200000; /* sh bit */
10413 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10414 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10416 inst.reloc.type = BFD_RELOC_UNUSED;
10420 static void
10421 do_t_usat16 (void)
10423 inst.instruction |= inst.operands[0].reg << 8;
10424 inst.instruction |= inst.operands[1].imm;
10425 inst.instruction |= inst.operands[2].reg << 16;
10428 /* Neon instruction encoder helpers. */
10430 /* Encodings for the different types for various Neon opcodes. */
10432 /* An "invalid" code for the following tables. */
10433 #define N_INV -1u
10435 struct neon_tab_entry
10437 unsigned integer;
10438 unsigned float_or_poly;
10439 unsigned scalar_or_imm;
10442 /* Map overloaded Neon opcodes to their respective encodings. */
10443 #define NEON_ENC_TAB \
10444 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10445 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10446 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10447 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10448 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10449 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10450 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10451 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10452 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10453 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10454 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10455 /* Register variants of the following two instructions are encoded as
10456 vcge / vcgt with the operands reversed. */ \
10457 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10458 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
10459 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10460 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10461 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10462 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10463 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10464 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10465 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10466 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10467 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10468 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10469 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10470 X(vshl, 0x0000400, N_INV, 0x0800510), \
10471 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10472 X(vand, 0x0000110, N_INV, 0x0800030), \
10473 X(vbic, 0x0100110, N_INV, 0x0800030), \
10474 X(veor, 0x1000110, N_INV, N_INV), \
10475 X(vorn, 0x0300110, N_INV, 0x0800010), \
10476 X(vorr, 0x0200110, N_INV, 0x0800010), \
10477 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10478 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10479 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10480 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10481 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10482 X(vst1, 0x0000000, 0x0800000, N_INV), \
10483 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10484 X(vst2, 0x0000100, 0x0800100, N_INV), \
10485 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10486 X(vst3, 0x0000200, 0x0800200, N_INV), \
10487 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10488 X(vst4, 0x0000300, 0x0800300, N_INV), \
10489 X(vmovn, 0x1b20200, N_INV, N_INV), \
10490 X(vtrn, 0x1b20080, N_INV, N_INV), \
10491 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10492 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10493 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10494 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10495 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10496 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10497 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10498 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10499 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10501 enum neon_opc
10503 #define X(OPC,I,F,S) N_MNEM_##OPC
10504 NEON_ENC_TAB
10505 #undef X
10508 static const struct neon_tab_entry neon_enc_tab[] =
10510 #define X(OPC,I,F,S) { (I), (F), (S) }
10511 NEON_ENC_TAB
10512 #undef X
10515 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10516 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10517 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10518 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10519 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10520 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10521 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10522 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10523 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10524 #define NEON_ENC_SINGLE(X) \
10525 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10526 #define NEON_ENC_DOUBLE(X) \
10527 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10529 /* Define shapes for instruction operands. The following mnemonic characters
10530 are used in this table:
10532 F - VFP S<n> register
10533 D - Neon D<n> register
10534 Q - Neon Q<n> register
10535 I - Immediate
10536 S - Scalar
10537 R - ARM register
10538 L - D<n> register list
10540 This table is used to generate various data:
10541 - enumerations of the form NS_DDR to be used as arguments to
10542 neon_select_shape.
10543 - a table classifying shapes into single, double, quad, mixed.
10544 - a table used to drive neon_select_shape. */
10546 #define NEON_SHAPE_DEF \
10547 X(3, (D, D, D), DOUBLE), \
10548 X(3, (Q, Q, Q), QUAD), \
10549 X(3, (D, D, I), DOUBLE), \
10550 X(3, (Q, Q, I), QUAD), \
10551 X(3, (D, D, S), DOUBLE), \
10552 X(3, (Q, Q, S), QUAD), \
10553 X(2, (D, D), DOUBLE), \
10554 X(2, (Q, Q), QUAD), \
10555 X(2, (D, S), DOUBLE), \
10556 X(2, (Q, S), QUAD), \
10557 X(2, (D, R), DOUBLE), \
10558 X(2, (Q, R), QUAD), \
10559 X(2, (D, I), DOUBLE), \
10560 X(2, (Q, I), QUAD), \
10561 X(3, (D, L, D), DOUBLE), \
10562 X(2, (D, Q), MIXED), \
10563 X(2, (Q, D), MIXED), \
10564 X(3, (D, Q, I), MIXED), \
10565 X(3, (Q, D, I), MIXED), \
10566 X(3, (Q, D, D), MIXED), \
10567 X(3, (D, Q, Q), MIXED), \
10568 X(3, (Q, Q, D), MIXED), \
10569 X(3, (Q, D, S), MIXED), \
10570 X(3, (D, Q, S), MIXED), \
10571 X(4, (D, D, D, I), DOUBLE), \
10572 X(4, (Q, Q, Q, I), QUAD), \
10573 X(2, (F, F), SINGLE), \
10574 X(3, (F, F, F), SINGLE), \
10575 X(2, (F, I), SINGLE), \
10576 X(2, (F, D), MIXED), \
10577 X(2, (D, F), MIXED), \
10578 X(3, (F, F, I), MIXED), \
10579 X(4, (R, R, F, F), SINGLE), \
10580 X(4, (F, F, R, R), SINGLE), \
10581 X(3, (D, R, R), DOUBLE), \
10582 X(3, (R, R, D), DOUBLE), \
10583 X(2, (S, R), SINGLE), \
10584 X(2, (R, S), SINGLE), \
10585 X(2, (F, R), SINGLE), \
10586 X(2, (R, F), SINGLE)
10588 #define S2(A,B) NS_##A##B
10589 #define S3(A,B,C) NS_##A##B##C
10590 #define S4(A,B,C,D) NS_##A##B##C##D
10592 #define X(N, L, C) S##N L
10594 enum neon_shape
10596 NEON_SHAPE_DEF,
10597 NS_NULL
10600 #undef X
10601 #undef S2
10602 #undef S3
10603 #undef S4
10605 enum neon_shape_class
10607 SC_SINGLE,
10608 SC_DOUBLE,
10609 SC_QUAD,
10610 SC_MIXED
10613 #define X(N, L, C) SC_##C
10615 static enum neon_shape_class neon_shape_class[] =
10617 NEON_SHAPE_DEF
10620 #undef X
10622 enum neon_shape_el
10624 SE_F,
10625 SE_D,
10626 SE_Q,
10627 SE_I,
10628 SE_S,
10629 SE_R,
10630 SE_L
10633 /* Register widths of above. */
10634 static unsigned neon_shape_el_size[] =
10638 128,
10645 struct neon_shape_info
10647 unsigned els;
10648 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10651 #define S2(A,B) { SE_##A, SE_##B }
10652 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10653 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10655 #define X(N, L, C) { N, S##N L }
10657 static struct neon_shape_info neon_shape_tab[] =
10659 NEON_SHAPE_DEF
10662 #undef X
10663 #undef S2
10664 #undef S3
10665 #undef S4
10667 /* Bit masks used in type checking given instructions.
10668 'N_EQK' means the type must be the same as (or based on in some way) the key
10669 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10670 set, various other bits can be set as well in order to modify the meaning of
10671 the type constraint. */
10673 enum neon_type_mask
10675 N_S8 = 0x000001,
10676 N_S16 = 0x000002,
10677 N_S32 = 0x000004,
10678 N_S64 = 0x000008,
10679 N_U8 = 0x000010,
10680 N_U16 = 0x000020,
10681 N_U32 = 0x000040,
10682 N_U64 = 0x000080,
10683 N_I8 = 0x000100,
10684 N_I16 = 0x000200,
10685 N_I32 = 0x000400,
10686 N_I64 = 0x000800,
10687 N_8 = 0x001000,
10688 N_16 = 0x002000,
10689 N_32 = 0x004000,
10690 N_64 = 0x008000,
10691 N_P8 = 0x010000,
10692 N_P16 = 0x020000,
10693 N_F32 = 0x040000,
10694 N_F64 = 0x080000,
10695 N_KEY = 0x100000, /* key element (main type specifier). */
10696 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10697 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
10698 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10699 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10700 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10701 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10702 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10703 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
10704 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
10705 N_UTYP = 0,
10706 N_MAX_NONSPECIAL = N_F64
10709 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10711 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10712 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10713 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10714 #define N_SUF_32 (N_SU_32 | N_F32)
10715 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10716 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10718 /* Pass this as the first type argument to neon_check_type to ignore types
10719 altogether. */
10720 #define N_IGNORE_TYPE (N_KEY | N_EQK)
10722 /* Select a "shape" for the current instruction (describing register types or
10723 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10724 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10725 function of operand parsing, so this function doesn't need to be called.
10726 Shapes should be listed in order of decreasing length. */
10728 static enum neon_shape
10729 neon_select_shape (enum neon_shape shape, ...)
10731 va_list ap;
10732 enum neon_shape first_shape = shape;
10734 /* Fix missing optional operands. FIXME: we don't know at this point how
10735 many arguments we should have, so this makes the assumption that we have
10736 > 1. This is true of all current Neon opcodes, I think, but may not be
10737 true in the future. */
10738 if (!inst.operands[1].present)
10739 inst.operands[1] = inst.operands[0];
10741 va_start (ap, shape);
10743 for (; shape != NS_NULL; shape = va_arg (ap, int))
10745 unsigned j;
10746 int matches = 1;
10748 for (j = 0; j < neon_shape_tab[shape].els; j++)
10750 if (!inst.operands[j].present)
10752 matches = 0;
10753 break;
10756 switch (neon_shape_tab[shape].el[j])
10758 case SE_F:
10759 if (!(inst.operands[j].isreg
10760 && inst.operands[j].isvec
10761 && inst.operands[j].issingle
10762 && !inst.operands[j].isquad))
10763 matches = 0;
10764 break;
10766 case SE_D:
10767 if (!(inst.operands[j].isreg
10768 && inst.operands[j].isvec
10769 && !inst.operands[j].isquad
10770 && !inst.operands[j].issingle))
10771 matches = 0;
10772 break;
10774 case SE_R:
10775 if (!(inst.operands[j].isreg
10776 && !inst.operands[j].isvec))
10777 matches = 0;
10778 break;
10780 case SE_Q:
10781 if (!(inst.operands[j].isreg
10782 && inst.operands[j].isvec
10783 && inst.operands[j].isquad
10784 && !inst.operands[j].issingle))
10785 matches = 0;
10786 break;
10788 case SE_I:
10789 if (!(!inst.operands[j].isreg
10790 && !inst.operands[j].isscalar))
10791 matches = 0;
10792 break;
10794 case SE_S:
10795 if (!(!inst.operands[j].isreg
10796 && inst.operands[j].isscalar))
10797 matches = 0;
10798 break;
10800 case SE_L:
10801 break;
10804 if (matches)
10805 break;
10808 va_end (ap);
10810 if (shape == NS_NULL && first_shape != NS_NULL)
10811 first_error (_("invalid instruction shape"));
10813 return shape;
10816 /* True if SHAPE is predominantly a quadword operation (most of the time, this
10817 means the Q bit should be set). */
10819 static int
10820 neon_quad (enum neon_shape shape)
10822 return neon_shape_class[shape] == SC_QUAD;
10825 static void
10826 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10827 unsigned *g_size)
10829 /* Allow modification to be made to types which are constrained to be
10830 based on the key element, based on bits set alongside N_EQK. */
10831 if ((typebits & N_EQK) != 0)
10833 if ((typebits & N_HLF) != 0)
10834 *g_size /= 2;
10835 else if ((typebits & N_DBL) != 0)
10836 *g_size *= 2;
10837 if ((typebits & N_SGN) != 0)
10838 *g_type = NT_signed;
10839 else if ((typebits & N_UNS) != 0)
10840 *g_type = NT_unsigned;
10841 else if ((typebits & N_INT) != 0)
10842 *g_type = NT_integer;
10843 else if ((typebits & N_FLT) != 0)
10844 *g_type = NT_float;
10845 else if ((typebits & N_SIZ) != 0)
10846 *g_type = NT_untyped;
10850 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10851 operand type, i.e. the single type specified in a Neon instruction when it
10852 is the only one given. */
10854 static struct neon_type_el
10855 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10857 struct neon_type_el dest = *key;
10859 assert ((thisarg & N_EQK) != 0);
10861 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10863 return dest;
10866 /* Convert Neon type and size into compact bitmask representation. */
10868 static enum neon_type_mask
10869 type_chk_of_el_type (enum neon_el_type type, unsigned size)
10871 switch (type)
10873 case NT_untyped:
10874 switch (size)
10876 case 8: return N_8;
10877 case 16: return N_16;
10878 case 32: return N_32;
10879 case 64: return N_64;
10880 default: ;
10882 break;
10884 case NT_integer:
10885 switch (size)
10887 case 8: return N_I8;
10888 case 16: return N_I16;
10889 case 32: return N_I32;
10890 case 64: return N_I64;
10891 default: ;
10893 break;
10895 case NT_float:
10896 switch (size)
10898 case 32: return N_F32;
10899 case 64: return N_F64;
10900 default: ;
10902 break;
10904 case NT_poly:
10905 switch (size)
10907 case 8: return N_P8;
10908 case 16: return N_P16;
10909 default: ;
10911 break;
10913 case NT_signed:
10914 switch (size)
10916 case 8: return N_S8;
10917 case 16: return N_S16;
10918 case 32: return N_S32;
10919 case 64: return N_S64;
10920 default: ;
10922 break;
10924 case NT_unsigned:
10925 switch (size)
10927 case 8: return N_U8;
10928 case 16: return N_U16;
10929 case 32: return N_U32;
10930 case 64: return N_U64;
10931 default: ;
10933 break;
10935 default: ;
10938 return N_UTYP;
10941 /* Convert compact Neon bitmask type representation to a type and size. Only
10942 handles the case where a single bit is set in the mask. */
10944 static int
10945 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10946 enum neon_type_mask mask)
10948 if ((mask & N_EQK) != 0)
10949 return FAIL;
10951 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10952 *size = 8;
10953 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
10954 *size = 16;
10955 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
10956 *size = 32;
10957 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
10958 *size = 64;
10959 else
10960 return FAIL;
10962 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10963 *type = NT_signed;
10964 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
10965 *type = NT_unsigned;
10966 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
10967 *type = NT_integer;
10968 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
10969 *type = NT_untyped;
10970 else if ((mask & (N_P8 | N_P16)) != 0)
10971 *type = NT_poly;
10972 else if ((mask & (N_F32 | N_F64)) != 0)
10973 *type = NT_float;
10974 else
10975 return FAIL;
10977 return SUCCESS;
10980 /* Modify a bitmask of allowed types. This is only needed for type
10981 relaxation. */
10983 static unsigned
10984 modify_types_allowed (unsigned allowed, unsigned mods)
10986 unsigned size;
10987 enum neon_el_type type;
10988 unsigned destmask;
10989 int i;
10991 destmask = 0;
10993 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10995 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10997 neon_modify_type_size (mods, &type, &size);
10998 destmask |= type_chk_of_el_type (type, size);
11002 return destmask;
11005 /* Check type and return type classification.
11006 The manual states (paraphrase): If one datatype is given, it indicates the
11007 type given in:
11008 - the second operand, if there is one
11009 - the operand, if there is no second operand
11010 - the result, if there are no operands.
11011 This isn't quite good enough though, so we use a concept of a "key" datatype
11012 which is set on a per-instruction basis, which is the one which matters when
11013 only one data type is written.
11014 Note: this function has side-effects (e.g. filling in missing operands). All
11015 Neon instructions should call it before performing bit encoding. */
11017 static struct neon_type_el
11018 neon_check_type (unsigned els, enum neon_shape ns, ...)
11020 va_list ap;
11021 unsigned i, pass, key_el = 0;
11022 unsigned types[NEON_MAX_TYPE_ELS];
11023 enum neon_el_type k_type = NT_invtype;
11024 unsigned k_size = -1u;
11025 struct neon_type_el badtype = {NT_invtype, -1};
11026 unsigned key_allowed = 0;
11028 /* Optional registers in Neon instructions are always (not) in operand 1.
11029 Fill in the missing operand here, if it was omitted. */
11030 if (els > 1 && !inst.operands[1].present)
11031 inst.operands[1] = inst.operands[0];
11033 /* Suck up all the varargs. */
11034 va_start (ap, ns);
11035 for (i = 0; i < els; i++)
11037 unsigned thisarg = va_arg (ap, unsigned);
11038 if (thisarg == N_IGNORE_TYPE)
11040 va_end (ap);
11041 return badtype;
11043 types[i] = thisarg;
11044 if ((thisarg & N_KEY) != 0)
11045 key_el = i;
11047 va_end (ap);
11049 if (inst.vectype.elems > 0)
11050 for (i = 0; i < els; i++)
11051 if (inst.operands[i].vectype.type != NT_invtype)
11053 first_error (_("types specified in both the mnemonic and operands"));
11054 return badtype;
11057 /* Duplicate inst.vectype elements here as necessary.
11058 FIXME: No idea if this is exactly the same as the ARM assembler,
11059 particularly when an insn takes one register and one non-register
11060 operand. */
11061 if (inst.vectype.elems == 1 && els > 1)
11063 unsigned j;
11064 inst.vectype.elems = els;
11065 inst.vectype.el[key_el] = inst.vectype.el[0];
11066 for (j = 0; j < els; j++)
11067 if (j != key_el)
11068 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11069 types[j]);
11071 else if (inst.vectype.elems == 0 && els > 0)
11073 unsigned j;
11074 /* No types were given after the mnemonic, so look for types specified
11075 after each operand. We allow some flexibility here; as long as the
11076 "key" operand has a type, we can infer the others. */
11077 for (j = 0; j < els; j++)
11078 if (inst.operands[j].vectype.type != NT_invtype)
11079 inst.vectype.el[j] = inst.operands[j].vectype;
11081 if (inst.operands[key_el].vectype.type != NT_invtype)
11083 for (j = 0; j < els; j++)
11084 if (inst.operands[j].vectype.type == NT_invtype)
11085 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11086 types[j]);
11088 else
11090 first_error (_("operand types can't be inferred"));
11091 return badtype;
11094 else if (inst.vectype.elems != els)
11096 first_error (_("type specifier has the wrong number of parts"));
11097 return badtype;
11100 for (pass = 0; pass < 2; pass++)
11102 for (i = 0; i < els; i++)
11104 unsigned thisarg = types[i];
11105 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11106 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11107 enum neon_el_type g_type = inst.vectype.el[i].type;
11108 unsigned g_size = inst.vectype.el[i].size;
11110 /* Decay more-specific signed & unsigned types to sign-insensitive
11111 integer types if sign-specific variants are unavailable. */
11112 if ((g_type == NT_signed || g_type == NT_unsigned)
11113 && (types_allowed & N_SU_ALL) == 0)
11114 g_type = NT_integer;
11116 /* If only untyped args are allowed, decay any more specific types to
11117 them. Some instructions only care about signs for some element
11118 sizes, so handle that properly. */
11119 if ((g_size == 8 && (types_allowed & N_8) != 0)
11120 || (g_size == 16 && (types_allowed & N_16) != 0)
11121 || (g_size == 32 && (types_allowed & N_32) != 0)
11122 || (g_size == 64 && (types_allowed & N_64) != 0))
11123 g_type = NT_untyped;
11125 if (pass == 0)
11127 if ((thisarg & N_KEY) != 0)
11129 k_type = g_type;
11130 k_size = g_size;
11131 key_allowed = thisarg & ~N_KEY;
11134 else
11136 if ((thisarg & N_VFP) != 0)
11138 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11139 unsigned regwidth = neon_shape_el_size[regshape], match;
11141 /* In VFP mode, operands must match register widths. If we
11142 have a key operand, use its width, else use the width of
11143 the current operand. */
11144 if (k_size != -1u)
11145 match = k_size;
11146 else
11147 match = g_size;
11149 if (regwidth != match)
11151 first_error (_("operand size must match register width"));
11152 return badtype;
11156 if ((thisarg & N_EQK) == 0)
11158 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11160 if ((given_type & types_allowed) == 0)
11162 first_error (_("bad type in Neon instruction"));
11163 return badtype;
11166 else
11168 enum neon_el_type mod_k_type = k_type;
11169 unsigned mod_k_size = k_size;
11170 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11171 if (g_type != mod_k_type || g_size != mod_k_size)
11173 first_error (_("inconsistent types in Neon instruction"));
11174 return badtype;
11181 return inst.vectype.el[key_el];
11184 /* Neon-style VFP instruction forwarding. */
11186 /* Thumb VFP instructions have 0xE in the condition field. */
11188 static void
11189 do_vfp_cond_or_thumb (void)
11191 if (thumb_mode)
11192 inst.instruction |= 0xe0000000;
11193 else
11194 inst.instruction |= inst.cond << 28;
11197 /* Look up and encode a simple mnemonic, for use as a helper function for the
11198 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11199 etc. It is assumed that operand parsing has already been done, and that the
11200 operands are in the form expected by the given opcode (this isn't necessarily
11201 the same as the form in which they were parsed, hence some massaging must
11202 take place before this function is called).
11203 Checks current arch version against that in the looked-up opcode. */
11205 static void
11206 do_vfp_nsyn_opcode (const char *opname)
11208 const struct asm_opcode *opcode;
11210 opcode = hash_find (arm_ops_hsh, opname);
11212 if (!opcode)
11213 abort ();
11215 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11216 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11217 _(BAD_FPU));
11219 if (thumb_mode)
11221 inst.instruction = opcode->tvalue;
11222 opcode->tencode ();
11224 else
11226 inst.instruction = (inst.cond << 28) | opcode->avalue;
11227 opcode->aencode ();
11231 static void
11232 do_vfp_nsyn_add_sub (enum neon_shape rs)
11234 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11236 if (rs == NS_FFF)
11238 if (is_add)
11239 do_vfp_nsyn_opcode ("fadds");
11240 else
11241 do_vfp_nsyn_opcode ("fsubs");
11243 else
11245 if (is_add)
11246 do_vfp_nsyn_opcode ("faddd");
11247 else
11248 do_vfp_nsyn_opcode ("fsubd");
11252 /* Check operand types to see if this is a VFP instruction, and if so call
11253 PFN (). */
11255 static int
11256 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11258 enum neon_shape rs;
11259 struct neon_type_el et;
11261 switch (args)
11263 case 2:
11264 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11265 et = neon_check_type (2, rs,
11266 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11267 break;
11269 case 3:
11270 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11271 et = neon_check_type (3, rs,
11272 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11273 break;
11275 default:
11276 abort ();
11279 if (et.type != NT_invtype)
11281 pfn (rs);
11282 return SUCCESS;
11284 else
11285 inst.error = NULL;
11287 return FAIL;
11290 static void
11291 do_vfp_nsyn_mla_mls (enum neon_shape rs)
11293 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11295 if (rs == NS_FFF)
11297 if (is_mla)
11298 do_vfp_nsyn_opcode ("fmacs");
11299 else
11300 do_vfp_nsyn_opcode ("fmscs");
11302 else
11304 if (is_mla)
11305 do_vfp_nsyn_opcode ("fmacd");
11306 else
11307 do_vfp_nsyn_opcode ("fmscd");
11311 static void
11312 do_vfp_nsyn_mul (enum neon_shape rs)
11314 if (rs == NS_FFF)
11315 do_vfp_nsyn_opcode ("fmuls");
11316 else
11317 do_vfp_nsyn_opcode ("fmuld");
11320 static void
11321 do_vfp_nsyn_abs_neg (enum neon_shape rs)
11323 int is_neg = (inst.instruction & 0x80) != 0;
11324 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11326 if (rs == NS_FF)
11328 if (is_neg)
11329 do_vfp_nsyn_opcode ("fnegs");
11330 else
11331 do_vfp_nsyn_opcode ("fabss");
11333 else
11335 if (is_neg)
11336 do_vfp_nsyn_opcode ("fnegd");
11337 else
11338 do_vfp_nsyn_opcode ("fabsd");
11342 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11343 insns belong to Neon, and are handled elsewhere. */
11345 static void
11346 do_vfp_nsyn_ldm_stm (int is_dbmode)
11348 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11349 if (is_ldm)
11351 if (is_dbmode)
11352 do_vfp_nsyn_opcode ("fldmdbs");
11353 else
11354 do_vfp_nsyn_opcode ("fldmias");
11356 else
11358 if (is_dbmode)
11359 do_vfp_nsyn_opcode ("fstmdbs");
11360 else
11361 do_vfp_nsyn_opcode ("fstmias");
11365 static void
11366 do_vfp_nsyn_sqrt (void)
11368 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11369 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11371 if (rs == NS_FF)
11372 do_vfp_nsyn_opcode ("fsqrts");
11373 else
11374 do_vfp_nsyn_opcode ("fsqrtd");
11377 static void
11378 do_vfp_nsyn_div (void)
11380 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11381 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11382 N_F32 | N_F64 | N_KEY | N_VFP);
11384 if (rs == NS_FFF)
11385 do_vfp_nsyn_opcode ("fdivs");
11386 else
11387 do_vfp_nsyn_opcode ("fdivd");
11390 static void
11391 do_vfp_nsyn_nmul (void)
11393 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11394 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11395 N_F32 | N_F64 | N_KEY | N_VFP);
11397 if (rs == NS_FFF)
11399 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11400 do_vfp_sp_dyadic ();
11402 else
11404 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11405 do_vfp_dp_rd_rn_rm ();
11407 do_vfp_cond_or_thumb ();
11410 static void
11411 do_vfp_nsyn_cmp (void)
11413 if (inst.operands[1].isreg)
11415 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11416 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11418 if (rs == NS_FF)
11420 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11421 do_vfp_sp_monadic ();
11423 else
11425 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11426 do_vfp_dp_rd_rm ();
11429 else
11431 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11432 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11434 switch (inst.instruction & 0x0fffffff)
11436 case N_MNEM_vcmp:
11437 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11438 break;
11439 case N_MNEM_vcmpe:
11440 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11441 break;
11442 default:
11443 abort ();
11446 if (rs == NS_FI)
11448 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11449 do_vfp_sp_compare_z ();
11451 else
11453 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11454 do_vfp_dp_rd ();
11457 do_vfp_cond_or_thumb ();
11460 static void
11461 nsyn_insert_sp (void)
11463 inst.operands[1] = inst.operands[0];
11464 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11465 inst.operands[0].reg = 13;
11466 inst.operands[0].isreg = 1;
11467 inst.operands[0].writeback = 1;
11468 inst.operands[0].present = 1;
11471 static void
11472 do_vfp_nsyn_push (void)
11474 nsyn_insert_sp ();
11475 if (inst.operands[1].issingle)
11476 do_vfp_nsyn_opcode ("fstmdbs");
11477 else
11478 do_vfp_nsyn_opcode ("fstmdbd");
11481 static void
11482 do_vfp_nsyn_pop (void)
11484 nsyn_insert_sp ();
11485 if (inst.operands[1].issingle)
11486 do_vfp_nsyn_opcode ("fldmias");
11487 else
11488 do_vfp_nsyn_opcode ("fldmiad");
11491 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11492 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11494 static unsigned
11495 neon_dp_fixup (unsigned i)
11497 if (thumb_mode)
11499 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11500 if (i & (1 << 24))
11501 i |= 1 << 28;
11503 i &= ~(1 << 24);
11505 i |= 0xef000000;
11507 else
11508 i |= 0xf2000000;
11510 return i;
11513 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11514 (0, 1, 2, 3). */
11516 static unsigned
11517 neon_logbits (unsigned x)
11519 return ffs (x) - 4;
11522 #define LOW4(R) ((R) & 0xf)
11523 #define HI1(R) (((R) >> 4) & 1)
11525 /* Encode insns with bit pattern:
11527 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11528 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11530 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11531 different meaning for some instruction. */
11533 static void
11534 neon_three_same (int isquad, int ubit, int size)
11536 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11537 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11538 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11539 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11540 inst.instruction |= LOW4 (inst.operands[2].reg);
11541 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11542 inst.instruction |= (isquad != 0) << 6;
11543 inst.instruction |= (ubit != 0) << 24;
11544 if (size != -1)
11545 inst.instruction |= neon_logbits (size) << 20;
11547 inst.instruction = neon_dp_fixup (inst.instruction);
11550 /* Encode instructions of the form:
11552 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11553 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
11555 Don't write size if SIZE == -1. */
11557 static void
11558 neon_two_same (int qbit, int ubit, int size)
11560 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11561 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11562 inst.instruction |= LOW4 (inst.operands[1].reg);
11563 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11564 inst.instruction |= (qbit != 0) << 6;
11565 inst.instruction |= (ubit != 0) << 24;
11567 if (size != -1)
11568 inst.instruction |= neon_logbits (size) << 18;
11570 inst.instruction = neon_dp_fixup (inst.instruction);
11573 /* Neon instruction encoders, in approximate order of appearance. */
11575 static void
11576 do_neon_dyadic_i_su (void)
11578 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11579 struct neon_type_el et = neon_check_type (3, rs,
11580 N_EQK, N_EQK, N_SU_32 | N_KEY);
11581 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11584 static void
11585 do_neon_dyadic_i64_su (void)
11587 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11588 struct neon_type_el et = neon_check_type (3, rs,
11589 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11590 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11593 static void
11594 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11595 unsigned immbits)
11597 unsigned size = et.size >> 3;
11598 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11599 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11600 inst.instruction |= LOW4 (inst.operands[1].reg);
11601 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11602 inst.instruction |= (isquad != 0) << 6;
11603 inst.instruction |= immbits << 16;
11604 inst.instruction |= (size >> 3) << 7;
11605 inst.instruction |= (size & 0x7) << 19;
11606 if (write_ubit)
11607 inst.instruction |= (uval != 0) << 24;
11609 inst.instruction = neon_dp_fixup (inst.instruction);
11612 static void
11613 do_neon_shl_imm (void)
11615 if (!inst.operands[2].isreg)
11617 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11618 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11619 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11620 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
11622 else
11624 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11625 struct neon_type_el et = neon_check_type (3, rs,
11626 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11627 unsigned int tmp;
11629 /* VSHL/VQSHL 3-register variants have syntax such as:
11630 vshl.xx Dd, Dm, Dn
11631 whereas other 3-register operations encoded by neon_three_same have
11632 syntax like:
11633 vadd.xx Dd, Dn, Dm
11634 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11635 here. */
11636 tmp = inst.operands[2].reg;
11637 inst.operands[2].reg = inst.operands[1].reg;
11638 inst.operands[1].reg = tmp;
11639 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11640 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11644 static void
11645 do_neon_qshl_imm (void)
11647 if (!inst.operands[2].isreg)
11649 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11650 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
11652 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11653 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
11654 inst.operands[2].imm);
11656 else
11658 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11659 struct neon_type_el et = neon_check_type (3, rs,
11660 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11661 unsigned int tmp;
11663 /* See note in do_neon_shl_imm. */
11664 tmp = inst.operands[2].reg;
11665 inst.operands[2].reg = inst.operands[1].reg;
11666 inst.operands[1].reg = tmp;
11667 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11668 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11672 static void
11673 do_neon_rshl (void)
11675 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11676 struct neon_type_el et = neon_check_type (3, rs,
11677 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11678 unsigned int tmp;
11680 tmp = inst.operands[2].reg;
11681 inst.operands[2].reg = inst.operands[1].reg;
11682 inst.operands[1].reg = tmp;
11683 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11686 static int
11687 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11689 /* Handle .I8 pseudo-instructions. */
11690 if (size == 8)
11692 /* Unfortunately, this will make everything apart from zero out-of-range.
11693 FIXME is this the intended semantics? There doesn't seem much point in
11694 accepting .I8 if so. */
11695 immediate |= immediate << 8;
11696 size = 16;
11699 if (size >= 32)
11701 if (immediate == (immediate & 0x000000ff))
11703 *immbits = immediate;
11704 return 0x1;
11706 else if (immediate == (immediate & 0x0000ff00))
11708 *immbits = immediate >> 8;
11709 return 0x3;
11711 else if (immediate == (immediate & 0x00ff0000))
11713 *immbits = immediate >> 16;
11714 return 0x5;
11716 else if (immediate == (immediate & 0xff000000))
11718 *immbits = immediate >> 24;
11719 return 0x7;
11721 if ((immediate & 0xffff) != (immediate >> 16))
11722 goto bad_immediate;
11723 immediate &= 0xffff;
11726 if (immediate == (immediate & 0x000000ff))
11728 *immbits = immediate;
11729 return 0x9;
11731 else if (immediate == (immediate & 0x0000ff00))
11733 *immbits = immediate >> 8;
11734 return 0xb;
11737 bad_immediate:
11738 first_error (_("immediate value out of range"));
11739 return FAIL;
11742 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11743 A, B, C, D. */
11745 static int
11746 neon_bits_same_in_bytes (unsigned imm)
11748 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11749 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11750 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11751 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11754 /* For immediate of above form, return 0bABCD. */
11756 static unsigned
11757 neon_squash_bits (unsigned imm)
11759 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11760 | ((imm & 0x01000000) >> 21);
11763 /* Compress quarter-float representation to 0b...000 abcdefgh. */
11765 static unsigned
11766 neon_qfloat_bits (unsigned imm)
11768 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
11771 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11772 the instruction. *OP is passed as the initial value of the op field, and
11773 may be set to a different value depending on the constant (i.e.
11774 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
11775 MVN). If the immediate looks like a repeated pattern then also
11776 try smaller element sizes. */
11778 static int
11779 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11780 unsigned *immbits, int *op, int size,
11781 enum neon_el_type type)
11783 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11784 float. */
11785 if (type == NT_float && !float_p)
11786 return FAIL;
11788 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11790 if (size != 32 || *op == 1)
11791 return FAIL;
11792 *immbits = neon_qfloat_bits (immlo);
11793 return 0xf;
11796 if (size == 64)
11798 if (neon_bits_same_in_bytes (immhi)
11799 && neon_bits_same_in_bytes (immlo))
11801 if (*op == 1)
11802 return FAIL;
11803 *immbits = (neon_squash_bits (immhi) << 4)
11804 | neon_squash_bits (immlo);
11805 *op = 1;
11806 return 0xe;
11809 if (immhi != immlo)
11810 return FAIL;
11813 if (size >= 32)
11815 if (immlo == (immlo & 0x000000ff))
11817 *immbits = immlo;
11818 return 0x0;
11820 else if (immlo == (immlo & 0x0000ff00))
11822 *immbits = immlo >> 8;
11823 return 0x2;
11825 else if (immlo == (immlo & 0x00ff0000))
11827 *immbits = immlo >> 16;
11828 return 0x4;
11830 else if (immlo == (immlo & 0xff000000))
11832 *immbits = immlo >> 24;
11833 return 0x6;
11835 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11837 *immbits = (immlo >> 8) & 0xff;
11838 return 0xc;
11840 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11842 *immbits = (immlo >> 16) & 0xff;
11843 return 0xd;
11846 if ((immlo & 0xffff) != (immlo >> 16))
11847 return FAIL;
11848 immlo &= 0xffff;
11851 if (size >= 16)
11853 if (immlo == (immlo & 0x000000ff))
11855 *immbits = immlo;
11856 return 0x8;
11858 else if (immlo == (immlo & 0x0000ff00))
11860 *immbits = immlo >> 8;
11861 return 0xa;
11864 if ((immlo & 0xff) != (immlo >> 8))
11865 return FAIL;
11866 immlo &= 0xff;
11869 if (immlo == (immlo & 0x000000ff))
11871 /* Don't allow MVN with 8-bit immediate. */
11872 if (*op == 1)
11873 return FAIL;
11874 *immbits = immlo;
11875 return 0xe;
11878 return FAIL;
11881 /* Write immediate bits [7:0] to the following locations:
11883 |28/24|23 19|18 16|15 4|3 0|
11884 | 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|
11886 This function is used by VMOV/VMVN/VORR/VBIC. */
11888 static void
11889 neon_write_immbits (unsigned immbits)
11891 inst.instruction |= immbits & 0xf;
11892 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11893 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11896 /* Invert low-order SIZE bits of XHI:XLO. */
11898 static void
11899 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11901 unsigned immlo = xlo ? *xlo : 0;
11902 unsigned immhi = xhi ? *xhi : 0;
11904 switch (size)
11906 case 8:
11907 immlo = (~immlo) & 0xff;
11908 break;
11910 case 16:
11911 immlo = (~immlo) & 0xffff;
11912 break;
11914 case 64:
11915 immhi = (~immhi) & 0xffffffff;
11916 /* fall through. */
11918 case 32:
11919 immlo = (~immlo) & 0xffffffff;
11920 break;
11922 default:
11923 abort ();
11926 if (xlo)
11927 *xlo = immlo;
11929 if (xhi)
11930 *xhi = immhi;
11933 static void
11934 do_neon_logic (void)
11936 if (inst.operands[2].present && inst.operands[2].isreg)
11938 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11939 neon_check_type (3, rs, N_IGNORE_TYPE);
11940 /* U bit and size field were set as part of the bitmask. */
11941 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11942 neon_three_same (neon_quad (rs), 0, -1);
11944 else
11946 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11947 struct neon_type_el et = neon_check_type (2, rs,
11948 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
11949 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11950 unsigned immbits;
11951 int cmode;
11953 if (et.type == NT_invtype)
11954 return;
11956 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11958 immbits = inst.operands[1].imm;
11959 if (et.size == 64)
11961 /* .i64 is a pseudo-op, so the immediate must be a repeating
11962 pattern. */
11963 if (immbits != (inst.operands[1].regisimm ?
11964 inst.operands[1].reg : 0))
11966 /* Set immbits to an invalid constant. */
11967 immbits = 0xdeadbeef;
11971 switch (opcode)
11973 case N_MNEM_vbic:
11974 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11975 break;
11977 case N_MNEM_vorr:
11978 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11979 break;
11981 case N_MNEM_vand:
11982 /* Pseudo-instruction for VBIC. */
11983 neon_invert_size (&immbits, 0, et.size);
11984 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11985 break;
11987 case N_MNEM_vorn:
11988 /* Pseudo-instruction for VORR. */
11989 neon_invert_size (&immbits, 0, et.size);
11990 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11991 break;
11993 default:
11994 abort ();
11997 if (cmode == FAIL)
11998 return;
12000 inst.instruction |= neon_quad (rs) << 6;
12001 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12002 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12003 inst.instruction |= cmode << 8;
12004 neon_write_immbits (immbits);
12006 inst.instruction = neon_dp_fixup (inst.instruction);
12010 static void
12011 do_neon_bitfield (void)
12013 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12014 neon_check_type (3, rs, N_IGNORE_TYPE);
12015 neon_three_same (neon_quad (rs), 0, -1);
12018 static void
12019 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12020 unsigned destbits)
12022 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12023 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12024 types | N_KEY);
12025 if (et.type == NT_float)
12027 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
12028 neon_three_same (neon_quad (rs), 0, -1);
12030 else
12032 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12033 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
12037 static void
12038 do_neon_dyadic_if_su (void)
12040 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12043 static void
12044 do_neon_dyadic_if_su_d (void)
12046 /* This version only allow D registers, but that constraint is enforced during
12047 operand parsing so we don't need to do anything extra here. */
12048 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12051 static void
12052 do_neon_dyadic_if_i_d (void)
12054 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12055 affected if we specify unsigned args. */
12056 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12059 enum vfp_or_neon_is_neon_bits
12061 NEON_CHECK_CC = 1,
12062 NEON_CHECK_ARCH = 2
12065 /* Call this function if an instruction which may have belonged to the VFP or
12066 Neon instruction sets, but turned out to be a Neon instruction (due to the
12067 operand types involved, etc.). We have to check and/or fix-up a couple of
12068 things:
12070 - Make sure the user hasn't attempted to make a Neon instruction
12071 conditional.
12072 - Alter the value in the condition code field if necessary.
12073 - Make sure that the arch supports Neon instructions.
12075 Which of these operations take place depends on bits from enum
12076 vfp_or_neon_is_neon_bits.
12078 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12079 current instruction's condition is COND_ALWAYS, the condition field is
12080 changed to inst.uncond_value. This is necessary because instructions shared
12081 between VFP and Neon may be conditional for the VFP variants only, and the
12082 unconditional Neon version must have, e.g., 0xF in the condition field. */
12084 static int
12085 vfp_or_neon_is_neon (unsigned check)
12087 /* Conditions are always legal in Thumb mode (IT blocks). */
12088 if (!thumb_mode && (check & NEON_CHECK_CC))
12090 if (inst.cond != COND_ALWAYS)
12092 first_error (_(BAD_COND));
12093 return FAIL;
12095 if (inst.uncond_value != -1)
12096 inst.instruction |= inst.uncond_value << 28;
12099 if ((check & NEON_CHECK_ARCH)
12100 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12102 first_error (_(BAD_FPU));
12103 return FAIL;
12106 return SUCCESS;
12109 static void
12110 do_neon_addsub_if_i (void)
12112 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12113 return;
12115 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12116 return;
12118 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12119 affected if we specify unsigned args. */
12120 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
12123 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12124 result to be:
12125 V<op> A,B (A is operand 0, B is operand 2)
12126 to mean:
12127 V<op> A,B,A
12128 not:
12129 V<op> A,B,B
12130 so handle that case specially. */
12132 static void
12133 neon_exchange_operands (void)
12135 void *scratch = alloca (sizeof (inst.operands[0]));
12136 if (inst.operands[1].present)
12138 /* Swap operands[1] and operands[2]. */
12139 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12140 inst.operands[1] = inst.operands[2];
12141 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12143 else
12145 inst.operands[1] = inst.operands[2];
12146 inst.operands[2] = inst.operands[0];
12150 static void
12151 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12153 if (inst.operands[2].isreg)
12155 if (invert)
12156 neon_exchange_operands ();
12157 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
12159 else
12161 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12162 struct neon_type_el et = neon_check_type (2, rs,
12163 N_EQK | N_SIZ, immtypes | N_KEY);
12165 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12166 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12167 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12168 inst.instruction |= LOW4 (inst.operands[1].reg);
12169 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12170 inst.instruction |= neon_quad (rs) << 6;
12171 inst.instruction |= (et.type == NT_float) << 10;
12172 inst.instruction |= neon_logbits (et.size) << 18;
12174 inst.instruction = neon_dp_fixup (inst.instruction);
12178 static void
12179 do_neon_cmp (void)
12181 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12184 static void
12185 do_neon_cmp_inv (void)
12187 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12190 static void
12191 do_neon_ceq (void)
12193 neon_compare (N_IF_32, N_IF_32, FALSE);
12196 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
12197 scalars, which are encoded in 5 bits, M : Rm.
12198 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12199 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12200 index in M. */
12202 static unsigned
12203 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12205 unsigned regno = NEON_SCALAR_REG (scalar);
12206 unsigned elno = NEON_SCALAR_INDEX (scalar);
12208 switch (elsize)
12210 case 16:
12211 if (regno > 7 || elno > 3)
12212 goto bad_scalar;
12213 return regno | (elno << 3);
12215 case 32:
12216 if (regno > 15 || elno > 1)
12217 goto bad_scalar;
12218 return regno | (elno << 4);
12220 default:
12221 bad_scalar:
12222 first_error (_("scalar out of range for multiply instruction"));
12225 return 0;
12228 /* Encode multiply / multiply-accumulate scalar instructions. */
12230 static void
12231 neon_mul_mac (struct neon_type_el et, int ubit)
12233 unsigned scalar;
12235 /* Give a more helpful error message if we have an invalid type. */
12236 if (et.type == NT_invtype)
12237 return;
12239 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
12240 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12241 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12242 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12243 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12244 inst.instruction |= LOW4 (scalar);
12245 inst.instruction |= HI1 (scalar) << 5;
12246 inst.instruction |= (et.type == NT_float) << 8;
12247 inst.instruction |= neon_logbits (et.size) << 20;
12248 inst.instruction |= (ubit != 0) << 24;
12250 inst.instruction = neon_dp_fixup (inst.instruction);
12253 static void
12254 do_neon_mac_maybe_scalar (void)
12256 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12257 return;
12259 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12260 return;
12262 if (inst.operands[2].isscalar)
12264 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12265 struct neon_type_el et = neon_check_type (3, rs,
12266 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12267 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12268 neon_mul_mac (et, neon_quad (rs));
12270 else
12272 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12273 affected if we specify unsigned args. */
12274 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12278 static void
12279 do_neon_tst (void)
12281 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12282 struct neon_type_el et = neon_check_type (3, rs,
12283 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
12284 neon_three_same (neon_quad (rs), 0, et.size);
12287 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
12288 same types as the MAC equivalents. The polynomial type for this instruction
12289 is encoded the same as the integer type. */
12291 static void
12292 do_neon_mul (void)
12294 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12295 return;
12297 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12298 return;
12300 if (inst.operands[2].isscalar)
12301 do_neon_mac_maybe_scalar ();
12302 else
12303 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
12306 static void
12307 do_neon_qdmulh (void)
12309 if (inst.operands[2].isscalar)
12311 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12312 struct neon_type_el et = neon_check_type (3, rs,
12313 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12314 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12315 neon_mul_mac (et, neon_quad (rs));
12317 else
12319 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12320 struct neon_type_el et = neon_check_type (3, rs,
12321 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12322 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12323 /* The U bit (rounding) comes from bit mask. */
12324 neon_three_same (neon_quad (rs), 0, et.size);
12328 static void
12329 do_neon_fcmp_absolute (void)
12331 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12332 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12333 /* Size field comes from bit mask. */
12334 neon_three_same (neon_quad (rs), 1, -1);
12337 static void
12338 do_neon_fcmp_absolute_inv (void)
12340 neon_exchange_operands ();
12341 do_neon_fcmp_absolute ();
12344 static void
12345 do_neon_step (void)
12347 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12348 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12349 neon_three_same (neon_quad (rs), 0, -1);
12352 static void
12353 do_neon_abs_neg (void)
12355 enum neon_shape rs;
12356 struct neon_type_el et;
12358 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12359 return;
12361 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12362 return;
12364 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12365 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12367 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12368 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12369 inst.instruction |= LOW4 (inst.operands[1].reg);
12370 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12371 inst.instruction |= neon_quad (rs) << 6;
12372 inst.instruction |= (et.type == NT_float) << 10;
12373 inst.instruction |= neon_logbits (et.size) << 18;
12375 inst.instruction = neon_dp_fixup (inst.instruction);
12378 static void
12379 do_neon_sli (void)
12381 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12382 struct neon_type_el et = neon_check_type (2, rs,
12383 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12384 int imm = inst.operands[2].imm;
12385 constraint (imm < 0 || (unsigned)imm >= et.size,
12386 _("immediate out of range for insert"));
12387 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12390 static void
12391 do_neon_sri (void)
12393 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12394 struct neon_type_el et = neon_check_type (2, rs,
12395 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12396 int imm = inst.operands[2].imm;
12397 constraint (imm < 1 || (unsigned)imm > et.size,
12398 _("immediate out of range for insert"));
12399 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
12402 static void
12403 do_neon_qshlu_imm (void)
12405 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12406 struct neon_type_el et = neon_check_type (2, rs,
12407 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12408 int imm = inst.operands[2].imm;
12409 constraint (imm < 0 || (unsigned)imm >= et.size,
12410 _("immediate out of range for shift"));
12411 /* Only encodes the 'U present' variant of the instruction.
12412 In this case, signed types have OP (bit 8) set to 0.
12413 Unsigned types have OP set to 1. */
12414 inst.instruction |= (et.type == NT_unsigned) << 8;
12415 /* The rest of the bits are the same as other immediate shifts. */
12416 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12419 static void
12420 do_neon_qmovn (void)
12422 struct neon_type_el et = neon_check_type (2, NS_DQ,
12423 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12424 /* Saturating move where operands can be signed or unsigned, and the
12425 destination has the same signedness. */
12426 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12427 if (et.type == NT_unsigned)
12428 inst.instruction |= 0xc0;
12429 else
12430 inst.instruction |= 0x80;
12431 neon_two_same (0, 1, et.size / 2);
12434 static void
12435 do_neon_qmovun (void)
12437 struct neon_type_el et = neon_check_type (2, NS_DQ,
12438 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12439 /* Saturating move with unsigned results. Operands must be signed. */
12440 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12441 neon_two_same (0, 1, et.size / 2);
12444 static void
12445 do_neon_rshift_sat_narrow (void)
12447 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12448 or unsigned. If operands are unsigned, results must also be unsigned. */
12449 struct neon_type_el et = neon_check_type (2, NS_DQI,
12450 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12451 int imm = inst.operands[2].imm;
12452 /* This gets the bounds check, size encoding and immediate bits calculation
12453 right. */
12454 et.size /= 2;
12456 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12457 VQMOVN.I<size> <Dd>, <Qm>. */
12458 if (imm == 0)
12460 inst.operands[2].present = 0;
12461 inst.instruction = N_MNEM_vqmovn;
12462 do_neon_qmovn ();
12463 return;
12466 constraint (imm < 1 || (unsigned)imm > et.size,
12467 _("immediate out of range"));
12468 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12471 static void
12472 do_neon_rshift_sat_narrow_u (void)
12474 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12475 or unsigned. If operands are unsigned, results must also be unsigned. */
12476 struct neon_type_el et = neon_check_type (2, NS_DQI,
12477 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12478 int imm = inst.operands[2].imm;
12479 /* This gets the bounds check, size encoding and immediate bits calculation
12480 right. */
12481 et.size /= 2;
12483 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12484 VQMOVUN.I<size> <Dd>, <Qm>. */
12485 if (imm == 0)
12487 inst.operands[2].present = 0;
12488 inst.instruction = N_MNEM_vqmovun;
12489 do_neon_qmovun ();
12490 return;
12493 constraint (imm < 1 || (unsigned)imm > et.size,
12494 _("immediate out of range"));
12495 /* FIXME: The manual is kind of unclear about what value U should have in
12496 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12497 must be 1. */
12498 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12501 static void
12502 do_neon_movn (void)
12504 struct neon_type_el et = neon_check_type (2, NS_DQ,
12505 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12506 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12507 neon_two_same (0, 1, et.size / 2);
12510 static void
12511 do_neon_rshift_narrow (void)
12513 struct neon_type_el et = neon_check_type (2, NS_DQI,
12514 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12515 int imm = inst.operands[2].imm;
12516 /* This gets the bounds check, size encoding and immediate bits calculation
12517 right. */
12518 et.size /= 2;
12520 /* If immediate is zero then we are a pseudo-instruction for
12521 VMOVN.I<size> <Dd>, <Qm> */
12522 if (imm == 0)
12524 inst.operands[2].present = 0;
12525 inst.instruction = N_MNEM_vmovn;
12526 do_neon_movn ();
12527 return;
12530 constraint (imm < 1 || (unsigned)imm > et.size,
12531 _("immediate out of range for narrowing operation"));
12532 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12535 static void
12536 do_neon_shll (void)
12538 /* FIXME: Type checking when lengthening. */
12539 struct neon_type_el et = neon_check_type (2, NS_QDI,
12540 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12541 unsigned imm = inst.operands[2].imm;
12543 if (imm == et.size)
12545 /* Maximum shift variant. */
12546 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12547 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12548 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12549 inst.instruction |= LOW4 (inst.operands[1].reg);
12550 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12551 inst.instruction |= neon_logbits (et.size) << 18;
12553 inst.instruction = neon_dp_fixup (inst.instruction);
12555 else
12557 /* A more-specific type check for non-max versions. */
12558 et = neon_check_type (2, NS_QDI,
12559 N_EQK | N_DBL, N_SU_32 | N_KEY);
12560 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12561 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12565 /* Check the various types for the VCVT instruction, and return which version
12566 the current instruction is. */
12568 static int
12569 neon_cvt_flavour (enum neon_shape rs)
12571 #define CVT_VAR(C,X,Y) \
12572 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12573 if (et.type != NT_invtype) \
12575 inst.error = NULL; \
12576 return (C); \
12578 struct neon_type_el et;
12579 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12580 || rs == NS_FF) ? N_VFP : 0;
12581 /* The instruction versions which take an immediate take one register
12582 argument, which is extended to the width of the full register. Thus the
12583 "source" and "destination" registers must have the same width. Hack that
12584 here by making the size equal to the key (wider, in this case) operand. */
12585 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
12587 CVT_VAR (0, N_S32, N_F32);
12588 CVT_VAR (1, N_U32, N_F32);
12589 CVT_VAR (2, N_F32, N_S32);
12590 CVT_VAR (3, N_F32, N_U32);
12592 whole_reg = N_VFP;
12594 /* VFP instructions. */
12595 CVT_VAR (4, N_F32, N_F64);
12596 CVT_VAR (5, N_F64, N_F32);
12597 CVT_VAR (6, N_S32, N_F64 | key);
12598 CVT_VAR (7, N_U32, N_F64 | key);
12599 CVT_VAR (8, N_F64 | key, N_S32);
12600 CVT_VAR (9, N_F64 | key, N_U32);
12601 /* VFP instructions with bitshift. */
12602 CVT_VAR (10, N_F32 | key, N_S16);
12603 CVT_VAR (11, N_F32 | key, N_U16);
12604 CVT_VAR (12, N_F64 | key, N_S16);
12605 CVT_VAR (13, N_F64 | key, N_U16);
12606 CVT_VAR (14, N_S16, N_F32 | key);
12607 CVT_VAR (15, N_U16, N_F32 | key);
12608 CVT_VAR (16, N_S16, N_F64 | key);
12609 CVT_VAR (17, N_U16, N_F64 | key);
12611 return -1;
12612 #undef CVT_VAR
12615 /* Neon-syntax VFP conversions. */
12617 static void
12618 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
12620 const char *opname = 0;
12622 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
12624 /* Conversions with immediate bitshift. */
12625 const char *enc[] =
12627 "ftosls",
12628 "ftouls",
12629 "fsltos",
12630 "fultos",
12631 NULL,
12632 NULL,
12633 "ftosld",
12634 "ftould",
12635 "fsltod",
12636 "fultod",
12637 "fshtos",
12638 "fuhtos",
12639 "fshtod",
12640 "fuhtod",
12641 "ftoshs",
12642 "ftouhs",
12643 "ftoshd",
12644 "ftouhd"
12647 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12649 opname = enc[flavour];
12650 constraint (inst.operands[0].reg != inst.operands[1].reg,
12651 _("operands 0 and 1 must be the same register"));
12652 inst.operands[1] = inst.operands[2];
12653 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12656 else
12658 /* Conversions without bitshift. */
12659 const char *enc[] =
12661 "ftosis",
12662 "ftouis",
12663 "fsitos",
12664 "fuitos",
12665 "fcvtsd",
12666 "fcvtds",
12667 "ftosid",
12668 "ftouid",
12669 "fsitod",
12670 "fuitod"
12673 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12674 opname = enc[flavour];
12677 if (opname)
12678 do_vfp_nsyn_opcode (opname);
12681 static void
12682 do_vfp_nsyn_cvtz (void)
12684 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12685 int flavour = neon_cvt_flavour (rs);
12686 const char *enc[] =
12688 "ftosizs",
12689 "ftouizs",
12690 NULL,
12691 NULL,
12692 NULL,
12693 NULL,
12694 "ftosizd",
12695 "ftouizd"
12698 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12699 do_vfp_nsyn_opcode (enc[flavour]);
12702 static void
12703 do_neon_cvt (void)
12705 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12706 NS_FD, NS_DF, NS_FF, NS_NULL);
12707 int flavour = neon_cvt_flavour (rs);
12709 /* VFP rather than Neon conversions. */
12710 if (flavour >= 4)
12712 do_vfp_nsyn_cvt (rs, flavour);
12713 return;
12716 switch (rs)
12718 case NS_DDI:
12719 case NS_QQI:
12721 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12722 return;
12724 /* Fixed-point conversion with #0 immediate is encoded as an
12725 integer conversion. */
12726 if (inst.operands[2].present && inst.operands[2].imm == 0)
12727 goto int_encode;
12728 unsigned immbits = 32 - inst.operands[2].imm;
12729 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12730 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12731 if (flavour != -1)
12732 inst.instruction |= enctab[flavour];
12733 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12734 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12735 inst.instruction |= LOW4 (inst.operands[1].reg);
12736 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12737 inst.instruction |= neon_quad (rs) << 6;
12738 inst.instruction |= 1 << 21;
12739 inst.instruction |= immbits << 16;
12741 inst.instruction = neon_dp_fixup (inst.instruction);
12743 break;
12745 case NS_DD:
12746 case NS_QQ:
12747 int_encode:
12749 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12751 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12753 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12754 return;
12756 if (flavour != -1)
12757 inst.instruction |= enctab[flavour];
12759 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12760 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12761 inst.instruction |= LOW4 (inst.operands[1].reg);
12762 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12763 inst.instruction |= neon_quad (rs) << 6;
12764 inst.instruction |= 2 << 18;
12766 inst.instruction = neon_dp_fixup (inst.instruction);
12768 break;
12770 default:
12771 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12772 do_vfp_nsyn_cvt (rs, flavour);
12776 static void
12777 neon_move_immediate (void)
12779 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12780 struct neon_type_el et = neon_check_type (2, rs,
12781 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12782 unsigned immlo, immhi = 0, immbits;
12783 int op, cmode, float_p;
12785 constraint (et.type == NT_invtype,
12786 _("operand size must be specified for immediate VMOV"));
12788 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12789 op = (inst.instruction & (1 << 5)) != 0;
12791 immlo = inst.operands[1].imm;
12792 if (inst.operands[1].regisimm)
12793 immhi = inst.operands[1].reg;
12795 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12796 _("immediate has bits set outside the operand size"));
12798 float_p = inst.operands[1].immisfloat;
12800 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
12801 et.size, et.type)) == FAIL)
12803 /* Invert relevant bits only. */
12804 neon_invert_size (&immlo, &immhi, et.size);
12805 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12806 with one or the other; those cases are caught by
12807 neon_cmode_for_move_imm. */
12808 op = !op;
12809 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12810 &op, et.size, et.type)) == FAIL)
12812 first_error (_("immediate out of range"));
12813 return;
12817 inst.instruction &= ~(1 << 5);
12818 inst.instruction |= op << 5;
12820 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12821 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12822 inst.instruction |= neon_quad (rs) << 6;
12823 inst.instruction |= cmode << 8;
12825 neon_write_immbits (immbits);
12828 static void
12829 do_neon_mvn (void)
12831 if (inst.operands[1].isreg)
12833 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12835 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12836 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12837 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12838 inst.instruction |= LOW4 (inst.operands[1].reg);
12839 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12840 inst.instruction |= neon_quad (rs) << 6;
12842 else
12844 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12845 neon_move_immediate ();
12848 inst.instruction = neon_dp_fixup (inst.instruction);
12851 /* Encode instructions of form:
12853 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12854 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
12856 static void
12857 neon_mixed_length (struct neon_type_el et, unsigned size)
12859 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12860 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12861 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12862 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12863 inst.instruction |= LOW4 (inst.operands[2].reg);
12864 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12865 inst.instruction |= (et.type == NT_unsigned) << 24;
12866 inst.instruction |= neon_logbits (size) << 20;
12868 inst.instruction = neon_dp_fixup (inst.instruction);
12871 static void
12872 do_neon_dyadic_long (void)
12874 /* FIXME: Type checking for lengthening op. */
12875 struct neon_type_el et = neon_check_type (3, NS_QDD,
12876 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12877 neon_mixed_length (et, et.size);
12880 static void
12881 do_neon_abal (void)
12883 struct neon_type_el et = neon_check_type (3, NS_QDD,
12884 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12885 neon_mixed_length (et, et.size);
12888 static void
12889 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12891 if (inst.operands[2].isscalar)
12893 struct neon_type_el et = neon_check_type (3, NS_QDS,
12894 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
12895 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12896 neon_mul_mac (et, et.type == NT_unsigned);
12898 else
12900 struct neon_type_el et = neon_check_type (3, NS_QDD,
12901 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12902 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12903 neon_mixed_length (et, et.size);
12907 static void
12908 do_neon_mac_maybe_scalar_long (void)
12910 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12913 static void
12914 do_neon_dyadic_wide (void)
12916 struct neon_type_el et = neon_check_type (3, NS_QQD,
12917 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12918 neon_mixed_length (et, et.size);
12921 static void
12922 do_neon_dyadic_narrow (void)
12924 struct neon_type_el et = neon_check_type (3, NS_QDD,
12925 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
12926 /* Operand sign is unimportant, and the U bit is part of the opcode,
12927 so force the operand type to integer. */
12928 et.type = NT_integer;
12929 neon_mixed_length (et, et.size / 2);
12932 static void
12933 do_neon_mul_sat_scalar_long (void)
12935 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12938 static void
12939 do_neon_vmull (void)
12941 if (inst.operands[2].isscalar)
12942 do_neon_mac_maybe_scalar_long ();
12943 else
12945 struct neon_type_el et = neon_check_type (3, NS_QDD,
12946 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12947 if (et.type == NT_poly)
12948 inst.instruction = NEON_ENC_POLY (inst.instruction);
12949 else
12950 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12951 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12952 zero. Should be OK as-is. */
12953 neon_mixed_length (et, et.size);
12957 static void
12958 do_neon_ext (void)
12960 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
12961 struct neon_type_el et = neon_check_type (3, rs,
12962 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12963 unsigned imm = (inst.operands[3].imm * et.size) / 8;
12964 constraint (imm >= (neon_quad (rs) ? 16 : 8), _("shift out of range"));
12965 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12966 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12967 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12968 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12969 inst.instruction |= LOW4 (inst.operands[2].reg);
12970 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12971 inst.instruction |= neon_quad (rs) << 6;
12972 inst.instruction |= imm << 8;
12974 inst.instruction = neon_dp_fixup (inst.instruction);
12977 static void
12978 do_neon_rev (void)
12980 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12981 struct neon_type_el et = neon_check_type (2, rs,
12982 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12983 unsigned op = (inst.instruction >> 7) & 3;
12984 /* N (width of reversed regions) is encoded as part of the bitmask. We
12985 extract it here to check the elements to be reversed are smaller.
12986 Otherwise we'd get a reserved instruction. */
12987 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12988 assert (elsize != 0);
12989 constraint (et.size >= elsize,
12990 _("elements must be smaller than reversal region"));
12991 neon_two_same (neon_quad (rs), 1, et.size);
12994 static void
12995 do_neon_dup (void)
12997 if (inst.operands[1].isscalar)
12999 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
13000 struct neon_type_el et = neon_check_type (2, rs,
13001 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13002 unsigned sizebits = et.size >> 3;
13003 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
13004 int logsize = neon_logbits (et.size);
13005 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
13007 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13008 return;
13010 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13011 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13012 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13013 inst.instruction |= LOW4 (dm);
13014 inst.instruction |= HI1 (dm) << 5;
13015 inst.instruction |= neon_quad (rs) << 6;
13016 inst.instruction |= x << 17;
13017 inst.instruction |= sizebits << 16;
13019 inst.instruction = neon_dp_fixup (inst.instruction);
13021 else
13023 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13024 struct neon_type_el et = neon_check_type (2, rs,
13025 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13026 /* Duplicate ARM register to lanes of vector. */
13027 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13028 switch (et.size)
13030 case 8: inst.instruction |= 0x400000; break;
13031 case 16: inst.instruction |= 0x000020; break;
13032 case 32: inst.instruction |= 0x000000; break;
13033 default: break;
13035 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13036 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13037 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
13038 inst.instruction |= neon_quad (rs) << 21;
13039 /* The encoding for this instruction is identical for the ARM and Thumb
13040 variants, except for the condition field. */
13041 do_vfp_cond_or_thumb ();
13045 /* VMOV has particularly many variations. It can be one of:
13046 0. VMOV<c><q> <Qd>, <Qm>
13047 1. VMOV<c><q> <Dd>, <Dm>
13048 (Register operations, which are VORR with Rm = Rn.)
13049 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13050 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13051 (Immediate loads.)
13052 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13053 (ARM register to scalar.)
13054 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13055 (Two ARM registers to vector.)
13056 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13057 (Scalar to ARM register.)
13058 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13059 (Vector to two ARM registers.)
13060 8. VMOV.F32 <Sd>, <Sm>
13061 9. VMOV.F64 <Dd>, <Dm>
13062 (VFP register moves.)
13063 10. VMOV.F32 <Sd>, #imm
13064 11. VMOV.F64 <Dd>, #imm
13065 (VFP float immediate load.)
13066 12. VMOV <Rd>, <Sm>
13067 (VFP single to ARM reg.)
13068 13. VMOV <Sd>, <Rm>
13069 (ARM reg to VFP single.)
13070 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13071 (Two ARM regs to two VFP singles.)
13072 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13073 (Two VFP singles to two ARM regs.)
13075 These cases can be disambiguated using neon_select_shape, except cases 1/9
13076 and 3/11 which depend on the operand type too.
13078 All the encoded bits are hardcoded by this function.
13080 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13081 Cases 5, 7 may be used with VFPv2 and above.
13083 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13084 can specify a type where it doesn't make sense to, and is ignored). */
13086 static void
13087 do_neon_mov (void)
13089 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13090 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13091 NS_NULL);
13092 struct neon_type_el et;
13093 const char *ldconst = 0;
13095 switch (rs)
13097 case NS_DD: /* case 1/9. */
13098 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13099 /* It is not an error here if no type is given. */
13100 inst.error = NULL;
13101 if (et.type == NT_float && et.size == 64)
13103 do_vfp_nsyn_opcode ("fcpyd");
13104 break;
13106 /* fall through. */
13108 case NS_QQ: /* case 0/1. */
13110 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13111 return;
13112 /* The architecture manual I have doesn't explicitly state which
13113 value the U bit should have for register->register moves, but
13114 the equivalent VORR instruction has U = 0, so do that. */
13115 inst.instruction = 0x0200110;
13116 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13117 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13118 inst.instruction |= LOW4 (inst.operands[1].reg);
13119 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13120 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13121 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13122 inst.instruction |= neon_quad (rs) << 6;
13124 inst.instruction = neon_dp_fixup (inst.instruction);
13126 break;
13128 case NS_DI: /* case 3/11. */
13129 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13130 inst.error = NULL;
13131 if (et.type == NT_float && et.size == 64)
13133 /* case 11 (fconstd). */
13134 ldconst = "fconstd";
13135 goto encode_fconstd;
13137 /* fall through. */
13139 case NS_QI: /* case 2/3. */
13140 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13141 return;
13142 inst.instruction = 0x0800010;
13143 neon_move_immediate ();
13144 inst.instruction = neon_dp_fixup (inst.instruction);
13145 break;
13147 case NS_SR: /* case 4. */
13149 unsigned bcdebits = 0;
13150 struct neon_type_el et = neon_check_type (2, NS_NULL,
13151 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13152 int logsize = neon_logbits (et.size);
13153 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13154 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13156 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13157 _(BAD_FPU));
13158 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13159 && et.size != 32, _(BAD_FPU));
13160 constraint (et.type == NT_invtype, _("bad type for scalar"));
13161 constraint (x >= 64 / et.size, _("scalar index out of range"));
13163 switch (et.size)
13165 case 8: bcdebits = 0x8; break;
13166 case 16: bcdebits = 0x1; break;
13167 case 32: bcdebits = 0x0; break;
13168 default: ;
13171 bcdebits |= x << logsize;
13173 inst.instruction = 0xe000b10;
13174 do_vfp_cond_or_thumb ();
13175 inst.instruction |= LOW4 (dn) << 16;
13176 inst.instruction |= HI1 (dn) << 7;
13177 inst.instruction |= inst.operands[1].reg << 12;
13178 inst.instruction |= (bcdebits & 3) << 5;
13179 inst.instruction |= (bcdebits >> 2) << 21;
13181 break;
13183 case NS_DRR: /* case 5 (fmdrr). */
13184 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13185 _(BAD_FPU));
13187 inst.instruction = 0xc400b10;
13188 do_vfp_cond_or_thumb ();
13189 inst.instruction |= LOW4 (inst.operands[0].reg);
13190 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13191 inst.instruction |= inst.operands[1].reg << 12;
13192 inst.instruction |= inst.operands[2].reg << 16;
13193 break;
13195 case NS_RS: /* case 6. */
13197 struct neon_type_el et = neon_check_type (2, NS_NULL,
13198 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13199 unsigned logsize = neon_logbits (et.size);
13200 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13201 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13202 unsigned abcdebits = 0;
13204 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13205 _(BAD_FPU));
13206 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13207 && et.size != 32, _(BAD_FPU));
13208 constraint (et.type == NT_invtype, _("bad type for scalar"));
13209 constraint (x >= 64 / et.size, _("scalar index out of range"));
13211 switch (et.size)
13213 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13214 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13215 case 32: abcdebits = 0x00; break;
13216 default: ;
13219 abcdebits |= x << logsize;
13220 inst.instruction = 0xe100b10;
13221 do_vfp_cond_or_thumb ();
13222 inst.instruction |= LOW4 (dn) << 16;
13223 inst.instruction |= HI1 (dn) << 7;
13224 inst.instruction |= inst.operands[0].reg << 12;
13225 inst.instruction |= (abcdebits & 3) << 5;
13226 inst.instruction |= (abcdebits >> 2) << 21;
13228 break;
13230 case NS_RRD: /* case 7 (fmrrd). */
13231 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13232 _(BAD_FPU));
13234 inst.instruction = 0xc500b10;
13235 do_vfp_cond_or_thumb ();
13236 inst.instruction |= inst.operands[0].reg << 12;
13237 inst.instruction |= inst.operands[1].reg << 16;
13238 inst.instruction |= LOW4 (inst.operands[2].reg);
13239 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13240 break;
13242 case NS_FF: /* case 8 (fcpys). */
13243 do_vfp_nsyn_opcode ("fcpys");
13244 break;
13246 case NS_FI: /* case 10 (fconsts). */
13247 ldconst = "fconsts";
13248 encode_fconstd:
13249 if (is_quarter_float (inst.operands[1].imm))
13251 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13252 do_vfp_nsyn_opcode (ldconst);
13254 else
13255 first_error (_("immediate out of range"));
13256 break;
13258 case NS_RF: /* case 12 (fmrs). */
13259 do_vfp_nsyn_opcode ("fmrs");
13260 break;
13262 case NS_FR: /* case 13 (fmsr). */
13263 do_vfp_nsyn_opcode ("fmsr");
13264 break;
13266 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13267 (one of which is a list), but we have parsed four. Do some fiddling to
13268 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13269 expect. */
13270 case NS_RRFF: /* case 14 (fmrrs). */
13271 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13272 _("VFP registers must be adjacent"));
13273 inst.operands[2].imm = 2;
13274 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13275 do_vfp_nsyn_opcode ("fmrrs");
13276 break;
13278 case NS_FFRR: /* case 15 (fmsrr). */
13279 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13280 _("VFP registers must be adjacent"));
13281 inst.operands[1] = inst.operands[2];
13282 inst.operands[2] = inst.operands[3];
13283 inst.operands[0].imm = 2;
13284 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13285 do_vfp_nsyn_opcode ("fmsrr");
13286 break;
13288 default:
13289 abort ();
13293 static void
13294 do_neon_rshift_round_imm (void)
13296 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13297 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13298 int imm = inst.operands[2].imm;
13300 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13301 if (imm == 0)
13303 inst.operands[2].present = 0;
13304 do_neon_mov ();
13305 return;
13308 constraint (imm < 1 || (unsigned)imm > et.size,
13309 _("immediate out of range for shift"));
13310 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13311 et.size - imm);
13314 static void
13315 do_neon_movl (void)
13317 struct neon_type_el et = neon_check_type (2, NS_QD,
13318 N_EQK | N_DBL, N_SU_32 | N_KEY);
13319 unsigned sizebits = et.size >> 3;
13320 inst.instruction |= sizebits << 19;
13321 neon_two_same (0, et.type == NT_unsigned, -1);
13324 static void
13325 do_neon_trn (void)
13327 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13328 struct neon_type_el et = neon_check_type (2, rs,
13329 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13330 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13331 neon_two_same (neon_quad (rs), 1, et.size);
13334 static void
13335 do_neon_zip_uzp (void)
13337 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13338 struct neon_type_el et = neon_check_type (2, rs,
13339 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13340 if (rs == NS_DD && et.size == 32)
13342 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13343 inst.instruction = N_MNEM_vtrn;
13344 do_neon_trn ();
13345 return;
13347 neon_two_same (neon_quad (rs), 1, et.size);
13350 static void
13351 do_neon_sat_abs_neg (void)
13353 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13354 struct neon_type_el et = neon_check_type (2, rs,
13355 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13356 neon_two_same (neon_quad (rs), 1, et.size);
13359 static void
13360 do_neon_pair_long (void)
13362 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13363 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13364 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13365 inst.instruction |= (et.type == NT_unsigned) << 7;
13366 neon_two_same (neon_quad (rs), 1, et.size);
13369 static void
13370 do_neon_recip_est (void)
13372 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13373 struct neon_type_el et = neon_check_type (2, rs,
13374 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13375 inst.instruction |= (et.type == NT_float) << 8;
13376 neon_two_same (neon_quad (rs), 1, et.size);
13379 static void
13380 do_neon_cls (void)
13382 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13383 struct neon_type_el et = neon_check_type (2, rs,
13384 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13385 neon_two_same (neon_quad (rs), 1, et.size);
13388 static void
13389 do_neon_clz (void)
13391 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13392 struct neon_type_el et = neon_check_type (2, rs,
13393 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
13394 neon_two_same (neon_quad (rs), 1, et.size);
13397 static void
13398 do_neon_cnt (void)
13400 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13401 struct neon_type_el et = neon_check_type (2, rs,
13402 N_EQK | N_INT, N_8 | N_KEY);
13403 neon_two_same (neon_quad (rs), 1, et.size);
13406 static void
13407 do_neon_swp (void)
13409 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13410 neon_two_same (neon_quad (rs), 1, -1);
13413 static void
13414 do_neon_tbl_tbx (void)
13416 unsigned listlenbits;
13417 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
13419 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13421 first_error (_("bad list length for table lookup"));
13422 return;
13425 listlenbits = inst.operands[1].imm - 1;
13426 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13427 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13428 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13429 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13430 inst.instruction |= LOW4 (inst.operands[2].reg);
13431 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13432 inst.instruction |= listlenbits << 8;
13434 inst.instruction = neon_dp_fixup (inst.instruction);
13437 static void
13438 do_neon_ldm_stm (void)
13440 /* P, U and L bits are part of bitmask. */
13441 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13442 unsigned offsetbits = inst.operands[1].imm * 2;
13444 if (inst.operands[1].issingle)
13446 do_vfp_nsyn_ldm_stm (is_dbmode);
13447 return;
13450 constraint (is_dbmode && !inst.operands[0].writeback,
13451 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13453 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13454 _("register list must contain at least 1 and at most 16 "
13455 "registers"));
13457 inst.instruction |= inst.operands[0].reg << 16;
13458 inst.instruction |= inst.operands[0].writeback << 21;
13459 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13460 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13462 inst.instruction |= offsetbits;
13464 do_vfp_cond_or_thumb ();
13467 static void
13468 do_neon_ldr_str (void)
13470 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13472 if (inst.operands[0].issingle)
13474 if (is_ldr)
13475 do_vfp_nsyn_opcode ("flds");
13476 else
13477 do_vfp_nsyn_opcode ("fsts");
13479 else
13481 if (is_ldr)
13482 do_vfp_nsyn_opcode ("fldd");
13483 else
13484 do_vfp_nsyn_opcode ("fstd");
13488 /* "interleave" version also handles non-interleaving register VLD1/VST1
13489 instructions. */
13491 static void
13492 do_neon_ld_st_interleave (void)
13494 struct neon_type_el et = neon_check_type (1, NS_NULL,
13495 N_8 | N_16 | N_32 | N_64);
13496 unsigned alignbits = 0;
13497 unsigned idx;
13498 /* The bits in this table go:
13499 0: register stride of one (0) or two (1)
13500 1,2: register list length, minus one (1, 2, 3, 4).
13501 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13502 We use -1 for invalid entries. */
13503 const int typetable[] =
13505 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13506 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13507 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13508 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13510 int typebits;
13512 if (et.type == NT_invtype)
13513 return;
13515 if (inst.operands[1].immisalign)
13516 switch (inst.operands[1].imm >> 8)
13518 case 64: alignbits = 1; break;
13519 case 128:
13520 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13521 goto bad_alignment;
13522 alignbits = 2;
13523 break;
13524 case 256:
13525 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13526 goto bad_alignment;
13527 alignbits = 3;
13528 break;
13529 default:
13530 bad_alignment:
13531 first_error (_("bad alignment"));
13532 return;
13535 inst.instruction |= alignbits << 4;
13536 inst.instruction |= neon_logbits (et.size) << 6;
13538 /* Bits [4:6] of the immediate in a list specifier encode register stride
13539 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13540 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13541 up the right value for "type" in a table based on this value and the given
13542 list style, then stick it back. */
13543 idx = ((inst.operands[0].imm >> 4) & 7)
13544 | (((inst.instruction >> 8) & 3) << 3);
13546 typebits = typetable[idx];
13548 constraint (typebits == -1, _("bad list type for instruction"));
13550 inst.instruction &= ~0xf00;
13551 inst.instruction |= typebits << 8;
13554 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13555 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13556 otherwise. The variable arguments are a list of pairs of legal (size, align)
13557 values, terminated with -1. */
13559 static int
13560 neon_alignment_bit (int size, int align, int *do_align, ...)
13562 va_list ap;
13563 int result = FAIL, thissize, thisalign;
13565 if (!inst.operands[1].immisalign)
13567 *do_align = 0;
13568 return SUCCESS;
13571 va_start (ap, do_align);
13575 thissize = va_arg (ap, int);
13576 if (thissize == -1)
13577 break;
13578 thisalign = va_arg (ap, int);
13580 if (size == thissize && align == thisalign)
13581 result = SUCCESS;
13583 while (result != SUCCESS);
13585 va_end (ap);
13587 if (result == SUCCESS)
13588 *do_align = 1;
13589 else
13590 first_error (_("unsupported alignment for instruction"));
13592 return result;
13595 static void
13596 do_neon_ld_st_lane (void)
13598 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13599 int align_good, do_align = 0;
13600 int logsize = neon_logbits (et.size);
13601 int align = inst.operands[1].imm >> 8;
13602 int n = (inst.instruction >> 8) & 3;
13603 int max_el = 64 / et.size;
13605 if (et.type == NT_invtype)
13606 return;
13608 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13609 _("bad list length"));
13610 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13611 _("scalar index out of range"));
13612 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13613 && et.size == 8,
13614 _("stride of 2 unavailable when element size is 8"));
13616 switch (n)
13618 case 0: /* VLD1 / VST1. */
13619 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13620 32, 32, -1);
13621 if (align_good == FAIL)
13622 return;
13623 if (do_align)
13625 unsigned alignbits = 0;
13626 switch (et.size)
13628 case 16: alignbits = 0x1; break;
13629 case 32: alignbits = 0x3; break;
13630 default: ;
13632 inst.instruction |= alignbits << 4;
13634 break;
13636 case 1: /* VLD2 / VST2. */
13637 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13638 32, 64, -1);
13639 if (align_good == FAIL)
13640 return;
13641 if (do_align)
13642 inst.instruction |= 1 << 4;
13643 break;
13645 case 2: /* VLD3 / VST3. */
13646 constraint (inst.operands[1].immisalign,
13647 _("can't use alignment with this instruction"));
13648 break;
13650 case 3: /* VLD4 / VST4. */
13651 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13652 16, 64, 32, 64, 32, 128, -1);
13653 if (align_good == FAIL)
13654 return;
13655 if (do_align)
13657 unsigned alignbits = 0;
13658 switch (et.size)
13660 case 8: alignbits = 0x1; break;
13661 case 16: alignbits = 0x1; break;
13662 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13663 default: ;
13665 inst.instruction |= alignbits << 4;
13667 break;
13669 default: ;
13672 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13673 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13674 inst.instruction |= 1 << (4 + logsize);
13676 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13677 inst.instruction |= logsize << 10;
13680 /* Encode single n-element structure to all lanes VLD<n> instructions. */
13682 static void
13683 do_neon_ld_dup (void)
13685 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13686 int align_good, do_align = 0;
13688 if (et.type == NT_invtype)
13689 return;
13691 switch ((inst.instruction >> 8) & 3)
13693 case 0: /* VLD1. */
13694 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13695 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13696 &do_align, 16, 16, 32, 32, -1);
13697 if (align_good == FAIL)
13698 return;
13699 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13701 case 1: break;
13702 case 2: inst.instruction |= 1 << 5; break;
13703 default: first_error (_("bad list length")); return;
13705 inst.instruction |= neon_logbits (et.size) << 6;
13706 break;
13708 case 1: /* VLD2. */
13709 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13710 &do_align, 8, 16, 16, 32, 32, 64, -1);
13711 if (align_good == FAIL)
13712 return;
13713 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13714 _("bad list length"));
13715 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13716 inst.instruction |= 1 << 5;
13717 inst.instruction |= neon_logbits (et.size) << 6;
13718 break;
13720 case 2: /* VLD3. */
13721 constraint (inst.operands[1].immisalign,
13722 _("can't use alignment with this instruction"));
13723 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13724 _("bad list length"));
13725 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13726 inst.instruction |= 1 << 5;
13727 inst.instruction |= neon_logbits (et.size) << 6;
13728 break;
13730 case 3: /* VLD4. */
13732 int align = inst.operands[1].imm >> 8;
13733 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13734 16, 64, 32, 64, 32, 128, -1);
13735 if (align_good == FAIL)
13736 return;
13737 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13738 _("bad list length"));
13739 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13740 inst.instruction |= 1 << 5;
13741 if (et.size == 32 && align == 128)
13742 inst.instruction |= 0x3 << 6;
13743 else
13744 inst.instruction |= neon_logbits (et.size) << 6;
13746 break;
13748 default: ;
13751 inst.instruction |= do_align << 4;
13754 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13755 apart from bits [11:4]. */
13757 static void
13758 do_neon_ldx_stx (void)
13760 switch (NEON_LANE (inst.operands[0].imm))
13762 case NEON_INTERLEAVE_LANES:
13763 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13764 do_neon_ld_st_interleave ();
13765 break;
13767 case NEON_ALL_LANES:
13768 inst.instruction = NEON_ENC_DUP (inst.instruction);
13769 do_neon_ld_dup ();
13770 break;
13772 default:
13773 inst.instruction = NEON_ENC_LANE (inst.instruction);
13774 do_neon_ld_st_lane ();
13777 /* L bit comes from bit mask. */
13778 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13779 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13780 inst.instruction |= inst.operands[1].reg << 16;
13782 if (inst.operands[1].postind)
13784 int postreg = inst.operands[1].imm & 0xf;
13785 constraint (!inst.operands[1].immisreg,
13786 _("post-index must be a register"));
13787 constraint (postreg == 0xd || postreg == 0xf,
13788 _("bad register for post-index"));
13789 inst.instruction |= postreg;
13791 else if (inst.operands[1].writeback)
13793 inst.instruction |= 0xd;
13795 else
13796 inst.instruction |= 0xf;
13798 if (thumb_mode)
13799 inst.instruction |= 0xf9000000;
13800 else
13801 inst.instruction |= 0xf4000000;
13804 /* Overall per-instruction processing. */
13806 /* We need to be able to fix up arbitrary expressions in some statements.
13807 This is so that we can handle symbols that are an arbitrary distance from
13808 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13809 which returns part of an address in a form which will be valid for
13810 a data instruction. We do this by pushing the expression into a symbol
13811 in the expr_section, and creating a fix for that. */
13813 static void
13814 fix_new_arm (fragS * frag,
13815 int where,
13816 short int size,
13817 expressionS * exp,
13818 int pc_rel,
13819 int reloc)
13821 fixS * new_fix;
13823 switch (exp->X_op)
13825 case O_constant:
13826 case O_symbol:
13827 case O_add:
13828 case O_subtract:
13829 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13830 break;
13832 default:
13833 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13834 pc_rel, reloc);
13835 break;
13838 /* Mark whether the fix is to a THUMB instruction, or an ARM
13839 instruction. */
13840 new_fix->tc_fix_data = thumb_mode;
13843 /* Create a frg for an instruction requiring relaxation. */
13844 static void
13845 output_relax_insn (void)
13847 char * to;
13848 symbolS *sym;
13849 int offset;
13851 /* The size of the instruction is unknown, so tie the debug info to the
13852 start of the instruction. */
13853 dwarf2_emit_insn (0);
13855 switch (inst.reloc.exp.X_op)
13857 case O_symbol:
13858 sym = inst.reloc.exp.X_add_symbol;
13859 offset = inst.reloc.exp.X_add_number;
13860 break;
13861 case O_constant:
13862 sym = NULL;
13863 offset = inst.reloc.exp.X_add_number;
13864 break;
13865 default:
13866 sym = make_expr_symbol (&inst.reloc.exp);
13867 offset = 0;
13868 break;
13870 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13871 inst.relax, sym, offset, NULL/*offset, opcode*/);
13872 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
13875 /* Write a 32-bit thumb instruction to buf. */
13876 static void
13877 put_thumb32_insn (char * buf, unsigned long insn)
13879 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13880 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13883 static void
13884 output_inst (const char * str)
13886 char * to = NULL;
13888 if (inst.error)
13890 as_bad ("%s -- `%s'", inst.error, str);
13891 return;
13893 if (inst.relax)
13895 output_relax_insn ();
13896 return;
13898 if (inst.size == 0)
13899 return;
13901 to = frag_more (inst.size);
13903 if (thumb_mode && (inst.size > THUMB_SIZE))
13905 assert (inst.size == (2 * THUMB_SIZE));
13906 put_thumb32_insn (to, inst.instruction);
13908 else if (inst.size > INSN_SIZE)
13910 assert (inst.size == (2 * INSN_SIZE));
13911 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13912 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
13914 else
13915 md_number_to_chars (to, inst.instruction, inst.size);
13917 if (inst.reloc.type != BFD_RELOC_UNUSED)
13918 fix_new_arm (frag_now, to - frag_now->fr_literal,
13919 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13920 inst.reloc.type);
13922 dwarf2_emit_insn (inst.size);
13925 /* Tag values used in struct asm_opcode's tag field. */
13926 enum opcode_tag
13928 OT_unconditional, /* Instruction cannot be conditionalized.
13929 The ARM condition field is still 0xE. */
13930 OT_unconditionalF, /* Instruction cannot be conditionalized
13931 and carries 0xF in its ARM condition field. */
13932 OT_csuffix, /* Instruction takes a conditional suffix. */
13933 OT_csuffixF, /* Some forms of the instruction take a conditional
13934 suffix, others place 0xF where the condition field
13935 would be. */
13936 OT_cinfix3, /* Instruction takes a conditional infix,
13937 beginning at character index 3. (In
13938 unified mode, it becomes a suffix.) */
13939 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13940 tsts, cmps, cmns, and teqs. */
13941 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13942 character index 3, even in unified mode. Used for
13943 legacy instructions where suffix and infix forms
13944 may be ambiguous. */
13945 OT_csuf_or_in3, /* Instruction takes either a conditional
13946 suffix or an infix at character index 3. */
13947 OT_odd_infix_unc, /* This is the unconditional variant of an
13948 instruction that takes a conditional infix
13949 at an unusual position. In unified mode,
13950 this variant will accept a suffix. */
13951 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13952 are the conditional variants of instructions that
13953 take conditional infixes in unusual positions.
13954 The infix appears at character index
13955 (tag - OT_odd_infix_0). These are not accepted
13956 in unified mode. */
13959 /* Subroutine of md_assemble, responsible for looking up the primary
13960 opcode from the mnemonic the user wrote. STR points to the
13961 beginning of the mnemonic.
13963 This is not simply a hash table lookup, because of conditional
13964 variants. Most instructions have conditional variants, which are
13965 expressed with a _conditional affix_ to the mnemonic. If we were
13966 to encode each conditional variant as a literal string in the opcode
13967 table, it would have approximately 20,000 entries.
13969 Most mnemonics take this affix as a suffix, and in unified syntax,
13970 'most' is upgraded to 'all'. However, in the divided syntax, some
13971 instructions take the affix as an infix, notably the s-variants of
13972 the arithmetic instructions. Of those instructions, all but six
13973 have the infix appear after the third character of the mnemonic.
13975 Accordingly, the algorithm for looking up primary opcodes given
13976 an identifier is:
13978 1. Look up the identifier in the opcode table.
13979 If we find a match, go to step U.
13981 2. Look up the last two characters of the identifier in the
13982 conditions table. If we find a match, look up the first N-2
13983 characters of the identifier in the opcode table. If we
13984 find a match, go to step CE.
13986 3. Look up the fourth and fifth characters of the identifier in
13987 the conditions table. If we find a match, extract those
13988 characters from the identifier, and look up the remaining
13989 characters in the opcode table. If we find a match, go
13990 to step CM.
13992 4. Fail.
13994 U. Examine the tag field of the opcode structure, in case this is
13995 one of the six instructions with its conditional infix in an
13996 unusual place. If it is, the tag tells us where to find the
13997 infix; look it up in the conditions table and set inst.cond
13998 accordingly. Otherwise, this is an unconditional instruction.
13999 Again set inst.cond accordingly. Return the opcode structure.
14001 CE. Examine the tag field to make sure this is an instruction that
14002 should receive a conditional suffix. If it is not, fail.
14003 Otherwise, set inst.cond from the suffix we already looked up,
14004 and return the opcode structure.
14006 CM. Examine the tag field to make sure this is an instruction that
14007 should receive a conditional infix after the third character.
14008 If it is not, fail. Otherwise, undo the edits to the current
14009 line of input and proceed as for case CE. */
14011 static const struct asm_opcode *
14012 opcode_lookup (char **str)
14014 char *end, *base;
14015 char *affix;
14016 const struct asm_opcode *opcode;
14017 const struct asm_cond *cond;
14018 char save[2];
14019 bfd_boolean neon_supported;
14021 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
14023 /* Scan up to the end of the mnemonic, which must end in white space,
14024 '.' (in unified mode, or for Neon instructions), or end of string. */
14025 for (base = end = *str; *end != '\0'; end++)
14026 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
14027 break;
14029 if (end == base)
14030 return 0;
14032 /* Handle a possible width suffix and/or Neon type suffix. */
14033 if (end[0] == '.')
14035 int offset = 2;
14037 /* The .w and .n suffixes are only valid if the unified syntax is in
14038 use. */
14039 if (unified_syntax && end[1] == 'w')
14040 inst.size_req = 4;
14041 else if (unified_syntax && end[1] == 'n')
14042 inst.size_req = 2;
14043 else
14044 offset = 0;
14046 inst.vectype.elems = 0;
14048 *str = end + offset;
14050 if (end[offset] == '.')
14052 /* See if we have a Neon type suffix (possible in either unified or
14053 non-unified ARM syntax mode). */
14054 if (parse_neon_type (&inst.vectype, str) == FAIL)
14055 return 0;
14057 else if (end[offset] != '\0' && end[offset] != ' ')
14058 return 0;
14060 else
14061 *str = end;
14063 /* Look for unaffixed or special-case affixed mnemonic. */
14064 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14065 if (opcode)
14067 /* step U */
14068 if (opcode->tag < OT_odd_infix_0)
14070 inst.cond = COND_ALWAYS;
14071 return opcode;
14074 if (unified_syntax)
14075 as_warn (_("conditional infixes are deprecated in unified syntax"));
14076 affix = base + (opcode->tag - OT_odd_infix_0);
14077 cond = hash_find_n (arm_cond_hsh, affix, 2);
14078 assert (cond);
14080 inst.cond = cond->value;
14081 return opcode;
14084 /* Cannot have a conditional suffix on a mnemonic of less than two
14085 characters. */
14086 if (end - base < 3)
14087 return 0;
14089 /* Look for suffixed mnemonic. */
14090 affix = end - 2;
14091 cond = hash_find_n (arm_cond_hsh, affix, 2);
14092 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14093 if (opcode && cond)
14095 /* step CE */
14096 switch (opcode->tag)
14098 case OT_cinfix3_legacy:
14099 /* Ignore conditional suffixes matched on infix only mnemonics. */
14100 break;
14102 case OT_cinfix3:
14103 case OT_cinfix3_deprecated:
14104 case OT_odd_infix_unc:
14105 if (!unified_syntax)
14106 return 0;
14107 /* else fall through */
14109 case OT_csuffix:
14110 case OT_csuffixF:
14111 case OT_csuf_or_in3:
14112 inst.cond = cond->value;
14113 return opcode;
14115 case OT_unconditional:
14116 case OT_unconditionalF:
14117 if (thumb_mode)
14119 inst.cond = cond->value;
14121 else
14123 /* delayed diagnostic */
14124 inst.error = BAD_COND;
14125 inst.cond = COND_ALWAYS;
14127 return opcode;
14129 default:
14130 return 0;
14134 /* Cannot have a usual-position infix on a mnemonic of less than
14135 six characters (five would be a suffix). */
14136 if (end - base < 6)
14137 return 0;
14139 /* Look for infixed mnemonic in the usual position. */
14140 affix = base + 3;
14141 cond = hash_find_n (arm_cond_hsh, affix, 2);
14142 if (!cond)
14143 return 0;
14145 memcpy (save, affix, 2);
14146 memmove (affix, affix + 2, (end - affix) - 2);
14147 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14148 memmove (affix + 2, affix, (end - affix) - 2);
14149 memcpy (affix, save, 2);
14151 if (opcode
14152 && (opcode->tag == OT_cinfix3
14153 || opcode->tag == OT_cinfix3_deprecated
14154 || opcode->tag == OT_csuf_or_in3
14155 || opcode->tag == OT_cinfix3_legacy))
14157 /* step CM */
14158 if (unified_syntax
14159 && (opcode->tag == OT_cinfix3
14160 || opcode->tag == OT_cinfix3_deprecated))
14161 as_warn (_("conditional infixes are deprecated in unified syntax"));
14163 inst.cond = cond->value;
14164 return opcode;
14167 return 0;
14170 void
14171 md_assemble (char *str)
14173 char *p = str;
14174 const struct asm_opcode * opcode;
14176 /* Align the previous label if needed. */
14177 if (last_label_seen != NULL)
14179 symbol_set_frag (last_label_seen, frag_now);
14180 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14181 S_SET_SEGMENT (last_label_seen, now_seg);
14184 memset (&inst, '\0', sizeof (inst));
14185 inst.reloc.type = BFD_RELOC_UNUSED;
14187 opcode = opcode_lookup (&p);
14188 if (!opcode)
14190 /* It wasn't an instruction, but it might be a register alias of
14191 the form alias .req reg, or a Neon .dn/.qn directive. */
14192 if (!create_register_alias (str, p)
14193 && !create_neon_reg_alias (str, p))
14194 as_bad (_("bad instruction `%s'"), str);
14196 return;
14199 if (opcode->tag == OT_cinfix3_deprecated)
14200 as_warn (_("s suffix on comparison instruction is deprecated"));
14202 /* The value which unconditional instructions should have in place of the
14203 condition field. */
14204 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14206 if (thumb_mode)
14208 arm_feature_set variant;
14210 variant = cpu_variant;
14211 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
14212 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14213 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
14214 /* Check that this instruction is supported for this CPU. */
14215 if (!opcode->tvariant
14216 || (thumb_mode == 1
14217 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
14219 as_bad (_("selected processor does not support `%s'"), str);
14220 return;
14222 if (inst.cond != COND_ALWAYS && !unified_syntax
14223 && opcode->tencode != do_t_branch)
14225 as_bad (_("Thumb does not support conditional execution"));
14226 return;
14229 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14231 /* Implicit require narrow instructions on Thumb-1. This avoids
14232 relaxation accidentally introducing Thumb-2 instructions. */
14233 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
14234 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
14235 inst.size_req = 2;
14238 /* Check conditional suffixes. */
14239 if (current_it_mask)
14241 int cond;
14242 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
14243 current_it_mask <<= 1;
14244 current_it_mask &= 0x1f;
14245 /* The BKPT instruction is unconditional even in an IT block. */
14246 if (!inst.error
14247 && cond != inst.cond && opcode->tencode != do_t_bkpt)
14249 as_bad (_("incorrect condition in IT block"));
14250 return;
14253 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14255 as_bad (_("thumb conditional instruction not in IT block"));
14256 return;
14259 mapping_state (MAP_THUMB);
14260 inst.instruction = opcode->tvalue;
14262 if (!parse_operands (p, opcode->operands))
14263 opcode->tencode ();
14265 /* Clear current_it_mask at the end of an IT block. */
14266 if (current_it_mask == 0x10)
14267 current_it_mask = 0;
14269 if (!(inst.error || inst.relax))
14271 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14272 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14273 if (inst.size_req && inst.size_req != inst.size)
14275 as_bad (_("cannot honor width suffix -- `%s'"), str);
14276 return;
14280 /* Something has gone badly wrong if we try to relax a fixed size
14281 instruction. */
14282 assert (inst.size_req == 0 || !inst.relax);
14284 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14285 *opcode->tvariant);
14286 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
14287 set those bits when Thumb-2 32-bit instructions are seen. ie.
14288 anything other than bl/blx and v6-M instructions.
14289 This is overly pessimistic for relaxable instructions. */
14290 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14291 || inst.relax)
14292 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
14293 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14294 arm_ext_v6t2);
14296 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
14298 bfd_boolean is_bx;
14300 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14301 is_bx = (opcode->aencode == do_bx);
14303 /* Check that this instruction is supported for this CPU. */
14304 if (!(is_bx && fix_v4bx)
14305 && !(opcode->avariant &&
14306 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
14308 as_bad (_("selected processor does not support `%s'"), str);
14309 return;
14311 if (inst.size_req)
14313 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14314 return;
14317 mapping_state (MAP_ARM);
14318 inst.instruction = opcode->avalue;
14319 if (opcode->tag == OT_unconditionalF)
14320 inst.instruction |= 0xF << 28;
14321 else
14322 inst.instruction |= inst.cond << 28;
14323 inst.size = INSN_SIZE;
14324 if (!parse_operands (p, opcode->operands))
14325 opcode->aencode ();
14326 /* Arm mode bx is marked as both v4T and v5 because it's still required
14327 on a hypothetical non-thumb v5 core. */
14328 if (is_bx)
14329 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
14330 else
14331 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14332 *opcode->avariant);
14334 else
14336 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14337 "-- `%s'"), str);
14338 return;
14340 output_inst (str);
14343 /* Various frobbings of labels and their addresses. */
14345 void
14346 arm_start_line_hook (void)
14348 last_label_seen = NULL;
14351 void
14352 arm_frob_label (symbolS * sym)
14354 last_label_seen = sym;
14356 ARM_SET_THUMB (sym, thumb_mode);
14358 #if defined OBJ_COFF || defined OBJ_ELF
14359 ARM_SET_INTERWORK (sym, support_interwork);
14360 #endif
14362 /* Note - do not allow local symbols (.Lxxx) to be labelled
14363 as Thumb functions. This is because these labels, whilst
14364 they exist inside Thumb code, are not the entry points for
14365 possible ARM->Thumb calls. Also, these labels can be used
14366 as part of a computed goto or switch statement. eg gcc
14367 can generate code that looks like this:
14369 ldr r2, [pc, .Laaa]
14370 lsl r3, r3, #2
14371 ldr r2, [r3, r2]
14372 mov pc, r2
14374 .Lbbb: .word .Lxxx
14375 .Lccc: .word .Lyyy
14376 ..etc...
14377 .Laaa: .word Lbbb
14379 The first instruction loads the address of the jump table.
14380 The second instruction converts a table index into a byte offset.
14381 The third instruction gets the jump address out of the table.
14382 The fourth instruction performs the jump.
14384 If the address stored at .Laaa is that of a symbol which has the
14385 Thumb_Func bit set, then the linker will arrange for this address
14386 to have the bottom bit set, which in turn would mean that the
14387 address computation performed by the third instruction would end
14388 up with the bottom bit set. Since the ARM is capable of unaligned
14389 word loads, the instruction would then load the incorrect address
14390 out of the jump table, and chaos would ensue. */
14391 if (label_is_thumb_function_name
14392 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14393 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
14395 /* When the address of a Thumb function is taken the bottom
14396 bit of that address should be set. This will allow
14397 interworking between Arm and Thumb functions to work
14398 correctly. */
14400 THUMB_SET_FUNC (sym, 1);
14402 label_is_thumb_function_name = FALSE;
14405 dwarf2_emit_label (sym);
14409 arm_data_in_code (void)
14411 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
14413 *input_line_pointer = '/';
14414 input_line_pointer += 5;
14415 *input_line_pointer = 0;
14416 return 1;
14419 return 0;
14422 char *
14423 arm_canonicalize_symbol_name (char * name)
14425 int len;
14427 if (thumb_mode && (len = strlen (name)) > 5
14428 && streq (name + len - 5, "/data"))
14429 *(name + len - 5) = 0;
14431 return name;
14434 /* Table of all register names defined by default. The user can
14435 define additional names with .req. Note that all register names
14436 should appear in both upper and lowercase variants. Some registers
14437 also have mixed-case names. */
14439 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
14440 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
14441 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
14442 #define REGSET(p,t) \
14443 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14444 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14445 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14446 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
14447 #define REGSETH(p,t) \
14448 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14449 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14450 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14451 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14452 #define REGSET2(p,t) \
14453 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14454 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14455 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14456 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
14458 static const struct reg_entry reg_names[] =
14460 /* ARM integer registers. */
14461 REGSET(r, RN), REGSET(R, RN),
14463 /* ATPCS synonyms. */
14464 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14465 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14466 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
14468 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14469 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14470 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
14472 /* Well-known aliases. */
14473 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14474 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14476 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14477 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14479 /* Coprocessor numbers. */
14480 REGSET(p, CP), REGSET(P, CP),
14482 /* Coprocessor register numbers. The "cr" variants are for backward
14483 compatibility. */
14484 REGSET(c, CN), REGSET(C, CN),
14485 REGSET(cr, CN), REGSET(CR, CN),
14487 /* FPA registers. */
14488 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14489 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14491 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14492 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14494 /* VFP SP registers. */
14495 REGSET(s,VFS), REGSET(S,VFS),
14496 REGSETH(s,VFS), REGSETH(S,VFS),
14498 /* VFP DP Registers. */
14499 REGSET(d,VFD), REGSET(D,VFD),
14500 /* Extra Neon DP registers. */
14501 REGSETH(d,VFD), REGSETH(D,VFD),
14503 /* Neon QP registers. */
14504 REGSET2(q,NQ), REGSET2(Q,NQ),
14506 /* VFP control registers. */
14507 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14508 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
14509 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14510 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14511 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14512 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
14514 /* Maverick DSP coprocessor registers. */
14515 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14516 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14518 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14519 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14520 REGDEF(dspsc,0,DSPSC),
14522 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14523 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14524 REGDEF(DSPSC,0,DSPSC),
14526 /* iWMMXt data registers - p0, c0-15. */
14527 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14529 /* iWMMXt control registers - p1, c0-3. */
14530 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14531 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14532 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14533 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14535 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14536 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14537 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14538 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14539 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14541 /* XScale accumulator registers. */
14542 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14544 #undef REGDEF
14545 #undef REGNUM
14546 #undef REGSET
14548 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14549 within psr_required_here. */
14550 static const struct asm_psr psrs[] =
14552 /* Backward compatibility notation. Note that "all" is no longer
14553 truly all possible PSR bits. */
14554 {"all", PSR_c | PSR_f},
14555 {"flg", PSR_f},
14556 {"ctl", PSR_c},
14558 /* Individual flags. */
14559 {"f", PSR_f},
14560 {"c", PSR_c},
14561 {"x", PSR_x},
14562 {"s", PSR_s},
14563 /* Combinations of flags. */
14564 {"fs", PSR_f | PSR_s},
14565 {"fx", PSR_f | PSR_x},
14566 {"fc", PSR_f | PSR_c},
14567 {"sf", PSR_s | PSR_f},
14568 {"sx", PSR_s | PSR_x},
14569 {"sc", PSR_s | PSR_c},
14570 {"xf", PSR_x | PSR_f},
14571 {"xs", PSR_x | PSR_s},
14572 {"xc", PSR_x | PSR_c},
14573 {"cf", PSR_c | PSR_f},
14574 {"cs", PSR_c | PSR_s},
14575 {"cx", PSR_c | PSR_x},
14576 {"fsx", PSR_f | PSR_s | PSR_x},
14577 {"fsc", PSR_f | PSR_s | PSR_c},
14578 {"fxs", PSR_f | PSR_x | PSR_s},
14579 {"fxc", PSR_f | PSR_x | PSR_c},
14580 {"fcs", PSR_f | PSR_c | PSR_s},
14581 {"fcx", PSR_f | PSR_c | PSR_x},
14582 {"sfx", PSR_s | PSR_f | PSR_x},
14583 {"sfc", PSR_s | PSR_f | PSR_c},
14584 {"sxf", PSR_s | PSR_x | PSR_f},
14585 {"sxc", PSR_s | PSR_x | PSR_c},
14586 {"scf", PSR_s | PSR_c | PSR_f},
14587 {"scx", PSR_s | PSR_c | PSR_x},
14588 {"xfs", PSR_x | PSR_f | PSR_s},
14589 {"xfc", PSR_x | PSR_f | PSR_c},
14590 {"xsf", PSR_x | PSR_s | PSR_f},
14591 {"xsc", PSR_x | PSR_s | PSR_c},
14592 {"xcf", PSR_x | PSR_c | PSR_f},
14593 {"xcs", PSR_x | PSR_c | PSR_s},
14594 {"cfs", PSR_c | PSR_f | PSR_s},
14595 {"cfx", PSR_c | PSR_f | PSR_x},
14596 {"csf", PSR_c | PSR_s | PSR_f},
14597 {"csx", PSR_c | PSR_s | PSR_x},
14598 {"cxf", PSR_c | PSR_x | PSR_f},
14599 {"cxs", PSR_c | PSR_x | PSR_s},
14600 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14601 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14602 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14603 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14604 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14605 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14606 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14607 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14608 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14609 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14610 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14611 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14612 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14613 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14614 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14615 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14616 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14617 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14618 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14619 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14620 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14621 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14622 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14623 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14626 /* Table of V7M psr names. */
14627 static const struct asm_psr v7m_psrs[] =
14629 {"apsr", 0 }, {"APSR", 0 },
14630 {"iapsr", 1 }, {"IAPSR", 1 },
14631 {"eapsr", 2 }, {"EAPSR", 2 },
14632 {"psr", 3 }, {"PSR", 3 },
14633 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14634 {"ipsr", 5 }, {"IPSR", 5 },
14635 {"epsr", 6 }, {"EPSR", 6 },
14636 {"iepsr", 7 }, {"IEPSR", 7 },
14637 {"msp", 8 }, {"MSP", 8 },
14638 {"psp", 9 }, {"PSP", 9 },
14639 {"primask", 16}, {"PRIMASK", 16},
14640 {"basepri", 17}, {"BASEPRI", 17},
14641 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14642 {"faultmask", 19}, {"FAULTMASK", 19},
14643 {"control", 20}, {"CONTROL", 20}
14646 /* Table of all shift-in-operand names. */
14647 static const struct asm_shift_name shift_names [] =
14649 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14650 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14651 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14652 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14653 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14654 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14657 /* Table of all explicit relocation names. */
14658 #ifdef OBJ_ELF
14659 static struct reloc_entry reloc_names[] =
14661 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14662 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14663 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14664 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14665 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14666 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14667 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14668 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14669 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14670 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14671 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14673 #endif
14675 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
14676 static const struct asm_cond conds[] =
14678 {"eq", 0x0},
14679 {"ne", 0x1},
14680 {"cs", 0x2}, {"hs", 0x2},
14681 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14682 {"mi", 0x4},
14683 {"pl", 0x5},
14684 {"vs", 0x6},
14685 {"vc", 0x7},
14686 {"hi", 0x8},
14687 {"ls", 0x9},
14688 {"ge", 0xa},
14689 {"lt", 0xb},
14690 {"gt", 0xc},
14691 {"le", 0xd},
14692 {"al", 0xe}
14695 static struct asm_barrier_opt barrier_opt_names[] =
14697 { "sy", 0xf },
14698 { "un", 0x7 },
14699 { "st", 0xe },
14700 { "unst", 0x6 }
14703 /* Table of ARM-format instructions. */
14705 /* Macros for gluing together operand strings. N.B. In all cases
14706 other than OPS0, the trailing OP_stop comes from default
14707 zero-initialization of the unspecified elements of the array. */
14708 #define OPS0() { OP_stop, }
14709 #define OPS1(a) { OP_##a, }
14710 #define OPS2(a,b) { OP_##a,OP_##b, }
14711 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14712 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14713 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14714 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14716 /* These macros abstract out the exact format of the mnemonic table and
14717 save some repeated characters. */
14719 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14720 #define TxCE(mnem, op, top, nops, ops, ae, te) \
14721 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
14722 THUMB_VARIANT, do_##ae, do_##te }
14724 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14725 a T_MNEM_xyz enumerator. */
14726 #define TCE(mnem, aop, top, nops, ops, ae, te) \
14727 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14728 #define tCE(mnem, aop, top, nops, ops, ae, te) \
14729 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14731 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14732 infix after the third character. */
14733 #define TxC3(mnem, op, top, nops, ops, ae, te) \
14734 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
14735 THUMB_VARIANT, do_##ae, do_##te }
14736 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
14737 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14738 THUMB_VARIANT, do_##ae, do_##te }
14739 #define TC3(mnem, aop, top, nops, ops, ae, te) \
14740 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
14741 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
14742 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
14743 #define tC3(mnem, aop, top, nops, ops, ae, te) \
14744 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14745 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
14746 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14748 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14749 appear in the condition table. */
14750 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14751 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14752 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
14754 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14755 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14756 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14757 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14758 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14759 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14760 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14761 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14762 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14763 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14764 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14765 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14766 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14767 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14768 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14769 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14770 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14771 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14772 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14773 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14775 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14776 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14777 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14778 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14780 /* Mnemonic that cannot be conditionalized. The ARM condition-code
14781 field is still 0xE. Many of the Thumb variants can be executed
14782 conditionally, so this is checked separately. */
14783 #define TUE(mnem, op, top, nops, ops, ae, te) \
14784 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
14785 THUMB_VARIANT, do_##ae, do_##te }
14787 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14788 condition code field. */
14789 #define TUF(mnem, op, top, nops, ops, ae, te) \
14790 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
14791 THUMB_VARIANT, do_##ae, do_##te }
14793 /* ARM-only variants of all the above. */
14794 #define CE(mnem, op, nops, ops, ae) \
14795 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14797 #define C3(mnem, op, nops, ops, ae) \
14798 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14800 /* Legacy mnemonics that always have conditional infix after the third
14801 character. */
14802 #define CL(mnem, op, nops, ops, ae) \
14803 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14804 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14806 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14807 #define cCE(mnem, op, nops, ops, ae) \
14808 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14810 /* Legacy coprocessor instructions where conditional infix and conditional
14811 suffix are ambiguous. For consistency this includes all FPA instructions,
14812 not just the potentially ambiguous ones. */
14813 #define cCL(mnem, op, nops, ops, ae) \
14814 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14815 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14817 /* Coprocessor, takes either a suffix or a position-3 infix
14818 (for an FPA corner case). */
14819 #define C3E(mnem, op, nops, ops, ae) \
14820 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14821 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14823 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
14824 { #m1 #m2 #m3, OPS##nops ops, \
14825 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14826 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14828 #define CM(m1, m2, op, nops, ops, ae) \
14829 xCM_(m1, , m2, op, nops, ops, ae), \
14830 xCM_(m1, eq, m2, op, nops, ops, ae), \
14831 xCM_(m1, ne, m2, op, nops, ops, ae), \
14832 xCM_(m1, cs, m2, op, nops, ops, ae), \
14833 xCM_(m1, hs, m2, op, nops, ops, ae), \
14834 xCM_(m1, cc, m2, op, nops, ops, ae), \
14835 xCM_(m1, ul, m2, op, nops, ops, ae), \
14836 xCM_(m1, lo, m2, op, nops, ops, ae), \
14837 xCM_(m1, mi, m2, op, nops, ops, ae), \
14838 xCM_(m1, pl, m2, op, nops, ops, ae), \
14839 xCM_(m1, vs, m2, op, nops, ops, ae), \
14840 xCM_(m1, vc, m2, op, nops, ops, ae), \
14841 xCM_(m1, hi, m2, op, nops, ops, ae), \
14842 xCM_(m1, ls, m2, op, nops, ops, ae), \
14843 xCM_(m1, ge, m2, op, nops, ops, ae), \
14844 xCM_(m1, lt, m2, op, nops, ops, ae), \
14845 xCM_(m1, gt, m2, op, nops, ops, ae), \
14846 xCM_(m1, le, m2, op, nops, ops, ae), \
14847 xCM_(m1, al, m2, op, nops, ops, ae)
14849 #define UE(mnem, op, nops, ops, ae) \
14850 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14852 #define UF(mnem, op, nops, ops, ae) \
14853 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14855 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
14856 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14857 use the same encoding function for each. */
14858 #define NUF(mnem, op, nops, ops, enc) \
14859 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14860 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14862 /* Neon data processing, version which indirects through neon_enc_tab for
14863 the various overloaded versions of opcodes. */
14864 #define nUF(mnem, op, nops, ops, enc) \
14865 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14866 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14868 /* Neon insn with conditional suffix for the ARM version, non-overloaded
14869 version. */
14870 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
14871 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
14872 THUMB_VARIANT, do_##enc, do_##enc }
14874 #define NCE(mnem, op, nops, ops, enc) \
14875 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14877 #define NCEF(mnem, op, nops, ops, enc) \
14878 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14880 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
14881 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
14882 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
14883 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14885 #define nCE(mnem, op, nops, ops, enc) \
14886 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14888 #define nCEF(mnem, op, nops, ops, enc) \
14889 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14891 #define do_0 0
14893 /* Thumb-only, unconditional. */
14894 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14896 static const struct asm_opcode insns[] =
14898 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14899 #define THUMB_VARIANT &arm_ext_v4t
14900 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14901 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14902 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14903 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14904 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14905 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
14906 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14907 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
14908 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14909 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14910 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14911 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14912 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14913 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14914 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14915 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14917 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14918 for setting PSR flag bits. They are obsolete in V6 and do not
14919 have Thumb equivalents. */
14920 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14921 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14922 CL(tstp, 110f000, 2, (RR, SH), cmp),
14923 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14924 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14925 CL(cmpp, 150f000, 2, (RR, SH), cmp),
14926 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14927 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14928 CL(cmnp, 170f000, 2, (RR, SH), cmp),
14930 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14931 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14932 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14933 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14935 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14936 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14937 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14938 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14940 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14941 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14942 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14943 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14944 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14945 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14947 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
14948 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
14949 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
14950 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
14952 /* Pseudo ops. */
14953 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
14954 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14955 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
14957 /* Thumb-compatibility pseudo ops. */
14958 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14959 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14960 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14961 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14962 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
14963 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
14964 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14965 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14966 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14967 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14968 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14969 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14971 /* These may simplify to neg. */
14972 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14973 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14975 #undef THUMB_VARIANT
14976 #define THUMB_VARIANT &arm_ext_v6
14977 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
14979 /* V1 instructions with no Thumb analogue prior to V6T2. */
14980 #undef THUMB_VARIANT
14981 #define THUMB_VARIANT &arm_ext_v6t2
14982 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14983 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14984 CL(teqp, 130f000, 2, (RR, SH), cmp),
14986 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
14987 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
14988 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
14989 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
14991 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14992 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14994 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14995 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14997 /* V1 instructions with no Thumb analogue at all. */
14998 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14999 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15001 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15002 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15003 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15004 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15005 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15006 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15007 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15008 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15010 #undef ARM_VARIANT
15011 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
15012 #undef THUMB_VARIANT
15013 #define THUMB_VARIANT &arm_ext_v4t
15014 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15015 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15017 #undef THUMB_VARIANT
15018 #define THUMB_VARIANT &arm_ext_v6t2
15019 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15020 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15022 /* Generic coprocessor instructions. */
15023 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15024 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15025 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15026 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15027 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15028 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15029 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15031 #undef ARM_VARIANT
15032 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
15033 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15034 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15036 #undef ARM_VARIANT
15037 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
15038 #undef THUMB_VARIANT
15039 #define THUMB_VARIANT &arm_ext_msr
15040 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15041 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
15043 #undef ARM_VARIANT
15044 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
15045 #undef THUMB_VARIANT
15046 #define THUMB_VARIANT &arm_ext_v6t2
15047 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15048 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15049 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15050 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15051 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15052 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15053 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15054 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15056 #undef ARM_VARIANT
15057 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
15058 #undef THUMB_VARIANT
15059 #define THUMB_VARIANT &arm_ext_v4t
15060 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15061 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15062 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15063 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15064 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15065 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15067 #undef ARM_VARIANT
15068 #define ARM_VARIANT &arm_ext_v4t_5
15069 /* ARM Architecture 4T. */
15070 /* Note: bx (and blx) are required on V5, even if the processor does
15071 not support Thumb. */
15072 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15074 #undef ARM_VARIANT
15075 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
15076 #undef THUMB_VARIANT
15077 #define THUMB_VARIANT &arm_ext_v5t
15078 /* Note: blx has 2 variants; the .value coded here is for
15079 BLX(2). Only this variant has conditional execution. */
15080 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15081 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15083 #undef THUMB_VARIANT
15084 #define THUMB_VARIANT &arm_ext_v6t2
15085 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
15086 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15087 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15088 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15089 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15090 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15091 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15092 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15094 #undef ARM_VARIANT
15095 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
15096 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15097 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15098 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15099 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15101 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15102 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15104 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15105 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15106 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15107 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15109 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15110 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15111 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15112 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15114 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15115 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15117 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15118 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15119 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15120 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15122 #undef ARM_VARIANT
15123 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
15124 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
15125 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15126 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15128 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15129 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15131 #undef ARM_VARIANT
15132 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
15133 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15135 #undef ARM_VARIANT
15136 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
15137 #undef THUMB_VARIANT
15138 #define THUMB_VARIANT &arm_ext_v6
15139 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15140 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15141 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15142 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15143 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15144 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15145 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15146 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15147 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15148 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15150 #undef THUMB_VARIANT
15151 #define THUMB_VARIANT &arm_ext_v6t2
15152 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
15153 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
15154 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15155 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15157 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15158 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15160 /* ARM V6 not included in V7M (eg. integer SIMD). */
15161 #undef THUMB_VARIANT
15162 #define THUMB_VARIANT &arm_ext_v6_notm
15163 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
15164 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15165 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15166 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15167 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15168 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15169 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15170 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15171 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15172 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15173 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15174 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15175 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15176 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15177 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15178 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15179 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15180 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15181 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15182 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15183 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15184 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15185 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15186 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15187 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15188 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15189 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15190 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15191 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15192 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15193 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15194 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15195 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15196 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15197 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15198 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15199 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15200 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15201 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15202 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15203 UF(rfeib, 9900a00, 1, (RRw), rfe),
15204 UF(rfeda, 8100a00, 1, (RRw), rfe),
15205 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15206 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15207 UF(rfefa, 9900a00, 1, (RRw), rfe),
15208 UF(rfeea, 8100a00, 1, (RRw), rfe),
15209 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15210 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15211 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15212 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15213 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15214 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15215 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15216 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15217 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15218 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15219 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15220 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15221 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15222 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15223 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15224 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15225 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15226 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15227 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15228 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15229 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15230 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15231 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15232 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15233 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15234 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15235 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15236 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15237 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15238 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15239 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15240 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
15241 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
15242 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15243 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15244 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15245 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15247 #undef ARM_VARIANT
15248 #define ARM_VARIANT &arm_ext_v6k
15249 #undef THUMB_VARIANT
15250 #define THUMB_VARIANT &arm_ext_v6k
15251 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15252 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15253 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15254 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15256 #undef THUMB_VARIANT
15257 #define THUMB_VARIANT &arm_ext_v6_notm
15258 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15259 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15261 #undef THUMB_VARIANT
15262 #define THUMB_VARIANT &arm_ext_v6t2
15263 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15264 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15265 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15266 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15267 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15269 #undef ARM_VARIANT
15270 #define ARM_VARIANT &arm_ext_v6z
15271 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
15273 #undef ARM_VARIANT
15274 #define ARM_VARIANT &arm_ext_v6t2
15275 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15276 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15277 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15278 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15280 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15281 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15282 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
15283 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
15285 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15286 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15287 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15288 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15290 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15291 UT(cbz, b100, 2, (RR, EXP), t_cbz),
15292 /* ARM does not really have an IT instruction, so always allow it. */
15293 #undef ARM_VARIANT
15294 #define ARM_VARIANT &arm_ext_v1
15295 TUE(it, 0, bf08, 1, (COND), it, t_it),
15296 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15297 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15298 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15299 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15300 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15301 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15302 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15303 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15304 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15305 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15306 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15307 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15308 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15309 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15311 /* Thumb2 only instructions. */
15312 #undef ARM_VARIANT
15313 #define ARM_VARIANT NULL
15315 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15316 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15317 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15318 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15320 /* Thumb-2 hardware division instructions (R and M profiles only). */
15321 #undef THUMB_VARIANT
15322 #define THUMB_VARIANT &arm_ext_div
15323 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15324 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15326 /* ARM V6M/V7 instructions. */
15327 #undef ARM_VARIANT
15328 #define ARM_VARIANT &arm_ext_barrier
15329 #undef THUMB_VARIANT
15330 #define THUMB_VARIANT &arm_ext_barrier
15331 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15332 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15333 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15335 /* ARM V7 instructions. */
15336 #undef ARM_VARIANT
15337 #define ARM_VARIANT &arm_ext_v7
15338 #undef THUMB_VARIANT
15339 #define THUMB_VARIANT &arm_ext_v7
15340 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15341 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15343 #undef ARM_VARIANT
15344 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
15345 cCE(wfs, e200110, 1, (RR), rd),
15346 cCE(rfs, e300110, 1, (RR), rd),
15347 cCE(wfc, e400110, 1, (RR), rd),
15348 cCE(rfc, e500110, 1, (RR), rd),
15350 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15351 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15352 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15353 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
15355 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15356 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15357 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15358 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
15360 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15361 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15362 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15363 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15364 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15365 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15366 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15367 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15368 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15369 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15370 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15371 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15373 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15374 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15375 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15376 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15377 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15378 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15379 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15380 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15381 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15382 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15383 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15384 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15386 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15387 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15388 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15389 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15390 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15391 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15392 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15393 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15394 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15395 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15396 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15397 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15399 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15400 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15401 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15402 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15403 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15404 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15405 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15406 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15407 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15408 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15409 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15410 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15412 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15413 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15414 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15415 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15416 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15417 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15418 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15419 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15420 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15421 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15422 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15423 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15425 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15426 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15427 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15428 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15429 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15430 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15431 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15432 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15433 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15434 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15435 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15436 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15438 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15439 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15440 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15441 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15442 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15443 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15444 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15445 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15446 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15447 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15448 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15449 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15451 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15452 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15453 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15454 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15455 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15456 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15457 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15458 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15459 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15460 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15461 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15462 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15464 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15465 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15466 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15467 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15468 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15469 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15470 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15471 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15472 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15473 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15474 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15475 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15477 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15478 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15479 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15480 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15481 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15482 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15483 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15484 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15485 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15486 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15487 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15488 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15490 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15491 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15492 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15493 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15494 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15495 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15496 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15497 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15498 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15499 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15500 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15501 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15503 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15504 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15505 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15506 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15507 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15508 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15509 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15510 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15511 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15512 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15513 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15514 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15516 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15517 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15518 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15519 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15520 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15521 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15522 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15523 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15524 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15525 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15526 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15527 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15529 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15530 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15531 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15532 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15533 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15534 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15535 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15536 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15537 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15538 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15539 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15540 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15542 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15543 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15544 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15545 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15546 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15547 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15548 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15549 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15550 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15551 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15552 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15553 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15555 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15556 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15557 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15558 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15559 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15560 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15561 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15562 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15563 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15564 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15565 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15566 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15568 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15569 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15570 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15571 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15572 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15573 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15576 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15577 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15578 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15579 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15581 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15584 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15585 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15589 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15590 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15591 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15592 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15594 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15597 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15598 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15602 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15603 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15604 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15605 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15607 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15610 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15611 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15615 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15616 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15617 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15618 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15620 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15623 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15624 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15628 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15629 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15630 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15631 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15633 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15636 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15637 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15638 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15641 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15642 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15643 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15644 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15646 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15647 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15649 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15650 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15651 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15654 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15655 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15656 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15657 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15659 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15660 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15662 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15663 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15664 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15667 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15668 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15669 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15670 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15672 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15673 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15675 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15676 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15677 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15680 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15681 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15682 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15683 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15685 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15686 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15688 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15689 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15690 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15693 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15694 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15695 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15696 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15698 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15699 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15700 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15701 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15702 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15703 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15704 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15705 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15706 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15707 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15708 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15709 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15711 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15712 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15713 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15714 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15715 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15716 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15717 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15718 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15719 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15720 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15721 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15722 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15724 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15725 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15726 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15727 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15728 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15729 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15730 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15731 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15732 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15733 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15734 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15735 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15737 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
15738 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
15739 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
15740 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15742 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15743 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15744 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15745 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15746 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15747 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15748 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15749 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15750 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15751 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15752 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15753 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
15755 /* The implementation of the FIX instruction is broken on some
15756 assemblers, in that it accepts a precision specifier as well as a
15757 rounding specifier, despite the fact that this is meaningless.
15758 To be more compatible, we accept it as well, though of course it
15759 does not set any bits. */
15760 cCE(fix, e100110, 2, (RR, RF), rd_rm),
15761 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15762 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15763 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15764 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15765 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15766 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15767 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15768 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15769 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15770 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15771 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15772 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
15774 /* Instructions that were new with the real FPA, call them V2. */
15775 #undef ARM_VARIANT
15776 #define ARM_VARIANT &fpu_fpa_ext_v2
15777 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15778 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15779 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15780 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15781 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15782 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15784 #undef ARM_VARIANT
15785 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
15786 /* Moves and type conversions. */
15787 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15788 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15789 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15790 cCE(fmstat, ef1fa10, 0, (), noargs),
15791 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15792 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15793 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15794 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15795 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15796 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15797 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15798 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
15800 /* Memory operations. */
15801 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15802 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15803 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15804 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15805 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15806 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15807 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15808 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15809 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15810 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15811 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15812 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15813 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15814 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15815 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15816 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15817 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15818 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15820 /* Monadic operations. */
15821 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15822 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15823 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
15825 /* Dyadic operations. */
15826 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15827 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15828 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15829 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15830 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15831 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15832 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15833 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15834 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15836 /* Comparisons. */
15837 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15838 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15839 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15840 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
15842 #undef ARM_VARIANT
15843 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
15844 /* Moves and type conversions. */
15845 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15846 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15847 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15848 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15849 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15850 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15851 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
15852 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15853 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15854 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15855 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15856 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15857 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15859 /* Memory operations. */
15860 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15861 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15862 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15863 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15864 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15865 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15866 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15867 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15868 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15869 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15871 /* Monadic operations. */
15872 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15873 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15874 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15876 /* Dyadic operations. */
15877 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15878 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15879 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15880 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15881 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15882 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15883 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15884 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15885 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15887 /* Comparisons. */
15888 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15889 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15890 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15891 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
15893 #undef ARM_VARIANT
15894 #define ARM_VARIANT &fpu_vfp_ext_v2
15895 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15896 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
15897 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15898 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15900 /* Instructions which may belong to either the Neon or VFP instruction sets.
15901 Individual encoder functions perform additional architecture checks. */
15902 #undef ARM_VARIANT
15903 #define ARM_VARIANT &fpu_vfp_ext_v1xd
15904 #undef THUMB_VARIANT
15905 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
15906 /* These mnemonics are unique to VFP. */
15907 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15908 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15909 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15910 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15911 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15912 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15913 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15914 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15915 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15916 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15918 /* Mnemonics shared by Neon and VFP. */
15919 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15920 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15921 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15923 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15924 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15926 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15927 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15929 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15930 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15931 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15932 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15933 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15934 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15935 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15936 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15938 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15940 /* NOTE: All VMOV encoding is special-cased! */
15941 NCE(vmov, 0, 1, (VMOV), neon_mov),
15942 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15944 #undef THUMB_VARIANT
15945 #define THUMB_VARIANT &fpu_neon_ext_v1
15946 #undef ARM_VARIANT
15947 #define ARM_VARIANT &fpu_neon_ext_v1
15948 /* Data processing with three registers of the same length. */
15949 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15950 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15951 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15952 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15953 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15954 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15955 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15956 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15957 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15958 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15959 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15960 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15961 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15962 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15963 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15964 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15965 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15966 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15967 /* If not immediate, fall back to neon_dyadic_i64_su.
15968 shl_imm should accept I8 I16 I32 I64,
15969 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15970 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15971 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15972 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15973 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15974 /* Logic ops, types optional & ignored. */
15975 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15976 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15977 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15978 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15979 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15980 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15981 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15982 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15983 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15984 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15985 /* Bitfield ops, untyped. */
15986 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15987 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15988 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15989 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15990 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15991 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15992 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15993 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15994 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15995 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15996 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15997 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15998 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15999 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
16000 back to neon_dyadic_if_su. */
16001 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16002 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16003 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16004 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16005 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16006 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16007 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16008 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16009 /* Comparison. Type I8 I16 I32 F32. */
16010 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16011 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16012 /* As above, D registers only. */
16013 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16014 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16015 /* Int and float variants, signedness unimportant. */
16016 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16017 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16018 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16019 /* Add/sub take types I8 I16 I32 I64 F32. */
16020 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16021 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16022 /* vtst takes sizes 8, 16, 32. */
16023 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16024 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16025 /* VMUL takes I8 I16 I32 F32 P8. */
16026 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
16027 /* VQD{R}MULH takes S16 S32. */
16028 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16029 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16030 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16031 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16032 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16033 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16034 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16035 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16036 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16037 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16038 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16039 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16040 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16041 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16042 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16043 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16045 /* Two address, int/float. Types S8 S16 S32 F32. */
16046 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
16047 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16049 /* Data processing with two registers and a shift amount. */
16050 /* Right shifts, and variants with rounding.
16051 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16052 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16053 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16054 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16055 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16056 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16057 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16058 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16059 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16060 /* Shift and insert. Sizes accepted 8 16 32 64. */
16061 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16062 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16063 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16064 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16065 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16066 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16067 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16068 /* Right shift immediate, saturating & narrowing, with rounding variants.
16069 Types accepted S16 S32 S64 U16 U32 U64. */
16070 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16071 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16072 /* As above, unsigned. Types accepted S16 S32 S64. */
16073 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16074 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16075 /* Right shift narrowing. Types accepted I16 I32 I64. */
16076 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16077 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16078 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16079 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16080 /* CVT with optional immediate for fixed-point variant. */
16081 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
16083 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16084 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16086 /* Data processing, three registers of different lengths. */
16087 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16088 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16089 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16090 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16091 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16092 /* If not scalar, fall back to neon_dyadic_long.
16093 Vector types as above, scalar types S16 S32 U16 U32. */
16094 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16095 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16096 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16097 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16098 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16099 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16100 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16101 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16102 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16103 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16104 /* Saturating doubling multiplies. Types S16 S32. */
16105 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16106 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16107 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16108 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16109 S16 S32 U16 U32. */
16110 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16112 /* Extract. Size 8. */
16113 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16114 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
16116 /* Two registers, miscellaneous. */
16117 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16118 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16119 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16120 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16121 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16122 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16123 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16124 /* Vector replicate. Sizes 8 16 32. */
16125 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16126 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16127 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16128 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16129 /* VMOVN. Types I16 I32 I64. */
16130 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16131 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16132 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16133 /* VQMOVUN. Types S16 S32 S64. */
16134 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16135 /* VZIP / VUZP. Sizes 8 16 32. */
16136 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16137 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16138 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16139 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16140 /* VQABS / VQNEG. Types S8 S16 S32. */
16141 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16142 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16143 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16144 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16145 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16146 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16147 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16148 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16149 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16150 /* Reciprocal estimates. Types U32 F32. */
16151 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16152 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16153 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16154 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16155 /* VCLS. Types S8 S16 S32. */
16156 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16157 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16158 /* VCLZ. Types I8 I16 I32. */
16159 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16160 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16161 /* VCNT. Size 8. */
16162 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16163 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16164 /* Two address, untyped. */
16165 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16166 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16167 /* VTRN. Sizes 8 16 32. */
16168 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16169 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16171 /* Table lookup. Size 8. */
16172 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16173 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16175 #undef THUMB_VARIANT
16176 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16177 #undef ARM_VARIANT
16178 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
16179 /* Neon element/structure load/store. */
16180 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16181 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16182 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16183 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16184 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16185 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16186 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16187 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16189 #undef THUMB_VARIANT
16190 #define THUMB_VARIANT &fpu_vfp_ext_v3
16191 #undef ARM_VARIANT
16192 #define ARM_VARIANT &fpu_vfp_ext_v3
16193 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16194 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16195 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16196 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16197 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16198 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16199 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16200 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16201 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16202 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16203 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16204 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16205 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16206 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16207 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16208 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16209 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16210 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16212 #undef THUMB_VARIANT
16213 #undef ARM_VARIANT
16214 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
16215 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16216 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16217 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16218 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16219 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16220 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16221 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16222 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
16224 #undef ARM_VARIANT
16225 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
16226 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16227 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16228 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16229 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16230 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16231 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16232 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16233 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16234 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16235 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16236 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16237 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16238 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16239 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16240 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16241 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16242 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16243 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16244 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
16245 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16246 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16247 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16248 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16249 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16250 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16251 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16252 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16253 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16254 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
16255 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
16256 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16257 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16258 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16259 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16260 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16261 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16262 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16263 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16264 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16265 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16266 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16267 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16268 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16269 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16270 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16271 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16272 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16273 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16276 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16277 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16278 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16279 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16281 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16288 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16289 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16290 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16291 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16292 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16293 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16294 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16295 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16296 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16297 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16298 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16299 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16300 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16303 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16304 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16305 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16306 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16307 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16308 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16309 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16310 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16311 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16312 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16313 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16314 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16315 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16316 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16317 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16318 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16319 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16320 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16321 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16322 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16323 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16324 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16325 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16326 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16327 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16328 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16329 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16330 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16331 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16332 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16333 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16334 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16335 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16336 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
16337 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16338 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16339 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16340 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16341 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16342 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16343 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16344 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16345 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16346 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16347 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16348 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16349 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16350 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16351 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16352 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16353 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16354 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16355 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16356 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16357 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16358 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16359 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16360 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16361 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16362 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16363 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16364 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16365 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16366 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16367 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16368 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16369 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16370 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16371 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16372 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16373 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16374 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16375 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16376 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16377 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16378 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16379 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16380 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16381 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16382 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16383 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16384 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16385 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16386 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16387 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
16389 #undef ARM_VARIANT
16390 #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16391 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16392 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16393 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16394 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16395 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16396 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16397 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16398 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16399 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16400 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16401 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16402 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16403 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16404 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16405 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16406 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16407 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16408 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16410 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16412 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16415 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16416 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16417 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16418 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16419 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16420 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16421 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16422 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16423 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16424 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16425 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16426 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16427 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16428 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16429 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16430 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16431 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16432 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16433 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16434 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16435 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16436 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16437 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16438 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16439 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16440 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16441 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16442 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16443 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16444 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16445 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16446 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16447 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16449 #undef ARM_VARIANT
16450 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
16451 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16452 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16453 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16454 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16455 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16456 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16457 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16458 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16459 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16460 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16461 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16462 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16463 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16464 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16465 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16466 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16467 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16468 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16469 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16470 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16471 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16472 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16473 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16474 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16475 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16476 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16477 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16478 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16479 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16480 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16481 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16482 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16483 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16484 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16485 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16486 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16487 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16488 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16489 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16490 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16491 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16492 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16493 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16494 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16495 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16496 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16497 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16498 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16499 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16500 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16501 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16502 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16503 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16504 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16505 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16506 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16507 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16508 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16509 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16510 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16511 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16512 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16513 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16514 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16515 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16516 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16517 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16518 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16519 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16520 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16521 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16522 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16523 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16524 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16525 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16526 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16528 #undef ARM_VARIANT
16529 #undef THUMB_VARIANT
16530 #undef TCE
16531 #undef TCM
16532 #undef TUE
16533 #undef TUF
16534 #undef TCC
16535 #undef cCE
16536 #undef cCL
16537 #undef C3E
16538 #undef CE
16539 #undef CM
16540 #undef UE
16541 #undef UF
16542 #undef UT
16543 #undef NUF
16544 #undef nUF
16545 #undef NCE
16546 #undef nCE
16547 #undef OPS0
16548 #undef OPS1
16549 #undef OPS2
16550 #undef OPS3
16551 #undef OPS4
16552 #undef OPS5
16553 #undef OPS6
16554 #undef do_0
16556 /* MD interface: bits in the object file. */
16558 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16559 for use in the a.out file, and stores them in the array pointed to by buf.
16560 This knows about the endian-ness of the target machine and does
16561 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16562 2 (short) and 4 (long) Floating numbers are put out as a series of
16563 LITTLENUMS (shorts, here at least). */
16565 void
16566 md_number_to_chars (char * buf, valueT val, int n)
16568 if (target_big_endian)
16569 number_to_chars_bigendian (buf, val, n);
16570 else
16571 number_to_chars_littleendian (buf, val, n);
16574 static valueT
16575 md_chars_to_number (char * buf, int n)
16577 valueT result = 0;
16578 unsigned char * where = (unsigned char *) buf;
16580 if (target_big_endian)
16582 while (n--)
16584 result <<= 8;
16585 result |= (*where++ & 255);
16588 else
16590 while (n--)
16592 result <<= 8;
16593 result |= (where[n] & 255);
16597 return result;
16600 /* MD interface: Sections. */
16602 /* Estimate the size of a frag before relaxing. Assume everything fits in
16603 2 bytes. */
16606 md_estimate_size_before_relax (fragS * fragp,
16607 segT segtype ATTRIBUTE_UNUSED)
16609 fragp->fr_var = 2;
16610 return 2;
16613 /* Convert a machine dependent frag. */
16615 void
16616 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16618 unsigned long insn;
16619 unsigned long old_op;
16620 char *buf;
16621 expressionS exp;
16622 fixS *fixp;
16623 int reloc_type;
16624 int pc_rel;
16625 int opcode;
16627 buf = fragp->fr_literal + fragp->fr_fix;
16629 old_op = bfd_get_16(abfd, buf);
16630 if (fragp->fr_symbol)
16632 exp.X_op = O_symbol;
16633 exp.X_add_symbol = fragp->fr_symbol;
16635 else
16637 exp.X_op = O_constant;
16639 exp.X_add_number = fragp->fr_offset;
16640 opcode = fragp->fr_subtype;
16641 switch (opcode)
16643 case T_MNEM_ldr_pc:
16644 case T_MNEM_ldr_pc2:
16645 case T_MNEM_ldr_sp:
16646 case T_MNEM_str_sp:
16647 case T_MNEM_ldr:
16648 case T_MNEM_ldrb:
16649 case T_MNEM_ldrh:
16650 case T_MNEM_str:
16651 case T_MNEM_strb:
16652 case T_MNEM_strh:
16653 if (fragp->fr_var == 4)
16655 insn = THUMB_OP32 (opcode);
16656 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16658 insn |= (old_op & 0x700) << 4;
16660 else
16662 insn |= (old_op & 7) << 12;
16663 insn |= (old_op & 0x38) << 13;
16665 insn |= 0x00000c00;
16666 put_thumb32_insn (buf, insn);
16667 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16669 else
16671 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16673 pc_rel = (opcode == T_MNEM_ldr_pc2);
16674 break;
16675 case T_MNEM_adr:
16676 if (fragp->fr_var == 4)
16678 insn = THUMB_OP32 (opcode);
16679 insn |= (old_op & 0xf0) << 4;
16680 put_thumb32_insn (buf, insn);
16681 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16683 else
16685 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16686 exp.X_add_number -= 4;
16688 pc_rel = 1;
16689 break;
16690 case T_MNEM_mov:
16691 case T_MNEM_movs:
16692 case T_MNEM_cmp:
16693 case T_MNEM_cmn:
16694 if (fragp->fr_var == 4)
16696 int r0off = (opcode == T_MNEM_mov
16697 || opcode == T_MNEM_movs) ? 0 : 8;
16698 insn = THUMB_OP32 (opcode);
16699 insn = (insn & 0xe1ffffff) | 0x10000000;
16700 insn |= (old_op & 0x700) << r0off;
16701 put_thumb32_insn (buf, insn);
16702 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16704 else
16706 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16708 pc_rel = 0;
16709 break;
16710 case T_MNEM_b:
16711 if (fragp->fr_var == 4)
16713 insn = THUMB_OP32(opcode);
16714 put_thumb32_insn (buf, insn);
16715 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16717 else
16718 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16719 pc_rel = 1;
16720 break;
16721 case T_MNEM_bcond:
16722 if (fragp->fr_var == 4)
16724 insn = THUMB_OP32(opcode);
16725 insn |= (old_op & 0xf00) << 14;
16726 put_thumb32_insn (buf, insn);
16727 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16729 else
16730 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16731 pc_rel = 1;
16732 break;
16733 case T_MNEM_add_sp:
16734 case T_MNEM_add_pc:
16735 case T_MNEM_inc_sp:
16736 case T_MNEM_dec_sp:
16737 if (fragp->fr_var == 4)
16739 /* ??? Choose between add and addw. */
16740 insn = THUMB_OP32 (opcode);
16741 insn |= (old_op & 0xf0) << 4;
16742 put_thumb32_insn (buf, insn);
16743 if (opcode == T_MNEM_add_pc)
16744 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16745 else
16746 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16748 else
16749 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16750 pc_rel = 0;
16751 break;
16753 case T_MNEM_addi:
16754 case T_MNEM_addis:
16755 case T_MNEM_subi:
16756 case T_MNEM_subis:
16757 if (fragp->fr_var == 4)
16759 insn = THUMB_OP32 (opcode);
16760 insn |= (old_op & 0xf0) << 4;
16761 insn |= (old_op & 0xf) << 16;
16762 put_thumb32_insn (buf, insn);
16763 if (insn & (1 << 20))
16764 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16765 else
16766 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16768 else
16769 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16770 pc_rel = 0;
16771 break;
16772 default:
16773 abort ();
16775 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16776 reloc_type);
16777 fixp->fx_file = fragp->fr_file;
16778 fixp->fx_line = fragp->fr_line;
16779 fragp->fr_fix += fragp->fr_var;
16782 /* Return the size of a relaxable immediate operand instruction.
16783 SHIFT and SIZE specify the form of the allowable immediate. */
16784 static int
16785 relax_immediate (fragS *fragp, int size, int shift)
16787 offsetT offset;
16788 offsetT mask;
16789 offsetT low;
16791 /* ??? Should be able to do better than this. */
16792 if (fragp->fr_symbol)
16793 return 4;
16795 low = (1 << shift) - 1;
16796 mask = (1 << (shift + size)) - (1 << shift);
16797 offset = fragp->fr_offset;
16798 /* Force misaligned offsets to 32-bit variant. */
16799 if (offset & low)
16800 return 4;
16801 if (offset & ~mask)
16802 return 4;
16803 return 2;
16806 /* Get the address of a symbol during relaxation. */
16807 static addressT
16808 relaxed_symbol_addr (fragS *fragp, long stretch)
16810 fragS *sym_frag;
16811 addressT addr;
16812 symbolS *sym;
16814 sym = fragp->fr_symbol;
16815 sym_frag = symbol_get_frag (sym);
16816 know (S_GET_SEGMENT (sym) != absolute_section
16817 || sym_frag == &zero_address_frag);
16818 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16820 /* If frag has yet to be reached on this pass, assume it will
16821 move by STRETCH just as we did. If this is not so, it will
16822 be because some frag between grows, and that will force
16823 another pass. */
16825 if (stretch != 0
16826 && sym_frag->relax_marker != fragp->relax_marker)
16828 fragS *f;
16830 /* Adjust stretch for any alignment frag. Note that if have
16831 been expanding the earlier code, the symbol may be
16832 defined in what appears to be an earlier frag. FIXME:
16833 This doesn't handle the fr_subtype field, which specifies
16834 a maximum number of bytes to skip when doing an
16835 alignment. */
16836 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
16838 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
16840 if (stretch < 0)
16841 stretch = - ((- stretch)
16842 & ~ ((1 << (int) f->fr_offset) - 1));
16843 else
16844 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
16845 if (stretch == 0)
16846 break;
16849 if (f != NULL)
16850 addr += stretch;
16853 return addr;
16856 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
16857 load. */
16858 static int
16859 relax_adr (fragS *fragp, asection *sec, long stretch)
16861 addressT addr;
16862 offsetT val;
16864 /* Assume worst case for symbols not known to be in the same section. */
16865 if (!S_IS_DEFINED (fragp->fr_symbol)
16866 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16867 return 4;
16869 val = relaxed_symbol_addr (fragp, stretch);
16870 addr = fragp->fr_address + fragp->fr_fix;
16871 addr = (addr + 4) & ~3;
16872 /* Force misaligned targets to 32-bit variant. */
16873 if (val & 3)
16874 return 4;
16875 val -= addr;
16876 if (val < 0 || val > 1020)
16877 return 4;
16878 return 2;
16881 /* Return the size of a relaxable add/sub immediate instruction. */
16882 static int
16883 relax_addsub (fragS *fragp, asection *sec)
16885 char *buf;
16886 int op;
16888 buf = fragp->fr_literal + fragp->fr_fix;
16889 op = bfd_get_16(sec->owner, buf);
16890 if ((op & 0xf) == ((op >> 4) & 0xf))
16891 return relax_immediate (fragp, 8, 0);
16892 else
16893 return relax_immediate (fragp, 3, 0);
16897 /* Return the size of a relaxable branch instruction. BITS is the
16898 size of the offset field in the narrow instruction. */
16900 static int
16901 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
16903 addressT addr;
16904 offsetT val;
16905 offsetT limit;
16907 /* Assume worst case for symbols not known to be in the same section. */
16908 if (!S_IS_DEFINED (fragp->fr_symbol)
16909 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16910 return 4;
16912 val = relaxed_symbol_addr (fragp, stretch);
16913 addr = fragp->fr_address + fragp->fr_fix + 4;
16914 val -= addr;
16916 /* Offset is a signed value *2 */
16917 limit = 1 << bits;
16918 if (val >= limit || val < -limit)
16919 return 4;
16920 return 2;
16924 /* Relax a machine dependent frag. This returns the amount by which
16925 the current size of the frag should change. */
16928 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
16930 int oldsize;
16931 int newsize;
16933 oldsize = fragp->fr_var;
16934 switch (fragp->fr_subtype)
16936 case T_MNEM_ldr_pc2:
16937 newsize = relax_adr (fragp, sec, stretch);
16938 break;
16939 case T_MNEM_ldr_pc:
16940 case T_MNEM_ldr_sp:
16941 case T_MNEM_str_sp:
16942 newsize = relax_immediate (fragp, 8, 2);
16943 break;
16944 case T_MNEM_ldr:
16945 case T_MNEM_str:
16946 newsize = relax_immediate (fragp, 5, 2);
16947 break;
16948 case T_MNEM_ldrh:
16949 case T_MNEM_strh:
16950 newsize = relax_immediate (fragp, 5, 1);
16951 break;
16952 case T_MNEM_ldrb:
16953 case T_MNEM_strb:
16954 newsize = relax_immediate (fragp, 5, 0);
16955 break;
16956 case T_MNEM_adr:
16957 newsize = relax_adr (fragp, sec, stretch);
16958 break;
16959 case T_MNEM_mov:
16960 case T_MNEM_movs:
16961 case T_MNEM_cmp:
16962 case T_MNEM_cmn:
16963 newsize = relax_immediate (fragp, 8, 0);
16964 break;
16965 case T_MNEM_b:
16966 newsize = relax_branch (fragp, sec, 11, stretch);
16967 break;
16968 case T_MNEM_bcond:
16969 newsize = relax_branch (fragp, sec, 8, stretch);
16970 break;
16971 case T_MNEM_add_sp:
16972 case T_MNEM_add_pc:
16973 newsize = relax_immediate (fragp, 8, 2);
16974 break;
16975 case T_MNEM_inc_sp:
16976 case T_MNEM_dec_sp:
16977 newsize = relax_immediate (fragp, 7, 2);
16978 break;
16979 case T_MNEM_addi:
16980 case T_MNEM_addis:
16981 case T_MNEM_subi:
16982 case T_MNEM_subis:
16983 newsize = relax_addsub (fragp, sec);
16984 break;
16985 default:
16986 abort ();
16989 fragp->fr_var = newsize;
16990 /* Freeze wide instructions that are at or before the same location as
16991 in the previous pass. This avoids infinite loops.
16992 Don't freeze them unconditionally because targets may be artificially
16993 misaligned by the expansion of preceding frags. */
16994 if (stretch <= 0 && newsize > 2)
16996 md_convert_frag (sec->owner, sec, fragp);
16997 frag_wane (fragp);
17000 return newsize - oldsize;
17003 /* Round up a section size to the appropriate boundary. */
17005 valueT
17006 md_section_align (segT segment ATTRIBUTE_UNUSED,
17007 valueT size)
17009 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17010 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17012 /* For a.out, force the section size to be aligned. If we don't do
17013 this, BFD will align it for us, but it will not write out the
17014 final bytes of the section. This may be a bug in BFD, but it is
17015 easier to fix it here since that is how the other a.out targets
17016 work. */
17017 int align;
17019 align = bfd_get_section_alignment (stdoutput, segment);
17020 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17022 #endif
17024 return size;
17027 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17028 of an rs_align_code fragment. */
17030 void
17031 arm_handle_align (fragS * fragP)
17033 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
17034 static char const thumb_noop[2] = { 0xc0, 0x46 };
17035 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
17036 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
17038 int bytes, fix, noop_size;
17039 char * p;
17040 const char * noop;
17042 if (fragP->fr_type != rs_align_code)
17043 return;
17045 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17046 p = fragP->fr_literal + fragP->fr_fix;
17047 fix = 0;
17049 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17050 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
17052 if (fragP->tc_frag_data)
17054 if (target_big_endian)
17055 noop = thumb_bigend_noop;
17056 else
17057 noop = thumb_noop;
17058 noop_size = sizeof (thumb_noop);
17060 else
17062 if (target_big_endian)
17063 noop = arm_bigend_noop;
17064 else
17065 noop = arm_noop;
17066 noop_size = sizeof (arm_noop);
17069 if (bytes & (noop_size - 1))
17071 fix = bytes & (noop_size - 1);
17072 memset (p, 0, fix);
17073 p += fix;
17074 bytes -= fix;
17077 while (bytes >= noop_size)
17079 memcpy (p, noop, noop_size);
17080 p += noop_size;
17081 bytes -= noop_size;
17082 fix += noop_size;
17085 fragP->fr_fix += fix;
17086 fragP->fr_var = noop_size;
17089 /* Called from md_do_align. Used to create an alignment
17090 frag in a code section. */
17092 void
17093 arm_frag_align_code (int n, int max)
17095 char * p;
17097 /* We assume that there will never be a requirement
17098 to support alignments greater than 32 bytes. */
17099 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17100 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
17102 p = frag_var (rs_align_code,
17103 MAX_MEM_FOR_RS_ALIGN_CODE,
17105 (relax_substateT) max,
17106 (symbolS *) NULL,
17107 (offsetT) n,
17108 (char *) NULL);
17109 *p = 0;
17112 /* Perform target specific initialisation of a frag. */
17114 void
17115 arm_init_frag (fragS * fragP)
17117 /* Record whether this frag is in an ARM or a THUMB area. */
17118 fragP->tc_frag_data = thumb_mode;
17121 #ifdef OBJ_ELF
17122 /* When we change sections we need to issue a new mapping symbol. */
17124 void
17125 arm_elf_change_section (void)
17127 flagword flags;
17128 segment_info_type *seginfo;
17130 /* Link an unlinked unwind index table section to the .text section. */
17131 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17132 && elf_linked_to_section (now_seg) == NULL)
17133 elf_linked_to_section (now_seg) = text_section;
17135 if (!SEG_NORMAL (now_seg))
17136 return;
17138 flags = bfd_get_section_flags (stdoutput, now_seg);
17140 /* We can ignore sections that only contain debug info. */
17141 if ((flags & SEC_ALLOC) == 0)
17142 return;
17144 seginfo = seg_info (now_seg);
17145 mapstate = seginfo->tc_segment_info_data.mapstate;
17146 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
17150 arm_elf_section_type (const char * str, size_t len)
17152 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17153 return SHT_ARM_EXIDX;
17155 return -1;
17158 /* Code to deal with unwinding tables. */
17160 static void add_unwind_adjustsp (offsetT);
17162 /* Generate any deferred unwind frame offset. */
17164 static void
17165 flush_pending_unwind (void)
17167 offsetT offset;
17169 offset = unwind.pending_offset;
17170 unwind.pending_offset = 0;
17171 if (offset != 0)
17172 add_unwind_adjustsp (offset);
17175 /* Add an opcode to this list for this function. Two-byte opcodes should
17176 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17177 order. */
17179 static void
17180 add_unwind_opcode (valueT op, int length)
17182 /* Add any deferred stack adjustment. */
17183 if (unwind.pending_offset)
17184 flush_pending_unwind ();
17186 unwind.sp_restored = 0;
17188 if (unwind.opcode_count + length > unwind.opcode_alloc)
17190 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17191 if (unwind.opcodes)
17192 unwind.opcodes = xrealloc (unwind.opcodes,
17193 unwind.opcode_alloc);
17194 else
17195 unwind.opcodes = xmalloc (unwind.opcode_alloc);
17197 while (length > 0)
17199 length--;
17200 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17201 op >>= 8;
17202 unwind.opcode_count++;
17206 /* Add unwind opcodes to adjust the stack pointer. */
17208 static void
17209 add_unwind_adjustsp (offsetT offset)
17211 valueT op;
17213 if (offset > 0x200)
17215 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17216 char bytes[5];
17217 int n;
17218 valueT o;
17220 /* Long form: 0xb2, uleb128. */
17221 /* This might not fit in a word so add the individual bytes,
17222 remembering the list is built in reverse order. */
17223 o = (valueT) ((offset - 0x204) >> 2);
17224 if (o == 0)
17225 add_unwind_opcode (0, 1);
17227 /* Calculate the uleb128 encoding of the offset. */
17228 n = 0;
17229 while (o)
17231 bytes[n] = o & 0x7f;
17232 o >>= 7;
17233 if (o)
17234 bytes[n] |= 0x80;
17235 n++;
17237 /* Add the insn. */
17238 for (; n; n--)
17239 add_unwind_opcode (bytes[n - 1], 1);
17240 add_unwind_opcode (0xb2, 1);
17242 else if (offset > 0x100)
17244 /* Two short opcodes. */
17245 add_unwind_opcode (0x3f, 1);
17246 op = (offset - 0x104) >> 2;
17247 add_unwind_opcode (op, 1);
17249 else if (offset > 0)
17251 /* Short opcode. */
17252 op = (offset - 4) >> 2;
17253 add_unwind_opcode (op, 1);
17255 else if (offset < 0)
17257 offset = -offset;
17258 while (offset > 0x100)
17260 add_unwind_opcode (0x7f, 1);
17261 offset -= 0x100;
17263 op = ((offset - 4) >> 2) | 0x40;
17264 add_unwind_opcode (op, 1);
17268 /* Finish the list of unwind opcodes for this function. */
17269 static void
17270 finish_unwind_opcodes (void)
17272 valueT op;
17274 if (unwind.fp_used)
17276 /* Adjust sp as necessary. */
17277 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17278 flush_pending_unwind ();
17280 /* After restoring sp from the frame pointer. */
17281 op = 0x90 | unwind.fp_reg;
17282 add_unwind_opcode (op, 1);
17284 else
17285 flush_pending_unwind ();
17289 /* Start an exception table entry. If idx is nonzero this is an index table
17290 entry. */
17292 static void
17293 start_unwind_section (const segT text_seg, int idx)
17295 const char * text_name;
17296 const char * prefix;
17297 const char * prefix_once;
17298 const char * group_name;
17299 size_t prefix_len;
17300 size_t text_len;
17301 char * sec_name;
17302 size_t sec_name_len;
17303 int type;
17304 int flags;
17305 int linkonce;
17307 if (idx)
17309 prefix = ELF_STRING_ARM_unwind;
17310 prefix_once = ELF_STRING_ARM_unwind_once;
17311 type = SHT_ARM_EXIDX;
17313 else
17315 prefix = ELF_STRING_ARM_unwind_info;
17316 prefix_once = ELF_STRING_ARM_unwind_info_once;
17317 type = SHT_PROGBITS;
17320 text_name = segment_name (text_seg);
17321 if (streq (text_name, ".text"))
17322 text_name = "";
17324 if (strncmp (text_name, ".gnu.linkonce.t.",
17325 strlen (".gnu.linkonce.t.")) == 0)
17327 prefix = prefix_once;
17328 text_name += strlen (".gnu.linkonce.t.");
17331 prefix_len = strlen (prefix);
17332 text_len = strlen (text_name);
17333 sec_name_len = prefix_len + text_len;
17334 sec_name = xmalloc (sec_name_len + 1);
17335 memcpy (sec_name, prefix, prefix_len);
17336 memcpy (sec_name + prefix_len, text_name, text_len);
17337 sec_name[prefix_len + text_len] = '\0';
17339 flags = SHF_ALLOC;
17340 linkonce = 0;
17341 group_name = 0;
17343 /* Handle COMDAT group. */
17344 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
17346 group_name = elf_group_name (text_seg);
17347 if (group_name == NULL)
17349 as_bad (_("Group section `%s' has no group signature"),
17350 segment_name (text_seg));
17351 ignore_rest_of_line ();
17352 return;
17354 flags |= SHF_GROUP;
17355 linkonce = 1;
17358 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
17360 /* Set the section link for index tables. */
17361 if (idx)
17362 elf_linked_to_section (now_seg) = text_seg;
17366 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17367 personality routine data. Returns zero, or the index table value for
17368 and inline entry. */
17370 static valueT
17371 create_unwind_entry (int have_data)
17373 int size;
17374 addressT where;
17375 char *ptr;
17376 /* The current word of data. */
17377 valueT data;
17378 /* The number of bytes left in this word. */
17379 int n;
17381 finish_unwind_opcodes ();
17383 /* Remember the current text section. */
17384 unwind.saved_seg = now_seg;
17385 unwind.saved_subseg = now_subseg;
17387 start_unwind_section (now_seg, 0);
17389 if (unwind.personality_routine == NULL)
17391 if (unwind.personality_index == -2)
17393 if (have_data)
17394 as_bad (_("handlerdata in cantunwind frame"));
17395 return 1; /* EXIDX_CANTUNWIND. */
17398 /* Use a default personality routine if none is specified. */
17399 if (unwind.personality_index == -1)
17401 if (unwind.opcode_count > 3)
17402 unwind.personality_index = 1;
17403 else
17404 unwind.personality_index = 0;
17407 /* Space for the personality routine entry. */
17408 if (unwind.personality_index == 0)
17410 if (unwind.opcode_count > 3)
17411 as_bad (_("too many unwind opcodes for personality routine 0"));
17413 if (!have_data)
17415 /* All the data is inline in the index table. */
17416 data = 0x80;
17417 n = 3;
17418 while (unwind.opcode_count > 0)
17420 unwind.opcode_count--;
17421 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17422 n--;
17425 /* Pad with "finish" opcodes. */
17426 while (n--)
17427 data = (data << 8) | 0xb0;
17429 return data;
17431 size = 0;
17433 else
17434 /* We get two opcodes "free" in the first word. */
17435 size = unwind.opcode_count - 2;
17437 else
17438 /* An extra byte is required for the opcode count. */
17439 size = unwind.opcode_count + 1;
17441 size = (size + 3) >> 2;
17442 if (size > 0xff)
17443 as_bad (_("too many unwind opcodes"));
17445 frag_align (2, 0, 0);
17446 record_alignment (now_seg, 2);
17447 unwind.table_entry = expr_build_dot ();
17449 /* Allocate the table entry. */
17450 ptr = frag_more ((size << 2) + 4);
17451 where = frag_now_fix () - ((size << 2) + 4);
17453 switch (unwind.personality_index)
17455 case -1:
17456 /* ??? Should this be a PLT generating relocation? */
17457 /* Custom personality routine. */
17458 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17459 BFD_RELOC_ARM_PREL31);
17461 where += 4;
17462 ptr += 4;
17464 /* Set the first byte to the number of additional words. */
17465 data = size - 1;
17466 n = 3;
17467 break;
17469 /* ABI defined personality routines. */
17470 case 0:
17471 /* Three opcodes bytes are packed into the first word. */
17472 data = 0x80;
17473 n = 3;
17474 break;
17476 case 1:
17477 case 2:
17478 /* The size and first two opcode bytes go in the first word. */
17479 data = ((0x80 + unwind.personality_index) << 8) | size;
17480 n = 2;
17481 break;
17483 default:
17484 /* Should never happen. */
17485 abort ();
17488 /* Pack the opcodes into words (MSB first), reversing the list at the same
17489 time. */
17490 while (unwind.opcode_count > 0)
17492 if (n == 0)
17494 md_number_to_chars (ptr, data, 4);
17495 ptr += 4;
17496 n = 4;
17497 data = 0;
17499 unwind.opcode_count--;
17500 n--;
17501 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17504 /* Finish off the last word. */
17505 if (n < 4)
17507 /* Pad with "finish" opcodes. */
17508 while (n--)
17509 data = (data << 8) | 0xb0;
17511 md_number_to_chars (ptr, data, 4);
17514 if (!have_data)
17516 /* Add an empty descriptor if there is no user-specified data. */
17517 ptr = frag_more (4);
17518 md_number_to_chars (ptr, 0, 4);
17521 return 0;
17525 /* Initialize the DWARF-2 unwind information for this procedure. */
17527 void
17528 tc_arm_frame_initial_instructions (void)
17530 cfi_add_CFA_def_cfa (REG_SP, 0);
17532 #endif /* OBJ_ELF */
17534 /* Convert REGNAME to a DWARF-2 register number. */
17537 tc_arm_regname_to_dw2regnum (char *regname)
17539 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
17541 if (reg == FAIL)
17542 return -1;
17544 return reg;
17547 #ifdef TE_PE
17548 void
17549 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
17551 expressionS expr;
17553 expr.X_op = O_secrel;
17554 expr.X_add_symbol = symbol;
17555 expr.X_add_number = 0;
17556 emit_expr (&expr, size);
17558 #endif
17560 /* MD interface: Symbol and relocation handling. */
17562 /* Return the address within the segment that a PC-relative fixup is
17563 relative to. For ARM, PC-relative fixups applied to instructions
17564 are generally relative to the location of the fixup plus 8 bytes.
17565 Thumb branches are offset by 4, and Thumb loads relative to PC
17566 require special handling. */
17568 long
17569 md_pcrel_from_section (fixS * fixP, segT seg)
17571 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17573 /* If this is pc-relative and we are going to emit a relocation
17574 then we just want to put out any pipeline compensation that the linker
17575 will need. Otherwise we want to use the calculated base.
17576 For WinCE we skip the bias for externals as well, since this
17577 is how the MS ARM-CE assembler behaves and we want to be compatible. */
17578 if (fixP->fx_pcrel
17579 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
17580 || (arm_force_relocation (fixP)
17581 #ifdef TE_WINCE
17582 && !S_IS_EXTERNAL (fixP->fx_addsy)
17583 #endif
17585 base = 0;
17587 switch (fixP->fx_r_type)
17589 /* PC relative addressing on the Thumb is slightly odd as the
17590 bottom two bits of the PC are forced to zero for the
17591 calculation. This happens *after* application of the
17592 pipeline offset. However, Thumb adrl already adjusts for
17593 this, so we need not do it again. */
17594 case BFD_RELOC_ARM_THUMB_ADD:
17595 return base & ~3;
17597 case BFD_RELOC_ARM_THUMB_OFFSET:
17598 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17599 case BFD_RELOC_ARM_T32_ADD_PC12:
17600 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
17601 return (base + 4) & ~3;
17603 /* Thumb branches are simply offset by +4. */
17604 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17605 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17606 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17607 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17608 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17609 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17610 case BFD_RELOC_THUMB_PCREL_BLX:
17611 return base + 4;
17613 /* ARM mode branches are offset by +8. However, the Windows CE
17614 loader expects the relocation not to take this into account. */
17615 case BFD_RELOC_ARM_PCREL_BRANCH:
17616 case BFD_RELOC_ARM_PCREL_CALL:
17617 case BFD_RELOC_ARM_PCREL_JUMP:
17618 case BFD_RELOC_ARM_PCREL_BLX:
17619 case BFD_RELOC_ARM_PLT32:
17620 #ifdef TE_WINCE
17621 /* When handling fixups immediately, because we have already
17622 discovered the value of a symbol, or the address of the frag involved
17623 we must account for the offset by +8, as the OS loader will never see the reloc.
17624 see fixup_segment() in write.c
17625 The S_IS_EXTERNAL test handles the case of global symbols.
17626 Those need the calculated base, not just the pipe compensation the linker will need. */
17627 if (fixP->fx_pcrel
17628 && fixP->fx_addsy != NULL
17629 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17630 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17631 return base + 8;
17632 return base;
17633 #else
17634 return base + 8;
17635 #endif
17637 /* ARM mode loads relative to PC are also offset by +8. Unlike
17638 branches, the Windows CE loader *does* expect the relocation
17639 to take this into account. */
17640 case BFD_RELOC_ARM_OFFSET_IMM:
17641 case BFD_RELOC_ARM_OFFSET_IMM8:
17642 case BFD_RELOC_ARM_HWLITERAL:
17643 case BFD_RELOC_ARM_LITERAL:
17644 case BFD_RELOC_ARM_CP_OFF_IMM:
17645 return base + 8;
17648 /* Other PC-relative relocations are un-offset. */
17649 default:
17650 return base;
17654 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17655 Otherwise we have no need to default values of symbols. */
17657 symbolS *
17658 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
17660 #ifdef OBJ_ELF
17661 if (name[0] == '_' && name[1] == 'G'
17662 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17664 if (!GOT_symbol)
17666 if (symbol_find (name))
17667 as_bad (_("GOT already in the symbol table"));
17669 GOT_symbol = symbol_new (name, undefined_section,
17670 (valueT) 0, & zero_address_frag);
17673 return GOT_symbol;
17675 #endif
17677 return 0;
17680 /* Subroutine of md_apply_fix. Check to see if an immediate can be
17681 computed as two separate immediate values, added together. We
17682 already know that this value cannot be computed by just one ARM
17683 instruction. */
17685 static unsigned int
17686 validate_immediate_twopart (unsigned int val,
17687 unsigned int * highpart)
17689 unsigned int a;
17690 unsigned int i;
17692 for (i = 0; i < 32; i += 2)
17693 if (((a = rotate_left (val, i)) & 0xff) != 0)
17695 if (a & 0xff00)
17697 if (a & ~ 0xffff)
17698 continue;
17699 * highpart = (a >> 8) | ((i + 24) << 7);
17701 else if (a & 0xff0000)
17703 if (a & 0xff000000)
17704 continue;
17705 * highpart = (a >> 16) | ((i + 16) << 7);
17707 else
17709 assert (a & 0xff000000);
17710 * highpart = (a >> 24) | ((i + 8) << 7);
17713 return (a & 0xff) | (i << 7);
17716 return FAIL;
17719 static int
17720 validate_offset_imm (unsigned int val, int hwse)
17722 if ((hwse && val > 255) || val > 4095)
17723 return FAIL;
17724 return val;
17727 /* Subroutine of md_apply_fix. Do those data_ops which can take a
17728 negative immediate constant by altering the instruction. A bit of
17729 a hack really.
17730 MOV <-> MVN
17731 AND <-> BIC
17732 ADC <-> SBC
17733 by inverting the second operand, and
17734 ADD <-> SUB
17735 CMP <-> CMN
17736 by negating the second operand. */
17738 static int
17739 negate_data_op (unsigned long * instruction,
17740 unsigned long value)
17742 int op, new_inst;
17743 unsigned long negated, inverted;
17745 negated = encode_arm_immediate (-value);
17746 inverted = encode_arm_immediate (~value);
17748 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17749 switch (op)
17751 /* First negates. */
17752 case OPCODE_SUB: /* ADD <-> SUB */
17753 new_inst = OPCODE_ADD;
17754 value = negated;
17755 break;
17757 case OPCODE_ADD:
17758 new_inst = OPCODE_SUB;
17759 value = negated;
17760 break;
17762 case OPCODE_CMP: /* CMP <-> CMN */
17763 new_inst = OPCODE_CMN;
17764 value = negated;
17765 break;
17767 case OPCODE_CMN:
17768 new_inst = OPCODE_CMP;
17769 value = negated;
17770 break;
17772 /* Now Inverted ops. */
17773 case OPCODE_MOV: /* MOV <-> MVN */
17774 new_inst = OPCODE_MVN;
17775 value = inverted;
17776 break;
17778 case OPCODE_MVN:
17779 new_inst = OPCODE_MOV;
17780 value = inverted;
17781 break;
17783 case OPCODE_AND: /* AND <-> BIC */
17784 new_inst = OPCODE_BIC;
17785 value = inverted;
17786 break;
17788 case OPCODE_BIC:
17789 new_inst = OPCODE_AND;
17790 value = inverted;
17791 break;
17793 case OPCODE_ADC: /* ADC <-> SBC */
17794 new_inst = OPCODE_SBC;
17795 value = inverted;
17796 break;
17798 case OPCODE_SBC:
17799 new_inst = OPCODE_ADC;
17800 value = inverted;
17801 break;
17803 /* We cannot do anything. */
17804 default:
17805 return FAIL;
17808 if (value == (unsigned) FAIL)
17809 return FAIL;
17811 *instruction &= OPCODE_MASK;
17812 *instruction |= new_inst << DATA_OP_SHIFT;
17813 return value;
17816 /* Like negate_data_op, but for Thumb-2. */
17818 static unsigned int
17819 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
17821 int op, new_inst;
17822 int rd;
17823 unsigned int negated, inverted;
17825 negated = encode_thumb32_immediate (-value);
17826 inverted = encode_thumb32_immediate (~value);
17828 rd = (*instruction >> 8) & 0xf;
17829 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17830 switch (op)
17832 /* ADD <-> SUB. Includes CMP <-> CMN. */
17833 case T2_OPCODE_SUB:
17834 new_inst = T2_OPCODE_ADD;
17835 value = negated;
17836 break;
17838 case T2_OPCODE_ADD:
17839 new_inst = T2_OPCODE_SUB;
17840 value = negated;
17841 break;
17843 /* ORR <-> ORN. Includes MOV <-> MVN. */
17844 case T2_OPCODE_ORR:
17845 new_inst = T2_OPCODE_ORN;
17846 value = inverted;
17847 break;
17849 case T2_OPCODE_ORN:
17850 new_inst = T2_OPCODE_ORR;
17851 value = inverted;
17852 break;
17854 /* AND <-> BIC. TST has no inverted equivalent. */
17855 case T2_OPCODE_AND:
17856 new_inst = T2_OPCODE_BIC;
17857 if (rd == 15)
17858 value = FAIL;
17859 else
17860 value = inverted;
17861 break;
17863 case T2_OPCODE_BIC:
17864 new_inst = T2_OPCODE_AND;
17865 value = inverted;
17866 break;
17868 /* ADC <-> SBC */
17869 case T2_OPCODE_ADC:
17870 new_inst = T2_OPCODE_SBC;
17871 value = inverted;
17872 break;
17874 case T2_OPCODE_SBC:
17875 new_inst = T2_OPCODE_ADC;
17876 value = inverted;
17877 break;
17879 /* We cannot do anything. */
17880 default:
17881 return FAIL;
17884 if (value == (unsigned int)FAIL)
17885 return FAIL;
17887 *instruction &= T2_OPCODE_MASK;
17888 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17889 return value;
17892 /* Read a 32-bit thumb instruction from buf. */
17893 static unsigned long
17894 get_thumb32_insn (char * buf)
17896 unsigned long insn;
17897 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17898 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17900 return insn;
17904 /* We usually want to set the low bit on the address of thumb function
17905 symbols. In particular .word foo - . should have the low bit set.
17906 Generic code tries to fold the difference of two symbols to
17907 a constant. Prevent this and force a relocation when the first symbols
17908 is a thumb function. */
17910 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17912 if (op == O_subtract
17913 && l->X_op == O_symbol
17914 && r->X_op == O_symbol
17915 && THUMB_IS_FUNC (l->X_add_symbol))
17917 l->X_op = O_subtract;
17918 l->X_op_symbol = r->X_add_symbol;
17919 l->X_add_number -= r->X_add_number;
17920 return 1;
17922 /* Process as normal. */
17923 return 0;
17926 void
17927 md_apply_fix (fixS * fixP,
17928 valueT * valP,
17929 segT seg)
17931 offsetT value = * valP;
17932 offsetT newval;
17933 unsigned int newimm;
17934 unsigned long temp;
17935 int sign;
17936 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
17938 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
17940 /* Note whether this will delete the relocation. */
17942 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17943 fixP->fx_done = 1;
17945 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17946 consistency with the behaviour on 32-bit hosts. Remember value
17947 for emit_reloc. */
17948 value &= 0xffffffff;
17949 value ^= 0x80000000;
17950 value -= 0x80000000;
17952 *valP = value;
17953 fixP->fx_addnumber = value;
17955 /* Same treatment for fixP->fx_offset. */
17956 fixP->fx_offset &= 0xffffffff;
17957 fixP->fx_offset ^= 0x80000000;
17958 fixP->fx_offset -= 0x80000000;
17960 switch (fixP->fx_r_type)
17962 case BFD_RELOC_NONE:
17963 /* This will need to go in the object file. */
17964 fixP->fx_done = 0;
17965 break;
17967 case BFD_RELOC_ARM_IMMEDIATE:
17968 /* We claim that this fixup has been processed here,
17969 even if in fact we generate an error because we do
17970 not have a reloc for it, so tc_gen_reloc will reject it. */
17971 fixP->fx_done = 1;
17973 if (fixP->fx_addsy
17974 && ! S_IS_DEFINED (fixP->fx_addsy))
17976 as_bad_where (fixP->fx_file, fixP->fx_line,
17977 _("undefined symbol %s used as an immediate value"),
17978 S_GET_NAME (fixP->fx_addsy));
17979 break;
17982 newimm = encode_arm_immediate (value);
17983 temp = md_chars_to_number (buf, INSN_SIZE);
17985 /* If the instruction will fail, see if we can fix things up by
17986 changing the opcode. */
17987 if (newimm == (unsigned int) FAIL
17988 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
17990 as_bad_where (fixP->fx_file, fixP->fx_line,
17991 _("invalid constant (%lx) after fixup"),
17992 (unsigned long) value);
17993 break;
17996 newimm |= (temp & 0xfffff000);
17997 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17998 break;
18000 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18002 unsigned int highpart = 0;
18003 unsigned int newinsn = 0xe1a00000; /* nop. */
18005 newimm = encode_arm_immediate (value);
18006 temp = md_chars_to_number (buf, INSN_SIZE);
18008 /* If the instruction will fail, see if we can fix things up by
18009 changing the opcode. */
18010 if (newimm == (unsigned int) FAIL
18011 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18013 /* No ? OK - try using two ADD instructions to generate
18014 the value. */
18015 newimm = validate_immediate_twopart (value, & highpart);
18017 /* Yes - then make sure that the second instruction is
18018 also an add. */
18019 if (newimm != (unsigned int) FAIL)
18020 newinsn = temp;
18021 /* Still No ? Try using a negated value. */
18022 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18023 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18024 /* Otherwise - give up. */
18025 else
18027 as_bad_where (fixP->fx_file, fixP->fx_line,
18028 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18029 (long) value);
18030 break;
18033 /* Replace the first operand in the 2nd instruction (which
18034 is the PC) with the destination register. We have
18035 already added in the PC in the first instruction and we
18036 do not want to do it again. */
18037 newinsn &= ~ 0xf0000;
18038 newinsn |= ((newinsn & 0x0f000) << 4);
18041 newimm |= (temp & 0xfffff000);
18042 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18044 highpart |= (newinsn & 0xfffff000);
18045 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18047 break;
18049 case BFD_RELOC_ARM_OFFSET_IMM:
18050 if (!fixP->fx_done && seg->use_rela_p)
18051 value = 0;
18053 case BFD_RELOC_ARM_LITERAL:
18054 sign = value >= 0;
18056 if (value < 0)
18057 value = - value;
18059 if (validate_offset_imm (value, 0) == FAIL)
18061 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18062 as_bad_where (fixP->fx_file, fixP->fx_line,
18063 _("invalid literal constant: pool needs to be closer"));
18064 else
18065 as_bad_where (fixP->fx_file, fixP->fx_line,
18066 _("bad immediate value for offset (%ld)"),
18067 (long) value);
18068 break;
18071 newval = md_chars_to_number (buf, INSN_SIZE);
18072 newval &= 0xff7ff000;
18073 newval |= value | (sign ? INDEX_UP : 0);
18074 md_number_to_chars (buf, newval, INSN_SIZE);
18075 break;
18077 case BFD_RELOC_ARM_OFFSET_IMM8:
18078 case BFD_RELOC_ARM_HWLITERAL:
18079 sign = value >= 0;
18081 if (value < 0)
18082 value = - value;
18084 if (validate_offset_imm (value, 1) == FAIL)
18086 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18087 as_bad_where (fixP->fx_file, fixP->fx_line,
18088 _("invalid literal constant: pool needs to be closer"));
18089 else
18090 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
18091 (long) value);
18092 break;
18095 newval = md_chars_to_number (buf, INSN_SIZE);
18096 newval &= 0xff7ff0f0;
18097 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18098 md_number_to_chars (buf, newval, INSN_SIZE);
18099 break;
18101 case BFD_RELOC_ARM_T32_OFFSET_U8:
18102 if (value < 0 || value > 1020 || value % 4 != 0)
18103 as_bad_where (fixP->fx_file, fixP->fx_line,
18104 _("bad immediate value for offset (%ld)"), (long) value);
18105 value /= 4;
18107 newval = md_chars_to_number (buf+2, THUMB_SIZE);
18108 newval |= value;
18109 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18110 break;
18112 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18113 /* This is a complicated relocation used for all varieties of Thumb32
18114 load/store instruction with immediate offset:
18116 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18117 *4, optional writeback(W)
18118 (doubleword load/store)
18120 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18121 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18122 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18123 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18124 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18126 Uppercase letters indicate bits that are already encoded at
18127 this point. Lowercase letters are our problem. For the
18128 second block of instructions, the secondary opcode nybble
18129 (bits 8..11) is present, and bit 23 is zero, even if this is
18130 a PC-relative operation. */
18131 newval = md_chars_to_number (buf, THUMB_SIZE);
18132 newval <<= 16;
18133 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
18135 if ((newval & 0xf0000000) == 0xe0000000)
18137 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18138 if (value >= 0)
18139 newval |= (1 << 23);
18140 else
18141 value = -value;
18142 if (value % 4 != 0)
18144 as_bad_where (fixP->fx_file, fixP->fx_line,
18145 _("offset not a multiple of 4"));
18146 break;
18148 value /= 4;
18149 if (value > 0xff)
18151 as_bad_where (fixP->fx_file, fixP->fx_line,
18152 _("offset out of range"));
18153 break;
18155 newval &= ~0xff;
18157 else if ((newval & 0x000f0000) == 0x000f0000)
18159 /* PC-relative, 12-bit offset. */
18160 if (value >= 0)
18161 newval |= (1 << 23);
18162 else
18163 value = -value;
18164 if (value > 0xfff)
18166 as_bad_where (fixP->fx_file, fixP->fx_line,
18167 _("offset out of range"));
18168 break;
18170 newval &= ~0xfff;
18172 else if ((newval & 0x00000100) == 0x00000100)
18174 /* Writeback: 8-bit, +/- offset. */
18175 if (value >= 0)
18176 newval |= (1 << 9);
18177 else
18178 value = -value;
18179 if (value > 0xff)
18181 as_bad_where (fixP->fx_file, fixP->fx_line,
18182 _("offset out of range"));
18183 break;
18185 newval &= ~0xff;
18187 else if ((newval & 0x00000f00) == 0x00000e00)
18189 /* T-instruction: positive 8-bit offset. */
18190 if (value < 0 || value > 0xff)
18192 as_bad_where (fixP->fx_file, fixP->fx_line,
18193 _("offset out of range"));
18194 break;
18196 newval &= ~0xff;
18197 newval |= value;
18199 else
18201 /* Positive 12-bit or negative 8-bit offset. */
18202 int limit;
18203 if (value >= 0)
18205 newval |= (1 << 23);
18206 limit = 0xfff;
18208 else
18210 value = -value;
18211 limit = 0xff;
18213 if (value > limit)
18215 as_bad_where (fixP->fx_file, fixP->fx_line,
18216 _("offset out of range"));
18217 break;
18219 newval &= ~limit;
18222 newval |= value;
18223 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18224 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18225 break;
18227 case BFD_RELOC_ARM_SHIFT_IMM:
18228 newval = md_chars_to_number (buf, INSN_SIZE);
18229 if (((unsigned long) value) > 32
18230 || (value == 32
18231 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18233 as_bad_where (fixP->fx_file, fixP->fx_line,
18234 _("shift expression is too large"));
18235 break;
18238 if (value == 0)
18239 /* Shifts of zero must be done as lsl. */
18240 newval &= ~0x60;
18241 else if (value == 32)
18242 value = 0;
18243 newval &= 0xfffff07f;
18244 newval |= (value & 0x1f) << 7;
18245 md_number_to_chars (buf, newval, INSN_SIZE);
18246 break;
18248 case BFD_RELOC_ARM_T32_IMMEDIATE:
18249 case BFD_RELOC_ARM_T32_ADD_IMM:
18250 case BFD_RELOC_ARM_T32_IMM12:
18251 case BFD_RELOC_ARM_T32_ADD_PC12:
18252 /* We claim that this fixup has been processed here,
18253 even if in fact we generate an error because we do
18254 not have a reloc for it, so tc_gen_reloc will reject it. */
18255 fixP->fx_done = 1;
18257 if (fixP->fx_addsy
18258 && ! S_IS_DEFINED (fixP->fx_addsy))
18260 as_bad_where (fixP->fx_file, fixP->fx_line,
18261 _("undefined symbol %s used as an immediate value"),
18262 S_GET_NAME (fixP->fx_addsy));
18263 break;
18266 newval = md_chars_to_number (buf, THUMB_SIZE);
18267 newval <<= 16;
18268 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
18270 newimm = FAIL;
18271 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18272 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18274 newimm = encode_thumb32_immediate (value);
18275 if (newimm == (unsigned int) FAIL)
18276 newimm = thumb32_negate_data_op (&newval, value);
18278 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18279 && newimm == (unsigned int) FAIL)
18281 /* Turn add/sum into addw/subw. */
18282 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18283 newval = (newval & 0xfeffffff) | 0x02000000;
18285 /* 12 bit immediate for addw/subw. */
18286 if (value < 0)
18288 value = -value;
18289 newval ^= 0x00a00000;
18291 if (value > 0xfff)
18292 newimm = (unsigned int) FAIL;
18293 else
18294 newimm = value;
18297 if (newimm == (unsigned int)FAIL)
18299 as_bad_where (fixP->fx_file, fixP->fx_line,
18300 _("invalid constant (%lx) after fixup"),
18301 (unsigned long) value);
18302 break;
18305 newval |= (newimm & 0x800) << 15;
18306 newval |= (newimm & 0x700) << 4;
18307 newval |= (newimm & 0x0ff);
18309 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18310 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18311 break;
18313 case BFD_RELOC_ARM_SMC:
18314 if (((unsigned long) value) > 0xffff)
18315 as_bad_where (fixP->fx_file, fixP->fx_line,
18316 _("invalid smc expression"));
18317 newval = md_chars_to_number (buf, INSN_SIZE);
18318 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18319 md_number_to_chars (buf, newval, INSN_SIZE);
18320 break;
18322 case BFD_RELOC_ARM_SWI:
18323 if (fixP->tc_fix_data != 0)
18325 if (((unsigned long) value) > 0xff)
18326 as_bad_where (fixP->fx_file, fixP->fx_line,
18327 _("invalid swi expression"));
18328 newval = md_chars_to_number (buf, THUMB_SIZE);
18329 newval |= value;
18330 md_number_to_chars (buf, newval, THUMB_SIZE);
18332 else
18334 if (((unsigned long) value) > 0x00ffffff)
18335 as_bad_where (fixP->fx_file, fixP->fx_line,
18336 _("invalid swi expression"));
18337 newval = md_chars_to_number (buf, INSN_SIZE);
18338 newval |= value;
18339 md_number_to_chars (buf, newval, INSN_SIZE);
18341 break;
18343 case BFD_RELOC_ARM_MULTI:
18344 if (((unsigned long) value) > 0xffff)
18345 as_bad_where (fixP->fx_file, fixP->fx_line,
18346 _("invalid expression in load/store multiple"));
18347 newval = value | md_chars_to_number (buf, INSN_SIZE);
18348 md_number_to_chars (buf, newval, INSN_SIZE);
18349 break;
18351 #ifdef OBJ_ELF
18352 case BFD_RELOC_ARM_PCREL_CALL:
18353 newval = md_chars_to_number (buf, INSN_SIZE);
18354 if ((newval & 0xf0000000) == 0xf0000000)
18355 temp = 1;
18356 else
18357 temp = 3;
18358 goto arm_branch_common;
18360 case BFD_RELOC_ARM_PCREL_JUMP:
18361 case BFD_RELOC_ARM_PLT32:
18362 #endif
18363 case BFD_RELOC_ARM_PCREL_BRANCH:
18364 temp = 3;
18365 goto arm_branch_common;
18367 case BFD_RELOC_ARM_PCREL_BLX:
18368 temp = 1;
18369 arm_branch_common:
18370 /* We are going to store value (shifted right by two) in the
18371 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18372 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18373 also be be clear. */
18374 if (value & temp)
18375 as_bad_where (fixP->fx_file, fixP->fx_line,
18376 _("misaligned branch destination"));
18377 if ((value & (offsetT)0xfe000000) != (offsetT)0
18378 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18379 as_bad_where (fixP->fx_file, fixP->fx_line,
18380 _("branch out of range"));
18382 if (fixP->fx_done || !seg->use_rela_p)
18384 newval = md_chars_to_number (buf, INSN_SIZE);
18385 newval |= (value >> 2) & 0x00ffffff;
18386 /* Set the H bit on BLX instructions. */
18387 if (temp == 1)
18389 if (value & 2)
18390 newval |= 0x01000000;
18391 else
18392 newval &= ~0x01000000;
18394 md_number_to_chars (buf, newval, INSN_SIZE);
18396 break;
18398 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18399 /* CBZ can only branch forward. */
18401 /* Attempts to use CBZ to branch to the next instruction
18402 (which, strictly speaking, are prohibited) will be turned into
18403 no-ops.
18405 FIXME: It may be better to remove the instruction completely and
18406 perform relaxation. */
18407 if (value == -2)
18409 newval = md_chars_to_number (buf, THUMB_SIZE);
18410 newval = 0xbf00; /* NOP encoding T1 */
18411 md_number_to_chars (buf, newval, THUMB_SIZE);
18413 else
18415 if (value & ~0x7e)
18416 as_bad_where (fixP->fx_file, fixP->fx_line,
18417 _("branch out of range"));
18419 if (fixP->fx_done || !seg->use_rela_p)
18421 newval = md_chars_to_number (buf, THUMB_SIZE);
18422 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18423 md_number_to_chars (buf, newval, THUMB_SIZE);
18426 break;
18428 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
18429 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18430 as_bad_where (fixP->fx_file, fixP->fx_line,
18431 _("branch out of range"));
18433 if (fixP->fx_done || !seg->use_rela_p)
18435 newval = md_chars_to_number (buf, THUMB_SIZE);
18436 newval |= (value & 0x1ff) >> 1;
18437 md_number_to_chars (buf, newval, THUMB_SIZE);
18439 break;
18441 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
18442 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18443 as_bad_where (fixP->fx_file, fixP->fx_line,
18444 _("branch out of range"));
18446 if (fixP->fx_done || !seg->use_rela_p)
18448 newval = md_chars_to_number (buf, THUMB_SIZE);
18449 newval |= (value & 0xfff) >> 1;
18450 md_number_to_chars (buf, newval, THUMB_SIZE);
18452 break;
18454 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18455 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18456 as_bad_where (fixP->fx_file, fixP->fx_line,
18457 _("conditional branch out of range"));
18459 if (fixP->fx_done || !seg->use_rela_p)
18461 offsetT newval2;
18462 addressT S, J1, J2, lo, hi;
18464 S = (value & 0x00100000) >> 20;
18465 J2 = (value & 0x00080000) >> 19;
18466 J1 = (value & 0x00040000) >> 18;
18467 hi = (value & 0x0003f000) >> 12;
18468 lo = (value & 0x00000ffe) >> 1;
18470 newval = md_chars_to_number (buf, THUMB_SIZE);
18471 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18472 newval |= (S << 10) | hi;
18473 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18474 md_number_to_chars (buf, newval, THUMB_SIZE);
18475 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18477 break;
18479 case BFD_RELOC_THUMB_PCREL_BLX:
18480 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18481 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18482 as_bad_where (fixP->fx_file, fixP->fx_line,
18483 _("branch out of range"));
18485 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18486 /* For a BLX instruction, make sure that the relocation is rounded up
18487 to a word boundary. This follows the semantics of the instruction
18488 which specifies that bit 1 of the target address will come from bit
18489 1 of the base address. */
18490 value = (value + 1) & ~ 1;
18492 if (fixP->fx_done || !seg->use_rela_p)
18494 offsetT newval2;
18496 newval = md_chars_to_number (buf, THUMB_SIZE);
18497 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18498 newval |= (value & 0x7fffff) >> 12;
18499 newval2 |= (value & 0xfff) >> 1;
18500 md_number_to_chars (buf, newval, THUMB_SIZE);
18501 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18503 break;
18505 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18506 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18507 as_bad_where (fixP->fx_file, fixP->fx_line,
18508 _("branch out of range"));
18510 if (fixP->fx_done || !seg->use_rela_p)
18512 offsetT newval2;
18513 addressT S, I1, I2, lo, hi;
18515 S = (value & 0x01000000) >> 24;
18516 I1 = (value & 0x00800000) >> 23;
18517 I2 = (value & 0x00400000) >> 22;
18518 hi = (value & 0x003ff000) >> 12;
18519 lo = (value & 0x00000ffe) >> 1;
18521 I1 = !(I1 ^ S);
18522 I2 = !(I2 ^ S);
18524 newval = md_chars_to_number (buf, THUMB_SIZE);
18525 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18526 newval |= (S << 10) | hi;
18527 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18528 md_number_to_chars (buf, newval, THUMB_SIZE);
18529 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18531 break;
18533 case BFD_RELOC_8:
18534 if (fixP->fx_done || !seg->use_rela_p)
18535 md_number_to_chars (buf, value, 1);
18536 break;
18538 case BFD_RELOC_16:
18539 if (fixP->fx_done || !seg->use_rela_p)
18540 md_number_to_chars (buf, value, 2);
18541 break;
18543 #ifdef OBJ_ELF
18544 case BFD_RELOC_ARM_TLS_GD32:
18545 case BFD_RELOC_ARM_TLS_LE32:
18546 case BFD_RELOC_ARM_TLS_IE32:
18547 case BFD_RELOC_ARM_TLS_LDM32:
18548 case BFD_RELOC_ARM_TLS_LDO32:
18549 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18550 /* fall through */
18552 case BFD_RELOC_ARM_GOT32:
18553 case BFD_RELOC_ARM_GOTOFF:
18554 case BFD_RELOC_ARM_TARGET2:
18555 if (fixP->fx_done || !seg->use_rela_p)
18556 md_number_to_chars (buf, 0, 4);
18557 break;
18558 #endif
18560 case BFD_RELOC_RVA:
18561 case BFD_RELOC_32:
18562 case BFD_RELOC_ARM_TARGET1:
18563 case BFD_RELOC_ARM_ROSEGREL32:
18564 case BFD_RELOC_ARM_SBREL32:
18565 case BFD_RELOC_32_PCREL:
18566 #ifdef TE_PE
18567 case BFD_RELOC_32_SECREL:
18568 #endif
18569 if (fixP->fx_done || !seg->use_rela_p)
18570 #ifdef TE_WINCE
18571 /* For WinCE we only do this for pcrel fixups. */
18572 if (fixP->fx_done || fixP->fx_pcrel)
18573 #endif
18574 md_number_to_chars (buf, value, 4);
18575 break;
18577 #ifdef OBJ_ELF
18578 case BFD_RELOC_ARM_PREL31:
18579 if (fixP->fx_done || !seg->use_rela_p)
18581 newval = md_chars_to_number (buf, 4) & 0x80000000;
18582 if ((value ^ (value >> 1)) & 0x40000000)
18584 as_bad_where (fixP->fx_file, fixP->fx_line,
18585 _("rel31 relocation overflow"));
18587 newval |= value & 0x7fffffff;
18588 md_number_to_chars (buf, newval, 4);
18590 break;
18591 #endif
18593 case BFD_RELOC_ARM_CP_OFF_IMM:
18594 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
18595 if (value < -1023 || value > 1023 || (value & 3))
18596 as_bad_where (fixP->fx_file, fixP->fx_line,
18597 _("co-processor offset out of range"));
18598 cp_off_common:
18599 sign = value >= 0;
18600 if (value < 0)
18601 value = -value;
18602 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18603 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18604 newval = md_chars_to_number (buf, INSN_SIZE);
18605 else
18606 newval = get_thumb32_insn (buf);
18607 newval &= 0xff7fff00;
18608 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
18609 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18610 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18611 md_number_to_chars (buf, newval, INSN_SIZE);
18612 else
18613 put_thumb32_insn (buf, newval);
18614 break;
18616 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
18617 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
18618 if (value < -255 || value > 255)
18619 as_bad_where (fixP->fx_file, fixP->fx_line,
18620 _("co-processor offset out of range"));
18621 value *= 4;
18622 goto cp_off_common;
18624 case BFD_RELOC_ARM_THUMB_OFFSET:
18625 newval = md_chars_to_number (buf, THUMB_SIZE);
18626 /* Exactly what ranges, and where the offset is inserted depends
18627 on the type of instruction, we can establish this from the
18628 top 4 bits. */
18629 switch (newval >> 12)
18631 case 4: /* PC load. */
18632 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18633 forced to zero for these loads; md_pcrel_from has already
18634 compensated for this. */
18635 if (value & 3)
18636 as_bad_where (fixP->fx_file, fixP->fx_line,
18637 _("invalid offset, target not word aligned (0x%08lX)"),
18638 (((unsigned long) fixP->fx_frag->fr_address
18639 + (unsigned long) fixP->fx_where) & ~3)
18640 + (unsigned long) value);
18642 if (value & ~0x3fc)
18643 as_bad_where (fixP->fx_file, fixP->fx_line,
18644 _("invalid offset, value too big (0x%08lX)"),
18645 (long) value);
18647 newval |= value >> 2;
18648 break;
18650 case 9: /* SP load/store. */
18651 if (value & ~0x3fc)
18652 as_bad_where (fixP->fx_file, fixP->fx_line,
18653 _("invalid offset, value too big (0x%08lX)"),
18654 (long) value);
18655 newval |= value >> 2;
18656 break;
18658 case 6: /* Word load/store. */
18659 if (value & ~0x7c)
18660 as_bad_where (fixP->fx_file, fixP->fx_line,
18661 _("invalid offset, value too big (0x%08lX)"),
18662 (long) value);
18663 newval |= value << 4; /* 6 - 2. */
18664 break;
18666 case 7: /* Byte load/store. */
18667 if (value & ~0x1f)
18668 as_bad_where (fixP->fx_file, fixP->fx_line,
18669 _("invalid offset, value too big (0x%08lX)"),
18670 (long) value);
18671 newval |= value << 6;
18672 break;
18674 case 8: /* Halfword load/store. */
18675 if (value & ~0x3e)
18676 as_bad_where (fixP->fx_file, fixP->fx_line,
18677 _("invalid offset, value too big (0x%08lX)"),
18678 (long) value);
18679 newval |= value << 5; /* 6 - 1. */
18680 break;
18682 default:
18683 as_bad_where (fixP->fx_file, fixP->fx_line,
18684 "Unable to process relocation for thumb opcode: %lx",
18685 (unsigned long) newval);
18686 break;
18688 md_number_to_chars (buf, newval, THUMB_SIZE);
18689 break;
18691 case BFD_RELOC_ARM_THUMB_ADD:
18692 /* This is a complicated relocation, since we use it for all of
18693 the following immediate relocations:
18695 3bit ADD/SUB
18696 8bit ADD/SUB
18697 9bit ADD/SUB SP word-aligned
18698 10bit ADD PC/SP word-aligned
18700 The type of instruction being processed is encoded in the
18701 instruction field:
18703 0x8000 SUB
18704 0x00F0 Rd
18705 0x000F Rs
18707 newval = md_chars_to_number (buf, THUMB_SIZE);
18709 int rd = (newval >> 4) & 0xf;
18710 int rs = newval & 0xf;
18711 int subtract = !!(newval & 0x8000);
18713 /* Check for HI regs, only very restricted cases allowed:
18714 Adjusting SP, and using PC or SP to get an address. */
18715 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18716 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18717 as_bad_where (fixP->fx_file, fixP->fx_line,
18718 _("invalid Hi register with immediate"));
18720 /* If value is negative, choose the opposite instruction. */
18721 if (value < 0)
18723 value = -value;
18724 subtract = !subtract;
18725 if (value < 0)
18726 as_bad_where (fixP->fx_file, fixP->fx_line,
18727 _("immediate value out of range"));
18730 if (rd == REG_SP)
18732 if (value & ~0x1fc)
18733 as_bad_where (fixP->fx_file, fixP->fx_line,
18734 _("invalid immediate for stack address calculation"));
18735 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18736 newval |= value >> 2;
18738 else if (rs == REG_PC || rs == REG_SP)
18740 if (subtract || value & ~0x3fc)
18741 as_bad_where (fixP->fx_file, fixP->fx_line,
18742 _("invalid immediate for address calculation (value = 0x%08lX)"),
18743 (unsigned long) value);
18744 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18745 newval |= rd << 8;
18746 newval |= value >> 2;
18748 else if (rs == rd)
18750 if (value & ~0xff)
18751 as_bad_where (fixP->fx_file, fixP->fx_line,
18752 _("immediate value out of range"));
18753 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18754 newval |= (rd << 8) | value;
18756 else
18758 if (value & ~0x7)
18759 as_bad_where (fixP->fx_file, fixP->fx_line,
18760 _("immediate value out of range"));
18761 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18762 newval |= rd | (rs << 3) | (value << 6);
18765 md_number_to_chars (buf, newval, THUMB_SIZE);
18766 break;
18768 case BFD_RELOC_ARM_THUMB_IMM:
18769 newval = md_chars_to_number (buf, THUMB_SIZE);
18770 if (value < 0 || value > 255)
18771 as_bad_where (fixP->fx_file, fixP->fx_line,
18772 _("invalid immediate: %ld is out of range"),
18773 (long) value);
18774 newval |= value;
18775 md_number_to_chars (buf, newval, THUMB_SIZE);
18776 break;
18778 case BFD_RELOC_ARM_THUMB_SHIFT:
18779 /* 5bit shift value (0..32). LSL cannot take 32. */
18780 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18781 temp = newval & 0xf800;
18782 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18783 as_bad_where (fixP->fx_file, fixP->fx_line,
18784 _("invalid shift value: %ld"), (long) value);
18785 /* Shifts of zero must be encoded as LSL. */
18786 if (value == 0)
18787 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18788 /* Shifts of 32 are encoded as zero. */
18789 else if (value == 32)
18790 value = 0;
18791 newval |= value << 6;
18792 md_number_to_chars (buf, newval, THUMB_SIZE);
18793 break;
18795 case BFD_RELOC_VTABLE_INHERIT:
18796 case BFD_RELOC_VTABLE_ENTRY:
18797 fixP->fx_done = 0;
18798 return;
18800 case BFD_RELOC_ARM_MOVW:
18801 case BFD_RELOC_ARM_MOVT:
18802 case BFD_RELOC_ARM_THUMB_MOVW:
18803 case BFD_RELOC_ARM_THUMB_MOVT:
18804 if (fixP->fx_done || !seg->use_rela_p)
18806 /* REL format relocations are limited to a 16-bit addend. */
18807 if (!fixP->fx_done)
18809 if (value < -0x8000 || value > 0x7fff)
18810 as_bad_where (fixP->fx_file, fixP->fx_line,
18811 _("offset out of range"));
18813 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18814 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18816 value >>= 16;
18819 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18820 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18822 newval = get_thumb32_insn (buf);
18823 newval &= 0xfbf08f00;
18824 newval |= (value & 0xf000) << 4;
18825 newval |= (value & 0x0800) << 15;
18826 newval |= (value & 0x0700) << 4;
18827 newval |= (value & 0x00ff);
18828 put_thumb32_insn (buf, newval);
18830 else
18832 newval = md_chars_to_number (buf, 4);
18833 newval &= 0xfff0f000;
18834 newval |= value & 0x0fff;
18835 newval |= (value & 0xf000) << 4;
18836 md_number_to_chars (buf, newval, 4);
18839 return;
18841 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18842 case BFD_RELOC_ARM_ALU_PC_G0:
18843 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18844 case BFD_RELOC_ARM_ALU_PC_G1:
18845 case BFD_RELOC_ARM_ALU_PC_G2:
18846 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18847 case BFD_RELOC_ARM_ALU_SB_G0:
18848 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18849 case BFD_RELOC_ARM_ALU_SB_G1:
18850 case BFD_RELOC_ARM_ALU_SB_G2:
18851 assert (!fixP->fx_done);
18852 if (!seg->use_rela_p)
18854 bfd_vma insn;
18855 bfd_vma encoded_addend;
18856 bfd_vma addend_abs = abs (value);
18858 /* Check that the absolute value of the addend can be
18859 expressed as an 8-bit constant plus a rotation. */
18860 encoded_addend = encode_arm_immediate (addend_abs);
18861 if (encoded_addend == (unsigned int) FAIL)
18862 as_bad_where (fixP->fx_file, fixP->fx_line,
18863 _("the offset 0x%08lX is not representable"),
18864 (unsigned long) addend_abs);
18866 /* Extract the instruction. */
18867 insn = md_chars_to_number (buf, INSN_SIZE);
18869 /* If the addend is positive, use an ADD instruction.
18870 Otherwise use a SUB. Take care not to destroy the S bit. */
18871 insn &= 0xff1fffff;
18872 if (value < 0)
18873 insn |= 1 << 22;
18874 else
18875 insn |= 1 << 23;
18877 /* Place the encoded addend into the first 12 bits of the
18878 instruction. */
18879 insn &= 0xfffff000;
18880 insn |= encoded_addend;
18882 /* Update the instruction. */
18883 md_number_to_chars (buf, insn, INSN_SIZE);
18885 break;
18887 case BFD_RELOC_ARM_LDR_PC_G0:
18888 case BFD_RELOC_ARM_LDR_PC_G1:
18889 case BFD_RELOC_ARM_LDR_PC_G2:
18890 case BFD_RELOC_ARM_LDR_SB_G0:
18891 case BFD_RELOC_ARM_LDR_SB_G1:
18892 case BFD_RELOC_ARM_LDR_SB_G2:
18893 assert (!fixP->fx_done);
18894 if (!seg->use_rela_p)
18896 bfd_vma insn;
18897 bfd_vma addend_abs = abs (value);
18899 /* Check that the absolute value of the addend can be
18900 encoded in 12 bits. */
18901 if (addend_abs >= 0x1000)
18902 as_bad_where (fixP->fx_file, fixP->fx_line,
18903 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18904 (unsigned long) addend_abs);
18906 /* Extract the instruction. */
18907 insn = md_chars_to_number (buf, INSN_SIZE);
18909 /* If the addend is negative, clear bit 23 of the instruction.
18910 Otherwise set it. */
18911 if (value < 0)
18912 insn &= ~(1 << 23);
18913 else
18914 insn |= 1 << 23;
18916 /* Place the absolute value of the addend into the first 12 bits
18917 of the instruction. */
18918 insn &= 0xfffff000;
18919 insn |= addend_abs;
18921 /* Update the instruction. */
18922 md_number_to_chars (buf, insn, INSN_SIZE);
18924 break;
18926 case BFD_RELOC_ARM_LDRS_PC_G0:
18927 case BFD_RELOC_ARM_LDRS_PC_G1:
18928 case BFD_RELOC_ARM_LDRS_PC_G2:
18929 case BFD_RELOC_ARM_LDRS_SB_G0:
18930 case BFD_RELOC_ARM_LDRS_SB_G1:
18931 case BFD_RELOC_ARM_LDRS_SB_G2:
18932 assert (!fixP->fx_done);
18933 if (!seg->use_rela_p)
18935 bfd_vma insn;
18936 bfd_vma addend_abs = abs (value);
18938 /* Check that the absolute value of the addend can be
18939 encoded in 8 bits. */
18940 if (addend_abs >= 0x100)
18941 as_bad_where (fixP->fx_file, fixP->fx_line,
18942 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18943 (unsigned long) addend_abs);
18945 /* Extract the instruction. */
18946 insn = md_chars_to_number (buf, INSN_SIZE);
18948 /* If the addend is negative, clear bit 23 of the instruction.
18949 Otherwise set it. */
18950 if (value < 0)
18951 insn &= ~(1 << 23);
18952 else
18953 insn |= 1 << 23;
18955 /* Place the first four bits of the absolute value of the addend
18956 into the first 4 bits of the instruction, and the remaining
18957 four into bits 8 .. 11. */
18958 insn &= 0xfffff0f0;
18959 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18961 /* Update the instruction. */
18962 md_number_to_chars (buf, insn, INSN_SIZE);
18964 break;
18966 case BFD_RELOC_ARM_LDC_PC_G0:
18967 case BFD_RELOC_ARM_LDC_PC_G1:
18968 case BFD_RELOC_ARM_LDC_PC_G2:
18969 case BFD_RELOC_ARM_LDC_SB_G0:
18970 case BFD_RELOC_ARM_LDC_SB_G1:
18971 case BFD_RELOC_ARM_LDC_SB_G2:
18972 assert (!fixP->fx_done);
18973 if (!seg->use_rela_p)
18975 bfd_vma insn;
18976 bfd_vma addend_abs = abs (value);
18978 /* Check that the absolute value of the addend is a multiple of
18979 four and, when divided by four, fits in 8 bits. */
18980 if (addend_abs & 0x3)
18981 as_bad_where (fixP->fx_file, fixP->fx_line,
18982 _("bad offset 0x%08lX (must be word-aligned)"),
18983 (unsigned long) addend_abs);
18985 if ((addend_abs >> 2) > 0xff)
18986 as_bad_where (fixP->fx_file, fixP->fx_line,
18987 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18988 (unsigned long) addend_abs);
18990 /* Extract the instruction. */
18991 insn = md_chars_to_number (buf, INSN_SIZE);
18993 /* If the addend is negative, clear bit 23 of the instruction.
18994 Otherwise set it. */
18995 if (value < 0)
18996 insn &= ~(1 << 23);
18997 else
18998 insn |= 1 << 23;
19000 /* Place the addend (divided by four) into the first eight
19001 bits of the instruction. */
19002 insn &= 0xfffffff0;
19003 insn |= addend_abs >> 2;
19005 /* Update the instruction. */
19006 md_number_to_chars (buf, insn, INSN_SIZE);
19008 break;
19010 case BFD_RELOC_ARM_V4BX:
19011 /* This will need to go in the object file. */
19012 fixP->fx_done = 0;
19013 break;
19015 case BFD_RELOC_UNUSED:
19016 default:
19017 as_bad_where (fixP->fx_file, fixP->fx_line,
19018 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19022 /* Translate internal representation of relocation info to BFD target
19023 format. */
19025 arelent *
19026 tc_gen_reloc (asection *section, fixS *fixp)
19028 arelent * reloc;
19029 bfd_reloc_code_real_type code;
19031 reloc = xmalloc (sizeof (arelent));
19033 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19034 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19035 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
19037 if (fixp->fx_pcrel)
19039 if (section->use_rela_p)
19040 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19041 else
19042 fixp->fx_offset = reloc->address;
19044 reloc->addend = fixp->fx_offset;
19046 switch (fixp->fx_r_type)
19048 case BFD_RELOC_8:
19049 if (fixp->fx_pcrel)
19051 code = BFD_RELOC_8_PCREL;
19052 break;
19055 case BFD_RELOC_16:
19056 if (fixp->fx_pcrel)
19058 code = BFD_RELOC_16_PCREL;
19059 break;
19062 case BFD_RELOC_32:
19063 if (fixp->fx_pcrel)
19065 code = BFD_RELOC_32_PCREL;
19066 break;
19069 case BFD_RELOC_ARM_MOVW:
19070 if (fixp->fx_pcrel)
19072 code = BFD_RELOC_ARM_MOVW_PCREL;
19073 break;
19076 case BFD_RELOC_ARM_MOVT:
19077 if (fixp->fx_pcrel)
19079 code = BFD_RELOC_ARM_MOVT_PCREL;
19080 break;
19083 case BFD_RELOC_ARM_THUMB_MOVW:
19084 if (fixp->fx_pcrel)
19086 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19087 break;
19090 case BFD_RELOC_ARM_THUMB_MOVT:
19091 if (fixp->fx_pcrel)
19093 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19094 break;
19097 case BFD_RELOC_NONE:
19098 case BFD_RELOC_ARM_PCREL_BRANCH:
19099 case BFD_RELOC_ARM_PCREL_BLX:
19100 case BFD_RELOC_RVA:
19101 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19102 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19103 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19104 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19105 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19106 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19107 case BFD_RELOC_THUMB_PCREL_BLX:
19108 case BFD_RELOC_VTABLE_ENTRY:
19109 case BFD_RELOC_VTABLE_INHERIT:
19110 #ifdef TE_PE
19111 case BFD_RELOC_32_SECREL:
19112 #endif
19113 code = fixp->fx_r_type;
19114 break;
19116 case BFD_RELOC_ARM_LITERAL:
19117 case BFD_RELOC_ARM_HWLITERAL:
19118 /* If this is called then the a literal has
19119 been referenced across a section boundary. */
19120 as_bad_where (fixp->fx_file, fixp->fx_line,
19121 _("literal referenced across section boundary"));
19122 return NULL;
19124 #ifdef OBJ_ELF
19125 case BFD_RELOC_ARM_GOT32:
19126 case BFD_RELOC_ARM_GOTOFF:
19127 case BFD_RELOC_ARM_PLT32:
19128 case BFD_RELOC_ARM_TARGET1:
19129 case BFD_RELOC_ARM_ROSEGREL32:
19130 case BFD_RELOC_ARM_SBREL32:
19131 case BFD_RELOC_ARM_PREL31:
19132 case BFD_RELOC_ARM_TARGET2:
19133 case BFD_RELOC_ARM_TLS_LE32:
19134 case BFD_RELOC_ARM_TLS_LDO32:
19135 case BFD_RELOC_ARM_PCREL_CALL:
19136 case BFD_RELOC_ARM_PCREL_JUMP:
19137 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19138 case BFD_RELOC_ARM_ALU_PC_G0:
19139 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19140 case BFD_RELOC_ARM_ALU_PC_G1:
19141 case BFD_RELOC_ARM_ALU_PC_G2:
19142 case BFD_RELOC_ARM_LDR_PC_G0:
19143 case BFD_RELOC_ARM_LDR_PC_G1:
19144 case BFD_RELOC_ARM_LDR_PC_G2:
19145 case BFD_RELOC_ARM_LDRS_PC_G0:
19146 case BFD_RELOC_ARM_LDRS_PC_G1:
19147 case BFD_RELOC_ARM_LDRS_PC_G2:
19148 case BFD_RELOC_ARM_LDC_PC_G0:
19149 case BFD_RELOC_ARM_LDC_PC_G1:
19150 case BFD_RELOC_ARM_LDC_PC_G2:
19151 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19152 case BFD_RELOC_ARM_ALU_SB_G0:
19153 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19154 case BFD_RELOC_ARM_ALU_SB_G1:
19155 case BFD_RELOC_ARM_ALU_SB_G2:
19156 case BFD_RELOC_ARM_LDR_SB_G0:
19157 case BFD_RELOC_ARM_LDR_SB_G1:
19158 case BFD_RELOC_ARM_LDR_SB_G2:
19159 case BFD_RELOC_ARM_LDRS_SB_G0:
19160 case BFD_RELOC_ARM_LDRS_SB_G1:
19161 case BFD_RELOC_ARM_LDRS_SB_G2:
19162 case BFD_RELOC_ARM_LDC_SB_G0:
19163 case BFD_RELOC_ARM_LDC_SB_G1:
19164 case BFD_RELOC_ARM_LDC_SB_G2:
19165 case BFD_RELOC_ARM_V4BX:
19166 code = fixp->fx_r_type;
19167 break;
19169 case BFD_RELOC_ARM_TLS_GD32:
19170 case BFD_RELOC_ARM_TLS_IE32:
19171 case BFD_RELOC_ARM_TLS_LDM32:
19172 /* BFD will include the symbol's address in the addend.
19173 But we don't want that, so subtract it out again here. */
19174 if (!S_IS_COMMON (fixp->fx_addsy))
19175 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19176 code = fixp->fx_r_type;
19177 break;
19178 #endif
19180 case BFD_RELOC_ARM_IMMEDIATE:
19181 as_bad_where (fixp->fx_file, fixp->fx_line,
19182 _("internal relocation (type: IMMEDIATE) not fixed up"));
19183 return NULL;
19185 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19186 as_bad_where (fixp->fx_file, fixp->fx_line,
19187 _("ADRL used for a symbol not defined in the same file"));
19188 return NULL;
19190 case BFD_RELOC_ARM_OFFSET_IMM:
19191 if (section->use_rela_p)
19193 code = fixp->fx_r_type;
19194 break;
19197 if (fixp->fx_addsy != NULL
19198 && !S_IS_DEFINED (fixp->fx_addsy)
19199 && S_IS_LOCAL (fixp->fx_addsy))
19201 as_bad_where (fixp->fx_file, fixp->fx_line,
19202 _("undefined local label `%s'"),
19203 S_GET_NAME (fixp->fx_addsy));
19204 return NULL;
19207 as_bad_where (fixp->fx_file, fixp->fx_line,
19208 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19209 return NULL;
19211 default:
19213 char * type;
19215 switch (fixp->fx_r_type)
19217 case BFD_RELOC_NONE: type = "NONE"; break;
19218 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19219 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
19220 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
19221 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19222 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19223 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
19224 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
19225 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19226 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19227 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19228 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19229 default: type = _("<unknown>"); break;
19231 as_bad_where (fixp->fx_file, fixp->fx_line,
19232 _("cannot represent %s relocation in this object file format"),
19233 type);
19234 return NULL;
19238 #ifdef OBJ_ELF
19239 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19240 && GOT_symbol
19241 && fixp->fx_addsy == GOT_symbol)
19243 code = BFD_RELOC_ARM_GOTPC;
19244 reloc->addend = fixp->fx_offset = reloc->address;
19246 #endif
19248 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
19250 if (reloc->howto == NULL)
19252 as_bad_where (fixp->fx_file, fixp->fx_line,
19253 _("cannot represent %s relocation in this object file format"),
19254 bfd_get_reloc_code_name (code));
19255 return NULL;
19258 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19259 vtable entry to be used in the relocation's section offset. */
19260 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19261 reloc->address = fixp->fx_offset;
19263 return reloc;
19266 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
19268 void
19269 cons_fix_new_arm (fragS * frag,
19270 int where,
19271 int size,
19272 expressionS * exp)
19274 bfd_reloc_code_real_type type;
19275 int pcrel = 0;
19277 /* Pick a reloc.
19278 FIXME: @@ Should look at CPU word size. */
19279 switch (size)
19281 case 1:
19282 type = BFD_RELOC_8;
19283 break;
19284 case 2:
19285 type = BFD_RELOC_16;
19286 break;
19287 case 4:
19288 default:
19289 type = BFD_RELOC_32;
19290 break;
19291 case 8:
19292 type = BFD_RELOC_64;
19293 break;
19296 #ifdef TE_PE
19297 if (exp->X_op == O_secrel)
19299 exp->X_op = O_symbol;
19300 type = BFD_RELOC_32_SECREL;
19302 #endif
19304 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19307 #if defined OBJ_COFF || defined OBJ_ELF
19308 void
19309 arm_validate_fix (fixS * fixP)
19311 /* If the destination of the branch is a defined symbol which does not have
19312 the THUMB_FUNC attribute, then we must be calling a function which has
19313 the (interfacearm) attribute. We look for the Thumb entry point to that
19314 function and change the branch to refer to that function instead. */
19315 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19316 && fixP->fx_addsy != NULL
19317 && S_IS_DEFINED (fixP->fx_addsy)
19318 && ! THUMB_IS_FUNC (fixP->fx_addsy))
19320 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
19323 #endif
19326 arm_force_relocation (struct fix * fixp)
19328 #if defined (OBJ_COFF) && defined (TE_PE)
19329 if (fixp->fx_r_type == BFD_RELOC_RVA)
19330 return 1;
19331 #endif
19333 /* Resolve these relocations even if the symbol is extern or weak. */
19334 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19335 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
19336 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
19337 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
19338 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19339 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19340 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
19341 return 0;
19343 /* Always leave these relocations for the linker. */
19344 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19345 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19346 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19347 return 1;
19349 /* Always generate relocations against function symbols. */
19350 if (fixp->fx_r_type == BFD_RELOC_32
19351 && fixp->fx_addsy
19352 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19353 return 1;
19355 return generic_force_reloc (fixp);
19358 #if defined (OBJ_ELF) || defined (OBJ_COFF)
19359 /* Relocations against function names must be left unadjusted,
19360 so that the linker can use this information to generate interworking
19361 stubs. The MIPS version of this function
19362 also prevents relocations that are mips-16 specific, but I do not
19363 know why it does this.
19365 FIXME:
19366 There is one other problem that ought to be addressed here, but
19367 which currently is not: Taking the address of a label (rather
19368 than a function) and then later jumping to that address. Such
19369 addresses also ought to have their bottom bit set (assuming that
19370 they reside in Thumb code), but at the moment they will not. */
19372 bfd_boolean
19373 arm_fix_adjustable (fixS * fixP)
19375 if (fixP->fx_addsy == NULL)
19376 return 1;
19378 /* Preserve relocations against symbols with function type. */
19379 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19380 return 0;
19382 if (THUMB_IS_FUNC (fixP->fx_addsy)
19383 && fixP->fx_subsy == NULL)
19384 return 0;
19386 /* We need the symbol name for the VTABLE entries. */
19387 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19388 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19389 return 0;
19391 /* Don't allow symbols to be discarded on GOT related relocs. */
19392 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19393 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19394 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19395 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19396 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19397 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19398 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19399 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19400 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19401 return 0;
19403 /* Similarly for group relocations. */
19404 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19405 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19406 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19407 return 0;
19409 return 1;
19411 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19413 #ifdef OBJ_ELF
19415 const char *
19416 elf32_arm_target_format (void)
19418 #ifdef TE_SYMBIAN
19419 return (target_big_endian
19420 ? "elf32-bigarm-symbian"
19421 : "elf32-littlearm-symbian");
19422 #elif defined (TE_VXWORKS)
19423 return (target_big_endian
19424 ? "elf32-bigarm-vxworks"
19425 : "elf32-littlearm-vxworks");
19426 #else
19427 if (target_big_endian)
19428 return "elf32-bigarm";
19429 else
19430 return "elf32-littlearm";
19431 #endif
19434 void
19435 armelf_frob_symbol (symbolS * symp,
19436 int * puntp)
19438 elf_frob_symbol (symp, puntp);
19440 #endif
19442 /* MD interface: Finalization. */
19444 /* A good place to do this, although this was probably not intended
19445 for this kind of use. We need to dump the literal pool before
19446 references are made to a null symbol pointer. */
19448 void
19449 arm_cleanup (void)
19451 literal_pool * pool;
19453 for (pool = list_of_pools; pool; pool = pool->next)
19455 /* Put it at the end of the relevant section. */
19456 subseg_set (pool->section, pool->sub_section);
19457 #ifdef OBJ_ELF
19458 arm_elf_change_section ();
19459 #endif
19460 s_ltorg (0);
19464 /* Adjust the symbol table. This marks Thumb symbols as distinct from
19465 ARM ones. */
19467 void
19468 arm_adjust_symtab (void)
19470 #ifdef OBJ_COFF
19471 symbolS * sym;
19473 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19475 if (ARM_IS_THUMB (sym))
19477 if (THUMB_IS_FUNC (sym))
19479 /* Mark the symbol as a Thumb function. */
19480 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19481 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19482 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
19484 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19485 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19486 else
19487 as_bad (_("%s: unexpected function type: %d"),
19488 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19490 else switch (S_GET_STORAGE_CLASS (sym))
19492 case C_EXT:
19493 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19494 break;
19495 case C_STAT:
19496 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19497 break;
19498 case C_LABEL:
19499 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19500 break;
19501 default:
19502 /* Do nothing. */
19503 break;
19507 if (ARM_IS_INTERWORK (sym))
19508 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
19510 #endif
19511 #ifdef OBJ_ELF
19512 symbolS * sym;
19513 char bind;
19515 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19517 if (ARM_IS_THUMB (sym))
19519 elf_symbol_type * elf_sym;
19521 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19522 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
19524 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19525 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
19527 /* If it's a .thumb_func, declare it as so,
19528 otherwise tag label as .code 16. */
19529 if (THUMB_IS_FUNC (sym))
19530 elf_sym->internal_elf_sym.st_info =
19531 ELF_ST_INFO (bind, STT_ARM_TFUNC);
19532 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
19533 elf_sym->internal_elf_sym.st_info =
19534 ELF_ST_INFO (bind, STT_ARM_16BIT);
19538 #endif
19541 /* MD interface: Initialization. */
19543 static void
19544 set_constant_flonums (void)
19546 int i;
19548 for (i = 0; i < NUM_FLOAT_VALS; i++)
19549 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19550 abort ();
19553 /* Auto-select Thumb mode if it's the only available instruction set for the
19554 given architecture. */
19556 static void
19557 autoselect_thumb_from_cpu_variant (void)
19559 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19560 opcode_select (16);
19563 void
19564 md_begin (void)
19566 unsigned mach;
19567 unsigned int i;
19569 if ( (arm_ops_hsh = hash_new ()) == NULL
19570 || (arm_cond_hsh = hash_new ()) == NULL
19571 || (arm_shift_hsh = hash_new ()) == NULL
19572 || (arm_psr_hsh = hash_new ()) == NULL
19573 || (arm_v7m_psr_hsh = hash_new ()) == NULL
19574 || (arm_reg_hsh = hash_new ()) == NULL
19575 || (arm_reloc_hsh = hash_new ()) == NULL
19576 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
19577 as_fatal (_("virtual memory exhausted"));
19579 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19580 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19581 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19582 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19583 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19584 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19585 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19586 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
19587 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19588 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
19589 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19590 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
19591 for (i = 0;
19592 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19593 i++)
19594 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19595 (PTR) (barrier_opt_names + i));
19596 #ifdef OBJ_ELF
19597 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19598 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19599 #endif
19601 set_constant_flonums ();
19603 /* Set the cpu variant based on the command-line options. We prefer
19604 -mcpu= over -march= if both are set (as for GCC); and we prefer
19605 -mfpu= over any other way of setting the floating point unit.
19606 Use of legacy options with new options are faulted. */
19607 if (legacy_cpu)
19609 if (mcpu_cpu_opt || march_cpu_opt)
19610 as_bad (_("use of old and new-style options to set CPU type"));
19612 mcpu_cpu_opt = legacy_cpu;
19614 else if (!mcpu_cpu_opt)
19615 mcpu_cpu_opt = march_cpu_opt;
19617 if (legacy_fpu)
19619 if (mfpu_opt)
19620 as_bad (_("use of old and new-style options to set FPU type"));
19622 mfpu_opt = legacy_fpu;
19624 else if (!mfpu_opt)
19626 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
19627 /* Some environments specify a default FPU. If they don't, infer it
19628 from the processor. */
19629 if (mcpu_fpu_opt)
19630 mfpu_opt = mcpu_fpu_opt;
19631 else
19632 mfpu_opt = march_fpu_opt;
19633 #else
19634 mfpu_opt = &fpu_default;
19635 #endif
19638 if (!mfpu_opt)
19640 if (mcpu_cpu_opt != NULL)
19641 mfpu_opt = &fpu_default;
19642 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
19643 mfpu_opt = &fpu_arch_vfp_v2;
19644 else
19645 mfpu_opt = &fpu_arch_fpa;
19648 #ifdef CPU_DEFAULT
19649 if (!mcpu_cpu_opt)
19651 mcpu_cpu_opt = &cpu_default;
19652 selected_cpu = cpu_default;
19654 #else
19655 if (mcpu_cpu_opt)
19656 selected_cpu = *mcpu_cpu_opt;
19657 else
19658 mcpu_cpu_opt = &arm_arch_any;
19659 #endif
19661 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
19663 autoselect_thumb_from_cpu_variant ();
19665 arm_arch_used = thumb_arch_used = arm_arch_none;
19667 #if defined OBJ_COFF || defined OBJ_ELF
19669 unsigned int flags = 0;
19671 #if defined OBJ_ELF
19672 flags = meabi_flags;
19674 switch (meabi_flags)
19676 case EF_ARM_EABI_UNKNOWN:
19677 #endif
19678 /* Set the flags in the private structure. */
19679 if (uses_apcs_26) flags |= F_APCS26;
19680 if (support_interwork) flags |= F_INTERWORK;
19681 if (uses_apcs_float) flags |= F_APCS_FLOAT;
19682 if (pic_code) flags |= F_PIC;
19683 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
19684 flags |= F_SOFT_FLOAT;
19686 switch (mfloat_abi_opt)
19688 case ARM_FLOAT_ABI_SOFT:
19689 case ARM_FLOAT_ABI_SOFTFP:
19690 flags |= F_SOFT_FLOAT;
19691 break;
19693 case ARM_FLOAT_ABI_HARD:
19694 if (flags & F_SOFT_FLOAT)
19695 as_bad (_("hard-float conflicts with specified fpu"));
19696 break;
19699 /* Using pure-endian doubles (even if soft-float). */
19700 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
19701 flags |= F_VFP_FLOAT;
19703 #if defined OBJ_ELF
19704 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
19705 flags |= EF_ARM_MAVERICK_FLOAT;
19706 break;
19708 case EF_ARM_EABI_VER4:
19709 case EF_ARM_EABI_VER5:
19710 /* No additional flags to set. */
19711 break;
19713 default:
19714 abort ();
19716 #endif
19717 bfd_set_private_flags (stdoutput, flags);
19719 /* We have run out flags in the COFF header to encode the
19720 status of ATPCS support, so instead we create a dummy,
19721 empty, debug section called .arm.atpcs. */
19722 if (atpcs)
19724 asection * sec;
19726 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19728 if (sec != NULL)
19730 bfd_set_section_flags
19731 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19732 bfd_set_section_size (stdoutput, sec, 0);
19733 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19737 #endif
19739 /* Record the CPU type as well. */
19740 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19741 mach = bfd_mach_arm_iWMMXt2;
19742 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
19743 mach = bfd_mach_arm_iWMMXt;
19744 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
19745 mach = bfd_mach_arm_XScale;
19746 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
19747 mach = bfd_mach_arm_ep9312;
19748 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
19749 mach = bfd_mach_arm_5TE;
19750 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
19752 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19753 mach = bfd_mach_arm_5T;
19754 else
19755 mach = bfd_mach_arm_5;
19757 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
19759 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19760 mach = bfd_mach_arm_4T;
19761 else
19762 mach = bfd_mach_arm_4;
19764 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
19765 mach = bfd_mach_arm_3M;
19766 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19767 mach = bfd_mach_arm_3;
19768 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19769 mach = bfd_mach_arm_2a;
19770 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19771 mach = bfd_mach_arm_2;
19772 else
19773 mach = bfd_mach_arm_unknown;
19775 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19778 /* Command line processing. */
19780 /* md_parse_option
19781 Invocation line includes a switch not recognized by the base assembler.
19782 See if it's a processor-specific option.
19784 This routine is somewhat complicated by the need for backwards
19785 compatibility (since older releases of gcc can't be changed).
19786 The new options try to make the interface as compatible as
19787 possible with GCC.
19789 New options (supported) are:
19791 -mcpu=<cpu name> Assemble for selected processor
19792 -march=<architecture name> Assemble for selected architecture
19793 -mfpu=<fpu architecture> Assemble for selected FPU.
19794 -EB/-mbig-endian Big-endian
19795 -EL/-mlittle-endian Little-endian
19796 -k Generate PIC code
19797 -mthumb Start in Thumb mode
19798 -mthumb-interwork Code supports ARM/Thumb interworking
19800 For now we will also provide support for:
19802 -mapcs-32 32-bit Program counter
19803 -mapcs-26 26-bit Program counter
19804 -macps-float Floats passed in FP registers
19805 -mapcs-reentrant Reentrant code
19806 -matpcs
19807 (sometime these will probably be replaced with -mapcs=<list of options>
19808 and -matpcs=<list of options>)
19810 The remaining options are only supported for back-wards compatibility.
19811 Cpu variants, the arm part is optional:
19812 -m[arm]1 Currently not supported.
19813 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19814 -m[arm]3 Arm 3 processor
19815 -m[arm]6[xx], Arm 6 processors
19816 -m[arm]7[xx][t][[d]m] Arm 7 processors
19817 -m[arm]8[10] Arm 8 processors
19818 -m[arm]9[20][tdmi] Arm 9 processors
19819 -mstrongarm[110[0]] StrongARM processors
19820 -mxscale XScale processors
19821 -m[arm]v[2345[t[e]]] Arm architectures
19822 -mall All (except the ARM1)
19823 FP variants:
19824 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19825 -mfpe-old (No float load/store multiples)
19826 -mvfpxd VFP Single precision
19827 -mvfp All VFP
19828 -mno-fpu Disable all floating point instructions
19830 The following CPU names are recognized:
19831 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19832 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19833 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19834 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19835 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19836 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19837 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
19841 const char * md_shortopts = "m:k";
19843 #ifdef ARM_BI_ENDIAN
19844 #define OPTION_EB (OPTION_MD_BASE + 0)
19845 #define OPTION_EL (OPTION_MD_BASE + 1)
19846 #else
19847 #if TARGET_BYTES_BIG_ENDIAN
19848 #define OPTION_EB (OPTION_MD_BASE + 0)
19849 #else
19850 #define OPTION_EL (OPTION_MD_BASE + 1)
19851 #endif
19852 #endif
19853 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
19855 struct option md_longopts[] =
19857 #ifdef OPTION_EB
19858 {"EB", no_argument, NULL, OPTION_EB},
19859 #endif
19860 #ifdef OPTION_EL
19861 {"EL", no_argument, NULL, OPTION_EL},
19862 #endif
19863 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
19864 {NULL, no_argument, NULL, 0}
19867 size_t md_longopts_size = sizeof (md_longopts);
19869 struct arm_option_table
19871 char *option; /* Option name to match. */
19872 char *help; /* Help information. */
19873 int *var; /* Variable to change. */
19874 int value; /* What to change it to. */
19875 char *deprecated; /* If non-null, print this message. */
19878 struct arm_option_table arm_opts[] =
19880 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19881 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19882 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19883 &support_interwork, 1, NULL},
19884 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19885 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19886 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19887 1, NULL},
19888 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19889 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19890 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19891 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19892 NULL},
19894 /* These are recognized by the assembler, but have no affect on code. */
19895 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19896 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
19897 {NULL, NULL, NULL, 0, NULL}
19900 struct arm_legacy_option_table
19902 char *option; /* Option name to match. */
19903 const arm_feature_set **var; /* Variable to change. */
19904 const arm_feature_set value; /* What to change it to. */
19905 char *deprecated; /* If non-null, print this message. */
19908 const struct arm_legacy_option_table arm_legacy_opts[] =
19910 /* DON'T add any new processors to this list -- we want the whole list
19911 to go away... Add them to the processors table instead. */
19912 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19913 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19914 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19915 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19916 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19917 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19918 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19919 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19920 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19921 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19922 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19923 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19924 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19925 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19926 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19927 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19928 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19929 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19930 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19931 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19932 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19933 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19934 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19935 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19936 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19937 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19938 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19939 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19940 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19941 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19942 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19943 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19944 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19945 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19946 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19947 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19948 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19949 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19950 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19951 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19952 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19953 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19954 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19955 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19956 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19957 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19958 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19959 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19960 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19961 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19962 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19963 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19964 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19965 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19966 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19967 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19968 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19969 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19970 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19971 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19972 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19973 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19974 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19975 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19976 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19977 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19978 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19979 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19980 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19981 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
19982 N_("use -mcpu=strongarm110")},
19983 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
19984 N_("use -mcpu=strongarm1100")},
19985 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
19986 N_("use -mcpu=strongarm1110")},
19987 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19988 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19989 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
19991 /* Architecture variants -- don't add any more to this list either. */
19992 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19993 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19994 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19995 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19996 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19997 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19998 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19999 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20000 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20001 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20002 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20003 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20004 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20005 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20006 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20007 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20008 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20009 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20011 /* Floating point variants -- don't add any more to this list either. */
20012 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20013 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20014 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20015 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
20016 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
20018 {NULL, NULL, ARM_ARCH_NONE, NULL}
20021 struct arm_cpu_option_table
20023 char *name;
20024 const arm_feature_set value;
20025 /* For some CPUs we assume an FPU unless the user explicitly sets
20026 -mfpu=... */
20027 const arm_feature_set default_fpu;
20028 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20029 case. */
20030 const char *canonical_name;
20033 /* This list should, at a minimum, contain all the cpu names
20034 recognized by GCC. */
20035 static const struct arm_cpu_option_table arm_cpus[] =
20037 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20038 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20039 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20040 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20041 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20042 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20043 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20044 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20045 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20046 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20047 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20048 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20049 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20050 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20051 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20052 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20053 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20054 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20055 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20056 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20057 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20058 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20059 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20060 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20061 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20062 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20063 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20064 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20065 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20066 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20067 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20068 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20069 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20070 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20071 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20072 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20073 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20074 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20075 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20076 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20077 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20078 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20079 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20080 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20081 /* For V5 or later processors we default to using VFP; but the user
20082 should really set the FPU type explicitly. */
20083 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20084 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20085 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20086 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20087 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20088 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20089 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20090 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20091 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20092 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20093 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20094 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20095 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20096 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20097 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20098 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20099 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20100 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20101 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20102 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20103 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20104 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20105 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20106 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20107 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20108 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20109 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20110 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20111 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20112 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20113 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
20114 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20115 | FPU_NEON_EXT_V1),
20116 NULL},
20117 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20118 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
20119 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
20120 /* ??? XSCALE is really an architecture. */
20121 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20122 /* ??? iwmmxt is not a processor. */
20123 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
20124 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
20125 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20126 /* Maverick */
20127 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20128 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
20131 struct arm_arch_option_table
20133 char *name;
20134 const arm_feature_set value;
20135 const arm_feature_set default_fpu;
20138 /* This list should, at a minimum, contain all the architecture names
20139 recognized by GCC. */
20140 static const struct arm_arch_option_table arm_archs[] =
20142 {"all", ARM_ANY, FPU_ARCH_FPA},
20143 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20144 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20145 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20146 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20147 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20148 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20149 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20150 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20151 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20152 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20153 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20154 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20155 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20156 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20157 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20158 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20159 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20160 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20161 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20162 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20163 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20164 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20165 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20166 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20167 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
20168 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
20169 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
20170 /* The official spelling of the ARMv7 profile variants is the dashed form.
20171 Accept the non-dashed form for compatibility with old toolchains. */
20172 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20173 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20174 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20175 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20176 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20177 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20178 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20179 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
20180 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
20181 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
20184 /* ISA extensions in the co-processor space. */
20185 struct arm_option_cpu_value_table
20187 char *name;
20188 const arm_feature_set value;
20191 static const struct arm_option_cpu_value_table arm_extensions[] =
20193 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20194 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20195 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
20196 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
20197 {NULL, ARM_ARCH_NONE}
20200 /* This list should, at a minimum, contain all the fpu names
20201 recognized by GCC. */
20202 static const struct arm_option_cpu_value_table arm_fpus[] =
20204 {"softfpa", FPU_NONE},
20205 {"fpe", FPU_ARCH_FPE},
20206 {"fpe2", FPU_ARCH_FPE},
20207 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20208 {"fpa", FPU_ARCH_FPA},
20209 {"fpa10", FPU_ARCH_FPA},
20210 {"fpa11", FPU_ARCH_FPA},
20211 {"arm7500fe", FPU_ARCH_FPA},
20212 {"softvfp", FPU_ARCH_VFP},
20213 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20214 {"vfp", FPU_ARCH_VFP_V2},
20215 {"vfp9", FPU_ARCH_VFP_V2},
20216 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
20217 {"vfp10", FPU_ARCH_VFP_V2},
20218 {"vfp10-r0", FPU_ARCH_VFP_V1},
20219 {"vfpxd", FPU_ARCH_VFP_V1xD},
20220 {"vfpv2", FPU_ARCH_VFP_V2},
20221 {"vfpv3", FPU_ARCH_VFP_V3},
20222 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
20223 {"arm1020t", FPU_ARCH_VFP_V1},
20224 {"arm1020e", FPU_ARCH_VFP_V2},
20225 {"arm1136jfs", FPU_ARCH_VFP_V2},
20226 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20227 {"maverick", FPU_ARCH_MAVERICK},
20228 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
20229 {NULL, ARM_ARCH_NONE}
20232 struct arm_option_value_table
20234 char *name;
20235 long value;
20238 static const struct arm_option_value_table arm_float_abis[] =
20240 {"hard", ARM_FLOAT_ABI_HARD},
20241 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20242 {"soft", ARM_FLOAT_ABI_SOFT},
20243 {NULL, 0}
20246 #ifdef OBJ_ELF
20247 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
20248 static const struct arm_option_value_table arm_eabis[] =
20250 {"gnu", EF_ARM_EABI_UNKNOWN},
20251 {"4", EF_ARM_EABI_VER4},
20252 {"5", EF_ARM_EABI_VER5},
20253 {NULL, 0}
20255 #endif
20257 struct arm_long_option_table
20259 char * option; /* Substring to match. */
20260 char * help; /* Help information. */
20261 int (* func) (char * subopt); /* Function to decode sub-option. */
20262 char * deprecated; /* If non-null, print this message. */
20265 static int
20266 arm_parse_extension (char * str, const arm_feature_set **opt_p)
20268 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20270 /* Copy the feature set, so that we can modify it. */
20271 *ext_set = **opt_p;
20272 *opt_p = ext_set;
20274 while (str != NULL && *str != 0)
20276 const struct arm_option_cpu_value_table * opt;
20277 char * ext;
20278 int optlen;
20280 if (*str != '+')
20282 as_bad (_("invalid architectural extension"));
20283 return 0;
20286 str++;
20287 ext = strchr (str, '+');
20289 if (ext != NULL)
20290 optlen = ext - str;
20291 else
20292 optlen = strlen (str);
20294 if (optlen == 0)
20296 as_bad (_("missing architectural extension"));
20297 return 0;
20300 for (opt = arm_extensions; opt->name != NULL; opt++)
20301 if (strncmp (opt->name, str, optlen) == 0)
20303 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
20304 break;
20307 if (opt->name == NULL)
20309 as_bad (_("unknown architectural extension `%s'"), str);
20310 return 0;
20313 str = ext;
20316 return 1;
20319 static int
20320 arm_parse_cpu (char * str)
20322 const struct arm_cpu_option_table * opt;
20323 char * ext = strchr (str, '+');
20324 int optlen;
20326 if (ext != NULL)
20327 optlen = ext - str;
20328 else
20329 optlen = strlen (str);
20331 if (optlen == 0)
20333 as_bad (_("missing cpu name `%s'"), str);
20334 return 0;
20337 for (opt = arm_cpus; opt->name != NULL; opt++)
20338 if (strncmp (opt->name, str, optlen) == 0)
20340 mcpu_cpu_opt = &opt->value;
20341 mcpu_fpu_opt = &opt->default_fpu;
20342 if (opt->canonical_name)
20343 strcpy (selected_cpu_name, opt->canonical_name);
20344 else
20346 int i;
20347 for (i = 0; i < optlen; i++)
20348 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20349 selected_cpu_name[i] = 0;
20352 if (ext != NULL)
20353 return arm_parse_extension (ext, &mcpu_cpu_opt);
20355 return 1;
20358 as_bad (_("unknown cpu `%s'"), str);
20359 return 0;
20362 static int
20363 arm_parse_arch (char * str)
20365 const struct arm_arch_option_table *opt;
20366 char *ext = strchr (str, '+');
20367 int optlen;
20369 if (ext != NULL)
20370 optlen = ext - str;
20371 else
20372 optlen = strlen (str);
20374 if (optlen == 0)
20376 as_bad (_("missing architecture name `%s'"), str);
20377 return 0;
20380 for (opt = arm_archs; opt->name != NULL; opt++)
20381 if (streq (opt->name, str))
20383 march_cpu_opt = &opt->value;
20384 march_fpu_opt = &opt->default_fpu;
20385 strcpy (selected_cpu_name, opt->name);
20387 if (ext != NULL)
20388 return arm_parse_extension (ext, &march_cpu_opt);
20390 return 1;
20393 as_bad (_("unknown architecture `%s'\n"), str);
20394 return 0;
20397 static int
20398 arm_parse_fpu (char * str)
20400 const struct arm_option_cpu_value_table * opt;
20402 for (opt = arm_fpus; opt->name != NULL; opt++)
20403 if (streq (opt->name, str))
20405 mfpu_opt = &opt->value;
20406 return 1;
20409 as_bad (_("unknown floating point format `%s'\n"), str);
20410 return 0;
20413 static int
20414 arm_parse_float_abi (char * str)
20416 const struct arm_option_value_table * opt;
20418 for (opt = arm_float_abis; opt->name != NULL; opt++)
20419 if (streq (opt->name, str))
20421 mfloat_abi_opt = opt->value;
20422 return 1;
20425 as_bad (_("unknown floating point abi `%s'\n"), str);
20426 return 0;
20429 #ifdef OBJ_ELF
20430 static int
20431 arm_parse_eabi (char * str)
20433 const struct arm_option_value_table *opt;
20435 for (opt = arm_eabis; opt->name != NULL; opt++)
20436 if (streq (opt->name, str))
20438 meabi_flags = opt->value;
20439 return 1;
20441 as_bad (_("unknown EABI `%s'\n"), str);
20442 return 0;
20444 #endif
20446 struct arm_long_option_table arm_long_opts[] =
20448 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20449 arm_parse_cpu, NULL},
20450 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20451 arm_parse_arch, NULL},
20452 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20453 arm_parse_fpu, NULL},
20454 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20455 arm_parse_float_abi, NULL},
20456 #ifdef OBJ_ELF
20457 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20458 arm_parse_eabi, NULL},
20459 #endif
20460 {NULL, NULL, 0, NULL}
20464 md_parse_option (int c, char * arg)
20466 struct arm_option_table *opt;
20467 const struct arm_legacy_option_table *fopt;
20468 struct arm_long_option_table *lopt;
20470 switch (c)
20472 #ifdef OPTION_EB
20473 case OPTION_EB:
20474 target_big_endian = 1;
20475 break;
20476 #endif
20478 #ifdef OPTION_EL
20479 case OPTION_EL:
20480 target_big_endian = 0;
20481 break;
20482 #endif
20484 case OPTION_FIX_V4BX:
20485 fix_v4bx = TRUE;
20486 break;
20488 case 'a':
20489 /* Listing option. Just ignore these, we don't support additional
20490 ones. */
20491 return 0;
20493 default:
20494 for (opt = arm_opts; opt->option != NULL; opt++)
20496 if (c == opt->option[0]
20497 && ((arg == NULL && opt->option[1] == 0)
20498 || streq (arg, opt->option + 1)))
20500 #if WARN_DEPRECATED
20501 /* If the option is deprecated, tell the user. */
20502 if (opt->deprecated != NULL)
20503 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20504 arg ? arg : "", _(opt->deprecated));
20505 #endif
20507 if (opt->var != NULL)
20508 *opt->var = opt->value;
20510 return 1;
20514 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20516 if (c == fopt->option[0]
20517 && ((arg == NULL && fopt->option[1] == 0)
20518 || streq (arg, fopt->option + 1)))
20520 #if WARN_DEPRECATED
20521 /* If the option is deprecated, tell the user. */
20522 if (fopt->deprecated != NULL)
20523 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20524 arg ? arg : "", _(fopt->deprecated));
20525 #endif
20527 if (fopt->var != NULL)
20528 *fopt->var = &fopt->value;
20530 return 1;
20534 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20536 /* These options are expected to have an argument. */
20537 if (c == lopt->option[0]
20538 && arg != NULL
20539 && strncmp (arg, lopt->option + 1,
20540 strlen (lopt->option + 1)) == 0)
20542 #if WARN_DEPRECATED
20543 /* If the option is deprecated, tell the user. */
20544 if (lopt->deprecated != NULL)
20545 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20546 _(lopt->deprecated));
20547 #endif
20549 /* Call the sup-option parser. */
20550 return lopt->func (arg + strlen (lopt->option) - 1);
20554 return 0;
20557 return 1;
20560 void
20561 md_show_usage (FILE * fp)
20563 struct arm_option_table *opt;
20564 struct arm_long_option_table *lopt;
20566 fprintf (fp, _(" ARM-specific assembler options:\n"));
20568 for (opt = arm_opts; opt->option != NULL; opt++)
20569 if (opt->help != NULL)
20570 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
20572 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20573 if (lopt->help != NULL)
20574 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
20576 #ifdef OPTION_EB
20577 fprintf (fp, _("\
20578 -EB assemble code for a big-endian cpu\n"));
20579 #endif
20581 #ifdef OPTION_EL
20582 fprintf (fp, _("\
20583 -EL assemble code for a little-endian cpu\n"));
20584 #endif
20586 fprintf (fp, _("\
20587 --fix-v4bx Allow BX in ARMv4 code\n"));
20591 #ifdef OBJ_ELF
20592 typedef struct
20594 int val;
20595 arm_feature_set flags;
20596 } cpu_arch_ver_table;
20598 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20599 least features first. */
20600 static const cpu_arch_ver_table cpu_arch_ver[] =
20602 {1, ARM_ARCH_V4},
20603 {2, ARM_ARCH_V4T},
20604 {3, ARM_ARCH_V5},
20605 {4, ARM_ARCH_V5TE},
20606 {5, ARM_ARCH_V5TEJ},
20607 {6, ARM_ARCH_V6},
20608 {7, ARM_ARCH_V6Z},
20609 {9, ARM_ARCH_V6K},
20610 {9, ARM_ARCH_V6M},
20611 {8, ARM_ARCH_V6T2},
20612 {10, ARM_ARCH_V7A},
20613 {10, ARM_ARCH_V7R},
20614 {10, ARM_ARCH_V7M},
20615 {0, ARM_ARCH_NONE}
20618 /* Set the public EABI object attributes. */
20619 static void
20620 aeabi_set_public_attributes (void)
20622 int arch;
20623 arm_feature_set flags;
20624 arm_feature_set tmp;
20625 const cpu_arch_ver_table *p;
20627 /* Choose the architecture based on the capabilities of the requested cpu
20628 (if any) and/or the instructions actually used. */
20629 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20630 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20631 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
20632 /*Allow the user to override the reported architecture. */
20633 if (object_arch)
20635 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20636 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20639 tmp = flags;
20640 arch = 0;
20641 for (p = cpu_arch_ver; p->val; p++)
20643 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20645 arch = p->val;
20646 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20650 /* Tag_CPU_name. */
20651 if (selected_cpu_name[0])
20653 char *p;
20655 p = selected_cpu_name;
20656 if (strncmp (p, "armv", 4) == 0)
20658 int i;
20660 p += 4;
20661 for (i = 0; p[i]; i++)
20662 p[i] = TOUPPER (p[i]);
20664 bfd_elf_add_proc_attr_string (stdoutput, 5, p);
20666 /* Tag_CPU_arch. */
20667 bfd_elf_add_proc_attr_int (stdoutput, 6, arch);
20668 /* Tag_CPU_arch_profile. */
20669 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
20670 bfd_elf_add_proc_attr_int (stdoutput, 7, 'A');
20671 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
20672 bfd_elf_add_proc_attr_int (stdoutput, 7, 'R');
20673 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
20674 bfd_elf_add_proc_attr_int (stdoutput, 7, 'M');
20675 /* Tag_ARM_ISA_use. */
20676 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
20677 bfd_elf_add_proc_attr_int (stdoutput, 8, 1);
20678 /* Tag_THUMB_ISA_use. */
20679 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
20680 bfd_elf_add_proc_attr_int (stdoutput, 9,
20681 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
20682 /* Tag_VFP_arch. */
20683 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_d32)
20684 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_d32))
20685 bfd_elf_add_proc_attr_int (stdoutput, 10, 4);
20686 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20687 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
20688 bfd_elf_add_proc_attr_int (stdoutput, 10, 3);
20689 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20690 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
20691 bfd_elf_add_proc_attr_int (stdoutput, 10, 2);
20692 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20693 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20694 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20695 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
20696 bfd_elf_add_proc_attr_int (stdoutput, 10, 1);
20697 /* Tag_WMMX_arch. */
20698 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20699 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
20700 bfd_elf_add_proc_attr_int (stdoutput, 11, 1);
20701 /* Tag_NEON_arch. */
20702 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20703 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20704 bfd_elf_add_proc_attr_int (stdoutput, 12, 1);
20707 /* Add the default contents for the .ARM.attributes section. */
20708 void
20709 arm_md_end (void)
20711 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20712 return;
20714 aeabi_set_public_attributes ();
20716 #endif /* OBJ_ELF */
20719 /* Parse a .cpu directive. */
20721 static void
20722 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20724 const struct arm_cpu_option_table *opt;
20725 char *name;
20726 char saved_char;
20728 name = input_line_pointer;
20729 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20730 input_line_pointer++;
20731 saved_char = *input_line_pointer;
20732 *input_line_pointer = 0;
20734 /* Skip the first "all" entry. */
20735 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20736 if (streq (opt->name, name))
20738 mcpu_cpu_opt = &opt->value;
20739 selected_cpu = opt->value;
20740 if (opt->canonical_name)
20741 strcpy (selected_cpu_name, opt->canonical_name);
20742 else
20744 int i;
20745 for (i = 0; opt->name[i]; i++)
20746 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20747 selected_cpu_name[i] = 0;
20749 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20750 *input_line_pointer = saved_char;
20751 demand_empty_rest_of_line ();
20752 return;
20754 as_bad (_("unknown cpu `%s'"), name);
20755 *input_line_pointer = saved_char;
20756 ignore_rest_of_line ();
20760 /* Parse a .arch directive. */
20762 static void
20763 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20765 const struct arm_arch_option_table *opt;
20766 char saved_char;
20767 char *name;
20769 name = input_line_pointer;
20770 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20771 input_line_pointer++;
20772 saved_char = *input_line_pointer;
20773 *input_line_pointer = 0;
20775 /* Skip the first "all" entry. */
20776 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20777 if (streq (opt->name, name))
20779 mcpu_cpu_opt = &opt->value;
20780 selected_cpu = opt->value;
20781 strcpy (selected_cpu_name, opt->name);
20782 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20783 *input_line_pointer = saved_char;
20784 demand_empty_rest_of_line ();
20785 return;
20788 as_bad (_("unknown architecture `%s'\n"), name);
20789 *input_line_pointer = saved_char;
20790 ignore_rest_of_line ();
20794 /* Parse a .object_arch directive. */
20796 static void
20797 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20799 const struct arm_arch_option_table *opt;
20800 char saved_char;
20801 char *name;
20803 name = input_line_pointer;
20804 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20805 input_line_pointer++;
20806 saved_char = *input_line_pointer;
20807 *input_line_pointer = 0;
20809 /* Skip the first "all" entry. */
20810 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20811 if (streq (opt->name, name))
20813 object_arch = &opt->value;
20814 *input_line_pointer = saved_char;
20815 demand_empty_rest_of_line ();
20816 return;
20819 as_bad (_("unknown architecture `%s'\n"), name);
20820 *input_line_pointer = saved_char;
20821 ignore_rest_of_line ();
20825 /* Parse a .fpu directive. */
20827 static void
20828 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20830 const struct arm_option_cpu_value_table *opt;
20831 char saved_char;
20832 char *name;
20834 name = input_line_pointer;
20835 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20836 input_line_pointer++;
20837 saved_char = *input_line_pointer;
20838 *input_line_pointer = 0;
20840 for (opt = arm_fpus; opt->name != NULL; opt++)
20841 if (streq (opt->name, name))
20843 mfpu_opt = &opt->value;
20844 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20845 *input_line_pointer = saved_char;
20846 demand_empty_rest_of_line ();
20847 return;
20850 as_bad (_("unknown floating point format `%s'\n"), name);
20851 *input_line_pointer = saved_char;
20852 ignore_rest_of_line ();
20855 /* Copy symbol information. */
20856 void
20857 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20859 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);