file bfin-parse.h was initially added on branch binutils-2_17-branch.
[binutils.git] / gas / config / tc-arm.c
blob5af2cd4efbd0a080a1287b31c378c2cfa78c8900
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
11 This file is part of GAS, the GNU Assembler.
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
16 any later version.
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
28 #include <string.h>
29 #define NO_RELOC 0
30 #include "as.h"
31 #include "safe-ctype.h"
33 /* Need TARGET_CPU. */
34 #include "config.h"
35 #include "subsegs.h"
36 #include "obstack.h"
37 #include "symbols.h"
38 #include "listing.h"
40 #include "opcode/arm.h"
42 #ifdef OBJ_ELF
43 #include "elf/arm.h"
44 #include "dwarf2dbg.h"
45 #include "dw2gencfi.h"
46 #endif
48 /* XXX Set this to 1 after the next binutils release. */
49 #define WARN_DEPRECATED 0
51 #ifdef OBJ_ELF
52 /* Must be at least the size of the largest unwind opcode (currently two). */
53 #define ARM_OPCODE_CHUNK_SIZE 8
55 /* This structure holds the unwinding state. */
57 static struct
59 symbolS * proc_start;
60 symbolS * table_entry;
61 symbolS * personality_routine;
62 int personality_index;
63 /* The segment containing the function. */
64 segT saved_seg;
65 subsegT saved_subseg;
66 /* Opcodes generated from this function. */
67 unsigned char * opcodes;
68 int opcode_count;
69 int opcode_alloc;
70 /* The number of bytes pushed to the stack. */
71 offsetT frame_size;
72 /* We don't add stack adjustment opcodes immediately so that we can merge
73 multiple adjustments. We can also omit the final adjustment
74 when using a frame pointer. */
75 offsetT pending_offset;
76 /* These two fields are set by both unwind_movsp and unwind_setfp. They
77 hold the reg+offset to use when restoring sp from a frame pointer. */
78 offsetT fp_offset;
79 int fp_reg;
80 /* Nonzero if an unwind_setfp directive has been seen. */
81 unsigned fp_used:1;
82 /* Nonzero if the last opcode restores sp from fp_reg. */
83 unsigned sp_restored:1;
84 } unwind;
86 /* Bit N indicates that an R_ARM_NONE relocation has been output for
87 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
88 emitted only once per section, to save unnecessary bloat. */
89 static unsigned int marked_pr_dependency = 0;
91 #endif /* OBJ_ELF */
93 enum arm_float_abi
95 ARM_FLOAT_ABI_HARD,
96 ARM_FLOAT_ABI_SOFTFP,
97 ARM_FLOAT_ABI_SOFT
100 /* Types of processor to assemble for. */
101 #ifndef CPU_DEFAULT
102 #if defined __XSCALE__
103 #define CPU_DEFAULT ARM_ARCH_XSCALE
104 #else
105 #if defined __thumb__
106 #define CPU_DEFAULT ARM_ARCH_V5T
107 #endif
108 #endif
109 #endif
111 #ifndef FPU_DEFAULT
112 # ifdef TE_LINUX
113 # define FPU_DEFAULT FPU_ARCH_FPA
114 # elif defined (TE_NetBSD)
115 # ifdef OBJ_ELF
116 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
117 # else
118 /* Legacy a.out format. */
119 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
120 # endif
121 # elif defined (TE_VXWORKS)
122 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
123 # else
124 /* For backwards compatibility, default to FPA. */
125 # define FPU_DEFAULT FPU_ARCH_FPA
126 # endif
127 #endif /* ifndef FPU_DEFAULT */
129 #define streq(a, b) (strcmp (a, b) == 0)
131 static arm_feature_set cpu_variant;
132 static arm_feature_set arm_arch_used;
133 static arm_feature_set thumb_arch_used;
135 /* Flags stored in private area of BFD structure. */
136 static int uses_apcs_26 = FALSE;
137 static int atpcs = FALSE;
138 static int support_interwork = FALSE;
139 static int uses_apcs_float = FALSE;
140 static int pic_code = FALSE;
142 /* Variables that we set while parsing command-line options. Once all
143 options have been read we re-process these values to set the real
144 assembly flags. */
145 static const arm_feature_set *legacy_cpu = NULL;
146 static const arm_feature_set *legacy_fpu = NULL;
148 static const arm_feature_set *mcpu_cpu_opt = NULL;
149 static const arm_feature_set *mcpu_fpu_opt = NULL;
150 static const arm_feature_set *march_cpu_opt = NULL;
151 static const arm_feature_set *march_fpu_opt = NULL;
152 static const arm_feature_set *mfpu_opt = NULL;
154 /* Constants for known architecture features. */
155 static const arm_feature_set fpu_default = FPU_DEFAULT;
156 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
157 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
158 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
159 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
160 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
161 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
163 #ifdef CPU_DEFAULT
164 static const arm_feature_set cpu_default = CPU_DEFAULT;
165 #endif
167 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
168 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
169 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
170 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
171 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
172 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
173 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
174 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
175 static const arm_feature_set arm_ext_v4t_5 =
176 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
177 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
178 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
179 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
180 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
181 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
182 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
183 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
184 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
185 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
186 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
187 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
188 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
189 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
190 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
192 static const arm_feature_set arm_arch_any = ARM_ANY;
193 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
194 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
195 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
197 static const arm_feature_set arm_cext_iwmmxt =
198 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
199 static const arm_feature_set arm_cext_xscale =
200 ARM_FEATURE (0, ARM_CEXT_XSCALE);
201 static const arm_feature_set arm_cext_maverick =
202 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
203 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
204 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
205 static const arm_feature_set fpu_vfp_ext_v1xd =
206 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
207 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
208 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
210 static int mfloat_abi_opt = -1;
211 /* Record user cpu selection for object attributes. */
212 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
213 /* Must be long enough to hold any of the names in arm_cpus. */
214 static char selected_cpu_name[16];
215 #ifdef OBJ_ELF
216 # ifdef EABI_DEFAULT
217 static int meabi_flags = EABI_DEFAULT;
218 # else
219 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
220 # endif
221 #endif
223 #ifdef OBJ_ELF
224 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
225 symbolS * GOT_symbol;
226 #endif
228 /* 0: assemble for ARM,
229 1: assemble for Thumb,
230 2: assemble for Thumb even though target CPU does not support thumb
231 instructions. */
232 static int thumb_mode = 0;
234 /* If unified_syntax is true, we are processing the new unified
235 ARM/Thumb syntax. Important differences from the old ARM mode:
237 - Immediate operands do not require a # prefix.
238 - Conditional affixes always appear at the end of the
239 instruction. (For backward compatibility, those instructions
240 that formerly had them in the middle, continue to accept them
241 there.)
242 - The IT instruction may appear, and if it does is validated
243 against subsequent conditional affixes. It does not generate
244 machine code.
246 Important differences from the old Thumb mode:
248 - Immediate operands do not require a # prefix.
249 - Most of the V6T2 instructions are only available in unified mode.
250 - The .N and .W suffixes are recognized and honored (it is an error
251 if they cannot be honored).
252 - All instructions set the flags if and only if they have an 's' affix.
253 - Conditional affixes may be used. They are validated against
254 preceding IT instructions. Unlike ARM mode, you cannot use a
255 conditional affix except in the scope of an IT instruction. */
257 static bfd_boolean unified_syntax = FALSE;
259 struct arm_it
261 const char * error;
262 unsigned long instruction;
263 int size;
264 int size_req;
265 int cond;
266 /* Set to the opcode if the instruction needs relaxation.
267 Zero if the instruction is not relaxed. */
268 unsigned long relax;
269 struct
271 bfd_reloc_code_real_type type;
272 expressionS exp;
273 int pc_rel;
274 } reloc;
276 struct
278 unsigned reg;
279 signed int imm;
280 unsigned present : 1; /* Operand present. */
281 unsigned isreg : 1; /* Operand was a register. */
282 unsigned immisreg : 1; /* .imm field is a second register. */
283 unsigned hasreloc : 1; /* Operand has relocation suffix. */
284 unsigned writeback : 1; /* Operand has trailing ! */
285 unsigned preind : 1; /* Preindexed address. */
286 unsigned postind : 1; /* Postindexed address. */
287 unsigned negative : 1; /* Index register was negated. */
288 unsigned shifted : 1; /* Shift applied to operation. */
289 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
290 } operands[6];
293 static struct arm_it inst;
295 #define NUM_FLOAT_VALS 8
297 const char * fp_const[] =
299 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
302 /* Number of littlenums required to hold an extended precision number. */
303 #define MAX_LITTLENUMS 6
305 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
307 #define FAIL (-1)
308 #define SUCCESS (0)
310 #define SUFF_S 1
311 #define SUFF_D 2
312 #define SUFF_E 3
313 #define SUFF_P 4
315 #define CP_T_X 0x00008000
316 #define CP_T_Y 0x00400000
318 #define CONDS_BIT 0x00100000
319 #define LOAD_BIT 0x00100000
321 #define DOUBLE_LOAD_FLAG 0x00000001
323 struct asm_cond
325 const char * template;
326 unsigned long value;
329 #define COND_ALWAYS 0xE
331 struct asm_psr
333 const char *template;
334 unsigned long field;
337 struct asm_barrier_opt
339 const char *template;
340 unsigned long value;
343 /* The bit that distinguishes CPSR and SPSR. */
344 #define SPSR_BIT (1 << 22)
346 /* The individual PSR flag bits. */
347 #define PSR_c (1 << 16)
348 #define PSR_x (1 << 17)
349 #define PSR_s (1 << 18)
350 #define PSR_f (1 << 19)
352 struct reloc_entry
354 char *name;
355 bfd_reloc_code_real_type reloc;
358 enum vfp_sp_reg_pos
360 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn
363 enum vfp_ldstm_type
365 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
368 /* ARM register categories. This includes coprocessor numbers and various
369 architecture extensions' registers. */
370 enum arm_reg_type
372 REG_TYPE_RN,
373 REG_TYPE_CP,
374 REG_TYPE_CN,
375 REG_TYPE_FN,
376 REG_TYPE_VFS,
377 REG_TYPE_VFD,
378 REG_TYPE_VFC,
379 REG_TYPE_MVF,
380 REG_TYPE_MVD,
381 REG_TYPE_MVFX,
382 REG_TYPE_MVDX,
383 REG_TYPE_MVAX,
384 REG_TYPE_DSPSC,
385 REG_TYPE_MMXWR,
386 REG_TYPE_MMXWC,
387 REG_TYPE_MMXWCG,
388 REG_TYPE_XSCALE,
391 /* Structure for a hash table entry for a register. */
392 struct reg_entry
394 const char *name;
395 unsigned char number;
396 unsigned char type;
397 unsigned char builtin;
400 /* Diagnostics used when we don't get a register of the expected type. */
401 const char *const reg_expected_msgs[] =
403 N_("ARM register expected"),
404 N_("bad or missing co-processor number"),
405 N_("co-processor register expected"),
406 N_("FPA register expected"),
407 N_("VFP single precision register expected"),
408 N_("VFP double precision register expected"),
409 N_("VFP system register expected"),
410 N_("Maverick MVF register expected"),
411 N_("Maverick MVD register expected"),
412 N_("Maverick MVFX register expected"),
413 N_("Maverick MVDX register expected"),
414 N_("Maverick MVAX register expected"),
415 N_("Maverick DSPSC register expected"),
416 N_("iWMMXt data register expected"),
417 N_("iWMMXt control register expected"),
418 N_("iWMMXt scalar register expected"),
419 N_("XScale accumulator register expected"),
422 /* Some well known registers that we refer to directly elsewhere. */
423 #define REG_SP 13
424 #define REG_LR 14
425 #define REG_PC 15
427 /* ARM instructions take 4bytes in the object file, Thumb instructions
428 take 2: */
429 #define INSN_SIZE 4
431 struct asm_opcode
433 /* Basic string to match. */
434 const char *template;
436 /* Parameters to instruction. */
437 unsigned char operands[8];
439 /* Conditional tag - see opcode_lookup. */
440 unsigned int tag : 4;
442 /* Basic instruction code. */
443 unsigned int avalue : 28;
445 /* Thumb-format instruction code. */
446 unsigned int tvalue;
448 /* Which architecture variant provides this instruction. */
449 const arm_feature_set *avariant;
450 const arm_feature_set *tvariant;
452 /* Function to call to encode instruction in ARM format. */
453 void (* aencode) (void);
455 /* Function to call to encode instruction in Thumb format. */
456 void (* tencode) (void);
459 /* Defines for various bits that we will want to toggle. */
460 #define INST_IMMEDIATE 0x02000000
461 #define OFFSET_REG 0x02000000
462 #define HWOFFSET_IMM 0x00400000
463 #define SHIFT_BY_REG 0x00000010
464 #define PRE_INDEX 0x01000000
465 #define INDEX_UP 0x00800000
466 #define WRITE_BACK 0x00200000
467 #define LDM_TYPE_2_OR_3 0x00400000
469 #define LITERAL_MASK 0xf000f000
470 #define OPCODE_MASK 0xfe1fffff
471 #define V4_STR_BIT 0x00000020
473 #define DATA_OP_SHIFT 21
475 #define T2_OPCODE_MASK 0xfe1fffff
476 #define T2_DATA_OP_SHIFT 21
478 /* Codes to distinguish the arithmetic instructions. */
479 #define OPCODE_AND 0
480 #define OPCODE_EOR 1
481 #define OPCODE_SUB 2
482 #define OPCODE_RSB 3
483 #define OPCODE_ADD 4
484 #define OPCODE_ADC 5
485 #define OPCODE_SBC 6
486 #define OPCODE_RSC 7
487 #define OPCODE_TST 8
488 #define OPCODE_TEQ 9
489 #define OPCODE_CMP 10
490 #define OPCODE_CMN 11
491 #define OPCODE_ORR 12
492 #define OPCODE_MOV 13
493 #define OPCODE_BIC 14
494 #define OPCODE_MVN 15
496 #define T2_OPCODE_AND 0
497 #define T2_OPCODE_BIC 1
498 #define T2_OPCODE_ORR 2
499 #define T2_OPCODE_ORN 3
500 #define T2_OPCODE_EOR 4
501 #define T2_OPCODE_ADD 8
502 #define T2_OPCODE_ADC 10
503 #define T2_OPCODE_SBC 11
504 #define T2_OPCODE_SUB 13
505 #define T2_OPCODE_RSB 14
507 #define T_OPCODE_MUL 0x4340
508 #define T_OPCODE_TST 0x4200
509 #define T_OPCODE_CMN 0x42c0
510 #define T_OPCODE_NEG 0x4240
511 #define T_OPCODE_MVN 0x43c0
513 #define T_OPCODE_ADD_R3 0x1800
514 #define T_OPCODE_SUB_R3 0x1a00
515 #define T_OPCODE_ADD_HI 0x4400
516 #define T_OPCODE_ADD_ST 0xb000
517 #define T_OPCODE_SUB_ST 0xb080
518 #define T_OPCODE_ADD_SP 0xa800
519 #define T_OPCODE_ADD_PC 0xa000
520 #define T_OPCODE_ADD_I8 0x3000
521 #define T_OPCODE_SUB_I8 0x3800
522 #define T_OPCODE_ADD_I3 0x1c00
523 #define T_OPCODE_SUB_I3 0x1e00
525 #define T_OPCODE_ASR_R 0x4100
526 #define T_OPCODE_LSL_R 0x4080
527 #define T_OPCODE_LSR_R 0x40c0
528 #define T_OPCODE_ROR_R 0x41c0
529 #define T_OPCODE_ASR_I 0x1000
530 #define T_OPCODE_LSL_I 0x0000
531 #define T_OPCODE_LSR_I 0x0800
533 #define T_OPCODE_MOV_I8 0x2000
534 #define T_OPCODE_CMP_I8 0x2800
535 #define T_OPCODE_CMP_LR 0x4280
536 #define T_OPCODE_MOV_HR 0x4600
537 #define T_OPCODE_CMP_HR 0x4500
539 #define T_OPCODE_LDR_PC 0x4800
540 #define T_OPCODE_LDR_SP 0x9800
541 #define T_OPCODE_STR_SP 0x9000
542 #define T_OPCODE_LDR_IW 0x6800
543 #define T_OPCODE_STR_IW 0x6000
544 #define T_OPCODE_LDR_IH 0x8800
545 #define T_OPCODE_STR_IH 0x8000
546 #define T_OPCODE_LDR_IB 0x7800
547 #define T_OPCODE_STR_IB 0x7000
548 #define T_OPCODE_LDR_RW 0x5800
549 #define T_OPCODE_STR_RW 0x5000
550 #define T_OPCODE_LDR_RH 0x5a00
551 #define T_OPCODE_STR_RH 0x5200
552 #define T_OPCODE_LDR_RB 0x5c00
553 #define T_OPCODE_STR_RB 0x5400
555 #define T_OPCODE_PUSH 0xb400
556 #define T_OPCODE_POP 0xbc00
558 #define T_OPCODE_BRANCH 0xe000
560 #define THUMB_SIZE 2 /* Size of thumb instruction. */
561 #define THUMB_PP_PC_LR 0x0100
562 #define THUMB_LOAD_BIT 0x0800
563 #define THUMB2_LOAD_BIT 0x00100000
565 #define BAD_ARGS _("bad arguments to instruction")
566 #define BAD_PC _("r15 not allowed here")
567 #define BAD_COND _("instruction cannot be conditional")
568 #define BAD_OVERLAP _("registers may not be the same")
569 #define BAD_HIREG _("lo register required")
570 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
571 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
572 #define BAD_BRANCH _("branch must be last instruction in IT block")
573 #define BAD_NOT_IT _("instruction not allowed in IT block")
575 static struct hash_control *arm_ops_hsh;
576 static struct hash_control *arm_cond_hsh;
577 static struct hash_control *arm_shift_hsh;
578 static struct hash_control *arm_psr_hsh;
579 static struct hash_control *arm_v7m_psr_hsh;
580 static struct hash_control *arm_reg_hsh;
581 static struct hash_control *arm_reloc_hsh;
582 static struct hash_control *arm_barrier_opt_hsh;
584 /* Stuff needed to resolve the label ambiguity
587 label: <insn>
588 may differ from:
590 label:
591 <insn>
594 symbolS * last_label_seen;
595 static int label_is_thumb_function_name = FALSE;
597 /* Literal pool structure. Held on a per-section
598 and per-sub-section basis. */
600 #define MAX_LITERAL_POOL_SIZE 1024
601 typedef struct literal_pool
603 expressionS literals [MAX_LITERAL_POOL_SIZE];
604 unsigned int next_free_entry;
605 unsigned int id;
606 symbolS * symbol;
607 segT section;
608 subsegT sub_section;
609 struct literal_pool * next;
610 } literal_pool;
612 /* Pointer to a linked list of literal pools. */
613 literal_pool * list_of_pools = NULL;
615 /* State variables for IT block handling. */
616 static bfd_boolean current_it_mask = 0;
617 static int current_cc;
620 /* Pure syntax. */
622 /* This array holds the chars that always start a comment. If the
623 pre-processor is disabled, these aren't very useful. */
624 const char comment_chars[] = "@";
626 /* This array holds the chars that only start a comment at the beginning of
627 a line. If the line seems to have the form '# 123 filename'
628 .line and .file directives will appear in the pre-processed output. */
629 /* Note that input_file.c hand checks for '#' at the beginning of the
630 first line of the input file. This is because the compiler outputs
631 #NO_APP at the beginning of its output. */
632 /* Also note that comments like this one will always work. */
633 const char line_comment_chars[] = "#";
635 const char line_separator_chars[] = ";";
637 /* Chars that can be used to separate mant
638 from exp in floating point numbers. */
639 const char EXP_CHARS[] = "eE";
641 /* Chars that mean this number is a floating point constant. */
642 /* As in 0f12.456 */
643 /* or 0d1.2345e12 */
645 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
647 /* Prefix characters that indicate the start of an immediate
648 value. */
649 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
651 /* Separator character handling. */
653 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
655 static inline int
656 skip_past_char (char ** str, char c)
658 if (**str == c)
660 (*str)++;
661 return SUCCESS;
663 else
664 return FAIL;
666 #define skip_past_comma(str) skip_past_char (str, ',')
668 /* Arithmetic expressions (possibly involving symbols). */
670 /* Return TRUE if anything in the expression is a bignum. */
672 static int
673 walk_no_bignums (symbolS * sp)
675 if (symbol_get_value_expression (sp)->X_op == O_big)
676 return 1;
678 if (symbol_get_value_expression (sp)->X_add_symbol)
680 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
681 || (symbol_get_value_expression (sp)->X_op_symbol
682 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
685 return 0;
688 static int in_my_get_expression = 0;
690 /* Third argument to my_get_expression. */
691 #define GE_NO_PREFIX 0
692 #define GE_IMM_PREFIX 1
693 #define GE_OPT_PREFIX 2
695 static int
696 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
698 char * save_in;
699 segT seg;
701 /* In unified syntax, all prefixes are optional. */
702 if (unified_syntax)
703 prefix_mode = GE_OPT_PREFIX;
705 switch (prefix_mode)
707 case GE_NO_PREFIX: break;
708 case GE_IMM_PREFIX:
709 if (!is_immediate_prefix (**str))
711 inst.error = _("immediate expression requires a # prefix");
712 return FAIL;
714 (*str)++;
715 break;
716 case GE_OPT_PREFIX:
717 if (is_immediate_prefix (**str))
718 (*str)++;
719 break;
720 default: abort ();
723 memset (ep, 0, sizeof (expressionS));
725 save_in = input_line_pointer;
726 input_line_pointer = *str;
727 in_my_get_expression = 1;
728 seg = expression (ep);
729 in_my_get_expression = 0;
731 if (ep->X_op == O_illegal)
733 /* We found a bad expression in md_operand(). */
734 *str = input_line_pointer;
735 input_line_pointer = save_in;
736 if (inst.error == NULL)
737 inst.error = _("bad expression");
738 return 1;
741 #ifdef OBJ_AOUT
742 if (seg != absolute_section
743 && seg != text_section
744 && seg != data_section
745 && seg != bss_section
746 && seg != undefined_section)
748 inst.error = _("bad segment");
749 *str = input_line_pointer;
750 input_line_pointer = save_in;
751 return 1;
753 #endif
755 /* Get rid of any bignums now, so that we don't generate an error for which
756 we can't establish a line number later on. Big numbers are never valid
757 in instructions, which is where this routine is always called. */
758 if (ep->X_op == O_big
759 || (ep->X_add_symbol
760 && (walk_no_bignums (ep->X_add_symbol)
761 || (ep->X_op_symbol
762 && walk_no_bignums (ep->X_op_symbol)))))
764 inst.error = _("invalid constant");
765 *str = input_line_pointer;
766 input_line_pointer = save_in;
767 return 1;
770 *str = input_line_pointer;
771 input_line_pointer = save_in;
772 return 0;
775 /* Turn a string in input_line_pointer into a floating point constant
776 of type TYPE, and store the appropriate bytes in *LITP. The number
777 of LITTLENUMS emitted is stored in *SIZEP. An error message is
778 returned, or NULL on OK.
780 Note that fp constants aren't represent in the normal way on the ARM.
781 In big endian mode, things are as expected. However, in little endian
782 mode fp constants are big-endian word-wise, and little-endian byte-wise
783 within the words. For example, (double) 1.1 in big endian mode is
784 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
785 the byte sequence 99 99 f1 3f 9a 99 99 99.
787 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
789 char *
790 md_atof (int type, char * litP, int * sizeP)
792 int prec;
793 LITTLENUM_TYPE words[MAX_LITTLENUMS];
794 char *t;
795 int i;
797 switch (type)
799 case 'f':
800 case 'F':
801 case 's':
802 case 'S':
803 prec = 2;
804 break;
806 case 'd':
807 case 'D':
808 case 'r':
809 case 'R':
810 prec = 4;
811 break;
813 case 'x':
814 case 'X':
815 prec = 6;
816 break;
818 case 'p':
819 case 'P':
820 prec = 6;
821 break;
823 default:
824 *sizeP = 0;
825 return _("bad call to MD_ATOF()");
828 t = atof_ieee (input_line_pointer, type, words);
829 if (t)
830 input_line_pointer = t;
831 *sizeP = prec * 2;
833 if (target_big_endian)
835 for (i = 0; i < prec; i++)
837 md_number_to_chars (litP, (valueT) words[i], 2);
838 litP += 2;
841 else
843 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
844 for (i = prec - 1; i >= 0; i--)
846 md_number_to_chars (litP, (valueT) words[i], 2);
847 litP += 2;
849 else
850 /* For a 4 byte float the order of elements in `words' is 1 0.
851 For an 8 byte float the order is 1 0 3 2. */
852 for (i = 0; i < prec; i += 2)
854 md_number_to_chars (litP, (valueT) words[i + 1], 2);
855 md_number_to_chars (litP + 2, (valueT) words[i], 2);
856 litP += 4;
860 return 0;
863 /* We handle all bad expressions here, so that we can report the faulty
864 instruction in the error message. */
865 void
866 md_operand (expressionS * expr)
868 if (in_my_get_expression)
869 expr->X_op = O_illegal;
872 /* Immediate values. */
874 /* Generic immediate-value read function for use in directives.
875 Accepts anything that 'expression' can fold to a constant.
876 *val receives the number. */
877 #ifdef OBJ_ELF
878 static int
879 immediate_for_directive (int *val)
881 expressionS exp;
882 exp.X_op = O_illegal;
884 if (is_immediate_prefix (*input_line_pointer))
886 input_line_pointer++;
887 expression (&exp);
890 if (exp.X_op != O_constant)
892 as_bad (_("expected #constant"));
893 ignore_rest_of_line ();
894 return FAIL;
896 *val = exp.X_add_number;
897 return SUCCESS;
899 #endif
901 /* Register parsing. */
903 /* Generic register parser. CCP points to what should be the
904 beginning of a register name. If it is indeed a valid register
905 name, advance CCP over it and return the reg_entry structure;
906 otherwise return NULL. Does not issue diagnostics. */
908 static struct reg_entry *
909 arm_reg_parse_multi (char **ccp)
911 char *start = *ccp;
912 char *p;
913 struct reg_entry *reg;
915 #ifdef REGISTER_PREFIX
916 if (*start != REGISTER_PREFIX)
917 return NULL;
918 start++;
919 #endif
920 #ifdef OPTIONAL_REGISTER_PREFIX
921 if (*start == OPTIONAL_REGISTER_PREFIX)
922 start++;
923 #endif
925 p = start;
926 if (!ISALPHA (*p) || !is_name_beginner (*p))
927 return NULL;
930 p++;
931 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
933 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
935 if (!reg)
936 return NULL;
938 *ccp = p;
939 return reg;
942 /* As above, but the register must be of type TYPE, and the return
943 value is the register number or FAIL. */
945 static int
946 arm_reg_parse (char **ccp, enum arm_reg_type type)
948 char *start = *ccp;
949 struct reg_entry *reg = arm_reg_parse_multi (ccp);
951 if (reg && reg->type == type)
952 return reg->number;
954 /* Alternative syntaxes are accepted for a few register classes. */
955 switch (type)
957 case REG_TYPE_MVF:
958 case REG_TYPE_MVD:
959 case REG_TYPE_MVFX:
960 case REG_TYPE_MVDX:
961 /* Generic coprocessor register names are allowed for these. */
962 if (reg && reg->type == REG_TYPE_CN)
963 return reg->number;
964 break;
966 case REG_TYPE_CP:
967 /* For backward compatibility, a bare number is valid here. */
969 unsigned long processor = strtoul (start, ccp, 10);
970 if (*ccp != start && processor <= 15)
971 return processor;
974 case REG_TYPE_MMXWC:
975 /* WC includes WCG. ??? I'm not sure this is true for all
976 instructions that take WC registers. */
977 if (reg && reg->type == REG_TYPE_MMXWCG)
978 return reg->number;
979 break;
981 default:
982 break;
985 *ccp = start;
986 return FAIL;
989 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
990 static long
991 parse_reg_list (char ** strp)
993 char * str = * strp;
994 long range = 0;
995 int another_range;
997 /* We come back here if we get ranges concatenated by '+' or '|'. */
1000 another_range = 0;
1002 if (*str == '{')
1004 int in_range = 0;
1005 int cur_reg = -1;
1007 str++;
1010 int reg;
1012 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1014 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
1015 return FAIL;
1018 if (in_range)
1020 int i;
1022 if (reg <= cur_reg)
1024 inst.error = _("bad range in register list");
1025 return FAIL;
1028 for (i = cur_reg + 1; i < reg; i++)
1030 if (range & (1 << i))
1031 as_tsktsk
1032 (_("Warning: duplicated register (r%d) in register list"),
1034 else
1035 range |= 1 << i;
1037 in_range = 0;
1040 if (range & (1 << reg))
1041 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1042 reg);
1043 else if (reg <= cur_reg)
1044 as_tsktsk (_("Warning: register range not in ascending order"));
1046 range |= 1 << reg;
1047 cur_reg = reg;
1049 while (skip_past_comma (&str) != FAIL
1050 || (in_range = 1, *str++ == '-'));
1051 str--;
1053 if (*str++ != '}')
1055 inst.error = _("missing `}'");
1056 return FAIL;
1059 else
1061 expressionS expr;
1063 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1064 return FAIL;
1066 if (expr.X_op == O_constant)
1068 if (expr.X_add_number
1069 != (expr.X_add_number & 0x0000ffff))
1071 inst.error = _("invalid register mask");
1072 return FAIL;
1075 if ((range & expr.X_add_number) != 0)
1077 int regno = range & expr.X_add_number;
1079 regno &= -regno;
1080 regno = (1 << regno) - 1;
1081 as_tsktsk
1082 (_("Warning: duplicated register (r%d) in register list"),
1083 regno);
1086 range |= expr.X_add_number;
1088 else
1090 if (inst.reloc.type != 0)
1092 inst.error = _("expression too complex");
1093 return FAIL;
1096 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1097 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1098 inst.reloc.pc_rel = 0;
1102 if (*str == '|' || *str == '+')
1104 str++;
1105 another_range = 1;
1108 while (another_range);
1110 *strp = str;
1111 return range;
1114 /* Parse a VFP register list. If the string is invalid return FAIL.
1115 Otherwise return the number of registers, and set PBASE to the first
1116 register. Double precision registers are matched if DP is nonzero. */
1118 static int
1119 parse_vfp_reg_list (char **str, unsigned int *pbase, int dp)
1121 int base_reg;
1122 int new_base;
1123 int regtype;
1124 int max_regs;
1125 int count = 0;
1126 int warned = 0;
1127 unsigned long mask = 0;
1128 int i;
1130 if (**str != '{')
1131 return FAIL;
1133 (*str)++;
1135 if (dp)
1137 regtype = REG_TYPE_VFD;
1138 max_regs = 16;
1140 else
1142 regtype = REG_TYPE_VFS;
1143 max_regs = 32;
1146 base_reg = max_regs;
1150 new_base = arm_reg_parse (str, regtype);
1151 if (new_base == FAIL)
1153 inst.error = gettext (reg_expected_msgs[regtype]);
1154 return FAIL;
1157 if (new_base < base_reg)
1158 base_reg = new_base;
1160 if (mask & (1 << new_base))
1162 inst.error = _("invalid register list");
1163 return FAIL;
1166 if ((mask >> new_base) != 0 && ! warned)
1168 as_tsktsk (_("register list not in ascending order"));
1169 warned = 1;
1172 mask |= 1 << new_base;
1173 count++;
1175 if (**str == '-') /* We have the start of a range expression */
1177 int high_range;
1179 (*str)++;
1181 if ((high_range = arm_reg_parse (str, regtype)) == FAIL)
1183 inst.error = gettext (reg_expected_msgs[regtype]);
1184 return FAIL;
1187 if (high_range <= new_base)
1189 inst.error = _("register range not in ascending order");
1190 return FAIL;
1193 for (new_base++; new_base <= high_range; new_base++)
1195 if (mask & (1 << new_base))
1197 inst.error = _("invalid register list");
1198 return FAIL;
1201 mask |= 1 << new_base;
1202 count++;
1206 while (skip_past_comma (str) != FAIL);
1208 (*str)++;
1210 /* Sanity check -- should have raised a parse error above. */
1211 if (count == 0 || count > max_regs)
1212 abort ();
1214 *pbase = base_reg;
1216 /* Final test -- the registers must be consecutive. */
1217 mask >>= base_reg;
1218 for (i = 0; i < count; i++)
1220 if ((mask & (1u << i)) == 0)
1222 inst.error = _("non-contiguous register range");
1223 return FAIL;
1227 return count;
1230 /* Parse an explicit relocation suffix on an expression. This is
1231 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1232 arm_reloc_hsh contains no entries, so this function can only
1233 succeed if there is no () after the word. Returns -1 on error,
1234 BFD_RELOC_UNUSED if there wasn't any suffix. */
1235 static int
1236 parse_reloc (char **str)
1238 struct reloc_entry *r;
1239 char *p, *q;
1241 if (**str != '(')
1242 return BFD_RELOC_UNUSED;
1244 p = *str + 1;
1245 q = p;
1247 while (*q && *q != ')' && *q != ',')
1248 q++;
1249 if (*q != ')')
1250 return -1;
1252 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1253 return -1;
1255 *str = q + 1;
1256 return r->reloc;
1259 /* Directives: register aliases. */
1261 static void
1262 insert_reg_alias (char *str, int number, int type)
1264 struct reg_entry *new;
1265 const char *name;
1267 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1269 if (new->builtin)
1270 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1272 /* Only warn about a redefinition if it's not defined as the
1273 same register. */
1274 else if (new->number != number || new->type != type)
1275 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1277 return;
1280 name = xstrdup (str);
1281 new = xmalloc (sizeof (struct reg_entry));
1283 new->name = name;
1284 new->number = number;
1285 new->type = type;
1286 new->builtin = FALSE;
1288 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1289 abort ();
1292 /* Look for the .req directive. This is of the form:
1294 new_register_name .req existing_register_name
1296 If we find one, or if it looks sufficiently like one that we want to
1297 handle any error here, return non-zero. Otherwise return zero. */
1299 static int
1300 create_register_alias (char * newname, char *p)
1302 struct reg_entry *old;
1303 char *oldname, *nbuf;
1304 size_t nlen;
1306 /* The input scrubber ensures that whitespace after the mnemonic is
1307 collapsed to single spaces. */
1308 oldname = p;
1309 if (strncmp (oldname, " .req ", 6) != 0)
1310 return 0;
1312 oldname += 6;
1313 if (*oldname == '\0')
1314 return 0;
1316 old = hash_find (arm_reg_hsh, oldname);
1317 if (!old)
1319 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
1320 return 1;
1323 /* If TC_CASE_SENSITIVE is defined, then newname already points to
1324 the desired alias name, and p points to its end. If not, then
1325 the desired alias name is in the global original_case_string. */
1326 #ifdef TC_CASE_SENSITIVE
1327 nlen = p - newname;
1328 #else
1329 newname = original_case_string;
1330 nlen = strlen (newname);
1331 #endif
1333 nbuf = alloca (nlen + 1);
1334 memcpy (nbuf, newname, nlen);
1335 nbuf[nlen] = '\0';
1337 /* Create aliases under the new name as stated; an all-lowercase
1338 version of the new name; and an all-uppercase version of the new
1339 name. */
1340 insert_reg_alias (nbuf, old->number, old->type);
1342 for (p = nbuf; *p; p++)
1343 *p = TOUPPER (*p);
1345 if (strncmp (nbuf, newname, nlen))
1346 insert_reg_alias (nbuf, old->number, old->type);
1348 for (p = nbuf; *p; p++)
1349 *p = TOLOWER (*p);
1351 if (strncmp (nbuf, newname, nlen))
1352 insert_reg_alias (nbuf, old->number, old->type);
1354 return 1;
1357 /* Should never be called, as .req goes between the alias and the
1358 register name, not at the beginning of the line. */
1359 static void
1360 s_req (int a ATTRIBUTE_UNUSED)
1362 as_bad (_("invalid syntax for .req directive"));
1365 /* The .unreq directive deletes an alias which was previously defined
1366 by .req. For example:
1368 my_alias .req r11
1369 .unreq my_alias */
1371 static void
1372 s_unreq (int a ATTRIBUTE_UNUSED)
1374 char * name;
1375 char saved_char;
1377 name = input_line_pointer;
1379 while (*input_line_pointer != 0
1380 && *input_line_pointer != ' '
1381 && *input_line_pointer != '\n')
1382 ++input_line_pointer;
1384 saved_char = *input_line_pointer;
1385 *input_line_pointer = 0;
1387 if (!*name)
1388 as_bad (_("invalid syntax for .unreq directive"));
1389 else
1391 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
1393 if (!reg)
1394 as_bad (_("unknown register alias '%s'"), name);
1395 else if (reg->builtin)
1396 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
1397 name);
1398 else
1400 hash_delete (arm_reg_hsh, name);
1401 free ((char *) reg->name);
1402 free (reg);
1406 *input_line_pointer = saved_char;
1407 demand_empty_rest_of_line ();
1410 /* Directives: Instruction set selection. */
1412 #ifdef OBJ_ELF
1413 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
1414 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
1415 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
1416 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
1418 static enum mstate mapstate = MAP_UNDEFINED;
1420 static void
1421 mapping_state (enum mstate state)
1423 symbolS * symbolP;
1424 const char * symname;
1425 int type;
1427 if (mapstate == state)
1428 /* The mapping symbol has already been emitted.
1429 There is nothing else to do. */
1430 return;
1432 mapstate = state;
1434 switch (state)
1436 case MAP_DATA:
1437 symname = "$d";
1438 type = BSF_NO_FLAGS;
1439 break;
1440 case MAP_ARM:
1441 symname = "$a";
1442 type = BSF_NO_FLAGS;
1443 break;
1444 case MAP_THUMB:
1445 symname = "$t";
1446 type = BSF_NO_FLAGS;
1447 break;
1448 case MAP_UNDEFINED:
1449 return;
1450 default:
1451 abort ();
1454 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
1456 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
1457 symbol_table_insert (symbolP);
1458 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
1460 switch (state)
1462 case MAP_ARM:
1463 THUMB_SET_FUNC (symbolP, 0);
1464 ARM_SET_THUMB (symbolP, 0);
1465 ARM_SET_INTERWORK (symbolP, support_interwork);
1466 break;
1468 case MAP_THUMB:
1469 THUMB_SET_FUNC (symbolP, 1);
1470 ARM_SET_THUMB (symbolP, 1);
1471 ARM_SET_INTERWORK (symbolP, support_interwork);
1472 break;
1474 case MAP_DATA:
1475 default:
1476 return;
1479 #else
1480 #define mapping_state(x) /* nothing */
1481 #endif
1483 /* Find the real, Thumb encoded start of a Thumb function. */
1485 static symbolS *
1486 find_real_start (symbolS * symbolP)
1488 char * real_start;
1489 const char * name = S_GET_NAME (symbolP);
1490 symbolS * new_target;
1492 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
1493 #define STUB_NAME ".real_start_of"
1495 if (name == NULL)
1496 abort ();
1498 /* The compiler may generate BL instructions to local labels because
1499 it needs to perform a branch to a far away location. These labels
1500 do not have a corresponding ".real_start_of" label. We check
1501 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
1502 the ".real_start_of" convention for nonlocal branches. */
1503 if (S_IS_LOCAL (symbolP) || name[0] == '.')
1504 return symbolP;
1506 real_start = ACONCAT ((STUB_NAME, name, NULL));
1507 new_target = symbol_find (real_start);
1509 if (new_target == NULL)
1511 as_warn ("Failed to find real start of function: %s\n", name);
1512 new_target = symbolP;
1515 return new_target;
1518 static void
1519 opcode_select (int width)
1521 switch (width)
1523 case 16:
1524 if (! thumb_mode)
1526 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
1527 as_bad (_("selected processor does not support THUMB opcodes"));
1529 thumb_mode = 1;
1530 /* No need to force the alignment, since we will have been
1531 coming from ARM mode, which is word-aligned. */
1532 record_alignment (now_seg, 1);
1534 mapping_state (MAP_THUMB);
1535 break;
1537 case 32:
1538 if (thumb_mode)
1540 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
1541 as_bad (_("selected processor does not support ARM opcodes"));
1543 thumb_mode = 0;
1545 if (!need_pass_2)
1546 frag_align (2, 0, 0);
1548 record_alignment (now_seg, 1);
1550 mapping_state (MAP_ARM);
1551 break;
1553 default:
1554 as_bad (_("invalid instruction size selected (%d)"), width);
1558 static void
1559 s_arm (int ignore ATTRIBUTE_UNUSED)
1561 opcode_select (32);
1562 demand_empty_rest_of_line ();
1565 static void
1566 s_thumb (int ignore ATTRIBUTE_UNUSED)
1568 opcode_select (16);
1569 demand_empty_rest_of_line ();
1572 static void
1573 s_code (int unused ATTRIBUTE_UNUSED)
1575 int temp;
1577 temp = get_absolute_expression ();
1578 switch (temp)
1580 case 16:
1581 case 32:
1582 opcode_select (temp);
1583 break;
1585 default:
1586 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
1590 static void
1591 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
1593 /* If we are not already in thumb mode go into it, EVEN if
1594 the target processor does not support thumb instructions.
1595 This is used by gcc/config/arm/lib1funcs.asm for example
1596 to compile interworking support functions even if the
1597 target processor should not support interworking. */
1598 if (! thumb_mode)
1600 thumb_mode = 2;
1601 record_alignment (now_seg, 1);
1604 demand_empty_rest_of_line ();
1607 static void
1608 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
1610 s_thumb (0);
1612 /* The following label is the name/address of the start of a Thumb function.
1613 We need to know this for the interworking support. */
1614 label_is_thumb_function_name = TRUE;
1617 /* Perform a .set directive, but also mark the alias as
1618 being a thumb function. */
1620 static void
1621 s_thumb_set (int equiv)
1623 /* XXX the following is a duplicate of the code for s_set() in read.c
1624 We cannot just call that code as we need to get at the symbol that
1625 is created. */
1626 char * name;
1627 char delim;
1628 char * end_name;
1629 symbolS * symbolP;
1631 /* Especial apologies for the random logic:
1632 This just grew, and could be parsed much more simply!
1633 Dean - in haste. */
1634 name = input_line_pointer;
1635 delim = get_symbol_end ();
1636 end_name = input_line_pointer;
1637 *end_name = delim;
1639 if (*input_line_pointer != ',')
1641 *end_name = 0;
1642 as_bad (_("expected comma after name \"%s\""), name);
1643 *end_name = delim;
1644 ignore_rest_of_line ();
1645 return;
1648 input_line_pointer++;
1649 *end_name = 0;
1651 if (name[0] == '.' && name[1] == '\0')
1653 /* XXX - this should not happen to .thumb_set. */
1654 abort ();
1657 if ((symbolP = symbol_find (name)) == NULL
1658 && (symbolP = md_undefined_symbol (name)) == NULL)
1660 #ifndef NO_LISTING
1661 /* When doing symbol listings, play games with dummy fragments living
1662 outside the normal fragment chain to record the file and line info
1663 for this symbol. */
1664 if (listing & LISTING_SYMBOLS)
1666 extern struct list_info_struct * listing_tail;
1667 fragS * dummy_frag = xmalloc (sizeof (fragS));
1669 memset (dummy_frag, 0, sizeof (fragS));
1670 dummy_frag->fr_type = rs_fill;
1671 dummy_frag->line = listing_tail;
1672 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
1673 dummy_frag->fr_symbol = symbolP;
1675 else
1676 #endif
1677 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1679 #ifdef OBJ_COFF
1680 /* "set" symbols are local unless otherwise specified. */
1681 SF_SET_LOCAL (symbolP);
1682 #endif /* OBJ_COFF */
1683 } /* Make a new symbol. */
1685 symbol_table_insert (symbolP);
1687 * end_name = delim;
1689 if (equiv
1690 && S_IS_DEFINED (symbolP)
1691 && S_GET_SEGMENT (symbolP) != reg_section)
1692 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
1694 pseudo_set (symbolP);
1696 demand_empty_rest_of_line ();
1698 /* XXX Now we come to the Thumb specific bit of code. */
1700 THUMB_SET_FUNC (symbolP, 1);
1701 ARM_SET_THUMB (symbolP, 1);
1702 #if defined OBJ_ELF || defined OBJ_COFF
1703 ARM_SET_INTERWORK (symbolP, support_interwork);
1704 #endif
1707 /* Directives: Mode selection. */
1709 /* .syntax [unified|divided] - choose the new unified syntax
1710 (same for Arm and Thumb encoding, modulo slight differences in what
1711 can be represented) or the old divergent syntax for each mode. */
1712 static void
1713 s_syntax (int unused ATTRIBUTE_UNUSED)
1715 char *name, delim;
1717 name = input_line_pointer;
1718 delim = get_symbol_end ();
1720 if (!strcasecmp (name, "unified"))
1721 unified_syntax = TRUE;
1722 else if (!strcasecmp (name, "divided"))
1723 unified_syntax = FALSE;
1724 else
1726 as_bad (_("unrecognized syntax mode \"%s\""), name);
1727 return;
1729 *input_line_pointer = delim;
1730 demand_empty_rest_of_line ();
1733 /* Directives: sectioning and alignment. */
1735 /* Same as s_align_ptwo but align 0 => align 2. */
1737 static void
1738 s_align (int unused ATTRIBUTE_UNUSED)
1740 int temp;
1741 long temp_fill;
1742 long max_alignment = 15;
1744 temp = get_absolute_expression ();
1745 if (temp > max_alignment)
1746 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
1747 else if (temp < 0)
1749 as_bad (_("alignment negative. 0 assumed."));
1750 temp = 0;
1753 if (*input_line_pointer == ',')
1755 input_line_pointer++;
1756 temp_fill = get_absolute_expression ();
1758 else
1759 temp_fill = 0;
1761 if (!temp)
1762 temp = 2;
1764 /* Only make a frag if we HAVE to. */
1765 if (temp && !need_pass_2)
1766 frag_align (temp, (int) temp_fill, 0);
1767 demand_empty_rest_of_line ();
1769 record_alignment (now_seg, temp);
1772 static void
1773 s_bss (int ignore ATTRIBUTE_UNUSED)
1775 /* We don't support putting frags in the BSS segment, we fake it by
1776 marking in_bss, then looking at s_skip for clues. */
1777 subseg_set (bss_section, 0);
1778 demand_empty_rest_of_line ();
1779 mapping_state (MAP_DATA);
1782 static void
1783 s_even (int ignore ATTRIBUTE_UNUSED)
1785 /* Never make frag if expect extra pass. */
1786 if (!need_pass_2)
1787 frag_align (1, 0, 0);
1789 record_alignment (now_seg, 1);
1791 demand_empty_rest_of_line ();
1794 /* Directives: Literal pools. */
1796 static literal_pool *
1797 find_literal_pool (void)
1799 literal_pool * pool;
1801 for (pool = list_of_pools; pool != NULL; pool = pool->next)
1803 if (pool->section == now_seg
1804 && pool->sub_section == now_subseg)
1805 break;
1808 return pool;
1811 static literal_pool *
1812 find_or_make_literal_pool (void)
1814 /* Next literal pool ID number. */
1815 static unsigned int latest_pool_num = 1;
1816 literal_pool * pool;
1818 pool = find_literal_pool ();
1820 if (pool == NULL)
1822 /* Create a new pool. */
1823 pool = xmalloc (sizeof (* pool));
1824 if (! pool)
1825 return NULL;
1827 pool->next_free_entry = 0;
1828 pool->section = now_seg;
1829 pool->sub_section = now_subseg;
1830 pool->next = list_of_pools;
1831 pool->symbol = NULL;
1833 /* Add it to the list. */
1834 list_of_pools = pool;
1837 /* New pools, and emptied pools, will have a NULL symbol. */
1838 if (pool->symbol == NULL)
1840 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
1841 (valueT) 0, &zero_address_frag);
1842 pool->id = latest_pool_num ++;
1845 /* Done. */
1846 return pool;
1849 /* Add the literal in the global 'inst'
1850 structure to the relevent literal pool. */
1852 static int
1853 add_to_lit_pool (void)
1855 literal_pool * pool;
1856 unsigned int entry;
1858 pool = find_or_make_literal_pool ();
1860 /* Check if this literal value is already in the pool. */
1861 for (entry = 0; entry < pool->next_free_entry; entry ++)
1863 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1864 && (inst.reloc.exp.X_op == O_constant)
1865 && (pool->literals[entry].X_add_number
1866 == inst.reloc.exp.X_add_number)
1867 && (pool->literals[entry].X_unsigned
1868 == inst.reloc.exp.X_unsigned))
1869 break;
1871 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1872 && (inst.reloc.exp.X_op == O_symbol)
1873 && (pool->literals[entry].X_add_number
1874 == inst.reloc.exp.X_add_number)
1875 && (pool->literals[entry].X_add_symbol
1876 == inst.reloc.exp.X_add_symbol)
1877 && (pool->literals[entry].X_op_symbol
1878 == inst.reloc.exp.X_op_symbol))
1879 break;
1882 /* Do we need to create a new entry? */
1883 if (entry == pool->next_free_entry)
1885 if (entry >= MAX_LITERAL_POOL_SIZE)
1887 inst.error = _("literal pool overflow");
1888 return FAIL;
1891 pool->literals[entry] = inst.reloc.exp;
1892 pool->next_free_entry += 1;
1895 inst.reloc.exp.X_op = O_symbol;
1896 inst.reloc.exp.X_add_number = ((int) entry) * 4;
1897 inst.reloc.exp.X_add_symbol = pool->symbol;
1899 return SUCCESS;
1902 /* Can't use symbol_new here, so have to create a symbol and then at
1903 a later date assign it a value. Thats what these functions do. */
1905 static void
1906 symbol_locate (symbolS * symbolP,
1907 const char * name, /* It is copied, the caller can modify. */
1908 segT segment, /* Segment identifier (SEG_<something>). */
1909 valueT valu, /* Symbol value. */
1910 fragS * frag) /* Associated fragment. */
1912 unsigned int name_length;
1913 char * preserved_copy_of_name;
1915 name_length = strlen (name) + 1; /* +1 for \0. */
1916 obstack_grow (&notes, name, name_length);
1917 preserved_copy_of_name = obstack_finish (&notes);
1919 #ifdef tc_canonicalize_symbol_name
1920 preserved_copy_of_name =
1921 tc_canonicalize_symbol_name (preserved_copy_of_name);
1922 #endif
1924 S_SET_NAME (symbolP, preserved_copy_of_name);
1926 S_SET_SEGMENT (symbolP, segment);
1927 S_SET_VALUE (symbolP, valu);
1928 symbol_clear_list_pointers (symbolP);
1930 symbol_set_frag (symbolP, frag);
1932 /* Link to end of symbol chain. */
1934 extern int symbol_table_frozen;
1936 if (symbol_table_frozen)
1937 abort ();
1940 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
1942 obj_symbol_new_hook (symbolP);
1944 #ifdef tc_symbol_new_hook
1945 tc_symbol_new_hook (symbolP);
1946 #endif
1948 #ifdef DEBUG_SYMS
1949 verify_symbol_chain (symbol_rootP, symbol_lastP);
1950 #endif /* DEBUG_SYMS */
1954 static void
1955 s_ltorg (int ignored ATTRIBUTE_UNUSED)
1957 unsigned int entry;
1958 literal_pool * pool;
1959 char sym_name[20];
1961 pool = find_literal_pool ();
1962 if (pool == NULL
1963 || pool->symbol == NULL
1964 || pool->next_free_entry == 0)
1965 return;
1967 mapping_state (MAP_DATA);
1969 /* Align pool as you have word accesses.
1970 Only make a frag if we have to. */
1971 if (!need_pass_2)
1972 frag_align (2, 0, 0);
1974 record_alignment (now_seg, 2);
1976 sprintf (sym_name, "$$lit_\002%x", pool->id);
1978 symbol_locate (pool->symbol, sym_name, now_seg,
1979 (valueT) frag_now_fix (), frag_now);
1980 symbol_table_insert (pool->symbol);
1982 ARM_SET_THUMB (pool->symbol, thumb_mode);
1984 #if defined OBJ_COFF || defined OBJ_ELF
1985 ARM_SET_INTERWORK (pool->symbol, support_interwork);
1986 #endif
1988 for (entry = 0; entry < pool->next_free_entry; entry ++)
1989 /* First output the expression in the instruction to the pool. */
1990 emit_expr (&(pool->literals[entry]), 4); /* .word */
1992 /* Mark the pool as empty. */
1993 pool->next_free_entry = 0;
1994 pool->symbol = NULL;
1997 #ifdef OBJ_ELF
1998 /* Forward declarations for functions below, in the MD interface
1999 section. */
2000 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2001 static valueT create_unwind_entry (int);
2002 static void start_unwind_section (const segT, int);
2003 static void add_unwind_opcode (valueT, int);
2004 static void flush_pending_unwind (void);
2006 /* Directives: Data. */
2008 static void
2009 s_arm_elf_cons (int nbytes)
2011 expressionS exp;
2013 #ifdef md_flush_pending_output
2014 md_flush_pending_output ();
2015 #endif
2017 if (is_it_end_of_statement ())
2019 demand_empty_rest_of_line ();
2020 return;
2023 #ifdef md_cons_align
2024 md_cons_align (nbytes);
2025 #endif
2027 mapping_state (MAP_DATA);
2030 int reloc;
2031 char *base = input_line_pointer;
2033 expression (& exp);
2035 if (exp.X_op != O_symbol)
2036 emit_expr (&exp, (unsigned int) nbytes);
2037 else
2039 char *before_reloc = input_line_pointer;
2040 reloc = parse_reloc (&input_line_pointer);
2041 if (reloc == -1)
2043 as_bad (_("unrecognized relocation suffix"));
2044 ignore_rest_of_line ();
2045 return;
2047 else if (reloc == BFD_RELOC_UNUSED)
2048 emit_expr (&exp, (unsigned int) nbytes);
2049 else
2051 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2052 int size = bfd_get_reloc_size (howto);
2054 if (reloc == BFD_RELOC_ARM_PLT32)
2056 as_bad (_("(plt) is only valid on branch targets"));
2057 reloc = BFD_RELOC_UNUSED;
2058 size = 0;
2061 if (size > nbytes)
2062 as_bad (_("%s relocations do not fit in %d bytes"),
2063 howto->name, nbytes);
2064 else
2066 /* We've parsed an expression stopping at O_symbol.
2067 But there may be more expression left now that we
2068 have parsed the relocation marker. Parse it again.
2069 XXX Surely there is a cleaner way to do this. */
2070 char *p = input_line_pointer;
2071 int offset;
2072 char *save_buf = alloca (input_line_pointer - base);
2073 memcpy (save_buf, base, input_line_pointer - base);
2074 memmove (base + (input_line_pointer - before_reloc),
2075 base, before_reloc - base);
2077 input_line_pointer = base + (input_line_pointer-before_reloc);
2078 expression (&exp);
2079 memcpy (base, save_buf, p - base);
2081 offset = nbytes - size;
2082 p = frag_more ((int) nbytes);
2083 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2084 size, &exp, 0, reloc);
2089 while (*input_line_pointer++ == ',');
2091 /* Put terminator back into stream. */
2092 input_line_pointer --;
2093 demand_empty_rest_of_line ();
2097 /* Parse a .rel31 directive. */
2099 static void
2100 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2102 expressionS exp;
2103 char *p;
2104 valueT highbit;
2106 highbit = 0;
2107 if (*input_line_pointer == '1')
2108 highbit = 0x80000000;
2109 else if (*input_line_pointer != '0')
2110 as_bad (_("expected 0 or 1"));
2112 input_line_pointer++;
2113 if (*input_line_pointer != ',')
2114 as_bad (_("missing comma"));
2115 input_line_pointer++;
2117 #ifdef md_flush_pending_output
2118 md_flush_pending_output ();
2119 #endif
2121 #ifdef md_cons_align
2122 md_cons_align (4);
2123 #endif
2125 mapping_state (MAP_DATA);
2127 expression (&exp);
2129 p = frag_more (4);
2130 md_number_to_chars (p, highbit, 4);
2131 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2132 BFD_RELOC_ARM_PREL31);
2134 demand_empty_rest_of_line ();
2137 /* Directives: AEABI stack-unwind tables. */
2139 /* Parse an unwind_fnstart directive. Simply records the current location. */
2141 static void
2142 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
2144 demand_empty_rest_of_line ();
2145 /* Mark the start of the function. */
2146 unwind.proc_start = expr_build_dot ();
2148 /* Reset the rest of the unwind info. */
2149 unwind.opcode_count = 0;
2150 unwind.table_entry = NULL;
2151 unwind.personality_routine = NULL;
2152 unwind.personality_index = -1;
2153 unwind.frame_size = 0;
2154 unwind.fp_offset = 0;
2155 unwind.fp_reg = 13;
2156 unwind.fp_used = 0;
2157 unwind.sp_restored = 0;
2161 /* Parse a handlerdata directive. Creates the exception handling table entry
2162 for the function. */
2164 static void
2165 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
2167 demand_empty_rest_of_line ();
2168 if (unwind.table_entry)
2169 as_bad (_("dupicate .handlerdata directive"));
2171 create_unwind_entry (1);
2174 /* Parse an unwind_fnend directive. Generates the index table entry. */
2176 static void
2177 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
2179 long where;
2180 char *ptr;
2181 valueT val;
2183 demand_empty_rest_of_line ();
2185 /* Add eh table entry. */
2186 if (unwind.table_entry == NULL)
2187 val = create_unwind_entry (0);
2188 else
2189 val = 0;
2191 /* Add index table entry. This is two words. */
2192 start_unwind_section (unwind.saved_seg, 1);
2193 frag_align (2, 0, 0);
2194 record_alignment (now_seg, 2);
2196 ptr = frag_more (8);
2197 where = frag_now_fix () - 8;
2199 /* Self relative offset of the function start. */
2200 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
2201 BFD_RELOC_ARM_PREL31);
2203 /* Indicate dependency on EHABI-defined personality routines to the
2204 linker, if it hasn't been done already. */
2205 if (unwind.personality_index >= 0 && unwind.personality_index < 3
2206 && !(marked_pr_dependency & (1 << unwind.personality_index)))
2208 static const char *const name[] = {
2209 "__aeabi_unwind_cpp_pr0",
2210 "__aeabi_unwind_cpp_pr1",
2211 "__aeabi_unwind_cpp_pr2"
2213 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
2214 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
2215 marked_pr_dependency |= 1 << unwind.personality_index;
2216 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
2217 = marked_pr_dependency;
2220 if (val)
2221 /* Inline exception table entry. */
2222 md_number_to_chars (ptr + 4, val, 4);
2223 else
2224 /* Self relative offset of the table entry. */
2225 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
2226 BFD_RELOC_ARM_PREL31);
2228 /* Restore the original section. */
2229 subseg_set (unwind.saved_seg, unwind.saved_subseg);
2233 /* Parse an unwind_cantunwind directive. */
2235 static void
2236 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
2238 demand_empty_rest_of_line ();
2239 if (unwind.personality_routine || unwind.personality_index != -1)
2240 as_bad (_("personality routine specified for cantunwind frame"));
2242 unwind.personality_index = -2;
2246 /* Parse a personalityindex directive. */
2248 static void
2249 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
2251 expressionS exp;
2253 if (unwind.personality_routine || unwind.personality_index != -1)
2254 as_bad (_("duplicate .personalityindex directive"));
2256 expression (&exp);
2258 if (exp.X_op != O_constant
2259 || exp.X_add_number < 0 || exp.X_add_number > 15)
2261 as_bad (_("bad personality routine number"));
2262 ignore_rest_of_line ();
2263 return;
2266 unwind.personality_index = exp.X_add_number;
2268 demand_empty_rest_of_line ();
2272 /* Parse a personality directive. */
2274 static void
2275 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
2277 char *name, *p, c;
2279 if (unwind.personality_routine || unwind.personality_index != -1)
2280 as_bad (_("duplicate .personality directive"));
2282 name = input_line_pointer;
2283 c = get_symbol_end ();
2284 p = input_line_pointer;
2285 unwind.personality_routine = symbol_find_or_make (name);
2286 *p = c;
2287 demand_empty_rest_of_line ();
2291 /* Parse a directive saving core registers. */
2293 static void
2294 s_arm_unwind_save_core (void)
2296 valueT op;
2297 long range;
2298 int n;
2300 range = parse_reg_list (&input_line_pointer);
2301 if (range == FAIL)
2303 as_bad (_("expected register list"));
2304 ignore_rest_of_line ();
2305 return;
2308 demand_empty_rest_of_line ();
2310 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
2311 into .unwind_save {..., sp...}. We aren't bothered about the value of
2312 ip because it is clobbered by calls. */
2313 if (unwind.sp_restored && unwind.fp_reg == 12
2314 && (range & 0x3000) == 0x1000)
2316 unwind.opcode_count--;
2317 unwind.sp_restored = 0;
2318 range = (range | 0x2000) & ~0x1000;
2319 unwind.pending_offset = 0;
2322 /* Pop r4-r15. */
2323 if (range & 0xfff0)
2325 /* See if we can use the short opcodes. These pop a block of up to 8
2326 registers starting with r4, plus maybe r14. */
2327 for (n = 0; n < 8; n++)
2329 /* Break at the first non-saved register. */
2330 if ((range & (1 << (n + 4))) == 0)
2331 break;
2333 /* See if there are any other bits set. */
2334 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
2336 /* Use the long form. */
2337 op = 0x8000 | ((range >> 4) & 0xfff);
2338 add_unwind_opcode (op, 2);
2340 else
2342 /* Use the short form. */
2343 if (range & 0x4000)
2344 op = 0xa8; /* Pop r14. */
2345 else
2346 op = 0xa0; /* Do not pop r14. */
2347 op |= (n - 1);
2348 add_unwind_opcode (op, 1);
2352 /* Pop r0-r3. */
2353 if (range & 0xf)
2355 op = 0xb100 | (range & 0xf);
2356 add_unwind_opcode (op, 2);
2359 /* Record the number of bytes pushed. */
2360 for (n = 0; n < 16; n++)
2362 if (range & (1 << n))
2363 unwind.frame_size += 4;
2368 /* Parse a directive saving FPA registers. */
2370 static void
2371 s_arm_unwind_save_fpa (int reg)
2373 expressionS exp;
2374 int num_regs;
2375 valueT op;
2377 /* Get Number of registers to transfer. */
2378 if (skip_past_comma (&input_line_pointer) != FAIL)
2379 expression (&exp);
2380 else
2381 exp.X_op = O_illegal;
2383 if (exp.X_op != O_constant)
2385 as_bad (_("expected , <constant>"));
2386 ignore_rest_of_line ();
2387 return;
2390 num_regs = exp.X_add_number;
2392 if (num_regs < 1 || num_regs > 4)
2394 as_bad (_("number of registers must be in the range [1:4]"));
2395 ignore_rest_of_line ();
2396 return;
2399 demand_empty_rest_of_line ();
2401 if (reg == 4)
2403 /* Short form. */
2404 op = 0xb4 | (num_regs - 1);
2405 add_unwind_opcode (op, 1);
2407 else
2409 /* Long form. */
2410 op = 0xc800 | (reg << 4) | (num_regs - 1);
2411 add_unwind_opcode (op, 2);
2413 unwind.frame_size += num_regs * 12;
2417 /* Parse a directive saving VFP registers. */
2419 static void
2420 s_arm_unwind_save_vfp (void)
2422 int count;
2423 unsigned int reg;
2424 valueT op;
2426 count = parse_vfp_reg_list (&input_line_pointer, &reg, 1);
2427 if (count == FAIL)
2429 as_bad (_("expected register list"));
2430 ignore_rest_of_line ();
2431 return;
2434 demand_empty_rest_of_line ();
2436 if (reg == 8)
2438 /* Short form. */
2439 op = 0xb8 | (count - 1);
2440 add_unwind_opcode (op, 1);
2442 else
2444 /* Long form. */
2445 op = 0xb300 | (reg << 4) | (count - 1);
2446 add_unwind_opcode (op, 2);
2448 unwind.frame_size += count * 8 + 4;
2452 /* Parse a directive saving iWMMXt data registers. */
2454 static void
2455 s_arm_unwind_save_mmxwr (void)
2457 int reg;
2458 int hi_reg;
2459 int i;
2460 unsigned mask = 0;
2461 valueT op;
2463 if (*input_line_pointer == '{')
2464 input_line_pointer++;
2468 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2470 if (reg == FAIL)
2472 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2473 goto error;
2476 if (mask >> reg)
2477 as_tsktsk (_("register list not in ascending order"));
2478 mask |= 1 << reg;
2480 if (*input_line_pointer == '-')
2482 input_line_pointer++;
2483 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2484 if (hi_reg == FAIL)
2486 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2487 goto error;
2489 else if (reg >= hi_reg)
2491 as_bad (_("bad register range"));
2492 goto error;
2494 for (; reg < hi_reg; reg++)
2495 mask |= 1 << reg;
2498 while (skip_past_comma (&input_line_pointer) != FAIL);
2500 if (*input_line_pointer == '}')
2501 input_line_pointer++;
2503 demand_empty_rest_of_line ();
2505 /* Generate any deferred opcodes becuuse we're going to be looking at
2506 the list. */
2507 flush_pending_unwind ();
2509 for (i = 0; i < 16; i++)
2511 if (mask & (1 << i))
2512 unwind.frame_size += 8;
2515 /* Attempt to combine with a previous opcode. We do this because gcc
2516 likes to output separate unwind directives for a single block of
2517 registers. */
2518 if (unwind.opcode_count > 0)
2520 i = unwind.opcodes[unwind.opcode_count - 1];
2521 if ((i & 0xf8) == 0xc0)
2523 i &= 7;
2524 /* Only merge if the blocks are contiguous. */
2525 if (i < 6)
2527 if ((mask & 0xfe00) == (1 << 9))
2529 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
2530 unwind.opcode_count--;
2533 else if (i == 6 && unwind.opcode_count >= 2)
2535 i = unwind.opcodes[unwind.opcode_count - 2];
2536 reg = i >> 4;
2537 i &= 0xf;
2539 op = 0xffff << (reg - 1);
2540 if (reg > 0
2541 || ((mask & op) == (1u << (reg - 1))))
2543 op = (1 << (reg + i + 1)) - 1;
2544 op &= ~((1 << reg) - 1);
2545 mask |= op;
2546 unwind.opcode_count -= 2;
2552 hi_reg = 15;
2553 /* We want to generate opcodes in the order the registers have been
2554 saved, ie. descending order. */
2555 for (reg = 15; reg >= -1; reg--)
2557 /* Save registers in blocks. */
2558 if (reg < 0
2559 || !(mask & (1 << reg)))
2561 /* We found an unsaved reg. Generate opcodes to save the
2562 preceeding block. */
2563 if (reg != hi_reg)
2565 if (reg == 9)
2567 /* Short form. */
2568 op = 0xc0 | (hi_reg - 10);
2569 add_unwind_opcode (op, 1);
2571 else
2573 /* Long form. */
2574 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
2575 add_unwind_opcode (op, 2);
2578 hi_reg = reg - 1;
2582 return;
2583 error:
2584 ignore_rest_of_line ();
2587 static void
2588 s_arm_unwind_save_mmxwcg (void)
2590 int reg;
2591 int hi_reg;
2592 unsigned mask = 0;
2593 valueT op;
2595 if (*input_line_pointer == '{')
2596 input_line_pointer++;
2600 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2602 if (reg == FAIL)
2604 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2605 goto error;
2608 reg -= 8;
2609 if (mask >> reg)
2610 as_tsktsk (_("register list not in ascending order"));
2611 mask |= 1 << reg;
2613 if (*input_line_pointer == '-')
2615 input_line_pointer++;
2616 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2617 if (hi_reg == FAIL)
2619 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2620 goto error;
2622 else if (reg >= hi_reg)
2624 as_bad (_("bad register range"));
2625 goto error;
2627 for (; reg < hi_reg; reg++)
2628 mask |= 1 << reg;
2631 while (skip_past_comma (&input_line_pointer) != FAIL);
2633 if (*input_line_pointer == '}')
2634 input_line_pointer++;
2636 demand_empty_rest_of_line ();
2638 /* Generate any deferred opcodes becuuse we're going to be looking at
2639 the list. */
2640 flush_pending_unwind ();
2642 for (reg = 0; reg < 16; reg++)
2644 if (mask & (1 << reg))
2645 unwind.frame_size += 4;
2647 op = 0xc700 | mask;
2648 add_unwind_opcode (op, 2);
2649 return;
2650 error:
2651 ignore_rest_of_line ();
2655 /* Parse an unwind_save directive. */
2657 static void
2658 s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED)
2660 char *peek;
2661 struct reg_entry *reg;
2662 bfd_boolean had_brace = FALSE;
2664 /* Figure out what sort of save we have. */
2665 peek = input_line_pointer;
2667 if (*peek == '{')
2669 had_brace = TRUE;
2670 peek++;
2673 reg = arm_reg_parse_multi (&peek);
2675 if (!reg)
2677 as_bad (_("register expected"));
2678 ignore_rest_of_line ();
2679 return;
2682 switch (reg->type)
2684 case REG_TYPE_FN:
2685 if (had_brace)
2687 as_bad (_("FPA .unwind_save does not take a register list"));
2688 ignore_rest_of_line ();
2689 return;
2691 s_arm_unwind_save_fpa (reg->number);
2692 return;
2694 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
2695 case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return;
2696 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
2697 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
2699 default:
2700 as_bad (_(".unwind_save does not support this kind of register"));
2701 ignore_rest_of_line ();
2706 /* Parse an unwind_movsp directive. */
2708 static void
2709 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
2711 int reg;
2712 valueT op;
2714 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2715 if (reg == FAIL)
2717 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
2718 ignore_rest_of_line ();
2719 return;
2721 demand_empty_rest_of_line ();
2723 if (reg == REG_SP || reg == REG_PC)
2725 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
2726 return;
2729 if (unwind.fp_reg != REG_SP)
2730 as_bad (_("unexpected .unwind_movsp directive"));
2732 /* Generate opcode to restore the value. */
2733 op = 0x90 | reg;
2734 add_unwind_opcode (op, 1);
2736 /* Record the information for later. */
2737 unwind.fp_reg = reg;
2738 unwind.fp_offset = unwind.frame_size;
2739 unwind.sp_restored = 1;
2742 /* Parse an unwind_pad directive. */
2744 static void
2745 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
2747 int offset;
2749 if (immediate_for_directive (&offset) == FAIL)
2750 return;
2752 if (offset & 3)
2754 as_bad (_("stack increment must be multiple of 4"));
2755 ignore_rest_of_line ();
2756 return;
2759 /* Don't generate any opcodes, just record the details for later. */
2760 unwind.frame_size += offset;
2761 unwind.pending_offset += offset;
2763 demand_empty_rest_of_line ();
2766 /* Parse an unwind_setfp directive. */
2768 static void
2769 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
2771 int sp_reg;
2772 int fp_reg;
2773 int offset;
2775 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2776 if (skip_past_comma (&input_line_pointer) == FAIL)
2777 sp_reg = FAIL;
2778 else
2779 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2781 if (fp_reg == FAIL || sp_reg == FAIL)
2783 as_bad (_("expected <reg>, <reg>"));
2784 ignore_rest_of_line ();
2785 return;
2788 /* Optional constant. */
2789 if (skip_past_comma (&input_line_pointer) != FAIL)
2791 if (immediate_for_directive (&offset) == FAIL)
2792 return;
2794 else
2795 offset = 0;
2797 demand_empty_rest_of_line ();
2799 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
2801 as_bad (_("register must be either sp or set by a previous"
2802 "unwind_movsp directive"));
2803 return;
2806 /* Don't generate any opcodes, just record the information for later. */
2807 unwind.fp_reg = fp_reg;
2808 unwind.fp_used = 1;
2809 if (sp_reg == 13)
2810 unwind.fp_offset = unwind.frame_size - offset;
2811 else
2812 unwind.fp_offset -= offset;
2815 /* Parse an unwind_raw directive. */
2817 static void
2818 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
2820 expressionS exp;
2821 /* This is an arbitary limit. */
2822 unsigned char op[16];
2823 int count;
2825 expression (&exp);
2826 if (exp.X_op == O_constant
2827 && skip_past_comma (&input_line_pointer) != FAIL)
2829 unwind.frame_size += exp.X_add_number;
2830 expression (&exp);
2832 else
2833 exp.X_op = O_illegal;
2835 if (exp.X_op != O_constant)
2837 as_bad (_("expected <offset>, <opcode>"));
2838 ignore_rest_of_line ();
2839 return;
2842 count = 0;
2844 /* Parse the opcode. */
2845 for (;;)
2847 if (count >= 16)
2849 as_bad (_("unwind opcode too long"));
2850 ignore_rest_of_line ();
2852 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
2854 as_bad (_("invalid unwind opcode"));
2855 ignore_rest_of_line ();
2856 return;
2858 op[count++] = exp.X_add_number;
2860 /* Parse the next byte. */
2861 if (skip_past_comma (&input_line_pointer) == FAIL)
2862 break;
2864 expression (&exp);
2867 /* Add the opcode bytes in reverse order. */
2868 while (count--)
2869 add_unwind_opcode (op[count], 1);
2871 demand_empty_rest_of_line ();
2875 /* Parse a .eabi_attribute directive. */
2877 static void
2878 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
2880 expressionS exp;
2881 bfd_boolean is_string;
2882 int tag;
2883 unsigned int i = 0;
2884 char *s = NULL;
2885 char saved_char;
2887 expression (& exp);
2888 if (exp.X_op != O_constant)
2889 goto bad;
2891 tag = exp.X_add_number;
2892 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
2893 is_string = 1;
2894 else
2895 is_string = 0;
2897 if (skip_past_comma (&input_line_pointer) == FAIL)
2898 goto bad;
2899 if (tag == 32 || !is_string)
2901 expression (& exp);
2902 if (exp.X_op != O_constant)
2904 as_bad (_("expected numeric constant"));
2905 ignore_rest_of_line ();
2906 return;
2908 i = exp.X_add_number;
2910 if (tag == Tag_compatibility
2911 && skip_past_comma (&input_line_pointer) == FAIL)
2913 as_bad (_("expected comma"));
2914 ignore_rest_of_line ();
2915 return;
2917 if (is_string)
2919 skip_whitespace(input_line_pointer);
2920 if (*input_line_pointer != '"')
2921 goto bad_string;
2922 input_line_pointer++;
2923 s = input_line_pointer;
2924 while (*input_line_pointer && *input_line_pointer != '"')
2925 input_line_pointer++;
2926 if (*input_line_pointer != '"')
2927 goto bad_string;
2928 saved_char = *input_line_pointer;
2929 *input_line_pointer = 0;
2931 else
2933 s = NULL;
2934 saved_char = 0;
2937 if (tag == Tag_compatibility)
2938 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
2939 else if (is_string)
2940 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
2941 else
2942 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
2944 if (s)
2946 *input_line_pointer = saved_char;
2947 input_line_pointer++;
2949 demand_empty_rest_of_line ();
2950 return;
2951 bad_string:
2952 as_bad (_("bad string constant"));
2953 ignore_rest_of_line ();
2954 return;
2955 bad:
2956 as_bad (_("expected <tag> , <value>"));
2957 ignore_rest_of_line ();
2960 static void s_arm_arch (int);
2961 static void s_arm_cpu (int);
2962 static void s_arm_fpu (int);
2963 #endif /* OBJ_ELF */
2965 /* This table describes all the machine specific pseudo-ops the assembler
2966 has to support. The fields are:
2967 pseudo-op name without dot
2968 function to call to execute this pseudo-op
2969 Integer arg to pass to the function. */
2971 const pseudo_typeS md_pseudo_table[] =
2973 /* Never called because '.req' does not start a line. */
2974 { "req", s_req, 0 },
2975 { "unreq", s_unreq, 0 },
2976 { "bss", s_bss, 0 },
2977 { "align", s_align, 0 },
2978 { "arm", s_arm, 0 },
2979 { "thumb", s_thumb, 0 },
2980 { "code", s_code, 0 },
2981 { "force_thumb", s_force_thumb, 0 },
2982 { "thumb_func", s_thumb_func, 0 },
2983 { "thumb_set", s_thumb_set, 0 },
2984 { "even", s_even, 0 },
2985 { "ltorg", s_ltorg, 0 },
2986 { "pool", s_ltorg, 0 },
2987 { "syntax", s_syntax, 0 },
2988 #ifdef OBJ_ELF
2989 { "word", s_arm_elf_cons, 4 },
2990 { "long", s_arm_elf_cons, 4 },
2991 { "rel31", s_arm_rel31, 0 },
2992 { "fnstart", s_arm_unwind_fnstart, 0 },
2993 { "fnend", s_arm_unwind_fnend, 0 },
2994 { "cantunwind", s_arm_unwind_cantunwind, 0 },
2995 { "personality", s_arm_unwind_personality, 0 },
2996 { "personalityindex", s_arm_unwind_personalityindex, 0 },
2997 { "handlerdata", s_arm_unwind_handlerdata, 0 },
2998 { "save", s_arm_unwind_save, 0 },
2999 { "movsp", s_arm_unwind_movsp, 0 },
3000 { "pad", s_arm_unwind_pad, 0 },
3001 { "setfp", s_arm_unwind_setfp, 0 },
3002 { "unwind_raw", s_arm_unwind_raw, 0 },
3003 { "cpu", s_arm_cpu, 0 },
3004 { "arch", s_arm_arch, 0 },
3005 { "fpu", s_arm_fpu, 0 },
3006 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3007 #else
3008 { "word", cons, 4},
3009 #endif
3010 { "extend", float_cons, 'x' },
3011 { "ldouble", float_cons, 'x' },
3012 { "packed", float_cons, 'p' },
3013 { 0, 0, 0 }
3016 /* Parser functions used exclusively in instruction operands. */
3018 /* Generic immediate-value read function for use in insn parsing.
3019 STR points to the beginning of the immediate (the leading #);
3020 VAL receives the value; if the value is outside [MIN, MAX]
3021 issue an error. PREFIX_OPT is true if the immediate prefix is
3022 optional. */
3024 static int
3025 parse_immediate (char **str, int *val, int min, int max,
3026 bfd_boolean prefix_opt)
3028 expressionS exp;
3029 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3030 if (exp.X_op != O_constant)
3032 inst.error = _("constant expression required");
3033 return FAIL;
3036 if (exp.X_add_number < min || exp.X_add_number > max)
3038 inst.error = _("immediate value out of range");
3039 return FAIL;
3042 *val = exp.X_add_number;
3043 return SUCCESS;
3046 /* Returns the pseudo-register number of an FPA immediate constant,
3047 or FAIL if there isn't a valid constant here. */
3049 static int
3050 parse_fpa_immediate (char ** str)
3052 LITTLENUM_TYPE words[MAX_LITTLENUMS];
3053 char * save_in;
3054 expressionS exp;
3055 int i;
3056 int j;
3058 /* First try and match exact strings, this is to guarantee
3059 that some formats will work even for cross assembly. */
3061 for (i = 0; fp_const[i]; i++)
3063 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
3065 char *start = *str;
3067 *str += strlen (fp_const[i]);
3068 if (is_end_of_line[(unsigned char) **str])
3069 return i + 8;
3070 *str = start;
3074 /* Just because we didn't get a match doesn't mean that the constant
3075 isn't valid, just that it is in a format that we don't
3076 automatically recognize. Try parsing it with the standard
3077 expression routines. */
3079 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
3081 /* Look for a raw floating point number. */
3082 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
3083 && is_end_of_line[(unsigned char) *save_in])
3085 for (i = 0; i < NUM_FLOAT_VALS; i++)
3087 for (j = 0; j < MAX_LITTLENUMS; j++)
3089 if (words[j] != fp_values[i][j])
3090 break;
3093 if (j == MAX_LITTLENUMS)
3095 *str = save_in;
3096 return i + 8;
3101 /* Try and parse a more complex expression, this will probably fail
3102 unless the code uses a floating point prefix (eg "0f"). */
3103 save_in = input_line_pointer;
3104 input_line_pointer = *str;
3105 if (expression (&exp) == absolute_section
3106 && exp.X_op == O_big
3107 && exp.X_add_number < 0)
3109 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
3110 Ditto for 15. */
3111 if (gen_to_words (words, 5, (long) 15) == 0)
3113 for (i = 0; i < NUM_FLOAT_VALS; i++)
3115 for (j = 0; j < MAX_LITTLENUMS; j++)
3117 if (words[j] != fp_values[i][j])
3118 break;
3121 if (j == MAX_LITTLENUMS)
3123 *str = input_line_pointer;
3124 input_line_pointer = save_in;
3125 return i + 8;
3131 *str = input_line_pointer;
3132 input_line_pointer = save_in;
3133 inst.error = _("invalid FPA immediate expression");
3134 return FAIL;
3137 /* Shift operands. */
3138 enum shift_kind
3140 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
3143 struct asm_shift_name
3145 const char *name;
3146 enum shift_kind kind;
3149 /* Third argument to parse_shift. */
3150 enum parse_shift_mode
3152 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
3153 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
3154 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
3155 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
3156 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
3159 /* Parse a <shift> specifier on an ARM data processing instruction.
3160 This has three forms:
3162 (LSL|LSR|ASL|ASR|ROR) Rs
3163 (LSL|LSR|ASL|ASR|ROR) #imm
3166 Note that ASL is assimilated to LSL in the instruction encoding, and
3167 RRX to ROR #0 (which cannot be written as such). */
3169 static int
3170 parse_shift (char **str, int i, enum parse_shift_mode mode)
3172 const struct asm_shift_name *shift_name;
3173 enum shift_kind shift;
3174 char *s = *str;
3175 char *p = s;
3176 int reg;
3178 for (p = *str; ISALPHA (*p); p++)
3181 if (p == *str)
3183 inst.error = _("shift expression expected");
3184 return FAIL;
3187 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
3189 if (shift_name == NULL)
3191 inst.error = _("shift expression expected");
3192 return FAIL;
3195 shift = shift_name->kind;
3197 switch (mode)
3199 case NO_SHIFT_RESTRICT:
3200 case SHIFT_IMMEDIATE: break;
3202 case SHIFT_LSL_OR_ASR_IMMEDIATE:
3203 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
3205 inst.error = _("'LSL' or 'ASR' required");
3206 return FAIL;
3208 break;
3210 case SHIFT_LSL_IMMEDIATE:
3211 if (shift != SHIFT_LSL)
3213 inst.error = _("'LSL' required");
3214 return FAIL;
3216 break;
3218 case SHIFT_ASR_IMMEDIATE:
3219 if (shift != SHIFT_ASR)
3221 inst.error = _("'ASR' required");
3222 return FAIL;
3224 break;
3226 default: abort ();
3229 if (shift != SHIFT_RRX)
3231 /* Whitespace can appear here if the next thing is a bare digit. */
3232 skip_whitespace (p);
3234 if (mode == NO_SHIFT_RESTRICT
3235 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3237 inst.operands[i].imm = reg;
3238 inst.operands[i].immisreg = 1;
3240 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3241 return FAIL;
3243 inst.operands[i].shift_kind = shift;
3244 inst.operands[i].shifted = 1;
3245 *str = p;
3246 return SUCCESS;
3249 /* Parse a <shifter_operand> for an ARM data processing instruction:
3251 #<immediate>
3252 #<immediate>, <rotate>
3253 <Rm>
3254 <Rm>, <shift>
3256 where <shift> is defined by parse_shift above, and <rotate> is a
3257 multiple of 2 between 0 and 30. Validation of immediate operands
3258 is deferred to md_apply_fix. */
3260 static int
3261 parse_shifter_operand (char **str, int i)
3263 int value;
3264 expressionS expr;
3266 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
3268 inst.operands[i].reg = value;
3269 inst.operands[i].isreg = 1;
3271 /* parse_shift will override this if appropriate */
3272 inst.reloc.exp.X_op = O_constant;
3273 inst.reloc.exp.X_add_number = 0;
3275 if (skip_past_comma (str) == FAIL)
3276 return SUCCESS;
3278 /* Shift operation on register. */
3279 return parse_shift (str, i, NO_SHIFT_RESTRICT);
3282 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
3283 return FAIL;
3285 if (skip_past_comma (str) == SUCCESS)
3287 /* #x, y -- ie explicit rotation by Y. */
3288 if (my_get_expression (&expr, str, GE_NO_PREFIX))
3289 return FAIL;
3291 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
3293 inst.error = _("constant expression expected");
3294 return FAIL;
3297 value = expr.X_add_number;
3298 if (value < 0 || value > 30 || value % 2 != 0)
3300 inst.error = _("invalid rotation");
3301 return FAIL;
3303 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
3305 inst.error = _("invalid constant");
3306 return FAIL;
3309 /* Convert to decoded value. md_apply_fix will put it back. */
3310 inst.reloc.exp.X_add_number
3311 = (((inst.reloc.exp.X_add_number << (32 - value))
3312 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
3315 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
3316 inst.reloc.pc_rel = 0;
3317 return SUCCESS;
3320 /* Parse all forms of an ARM address expression. Information is written
3321 to inst.operands[i] and/or inst.reloc.
3323 Preindexed addressing (.preind=1):
3325 [Rn, #offset] .reg=Rn .reloc.exp=offset
3326 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3327 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3328 .shift_kind=shift .reloc.exp=shift_imm
3330 These three may have a trailing ! which causes .writeback to be set also.
3332 Postindexed addressing (.postind=1, .writeback=1):
3334 [Rn], #offset .reg=Rn .reloc.exp=offset
3335 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3336 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3337 .shift_kind=shift .reloc.exp=shift_imm
3339 Unindexed addressing (.preind=0, .postind=0):
3341 [Rn], {option} .reg=Rn .imm=option .immisreg=0
3343 Other:
3345 [Rn]{!} shorthand for [Rn,#0]{!}
3346 =immediate .isreg=0 .reloc.exp=immediate
3347 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
3349 It is the caller's responsibility to check for addressing modes not
3350 supported by the instruction, and to set inst.reloc.type. */
3352 static int
3353 parse_address (char **str, int i)
3355 char *p = *str;
3356 int reg;
3358 if (skip_past_char (&p, '[') == FAIL)
3360 if (skip_past_char (&p, '=') == FAIL)
3362 /* bare address - translate to PC-relative offset */
3363 inst.reloc.pc_rel = 1;
3364 inst.operands[i].reg = REG_PC;
3365 inst.operands[i].isreg = 1;
3366 inst.operands[i].preind = 1;
3368 /* else a load-constant pseudo op, no special treatment needed here */
3370 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
3371 return FAIL;
3373 *str = p;
3374 return SUCCESS;
3377 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3379 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3380 return FAIL;
3382 inst.operands[i].reg = reg;
3383 inst.operands[i].isreg = 1;
3385 if (skip_past_comma (&p) == SUCCESS)
3387 inst.operands[i].preind = 1;
3389 if (*p == '+') p++;
3390 else if (*p == '-') p++, inst.operands[i].negative = 1;
3392 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3394 inst.operands[i].imm = reg;
3395 inst.operands[i].immisreg = 1;
3397 if (skip_past_comma (&p) == SUCCESS)
3398 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3399 return FAIL;
3401 else
3403 if (inst.operands[i].negative)
3405 inst.operands[i].negative = 0;
3406 p--;
3408 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3409 return FAIL;
3413 if (skip_past_char (&p, ']') == FAIL)
3415 inst.error = _("']' expected");
3416 return FAIL;
3419 if (skip_past_char (&p, '!') == SUCCESS)
3420 inst.operands[i].writeback = 1;
3422 else if (skip_past_comma (&p) == SUCCESS)
3424 if (skip_past_char (&p, '{') == SUCCESS)
3426 /* [Rn], {expr} - unindexed, with option */
3427 if (parse_immediate (&p, &inst.operands[i].imm,
3428 0, 255, TRUE) == FAIL)
3429 return FAIL;
3431 if (skip_past_char (&p, '}') == FAIL)
3433 inst.error = _("'}' expected at end of 'option' field");
3434 return FAIL;
3436 if (inst.operands[i].preind)
3438 inst.error = _("cannot combine index with option");
3439 return FAIL;
3441 *str = p;
3442 return SUCCESS;
3444 else
3446 inst.operands[i].postind = 1;
3447 inst.operands[i].writeback = 1;
3449 if (inst.operands[i].preind)
3451 inst.error = _("cannot combine pre- and post-indexing");
3452 return FAIL;
3455 if (*p == '+') p++;
3456 else if (*p == '-') p++, inst.operands[i].negative = 1;
3458 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3460 inst.operands[i].imm = reg;
3461 inst.operands[i].immisreg = 1;
3463 if (skip_past_comma (&p) == SUCCESS)
3464 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3465 return FAIL;
3467 else
3469 if (inst.operands[i].negative)
3471 inst.operands[i].negative = 0;
3472 p--;
3474 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3475 return FAIL;
3480 /* If at this point neither .preind nor .postind is set, we have a
3481 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
3482 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
3484 inst.operands[i].preind = 1;
3485 inst.reloc.exp.X_op = O_constant;
3486 inst.reloc.exp.X_add_number = 0;
3488 *str = p;
3489 return SUCCESS;
3492 /* Miscellaneous. */
3494 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
3495 or a bitmask suitable to be or-ed into the ARM msr instruction. */
3496 static int
3497 parse_psr (char **str)
3499 char *p;
3500 unsigned long psr_field;
3501 const struct asm_psr *psr;
3502 char *start;
3504 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
3505 feature for ease of use and backwards compatibility. */
3506 p = *str;
3507 if (strncasecmp (p, "SPSR", 4) == 0)
3508 psr_field = SPSR_BIT;
3509 else if (strncasecmp (p, "CPSR", 4) == 0)
3510 psr_field = 0;
3511 else
3513 start = p;
3515 p++;
3516 while (ISALNUM (*p) || *p == '_');
3518 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
3519 if (!psr)
3520 return FAIL;
3522 *str = p;
3523 return psr->field;
3526 p += 4;
3527 if (*p == '_')
3529 /* A suffix follows. */
3530 p++;
3531 start = p;
3534 p++;
3535 while (ISALNUM (*p) || *p == '_');
3537 psr = hash_find_n (arm_psr_hsh, start, p - start);
3538 if (!psr)
3539 goto error;
3541 psr_field |= psr->field;
3543 else
3545 if (ISALNUM (*p))
3546 goto error; /* Garbage after "[CS]PSR". */
3548 psr_field |= (PSR_c | PSR_f);
3550 *str = p;
3551 return psr_field;
3553 error:
3554 inst.error = _("flag for {c}psr instruction expected");
3555 return FAIL;
3558 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
3559 value suitable for splatting into the AIF field of the instruction. */
3561 static int
3562 parse_cps_flags (char **str)
3564 int val = 0;
3565 int saw_a_flag = 0;
3566 char *s = *str;
3568 for (;;)
3569 switch (*s++)
3571 case '\0': case ',':
3572 goto done;
3574 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
3575 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
3576 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
3578 default:
3579 inst.error = _("unrecognized CPS flag");
3580 return FAIL;
3583 done:
3584 if (saw_a_flag == 0)
3586 inst.error = _("missing CPS flags");
3587 return FAIL;
3590 *str = s - 1;
3591 return val;
3594 /* Parse an endian specifier ("BE" or "LE", case insensitive);
3595 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
3597 static int
3598 parse_endian_specifier (char **str)
3600 int little_endian;
3601 char *s = *str;
3603 if (strncasecmp (s, "BE", 2))
3604 little_endian = 0;
3605 else if (strncasecmp (s, "LE", 2))
3606 little_endian = 1;
3607 else
3609 inst.error = _("valid endian specifiers are be or le");
3610 return FAIL;
3613 if (ISALNUM (s[2]) || s[2] == '_')
3615 inst.error = _("valid endian specifiers are be or le");
3616 return FAIL;
3619 *str = s + 2;
3620 return little_endian;
3623 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
3624 value suitable for poking into the rotate field of an sxt or sxta
3625 instruction, or FAIL on error. */
3627 static int
3628 parse_ror (char **str)
3630 int rot;
3631 char *s = *str;
3633 if (strncasecmp (s, "ROR", 3) == 0)
3634 s += 3;
3635 else
3637 inst.error = _("missing rotation field after comma");
3638 return FAIL;
3641 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
3642 return FAIL;
3644 switch (rot)
3646 case 0: *str = s; return 0x0;
3647 case 8: *str = s; return 0x1;
3648 case 16: *str = s; return 0x2;
3649 case 24: *str = s; return 0x3;
3651 default:
3652 inst.error = _("rotation can only be 0, 8, 16, or 24");
3653 return FAIL;
3657 /* Parse a conditional code (from conds[] below). The value returned is in the
3658 range 0 .. 14, or FAIL. */
3659 static int
3660 parse_cond (char **str)
3662 char *p, *q;
3663 const struct asm_cond *c;
3665 p = q = *str;
3666 while (ISALPHA (*q))
3667 q++;
3669 c = hash_find_n (arm_cond_hsh, p, q - p);
3670 if (!c)
3672 inst.error = _("condition required");
3673 return FAIL;
3676 *str = q;
3677 return c->value;
3680 /* Parse an option for a barrier instruction. Returns the encoding for the
3681 option, or FAIL. */
3682 static int
3683 parse_barrier (char **str)
3685 char *p, *q;
3686 const struct asm_barrier_opt *o;
3688 p = q = *str;
3689 while (ISALPHA (*q))
3690 q++;
3692 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
3693 if (!o)
3694 return FAIL;
3696 *str = q;
3697 return o->value;
3700 /* Parse the operands of a table branch instruction. Similar to a memory
3701 operand. */
3702 static int
3703 parse_tb (char **str)
3705 char * p = *str;
3706 int reg;
3708 if (skip_past_char (&p, '[') == FAIL)
3710 inst.error = _("'[' expected");
3711 return FAIL;
3714 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3716 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3717 return FAIL;
3719 inst.operands[0].reg = reg;
3721 if (skip_past_comma (&p) == FAIL)
3723 inst.error = _("',' expected");
3724 return FAIL;
3727 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3729 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3730 return FAIL;
3732 inst.operands[0].imm = reg;
3734 if (skip_past_comma (&p) == SUCCESS)
3736 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
3737 return FAIL;
3738 if (inst.reloc.exp.X_add_number != 1)
3740 inst.error = _("invalid shift");
3741 return FAIL;
3743 inst.operands[0].shifted = 1;
3746 if (skip_past_char (&p, ']') == FAIL)
3748 inst.error = _("']' expected");
3749 return FAIL;
3751 *str = p;
3752 return SUCCESS;
3755 /* Matcher codes for parse_operands. */
3756 enum operand_parse_code
3758 OP_stop, /* end of line */
3760 OP_RR, /* ARM register */
3761 OP_RRnpc, /* ARM register, not r15 */
3762 OP_RRnpcb, /* ARM register, not r15, in square brackets */
3763 OP_RRw, /* ARM register, not r15, optional trailing ! */
3764 OP_RCP, /* Coprocessor number */
3765 OP_RCN, /* Coprocessor register */
3766 OP_RF, /* FPA register */
3767 OP_RVS, /* VFP single precision register */
3768 OP_RVD, /* VFP double precision register */
3769 OP_RVC, /* VFP control register */
3770 OP_RMF, /* Maverick F register */
3771 OP_RMD, /* Maverick D register */
3772 OP_RMFX, /* Maverick FX register */
3773 OP_RMDX, /* Maverick DX register */
3774 OP_RMAX, /* Maverick AX register */
3775 OP_RMDS, /* Maverick DSPSC register */
3776 OP_RIWR, /* iWMMXt wR register */
3777 OP_RIWC, /* iWMMXt wC register */
3778 OP_RIWG, /* iWMMXt wCG register */
3779 OP_RXA, /* XScale accumulator register */
3781 OP_REGLST, /* ARM register list */
3782 OP_VRSLST, /* VFP single-precision register list */
3783 OP_VRDLST, /* VFP double-precision register list */
3785 OP_I7, /* immediate value 0 .. 7 */
3786 OP_I15, /* 0 .. 15 */
3787 OP_I16, /* 1 .. 16 */
3788 OP_I31, /* 0 .. 31 */
3789 OP_I31w, /* 0 .. 31, optional trailing ! */
3790 OP_I32, /* 1 .. 32 */
3791 OP_I63s, /* -64 .. 63 */
3792 OP_I255, /* 0 .. 255 */
3793 OP_Iffff, /* 0 .. 65535 */
3795 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
3796 OP_I7b, /* 0 .. 7 */
3797 OP_I15b, /* 0 .. 15 */
3798 OP_I31b, /* 0 .. 31 */
3800 OP_SH, /* shifter operand */
3801 OP_ADDR, /* Memory address expression (any mode) */
3802 OP_EXP, /* arbitrary expression */
3803 OP_EXPi, /* same, with optional immediate prefix */
3804 OP_EXPr, /* same, with optional relocation suffix */
3806 OP_CPSF, /* CPS flags */
3807 OP_ENDI, /* Endianness specifier */
3808 OP_PSR, /* CPSR/SPSR mask for msr */
3809 OP_COND, /* conditional code */
3810 OP_TB, /* Table branch. */
3812 OP_RRnpc_I0, /* ARM register or literal 0 */
3813 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
3814 OP_RR_EXi, /* ARM register or expression with imm prefix */
3815 OP_RF_IF, /* FPA register or immediate */
3816 OP_RIWR_RIWC, /* iWMMXt R or C reg */
3818 /* Optional operands. */
3819 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
3820 OP_oI31b, /* 0 .. 31 */
3821 OP_oIffffb, /* 0 .. 65535 */
3822 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
3824 OP_oRR, /* ARM register */
3825 OP_oRRnpc, /* ARM register, not the PC */
3826 OP_oSHll, /* LSL immediate */
3827 OP_oSHar, /* ASR immediate */
3828 OP_oSHllar, /* LSL or ASR immediate */
3829 OP_oROR, /* ROR 0/8/16/24 */
3830 OP_oBARRIER, /* Option argument for a barrier instruction. */
3832 OP_FIRST_OPTIONAL = OP_oI7b
3835 /* Generic instruction operand parser. This does no encoding and no
3836 semantic validation; it merely squirrels values away in the inst
3837 structure. Returns SUCCESS or FAIL depending on whether the
3838 specified grammar matched. */
3839 static int
3840 parse_operands (char *str, const unsigned char *pattern)
3842 unsigned const char *upat = pattern;
3843 char *backtrack_pos = 0;
3844 const char *backtrack_error = 0;
3845 int i, val, backtrack_index = 0;
3847 #define po_char_or_fail(chr) do { \
3848 if (skip_past_char (&str, chr) == FAIL) \
3849 goto bad_args; \
3850 } while (0)
3852 #define po_reg_or_fail(regtype) do { \
3853 val = arm_reg_parse (&str, regtype); \
3854 if (val == FAIL) \
3856 inst.error = _(reg_expected_msgs[regtype]); \
3857 goto failure; \
3859 inst.operands[i].reg = val; \
3860 inst.operands[i].isreg = 1; \
3861 } while (0)
3863 #define po_reg_or_goto(regtype, label) do { \
3864 val = arm_reg_parse (&str, regtype); \
3865 if (val == FAIL) \
3866 goto label; \
3868 inst.operands[i].reg = val; \
3869 inst.operands[i].isreg = 1; \
3870 } while (0)
3872 #define po_imm_or_fail(min, max, popt) do { \
3873 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
3874 goto failure; \
3875 inst.operands[i].imm = val; \
3876 } while (0)
3878 #define po_misc_or_fail(expr) do { \
3879 if (expr) \
3880 goto failure; \
3881 } while (0)
3883 skip_whitespace (str);
3885 for (i = 0; upat[i] != OP_stop; i++)
3887 if (upat[i] >= OP_FIRST_OPTIONAL)
3889 /* Remember where we are in case we need to backtrack. */
3890 assert (!backtrack_pos);
3891 backtrack_pos = str;
3892 backtrack_error = inst.error;
3893 backtrack_index = i;
3896 if (i > 0)
3897 po_char_or_fail (',');
3899 switch (upat[i])
3901 /* Registers */
3902 case OP_oRRnpc:
3903 case OP_RRnpc:
3904 case OP_oRR:
3905 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
3906 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
3907 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
3908 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
3909 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
3910 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
3911 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
3912 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
3913 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
3914 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
3915 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
3916 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
3917 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
3918 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
3919 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
3920 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
3921 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
3923 case OP_RRnpcb:
3924 po_char_or_fail ('[');
3925 po_reg_or_fail (REG_TYPE_RN);
3926 po_char_or_fail (']');
3927 break;
3929 case OP_RRw:
3930 po_reg_or_fail (REG_TYPE_RN);
3931 if (skip_past_char (&str, '!') == SUCCESS)
3932 inst.operands[i].writeback = 1;
3933 break;
3935 /* Immediates */
3936 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
3937 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
3938 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
3939 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
3940 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
3941 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
3942 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
3943 case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break;
3945 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
3946 case OP_oI7b:
3947 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
3948 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
3949 case OP_oI31b:
3950 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
3951 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
3953 /* Immediate variants */
3954 case OP_oI255c:
3955 po_char_or_fail ('{');
3956 po_imm_or_fail (0, 255, TRUE);
3957 po_char_or_fail ('}');
3958 break;
3960 case OP_I31w:
3961 /* The expression parser chokes on a trailing !, so we have
3962 to find it first and zap it. */
3964 char *s = str;
3965 while (*s && *s != ',')
3966 s++;
3967 if (s[-1] == '!')
3969 s[-1] = '\0';
3970 inst.operands[i].writeback = 1;
3972 po_imm_or_fail (0, 31, TRUE);
3973 if (str == s - 1)
3974 str = s;
3976 break;
3978 /* Expressions */
3979 case OP_EXPi: EXPi:
3980 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3981 GE_OPT_PREFIX));
3982 break;
3984 case OP_EXP:
3985 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3986 GE_NO_PREFIX));
3987 break;
3989 case OP_EXPr: EXPr:
3990 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3991 GE_NO_PREFIX));
3992 if (inst.reloc.exp.X_op == O_symbol)
3994 val = parse_reloc (&str);
3995 if (val == -1)
3997 inst.error = _("unrecognized relocation suffix");
3998 goto failure;
4000 else if (val != BFD_RELOC_UNUSED)
4002 inst.operands[i].imm = val;
4003 inst.operands[i].hasreloc = 1;
4006 break;
4008 /* Register or expression */
4009 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
4010 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
4012 /* Register or immediate */
4013 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
4014 I0: po_imm_or_fail (0, 0, FALSE); break;
4016 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
4018 if (!is_immediate_prefix (*str))
4019 goto bad_args;
4020 str++;
4021 val = parse_fpa_immediate (&str);
4022 if (val == FAIL)
4023 goto failure;
4024 /* FPA immediates are encoded as registers 8-15.
4025 parse_fpa_immediate has already applied the offset. */
4026 inst.operands[i].reg = val;
4027 inst.operands[i].isreg = 1;
4028 break;
4030 /* Two kinds of register */
4031 case OP_RIWR_RIWC:
4033 struct reg_entry *rege = arm_reg_parse_multi (&str);
4034 if (rege->type != REG_TYPE_MMXWR
4035 && rege->type != REG_TYPE_MMXWC
4036 && rege->type != REG_TYPE_MMXWCG)
4038 inst.error = _("iWMMXt data or control register expected");
4039 goto failure;
4041 inst.operands[i].reg = rege->number;
4042 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
4044 break;
4046 /* Misc */
4047 case OP_CPSF: val = parse_cps_flags (&str); break;
4048 case OP_ENDI: val = parse_endian_specifier (&str); break;
4049 case OP_oROR: val = parse_ror (&str); break;
4050 case OP_PSR: val = parse_psr (&str); break;
4051 case OP_COND: val = parse_cond (&str); break;
4052 case OP_oBARRIER:val = parse_barrier (&str); break;
4054 case OP_TB:
4055 po_misc_or_fail (parse_tb (&str));
4056 break;
4058 /* Register lists */
4059 case OP_REGLST:
4060 val = parse_reg_list (&str);
4061 if (*str == '^')
4063 inst.operands[1].writeback = 1;
4064 str++;
4066 break;
4068 case OP_VRSLST:
4069 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0);
4070 break;
4072 case OP_VRDLST:
4073 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1);
4074 break;
4076 /* Addressing modes */
4077 case OP_ADDR:
4078 po_misc_or_fail (parse_address (&str, i));
4079 break;
4081 case OP_SH:
4082 po_misc_or_fail (parse_shifter_operand (&str, i));
4083 break;
4085 case OP_oSHll:
4086 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
4087 break;
4089 case OP_oSHar:
4090 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
4091 break;
4093 case OP_oSHllar:
4094 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
4095 break;
4097 default:
4098 as_fatal ("unhandled operand code %d", upat[i]);
4101 /* Various value-based sanity checks and shared operations. We
4102 do not signal immediate failures for the register constraints;
4103 this allows a syntax error to take precedence. */
4104 switch (upat[i])
4106 case OP_oRRnpc:
4107 case OP_RRnpc:
4108 case OP_RRnpcb:
4109 case OP_RRw:
4110 case OP_RRnpc_I0:
4111 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
4112 inst.error = BAD_PC;
4113 break;
4115 case OP_CPSF:
4116 case OP_ENDI:
4117 case OP_oROR:
4118 case OP_PSR:
4119 case OP_COND:
4120 case OP_oBARRIER:
4121 case OP_REGLST:
4122 case OP_VRSLST:
4123 case OP_VRDLST:
4124 if (val == FAIL)
4125 goto failure;
4126 inst.operands[i].imm = val;
4127 break;
4129 default:
4130 break;
4133 /* If we get here, this operand was successfully parsed. */
4134 inst.operands[i].present = 1;
4135 continue;
4137 bad_args:
4138 inst.error = BAD_ARGS;
4140 failure:
4141 if (!backtrack_pos)
4143 /* The parse routine should already have set inst.error, but set a
4144 defaut here just in case. */
4145 if (!inst.error)
4146 inst.error = _("syntax error");
4147 return FAIL;
4150 /* Do not backtrack over a trailing optional argument that
4151 absorbed some text. We will only fail again, with the
4152 'garbage following instruction' error message, which is
4153 probably less helpful than the current one. */
4154 if (backtrack_index == i && backtrack_pos != str
4155 && upat[i+1] == OP_stop)
4157 if (!inst.error)
4158 inst.error = _("syntax error");
4159 return FAIL;
4162 /* Try again, skipping the optional argument at backtrack_pos. */
4163 str = backtrack_pos;
4164 inst.error = backtrack_error;
4165 inst.operands[backtrack_index].present = 0;
4166 i = backtrack_index;
4167 backtrack_pos = 0;
4170 /* Check that we have parsed all the arguments. */
4171 if (*str != '\0' && !inst.error)
4172 inst.error = _("garbage following instruction");
4174 return inst.error ? FAIL : SUCCESS;
4177 #undef po_char_or_fail
4178 #undef po_reg_or_fail
4179 #undef po_reg_or_goto
4180 #undef po_imm_or_fail
4182 /* Shorthand macro for instruction encoding functions issuing errors. */
4183 #define constraint(expr, err) do { \
4184 if (expr) \
4186 inst.error = err; \
4187 return; \
4189 } while (0)
4191 /* Functions for operand encoding. ARM, then Thumb. */
4193 #define rotate_left(v, n) (v << n | v >> (32 - n))
4195 /* If VAL can be encoded in the immediate field of an ARM instruction,
4196 return the encoded form. Otherwise, return FAIL. */
4198 static unsigned int
4199 encode_arm_immediate (unsigned int val)
4201 unsigned int a, i;
4203 for (i = 0; i < 32; i += 2)
4204 if ((a = rotate_left (val, i)) <= 0xff)
4205 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
4207 return FAIL;
4210 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
4211 return the encoded form. Otherwise, return FAIL. */
4212 static unsigned int
4213 encode_thumb32_immediate (unsigned int val)
4215 unsigned int a, i;
4217 if (val <= 0xff)
4218 return val;
4220 for (i = 1; i <= 24; i++)
4222 a = val >> i;
4223 if ((val & ~(0xff << i)) == 0)
4224 return ((val >> i) & 0x7f) | ((32 - i) << 7);
4227 a = val & 0xff;
4228 if (val == ((a << 16) | a))
4229 return 0x100 | a;
4230 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
4231 return 0x300 | a;
4233 a = val & 0xff00;
4234 if (val == ((a << 16) | a))
4235 return 0x200 | (a >> 8);
4237 return FAIL;
4239 /* Encode a VFP SP register number into inst.instruction. */
4241 static void
4242 encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos)
4244 switch (pos)
4246 case VFP_REG_Sd:
4247 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
4248 break;
4250 case VFP_REG_Sn:
4251 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
4252 break;
4254 case VFP_REG_Sm:
4255 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
4256 break;
4258 default:
4259 abort ();
4263 /* Encode a <shift> in an ARM-format instruction. The immediate,
4264 if any, is handled by md_apply_fix. */
4265 static void
4266 encode_arm_shift (int i)
4268 if (inst.operands[i].shift_kind == SHIFT_RRX)
4269 inst.instruction |= SHIFT_ROR << 5;
4270 else
4272 inst.instruction |= inst.operands[i].shift_kind << 5;
4273 if (inst.operands[i].immisreg)
4275 inst.instruction |= SHIFT_BY_REG;
4276 inst.instruction |= inst.operands[i].imm << 8;
4278 else
4279 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4283 static void
4284 encode_arm_shifter_operand (int i)
4286 if (inst.operands[i].isreg)
4288 inst.instruction |= inst.operands[i].reg;
4289 encode_arm_shift (i);
4291 else
4292 inst.instruction |= INST_IMMEDIATE;
4295 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
4296 static void
4297 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
4299 assert (inst.operands[i].isreg);
4300 inst.instruction |= inst.operands[i].reg << 16;
4302 if (inst.operands[i].preind)
4304 if (is_t)
4306 inst.error = _("instruction does not accept preindexed addressing");
4307 return;
4309 inst.instruction |= PRE_INDEX;
4310 if (inst.operands[i].writeback)
4311 inst.instruction |= WRITE_BACK;
4314 else if (inst.operands[i].postind)
4316 assert (inst.operands[i].writeback);
4317 if (is_t)
4318 inst.instruction |= WRITE_BACK;
4320 else /* unindexed - only for coprocessor */
4322 inst.error = _("instruction does not accept unindexed addressing");
4323 return;
4326 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
4327 && (((inst.instruction & 0x000f0000) >> 16)
4328 == ((inst.instruction & 0x0000f000) >> 12)))
4329 as_warn ((inst.instruction & LOAD_BIT)
4330 ? _("destination register same as write-back base")
4331 : _("source register same as write-back base"));
4334 /* inst.operands[i] was set up by parse_address. Encode it into an
4335 ARM-format mode 2 load or store instruction. If is_t is true,
4336 reject forms that cannot be used with a T instruction (i.e. not
4337 post-indexed). */
4338 static void
4339 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
4341 encode_arm_addr_mode_common (i, is_t);
4343 if (inst.operands[i].immisreg)
4345 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
4346 inst.instruction |= inst.operands[i].imm;
4347 if (!inst.operands[i].negative)
4348 inst.instruction |= INDEX_UP;
4349 if (inst.operands[i].shifted)
4351 if (inst.operands[i].shift_kind == SHIFT_RRX)
4352 inst.instruction |= SHIFT_ROR << 5;
4353 else
4355 inst.instruction |= inst.operands[i].shift_kind << 5;
4356 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4360 else /* immediate offset in inst.reloc */
4362 if (inst.reloc.type == BFD_RELOC_UNUSED)
4363 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
4367 /* inst.operands[i] was set up by parse_address. Encode it into an
4368 ARM-format mode 3 load or store instruction. Reject forms that
4369 cannot be used with such instructions. If is_t is true, reject
4370 forms that cannot be used with a T instruction (i.e. not
4371 post-indexed). */
4372 static void
4373 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
4375 if (inst.operands[i].immisreg && inst.operands[i].shifted)
4377 inst.error = _("instruction does not accept scaled register index");
4378 return;
4381 encode_arm_addr_mode_common (i, is_t);
4383 if (inst.operands[i].immisreg)
4385 inst.instruction |= inst.operands[i].imm;
4386 if (!inst.operands[i].negative)
4387 inst.instruction |= INDEX_UP;
4389 else /* immediate offset in inst.reloc */
4391 inst.instruction |= HWOFFSET_IMM;
4392 if (inst.reloc.type == BFD_RELOC_UNUSED)
4393 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
4397 /* inst.operands[i] was set up by parse_address. Encode it into an
4398 ARM-format instruction. Reject all forms which cannot be encoded
4399 into a coprocessor load/store instruction. If wb_ok is false,
4400 reject use of writeback; if unind_ok is false, reject use of
4401 unindexed addressing. If reloc_override is not 0, use it instead
4402 of BFD_ARM_CP_OFF_IMM. */
4404 static int
4405 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
4407 inst.instruction |= inst.operands[i].reg << 16;
4409 assert (!(inst.operands[i].preind && inst.operands[i].postind));
4411 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
4413 assert (!inst.operands[i].writeback);
4414 if (!unind_ok)
4416 inst.error = _("instruction does not support unindexed addressing");
4417 return FAIL;
4419 inst.instruction |= inst.operands[i].imm;
4420 inst.instruction |= INDEX_UP;
4421 return SUCCESS;
4424 if (inst.operands[i].preind)
4425 inst.instruction |= PRE_INDEX;
4427 if (inst.operands[i].writeback)
4429 if (inst.operands[i].reg == REG_PC)
4431 inst.error = _("pc may not be used with write-back");
4432 return FAIL;
4434 if (!wb_ok)
4436 inst.error = _("instruction does not support writeback");
4437 return FAIL;
4439 inst.instruction |= WRITE_BACK;
4442 if (reloc_override)
4443 inst.reloc.type = reloc_override;
4444 else if (thumb_mode)
4445 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
4446 else
4447 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
4448 return SUCCESS;
4451 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
4452 Determine whether it can be performed with a move instruction; if
4453 it can, convert inst.instruction to that move instruction and
4454 return 1; if it can't, convert inst.instruction to a literal-pool
4455 load and return 0. If this is not a valid thing to do in the
4456 current context, set inst.error and return 1.
4458 inst.operands[i] describes the destination register. */
4460 static int
4461 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
4463 unsigned long tbit;
4465 if (thumb_p)
4466 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
4467 else
4468 tbit = LOAD_BIT;
4470 if ((inst.instruction & tbit) == 0)
4472 inst.error = _("invalid pseudo operation");
4473 return 1;
4475 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
4477 inst.error = _("constant expression expected");
4478 return 1;
4480 if (inst.reloc.exp.X_op == O_constant)
4482 if (thumb_p)
4484 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
4486 /* This can be done with a mov(1) instruction. */
4487 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
4488 inst.instruction |= inst.reloc.exp.X_add_number;
4489 return 1;
4492 else
4494 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
4495 if (value != FAIL)
4497 /* This can be done with a mov instruction. */
4498 inst.instruction &= LITERAL_MASK;
4499 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
4500 inst.instruction |= value & 0xfff;
4501 return 1;
4504 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
4505 if (value != FAIL)
4507 /* This can be done with a mvn instruction. */
4508 inst.instruction &= LITERAL_MASK;
4509 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
4510 inst.instruction |= value & 0xfff;
4511 return 1;
4516 if (add_to_lit_pool () == FAIL)
4518 inst.error = _("literal pool insertion failed");
4519 return 1;
4521 inst.operands[1].reg = REG_PC;
4522 inst.operands[1].isreg = 1;
4523 inst.operands[1].preind = 1;
4524 inst.reloc.pc_rel = 1;
4525 inst.reloc.type = (thumb_p
4526 ? BFD_RELOC_ARM_THUMB_OFFSET
4527 : (mode_3
4528 ? BFD_RELOC_ARM_HWLITERAL
4529 : BFD_RELOC_ARM_LITERAL));
4530 return 0;
4533 /* Functions for instruction encoding, sorted by subarchitecture.
4534 First some generics; their names are taken from the conventional
4535 bit positions for register arguments in ARM format instructions. */
4537 static void
4538 do_noargs (void)
4542 static void
4543 do_rd (void)
4545 inst.instruction |= inst.operands[0].reg << 12;
4548 static void
4549 do_rd_rm (void)
4551 inst.instruction |= inst.operands[0].reg << 12;
4552 inst.instruction |= inst.operands[1].reg;
4555 static void
4556 do_rd_rn (void)
4558 inst.instruction |= inst.operands[0].reg << 12;
4559 inst.instruction |= inst.operands[1].reg << 16;
4562 static void
4563 do_rn_rd (void)
4565 inst.instruction |= inst.operands[0].reg << 16;
4566 inst.instruction |= inst.operands[1].reg << 12;
4569 static void
4570 do_rd_rm_rn (void)
4572 unsigned Rn = inst.operands[2].reg;
4573 /* Enforce resutrictions on SWP instruction. */
4574 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
4575 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
4576 _("Rn must not overlap other operands"));
4577 inst.instruction |= inst.operands[0].reg << 12;
4578 inst.instruction |= inst.operands[1].reg;
4579 inst.instruction |= Rn << 16;
4582 static void
4583 do_rd_rn_rm (void)
4585 inst.instruction |= inst.operands[0].reg << 12;
4586 inst.instruction |= inst.operands[1].reg << 16;
4587 inst.instruction |= inst.operands[2].reg;
4590 static void
4591 do_rm_rd_rn (void)
4593 inst.instruction |= inst.operands[0].reg;
4594 inst.instruction |= inst.operands[1].reg << 12;
4595 inst.instruction |= inst.operands[2].reg << 16;
4598 static void
4599 do_imm0 (void)
4601 inst.instruction |= inst.operands[0].imm;
4604 static void
4605 do_rd_cpaddr (void)
4607 inst.instruction |= inst.operands[0].reg << 12;
4608 encode_arm_cp_address (1, TRUE, TRUE, 0);
4611 /* ARM instructions, in alphabetical order by function name (except
4612 that wrapper functions appear immediately after the function they
4613 wrap). */
4615 /* This is a pseudo-op of the form "adr rd, label" to be converted
4616 into a relative address of the form "add rd, pc, #label-.-8". */
4618 static void
4619 do_adr (void)
4621 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
4623 /* Frag hacking will turn this into a sub instruction if the offset turns
4624 out to be negative. */
4625 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4626 inst.reloc.pc_rel = 1;
4627 inst.reloc.exp.X_add_number -= 8;
4630 /* This is a pseudo-op of the form "adrl rd, label" to be converted
4631 into a relative address of the form:
4632 add rd, pc, #low(label-.-8)"
4633 add rd, rd, #high(label-.-8)" */
4635 static void
4636 do_adrl (void)
4638 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
4640 /* Frag hacking will turn this into a sub instruction if the offset turns
4641 out to be negative. */
4642 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
4643 inst.reloc.pc_rel = 1;
4644 inst.size = INSN_SIZE * 2;
4645 inst.reloc.exp.X_add_number -= 8;
4648 static void
4649 do_arit (void)
4651 if (!inst.operands[1].present)
4652 inst.operands[1].reg = inst.operands[0].reg;
4653 inst.instruction |= inst.operands[0].reg << 12;
4654 inst.instruction |= inst.operands[1].reg << 16;
4655 encode_arm_shifter_operand (2);
4658 static void
4659 do_barrier (void)
4661 if (inst.operands[0].present)
4663 constraint ((inst.instruction & 0xf0) != 0x40
4664 && inst.operands[0].imm != 0xf,
4665 "bad barrier type");
4666 inst.instruction |= inst.operands[0].imm;
4668 else
4669 inst.instruction |= 0xf;
4672 static void
4673 do_bfc (void)
4675 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
4676 constraint (msb > 32, _("bit-field extends past end of register"));
4677 /* The instruction encoding stores the LSB and MSB,
4678 not the LSB and width. */
4679 inst.instruction |= inst.operands[0].reg << 12;
4680 inst.instruction |= inst.operands[1].imm << 7;
4681 inst.instruction |= (msb - 1) << 16;
4684 static void
4685 do_bfi (void)
4687 unsigned int msb;
4689 /* #0 in second position is alternative syntax for bfc, which is
4690 the same instruction but with REG_PC in the Rm field. */
4691 if (!inst.operands[1].isreg)
4692 inst.operands[1].reg = REG_PC;
4694 msb = inst.operands[2].imm + inst.operands[3].imm;
4695 constraint (msb > 32, _("bit-field extends past end of register"));
4696 /* The instruction encoding stores the LSB and MSB,
4697 not the LSB and width. */
4698 inst.instruction |= inst.operands[0].reg << 12;
4699 inst.instruction |= inst.operands[1].reg;
4700 inst.instruction |= inst.operands[2].imm << 7;
4701 inst.instruction |= (msb - 1) << 16;
4704 static void
4705 do_bfx (void)
4707 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
4708 _("bit-field extends past end of register"));
4709 inst.instruction |= inst.operands[0].reg << 12;
4710 inst.instruction |= inst.operands[1].reg;
4711 inst.instruction |= inst.operands[2].imm << 7;
4712 inst.instruction |= (inst.operands[3].imm - 1) << 16;
4715 /* ARM V5 breakpoint instruction (argument parse)
4716 BKPT <16 bit unsigned immediate>
4717 Instruction is not conditional.
4718 The bit pattern given in insns[] has the COND_ALWAYS condition,
4719 and it is an error if the caller tried to override that. */
4721 static void
4722 do_bkpt (void)
4724 /* Top 12 of 16 bits to bits 19:8. */
4725 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
4727 /* Bottom 4 of 16 bits to bits 3:0. */
4728 inst.instruction |= inst.operands[0].imm & 0xf;
4731 static void
4732 encode_branch (int default_reloc)
4734 if (inst.operands[0].hasreloc)
4736 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
4737 _("the only suffix valid here is '(plt)'"));
4738 inst.reloc.type = BFD_RELOC_ARM_PLT32;
4740 else
4742 inst.reloc.type = default_reloc;
4744 inst.reloc.pc_rel = 1;
4747 static void
4748 do_branch (void)
4750 #ifdef OBJ_ELF
4751 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
4752 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
4753 else
4754 #endif
4755 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
4758 static void
4759 do_bl (void)
4761 #ifdef OBJ_ELF
4762 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
4764 if (inst.cond == COND_ALWAYS)
4765 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
4766 else
4767 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
4769 else
4770 #endif
4771 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
4774 /* ARM V5 branch-link-exchange instruction (argument parse)
4775 BLX <target_addr> ie BLX(1)
4776 BLX{<condition>} <Rm> ie BLX(2)
4777 Unfortunately, there are two different opcodes for this mnemonic.
4778 So, the insns[].value is not used, and the code here zaps values
4779 into inst.instruction.
4780 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
4782 static void
4783 do_blx (void)
4785 if (inst.operands[0].isreg)
4787 /* Arg is a register; the opcode provided by insns[] is correct.
4788 It is not illegal to do "blx pc", just useless. */
4789 if (inst.operands[0].reg == REG_PC)
4790 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
4792 inst.instruction |= inst.operands[0].reg;
4794 else
4796 /* Arg is an address; this instruction cannot be executed
4797 conditionally, and the opcode must be adjusted. */
4798 constraint (inst.cond != COND_ALWAYS, BAD_COND);
4799 inst.instruction = 0xfa000000;
4800 #ifdef OBJ_ELF
4801 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
4802 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
4803 else
4804 #endif
4805 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
4809 static void
4810 do_bx (void)
4812 if (inst.operands[0].reg == REG_PC)
4813 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
4815 inst.instruction |= inst.operands[0].reg;
4819 /* ARM v5TEJ. Jump to Jazelle code. */
4821 static void
4822 do_bxj (void)
4824 if (inst.operands[0].reg == REG_PC)
4825 as_tsktsk (_("use of r15 in bxj is not really useful"));
4827 inst.instruction |= inst.operands[0].reg;
4830 /* Co-processor data operation:
4831 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
4832 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
4833 static void
4834 do_cdp (void)
4836 inst.instruction |= inst.operands[0].reg << 8;
4837 inst.instruction |= inst.operands[1].imm << 20;
4838 inst.instruction |= inst.operands[2].reg << 12;
4839 inst.instruction |= inst.operands[3].reg << 16;
4840 inst.instruction |= inst.operands[4].reg;
4841 inst.instruction |= inst.operands[5].imm << 5;
4844 static void
4845 do_cmp (void)
4847 inst.instruction |= inst.operands[0].reg << 16;
4848 encode_arm_shifter_operand (1);
4851 /* Transfer between coprocessor and ARM registers.
4852 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
4853 MRC2
4854 MCR{cond}
4855 MCR2
4857 No special properties. */
4859 static void
4860 do_co_reg (void)
4862 inst.instruction |= inst.operands[0].reg << 8;
4863 inst.instruction |= inst.operands[1].imm << 21;
4864 inst.instruction |= inst.operands[2].reg << 12;
4865 inst.instruction |= inst.operands[3].reg << 16;
4866 inst.instruction |= inst.operands[4].reg;
4867 inst.instruction |= inst.operands[5].imm << 5;
4870 /* Transfer between coprocessor register and pair of ARM registers.
4871 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
4872 MCRR2
4873 MRRC{cond}
4874 MRRC2
4876 Two XScale instructions are special cases of these:
4878 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
4879 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
4881 Result unpredicatable if Rd or Rn is R15. */
4883 static void
4884 do_co_reg2c (void)
4886 inst.instruction |= inst.operands[0].reg << 8;
4887 inst.instruction |= inst.operands[1].imm << 4;
4888 inst.instruction |= inst.operands[2].reg << 12;
4889 inst.instruction |= inst.operands[3].reg << 16;
4890 inst.instruction |= inst.operands[4].reg;
4893 static void
4894 do_cpsi (void)
4896 inst.instruction |= inst.operands[0].imm << 6;
4897 inst.instruction |= inst.operands[1].imm;
4900 static void
4901 do_dbg (void)
4903 inst.instruction |= inst.operands[0].imm;
4906 static void
4907 do_it (void)
4909 /* There is no IT instruction in ARM mode. We
4910 process it but do not generate code for it. */
4911 inst.size = 0;
4914 static void
4915 do_ldmstm (void)
4917 int base_reg = inst.operands[0].reg;
4918 int range = inst.operands[1].imm;
4920 inst.instruction |= base_reg << 16;
4921 inst.instruction |= range;
4923 if (inst.operands[1].writeback)
4924 inst.instruction |= LDM_TYPE_2_OR_3;
4926 if (inst.operands[0].writeback)
4928 inst.instruction |= WRITE_BACK;
4929 /* Check for unpredictable uses of writeback. */
4930 if (inst.instruction & LOAD_BIT)
4932 /* Not allowed in LDM type 2. */
4933 if ((inst.instruction & LDM_TYPE_2_OR_3)
4934 && ((range & (1 << REG_PC)) == 0))
4935 as_warn (_("writeback of base register is UNPREDICTABLE"));
4936 /* Only allowed if base reg not in list for other types. */
4937 else if (range & (1 << base_reg))
4938 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
4940 else /* STM. */
4942 /* Not allowed for type 2. */
4943 if (inst.instruction & LDM_TYPE_2_OR_3)
4944 as_warn (_("writeback of base register is UNPREDICTABLE"));
4945 /* Only allowed if base reg not in list, or first in list. */
4946 else if ((range & (1 << base_reg))
4947 && (range & ((1 << base_reg) - 1)))
4948 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
4953 /* ARMv5TE load-consecutive (argument parse)
4954 Mode is like LDRH.
4956 LDRccD R, mode
4957 STRccD R, mode. */
4959 static void
4960 do_ldrd (void)
4962 constraint (inst.operands[0].reg % 2 != 0,
4963 _("first destination register must be even"));
4964 constraint (inst.operands[1].present
4965 && inst.operands[1].reg != inst.operands[0].reg + 1,
4966 _("can only load two consecutive registers"));
4967 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
4968 constraint (!inst.operands[2].isreg, _("'[' expected"));
4970 if (!inst.operands[1].present)
4971 inst.operands[1].reg = inst.operands[0].reg + 1;
4973 if (inst.instruction & LOAD_BIT)
4975 /* encode_arm_addr_mode_3 will diagnose overlap between the base
4976 register and the first register written; we have to diagnose
4977 overlap between the base and the second register written here. */
4979 if (inst.operands[2].reg == inst.operands[1].reg
4980 && (inst.operands[2].writeback || inst.operands[2].postind))
4981 as_warn (_("base register written back, and overlaps "
4982 "second destination register"));
4984 /* For an index-register load, the index register must not overlap the
4985 destination (even if not write-back). */
4986 else if (inst.operands[2].immisreg
4987 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
4988 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
4989 as_warn (_("index register overlaps destination register"));
4992 inst.instruction |= inst.operands[0].reg << 12;
4993 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
4996 static void
4997 do_ldrex (void)
4999 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
5000 || inst.operands[1].postind || inst.operands[1].writeback
5001 || inst.operands[1].immisreg || inst.operands[1].shifted
5002 || inst.operands[1].negative
5003 /* This can arise if the programmer has written
5004 strex rN, rM, foo
5005 or if they have mistakenly used a register name as the last
5006 operand, eg:
5007 strex rN, rM, rX
5008 It is very difficult to distinguish between these two cases
5009 because "rX" might actually be a label. ie the register
5010 name has been occluded by a symbol of the same name. So we
5011 just generate a general 'bad addressing mode' type error
5012 message and leave it up to the programmer to discover the
5013 true cause and fix their mistake. */
5014 || (inst.operands[1].reg == REG_PC),
5015 BAD_ADDR_MODE);
5017 constraint (inst.reloc.exp.X_op != O_constant
5018 || inst.reloc.exp.X_add_number != 0,
5019 _("offset must be zero in ARM encoding"));
5021 inst.instruction |= inst.operands[0].reg << 12;
5022 inst.instruction |= inst.operands[1].reg << 16;
5023 inst.reloc.type = BFD_RELOC_UNUSED;
5026 static void
5027 do_ldrexd (void)
5029 constraint (inst.operands[0].reg % 2 != 0,
5030 _("even register required"));
5031 constraint (inst.operands[1].present
5032 && inst.operands[1].reg != inst.operands[0].reg + 1,
5033 _("can only load two consecutive registers"));
5034 /* If op 1 were present and equal to PC, this function wouldn't
5035 have been called in the first place. */
5036 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
5038 inst.instruction |= inst.operands[0].reg << 12;
5039 inst.instruction |= inst.operands[2].reg << 16;
5042 static void
5043 do_ldst (void)
5045 inst.instruction |= inst.operands[0].reg << 12;
5046 if (!inst.operands[1].isreg)
5047 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
5048 return;
5049 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
5052 static void
5053 do_ldstt (void)
5055 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
5056 reject [Rn,...]. */
5057 if (inst.operands[1].preind)
5059 constraint (inst.reloc.exp.X_op != O_constant ||
5060 inst.reloc.exp.X_add_number != 0,
5061 _("this instruction requires a post-indexed address"));
5063 inst.operands[1].preind = 0;
5064 inst.operands[1].postind = 1;
5065 inst.operands[1].writeback = 1;
5067 inst.instruction |= inst.operands[0].reg << 12;
5068 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
5071 /* Halfword and signed-byte load/store operations. */
5073 static void
5074 do_ldstv4 (void)
5076 inst.instruction |= inst.operands[0].reg << 12;
5077 if (!inst.operands[1].isreg)
5078 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
5079 return;
5080 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
5083 static void
5084 do_ldsttv4 (void)
5086 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
5087 reject [Rn,...]. */
5088 if (inst.operands[1].preind)
5090 constraint (inst.reloc.exp.X_op != O_constant ||
5091 inst.reloc.exp.X_add_number != 0,
5092 _("this instruction requires a post-indexed address"));
5094 inst.operands[1].preind = 0;
5095 inst.operands[1].postind = 1;
5096 inst.operands[1].writeback = 1;
5098 inst.instruction |= inst.operands[0].reg << 12;
5099 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
5102 /* Co-processor register load/store.
5103 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
5104 static void
5105 do_lstc (void)
5107 inst.instruction |= inst.operands[0].reg << 8;
5108 inst.instruction |= inst.operands[1].reg << 12;
5109 encode_arm_cp_address (2, TRUE, TRUE, 0);
5112 static void
5113 do_mlas (void)
5115 /* This restriction does not apply to mls (nor to mla in v6, but
5116 that's hard to detect at present). */
5117 if (inst.operands[0].reg == inst.operands[1].reg
5118 && !(inst.instruction & 0x00400000))
5119 as_tsktsk (_("rd and rm should be different in mla"));
5121 inst.instruction |= inst.operands[0].reg << 16;
5122 inst.instruction |= inst.operands[1].reg;
5123 inst.instruction |= inst.operands[2].reg << 8;
5124 inst.instruction |= inst.operands[3].reg << 12;
5128 static void
5129 do_mov (void)
5131 inst.instruction |= inst.operands[0].reg << 12;
5132 encode_arm_shifter_operand (1);
5135 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
5136 static void
5137 do_mov16 (void)
5139 inst.instruction |= inst.operands[0].reg << 12;
5140 /* The value is in two pieces: 0:11, 16:19. */
5141 inst.instruction |= (inst.operands[1].imm & 0x00000fff);
5142 inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4;
5145 static void
5146 do_mrs (void)
5148 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
5149 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
5150 != (PSR_c|PSR_f),
5151 _("'CPSR' or 'SPSR' expected"));
5152 inst.instruction |= inst.operands[0].reg << 12;
5153 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
5156 /* Two possible forms:
5157 "{C|S}PSR_<field>, Rm",
5158 "{C|S}PSR_f, #expression". */
5160 static void
5161 do_msr (void)
5163 inst.instruction |= inst.operands[0].imm;
5164 if (inst.operands[1].isreg)
5165 inst.instruction |= inst.operands[1].reg;
5166 else
5168 inst.instruction |= INST_IMMEDIATE;
5169 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5170 inst.reloc.pc_rel = 0;
5174 static void
5175 do_mul (void)
5177 if (!inst.operands[2].present)
5178 inst.operands[2].reg = inst.operands[0].reg;
5179 inst.instruction |= inst.operands[0].reg << 16;
5180 inst.instruction |= inst.operands[1].reg;
5181 inst.instruction |= inst.operands[2].reg << 8;
5183 if (inst.operands[0].reg == inst.operands[1].reg)
5184 as_tsktsk (_("rd and rm should be different in mul"));
5187 /* Long Multiply Parser
5188 UMULL RdLo, RdHi, Rm, Rs
5189 SMULL RdLo, RdHi, Rm, Rs
5190 UMLAL RdLo, RdHi, Rm, Rs
5191 SMLAL RdLo, RdHi, Rm, Rs. */
5193 static void
5194 do_mull (void)
5196 inst.instruction |= inst.operands[0].reg << 12;
5197 inst.instruction |= inst.operands[1].reg << 16;
5198 inst.instruction |= inst.operands[2].reg;
5199 inst.instruction |= inst.operands[3].reg << 8;
5201 /* rdhi, rdlo and rm must all be different. */
5202 if (inst.operands[0].reg == inst.operands[1].reg
5203 || inst.operands[0].reg == inst.operands[2].reg
5204 || inst.operands[1].reg == inst.operands[2].reg)
5205 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
5208 static void
5209 do_nop (void)
5211 if (inst.operands[0].present)
5213 /* Architectural NOP hints are CPSR sets with no bits selected. */
5214 inst.instruction &= 0xf0000000;
5215 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
5219 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
5220 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
5221 Condition defaults to COND_ALWAYS.
5222 Error if Rd, Rn or Rm are R15. */
5224 static void
5225 do_pkhbt (void)
5227 inst.instruction |= inst.operands[0].reg << 12;
5228 inst.instruction |= inst.operands[1].reg << 16;
5229 inst.instruction |= inst.operands[2].reg;
5230 if (inst.operands[3].present)
5231 encode_arm_shift (3);
5234 /* ARM V6 PKHTB (Argument Parse). */
5236 static void
5237 do_pkhtb (void)
5239 if (!inst.operands[3].present)
5241 /* If the shift specifier is omitted, turn the instruction
5242 into pkhbt rd, rm, rn. */
5243 inst.instruction &= 0xfff00010;
5244 inst.instruction |= inst.operands[0].reg << 12;
5245 inst.instruction |= inst.operands[1].reg;
5246 inst.instruction |= inst.operands[2].reg << 16;
5248 else
5250 inst.instruction |= inst.operands[0].reg << 12;
5251 inst.instruction |= inst.operands[1].reg << 16;
5252 inst.instruction |= inst.operands[2].reg;
5253 encode_arm_shift (3);
5257 /* ARMv5TE: Preload-Cache
5259 PLD <addr_mode>
5261 Syntactically, like LDR with B=1, W=0, L=1. */
5263 static void
5264 do_pld (void)
5266 constraint (!inst.operands[0].isreg,
5267 _("'[' expected after PLD mnemonic"));
5268 constraint (inst.operands[0].postind,
5269 _("post-indexed expression used in preload instruction"));
5270 constraint (inst.operands[0].writeback,
5271 _("writeback used in preload instruction"));
5272 constraint (!inst.operands[0].preind,
5273 _("unindexed addressing used in preload instruction"));
5274 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
5277 /* ARMv7: PLI <addr_mode> */
5278 static void
5279 do_pli (void)
5281 constraint (!inst.operands[0].isreg,
5282 _("'[' expected after PLI mnemonic"));
5283 constraint (inst.operands[0].postind,
5284 _("post-indexed expression used in preload instruction"));
5285 constraint (inst.operands[0].writeback,
5286 _("writeback used in preload instruction"));
5287 constraint (!inst.operands[0].preind,
5288 _("unindexed addressing used in preload instruction"));
5289 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
5290 inst.instruction &= ~PRE_INDEX;
5293 static void
5294 do_push_pop (void)
5296 inst.operands[1] = inst.operands[0];
5297 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
5298 inst.operands[0].isreg = 1;
5299 inst.operands[0].writeback = 1;
5300 inst.operands[0].reg = REG_SP;
5301 do_ldmstm ();
5304 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
5305 word at the specified address and the following word
5306 respectively.
5307 Unconditionally executed.
5308 Error if Rn is R15. */
5310 static void
5311 do_rfe (void)
5313 inst.instruction |= inst.operands[0].reg << 16;
5314 if (inst.operands[0].writeback)
5315 inst.instruction |= WRITE_BACK;
5318 /* ARM V6 ssat (argument parse). */
5320 static void
5321 do_ssat (void)
5323 inst.instruction |= inst.operands[0].reg << 12;
5324 inst.instruction |= (inst.operands[1].imm - 1) << 16;
5325 inst.instruction |= inst.operands[2].reg;
5327 if (inst.operands[3].present)
5328 encode_arm_shift (3);
5331 /* ARM V6 usat (argument parse). */
5333 static void
5334 do_usat (void)
5336 inst.instruction |= inst.operands[0].reg << 12;
5337 inst.instruction |= inst.operands[1].imm << 16;
5338 inst.instruction |= inst.operands[2].reg;
5340 if (inst.operands[3].present)
5341 encode_arm_shift (3);
5344 /* ARM V6 ssat16 (argument parse). */
5346 static void
5347 do_ssat16 (void)
5349 inst.instruction |= inst.operands[0].reg << 12;
5350 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
5351 inst.instruction |= inst.operands[2].reg;
5354 static void
5355 do_usat16 (void)
5357 inst.instruction |= inst.operands[0].reg << 12;
5358 inst.instruction |= inst.operands[1].imm << 16;
5359 inst.instruction |= inst.operands[2].reg;
5362 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
5363 preserving the other bits.
5365 setend <endian_specifier>, where <endian_specifier> is either
5366 BE or LE. */
5368 static void
5369 do_setend (void)
5371 if (inst.operands[0].imm)
5372 inst.instruction |= 0x200;
5375 static void
5376 do_shift (void)
5378 unsigned int Rm = (inst.operands[1].present
5379 ? inst.operands[1].reg
5380 : inst.operands[0].reg);
5382 inst.instruction |= inst.operands[0].reg << 12;
5383 inst.instruction |= Rm;
5384 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
5386 inst.instruction |= inst.operands[2].reg << 8;
5387 inst.instruction |= SHIFT_BY_REG;
5389 else
5390 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
5393 static void
5394 do_smc (void)
5396 inst.reloc.type = BFD_RELOC_ARM_SMC;
5397 inst.reloc.pc_rel = 0;
5400 static void
5401 do_swi (void)
5403 inst.reloc.type = BFD_RELOC_ARM_SWI;
5404 inst.reloc.pc_rel = 0;
5407 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
5408 SMLAxy{cond} Rd,Rm,Rs,Rn
5409 SMLAWy{cond} Rd,Rm,Rs,Rn
5410 Error if any register is R15. */
5412 static void
5413 do_smla (void)
5415 inst.instruction |= inst.operands[0].reg << 16;
5416 inst.instruction |= inst.operands[1].reg;
5417 inst.instruction |= inst.operands[2].reg << 8;
5418 inst.instruction |= inst.operands[3].reg << 12;
5421 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
5422 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
5423 Error if any register is R15.
5424 Warning if Rdlo == Rdhi. */
5426 static void
5427 do_smlal (void)
5429 inst.instruction |= inst.operands[0].reg << 12;
5430 inst.instruction |= inst.operands[1].reg << 16;
5431 inst.instruction |= inst.operands[2].reg;
5432 inst.instruction |= inst.operands[3].reg << 8;
5434 if (inst.operands[0].reg == inst.operands[1].reg)
5435 as_tsktsk (_("rdhi and rdlo must be different"));
5438 /* ARM V5E (El Segundo) signed-multiply (argument parse)
5439 SMULxy{cond} Rd,Rm,Rs
5440 Error if any register is R15. */
5442 static void
5443 do_smul (void)
5445 inst.instruction |= inst.operands[0].reg << 16;
5446 inst.instruction |= inst.operands[1].reg;
5447 inst.instruction |= inst.operands[2].reg << 8;
5450 /* ARM V6 srs (argument parse). */
5452 static void
5453 do_srs (void)
5455 inst.instruction |= inst.operands[0].imm;
5456 if (inst.operands[0].writeback)
5457 inst.instruction |= WRITE_BACK;
5460 /* ARM V6 strex (argument parse). */
5462 static void
5463 do_strex (void)
5465 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
5466 || inst.operands[2].postind || inst.operands[2].writeback
5467 || inst.operands[2].immisreg || inst.operands[2].shifted
5468 || inst.operands[2].negative
5469 /* See comment in do_ldrex(). */
5470 || (inst.operands[2].reg == REG_PC),
5471 BAD_ADDR_MODE);
5473 constraint (inst.operands[0].reg == inst.operands[1].reg
5474 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
5476 constraint (inst.reloc.exp.X_op != O_constant
5477 || inst.reloc.exp.X_add_number != 0,
5478 _("offset must be zero in ARM encoding"));
5480 inst.instruction |= inst.operands[0].reg << 12;
5481 inst.instruction |= inst.operands[1].reg;
5482 inst.instruction |= inst.operands[2].reg << 16;
5483 inst.reloc.type = BFD_RELOC_UNUSED;
5486 static void
5487 do_strexd (void)
5489 constraint (inst.operands[1].reg % 2 != 0,
5490 _("even register required"));
5491 constraint (inst.operands[2].present
5492 && inst.operands[2].reg != inst.operands[1].reg + 1,
5493 _("can only store two consecutive registers"));
5494 /* If op 2 were present and equal to PC, this function wouldn't
5495 have been called in the first place. */
5496 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
5498 constraint (inst.operands[0].reg == inst.operands[1].reg
5499 || inst.operands[0].reg == inst.operands[1].reg + 1
5500 || inst.operands[0].reg == inst.operands[3].reg,
5501 BAD_OVERLAP);
5503 inst.instruction |= inst.operands[0].reg << 12;
5504 inst.instruction |= inst.operands[1].reg;
5505 inst.instruction |= inst.operands[3].reg << 16;
5508 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
5509 extends it to 32-bits, and adds the result to a value in another
5510 register. You can specify a rotation by 0, 8, 16, or 24 bits
5511 before extracting the 16-bit value.
5512 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
5513 Condition defaults to COND_ALWAYS.
5514 Error if any register uses R15. */
5516 static void
5517 do_sxtah (void)
5519 inst.instruction |= inst.operands[0].reg << 12;
5520 inst.instruction |= inst.operands[1].reg << 16;
5521 inst.instruction |= inst.operands[2].reg;
5522 inst.instruction |= inst.operands[3].imm << 10;
5525 /* ARM V6 SXTH.
5527 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
5528 Condition defaults to COND_ALWAYS.
5529 Error if any register uses R15. */
5531 static void
5532 do_sxth (void)
5534 inst.instruction |= inst.operands[0].reg << 12;
5535 inst.instruction |= inst.operands[1].reg;
5536 inst.instruction |= inst.operands[2].imm << 10;
5539 /* VFP instructions. In a logical order: SP variant first, monad
5540 before dyad, arithmetic then move then load/store. */
5542 static void
5543 do_vfp_sp_monadic (void)
5545 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5546 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
5549 static void
5550 do_vfp_sp_dyadic (void)
5552 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5553 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5554 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
5557 static void
5558 do_vfp_sp_compare_z (void)
5560 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5563 static void
5564 do_vfp_dp_sp_cvt (void)
5566 inst.instruction |= inst.operands[0].reg << 12;
5567 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
5570 static void
5571 do_vfp_sp_dp_cvt (void)
5573 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5574 inst.instruction |= inst.operands[1].reg;
5577 static void
5578 do_vfp_reg_from_sp (void)
5580 inst.instruction |= inst.operands[0].reg << 12;
5581 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5584 static void
5585 do_vfp_reg2_from_sp2 (void)
5587 constraint (inst.operands[2].imm != 2,
5588 _("only two consecutive VFP SP registers allowed here"));
5589 inst.instruction |= inst.operands[0].reg << 12;
5590 inst.instruction |= inst.operands[1].reg << 16;
5591 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
5594 static void
5595 do_vfp_sp_from_reg (void)
5597 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn);
5598 inst.instruction |= inst.operands[1].reg << 12;
5601 static void
5602 do_vfp_sp2_from_reg2 (void)
5604 constraint (inst.operands[0].imm != 2,
5605 _("only two consecutive VFP SP registers allowed here"));
5606 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm);
5607 inst.instruction |= inst.operands[1].reg << 12;
5608 inst.instruction |= inst.operands[2].reg << 16;
5611 static void
5612 do_vfp_sp_ldst (void)
5614 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5615 encode_arm_cp_address (1, FALSE, TRUE, 0);
5618 static void
5619 do_vfp_dp_ldst (void)
5621 inst.instruction |= inst.operands[0].reg << 12;
5622 encode_arm_cp_address (1, FALSE, TRUE, 0);
5626 static void
5627 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
5629 if (inst.operands[0].writeback)
5630 inst.instruction |= WRITE_BACK;
5631 else
5632 constraint (ldstm_type != VFP_LDSTMIA,
5633 _("this addressing mode requires base-register writeback"));
5634 inst.instruction |= inst.operands[0].reg << 16;
5635 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd);
5636 inst.instruction |= inst.operands[1].imm;
5639 static void
5640 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
5642 int count;
5644 if (inst.operands[0].writeback)
5645 inst.instruction |= WRITE_BACK;
5646 else
5647 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
5648 _("this addressing mode requires base-register writeback"));
5650 inst.instruction |= inst.operands[0].reg << 16;
5651 inst.instruction |= inst.operands[1].reg << 12;
5653 count = inst.operands[1].imm << 1;
5654 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
5655 count += 1;
5657 inst.instruction |= count;
5660 static void
5661 do_vfp_sp_ldstmia (void)
5663 vfp_sp_ldstm (VFP_LDSTMIA);
5666 static void
5667 do_vfp_sp_ldstmdb (void)
5669 vfp_sp_ldstm (VFP_LDSTMDB);
5672 static void
5673 do_vfp_dp_ldstmia (void)
5675 vfp_dp_ldstm (VFP_LDSTMIA);
5678 static void
5679 do_vfp_dp_ldstmdb (void)
5681 vfp_dp_ldstm (VFP_LDSTMDB);
5684 static void
5685 do_vfp_xp_ldstmia (void)
5687 vfp_dp_ldstm (VFP_LDSTMIAX);
5690 static void
5691 do_vfp_xp_ldstmdb (void)
5693 vfp_dp_ldstm (VFP_LDSTMDBX);
5696 /* FPA instructions. Also in a logical order. */
5698 static void
5699 do_fpa_cmp (void)
5701 inst.instruction |= inst.operands[0].reg << 16;
5702 inst.instruction |= inst.operands[1].reg;
5705 static void
5706 do_fpa_ldmstm (void)
5708 inst.instruction |= inst.operands[0].reg << 12;
5709 switch (inst.operands[1].imm)
5711 case 1: inst.instruction |= CP_T_X; break;
5712 case 2: inst.instruction |= CP_T_Y; break;
5713 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
5714 case 4: break;
5715 default: abort ();
5718 if (inst.instruction & (PRE_INDEX | INDEX_UP))
5720 /* The instruction specified "ea" or "fd", so we can only accept
5721 [Rn]{!}. The instruction does not really support stacking or
5722 unstacking, so we have to emulate these by setting appropriate
5723 bits and offsets. */
5724 constraint (inst.reloc.exp.X_op != O_constant
5725 || inst.reloc.exp.X_add_number != 0,
5726 _("this instruction does not support indexing"));
5728 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
5729 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
5731 if (!(inst.instruction & INDEX_UP))
5732 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
5734 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
5736 inst.operands[2].preind = 0;
5737 inst.operands[2].postind = 1;
5741 encode_arm_cp_address (2, TRUE, TRUE, 0);
5744 /* iWMMXt instructions: strictly in alphabetical order. */
5746 static void
5747 do_iwmmxt_tandorc (void)
5749 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
5752 static void
5753 do_iwmmxt_textrc (void)
5755 inst.instruction |= inst.operands[0].reg << 12;
5756 inst.instruction |= inst.operands[1].imm;
5759 static void
5760 do_iwmmxt_textrm (void)
5762 inst.instruction |= inst.operands[0].reg << 12;
5763 inst.instruction |= inst.operands[1].reg << 16;
5764 inst.instruction |= inst.operands[2].imm;
5767 static void
5768 do_iwmmxt_tinsr (void)
5770 inst.instruction |= inst.operands[0].reg << 16;
5771 inst.instruction |= inst.operands[1].reg << 12;
5772 inst.instruction |= inst.operands[2].imm;
5775 static void
5776 do_iwmmxt_tmia (void)
5778 inst.instruction |= inst.operands[0].reg << 5;
5779 inst.instruction |= inst.operands[1].reg;
5780 inst.instruction |= inst.operands[2].reg << 12;
5783 static void
5784 do_iwmmxt_waligni (void)
5786 inst.instruction |= inst.operands[0].reg << 12;
5787 inst.instruction |= inst.operands[1].reg << 16;
5788 inst.instruction |= inst.operands[2].reg;
5789 inst.instruction |= inst.operands[3].imm << 20;
5792 static void
5793 do_iwmmxt_wmov (void)
5795 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
5796 inst.instruction |= inst.operands[0].reg << 12;
5797 inst.instruction |= inst.operands[1].reg << 16;
5798 inst.instruction |= inst.operands[1].reg;
5801 static void
5802 do_iwmmxt_wldstbh (void)
5804 int reloc;
5805 inst.instruction |= inst.operands[0].reg << 12;
5806 inst.reloc.exp.X_add_number *= 4;
5807 if (thumb_mode)
5808 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
5809 else
5810 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
5811 encode_arm_cp_address (1, TRUE, FALSE, reloc);
5814 static void
5815 do_iwmmxt_wldstw (void)
5817 /* RIWR_RIWC clears .isreg for a control register. */
5818 if (!inst.operands[0].isreg)
5820 constraint (inst.cond != COND_ALWAYS, BAD_COND);
5821 inst.instruction |= 0xf0000000;
5824 inst.instruction |= inst.operands[0].reg << 12;
5825 encode_arm_cp_address (1, TRUE, TRUE, 0);
5828 static void
5829 do_iwmmxt_wldstd (void)
5831 inst.instruction |= inst.operands[0].reg << 12;
5832 encode_arm_cp_address (1, TRUE, FALSE, 0);
5835 static void
5836 do_iwmmxt_wshufh (void)
5838 inst.instruction |= inst.operands[0].reg << 12;
5839 inst.instruction |= inst.operands[1].reg << 16;
5840 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
5841 inst.instruction |= (inst.operands[2].imm & 0x0f);
5844 static void
5845 do_iwmmxt_wzero (void)
5847 /* WZERO reg is an alias for WANDN reg, reg, reg. */
5848 inst.instruction |= inst.operands[0].reg;
5849 inst.instruction |= inst.operands[0].reg << 12;
5850 inst.instruction |= inst.operands[0].reg << 16;
5853 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
5854 operations first, then control, shift, and load/store. */
5856 /* Insns like "foo X,Y,Z". */
5858 static void
5859 do_mav_triple (void)
5861 inst.instruction |= inst.operands[0].reg << 16;
5862 inst.instruction |= inst.operands[1].reg;
5863 inst.instruction |= inst.operands[2].reg << 12;
5866 /* Insns like "foo W,X,Y,Z".
5867 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
5869 static void
5870 do_mav_quad (void)
5872 inst.instruction |= inst.operands[0].reg << 5;
5873 inst.instruction |= inst.operands[1].reg << 12;
5874 inst.instruction |= inst.operands[2].reg << 16;
5875 inst.instruction |= inst.operands[3].reg;
5878 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
5879 static void
5880 do_mav_dspsc (void)
5882 inst.instruction |= inst.operands[1].reg << 12;
5885 /* Maverick shift immediate instructions.
5886 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
5887 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
5889 static void
5890 do_mav_shift (void)
5892 int imm = inst.operands[2].imm;
5894 inst.instruction |= inst.operands[0].reg << 12;
5895 inst.instruction |= inst.operands[1].reg << 16;
5897 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
5898 Bits 5-7 of the insn should have bits 4-6 of the immediate.
5899 Bit 4 should be 0. */
5900 imm = (imm & 0xf) | ((imm & 0x70) << 1);
5902 inst.instruction |= imm;
5905 /* XScale instructions. Also sorted arithmetic before move. */
5907 /* Xscale multiply-accumulate (argument parse)
5908 MIAcc acc0,Rm,Rs
5909 MIAPHcc acc0,Rm,Rs
5910 MIAxycc acc0,Rm,Rs. */
5912 static void
5913 do_xsc_mia (void)
5915 inst.instruction |= inst.operands[1].reg;
5916 inst.instruction |= inst.operands[2].reg << 12;
5919 /* Xscale move-accumulator-register (argument parse)
5921 MARcc acc0,RdLo,RdHi. */
5923 static void
5924 do_xsc_mar (void)
5926 inst.instruction |= inst.operands[1].reg << 12;
5927 inst.instruction |= inst.operands[2].reg << 16;
5930 /* Xscale move-register-accumulator (argument parse)
5932 MRAcc RdLo,RdHi,acc0. */
5934 static void
5935 do_xsc_mra (void)
5937 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
5938 inst.instruction |= inst.operands[0].reg << 12;
5939 inst.instruction |= inst.operands[1].reg << 16;
5942 /* Encoding functions relevant only to Thumb. */
5944 /* inst.operands[i] is a shifted-register operand; encode
5945 it into inst.instruction in the format used by Thumb32. */
5947 static void
5948 encode_thumb32_shifted_operand (int i)
5950 unsigned int value = inst.reloc.exp.X_add_number;
5951 unsigned int shift = inst.operands[i].shift_kind;
5953 constraint (inst.operands[i].immisreg,
5954 _("shift by register not allowed in thumb mode"));
5955 inst.instruction |= inst.operands[i].reg;
5956 if (shift == SHIFT_RRX)
5957 inst.instruction |= SHIFT_ROR << 4;
5958 else
5960 constraint (inst.reloc.exp.X_op != O_constant,
5961 _("expression too complex"));
5963 constraint (value > 32
5964 || (value == 32 && (shift == SHIFT_LSL
5965 || shift == SHIFT_ROR)),
5966 _("shift expression is too large"));
5968 if (value == 0)
5969 shift = SHIFT_LSL;
5970 else if (value == 32)
5971 value = 0;
5973 inst.instruction |= shift << 4;
5974 inst.instruction |= (value & 0x1c) << 10;
5975 inst.instruction |= (value & 0x03) << 6;
5980 /* inst.operands[i] was set up by parse_address. Encode it into a
5981 Thumb32 format load or store instruction. Reject forms that cannot
5982 be used with such instructions. If is_t is true, reject forms that
5983 cannot be used with a T instruction; if is_d is true, reject forms
5984 that cannot be used with a D instruction. */
5986 static void
5987 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
5989 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
5991 constraint (!inst.operands[i].isreg,
5992 _("Instruction does not support =N addresses"));
5994 inst.instruction |= inst.operands[i].reg << 16;
5995 if (inst.operands[i].immisreg)
5997 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
5998 constraint (is_t || is_d, _("cannot use register index with this instruction"));
5999 constraint (inst.operands[i].negative,
6000 _("Thumb does not support negative register indexing"));
6001 constraint (inst.operands[i].postind,
6002 _("Thumb does not support register post-indexing"));
6003 constraint (inst.operands[i].writeback,
6004 _("Thumb does not support register indexing with writeback"));
6005 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
6006 _("Thumb supports only LSL in shifted register indexing"));
6008 inst.instruction |= inst.operands[i].imm;
6009 if (inst.operands[i].shifted)
6011 constraint (inst.reloc.exp.X_op != O_constant,
6012 _("expression too complex"));
6013 constraint (inst.reloc.exp.X_add_number < 0
6014 || inst.reloc.exp.X_add_number > 3,
6015 _("shift out of range"));
6016 inst.instruction |= inst.reloc.exp.X_add_number << 4;
6018 inst.reloc.type = BFD_RELOC_UNUSED;
6020 else if (inst.operands[i].preind)
6022 constraint (is_pc && inst.operands[i].writeback,
6023 _("cannot use writeback with PC-relative addressing"));
6024 constraint (is_t && inst.operands[i].writeback,
6025 _("cannot use writeback with this instruction"));
6027 if (is_d)
6029 inst.instruction |= 0x01000000;
6030 if (inst.operands[i].writeback)
6031 inst.instruction |= 0x00200000;
6033 else
6035 inst.instruction |= 0x00000c00;
6036 if (inst.operands[i].writeback)
6037 inst.instruction |= 0x00000100;
6039 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
6041 else if (inst.operands[i].postind)
6043 assert (inst.operands[i].writeback);
6044 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
6045 constraint (is_t, _("cannot use post-indexing with this instruction"));
6047 if (is_d)
6048 inst.instruction |= 0x00200000;
6049 else
6050 inst.instruction |= 0x00000900;
6051 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
6053 else /* unindexed - only for coprocessor */
6054 inst.error = _("instruction does not accept unindexed addressing");
6057 /* Table of Thumb instructions which exist in both 16- and 32-bit
6058 encodings (the latter only in post-V6T2 cores). The index is the
6059 value used in the insns table below. When there is more than one
6060 possible 16-bit encoding for the instruction, this table always
6061 holds variant (1).
6062 Also contains several pseudo-instructions used during relaxation. */
6063 #define T16_32_TAB \
6064 X(adc, 4140, eb400000), \
6065 X(adcs, 4140, eb500000), \
6066 X(add, 1c00, eb000000), \
6067 X(adds, 1c00, eb100000), \
6068 X(addi, 0000, f1000000), \
6069 X(addis, 0000, f1100000), \
6070 X(add_pc,000f, f20f0000), \
6071 X(add_sp,000d, f10d0000), \
6072 X(adr, 000f, f20f0000), \
6073 X(and, 4000, ea000000), \
6074 X(ands, 4000, ea100000), \
6075 X(asr, 1000, fa40f000), \
6076 X(asrs, 1000, fa50f000), \
6077 X(b, e000, f000b000), \
6078 X(bcond, d000, f0008000), \
6079 X(bic, 4380, ea200000), \
6080 X(bics, 4380, ea300000), \
6081 X(cmn, 42c0, eb100f00), \
6082 X(cmp, 2800, ebb00f00), \
6083 X(cpsie, b660, f3af8400), \
6084 X(cpsid, b670, f3af8600), \
6085 X(cpy, 4600, ea4f0000), \
6086 X(dec_sp,80dd, f1bd0d00), \
6087 X(eor, 4040, ea800000), \
6088 X(eors, 4040, ea900000), \
6089 X(inc_sp,00dd, f10d0d00), \
6090 X(ldmia, c800, e8900000), \
6091 X(ldr, 6800, f8500000), \
6092 X(ldrb, 7800, f8100000), \
6093 X(ldrh, 8800, f8300000), \
6094 X(ldrsb, 5600, f9100000), \
6095 X(ldrsh, 5e00, f9300000), \
6096 X(ldr_pc,4800, f85f0000), \
6097 X(ldr_pc2,4800, f85f0000), \
6098 X(ldr_sp,9800, f85d0000), \
6099 X(lsl, 0000, fa00f000), \
6100 X(lsls, 0000, fa10f000), \
6101 X(lsr, 0800, fa20f000), \
6102 X(lsrs, 0800, fa30f000), \
6103 X(mov, 2000, ea4f0000), \
6104 X(movs, 2000, ea5f0000), \
6105 X(mul, 4340, fb00f000), \
6106 X(muls, 4340, ffffffff), /* no 32b muls */ \
6107 X(mvn, 43c0, ea6f0000), \
6108 X(mvns, 43c0, ea7f0000), \
6109 X(neg, 4240, f1c00000), /* rsb #0 */ \
6110 X(negs, 4240, f1d00000), /* rsbs #0 */ \
6111 X(orr, 4300, ea400000), \
6112 X(orrs, 4300, ea500000), \
6113 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
6114 X(push, b400, e92d0000), /* stmdb sp!,... */ \
6115 X(rev, ba00, fa90f080), \
6116 X(rev16, ba40, fa90f090), \
6117 X(revsh, bac0, fa90f0b0), \
6118 X(ror, 41c0, fa60f000), \
6119 X(rors, 41c0, fa70f000), \
6120 X(sbc, 4180, eb600000), \
6121 X(sbcs, 4180, eb700000), \
6122 X(stmia, c000, e8800000), \
6123 X(str, 6000, f8400000), \
6124 X(strb, 7000, f8000000), \
6125 X(strh, 8000, f8200000), \
6126 X(str_sp,9000, f84d0000), \
6127 X(sub, 1e00, eba00000), \
6128 X(subs, 1e00, ebb00000), \
6129 X(subi, 8000, f1a00000), \
6130 X(subis, 8000, f1b00000), \
6131 X(sxtb, b240, fa4ff080), \
6132 X(sxth, b200, fa0ff080), \
6133 X(tst, 4200, ea100f00), \
6134 X(uxtb, b2c0, fa5ff080), \
6135 X(uxth, b280, fa1ff080), \
6136 X(nop, bf00, f3af8000), \
6137 X(yield, bf10, f3af8001), \
6138 X(wfe, bf20, f3af8002), \
6139 X(wfi, bf30, f3af8003), \
6140 X(sev, bf40, f3af9004), /* typo, 8004? */
6142 /* To catch errors in encoding functions, the codes are all offset by
6143 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
6144 as 16-bit instructions. */
6145 #define X(a,b,c) T_MNEM_##a
6146 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
6147 #undef X
6149 #define X(a,b,c) 0x##b
6150 static const unsigned short thumb_op16[] = { T16_32_TAB };
6151 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
6152 #undef X
6154 #define X(a,b,c) 0x##c
6155 static const unsigned int thumb_op32[] = { T16_32_TAB };
6156 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
6157 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
6158 #undef X
6159 #undef T16_32_TAB
6161 /* Thumb instruction encoders, in alphabetical order. */
6163 /* ADDW or SUBW. */
6164 static void
6165 do_t_add_sub_w (void)
6167 int Rd, Rn;
6169 Rd = inst.operands[0].reg;
6170 Rn = inst.operands[1].reg;
6172 constraint (Rd == 15, _("PC not allowed as destination"));
6173 inst.instruction |= (Rn << 16) | (Rd << 8);
6174 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
6177 /* Parse an add or subtract instruction. We get here with inst.instruction
6178 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
6180 static void
6181 do_t_add_sub (void)
6183 int Rd, Rs, Rn;
6185 Rd = inst.operands[0].reg;
6186 Rs = (inst.operands[1].present
6187 ? inst.operands[1].reg /* Rd, Rs, foo */
6188 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6190 if (unified_syntax)
6192 bfd_boolean flags;
6193 bfd_boolean narrow;
6194 int opcode;
6196 flags = (inst.instruction == T_MNEM_adds
6197 || inst.instruction == T_MNEM_subs);
6198 if (flags)
6199 narrow = (current_it_mask == 0);
6200 else
6201 narrow = (current_it_mask != 0);
6202 if (!inst.operands[2].isreg)
6204 opcode = 0;
6205 if (inst.size_req != 4)
6207 int add;
6209 add = (inst.instruction == T_MNEM_add
6210 || inst.instruction == T_MNEM_adds);
6211 /* Attempt to use a narrow opcode, with relaxation if
6212 appropriate. */
6213 if (Rd == REG_SP && Rs == REG_SP && !flags)
6214 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
6215 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
6216 opcode = T_MNEM_add_sp;
6217 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
6218 opcode = T_MNEM_add_pc;
6219 else if (Rd <= 7 && Rs <= 7 && narrow)
6221 if (flags)
6222 opcode = add ? T_MNEM_addis : T_MNEM_subis;
6223 else
6224 opcode = add ? T_MNEM_addi : T_MNEM_subi;
6226 if (opcode)
6228 inst.instruction = THUMB_OP16(opcode);
6229 inst.instruction |= (Rd << 4) | Rs;
6230 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6231 if (inst.size_req != 2)
6232 inst.relax = opcode;
6234 else
6235 constraint (inst.size_req == 2, BAD_HIREG);
6237 if (inst.size_req == 4
6238 || (inst.size_req != 2 && !opcode))
6240 /* ??? Convert large immediates to addw/subw. */
6241 inst.instruction = THUMB_OP32 (inst.instruction);
6242 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6243 inst.instruction |= inst.operands[0].reg << 8;
6244 inst.instruction |= inst.operands[1].reg << 16;
6245 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6248 else
6250 Rn = inst.operands[2].reg;
6251 /* See if we can do this with a 16-bit instruction. */
6252 if (!inst.operands[2].shifted && inst.size_req != 4)
6254 if (Rd > 7 || Rs > 7 || Rn > 7)
6255 narrow = FALSE;
6257 if (narrow)
6259 inst.instruction = ((inst.instruction == T_MNEM_adds
6260 || inst.instruction == T_MNEM_add)
6261 ? T_OPCODE_ADD_R3
6262 : T_OPCODE_SUB_R3);
6263 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
6264 return;
6267 if (inst.instruction == T_MNEM_add)
6269 if (Rd == Rs)
6271 inst.instruction = T_OPCODE_ADD_HI;
6272 inst.instruction |= (Rd & 8) << 4;
6273 inst.instruction |= (Rd & 7);
6274 inst.instruction |= Rn << 3;
6275 return;
6277 /* ... because addition is commutative! */
6278 else if (Rd == Rn)
6280 inst.instruction = T_OPCODE_ADD_HI;
6281 inst.instruction |= (Rd & 8) << 4;
6282 inst.instruction |= (Rd & 7);
6283 inst.instruction |= Rs << 3;
6284 return;
6288 /* If we get here, it can't be done in 16 bits. */
6289 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
6290 _("shift must be constant"));
6291 inst.instruction = THUMB_OP32 (inst.instruction);
6292 inst.instruction |= Rd << 8;
6293 inst.instruction |= Rs << 16;
6294 encode_thumb32_shifted_operand (2);
6297 else
6299 constraint (inst.instruction == T_MNEM_adds
6300 || inst.instruction == T_MNEM_subs,
6301 BAD_THUMB32);
6303 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
6305 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
6306 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
6307 BAD_HIREG);
6309 inst.instruction = (inst.instruction == T_MNEM_add
6310 ? 0x0000 : 0x8000);
6311 inst.instruction |= (Rd << 4) | Rs;
6312 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6313 return;
6316 Rn = inst.operands[2].reg;
6317 constraint (inst.operands[2].shifted, _("unshifted register required"));
6319 /* We now have Rd, Rs, and Rn set to registers. */
6320 if (Rd > 7 || Rs > 7 || Rn > 7)
6322 /* Can't do this for SUB. */
6323 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
6324 inst.instruction = T_OPCODE_ADD_HI;
6325 inst.instruction |= (Rd & 8) << 4;
6326 inst.instruction |= (Rd & 7);
6327 if (Rs == Rd)
6328 inst.instruction |= Rn << 3;
6329 else if (Rn == Rd)
6330 inst.instruction |= Rs << 3;
6331 else
6332 constraint (1, _("dest must overlap one source register"));
6334 else
6336 inst.instruction = (inst.instruction == T_MNEM_add
6337 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
6338 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
6343 static void
6344 do_t_adr (void)
6346 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
6348 /* Defer to section relaxation. */
6349 inst.relax = inst.instruction;
6350 inst.instruction = THUMB_OP16 (inst.instruction);
6351 inst.instruction |= inst.operands[0].reg << 4;
6353 else if (unified_syntax && inst.size_req != 2)
6355 /* Generate a 32-bit opcode. */
6356 inst.instruction = THUMB_OP32 (inst.instruction);
6357 inst.instruction |= inst.operands[0].reg << 8;
6358 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
6359 inst.reloc.pc_rel = 1;
6361 else
6363 /* Generate a 16-bit opcode. */
6364 inst.instruction = THUMB_OP16 (inst.instruction);
6365 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6366 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
6367 inst.reloc.pc_rel = 1;
6369 inst.instruction |= inst.operands[0].reg << 4;
6373 /* Arithmetic instructions for which there is just one 16-bit
6374 instruction encoding, and it allows only two low registers.
6375 For maximal compatibility with ARM syntax, we allow three register
6376 operands even when Thumb-32 instructions are not available, as long
6377 as the first two are identical. For instance, both "sbc r0,r1" and
6378 "sbc r0,r0,r1" are allowed. */
6379 static void
6380 do_t_arit3 (void)
6382 int Rd, Rs, Rn;
6384 Rd = inst.operands[0].reg;
6385 Rs = (inst.operands[1].present
6386 ? inst.operands[1].reg /* Rd, Rs, foo */
6387 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6388 Rn = inst.operands[2].reg;
6390 if (unified_syntax)
6392 if (!inst.operands[2].isreg)
6394 /* For an immediate, we always generate a 32-bit opcode;
6395 section relaxation will shrink it later if possible. */
6396 inst.instruction = THUMB_OP32 (inst.instruction);
6397 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6398 inst.instruction |= Rd << 8;
6399 inst.instruction |= Rs << 16;
6400 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6402 else
6404 bfd_boolean narrow;
6406 /* See if we can do this with a 16-bit instruction. */
6407 if (THUMB_SETS_FLAGS (inst.instruction))
6408 narrow = current_it_mask == 0;
6409 else
6410 narrow = current_it_mask != 0;
6412 if (Rd > 7 || Rn > 7 || Rs > 7)
6413 narrow = FALSE;
6414 if (inst.operands[2].shifted)
6415 narrow = FALSE;
6416 if (inst.size_req == 4)
6417 narrow = FALSE;
6419 if (narrow
6420 && Rd == Rs)
6422 inst.instruction = THUMB_OP16 (inst.instruction);
6423 inst.instruction |= Rd;
6424 inst.instruction |= Rn << 3;
6425 return;
6428 /* If we get here, it can't be done in 16 bits. */
6429 constraint (inst.operands[2].shifted
6430 && inst.operands[2].immisreg,
6431 _("shift must be constant"));
6432 inst.instruction = THUMB_OP32 (inst.instruction);
6433 inst.instruction |= Rd << 8;
6434 inst.instruction |= Rs << 16;
6435 encode_thumb32_shifted_operand (2);
6438 else
6440 /* On its face this is a lie - the instruction does set the
6441 flags. However, the only supported mnemonic in this mode
6442 says it doesn't. */
6443 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
6445 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6446 _("unshifted register required"));
6447 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6448 constraint (Rd != Rs,
6449 _("dest and source1 must be the same register"));
6451 inst.instruction = THUMB_OP16 (inst.instruction);
6452 inst.instruction |= Rd;
6453 inst.instruction |= Rn << 3;
6457 /* Similarly, but for instructions where the arithmetic operation is
6458 commutative, so we can allow either of them to be different from
6459 the destination operand in a 16-bit instruction. For instance, all
6460 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
6461 accepted. */
6462 static void
6463 do_t_arit3c (void)
6465 int Rd, Rs, Rn;
6467 Rd = inst.operands[0].reg;
6468 Rs = (inst.operands[1].present
6469 ? inst.operands[1].reg /* Rd, Rs, foo */
6470 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6471 Rn = inst.operands[2].reg;
6473 if (unified_syntax)
6475 if (!inst.operands[2].isreg)
6477 /* For an immediate, we always generate a 32-bit opcode;
6478 section relaxation will shrink it later if possible. */
6479 inst.instruction = THUMB_OP32 (inst.instruction);
6480 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6481 inst.instruction |= Rd << 8;
6482 inst.instruction |= Rs << 16;
6483 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6485 else
6487 bfd_boolean narrow;
6489 /* See if we can do this with a 16-bit instruction. */
6490 if (THUMB_SETS_FLAGS (inst.instruction))
6491 narrow = current_it_mask == 0;
6492 else
6493 narrow = current_it_mask != 0;
6495 if (Rd > 7 || Rn > 7 || Rs > 7)
6496 narrow = FALSE;
6497 if (inst.operands[2].shifted)
6498 narrow = FALSE;
6499 if (inst.size_req == 4)
6500 narrow = FALSE;
6502 if (narrow)
6504 if (Rd == Rs)
6506 inst.instruction = THUMB_OP16 (inst.instruction);
6507 inst.instruction |= Rd;
6508 inst.instruction |= Rn << 3;
6509 return;
6511 if (Rd == Rn)
6513 inst.instruction = THUMB_OP16 (inst.instruction);
6514 inst.instruction |= Rd;
6515 inst.instruction |= Rs << 3;
6516 return;
6520 /* If we get here, it can't be done in 16 bits. */
6521 constraint (inst.operands[2].shifted
6522 && inst.operands[2].immisreg,
6523 _("shift must be constant"));
6524 inst.instruction = THUMB_OP32 (inst.instruction);
6525 inst.instruction |= Rd << 8;
6526 inst.instruction |= Rs << 16;
6527 encode_thumb32_shifted_operand (2);
6530 else
6532 /* On its face this is a lie - the instruction does set the
6533 flags. However, the only supported mnemonic in this mode
6534 says it doesn't. */
6535 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
6537 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6538 _("unshifted register required"));
6539 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6541 inst.instruction = THUMB_OP16 (inst.instruction);
6542 inst.instruction |= Rd;
6544 if (Rd == Rs)
6545 inst.instruction |= Rn << 3;
6546 else if (Rd == Rn)
6547 inst.instruction |= Rs << 3;
6548 else
6549 constraint (1, _("dest must overlap one source register"));
6553 static void
6554 do_t_barrier (void)
6556 if (inst.operands[0].present)
6558 constraint ((inst.instruction & 0xf0) != 0x40
6559 && inst.operands[0].imm != 0xf,
6560 "bad barrier type");
6561 inst.instruction |= inst.operands[0].imm;
6563 else
6564 inst.instruction |= 0xf;
6567 static void
6568 do_t_bfc (void)
6570 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6571 constraint (msb > 32, _("bit-field extends past end of register"));
6572 /* The instruction encoding stores the LSB and MSB,
6573 not the LSB and width. */
6574 inst.instruction |= inst.operands[0].reg << 8;
6575 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
6576 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
6577 inst.instruction |= msb - 1;
6580 static void
6581 do_t_bfi (void)
6583 unsigned int msb;
6585 /* #0 in second position is alternative syntax for bfc, which is
6586 the same instruction but with REG_PC in the Rm field. */
6587 if (!inst.operands[1].isreg)
6588 inst.operands[1].reg = REG_PC;
6590 msb = inst.operands[2].imm + inst.operands[3].imm;
6591 constraint (msb > 32, _("bit-field extends past end of register"));
6592 /* The instruction encoding stores the LSB and MSB,
6593 not the LSB and width. */
6594 inst.instruction |= inst.operands[0].reg << 8;
6595 inst.instruction |= inst.operands[1].reg << 16;
6596 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6597 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6598 inst.instruction |= msb - 1;
6601 static void
6602 do_t_bfx (void)
6604 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6605 _("bit-field extends past end of register"));
6606 inst.instruction |= inst.operands[0].reg << 8;
6607 inst.instruction |= inst.operands[1].reg << 16;
6608 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6609 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6610 inst.instruction |= inst.operands[3].imm - 1;
6613 /* ARM V5 Thumb BLX (argument parse)
6614 BLX <target_addr> which is BLX(1)
6615 BLX <Rm> which is BLX(2)
6616 Unfortunately, there are two different opcodes for this mnemonic.
6617 So, the insns[].value is not used, and the code here zaps values
6618 into inst.instruction.
6620 ??? How to take advantage of the additional two bits of displacement
6621 available in Thumb32 mode? Need new relocation? */
6623 static void
6624 do_t_blx (void)
6626 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
6627 if (inst.operands[0].isreg)
6628 /* We have a register, so this is BLX(2). */
6629 inst.instruction |= inst.operands[0].reg << 3;
6630 else
6632 /* No register. This must be BLX(1). */
6633 inst.instruction = 0xf000e800;
6634 #ifdef OBJ_ELF
6635 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6636 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
6637 else
6638 #endif
6639 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
6640 inst.reloc.pc_rel = 1;
6644 static void
6645 do_t_branch (void)
6647 int opcode;
6648 int cond;
6650 if (current_it_mask)
6652 /* Conditional branches inside IT blocks are encoded as unconditional
6653 branches. */
6654 cond = COND_ALWAYS;
6655 /* A branch must be the last instruction in an IT block. */
6656 constraint (current_it_mask != 0x10, BAD_BRANCH);
6658 else
6659 cond = inst.cond;
6661 if (cond != COND_ALWAYS)
6662 opcode = T_MNEM_bcond;
6663 else
6664 opcode = inst.instruction;
6666 if (unified_syntax && inst.size_req == 4)
6668 inst.instruction = THUMB_OP32(opcode);
6669 if (cond == COND_ALWAYS)
6670 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
6671 else
6673 assert (cond != 0xF);
6674 inst.instruction |= cond << 22;
6675 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
6678 else
6680 inst.instruction = THUMB_OP16(opcode);
6681 if (cond == COND_ALWAYS)
6682 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
6683 else
6685 inst.instruction |= cond << 8;
6686 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
6688 /* Allow section relaxation. */
6689 if (unified_syntax && inst.size_req != 2)
6690 inst.relax = opcode;
6693 inst.reloc.pc_rel = 1;
6696 static void
6697 do_t_bkpt (void)
6699 constraint (inst.cond != COND_ALWAYS,
6700 _("instruction is always unconditional"));
6701 if (inst.operands[0].present)
6703 constraint (inst.operands[0].imm > 255,
6704 _("immediate value out of range"));
6705 inst.instruction |= inst.operands[0].imm;
6709 static void
6710 do_t_branch23 (void)
6712 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
6713 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
6714 inst.reloc.pc_rel = 1;
6716 /* If the destination of the branch is a defined symbol which does not have
6717 the THUMB_FUNC attribute, then we must be calling a function which has
6718 the (interfacearm) attribute. We look for the Thumb entry point to that
6719 function and change the branch to refer to that function instead. */
6720 if ( inst.reloc.exp.X_op == O_symbol
6721 && inst.reloc.exp.X_add_symbol != NULL
6722 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
6723 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
6724 inst.reloc.exp.X_add_symbol =
6725 find_real_start (inst.reloc.exp.X_add_symbol);
6728 static void
6729 do_t_bx (void)
6731 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
6732 inst.instruction |= inst.operands[0].reg << 3;
6733 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
6734 should cause the alignment to be checked once it is known. This is
6735 because BX PC only works if the instruction is word aligned. */
6738 static void
6739 do_t_bxj (void)
6741 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
6742 if (inst.operands[0].reg == REG_PC)
6743 as_tsktsk (_("use of r15 in bxj is not really useful"));
6745 inst.instruction |= inst.operands[0].reg << 16;
6748 static void
6749 do_t_clz (void)
6751 inst.instruction |= inst.operands[0].reg << 8;
6752 inst.instruction |= inst.operands[1].reg << 16;
6753 inst.instruction |= inst.operands[1].reg;
6756 static void
6757 do_t_cps (void)
6759 constraint (current_it_mask, BAD_NOT_IT);
6760 inst.instruction |= inst.operands[0].imm;
6763 static void
6764 do_t_cpsi (void)
6766 constraint (current_it_mask, BAD_NOT_IT);
6767 if (unified_syntax
6768 && (inst.operands[1].present || inst.size_req == 4)
6769 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
6771 unsigned int imod = (inst.instruction & 0x0030) >> 4;
6772 inst.instruction = 0xf3af8000;
6773 inst.instruction |= imod << 9;
6774 inst.instruction |= inst.operands[0].imm << 5;
6775 if (inst.operands[1].present)
6776 inst.instruction |= 0x100 | inst.operands[1].imm;
6778 else
6780 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
6781 && (inst.operands[0].imm & 4),
6782 _("selected processor does not support 'A' form "
6783 "of this instruction"));
6784 constraint (inst.operands[1].present || inst.size_req == 4,
6785 _("Thumb does not support the 2-argument "
6786 "form of this instruction"));
6787 inst.instruction |= inst.operands[0].imm;
6791 /* THUMB CPY instruction (argument parse). */
6793 static void
6794 do_t_cpy (void)
6796 if (inst.size_req == 4)
6798 inst.instruction = THUMB_OP32 (T_MNEM_mov);
6799 inst.instruction |= inst.operands[0].reg << 8;
6800 inst.instruction |= inst.operands[1].reg;
6802 else
6804 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6805 inst.instruction |= (inst.operands[0].reg & 0x7);
6806 inst.instruction |= inst.operands[1].reg << 3;
6810 static void
6811 do_t_czb (void)
6813 constraint (current_it_mask, BAD_NOT_IT);
6814 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6815 inst.instruction |= inst.operands[0].reg;
6816 inst.reloc.pc_rel = 1;
6817 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
6820 static void
6821 do_t_dbg (void)
6823 inst.instruction |= inst.operands[0].imm;
6826 static void
6827 do_t_div (void)
6829 if (!inst.operands[1].present)
6830 inst.operands[1].reg = inst.operands[0].reg;
6831 inst.instruction |= inst.operands[0].reg << 8;
6832 inst.instruction |= inst.operands[1].reg << 16;
6833 inst.instruction |= inst.operands[2].reg;
6836 static void
6837 do_t_hint (void)
6839 if (unified_syntax && inst.size_req == 4)
6840 inst.instruction = THUMB_OP32 (inst.instruction);
6841 else
6842 inst.instruction = THUMB_OP16 (inst.instruction);
6845 static void
6846 do_t_it (void)
6848 unsigned int cond = inst.operands[0].imm;
6850 constraint (current_it_mask, BAD_NOT_IT);
6851 current_it_mask = (inst.instruction & 0xf) | 0x10;
6852 current_cc = cond;
6854 /* If the condition is a negative condition, invert the mask. */
6855 if ((cond & 0x1) == 0x0)
6857 unsigned int mask = inst.instruction & 0x000f;
6859 if ((mask & 0x7) == 0)
6860 /* no conversion needed */;
6861 else if ((mask & 0x3) == 0)
6862 mask ^= 0x8;
6863 else if ((mask & 0x1) == 0)
6864 mask ^= 0xC;
6865 else
6866 mask ^= 0xE;
6868 inst.instruction &= 0xfff0;
6869 inst.instruction |= mask;
6872 inst.instruction |= cond << 4;
6875 static void
6876 do_t_ldmstm (void)
6878 /* This really doesn't seem worth it. */
6879 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6880 _("expression too complex"));
6881 constraint (inst.operands[1].writeback,
6882 _("Thumb load/store multiple does not support {reglist}^"));
6884 if (unified_syntax)
6886 /* See if we can use a 16-bit instruction. */
6887 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
6888 && inst.size_req != 4
6889 && inst.operands[0].reg <= 7
6890 && !(inst.operands[1].imm & ~0xff)
6891 && (inst.instruction == T_MNEM_stmia
6892 ? inst.operands[0].writeback
6893 : (inst.operands[0].writeback
6894 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
6896 if (inst.instruction == T_MNEM_stmia
6897 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
6898 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6899 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6900 inst.operands[0].reg);
6902 inst.instruction = THUMB_OP16 (inst.instruction);
6903 inst.instruction |= inst.operands[0].reg << 8;
6904 inst.instruction |= inst.operands[1].imm;
6906 else
6908 if (inst.operands[1].imm & (1 << 13))
6909 as_warn (_("SP should not be in register list"));
6910 if (inst.instruction == T_MNEM_stmia)
6912 if (inst.operands[1].imm & (1 << 15))
6913 as_warn (_("PC should not be in register list"));
6914 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
6915 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6916 inst.operands[0].reg);
6918 else
6920 if (inst.operands[1].imm & (1 << 14)
6921 && inst.operands[1].imm & (1 << 15))
6922 as_warn (_("LR and PC should not both be in register list"));
6923 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6924 && inst.operands[0].writeback)
6925 as_warn (_("base register should not be in register list "
6926 "when written back"));
6928 if (inst.instruction < 0xffff)
6929 inst.instruction = THUMB_OP32 (inst.instruction);
6930 inst.instruction |= inst.operands[0].reg << 16;
6931 inst.instruction |= inst.operands[1].imm;
6932 if (inst.operands[0].writeback)
6933 inst.instruction |= WRITE_BACK;
6936 else
6938 constraint (inst.operands[0].reg > 7
6939 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
6940 if (inst.instruction == T_MNEM_stmia)
6942 if (!inst.operands[0].writeback)
6943 as_warn (_("this instruction will write back the base register"));
6944 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6945 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6946 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6947 inst.operands[0].reg);
6949 else
6951 if (!inst.operands[0].writeback
6952 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
6953 as_warn (_("this instruction will write back the base register"));
6954 else if (inst.operands[0].writeback
6955 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
6956 as_warn (_("this instruction will not write back the base register"));
6959 inst.instruction = THUMB_OP16 (inst.instruction);
6960 inst.instruction |= inst.operands[0].reg << 8;
6961 inst.instruction |= inst.operands[1].imm;
6965 static void
6966 do_t_ldrex (void)
6968 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6969 || inst.operands[1].postind || inst.operands[1].writeback
6970 || inst.operands[1].immisreg || inst.operands[1].shifted
6971 || inst.operands[1].negative,
6972 BAD_ADDR_MODE);
6974 inst.instruction |= inst.operands[0].reg << 12;
6975 inst.instruction |= inst.operands[1].reg << 16;
6976 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
6979 static void
6980 do_t_ldrexd (void)
6982 if (!inst.operands[1].present)
6984 constraint (inst.operands[0].reg == REG_LR,
6985 _("r14 not allowed as first register "
6986 "when second register is omitted"));
6987 inst.operands[1].reg = inst.operands[0].reg + 1;
6989 constraint (inst.operands[0].reg == inst.operands[1].reg,
6990 BAD_OVERLAP);
6992 inst.instruction |= inst.operands[0].reg << 12;
6993 inst.instruction |= inst.operands[1].reg << 8;
6994 inst.instruction |= inst.operands[2].reg << 16;
6997 static void
6998 do_t_ldst (void)
7000 unsigned long opcode;
7001 int Rn;
7003 opcode = inst.instruction;
7004 if (unified_syntax)
7006 if (!inst.operands[1].isreg)
7008 if (opcode <= 0xffff)
7009 inst.instruction = THUMB_OP32 (opcode);
7010 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
7011 return;
7013 if (inst.operands[1].isreg
7014 && !inst.operands[1].writeback
7015 && !inst.operands[1].shifted && !inst.operands[1].postind
7016 && !inst.operands[1].negative && inst.operands[0].reg <= 7
7017 && opcode <= 0xffff
7018 && inst.size_req != 4)
7020 /* Insn may have a 16-bit form. */
7021 Rn = inst.operands[1].reg;
7022 if (inst.operands[1].immisreg)
7024 inst.instruction = THUMB_OP16 (opcode);
7025 /* [Rn, Ri] */
7026 if (Rn <= 7 && inst.operands[1].imm <= 7)
7027 goto op16;
7029 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
7030 && opcode != T_MNEM_ldrsb)
7031 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
7032 || (Rn == REG_SP && opcode == T_MNEM_str))
7034 /* [Rn, #const] */
7035 if (Rn > 7)
7037 if (Rn == REG_PC)
7039 if (inst.reloc.pc_rel)
7040 opcode = T_MNEM_ldr_pc2;
7041 else
7042 opcode = T_MNEM_ldr_pc;
7044 else
7046 if (opcode == T_MNEM_ldr)
7047 opcode = T_MNEM_ldr_sp;
7048 else
7049 opcode = T_MNEM_str_sp;
7051 inst.instruction = inst.operands[0].reg << 8;
7053 else
7055 inst.instruction = inst.operands[0].reg;
7056 inst.instruction |= inst.operands[1].reg << 3;
7058 inst.instruction |= THUMB_OP16 (opcode);
7059 if (inst.size_req == 2)
7060 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
7061 else
7062 inst.relax = opcode;
7063 return;
7066 /* Definitely a 32-bit variant. */
7067 inst.instruction = THUMB_OP32 (opcode);
7068 inst.instruction |= inst.operands[0].reg << 12;
7069 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
7070 return;
7073 constraint (inst.operands[0].reg > 7, BAD_HIREG);
7075 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
7077 /* Only [Rn,Rm] is acceptable. */
7078 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
7079 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
7080 || inst.operands[1].postind || inst.operands[1].shifted
7081 || inst.operands[1].negative,
7082 _("Thumb does not support this addressing mode"));
7083 inst.instruction = THUMB_OP16 (inst.instruction);
7084 goto op16;
7087 inst.instruction = THUMB_OP16 (inst.instruction);
7088 if (!inst.operands[1].isreg)
7089 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
7090 return;
7092 constraint (!inst.operands[1].preind
7093 || inst.operands[1].shifted
7094 || inst.operands[1].writeback,
7095 _("Thumb does not support this addressing mode"));
7096 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
7098 constraint (inst.instruction & 0x0600,
7099 _("byte or halfword not valid for base register"));
7100 constraint (inst.operands[1].reg == REG_PC
7101 && !(inst.instruction & THUMB_LOAD_BIT),
7102 _("r15 based store not allowed"));
7103 constraint (inst.operands[1].immisreg,
7104 _("invalid base register for register offset"));
7106 if (inst.operands[1].reg == REG_PC)
7107 inst.instruction = T_OPCODE_LDR_PC;
7108 else if (inst.instruction & THUMB_LOAD_BIT)
7109 inst.instruction = T_OPCODE_LDR_SP;
7110 else
7111 inst.instruction = T_OPCODE_STR_SP;
7113 inst.instruction |= inst.operands[0].reg << 8;
7114 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
7115 return;
7118 constraint (inst.operands[1].reg > 7, BAD_HIREG);
7119 if (!inst.operands[1].immisreg)
7121 /* Immediate offset. */
7122 inst.instruction |= inst.operands[0].reg;
7123 inst.instruction |= inst.operands[1].reg << 3;
7124 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
7125 return;
7128 /* Register offset. */
7129 constraint (inst.operands[1].imm > 7, BAD_HIREG);
7130 constraint (inst.operands[1].negative,
7131 _("Thumb does not support this addressing mode"));
7133 op16:
7134 switch (inst.instruction)
7136 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
7137 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
7138 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
7139 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
7140 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
7141 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
7142 case 0x5600 /* ldrsb */:
7143 case 0x5e00 /* ldrsh */: break;
7144 default: abort ();
7147 inst.instruction |= inst.operands[0].reg;
7148 inst.instruction |= inst.operands[1].reg << 3;
7149 inst.instruction |= inst.operands[1].imm << 6;
7152 static void
7153 do_t_ldstd (void)
7155 if (!inst.operands[1].present)
7157 inst.operands[1].reg = inst.operands[0].reg + 1;
7158 constraint (inst.operands[0].reg == REG_LR,
7159 _("r14 not allowed here"));
7161 inst.instruction |= inst.operands[0].reg << 12;
7162 inst.instruction |= inst.operands[1].reg << 8;
7163 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
7167 static void
7168 do_t_ldstt (void)
7170 inst.instruction |= inst.operands[0].reg << 12;
7171 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
7174 static void
7175 do_t_mla (void)
7177 inst.instruction |= inst.operands[0].reg << 8;
7178 inst.instruction |= inst.operands[1].reg << 16;
7179 inst.instruction |= inst.operands[2].reg;
7180 inst.instruction |= inst.operands[3].reg << 12;
7183 static void
7184 do_t_mlal (void)
7186 inst.instruction |= inst.operands[0].reg << 12;
7187 inst.instruction |= inst.operands[1].reg << 8;
7188 inst.instruction |= inst.operands[2].reg << 16;
7189 inst.instruction |= inst.operands[3].reg;
7192 static void
7193 do_t_mov_cmp (void)
7195 if (unified_syntax)
7197 int r0off = (inst.instruction == T_MNEM_mov
7198 || inst.instruction == T_MNEM_movs) ? 8 : 16;
7199 unsigned long opcode;
7200 bfd_boolean narrow;
7201 bfd_boolean low_regs;
7203 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
7204 opcode = inst.instruction;
7205 if (current_it_mask)
7206 narrow = opcode != T_MNEM_movs;
7207 else
7208 narrow = opcode != T_MNEM_movs || low_regs;
7209 if (inst.size_req == 4
7210 || inst.operands[1].shifted)
7211 narrow = FALSE;
7213 if (!inst.operands[1].isreg)
7215 /* Immediate operand. */
7216 if (current_it_mask == 0 && opcode == T_MNEM_mov)
7217 narrow = 0;
7218 if (low_regs && narrow)
7220 inst.instruction = THUMB_OP16 (opcode);
7221 inst.instruction |= inst.operands[0].reg << 8;
7222 if (inst.size_req == 2)
7223 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
7224 else
7225 inst.relax = opcode;
7227 else
7229 inst.instruction = THUMB_OP32 (inst.instruction);
7230 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7231 inst.instruction |= inst.operands[0].reg << r0off;
7232 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7235 else if (!narrow)
7237 inst.instruction = THUMB_OP32 (inst.instruction);
7238 inst.instruction |= inst.operands[0].reg << r0off;
7239 encode_thumb32_shifted_operand (1);
7241 else
7242 switch (inst.instruction)
7244 case T_MNEM_mov:
7245 inst.instruction = T_OPCODE_MOV_HR;
7246 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
7247 inst.instruction |= (inst.operands[0].reg & 0x7);
7248 inst.instruction |= inst.operands[1].reg << 3;
7249 break;
7251 case T_MNEM_movs:
7252 /* We know we have low registers at this point.
7253 Generate ADD Rd, Rs, #0. */
7254 inst.instruction = T_OPCODE_ADD_I3;
7255 inst.instruction |= inst.operands[0].reg;
7256 inst.instruction |= inst.operands[1].reg << 3;
7257 break;
7259 case T_MNEM_cmp:
7260 if (low_regs)
7262 inst.instruction = T_OPCODE_CMP_LR;
7263 inst.instruction |= inst.operands[0].reg;
7264 inst.instruction |= inst.operands[1].reg << 3;
7266 else
7268 inst.instruction = T_OPCODE_CMP_HR;
7269 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
7270 inst.instruction |= (inst.operands[0].reg & 0x7);
7271 inst.instruction |= inst.operands[1].reg << 3;
7273 break;
7275 return;
7278 inst.instruction = THUMB_OP16 (inst.instruction);
7279 if (inst.operands[1].isreg)
7281 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
7283 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
7284 since a MOV instruction produces unpredictable results. */
7285 if (inst.instruction == T_OPCODE_MOV_I8)
7286 inst.instruction = T_OPCODE_ADD_I3;
7287 else
7288 inst.instruction = T_OPCODE_CMP_LR;
7290 inst.instruction |= inst.operands[0].reg;
7291 inst.instruction |= inst.operands[1].reg << 3;
7293 else
7295 if (inst.instruction == T_OPCODE_MOV_I8)
7296 inst.instruction = T_OPCODE_MOV_HR;
7297 else
7298 inst.instruction = T_OPCODE_CMP_HR;
7299 do_t_cpy ();
7302 else
7304 constraint (inst.operands[0].reg > 7,
7305 _("only lo regs allowed with immediate"));
7306 inst.instruction |= inst.operands[0].reg << 8;
7307 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
7311 static void
7312 do_t_mov16 (void)
7314 inst.instruction |= inst.operands[0].reg << 8;
7315 inst.instruction |= (inst.operands[1].imm & 0xf000) << 4;
7316 inst.instruction |= (inst.operands[1].imm & 0x0800) << 15;
7317 inst.instruction |= (inst.operands[1].imm & 0x0700) << 4;
7318 inst.instruction |= (inst.operands[1].imm & 0x00ff);
7321 static void
7322 do_t_mvn_tst (void)
7324 if (unified_syntax)
7326 int r0off = (inst.instruction == T_MNEM_mvn
7327 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
7328 bfd_boolean narrow;
7330 if (inst.size_req == 4
7331 || inst.instruction > 0xffff
7332 || inst.operands[1].shifted
7333 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7334 narrow = FALSE;
7335 else if (inst.instruction == T_MNEM_cmn)
7336 narrow = TRUE;
7337 else if (THUMB_SETS_FLAGS (inst.instruction))
7338 narrow = (current_it_mask == 0);
7339 else
7340 narrow = (current_it_mask != 0);
7342 if (!inst.operands[1].isreg)
7344 /* For an immediate, we always generate a 32-bit opcode;
7345 section relaxation will shrink it later if possible. */
7346 if (inst.instruction < 0xffff)
7347 inst.instruction = THUMB_OP32 (inst.instruction);
7348 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7349 inst.instruction |= inst.operands[0].reg << r0off;
7350 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7352 else
7354 /* See if we can do this with a 16-bit instruction. */
7355 if (narrow)
7357 inst.instruction = THUMB_OP16 (inst.instruction);
7358 inst.instruction |= inst.operands[0].reg;
7359 inst.instruction |= inst.operands[1].reg << 3;
7361 else
7363 constraint (inst.operands[1].shifted
7364 && inst.operands[1].immisreg,
7365 _("shift must be constant"));
7366 if (inst.instruction < 0xffff)
7367 inst.instruction = THUMB_OP32 (inst.instruction);
7368 inst.instruction |= inst.operands[0].reg << r0off;
7369 encode_thumb32_shifted_operand (1);
7373 else
7375 constraint (inst.instruction > 0xffff
7376 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
7377 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
7378 _("unshifted register required"));
7379 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7380 BAD_HIREG);
7382 inst.instruction = THUMB_OP16 (inst.instruction);
7383 inst.instruction |= inst.operands[0].reg;
7384 inst.instruction |= inst.operands[1].reg << 3;
7388 static void
7389 do_t_mrs (void)
7391 int flags;
7392 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
7393 if (flags == 0)
7395 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
7396 _("selected processor does not support "
7397 "requested special purpose register"));
7399 else
7401 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
7402 _("selected processor does not support "
7403 "requested special purpose register %x"));
7404 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7405 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
7406 _("'CPSR' or 'SPSR' expected"));
7409 inst.instruction |= inst.operands[0].reg << 8;
7410 inst.instruction |= (flags & SPSR_BIT) >> 2;
7411 inst.instruction |= inst.operands[1].imm & 0xff;
7414 static void
7415 do_t_msr (void)
7417 int flags;
7419 constraint (!inst.operands[1].isreg,
7420 _("Thumb encoding does not support an immediate here"));
7421 flags = inst.operands[0].imm;
7422 if (flags & ~0xff)
7424 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
7425 _("selected processor does not support "
7426 "requested special purpose register"));
7428 else
7430 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
7431 _("selected processor does not support "
7432 "requested special purpose register"));
7433 flags |= PSR_f;
7435 inst.instruction |= (flags & SPSR_BIT) >> 2;
7436 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
7437 inst.instruction |= (flags & 0xff);
7438 inst.instruction |= inst.operands[1].reg << 16;
7441 static void
7442 do_t_mul (void)
7444 if (!inst.operands[2].present)
7445 inst.operands[2].reg = inst.operands[0].reg;
7447 /* There is no 32-bit MULS and no 16-bit MUL. */
7448 if (unified_syntax && inst.instruction == T_MNEM_mul)
7450 inst.instruction = THUMB_OP32 (inst.instruction);
7451 inst.instruction |= inst.operands[0].reg << 8;
7452 inst.instruction |= inst.operands[1].reg << 16;
7453 inst.instruction |= inst.operands[2].reg << 0;
7455 else
7457 constraint (!unified_syntax
7458 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
7459 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7460 BAD_HIREG);
7462 inst.instruction = THUMB_OP16 (inst.instruction);
7463 inst.instruction |= inst.operands[0].reg;
7465 if (inst.operands[0].reg == inst.operands[1].reg)
7466 inst.instruction |= inst.operands[2].reg << 3;
7467 else if (inst.operands[0].reg == inst.operands[2].reg)
7468 inst.instruction |= inst.operands[1].reg << 3;
7469 else
7470 constraint (1, _("dest must overlap one source register"));
7474 static void
7475 do_t_mull (void)
7477 inst.instruction |= inst.operands[0].reg << 12;
7478 inst.instruction |= inst.operands[1].reg << 8;
7479 inst.instruction |= inst.operands[2].reg << 16;
7480 inst.instruction |= inst.operands[3].reg;
7482 if (inst.operands[0].reg == inst.operands[1].reg)
7483 as_tsktsk (_("rdhi and rdlo must be different"));
7486 static void
7487 do_t_nop (void)
7489 if (unified_syntax)
7491 if (inst.size_req == 4 || inst.operands[0].imm > 15)
7493 inst.instruction = THUMB_OP32 (inst.instruction);
7494 inst.instruction |= inst.operands[0].imm;
7496 else
7498 inst.instruction = THUMB_OP16 (inst.instruction);
7499 inst.instruction |= inst.operands[0].imm << 4;
7502 else
7504 constraint (inst.operands[0].present,
7505 _("Thumb does not support NOP with hints"));
7506 inst.instruction = 0x46c0;
7510 static void
7511 do_t_neg (void)
7513 if (unified_syntax)
7515 bfd_boolean narrow;
7517 if (THUMB_SETS_FLAGS (inst.instruction))
7518 narrow = (current_it_mask == 0);
7519 else
7520 narrow = (current_it_mask != 0);
7521 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7522 narrow = FALSE;
7523 if (inst.size_req == 4)
7524 narrow = FALSE;
7526 if (!narrow)
7528 inst.instruction = THUMB_OP32 (inst.instruction);
7529 inst.instruction |= inst.operands[0].reg << 8;
7530 inst.instruction |= inst.operands[1].reg << 16;
7532 else
7534 inst.instruction = THUMB_OP16 (inst.instruction);
7535 inst.instruction |= inst.operands[0].reg;
7536 inst.instruction |= inst.operands[1].reg << 3;
7539 else
7541 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7542 BAD_HIREG);
7543 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
7545 inst.instruction = THUMB_OP16 (inst.instruction);
7546 inst.instruction |= inst.operands[0].reg;
7547 inst.instruction |= inst.operands[1].reg << 3;
7551 static void
7552 do_t_pkhbt (void)
7554 inst.instruction |= inst.operands[0].reg << 8;
7555 inst.instruction |= inst.operands[1].reg << 16;
7556 inst.instruction |= inst.operands[2].reg;
7557 if (inst.operands[3].present)
7559 unsigned int val = inst.reloc.exp.X_add_number;
7560 constraint (inst.reloc.exp.X_op != O_constant,
7561 _("expression too complex"));
7562 inst.instruction |= (val & 0x1c) << 10;
7563 inst.instruction |= (val & 0x03) << 6;
7567 static void
7568 do_t_pkhtb (void)
7570 if (!inst.operands[3].present)
7571 inst.instruction &= ~0x00000020;
7572 do_t_pkhbt ();
7575 static void
7576 do_t_pld (void)
7578 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
7581 static void
7582 do_t_push_pop (void)
7584 unsigned mask;
7586 constraint (inst.operands[0].writeback,
7587 _("push/pop do not support {reglist}^"));
7588 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
7589 _("expression too complex"));
7591 mask = inst.operands[0].imm;
7592 if ((mask & ~0xff) == 0)
7593 inst.instruction = THUMB_OP16 (inst.instruction);
7594 else if ((inst.instruction == T_MNEM_push
7595 && (mask & ~0xff) == 1 << REG_LR)
7596 || (inst.instruction == T_MNEM_pop
7597 && (mask & ~0xff) == 1 << REG_PC))
7599 inst.instruction = THUMB_OP16 (inst.instruction);
7600 inst.instruction |= THUMB_PP_PC_LR;
7601 mask &= 0xff;
7603 else if (unified_syntax)
7605 if (mask & (1 << 13))
7606 inst.error = _("SP not allowed in register list");
7607 if (inst.instruction == T_MNEM_push)
7609 if (mask & (1 << 15))
7610 inst.error = _("PC not allowed in register list");
7612 else
7614 if (mask & (1 << 14)
7615 && mask & (1 << 15))
7616 inst.error = _("LR and PC should not both be in register list");
7618 if ((mask & (mask - 1)) == 0)
7620 /* Single register push/pop implemented as str/ldr. */
7621 if (inst.instruction == T_MNEM_push)
7622 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
7623 else
7624 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
7625 mask = ffs(mask) - 1;
7626 mask <<= 12;
7628 else
7629 inst.instruction = THUMB_OP32 (inst.instruction);
7631 else
7633 inst.error = _("invalid register list to push/pop instruction");
7634 return;
7637 inst.instruction |= mask;
7640 static void
7641 do_t_rbit (void)
7643 inst.instruction |= inst.operands[0].reg << 8;
7644 inst.instruction |= inst.operands[1].reg << 16;
7647 static void
7648 do_t_rev (void)
7650 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7651 && inst.size_req != 4)
7653 inst.instruction = THUMB_OP16 (inst.instruction);
7654 inst.instruction |= inst.operands[0].reg;
7655 inst.instruction |= inst.operands[1].reg << 3;
7657 else if (unified_syntax)
7659 inst.instruction = THUMB_OP32 (inst.instruction);
7660 inst.instruction |= inst.operands[0].reg << 8;
7661 inst.instruction |= inst.operands[1].reg << 16;
7662 inst.instruction |= inst.operands[1].reg;
7664 else
7665 inst.error = BAD_HIREG;
7668 static void
7669 do_t_rsb (void)
7671 int Rd, Rs;
7673 Rd = inst.operands[0].reg;
7674 Rs = (inst.operands[1].present
7675 ? inst.operands[1].reg /* Rd, Rs, foo */
7676 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
7678 inst.instruction |= Rd << 8;
7679 inst.instruction |= Rs << 16;
7680 if (!inst.operands[2].isreg)
7682 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7683 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7685 else
7686 encode_thumb32_shifted_operand (2);
7689 static void
7690 do_t_setend (void)
7692 constraint (current_it_mask, BAD_NOT_IT);
7693 if (inst.operands[0].imm)
7694 inst.instruction |= 0x8;
7697 static void
7698 do_t_shift (void)
7700 if (!inst.operands[1].present)
7701 inst.operands[1].reg = inst.operands[0].reg;
7703 if (unified_syntax)
7705 bfd_boolean narrow;
7706 int shift_kind;
7708 switch (inst.instruction)
7710 case T_MNEM_asr:
7711 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
7712 case T_MNEM_lsl:
7713 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
7714 case T_MNEM_lsr:
7715 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
7716 case T_MNEM_ror:
7717 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
7718 default: abort ();
7721 if (THUMB_SETS_FLAGS (inst.instruction))
7722 narrow = (current_it_mask == 0);
7723 else
7724 narrow = (current_it_mask != 0);
7725 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7726 narrow = FALSE;
7727 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
7728 narrow = FALSE;
7729 if (inst.operands[2].isreg
7730 && (inst.operands[1].reg != inst.operands[0].reg
7731 || inst.operands[2].reg > 7))
7732 narrow = FALSE;
7733 if (inst.size_req == 4)
7734 narrow = FALSE;
7736 if (!narrow)
7738 if (inst.operands[2].isreg)
7740 inst.instruction = THUMB_OP32 (inst.instruction);
7741 inst.instruction |= inst.operands[0].reg << 8;
7742 inst.instruction |= inst.operands[1].reg << 16;
7743 inst.instruction |= inst.operands[2].reg;
7745 else
7747 inst.operands[1].shifted = 1;
7748 inst.operands[1].shift_kind = shift_kind;
7749 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
7750 ? T_MNEM_movs : T_MNEM_mov);
7751 inst.instruction |= inst.operands[0].reg << 8;
7752 encode_thumb32_shifted_operand (1);
7753 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
7754 inst.reloc.type = BFD_RELOC_UNUSED;
7757 else
7759 if (inst.operands[2].isreg)
7761 switch (shift_kind)
7763 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
7764 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
7765 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
7766 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
7767 default: abort ();
7770 inst.instruction |= inst.operands[0].reg;
7771 inst.instruction |= inst.operands[2].reg << 3;
7773 else
7775 switch (shift_kind)
7777 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
7778 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
7779 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
7780 default: abort ();
7782 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7783 inst.instruction |= inst.operands[0].reg;
7784 inst.instruction |= inst.operands[1].reg << 3;
7788 else
7790 constraint (inst.operands[0].reg > 7
7791 || inst.operands[1].reg > 7, BAD_HIREG);
7792 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
7794 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
7796 constraint (inst.operands[2].reg > 7, BAD_HIREG);
7797 constraint (inst.operands[0].reg != inst.operands[1].reg,
7798 _("source1 and dest must be same register"));
7800 switch (inst.instruction)
7802 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
7803 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
7804 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
7805 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
7806 default: abort ();
7809 inst.instruction |= inst.operands[0].reg;
7810 inst.instruction |= inst.operands[2].reg << 3;
7812 else
7814 switch (inst.instruction)
7816 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
7817 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
7818 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
7819 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
7820 default: abort ();
7822 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7823 inst.instruction |= inst.operands[0].reg;
7824 inst.instruction |= inst.operands[1].reg << 3;
7829 static void
7830 do_t_simd (void)
7832 inst.instruction |= inst.operands[0].reg << 8;
7833 inst.instruction |= inst.operands[1].reg << 16;
7834 inst.instruction |= inst.operands[2].reg;
7837 static void
7838 do_t_smc (void)
7840 unsigned int value = inst.reloc.exp.X_add_number;
7841 constraint (inst.reloc.exp.X_op != O_constant,
7842 _("expression too complex"));
7843 inst.reloc.type = BFD_RELOC_UNUSED;
7844 inst.instruction |= (value & 0xf000) >> 12;
7845 inst.instruction |= (value & 0x0ff0);
7846 inst.instruction |= (value & 0x000f) << 16;
7849 static void
7850 do_t_ssat (void)
7852 inst.instruction |= inst.operands[0].reg << 8;
7853 inst.instruction |= inst.operands[1].imm - 1;
7854 inst.instruction |= inst.operands[2].reg << 16;
7856 if (inst.operands[3].present)
7858 constraint (inst.reloc.exp.X_op != O_constant,
7859 _("expression too complex"));
7861 if (inst.reloc.exp.X_add_number != 0)
7863 if (inst.operands[3].shift_kind == SHIFT_ASR)
7864 inst.instruction |= 0x00200000; /* sh bit */
7865 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7866 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7868 inst.reloc.type = BFD_RELOC_UNUSED;
7872 static void
7873 do_t_ssat16 (void)
7875 inst.instruction |= inst.operands[0].reg << 8;
7876 inst.instruction |= inst.operands[1].imm - 1;
7877 inst.instruction |= inst.operands[2].reg << 16;
7880 static void
7881 do_t_strex (void)
7883 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7884 || inst.operands[2].postind || inst.operands[2].writeback
7885 || inst.operands[2].immisreg || inst.operands[2].shifted
7886 || inst.operands[2].negative,
7887 BAD_ADDR_MODE);
7889 inst.instruction |= inst.operands[0].reg << 8;
7890 inst.instruction |= inst.operands[1].reg << 12;
7891 inst.instruction |= inst.operands[2].reg << 16;
7892 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
7895 static void
7896 do_t_strexd (void)
7898 if (!inst.operands[2].present)
7899 inst.operands[2].reg = inst.operands[1].reg + 1;
7901 constraint (inst.operands[0].reg == inst.operands[1].reg
7902 || inst.operands[0].reg == inst.operands[2].reg
7903 || inst.operands[0].reg == inst.operands[3].reg
7904 || inst.operands[1].reg == inst.operands[2].reg,
7905 BAD_OVERLAP);
7907 inst.instruction |= inst.operands[0].reg;
7908 inst.instruction |= inst.operands[1].reg << 12;
7909 inst.instruction |= inst.operands[2].reg << 8;
7910 inst.instruction |= inst.operands[3].reg << 16;
7913 static void
7914 do_t_sxtah (void)
7916 inst.instruction |= inst.operands[0].reg << 8;
7917 inst.instruction |= inst.operands[1].reg << 16;
7918 inst.instruction |= inst.operands[2].reg;
7919 inst.instruction |= inst.operands[3].imm << 4;
7922 static void
7923 do_t_sxth (void)
7925 if (inst.instruction <= 0xffff && inst.size_req != 4
7926 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7927 && (!inst.operands[2].present || inst.operands[2].imm == 0))
7929 inst.instruction = THUMB_OP16 (inst.instruction);
7930 inst.instruction |= inst.operands[0].reg;
7931 inst.instruction |= inst.operands[1].reg << 3;
7933 else if (unified_syntax)
7935 if (inst.instruction <= 0xffff)
7936 inst.instruction = THUMB_OP32 (inst.instruction);
7937 inst.instruction |= inst.operands[0].reg << 8;
7938 inst.instruction |= inst.operands[1].reg;
7939 inst.instruction |= inst.operands[2].imm << 4;
7941 else
7943 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
7944 _("Thumb encoding does not support rotation"));
7945 constraint (1, BAD_HIREG);
7949 static void
7950 do_t_swi (void)
7952 inst.reloc.type = BFD_RELOC_ARM_SWI;
7955 static void
7956 do_t_tb (void)
7958 int half;
7960 half = (inst.instruction & 0x10) != 0;
7961 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
7962 constraint (inst.operands[0].immisreg,
7963 _("instruction requires register index"));
7964 constraint (inst.operands[0].imm == 15,
7965 _("PC is not a valid index register"));
7966 constraint (!half && inst.operands[0].shifted,
7967 _("instruction does not allow shifted index"));
7968 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
7971 static void
7972 do_t_usat (void)
7974 inst.instruction |= inst.operands[0].reg << 8;
7975 inst.instruction |= inst.operands[1].imm;
7976 inst.instruction |= inst.operands[2].reg << 16;
7978 if (inst.operands[3].present)
7980 constraint (inst.reloc.exp.X_op != O_constant,
7981 _("expression too complex"));
7982 if (inst.reloc.exp.X_add_number != 0)
7984 if (inst.operands[3].shift_kind == SHIFT_ASR)
7985 inst.instruction |= 0x00200000; /* sh bit */
7987 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7988 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7990 inst.reloc.type = BFD_RELOC_UNUSED;
7994 static void
7995 do_t_usat16 (void)
7997 inst.instruction |= inst.operands[0].reg << 8;
7998 inst.instruction |= inst.operands[1].imm;
7999 inst.instruction |= inst.operands[2].reg << 16;
8002 /* Overall per-instruction processing. */
8004 /* We need to be able to fix up arbitrary expressions in some statements.
8005 This is so that we can handle symbols that are an arbitrary distance from
8006 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
8007 which returns part of an address in a form which will be valid for
8008 a data instruction. We do this by pushing the expression into a symbol
8009 in the expr_section, and creating a fix for that. */
8011 static void
8012 fix_new_arm (fragS * frag,
8013 int where,
8014 short int size,
8015 expressionS * exp,
8016 int pc_rel,
8017 int reloc)
8019 fixS * new_fix;
8021 switch (exp->X_op)
8023 case O_constant:
8024 case O_symbol:
8025 case O_add:
8026 case O_subtract:
8027 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
8028 break;
8030 default:
8031 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
8032 pc_rel, reloc);
8033 break;
8036 /* Mark whether the fix is to a THUMB instruction, or an ARM
8037 instruction. */
8038 new_fix->tc_fix_data = thumb_mode;
8041 /* Create a frg for an instruction requiring relaxation. */
8042 static void
8043 output_relax_insn (void)
8045 char * to;
8046 symbolS *sym;
8047 int offset;
8049 #ifdef OBJ_ELF
8050 /* The size of the instruction is unknown, so tie the debug info to the
8051 start of the instruction. */
8052 dwarf2_emit_insn (0);
8053 #endif
8055 switch (inst.reloc.exp.X_op)
8057 case O_symbol:
8058 sym = inst.reloc.exp.X_add_symbol;
8059 offset = inst.reloc.exp.X_add_number;
8060 break;
8061 case O_constant:
8062 sym = NULL;
8063 offset = inst.reloc.exp.X_add_number;
8064 break;
8065 default:
8066 sym = make_expr_symbol (&inst.reloc.exp);
8067 offset = 0;
8068 break;
8070 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
8071 inst.relax, sym, offset, NULL/*offset, opcode*/);
8072 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
8075 /* Write a 32-bit thumb instruction to buf. */
8076 static void
8077 put_thumb32_insn (char * buf, unsigned long insn)
8079 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
8080 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
8083 static void
8084 output_inst (const char * str)
8086 char * to = NULL;
8088 if (inst.error)
8090 as_bad ("%s -- `%s'", inst.error, str);
8091 return;
8093 if (inst.relax) {
8094 output_relax_insn();
8095 return;
8097 if (inst.size == 0)
8098 return;
8100 to = frag_more (inst.size);
8102 if (thumb_mode && (inst.size > THUMB_SIZE))
8104 assert (inst.size == (2 * THUMB_SIZE));
8105 put_thumb32_insn (to, inst.instruction);
8107 else if (inst.size > INSN_SIZE)
8109 assert (inst.size == (2 * INSN_SIZE));
8110 md_number_to_chars (to, inst.instruction, INSN_SIZE);
8111 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
8113 else
8114 md_number_to_chars (to, inst.instruction, inst.size);
8116 if (inst.reloc.type != BFD_RELOC_UNUSED)
8117 fix_new_arm (frag_now, to - frag_now->fr_literal,
8118 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
8119 inst.reloc.type);
8121 #ifdef OBJ_ELF
8122 dwarf2_emit_insn (inst.size);
8123 #endif
8126 /* Tag values used in struct asm_opcode's tag field. */
8127 enum opcode_tag
8129 OT_unconditional, /* Instruction cannot be conditionalized.
8130 The ARM condition field is still 0xE. */
8131 OT_unconditionalF, /* Instruction cannot be conditionalized
8132 and carries 0xF in its ARM condition field. */
8133 OT_csuffix, /* Instruction takes a conditional suffix. */
8134 OT_cinfix3, /* Instruction takes a conditional infix,
8135 beginning at character index 3. (In
8136 unified mode, it becomes a suffix.) */
8137 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
8138 character index 3, even in unified mode. Used for
8139 legacy instructions where suffix and infix forms
8140 may be ambiguous. */
8141 OT_csuf_or_in3, /* Instruction takes either a conditional
8142 suffix or an infix at character index 3. */
8143 OT_odd_infix_unc, /* This is the unconditional variant of an
8144 instruction that takes a conditional infix
8145 at an unusual position. In unified mode,
8146 this variant will accept a suffix. */
8147 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
8148 are the conditional variants of instructions that
8149 take conditional infixes in unusual positions.
8150 The infix appears at character index
8151 (tag - OT_odd_infix_0). These are not accepted
8152 in unified mode. */
8155 /* Subroutine of md_assemble, responsible for looking up the primary
8156 opcode from the mnemonic the user wrote. STR points to the
8157 beginning of the mnemonic.
8159 This is not simply a hash table lookup, because of conditional
8160 variants. Most instructions have conditional variants, which are
8161 expressed with a _conditional affix_ to the mnemonic. If we were
8162 to encode each conditional variant as a literal string in the opcode
8163 table, it would have approximately 20,000 entries.
8165 Most mnemonics take this affix as a suffix, and in unified syntax,
8166 'most' is upgraded to 'all'. However, in the divided syntax, some
8167 instructions take the affix as an infix, notably the s-variants of
8168 the arithmetic instructions. Of those instructions, all but six
8169 have the infix appear after the third character of the mnemonic.
8171 Accordingly, the algorithm for looking up primary opcodes given
8172 an identifier is:
8174 1. Look up the identifier in the opcode table.
8175 If we find a match, go to step U.
8177 2. Look up the last two characters of the identifier in the
8178 conditions table. If we find a match, look up the first N-2
8179 characters of the identifier in the opcode table. If we
8180 find a match, go to step CE.
8182 3. Look up the fourth and fifth characters of the identifier in
8183 the conditions table. If we find a match, extract those
8184 characters from the identifier, and look up the remaining
8185 characters in the opcode table. If we find a match, go
8186 to step CM.
8188 4. Fail.
8190 U. Examine the tag field of the opcode structure, in case this is
8191 one of the six instructions with its conditional infix in an
8192 unusual place. If it is, the tag tells us where to find the
8193 infix; look it up in the conditions table and set inst.cond
8194 accordingly. Otherwise, this is an unconditional instruction.
8195 Again set inst.cond accordingly. Return the opcode structure.
8197 CE. Examine the tag field to make sure this is an instruction that
8198 should receive a conditional suffix. If it is not, fail.
8199 Otherwise, set inst.cond from the suffix we already looked up,
8200 and return the opcode structure.
8202 CM. Examine the tag field to make sure this is an instruction that
8203 should receive a conditional infix after the third character.
8204 If it is not, fail. Otherwise, undo the edits to the current
8205 line of input and proceed as for case CE. */
8207 static const struct asm_opcode *
8208 opcode_lookup (char **str)
8210 char *end, *base;
8211 char *affix;
8212 const struct asm_opcode *opcode;
8213 const struct asm_cond *cond;
8214 char save[2];
8216 /* Scan up to the end of the mnemonic, which must end in white space,
8217 '.' (in unified mode only), or end of string. */
8218 for (base = end = *str; *end != '\0'; end++)
8219 if (*end == ' ' || (unified_syntax && *end == '.'))
8220 break;
8222 if (end == base)
8223 return 0;
8225 /* Handle a possible width suffix. */
8226 if (end[0] == '.')
8228 if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0'))
8229 inst.size_req = 4;
8230 else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0'))
8231 inst.size_req = 2;
8232 else
8233 return 0;
8235 *str = end + 2;
8237 else
8238 *str = end;
8240 /* Look for unaffixed or special-case affixed mnemonic. */
8241 opcode = hash_find_n (arm_ops_hsh, base, end - base);
8242 if (opcode)
8244 /* step U */
8245 if (opcode->tag < OT_odd_infix_0)
8247 inst.cond = COND_ALWAYS;
8248 return opcode;
8251 if (unified_syntax)
8252 as_warn (_("conditional infixes are deprecated in unified syntax"));
8253 affix = base + (opcode->tag - OT_odd_infix_0);
8254 cond = hash_find_n (arm_cond_hsh, affix, 2);
8255 assert (cond);
8257 inst.cond = cond->value;
8258 return opcode;
8261 /* Cannot have a conditional suffix on a mnemonic of less than two
8262 characters. */
8263 if (end - base < 3)
8264 return 0;
8266 /* Look for suffixed mnemonic. */
8267 affix = end - 2;
8268 cond = hash_find_n (arm_cond_hsh, affix, 2);
8269 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
8270 if (opcode && cond)
8272 /* step CE */
8273 switch (opcode->tag)
8275 case OT_cinfix3_legacy:
8276 /* Ignore conditional suffixes matched on infix only mnemonics. */
8277 break;
8279 case OT_cinfix3:
8280 case OT_odd_infix_unc:
8281 if (!unified_syntax)
8282 return 0;
8283 /* else fall through */
8285 case OT_csuffix:
8286 case OT_csuf_or_in3:
8287 inst.cond = cond->value;
8288 return opcode;
8290 case OT_unconditional:
8291 case OT_unconditionalF:
8292 if (thumb_mode)
8294 inst.cond = cond->value;
8296 else
8298 /* delayed diagnostic */
8299 inst.error = BAD_COND;
8300 inst.cond = COND_ALWAYS;
8302 return opcode;
8304 default:
8305 return 0;
8309 /* Cannot have a usual-position infix on a mnemonic of less than
8310 six characters (five would be a suffix). */
8311 if (end - base < 6)
8312 return 0;
8314 /* Look for infixed mnemonic in the usual position. */
8315 affix = base + 3;
8316 cond = hash_find_n (arm_cond_hsh, affix, 2);
8317 if (!cond)
8318 return 0;
8320 memcpy (save, affix, 2);
8321 memmove (affix, affix + 2, (end - affix) - 2);
8322 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
8323 memmove (affix + 2, affix, (end - affix) - 2);
8324 memcpy (affix, save, 2);
8326 if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3
8327 || opcode->tag == OT_cinfix3_legacy))
8329 /* step CM */
8330 if (unified_syntax && opcode->tag == OT_cinfix3)
8331 as_warn (_("conditional infixes are deprecated in unified syntax"));
8333 inst.cond = cond->value;
8334 return opcode;
8337 return 0;
8340 void
8341 md_assemble (char *str)
8343 char *p = str;
8344 const struct asm_opcode * opcode;
8346 /* Align the previous label if needed. */
8347 if (last_label_seen != NULL)
8349 symbol_set_frag (last_label_seen, frag_now);
8350 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
8351 S_SET_SEGMENT (last_label_seen, now_seg);
8354 memset (&inst, '\0', sizeof (inst));
8355 inst.reloc.type = BFD_RELOC_UNUSED;
8357 opcode = opcode_lookup (&p);
8358 if (!opcode)
8360 /* It wasn't an instruction, but it might be a register alias of
8361 the form alias .req reg. */
8362 if (!create_register_alias (str, p))
8363 as_bad (_("bad instruction `%s'"), str);
8365 return;
8368 if (thumb_mode)
8370 arm_feature_set variant;
8372 variant = cpu_variant;
8373 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
8374 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
8375 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
8376 /* Check that this instruction is supported for this CPU. */
8377 if (!opcode->tvariant
8378 || (thumb_mode == 1
8379 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
8381 as_bad (_("selected processor does not support `%s'"), str);
8382 return;
8384 if (inst.cond != COND_ALWAYS && !unified_syntax
8385 && opcode->tencode != do_t_branch)
8387 as_bad (_("Thumb does not support conditional execution"));
8388 return;
8391 /* Check conditional suffixes. */
8392 if (current_it_mask)
8394 int cond;
8395 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
8396 current_it_mask <<= 1;
8397 current_it_mask &= 0x1f;
8398 /* The BKPT instruction is unconditional even in an IT block. */
8399 if (!inst.error
8400 && cond != inst.cond && opcode->tencode != do_t_bkpt)
8402 as_bad (_("incorrect condition in IT block"));
8403 return;
8406 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
8408 as_bad (_("thumb conditional instrunction not in IT block"));
8409 return;
8412 mapping_state (MAP_THUMB);
8413 inst.instruction = opcode->tvalue;
8415 if (!parse_operands (p, opcode->operands))
8416 opcode->tencode ();
8418 /* Clear current_it_mask at the end of an IT block. */
8419 if (current_it_mask == 0x10)
8420 current_it_mask = 0;
8422 if (!(inst.error || inst.relax))
8424 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
8425 inst.size = (inst.instruction > 0xffff ? 4 : 2);
8426 if (inst.size_req && inst.size_req != inst.size)
8428 as_bad (_("cannot honor width suffix -- `%s'"), str);
8429 return;
8432 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8433 *opcode->tvariant);
8434 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
8435 set those bits when Thumb-2 32-bit instuctions are seen. ie.
8436 anything other than bl/blx.
8437 This is overly pessimistic for relaxable instructions. */
8438 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
8439 || inst.relax)
8440 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8441 arm_ext_v6t2);
8443 else
8445 /* Check that this instruction is supported for this CPU. */
8446 if (!opcode->avariant ||
8447 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
8449 as_bad (_("selected processor does not support `%s'"), str);
8450 return;
8452 if (inst.size_req)
8454 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
8455 return;
8458 mapping_state (MAP_ARM);
8459 inst.instruction = opcode->avalue;
8460 if (opcode->tag == OT_unconditionalF)
8461 inst.instruction |= 0xF << 28;
8462 else
8463 inst.instruction |= inst.cond << 28;
8464 inst.size = INSN_SIZE;
8465 if (!parse_operands (p, opcode->operands))
8466 opcode->aencode ();
8467 /* Arm mode bx is marked as both v4T and v5 because it's still required
8468 on a hypothetical non-thumb v5 core. */
8469 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
8470 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
8471 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
8472 else
8473 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8474 *opcode->avariant);
8476 output_inst (str);
8479 /* Various frobbings of labels and their addresses. */
8481 void
8482 arm_start_line_hook (void)
8484 last_label_seen = NULL;
8487 void
8488 arm_frob_label (symbolS * sym)
8490 last_label_seen = sym;
8492 ARM_SET_THUMB (sym, thumb_mode);
8494 #if defined OBJ_COFF || defined OBJ_ELF
8495 ARM_SET_INTERWORK (sym, support_interwork);
8496 #endif
8498 /* Note - do not allow local symbols (.Lxxx) to be labeled
8499 as Thumb functions. This is because these labels, whilst
8500 they exist inside Thumb code, are not the entry points for
8501 possible ARM->Thumb calls. Also, these labels can be used
8502 as part of a computed goto or switch statement. eg gcc
8503 can generate code that looks like this:
8505 ldr r2, [pc, .Laaa]
8506 lsl r3, r3, #2
8507 ldr r2, [r3, r2]
8508 mov pc, r2
8510 .Lbbb: .word .Lxxx
8511 .Lccc: .word .Lyyy
8512 ..etc...
8513 .Laaa: .word Lbbb
8515 The first instruction loads the address of the jump table.
8516 The second instruction converts a table index into a byte offset.
8517 The third instruction gets the jump address out of the table.
8518 The fourth instruction performs the jump.
8520 If the address stored at .Laaa is that of a symbol which has the
8521 Thumb_Func bit set, then the linker will arrange for this address
8522 to have the bottom bit set, which in turn would mean that the
8523 address computation performed by the third instruction would end
8524 up with the bottom bit set. Since the ARM is capable of unaligned
8525 word loads, the instruction would then load the incorrect address
8526 out of the jump table, and chaos would ensue. */
8527 if (label_is_thumb_function_name
8528 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
8529 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
8531 /* When the address of a Thumb function is taken the bottom
8532 bit of that address should be set. This will allow
8533 interworking between Arm and Thumb functions to work
8534 correctly. */
8536 THUMB_SET_FUNC (sym, 1);
8538 label_is_thumb_function_name = FALSE;
8541 #ifdef OBJ_ELF
8542 dwarf2_emit_label (sym);
8543 #endif
8547 arm_data_in_code (void)
8549 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
8551 *input_line_pointer = '/';
8552 input_line_pointer += 5;
8553 *input_line_pointer = 0;
8554 return 1;
8557 return 0;
8560 char *
8561 arm_canonicalize_symbol_name (char * name)
8563 int len;
8565 if (thumb_mode && (len = strlen (name)) > 5
8566 && streq (name + len - 5, "/data"))
8567 *(name + len - 5) = 0;
8569 return name;
8572 /* Table of all register names defined by default. The user can
8573 define additional names with .req. Note that all register names
8574 should appear in both upper and lowercase variants. Some registers
8575 also have mixed-case names. */
8577 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE }
8578 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
8579 #define REGSET(p,t) \
8580 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
8581 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
8582 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
8583 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
8585 static const struct reg_entry reg_names[] =
8587 /* ARM integer registers. */
8588 REGSET(r, RN), REGSET(R, RN),
8590 /* ATPCS synonyms. */
8591 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
8592 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
8593 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
8595 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
8596 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
8597 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
8599 /* Well-known aliases. */
8600 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
8601 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
8603 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
8604 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
8606 /* Coprocessor numbers. */
8607 REGSET(p, CP), REGSET(P, CP),
8609 /* Coprocessor register numbers. The "cr" variants are for backward
8610 compatibility. */
8611 REGSET(c, CN), REGSET(C, CN),
8612 REGSET(cr, CN), REGSET(CR, CN),
8614 /* FPA registers. */
8615 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
8616 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
8618 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
8619 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
8621 /* VFP SP registers. */
8622 REGSET(s,VFS),
8623 REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS),
8624 REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS),
8625 REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS),
8626 REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS),
8628 REGSET(S,VFS),
8629 REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS),
8630 REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS),
8631 REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS),
8632 REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS),
8634 /* VFP DP Registers. */
8635 REGSET(d,VFD), REGSET(D,VFS),
8637 /* VFP control registers. */
8638 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
8639 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
8641 /* Maverick DSP coprocessor registers. */
8642 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
8643 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
8645 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
8646 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
8647 REGDEF(dspsc,0,DSPSC),
8649 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
8650 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
8651 REGDEF(DSPSC,0,DSPSC),
8653 /* iWMMXt data registers - p0, c0-15. */
8654 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
8656 /* iWMMXt control registers - p1, c0-3. */
8657 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
8658 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
8659 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
8660 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
8662 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
8663 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
8664 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
8665 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
8666 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
8668 /* XScale accumulator registers. */
8669 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
8671 #undef REGDEF
8672 #undef REGNUM
8673 #undef REGSET
8675 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
8676 within psr_required_here. */
8677 static const struct asm_psr psrs[] =
8679 /* Backward compatibility notation. Note that "all" is no longer
8680 truly all possible PSR bits. */
8681 {"all", PSR_c | PSR_f},
8682 {"flg", PSR_f},
8683 {"ctl", PSR_c},
8685 /* Individual flags. */
8686 {"f", PSR_f},
8687 {"c", PSR_c},
8688 {"x", PSR_x},
8689 {"s", PSR_s},
8690 /* Combinations of flags. */
8691 {"fs", PSR_f | PSR_s},
8692 {"fx", PSR_f | PSR_x},
8693 {"fc", PSR_f | PSR_c},
8694 {"sf", PSR_s | PSR_f},
8695 {"sx", PSR_s | PSR_x},
8696 {"sc", PSR_s | PSR_c},
8697 {"xf", PSR_x | PSR_f},
8698 {"xs", PSR_x | PSR_s},
8699 {"xc", PSR_x | PSR_c},
8700 {"cf", PSR_c | PSR_f},
8701 {"cs", PSR_c | PSR_s},
8702 {"cx", PSR_c | PSR_x},
8703 {"fsx", PSR_f | PSR_s | PSR_x},
8704 {"fsc", PSR_f | PSR_s | PSR_c},
8705 {"fxs", PSR_f | PSR_x | PSR_s},
8706 {"fxc", PSR_f | PSR_x | PSR_c},
8707 {"fcs", PSR_f | PSR_c | PSR_s},
8708 {"fcx", PSR_f | PSR_c | PSR_x},
8709 {"sfx", PSR_s | PSR_f | PSR_x},
8710 {"sfc", PSR_s | PSR_f | PSR_c},
8711 {"sxf", PSR_s | PSR_x | PSR_f},
8712 {"sxc", PSR_s | PSR_x | PSR_c},
8713 {"scf", PSR_s | PSR_c | PSR_f},
8714 {"scx", PSR_s | PSR_c | PSR_x},
8715 {"xfs", PSR_x | PSR_f | PSR_s},
8716 {"xfc", PSR_x | PSR_f | PSR_c},
8717 {"xsf", PSR_x | PSR_s | PSR_f},
8718 {"xsc", PSR_x | PSR_s | PSR_c},
8719 {"xcf", PSR_x | PSR_c | PSR_f},
8720 {"xcs", PSR_x | PSR_c | PSR_s},
8721 {"cfs", PSR_c | PSR_f | PSR_s},
8722 {"cfx", PSR_c | PSR_f | PSR_x},
8723 {"csf", PSR_c | PSR_s | PSR_f},
8724 {"csx", PSR_c | PSR_s | PSR_x},
8725 {"cxf", PSR_c | PSR_x | PSR_f},
8726 {"cxs", PSR_c | PSR_x | PSR_s},
8727 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
8728 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
8729 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
8730 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
8731 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
8732 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
8733 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
8734 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
8735 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
8736 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
8737 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
8738 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
8739 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
8740 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
8741 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
8742 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
8743 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
8744 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
8745 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
8746 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
8747 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
8748 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
8749 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
8750 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
8753 /* Table of V7M psr names. */
8754 static const struct asm_psr v7m_psrs[] =
8756 {"apsr", 0 },
8757 {"iapsr", 1 },
8758 {"eapsr", 2 },
8759 {"psr", 3 },
8760 {"ipsr", 5 },
8761 {"epsr", 6 },
8762 {"iepsr", 7 },
8763 {"msp", 8 },
8764 {"psp", 9 },
8765 {"primask", 16},
8766 {"basepri", 17},
8767 {"basepri_max", 18},
8768 {"faultmask", 19},
8769 {"control", 20}
8772 /* Table of all shift-in-operand names. */
8773 static const struct asm_shift_name shift_names [] =
8775 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
8776 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
8777 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
8778 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
8779 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
8780 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
8783 /* Table of all explicit relocation names. */
8784 #ifdef OBJ_ELF
8785 static struct reloc_entry reloc_names[] =
8787 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
8788 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
8789 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
8790 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
8791 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
8792 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
8793 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
8794 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
8795 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
8796 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
8797 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
8799 #endif
8801 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
8802 static const struct asm_cond conds[] =
8804 {"eq", 0x0},
8805 {"ne", 0x1},
8806 {"cs", 0x2}, {"hs", 0x2},
8807 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
8808 {"mi", 0x4},
8809 {"pl", 0x5},
8810 {"vs", 0x6},
8811 {"vc", 0x7},
8812 {"hi", 0x8},
8813 {"ls", 0x9},
8814 {"ge", 0xa},
8815 {"lt", 0xb},
8816 {"gt", 0xc},
8817 {"le", 0xd},
8818 {"al", 0xe}
8821 static struct asm_barrier_opt barrier_opt_names[] =
8823 { "sy", 0xf },
8824 { "un", 0x7 },
8825 { "st", 0xe },
8826 { "unst", 0x6 }
8829 /* Table of ARM-format instructions. */
8831 /* Macros for gluing together operand strings. N.B. In all cases
8832 other than OPS0, the trailing OP_stop comes from default
8833 zero-initialization of the unspecified elements of the array. */
8834 #define OPS0() { OP_stop, }
8835 #define OPS1(a) { OP_##a, }
8836 #define OPS2(a,b) { OP_##a,OP_##b, }
8837 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
8838 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
8839 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
8840 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
8842 /* These macros abstract out the exact format of the mnemonic table and
8843 save some repeated characters. */
8845 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
8846 #define TxCE(mnem, op, top, nops, ops, ae, te) \
8847 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
8848 THUMB_VARIANT, do_##ae, do_##te }
8850 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
8851 a T_MNEM_xyz enumerator. */
8852 #define TCE(mnem, aop, top, nops, ops, ae, te) \
8853 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
8854 #define tCE(mnem, aop, top, nops, ops, ae, te) \
8855 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8857 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
8858 infix after the third character. */
8859 #define TxC3(mnem, op, top, nops, ops, ae, te) \
8860 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
8861 THUMB_VARIANT, do_##ae, do_##te }
8862 #define TC3(mnem, aop, top, nops, ops, ae, te) \
8863 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
8864 #define tC3(mnem, aop, top, nops, ops, ae, te) \
8865 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8867 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
8868 appear in the condition table. */
8869 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
8870 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8871 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
8873 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
8874 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
8875 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
8876 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
8877 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
8878 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
8879 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
8880 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
8881 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
8882 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
8883 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
8884 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
8885 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
8886 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
8887 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
8888 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
8889 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
8890 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
8891 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
8892 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
8894 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
8895 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
8896 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
8897 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
8899 /* Mnemonic that cannot be conditionalized. The ARM condition-code
8900 field is still 0xE. Many of the Thumb variants can be executed
8901 conditionally, so this is checked separately. */
8902 #define TUE(mnem, op, top, nops, ops, ae, te) \
8903 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
8904 THUMB_VARIANT, do_##ae, do_##te }
8906 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
8907 condition code field. */
8908 #define TUF(mnem, op, top, nops, ops, ae, te) \
8909 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
8910 THUMB_VARIANT, do_##ae, do_##te }
8912 /* ARM-only variants of all the above. */
8913 #define CE(mnem, op, nops, ops, ae) \
8914 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8916 #define C3(mnem, op, nops, ops, ae) \
8917 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8919 /* Legacy mnemonics that always have conditional infix after the third
8920 character. */
8921 #define CL(mnem, op, nops, ops, ae) \
8922 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
8923 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8925 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
8926 #define cCE(mnem, op, nops, ops, ae) \
8927 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8929 /* Legacy coprocessor instructions where conditional infix and conditional
8930 suffix are ambiguous. For consistency this includes all FPA instructions,
8931 not just the potentially ambiguous ones. */
8932 #define cCL(mnem, op, nops, ops, ae) \
8933 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
8934 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8936 /* Coprocessor, takes either a suffix or a position-3 infix
8937 (for an FPA corner case). */
8938 #define C3E(mnem, op, nops, ops, ae) \
8939 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
8940 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8942 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
8943 { #m1 #m2 #m3, OPS##nops ops, \
8944 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8945 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8947 #define CM(m1, m2, op, nops, ops, ae) \
8948 xCM_(m1, , m2, op, nops, ops, ae), \
8949 xCM_(m1, eq, m2, op, nops, ops, ae), \
8950 xCM_(m1, ne, m2, op, nops, ops, ae), \
8951 xCM_(m1, cs, m2, op, nops, ops, ae), \
8952 xCM_(m1, hs, m2, op, nops, ops, ae), \
8953 xCM_(m1, cc, m2, op, nops, ops, ae), \
8954 xCM_(m1, ul, m2, op, nops, ops, ae), \
8955 xCM_(m1, lo, m2, op, nops, ops, ae), \
8956 xCM_(m1, mi, m2, op, nops, ops, ae), \
8957 xCM_(m1, pl, m2, op, nops, ops, ae), \
8958 xCM_(m1, vs, m2, op, nops, ops, ae), \
8959 xCM_(m1, vc, m2, op, nops, ops, ae), \
8960 xCM_(m1, hi, m2, op, nops, ops, ae), \
8961 xCM_(m1, ls, m2, op, nops, ops, ae), \
8962 xCM_(m1, ge, m2, op, nops, ops, ae), \
8963 xCM_(m1, lt, m2, op, nops, ops, ae), \
8964 xCM_(m1, gt, m2, op, nops, ops, ae), \
8965 xCM_(m1, le, m2, op, nops, ops, ae), \
8966 xCM_(m1, al, m2, op, nops, ops, ae)
8968 #define UE(mnem, op, nops, ops, ae) \
8969 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8971 #define UF(mnem, op, nops, ops, ae) \
8972 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8974 #define do_0 0
8976 /* Thumb-only, unconditional. */
8977 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
8979 static const struct asm_opcode insns[] =
8981 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
8982 #define THUMB_VARIANT &arm_ext_v4t
8983 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
8984 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
8985 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
8986 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
8987 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
8988 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
8989 tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub),
8990 tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub),
8991 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
8992 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
8993 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
8994 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
8995 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
8996 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
8997 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
8998 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
9000 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
9001 for setting PSR flag bits. They are obsolete in V6 and do not
9002 have Thumb equivalents. */
9003 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
9004 tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
9005 CL(tstp, 110f000, 2, (RR, SH), cmp),
9006 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
9007 tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
9008 CL(cmpp, 150f000, 2, (RR, SH), cmp),
9009 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
9010 tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
9011 CL(cmnp, 170f000, 2, (RR, SH), cmp),
9013 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
9014 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
9015 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
9016 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
9018 tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst),
9019 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst),
9020 tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst),
9021 tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst),
9023 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9024 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9025 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9026 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9027 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9028 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9030 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
9031 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
9032 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
9033 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
9035 /* Pseudo ops. */
9036 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
9037 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
9038 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
9040 /* Thumb-compatibility pseudo ops. */
9041 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
9042 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
9043 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
9044 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
9045 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
9046 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
9047 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
9048 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
9049 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
9050 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
9051 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
9052 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
9054 #undef THUMB_VARIANT
9055 #define THUMB_VARIANT &arm_ext_v6
9056 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
9058 /* V1 instructions with no Thumb analogue prior to V6T2. */
9059 #undef THUMB_VARIANT
9060 #define THUMB_VARIANT &arm_ext_v6t2
9061 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
9062 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
9063 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
9064 TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
9065 CL(teqp, 130f000, 2, (RR, SH), cmp),
9067 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
9068 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
9069 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
9070 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
9072 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9073 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9075 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9076 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9078 /* V1 instructions with no Thumb analogue at all. */
9079 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
9080 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
9082 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
9083 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
9084 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
9085 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
9086 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
9087 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
9088 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
9089 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
9091 #undef ARM_VARIANT
9092 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
9093 #undef THUMB_VARIANT
9094 #define THUMB_VARIANT &arm_ext_v4t
9095 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
9096 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
9098 #undef THUMB_VARIANT
9099 #define THUMB_VARIANT &arm_ext_v6t2
9100 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
9101 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
9103 /* Generic coprocessor instructions. */
9104 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
9105 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc),
9106 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc),
9107 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc),
9108 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc),
9109 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9110 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9112 #undef ARM_VARIANT
9113 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
9114 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
9115 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
9117 #undef ARM_VARIANT
9118 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
9119 TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs),
9120 TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr),
9122 #undef ARM_VARIANT
9123 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
9124 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9125 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9126 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9127 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9128 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9129 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9130 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9131 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9133 #undef ARM_VARIANT
9134 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
9135 #undef THUMB_VARIANT
9136 #define THUMB_VARIANT &arm_ext_v4t
9137 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst),
9138 tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst),
9139 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
9140 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
9141 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
9142 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
9144 #undef ARM_VARIANT
9145 #define ARM_VARIANT &arm_ext_v4t_5
9146 /* ARM Architecture 4T. */
9147 /* Note: bx (and blx) are required on V5, even if the processor does
9148 not support Thumb. */
9149 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
9151 #undef ARM_VARIANT
9152 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
9153 #undef THUMB_VARIANT
9154 #define THUMB_VARIANT &arm_ext_v5t
9155 /* Note: blx has 2 variants; the .value coded here is for
9156 BLX(2). Only this variant has conditional execution. */
9157 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
9158 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
9160 #undef THUMB_VARIANT
9161 #define THUMB_VARIANT &arm_ext_v6t2
9162 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
9163 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc),
9164 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc),
9165 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc),
9166 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc),
9167 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
9168 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9169 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9171 #undef ARM_VARIANT
9172 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
9173 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9174 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9175 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9176 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9178 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9179 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9181 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9182 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9183 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9184 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9186 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9187 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9188 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9189 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9191 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9192 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9194 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9195 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9196 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9197 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9199 #undef ARM_VARIANT
9200 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
9201 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
9202 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
9203 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
9205 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
9206 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
9208 #undef ARM_VARIANT
9209 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
9210 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
9212 #undef ARM_VARIANT
9213 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
9214 #undef THUMB_VARIANT
9215 #define THUMB_VARIANT &arm_ext_v6
9216 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
9217 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
9218 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
9219 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
9220 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
9221 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9222 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9223 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9224 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9225 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
9227 #undef THUMB_VARIANT
9228 #define THUMB_VARIANT &arm_ext_v6t2
9229 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
9230 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
9231 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
9233 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
9234 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
9236 /* ARM V6 not included in V7M (eg. integer SIMD). */
9237 #undef THUMB_VARIANT
9238 #define THUMB_VARIANT &arm_ext_v6_notm
9239 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
9240 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
9241 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
9242 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9243 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9244 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9245 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9246 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9247 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9248 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9249 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9250 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9251 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9252 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9253 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9254 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9255 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9256 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9257 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9258 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9259 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9260 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9261 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9262 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9263 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9264 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9265 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9266 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9267 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9268 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9269 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9270 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9271 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9272 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9273 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9274 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9275 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9276 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9277 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9278 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
9279 UF(rfeib, 9900a00, 1, (RRw), rfe),
9280 UF(rfeda, 8100a00, 1, (RRw), rfe),
9281 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
9282 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
9283 UF(rfefa, 9900a00, 1, (RRw), rfe),
9284 UF(rfeea, 8100a00, 1, (RRw), rfe),
9285 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
9286 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9287 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9288 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9289 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9290 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9291 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9292 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9293 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9294 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9295 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9296 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9297 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9298 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9299 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9300 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9301 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9302 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9303 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9304 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9305 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9306 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9307 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9308 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9309 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9310 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9311 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9312 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9313 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
9314 UF(srsib, 9cd0500, 1, (I31w), srs),
9315 UF(srsda, 84d0500, 1, (I31w), srs),
9316 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
9317 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
9318 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
9319 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
9320 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9321 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9322 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
9324 #undef ARM_VARIANT
9325 #define ARM_VARIANT &arm_ext_v6k
9326 #undef THUMB_VARIANT
9327 #define THUMB_VARIANT &arm_ext_v6k
9328 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
9329 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
9330 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
9331 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
9333 #undef THUMB_VARIANT
9334 #define THUMB_VARIANT &arm_ext_v6_notm
9335 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
9336 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
9338 #undef THUMB_VARIANT
9339 #define THUMB_VARIANT &arm_ext_v6t2
9340 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
9341 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
9342 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
9343 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
9344 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
9346 #undef ARM_VARIANT
9347 #define ARM_VARIANT &arm_ext_v6z
9348 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
9350 #undef ARM_VARIANT
9351 #define ARM_VARIANT &arm_ext_v6t2
9352 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
9353 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
9354 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
9355 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
9357 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
9358 TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16),
9359 TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16),
9360 TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
9362 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9363 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9364 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9365 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9367 UT(cbnz, b900, 2, (RR, EXP), t_czb),
9368 UT(cbz, b100, 2, (RR, EXP), t_czb),
9369 /* ARM does not really have an IT instruction. */
9370 TUE(it, 0, bf08, 1, (COND), it, t_it),
9371 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
9372 TUE(ite, 0, bf04, 1, (COND), it, t_it),
9373 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
9374 TUE(itet, 0, bf06, 1, (COND), it, t_it),
9375 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
9376 TUE(itee, 0, bf02, 1, (COND), it, t_it),
9377 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
9378 TUE(itett, 0, bf07, 1, (COND), it, t_it),
9379 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
9380 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
9381 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
9382 TUE(itete, 0, bf05, 1, (COND), it, t_it),
9383 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
9384 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
9386 /* Thumb2 only instructions. */
9387 #undef ARM_VARIANT
9388 #define ARM_VARIANT NULL
9390 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
9391 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
9392 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
9393 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
9395 /* Thumb-2 hardware division instructions (R and M profiles only). */
9396 #undef THUMB_VARIANT
9397 #define THUMB_VARIANT &arm_ext_div
9398 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
9399 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
9401 /* ARM V7 instructions. */
9402 #undef ARM_VARIANT
9403 #define ARM_VARIANT &arm_ext_v7
9404 #undef THUMB_VARIANT
9405 #define THUMB_VARIANT &arm_ext_v7
9406 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
9407 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
9408 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
9409 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
9410 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
9412 #undef ARM_VARIANT
9413 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
9414 cCE(wfs, e200110, 1, (RR), rd),
9415 cCE(rfs, e300110, 1, (RR), rd),
9416 cCE(wfc, e400110, 1, (RR), rd),
9417 cCE(rfc, e500110, 1, (RR), rd),
9419 cCL(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr),
9420 cCL(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr),
9421 cCL(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr),
9422 cCL(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr),
9424 cCL(stfs, c000100, 2, (RF, ADDR), rd_cpaddr),
9425 cCL(stfd, c008100, 2, (RF, ADDR), rd_cpaddr),
9426 cCL(stfe, c400100, 2, (RF, ADDR), rd_cpaddr),
9427 cCL(stfp, c408100, 2, (RF, ADDR), rd_cpaddr),
9429 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
9430 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
9431 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
9432 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
9433 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
9434 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
9435 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
9436 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
9437 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
9438 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
9439 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
9440 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
9442 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
9443 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
9444 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
9445 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
9446 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
9447 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
9448 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
9449 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
9450 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
9451 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
9452 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
9453 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
9455 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
9456 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
9457 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
9458 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
9459 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
9460 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
9461 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
9462 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
9463 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
9464 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
9465 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
9466 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
9468 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
9469 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
9470 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
9471 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
9472 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
9473 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
9474 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
9475 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
9476 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
9477 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
9478 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
9479 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
9481 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
9482 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
9483 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
9484 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
9485 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
9486 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
9487 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
9488 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
9489 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
9490 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
9491 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
9492 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
9494 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
9495 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
9496 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
9497 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
9498 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
9499 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
9500 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
9501 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
9502 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
9503 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
9504 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
9505 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
9507 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
9508 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
9509 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
9510 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
9511 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
9512 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
9513 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
9514 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
9515 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
9516 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
9517 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
9518 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
9520 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
9521 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
9522 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
9523 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
9524 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
9525 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
9526 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
9527 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
9528 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
9529 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
9530 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
9531 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
9533 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
9534 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
9535 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
9536 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
9537 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
9538 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
9539 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
9540 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
9541 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
9542 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
9543 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
9544 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
9546 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
9547 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
9548 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
9549 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
9550 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
9551 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
9552 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
9553 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
9554 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
9555 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
9556 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
9557 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
9559 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
9560 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
9561 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
9562 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
9563 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
9564 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
9565 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
9566 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
9567 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
9568 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
9569 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
9570 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
9572 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
9573 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
9574 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
9575 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
9576 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
9577 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
9578 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
9579 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
9580 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
9581 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
9582 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
9583 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
9585 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
9586 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
9587 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
9588 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
9589 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
9590 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
9591 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
9592 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
9593 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
9594 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
9595 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
9596 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
9598 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
9599 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
9600 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
9601 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
9602 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
9603 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
9604 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
9605 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
9606 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
9607 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
9608 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
9609 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
9611 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
9612 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
9613 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
9614 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
9615 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
9616 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
9617 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
9618 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
9619 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
9620 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
9621 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
9622 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
9624 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
9625 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
9626 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
9627 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
9628 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
9629 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
9630 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
9631 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
9632 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
9633 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
9634 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
9635 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
9637 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
9638 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
9639 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
9640 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
9641 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
9642 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9643 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9644 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9645 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
9646 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
9647 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
9648 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
9650 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
9651 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
9652 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
9653 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
9654 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
9655 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9656 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9657 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9658 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
9659 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
9660 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
9661 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
9663 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
9664 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
9665 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
9666 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
9667 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
9668 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9669 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9670 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9671 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
9672 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
9673 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
9674 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
9676 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
9677 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
9678 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
9679 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
9680 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
9681 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9682 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9683 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9684 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
9685 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
9686 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
9687 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
9689 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
9690 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
9691 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
9692 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
9693 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
9694 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9695 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9696 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9697 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
9698 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
9699 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
9700 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
9702 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
9703 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
9704 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
9705 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
9706 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
9707 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9708 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9709 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9710 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
9711 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
9712 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
9713 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
9715 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
9716 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
9717 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
9718 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
9719 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
9720 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9721 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9722 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9723 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
9724 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
9725 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
9726 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
9728 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
9729 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
9730 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
9731 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
9732 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
9733 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9734 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9735 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9736 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
9737 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
9738 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
9739 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
9741 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
9742 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
9743 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
9744 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
9745 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
9746 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9747 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9748 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9749 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
9750 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
9751 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
9752 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
9754 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
9755 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
9756 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
9757 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
9758 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
9759 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9760 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9761 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9762 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
9763 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
9764 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
9765 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
9767 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9768 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9769 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9770 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9771 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9772 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9773 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9774 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9775 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9776 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9777 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9778 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9780 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9781 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9782 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9783 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9784 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9785 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9786 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9787 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9788 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9789 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9790 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9791 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9793 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9794 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9795 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9796 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9797 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9798 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9799 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9800 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9801 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9802 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9803 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9804 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9806 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
9807 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
9808 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
9809 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
9811 cCL(flts, e000110, 2, (RF, RR), rn_rd),
9812 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
9813 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
9814 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
9815 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
9816 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
9817 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
9818 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
9819 cCL(flte, e080110, 2, (RF, RR), rn_rd),
9820 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
9821 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
9822 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
9824 /* The implementation of the FIX instruction is broken on some
9825 assemblers, in that it accepts a precision specifier as well as a
9826 rounding specifier, despite the fact that this is meaningless.
9827 To be more compatible, we accept it as well, though of course it
9828 does not set any bits. */
9829 cCE(fix, e100110, 2, (RR, RF), rd_rm),
9830 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
9831 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
9832 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
9833 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
9834 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
9835 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
9836 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
9837 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
9838 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
9839 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
9840 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
9841 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
9843 /* Instructions that were new with the real FPA, call them V2. */
9844 #undef ARM_VARIANT
9845 #define ARM_VARIANT &fpu_fpa_ext_v2
9846 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9847 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9848 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9849 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9850 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9851 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9853 #undef ARM_VARIANT
9854 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
9855 /* Moves and type conversions. */
9856 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
9857 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
9858 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
9859 cCE(fmstat, ef1fa10, 0, (), noargs),
9860 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
9861 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
9862 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
9863 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9864 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
9865 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9866 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
9867 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
9869 /* Memory operations. */
9870 cCE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst),
9871 cCE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst),
9872 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9873 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9874 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9875 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9876 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9877 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9878 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9879 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9880 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9881 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9882 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9883 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9884 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9885 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9886 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9887 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9889 /* Monadic operations. */
9890 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
9891 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
9892 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
9894 /* Dyadic operations. */
9895 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9896 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9897 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9898 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9899 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9900 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9901 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9902 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9903 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9905 /* Comparisons. */
9906 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
9907 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
9908 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
9909 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
9911 #undef ARM_VARIANT
9912 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
9913 /* Moves and type conversions. */
9914 cCE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm),
9915 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9916 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9917 cCE(fmdhr, e200b10, 2, (RVD, RR), rn_rd),
9918 cCE(fmdlr, e000b10, 2, (RVD, RR), rn_rd),
9919 cCE(fmrdh, e300b10, 2, (RR, RVD), rd_rn),
9920 cCE(fmrdl, e100b10, 2, (RR, RVD), rd_rn),
9921 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9922 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
9923 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9924 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9925 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9926 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9928 /* Memory operations. */
9929 cCE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst),
9930 cCE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst),
9931 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9932 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9933 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9934 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9935 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9936 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9937 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9938 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9940 /* Monadic operations. */
9941 cCE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm),
9942 cCE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm),
9943 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm),
9945 /* Dyadic operations. */
9946 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9947 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9948 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9949 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9950 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9951 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9952 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9953 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9954 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9956 /* Comparisons. */
9957 cCE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm),
9958 cCE(fcmpzd, eb50b40, 1, (RVD), rd),
9959 cCE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm),
9960 cCE(fcmpezd, eb50bc0, 1, (RVD), rd),
9962 #undef ARM_VARIANT
9963 #define ARM_VARIANT &fpu_vfp_ext_v2
9964 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
9965 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
9966 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn),
9967 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm),
9969 #undef ARM_VARIANT
9970 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
9971 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9972 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9973 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9974 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9975 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9976 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9977 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
9978 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
9980 #undef ARM_VARIANT
9981 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
9982 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
9983 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
9984 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
9985 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
9986 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
9987 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
9988 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
9989 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
9990 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
9991 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9992 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9993 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9994 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9995 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9996 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9997 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9998 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9999 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
10000 cCE(tmcr, e000110, 2, (RIWC, RR), rn_rd),
10001 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
10002 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
10003 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
10004 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
10005 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
10006 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
10007 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
10008 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
10009 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
10010 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
10011 cCE(tmrc, e100110, 2, (RR, RIWC), rd_rn),
10012 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
10013 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
10014 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
10015 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
10016 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
10017 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
10018 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
10019 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10020 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10021 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10022 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10023 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10024 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10025 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10026 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10027 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10028 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
10029 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10030 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10031 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10032 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10033 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10034 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10035 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10036 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10037 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10038 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10039 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10040 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10041 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10042 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10043 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10044 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10045 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10046 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10047 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10048 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
10049 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
10050 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
10051 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
10052 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10053 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10054 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10055 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10056 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10057 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10058 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10059 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10060 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10061 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10062 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10063 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10064 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10065 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10066 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10067 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10068 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10069 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10070 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
10071 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10072 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10073 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10074 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10075 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10076 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10077 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10078 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10079 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10080 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10081 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10082 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10083 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10084 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10085 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10086 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10087 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10088 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10089 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10090 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10091 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10092 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
10093 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10094 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10095 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10096 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10097 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10098 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10099 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10100 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10101 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10102 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10103 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10104 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10105 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10106 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10107 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10108 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10109 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10110 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10111 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
10112 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
10113 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
10114 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
10115 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10116 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10117 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10118 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10119 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10120 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10121 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10122 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10123 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10124 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
10125 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
10126 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
10127 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
10128 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
10129 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
10130 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10131 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10132 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10133 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
10134 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
10135 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
10136 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
10137 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
10138 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
10139 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10140 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10141 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10142 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10143 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
10145 #undef ARM_VARIANT
10146 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
10147 cCE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr),
10148 cCE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr),
10149 cCE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr),
10150 cCE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr),
10151 cCE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr),
10152 cCE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr),
10153 cCE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr),
10154 cCE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr),
10155 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
10156 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
10157 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
10158 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
10159 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
10160 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
10161 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
10162 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
10163 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
10164 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
10165 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
10166 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
10167 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
10168 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
10169 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
10170 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
10171 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
10172 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
10173 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
10174 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
10175 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
10176 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
10177 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
10178 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
10179 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
10180 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
10181 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
10182 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
10183 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
10184 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
10185 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
10186 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
10187 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
10188 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
10189 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
10190 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
10191 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
10192 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
10193 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
10194 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
10195 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
10196 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
10197 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
10198 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
10199 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
10200 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
10201 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
10202 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
10203 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
10204 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
10205 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
10206 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
10207 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
10208 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
10209 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
10210 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
10211 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10212 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
10213 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10214 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
10215 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10216 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
10217 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10218 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10219 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
10220 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
10221 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
10222 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
10224 #undef ARM_VARIANT
10225 #undef THUMB_VARIANT
10226 #undef TCE
10227 #undef TCM
10228 #undef TUE
10229 #undef TUF
10230 #undef TCC
10231 #undef cCE
10232 #undef cCL
10233 #undef C3E
10234 #undef CE
10235 #undef CM
10236 #undef UE
10237 #undef UF
10238 #undef UT
10239 #undef OPS0
10240 #undef OPS1
10241 #undef OPS2
10242 #undef OPS3
10243 #undef OPS4
10244 #undef OPS5
10245 #undef OPS6
10246 #undef do_0
10248 /* MD interface: bits in the object file. */
10250 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
10251 for use in the a.out file, and stores them in the array pointed to by buf.
10252 This knows about the endian-ness of the target machine and does
10253 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
10254 2 (short) and 4 (long) Floating numbers are put out as a series of
10255 LITTLENUMS (shorts, here at least). */
10257 void
10258 md_number_to_chars (char * buf, valueT val, int n)
10260 if (target_big_endian)
10261 number_to_chars_bigendian (buf, val, n);
10262 else
10263 number_to_chars_littleendian (buf, val, n);
10266 static valueT
10267 md_chars_to_number (char * buf, int n)
10269 valueT result = 0;
10270 unsigned char * where = (unsigned char *) buf;
10272 if (target_big_endian)
10274 while (n--)
10276 result <<= 8;
10277 result |= (*where++ & 255);
10280 else
10282 while (n--)
10284 result <<= 8;
10285 result |= (where[n] & 255);
10289 return result;
10292 /* MD interface: Sections. */
10294 /* Estimate the size of a frag before relaxing. Assume everything fits in
10295 2 bytes. */
10298 md_estimate_size_before_relax (fragS * fragp,
10299 segT segtype ATTRIBUTE_UNUSED)
10301 fragp->fr_var = 2;
10302 return 2;
10305 /* Convert a machine dependent frag. */
10307 void
10308 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
10310 unsigned long insn;
10311 unsigned long old_op;
10312 char *buf;
10313 expressionS exp;
10314 fixS *fixp;
10315 int reloc_type;
10316 int pc_rel;
10317 int opcode;
10319 buf = fragp->fr_literal + fragp->fr_fix;
10321 old_op = bfd_get_16(abfd, buf);
10322 if (fragp->fr_symbol) {
10323 exp.X_op = O_symbol;
10324 exp.X_add_symbol = fragp->fr_symbol;
10325 } else {
10326 exp.X_op = O_constant;
10328 exp.X_add_number = fragp->fr_offset;
10329 opcode = fragp->fr_subtype;
10330 switch (opcode)
10332 case T_MNEM_ldr_pc:
10333 case T_MNEM_ldr_pc2:
10334 case T_MNEM_ldr_sp:
10335 case T_MNEM_str_sp:
10336 case T_MNEM_ldr:
10337 case T_MNEM_ldrb:
10338 case T_MNEM_ldrh:
10339 case T_MNEM_str:
10340 case T_MNEM_strb:
10341 case T_MNEM_strh:
10342 if (fragp->fr_var == 4)
10344 insn = THUMB_OP32(opcode);
10345 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
10347 insn |= (old_op & 0x700) << 4;
10349 else
10351 insn |= (old_op & 7) << 12;
10352 insn |= (old_op & 0x38) << 13;
10354 insn |= 0x00000c00;
10355 put_thumb32_insn (buf, insn);
10356 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10358 else
10360 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
10362 pc_rel = (opcode == T_MNEM_ldr_pc2);
10363 break;
10364 case T_MNEM_adr:
10365 if (fragp->fr_var == 4)
10367 insn = THUMB_OP32 (opcode);
10368 insn |= (old_op & 0xf0) << 4;
10369 put_thumb32_insn (buf, insn);
10370 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
10372 else
10374 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10375 exp.X_add_number -= 4;
10377 pc_rel = 1;
10378 break;
10379 case T_MNEM_mov:
10380 case T_MNEM_movs:
10381 case T_MNEM_cmp:
10382 case T_MNEM_cmn:
10383 if (fragp->fr_var == 4)
10385 int r0off = (opcode == T_MNEM_mov
10386 || opcode == T_MNEM_movs) ? 0 : 8;
10387 insn = THUMB_OP32 (opcode);
10388 insn = (insn & 0xe1ffffff) | 0x10000000;
10389 insn |= (old_op & 0x700) << r0off;
10390 put_thumb32_insn (buf, insn);
10391 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10393 else
10395 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
10397 pc_rel = 0;
10398 break;
10399 case T_MNEM_b:
10400 if (fragp->fr_var == 4)
10402 insn = THUMB_OP32(opcode);
10403 put_thumb32_insn (buf, insn);
10404 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
10406 else
10407 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
10408 pc_rel = 1;
10409 break;
10410 case T_MNEM_bcond:
10411 if (fragp->fr_var == 4)
10413 insn = THUMB_OP32(opcode);
10414 insn |= (old_op & 0xf00) << 14;
10415 put_thumb32_insn (buf, insn);
10416 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
10418 else
10419 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
10420 pc_rel = 1;
10421 break;
10422 case T_MNEM_add_sp:
10423 case T_MNEM_add_pc:
10424 case T_MNEM_inc_sp:
10425 case T_MNEM_dec_sp:
10426 if (fragp->fr_var == 4)
10428 /* ??? Choose between add and addw. */
10429 insn = THUMB_OP32 (opcode);
10430 insn |= (old_op & 0xf0) << 4;
10431 put_thumb32_insn (buf, insn);
10432 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10434 else
10435 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10436 pc_rel = 0;
10437 break;
10439 case T_MNEM_addi:
10440 case T_MNEM_addis:
10441 case T_MNEM_subi:
10442 case T_MNEM_subis:
10443 if (fragp->fr_var == 4)
10445 insn = THUMB_OP32 (opcode);
10446 insn |= (old_op & 0xf0) << 4;
10447 insn |= (old_op & 0xf) << 16;
10448 put_thumb32_insn (buf, insn);
10449 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10451 else
10452 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10453 pc_rel = 0;
10454 break;
10455 default:
10456 abort();
10458 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
10459 reloc_type);
10460 fixp->fx_file = fragp->fr_file;
10461 fixp->fx_line = fragp->fr_line;
10462 fragp->fr_fix += fragp->fr_var;
10465 /* Return the size of a relaxable immediate operand instruction.
10466 SHIFT and SIZE specify the form of the allowable immediate. */
10467 static int
10468 relax_immediate (fragS *fragp, int size, int shift)
10470 offsetT offset;
10471 offsetT mask;
10472 offsetT low;
10474 /* ??? Should be able to do better than this. */
10475 if (fragp->fr_symbol)
10476 return 4;
10478 low = (1 << shift) - 1;
10479 mask = (1 << (shift + size)) - (1 << shift);
10480 offset = fragp->fr_offset;
10481 /* Force misaligned offsets to 32-bit variant. */
10482 if (offset & low)
10483 return -4;
10484 if (offset & ~mask)
10485 return 4;
10486 return 2;
10489 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
10490 load. */
10491 static int
10492 relax_adr (fragS *fragp, asection *sec)
10494 addressT addr;
10495 offsetT val;
10497 /* Assume worst case for symbols not known to be in the same section. */
10498 if (!S_IS_DEFINED(fragp->fr_symbol)
10499 || sec != S_GET_SEGMENT (fragp->fr_symbol))
10500 return 4;
10502 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
10503 addr = fragp->fr_address + fragp->fr_fix;
10504 addr = (addr + 4) & ~3;
10505 /* Fix the insn as the 4-byte version if the target address is not
10506 sufficiently aligned. This is prevents an infinite loop when two
10507 instructions have contradictory range/alignment requirements. */
10508 if (val & 3)
10509 return -4;
10510 val -= addr;
10511 if (val < 0 || val > 1020)
10512 return 4;
10513 return 2;
10516 /* Return the size of a relaxable add/sub immediate instruction. */
10517 static int
10518 relax_addsub (fragS *fragp, asection *sec)
10520 char *buf;
10521 int op;
10523 buf = fragp->fr_literal + fragp->fr_fix;
10524 op = bfd_get_16(sec->owner, buf);
10525 if ((op & 0xf) == ((op >> 4) & 0xf))
10526 return relax_immediate (fragp, 8, 0);
10527 else
10528 return relax_immediate (fragp, 3, 0);
10532 /* Return the size of a relaxable branch instruction. BITS is the
10533 size of the offset field in the narrow instruction. */
10535 static int
10536 relax_branch (fragS *fragp, asection *sec, int bits)
10538 addressT addr;
10539 offsetT val;
10540 offsetT limit;
10542 /* Assume worst case for symbols not known to be in the same section. */
10543 if (!S_IS_DEFINED(fragp->fr_symbol)
10544 || sec != S_GET_SEGMENT (fragp->fr_symbol))
10545 return 4;
10547 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
10548 addr = fragp->fr_address + fragp->fr_fix + 4;
10549 val -= addr;
10551 /* Offset is a signed value *2 */
10552 limit = 1 << bits;
10553 if (val >= limit || val < -limit)
10554 return 4;
10555 return 2;
10559 /* Relax a machine dependent frag. This returns the amount by which
10560 the current size of the frag should change. */
10563 arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED)
10565 int oldsize;
10566 int newsize;
10568 oldsize = fragp->fr_var;
10569 switch (fragp->fr_subtype)
10571 case T_MNEM_ldr_pc2:
10572 newsize = relax_adr(fragp, sec);
10573 break;
10574 case T_MNEM_ldr_pc:
10575 case T_MNEM_ldr_sp:
10576 case T_MNEM_str_sp:
10577 newsize = relax_immediate(fragp, 8, 2);
10578 break;
10579 case T_MNEM_ldr:
10580 case T_MNEM_str:
10581 newsize = relax_immediate(fragp, 5, 2);
10582 break;
10583 case T_MNEM_ldrh:
10584 case T_MNEM_strh:
10585 newsize = relax_immediate(fragp, 5, 1);
10586 break;
10587 case T_MNEM_ldrb:
10588 case T_MNEM_strb:
10589 newsize = relax_immediate(fragp, 5, 0);
10590 break;
10591 case T_MNEM_adr:
10592 newsize = relax_adr(fragp, sec);
10593 break;
10594 case T_MNEM_mov:
10595 case T_MNEM_movs:
10596 case T_MNEM_cmp:
10597 case T_MNEM_cmn:
10598 newsize = relax_immediate(fragp, 8, 0);
10599 break;
10600 case T_MNEM_b:
10601 newsize = relax_branch(fragp, sec, 11);
10602 break;
10603 case T_MNEM_bcond:
10604 newsize = relax_branch(fragp, sec, 8);
10605 break;
10606 case T_MNEM_add_sp:
10607 case T_MNEM_add_pc:
10608 newsize = relax_immediate (fragp, 8, 2);
10609 break;
10610 case T_MNEM_inc_sp:
10611 case T_MNEM_dec_sp:
10612 newsize = relax_immediate (fragp, 7, 2);
10613 break;
10614 case T_MNEM_addi:
10615 case T_MNEM_addis:
10616 case T_MNEM_subi:
10617 case T_MNEM_subis:
10618 newsize = relax_addsub (fragp, sec);
10619 break;
10620 default:
10621 abort();
10623 if (newsize < 0)
10625 fragp->fr_var = -newsize;
10626 md_convert_frag (sec->owner, sec, fragp);
10627 frag_wane(fragp);
10628 return -(newsize + oldsize);
10630 fragp->fr_var = newsize;
10631 return newsize - oldsize;
10634 /* Round up a section size to the appropriate boundary. */
10636 valueT
10637 md_section_align (segT segment ATTRIBUTE_UNUSED,
10638 valueT size)
10640 #ifdef OBJ_ELF
10641 return size;
10642 #else
10643 /* Round all sects to multiple of 4. */
10644 return (size + 3) & ~3;
10645 #endif
10648 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10649 of an rs_align_code fragment. */
10651 void
10652 arm_handle_align (fragS * fragP)
10654 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
10655 static char const thumb_noop[2] = { 0xc0, 0x46 };
10656 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
10657 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
10659 int bytes, fix, noop_size;
10660 char * p;
10661 const char * noop;
10663 if (fragP->fr_type != rs_align_code)
10664 return;
10666 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
10667 p = fragP->fr_literal + fragP->fr_fix;
10668 fix = 0;
10670 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
10671 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
10673 if (fragP->tc_frag_data)
10675 if (target_big_endian)
10676 noop = thumb_bigend_noop;
10677 else
10678 noop = thumb_noop;
10679 noop_size = sizeof (thumb_noop);
10681 else
10683 if (target_big_endian)
10684 noop = arm_bigend_noop;
10685 else
10686 noop = arm_noop;
10687 noop_size = sizeof (arm_noop);
10690 if (bytes & (noop_size - 1))
10692 fix = bytes & (noop_size - 1);
10693 memset (p, 0, fix);
10694 p += fix;
10695 bytes -= fix;
10698 while (bytes >= noop_size)
10700 memcpy (p, noop, noop_size);
10701 p += noop_size;
10702 bytes -= noop_size;
10703 fix += noop_size;
10706 fragP->fr_fix += fix;
10707 fragP->fr_var = noop_size;
10710 /* Called from md_do_align. Used to create an alignment
10711 frag in a code section. */
10713 void
10714 arm_frag_align_code (int n, int max)
10716 char * p;
10718 /* We assume that there will never be a requirement
10719 to support alignments greater than 32 bytes. */
10720 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
10721 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
10723 p = frag_var (rs_align_code,
10724 MAX_MEM_FOR_RS_ALIGN_CODE,
10726 (relax_substateT) max,
10727 (symbolS *) NULL,
10728 (offsetT) n,
10729 (char *) NULL);
10730 *p = 0;
10733 /* Perform target specific initialisation of a frag. */
10735 void
10736 arm_init_frag (fragS * fragP)
10738 /* Record whether this frag is in an ARM or a THUMB area. */
10739 fragP->tc_frag_data = thumb_mode;
10742 #ifdef OBJ_ELF
10743 /* When we change sections we need to issue a new mapping symbol. */
10745 void
10746 arm_elf_change_section (void)
10748 flagword flags;
10749 segment_info_type *seginfo;
10751 /* Link an unlinked unwind index table section to the .text section. */
10752 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
10753 && elf_linked_to_section (now_seg) == NULL)
10754 elf_linked_to_section (now_seg) = text_section;
10756 if (!SEG_NORMAL (now_seg))
10757 return;
10759 flags = bfd_get_section_flags (stdoutput, now_seg);
10761 /* We can ignore sections that only contain debug info. */
10762 if ((flags & SEC_ALLOC) == 0)
10763 return;
10765 seginfo = seg_info (now_seg);
10766 mapstate = seginfo->tc_segment_info_data.mapstate;
10767 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
10771 arm_elf_section_type (const char * str, size_t len)
10773 if (len == 5 && strncmp (str, "exidx", 5) == 0)
10774 return SHT_ARM_EXIDX;
10776 return -1;
10779 /* Code to deal with unwinding tables. */
10781 static void add_unwind_adjustsp (offsetT);
10783 /* Cenerate and deferred unwind frame offset. */
10785 static void
10786 flush_pending_unwind (void)
10788 offsetT offset;
10790 offset = unwind.pending_offset;
10791 unwind.pending_offset = 0;
10792 if (offset != 0)
10793 add_unwind_adjustsp (offset);
10796 /* Add an opcode to this list for this function. Two-byte opcodes should
10797 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
10798 order. */
10800 static void
10801 add_unwind_opcode (valueT op, int length)
10803 /* Add any deferred stack adjustment. */
10804 if (unwind.pending_offset)
10805 flush_pending_unwind ();
10807 unwind.sp_restored = 0;
10809 if (unwind.opcode_count + length > unwind.opcode_alloc)
10811 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
10812 if (unwind.opcodes)
10813 unwind.opcodes = xrealloc (unwind.opcodes,
10814 unwind.opcode_alloc);
10815 else
10816 unwind.opcodes = xmalloc (unwind.opcode_alloc);
10818 while (length > 0)
10820 length--;
10821 unwind.opcodes[unwind.opcode_count] = op & 0xff;
10822 op >>= 8;
10823 unwind.opcode_count++;
10827 /* Add unwind opcodes to adjust the stack pointer. */
10829 static void
10830 add_unwind_adjustsp (offsetT offset)
10832 valueT op;
10834 if (offset > 0x200)
10836 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
10837 char bytes[5];
10838 int n;
10839 valueT o;
10841 /* Long form: 0xb2, uleb128. */
10842 /* This might not fit in a word so add the individual bytes,
10843 remembering the list is built in reverse order. */
10844 o = (valueT) ((offset - 0x204) >> 2);
10845 if (o == 0)
10846 add_unwind_opcode (0, 1);
10848 /* Calculate the uleb128 encoding of the offset. */
10849 n = 0;
10850 while (o)
10852 bytes[n] = o & 0x7f;
10853 o >>= 7;
10854 if (o)
10855 bytes[n] |= 0x80;
10856 n++;
10858 /* Add the insn. */
10859 for (; n; n--)
10860 add_unwind_opcode (bytes[n - 1], 1);
10861 add_unwind_opcode (0xb2, 1);
10863 else if (offset > 0x100)
10865 /* Two short opcodes. */
10866 add_unwind_opcode (0x3f, 1);
10867 op = (offset - 0x104) >> 2;
10868 add_unwind_opcode (op, 1);
10870 else if (offset > 0)
10872 /* Short opcode. */
10873 op = (offset - 4) >> 2;
10874 add_unwind_opcode (op, 1);
10876 else if (offset < 0)
10878 offset = -offset;
10879 while (offset > 0x100)
10881 add_unwind_opcode (0x7f, 1);
10882 offset -= 0x100;
10884 op = ((offset - 4) >> 2) | 0x40;
10885 add_unwind_opcode (op, 1);
10889 /* Finish the list of unwind opcodes for this function. */
10890 static void
10891 finish_unwind_opcodes (void)
10893 valueT op;
10895 if (unwind.fp_used)
10897 /* Adjust sp as neccessary. */
10898 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
10899 flush_pending_unwind ();
10901 /* After restoring sp from the frame pointer. */
10902 op = 0x90 | unwind.fp_reg;
10903 add_unwind_opcode (op, 1);
10905 else
10906 flush_pending_unwind ();
10910 /* Start an exception table entry. If idx is nonzero this is an index table
10911 entry. */
10913 static void
10914 start_unwind_section (const segT text_seg, int idx)
10916 const char * text_name;
10917 const char * prefix;
10918 const char * prefix_once;
10919 const char * group_name;
10920 size_t prefix_len;
10921 size_t text_len;
10922 char * sec_name;
10923 size_t sec_name_len;
10924 int type;
10925 int flags;
10926 int linkonce;
10928 if (idx)
10930 prefix = ELF_STRING_ARM_unwind;
10931 prefix_once = ELF_STRING_ARM_unwind_once;
10932 type = SHT_ARM_EXIDX;
10934 else
10936 prefix = ELF_STRING_ARM_unwind_info;
10937 prefix_once = ELF_STRING_ARM_unwind_info_once;
10938 type = SHT_PROGBITS;
10941 text_name = segment_name (text_seg);
10942 if (streq (text_name, ".text"))
10943 text_name = "";
10945 if (strncmp (text_name, ".gnu.linkonce.t.",
10946 strlen (".gnu.linkonce.t.")) == 0)
10948 prefix = prefix_once;
10949 text_name += strlen (".gnu.linkonce.t.");
10952 prefix_len = strlen (prefix);
10953 text_len = strlen (text_name);
10954 sec_name_len = prefix_len + text_len;
10955 sec_name = xmalloc (sec_name_len + 1);
10956 memcpy (sec_name, prefix, prefix_len);
10957 memcpy (sec_name + prefix_len, text_name, text_len);
10958 sec_name[prefix_len + text_len] = '\0';
10960 flags = SHF_ALLOC;
10961 linkonce = 0;
10962 group_name = 0;
10964 /* Handle COMDAT group. */
10965 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
10967 group_name = elf_group_name (text_seg);
10968 if (group_name == NULL)
10970 as_bad ("Group section `%s' has no group signature",
10971 segment_name (text_seg));
10972 ignore_rest_of_line ();
10973 return;
10975 flags |= SHF_GROUP;
10976 linkonce = 1;
10979 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
10981 /* Set the setion link for index tables. */
10982 if (idx)
10983 elf_linked_to_section (now_seg) = text_seg;
10987 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
10988 personality routine data. Returns zero, or the index table value for
10989 and inline entry. */
10991 static valueT
10992 create_unwind_entry (int have_data)
10994 int size;
10995 addressT where;
10996 char *ptr;
10997 /* The current word of data. */
10998 valueT data;
10999 /* The number of bytes left in this word. */
11000 int n;
11002 finish_unwind_opcodes ();
11004 /* Remember the current text section. */
11005 unwind.saved_seg = now_seg;
11006 unwind.saved_subseg = now_subseg;
11008 start_unwind_section (now_seg, 0);
11010 if (unwind.personality_routine == NULL)
11012 if (unwind.personality_index == -2)
11014 if (have_data)
11015 as_bad (_("handerdata in cantunwind frame"));
11016 return 1; /* EXIDX_CANTUNWIND. */
11019 /* Use a default personality routine if none is specified. */
11020 if (unwind.personality_index == -1)
11022 if (unwind.opcode_count > 3)
11023 unwind.personality_index = 1;
11024 else
11025 unwind.personality_index = 0;
11028 /* Space for the personality routine entry. */
11029 if (unwind.personality_index == 0)
11031 if (unwind.opcode_count > 3)
11032 as_bad (_("too many unwind opcodes for personality routine 0"));
11034 if (!have_data)
11036 /* All the data is inline in the index table. */
11037 data = 0x80;
11038 n = 3;
11039 while (unwind.opcode_count > 0)
11041 unwind.opcode_count--;
11042 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
11043 n--;
11046 /* Pad with "finish" opcodes. */
11047 while (n--)
11048 data = (data << 8) | 0xb0;
11050 return data;
11052 size = 0;
11054 else
11055 /* We get two opcodes "free" in the first word. */
11056 size = unwind.opcode_count - 2;
11058 else
11059 /* An extra byte is required for the opcode count. */
11060 size = unwind.opcode_count + 1;
11062 size = (size + 3) >> 2;
11063 if (size > 0xff)
11064 as_bad (_("too many unwind opcodes"));
11066 frag_align (2, 0, 0);
11067 record_alignment (now_seg, 2);
11068 unwind.table_entry = expr_build_dot ();
11070 /* Allocate the table entry. */
11071 ptr = frag_more ((size << 2) + 4);
11072 where = frag_now_fix () - ((size << 2) + 4);
11074 switch (unwind.personality_index)
11076 case -1:
11077 /* ??? Should this be a PLT generating relocation? */
11078 /* Custom personality routine. */
11079 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
11080 BFD_RELOC_ARM_PREL31);
11082 where += 4;
11083 ptr += 4;
11085 /* Set the first byte to the number of additional words. */
11086 data = size - 1;
11087 n = 3;
11088 break;
11090 /* ABI defined personality routines. */
11091 case 0:
11092 /* Three opcodes bytes are packed into the first word. */
11093 data = 0x80;
11094 n = 3;
11095 break;
11097 case 1:
11098 case 2:
11099 /* The size and first two opcode bytes go in the first word. */
11100 data = ((0x80 + unwind.personality_index) << 8) | size;
11101 n = 2;
11102 break;
11104 default:
11105 /* Should never happen. */
11106 abort ();
11109 /* Pack the opcodes into words (MSB first), reversing the list at the same
11110 time. */
11111 while (unwind.opcode_count > 0)
11113 if (n == 0)
11115 md_number_to_chars (ptr, data, 4);
11116 ptr += 4;
11117 n = 4;
11118 data = 0;
11120 unwind.opcode_count--;
11121 n--;
11122 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
11125 /* Finish off the last word. */
11126 if (n < 4)
11128 /* Pad with "finish" opcodes. */
11129 while (n--)
11130 data = (data << 8) | 0xb0;
11132 md_number_to_chars (ptr, data, 4);
11135 if (!have_data)
11137 /* Add an empty descriptor if there is no user-specified data. */
11138 ptr = frag_more (4);
11139 md_number_to_chars (ptr, 0, 4);
11142 return 0;
11145 /* Convert REGNAME to a DWARF-2 register number. */
11148 tc_arm_regname_to_dw2regnum (const char *regname)
11150 int reg = arm_reg_parse ((char **) &regname, REG_TYPE_RN);
11152 if (reg == FAIL)
11153 return -1;
11155 return reg;
11158 /* Initialize the DWARF-2 unwind information for this procedure. */
11160 void
11161 tc_arm_frame_initial_instructions (void)
11163 cfi_add_CFA_def_cfa (REG_SP, 0);
11165 #endif /* OBJ_ELF */
11168 /* MD interface: Symbol and relocation handling. */
11170 /* Return the address within the segment that a PC-relative fixup is
11171 relative to. For ARM, PC-relative fixups applied to instructions
11172 are generally relative to the location of the fixup plus 8 bytes.
11173 Thumb branches are offset by 4, and Thumb loads relative to PC
11174 require special handling. */
11176 long
11177 md_pcrel_from_section (fixS * fixP, segT seg)
11179 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
11181 /* If this is pc-relative and we are going to emit a relocation
11182 then we just want to put out any pipeline compensation that the linker
11183 will need. Otherwise we want to use the calculated base. */
11184 if (fixP->fx_pcrel
11185 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
11186 || arm_force_relocation (fixP)))
11187 base = 0;
11189 switch (fixP->fx_r_type)
11191 /* PC relative addressing on the Thumb is slightly odd as the
11192 bottom two bits of the PC are forced to zero for the
11193 calculation. This happens *after* application of the
11194 pipeline offset. However, Thumb adrl already adjusts for
11195 this, so we need not do it again. */
11196 case BFD_RELOC_ARM_THUMB_ADD:
11197 return base & ~3;
11199 case BFD_RELOC_ARM_THUMB_OFFSET:
11200 case BFD_RELOC_ARM_T32_OFFSET_IMM:
11201 case BFD_RELOC_ARM_T32_ADD_PC12:
11202 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
11203 return (base + 4) & ~3;
11205 /* Thumb branches are simply offset by +4. */
11206 case BFD_RELOC_THUMB_PCREL_BRANCH7:
11207 case BFD_RELOC_THUMB_PCREL_BRANCH9:
11208 case BFD_RELOC_THUMB_PCREL_BRANCH12:
11209 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11210 case BFD_RELOC_THUMB_PCREL_BRANCH23:
11211 case BFD_RELOC_THUMB_PCREL_BRANCH25:
11212 case BFD_RELOC_THUMB_PCREL_BLX:
11213 return base + 4;
11215 /* ARM mode branches are offset by +8. However, the Windows CE
11216 loader expects the relocation not to take this into account. */
11217 case BFD_RELOC_ARM_PCREL_BRANCH:
11218 case BFD_RELOC_ARM_PCREL_CALL:
11219 case BFD_RELOC_ARM_PCREL_JUMP:
11220 case BFD_RELOC_ARM_PCREL_BLX:
11221 case BFD_RELOC_ARM_PLT32:
11222 #ifdef TE_WINCE
11223 return base;
11224 #else
11225 return base + 8;
11226 #endif
11228 /* ARM mode loads relative to PC are also offset by +8. Unlike
11229 branches, the Windows CE loader *does* expect the relocation
11230 to take this into account. */
11231 case BFD_RELOC_ARM_OFFSET_IMM:
11232 case BFD_RELOC_ARM_OFFSET_IMM8:
11233 case BFD_RELOC_ARM_HWLITERAL:
11234 case BFD_RELOC_ARM_LITERAL:
11235 case BFD_RELOC_ARM_CP_OFF_IMM:
11236 return base + 8;
11239 /* Other PC-relative relocations are un-offset. */
11240 default:
11241 return base;
11245 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
11246 Otherwise we have no need to default values of symbols. */
11248 symbolS *
11249 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
11251 #ifdef OBJ_ELF
11252 if (name[0] == '_' && name[1] == 'G'
11253 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
11255 if (!GOT_symbol)
11257 if (symbol_find (name))
11258 as_bad ("GOT already in the symbol table");
11260 GOT_symbol = symbol_new (name, undefined_section,
11261 (valueT) 0, & zero_address_frag);
11264 return GOT_symbol;
11266 #endif
11268 return 0;
11271 /* Subroutine of md_apply_fix. Check to see if an immediate can be
11272 computed as two separate immediate values, added together. We
11273 already know that this value cannot be computed by just one ARM
11274 instruction. */
11276 static unsigned int
11277 validate_immediate_twopart (unsigned int val,
11278 unsigned int * highpart)
11280 unsigned int a;
11281 unsigned int i;
11283 for (i = 0; i < 32; i += 2)
11284 if (((a = rotate_left (val, i)) & 0xff) != 0)
11286 if (a & 0xff00)
11288 if (a & ~ 0xffff)
11289 continue;
11290 * highpart = (a >> 8) | ((i + 24) << 7);
11292 else if (a & 0xff0000)
11294 if (a & 0xff000000)
11295 continue;
11296 * highpart = (a >> 16) | ((i + 16) << 7);
11298 else
11300 assert (a & 0xff000000);
11301 * highpart = (a >> 24) | ((i + 8) << 7);
11304 return (a & 0xff) | (i << 7);
11307 return FAIL;
11310 static int
11311 validate_offset_imm (unsigned int val, int hwse)
11313 if ((hwse && val > 255) || val > 4095)
11314 return FAIL;
11315 return val;
11318 /* Subroutine of md_apply_fix. Do those data_ops which can take a
11319 negative immediate constant by altering the instruction. A bit of
11320 a hack really.
11321 MOV <-> MVN
11322 AND <-> BIC
11323 ADC <-> SBC
11324 by inverting the second operand, and
11325 ADD <-> SUB
11326 CMP <-> CMN
11327 by negating the second operand. */
11329 static int
11330 negate_data_op (unsigned long * instruction,
11331 unsigned long value)
11333 int op, new_inst;
11334 unsigned long negated, inverted;
11336 negated = encode_arm_immediate (-value);
11337 inverted = encode_arm_immediate (~value);
11339 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
11340 switch (op)
11342 /* First negates. */
11343 case OPCODE_SUB: /* ADD <-> SUB */
11344 new_inst = OPCODE_ADD;
11345 value = negated;
11346 break;
11348 case OPCODE_ADD:
11349 new_inst = OPCODE_SUB;
11350 value = negated;
11351 break;
11353 case OPCODE_CMP: /* CMP <-> CMN */
11354 new_inst = OPCODE_CMN;
11355 value = negated;
11356 break;
11358 case OPCODE_CMN:
11359 new_inst = OPCODE_CMP;
11360 value = negated;
11361 break;
11363 /* Now Inverted ops. */
11364 case OPCODE_MOV: /* MOV <-> MVN */
11365 new_inst = OPCODE_MVN;
11366 value = inverted;
11367 break;
11369 case OPCODE_MVN:
11370 new_inst = OPCODE_MOV;
11371 value = inverted;
11372 break;
11374 case OPCODE_AND: /* AND <-> BIC */
11375 new_inst = OPCODE_BIC;
11376 value = inverted;
11377 break;
11379 case OPCODE_BIC:
11380 new_inst = OPCODE_AND;
11381 value = inverted;
11382 break;
11384 case OPCODE_ADC: /* ADC <-> SBC */
11385 new_inst = OPCODE_SBC;
11386 value = inverted;
11387 break;
11389 case OPCODE_SBC:
11390 new_inst = OPCODE_ADC;
11391 value = inverted;
11392 break;
11394 /* We cannot do anything. */
11395 default:
11396 return FAIL;
11399 if (value == (unsigned) FAIL)
11400 return FAIL;
11402 *instruction &= OPCODE_MASK;
11403 *instruction |= new_inst << DATA_OP_SHIFT;
11404 return value;
11407 /* Like negate_data_op, but for Thumb-2. */
11409 static unsigned int
11410 thumb32_negate_data_op (offsetT *instruction, offsetT value)
11412 int op, new_inst;
11413 int rd;
11414 offsetT negated, inverted;
11416 negated = encode_thumb32_immediate (-value);
11417 inverted = encode_thumb32_immediate (~value);
11419 rd = (*instruction >> 8) & 0xf;
11420 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
11421 switch (op)
11423 /* ADD <-> SUB. Includes CMP <-> CMN. */
11424 case T2_OPCODE_SUB:
11425 new_inst = T2_OPCODE_ADD;
11426 value = negated;
11427 break;
11429 case T2_OPCODE_ADD:
11430 new_inst = T2_OPCODE_SUB;
11431 value = negated;
11432 break;
11434 /* ORR <-> ORN. Includes MOV <-> MVN. */
11435 case T2_OPCODE_ORR:
11436 new_inst = T2_OPCODE_ORN;
11437 value = inverted;
11438 break;
11440 case T2_OPCODE_ORN:
11441 new_inst = T2_OPCODE_ORR;
11442 value = inverted;
11443 break;
11445 /* AND <-> BIC. TST has no inverted equivalent. */
11446 case T2_OPCODE_AND:
11447 new_inst = T2_OPCODE_BIC;
11448 if (rd == 15)
11449 value = FAIL;
11450 else
11451 value = inverted;
11452 break;
11454 case T2_OPCODE_BIC:
11455 new_inst = T2_OPCODE_AND;
11456 value = inverted;
11457 break;
11459 /* ADC <-> SBC */
11460 case T2_OPCODE_ADC:
11461 new_inst = T2_OPCODE_SBC;
11462 value = inverted;
11463 break;
11465 case T2_OPCODE_SBC:
11466 new_inst = T2_OPCODE_ADC;
11467 value = inverted;
11468 break;
11470 /* We cannot do anything. */
11471 default:
11472 return FAIL;
11475 if (value == FAIL)
11476 return FAIL;
11478 *instruction &= T2_OPCODE_MASK;
11479 *instruction |= new_inst << T2_DATA_OP_SHIFT;
11480 return value;
11483 /* Read a 32-bit thumb instruction from buf. */
11484 static unsigned long
11485 get_thumb32_insn (char * buf)
11487 unsigned long insn;
11488 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
11489 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11491 return insn;
11494 void
11495 md_apply_fix (fixS * fixP,
11496 valueT * valP,
11497 segT seg)
11499 offsetT value = * valP;
11500 offsetT newval;
11501 unsigned int newimm;
11502 unsigned long temp;
11503 int sign;
11504 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
11506 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
11508 /* Note whether this will delete the relocation. */
11509 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
11510 fixP->fx_done = 1;
11512 /* On a 64-bit host, silently truncate 'value' to 32 bits for
11513 consistency with the behavior on 32-bit hosts. Remember value
11514 for emit_reloc. */
11515 value &= 0xffffffff;
11516 value ^= 0x80000000;
11517 value -= 0x80000000;
11519 *valP = value;
11520 fixP->fx_addnumber = value;
11522 /* Same treatment for fixP->fx_offset. */
11523 fixP->fx_offset &= 0xffffffff;
11524 fixP->fx_offset ^= 0x80000000;
11525 fixP->fx_offset -= 0x80000000;
11527 switch (fixP->fx_r_type)
11529 case BFD_RELOC_NONE:
11530 /* This will need to go in the object file. */
11531 fixP->fx_done = 0;
11532 break;
11534 case BFD_RELOC_ARM_IMMEDIATE:
11535 /* We claim that this fixup has been processed here,
11536 even if in fact we generate an error because we do
11537 not have a reloc for it, so tc_gen_reloc will reject it. */
11538 fixP->fx_done = 1;
11540 if (fixP->fx_addsy
11541 && ! S_IS_DEFINED (fixP->fx_addsy))
11543 as_bad_where (fixP->fx_file, fixP->fx_line,
11544 _("undefined symbol %s used as an immediate value"),
11545 S_GET_NAME (fixP->fx_addsy));
11546 break;
11549 newimm = encode_arm_immediate (value);
11550 temp = md_chars_to_number (buf, INSN_SIZE);
11552 /* If the instruction will fail, see if we can fix things up by
11553 changing the opcode. */
11554 if (newimm == (unsigned int) FAIL
11555 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
11557 as_bad_where (fixP->fx_file, fixP->fx_line,
11558 _("invalid constant (%lx) after fixup"),
11559 (unsigned long) value);
11560 break;
11563 newimm |= (temp & 0xfffff000);
11564 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
11565 break;
11567 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11569 unsigned int highpart = 0;
11570 unsigned int newinsn = 0xe1a00000; /* nop. */
11572 newimm = encode_arm_immediate (value);
11573 temp = md_chars_to_number (buf, INSN_SIZE);
11575 /* If the instruction will fail, see if we can fix things up by
11576 changing the opcode. */
11577 if (newimm == (unsigned int) FAIL
11578 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
11580 /* No ? OK - try using two ADD instructions to generate
11581 the value. */
11582 newimm = validate_immediate_twopart (value, & highpart);
11584 /* Yes - then make sure that the second instruction is
11585 also an add. */
11586 if (newimm != (unsigned int) FAIL)
11587 newinsn = temp;
11588 /* Still No ? Try using a negated value. */
11589 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
11590 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
11591 /* Otherwise - give up. */
11592 else
11594 as_bad_where (fixP->fx_file, fixP->fx_line,
11595 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
11596 (long) value);
11597 break;
11600 /* Replace the first operand in the 2nd instruction (which
11601 is the PC) with the destination register. We have
11602 already added in the PC in the first instruction and we
11603 do not want to do it again. */
11604 newinsn &= ~ 0xf0000;
11605 newinsn |= ((newinsn & 0x0f000) << 4);
11608 newimm |= (temp & 0xfffff000);
11609 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
11611 highpart |= (newinsn & 0xfffff000);
11612 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
11614 break;
11616 case BFD_RELOC_ARM_OFFSET_IMM:
11617 if (!fixP->fx_done && seg->use_rela_p)
11618 value = 0;
11620 case BFD_RELOC_ARM_LITERAL:
11621 sign = value >= 0;
11623 if (value < 0)
11624 value = - value;
11626 if (validate_offset_imm (value, 0) == FAIL)
11628 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
11629 as_bad_where (fixP->fx_file, fixP->fx_line,
11630 _("invalid literal constant: pool needs to be closer"));
11631 else
11632 as_bad_where (fixP->fx_file, fixP->fx_line,
11633 _("bad immediate value for offset (%ld)"),
11634 (long) value);
11635 break;
11638 newval = md_chars_to_number (buf, INSN_SIZE);
11639 newval &= 0xff7ff000;
11640 newval |= value | (sign ? INDEX_UP : 0);
11641 md_number_to_chars (buf, newval, INSN_SIZE);
11642 break;
11644 case BFD_RELOC_ARM_OFFSET_IMM8:
11645 case BFD_RELOC_ARM_HWLITERAL:
11646 sign = value >= 0;
11648 if (value < 0)
11649 value = - value;
11651 if (validate_offset_imm (value, 1) == FAIL)
11653 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
11654 as_bad_where (fixP->fx_file, fixP->fx_line,
11655 _("invalid literal constant: pool needs to be closer"));
11656 else
11657 as_bad (_("bad immediate value for half-word offset (%ld)"),
11658 (long) value);
11659 break;
11662 newval = md_chars_to_number (buf, INSN_SIZE);
11663 newval &= 0xff7ff0f0;
11664 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
11665 md_number_to_chars (buf, newval, INSN_SIZE);
11666 break;
11668 case BFD_RELOC_ARM_T32_OFFSET_U8:
11669 if (value < 0 || value > 1020 || value % 4 != 0)
11670 as_bad_where (fixP->fx_file, fixP->fx_line,
11671 _("bad immediate value for offset (%ld)"), (long) value);
11672 value /= 4;
11674 newval = md_chars_to_number (buf+2, THUMB_SIZE);
11675 newval |= value;
11676 md_number_to_chars (buf+2, newval, THUMB_SIZE);
11677 break;
11679 case BFD_RELOC_ARM_T32_OFFSET_IMM:
11680 /* This is a complicated relocation used for all varieties of Thumb32
11681 load/store instruction with immediate offset:
11683 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
11684 *4, optional writeback(W)
11685 (doubleword load/store)
11687 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
11688 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
11689 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
11690 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
11691 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
11693 Uppercase letters indicate bits that are already encoded at
11694 this point. Lowercase letters are our problem. For the
11695 second block of instructions, the secondary opcode nybble
11696 (bits 8..11) is present, and bit 23 is zero, even if this is
11697 a PC-relative operation. */
11698 newval = md_chars_to_number (buf, THUMB_SIZE);
11699 newval <<= 16;
11700 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
11702 if ((newval & 0xf0000000) == 0xe0000000)
11704 /* Doubleword load/store: 8-bit offset, scaled by 4. */
11705 if (value >= 0)
11706 newval |= (1 << 23);
11707 else
11708 value = -value;
11709 if (value % 4 != 0)
11711 as_bad_where (fixP->fx_file, fixP->fx_line,
11712 _("offset not a multiple of 4"));
11713 break;
11715 value /= 4;
11716 if (value > 0xff)
11718 as_bad_where (fixP->fx_file, fixP->fx_line,
11719 _("offset out of range"));
11720 break;
11722 newval &= ~0xff;
11724 else if ((newval & 0x000f0000) == 0x000f0000)
11726 /* PC-relative, 12-bit offset. */
11727 if (value >= 0)
11728 newval |= (1 << 23);
11729 else
11730 value = -value;
11731 if (value > 0xfff)
11733 as_bad_where (fixP->fx_file, fixP->fx_line,
11734 _("offset out of range"));
11735 break;
11737 newval &= ~0xfff;
11739 else if ((newval & 0x00000100) == 0x00000100)
11741 /* Writeback: 8-bit, +/- offset. */
11742 if (value >= 0)
11743 newval |= (1 << 9);
11744 else
11745 value = -value;
11746 if (value > 0xff)
11748 as_bad_where (fixP->fx_file, fixP->fx_line,
11749 _("offset out of range"));
11750 break;
11752 newval &= ~0xff;
11754 else if ((newval & 0x00000f00) == 0x00000e00)
11756 /* T-instruction: positive 8-bit offset. */
11757 if (value < 0 || value > 0xff)
11759 as_bad_where (fixP->fx_file, fixP->fx_line,
11760 _("offset out of range"));
11761 break;
11763 newval &= ~0xff;
11764 newval |= value;
11766 else
11768 /* Positive 12-bit or negative 8-bit offset. */
11769 int limit;
11770 if (value >= 0)
11772 newval |= (1 << 23);
11773 limit = 0xfff;
11775 else
11777 value = -value;
11778 limit = 0xff;
11780 if (value > limit)
11782 as_bad_where (fixP->fx_file, fixP->fx_line,
11783 _("offset out of range"));
11784 break;
11786 newval &= ~limit;
11789 newval |= value;
11790 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
11791 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
11792 break;
11794 case BFD_RELOC_ARM_SHIFT_IMM:
11795 newval = md_chars_to_number (buf, INSN_SIZE);
11796 if (((unsigned long) value) > 32
11797 || (value == 32
11798 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
11800 as_bad_where (fixP->fx_file, fixP->fx_line,
11801 _("shift expression is too large"));
11802 break;
11805 if (value == 0)
11806 /* Shifts of zero must be done as lsl. */
11807 newval &= ~0x60;
11808 else if (value == 32)
11809 value = 0;
11810 newval &= 0xfffff07f;
11811 newval |= (value & 0x1f) << 7;
11812 md_number_to_chars (buf, newval, INSN_SIZE);
11813 break;
11815 case BFD_RELOC_ARM_T32_IMMEDIATE:
11816 case BFD_RELOC_ARM_T32_IMM12:
11817 case BFD_RELOC_ARM_T32_ADD_PC12:
11818 /* We claim that this fixup has been processed here,
11819 even if in fact we generate an error because we do
11820 not have a reloc for it, so tc_gen_reloc will reject it. */
11821 fixP->fx_done = 1;
11823 if (fixP->fx_addsy
11824 && ! S_IS_DEFINED (fixP->fx_addsy))
11826 as_bad_where (fixP->fx_file, fixP->fx_line,
11827 _("undefined symbol %s used as an immediate value"),
11828 S_GET_NAME (fixP->fx_addsy));
11829 break;
11832 newval = md_chars_to_number (buf, THUMB_SIZE);
11833 newval <<= 16;
11834 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
11836 /* FUTURE: Implement analogue of negate_data_op for T32. */
11837 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE)
11839 newimm = encode_thumb32_immediate (value);
11840 if (newimm == (unsigned int) FAIL)
11841 newimm = thumb32_negate_data_op (&newval, value);
11843 else
11845 /* 12 bit immediate for addw/subw. */
11846 if (value < 0)
11848 value = -value;
11849 newval ^= 0x00a00000;
11851 if (value > 0xfff)
11852 newimm = (unsigned int) FAIL;
11853 else
11854 newimm = value;
11857 if (newimm == (unsigned int)FAIL)
11859 as_bad_where (fixP->fx_file, fixP->fx_line,
11860 _("invalid constant (%lx) after fixup"),
11861 (unsigned long) value);
11862 break;
11865 newval |= (newimm & 0x800) << 15;
11866 newval |= (newimm & 0x700) << 4;
11867 newval |= (newimm & 0x0ff);
11869 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
11870 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
11871 break;
11873 case BFD_RELOC_ARM_SMC:
11874 if (((unsigned long) value) > 0xffff)
11875 as_bad_where (fixP->fx_file, fixP->fx_line,
11876 _("invalid smc expression"));
11877 newval = md_chars_to_number (buf, INSN_SIZE);
11878 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
11879 md_number_to_chars (buf, newval, INSN_SIZE);
11880 break;
11882 case BFD_RELOC_ARM_SWI:
11883 if (fixP->tc_fix_data != 0)
11885 if (((unsigned long) value) > 0xff)
11886 as_bad_where (fixP->fx_file, fixP->fx_line,
11887 _("invalid swi expression"));
11888 newval = md_chars_to_number (buf, THUMB_SIZE);
11889 newval |= value;
11890 md_number_to_chars (buf, newval, THUMB_SIZE);
11892 else
11894 if (((unsigned long) value) > 0x00ffffff)
11895 as_bad_where (fixP->fx_file, fixP->fx_line,
11896 _("invalid swi expression"));
11897 newval = md_chars_to_number (buf, INSN_SIZE);
11898 newval |= value;
11899 md_number_to_chars (buf, newval, INSN_SIZE);
11901 break;
11903 case BFD_RELOC_ARM_MULTI:
11904 if (((unsigned long) value) > 0xffff)
11905 as_bad_where (fixP->fx_file, fixP->fx_line,
11906 _("invalid expression in load/store multiple"));
11907 newval = value | md_chars_to_number (buf, INSN_SIZE);
11908 md_number_to_chars (buf, newval, INSN_SIZE);
11909 break;
11911 #ifdef OBJ_ELF
11912 case BFD_RELOC_ARM_PCREL_CALL:
11913 newval = md_chars_to_number (buf, INSN_SIZE);
11914 if ((newval & 0xf0000000) == 0xf0000000)
11915 temp = 1;
11916 else
11917 temp = 3;
11918 goto arm_branch_common;
11920 case BFD_RELOC_ARM_PCREL_JUMP:
11921 case BFD_RELOC_ARM_PLT32:
11922 #endif
11923 case BFD_RELOC_ARM_PCREL_BRANCH:
11924 temp = 3;
11925 goto arm_branch_common;
11927 case BFD_RELOC_ARM_PCREL_BLX:
11928 temp = 1;
11929 arm_branch_common:
11930 /* We are going to store value (shifted right by two) in the
11931 instruction, in a 24 bit, signed field. Bits 26 through 32 either
11932 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
11933 also be be clear. */
11934 if (value & temp)
11935 as_bad_where (fixP->fx_file, fixP->fx_line,
11936 _("misaligned branch destination"));
11937 if ((value & (offsetT)0xfe000000) != (offsetT)0
11938 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
11939 as_bad_where (fixP->fx_file, fixP->fx_line,
11940 _("branch out of range"));
11942 if (fixP->fx_done || !seg->use_rela_p)
11944 newval = md_chars_to_number (buf, INSN_SIZE);
11945 newval |= (value >> 2) & 0x00ffffff;
11946 /* Set the H bit on BLX instructions. */
11947 if (temp == 1)
11949 if (value & 2)
11950 newval |= 0x01000000;
11951 else
11952 newval &= ~0x01000000;
11954 md_number_to_chars (buf, newval, INSN_SIZE);
11956 break;
11958 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
11959 /* CZB can only branch forward. */
11960 if (value & ~0x7e)
11961 as_bad_where (fixP->fx_file, fixP->fx_line,
11962 _("branch out of range"));
11964 if (fixP->fx_done || !seg->use_rela_p)
11966 newval = md_chars_to_number (buf, THUMB_SIZE);
11967 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
11968 md_number_to_chars (buf, newval, THUMB_SIZE);
11970 break;
11972 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
11973 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
11974 as_bad_where (fixP->fx_file, fixP->fx_line,
11975 _("branch out of range"));
11977 if (fixP->fx_done || !seg->use_rela_p)
11979 newval = md_chars_to_number (buf, THUMB_SIZE);
11980 newval |= (value & 0x1ff) >> 1;
11981 md_number_to_chars (buf, newval, THUMB_SIZE);
11983 break;
11985 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
11986 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
11987 as_bad_where (fixP->fx_file, fixP->fx_line,
11988 _("branch out of range"));
11990 if (fixP->fx_done || !seg->use_rela_p)
11992 newval = md_chars_to_number (buf, THUMB_SIZE);
11993 newval |= (value & 0xfff) >> 1;
11994 md_number_to_chars (buf, newval, THUMB_SIZE);
11996 break;
11998 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11999 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
12000 as_bad_where (fixP->fx_file, fixP->fx_line,
12001 _("conditional branch out of range"));
12003 if (fixP->fx_done || !seg->use_rela_p)
12005 offsetT newval2;
12006 addressT S, J1, J2, lo, hi;
12008 S = (value & 0x00100000) >> 20;
12009 J2 = (value & 0x00080000) >> 19;
12010 J1 = (value & 0x00040000) >> 18;
12011 hi = (value & 0x0003f000) >> 12;
12012 lo = (value & 0x00000ffe) >> 1;
12014 newval = md_chars_to_number (buf, THUMB_SIZE);
12015 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
12016 newval |= (S << 10) | hi;
12017 newval2 |= (J1 << 13) | (J2 << 11) | lo;
12018 md_number_to_chars (buf, newval, THUMB_SIZE);
12019 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
12021 break;
12023 case BFD_RELOC_THUMB_PCREL_BLX:
12024 case BFD_RELOC_THUMB_PCREL_BRANCH23:
12025 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
12026 as_bad_where (fixP->fx_file, fixP->fx_line,
12027 _("branch out of range"));
12029 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
12030 /* For a BLX instruction, make sure that the relocation is rounded up
12031 to a word boundary. This follows the semantics of the instruction
12032 which specifies that bit 1 of the target address will come from bit
12033 1 of the base address. */
12034 value = (value + 1) & ~ 1;
12036 if (fixP->fx_done || !seg->use_rela_p)
12038 offsetT newval2;
12040 newval = md_chars_to_number (buf, THUMB_SIZE);
12041 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
12042 newval |= (value & 0x7fffff) >> 12;
12043 newval2 |= (value & 0xfff) >> 1;
12044 md_number_to_chars (buf, newval, THUMB_SIZE);
12045 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
12047 break;
12049 case BFD_RELOC_THUMB_PCREL_BRANCH25:
12050 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
12051 as_bad_where (fixP->fx_file, fixP->fx_line,
12052 _("branch out of range"));
12054 if (fixP->fx_done || !seg->use_rela_p)
12056 offsetT newval2;
12057 addressT S, I1, I2, lo, hi;
12059 S = (value & 0x01000000) >> 24;
12060 I1 = (value & 0x00800000) >> 23;
12061 I2 = (value & 0x00400000) >> 22;
12062 hi = (value & 0x003ff000) >> 12;
12063 lo = (value & 0x00000ffe) >> 1;
12065 I1 = !(I1 ^ S);
12066 I2 = !(I2 ^ S);
12068 newval = md_chars_to_number (buf, THUMB_SIZE);
12069 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
12070 newval |= (S << 10) | hi;
12071 newval2 |= (I1 << 13) | (I2 << 11) | lo;
12072 md_number_to_chars (buf, newval, THUMB_SIZE);
12073 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
12075 break;
12077 case BFD_RELOC_8:
12078 if (fixP->fx_done || !seg->use_rela_p)
12079 md_number_to_chars (buf, value, 1);
12080 break;
12082 case BFD_RELOC_16:
12083 if (fixP->fx_done || !seg->use_rela_p)
12084 md_number_to_chars (buf, value, 2);
12085 break;
12087 #ifdef OBJ_ELF
12088 case BFD_RELOC_ARM_TLS_GD32:
12089 case BFD_RELOC_ARM_TLS_LE32:
12090 case BFD_RELOC_ARM_TLS_IE32:
12091 case BFD_RELOC_ARM_TLS_LDM32:
12092 case BFD_RELOC_ARM_TLS_LDO32:
12093 S_SET_THREAD_LOCAL (fixP->fx_addsy);
12094 /* fall through */
12096 case BFD_RELOC_ARM_GOT32:
12097 case BFD_RELOC_ARM_GOTOFF:
12098 case BFD_RELOC_ARM_TARGET2:
12099 if (fixP->fx_done || !seg->use_rela_p)
12100 md_number_to_chars (buf, 0, 4);
12101 break;
12102 #endif
12104 case BFD_RELOC_RVA:
12105 case BFD_RELOC_32:
12106 case BFD_RELOC_ARM_TARGET1:
12107 case BFD_RELOC_ARM_ROSEGREL32:
12108 case BFD_RELOC_ARM_SBREL32:
12109 case BFD_RELOC_32_PCREL:
12110 if (fixP->fx_done || !seg->use_rela_p)
12111 md_number_to_chars (buf, value, 4);
12112 break;
12114 #ifdef OBJ_ELF
12115 case BFD_RELOC_ARM_PREL31:
12116 if (fixP->fx_done || !seg->use_rela_p)
12118 newval = md_chars_to_number (buf, 4) & 0x80000000;
12119 if ((value ^ (value >> 1)) & 0x40000000)
12121 as_bad_where (fixP->fx_file, fixP->fx_line,
12122 _("rel31 relocation overflow"));
12124 newval |= value & 0x7fffffff;
12125 md_number_to_chars (buf, newval, 4);
12127 break;
12128 #endif
12130 case BFD_RELOC_ARM_CP_OFF_IMM:
12131 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
12132 if (value < -1023 || value > 1023 || (value & 3))
12133 as_bad_where (fixP->fx_file, fixP->fx_line,
12134 _("co-processor offset out of range"));
12135 cp_off_common:
12136 sign = value >= 0;
12137 if (value < 0)
12138 value = -value;
12139 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
12140 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
12141 newval = md_chars_to_number (buf, INSN_SIZE);
12142 else
12143 newval = get_thumb32_insn (buf);
12144 newval &= 0xff7fff00;
12145 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
12146 if (value == 0)
12147 newval &= ~WRITE_BACK;
12148 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
12149 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
12150 md_number_to_chars (buf, newval, INSN_SIZE);
12151 else
12152 put_thumb32_insn (buf, newval);
12153 break;
12155 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
12156 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
12157 if (value < -255 || value > 255)
12158 as_bad_where (fixP->fx_file, fixP->fx_line,
12159 _("co-processor offset out of range"));
12160 goto cp_off_common;
12162 case BFD_RELOC_ARM_THUMB_OFFSET:
12163 newval = md_chars_to_number (buf, THUMB_SIZE);
12164 /* Exactly what ranges, and where the offset is inserted depends
12165 on the type of instruction, we can establish this from the
12166 top 4 bits. */
12167 switch (newval >> 12)
12169 case 4: /* PC load. */
12170 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
12171 forced to zero for these loads; md_pcrel_from has already
12172 compensated for this. */
12173 if (value & 3)
12174 as_bad_where (fixP->fx_file, fixP->fx_line,
12175 _("invalid offset, target not word aligned (0x%08lX)"),
12176 (((unsigned long) fixP->fx_frag->fr_address
12177 + (unsigned long) fixP->fx_where) & ~3)
12178 + (unsigned long) value);
12180 if (value & ~0x3fc)
12181 as_bad_where (fixP->fx_file, fixP->fx_line,
12182 _("invalid offset, value too big (0x%08lX)"),
12183 (long) value);
12185 newval |= value >> 2;
12186 break;
12188 case 9: /* SP load/store. */
12189 if (value & ~0x3fc)
12190 as_bad_where (fixP->fx_file, fixP->fx_line,
12191 _("invalid offset, value too big (0x%08lX)"),
12192 (long) value);
12193 newval |= value >> 2;
12194 break;
12196 case 6: /* Word load/store. */
12197 if (value & ~0x7c)
12198 as_bad_where (fixP->fx_file, fixP->fx_line,
12199 _("invalid offset, value too big (0x%08lX)"),
12200 (long) value);
12201 newval |= value << 4; /* 6 - 2. */
12202 break;
12204 case 7: /* Byte load/store. */
12205 if (value & ~0x1f)
12206 as_bad_where (fixP->fx_file, fixP->fx_line,
12207 _("invalid offset, value too big (0x%08lX)"),
12208 (long) value);
12209 newval |= value << 6;
12210 break;
12212 case 8: /* Halfword load/store. */
12213 if (value & ~0x3e)
12214 as_bad_where (fixP->fx_file, fixP->fx_line,
12215 _("invalid offset, value too big (0x%08lX)"),
12216 (long) value);
12217 newval |= value << 5; /* 6 - 1. */
12218 break;
12220 default:
12221 as_bad_where (fixP->fx_file, fixP->fx_line,
12222 "Unable to process relocation for thumb opcode: %lx",
12223 (unsigned long) newval);
12224 break;
12226 md_number_to_chars (buf, newval, THUMB_SIZE);
12227 break;
12229 case BFD_RELOC_ARM_THUMB_ADD:
12230 /* This is a complicated relocation, since we use it for all of
12231 the following immediate relocations:
12233 3bit ADD/SUB
12234 8bit ADD/SUB
12235 9bit ADD/SUB SP word-aligned
12236 10bit ADD PC/SP word-aligned
12238 The type of instruction being processed is encoded in the
12239 instruction field:
12241 0x8000 SUB
12242 0x00F0 Rd
12243 0x000F Rs
12245 newval = md_chars_to_number (buf, THUMB_SIZE);
12247 int rd = (newval >> 4) & 0xf;
12248 int rs = newval & 0xf;
12249 int subtract = !!(newval & 0x8000);
12251 /* Check for HI regs, only very restricted cases allowed:
12252 Adjusting SP, and using PC or SP to get an address. */
12253 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
12254 || (rs > 7 && rs != REG_SP && rs != REG_PC))
12255 as_bad_where (fixP->fx_file, fixP->fx_line,
12256 _("invalid Hi register with immediate"));
12258 /* If value is negative, choose the opposite instruction. */
12259 if (value < 0)
12261 value = -value;
12262 subtract = !subtract;
12263 if (value < 0)
12264 as_bad_where (fixP->fx_file, fixP->fx_line,
12265 _("immediate value out of range"));
12268 if (rd == REG_SP)
12270 if (value & ~0x1fc)
12271 as_bad_where (fixP->fx_file, fixP->fx_line,
12272 _("invalid immediate for stack address calculation"));
12273 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
12274 newval |= value >> 2;
12276 else if (rs == REG_PC || rs == REG_SP)
12278 if (subtract || value & ~0x3fc)
12279 as_bad_where (fixP->fx_file, fixP->fx_line,
12280 _("invalid immediate for address calculation (value = 0x%08lX)"),
12281 (unsigned long) value);
12282 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
12283 newval |= rd << 8;
12284 newval |= value >> 2;
12286 else if (rs == rd)
12288 if (value & ~0xff)
12289 as_bad_where (fixP->fx_file, fixP->fx_line,
12290 _("immediate value out of range"));
12291 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
12292 newval |= (rd << 8) | value;
12294 else
12296 if (value & ~0x7)
12297 as_bad_where (fixP->fx_file, fixP->fx_line,
12298 _("immediate value out of range"));
12299 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
12300 newval |= rd | (rs << 3) | (value << 6);
12303 md_number_to_chars (buf, newval, THUMB_SIZE);
12304 break;
12306 case BFD_RELOC_ARM_THUMB_IMM:
12307 newval = md_chars_to_number (buf, THUMB_SIZE);
12308 if (value < 0 || value > 255)
12309 as_bad_where (fixP->fx_file, fixP->fx_line,
12310 _("invalid immediate: %ld is too large"),
12311 (long) value);
12312 newval |= value;
12313 md_number_to_chars (buf, newval, THUMB_SIZE);
12314 break;
12316 case BFD_RELOC_ARM_THUMB_SHIFT:
12317 /* 5bit shift value (0..32). LSL cannot take 32. */
12318 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
12319 temp = newval & 0xf800;
12320 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
12321 as_bad_where (fixP->fx_file, fixP->fx_line,
12322 _("invalid shift value: %ld"), (long) value);
12323 /* Shifts of zero must be encoded as LSL. */
12324 if (value == 0)
12325 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
12326 /* Shifts of 32 are encoded as zero. */
12327 else if (value == 32)
12328 value = 0;
12329 newval |= value << 6;
12330 md_number_to_chars (buf, newval, THUMB_SIZE);
12331 break;
12333 case BFD_RELOC_VTABLE_INHERIT:
12334 case BFD_RELOC_VTABLE_ENTRY:
12335 fixP->fx_done = 0;
12336 return;
12338 case BFD_RELOC_UNUSED:
12339 default:
12340 as_bad_where (fixP->fx_file, fixP->fx_line,
12341 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
12345 /* Translate internal representation of relocation info to BFD target
12346 format. */
12348 arelent *
12349 tc_gen_reloc (asection *section, fixS *fixp)
12351 arelent * reloc;
12352 bfd_reloc_code_real_type code;
12354 reloc = xmalloc (sizeof (arelent));
12356 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
12357 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12358 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
12360 if (fixp->fx_pcrel)
12362 if (section->use_rela_p)
12363 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
12364 else
12365 fixp->fx_offset = reloc->address;
12367 reloc->addend = fixp->fx_offset;
12369 switch (fixp->fx_r_type)
12371 case BFD_RELOC_8:
12372 if (fixp->fx_pcrel)
12374 code = BFD_RELOC_8_PCREL;
12375 break;
12378 case BFD_RELOC_16:
12379 if (fixp->fx_pcrel)
12381 code = BFD_RELOC_16_PCREL;
12382 break;
12385 case BFD_RELOC_32:
12386 if (fixp->fx_pcrel)
12388 code = BFD_RELOC_32_PCREL;
12389 break;
12392 case BFD_RELOC_NONE:
12393 case BFD_RELOC_ARM_PCREL_BRANCH:
12394 case BFD_RELOC_ARM_PCREL_BLX:
12395 case BFD_RELOC_RVA:
12396 case BFD_RELOC_THUMB_PCREL_BRANCH7:
12397 case BFD_RELOC_THUMB_PCREL_BRANCH9:
12398 case BFD_RELOC_THUMB_PCREL_BRANCH12:
12399 case BFD_RELOC_THUMB_PCREL_BRANCH20:
12400 case BFD_RELOC_THUMB_PCREL_BRANCH23:
12401 case BFD_RELOC_THUMB_PCREL_BRANCH25:
12402 case BFD_RELOC_THUMB_PCREL_BLX:
12403 case BFD_RELOC_VTABLE_ENTRY:
12404 case BFD_RELOC_VTABLE_INHERIT:
12405 code = fixp->fx_r_type;
12406 break;
12408 case BFD_RELOC_ARM_LITERAL:
12409 case BFD_RELOC_ARM_HWLITERAL:
12410 /* If this is called then the a literal has
12411 been referenced across a section boundary. */
12412 as_bad_where (fixp->fx_file, fixp->fx_line,
12413 _("literal referenced across section boundary"));
12414 return NULL;
12416 #ifdef OBJ_ELF
12417 case BFD_RELOC_ARM_GOT32:
12418 case BFD_RELOC_ARM_GOTOFF:
12419 case BFD_RELOC_ARM_PLT32:
12420 case BFD_RELOC_ARM_TARGET1:
12421 case BFD_RELOC_ARM_ROSEGREL32:
12422 case BFD_RELOC_ARM_SBREL32:
12423 case BFD_RELOC_ARM_PREL31:
12424 case BFD_RELOC_ARM_TARGET2:
12425 case BFD_RELOC_ARM_TLS_LE32:
12426 case BFD_RELOC_ARM_TLS_LDO32:
12427 case BFD_RELOC_ARM_PCREL_CALL:
12428 case BFD_RELOC_ARM_PCREL_JUMP:
12429 code = fixp->fx_r_type;
12430 break;
12432 case BFD_RELOC_ARM_TLS_GD32:
12433 case BFD_RELOC_ARM_TLS_IE32:
12434 case BFD_RELOC_ARM_TLS_LDM32:
12435 /* BFD will include the symbol's address in the addend.
12436 But we don't want that, so subtract it out again here. */
12437 if (!S_IS_COMMON (fixp->fx_addsy))
12438 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
12439 code = fixp->fx_r_type;
12440 break;
12441 #endif
12443 case BFD_RELOC_ARM_IMMEDIATE:
12444 as_bad_where (fixp->fx_file, fixp->fx_line,
12445 _("internal relocation (type: IMMEDIATE) not fixed up"));
12446 return NULL;
12448 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
12449 as_bad_where (fixp->fx_file, fixp->fx_line,
12450 _("ADRL used for a symbol not defined in the same file"));
12451 return NULL;
12453 case BFD_RELOC_ARM_OFFSET_IMM:
12454 if (section->use_rela_p)
12456 code = fixp->fx_r_type;
12457 break;
12460 if (fixp->fx_addsy != NULL
12461 && !S_IS_DEFINED (fixp->fx_addsy)
12462 && S_IS_LOCAL (fixp->fx_addsy))
12464 as_bad_where (fixp->fx_file, fixp->fx_line,
12465 _("undefined local label `%s'"),
12466 S_GET_NAME (fixp->fx_addsy));
12467 return NULL;
12470 as_bad_where (fixp->fx_file, fixp->fx_line,
12471 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
12472 return NULL;
12474 default:
12476 char * type;
12478 switch (fixp->fx_r_type)
12480 case BFD_RELOC_NONE: type = "NONE"; break;
12481 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
12482 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
12483 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
12484 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
12485 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
12486 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
12487 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
12488 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
12489 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
12490 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
12491 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
12492 default: type = _("<unknown>"); break;
12494 as_bad_where (fixp->fx_file, fixp->fx_line,
12495 _("cannot represent %s relocation in this object file format"),
12496 type);
12497 return NULL;
12501 #ifdef OBJ_ELF
12502 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
12503 && GOT_symbol
12504 && fixp->fx_addsy == GOT_symbol)
12506 code = BFD_RELOC_ARM_GOTPC;
12507 reloc->addend = fixp->fx_offset = reloc->address;
12509 #endif
12511 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
12513 if (reloc->howto == NULL)
12515 as_bad_where (fixp->fx_file, fixp->fx_line,
12516 _("cannot represent %s relocation in this object file format"),
12517 bfd_get_reloc_code_name (code));
12518 return NULL;
12521 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
12522 vtable entry to be used in the relocation's section offset. */
12523 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12524 reloc->address = fixp->fx_offset;
12526 return reloc;
12529 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
12531 void
12532 cons_fix_new_arm (fragS * frag,
12533 int where,
12534 int size,
12535 expressionS * exp)
12537 bfd_reloc_code_real_type type;
12538 int pcrel = 0;
12540 /* Pick a reloc.
12541 FIXME: @@ Should look at CPU word size. */
12542 switch (size)
12544 case 1:
12545 type = BFD_RELOC_8;
12546 break;
12547 case 2:
12548 type = BFD_RELOC_16;
12549 break;
12550 case 4:
12551 default:
12552 type = BFD_RELOC_32;
12553 break;
12554 case 8:
12555 type = BFD_RELOC_64;
12556 break;
12559 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
12562 #if defined OBJ_COFF || defined OBJ_ELF
12563 void
12564 arm_validate_fix (fixS * fixP)
12566 /* If the destination of the branch is a defined symbol which does not have
12567 the THUMB_FUNC attribute, then we must be calling a function which has
12568 the (interfacearm) attribute. We look for the Thumb entry point to that
12569 function and change the branch to refer to that function instead. */
12570 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
12571 && fixP->fx_addsy != NULL
12572 && S_IS_DEFINED (fixP->fx_addsy)
12573 && ! THUMB_IS_FUNC (fixP->fx_addsy))
12575 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
12578 #endif
12581 arm_force_relocation (struct fix * fixp)
12583 #if defined (OBJ_COFF) && defined (TE_PE)
12584 if (fixp->fx_r_type == BFD_RELOC_RVA)
12585 return 1;
12586 #endif
12588 /* Resolve these relocations even if the symbol is extern or weak. */
12589 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
12590 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
12591 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
12592 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
12593 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
12594 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
12595 return 0;
12597 return generic_force_reloc (fixp);
12600 #ifdef OBJ_COFF
12601 /* This is a little hack to help the gas/arm/adrl.s test. It prevents
12602 local labels from being added to the output symbol table when they
12603 are used with the ADRL pseudo op. The ADRL relocation should always
12604 be resolved before the binbary is emitted, so it is safe to say that
12605 it is adjustable. */
12607 bfd_boolean
12608 arm_fix_adjustable (fixS * fixP)
12610 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
12611 return 1;
12612 return 0;
12614 #endif
12616 #ifdef OBJ_ELF
12617 /* Relocations against Thumb function names must be left unadjusted,
12618 so that the linker can use this information to correctly set the
12619 bottom bit of their addresses. The MIPS version of this function
12620 also prevents relocations that are mips-16 specific, but I do not
12621 know why it does this.
12623 FIXME:
12624 There is one other problem that ought to be addressed here, but
12625 which currently is not: Taking the address of a label (rather
12626 than a function) and then later jumping to that address. Such
12627 addresses also ought to have their bottom bit set (assuming that
12628 they reside in Thumb code), but at the moment they will not. */
12630 bfd_boolean
12631 arm_fix_adjustable (fixS * fixP)
12633 if (fixP->fx_addsy == NULL)
12634 return 1;
12636 if (THUMB_IS_FUNC (fixP->fx_addsy)
12637 && fixP->fx_subsy == NULL)
12638 return 0;
12640 /* We need the symbol name for the VTABLE entries. */
12641 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12642 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12643 return 0;
12645 /* Don't allow symbols to be discarded on GOT related relocs. */
12646 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
12647 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
12648 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
12649 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
12650 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
12651 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
12652 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
12653 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
12654 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
12655 return 0;
12657 return 1;
12660 const char *
12661 elf32_arm_target_format (void)
12663 #ifdef TE_SYMBIAN
12664 return (target_big_endian
12665 ? "elf32-bigarm-symbian"
12666 : "elf32-littlearm-symbian");
12667 #elif defined (TE_VXWORKS)
12668 return (target_big_endian
12669 ? "elf32-bigarm-vxworks"
12670 : "elf32-littlearm-vxworks");
12671 #else
12672 if (target_big_endian)
12673 return "elf32-bigarm";
12674 else
12675 return "elf32-littlearm";
12676 #endif
12679 void
12680 armelf_frob_symbol (symbolS * symp,
12681 int * puntp)
12683 elf_frob_symbol (symp, puntp);
12685 #endif
12687 /* MD interface: Finalization. */
12689 /* A good place to do this, although this was probably not intended
12690 for this kind of use. We need to dump the literal pool before
12691 references are made to a null symbol pointer. */
12693 void
12694 arm_cleanup (void)
12696 literal_pool * pool;
12698 for (pool = list_of_pools; pool; pool = pool->next)
12700 /* Put it at the end of the relevent section. */
12701 subseg_set (pool->section, pool->sub_section);
12702 #ifdef OBJ_ELF
12703 arm_elf_change_section ();
12704 #endif
12705 s_ltorg (0);
12709 /* Adjust the symbol table. This marks Thumb symbols as distinct from
12710 ARM ones. */
12712 void
12713 arm_adjust_symtab (void)
12715 #ifdef OBJ_COFF
12716 symbolS * sym;
12718 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
12720 if (ARM_IS_THUMB (sym))
12722 if (THUMB_IS_FUNC (sym))
12724 /* Mark the symbol as a Thumb function. */
12725 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
12726 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
12727 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
12729 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
12730 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
12731 else
12732 as_bad (_("%s: unexpected function type: %d"),
12733 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
12735 else switch (S_GET_STORAGE_CLASS (sym))
12737 case C_EXT:
12738 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
12739 break;
12740 case C_STAT:
12741 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
12742 break;
12743 case C_LABEL:
12744 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
12745 break;
12746 default:
12747 /* Do nothing. */
12748 break;
12752 if (ARM_IS_INTERWORK (sym))
12753 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
12755 #endif
12756 #ifdef OBJ_ELF
12757 symbolS * sym;
12758 char bind;
12760 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
12762 if (ARM_IS_THUMB (sym))
12764 elf_symbol_type * elf_sym;
12766 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
12767 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
12769 if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name))
12771 /* If it's a .thumb_func, declare it as so,
12772 otherwise tag label as .code 16. */
12773 if (THUMB_IS_FUNC (sym))
12774 elf_sym->internal_elf_sym.st_info =
12775 ELF_ST_INFO (bind, STT_ARM_TFUNC);
12776 else
12777 elf_sym->internal_elf_sym.st_info =
12778 ELF_ST_INFO (bind, STT_ARM_16BIT);
12782 #endif
12785 /* MD interface: Initialization. */
12787 static void
12788 set_constant_flonums (void)
12790 int i;
12792 for (i = 0; i < NUM_FLOAT_VALS; i++)
12793 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
12794 abort ();
12797 void
12798 md_begin (void)
12800 unsigned mach;
12801 unsigned int i;
12803 if ( (arm_ops_hsh = hash_new ()) == NULL
12804 || (arm_cond_hsh = hash_new ()) == NULL
12805 || (arm_shift_hsh = hash_new ()) == NULL
12806 || (arm_psr_hsh = hash_new ()) == NULL
12807 || (arm_v7m_psr_hsh = hash_new ()) == NULL
12808 || (arm_reg_hsh = hash_new ()) == NULL
12809 || (arm_reloc_hsh = hash_new ()) == NULL
12810 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
12811 as_fatal (_("virtual memory exhausted"));
12813 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
12814 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
12815 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
12816 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
12817 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
12818 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
12819 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
12820 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
12821 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
12822 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
12823 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
12824 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
12825 for (i = 0;
12826 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
12827 i++)
12828 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
12829 (PTR) (barrier_opt_names + i));
12830 #ifdef OBJ_ELF
12831 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
12832 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
12833 #endif
12835 set_constant_flonums ();
12837 /* Set the cpu variant based on the command-line options. We prefer
12838 -mcpu= over -march= if both are set (as for GCC); and we prefer
12839 -mfpu= over any other way of setting the floating point unit.
12840 Use of legacy options with new options are faulted. */
12841 if (legacy_cpu)
12843 if (mcpu_cpu_opt || march_cpu_opt)
12844 as_bad (_("use of old and new-style options to set CPU type"));
12846 mcpu_cpu_opt = legacy_cpu;
12848 else if (!mcpu_cpu_opt)
12849 mcpu_cpu_opt = march_cpu_opt;
12851 if (legacy_fpu)
12853 if (mfpu_opt)
12854 as_bad (_("use of old and new-style options to set FPU type"));
12856 mfpu_opt = legacy_fpu;
12858 else if (!mfpu_opt)
12860 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
12861 /* Some environments specify a default FPU. If they don't, infer it
12862 from the processor. */
12863 if (mcpu_fpu_opt)
12864 mfpu_opt = mcpu_fpu_opt;
12865 else
12866 mfpu_opt = march_fpu_opt;
12867 #else
12868 mfpu_opt = &fpu_default;
12869 #endif
12872 if (!mfpu_opt)
12874 if (!mcpu_cpu_opt)
12875 mfpu_opt = &fpu_default;
12876 else if (ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
12877 mfpu_opt = &fpu_arch_vfp_v2;
12878 else
12879 mfpu_opt = &fpu_arch_fpa;
12882 #ifdef CPU_DEFAULT
12883 if (!mcpu_cpu_opt)
12885 mcpu_cpu_opt = &cpu_default;
12886 selected_cpu = cpu_default;
12888 #else
12889 if (mcpu_cpu_opt)
12890 selected_cpu = *mcpu_cpu_opt;
12891 else
12892 mcpu_cpu_opt = &arm_arch_any;
12893 #endif
12895 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
12897 arm_arch_used = thumb_arch_used = arm_arch_none;
12899 #if defined OBJ_COFF || defined OBJ_ELF
12901 unsigned int flags = 0;
12903 #if defined OBJ_ELF
12904 flags = meabi_flags;
12906 switch (meabi_flags)
12908 case EF_ARM_EABI_UNKNOWN:
12909 #endif
12910 /* Set the flags in the private structure. */
12911 if (uses_apcs_26) flags |= F_APCS26;
12912 if (support_interwork) flags |= F_INTERWORK;
12913 if (uses_apcs_float) flags |= F_APCS_FLOAT;
12914 if (pic_code) flags |= F_PIC;
12915 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
12916 flags |= F_SOFT_FLOAT;
12918 switch (mfloat_abi_opt)
12920 case ARM_FLOAT_ABI_SOFT:
12921 case ARM_FLOAT_ABI_SOFTFP:
12922 flags |= F_SOFT_FLOAT;
12923 break;
12925 case ARM_FLOAT_ABI_HARD:
12926 if (flags & F_SOFT_FLOAT)
12927 as_bad (_("hard-float conflicts with specified fpu"));
12928 break;
12931 /* Using pure-endian doubles (even if soft-float). */
12932 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
12933 flags |= F_VFP_FLOAT;
12935 #if defined OBJ_ELF
12936 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
12937 flags |= EF_ARM_MAVERICK_FLOAT;
12938 break;
12940 case EF_ARM_EABI_VER4:
12941 case EF_ARM_EABI_VER5:
12942 /* No additional flags to set. */
12943 break;
12945 default:
12946 abort ();
12948 #endif
12949 bfd_set_private_flags (stdoutput, flags);
12951 /* We have run out flags in the COFF header to encode the
12952 status of ATPCS support, so instead we create a dummy,
12953 empty, debug section called .arm.atpcs. */
12954 if (atpcs)
12956 asection * sec;
12958 sec = bfd_make_section (stdoutput, ".arm.atpcs");
12960 if (sec != NULL)
12962 bfd_set_section_flags
12963 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
12964 bfd_set_section_size (stdoutput, sec, 0);
12965 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
12969 #endif
12971 /* Record the CPU type as well. */
12972 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
12973 mach = bfd_mach_arm_iWMMXt;
12974 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
12975 mach = bfd_mach_arm_XScale;
12976 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
12977 mach = bfd_mach_arm_ep9312;
12978 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
12979 mach = bfd_mach_arm_5TE;
12980 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
12982 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
12983 mach = bfd_mach_arm_5T;
12984 else
12985 mach = bfd_mach_arm_5;
12987 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
12989 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
12990 mach = bfd_mach_arm_4T;
12991 else
12992 mach = bfd_mach_arm_4;
12994 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
12995 mach = bfd_mach_arm_3M;
12996 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
12997 mach = bfd_mach_arm_3;
12998 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
12999 mach = bfd_mach_arm_2a;
13000 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
13001 mach = bfd_mach_arm_2;
13002 else
13003 mach = bfd_mach_arm_unknown;
13005 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
13008 /* Command line processing. */
13010 /* md_parse_option
13011 Invocation line includes a switch not recognized by the base assembler.
13012 See if it's a processor-specific option.
13014 This routine is somewhat complicated by the need for backwards
13015 compatibility (since older releases of gcc can't be changed).
13016 The new options try to make the interface as compatible as
13017 possible with GCC.
13019 New options (supported) are:
13021 -mcpu=<cpu name> Assemble for selected processor
13022 -march=<architecture name> Assemble for selected architecture
13023 -mfpu=<fpu architecture> Assemble for selected FPU.
13024 -EB/-mbig-endian Big-endian
13025 -EL/-mlittle-endian Little-endian
13026 -k Generate PIC code
13027 -mthumb Start in Thumb mode
13028 -mthumb-interwork Code supports ARM/Thumb interworking
13030 For now we will also provide support for:
13032 -mapcs-32 32-bit Program counter
13033 -mapcs-26 26-bit Program counter
13034 -macps-float Floats passed in FP registers
13035 -mapcs-reentrant Reentrant code
13036 -matpcs
13037 (sometime these will probably be replaced with -mapcs=<list of options>
13038 and -matpcs=<list of options>)
13040 The remaining options are only supported for back-wards compatibility.
13041 Cpu variants, the arm part is optional:
13042 -m[arm]1 Currently not supported.
13043 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
13044 -m[arm]3 Arm 3 processor
13045 -m[arm]6[xx], Arm 6 processors
13046 -m[arm]7[xx][t][[d]m] Arm 7 processors
13047 -m[arm]8[10] Arm 8 processors
13048 -m[arm]9[20][tdmi] Arm 9 processors
13049 -mstrongarm[110[0]] StrongARM processors
13050 -mxscale XScale processors
13051 -m[arm]v[2345[t[e]]] Arm architectures
13052 -mall All (except the ARM1)
13053 FP variants:
13054 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
13055 -mfpe-old (No float load/store multiples)
13056 -mvfpxd VFP Single precision
13057 -mvfp All VFP
13058 -mno-fpu Disable all floating point instructions
13060 The following CPU names are recognized:
13061 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
13062 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
13063 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
13064 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
13065 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
13066 arm10t arm10e, arm1020t, arm1020e, arm10200e,
13067 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
13071 const char * md_shortopts = "m:k";
13073 #ifdef ARM_BI_ENDIAN
13074 #define OPTION_EB (OPTION_MD_BASE + 0)
13075 #define OPTION_EL (OPTION_MD_BASE + 1)
13076 #else
13077 #if TARGET_BYTES_BIG_ENDIAN
13078 #define OPTION_EB (OPTION_MD_BASE + 0)
13079 #else
13080 #define OPTION_EL (OPTION_MD_BASE + 1)
13081 #endif
13082 #endif
13084 struct option md_longopts[] =
13086 #ifdef OPTION_EB
13087 {"EB", no_argument, NULL, OPTION_EB},
13088 #endif
13089 #ifdef OPTION_EL
13090 {"EL", no_argument, NULL, OPTION_EL},
13091 #endif
13092 {NULL, no_argument, NULL, 0}
13095 size_t md_longopts_size = sizeof (md_longopts);
13097 struct arm_option_table
13099 char *option; /* Option name to match. */
13100 char *help; /* Help information. */
13101 int *var; /* Variable to change. */
13102 int value; /* What to change it to. */
13103 char *deprecated; /* If non-null, print this message. */
13106 struct arm_option_table arm_opts[] =
13108 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
13109 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
13110 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
13111 &support_interwork, 1, NULL},
13112 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
13113 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
13114 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
13115 1, NULL},
13116 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
13117 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
13118 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
13119 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
13120 NULL},
13122 /* These are recognized by the assembler, but have no affect on code. */
13123 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
13124 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
13125 {NULL, NULL, NULL, 0, NULL}
13128 struct arm_legacy_option_table
13130 char *option; /* Option name to match. */
13131 const arm_feature_set **var; /* Variable to change. */
13132 const arm_feature_set value; /* What to change it to. */
13133 char *deprecated; /* If non-null, print this message. */
13136 const struct arm_legacy_option_table arm_legacy_opts[] =
13138 /* DON'T add any new processors to this list -- we want the whole list
13139 to go away... Add them to the processors table instead. */
13140 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
13141 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
13142 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
13143 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
13144 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
13145 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
13146 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
13147 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
13148 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
13149 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
13150 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
13151 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
13152 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
13153 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
13154 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
13155 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
13156 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
13157 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
13158 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
13159 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
13160 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
13161 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
13162 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
13163 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
13164 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
13165 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
13166 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
13167 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
13168 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
13169 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
13170 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
13171 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
13172 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
13173 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
13174 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
13175 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
13176 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
13177 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
13178 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
13179 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
13180 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
13181 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
13182 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
13183 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
13184 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
13185 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
13186 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13187 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13188 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13189 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13190 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
13191 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
13192 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
13193 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
13194 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
13195 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
13196 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
13197 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
13198 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
13199 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
13200 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
13201 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
13202 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
13203 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
13204 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
13205 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
13206 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
13207 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
13208 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
13209 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
13210 N_("use -mcpu=strongarm110")},
13211 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
13212 N_("use -mcpu=strongarm1100")},
13213 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
13214 N_("use -mcpu=strongarm1110")},
13215 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
13216 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
13217 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
13219 /* Architecture variants -- don't add any more to this list either. */
13220 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
13221 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
13222 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
13223 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
13224 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
13225 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
13226 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
13227 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
13228 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
13229 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
13230 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
13231 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
13232 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
13233 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
13234 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
13235 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
13236 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
13237 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
13239 /* Floating point variants -- don't add any more to this list either. */
13240 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
13241 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
13242 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
13243 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
13244 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
13246 {NULL, NULL, ARM_ARCH_NONE, NULL}
13249 struct arm_cpu_option_table
13251 char *name;
13252 const arm_feature_set value;
13253 /* For some CPUs we assume an FPU unless the user explicitly sets
13254 -mfpu=... */
13255 const arm_feature_set default_fpu;
13256 /* The canonical name of the CPU, or NULL to use NAME converted to upper
13257 case. */
13258 const char *canonical_name;
13261 /* This list should, at a minimum, contain all the cpu names
13262 recognized by GCC. */
13263 static const struct arm_cpu_option_table arm_cpus[] =
13265 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
13266 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
13267 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
13268 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
13269 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
13270 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13271 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13272 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13273 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13274 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13275 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13276 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
13277 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13278 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
13279 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13280 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
13281 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13282 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13283 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13284 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13285 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13286 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13287 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13288 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13289 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13290 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13291 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13292 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13293 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13294 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13295 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13296 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13297 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13298 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13299 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13300 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13301 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13302 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13303 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13304 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
13305 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13306 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13307 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13308 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13309 /* For V5 or later processors we default to using VFP; but the user
13310 should really set the FPU type explicitly. */
13311 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
13312 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13313 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
13314 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
13315 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
13316 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
13317 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
13318 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13319 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
13320 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
13321 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13322 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13323 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
13324 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
13325 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13326 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
13327 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
13328 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13329 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13330 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
13331 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
13332 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
13333 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
13334 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
13335 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
13336 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
13337 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
13338 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
13339 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
13340 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
13341 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
13342 {"cortex-a8", ARM_ARCH_V7A, FPU_ARCH_VFP_V2, NULL},
13343 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
13344 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
13345 /* ??? XSCALE is really an architecture. */
13346 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
13347 /* ??? iwmmxt is not a processor. */
13348 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
13349 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
13350 /* Maverick */
13351 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
13352 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
13355 struct arm_arch_option_table
13357 char *name;
13358 const arm_feature_set value;
13359 const arm_feature_set default_fpu;
13362 /* This list should, at a minimum, contain all the architecture names
13363 recognized by GCC. */
13364 static const struct arm_arch_option_table arm_archs[] =
13366 {"all", ARM_ANY, FPU_ARCH_FPA},
13367 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
13368 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
13369 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
13370 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
13371 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
13372 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
13373 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
13374 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
13375 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
13376 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
13377 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
13378 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
13379 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
13380 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
13381 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
13382 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
13383 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
13384 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
13385 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
13386 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
13387 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
13388 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
13389 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
13390 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
13391 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
13392 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
13393 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
13394 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
13395 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
13396 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
13397 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
13398 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
13401 /* ISA extensions in the co-processor space. */
13402 struct arm_option_cpu_value_table
13404 char *name;
13405 const arm_feature_set value;
13408 static const struct arm_option_cpu_value_table arm_extensions[] =
13410 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
13411 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
13412 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
13413 {NULL, ARM_ARCH_NONE}
13416 /* This list should, at a minimum, contain all the fpu names
13417 recognized by GCC. */
13418 static const struct arm_option_cpu_value_table arm_fpus[] =
13420 {"softfpa", FPU_NONE},
13421 {"fpe", FPU_ARCH_FPE},
13422 {"fpe2", FPU_ARCH_FPE},
13423 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
13424 {"fpa", FPU_ARCH_FPA},
13425 {"fpa10", FPU_ARCH_FPA},
13426 {"fpa11", FPU_ARCH_FPA},
13427 {"arm7500fe", FPU_ARCH_FPA},
13428 {"softvfp", FPU_ARCH_VFP},
13429 {"softvfp+vfp", FPU_ARCH_VFP_V2},
13430 {"vfp", FPU_ARCH_VFP_V2},
13431 {"vfp9", FPU_ARCH_VFP_V2},
13432 {"vfp10", FPU_ARCH_VFP_V2},
13433 {"vfp10-r0", FPU_ARCH_VFP_V1},
13434 {"vfpxd", FPU_ARCH_VFP_V1xD},
13435 {"arm1020t", FPU_ARCH_VFP_V1},
13436 {"arm1020e", FPU_ARCH_VFP_V2},
13437 {"arm1136jfs", FPU_ARCH_VFP_V2},
13438 {"arm1136jf-s", FPU_ARCH_VFP_V2},
13439 {"maverick", FPU_ARCH_MAVERICK},
13440 {NULL, ARM_ARCH_NONE}
13443 struct arm_option_value_table
13445 char *name;
13446 long value;
13449 static const struct arm_option_value_table arm_float_abis[] =
13451 {"hard", ARM_FLOAT_ABI_HARD},
13452 {"softfp", ARM_FLOAT_ABI_SOFTFP},
13453 {"soft", ARM_FLOAT_ABI_SOFT},
13454 {NULL, 0}
13457 #ifdef OBJ_ELF
13458 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
13459 static const struct arm_option_value_table arm_eabis[] =
13461 {"gnu", EF_ARM_EABI_UNKNOWN},
13462 {"4", EF_ARM_EABI_VER4},
13463 {"5", EF_ARM_EABI_VER5},
13464 {NULL, 0}
13466 #endif
13468 struct arm_long_option_table
13470 char * option; /* Substring to match. */
13471 char * help; /* Help information. */
13472 int (* func) (char * subopt); /* Function to decode sub-option. */
13473 char * deprecated; /* If non-null, print this message. */
13476 static int
13477 arm_parse_extension (char * str, const arm_feature_set **opt_p)
13479 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
13481 /* Copy the feature set, so that we can modify it. */
13482 *ext_set = **opt_p;
13483 *opt_p = ext_set;
13485 while (str != NULL && *str != 0)
13487 const struct arm_option_cpu_value_table * opt;
13488 char * ext;
13489 int optlen;
13491 if (*str != '+')
13493 as_bad (_("invalid architectural extension"));
13494 return 0;
13497 str++;
13498 ext = strchr (str, '+');
13500 if (ext != NULL)
13501 optlen = ext - str;
13502 else
13503 optlen = strlen (str);
13505 if (optlen == 0)
13507 as_bad (_("missing architectural extension"));
13508 return 0;
13511 for (opt = arm_extensions; opt->name != NULL; opt++)
13512 if (strncmp (opt->name, str, optlen) == 0)
13514 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
13515 break;
13518 if (opt->name == NULL)
13520 as_bad (_("unknown architectural extnsion `%s'"), str);
13521 return 0;
13524 str = ext;
13527 return 1;
13530 static int
13531 arm_parse_cpu (char * str)
13533 const struct arm_cpu_option_table * opt;
13534 char * ext = strchr (str, '+');
13535 int optlen;
13537 if (ext != NULL)
13538 optlen = ext - str;
13539 else
13540 optlen = strlen (str);
13542 if (optlen == 0)
13544 as_bad (_("missing cpu name `%s'"), str);
13545 return 0;
13548 for (opt = arm_cpus; opt->name != NULL; opt++)
13549 if (strncmp (opt->name, str, optlen) == 0)
13551 mcpu_cpu_opt = &opt->value;
13552 mcpu_fpu_opt = &opt->default_fpu;
13553 if (opt->canonical_name)
13554 strcpy(selected_cpu_name, opt->canonical_name);
13555 else
13557 int i;
13558 for (i = 0; i < optlen; i++)
13559 selected_cpu_name[i] = TOUPPER (opt->name[i]);
13560 selected_cpu_name[i] = 0;
13563 if (ext != NULL)
13564 return arm_parse_extension (ext, &mcpu_cpu_opt);
13566 return 1;
13569 as_bad (_("unknown cpu `%s'"), str);
13570 return 0;
13573 static int
13574 arm_parse_arch (char * str)
13576 const struct arm_arch_option_table *opt;
13577 char *ext = strchr (str, '+');
13578 int optlen;
13580 if (ext != NULL)
13581 optlen = ext - str;
13582 else
13583 optlen = strlen (str);
13585 if (optlen == 0)
13587 as_bad (_("missing architecture name `%s'"), str);
13588 return 0;
13591 for (opt = arm_archs; opt->name != NULL; opt++)
13592 if (streq (opt->name, str))
13594 march_cpu_opt = &opt->value;
13595 march_fpu_opt = &opt->default_fpu;
13596 strcpy(selected_cpu_name, opt->name);
13598 if (ext != NULL)
13599 return arm_parse_extension (ext, &march_cpu_opt);
13601 return 1;
13604 as_bad (_("unknown architecture `%s'\n"), str);
13605 return 0;
13608 static int
13609 arm_parse_fpu (char * str)
13611 const struct arm_option_cpu_value_table * opt;
13613 for (opt = arm_fpus; opt->name != NULL; opt++)
13614 if (streq (opt->name, str))
13616 mfpu_opt = &opt->value;
13617 return 1;
13620 as_bad (_("unknown floating point format `%s'\n"), str);
13621 return 0;
13624 static int
13625 arm_parse_float_abi (char * str)
13627 const struct arm_option_value_table * opt;
13629 for (opt = arm_float_abis; opt->name != NULL; opt++)
13630 if (streq (opt->name, str))
13632 mfloat_abi_opt = opt->value;
13633 return 1;
13636 as_bad (_("unknown floating point abi `%s'\n"), str);
13637 return 0;
13640 #ifdef OBJ_ELF
13641 static int
13642 arm_parse_eabi (char * str)
13644 const struct arm_option_value_table *opt;
13646 for (opt = arm_eabis; opt->name != NULL; opt++)
13647 if (streq (opt->name, str))
13649 meabi_flags = opt->value;
13650 return 1;
13652 as_bad (_("unknown EABI `%s'\n"), str);
13653 return 0;
13655 #endif
13657 struct arm_long_option_table arm_long_opts[] =
13659 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
13660 arm_parse_cpu, NULL},
13661 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
13662 arm_parse_arch, NULL},
13663 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
13664 arm_parse_fpu, NULL},
13665 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
13666 arm_parse_float_abi, NULL},
13667 #ifdef OBJ_ELF
13668 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
13669 arm_parse_eabi, NULL},
13670 #endif
13671 {NULL, NULL, 0, NULL}
13675 md_parse_option (int c, char * arg)
13677 struct arm_option_table *opt;
13678 const struct arm_legacy_option_table *fopt;
13679 struct arm_long_option_table *lopt;
13681 switch (c)
13683 #ifdef OPTION_EB
13684 case OPTION_EB:
13685 target_big_endian = 1;
13686 break;
13687 #endif
13689 #ifdef OPTION_EL
13690 case OPTION_EL:
13691 target_big_endian = 0;
13692 break;
13693 #endif
13695 case 'a':
13696 /* Listing option. Just ignore these, we don't support additional
13697 ones. */
13698 return 0;
13700 default:
13701 for (opt = arm_opts; opt->option != NULL; opt++)
13703 if (c == opt->option[0]
13704 && ((arg == NULL && opt->option[1] == 0)
13705 || streq (arg, opt->option + 1)))
13707 #if WARN_DEPRECATED
13708 /* If the option is deprecated, tell the user. */
13709 if (opt->deprecated != NULL)
13710 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
13711 arg ? arg : "", _(opt->deprecated));
13712 #endif
13714 if (opt->var != NULL)
13715 *opt->var = opt->value;
13717 return 1;
13721 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
13723 if (c == fopt->option[0]
13724 && ((arg == NULL && fopt->option[1] == 0)
13725 || streq (arg, fopt->option + 1)))
13727 #if WARN_DEPRECATED
13728 /* If the option is deprecated, tell the user. */
13729 if (fopt->deprecated != NULL)
13730 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
13731 arg ? arg : "", _(fopt->deprecated));
13732 #endif
13734 if (fopt->var != NULL)
13735 *fopt->var = &fopt->value;
13737 return 1;
13741 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
13743 /* These options are expected to have an argument. */
13744 if (c == lopt->option[0]
13745 && arg != NULL
13746 && strncmp (arg, lopt->option + 1,
13747 strlen (lopt->option + 1)) == 0)
13749 #if WARN_DEPRECATED
13750 /* If the option is deprecated, tell the user. */
13751 if (lopt->deprecated != NULL)
13752 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
13753 _(lopt->deprecated));
13754 #endif
13756 /* Call the sup-option parser. */
13757 return lopt->func (arg + strlen (lopt->option) - 1);
13761 return 0;
13764 return 1;
13767 void
13768 md_show_usage (FILE * fp)
13770 struct arm_option_table *opt;
13771 struct arm_long_option_table *lopt;
13773 fprintf (fp, _(" ARM-specific assembler options:\n"));
13775 for (opt = arm_opts; opt->option != NULL; opt++)
13776 if (opt->help != NULL)
13777 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
13779 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
13780 if (lopt->help != NULL)
13781 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
13783 #ifdef OPTION_EB
13784 fprintf (fp, _("\
13785 -EB assemble code for a big-endian cpu\n"));
13786 #endif
13788 #ifdef OPTION_EL
13789 fprintf (fp, _("\
13790 -EL assemble code for a little-endian cpu\n"));
13791 #endif
13795 #ifdef OBJ_ELF
13796 typedef struct
13798 int val;
13799 arm_feature_set flags;
13800 } cpu_arch_ver_table;
13802 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
13803 least features first. */
13804 static const cpu_arch_ver_table cpu_arch_ver[] =
13806 {1, ARM_ARCH_V4},
13807 {2, ARM_ARCH_V4T},
13808 {3, ARM_ARCH_V5},
13809 {4, ARM_ARCH_V5TE},
13810 {5, ARM_ARCH_V5TEJ},
13811 {6, ARM_ARCH_V6},
13812 {7, ARM_ARCH_V6Z},
13813 {8, ARM_ARCH_V6K},
13814 {9, ARM_ARCH_V6T2},
13815 {10, ARM_ARCH_V7A},
13816 {10, ARM_ARCH_V7R},
13817 {10, ARM_ARCH_V7M},
13818 {0, ARM_ARCH_NONE}
13821 /* Set the public EABI object attributes. */
13822 static void
13823 aeabi_set_public_attributes (void)
13825 int arch;
13826 arm_feature_set flags;
13827 arm_feature_set tmp;
13828 const cpu_arch_ver_table *p;
13830 /* Choose the architecture based on the capabilities of the requested cpu
13831 (if any) and/or the instructions actually used. */
13832 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
13833 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
13834 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
13836 tmp = flags;
13837 arch = 0;
13838 for (p = cpu_arch_ver; p->val; p++)
13840 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
13842 arch = p->val;
13843 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
13847 /* Tag_CPU_name. */
13848 if (selected_cpu_name[0])
13850 char *p;
13852 p = selected_cpu_name;
13853 if (strncmp(p, "armv", 4) == 0)
13855 int i;
13857 p += 4;
13858 for (i = 0; p[i]; i++)
13859 p[i] = TOUPPER (p[i]);
13861 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
13863 /* Tag_CPU_arch. */
13864 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
13865 /* Tag_CPU_arch_profile. */
13866 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
13867 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A');
13868 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
13869 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R');
13870 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
13871 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M');
13872 /* Tag_ARM_ISA_use. */
13873 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
13874 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
13875 /* Tag_THUMB_ISA_use. */
13876 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
13877 elf32_arm_add_eabi_attr_int (stdoutput, 9,
13878 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
13879 /* Tag_VFP_arch. */
13880 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_arch_vfp_v2)
13881 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_arch_vfp_v2))
13882 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
13883 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_arch_vfp_v1)
13884 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_arch_vfp_v1))
13885 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
13886 /* Tag_WMMX_arch. */
13887 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
13888 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
13889 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
13892 /* Add the .ARM.attributes section. */
13893 void
13894 arm_md_end (void)
13896 segT s;
13897 char *p;
13898 addressT addr;
13899 offsetT size;
13901 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
13902 return;
13904 aeabi_set_public_attributes ();
13905 size = elf32_arm_eabi_attr_size (stdoutput);
13906 s = subseg_new (".ARM.attributes", 0);
13907 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
13908 addr = frag_now_fix ();
13909 p = frag_more (size);
13910 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
13914 /* Parse a .cpu directive. */
13916 static void
13917 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
13919 const struct arm_cpu_option_table *opt;
13920 char *name;
13921 char saved_char;
13923 name = input_line_pointer;
13924 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13925 input_line_pointer++;
13926 saved_char = *input_line_pointer;
13927 *input_line_pointer = 0;
13929 /* Skip the first "all" entry. */
13930 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
13931 if (streq (opt->name, name))
13933 mcpu_cpu_opt = &opt->value;
13934 selected_cpu = opt->value;
13935 if (opt->canonical_name)
13936 strcpy(selected_cpu_name, opt->canonical_name);
13937 else
13939 int i;
13940 for (i = 0; opt->name[i]; i++)
13941 selected_cpu_name[i] = TOUPPER (opt->name[i]);
13942 selected_cpu_name[i] = 0;
13944 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
13945 *input_line_pointer = saved_char;
13946 demand_empty_rest_of_line ();
13947 return;
13949 as_bad (_("unknown cpu `%s'"), name);
13950 *input_line_pointer = saved_char;
13951 ignore_rest_of_line ();
13955 /* Parse a .arch directive. */
13957 static void
13958 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
13960 const struct arm_arch_option_table *opt;
13961 char saved_char;
13962 char *name;
13964 name = input_line_pointer;
13965 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13966 input_line_pointer++;
13967 saved_char = *input_line_pointer;
13968 *input_line_pointer = 0;
13970 /* Skip the first "all" entry. */
13971 for (opt = arm_archs + 1; opt->name != NULL; opt++)
13972 if (streq (opt->name, name))
13974 mcpu_cpu_opt = &opt->value;
13975 selected_cpu = opt->value;
13976 strcpy(selected_cpu_name, opt->name);
13977 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
13978 *input_line_pointer = saved_char;
13979 demand_empty_rest_of_line ();
13980 return;
13983 as_bad (_("unknown architecture `%s'\n"), name);
13984 *input_line_pointer = saved_char;
13985 ignore_rest_of_line ();
13989 /* Parse a .fpu directive. */
13991 static void
13992 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
13994 const struct arm_option_cpu_value_table *opt;
13995 char saved_char;
13996 char *name;
13998 name = input_line_pointer;
13999 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
14000 input_line_pointer++;
14001 saved_char = *input_line_pointer;
14002 *input_line_pointer = 0;
14004 for (opt = arm_fpus; opt->name != NULL; opt++)
14005 if (streq (opt->name, name))
14007 mfpu_opt = &opt->value;
14008 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
14009 *input_line_pointer = saved_char;
14010 demand_empty_rest_of_line ();
14011 return;
14014 as_bad (_("unknown floating point format `%s'\n"), name);
14015 *input_line_pointer = saved_char;
14016 ignore_rest_of_line ();
14018 #endif /* OBJ_ELF */