2005-10-28 Paul Brook <paul@codesourcery.com>
[binutils.git] / gas / config / tc-arm.c
blob9df9e0eb9ae01734fe0b521bd3d67dd9a8c1452a
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 #define ARM_1 ARM_ARCH_V1
102 #define ARM_2 ARM_ARCH_V2
103 #define ARM_3 ARM_ARCH_V2S
104 #define ARM_250 ARM_ARCH_V2S
105 #define ARM_6 ARM_ARCH_V3
106 #define ARM_7 ARM_ARCH_V3
107 #define ARM_8 ARM_ARCH_V4
108 #define ARM_9 ARM_ARCH_V4T
109 #define ARM_STRONG ARM_ARCH_V4
110 #define ARM_CPU_MASK 0x0000000f /* XXX? */
112 #ifndef CPU_DEFAULT
113 #if defined __XSCALE__
114 #define CPU_DEFAULT (ARM_ARCH_XSCALE)
115 #else
116 #if defined __thumb__
117 #define CPU_DEFAULT (ARM_ARCH_V5T)
118 #endif
119 #endif
120 #endif
122 #ifndef FPU_DEFAULT
123 # ifdef TE_LINUX
124 # define FPU_DEFAULT FPU_ARCH_FPA
125 # elif defined (TE_NetBSD)
126 # ifdef OBJ_ELF
127 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
128 # else
129 /* Legacy a.out format. */
130 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
131 # endif
132 # elif defined (TE_VXWORKS)
133 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
134 # else
135 /* For backwards compatibility, default to FPA. */
136 # define FPU_DEFAULT FPU_ARCH_FPA
137 # endif
138 #endif /* ifndef FPU_DEFAULT */
140 #define streq(a, b) (strcmp (a, b) == 0)
142 static unsigned long cpu_variant;
143 static unsigned long arm_arch_used;
144 static unsigned long thumb_arch_used;
146 /* Flags stored in private area of BFD structure. */
147 static int uses_apcs_26 = FALSE;
148 static int atpcs = FALSE;
149 static int support_interwork = FALSE;
150 static int uses_apcs_float = FALSE;
151 static int pic_code = FALSE;
153 /* Variables that we set while parsing command-line options. Once all
154 options have been read we re-process these values to set the real
155 assembly flags. */
156 static int legacy_cpu = -1;
157 static int legacy_fpu = -1;
159 static int mcpu_cpu_opt = -1;
160 static int mcpu_fpu_opt = -1;
161 static int march_cpu_opt = -1;
162 static int march_fpu_opt = -1;
163 static int mfpu_opt = -1;
164 static int mfloat_abi_opt = -1;
165 /* Record user cpu selection for object attributes.
166 Zero if no default or user specified CPU. */
167 static int selected_cpu = -1;
168 /* Must be long enough to hold any of the names in arm_cpus. */
169 static char selected_cpu_name[16];
170 #ifdef OBJ_ELF
171 # ifdef EABI_DEFAULT
172 static int meabi_flags = EABI_DEFAULT;
173 # else
174 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
175 # endif
176 #endif
178 #ifdef OBJ_ELF
179 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
180 symbolS * GOT_symbol;
181 #endif
183 /* 0: assemble for ARM,
184 1: assemble for Thumb,
185 2: assemble for Thumb even though target CPU does not support thumb
186 instructions. */
187 static int thumb_mode = 0;
189 /* If unified_syntax is true, we are processing the new unified
190 ARM/Thumb syntax. Important differences from the old ARM mode:
192 - Immediate operands do not require a # prefix.
193 - Conditional affixes always appear at the end of the
194 instruction. (For backward compatibility, those instructions
195 that formerly had them in the middle, continue to accept them
196 there.)
197 - The IT instruction may appear, and if it does is validated
198 against subsequent conditional affixes. It does not generate
199 machine code.
201 Important differences from the old Thumb mode:
203 - Immediate operands do not require a # prefix.
204 - Most of the V6T2 instructions are only available in unified mode.
205 - The .N and .W suffixes are recognized and honored (it is an error
206 if they cannot be honored).
207 - All instructions set the flags if and only if they have an 's' affix.
208 - Conditional affixes may be used. They are validated against
209 preceding IT instructions. Unlike ARM mode, you cannot use a
210 conditional affix except in the scope of an IT instruction. */
212 static bfd_boolean unified_syntax = FALSE;
214 struct arm_it
216 const char * error;
217 unsigned long instruction;
218 int size;
219 int size_req;
220 int cond;
221 /* Set to the opcode if the instruction needs relaxation.
222 Zero if the instruction is not relaxed. */
223 unsigned long relax;
224 struct
226 bfd_reloc_code_real_type type;
227 expressionS exp;
228 int pc_rel;
229 } reloc;
231 struct
233 unsigned reg;
234 signed int imm;
235 unsigned present : 1; /* Operand present. */
236 unsigned isreg : 1; /* Operand was a register. */
237 unsigned immisreg : 1; /* .imm field is a second register. */
238 unsigned hasreloc : 1; /* Operand has relocation suffix. */
239 unsigned writeback : 1; /* Operand has trailing ! */
240 unsigned preind : 1; /* Preindexed address. */
241 unsigned postind : 1; /* Postindexed address. */
242 unsigned negative : 1; /* Index register was negated. */
243 unsigned shifted : 1; /* Shift applied to operation. */
244 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
245 } operands[6];
248 static struct arm_it inst;
250 #define NUM_FLOAT_VALS 8
252 const char * fp_const[] =
254 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
257 /* Number of littlenums required to hold an extended precision number. */
258 #define MAX_LITTLENUMS 6
260 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
262 #define FAIL (-1)
263 #define SUCCESS (0)
265 #define SUFF_S 1
266 #define SUFF_D 2
267 #define SUFF_E 3
268 #define SUFF_P 4
270 #define CP_T_X 0x00008000
271 #define CP_T_Y 0x00400000
273 #define CONDS_BIT 0x00100000
274 #define LOAD_BIT 0x00100000
276 #define DOUBLE_LOAD_FLAG 0x00000001
278 struct asm_cond
280 const char * template;
281 unsigned long value;
284 #define COND_ALWAYS 0xE
286 struct asm_psr
288 const char *template;
289 unsigned long field;
292 /* The bit that distinguishes CPSR and SPSR. */
293 #define SPSR_BIT (1 << 22)
295 /* The individual PSR flag bits. */
296 #define PSR_c (1 << 16)
297 #define PSR_x (1 << 17)
298 #define PSR_s (1 << 18)
299 #define PSR_f (1 << 19)
301 struct reloc_entry
303 char *name;
304 bfd_reloc_code_real_type reloc;
307 enum vfp_sp_reg_pos
309 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn
312 enum vfp_ldstm_type
314 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
317 /* ARM register categories. This includes coprocessor numbers and various
318 architecture extensions' registers. */
319 enum arm_reg_type
321 REG_TYPE_RN,
322 REG_TYPE_CP,
323 REG_TYPE_CN,
324 REG_TYPE_FN,
325 REG_TYPE_VFS,
326 REG_TYPE_VFD,
327 REG_TYPE_VFC,
328 REG_TYPE_MVF,
329 REG_TYPE_MVD,
330 REG_TYPE_MVFX,
331 REG_TYPE_MVDX,
332 REG_TYPE_MVAX,
333 REG_TYPE_DSPSC,
334 REG_TYPE_MMXWR,
335 REG_TYPE_MMXWC,
336 REG_TYPE_MMXWCG,
337 REG_TYPE_XSCALE,
340 /* Structure for a hash table entry for a register. */
341 struct reg_entry
343 const char *name;
344 unsigned char number;
345 unsigned char type;
346 unsigned char builtin;
349 /* Diagnostics used when we don't get a register of the expected type. */
350 const char *const reg_expected_msgs[] =
352 N_("ARM register expected"),
353 N_("bad or missing co-processor number"),
354 N_("co-processor register expected"),
355 N_("FPA register expected"),
356 N_("VFP single precision register expected"),
357 N_("VFP double precision register expected"),
358 N_("VFP system register expected"),
359 N_("Maverick MVF register expected"),
360 N_("Maverick MVD register expected"),
361 N_("Maverick MVFX register expected"),
362 N_("Maverick MVDX register expected"),
363 N_("Maverick MVAX register expected"),
364 N_("Maverick DSPSC register expected"),
365 N_("iWMMXt data register expected"),
366 N_("iWMMXt control register expected"),
367 N_("iWMMXt scalar register expected"),
368 N_("XScale accumulator register expected"),
371 /* Some well known registers that we refer to directly elsewhere. */
372 #define REG_SP 13
373 #define REG_LR 14
374 #define REG_PC 15
376 /* ARM instructions take 4bytes in the object file, Thumb instructions
377 take 2: */
378 #define INSN_SIZE 4
380 struct asm_opcode
382 /* Basic string to match. */
383 const char *template;
385 /* Parameters to instruction. */
386 unsigned char operands[8];
388 /* Conditional tag - see opcode_lookup. */
389 unsigned int tag : 4;
391 /* Basic instruction code. */
392 unsigned int avalue : 28;
394 /* Thumb-format instruction code. */
395 unsigned int tvalue;
397 /* Which architecture variant provides this instruction. */
398 unsigned long avariant;
399 unsigned long tvariant;
401 /* Function to call to encode instruction in ARM format. */
402 void (* aencode) (void);
404 /* Function to call to encode instruction in Thumb format. */
405 void (* tencode) (void);
408 /* Defines for various bits that we will want to toggle. */
409 #define INST_IMMEDIATE 0x02000000
410 #define OFFSET_REG 0x02000000
411 #define HWOFFSET_IMM 0x00400000
412 #define SHIFT_BY_REG 0x00000010
413 #define PRE_INDEX 0x01000000
414 #define INDEX_UP 0x00800000
415 #define WRITE_BACK 0x00200000
416 #define LDM_TYPE_2_OR_3 0x00400000
418 #define LITERAL_MASK 0xf000f000
419 #define OPCODE_MASK 0xfe1fffff
420 #define V4_STR_BIT 0x00000020
422 #define DATA_OP_SHIFT 21
424 /* Codes to distinguish the arithmetic instructions. */
425 #define OPCODE_AND 0
426 #define OPCODE_EOR 1
427 #define OPCODE_SUB 2
428 #define OPCODE_RSB 3
429 #define OPCODE_ADD 4
430 #define OPCODE_ADC 5
431 #define OPCODE_SBC 6
432 #define OPCODE_RSC 7
433 #define OPCODE_TST 8
434 #define OPCODE_TEQ 9
435 #define OPCODE_CMP 10
436 #define OPCODE_CMN 11
437 #define OPCODE_ORR 12
438 #define OPCODE_MOV 13
439 #define OPCODE_BIC 14
440 #define OPCODE_MVN 15
442 #define T_OPCODE_MUL 0x4340
443 #define T_OPCODE_TST 0x4200
444 #define T_OPCODE_CMN 0x42c0
445 #define T_OPCODE_NEG 0x4240
446 #define T_OPCODE_MVN 0x43c0
448 #define T_OPCODE_ADD_R3 0x1800
449 #define T_OPCODE_SUB_R3 0x1a00
450 #define T_OPCODE_ADD_HI 0x4400
451 #define T_OPCODE_ADD_ST 0xb000
452 #define T_OPCODE_SUB_ST 0xb080
453 #define T_OPCODE_ADD_SP 0xa800
454 #define T_OPCODE_ADD_PC 0xa000
455 #define T_OPCODE_ADD_I8 0x3000
456 #define T_OPCODE_SUB_I8 0x3800
457 #define T_OPCODE_ADD_I3 0x1c00
458 #define T_OPCODE_SUB_I3 0x1e00
460 #define T_OPCODE_ASR_R 0x4100
461 #define T_OPCODE_LSL_R 0x4080
462 #define T_OPCODE_LSR_R 0x40c0
463 #define T_OPCODE_ROR_R 0x41c0
464 #define T_OPCODE_ASR_I 0x1000
465 #define T_OPCODE_LSL_I 0x0000
466 #define T_OPCODE_LSR_I 0x0800
468 #define T_OPCODE_MOV_I8 0x2000
469 #define T_OPCODE_CMP_I8 0x2800
470 #define T_OPCODE_CMP_LR 0x4280
471 #define T_OPCODE_MOV_HR 0x4600
472 #define T_OPCODE_CMP_HR 0x4500
474 #define T_OPCODE_LDR_PC 0x4800
475 #define T_OPCODE_LDR_SP 0x9800
476 #define T_OPCODE_STR_SP 0x9000
477 #define T_OPCODE_LDR_IW 0x6800
478 #define T_OPCODE_STR_IW 0x6000
479 #define T_OPCODE_LDR_IH 0x8800
480 #define T_OPCODE_STR_IH 0x8000
481 #define T_OPCODE_LDR_IB 0x7800
482 #define T_OPCODE_STR_IB 0x7000
483 #define T_OPCODE_LDR_RW 0x5800
484 #define T_OPCODE_STR_RW 0x5000
485 #define T_OPCODE_LDR_RH 0x5a00
486 #define T_OPCODE_STR_RH 0x5200
487 #define T_OPCODE_LDR_RB 0x5c00
488 #define T_OPCODE_STR_RB 0x5400
490 #define T_OPCODE_PUSH 0xb400
491 #define T_OPCODE_POP 0xbc00
493 #define T_OPCODE_BRANCH 0xe000
495 #define THUMB_SIZE 2 /* Size of thumb instruction. */
496 #define THUMB_PP_PC_LR 0x0100
497 #define THUMB_LOAD_BIT 0x0800
499 #define BAD_ARGS _("bad arguments to instruction")
500 #define BAD_PC _("r15 not allowed here")
501 #define BAD_COND _("instruction cannot be conditional")
502 #define BAD_OVERLAP _("registers may not be the same")
503 #define BAD_HIREG _("lo register required")
504 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
506 static struct hash_control *arm_ops_hsh;
507 static struct hash_control *arm_cond_hsh;
508 static struct hash_control *arm_shift_hsh;
509 static struct hash_control *arm_psr_hsh;
510 static struct hash_control *arm_reg_hsh;
511 static struct hash_control *arm_reloc_hsh;
513 /* Stuff needed to resolve the label ambiguity
516 label: <insn>
517 may differ from:
519 label:
520 <insn>
523 symbolS * last_label_seen;
524 static int label_is_thumb_function_name = FALSE;
526 /* Literal pool structure. Held on a per-section
527 and per-sub-section basis. */
529 #define MAX_LITERAL_POOL_SIZE 1024
530 typedef struct literal_pool
532 expressionS literals [MAX_LITERAL_POOL_SIZE];
533 unsigned int next_free_entry;
534 unsigned int id;
535 symbolS * symbol;
536 segT section;
537 subsegT sub_section;
538 struct literal_pool * next;
539 } literal_pool;
541 /* Pointer to a linked list of literal pools. */
542 literal_pool * list_of_pools = NULL;
544 /* State variables for IT block handling. */
545 static bfd_boolean current_it_mask = 0;
546 static int current_cc;
549 /* Pure syntax. */
551 /* This array holds the chars that always start a comment. If the
552 pre-processor is disabled, these aren't very useful. */
553 const char comment_chars[] = "@";
555 /* This array holds the chars that only start a comment at the beginning of
556 a line. If the line seems to have the form '# 123 filename'
557 .line and .file directives will appear in the pre-processed output. */
558 /* Note that input_file.c hand checks for '#' at the beginning of the
559 first line of the input file. This is because the compiler outputs
560 #NO_APP at the beginning of its output. */
561 /* Also note that comments like this one will always work. */
562 const char line_comment_chars[] = "#";
564 const char line_separator_chars[] = ";";
566 /* Chars that can be used to separate mant
567 from exp in floating point numbers. */
568 const char EXP_CHARS[] = "eE";
570 /* Chars that mean this number is a floating point constant. */
571 /* As in 0f12.456 */
572 /* or 0d1.2345e12 */
574 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
576 /* Prefix characters that indicate the start of an immediate
577 value. */
578 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
580 /* Separator character handling. */
582 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
584 static inline int
585 skip_past_char (char ** str, char c)
587 if (**str == c)
589 (*str)++;
590 return SUCCESS;
592 else
593 return FAIL;
595 #define skip_past_comma(str) skip_past_char (str, ',')
597 /* Arithmetic expressions (possibly involving symbols). */
599 /* Return TRUE if anything in the expression is a bignum. */
601 static int
602 walk_no_bignums (symbolS * sp)
604 if (symbol_get_value_expression (sp)->X_op == O_big)
605 return 1;
607 if (symbol_get_value_expression (sp)->X_add_symbol)
609 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
610 || (symbol_get_value_expression (sp)->X_op_symbol
611 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
614 return 0;
617 static int in_my_get_expression = 0;
619 /* Third argument to my_get_expression. */
620 #define GE_NO_PREFIX 0
621 #define GE_IMM_PREFIX 1
622 #define GE_OPT_PREFIX 2
624 static int
625 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
627 char * save_in;
628 segT seg;
630 /* In unified syntax, all prefixes are optional. */
631 if (unified_syntax)
632 prefix_mode = GE_OPT_PREFIX;
634 switch (prefix_mode)
636 case GE_NO_PREFIX: break;
637 case GE_IMM_PREFIX:
638 if (!is_immediate_prefix (**str))
640 inst.error = _("immediate expression requires a # prefix");
641 return FAIL;
643 (*str)++;
644 break;
645 case GE_OPT_PREFIX:
646 if (is_immediate_prefix (**str))
647 (*str)++;
648 break;
649 default: abort ();
652 memset (ep, 0, sizeof (expressionS));
654 save_in = input_line_pointer;
655 input_line_pointer = *str;
656 in_my_get_expression = 1;
657 seg = expression (ep);
658 in_my_get_expression = 0;
660 if (ep->X_op == O_illegal)
662 /* We found a bad expression in md_operand(). */
663 *str = input_line_pointer;
664 input_line_pointer = save_in;
665 if (inst.error == NULL)
666 inst.error = _("bad expression");
667 return 1;
670 #ifdef OBJ_AOUT
671 if (seg != absolute_section
672 && seg != text_section
673 && seg != data_section
674 && seg != bss_section
675 && seg != undefined_section)
677 inst.error = _("bad segment");
678 *str = input_line_pointer;
679 input_line_pointer = save_in;
680 return 1;
682 #endif
684 /* Get rid of any bignums now, so that we don't generate an error for which
685 we can't establish a line number later on. Big numbers are never valid
686 in instructions, which is where this routine is always called. */
687 if (ep->X_op == O_big
688 || (ep->X_add_symbol
689 && (walk_no_bignums (ep->X_add_symbol)
690 || (ep->X_op_symbol
691 && walk_no_bignums (ep->X_op_symbol)))))
693 inst.error = _("invalid constant");
694 *str = input_line_pointer;
695 input_line_pointer = save_in;
696 return 1;
699 *str = input_line_pointer;
700 input_line_pointer = save_in;
701 return 0;
704 /* Turn a string in input_line_pointer into a floating point constant
705 of type TYPE, and store the appropriate bytes in *LITP. The number
706 of LITTLENUMS emitted is stored in *SIZEP. An error message is
707 returned, or NULL on OK.
709 Note that fp constants aren't represent in the normal way on the ARM.
710 In big endian mode, things are as expected. However, in little endian
711 mode fp constants are big-endian word-wise, and little-endian byte-wise
712 within the words. For example, (double) 1.1 in big endian mode is
713 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
714 the byte sequence 99 99 f1 3f 9a 99 99 99.
716 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
718 char *
719 md_atof (int type, char * litP, int * sizeP)
721 int prec;
722 LITTLENUM_TYPE words[MAX_LITTLENUMS];
723 char *t;
724 int i;
726 switch (type)
728 case 'f':
729 case 'F':
730 case 's':
731 case 'S':
732 prec = 2;
733 break;
735 case 'd':
736 case 'D':
737 case 'r':
738 case 'R':
739 prec = 4;
740 break;
742 case 'x':
743 case 'X':
744 prec = 6;
745 break;
747 case 'p':
748 case 'P':
749 prec = 6;
750 break;
752 default:
753 *sizeP = 0;
754 return _("bad call to MD_ATOF()");
757 t = atof_ieee (input_line_pointer, type, words);
758 if (t)
759 input_line_pointer = t;
760 *sizeP = prec * 2;
762 if (target_big_endian)
764 for (i = 0; i < prec; i++)
766 md_number_to_chars (litP, (valueT) words[i], 2);
767 litP += 2;
770 else
772 if (cpu_variant & FPU_ARCH_VFP)
773 for (i = prec - 1; i >= 0; i--)
775 md_number_to_chars (litP, (valueT) words[i], 2);
776 litP += 2;
778 else
779 /* For a 4 byte float the order of elements in `words' is 1 0.
780 For an 8 byte float the order is 1 0 3 2. */
781 for (i = 0; i < prec; i += 2)
783 md_number_to_chars (litP, (valueT) words[i + 1], 2);
784 md_number_to_chars (litP + 2, (valueT) words[i], 2);
785 litP += 4;
789 return 0;
792 /* We handle all bad expressions here, so that we can report the faulty
793 instruction in the error message. */
794 void
795 md_operand (expressionS * expr)
797 if (in_my_get_expression)
798 expr->X_op = O_illegal;
801 /* Immediate values. */
803 /* Generic immediate-value read function for use in directives.
804 Accepts anything that 'expression' can fold to a constant.
805 *val receives the number. */
806 #ifdef OBJ_ELF
807 static int
808 immediate_for_directive (int *val)
810 expressionS exp;
811 exp.X_op = O_illegal;
813 if (is_immediate_prefix (*input_line_pointer))
815 input_line_pointer++;
816 expression (&exp);
819 if (exp.X_op != O_constant)
821 as_bad (_("expected #constant"));
822 ignore_rest_of_line ();
823 return FAIL;
825 *val = exp.X_add_number;
826 return SUCCESS;
828 #endif
830 /* Register parsing. */
832 /* Generic register parser. CCP points to what should be the
833 beginning of a register name. If it is indeed a valid register
834 name, advance CCP over it and return the reg_entry structure;
835 otherwise return NULL. Does not issue diagnostics. */
837 static struct reg_entry *
838 arm_reg_parse_multi (char **ccp)
840 char *start = *ccp;
841 char *p;
842 struct reg_entry *reg;
844 #ifdef REGISTER_PREFIX
845 if (*start != REGISTER_PREFIX)
846 return FAIL;
847 start++;
848 #endif
849 #ifdef OPTIONAL_REGISTER_PREFIX
850 if (*start == OPTIONAL_REGISTER_PREFIX)
851 start++;
852 #endif
854 p = start;
855 if (!ISALPHA (*p) || !is_name_beginner (*p))
856 return NULL;
859 p++;
860 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
862 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
864 if (!reg)
865 return NULL;
867 *ccp = p;
868 return reg;
871 /* As above, but the register must be of type TYPE, and the return
872 value is the register number or NULL. */
874 static int
875 arm_reg_parse (char **ccp, enum arm_reg_type type)
877 char *start = *ccp;
878 struct reg_entry *reg = arm_reg_parse_multi (ccp);
880 if (reg && reg->type == type)
881 return reg->number;
883 /* Alternative syntaxes are accepted for a few register classes. */
884 switch (type)
886 case REG_TYPE_MVF:
887 case REG_TYPE_MVD:
888 case REG_TYPE_MVFX:
889 case REG_TYPE_MVDX:
890 /* Generic coprocessor register names are allowed for these. */
891 if (reg->type == REG_TYPE_CN)
892 return reg->number;
893 break;
895 case REG_TYPE_CP:
896 /* For backward compatibility, a bare number is valid here. */
898 unsigned long processor = strtoul (start, ccp, 10);
899 if (*ccp != start && processor <= 15)
900 return processor;
903 case REG_TYPE_MMXWC:
904 /* WC includes WCG. ??? I'm not sure this is true for all
905 instructions that take WC registers. */
906 if (reg->type == REG_TYPE_MMXWCG)
907 return reg->number;
908 break;
910 default:
911 break;
914 *ccp = start;
915 return FAIL;
918 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
919 static long
920 parse_reg_list (char ** strp)
922 char * str = * strp;
923 long range = 0;
924 int another_range;
926 /* We come back here if we get ranges concatenated by '+' or '|'. */
929 another_range = 0;
931 if (*str == '{')
933 int in_range = 0;
934 int cur_reg = -1;
936 str++;
939 int reg;
941 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
943 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
944 return FAIL;
947 if (in_range)
949 int i;
951 if (reg <= cur_reg)
953 inst.error = _("bad range in register list");
954 return FAIL;
957 for (i = cur_reg + 1; i < reg; i++)
959 if (range & (1 << i))
960 as_tsktsk
961 (_("Warning: duplicated register (r%d) in register list"),
963 else
964 range |= 1 << i;
966 in_range = 0;
969 if (range & (1 << reg))
970 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
971 reg);
972 else if (reg <= cur_reg)
973 as_tsktsk (_("Warning: register range not in ascending order"));
975 range |= 1 << reg;
976 cur_reg = reg;
978 while (skip_past_comma (&str) != FAIL
979 || (in_range = 1, *str++ == '-'));
980 str--;
982 if (*str++ != '}')
984 inst.error = _("missing `}'");
985 return FAIL;
988 else
990 expressionS expr;
992 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
993 return FAIL;
995 if (expr.X_op == O_constant)
997 if (expr.X_add_number
998 != (expr.X_add_number & 0x0000ffff))
1000 inst.error = _("invalid register mask");
1001 return FAIL;
1004 if ((range & expr.X_add_number) != 0)
1006 int regno = range & expr.X_add_number;
1008 regno &= -regno;
1009 regno = (1 << regno) - 1;
1010 as_tsktsk
1011 (_("Warning: duplicated register (r%d) in register list"),
1012 regno);
1015 range |= expr.X_add_number;
1017 else
1019 if (inst.reloc.type != 0)
1021 inst.error = _("expression too complex");
1022 return FAIL;
1025 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1026 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1027 inst.reloc.pc_rel = 0;
1031 if (*str == '|' || *str == '+')
1033 str++;
1034 another_range = 1;
1037 while (another_range);
1039 *strp = str;
1040 return range;
1043 /* Parse a VFP register list. If the string is invalid return FAIL.
1044 Otherwise return the number of registers, and set PBASE to the first
1045 register. Double precision registers are matched if DP is nonzero. */
1047 static int
1048 parse_vfp_reg_list (char **str, unsigned int *pbase, int dp)
1050 int base_reg;
1051 int new_base;
1052 int regtype;
1053 int max_regs;
1054 int count = 0;
1055 int warned = 0;
1056 unsigned long mask = 0;
1057 int i;
1059 if (**str != '{')
1060 return FAIL;
1062 (*str)++;
1064 if (dp)
1066 regtype = REG_TYPE_VFD;
1067 max_regs = 16;
1069 else
1071 regtype = REG_TYPE_VFS;
1072 max_regs = 32;
1075 base_reg = max_regs;
1079 new_base = arm_reg_parse (str, regtype);
1080 if (new_base == FAIL)
1082 inst.error = gettext (reg_expected_msgs[regtype]);
1083 return FAIL;
1086 if (new_base < base_reg)
1087 base_reg = new_base;
1089 if (mask & (1 << new_base))
1091 inst.error = _("invalid register list");
1092 return FAIL;
1095 if ((mask >> new_base) != 0 && ! warned)
1097 as_tsktsk (_("register list not in ascending order"));
1098 warned = 1;
1101 mask |= 1 << new_base;
1102 count++;
1104 if (**str == '-') /* We have the start of a range expression */
1106 int high_range;
1108 (*str)++;
1110 if ((high_range = arm_reg_parse (str, regtype)) == FAIL)
1112 inst.error = gettext (reg_expected_msgs[regtype]);
1113 return FAIL;
1116 if (high_range <= new_base)
1118 inst.error = _("register range not in ascending order");
1119 return FAIL;
1122 for (new_base++; new_base <= high_range; new_base++)
1124 if (mask & (1 << new_base))
1126 inst.error = _("invalid register list");
1127 return FAIL;
1130 mask |= 1 << new_base;
1131 count++;
1135 while (skip_past_comma (str) != FAIL);
1137 (*str)++;
1139 /* Sanity check -- should have raised a parse error above. */
1140 if (count == 0 || count > max_regs)
1141 abort ();
1143 *pbase = base_reg;
1145 /* Final test -- the registers must be consecutive. */
1146 mask >>= base_reg;
1147 for (i = 0; i < count; i++)
1149 if ((mask & (1u << i)) == 0)
1151 inst.error = _("non-contiguous register range");
1152 return FAIL;
1156 return count;
1159 /* Parse an explicit relocation suffix on an expression. This is
1160 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1161 arm_reloc_hsh contains no entries, so this function can only
1162 succeed if there is no () after the word. Returns -1 on error,
1163 BFD_RELOC_UNUSED if there wasn't any suffix. */
1164 static int
1165 parse_reloc (char **str)
1167 struct reloc_entry *r;
1168 char *p, *q;
1170 if (**str != '(')
1171 return BFD_RELOC_UNUSED;
1173 p = *str + 1;
1174 q = p;
1176 while (*q && *q != ')' && *q != ',')
1177 q++;
1178 if (*q != ')')
1179 return -1;
1181 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1182 return -1;
1184 *str = q + 1;
1185 return r->reloc;
1188 /* Directives: register aliases. */
1190 static void
1191 insert_reg_alias (char *str, int number, int type)
1193 struct reg_entry *new;
1194 const char *name;
1196 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1198 if (new->builtin)
1199 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1201 /* Only warn about a redefinition if it's not defined as the
1202 same register. */
1203 else if (new->number != number || new->type != type)
1204 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1206 return;
1209 name = xstrdup (str);
1210 new = xmalloc (sizeof (struct reg_entry));
1212 new->name = name;
1213 new->number = number;
1214 new->type = type;
1215 new->builtin = FALSE;
1217 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1218 abort ();
1221 /* Look for the .req directive. This is of the form:
1223 new_register_name .req existing_register_name
1225 If we find one, or if it looks sufficiently like one that we want to
1226 handle any error here, return non-zero. Otherwise return zero. */
1228 static int
1229 create_register_alias (char * newname, char *p)
1231 struct reg_entry *old;
1232 char *oldname, *nbuf;
1233 size_t nlen;
1235 /* The input scrubber ensures that whitespace after the mnemonic is
1236 collapsed to single spaces. */
1237 oldname = p;
1238 if (strncmp (oldname, " .req ", 6) != 0)
1239 return 0;
1241 oldname += 6;
1242 if (*oldname == '\0')
1243 return 0;
1245 old = hash_find (arm_reg_hsh, oldname);
1246 if (!old)
1248 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
1249 return 1;
1252 /* If TC_CASE_SENSITIVE is defined, then newname already points to
1253 the desired alias name, and p points to its end. If not, then
1254 the desired alias name is in the global original_case_string. */
1255 #ifdef TC_CASE_SENSITIVE
1256 nlen = p - newname;
1257 #else
1258 newname = original_case_string;
1259 nlen = strlen (newname);
1260 #endif
1262 nbuf = alloca (nlen + 1);
1263 memcpy (nbuf, newname, nlen);
1264 nbuf[nlen] = '\0';
1266 /* Create aliases under the new name as stated; an all-lowercase
1267 version of the new name; and an all-uppercase version of the new
1268 name. */
1269 insert_reg_alias (nbuf, old->number, old->type);
1271 for (p = nbuf; *p; p++)
1272 *p = TOUPPER (*p);
1274 if (strncmp (nbuf, newname, nlen))
1275 insert_reg_alias (nbuf, old->number, old->type);
1277 for (p = nbuf; *p; p++)
1278 *p = TOLOWER (*p);
1280 if (strncmp (nbuf, newname, nlen))
1281 insert_reg_alias (nbuf, old->number, old->type);
1283 return 1;
1286 /* Should never be called, as .req goes between the alias and the
1287 register name, not at the beginning of the line. */
1288 static void
1289 s_req (int a ATTRIBUTE_UNUSED)
1291 as_bad (_("invalid syntax for .req directive"));
1294 /* The .unreq directive deletes an alias which was previously defined
1295 by .req. For example:
1297 my_alias .req r11
1298 .unreq my_alias */
1300 static void
1301 s_unreq (int a ATTRIBUTE_UNUSED)
1303 char * name;
1304 char saved_char;
1306 name = input_line_pointer;
1308 while (*input_line_pointer != 0
1309 && *input_line_pointer != ' '
1310 && *input_line_pointer != '\n')
1311 ++input_line_pointer;
1313 saved_char = *input_line_pointer;
1314 *input_line_pointer = 0;
1316 if (!*name)
1317 as_bad (_("invalid syntax for .unreq directive"));
1318 else
1320 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
1322 if (!reg)
1323 as_bad (_("unknown register alias '%s'"), name);
1324 else if (reg->builtin)
1325 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
1326 name);
1327 else
1329 hash_delete (arm_reg_hsh, name);
1330 free ((char *) reg->name);
1331 free (reg);
1335 *input_line_pointer = saved_char;
1336 demand_empty_rest_of_line ();
1339 /* Directives: Instruction set selection. */
1341 #ifdef OBJ_ELF
1342 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
1343 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
1344 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
1345 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
1347 static enum mstate mapstate = MAP_UNDEFINED;
1349 static void
1350 mapping_state (enum mstate state)
1352 symbolS * symbolP;
1353 const char * symname;
1354 int type;
1356 if (mapstate == state)
1357 /* The mapping symbol has already been emitted.
1358 There is nothing else to do. */
1359 return;
1361 mapstate = state;
1363 switch (state)
1365 case MAP_DATA:
1366 symname = "$d";
1367 type = BSF_NO_FLAGS;
1368 break;
1369 case MAP_ARM:
1370 symname = "$a";
1371 type = BSF_NO_FLAGS;
1372 break;
1373 case MAP_THUMB:
1374 symname = "$t";
1375 type = BSF_NO_FLAGS;
1376 break;
1377 case MAP_UNDEFINED:
1378 return;
1379 default:
1380 abort ();
1383 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
1385 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
1386 symbol_table_insert (symbolP);
1387 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
1389 switch (state)
1391 case MAP_ARM:
1392 THUMB_SET_FUNC (symbolP, 0);
1393 ARM_SET_THUMB (symbolP, 0);
1394 ARM_SET_INTERWORK (symbolP, support_interwork);
1395 break;
1397 case MAP_THUMB:
1398 THUMB_SET_FUNC (symbolP, 1);
1399 ARM_SET_THUMB (symbolP, 1);
1400 ARM_SET_INTERWORK (symbolP, support_interwork);
1401 break;
1403 case MAP_DATA:
1404 default:
1405 return;
1408 #else
1409 #define mapping_state(x) /* nothing */
1410 #endif
1412 /* Find the real, Thumb encoded start of a Thumb function. */
1414 static symbolS *
1415 find_real_start (symbolS * symbolP)
1417 char * real_start;
1418 const char * name = S_GET_NAME (symbolP);
1419 symbolS * new_target;
1421 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
1422 #define STUB_NAME ".real_start_of"
1424 if (name == NULL)
1425 abort ();
1427 /* The compiler may generate BL instructions to local labels because
1428 it needs to perform a branch to a far away location. These labels
1429 do not have a corresponding ".real_start_of" label. We check
1430 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
1431 the ".real_start_of" convention for nonlocal branches. */
1432 if (S_IS_LOCAL (symbolP) || name[0] == '.')
1433 return symbolP;
1435 real_start = ACONCAT ((STUB_NAME, name, NULL));
1436 new_target = symbol_find (real_start);
1438 if (new_target == NULL)
1440 as_warn ("Failed to find real start of function: %s\n", name);
1441 new_target = symbolP;
1444 return new_target;
1447 static void
1448 opcode_select (int width)
1450 switch (width)
1452 case 16:
1453 if (! thumb_mode)
1455 if (! (cpu_variant & ARM_EXT_V4T))
1456 as_bad (_("selected processor does not support THUMB opcodes"));
1458 thumb_mode = 1;
1459 /* No need to force the alignment, since we will have been
1460 coming from ARM mode, which is word-aligned. */
1461 record_alignment (now_seg, 1);
1463 mapping_state (MAP_THUMB);
1464 break;
1466 case 32:
1467 if (thumb_mode)
1469 if ((cpu_variant & ARM_ALL) == ARM_EXT_V4T)
1470 as_bad (_("selected processor does not support ARM opcodes"));
1472 thumb_mode = 0;
1474 if (!need_pass_2)
1475 frag_align (2, 0, 0);
1477 record_alignment (now_seg, 1);
1479 mapping_state (MAP_ARM);
1480 break;
1482 default:
1483 as_bad (_("invalid instruction size selected (%d)"), width);
1487 static void
1488 s_arm (int ignore ATTRIBUTE_UNUSED)
1490 opcode_select (32);
1491 demand_empty_rest_of_line ();
1494 static void
1495 s_thumb (int ignore ATTRIBUTE_UNUSED)
1497 opcode_select (16);
1498 demand_empty_rest_of_line ();
1501 static void
1502 s_code (int unused ATTRIBUTE_UNUSED)
1504 int temp;
1506 temp = get_absolute_expression ();
1507 switch (temp)
1509 case 16:
1510 case 32:
1511 opcode_select (temp);
1512 break;
1514 default:
1515 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
1519 static void
1520 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
1522 /* If we are not already in thumb mode go into it, EVEN if
1523 the target processor does not support thumb instructions.
1524 This is used by gcc/config/arm/lib1funcs.asm for example
1525 to compile interworking support functions even if the
1526 target processor should not support interworking. */
1527 if (! thumb_mode)
1529 thumb_mode = 2;
1530 record_alignment (now_seg, 1);
1533 demand_empty_rest_of_line ();
1536 static void
1537 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
1539 s_thumb (0);
1541 /* The following label is the name/address of the start of a Thumb function.
1542 We need to know this for the interworking support. */
1543 label_is_thumb_function_name = TRUE;
1546 /* Perform a .set directive, but also mark the alias as
1547 being a thumb function. */
1549 static void
1550 s_thumb_set (int equiv)
1552 /* XXX the following is a duplicate of the code for s_set() in read.c
1553 We cannot just call that code as we need to get at the symbol that
1554 is created. */
1555 char * name;
1556 char delim;
1557 char * end_name;
1558 symbolS * symbolP;
1560 /* Especial apologies for the random logic:
1561 This just grew, and could be parsed much more simply!
1562 Dean - in haste. */
1563 name = input_line_pointer;
1564 delim = get_symbol_end ();
1565 end_name = input_line_pointer;
1566 *end_name = delim;
1568 if (*input_line_pointer != ',')
1570 *end_name = 0;
1571 as_bad (_("expected comma after name \"%s\""), name);
1572 *end_name = delim;
1573 ignore_rest_of_line ();
1574 return;
1577 input_line_pointer++;
1578 *end_name = 0;
1580 if (name[0] == '.' && name[1] == '\0')
1582 /* XXX - this should not happen to .thumb_set. */
1583 abort ();
1586 if ((symbolP = symbol_find (name)) == NULL
1587 && (symbolP = md_undefined_symbol (name)) == NULL)
1589 #ifndef NO_LISTING
1590 /* When doing symbol listings, play games with dummy fragments living
1591 outside the normal fragment chain to record the file and line info
1592 for this symbol. */
1593 if (listing & LISTING_SYMBOLS)
1595 extern struct list_info_struct * listing_tail;
1596 fragS * dummy_frag = xmalloc (sizeof (fragS));
1598 memset (dummy_frag, 0, sizeof (fragS));
1599 dummy_frag->fr_type = rs_fill;
1600 dummy_frag->line = listing_tail;
1601 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
1602 dummy_frag->fr_symbol = symbolP;
1604 else
1605 #endif
1606 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1608 #ifdef OBJ_COFF
1609 /* "set" symbols are local unless otherwise specified. */
1610 SF_SET_LOCAL (symbolP);
1611 #endif /* OBJ_COFF */
1612 } /* Make a new symbol. */
1614 symbol_table_insert (symbolP);
1616 * end_name = delim;
1618 if (equiv
1619 && S_IS_DEFINED (symbolP)
1620 && S_GET_SEGMENT (symbolP) != reg_section)
1621 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
1623 pseudo_set (symbolP);
1625 demand_empty_rest_of_line ();
1627 /* XXX Now we come to the Thumb specific bit of code. */
1629 THUMB_SET_FUNC (symbolP, 1);
1630 ARM_SET_THUMB (symbolP, 1);
1631 #if defined OBJ_ELF || defined OBJ_COFF
1632 ARM_SET_INTERWORK (symbolP, support_interwork);
1633 #endif
1636 /* Directives: Mode selection. */
1638 /* .syntax [unified|divided] - choose the new unified syntax
1639 (same for Arm and Thumb encoding, modulo slight differences in what
1640 can be represented) or the old divergent syntax for each mode. */
1641 static void
1642 s_syntax (int unused ATTRIBUTE_UNUSED)
1644 char *name, delim;
1646 name = input_line_pointer;
1647 delim = get_symbol_end ();
1649 if (!strcasecmp (name, "unified"))
1650 unified_syntax = TRUE;
1651 else if (!strcasecmp (name, "divided"))
1652 unified_syntax = FALSE;
1653 else
1655 as_bad (_("unrecognized syntax mode \"%s\""), name);
1656 return;
1658 *input_line_pointer = delim;
1659 demand_empty_rest_of_line ();
1662 /* Directives: sectioning and alignment. */
1664 /* Same as s_align_ptwo but align 0 => align 2. */
1666 static void
1667 s_align (int unused ATTRIBUTE_UNUSED)
1669 int temp;
1670 long temp_fill;
1671 long max_alignment = 15;
1673 temp = get_absolute_expression ();
1674 if (temp > max_alignment)
1675 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
1676 else if (temp < 0)
1678 as_bad (_("alignment negative. 0 assumed."));
1679 temp = 0;
1682 if (*input_line_pointer == ',')
1684 input_line_pointer++;
1685 temp_fill = get_absolute_expression ();
1687 else
1688 temp_fill = 0;
1690 if (!temp)
1691 temp = 2;
1693 /* Only make a frag if we HAVE to. */
1694 if (temp && !need_pass_2)
1695 frag_align (temp, (int) temp_fill, 0);
1696 demand_empty_rest_of_line ();
1698 record_alignment (now_seg, temp);
1701 static void
1702 s_bss (int ignore ATTRIBUTE_UNUSED)
1704 /* We don't support putting frags in the BSS segment, we fake it by
1705 marking in_bss, then looking at s_skip for clues. */
1706 subseg_set (bss_section, 0);
1707 demand_empty_rest_of_line ();
1708 mapping_state (MAP_DATA);
1711 static void
1712 s_even (int ignore ATTRIBUTE_UNUSED)
1714 /* Never make frag if expect extra pass. */
1715 if (!need_pass_2)
1716 frag_align (1, 0, 0);
1718 record_alignment (now_seg, 1);
1720 demand_empty_rest_of_line ();
1723 /* Directives: Literal pools. */
1725 static literal_pool *
1726 find_literal_pool (void)
1728 literal_pool * pool;
1730 for (pool = list_of_pools; pool != NULL; pool = pool->next)
1732 if (pool->section == now_seg
1733 && pool->sub_section == now_subseg)
1734 break;
1737 return pool;
1740 static literal_pool *
1741 find_or_make_literal_pool (void)
1743 /* Next literal pool ID number. */
1744 static unsigned int latest_pool_num = 1;
1745 literal_pool * pool;
1747 pool = find_literal_pool ();
1749 if (pool == NULL)
1751 /* Create a new pool. */
1752 pool = xmalloc (sizeof (* pool));
1753 if (! pool)
1754 return NULL;
1756 pool->next_free_entry = 0;
1757 pool->section = now_seg;
1758 pool->sub_section = now_subseg;
1759 pool->next = list_of_pools;
1760 pool->symbol = NULL;
1762 /* Add it to the list. */
1763 list_of_pools = pool;
1766 /* New pools, and emptied pools, will have a NULL symbol. */
1767 if (pool->symbol == NULL)
1769 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
1770 (valueT) 0, &zero_address_frag);
1771 pool->id = latest_pool_num ++;
1774 /* Done. */
1775 return pool;
1778 /* Add the literal in the global 'inst'
1779 structure to the relevent literal pool. */
1781 static int
1782 add_to_lit_pool (void)
1784 literal_pool * pool;
1785 unsigned int entry;
1787 pool = find_or_make_literal_pool ();
1789 /* Check if this literal value is already in the pool. */
1790 for (entry = 0; entry < pool->next_free_entry; entry ++)
1792 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1793 && (inst.reloc.exp.X_op == O_constant)
1794 && (pool->literals[entry].X_add_number
1795 == inst.reloc.exp.X_add_number)
1796 && (pool->literals[entry].X_unsigned
1797 == inst.reloc.exp.X_unsigned))
1798 break;
1800 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1801 && (inst.reloc.exp.X_op == O_symbol)
1802 && (pool->literals[entry].X_add_number
1803 == inst.reloc.exp.X_add_number)
1804 && (pool->literals[entry].X_add_symbol
1805 == inst.reloc.exp.X_add_symbol)
1806 && (pool->literals[entry].X_op_symbol
1807 == inst.reloc.exp.X_op_symbol))
1808 break;
1811 /* Do we need to create a new entry? */
1812 if (entry == pool->next_free_entry)
1814 if (entry >= MAX_LITERAL_POOL_SIZE)
1816 inst.error = _("literal pool overflow");
1817 return FAIL;
1820 pool->literals[entry] = inst.reloc.exp;
1821 pool->next_free_entry += 1;
1824 inst.reloc.exp.X_op = O_symbol;
1825 inst.reloc.exp.X_add_number = ((int) entry) * 4;
1826 inst.reloc.exp.X_add_symbol = pool->symbol;
1828 return SUCCESS;
1831 /* Can't use symbol_new here, so have to create a symbol and then at
1832 a later date assign it a value. Thats what these functions do. */
1834 static void
1835 symbol_locate (symbolS * symbolP,
1836 const char * name, /* It is copied, the caller can modify. */
1837 segT segment, /* Segment identifier (SEG_<something>). */
1838 valueT valu, /* Symbol value. */
1839 fragS * frag) /* Associated fragment. */
1841 unsigned int name_length;
1842 char * preserved_copy_of_name;
1844 name_length = strlen (name) + 1; /* +1 for \0. */
1845 obstack_grow (&notes, name, name_length);
1846 preserved_copy_of_name = obstack_finish (&notes);
1848 #ifdef tc_canonicalize_symbol_name
1849 preserved_copy_of_name =
1850 tc_canonicalize_symbol_name (preserved_copy_of_name);
1851 #endif
1853 S_SET_NAME (symbolP, preserved_copy_of_name);
1855 S_SET_SEGMENT (symbolP, segment);
1856 S_SET_VALUE (symbolP, valu);
1857 symbol_clear_list_pointers (symbolP);
1859 symbol_set_frag (symbolP, frag);
1861 /* Link to end of symbol chain. */
1863 extern int symbol_table_frozen;
1865 if (symbol_table_frozen)
1866 abort ();
1869 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
1871 obj_symbol_new_hook (symbolP);
1873 #ifdef tc_symbol_new_hook
1874 tc_symbol_new_hook (symbolP);
1875 #endif
1877 #ifdef DEBUG_SYMS
1878 verify_symbol_chain (symbol_rootP, symbol_lastP);
1879 #endif /* DEBUG_SYMS */
1883 static void
1884 s_ltorg (int ignored ATTRIBUTE_UNUSED)
1886 unsigned int entry;
1887 literal_pool * pool;
1888 char sym_name[20];
1890 pool = find_literal_pool ();
1891 if (pool == NULL
1892 || pool->symbol == NULL
1893 || pool->next_free_entry == 0)
1894 return;
1896 mapping_state (MAP_DATA);
1898 /* Align pool as you have word accesses.
1899 Only make a frag if we have to. */
1900 if (!need_pass_2)
1901 frag_align (2, 0, 0);
1903 record_alignment (now_seg, 2);
1905 sprintf (sym_name, "$$lit_\002%x", pool->id);
1907 symbol_locate (pool->symbol, sym_name, now_seg,
1908 (valueT) frag_now_fix (), frag_now);
1909 symbol_table_insert (pool->symbol);
1911 ARM_SET_THUMB (pool->symbol, thumb_mode);
1913 #if defined OBJ_COFF || defined OBJ_ELF
1914 ARM_SET_INTERWORK (pool->symbol, support_interwork);
1915 #endif
1917 for (entry = 0; entry < pool->next_free_entry; entry ++)
1918 /* First output the expression in the instruction to the pool. */
1919 emit_expr (&(pool->literals[entry]), 4); /* .word */
1921 /* Mark the pool as empty. */
1922 pool->next_free_entry = 0;
1923 pool->symbol = NULL;
1926 #ifdef OBJ_ELF
1927 /* Forward declarations for functions below, in the MD interface
1928 section. */
1929 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
1930 static valueT create_unwind_entry (int);
1931 static void start_unwind_section (const segT, int);
1932 static void add_unwind_opcode (valueT, int);
1933 static void flush_pending_unwind (void);
1935 /* Directives: Data. */
1937 static void
1938 s_arm_elf_cons (int nbytes)
1940 expressionS exp;
1942 #ifdef md_flush_pending_output
1943 md_flush_pending_output ();
1944 #endif
1946 if (is_it_end_of_statement ())
1948 demand_empty_rest_of_line ();
1949 return;
1952 #ifdef md_cons_align
1953 md_cons_align (nbytes);
1954 #endif
1956 mapping_state (MAP_DATA);
1959 int reloc;
1960 char *base = input_line_pointer;
1962 expression (& exp);
1964 if (exp.X_op != O_symbol)
1965 emit_expr (&exp, (unsigned int) nbytes);
1966 else
1968 char *before_reloc = input_line_pointer;
1969 reloc = parse_reloc (&input_line_pointer);
1970 if (reloc == -1)
1972 as_bad (_("unrecognized relocation suffix"));
1973 ignore_rest_of_line ();
1974 return;
1976 else if (reloc == BFD_RELOC_UNUSED)
1977 emit_expr (&exp, (unsigned int) nbytes);
1978 else
1980 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
1981 int size = bfd_get_reloc_size (howto);
1983 if (reloc == BFD_RELOC_ARM_PLT32)
1985 as_bad (_("(plt) is only valid on branch targets"));
1986 reloc = BFD_RELOC_UNUSED;
1987 size = 0;
1990 if (size > nbytes)
1991 as_bad (_("%s relocations do not fit in %d bytes"),
1992 howto->name, nbytes);
1993 else
1995 /* We've parsed an expression stopping at O_symbol.
1996 But there may be more expression left now that we
1997 have parsed the relocation marker. Parse it again.
1998 XXX Surely there is a cleaner way to do this. */
1999 char *p = input_line_pointer;
2000 int offset;
2001 char *save_buf = alloca (input_line_pointer - base);
2002 memcpy (save_buf, base, input_line_pointer - base);
2003 memmove (base + (input_line_pointer - before_reloc),
2004 base, before_reloc - base);
2006 input_line_pointer = base + (input_line_pointer-before_reloc);
2007 expression (&exp);
2008 memcpy (base, save_buf, p - base);
2010 offset = nbytes - size;
2011 p = frag_more ((int) nbytes);
2012 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2013 size, &exp, 0, reloc);
2018 while (*input_line_pointer++ == ',');
2020 /* Put terminator back into stream. */
2021 input_line_pointer --;
2022 demand_empty_rest_of_line ();
2026 /* Parse a .rel31 directive. */
2028 static void
2029 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2031 expressionS exp;
2032 char *p;
2033 valueT highbit;
2035 highbit = 0;
2036 if (*input_line_pointer == '1')
2037 highbit = 0x80000000;
2038 else if (*input_line_pointer != '0')
2039 as_bad (_("expected 0 or 1"));
2041 input_line_pointer++;
2042 if (*input_line_pointer != ',')
2043 as_bad (_("missing comma"));
2044 input_line_pointer++;
2046 #ifdef md_flush_pending_output
2047 md_flush_pending_output ();
2048 #endif
2050 #ifdef md_cons_align
2051 md_cons_align (4);
2052 #endif
2054 mapping_state (MAP_DATA);
2056 expression (&exp);
2058 p = frag_more (4);
2059 md_number_to_chars (p, highbit, 4);
2060 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2061 BFD_RELOC_ARM_PREL31);
2063 demand_empty_rest_of_line ();
2066 /* Directives: AEABI stack-unwind tables. */
2068 /* Parse an unwind_fnstart directive. Simply records the current location. */
2070 static void
2071 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
2073 demand_empty_rest_of_line ();
2074 /* Mark the start of the function. */
2075 unwind.proc_start = expr_build_dot ();
2077 /* Reset the rest of the unwind info. */
2078 unwind.opcode_count = 0;
2079 unwind.table_entry = NULL;
2080 unwind.personality_routine = NULL;
2081 unwind.personality_index = -1;
2082 unwind.frame_size = 0;
2083 unwind.fp_offset = 0;
2084 unwind.fp_reg = 13;
2085 unwind.fp_used = 0;
2086 unwind.sp_restored = 0;
2090 /* Parse a handlerdata directive. Creates the exception handling table entry
2091 for the function. */
2093 static void
2094 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
2096 demand_empty_rest_of_line ();
2097 if (unwind.table_entry)
2098 as_bad (_("dupicate .handlerdata directive"));
2100 create_unwind_entry (1);
2103 /* Parse an unwind_fnend directive. Generates the index table entry. */
2105 static void
2106 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
2108 long where;
2109 char *ptr;
2110 valueT val;
2112 demand_empty_rest_of_line ();
2114 /* Add eh table entry. */
2115 if (unwind.table_entry == NULL)
2116 val = create_unwind_entry (0);
2117 else
2118 val = 0;
2120 /* Add index table entry. This is two words. */
2121 start_unwind_section (unwind.saved_seg, 1);
2122 frag_align (2, 0, 0);
2123 record_alignment (now_seg, 2);
2125 ptr = frag_more (8);
2126 where = frag_now_fix () - 8;
2128 /* Self relative offset of the function start. */
2129 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
2130 BFD_RELOC_ARM_PREL31);
2132 /* Indicate dependency on EHABI-defined personality routines to the
2133 linker, if it hasn't been done already. */
2134 if (unwind.personality_index >= 0 && unwind.personality_index < 3
2135 && !(marked_pr_dependency & (1 << unwind.personality_index)))
2137 static const char *const name[] = {
2138 "__aeabi_unwind_cpp_pr0",
2139 "__aeabi_unwind_cpp_pr1",
2140 "__aeabi_unwind_cpp_pr2"
2142 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
2143 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
2144 marked_pr_dependency |= 1 << unwind.personality_index;
2145 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
2146 = marked_pr_dependency;
2149 if (val)
2150 /* Inline exception table entry. */
2151 md_number_to_chars (ptr + 4, val, 4);
2152 else
2153 /* Self relative offset of the table entry. */
2154 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
2155 BFD_RELOC_ARM_PREL31);
2157 /* Restore the original section. */
2158 subseg_set (unwind.saved_seg, unwind.saved_subseg);
2162 /* Parse an unwind_cantunwind directive. */
2164 static void
2165 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
2167 demand_empty_rest_of_line ();
2168 if (unwind.personality_routine || unwind.personality_index != -1)
2169 as_bad (_("personality routine specified for cantunwind frame"));
2171 unwind.personality_index = -2;
2175 /* Parse a personalityindex directive. */
2177 static void
2178 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
2180 expressionS exp;
2182 if (unwind.personality_routine || unwind.personality_index != -1)
2183 as_bad (_("duplicate .personalityindex directive"));
2185 expression (&exp);
2187 if (exp.X_op != O_constant
2188 || exp.X_add_number < 0 || exp.X_add_number > 15)
2190 as_bad (_("bad personality routine number"));
2191 ignore_rest_of_line ();
2192 return;
2195 unwind.personality_index = exp.X_add_number;
2197 demand_empty_rest_of_line ();
2201 /* Parse a personality directive. */
2203 static void
2204 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
2206 char *name, *p, c;
2208 if (unwind.personality_routine || unwind.personality_index != -1)
2209 as_bad (_("duplicate .personality directive"));
2211 name = input_line_pointer;
2212 c = get_symbol_end ();
2213 p = input_line_pointer;
2214 unwind.personality_routine = symbol_find_or_make (name);
2215 *p = c;
2216 demand_empty_rest_of_line ();
2220 /* Parse a directive saving core registers. */
2222 static void
2223 s_arm_unwind_save_core (void)
2225 valueT op;
2226 long range;
2227 int n;
2229 range = parse_reg_list (&input_line_pointer);
2230 if (range == FAIL)
2232 as_bad (_("expected register list"));
2233 ignore_rest_of_line ();
2234 return;
2237 demand_empty_rest_of_line ();
2239 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
2240 into .unwind_save {..., sp...}. We aren't bothered about the value of
2241 ip because it is clobbered by calls. */
2242 if (unwind.sp_restored && unwind.fp_reg == 12
2243 && (range & 0x3000) == 0x1000)
2245 unwind.opcode_count--;
2246 unwind.sp_restored = 0;
2247 range = (range | 0x2000) & ~0x1000;
2248 unwind.pending_offset = 0;
2251 /* See if we can use the short opcodes. These pop a block of upto 8
2252 registers starting with r4, plus maybe r14. */
2253 for (n = 0; n < 8; n++)
2255 /* Break at the first non-saved register. */
2256 if ((range & (1 << (n + 4))) == 0)
2257 break;
2259 /* See if there are any other bits set. */
2260 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
2262 /* Use the long form. */
2263 op = 0x8000 | ((range >> 4) & 0xfff);
2264 add_unwind_opcode (op, 2);
2266 else
2268 /* Use the short form. */
2269 if (range & 0x4000)
2270 op = 0xa8; /* Pop r14. */
2271 else
2272 op = 0xa0; /* Do not pop r14. */
2273 op |= (n - 1);
2274 add_unwind_opcode (op, 1);
2277 /* Pop r0-r3. */
2278 if (range & 0xf)
2280 op = 0xb100 | (range & 0xf);
2281 add_unwind_opcode (op, 2);
2284 /* Record the number of bytes pushed. */
2285 for (n = 0; n < 16; n++)
2287 if (range & (1 << n))
2288 unwind.frame_size += 4;
2293 /* Parse a directive saving FPA registers. */
2295 static void
2296 s_arm_unwind_save_fpa (int reg)
2298 expressionS exp;
2299 int num_regs;
2300 valueT op;
2302 /* Get Number of registers to transfer. */
2303 if (skip_past_comma (&input_line_pointer) != FAIL)
2304 expression (&exp);
2305 else
2306 exp.X_op = O_illegal;
2308 if (exp.X_op != O_constant)
2310 as_bad (_("expected , <constant>"));
2311 ignore_rest_of_line ();
2312 return;
2315 num_regs = exp.X_add_number;
2317 if (num_regs < 1 || num_regs > 4)
2319 as_bad (_("number of registers must be in the range [1:4]"));
2320 ignore_rest_of_line ();
2321 return;
2324 demand_empty_rest_of_line ();
2326 if (reg == 4)
2328 /* Short form. */
2329 op = 0xb4 | (num_regs - 1);
2330 add_unwind_opcode (op, 1);
2332 else
2334 /* Long form. */
2335 op = 0xc800 | (reg << 4) | (num_regs - 1);
2336 add_unwind_opcode (op, 2);
2338 unwind.frame_size += num_regs * 12;
2342 /* Parse a directive saving VFP registers. */
2344 static void
2345 s_arm_unwind_save_vfp (void)
2347 int count;
2348 unsigned int reg;
2349 valueT op;
2351 count = parse_vfp_reg_list (&input_line_pointer, &reg, 1);
2352 if (count == FAIL)
2354 as_bad (_("expected register list"));
2355 ignore_rest_of_line ();
2356 return;
2359 demand_empty_rest_of_line ();
2361 if (reg == 8)
2363 /* Short form. */
2364 op = 0xb8 | (count - 1);
2365 add_unwind_opcode (op, 1);
2367 else
2369 /* Long form. */
2370 op = 0xb300 | (reg << 4) | (count - 1);
2371 add_unwind_opcode (op, 2);
2373 unwind.frame_size += count * 8 + 4;
2377 /* Parse a directive saving iWMMXt data registers. */
2379 static void
2380 s_arm_unwind_save_mmxwr (void)
2382 int reg;
2383 int hi_reg;
2384 int i;
2385 unsigned mask = 0;
2386 valueT op;
2388 if (*input_line_pointer == '{')
2389 input_line_pointer++;
2393 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2395 if (reg == FAIL)
2397 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2398 goto error;
2401 if (mask >> reg)
2402 as_tsktsk (_("register list not in ascending order"));
2403 mask |= 1 << reg;
2405 if (*input_line_pointer == '-')
2407 input_line_pointer++;
2408 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2409 if (hi_reg == FAIL)
2411 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2412 goto error;
2414 else if (reg >= hi_reg)
2416 as_bad (_("bad register range"));
2417 goto error;
2419 for (; reg < hi_reg; reg++)
2420 mask |= 1 << reg;
2423 while (skip_past_comma (&input_line_pointer) != FAIL);
2425 if (*input_line_pointer == '}')
2426 input_line_pointer++;
2428 demand_empty_rest_of_line ();
2430 /* Generate any deferred opcodes becuuse we're going to be looking at
2431 the list. */
2432 flush_pending_unwind ();
2434 for (i = 0; i < 16; i++)
2436 if (mask & (1 << i))
2437 unwind.frame_size += 8;
2440 /* Attempt to combine with a previous opcode. We do this because gcc
2441 likes to output separate unwind directives for a single block of
2442 registers. */
2443 if (unwind.opcode_count > 0)
2445 i = unwind.opcodes[unwind.opcode_count - 1];
2446 if ((i & 0xf8) == 0xc0)
2448 i &= 7;
2449 /* Only merge if the blocks are contiguous. */
2450 if (i < 6)
2452 if ((mask & 0xfe00) == (1 << 9))
2454 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
2455 unwind.opcode_count--;
2458 else if (i == 6 && unwind.opcode_count >= 2)
2460 i = unwind.opcodes[unwind.opcode_count - 2];
2461 reg = i >> 4;
2462 i &= 0xf;
2464 op = 0xffff << (reg - 1);
2465 if (reg > 0
2466 || ((mask & op) == (1u << (reg - 1))))
2468 op = (1 << (reg + i + 1)) - 1;
2469 op &= ~((1 << reg) - 1);
2470 mask |= op;
2471 unwind.opcode_count -= 2;
2477 hi_reg = 15;
2478 /* We want to generate opcodes in the order the registers have been
2479 saved, ie. descending order. */
2480 for (reg = 15; reg >= -1; reg--)
2482 /* Save registers in blocks. */
2483 if (reg < 0
2484 || !(mask & (1 << reg)))
2486 /* We found an unsaved reg. Generate opcodes to save the
2487 preceeding block. */
2488 if (reg != hi_reg)
2490 if (reg == 9)
2492 /* Short form. */
2493 op = 0xc0 | (hi_reg - 10);
2494 add_unwind_opcode (op, 1);
2496 else
2498 /* Long form. */
2499 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
2500 add_unwind_opcode (op, 2);
2503 hi_reg = reg - 1;
2507 return;
2508 error:
2509 ignore_rest_of_line ();
2512 static void
2513 s_arm_unwind_save_mmxwcg (void)
2515 int reg;
2516 int hi_reg;
2517 unsigned mask = 0;
2518 valueT op;
2520 if (*input_line_pointer == '{')
2521 input_line_pointer++;
2525 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2527 if (reg == FAIL)
2529 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2530 goto error;
2533 reg -= 8;
2534 if (mask >> reg)
2535 as_tsktsk (_("register list not in ascending order"));
2536 mask |= 1 << reg;
2538 if (*input_line_pointer == '-')
2540 input_line_pointer++;
2541 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2542 if (hi_reg == FAIL)
2544 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2545 goto error;
2547 else if (reg >= hi_reg)
2549 as_bad (_("bad register range"));
2550 goto error;
2552 for (; reg < hi_reg; reg++)
2553 mask |= 1 << reg;
2556 while (skip_past_comma (&input_line_pointer) != FAIL);
2558 if (*input_line_pointer == '}')
2559 input_line_pointer++;
2561 demand_empty_rest_of_line ();
2563 /* Generate any deferred opcodes becuuse we're going to be looking at
2564 the list. */
2565 flush_pending_unwind ();
2567 for (reg = 0; reg < 16; reg++)
2569 if (mask & (1 << reg))
2570 unwind.frame_size += 4;
2572 op = 0xc700 | mask;
2573 add_unwind_opcode (op, 2);
2574 return;
2575 error:
2576 ignore_rest_of_line ();
2580 /* Parse an unwind_save directive. */
2582 static void
2583 s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED)
2585 char *peek;
2586 struct reg_entry *reg;
2587 bfd_boolean had_brace = FALSE;
2589 /* Figure out what sort of save we have. */
2590 peek = input_line_pointer;
2592 if (*peek == '{')
2594 had_brace = TRUE;
2595 peek++;
2598 reg = arm_reg_parse_multi (&peek);
2600 if (!reg)
2602 as_bad (_("register expected"));
2603 ignore_rest_of_line ();
2604 return;
2607 switch (reg->type)
2609 case REG_TYPE_FN:
2610 if (had_brace)
2612 as_bad (_("FPA .unwind_save does not take a register list"));
2613 ignore_rest_of_line ();
2614 return;
2616 s_arm_unwind_save_fpa (reg->number);
2617 return;
2619 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
2620 case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return;
2621 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
2622 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
2624 default:
2625 as_bad (_(".unwind_save does not support this kind of register"));
2626 ignore_rest_of_line ();
2631 /* Parse an unwind_movsp directive. */
2633 static void
2634 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
2636 int reg;
2637 valueT op;
2639 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2640 if (reg == FAIL)
2642 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
2643 ignore_rest_of_line ();
2644 return;
2646 demand_empty_rest_of_line ();
2648 if (reg == REG_SP || reg == REG_PC)
2650 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
2651 return;
2654 if (unwind.fp_reg != REG_SP)
2655 as_bad (_("unexpected .unwind_movsp directive"));
2657 /* Generate opcode to restore the value. */
2658 op = 0x90 | reg;
2659 add_unwind_opcode (op, 1);
2661 /* Record the information for later. */
2662 unwind.fp_reg = reg;
2663 unwind.fp_offset = unwind.frame_size;
2664 unwind.sp_restored = 1;
2667 /* Parse an unwind_pad directive. */
2669 static void
2670 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
2672 int offset;
2674 if (immediate_for_directive (&offset) == FAIL)
2675 return;
2677 if (offset & 3)
2679 as_bad (_("stack increment must be multiple of 4"));
2680 ignore_rest_of_line ();
2681 return;
2684 /* Don't generate any opcodes, just record the details for later. */
2685 unwind.frame_size += offset;
2686 unwind.pending_offset += offset;
2688 demand_empty_rest_of_line ();
2691 /* Parse an unwind_setfp directive. */
2693 static void
2694 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
2696 int sp_reg;
2697 int fp_reg;
2698 int offset;
2700 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2701 if (skip_past_comma (&input_line_pointer) == FAIL)
2702 sp_reg = FAIL;
2703 else
2704 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2706 if (fp_reg == FAIL || sp_reg == FAIL)
2708 as_bad (_("expected <reg>, <reg>"));
2709 ignore_rest_of_line ();
2710 return;
2713 /* Optional constant. */
2714 if (skip_past_comma (&input_line_pointer) != FAIL)
2716 if (immediate_for_directive (&offset) == FAIL)
2717 return;
2719 else
2720 offset = 0;
2722 demand_empty_rest_of_line ();
2724 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
2726 as_bad (_("register must be either sp or set by a previous"
2727 "unwind_movsp directive"));
2728 return;
2731 /* Don't generate any opcodes, just record the information for later. */
2732 unwind.fp_reg = fp_reg;
2733 unwind.fp_used = 1;
2734 if (sp_reg == 13)
2735 unwind.fp_offset = unwind.frame_size - offset;
2736 else
2737 unwind.fp_offset -= offset;
2740 /* Parse an unwind_raw directive. */
2742 static void
2743 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
2745 expressionS exp;
2746 /* This is an arbitary limit. */
2747 unsigned char op[16];
2748 int count;
2750 expression (&exp);
2751 if (exp.X_op == O_constant
2752 && skip_past_comma (&input_line_pointer) != FAIL)
2754 unwind.frame_size += exp.X_add_number;
2755 expression (&exp);
2757 else
2758 exp.X_op = O_illegal;
2760 if (exp.X_op != O_constant)
2762 as_bad (_("expected <offset>, <opcode>"));
2763 ignore_rest_of_line ();
2764 return;
2767 count = 0;
2769 /* Parse the opcode. */
2770 for (;;)
2772 if (count >= 16)
2774 as_bad (_("unwind opcode too long"));
2775 ignore_rest_of_line ();
2777 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
2779 as_bad (_("invalid unwind opcode"));
2780 ignore_rest_of_line ();
2781 return;
2783 op[count++] = exp.X_add_number;
2785 /* Parse the next byte. */
2786 if (skip_past_comma (&input_line_pointer) == FAIL)
2787 break;
2789 expression (&exp);
2792 /* Add the opcode bytes in reverse order. */
2793 while (count--)
2794 add_unwind_opcode (op[count], 1);
2796 demand_empty_rest_of_line ();
2800 /* Parse a .eabi_attribute directive. */
2802 static void
2803 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
2805 expressionS exp;
2806 bfd_boolean is_string;
2807 int tag;
2808 unsigned int i = 0;
2809 char *s = NULL;
2810 char saved_char;
2812 expression (& exp);
2813 if (exp.X_op != O_constant)
2814 goto bad;
2816 tag = exp.X_add_number;
2817 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
2818 is_string = 1;
2819 else
2820 is_string = 0;
2822 if (skip_past_comma (&input_line_pointer) == FAIL)
2823 goto bad;
2824 if (tag == 32 || !is_string)
2826 expression (& exp);
2827 if (exp.X_op != O_constant)
2829 as_bad (_("expected numeric constant"));
2830 ignore_rest_of_line ();
2831 return;
2833 i = exp.X_add_number;
2835 if (tag == Tag_compatibility
2836 && skip_past_comma (&input_line_pointer) == FAIL)
2838 as_bad (_("expected comma"));
2839 ignore_rest_of_line ();
2840 return;
2842 if (is_string)
2844 skip_whitespace(input_line_pointer);
2845 if (*input_line_pointer != '"')
2846 goto bad_string;
2847 input_line_pointer++;
2848 s = input_line_pointer;
2849 while (*input_line_pointer && *input_line_pointer != '"')
2850 input_line_pointer++;
2851 if (*input_line_pointer != '"')
2852 goto bad_string;
2853 saved_char = *input_line_pointer;
2854 *input_line_pointer = 0;
2856 else
2858 s = NULL;
2859 saved_char = 0;
2862 if (tag == Tag_compatibility)
2863 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
2864 else if (is_string)
2865 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
2866 else
2867 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
2869 if (s)
2871 *input_line_pointer = saved_char;
2872 input_line_pointer++;
2874 demand_empty_rest_of_line ();
2875 return;
2876 bad_string:
2877 as_bad (_("bad string constant"));
2878 ignore_rest_of_line ();
2879 return;
2880 bad:
2881 as_bad (_("expected <tag> , <value>"));
2882 ignore_rest_of_line ();
2885 static void s_arm_arch (int);
2886 static void s_arm_cpu (int);
2887 static void s_arm_fpu (int);
2888 #endif /* OBJ_ELF */
2890 /* This table describes all the machine specific pseudo-ops the assembler
2891 has to support. The fields are:
2892 pseudo-op name without dot
2893 function to call to execute this pseudo-op
2894 Integer arg to pass to the function. */
2896 const pseudo_typeS md_pseudo_table[] =
2898 /* Never called because '.req' does not start a line. */
2899 { "req", s_req, 0 },
2900 { "unreq", s_unreq, 0 },
2901 { "bss", s_bss, 0 },
2902 { "align", s_align, 0 },
2903 { "arm", s_arm, 0 },
2904 { "thumb", s_thumb, 0 },
2905 { "code", s_code, 0 },
2906 { "force_thumb", s_force_thumb, 0 },
2907 { "thumb_func", s_thumb_func, 0 },
2908 { "thumb_set", s_thumb_set, 0 },
2909 { "even", s_even, 0 },
2910 { "ltorg", s_ltorg, 0 },
2911 { "pool", s_ltorg, 0 },
2912 { "syntax", s_syntax, 0 },
2913 #ifdef OBJ_ELF
2914 { "word", s_arm_elf_cons, 4 },
2915 { "long", s_arm_elf_cons, 4 },
2916 { "rel31", s_arm_rel31, 0 },
2917 { "fnstart", s_arm_unwind_fnstart, 0 },
2918 { "fnend", s_arm_unwind_fnend, 0 },
2919 { "cantunwind", s_arm_unwind_cantunwind, 0 },
2920 { "personality", s_arm_unwind_personality, 0 },
2921 { "personalityindex", s_arm_unwind_personalityindex, 0 },
2922 { "handlerdata", s_arm_unwind_handlerdata, 0 },
2923 { "save", s_arm_unwind_save, 0 },
2924 { "movsp", s_arm_unwind_movsp, 0 },
2925 { "pad", s_arm_unwind_pad, 0 },
2926 { "setfp", s_arm_unwind_setfp, 0 },
2927 { "unwind_raw", s_arm_unwind_raw, 0 },
2928 { "cpu", s_arm_cpu, 0 },
2929 { "arch", s_arm_arch, 0 },
2930 { "fpu", s_arm_fpu, 0 },
2931 { "eabi_attribute", s_arm_eabi_attribute, 0 },
2932 #else
2933 { "word", cons, 4},
2934 #endif
2935 { "extend", float_cons, 'x' },
2936 { "ldouble", float_cons, 'x' },
2937 { "packed", float_cons, 'p' },
2938 { 0, 0, 0 }
2941 /* Parser functions used exclusively in instruction operands. */
2943 /* Generic immediate-value read function for use in insn parsing.
2944 STR points to the beginning of the immediate (the leading #);
2945 VAL receives the value; if the value is outside [MIN, MAX]
2946 issue an error. PREFIX_OPT is true if the immediate prefix is
2947 optional. */
2949 static int
2950 parse_immediate (char **str, int *val, int min, int max,
2951 bfd_boolean prefix_opt)
2953 expressionS exp;
2954 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
2955 if (exp.X_op != O_constant)
2957 inst.error = _("constant expression required");
2958 return FAIL;
2961 if (exp.X_add_number < min || exp.X_add_number > max)
2963 inst.error = _("immediate value out of range");
2964 return FAIL;
2967 *val = exp.X_add_number;
2968 return SUCCESS;
2971 /* Returns the pseudo-register number of an FPA immediate constant,
2972 or FAIL if there isn't a valid constant here. */
2974 static int
2975 parse_fpa_immediate (char ** str)
2977 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2978 char * save_in;
2979 expressionS exp;
2980 int i;
2981 int j;
2983 /* First try and match exact strings, this is to guarantee
2984 that some formats will work even for cross assembly. */
2986 for (i = 0; fp_const[i]; i++)
2988 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
2990 char *start = *str;
2992 *str += strlen (fp_const[i]);
2993 if (is_end_of_line[(unsigned char) **str])
2994 return i + 8;
2995 *str = start;
2999 /* Just because we didn't get a match doesn't mean that the constant
3000 isn't valid, just that it is in a format that we don't
3001 automatically recognize. Try parsing it with the standard
3002 expression routines. */
3004 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
3006 /* Look for a raw floating point number. */
3007 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
3008 && is_end_of_line[(unsigned char) *save_in])
3010 for (i = 0; i < NUM_FLOAT_VALS; i++)
3012 for (j = 0; j < MAX_LITTLENUMS; j++)
3014 if (words[j] != fp_values[i][j])
3015 break;
3018 if (j == MAX_LITTLENUMS)
3020 *str = save_in;
3021 return i + 8;
3026 /* Try and parse a more complex expression, this will probably fail
3027 unless the code uses a floating point prefix (eg "0f"). */
3028 save_in = input_line_pointer;
3029 input_line_pointer = *str;
3030 if (expression (&exp) == absolute_section
3031 && exp.X_op == O_big
3032 && exp.X_add_number < 0)
3034 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
3035 Ditto for 15. */
3036 if (gen_to_words (words, 5, (long) 15) == 0)
3038 for (i = 0; i < NUM_FLOAT_VALS; i++)
3040 for (j = 0; j < MAX_LITTLENUMS; j++)
3042 if (words[j] != fp_values[i][j])
3043 break;
3046 if (j == MAX_LITTLENUMS)
3048 *str = input_line_pointer;
3049 input_line_pointer = save_in;
3050 return i + 8;
3056 *str = input_line_pointer;
3057 input_line_pointer = save_in;
3058 inst.error = _("invalid FPA immediate expression");
3059 return FAIL;
3062 /* Shift operands. */
3063 enum shift_kind
3065 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
3068 struct asm_shift_name
3070 const char *name;
3071 enum shift_kind kind;
3074 /* Third argument to parse_shift. */
3075 enum parse_shift_mode
3077 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
3078 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
3079 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
3080 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
3081 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
3084 /* Parse a <shift> specifier on an ARM data processing instruction.
3085 This has three forms:
3087 (LSL|LSR|ASL|ASR|ROR) Rs
3088 (LSL|LSR|ASL|ASR|ROR) #imm
3091 Note that ASL is assimilated to LSL in the instruction encoding, and
3092 RRX to ROR #0 (which cannot be written as such). */
3094 static int
3095 parse_shift (char **str, int i, enum parse_shift_mode mode)
3097 const struct asm_shift_name *shift_name;
3098 enum shift_kind shift;
3099 char *s = *str;
3100 char *p = s;
3101 int reg;
3103 for (p = *str; ISALPHA (*p); p++)
3106 if (p == *str)
3108 inst.error = _("shift expression expected");
3109 return FAIL;
3112 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
3114 if (shift_name == NULL)
3116 inst.error = _("shift expression expected");
3117 return FAIL;
3120 shift = shift_name->kind;
3122 switch (mode)
3124 case NO_SHIFT_RESTRICT:
3125 case SHIFT_IMMEDIATE: break;
3127 case SHIFT_LSL_OR_ASR_IMMEDIATE:
3128 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
3130 inst.error = _("'LSL' or 'ASR' required");
3131 return FAIL;
3133 break;
3135 case SHIFT_LSL_IMMEDIATE:
3136 if (shift != SHIFT_LSL)
3138 inst.error = _("'LSL' required");
3139 return FAIL;
3141 break;
3143 case SHIFT_ASR_IMMEDIATE:
3144 if (shift != SHIFT_ASR)
3146 inst.error = _("'ASR' required");
3147 return FAIL;
3149 break;
3151 default: abort ();
3154 if (shift != SHIFT_RRX)
3156 /* Whitespace can appear here if the next thing is a bare digit. */
3157 skip_whitespace (p);
3159 if (mode == NO_SHIFT_RESTRICT
3160 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3162 inst.operands[i].imm = reg;
3163 inst.operands[i].immisreg = 1;
3165 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3166 return FAIL;
3168 inst.operands[i].shift_kind = shift;
3169 inst.operands[i].shifted = 1;
3170 *str = p;
3171 return SUCCESS;
3174 /* Parse a <shifter_operand> for an ARM data processing instruction:
3176 #<immediate>
3177 #<immediate>, <rotate>
3178 <Rm>
3179 <Rm>, <shift>
3181 where <shift> is defined by parse_shift above, and <rotate> is a
3182 multiple of 2 between 0 and 30. Validation of immediate operands
3183 is deferred to md_apply_fix. */
3185 static int
3186 parse_shifter_operand (char **str, int i)
3188 int value;
3189 expressionS expr;
3191 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
3193 inst.operands[i].reg = value;
3194 inst.operands[i].isreg = 1;
3196 /* parse_shift will override this if appropriate */
3197 inst.reloc.exp.X_op = O_constant;
3198 inst.reloc.exp.X_add_number = 0;
3200 if (skip_past_comma (str) == FAIL)
3201 return SUCCESS;
3203 /* Shift operation on register. */
3204 return parse_shift (str, i, NO_SHIFT_RESTRICT);
3207 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
3208 return FAIL;
3210 if (skip_past_comma (str) == SUCCESS)
3212 /* #x, y -- ie explicit rotation by Y. */
3213 if (my_get_expression (&expr, str, GE_NO_PREFIX))
3214 return FAIL;
3216 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
3218 inst.error = _("constant expression expected");
3219 return FAIL;
3222 value = expr.X_add_number;
3223 if (value < 0 || value > 30 || value % 2 != 0)
3225 inst.error = _("invalid rotation");
3226 return FAIL;
3228 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
3230 inst.error = _("invalid constant");
3231 return FAIL;
3234 /* Convert to decoded value. md_apply_fix will put it back. */
3235 inst.reloc.exp.X_add_number
3236 = (((inst.reloc.exp.X_add_number << (32 - value))
3237 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
3240 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
3241 inst.reloc.pc_rel = 0;
3242 return SUCCESS;
3245 /* Parse all forms of an ARM address expression. Information is written
3246 to inst.operands[i] and/or inst.reloc.
3248 Preindexed addressing (.preind=1):
3250 [Rn, #offset] .reg=Rn .reloc.exp=offset
3251 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3252 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3253 .shift_kind=shift .reloc.exp=shift_imm
3255 These three may have a trailing ! which causes .writeback to be set also.
3257 Postindexed addressing (.postind=1, .writeback=1):
3259 [Rn], #offset .reg=Rn .reloc.exp=offset
3260 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3261 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3262 .shift_kind=shift .reloc.exp=shift_imm
3264 Unindexed addressing (.preind=0, .postind=0):
3266 [Rn], {option} .reg=Rn .imm=option .immisreg=0
3268 Other:
3270 [Rn]{!} shorthand for [Rn,#0]{!}
3271 =immediate .isreg=0 .reloc.exp=immediate
3272 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
3274 It is the caller's responsibility to check for addressing modes not
3275 supported by the instruction, and to set inst.reloc.type. */
3277 static int
3278 parse_address (char **str, int i)
3280 char *p = *str;
3281 int reg;
3283 if (skip_past_char (&p, '[') == FAIL)
3285 if (skip_past_char (&p, '=') == FAIL)
3287 /* bare address - translate to PC-relative offset */
3288 inst.reloc.pc_rel = 1;
3289 inst.operands[i].reg = REG_PC;
3290 inst.operands[i].isreg = 1;
3291 inst.operands[i].preind = 1;
3293 /* else a load-constant pseudo op, no special treatment needed here */
3295 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
3296 return FAIL;
3298 *str = p;
3299 return SUCCESS;
3302 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3304 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3305 return FAIL;
3307 inst.operands[i].reg = reg;
3308 inst.operands[i].isreg = 1;
3310 if (skip_past_comma (&p) == SUCCESS)
3312 inst.operands[i].preind = 1;
3314 if (*p == '+') p++;
3315 else if (*p == '-') p++, inst.operands[i].negative = 1;
3317 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3319 inst.operands[i].imm = reg;
3320 inst.operands[i].immisreg = 1;
3322 if (skip_past_comma (&p) == SUCCESS)
3323 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3324 return FAIL;
3326 else
3328 if (inst.operands[i].negative)
3330 inst.operands[i].negative = 0;
3331 p--;
3333 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3334 return FAIL;
3338 if (skip_past_char (&p, ']') == FAIL)
3340 inst.error = _("']' expected");
3341 return FAIL;
3344 if (skip_past_char (&p, '!') == SUCCESS)
3345 inst.operands[i].writeback = 1;
3347 else if (skip_past_comma (&p) == SUCCESS)
3349 if (skip_past_char (&p, '{') == SUCCESS)
3351 /* [Rn], {expr} - unindexed, with option */
3352 if (parse_immediate (&p, &inst.operands[i].imm,
3353 0, 255, TRUE) == FAIL)
3354 return FAIL;
3356 if (skip_past_char (&p, '}') == FAIL)
3358 inst.error = _("'}' expected at end of 'option' field");
3359 return FAIL;
3361 if (inst.operands[i].preind)
3363 inst.error = _("cannot combine index with option");
3364 return FAIL;
3366 *str = p;
3367 return SUCCESS;
3369 else
3371 inst.operands[i].postind = 1;
3372 inst.operands[i].writeback = 1;
3374 if (inst.operands[i].preind)
3376 inst.error = _("cannot combine pre- and post-indexing");
3377 return FAIL;
3380 if (*p == '+') p++;
3381 else if (*p == '-') p++, inst.operands[i].negative = 1;
3383 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3385 inst.operands[i].imm = reg;
3386 inst.operands[i].immisreg = 1;
3388 if (skip_past_comma (&p) == SUCCESS)
3389 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3390 return FAIL;
3392 else
3394 if (inst.operands[i].negative)
3396 inst.operands[i].negative = 0;
3397 p--;
3399 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3400 return FAIL;
3405 /* If at this point neither .preind nor .postind is set, we have a
3406 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
3407 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
3409 inst.operands[i].preind = 1;
3410 inst.reloc.exp.X_op = O_constant;
3411 inst.reloc.exp.X_add_number = 0;
3413 *str = p;
3414 return SUCCESS;
3417 /* Miscellaneous. */
3419 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
3420 or a bitmask suitable to be or-ed into the ARM msr instruction. */
3421 static int
3422 parse_psr (char **str)
3424 char *p;
3425 unsigned long psr_field;
3427 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
3428 feature for ease of use and backwards compatibility. */
3429 p = *str;
3430 if (*p == 's' || *p == 'S')
3431 psr_field = SPSR_BIT;
3432 else if (*p == 'c' || *p == 'C')
3433 psr_field = 0;
3434 else
3435 goto error;
3437 p++;
3438 if (strncasecmp (p, "PSR", 3) != 0)
3439 goto error;
3440 p += 3;
3442 if (*p == '_')
3444 /* A suffix follows. */
3445 const struct asm_psr *psr;
3446 char *start;
3448 p++;
3449 start = p;
3452 p++;
3453 while (ISALNUM (*p) || *p == '_');
3455 psr = hash_find_n (arm_psr_hsh, start, p - start);
3456 if (!psr)
3457 goto error;
3459 psr_field |= psr->field;
3461 else
3463 if (ISALNUM (*p))
3464 goto error; /* Garbage after "[CS]PSR". */
3466 psr_field |= (PSR_c | PSR_f);
3468 *str = p;
3469 return psr_field;
3471 error:
3472 inst.error = _("flag for {c}psr instruction expected");
3473 return FAIL;
3476 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
3477 value suitable for splatting into the AIF field of the instruction. */
3479 static int
3480 parse_cps_flags (char **str)
3482 int val = 0;
3483 int saw_a_flag = 0;
3484 char *s = *str;
3486 for (;;)
3487 switch (*s++)
3489 case '\0': case ',':
3490 goto done;
3492 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
3493 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
3494 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
3496 default:
3497 inst.error = _("unrecognized CPS flag");
3498 return FAIL;
3501 done:
3502 if (saw_a_flag == 0)
3504 inst.error = _("missing CPS flags");
3505 return FAIL;
3508 *str = s - 1;
3509 return val;
3512 /* Parse an endian specifier ("BE" or "LE", case insensitive);
3513 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
3515 static int
3516 parse_endian_specifier (char **str)
3518 int little_endian;
3519 char *s = *str;
3521 if (strncasecmp (s, "BE", 2))
3522 little_endian = 0;
3523 else if (strncasecmp (s, "LE", 2))
3524 little_endian = 1;
3525 else
3527 inst.error = _("valid endian specifiers are be or le");
3528 return FAIL;
3531 if (ISALNUM (s[2]) || s[2] == '_')
3533 inst.error = _("valid endian specifiers are be or le");
3534 return FAIL;
3537 *str = s + 2;
3538 return little_endian;
3541 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
3542 value suitable for poking into the rotate field of an sxt or sxta
3543 instruction, or FAIL on error. */
3545 static int
3546 parse_ror (char **str)
3548 int rot;
3549 char *s = *str;
3551 if (strncasecmp (s, "ROR", 3) == 0)
3552 s += 3;
3553 else
3555 inst.error = _("missing rotation field after comma");
3556 return FAIL;
3559 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
3560 return FAIL;
3562 switch (rot)
3564 case 0: *str = s; return 0x0;
3565 case 8: *str = s; return 0x1;
3566 case 16: *str = s; return 0x2;
3567 case 24: *str = s; return 0x3;
3569 default:
3570 inst.error = _("rotation can only be 0, 8, 16, or 24");
3571 return FAIL;
3575 /* Parse a conditional code (from conds[] below). The value returned is in the
3576 range 0 .. 14, or FAIL. */
3577 static int
3578 parse_cond (char **str)
3580 char *p, *q;
3581 const struct asm_cond *c;
3583 p = q = *str;
3584 while (ISALPHA (*q))
3585 q++;
3587 c = hash_find_n (arm_cond_hsh, p, q - p);
3588 if (!c)
3590 inst.error = _("condition required");
3591 return FAIL;
3594 *str = q;
3595 return c->value;
3598 /* Parse the operands of a table branch instruction. Similar to a memory
3599 operand. */
3600 static int
3601 parse_tb (char **str)
3603 char * p = *str;
3604 int reg;
3606 if (skip_past_char (&p, '[') == FAIL)
3607 return FAIL;
3609 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3611 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3612 return FAIL;
3614 inst.operands[0].reg = reg;
3616 if (skip_past_comma (&p) == FAIL)
3617 return FAIL;
3619 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3621 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3622 return FAIL;
3624 inst.operands[0].imm = reg;
3626 if (skip_past_comma (&p) == SUCCESS)
3628 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
3629 return FAIL;
3630 if (inst.reloc.exp.X_add_number != 1)
3632 inst.error = _("invalid shift");
3633 return FAIL;
3635 inst.operands[0].shifted = 1;
3638 if (skip_past_char (&p, ']') == FAIL)
3640 inst.error = _("']' expected");
3641 return FAIL;
3643 *str = p;
3644 return SUCCESS;
3647 /* Matcher codes for parse_operands. */
3648 enum operand_parse_code
3650 OP_stop, /* end of line */
3652 OP_RR, /* ARM register */
3653 OP_RRnpc, /* ARM register, not r15 */
3654 OP_RRnpcb, /* ARM register, not r15, in square brackets */
3655 OP_RRw, /* ARM register, not r15, optional trailing ! */
3656 OP_RCP, /* Coprocessor number */
3657 OP_RCN, /* Coprocessor register */
3658 OP_RF, /* FPA register */
3659 OP_RVS, /* VFP single precision register */
3660 OP_RVD, /* VFP double precision register */
3661 OP_RVC, /* VFP control register */
3662 OP_RMF, /* Maverick F register */
3663 OP_RMD, /* Maverick D register */
3664 OP_RMFX, /* Maverick FX register */
3665 OP_RMDX, /* Maverick DX register */
3666 OP_RMAX, /* Maverick AX register */
3667 OP_RMDS, /* Maverick DSPSC register */
3668 OP_RIWR, /* iWMMXt wR register */
3669 OP_RIWC, /* iWMMXt wC register */
3670 OP_RIWG, /* iWMMXt wCG register */
3671 OP_RXA, /* XScale accumulator register */
3673 OP_REGLST, /* ARM register list */
3674 OP_VRSLST, /* VFP single-precision register list */
3675 OP_VRDLST, /* VFP double-precision register list */
3677 OP_I7, /* immediate value 0 .. 7 */
3678 OP_I15, /* 0 .. 15 */
3679 OP_I16, /* 1 .. 16 */
3680 OP_I31, /* 0 .. 31 */
3681 OP_I31w, /* 0 .. 31, optional trailing ! */
3682 OP_I32, /* 1 .. 32 */
3683 OP_I63s, /* -64 .. 63 */
3684 OP_I255, /* 0 .. 255 */
3685 OP_Iffff, /* 0 .. 65535 */
3687 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
3688 OP_I7b, /* 0 .. 7 */
3689 OP_I15b, /* 0 .. 15 */
3690 OP_I31b, /* 0 .. 31 */
3692 OP_SH, /* shifter operand */
3693 OP_ADDR, /* Memory address expression (any mode) */
3694 OP_EXP, /* arbitrary expression */
3695 OP_EXPi, /* same, with optional immediate prefix */
3696 OP_EXPr, /* same, with optional relocation suffix */
3698 OP_CPSF, /* CPS flags */
3699 OP_ENDI, /* Endianness specifier */
3700 OP_PSR, /* CPSR/SPSR mask for msr */
3701 OP_COND, /* conditional code */
3702 OP_TB, /* Table branch. */
3704 OP_RRnpc_I0, /* ARM register or literal 0 */
3705 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
3706 OP_RR_EXi, /* ARM register or expression with imm prefix */
3707 OP_RF_IF, /* FPA register or immediate */
3708 OP_RIWR_RIWC, /* iWMMXt R or C reg */
3710 /* Optional operands. */
3711 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
3712 OP_oI31b, /* 0 .. 31 */
3713 OP_oIffffb, /* 0 .. 65535 */
3714 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
3716 OP_oRR, /* ARM register */
3717 OP_oRRnpc, /* ARM register, not the PC */
3718 OP_oSHll, /* LSL immediate */
3719 OP_oSHar, /* ASR immediate */
3720 OP_oSHllar, /* LSL or ASR immediate */
3721 OP_oROR, /* ROR 0/8/16/24 */
3723 OP_FIRST_OPTIONAL = OP_oI7b
3726 /* Generic instruction operand parser. This does no encoding and no
3727 semantic validation; it merely squirrels values away in the inst
3728 structure. Returns SUCCESS or FAIL depending on whether the
3729 specified grammar matched. */
3730 static int
3731 parse_operands (char *str, const unsigned char *pattern)
3733 unsigned const char *upat = pattern;
3734 char *backtrack_pos = 0;
3735 const char *backtrack_error = 0;
3736 int i, val, backtrack_index = 0;
3738 #define po_char_or_fail(chr) do { \
3739 if (skip_past_char (&str, chr) == FAIL) \
3740 goto bad_args; \
3741 } while (0)
3743 #define po_reg_or_fail(regtype) do { \
3744 val = arm_reg_parse (&str, regtype); \
3745 if (val == FAIL) \
3747 inst.error = _(reg_expected_msgs[regtype]); \
3748 goto failure; \
3750 inst.operands[i].reg = val; \
3751 inst.operands[i].isreg = 1; \
3752 } while (0)
3754 #define po_reg_or_goto(regtype, label) do { \
3755 val = arm_reg_parse (&str, regtype); \
3756 if (val == FAIL) \
3757 goto label; \
3759 inst.operands[i].reg = val; \
3760 inst.operands[i].isreg = 1; \
3761 } while (0)
3763 #define po_imm_or_fail(min, max, popt) do { \
3764 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
3765 goto failure; \
3766 inst.operands[i].imm = val; \
3767 } while (0)
3769 #define po_misc_or_fail(expr) do { \
3770 if (expr) \
3771 goto failure; \
3772 } while (0)
3774 skip_whitespace (str);
3776 for (i = 0; upat[i] != OP_stop; i++)
3778 if (upat[i] >= OP_FIRST_OPTIONAL)
3780 /* Remember where we are in case we need to backtrack. */
3781 assert (!backtrack_pos);
3782 backtrack_pos = str;
3783 backtrack_error = inst.error;
3784 backtrack_index = i;
3787 if (i > 0)
3788 po_char_or_fail (',');
3790 switch (upat[i])
3792 /* Registers */
3793 case OP_oRRnpc:
3794 case OP_RRnpc:
3795 case OP_oRR:
3796 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
3797 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
3798 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
3799 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
3800 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
3801 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
3802 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
3803 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
3804 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
3805 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
3806 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
3807 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
3808 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
3809 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
3810 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
3811 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
3812 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
3814 case OP_RRnpcb:
3815 po_char_or_fail ('[');
3816 po_reg_or_fail (REG_TYPE_RN);
3817 po_char_or_fail (']');
3818 break;
3820 case OP_RRw:
3821 po_reg_or_fail (REG_TYPE_RN);
3822 if (skip_past_char (&str, '!') == SUCCESS)
3823 inst.operands[i].writeback = 1;
3824 break;
3826 /* Immediates */
3827 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
3828 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
3829 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
3830 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
3831 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
3832 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
3833 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
3834 case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break;
3836 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
3837 case OP_oI7b:
3838 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
3839 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
3840 case OP_oI31b:
3841 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
3842 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
3844 /* Immediate variants */
3845 case OP_oI255c:
3846 po_char_or_fail ('{');
3847 po_imm_or_fail (0, 255, TRUE);
3848 po_char_or_fail ('}');
3849 break;
3851 case OP_I31w:
3852 /* The expression parser chokes on a trailing !, so we have
3853 to find it first and zap it. */
3855 char *s = str;
3856 while (*s && *s != ',')
3857 s++;
3858 if (s[-1] == '!')
3860 s[-1] = '\0';
3861 inst.operands[i].writeback = 1;
3863 po_imm_or_fail (0, 31, TRUE);
3864 if (str == s - 1)
3865 str = s;
3867 break;
3869 /* Expressions */
3870 case OP_EXPi: EXPi:
3871 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3872 GE_OPT_PREFIX));
3873 break;
3875 case OP_EXP:
3876 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3877 GE_NO_PREFIX));
3878 break;
3880 case OP_EXPr: EXPr:
3881 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3882 GE_NO_PREFIX));
3883 if (inst.reloc.exp.X_op == O_symbol)
3885 val = parse_reloc (&str);
3886 if (val == -1)
3888 inst.error = _("unrecognized relocation suffix");
3889 goto failure;
3891 else if (val != BFD_RELOC_UNUSED)
3893 inst.operands[i].imm = val;
3894 inst.operands[i].hasreloc = 1;
3897 break;
3899 /* Register or expression */
3900 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
3901 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
3903 /* Register or immediate */
3904 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
3905 I0: po_imm_or_fail (0, 0, FALSE); break;
3907 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
3909 if (!is_immediate_prefix (*str))
3910 goto bad_args;
3911 str++;
3912 val = parse_fpa_immediate (&str);
3913 if (val == FAIL)
3914 goto failure;
3915 /* FPA immediates are encoded as registers 8-15.
3916 parse_fpa_immediate has already applied the offset. */
3917 inst.operands[i].reg = val;
3918 inst.operands[i].isreg = 1;
3919 break;
3921 /* Two kinds of register */
3922 case OP_RIWR_RIWC:
3924 struct reg_entry *rege = arm_reg_parse_multi (&str);
3925 if (rege->type != REG_TYPE_MMXWR
3926 && rege->type != REG_TYPE_MMXWC
3927 && rege->type != REG_TYPE_MMXWCG)
3929 inst.error = _("iWMMXt data or control register expected");
3930 goto failure;
3932 inst.operands[i].reg = rege->number;
3933 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
3935 break;
3937 /* Misc */
3938 case OP_CPSF: val = parse_cps_flags (&str); break;
3939 case OP_ENDI: val = parse_endian_specifier (&str); break;
3940 case OP_oROR: val = parse_ror (&str); break;
3941 case OP_PSR: val = parse_psr (&str); break;
3942 case OP_COND: val = parse_cond (&str); break;
3944 case OP_TB:
3945 po_misc_or_fail (parse_tb (&str));
3946 break;
3948 /* Register lists */
3949 case OP_REGLST:
3950 val = parse_reg_list (&str);
3951 if (*str == '^')
3953 inst.operands[1].writeback = 1;
3954 str++;
3956 break;
3958 case OP_VRSLST:
3959 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0);
3960 break;
3962 case OP_VRDLST:
3963 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1);
3964 break;
3966 /* Addressing modes */
3967 case OP_ADDR:
3968 po_misc_or_fail (parse_address (&str, i));
3969 break;
3971 case OP_SH:
3972 po_misc_or_fail (parse_shifter_operand (&str, i));
3973 break;
3975 case OP_oSHll:
3976 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
3977 break;
3979 case OP_oSHar:
3980 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
3981 break;
3983 case OP_oSHllar:
3984 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
3985 break;
3987 default:
3988 as_fatal ("unhandled operand code %d", upat[i]);
3991 /* Various value-based sanity checks and shared operations. We
3992 do not signal immediate failures for the register constraints;
3993 this allows a syntax error to take precedence. */
3994 switch (upat[i])
3996 case OP_oRRnpc:
3997 case OP_RRnpc:
3998 case OP_RRnpcb:
3999 case OP_RRw:
4000 case OP_RRnpc_I0:
4001 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
4002 inst.error = BAD_PC;
4003 break;
4005 case OP_CPSF:
4006 case OP_ENDI:
4007 case OP_oROR:
4008 case OP_PSR:
4009 case OP_COND:
4010 case OP_REGLST:
4011 case OP_VRSLST:
4012 case OP_VRDLST:
4013 if (val == FAIL)
4014 goto failure;
4015 inst.operands[i].imm = val;
4016 break;
4018 default:
4019 break;
4022 /* If we get here, this operand was successfully parsed. */
4023 inst.operands[i].present = 1;
4024 continue;
4026 bad_args:
4027 inst.error = BAD_ARGS;
4029 failure:
4030 if (!backtrack_pos)
4031 return FAIL;
4033 /* Do not backtrack over a trailing optional argument that
4034 absorbed some text. We will only fail again, with the
4035 'garbage following instruction' error message, which is
4036 probably less helpful than the current one. */
4037 if (backtrack_index == i && backtrack_pos != str
4038 && upat[i+1] == OP_stop)
4039 return FAIL;
4041 /* Try again, skipping the optional argument at backtrack_pos. */
4042 str = backtrack_pos;
4043 inst.error = backtrack_error;
4044 inst.operands[backtrack_index].present = 0;
4045 i = backtrack_index;
4046 backtrack_pos = 0;
4049 /* Check that we have parsed all the arguments. */
4050 if (*str != '\0' && !inst.error)
4051 inst.error = _("garbage following instruction");
4053 return inst.error ? FAIL : SUCCESS;
4056 #undef po_char_or_fail
4057 #undef po_reg_or_fail
4058 #undef po_reg_or_goto
4059 #undef po_imm_or_fail
4061 /* Shorthand macro for instruction encoding functions issuing errors. */
4062 #define constraint(expr, err) do { \
4063 if (expr) \
4065 inst.error = err; \
4066 return; \
4068 } while (0)
4070 /* Functions for operand encoding. ARM, then Thumb. */
4072 #define rotate_left(v, n) (v << n | v >> (32 - n))
4074 /* If VAL can be encoded in the immediate field of an ARM instruction,
4075 return the encoded form. Otherwise, return FAIL. */
4077 static unsigned int
4078 encode_arm_immediate (unsigned int val)
4080 unsigned int a, i;
4082 for (i = 0; i < 32; i += 2)
4083 if ((a = rotate_left (val, i)) <= 0xff)
4084 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
4086 return FAIL;
4089 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
4090 return the encoded form. Otherwise, return FAIL. */
4091 static unsigned int
4092 encode_thumb32_immediate (unsigned int val)
4094 unsigned int a, i;
4096 if (val <= 0xff)
4097 return val;
4099 for (i = 1; i <= 24; i++)
4101 a = val >> i;
4102 if ((val & ~(0xff << i)) == 0)
4103 return ((val >> i) & 0x7f) | ((32 - i) << 7);
4106 a = val & 0xff;
4107 if (val == ((a << 16) | a))
4108 return 0x100 | a;
4109 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
4110 return 0x300 | a;
4112 a = val & 0xff00;
4113 if (val == ((a << 16) | a))
4114 return 0x200 | (a >> 8);
4116 return FAIL;
4118 /* Encode a VFP SP register number into inst.instruction. */
4120 static void
4121 encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos)
4123 switch (pos)
4125 case VFP_REG_Sd:
4126 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
4127 break;
4129 case VFP_REG_Sn:
4130 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
4131 break;
4133 case VFP_REG_Sm:
4134 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
4135 break;
4137 default:
4138 abort ();
4142 /* Encode a <shift> in an ARM-format instruction. The immediate,
4143 if any, is handled by md_apply_fix. */
4144 static void
4145 encode_arm_shift (int i)
4147 if (inst.operands[i].shift_kind == SHIFT_RRX)
4148 inst.instruction |= SHIFT_ROR << 5;
4149 else
4151 inst.instruction |= inst.operands[i].shift_kind << 5;
4152 if (inst.operands[i].immisreg)
4154 inst.instruction |= SHIFT_BY_REG;
4155 inst.instruction |= inst.operands[i].imm << 8;
4157 else
4158 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4162 static void
4163 encode_arm_shifter_operand (int i)
4165 if (inst.operands[i].isreg)
4167 inst.instruction |= inst.operands[i].reg;
4168 encode_arm_shift (i);
4170 else
4171 inst.instruction |= INST_IMMEDIATE;
4174 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
4175 static void
4176 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
4178 assert (inst.operands[i].isreg);
4179 inst.instruction |= inst.operands[i].reg << 16;
4181 if (inst.operands[i].preind)
4183 if (is_t)
4185 inst.error = _("instruction does not accept preindexed addressing");
4186 return;
4188 inst.instruction |= PRE_INDEX;
4189 if (inst.operands[i].writeback)
4190 inst.instruction |= WRITE_BACK;
4193 else if (inst.operands[i].postind)
4195 assert (inst.operands[i].writeback);
4196 if (is_t)
4197 inst.instruction |= WRITE_BACK;
4199 else /* unindexed - only for coprocessor */
4201 inst.error = _("instruction does not accept unindexed addressing");
4202 return;
4205 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
4206 && (((inst.instruction & 0x000f0000) >> 16)
4207 == ((inst.instruction & 0x0000f000) >> 12)))
4208 as_warn ((inst.instruction & LOAD_BIT)
4209 ? _("destination register same as write-back base")
4210 : _("source register same as write-back base"));
4213 /* inst.operands[i] was set up by parse_address. Encode it into an
4214 ARM-format mode 2 load or store instruction. If is_t is true,
4215 reject forms that cannot be used with a T instruction (i.e. not
4216 post-indexed). */
4217 static void
4218 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
4220 encode_arm_addr_mode_common (i, is_t);
4222 if (inst.operands[i].immisreg)
4224 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
4225 inst.instruction |= inst.operands[i].imm;
4226 if (!inst.operands[i].negative)
4227 inst.instruction |= INDEX_UP;
4228 if (inst.operands[i].shifted)
4230 if (inst.operands[i].shift_kind == SHIFT_RRX)
4231 inst.instruction |= SHIFT_ROR << 5;
4232 else
4234 inst.instruction |= inst.operands[i].shift_kind << 5;
4235 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4239 else /* immediate offset in inst.reloc */
4241 if (inst.reloc.type == BFD_RELOC_UNUSED)
4242 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
4246 /* inst.operands[i] was set up by parse_address. Encode it into an
4247 ARM-format mode 3 load or store instruction. Reject forms that
4248 cannot be used with such instructions. If is_t is true, reject
4249 forms that cannot be used with a T instruction (i.e. not
4250 post-indexed). */
4251 static void
4252 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
4254 if (inst.operands[i].immisreg && inst.operands[i].shifted)
4256 inst.error = _("instruction does not accept scaled register index");
4257 return;
4260 encode_arm_addr_mode_common (i, is_t);
4262 if (inst.operands[i].immisreg)
4264 inst.instruction |= inst.operands[i].imm;
4265 if (!inst.operands[i].negative)
4266 inst.instruction |= INDEX_UP;
4268 else /* immediate offset in inst.reloc */
4270 inst.instruction |= HWOFFSET_IMM;
4271 if (inst.reloc.type == BFD_RELOC_UNUSED)
4272 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
4276 /* inst.operands[i] was set up by parse_address. Encode it into an
4277 ARM-format instruction. Reject all forms which cannot be encoded
4278 into a coprocessor load/store instruction. If wb_ok is false,
4279 reject use of writeback; if unind_ok is false, reject use of
4280 unindexed addressing. If reloc_override is not 0, use it instead
4281 of BFD_ARM_CP_OFF_IMM. */
4283 static int
4284 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
4286 inst.instruction |= inst.operands[i].reg << 16;
4288 assert (!(inst.operands[i].preind && inst.operands[i].postind));
4290 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
4292 assert (!inst.operands[i].writeback);
4293 if (!unind_ok)
4295 inst.error = _("instruction does not support unindexed addressing");
4296 return FAIL;
4298 inst.instruction |= inst.operands[i].imm;
4299 inst.instruction |= INDEX_UP;
4300 return SUCCESS;
4303 if (inst.operands[i].preind)
4304 inst.instruction |= PRE_INDEX;
4306 if (inst.operands[i].writeback)
4308 if (inst.operands[i].reg == REG_PC)
4310 inst.error = _("pc may not be used with write-back");
4311 return FAIL;
4313 if (!wb_ok)
4315 inst.error = _("instruction does not support writeback");
4316 return FAIL;
4318 inst.instruction |= WRITE_BACK;
4321 if (reloc_override)
4322 inst.reloc.type = reloc_override;
4323 else if (thumb_mode)
4324 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
4325 else
4326 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
4327 return SUCCESS;
4330 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
4331 Determine whether it can be performed with a move instruction; if
4332 it can, convert inst.instruction to that move instruction and
4333 return 1; if it can't, convert inst.instruction to a literal-pool
4334 load and return 0. If this is not a valid thing to do in the
4335 current context, set inst.error and return 1.
4337 inst.operands[i] describes the destination register. */
4339 static int
4340 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
4342 if ((inst.instruction & (thumb_p ? THUMB_LOAD_BIT : LOAD_BIT)) == 0)
4344 inst.error = _("invalid pseudo operation");
4345 return 1;
4347 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
4349 inst.error = _("constant expression expected");
4350 return 1;
4352 if (inst.reloc.exp.X_op == O_constant)
4354 if (thumb_p)
4356 if ((inst.reloc.exp.X_add_number & ~0xFF) == 0)
4358 /* This can be done with a mov(1) instruction. */
4359 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
4360 inst.instruction |= inst.reloc.exp.X_add_number;
4361 return 1;
4364 else
4366 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
4367 if (value != FAIL)
4369 /* This can be done with a mov instruction. */
4370 inst.instruction &= LITERAL_MASK;
4371 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
4372 inst.instruction |= value & 0xfff;
4373 return 1;
4376 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
4377 if (value != FAIL)
4379 /* This can be done with a mvn instruction. */
4380 inst.instruction &= LITERAL_MASK;
4381 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
4382 inst.instruction |= value & 0xfff;
4383 return 1;
4388 if (add_to_lit_pool () == FAIL)
4390 inst.error = _("literal pool insertion failed");
4391 return 1;
4393 inst.operands[1].reg = REG_PC;
4394 inst.operands[1].isreg = 1;
4395 inst.operands[1].preind = 1;
4396 inst.reloc.pc_rel = 1;
4397 inst.reloc.type = (thumb_p
4398 ? BFD_RELOC_ARM_THUMB_OFFSET
4399 : (mode_3
4400 ? BFD_RELOC_ARM_HWLITERAL
4401 : BFD_RELOC_ARM_LITERAL));
4402 return 0;
4405 /* Functions for instruction encoding, sorted by subarchitecture.
4406 First some generics; their names are taken from the conventional
4407 bit positions for register arguments in ARM format instructions. */
4409 static void
4410 do_noargs (void)
4414 static void
4415 do_rd (void)
4417 inst.instruction |= inst.operands[0].reg << 12;
4420 static void
4421 do_rd_rm (void)
4423 inst.instruction |= inst.operands[0].reg << 12;
4424 inst.instruction |= inst.operands[1].reg;
4427 static void
4428 do_rd_rn (void)
4430 inst.instruction |= inst.operands[0].reg << 12;
4431 inst.instruction |= inst.operands[1].reg << 16;
4434 static void
4435 do_rn_rd (void)
4437 inst.instruction |= inst.operands[0].reg << 16;
4438 inst.instruction |= inst.operands[1].reg << 12;
4441 static void
4442 do_rd_rm_rn (void)
4444 unsigned Rn = inst.operands[2].reg;
4445 /* Enforce resutrictions on SWP instruction. */
4446 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
4447 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
4448 _("Rn must not overlap other operands"));
4449 inst.instruction |= inst.operands[0].reg << 12;
4450 inst.instruction |= inst.operands[1].reg;
4451 inst.instruction |= Rn << 16;
4454 static void
4455 do_rd_rn_rm (void)
4457 inst.instruction |= inst.operands[0].reg << 12;
4458 inst.instruction |= inst.operands[1].reg << 16;
4459 inst.instruction |= inst.operands[2].reg;
4462 static void
4463 do_rm_rd_rn (void)
4465 inst.instruction |= inst.operands[0].reg;
4466 inst.instruction |= inst.operands[1].reg << 12;
4467 inst.instruction |= inst.operands[2].reg << 16;
4470 static void
4471 do_imm0 (void)
4473 inst.instruction |= inst.operands[0].imm;
4476 static void
4477 do_rd_cpaddr (void)
4479 inst.instruction |= inst.operands[0].reg << 12;
4480 encode_arm_cp_address (1, TRUE, TRUE, 0);
4483 /* ARM instructions, in alphabetical order by function name (except
4484 that wrapper functions appear immediately after the function they
4485 wrap). */
4487 /* This is a pseudo-op of the form "adr rd, label" to be converted
4488 into a relative address of the form "add rd, pc, #label-.-8". */
4490 static void
4491 do_adr (void)
4493 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
4495 /* Frag hacking will turn this into a sub instruction if the offset turns
4496 out to be negative. */
4497 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4498 inst.reloc.pc_rel = 1;
4499 inst.reloc.exp.X_add_number -= 8;
4502 /* This is a pseudo-op of the form "adrl rd, label" to be converted
4503 into a relative address of the form:
4504 add rd, pc, #low(label-.-8)"
4505 add rd, rd, #high(label-.-8)" */
4507 static void
4508 do_adrl (void)
4510 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
4512 /* Frag hacking will turn this into a sub instruction if the offset turns
4513 out to be negative. */
4514 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
4515 inst.reloc.pc_rel = 1;
4516 inst.size = INSN_SIZE * 2;
4517 inst.reloc.exp.X_add_number -= 8;
4520 static void
4521 do_arit (void)
4523 if (!inst.operands[1].present)
4524 inst.operands[1].reg = inst.operands[0].reg;
4525 inst.instruction |= inst.operands[0].reg << 12;
4526 inst.instruction |= inst.operands[1].reg << 16;
4527 encode_arm_shifter_operand (2);
4530 static void
4531 do_bfc (void)
4533 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
4534 constraint (msb > 32, _("bit-field extends past end of register"));
4535 /* The instruction encoding stores the LSB and MSB,
4536 not the LSB and width. */
4537 inst.instruction |= inst.operands[0].reg << 12;
4538 inst.instruction |= inst.operands[1].imm << 7;
4539 inst.instruction |= (msb - 1) << 16;
4542 static void
4543 do_bfi (void)
4545 unsigned int msb;
4547 /* #0 in second position is alternative syntax for bfc, which is
4548 the same instruction but with REG_PC in the Rm field. */
4549 if (!inst.operands[1].isreg)
4550 inst.operands[1].reg = REG_PC;
4552 msb = inst.operands[2].imm + inst.operands[3].imm;
4553 constraint (msb > 32, _("bit-field extends past end of register"));
4554 /* The instruction encoding stores the LSB and MSB,
4555 not the LSB and width. */
4556 inst.instruction |= inst.operands[0].reg << 12;
4557 inst.instruction |= inst.operands[1].reg;
4558 inst.instruction |= inst.operands[2].imm << 7;
4559 inst.instruction |= (msb - 1) << 16;
4562 static void
4563 do_bfx (void)
4565 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
4566 _("bit-field extends past end of register"));
4567 inst.instruction |= inst.operands[0].reg << 12;
4568 inst.instruction |= inst.operands[1].reg;
4569 inst.instruction |= inst.operands[2].imm << 7;
4570 inst.instruction |= (inst.operands[3].imm - 1) << 16;
4573 /* ARM V5 breakpoint instruction (argument parse)
4574 BKPT <16 bit unsigned immediate>
4575 Instruction is not conditional.
4576 The bit pattern given in insns[] has the COND_ALWAYS condition,
4577 and it is an error if the caller tried to override that. */
4579 static void
4580 do_bkpt (void)
4582 /* Top 12 of 16 bits to bits 19:8. */
4583 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
4585 /* Bottom 4 of 16 bits to bits 3:0. */
4586 inst.instruction |= inst.operands[0].imm & 0xf;
4589 static void
4590 encode_branch (int default_reloc)
4592 if (inst.operands[0].hasreloc)
4594 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
4595 _("the only suffix valid here is '(plt)'"));
4596 inst.reloc.type = BFD_RELOC_ARM_PLT32;
4598 else
4600 inst.reloc.type = default_reloc;
4602 inst.reloc.pc_rel = 1;
4605 static void
4606 do_branch (void)
4608 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
4611 /* ARM V5 branch-link-exchange instruction (argument parse)
4612 BLX <target_addr> ie BLX(1)
4613 BLX{<condition>} <Rm> ie BLX(2)
4614 Unfortunately, there are two different opcodes for this mnemonic.
4615 So, the insns[].value is not used, and the code here zaps values
4616 into inst.instruction.
4617 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
4619 static void
4620 do_blx (void)
4622 if (inst.operands[0].isreg)
4624 /* Arg is a register; the opcode provided by insns[] is correct.
4625 It is not illegal to do "blx pc", just useless. */
4626 if (inst.operands[0].reg == REG_PC)
4627 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
4629 inst.instruction |= inst.operands[0].reg;
4631 else
4633 /* Arg is an address; this instruction cannot be executed
4634 conditionally, and the opcode must be adjusted. */
4635 constraint (inst.cond != COND_ALWAYS, BAD_COND);
4636 inst.instruction = 0xfa000000;
4637 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
4641 static void
4642 do_bx (void)
4644 if (inst.operands[0].reg == REG_PC)
4645 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
4647 inst.instruction |= inst.operands[0].reg;
4651 /* ARM v5TEJ. Jump to Jazelle code. */
4653 static void
4654 do_bxj (void)
4656 if (inst.operands[0].reg == REG_PC)
4657 as_tsktsk (_("use of r15 in bxj is not really useful"));
4659 inst.instruction |= inst.operands[0].reg;
4662 /* Co-processor data operation:
4663 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
4664 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
4665 static void
4666 do_cdp (void)
4668 inst.instruction |= inst.operands[0].reg << 8;
4669 inst.instruction |= inst.operands[1].imm << 20;
4670 inst.instruction |= inst.operands[2].reg << 12;
4671 inst.instruction |= inst.operands[3].reg << 16;
4672 inst.instruction |= inst.operands[4].reg;
4673 inst.instruction |= inst.operands[5].imm << 5;
4676 static void
4677 do_cmp (void)
4679 inst.instruction |= inst.operands[0].reg << 16;
4680 encode_arm_shifter_operand (1);
4683 /* Transfer between coprocessor and ARM registers.
4684 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
4685 MRC2
4686 MCR{cond}
4687 MCR2
4689 No special properties. */
4691 static void
4692 do_co_reg (void)
4694 inst.instruction |= inst.operands[0].reg << 8;
4695 inst.instruction |= inst.operands[1].imm << 21;
4696 inst.instruction |= inst.operands[2].reg << 12;
4697 inst.instruction |= inst.operands[3].reg << 16;
4698 inst.instruction |= inst.operands[4].reg;
4699 inst.instruction |= inst.operands[5].imm << 5;
4702 /* Transfer between coprocessor register and pair of ARM registers.
4703 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
4704 MCRR2
4705 MRRC{cond}
4706 MRRC2
4708 Two XScale instructions are special cases of these:
4710 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
4711 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
4713 Result unpredicatable if Rd or Rn is R15. */
4715 static void
4716 do_co_reg2c (void)
4718 inst.instruction |= inst.operands[0].reg << 8;
4719 inst.instruction |= inst.operands[1].imm << 4;
4720 inst.instruction |= inst.operands[2].reg << 12;
4721 inst.instruction |= inst.operands[3].reg << 16;
4722 inst.instruction |= inst.operands[4].reg;
4725 static void
4726 do_cpsi (void)
4728 inst.instruction |= inst.operands[0].imm << 6;
4729 inst.instruction |= inst.operands[1].imm;
4732 static void
4733 do_it (void)
4735 /* There is no IT instruction in ARM mode. We
4736 process it but do not generate code for it. */
4737 inst.size = 0;
4740 static void
4741 do_ldmstm (void)
4743 int base_reg = inst.operands[0].reg;
4744 int range = inst.operands[1].imm;
4746 inst.instruction |= base_reg << 16;
4747 inst.instruction |= range;
4749 if (inst.operands[1].writeback)
4750 inst.instruction |= LDM_TYPE_2_OR_3;
4752 if (inst.operands[0].writeback)
4754 inst.instruction |= WRITE_BACK;
4755 /* Check for unpredictable uses of writeback. */
4756 if (inst.instruction & LOAD_BIT)
4758 /* Not allowed in LDM type 2. */
4759 if ((inst.instruction & LDM_TYPE_2_OR_3)
4760 && ((range & (1 << REG_PC)) == 0))
4761 as_warn (_("writeback of base register is UNPREDICTABLE"));
4762 /* Only allowed if base reg not in list for other types. */
4763 else if (range & (1 << base_reg))
4764 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
4766 else /* STM. */
4768 /* Not allowed for type 2. */
4769 if (inst.instruction & LDM_TYPE_2_OR_3)
4770 as_warn (_("writeback of base register is UNPREDICTABLE"));
4771 /* Only allowed if base reg not in list, or first in list. */
4772 else if ((range & (1 << base_reg))
4773 && (range & ((1 << base_reg) - 1)))
4774 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
4779 /* ARMv5TE load-consecutive (argument parse)
4780 Mode is like LDRH.
4782 LDRccD R, mode
4783 STRccD R, mode. */
4785 static void
4786 do_ldrd (void)
4788 constraint (inst.operands[0].reg % 2 != 0,
4789 _("first destination register must be even"));
4790 constraint (inst.operands[1].present
4791 && inst.operands[1].reg != inst.operands[0].reg + 1,
4792 _("can only load two consecutive registers"));
4793 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
4794 constraint (!inst.operands[2].isreg, _("'[' expected"));
4796 if (!inst.operands[1].present)
4797 inst.operands[1].reg = inst.operands[0].reg + 1;
4799 if (inst.instruction & LOAD_BIT)
4801 /* encode_arm_addr_mode_3 will diagnose overlap between the base
4802 register and the first register written; we have to diagnose
4803 overlap between the base and the second register written here. */
4805 if (inst.operands[2].reg == inst.operands[1].reg
4806 && (inst.operands[2].writeback || inst.operands[2].postind))
4807 as_warn (_("base register written back, and overlaps "
4808 "second destination register"));
4810 /* For an index-register load, the index register must not overlap the
4811 destination (even if not write-back). */
4812 else if (inst.operands[2].immisreg
4813 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
4814 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
4815 as_warn (_("index register overlaps destination register"));
4818 inst.instruction |= inst.operands[0].reg << 12;
4819 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
4822 static void
4823 do_ldrex (void)
4825 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
4826 || inst.operands[1].postind || inst.operands[1].writeback
4827 || inst.operands[1].immisreg || inst.operands[1].shifted
4828 || inst.operands[1].negative,
4829 _("instruction does not accept this addressing mode"));
4831 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
4833 constraint (inst.reloc.exp.X_op != O_constant
4834 || inst.reloc.exp.X_add_number != 0,
4835 _("offset must be zero in ARM encoding"));
4837 inst.instruction |= inst.operands[0].reg << 12;
4838 inst.instruction |= inst.operands[1].reg << 16;
4839 inst.reloc.type = BFD_RELOC_UNUSED;
4842 static void
4843 do_ldrexd (void)
4845 constraint (inst.operands[0].reg % 2 != 0,
4846 _("even register required"));
4847 constraint (inst.operands[1].present
4848 && inst.operands[1].reg != inst.operands[0].reg + 1,
4849 _("can only load two consecutive registers"));
4850 /* If op 1 were present and equal to PC, this function wouldn't
4851 have been called in the first place. */
4852 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
4854 inst.instruction |= inst.operands[0].reg << 12;
4855 inst.instruction |= inst.operands[2].reg << 16;
4858 static void
4859 do_ldst (void)
4861 inst.instruction |= inst.operands[0].reg << 12;
4862 if (!inst.operands[1].isreg)
4863 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
4864 return;
4865 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
4868 static void
4869 do_ldstt (void)
4871 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4872 reject [Rn,...]. */
4873 if (inst.operands[1].preind)
4875 constraint (inst.reloc.exp.X_op != O_constant ||
4876 inst.reloc.exp.X_add_number != 0,
4877 _("this instruction requires a post-indexed address"));
4879 inst.operands[1].preind = 0;
4880 inst.operands[1].postind = 1;
4881 inst.operands[1].writeback = 1;
4883 inst.instruction |= inst.operands[0].reg << 12;
4884 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
4887 /* Halfword and signed-byte load/store operations. */
4889 static void
4890 do_ldstv4 (void)
4892 inst.instruction |= inst.operands[0].reg << 12;
4893 if (!inst.operands[1].isreg)
4894 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
4895 return;
4896 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
4899 static void
4900 do_ldsttv4 (void)
4902 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
4903 reject [Rn,...]. */
4904 if (inst.operands[1].preind)
4906 constraint (inst.reloc.exp.X_op != O_constant ||
4907 inst.reloc.exp.X_add_number != 0,
4908 _("this instruction requires a post-indexed address"));
4910 inst.operands[1].preind = 0;
4911 inst.operands[1].postind = 1;
4912 inst.operands[1].writeback = 1;
4914 inst.instruction |= inst.operands[0].reg << 12;
4915 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
4918 /* Co-processor register load/store.
4919 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
4920 static void
4921 do_lstc (void)
4923 inst.instruction |= inst.operands[0].reg << 8;
4924 inst.instruction |= inst.operands[1].reg << 12;
4925 encode_arm_cp_address (2, TRUE, TRUE, 0);
4928 static void
4929 do_mlas (void)
4931 /* This restriction does not apply to mls (nor to mla in v6, but
4932 that's hard to detect at present). */
4933 if (inst.operands[0].reg == inst.operands[1].reg
4934 && !(inst.instruction & 0x00400000))
4935 as_tsktsk (_("rd and rm should be different in mla"));
4937 inst.instruction |= inst.operands[0].reg << 16;
4938 inst.instruction |= inst.operands[1].reg;
4939 inst.instruction |= inst.operands[2].reg << 8;
4940 inst.instruction |= inst.operands[3].reg << 12;
4944 static void
4945 do_mov (void)
4947 inst.instruction |= inst.operands[0].reg << 12;
4948 encode_arm_shifter_operand (1);
4951 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
4952 static void
4953 do_mov16 (void)
4955 inst.instruction |= inst.operands[0].reg << 12;
4956 /* The value is in two pieces: 0:11, 16:19. */
4957 inst.instruction |= (inst.operands[1].imm & 0x00000fff);
4958 inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4;
4961 static void
4962 do_mrs (void)
4964 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
4965 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
4966 != (PSR_c|PSR_f),
4967 _("'CPSR' or 'SPSR' expected"));
4968 inst.instruction |= inst.operands[0].reg << 12;
4969 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
4972 /* Two possible forms:
4973 "{C|S}PSR_<field>, Rm",
4974 "{C|S}PSR_f, #expression". */
4976 static void
4977 do_msr (void)
4979 inst.instruction |= inst.operands[0].imm;
4980 if (inst.operands[1].isreg)
4981 inst.instruction |= inst.operands[1].reg;
4982 else
4984 inst.instruction |= INST_IMMEDIATE;
4985 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4986 inst.reloc.pc_rel = 0;
4990 static void
4991 do_mul (void)
4993 if (!inst.operands[2].present)
4994 inst.operands[2].reg = inst.operands[0].reg;
4995 inst.instruction |= inst.operands[0].reg << 16;
4996 inst.instruction |= inst.operands[1].reg;
4997 inst.instruction |= inst.operands[2].reg << 8;
4999 if (inst.operands[0].reg == inst.operands[1].reg)
5000 as_tsktsk (_("rd and rm should be different in mul"));
5003 /* Long Multiply Parser
5004 UMULL RdLo, RdHi, Rm, Rs
5005 SMULL RdLo, RdHi, Rm, Rs
5006 UMLAL RdLo, RdHi, Rm, Rs
5007 SMLAL RdLo, RdHi, Rm, Rs. */
5009 static void
5010 do_mull (void)
5012 inst.instruction |= inst.operands[0].reg << 12;
5013 inst.instruction |= inst.operands[1].reg << 16;
5014 inst.instruction |= inst.operands[2].reg;
5015 inst.instruction |= inst.operands[3].reg << 8;
5017 /* rdhi, rdlo and rm must all be different. */
5018 if (inst.operands[0].reg == inst.operands[1].reg
5019 || inst.operands[0].reg == inst.operands[2].reg
5020 || inst.operands[1].reg == inst.operands[2].reg)
5021 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
5024 static void
5025 do_nop (void)
5027 if (inst.operands[0].present)
5029 /* Architectural NOP hints are CPSR sets with no bits selected. */
5030 inst.instruction &= 0xf0000000;
5031 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
5035 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
5036 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
5037 Condition defaults to COND_ALWAYS.
5038 Error if Rd, Rn or Rm are R15. */
5040 static void
5041 do_pkhbt (void)
5043 inst.instruction |= inst.operands[0].reg << 12;
5044 inst.instruction |= inst.operands[1].reg << 16;
5045 inst.instruction |= inst.operands[2].reg;
5046 if (inst.operands[3].present)
5047 encode_arm_shift (3);
5050 /* ARM V6 PKHTB (Argument Parse). */
5052 static void
5053 do_pkhtb (void)
5055 if (!inst.operands[3].present)
5057 /* If the shift specifier is omitted, turn the instruction
5058 into pkhbt rd, rm, rn. */
5059 inst.instruction &= 0xfff00010;
5060 inst.instruction |= inst.operands[0].reg << 12;
5061 inst.instruction |= inst.operands[1].reg;
5062 inst.instruction |= inst.operands[2].reg << 16;
5064 else
5066 inst.instruction |= inst.operands[0].reg << 12;
5067 inst.instruction |= inst.operands[1].reg << 16;
5068 inst.instruction |= inst.operands[2].reg;
5069 encode_arm_shift (3);
5073 /* ARMv5TE: Preload-Cache
5075 PLD <addr_mode>
5077 Syntactically, like LDR with B=1, W=0, L=1. */
5079 static void
5080 do_pld (void)
5082 constraint (!inst.operands[0].isreg,
5083 _("'[' expected after PLD mnemonic"));
5084 constraint (inst.operands[0].postind,
5085 _("post-indexed expression used in preload instruction"));
5086 constraint (inst.operands[0].writeback,
5087 _("writeback used in preload instruction"));
5088 constraint (!inst.operands[0].preind,
5089 _("unindexed addressing used in preload instruction"));
5090 inst.instruction |= inst.operands[0].reg;
5091 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
5094 static void
5095 do_push_pop (void)
5097 inst.operands[1] = inst.operands[0];
5098 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
5099 inst.operands[0].isreg = 1;
5100 inst.operands[0].writeback = 1;
5101 inst.operands[0].reg = REG_SP;
5102 do_ldmstm ();
5105 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
5106 word at the specified address and the following word
5107 respectively.
5108 Unconditionally executed.
5109 Error if Rn is R15. */
5111 static void
5112 do_rfe (void)
5114 inst.instruction |= inst.operands[0].reg << 16;
5115 if (inst.operands[0].writeback)
5116 inst.instruction |= WRITE_BACK;
5119 /* ARM V6 ssat (argument parse). */
5121 static void
5122 do_ssat (void)
5124 inst.instruction |= inst.operands[0].reg << 12;
5125 inst.instruction |= (inst.operands[1].imm - 1) << 16;
5126 inst.instruction |= inst.operands[2].reg;
5128 if (inst.operands[3].present)
5129 encode_arm_shift (3);
5132 /* ARM V6 usat (argument parse). */
5134 static void
5135 do_usat (void)
5137 inst.instruction |= inst.operands[0].reg << 12;
5138 inst.instruction |= inst.operands[1].imm << 16;
5139 inst.instruction |= inst.operands[2].reg;
5141 if (inst.operands[3].present)
5142 encode_arm_shift (3);
5145 /* ARM V6 ssat16 (argument parse). */
5147 static void
5148 do_ssat16 (void)
5150 inst.instruction |= inst.operands[0].reg << 12;
5151 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
5152 inst.instruction |= inst.operands[2].reg;
5155 static void
5156 do_usat16 (void)
5158 inst.instruction |= inst.operands[0].reg << 12;
5159 inst.instruction |= inst.operands[1].imm << 16;
5160 inst.instruction |= inst.operands[2].reg;
5163 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
5164 preserving the other bits.
5166 setend <endian_specifier>, where <endian_specifier> is either
5167 BE or LE. */
5169 static void
5170 do_setend (void)
5172 if (inst.operands[0].imm)
5173 inst.instruction |= 0x200;
5176 static void
5177 do_shift (void)
5179 unsigned int Rm = (inst.operands[1].present
5180 ? inst.operands[1].reg
5181 : inst.operands[0].reg);
5183 inst.instruction |= inst.operands[0].reg << 12;
5184 inst.instruction |= Rm;
5185 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
5187 constraint (inst.operands[0].reg != Rm,
5188 _("source1 and dest must be same register"));
5189 inst.instruction |= inst.operands[2].reg << 8;
5190 inst.instruction |= SHIFT_BY_REG;
5192 else
5193 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
5196 static void
5197 do_smc (void)
5199 inst.reloc.type = BFD_RELOC_ARM_SMC;
5200 inst.reloc.pc_rel = 0;
5203 static void
5204 do_swi (void)
5206 inst.reloc.type = BFD_RELOC_ARM_SWI;
5207 inst.reloc.pc_rel = 0;
5210 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
5211 SMLAxy{cond} Rd,Rm,Rs,Rn
5212 SMLAWy{cond} Rd,Rm,Rs,Rn
5213 Error if any register is R15. */
5215 static void
5216 do_smla (void)
5218 inst.instruction |= inst.operands[0].reg << 16;
5219 inst.instruction |= inst.operands[1].reg;
5220 inst.instruction |= inst.operands[2].reg << 8;
5221 inst.instruction |= inst.operands[3].reg << 12;
5224 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
5225 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
5226 Error if any register is R15.
5227 Warning if Rdlo == Rdhi. */
5229 static void
5230 do_smlal (void)
5232 inst.instruction |= inst.operands[0].reg << 12;
5233 inst.instruction |= inst.operands[1].reg << 16;
5234 inst.instruction |= inst.operands[2].reg;
5235 inst.instruction |= inst.operands[3].reg << 8;
5237 if (inst.operands[0].reg == inst.operands[1].reg)
5238 as_tsktsk (_("rdhi and rdlo must be different"));
5241 /* ARM V5E (El Segundo) signed-multiply (argument parse)
5242 SMULxy{cond} Rd,Rm,Rs
5243 Error if any register is R15. */
5245 static void
5246 do_smul (void)
5248 inst.instruction |= inst.operands[0].reg << 16;
5249 inst.instruction |= inst.operands[1].reg;
5250 inst.instruction |= inst.operands[2].reg << 8;
5253 /* ARM V6 srs (argument parse). */
5255 static void
5256 do_srs (void)
5258 inst.instruction |= inst.operands[0].imm;
5259 if (inst.operands[0].writeback)
5260 inst.instruction |= WRITE_BACK;
5263 /* ARM V6 strex (argument parse). */
5265 static void
5266 do_strex (void)
5268 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
5269 || inst.operands[2].postind || inst.operands[2].writeback
5270 || inst.operands[2].immisreg || inst.operands[2].shifted
5271 || inst.operands[2].negative,
5272 _("instruction does not accept this addressing mode"));
5274 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
5276 constraint (inst.operands[0].reg == inst.operands[1].reg
5277 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
5279 constraint (inst.reloc.exp.X_op != O_constant
5280 || inst.reloc.exp.X_add_number != 0,
5281 _("offset must be zero in ARM encoding"));
5283 inst.instruction |= inst.operands[0].reg << 12;
5284 inst.instruction |= inst.operands[1].reg;
5285 inst.instruction |= inst.operands[2].reg << 16;
5286 inst.reloc.type = BFD_RELOC_UNUSED;
5289 static void
5290 do_strexd (void)
5292 constraint (inst.operands[1].reg % 2 != 0,
5293 _("even register required"));
5294 constraint (inst.operands[2].present
5295 && inst.operands[2].reg != inst.operands[1].reg + 1,
5296 _("can only store two consecutive registers"));
5297 /* If op 2 were present and equal to PC, this function wouldn't
5298 have been called in the first place. */
5299 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
5301 constraint (inst.operands[0].reg == inst.operands[1].reg
5302 || inst.operands[0].reg == inst.operands[1].reg + 1
5303 || inst.operands[0].reg == inst.operands[3].reg,
5304 BAD_OVERLAP);
5306 inst.instruction |= inst.operands[0].reg << 12;
5307 inst.instruction |= inst.operands[1].reg;
5308 inst.instruction |= inst.operands[3].reg << 16;
5311 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
5312 extends it to 32-bits, and adds the result to a value in another
5313 register. You can specify a rotation by 0, 8, 16, or 24 bits
5314 before extracting the 16-bit value.
5315 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
5316 Condition defaults to COND_ALWAYS.
5317 Error if any register uses R15. */
5319 static void
5320 do_sxtah (void)
5322 inst.instruction |= inst.operands[0].reg << 12;
5323 inst.instruction |= inst.operands[1].reg << 16;
5324 inst.instruction |= inst.operands[2].reg;
5325 inst.instruction |= inst.operands[3].imm << 10;
5328 /* ARM V6 SXTH.
5330 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
5331 Condition defaults to COND_ALWAYS.
5332 Error if any register uses R15. */
5334 static void
5335 do_sxth (void)
5337 inst.instruction |= inst.operands[0].reg << 12;
5338 inst.instruction |= inst.operands[1].reg;
5339 inst.instruction |= inst.operands[2].imm << 10;
5342 /* VFP instructions. In a logical order: SP variant first, monad
5343 before dyad, arithmetic then move then load/store. */
5345 static void
5346 do_vfp_sp_monadic (void)
5348 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5349 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
5352 static void
5353 do_vfp_sp_dyadic (void)
5355 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5356 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5357 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
5360 static void
5361 do_vfp_sp_compare_z (void)
5363 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5366 static void
5367 do_vfp_dp_sp_cvt (void)
5369 inst.instruction |= inst.operands[0].reg << 12;
5370 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
5373 static void
5374 do_vfp_sp_dp_cvt (void)
5376 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5377 inst.instruction |= inst.operands[1].reg;
5380 static void
5381 do_vfp_reg_from_sp (void)
5383 inst.instruction |= inst.operands[0].reg << 12;
5384 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5387 static void
5388 do_vfp_reg2_from_sp2 (void)
5390 constraint (inst.operands[2].imm != 2,
5391 _("only two consecutive VFP SP registers allowed here"));
5392 inst.instruction |= inst.operands[0].reg << 12;
5393 inst.instruction |= inst.operands[1].reg << 16;
5394 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
5397 static void
5398 do_vfp_sp_from_reg (void)
5400 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn);
5401 inst.instruction |= inst.operands[1].reg << 12;
5404 static void
5405 do_vfp_sp2_from_reg2 (void)
5407 constraint (inst.operands[0].imm != 2,
5408 _("only two consecutive VFP SP registers allowed here"));
5409 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm);
5410 inst.instruction |= inst.operands[1].reg << 12;
5411 inst.instruction |= inst.operands[2].reg << 16;
5414 static void
5415 do_vfp_sp_ldst (void)
5417 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5418 encode_arm_cp_address (1, FALSE, TRUE, 0);
5421 static void
5422 do_vfp_dp_ldst (void)
5424 inst.instruction |= inst.operands[0].reg << 12;
5425 encode_arm_cp_address (1, FALSE, TRUE, 0);
5429 static void
5430 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
5432 if (inst.operands[0].writeback)
5433 inst.instruction |= WRITE_BACK;
5434 else
5435 constraint (ldstm_type != VFP_LDSTMIA,
5436 _("this addressing mode requires base-register writeback"));
5437 inst.instruction |= inst.operands[0].reg << 16;
5438 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd);
5439 inst.instruction |= inst.operands[1].imm;
5442 static void
5443 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
5445 int count;
5447 if (inst.operands[0].writeback)
5448 inst.instruction |= WRITE_BACK;
5449 else
5450 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
5451 _("this addressing mode requires base-register writeback"));
5453 inst.instruction |= inst.operands[0].reg << 16;
5454 inst.instruction |= inst.operands[1].reg << 12;
5456 count = inst.operands[1].imm << 1;
5457 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
5458 count += 1;
5460 inst.instruction |= count;
5463 static void
5464 do_vfp_sp_ldstmia (void)
5466 vfp_sp_ldstm (VFP_LDSTMIA);
5469 static void
5470 do_vfp_sp_ldstmdb (void)
5472 vfp_sp_ldstm (VFP_LDSTMDB);
5475 static void
5476 do_vfp_dp_ldstmia (void)
5478 vfp_dp_ldstm (VFP_LDSTMIA);
5481 static void
5482 do_vfp_dp_ldstmdb (void)
5484 vfp_dp_ldstm (VFP_LDSTMDB);
5487 static void
5488 do_vfp_xp_ldstmia (void)
5490 vfp_dp_ldstm (VFP_LDSTMIAX);
5493 static void
5494 do_vfp_xp_ldstmdb (void)
5496 vfp_dp_ldstm (VFP_LDSTMDBX);
5499 /* FPA instructions. Also in a logical order. */
5501 static void
5502 do_fpa_cmp (void)
5504 inst.instruction |= inst.operands[0].reg << 16;
5505 inst.instruction |= inst.operands[1].reg;
5508 static void
5509 do_fpa_ldmstm (void)
5511 inst.instruction |= inst.operands[0].reg << 12;
5512 switch (inst.operands[1].imm)
5514 case 1: inst.instruction |= CP_T_X; break;
5515 case 2: inst.instruction |= CP_T_Y; break;
5516 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
5517 case 4: break;
5518 default: abort ();
5521 if (inst.instruction & (PRE_INDEX | INDEX_UP))
5523 /* The instruction specified "ea" or "fd", so we can only accept
5524 [Rn]{!}. The instruction does not really support stacking or
5525 unstacking, so we have to emulate these by setting appropriate
5526 bits and offsets. */
5527 constraint (inst.reloc.exp.X_op != O_constant
5528 || inst.reloc.exp.X_add_number != 0,
5529 _("this instruction does not support indexing"));
5531 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
5532 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
5534 if (!(inst.instruction & INDEX_UP))
5535 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
5537 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
5539 inst.operands[2].preind = 0;
5540 inst.operands[2].postind = 1;
5544 encode_arm_cp_address (2, TRUE, TRUE, 0);
5547 /* iWMMXt instructions: strictly in alphabetical order. */
5549 static void
5550 do_iwmmxt_tandorc (void)
5552 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
5555 static void
5556 do_iwmmxt_textrc (void)
5558 inst.instruction |= inst.operands[0].reg << 12;
5559 inst.instruction |= inst.operands[1].imm;
5562 static void
5563 do_iwmmxt_textrm (void)
5565 inst.instruction |= inst.operands[0].reg << 12;
5566 inst.instruction |= inst.operands[1].reg << 16;
5567 inst.instruction |= inst.operands[2].imm;
5570 static void
5571 do_iwmmxt_tinsr (void)
5573 inst.instruction |= inst.operands[0].reg << 16;
5574 inst.instruction |= inst.operands[1].reg << 12;
5575 inst.instruction |= inst.operands[2].imm;
5578 static void
5579 do_iwmmxt_tmia (void)
5581 inst.instruction |= inst.operands[0].reg << 5;
5582 inst.instruction |= inst.operands[1].reg;
5583 inst.instruction |= inst.operands[2].reg << 12;
5586 static void
5587 do_iwmmxt_waligni (void)
5589 inst.instruction |= inst.operands[0].reg << 12;
5590 inst.instruction |= inst.operands[1].reg << 16;
5591 inst.instruction |= inst.operands[2].reg;
5592 inst.instruction |= inst.operands[3].imm << 20;
5595 static void
5596 do_iwmmxt_wmov (void)
5598 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
5599 inst.instruction |= inst.operands[0].reg << 12;
5600 inst.instruction |= inst.operands[1].reg << 16;
5601 inst.instruction |= inst.operands[1].reg;
5604 static void
5605 do_iwmmxt_wldstbh (void)
5607 int reloc;
5608 inst.instruction |= inst.operands[0].reg << 12;
5609 inst.reloc.exp.X_add_number *= 4;
5610 if (thumb_mode)
5611 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
5612 else
5613 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
5614 encode_arm_cp_address (1, TRUE, FALSE, reloc);
5617 static void
5618 do_iwmmxt_wldstw (void)
5620 /* RIWR_RIWC clears .isreg for a control register. */
5621 if (!inst.operands[0].isreg)
5623 constraint (inst.cond != COND_ALWAYS, BAD_COND);
5624 inst.instruction |= 0xf0000000;
5627 inst.instruction |= inst.operands[0].reg << 12;
5628 encode_arm_cp_address (1, TRUE, TRUE, 0);
5631 static void
5632 do_iwmmxt_wldstd (void)
5634 inst.instruction |= inst.operands[0].reg << 12;
5635 encode_arm_cp_address (1, TRUE, FALSE, 0);
5638 static void
5639 do_iwmmxt_wshufh (void)
5641 inst.instruction |= inst.operands[0].reg << 12;
5642 inst.instruction |= inst.operands[1].reg << 16;
5643 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
5644 inst.instruction |= (inst.operands[2].imm & 0x0f);
5647 static void
5648 do_iwmmxt_wzero (void)
5650 /* WZERO reg is an alias for WANDN reg, reg, reg. */
5651 inst.instruction |= inst.operands[0].reg;
5652 inst.instruction |= inst.operands[0].reg << 12;
5653 inst.instruction |= inst.operands[0].reg << 16;
5656 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
5657 operations first, then control, shift, and load/store. */
5659 /* Insns like "foo X,Y,Z". */
5661 static void
5662 do_mav_triple (void)
5664 inst.instruction |= inst.operands[0].reg << 16;
5665 inst.instruction |= inst.operands[1].reg;
5666 inst.instruction |= inst.operands[2].reg << 12;
5669 /* Insns like "foo W,X,Y,Z".
5670 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
5672 static void
5673 do_mav_quad (void)
5675 inst.instruction |= inst.operands[0].reg << 5;
5676 inst.instruction |= inst.operands[1].reg << 12;
5677 inst.instruction |= inst.operands[2].reg << 16;
5678 inst.instruction |= inst.operands[3].reg;
5681 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
5682 static void
5683 do_mav_dspsc (void)
5685 inst.instruction |= inst.operands[1].reg << 12;
5688 /* Maverick shift immediate instructions.
5689 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
5690 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
5692 static void
5693 do_mav_shift (void)
5695 int imm = inst.operands[2].imm;
5697 inst.instruction |= inst.operands[0].reg << 12;
5698 inst.instruction |= inst.operands[1].reg << 16;
5700 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
5701 Bits 5-7 of the insn should have bits 4-6 of the immediate.
5702 Bit 4 should be 0. */
5703 imm = (imm & 0xf) | ((imm & 0x70) << 1);
5705 inst.instruction |= imm;
5708 /* XScale instructions. Also sorted arithmetic before move. */
5710 /* Xscale multiply-accumulate (argument parse)
5711 MIAcc acc0,Rm,Rs
5712 MIAPHcc acc0,Rm,Rs
5713 MIAxycc acc0,Rm,Rs. */
5715 static void
5716 do_xsc_mia (void)
5718 inst.instruction |= inst.operands[1].reg;
5719 inst.instruction |= inst.operands[2].reg << 12;
5722 /* Xscale move-accumulator-register (argument parse)
5724 MARcc acc0,RdLo,RdHi. */
5726 static void
5727 do_xsc_mar (void)
5729 inst.instruction |= inst.operands[1].reg << 12;
5730 inst.instruction |= inst.operands[2].reg << 16;
5733 /* Xscale move-register-accumulator (argument parse)
5735 MRAcc RdLo,RdHi,acc0. */
5737 static void
5738 do_xsc_mra (void)
5740 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
5741 inst.instruction |= inst.operands[0].reg << 12;
5742 inst.instruction |= inst.operands[1].reg << 16;
5745 /* Encoding functions relevant only to Thumb. */
5747 /* inst.operands[i] is a shifted-register operand; encode
5748 it into inst.instruction in the format used by Thumb32. */
5750 static void
5751 encode_thumb32_shifted_operand (int i)
5753 unsigned int value = inst.reloc.exp.X_add_number;
5754 unsigned int shift = inst.operands[i].shift_kind;
5756 constraint (inst.operands[i].immisreg,
5757 _("shift by register not allowed in thumb mode"));
5758 inst.instruction |= inst.operands[i].reg;
5759 if (shift == SHIFT_RRX)
5760 inst.instruction |= SHIFT_ROR << 4;
5761 else
5763 constraint (inst.reloc.exp.X_op != O_constant,
5764 _("expression too complex"));
5766 constraint (value > 32
5767 || (value == 32 && (shift == SHIFT_LSL
5768 || shift == SHIFT_ROR)),
5769 _("shift expression is too large"));
5771 if (value == 0)
5772 shift = SHIFT_LSL;
5773 else if (value == 32)
5774 value = 0;
5776 inst.instruction |= shift << 4;
5777 inst.instruction |= (value & 0x1c) << 10;
5778 inst.instruction |= (value & 0x03) << 6;
5783 /* inst.operands[i] was set up by parse_address. Encode it into a
5784 Thumb32 format load or store instruction. Reject forms that cannot
5785 be used with such instructions. If is_t is true, reject forms that
5786 cannot be used with a T instruction; if is_d is true, reject forms
5787 that cannot be used with a D instruction. */
5789 static void
5790 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
5792 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
5794 constraint (!inst.operands[i].isreg,
5795 _("Thumb does not support the ldr =N pseudo-operation"));
5797 inst.instruction |= inst.operands[i].reg << 16;
5798 if (inst.operands[i].immisreg)
5800 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
5801 constraint (is_t || is_d, _("cannot use register index with this instruction"));
5802 constraint (inst.operands[i].negative,
5803 _("Thumb does not support negative register indexing"));
5804 constraint (inst.operands[i].postind,
5805 _("Thumb does not support register post-indexing"));
5806 constraint (inst.operands[i].writeback,
5807 _("Thumb does not support register indexing with writeback"));
5808 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
5809 _("Thumb supports only LSL in shifted register indexing"));
5811 inst.instruction |= inst.operands[1].imm;
5812 if (inst.operands[i].shifted)
5814 constraint (inst.reloc.exp.X_op != O_constant,
5815 _("expression too complex"));
5816 constraint (inst.reloc.exp.X_add_number < 0
5817 || inst.reloc.exp.X_add_number > 3,
5818 _("shift out of range"));
5819 inst.instruction |= inst.reloc.exp.X_add_number << 4;
5821 inst.reloc.type = BFD_RELOC_UNUSED;
5823 else if (inst.operands[i].preind)
5825 constraint (is_pc && inst.operands[i].writeback,
5826 _("cannot use writeback with PC-relative addressing"));
5827 constraint (is_t && inst.operands[1].writeback,
5828 _("cannot use writeback with this instruction"));
5830 if (is_d)
5832 inst.instruction |= 0x01000000;
5833 if (inst.operands[i].writeback)
5834 inst.instruction |= 0x00200000;
5836 else
5838 inst.instruction |= 0x00000c00;
5839 if (inst.operands[i].writeback)
5840 inst.instruction |= 0x00000100;
5842 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
5844 else if (inst.operands[i].postind)
5846 assert (inst.operands[i].writeback);
5847 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
5848 constraint (is_t, _("cannot use post-indexing with this instruction"));
5850 if (is_d)
5851 inst.instruction |= 0x00200000;
5852 else
5853 inst.instruction |= 0x00000900;
5854 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
5856 else /* unindexed - only for coprocessor */
5857 inst.error = _("instruction does not accept unindexed addressing");
5860 /* Table of Thumb instructions which exist in both 16- and 32-bit
5861 encodings (the latter only in post-V6T2 cores). The index is the
5862 value used in the insns table below. When there is more than one
5863 possible 16-bit encoding for the instruction, this table always
5864 holds variant (1).
5865 Also contains several pseudo-instructions used during relaxation. */
5866 #define T16_32_TAB \
5867 X(adc, 4140, eb400000), \
5868 X(adcs, 4140, eb500000), \
5869 X(add, 1c00, eb000000), \
5870 X(adds, 1c00, eb100000), \
5871 X(addi, 0000, f1000000), \
5872 X(addis, 0000, f1100000), \
5873 X(add_pc,000f, f20f0000), \
5874 X(add_sp,000d, f10d0000), \
5875 X(adr, 000f, f20f0000), \
5876 X(and, 4000, ea000000), \
5877 X(ands, 4000, ea100000), \
5878 X(asr, 1000, fa40f000), \
5879 X(asrs, 1000, fa50f000), \
5880 X(b, e000, f000b000), \
5881 X(bcond, d000, f0008000), \
5882 X(bic, 4380, ea200000), \
5883 X(bics, 4380, ea300000), \
5884 X(cmn, 42c0, eb100f00), \
5885 X(cmp, 2800, ebb00f00), \
5886 X(cpsie, b660, f3af8400), \
5887 X(cpsid, b670, f3af8600), \
5888 X(cpy, 4600, ea4f0000), \
5889 X(dec_sp,80dd, f1bd0d00), \
5890 X(eor, 4040, ea800000), \
5891 X(eors, 4040, ea900000), \
5892 X(inc_sp,00dd, f10d0d00), \
5893 X(ldmia, c800, e8900000), \
5894 X(ldr, 6800, f8500000), \
5895 X(ldrb, 7800, f8100000), \
5896 X(ldrh, 8800, f8300000), \
5897 X(ldrsb, 5600, f9100000), \
5898 X(ldrsh, 5e00, f9300000), \
5899 X(ldr_pc,4800, f85f0000), \
5900 X(ldr_pc2,4800, f85f0000), \
5901 X(ldr_sp,9800, f85d0000), \
5902 X(lsl, 0000, fa00f000), \
5903 X(lsls, 0000, fa10f000), \
5904 X(lsr, 0800, fa20f000), \
5905 X(lsrs, 0800, fa30f000), \
5906 X(mov, 2000, ea4f0000), \
5907 X(movs, 2000, ea5f0000), \
5908 X(mul, 4340, fb00f000), \
5909 X(muls, 4340, ffffffff), /* no 32b muls */ \
5910 X(mvn, 43c0, ea6f0000), \
5911 X(mvns, 43c0, ea7f0000), \
5912 X(neg, 4240, f1c00000), /* rsb #0 */ \
5913 X(negs, 4240, f1d00000), /* rsbs #0 */ \
5914 X(orr, 4300, ea400000), \
5915 X(orrs, 4300, ea500000), \
5916 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
5917 X(push, b400, e92d0000), /* stmdb sp!,... */ \
5918 X(rev, ba00, fa90f080), \
5919 X(rev16, ba40, fa90f090), \
5920 X(revsh, bac0, fa90f0b0), \
5921 X(ror, 41c0, fa60f000), \
5922 X(rors, 41c0, fa70f000), \
5923 X(sbc, 4180, eb600000), \
5924 X(sbcs, 4180, eb700000), \
5925 X(stmia, c000, e8800000), \
5926 X(str, 6000, f8400000), \
5927 X(strb, 7000, f8000000), \
5928 X(strh, 8000, f8200000), \
5929 X(str_sp,9000, f84d0000), \
5930 X(sub, 1e00, eba00000), \
5931 X(subs, 1e00, ebb00000), \
5932 X(subi, 8000, f1a00000), \
5933 X(subis, 8000, f1b00000), \
5934 X(sxtb, b240, fa4ff080), \
5935 X(sxth, b200, fa0ff080), \
5936 X(tst, 4200, ea100f00), \
5937 X(uxtb, b2c0, fa5ff080), \
5938 X(uxth, b280, fa1ff080), \
5939 X(nop, bf00, f3af8000), \
5940 X(yield, bf10, f3af8001), \
5941 X(wfe, bf20, f3af8002), \
5942 X(wfi, bf30, f3af8003), \
5943 X(sev, bf40, f3af9004), /* typo, 8004? */
5945 /* To catch errors in encoding functions, the codes are all offset by
5946 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
5947 as 16-bit instructions. */
5948 #define X(a,b,c) T_MNEM_##a
5949 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
5950 #undef X
5952 #define X(a,b,c) 0x##b
5953 static const unsigned short thumb_op16[] = { T16_32_TAB };
5954 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
5955 #undef X
5957 #define X(a,b,c) 0x##c
5958 static const unsigned int thumb_op32[] = { T16_32_TAB };
5959 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
5960 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
5961 #undef X
5962 #undef T16_32_TAB
5964 /* Thumb instruction encoders, in alphabetical order. */
5966 /* ADDW or SUBW. */
5967 static void
5968 do_t_add_sub_w (void)
5970 int Rd, Rn;
5972 Rd = inst.operands[0].reg;
5973 Rn = inst.operands[1].reg;
5975 constraint (Rd == 15, _("PC not allowed as destination"));
5976 inst.instruction |= (Rn << 16) | (Rd << 8);
5977 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
5980 /* Parse an add or subtract instruction. We get here with inst.instruction
5981 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
5983 static void
5984 do_t_add_sub (void)
5986 int Rd, Rs, Rn;
5988 Rd = inst.operands[0].reg;
5989 Rs = (inst.operands[1].present
5990 ? inst.operands[1].reg /* Rd, Rs, foo */
5991 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
5993 if (unified_syntax)
5995 bfd_boolean flags;
5996 bfd_boolean narrow;
5997 int opcode;
5999 flags = (inst.instruction == T_MNEM_adds
6000 || inst.instruction == T_MNEM_subs);
6001 if (flags)
6002 narrow = (current_it_mask == 0);
6003 else
6004 narrow = (current_it_mask != 0);
6005 if (!inst.operands[2].isreg)
6007 opcode = 0;
6008 if (inst.size_req != 4)
6010 int add;
6012 add = (inst.instruction == T_MNEM_add
6013 || inst.instruction == T_MNEM_adds);
6014 /* Attempt to use a narrow opcode, with relaxation if
6015 appropriate. */
6016 if (Rd == REG_SP && Rs == REG_SP && !flags)
6017 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
6018 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
6019 opcode = T_MNEM_add_sp;
6020 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
6021 opcode = T_MNEM_add_pc;
6022 else if (Rd <= 7 && Rs <= 7 && narrow)
6024 if (flags)
6025 opcode = add ? T_MNEM_addis : T_MNEM_subis;
6026 else
6027 opcode = add ? T_MNEM_addi : T_MNEM_subi;
6029 if (opcode)
6031 inst.instruction = THUMB_OP16(opcode);
6032 inst.instruction |= (Rd << 4) | Rs;
6033 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6034 if (inst.size_req != 2)
6035 inst.relax = opcode;
6037 else
6038 constraint (inst.size_req == 2, BAD_HIREG);
6040 if (inst.size_req == 4
6041 || (inst.size_req != 2 && !opcode))
6043 /* ??? Convert large immediates to addw/subw. */
6044 inst.instruction = THUMB_OP32 (inst.instruction);
6045 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6046 inst.instruction |= inst.operands[0].reg << 8;
6047 inst.instruction |= inst.operands[1].reg << 16;
6048 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6051 else
6053 Rn = inst.operands[2].reg;
6054 /* See if we can do this with a 16-bit instruction. */
6055 if (!inst.operands[2].shifted && inst.size_req != 4)
6057 if (Rd > 7 || Rs > 7 || Rn > 7)
6058 narrow = FALSE;
6060 if (narrow)
6062 inst.instruction = ((inst.instruction == T_MNEM_adds
6063 || inst.instruction == T_MNEM_add)
6064 ? T_OPCODE_ADD_R3
6065 : T_OPCODE_SUB_R3);
6066 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
6067 return;
6070 if (inst.instruction == T_MNEM_add)
6072 if (Rd == Rs)
6074 inst.instruction = T_OPCODE_ADD_HI;
6075 inst.instruction |= (Rd & 8) << 4;
6076 inst.instruction |= (Rd & 7);
6077 inst.instruction |= Rn << 3;
6078 return;
6080 /* ... because addition is commutative! */
6081 else if (Rd == Rn)
6083 inst.instruction = T_OPCODE_ADD_HI;
6084 inst.instruction |= (Rd & 8) << 4;
6085 inst.instruction |= (Rd & 7);
6086 inst.instruction |= Rs << 3;
6087 return;
6091 /* If we get here, it can't be done in 16 bits. */
6092 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
6093 _("shift must be constant"));
6094 inst.instruction = THUMB_OP32 (inst.instruction);
6095 inst.instruction |= Rd << 8;
6096 inst.instruction |= Rs << 16;
6097 encode_thumb32_shifted_operand (2);
6100 else
6102 constraint (inst.instruction == T_MNEM_adds
6103 || inst.instruction == T_MNEM_subs,
6104 BAD_THUMB32);
6106 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
6108 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
6109 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
6110 BAD_HIREG);
6112 inst.instruction = (inst.instruction == T_MNEM_add
6113 ? 0x0000 : 0x8000);
6114 inst.instruction |= (Rd << 4) | Rs;
6115 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6116 return;
6119 Rn = inst.operands[2].reg;
6120 constraint (inst.operands[2].shifted, _("unshifted register required"));
6122 /* We now have Rd, Rs, and Rn set to registers. */
6123 if (Rd > 7 || Rs > 7 || Rn > 7)
6125 /* Can't do this for SUB. */
6126 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
6127 inst.instruction = T_OPCODE_ADD_HI;
6128 inst.instruction |= (Rd & 8) << 4;
6129 inst.instruction |= (Rd & 7);
6130 if (Rs == Rd)
6131 inst.instruction |= Rn << 3;
6132 else if (Rn == Rd)
6133 inst.instruction |= Rs << 3;
6134 else
6135 constraint (1, _("dest must overlap one source register"));
6137 else
6139 inst.instruction = (inst.instruction == T_MNEM_add
6140 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
6141 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
6146 static void
6147 do_t_adr (void)
6149 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
6151 /* Defer to section relaxation. */
6152 inst.relax = inst.instruction;
6153 inst.instruction = THUMB_OP16 (inst.instruction);
6154 inst.instruction |= inst.operands[0].reg << 4;
6156 else if (unified_syntax && inst.size_req != 2)
6158 /* Generate a 32-bit opcode. */
6159 inst.instruction = THUMB_OP32 (inst.instruction);
6160 inst.instruction |= inst.operands[0].reg << 8;
6161 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
6162 inst.reloc.pc_rel = 1;
6164 else
6166 /* Generate a 16-bit opcode. */
6167 inst.instruction = THUMB_OP16 (inst.instruction);
6168 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6169 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
6170 inst.reloc.pc_rel = 1;
6172 inst.instruction |= inst.operands[0].reg << 4;
6176 /* Arithmetic instructions for which there is just one 16-bit
6177 instruction encoding, and it allows only two low registers.
6178 For maximal compatibility with ARM syntax, we allow three register
6179 operands even when Thumb-32 instructions are not available, as long
6180 as the first two are identical. For instance, both "sbc r0,r1" and
6181 "sbc r0,r0,r1" are allowed. */
6182 static void
6183 do_t_arit3 (void)
6185 int Rd, Rs, Rn;
6187 Rd = inst.operands[0].reg;
6188 Rs = (inst.operands[1].present
6189 ? inst.operands[1].reg /* Rd, Rs, foo */
6190 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6191 Rn = inst.operands[2].reg;
6193 if (unified_syntax)
6195 if (!inst.operands[2].isreg)
6197 /* For an immediate, we always generate a 32-bit opcode;
6198 section relaxation will shrink it later if possible. */
6199 inst.instruction = THUMB_OP32 (inst.instruction);
6200 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6201 inst.instruction |= Rd << 8;
6202 inst.instruction |= Rs << 16;
6203 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6205 else
6207 bfd_boolean narrow;
6209 /* See if we can do this with a 16-bit instruction. */
6210 if (THUMB_SETS_FLAGS (inst.instruction))
6211 narrow = current_it_mask == 0;
6212 else
6213 narrow = current_it_mask != 0;
6215 if (Rd > 7 || Rn > 7 || Rs > 7)
6216 narrow = FALSE;
6217 if (inst.operands[2].shifted)
6218 narrow = FALSE;
6219 if (inst.size_req == 4)
6220 narrow = FALSE;
6222 if (narrow
6223 && Rd == Rs)
6225 inst.instruction = THUMB_OP16 (inst.instruction);
6226 inst.instruction |= Rd;
6227 inst.instruction |= Rn << 3;
6228 return;
6231 /* If we get here, it can't be done in 16 bits. */
6232 constraint (inst.operands[2].shifted
6233 && inst.operands[2].immisreg,
6234 _("shift must be constant"));
6235 inst.instruction = THUMB_OP32 (inst.instruction);
6236 inst.instruction |= Rd << 8;
6237 inst.instruction |= Rs << 16;
6238 encode_thumb32_shifted_operand (2);
6241 else
6243 /* On its face this is a lie - the instruction does set the
6244 flags. However, the only supported mnemonic in this mode
6245 says it doesn't. */
6246 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
6248 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6249 _("unshifted register required"));
6250 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6251 constraint (Rd != Rs,
6252 _("dest and source1 must be the same register"));
6254 inst.instruction = THUMB_OP16 (inst.instruction);
6255 inst.instruction |= Rd;
6256 inst.instruction |= Rn << 3;
6260 /* Similarly, but for instructions where the arithmetic operation is
6261 commutative, so we can allow either of them to be different from
6262 the destination operand in a 16-bit instruction. For instance, all
6263 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
6264 accepted. */
6265 static void
6266 do_t_arit3c (void)
6268 int Rd, Rs, Rn;
6270 Rd = inst.operands[0].reg;
6271 Rs = (inst.operands[1].present
6272 ? inst.operands[1].reg /* Rd, Rs, foo */
6273 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6274 Rn = inst.operands[2].reg;
6276 if (unified_syntax)
6278 if (!inst.operands[2].isreg)
6280 /* For an immediate, we always generate a 32-bit opcode;
6281 section relaxation will shrink it later if possible. */
6282 inst.instruction = THUMB_OP32 (inst.instruction);
6283 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6284 inst.instruction |= Rd << 8;
6285 inst.instruction |= Rs << 16;
6286 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6288 else
6290 bfd_boolean narrow;
6292 /* See if we can do this with a 16-bit instruction. */
6293 if (THUMB_SETS_FLAGS (inst.instruction))
6294 narrow = current_it_mask == 0;
6295 else
6296 narrow = current_it_mask != 0;
6298 if (Rd > 7 || Rn > 7 || Rs > 7)
6299 narrow = FALSE;
6300 if (inst.operands[2].shifted)
6301 narrow = FALSE;
6302 if (inst.size_req == 4)
6303 narrow = FALSE;
6305 if (narrow)
6307 if (Rd == Rs)
6309 inst.instruction = THUMB_OP16 (inst.instruction);
6310 inst.instruction |= Rd;
6311 inst.instruction |= Rn << 3;
6312 return;
6314 if (Rd == Rn)
6316 inst.instruction = THUMB_OP16 (inst.instruction);
6317 inst.instruction |= Rd;
6318 inst.instruction |= Rs << 3;
6319 return;
6323 /* If we get here, it can't be done in 16 bits. */
6324 constraint (inst.operands[2].shifted
6325 && inst.operands[2].immisreg,
6326 _("shift must be constant"));
6327 inst.instruction = THUMB_OP32 (inst.instruction);
6328 inst.instruction |= Rd << 8;
6329 inst.instruction |= Rs << 16;
6330 encode_thumb32_shifted_operand (2);
6333 else
6335 /* On its face this is a lie - the instruction does set the
6336 flags. However, the only supported mnemonic in this mode
6337 says it doesn't. */
6338 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
6340 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6341 _("unshifted register required"));
6342 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6344 inst.instruction = THUMB_OP16 (inst.instruction);
6345 inst.instruction |= Rd;
6347 if (Rd == Rs)
6348 inst.instruction |= Rn << 3;
6349 else if (Rd == Rn)
6350 inst.instruction |= Rs << 3;
6351 else
6352 constraint (1, _("dest must overlap one source register"));
6356 static void
6357 do_t_bfc (void)
6359 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6360 constraint (msb > 32, _("bit-field extends past end of register"));
6361 /* The instruction encoding stores the LSB and MSB,
6362 not the LSB and width. */
6363 inst.instruction |= inst.operands[0].reg << 8;
6364 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
6365 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
6366 inst.instruction |= msb - 1;
6369 static void
6370 do_t_bfi (void)
6372 unsigned int msb;
6374 /* #0 in second position is alternative syntax for bfc, which is
6375 the same instruction but with REG_PC in the Rm field. */
6376 if (!inst.operands[1].isreg)
6377 inst.operands[1].reg = REG_PC;
6379 msb = inst.operands[2].imm + inst.operands[3].imm;
6380 constraint (msb > 32, _("bit-field extends past end of register"));
6381 /* The instruction encoding stores the LSB and MSB,
6382 not the LSB and width. */
6383 inst.instruction |= inst.operands[0].reg << 8;
6384 inst.instruction |= inst.operands[1].reg << 16;
6385 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6386 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6387 inst.instruction |= msb - 1;
6390 static void
6391 do_t_bfx (void)
6393 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6394 _("bit-field extends past end of register"));
6395 inst.instruction |= inst.operands[0].reg << 8;
6396 inst.instruction |= inst.operands[1].reg << 16;
6397 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6398 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6399 inst.instruction |= inst.operands[3].imm - 1;
6402 /* ARM V5 Thumb BLX (argument parse)
6403 BLX <target_addr> which is BLX(1)
6404 BLX <Rm> which is BLX(2)
6405 Unfortunately, there are two different opcodes for this mnemonic.
6406 So, the insns[].value is not used, and the code here zaps values
6407 into inst.instruction.
6409 ??? How to take advantage of the additional two bits of displacement
6410 available in Thumb32 mode? Need new relocation? */
6412 static void
6413 do_t_blx (void)
6415 if (inst.operands[0].isreg)
6416 /* We have a register, so this is BLX(2). */
6417 inst.instruction |= inst.operands[0].reg << 3;
6418 else
6420 /* No register. This must be BLX(1). */
6421 inst.instruction = 0xf000e800;
6422 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
6423 inst.reloc.pc_rel = 1;
6427 static void
6428 do_t_branch (void)
6430 int opcode;
6431 if (inst.cond != COND_ALWAYS)
6432 opcode = T_MNEM_bcond;
6433 else
6434 opcode = inst.instruction;
6436 if (unified_syntax && inst.size_req == 4)
6438 inst.instruction = THUMB_OP32(opcode);
6439 if (inst.cond == COND_ALWAYS)
6440 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
6441 else
6443 assert (inst.cond != 0xF);
6444 inst.instruction |= inst.cond << 22;
6445 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
6448 else
6450 inst.instruction = THUMB_OP16(opcode);
6451 if (inst.cond == COND_ALWAYS)
6452 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
6453 else
6455 inst.instruction |= inst.cond << 8;
6456 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
6458 /* Allow section relaxation. */
6459 if (unified_syntax && inst.size_req != 2)
6460 inst.relax = opcode;
6463 inst.reloc.pc_rel = 1;
6466 static void
6467 do_t_bkpt (void)
6469 if (inst.operands[0].present)
6471 constraint (inst.operands[0].imm > 255,
6472 _("immediate value out of range"));
6473 inst.instruction |= inst.operands[0].imm;
6477 static void
6478 do_t_branch23 (void)
6480 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
6481 inst.reloc.pc_rel = 1;
6483 /* If the destination of the branch is a defined symbol which does not have
6484 the THUMB_FUNC attribute, then we must be calling a function which has
6485 the (interfacearm) attribute. We look for the Thumb entry point to that
6486 function and change the branch to refer to that function instead. */
6487 if ( inst.reloc.exp.X_op == O_symbol
6488 && inst.reloc.exp.X_add_symbol != NULL
6489 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
6490 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
6491 inst.reloc.exp.X_add_symbol =
6492 find_real_start (inst.reloc.exp.X_add_symbol);
6495 static void
6496 do_t_bx (void)
6498 inst.instruction |= inst.operands[0].reg << 3;
6499 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
6500 should cause the alignment to be checked once it is known. This is
6501 because BX PC only works if the instruction is word aligned. */
6504 static void
6505 do_t_bxj (void)
6507 if (inst.operands[0].reg == REG_PC)
6508 as_tsktsk (_("use of r15 in bxj is not really useful"));
6510 inst.instruction |= inst.operands[0].reg << 16;
6513 static void
6514 do_t_clz (void)
6516 inst.instruction |= inst.operands[0].reg << 8;
6517 inst.instruction |= inst.operands[1].reg << 16;
6518 inst.instruction |= inst.operands[1].reg;
6521 static void
6522 do_t_cpsi (void)
6524 if (unified_syntax
6525 && (inst.operands[1].present || inst.size_req == 4))
6527 unsigned int imod = (inst.instruction & 0x0030) >> 4;
6528 inst.instruction = 0xf3af8000;
6529 inst.instruction |= imod << 9;
6530 inst.instruction |= inst.operands[0].imm << 5;
6531 if (inst.operands[1].present)
6532 inst.instruction |= 0x100 | inst.operands[1].imm;
6534 else
6536 constraint (inst.operands[1].present,
6537 _("Thumb does not support the 2-argument "
6538 "form of this instruction"));
6539 inst.instruction |= inst.operands[0].imm;
6543 /* THUMB CPY instruction (argument parse). */
6545 static void
6546 do_t_cpy (void)
6548 if (inst.size_req == 4)
6550 inst.instruction = THUMB_OP32 (T_MNEM_mov);
6551 inst.instruction |= inst.operands[0].reg << 8;
6552 inst.instruction |= inst.operands[1].reg;
6554 else
6556 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6557 inst.instruction |= (inst.operands[0].reg & 0x7);
6558 inst.instruction |= inst.operands[1].reg << 3;
6562 static void
6563 do_t_czb (void)
6565 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6566 inst.instruction |= inst.operands[0].reg;
6567 inst.reloc.pc_rel = 1;
6568 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
6571 static void
6572 do_t_hint (void)
6574 if (unified_syntax && inst.size_req == 4)
6575 inst.instruction = THUMB_OP32 (inst.instruction);
6576 else
6577 inst.instruction = THUMB_OP16 (inst.instruction);
6580 static void
6581 do_t_it (void)
6583 unsigned int cond = inst.operands[0].imm;
6585 current_it_mask = (inst.instruction & 0xf) | 0x10;
6586 current_cc = cond;
6588 /* If the condition is a negative condition, invert the mask. */
6589 if ((cond & 0x1) == 0x0)
6591 unsigned int mask = inst.instruction & 0x000f;
6593 if ((mask & 0x7) == 0)
6594 /* no conversion needed */;
6595 else if ((mask & 0x3) == 0)
6596 mask ^= 0x8;
6597 else if ((mask & 0x1) == 0)
6598 mask ^= 0xC;
6599 else
6600 mask ^= 0xE;
6602 inst.instruction &= 0xfff0;
6603 inst.instruction |= mask;
6606 inst.instruction |= cond << 4;
6609 static void
6610 do_t_ldmstm (void)
6612 /* This really doesn't seem worth it. */
6613 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6614 _("expression too complex"));
6615 constraint (inst.operands[1].writeback,
6616 _("Thumb load/store multiple does not support {reglist}^"));
6618 if (unified_syntax)
6620 /* See if we can use a 16-bit instruction. */
6621 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
6622 && inst.size_req != 4
6623 && inst.operands[0].reg <= 7
6624 && !(inst.operands[1].imm & ~0xff)
6625 && (inst.instruction == T_MNEM_stmia
6626 ? inst.operands[0].writeback
6627 : (inst.operands[0].writeback
6628 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
6630 if (inst.instruction == T_MNEM_stmia
6631 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
6632 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6633 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6634 inst.operands[0].reg);
6636 inst.instruction = THUMB_OP16 (inst.instruction);
6637 inst.instruction |= inst.operands[0].reg << 8;
6638 inst.instruction |= inst.operands[1].imm;
6640 else
6642 if (inst.operands[1].imm & (1 << 13))
6643 as_warn (_("SP should not be in register list"));
6644 if (inst.instruction == T_MNEM_stmia)
6646 if (inst.operands[1].imm & (1 << 15))
6647 as_warn (_("PC should not be in register list"));
6648 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
6649 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6650 inst.operands[0].reg);
6652 else
6654 if (inst.operands[1].imm & (1 << 14)
6655 && inst.operands[1].imm & (1 << 15))
6656 as_warn (_("LR and PC should not both be in register list"));
6657 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6658 && inst.operands[0].writeback)
6659 as_warn (_("base register should not be in register list "
6660 "when written back"));
6662 if (inst.instruction < 0xffff)
6663 inst.instruction = THUMB_OP32 (inst.instruction);
6664 inst.instruction |= inst.operands[0].reg << 16;
6665 inst.instruction |= inst.operands[1].imm;
6666 if (inst.operands[0].writeback)
6667 inst.instruction |= WRITE_BACK;
6670 else
6672 constraint (inst.operands[0].reg > 7
6673 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
6674 if (inst.instruction == T_MNEM_stmia)
6676 if (!inst.operands[0].writeback)
6677 as_warn (_("this instruction will write back the base register"));
6678 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6679 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6680 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6681 inst.operands[0].reg);
6683 else
6685 if (!inst.operands[0].writeback
6686 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
6687 as_warn (_("this instruction will write back the base register"));
6688 else if (inst.operands[0].writeback
6689 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
6690 as_warn (_("this instruction will not write back the base register"));
6693 inst.instruction = THUMB_OP16 (inst.instruction);
6694 inst.instruction |= inst.operands[0].reg << 8;
6695 inst.instruction |= inst.operands[1].imm;
6699 static void
6700 do_t_ldrex (void)
6702 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6703 || inst.operands[1].postind || inst.operands[1].writeback
6704 || inst.operands[1].immisreg || inst.operands[1].shifted
6705 || inst.operands[1].negative,
6706 _("instruction does not accept this addressing mode"));
6708 inst.instruction |= inst.operands[0].reg << 12;
6709 inst.instruction |= inst.operands[1].reg << 16;
6710 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
6713 static void
6714 do_t_ldrexd (void)
6716 if (!inst.operands[1].present)
6718 constraint (inst.operands[0].reg == REG_LR,
6719 _("r14 not allowed as first register "
6720 "when second register is omitted"));
6721 inst.operands[1].reg = inst.operands[0].reg + 1;
6723 constraint (inst.operands[0].reg == inst.operands[1].reg,
6724 BAD_OVERLAP);
6726 inst.instruction |= inst.operands[0].reg << 12;
6727 inst.instruction |= inst.operands[1].reg << 8;
6728 inst.instruction |= inst.operands[2].reg << 16;
6731 static void
6732 do_t_ldst (void)
6734 unsigned long opcode;
6735 int Rn;
6737 opcode = inst.instruction;
6738 if (unified_syntax)
6740 if (inst.operands[1].isreg
6741 && !inst.operands[1].writeback
6742 && !inst.operands[1].shifted && !inst.operands[1].postind
6743 && !inst.operands[1].negative && inst.operands[0].reg <= 7
6744 && opcode <= 0xffff
6745 && inst.size_req != 4)
6747 /* Insn may have a 16-bit form. */
6748 Rn = inst.operands[1].reg;
6749 if (inst.operands[1].immisreg)
6751 inst.instruction = THUMB_OP16 (opcode);
6752 /* [Rn, Ri] */
6753 if (Rn <= 7 && inst.operands[1].imm <= 7)
6754 goto op16;
6756 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
6757 && opcode != T_MNEM_ldrsb)
6758 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
6759 || (Rn == REG_SP && opcode == T_MNEM_str))
6761 /* [Rn, #const] */
6762 if (Rn > 7)
6764 if (Rn == REG_PC)
6766 if (inst.reloc.pc_rel)
6767 opcode = T_MNEM_ldr_pc2;
6768 else
6769 opcode = T_MNEM_ldr_pc;
6771 else
6773 if (opcode == T_MNEM_ldr)
6774 opcode = T_MNEM_ldr_sp;
6775 else
6776 opcode = T_MNEM_str_sp;
6778 inst.instruction = inst.operands[0].reg << 8;
6780 else
6782 inst.instruction = inst.operands[0].reg;
6783 inst.instruction |= inst.operands[1].reg << 3;
6785 inst.instruction |= THUMB_OP16 (opcode);
6786 if (inst.size_req == 2)
6787 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6788 else
6789 inst.relax = opcode;
6790 return;
6793 /* Definitely a 32-bit variant. */
6794 inst.instruction = THUMB_OP32 (opcode);
6795 inst.instruction |= inst.operands[0].reg << 12;
6796 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
6797 return;
6800 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6802 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
6804 /* Only [Rn,Rm] is acceptable. */
6805 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
6806 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
6807 || inst.operands[1].postind || inst.operands[1].shifted
6808 || inst.operands[1].negative,
6809 _("Thumb does not support this addressing mode"));
6810 inst.instruction = THUMB_OP16 (inst.instruction);
6811 goto op16;
6814 inst.instruction = THUMB_OP16 (inst.instruction);
6815 if (!inst.operands[1].isreg)
6816 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
6817 return;
6819 constraint (!inst.operands[1].preind
6820 || inst.operands[1].shifted
6821 || inst.operands[1].writeback,
6822 _("Thumb does not support this addressing mode"));
6823 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
6825 constraint (inst.instruction & 0x0600,
6826 _("byte or halfword not valid for base register"));
6827 constraint (inst.operands[1].reg == REG_PC
6828 && !(inst.instruction & THUMB_LOAD_BIT),
6829 _("r15 based store not allowed"));
6830 constraint (inst.operands[1].immisreg,
6831 _("invalid base register for register offset"));
6833 if (inst.operands[1].reg == REG_PC)
6834 inst.instruction = T_OPCODE_LDR_PC;
6835 else if (inst.instruction & THUMB_LOAD_BIT)
6836 inst.instruction = T_OPCODE_LDR_SP;
6837 else
6838 inst.instruction = T_OPCODE_STR_SP;
6840 inst.instruction |= inst.operands[0].reg << 8;
6841 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6842 return;
6845 constraint (inst.operands[1].reg > 7, BAD_HIREG);
6846 if (!inst.operands[1].immisreg)
6848 /* Immediate offset. */
6849 inst.instruction |= inst.operands[0].reg;
6850 inst.instruction |= inst.operands[1].reg << 3;
6851 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6852 return;
6855 /* Register offset. */
6856 constraint (inst.operands[1].imm > 7, BAD_HIREG);
6857 constraint (inst.operands[1].negative,
6858 _("Thumb does not support this addressing mode"));
6860 op16:
6861 switch (inst.instruction)
6863 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
6864 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
6865 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
6866 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
6867 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
6868 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
6869 case 0x5600 /* ldrsb */:
6870 case 0x5e00 /* ldrsh */: break;
6871 default: abort ();
6874 inst.instruction |= inst.operands[0].reg;
6875 inst.instruction |= inst.operands[1].reg << 3;
6876 inst.instruction |= inst.operands[1].imm << 6;
6879 static void
6880 do_t_ldstd (void)
6882 if (!inst.operands[1].present)
6884 inst.operands[1].reg = inst.operands[0].reg + 1;
6885 constraint (inst.operands[0].reg == REG_LR,
6886 _("r14 not allowed here"));
6888 inst.instruction |= inst.operands[0].reg << 12;
6889 inst.instruction |= inst.operands[1].reg << 8;
6890 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
6894 static void
6895 do_t_ldstt (void)
6897 inst.instruction |= inst.operands[0].reg << 12;
6898 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
6901 static void
6902 do_t_mla (void)
6904 inst.instruction |= inst.operands[0].reg << 8;
6905 inst.instruction |= inst.operands[1].reg << 16;
6906 inst.instruction |= inst.operands[2].reg;
6907 inst.instruction |= inst.operands[3].reg << 12;
6910 static void
6911 do_t_mlal (void)
6913 inst.instruction |= inst.operands[0].reg << 12;
6914 inst.instruction |= inst.operands[1].reg << 8;
6915 inst.instruction |= inst.operands[2].reg << 16;
6916 inst.instruction |= inst.operands[3].reg;
6919 static void
6920 do_t_mov_cmp (void)
6922 if (unified_syntax)
6924 int r0off = (inst.instruction == T_MNEM_mov
6925 || inst.instruction == T_MNEM_movs) ? 8 : 16;
6926 unsigned long opcode;
6927 bfd_boolean narrow;
6928 bfd_boolean low_regs;
6930 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
6931 opcode = inst.instruction;
6932 if (current_it_mask)
6933 narrow = opcode != T_MNEM_movs;
6934 else
6935 narrow = opcode != T_MNEM_movs || low_regs;
6936 if (inst.size_req == 4
6937 || inst.operands[1].shifted)
6938 narrow = FALSE;
6940 if (!inst.operands[1].isreg)
6942 /* Immediate operand. */
6943 if (current_it_mask == 0 && opcode == T_MNEM_mov)
6944 narrow = 0;
6945 if (low_regs && narrow)
6947 inst.instruction = THUMB_OP16 (opcode);
6948 inst.instruction |= inst.operands[0].reg << 8;
6949 if (inst.size_req == 2)
6950 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
6951 else
6952 inst.relax = opcode;
6954 else
6956 inst.instruction = THUMB_OP32 (inst.instruction);
6957 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6958 inst.instruction |= inst.operands[0].reg << r0off;
6959 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6962 else if (!narrow)
6964 inst.instruction = THUMB_OP32 (inst.instruction);
6965 inst.instruction |= inst.operands[0].reg << r0off;
6966 encode_thumb32_shifted_operand (1);
6968 else
6969 switch (inst.instruction)
6971 case T_MNEM_mov:
6972 inst.instruction = T_OPCODE_MOV_HR;
6973 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6974 inst.instruction |= (inst.operands[0].reg & 0x7);
6975 inst.instruction |= inst.operands[1].reg << 3;
6976 break;
6978 case T_MNEM_movs:
6979 /* We know we have low registers at this point.
6980 Generate ADD Rd, Rs, #0. */
6981 inst.instruction = T_OPCODE_ADD_I3;
6982 inst.instruction |= inst.operands[0].reg;
6983 inst.instruction |= inst.operands[1].reg << 3;
6984 break;
6986 case T_MNEM_cmp:
6987 if (low_regs)
6989 inst.instruction = T_OPCODE_CMP_LR;
6990 inst.instruction |= inst.operands[0].reg;
6991 inst.instruction |= inst.operands[1].reg << 3;
6993 else
6995 inst.instruction = T_OPCODE_CMP_HR;
6996 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6997 inst.instruction |= (inst.operands[0].reg & 0x7);
6998 inst.instruction |= inst.operands[1].reg << 3;
7000 break;
7002 return;
7005 inst.instruction = THUMB_OP16 (inst.instruction);
7006 if (inst.operands[1].isreg)
7008 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
7010 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
7011 since a MOV instruction produces unpredictable results. */
7012 if (inst.instruction == T_OPCODE_MOV_I8)
7013 inst.instruction = T_OPCODE_ADD_I3;
7014 else
7015 inst.instruction = T_OPCODE_CMP_LR;
7017 inst.instruction |= inst.operands[0].reg;
7018 inst.instruction |= inst.operands[1].reg << 3;
7020 else
7022 if (inst.instruction == T_OPCODE_MOV_I8)
7023 inst.instruction = T_OPCODE_MOV_HR;
7024 else
7025 inst.instruction = T_OPCODE_CMP_HR;
7026 do_t_cpy ();
7029 else
7031 constraint (inst.operands[0].reg > 7,
7032 _("only lo regs allowed with immediate"));
7033 inst.instruction |= inst.operands[0].reg << 8;
7034 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
7038 static void
7039 do_t_mov16 (void)
7041 inst.instruction |= inst.operands[0].reg << 8;
7042 inst.instruction |= (inst.operands[1].imm & 0xf000) << 4;
7043 inst.instruction |= (inst.operands[1].imm & 0x0800) << 15;
7044 inst.instruction |= (inst.operands[1].imm & 0x0700) << 4;
7045 inst.instruction |= (inst.operands[1].imm & 0x00ff);
7048 static void
7049 do_t_mvn_tst (void)
7051 if (unified_syntax)
7053 int r0off = (inst.instruction == T_MNEM_mvn
7054 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
7055 bfd_boolean narrow;
7057 if (inst.size_req == 4
7058 || inst.instruction > 0xffff
7059 || inst.operands[1].shifted
7060 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7061 narrow = FALSE;
7062 else if (inst.instruction == T_MNEM_cmn)
7063 narrow = TRUE;
7064 else if (THUMB_SETS_FLAGS (inst.instruction))
7065 narrow = (current_it_mask == 0);
7066 else
7067 narrow = (current_it_mask != 0);
7069 if (!inst.operands[1].isreg)
7071 /* For an immediate, we always generate a 32-bit opcode;
7072 section relaxation will shrink it later if possible. */
7073 if (inst.instruction < 0xffff)
7074 inst.instruction = THUMB_OP32 (inst.instruction);
7075 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7076 inst.instruction |= inst.operands[0].reg << r0off;
7077 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7079 else
7081 /* See if we can do this with a 16-bit instruction. */
7082 if (narrow)
7084 inst.instruction = THUMB_OP16 (inst.instruction);
7085 inst.instruction |= inst.operands[0].reg;
7086 inst.instruction |= inst.operands[1].reg << 3;
7088 else
7090 constraint (inst.operands[1].shifted
7091 && inst.operands[1].immisreg,
7092 _("shift must be constant"));
7093 if (inst.instruction < 0xffff)
7094 inst.instruction = THUMB_OP32 (inst.instruction);
7095 inst.instruction |= inst.operands[0].reg << r0off;
7096 encode_thumb32_shifted_operand (1);
7100 else
7102 constraint (inst.instruction > 0xffff
7103 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
7104 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
7105 _("unshifted register required"));
7106 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7107 BAD_HIREG);
7109 inst.instruction = THUMB_OP16 (inst.instruction);
7110 inst.instruction |= inst.operands[0].reg;
7111 inst.instruction |= inst.operands[1].reg << 3;
7115 static void
7116 do_t_mrs (void)
7118 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7119 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7120 != (PSR_c|PSR_f),
7121 _("'CPSR' or 'SPSR' expected"));
7122 inst.instruction |= inst.operands[0].reg << 8;
7123 inst.instruction |= (inst.operands[1].imm & SPSR_BIT) >> 2;
7126 static void
7127 do_t_msr (void)
7129 constraint (!inst.operands[1].isreg,
7130 _("Thumb encoding does not support an immediate here"));
7131 inst.instruction |= (inst.operands[0].imm & SPSR_BIT) >> 2;
7132 inst.instruction |= (inst.operands[0].imm & ~SPSR_BIT) >> 8;
7133 inst.instruction |= inst.operands[1].reg << 16;
7136 static void
7137 do_t_mul (void)
7139 if (!inst.operands[2].present)
7140 inst.operands[2].reg = inst.operands[0].reg;
7142 /* There is no 32-bit MULS and no 16-bit MUL. */
7143 if (unified_syntax && inst.instruction == T_MNEM_mul)
7145 inst.instruction = THUMB_OP32 (inst.instruction);
7146 inst.instruction |= inst.operands[0].reg << 8;
7147 inst.instruction |= inst.operands[1].reg << 16;
7148 inst.instruction |= inst.operands[2].reg << 0;
7150 else
7152 constraint (!unified_syntax
7153 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
7154 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7155 BAD_HIREG);
7157 inst.instruction = THUMB_OP16 (inst.instruction);
7158 inst.instruction |= inst.operands[0].reg;
7160 if (inst.operands[0].reg == inst.operands[1].reg)
7161 inst.instruction |= inst.operands[2].reg << 3;
7162 else if (inst.operands[0].reg == inst.operands[2].reg)
7163 inst.instruction |= inst.operands[1].reg << 3;
7164 else
7165 constraint (1, _("dest must overlap one source register"));
7169 static void
7170 do_t_mull (void)
7172 inst.instruction |= inst.operands[0].reg << 12;
7173 inst.instruction |= inst.operands[1].reg << 8;
7174 inst.instruction |= inst.operands[2].reg << 16;
7175 inst.instruction |= inst.operands[3].reg;
7177 if (inst.operands[0].reg == inst.operands[1].reg)
7178 as_tsktsk (_("rdhi and rdlo must be different"));
7181 static void
7182 do_t_nop (void)
7184 if (unified_syntax)
7186 if (inst.size_req == 4 || inst.operands[0].imm > 15)
7188 inst.instruction = THUMB_OP32 (inst.instruction);
7189 inst.instruction |= inst.operands[0].imm;
7191 else
7193 inst.instruction = THUMB_OP16 (inst.instruction);
7194 inst.instruction |= inst.operands[0].imm << 4;
7197 else
7199 constraint (inst.operands[0].present,
7200 _("Thumb does not support NOP with hints"));
7201 inst.instruction = 0x46c0;
7205 static void
7206 do_t_neg (void)
7208 if (unified_syntax)
7210 bfd_boolean narrow;
7212 if (THUMB_SETS_FLAGS (inst.instruction))
7213 narrow = (current_it_mask == 0);
7214 else
7215 narrow = (current_it_mask != 0);
7216 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7217 narrow = FALSE;
7218 if (inst.size_req == 4)
7219 narrow = FALSE;
7221 if (!narrow)
7223 inst.instruction = THUMB_OP32 (inst.instruction);
7224 inst.instruction |= inst.operands[0].reg << 8;
7225 inst.instruction |= inst.operands[1].reg << 16;
7227 else
7229 inst.instruction = THUMB_OP16 (inst.instruction);
7230 inst.instruction |= inst.operands[0].reg;
7231 inst.instruction |= inst.operands[1].reg << 3;
7234 else
7236 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7237 BAD_HIREG);
7238 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
7240 inst.instruction = THUMB_OP16 (inst.instruction);
7241 inst.instruction |= inst.operands[0].reg;
7242 inst.instruction |= inst.operands[1].reg << 3;
7246 static void
7247 do_t_pkhbt (void)
7249 inst.instruction |= inst.operands[0].reg << 8;
7250 inst.instruction |= inst.operands[1].reg << 16;
7251 inst.instruction |= inst.operands[2].reg;
7252 if (inst.operands[3].present)
7254 unsigned int val = inst.reloc.exp.X_add_number;
7255 constraint (inst.reloc.exp.X_op != O_constant,
7256 _("expression too complex"));
7257 inst.instruction |= (val & 0x1c) << 10;
7258 inst.instruction |= (val & 0x03) << 6;
7262 static void
7263 do_t_pkhtb (void)
7265 if (!inst.operands[3].present)
7266 inst.instruction &= ~0x00000020;
7267 do_t_pkhbt ();
7270 static void
7271 do_t_pld (void)
7273 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
7276 static void
7277 do_t_push_pop (void)
7279 unsigned mask;
7281 constraint (inst.operands[0].writeback,
7282 _("push/pop do not support {reglist}^"));
7283 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
7284 _("expression too complex"));
7286 mask = inst.operands[0].imm;
7287 if ((mask & ~0xff) == 0)
7288 inst.instruction = THUMB_OP16 (inst.instruction);
7289 else if ((inst.instruction == T_MNEM_push
7290 && (mask & ~0xff) == 1 << REG_LR)
7291 || (inst.instruction == T_MNEM_pop
7292 && (mask & ~0xff) == 1 << REG_PC))
7294 inst.instruction = THUMB_OP16 (inst.instruction);
7295 inst.instruction |= THUMB_PP_PC_LR;
7296 mask &= 0xff;
7298 else if (unified_syntax)
7300 if (mask & (1 << 13))
7301 inst.error = _("SP not allowed in register list");
7302 if (inst.instruction == T_MNEM_push)
7304 if (mask & (1 << 15))
7305 inst.error = _("PC not allowed in register list");
7307 else
7309 if (mask & (1 << 14)
7310 && mask & (1 << 15))
7311 inst.error = _("LR and PC should not both be in register list");
7313 if ((mask & (mask - 1)) == 0)
7315 /* Single register push/pop implemented as str/ldr. */
7316 if (inst.instruction == T_MNEM_push)
7317 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
7318 else
7319 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
7320 mask = ffs(mask) - 1;
7321 mask <<= 12;
7323 else
7324 inst.instruction = THUMB_OP32 (inst.instruction);
7326 else
7328 inst.error = _("invalid register list to push/pop instruction");
7329 return;
7332 inst.instruction |= mask;
7335 static void
7336 do_t_rbit (void)
7338 inst.instruction |= inst.operands[0].reg << 8;
7339 inst.instruction |= inst.operands[1].reg << 16;
7342 static void
7343 do_t_rev (void)
7345 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7346 && inst.size_req != 4)
7348 inst.instruction = THUMB_OP16 (inst.instruction);
7349 inst.instruction |= inst.operands[0].reg;
7350 inst.instruction |= inst.operands[1].reg << 3;
7352 else if (unified_syntax)
7354 inst.instruction = THUMB_OP32 (inst.instruction);
7355 inst.instruction |= inst.operands[0].reg << 8;
7356 inst.instruction |= inst.operands[1].reg << 16;
7357 inst.instruction |= inst.operands[1].reg;
7359 else
7360 inst.error = BAD_HIREG;
7363 static void
7364 do_t_rsb (void)
7366 int Rd, Rs;
7368 Rd = inst.operands[0].reg;
7369 Rs = (inst.operands[1].present
7370 ? inst.operands[1].reg /* Rd, Rs, foo */
7371 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
7373 inst.instruction |= Rd << 8;
7374 inst.instruction |= Rs << 16;
7375 if (!inst.operands[2].isreg)
7377 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7378 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7380 else
7381 encode_thumb32_shifted_operand (2);
7384 static void
7385 do_t_setend (void)
7387 if (inst.operands[0].imm)
7388 inst.instruction |= 0x8;
7391 static void
7392 do_t_shift (void)
7394 if (!inst.operands[1].present)
7395 inst.operands[1].reg = inst.operands[0].reg;
7397 if (unified_syntax)
7399 bfd_boolean narrow;
7400 int shift_kind;
7402 switch (inst.instruction)
7404 case T_MNEM_asr:
7405 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
7406 case T_MNEM_lsl:
7407 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
7408 case T_MNEM_lsr:
7409 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
7410 case T_MNEM_ror:
7411 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
7412 default: abort ();
7415 if (THUMB_SETS_FLAGS (inst.instruction))
7416 narrow = (current_it_mask == 0);
7417 else
7418 narrow = (current_it_mask != 0);
7419 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7420 narrow = FALSE;
7421 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
7422 narrow = FALSE;
7423 if (inst.operands[2].isreg
7424 && (inst.operands[1].reg != inst.operands[0].reg
7425 || inst.operands[2].reg > 7))
7426 narrow = FALSE;
7427 if (inst.size_req == 4)
7428 narrow = FALSE;
7430 if (!narrow)
7432 if (inst.operands[2].isreg)
7434 inst.instruction = THUMB_OP32 (inst.instruction);
7435 inst.instruction |= inst.operands[0].reg << 8;
7436 inst.instruction |= inst.operands[1].reg << 16;
7437 inst.instruction |= inst.operands[2].reg;
7439 else
7441 inst.operands[1].shifted = 1;
7442 inst.operands[1].shift_kind = shift_kind;
7443 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
7444 ? T_MNEM_movs : T_MNEM_mov);
7445 inst.instruction |= inst.operands[0].reg << 8;
7446 encode_thumb32_shifted_operand (1);
7447 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
7448 inst.reloc.type = BFD_RELOC_UNUSED;
7451 else
7453 if (inst.operands[2].isreg)
7455 switch (shift_kind)
7457 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
7458 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
7459 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
7460 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
7461 default: abort ();
7464 inst.instruction |= inst.operands[0].reg;
7465 inst.instruction |= inst.operands[2].reg << 3;
7467 else
7469 switch (shift_kind)
7471 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
7472 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
7473 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
7474 default: abort ();
7476 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7477 inst.instruction |= inst.operands[0].reg;
7478 inst.instruction |= inst.operands[1].reg << 3;
7482 else
7484 constraint (inst.operands[0].reg > 7
7485 || inst.operands[1].reg > 7, BAD_HIREG);
7486 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
7488 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
7490 constraint (inst.operands[2].reg > 7, BAD_HIREG);
7491 constraint (inst.operands[0].reg != inst.operands[1].reg,
7492 _("source1 and dest must be same register"));
7494 switch (inst.instruction)
7496 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
7497 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
7498 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
7499 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
7500 default: abort ();
7503 inst.instruction |= inst.operands[0].reg;
7504 inst.instruction |= inst.operands[2].reg << 3;
7506 else
7508 switch (inst.instruction)
7510 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
7511 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
7512 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
7513 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
7514 default: abort ();
7516 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7517 inst.instruction |= inst.operands[0].reg;
7518 inst.instruction |= inst.operands[1].reg << 3;
7523 static void
7524 do_t_simd (void)
7526 inst.instruction |= inst.operands[0].reg << 8;
7527 inst.instruction |= inst.operands[1].reg << 16;
7528 inst.instruction |= inst.operands[2].reg;
7531 static void
7532 do_t_smc (void)
7534 unsigned int value = inst.reloc.exp.X_add_number;
7535 constraint (inst.reloc.exp.X_op != O_constant,
7536 _("expression too complex"));
7537 inst.reloc.type = BFD_RELOC_UNUSED;
7538 inst.instruction |= (value & 0xf000) >> 12;
7539 inst.instruction |= (value & 0x0ff0);
7540 inst.instruction |= (value & 0x000f) << 16;
7543 static void
7544 do_t_ssat (void)
7546 inst.instruction |= inst.operands[0].reg << 8;
7547 inst.instruction |= inst.operands[1].imm - 1;
7548 inst.instruction |= inst.operands[2].reg << 16;
7550 if (inst.operands[3].present)
7552 constraint (inst.reloc.exp.X_op != O_constant,
7553 _("expression too complex"));
7555 if (inst.reloc.exp.X_add_number != 0)
7557 if (inst.operands[3].shift_kind == SHIFT_ASR)
7558 inst.instruction |= 0x00200000; /* sh bit */
7559 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7560 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7562 inst.reloc.type = BFD_RELOC_UNUSED;
7566 static void
7567 do_t_ssat16 (void)
7569 inst.instruction |= inst.operands[0].reg << 8;
7570 inst.instruction |= inst.operands[1].imm - 1;
7571 inst.instruction |= inst.operands[2].reg << 16;
7574 static void
7575 do_t_strex (void)
7577 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7578 || inst.operands[2].postind || inst.operands[2].writeback
7579 || inst.operands[2].immisreg || inst.operands[2].shifted
7580 || inst.operands[2].negative,
7581 _("instruction does not accept this addressing mode"));
7583 inst.instruction |= inst.operands[0].reg << 8;
7584 inst.instruction |= inst.operands[1].reg << 12;
7585 inst.instruction |= inst.operands[2].reg << 16;
7586 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
7589 static void
7590 do_t_strexd (void)
7592 if (!inst.operands[2].present)
7593 inst.operands[2].reg = inst.operands[1].reg + 1;
7595 constraint (inst.operands[0].reg == inst.operands[1].reg
7596 || inst.operands[0].reg == inst.operands[2].reg
7597 || inst.operands[0].reg == inst.operands[3].reg
7598 || inst.operands[1].reg == inst.operands[2].reg,
7599 BAD_OVERLAP);
7601 inst.instruction |= inst.operands[0].reg;
7602 inst.instruction |= inst.operands[1].reg << 12;
7603 inst.instruction |= inst.operands[2].reg << 8;
7604 inst.instruction |= inst.operands[3].reg << 16;
7607 static void
7608 do_t_sxtah (void)
7610 inst.instruction |= inst.operands[0].reg << 8;
7611 inst.instruction |= inst.operands[1].reg << 16;
7612 inst.instruction |= inst.operands[2].reg;
7613 inst.instruction |= inst.operands[3].imm << 4;
7616 static void
7617 do_t_sxth (void)
7619 if (inst.instruction <= 0xffff && inst.size_req != 4
7620 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7621 && (!inst.operands[2].present || inst.operands[2].imm == 0))
7623 inst.instruction = THUMB_OP16 (inst.instruction);
7624 inst.instruction |= inst.operands[0].reg;
7625 inst.instruction |= inst.operands[1].reg << 3;
7627 else if (unified_syntax)
7629 if (inst.instruction <= 0xffff)
7630 inst.instruction = THUMB_OP32 (inst.instruction);
7631 inst.instruction |= inst.operands[0].reg << 8;
7632 inst.instruction |= inst.operands[1].reg;
7633 inst.instruction |= inst.operands[2].imm << 4;
7635 else
7637 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
7638 _("Thumb encoding does not support rotation"));
7639 constraint (1, BAD_HIREG);
7643 static void
7644 do_t_swi (void)
7646 inst.reloc.type = BFD_RELOC_ARM_SWI;
7649 static void
7650 do_t_tb (void)
7652 int half;
7654 half = (inst.instruction & 0x10) != 0;
7655 constraint (inst.operands[0].imm == 15,
7656 _("PC is not a valid index register"));
7657 constraint (!half && inst.operands[0].shifted,
7658 _("instruction does not allow shifted index"));
7659 constraint (half && !inst.operands[0].shifted,
7660 _("instruction requires shifted index"));
7661 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
7664 static void
7665 do_t_usat (void)
7667 inst.instruction |= inst.operands[0].reg << 8;
7668 inst.instruction |= inst.operands[1].imm;
7669 inst.instruction |= inst.operands[2].reg << 16;
7671 if (inst.operands[3].present)
7673 constraint (inst.reloc.exp.X_op != O_constant,
7674 _("expression too complex"));
7675 if (inst.reloc.exp.X_add_number != 0)
7677 if (inst.operands[3].shift_kind == SHIFT_ASR)
7678 inst.instruction |= 0x00200000; /* sh bit */
7680 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7681 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7683 inst.reloc.type = BFD_RELOC_UNUSED;
7687 static void
7688 do_t_usat16 (void)
7690 inst.instruction |= inst.operands[0].reg << 8;
7691 inst.instruction |= inst.operands[1].imm;
7692 inst.instruction |= inst.operands[2].reg << 16;
7695 /* Overall per-instruction processing. */
7697 /* We need to be able to fix up arbitrary expressions in some statements.
7698 This is so that we can handle symbols that are an arbitrary distance from
7699 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
7700 which returns part of an address in a form which will be valid for
7701 a data instruction. We do this by pushing the expression into a symbol
7702 in the expr_section, and creating a fix for that. */
7704 static void
7705 fix_new_arm (fragS * frag,
7706 int where,
7707 short int size,
7708 expressionS * exp,
7709 int pc_rel,
7710 int reloc)
7712 fixS * new_fix;
7714 switch (exp->X_op)
7716 case O_constant:
7717 case O_symbol:
7718 case O_add:
7719 case O_subtract:
7720 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
7721 break;
7723 default:
7724 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
7725 pc_rel, reloc);
7726 break;
7729 /* Mark whether the fix is to a THUMB instruction, or an ARM
7730 instruction. */
7731 new_fix->tc_fix_data = thumb_mode;
7734 /* Create a frg for an instruction requiring relaxation. */
7735 static void
7736 output_relax_insn (void)
7738 char * to;
7739 symbolS *sym;
7740 int offset;
7742 switch (inst.reloc.exp.X_op)
7744 case O_symbol:
7745 sym = inst.reloc.exp.X_add_symbol;
7746 offset = inst.reloc.exp.X_add_number;
7747 break;
7748 case O_constant:
7749 sym = NULL;
7750 offset = inst.reloc.exp.X_add_number;
7751 break;
7752 default:
7753 sym = make_expr_symbol (&inst.reloc.exp);
7754 offset = 0;
7755 break;
7757 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
7758 inst.relax, sym, offset, NULL/*offset, opcode*/);
7759 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
7761 #ifdef OBJ_ELF
7762 dwarf2_emit_insn (INSN_SIZE);
7763 #endif
7766 /* Write a 32-bit thumb instruction to buf. */
7767 static void
7768 put_thumb32_insn (char * buf, unsigned long insn)
7770 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
7771 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
7774 static void
7775 output_inst (const char * str)
7777 char * to = NULL;
7779 if (inst.error)
7781 as_bad ("%s -- `%s'", inst.error, str);
7782 return;
7784 if (inst.relax) {
7785 output_relax_insn();
7786 return;
7788 if (inst.size == 0)
7789 return;
7791 to = frag_more (inst.size);
7793 if (thumb_mode && (inst.size > THUMB_SIZE))
7795 assert (inst.size == (2 * THUMB_SIZE));
7796 put_thumb32_insn (to, inst.instruction);
7798 else if (inst.size > INSN_SIZE)
7800 assert (inst.size == (2 * INSN_SIZE));
7801 md_number_to_chars (to, inst.instruction, INSN_SIZE);
7802 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
7804 else
7805 md_number_to_chars (to, inst.instruction, inst.size);
7807 if (inst.reloc.type != BFD_RELOC_UNUSED)
7808 fix_new_arm (frag_now, to - frag_now->fr_literal,
7809 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
7810 inst.reloc.type);
7812 #ifdef OBJ_ELF
7813 dwarf2_emit_insn (inst.size);
7814 #endif
7817 /* Tag values used in struct asm_opcode's tag field. */
7818 enum opcode_tag
7820 OT_unconditional, /* Instruction cannot be conditionalized.
7821 The ARM condition field is still 0xE. */
7822 OT_unconditionalF, /* Instruction cannot be conditionalized
7823 and carries 0xF in its ARM condition field. */
7824 OT_csuffix, /* Instruction takes a conditional suffix. */
7825 OT_cinfix3, /* Instruction takes a conditional infix,
7826 beginning at character index 3. (In
7827 unified mode, it becomes a suffix.) */
7828 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
7829 character index 3, even in unified mode. Used for
7830 legacy instructions where suffix and infix forms
7831 may be ambiguous. */
7832 OT_csuf_or_in3, /* Instruction takes either a conditional
7833 suffix or an infix at character index 3. */
7834 OT_odd_infix_unc, /* This is the unconditional variant of an
7835 instruction that takes a conditional infix
7836 at an unusual position. In unified mode,
7837 this variant will accept a suffix. */
7838 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
7839 are the conditional variants of instructions that
7840 take conditional infixes in unusual positions.
7841 The infix appears at character index
7842 (tag - OT_odd_infix_0). These are not accepted
7843 in unified mode. */
7846 /* Subroutine of md_assemble, responsible for looking up the primary
7847 opcode from the mnemonic the user wrote. STR points to the
7848 beginning of the mnemonic.
7850 This is not simply a hash table lookup, because of conditional
7851 variants. Most instructions have conditional variants, which are
7852 expressed with a _conditional affix_ to the mnemonic. If we were
7853 to encode each conditional variant as a literal string in the opcode
7854 table, it would have approximately 20,000 entries.
7856 Most mnemonics take this affix as a suffix, and in unified syntax,
7857 'most' is upgraded to 'all'. However, in the divided syntax, some
7858 instructions take the affix as an infix, notably the s-variants of
7859 the arithmetic instructions. Of those instructions, all but six
7860 have the infix appear after the third character of the mnemonic.
7862 Accordingly, the algorithm for looking up primary opcodes given
7863 an identifier is:
7865 1. Look up the identifier in the opcode table.
7866 If we find a match, go to step U.
7868 2. Look up the last two characters of the identifier in the
7869 conditions table. If we find a match, look up the first N-2
7870 characters of the identifier in the opcode table. If we
7871 find a match, go to step CE.
7873 3. Look up the fourth and fifth characters of the identifier in
7874 the conditions table. If we find a match, extract those
7875 characters from the identifier, and look up the remaining
7876 characters in the opcode table. If we find a match, go
7877 to step CM.
7879 4. Fail.
7881 U. Examine the tag field of the opcode structure, in case this is
7882 one of the six instructions with its conditional infix in an
7883 unusual place. If it is, the tag tells us where to find the
7884 infix; look it up in the conditions table and set inst.cond
7885 accordingly. Otherwise, this is an unconditional instruction.
7886 Again set inst.cond accordingly. Return the opcode structure.
7888 CE. Examine the tag field to make sure this is an instruction that
7889 should receive a conditional suffix. If it is not, fail.
7890 Otherwise, set inst.cond from the suffix we already looked up,
7891 and return the opcode structure.
7893 CM. Examine the tag field to make sure this is an instruction that
7894 should receive a conditional infix after the third character.
7895 If it is not, fail. Otherwise, undo the edits to the current
7896 line of input and proceed as for case CE. */
7898 static const struct asm_opcode *
7899 opcode_lookup (char **str)
7901 char *end, *base;
7902 char *affix;
7903 const struct asm_opcode *opcode;
7904 const struct asm_cond *cond;
7905 char save[2];
7907 /* Scan up to the end of the mnemonic, which must end in white space,
7908 '.' (in unified mode only), or end of string. */
7909 for (base = end = *str; *end != '\0'; end++)
7910 if (*end == ' ' || (unified_syntax && *end == '.'))
7911 break;
7913 if (end == base)
7914 return 0;
7916 /* Handle a possible width suffix. */
7917 if (end[0] == '.')
7919 if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0'))
7920 inst.size_req = 4;
7921 else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0'))
7922 inst.size_req = 2;
7923 else
7924 return 0;
7926 *str = end + 2;
7928 else
7929 *str = end;
7931 /* Look for unaffixed or special-case affixed mnemonic. */
7932 opcode = hash_find_n (arm_ops_hsh, base, end - base);
7933 if (opcode)
7935 /* step U */
7936 if (opcode->tag < OT_odd_infix_0)
7938 inst.cond = COND_ALWAYS;
7939 return opcode;
7942 if (unified_syntax)
7943 as_warn (_("conditional infixes are deprecated in unified syntax"));
7944 affix = base + (opcode->tag - OT_odd_infix_0);
7945 cond = hash_find_n (arm_cond_hsh, affix, 2);
7946 assert (cond);
7948 inst.cond = cond->value;
7949 return opcode;
7952 /* Cannot have a conditional suffix on a mnemonic of less than two
7953 characters. */
7954 if (end - base < 3)
7955 return 0;
7957 /* Look for suffixed mnemonic. */
7958 affix = end - 2;
7959 cond = hash_find_n (arm_cond_hsh, affix, 2);
7960 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
7961 if (opcode && cond)
7963 /* step CE */
7964 switch (opcode->tag)
7966 case OT_cinfix3_legacy:
7967 /* Ignore conditional suffixes matched on infix only mnemonics. */
7968 break;
7970 case OT_cinfix3:
7971 case OT_odd_infix_unc:
7972 if (!unified_syntax)
7973 return 0;
7974 /* else fall through */
7976 case OT_csuffix:
7977 case OT_csuf_or_in3:
7978 inst.cond = cond->value;
7979 return opcode;
7981 case OT_unconditional:
7982 case OT_unconditionalF:
7983 /* delayed diagnostic */
7984 inst.error = BAD_COND;
7985 inst.cond = COND_ALWAYS;
7986 return opcode;
7988 default:
7989 return 0;
7993 /* Cannot have a usual-position infix on a mnemonic of less than
7994 six characters (five would be a suffix). */
7995 if (end - base < 6)
7996 return 0;
7998 /* Look for infixed mnemonic in the usual position. */
7999 affix = base + 3;
8000 cond = hash_find_n (arm_cond_hsh, affix, 2);
8001 if (!cond)
8002 return 0;
8004 memcpy (save, affix, 2);
8005 memmove (affix, affix + 2, (end - affix) - 2);
8006 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
8007 memmove (affix + 2, affix, (end - affix) - 2);
8008 memcpy (affix, save, 2);
8010 if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3
8011 || opcode->tag == OT_cinfix3_legacy))
8013 /* step CM */
8014 if (unified_syntax && opcode->tag == OT_cinfix3)
8015 as_warn (_("conditional infixes are deprecated in unified syntax"));
8017 inst.cond = cond->value;
8018 return opcode;
8021 return 0;
8024 void
8025 md_assemble (char *str)
8027 char *p = str;
8028 const struct asm_opcode * opcode;
8030 /* Align the previous label if needed. */
8031 if (last_label_seen != NULL)
8033 symbol_set_frag (last_label_seen, frag_now);
8034 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
8035 S_SET_SEGMENT (last_label_seen, now_seg);
8038 memset (&inst, '\0', sizeof (inst));
8039 inst.reloc.type = BFD_RELOC_UNUSED;
8041 opcode = opcode_lookup (&p);
8042 if (!opcode)
8044 /* It wasn't an instruction, but it might be a register alias of
8045 the form alias .req reg. */
8046 if (!create_register_alias (str, p))
8047 as_bad (_("bad instruction `%s'"), str);
8049 return;
8052 if (thumb_mode)
8054 unsigned long variant;
8056 variant = cpu_variant;
8057 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
8058 if ((variant & ARM_EXT_V6T2) == 0)
8059 variant &= ARM_ANY;
8060 /* Check that this instruction is supported for this CPU. */
8061 if (thumb_mode == 1 && (opcode->tvariant & variant) == 0)
8063 as_bad (_("selected processor does not support `%s'"), str);
8064 return;
8066 if (inst.cond != COND_ALWAYS && !unified_syntax
8067 && opcode->tencode != do_t_branch)
8069 as_bad (_("Thumb does not support conditional execution"));
8070 return;
8073 /* Check conditional suffixes. */
8074 if (current_it_mask)
8076 int cond;
8077 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
8078 if (cond != inst.cond)
8080 as_bad (_("incorrect condition in IT block"));
8081 return;
8083 current_it_mask <<= 1;
8084 current_it_mask &= 0x1f;
8086 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
8088 as_bad (_("thumb conditional instrunction not in IT block"));
8089 return;
8092 mapping_state (MAP_THUMB);
8093 inst.instruction = opcode->tvalue;
8095 if (!parse_operands (p, opcode->operands))
8096 opcode->tencode ();
8098 /* Clear current_it_mask at the end of an IT block. */
8099 if (current_it_mask == 0x10)
8100 current_it_mask = 0;
8102 if (!(inst.error || inst.relax))
8104 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
8105 inst.size = (inst.instruction > 0xffff ? 4 : 2);
8106 if (inst.size_req && inst.size_req != inst.size)
8108 as_bad (_("cannot honor width suffix -- `%s'"), str);
8109 return;
8112 thumb_arch_used |= opcode->tvariant;
8113 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
8114 set those bits when Thumb-2 32-bit instuctions are seen. ie.
8115 anything other than bl/blx.
8116 This is overly pessimistic for relaxable instructions. */
8117 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
8118 || inst.relax)
8119 thumb_arch_used |= ARM_EXT_V6T2;
8121 else
8123 /* Check that this instruction is supported for this CPU. */
8124 if ((opcode->avariant & cpu_variant) == 0)
8126 as_bad (_("selected processor does not support `%s'"), str);
8127 return;
8129 if (inst.size_req)
8131 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
8132 return;
8135 mapping_state (MAP_ARM);
8136 inst.instruction = opcode->avalue;
8137 if (opcode->tag == OT_unconditionalF)
8138 inst.instruction |= 0xF << 28;
8139 else
8140 inst.instruction |= inst.cond << 28;
8141 inst.size = INSN_SIZE;
8142 if (!parse_operands (p, opcode->operands))
8143 opcode->aencode ();
8144 /* Arm mode bx is marked as both v4T and v5 because it's still required
8145 on a hypothetical non-thumb v5 core. */
8146 if (opcode->avariant == (ARM_EXT_V4T | ARM_EXT_V5))
8147 arm_arch_used |= ARM_EXT_V4T;
8148 else
8149 arm_arch_used |= opcode->avariant;
8151 output_inst (str);
8154 /* Various frobbings of labels and their addresses. */
8156 void
8157 arm_start_line_hook (void)
8159 last_label_seen = NULL;
8162 void
8163 arm_frob_label (symbolS * sym)
8165 last_label_seen = sym;
8167 ARM_SET_THUMB (sym, thumb_mode);
8169 #if defined OBJ_COFF || defined OBJ_ELF
8170 ARM_SET_INTERWORK (sym, support_interwork);
8171 #endif
8173 /* Note - do not allow local symbols (.Lxxx) to be labeled
8174 as Thumb functions. This is because these labels, whilst
8175 they exist inside Thumb code, are not the entry points for
8176 possible ARM->Thumb calls. Also, these labels can be used
8177 as part of a computed goto or switch statement. eg gcc
8178 can generate code that looks like this:
8180 ldr r2, [pc, .Laaa]
8181 lsl r3, r3, #2
8182 ldr r2, [r3, r2]
8183 mov pc, r2
8185 .Lbbb: .word .Lxxx
8186 .Lccc: .word .Lyyy
8187 ..etc...
8188 .Laaa: .word Lbbb
8190 The first instruction loads the address of the jump table.
8191 The second instruction converts a table index into a byte offset.
8192 The third instruction gets the jump address out of the table.
8193 The fourth instruction performs the jump.
8195 If the address stored at .Laaa is that of a symbol which has the
8196 Thumb_Func bit set, then the linker will arrange for this address
8197 to have the bottom bit set, which in turn would mean that the
8198 address computation performed by the third instruction would end
8199 up with the bottom bit set. Since the ARM is capable of unaligned
8200 word loads, the instruction would then load the incorrect address
8201 out of the jump table, and chaos would ensue. */
8202 if (label_is_thumb_function_name
8203 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
8204 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
8206 /* When the address of a Thumb function is taken the bottom
8207 bit of that address should be set. This will allow
8208 interworking between Arm and Thumb functions to work
8209 correctly. */
8211 THUMB_SET_FUNC (sym, 1);
8213 label_is_thumb_function_name = FALSE;
8216 #ifdef OBJ_ELF
8217 dwarf2_emit_label (sym);
8218 #endif
8222 arm_data_in_code (void)
8224 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
8226 *input_line_pointer = '/';
8227 input_line_pointer += 5;
8228 *input_line_pointer = 0;
8229 return 1;
8232 return 0;
8235 char *
8236 arm_canonicalize_symbol_name (char * name)
8238 int len;
8240 if (thumb_mode && (len = strlen (name)) > 5
8241 && streq (name + len - 5, "/data"))
8242 *(name + len - 5) = 0;
8244 return name;
8247 /* Table of all register names defined by default. The user can
8248 define additional names with .req. Note that all register names
8249 should appear in both upper and lowercase variants. Some registers
8250 also have mixed-case names. */
8252 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE }
8253 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
8254 #define REGSET(p,t) \
8255 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
8256 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
8257 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
8258 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
8260 static const struct reg_entry reg_names[] =
8262 /* ARM integer registers. */
8263 REGSET(r, RN), REGSET(R, RN),
8265 /* ATPCS synonyms. */
8266 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
8267 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
8268 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
8270 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
8271 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
8272 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
8274 /* Well-known aliases. */
8275 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
8276 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
8278 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
8279 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
8281 /* Coprocessor numbers. */
8282 REGSET(p, CP), REGSET(P, CP),
8284 /* Coprocessor register numbers. The "cr" variants are for backward
8285 compatibility. */
8286 REGSET(c, CN), REGSET(C, CN),
8287 REGSET(cr, CN), REGSET(CR, CN),
8289 /* FPA registers. */
8290 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
8291 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
8293 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
8294 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
8296 /* VFP SP registers. */
8297 REGSET(s,VFS),
8298 REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS),
8299 REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS),
8300 REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS),
8301 REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS),
8303 REGSET(S,VFS),
8304 REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS),
8305 REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS),
8306 REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS),
8307 REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS),
8309 /* VFP DP Registers. */
8310 REGSET(d,VFD), REGSET(D,VFS),
8312 /* VFP control registers. */
8313 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
8314 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
8316 /* Maverick DSP coprocessor registers. */
8317 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
8318 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
8320 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
8321 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
8322 REGDEF(dspsc,0,DSPSC),
8324 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
8325 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
8326 REGDEF(DSPSC,0,DSPSC),
8328 /* iWMMXt data registers - p0, c0-15. */
8329 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
8331 /* iWMMXt control registers - p1, c0-3. */
8332 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
8333 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
8334 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
8335 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
8337 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
8338 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
8339 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
8340 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
8341 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
8343 /* XScale accumulator registers. */
8344 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
8346 #undef REGDEF
8347 #undef REGNUM
8348 #undef REGSET
8350 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
8351 within psr_required_here. */
8352 static const struct asm_psr psrs[] =
8354 /* Backward compatibility notation. Note that "all" is no longer
8355 truly all possible PSR bits. */
8356 {"all", PSR_c | PSR_f},
8357 {"flg", PSR_f},
8358 {"ctl", PSR_c},
8360 /* Individual flags. */
8361 {"f", PSR_f},
8362 {"c", PSR_c},
8363 {"x", PSR_x},
8364 {"s", PSR_s},
8365 /* Combinations of flags. */
8366 {"fs", PSR_f | PSR_s},
8367 {"fx", PSR_f | PSR_x},
8368 {"fc", PSR_f | PSR_c},
8369 {"sf", PSR_s | PSR_f},
8370 {"sx", PSR_s | PSR_x},
8371 {"sc", PSR_s | PSR_c},
8372 {"xf", PSR_x | PSR_f},
8373 {"xs", PSR_x | PSR_s},
8374 {"xc", PSR_x | PSR_c},
8375 {"cf", PSR_c | PSR_f},
8376 {"cs", PSR_c | PSR_s},
8377 {"cx", PSR_c | PSR_x},
8378 {"fsx", PSR_f | PSR_s | PSR_x},
8379 {"fsc", PSR_f | PSR_s | PSR_c},
8380 {"fxs", PSR_f | PSR_x | PSR_s},
8381 {"fxc", PSR_f | PSR_x | PSR_c},
8382 {"fcs", PSR_f | PSR_c | PSR_s},
8383 {"fcx", PSR_f | PSR_c | PSR_x},
8384 {"sfx", PSR_s | PSR_f | PSR_x},
8385 {"sfc", PSR_s | PSR_f | PSR_c},
8386 {"sxf", PSR_s | PSR_x | PSR_f},
8387 {"sxc", PSR_s | PSR_x | PSR_c},
8388 {"scf", PSR_s | PSR_c | PSR_f},
8389 {"scx", PSR_s | PSR_c | PSR_x},
8390 {"xfs", PSR_x | PSR_f | PSR_s},
8391 {"xfc", PSR_x | PSR_f | PSR_c},
8392 {"xsf", PSR_x | PSR_s | PSR_f},
8393 {"xsc", PSR_x | PSR_s | PSR_c},
8394 {"xcf", PSR_x | PSR_c | PSR_f},
8395 {"xcs", PSR_x | PSR_c | PSR_s},
8396 {"cfs", PSR_c | PSR_f | PSR_s},
8397 {"cfx", PSR_c | PSR_f | PSR_x},
8398 {"csf", PSR_c | PSR_s | PSR_f},
8399 {"csx", PSR_c | PSR_s | PSR_x},
8400 {"cxf", PSR_c | PSR_x | PSR_f},
8401 {"cxs", PSR_c | PSR_x | PSR_s},
8402 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
8403 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
8404 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
8405 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
8406 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
8407 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
8408 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
8409 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
8410 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
8411 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
8412 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
8413 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
8414 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
8415 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
8416 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
8417 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
8418 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
8419 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
8420 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
8421 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
8422 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
8423 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
8424 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
8425 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
8428 /* Table of all shift-in-operand names. */
8429 static const struct asm_shift_name shift_names [] =
8431 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
8432 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
8433 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
8434 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
8435 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
8436 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
8439 /* Table of all explicit relocation names. */
8440 #ifdef OBJ_ELF
8441 static struct reloc_entry reloc_names[] =
8443 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
8444 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
8445 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
8446 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
8447 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
8448 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
8449 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
8450 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
8451 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
8452 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
8453 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
8455 #endif
8457 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
8458 static const struct asm_cond conds[] =
8460 {"eq", 0x0},
8461 {"ne", 0x1},
8462 {"cs", 0x2}, {"hs", 0x2},
8463 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
8464 {"mi", 0x4},
8465 {"pl", 0x5},
8466 {"vs", 0x6},
8467 {"vc", 0x7},
8468 {"hi", 0x8},
8469 {"ls", 0x9},
8470 {"ge", 0xa},
8471 {"lt", 0xb},
8472 {"gt", 0xc},
8473 {"le", 0xd},
8474 {"al", 0xe}
8477 /* Table of ARM-format instructions. */
8479 /* Macros for gluing together operand strings. N.B. In all cases
8480 other than OPS0, the trailing OP_stop comes from default
8481 zero-initialization of the unspecified elements of the array. */
8482 #define OPS0() { OP_stop, }
8483 #define OPS1(a) { OP_##a, }
8484 #define OPS2(a,b) { OP_##a,OP_##b, }
8485 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
8486 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
8487 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
8488 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
8490 /* These macros abstract out the exact format of the mnemonic table and
8491 save some repeated characters. */
8493 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
8494 #define TxCE(mnem, op, top, nops, ops, ae, te) \
8495 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
8496 THUMB_VARIANT, do_##ae, do_##te }
8498 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
8499 a T_MNEM_xyz enumerator. */
8500 #define TCE(mnem, aop, top, nops, ops, ae, te) \
8501 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
8502 #define tCE(mnem, aop, top, nops, ops, ae, te) \
8503 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8505 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
8506 infix after the third character. */
8507 #define TxC3(mnem, op, top, nops, ops, ae, te) \
8508 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
8509 THUMB_VARIANT, do_##ae, do_##te }
8510 #define TC3(mnem, aop, top, nops, ops, ae, te) \
8511 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
8512 #define tC3(mnem, aop, top, nops, ops, ae, te) \
8513 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8515 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
8516 appear in the condition table. */
8517 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
8518 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8519 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
8521 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
8522 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
8523 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
8524 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
8525 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
8526 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
8527 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
8528 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
8529 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
8530 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
8531 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
8532 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
8533 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
8534 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
8535 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
8536 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
8537 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
8538 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
8539 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
8540 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
8542 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
8543 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
8544 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
8545 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
8547 /* Mnemonic that cannot be conditionalized. The ARM condition-code
8548 field is still 0xE. */
8549 #define TUE(mnem, op, top, nops, ops, ae, te) \
8550 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
8551 THUMB_VARIANT, do_##ae, do_##te }
8553 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
8554 condition code field. */
8555 #define TUF(mnem, op, top, nops, ops, ae, te) \
8556 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
8557 THUMB_VARIANT, do_##ae, do_##te }
8559 /* ARM-only variants of all the above. */
8560 #define CE(mnem, op, nops, ops, ae) \
8561 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8563 #define C3(mnem, op, nops, ops, ae) \
8564 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8566 /* Legacy mnemonics that always have conditional infix after the third
8567 character. */
8568 #define CL(mnem, op, nops, ops, ae) \
8569 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
8570 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8572 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
8573 #define cCE(mnem, op, nops, ops, ae) \
8574 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8576 /* Legacy coprocessor instructions where conditional infix and conditional
8577 suffix are ambiguous. For consistency this includes all FPA instructions,
8578 not just the potentially ambiguous ones. */
8579 #define cCL(mnem, op, nops, ops, ae) \
8580 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
8581 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8583 /* Coprocessor, takes either a suffix or a position-3 infix
8584 (for an FPA corner case). */
8585 #define C3E(mnem, op, nops, ops, ae) \
8586 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
8587 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8589 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
8590 { #m1 #m2 #m3, OPS##nops ops, \
8591 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8592 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8594 #define CM(m1, m2, op, nops, ops, ae) \
8595 xCM_(m1, , m2, op, nops, ops, ae), \
8596 xCM_(m1, eq, m2, op, nops, ops, ae), \
8597 xCM_(m1, ne, m2, op, nops, ops, ae), \
8598 xCM_(m1, cs, m2, op, nops, ops, ae), \
8599 xCM_(m1, hs, m2, op, nops, ops, ae), \
8600 xCM_(m1, cc, m2, op, nops, ops, ae), \
8601 xCM_(m1, ul, m2, op, nops, ops, ae), \
8602 xCM_(m1, lo, m2, op, nops, ops, ae), \
8603 xCM_(m1, mi, m2, op, nops, ops, ae), \
8604 xCM_(m1, pl, m2, op, nops, ops, ae), \
8605 xCM_(m1, vs, m2, op, nops, ops, ae), \
8606 xCM_(m1, vc, m2, op, nops, ops, ae), \
8607 xCM_(m1, hi, m2, op, nops, ops, ae), \
8608 xCM_(m1, ls, m2, op, nops, ops, ae), \
8609 xCM_(m1, ge, m2, op, nops, ops, ae), \
8610 xCM_(m1, lt, m2, op, nops, ops, ae), \
8611 xCM_(m1, gt, m2, op, nops, ops, ae), \
8612 xCM_(m1, le, m2, op, nops, ops, ae), \
8613 xCM_(m1, al, m2, op, nops, ops, ae)
8615 #define UE(mnem, op, nops, ops, ae) \
8616 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8618 #define UF(mnem, op, nops, ops, ae) \
8619 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8621 #define do_0 0
8623 /* Thumb-only, unconditional. */
8624 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
8626 static const struct asm_opcode insns[] =
8628 #define ARM_VARIANT ARM_EXT_V1 /* Core ARM Instructions. */
8629 #define THUMB_VARIANT ARM_EXT_V4T
8630 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
8631 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
8632 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
8633 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
8634 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
8635 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
8636 tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub),
8637 tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub),
8638 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
8639 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
8640 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
8641 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
8642 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
8643 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
8644 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
8645 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
8647 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
8648 for setting PSR flag bits. They are obsolete in V6 and do not
8649 have Thumb equivalents. */
8650 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8651 tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8652 CL(tstp, 110f000, 2, (RR, SH), cmp),
8653 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8654 tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8655 CL(cmpp, 150f000, 2, (RR, SH), cmp),
8656 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8657 tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8658 CL(cmnp, 170f000, 2, (RR, SH), cmp),
8660 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
8661 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
8662 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
8663 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
8665 tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst),
8666 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst),
8667 tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst),
8668 tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst),
8670 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8671 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8672 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8673 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8675 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
8676 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
8677 TCE(bl, b000000, f000f800, 1, (EXPr), branch, t_branch23),
8679 /* Pseudo ops. */
8680 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
8681 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
8682 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
8684 /* Thumb-compatibility pseudo ops. */
8685 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
8686 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
8687 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
8688 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
8689 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
8690 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
8691 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
8692 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
8693 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
8694 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
8695 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
8696 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
8698 #undef THUMB_VARIANT
8699 #define THUMB_VARIANT ARM_EXT_V6
8700 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
8702 /* V1 instructions with no Thumb analogue prior to V6T2. */
8703 #undef THUMB_VARIANT
8704 #define THUMB_VARIANT ARM_EXT_V6T2
8705 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
8706 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
8707 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8708 TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8709 CL(teqp, 130f000, 2, (RR, SH), cmp),
8711 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
8712 TC3(ldrbt, 4700000, f8300e00, 2, (RR, ADDR), ldstt, t_ldstt),
8713 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
8714 TC3(strbt, 4600000, f8200e00, 2, (RR, ADDR), ldstt, t_ldstt),
8716 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8717 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8719 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8720 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8722 /* V1 instructions with no Thumb analogue at all. */
8723 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
8724 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
8726 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
8727 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
8728 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
8729 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
8730 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
8731 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
8732 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
8733 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
8735 #undef ARM_VARIANT
8736 #define ARM_VARIANT ARM_EXT_V2 /* ARM 2 - multiplies. */
8737 #undef THUMB_VARIANT
8738 #define THUMB_VARIANT ARM_EXT_V4T
8739 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8740 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
8742 #undef THUMB_VARIANT
8743 #define THUMB_VARIANT ARM_EXT_V6T2
8744 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8745 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
8747 /* Generic coprocessor instructions. */
8748 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8749 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8750 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8751 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8752 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8753 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8754 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8756 #undef ARM_VARIANT
8757 #define ARM_VARIANT ARM_EXT_V2S /* ARM 3 - swp instructions. */
8758 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8759 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
8761 #undef ARM_VARIANT
8762 #define ARM_VARIANT ARM_EXT_V3 /* ARM 6 Status register instructions. */
8763 TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs),
8764 TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr),
8766 #undef ARM_VARIANT
8767 #define ARM_VARIANT ARM_EXT_V3M /* ARM 7M long multiplies. */
8768 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8769 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8770 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8771 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8772 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8773 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8774 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
8775 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
8777 #undef ARM_VARIANT
8778 #define ARM_VARIANT ARM_EXT_V4 /* ARM Architecture 4. */
8779 #undef THUMB_VARIANT
8780 #define THUMB_VARIANT ARM_EXT_V4T
8781 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst),
8782 tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst),
8783 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8784 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8785 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
8786 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
8788 #undef ARM_VARIANT
8789 #define ARM_VARIANT ARM_EXT_V4T|ARM_EXT_V5
8790 /* ARM Architecture 4T. */
8791 /* Note: bx (and blx) are required on V5, even if the processor does
8792 not support Thumb. */
8793 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
8795 #undef ARM_VARIANT
8796 #define ARM_VARIANT ARM_EXT_V5 /* ARM Architecture 5T. */
8797 #undef THUMB_VARIANT
8798 #define THUMB_VARIANT ARM_EXT_V5T
8799 /* Note: blx has 2 variants; the .value coded here is for
8800 BLX(2). Only this variant has conditional execution. */
8801 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
8802 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
8804 #undef THUMB_VARIANT
8805 #define THUMB_VARIANT ARM_EXT_V6T2
8806 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
8807 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc),
8808 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc),
8809 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc),
8810 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc),
8811 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
8812 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8813 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
8815 #undef ARM_VARIANT
8816 #define ARM_VARIANT ARM_EXT_V5ExP /* ARM Architecture 5TExP. */
8817 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8818 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8819 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8820 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8822 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8823 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
8825 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8826 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8827 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8828 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
8830 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8831 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8832 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8833 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8835 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8836 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8838 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8839 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8840 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8841 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
8843 #undef ARM_VARIANT
8844 #define ARM_VARIANT ARM_EXT_V5E /* ARM Architecture 5TE. */
8845 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
8846 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8847 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
8849 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8850 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8852 #undef ARM_VARIANT
8853 #define ARM_VARIANT ARM_EXT_V5J /* ARM Architecture 5TEJ. */
8854 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
8856 #undef ARM_VARIANT
8857 #define ARM_VARIANT ARM_EXT_V6 /* ARM V6. */
8858 #undef THUMB_VARIANT
8859 #define THUMB_VARIANT ARM_EXT_V6
8860 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
8861 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
8862 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8863 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8864 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
8865 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8866 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8867 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8868 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8869 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
8871 #undef THUMB_VARIANT
8872 #define THUMB_VARIANT ARM_EXT_V6T2
8873 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, imm0),
8874 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
8875 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8876 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
8877 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
8878 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
8879 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8880 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8881 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8882 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8883 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8884 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8885 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8886 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8887 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8888 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8889 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8890 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8891 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8892 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8893 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8894 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8895 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8896 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8897 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8898 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8899 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8900 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8901 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8902 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8903 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8904 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8905 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8906 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8907 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8908 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8909 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8910 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8911 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8912 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8913 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8914 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8915 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8916 UF(rfeib, 9900a00, 1, (RRw), rfe),
8917 UF(rfeda, 8100a00, 1, (RRw), rfe),
8918 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8919 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
8920 UF(rfefa, 9900a00, 1, (RRw), rfe),
8921 UF(rfeea, 8100a00, 1, (RRw), rfe),
8922 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
8923 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8924 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8925 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8926 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8927 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8928 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8929 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
8930 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
8931 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
8932 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8933 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8934 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8935 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8936 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8937 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8938 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8939 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
8940 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8941 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8942 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8943 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8944 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8945 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8946 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8947 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8948 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8949 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8950 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
8951 UF(srsib, 9cd0500, 1, (I31w), srs),
8952 UF(srsda, 84d0500, 1, (I31w), srs),
8953 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
8954 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
8955 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
8956 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
8957 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
8958 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
8959 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
8960 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
8961 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
8963 #undef ARM_VARIANT
8964 #define ARM_VARIANT ARM_EXT_V6K
8965 #undef THUMB_VARIANT
8966 #define THUMB_VARIANT ARM_EXT_V6K
8967 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
8968 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
8969 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
8970 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
8972 #undef THUMB_VARIANT
8973 #define THUMB_VARIANT ARM_EXT_V6T2
8974 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8975 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
8976 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
8977 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8978 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
8979 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
8980 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
8982 #undef ARM_VARIANT
8983 #define ARM_VARIANT ARM_EXT_V6Z
8984 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
8986 #undef ARM_VARIANT
8987 #define ARM_VARIANT ARM_EXT_V6T2
8988 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
8989 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
8990 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8991 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
8993 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
8994 TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16),
8995 TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16),
8996 TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
8998 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
8999 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9000 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9001 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9003 UT(cbnz, b900, 2, (RR, EXP), t_czb),
9004 UT(cbz, b100, 2, (RR, EXP), t_czb),
9005 /* ARM does not really have an IT instruction. */
9006 TUE(it, 0, bf08, 1, (COND), it, t_it),
9007 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
9008 TUE(ite, 0, bf04, 1, (COND), it, t_it),
9009 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
9010 TUE(itet, 0, bf06, 1, (COND), it, t_it),
9011 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
9012 TUE(itee, 0, bf02, 1, (COND), it, t_it),
9013 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
9014 TUE(itett, 0, bf07, 1, (COND), it, t_it),
9015 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
9016 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
9017 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
9018 TUE(itete, 0, bf05, 1, (COND), it, t_it),
9019 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
9020 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
9022 /* Thumb2 only instructions. */
9023 #undef ARM_VARIANT
9024 #define ARM_VARIANT 0
9026 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
9027 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
9028 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
9029 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
9031 #undef ARM_VARIANT
9032 #define ARM_VARIANT FPU_FPA_EXT_V1 /* Core FPA instruction set (V1). */
9033 cCE(wfs, e200110, 1, (RR), rd),
9034 cCE(rfs, e300110, 1, (RR), rd),
9035 cCE(wfc, e400110, 1, (RR), rd),
9036 cCE(rfc, e500110, 1, (RR), rd),
9038 cCL(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr),
9039 cCL(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr),
9040 cCL(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr),
9041 cCL(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr),
9043 cCL(stfs, c000100, 2, (RF, ADDR), rd_cpaddr),
9044 cCL(stfd, c008100, 2, (RF, ADDR), rd_cpaddr),
9045 cCL(stfe, c400100, 2, (RF, ADDR), rd_cpaddr),
9046 cCL(stfp, c408100, 2, (RF, ADDR), rd_cpaddr),
9048 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
9049 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
9050 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
9051 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
9052 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
9053 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
9054 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
9055 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
9056 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
9057 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
9058 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
9059 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
9061 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
9062 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
9063 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
9064 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
9065 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
9066 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
9067 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
9068 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
9069 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
9070 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
9071 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
9072 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
9074 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
9075 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
9076 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
9077 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
9078 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
9079 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
9080 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
9081 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
9082 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
9083 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
9084 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
9085 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
9087 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
9088 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
9089 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
9090 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
9091 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
9092 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
9093 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
9094 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
9095 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
9096 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
9097 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
9098 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
9100 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
9101 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
9102 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
9103 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
9104 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
9105 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
9106 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
9107 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
9108 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
9109 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
9110 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
9111 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
9113 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
9114 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
9115 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
9116 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
9117 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
9118 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
9119 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
9120 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
9121 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
9122 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
9123 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
9124 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
9126 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
9127 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
9128 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
9129 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
9130 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
9131 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
9132 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
9133 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
9134 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
9135 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
9136 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
9137 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
9139 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
9140 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
9141 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
9142 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
9143 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
9144 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
9145 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
9146 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
9147 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
9148 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
9149 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
9150 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
9152 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
9153 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
9154 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
9155 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
9156 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
9157 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
9158 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
9159 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
9160 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
9161 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
9162 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
9163 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
9165 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
9166 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
9167 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
9168 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
9169 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
9170 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
9171 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
9172 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
9173 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
9174 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
9175 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
9176 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
9178 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
9179 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
9180 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
9181 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
9182 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
9183 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
9184 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
9185 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
9186 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
9187 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
9188 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
9189 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
9191 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
9192 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
9193 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
9194 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
9195 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
9196 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
9197 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
9198 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
9199 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
9200 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
9201 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
9202 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
9204 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
9205 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
9206 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
9207 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
9208 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
9209 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
9210 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
9211 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
9212 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
9213 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
9214 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
9215 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
9217 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
9218 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
9219 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
9220 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
9221 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
9222 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
9223 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
9224 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
9225 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
9226 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
9227 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
9228 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
9230 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
9231 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
9232 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
9233 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
9234 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
9235 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
9236 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
9237 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
9238 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
9239 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
9240 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
9241 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
9243 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
9244 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
9245 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
9246 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
9247 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
9248 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
9249 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
9250 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
9251 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
9252 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
9253 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
9254 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
9256 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
9257 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
9258 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
9259 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
9260 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
9261 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9262 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9263 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9264 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
9265 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
9266 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
9267 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
9269 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
9270 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
9271 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
9272 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
9273 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
9274 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9275 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9276 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9277 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
9278 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
9279 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
9280 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
9282 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
9283 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
9284 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
9285 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
9286 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
9287 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9288 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9289 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9290 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
9291 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
9292 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
9293 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
9295 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
9296 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
9297 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
9298 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
9299 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
9300 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9301 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9302 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9303 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
9304 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
9305 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
9306 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
9308 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
9309 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
9310 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
9311 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
9312 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
9313 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9314 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9315 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9316 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
9317 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
9318 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
9319 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
9321 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
9322 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
9323 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
9324 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
9325 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
9326 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9327 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9328 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9329 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
9330 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
9331 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
9332 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
9334 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
9335 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
9336 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
9337 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
9338 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
9339 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9340 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9341 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9342 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
9343 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
9344 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
9345 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
9347 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
9348 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
9349 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
9350 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
9351 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
9352 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9353 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9354 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9355 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
9356 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
9357 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
9358 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
9360 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
9361 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
9362 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
9363 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
9364 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
9365 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9366 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9367 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9368 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
9369 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
9370 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
9371 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
9373 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
9374 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
9375 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
9376 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
9377 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
9378 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9379 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9380 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9381 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
9382 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
9383 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
9384 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
9386 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9387 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9388 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9389 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9390 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9391 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9392 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9393 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9394 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9395 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9396 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9397 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9399 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9400 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9401 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9402 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9403 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9404 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9405 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9406 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9407 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9408 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9409 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9410 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9412 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9413 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9414 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9415 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9416 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9417 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9418 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9419 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9420 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9421 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9422 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9423 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9425 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
9426 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
9427 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
9428 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
9430 cCL(flts, e000110, 2, (RF, RR), rn_rd),
9431 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
9432 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
9433 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
9434 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
9435 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
9436 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
9437 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
9438 cCL(flte, e080110, 2, (RF, RR), rn_rd),
9439 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
9440 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
9441 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
9443 /* The implementation of the FIX instruction is broken on some
9444 assemblers, in that it accepts a precision specifier as well as a
9445 rounding specifier, despite the fact that this is meaningless.
9446 To be more compatible, we accept it as well, though of course it
9447 does not set any bits. */
9448 cCE(fix, e100110, 2, (RR, RF), rd_rm),
9449 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
9450 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
9451 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
9452 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
9453 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
9454 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
9455 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
9456 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
9457 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
9458 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
9459 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
9460 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
9462 /* Instructions that were new with the real FPA, call them V2. */
9463 #undef ARM_VARIANT
9464 #define ARM_VARIANT FPU_FPA_EXT_V2
9465 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9466 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9467 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9468 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9469 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9470 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9472 #undef ARM_VARIANT
9473 #define ARM_VARIANT FPU_VFP_EXT_V1xD /* VFP V1xD (single precision). */
9474 /* Moves and type conversions. */
9475 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
9476 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
9477 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
9478 cCE(fmstat, ef1fa10, 0, (), noargs),
9479 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
9480 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
9481 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
9482 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9483 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
9484 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9485 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
9486 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
9488 /* Memory operations. */
9489 cCE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst),
9490 cCE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst),
9491 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9492 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9493 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9494 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9495 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9496 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9497 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9498 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9499 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9500 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9501 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9502 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9503 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9504 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9505 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9506 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9508 /* Monadic operations. */
9509 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
9510 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
9511 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
9513 /* Dyadic operations. */
9514 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9515 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9516 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9517 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9518 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9519 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9520 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9521 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9522 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9524 /* Comparisons. */
9525 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
9526 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
9527 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
9528 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
9530 #undef ARM_VARIANT
9531 #define ARM_VARIANT FPU_VFP_EXT_V1 /* VFP V1 (Double precision). */
9532 /* Moves and type conversions. */
9533 cCE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm),
9534 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9535 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9536 cCE(fmdhr, e200b10, 2, (RVD, RR), rn_rd),
9537 cCE(fmdlr, e000b10, 2, (RVD, RR), rn_rd),
9538 cCE(fmrdh, e300b10, 2, (RR, RVD), rd_rn),
9539 cCE(fmrdl, e100b10, 2, (RR, RVD), rd_rn),
9540 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9541 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
9542 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9543 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9544 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9545 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9547 /* Memory operations. */
9548 cCE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst),
9549 cCE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst),
9550 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9551 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9552 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9553 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9554 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9555 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9556 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9557 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9559 /* Monadic operations. */
9560 cCE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm),
9561 cCE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm),
9562 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm),
9564 /* Dyadic operations. */
9565 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9566 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9567 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9568 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9569 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9570 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9571 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9572 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9573 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9575 /* Comparisons. */
9576 cCE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm),
9577 cCE(fcmpzd, eb50b40, 1, (RVD), rd),
9578 cCE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm),
9579 cCE(fcmpezd, eb50bc0, 1, (RVD), rd),
9581 #undef ARM_VARIANT
9582 #define ARM_VARIANT FPU_VFP_EXT_V2
9583 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
9584 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
9585 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn),
9586 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm),
9588 #undef ARM_VARIANT
9589 #define ARM_VARIANT ARM_CEXT_XSCALE /* Intel XScale extensions. */
9590 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9591 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9592 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9593 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9594 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9595 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9596 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
9597 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
9599 #undef ARM_VARIANT
9600 #define ARM_VARIANT ARM_CEXT_IWMMXT /* Intel Wireless MMX technology. */
9601 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
9602 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
9603 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
9604 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
9605 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
9606 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
9607 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
9608 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
9609 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
9610 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9611 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9612 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9613 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9614 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9615 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9616 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9617 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9618 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9619 cCE(tmcr, e000110, 2, (RIWC, RR), rn_rd),
9620 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
9621 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9622 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9623 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9624 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9625 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9626 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9627 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
9628 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
9629 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
9630 cCE(tmrc, e100110, 2, (RR, RIWC), rd_rn),
9631 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
9632 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
9633 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
9634 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
9635 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
9636 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
9637 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
9638 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9639 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9640 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9641 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9642 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9643 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9644 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9645 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9646 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9647 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
9648 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9649 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9650 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9651 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9652 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9653 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9654 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9655 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9656 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9657 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9658 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9659 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9660 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9661 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9662 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9663 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9664 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9665 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9666 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9667 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9668 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9669 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9670 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9671 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9672 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9673 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9674 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9675 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9676 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9677 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9678 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9679 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9680 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9681 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9682 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9683 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9684 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9685 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9686 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9687 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9688 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9689 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
9690 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9691 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9692 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9693 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9694 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9695 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9696 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9697 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9698 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9699 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9700 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9701 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9702 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9703 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9704 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9705 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9706 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9707 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9708 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9709 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9710 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9711 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
9712 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9713 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9714 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9715 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9716 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9717 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9718 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9719 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9720 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9721 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9722 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9723 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9724 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9725 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9726 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9727 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9728 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9729 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
9730 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9731 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9732 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9733 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9734 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9735 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9736 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9737 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9738 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9739 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9740 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9741 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9742 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9743 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
9744 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
9745 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
9746 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
9747 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
9748 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
9749 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9750 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9751 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9752 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
9753 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
9754 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
9755 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
9756 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
9757 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
9758 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9759 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9760 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9761 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9762 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
9764 #undef ARM_VARIANT
9765 #define ARM_VARIANT ARM_CEXT_MAVERICK /* Cirrus Maverick instructions. */
9766 cCE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr),
9767 cCE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr),
9768 cCE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr),
9769 cCE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr),
9770 cCE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr),
9771 cCE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr),
9772 cCE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr),
9773 cCE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr),
9774 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
9775 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
9776 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
9777 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
9778 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
9779 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
9780 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
9781 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
9782 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
9783 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
9784 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
9785 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
9786 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
9787 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
9788 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
9789 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
9790 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
9791 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
9792 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
9793 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
9794 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
9795 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
9796 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
9797 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
9798 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
9799 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
9800 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
9801 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
9802 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
9803 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
9804 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
9805 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
9806 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
9807 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
9808 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
9809 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
9810 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
9811 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
9812 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
9813 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
9814 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
9815 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
9816 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
9817 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
9818 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
9819 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
9820 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
9821 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
9822 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
9823 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
9824 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
9825 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
9826 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
9827 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
9828 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
9829 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
9830 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9831 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9832 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9833 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9834 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9835 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
9836 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9837 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
9838 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9839 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
9840 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9841 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
9843 #undef ARM_VARIANT
9844 #undef THUMB_VARIANT
9845 #undef TCE
9846 #undef TCM
9847 #undef TUE
9848 #undef TUF
9849 #undef TCC
9850 #undef cCE
9851 #undef cCL
9852 #undef C3E
9853 #undef CE
9854 #undef CM
9855 #undef UE
9856 #undef UF
9857 #undef UT
9858 #undef OPS0
9859 #undef OPS1
9860 #undef OPS2
9861 #undef OPS3
9862 #undef OPS4
9863 #undef OPS5
9864 #undef OPS6
9865 #undef do_0
9867 /* MD interface: bits in the object file. */
9869 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
9870 for use in the a.out file, and stores them in the array pointed to by buf.
9871 This knows about the endian-ness of the target machine and does
9872 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
9873 2 (short) and 4 (long) Floating numbers are put out as a series of
9874 LITTLENUMS (shorts, here at least). */
9876 void
9877 md_number_to_chars (char * buf, valueT val, int n)
9879 if (target_big_endian)
9880 number_to_chars_bigendian (buf, val, n);
9881 else
9882 number_to_chars_littleendian (buf, val, n);
9885 static valueT
9886 md_chars_to_number (char * buf, int n)
9888 valueT result = 0;
9889 unsigned char * where = (unsigned char *) buf;
9891 if (target_big_endian)
9893 while (n--)
9895 result <<= 8;
9896 result |= (*where++ & 255);
9899 else
9901 while (n--)
9903 result <<= 8;
9904 result |= (where[n] & 255);
9908 return result;
9911 /* MD interface: Sections. */
9913 /* Estimate the size of a frag before relaxing. Assume everything fits in
9914 2 bytes. */
9917 md_estimate_size_before_relax (fragS * fragp,
9918 segT segtype ATTRIBUTE_UNUSED)
9920 fragp->fr_var = 2;
9921 return 2;
9924 /* Convert a machine dependent frag. */
9926 void
9927 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
9929 unsigned long insn;
9930 unsigned long old_op;
9931 char *buf;
9932 expressionS exp;
9933 fixS *fixp;
9934 int reloc_type;
9935 int pc_rel;
9936 int opcode;
9938 buf = fragp->fr_literal + fragp->fr_fix;
9940 old_op = bfd_get_16(abfd, buf);
9941 if (fragp->fr_symbol) {
9942 exp.X_op = O_symbol;
9943 exp.X_add_symbol = fragp->fr_symbol;
9944 } else {
9945 exp.X_op = O_constant;
9947 exp.X_add_number = fragp->fr_offset;
9948 opcode = fragp->fr_subtype;
9949 switch (opcode)
9951 case T_MNEM_ldr_pc:
9952 case T_MNEM_ldr_pc2:
9953 case T_MNEM_ldr_sp:
9954 case T_MNEM_str_sp:
9955 case T_MNEM_ldr:
9956 case T_MNEM_ldrb:
9957 case T_MNEM_ldrh:
9958 case T_MNEM_str:
9959 case T_MNEM_strb:
9960 case T_MNEM_strh:
9961 if (fragp->fr_var == 4)
9963 insn = THUMB_OP32(opcode);
9964 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
9966 insn |= (old_op & 0x700) << 4;
9968 else
9970 insn |= (old_op & 7) << 12;
9971 insn |= (old_op & 0x38) << 13;
9973 insn |= 0x00000c00;
9974 put_thumb32_insn (buf, insn);
9975 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9977 else
9979 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
9981 pc_rel = (opcode == T_MNEM_ldr_pc2);
9982 break;
9983 case T_MNEM_adr:
9984 if (fragp->fr_var == 4)
9986 insn = THUMB_OP32 (opcode);
9987 insn |= (old_op & 0xf0) << 4;
9988 put_thumb32_insn (buf, insn);
9989 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
9991 else
9993 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
9994 exp.X_add_number -= 4;
9996 pc_rel = 1;
9997 break;
9998 case T_MNEM_mov:
9999 case T_MNEM_movs:
10000 case T_MNEM_cmp:
10001 case T_MNEM_cmn:
10002 if (fragp->fr_var == 4)
10004 int r0off = (opcode == T_MNEM_mov
10005 || opcode == T_MNEM_movs) ? 0 : 8;
10006 insn = THUMB_OP32 (opcode);
10007 insn = (insn & 0xe1ffffff) | 0x10000000;
10008 insn |= (old_op & 0x700) << r0off;
10009 put_thumb32_insn (buf, insn);
10010 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10012 else
10014 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
10016 pc_rel = 0;
10017 break;
10018 case T_MNEM_b:
10019 if (fragp->fr_var == 4)
10021 insn = THUMB_OP32(opcode);
10022 put_thumb32_insn (buf, insn);
10023 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
10025 else
10026 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
10027 pc_rel = 1;
10028 break;
10029 case T_MNEM_bcond:
10030 if (fragp->fr_var == 4)
10032 insn = THUMB_OP32(opcode);
10033 insn |= (old_op & 0xf00) << 14;
10034 put_thumb32_insn (buf, insn);
10035 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
10037 else
10038 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
10039 pc_rel = 1;
10040 break;
10041 case T_MNEM_add_sp:
10042 case T_MNEM_add_pc:
10043 case T_MNEM_inc_sp:
10044 case T_MNEM_dec_sp:
10045 if (fragp->fr_var == 4)
10047 /* ??? Choose between add and addw. */
10048 insn = THUMB_OP32 (opcode);
10049 insn |= (old_op & 0xf0) << 4;
10050 put_thumb32_insn (buf, insn);
10051 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10053 else
10054 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10055 pc_rel = 0;
10056 break;
10058 case T_MNEM_addi:
10059 case T_MNEM_addis:
10060 case T_MNEM_subi:
10061 case T_MNEM_subis:
10062 if (fragp->fr_var == 4)
10064 insn = THUMB_OP32 (opcode);
10065 insn |= (old_op & 0xf0) << 4;
10066 insn |= (old_op & 0xf) << 16;
10067 put_thumb32_insn (buf, insn);
10068 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10070 else
10071 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10072 pc_rel = 0;
10073 break;
10074 default:
10075 abort();
10077 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
10078 reloc_type);
10079 fixp->fx_file = fragp->fr_file;
10080 fixp->fx_line = fragp->fr_line;
10081 fragp->fr_fix += fragp->fr_var;
10084 /* Return the size of a relaxable immediate operand instruction.
10085 SHIFT and SIZE specify the form of the allowable immediate. */
10086 static int
10087 relax_immediate (fragS *fragp, int size, int shift)
10089 offsetT offset;
10090 offsetT mask;
10091 offsetT low;
10093 /* ??? Should be able to do better than this. */
10094 if (fragp->fr_symbol)
10095 return 4;
10097 low = (1 << shift) - 1;
10098 mask = (1 << (shift + size)) - (1 << shift);
10099 offset = fragp->fr_offset;
10100 /* Force misaligned offsets to 32-bit variant. */
10101 if (offset & low)
10102 return -4;
10103 if (offset & ~mask)
10104 return 4;
10105 return 2;
10108 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
10109 load. */
10110 static int
10111 relax_adr (fragS *fragp, asection *sec)
10113 addressT addr;
10114 offsetT val;
10116 /* Assume worst case for symbols not known to be in the same section. */
10117 if (!S_IS_DEFINED(fragp->fr_symbol)
10118 || sec != S_GET_SEGMENT (fragp->fr_symbol))
10119 return 4;
10121 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
10122 addr = fragp->fr_address + fragp->fr_fix;
10123 addr = (addr + 4) & ~3;
10124 /* Fix the insn as the 4-byte version if the target address is not
10125 sufficiently aligned. This is prevents an infinite loop when two
10126 instructions have contradictory range/alignment requirements. */
10127 if (val & 3)
10128 return -4;
10129 val -= addr;
10130 if (val < 0 || val > 1020)
10131 return 4;
10132 return 2;
10135 /* Return the size of a relaxable add/sub immediate instruction. */
10136 static int
10137 relax_addsub (fragS *fragp, asection *sec)
10139 char *buf;
10140 int op;
10142 buf = fragp->fr_literal + fragp->fr_fix;
10143 op = bfd_get_16(sec->owner, buf);
10144 if ((op & 0xf) == ((op >> 4) & 0xf))
10145 return relax_immediate (fragp, 8, 0);
10146 else
10147 return relax_immediate (fragp, 3, 0);
10151 /* Return the size of a relaxable branch instruction. BITS is the
10152 size of the offset field in the narrow instruction. */
10154 static int
10155 relax_branch (fragS *fragp, asection *sec, int bits)
10157 addressT addr;
10158 offsetT val;
10159 offsetT limit;
10161 /* Assume worst case for symbols not known to be in the same section. */
10162 if (!S_IS_DEFINED(fragp->fr_symbol)
10163 || sec != S_GET_SEGMENT (fragp->fr_symbol))
10164 return 4;
10166 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
10167 addr = fragp->fr_address + fragp->fr_fix + 4;
10168 val -= addr;
10170 /* Offset is a signed value *2 */
10171 limit = 1 << bits;
10172 if (val >= limit || val < -limit)
10173 return 4;
10174 return 2;
10178 /* Relax a machine dependent frag. This returns the amount by which
10179 the current size of the frag should change. */
10182 arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED)
10184 int oldsize;
10185 int newsize;
10187 oldsize = fragp->fr_var;
10188 switch (fragp->fr_subtype)
10190 case T_MNEM_ldr_pc2:
10191 newsize = relax_adr(fragp, sec);
10192 break;
10193 case T_MNEM_ldr_pc:
10194 case T_MNEM_ldr_sp:
10195 case T_MNEM_str_sp:
10196 newsize = relax_immediate(fragp, 8, 2);
10197 break;
10198 case T_MNEM_ldr:
10199 case T_MNEM_str:
10200 newsize = relax_immediate(fragp, 5, 2);
10201 break;
10202 case T_MNEM_ldrh:
10203 case T_MNEM_strh:
10204 newsize = relax_immediate(fragp, 5, 1);
10205 break;
10206 case T_MNEM_ldrb:
10207 case T_MNEM_strb:
10208 newsize = relax_immediate(fragp, 5, 0);
10209 break;
10210 case T_MNEM_adr:
10211 newsize = relax_adr(fragp, sec);
10212 break;
10213 case T_MNEM_mov:
10214 case T_MNEM_movs:
10215 case T_MNEM_cmp:
10216 case T_MNEM_cmn:
10217 newsize = relax_immediate(fragp, 8, 0);
10218 break;
10219 case T_MNEM_b:
10220 newsize = relax_branch(fragp, sec, 11);
10221 break;
10222 case T_MNEM_bcond:
10223 newsize = relax_branch(fragp, sec, 8);
10224 break;
10225 case T_MNEM_add_sp:
10226 case T_MNEM_add_pc:
10227 newsize = relax_immediate (fragp, 8, 2);
10228 break;
10229 case T_MNEM_inc_sp:
10230 case T_MNEM_dec_sp:
10231 newsize = relax_immediate (fragp, 7, 2);
10232 break;
10233 case T_MNEM_addi:
10234 case T_MNEM_addis:
10235 case T_MNEM_subi:
10236 case T_MNEM_subis:
10237 newsize = relax_addsub (fragp, sec);
10238 break;
10239 default:
10240 abort();
10242 if (newsize < 0)
10244 fragp->fr_var = -newsize;
10245 md_convert_frag (sec->owner, sec, fragp);
10246 frag_wane(fragp);
10247 return -(newsize + oldsize);
10249 fragp->fr_var = newsize;
10250 return newsize - oldsize;
10253 /* Round up a section size to the appropriate boundary. */
10255 valueT
10256 md_section_align (segT segment ATTRIBUTE_UNUSED,
10257 valueT size)
10259 #ifdef OBJ_ELF
10260 return size;
10261 #else
10262 /* Round all sects to multiple of 4. */
10263 return (size + 3) & ~3;
10264 #endif
10267 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10268 of an rs_align_code fragment. */
10270 void
10271 arm_handle_align (fragS * fragP)
10273 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
10274 static char const thumb_noop[2] = { 0xc0, 0x46 };
10275 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
10276 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
10278 int bytes, fix, noop_size;
10279 char * p;
10280 const char * noop;
10282 if (fragP->fr_type != rs_align_code)
10283 return;
10285 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
10286 p = fragP->fr_literal + fragP->fr_fix;
10287 fix = 0;
10289 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
10290 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
10292 if (fragP->tc_frag_data)
10294 if (target_big_endian)
10295 noop = thumb_bigend_noop;
10296 else
10297 noop = thumb_noop;
10298 noop_size = sizeof (thumb_noop);
10300 else
10302 if (target_big_endian)
10303 noop = arm_bigend_noop;
10304 else
10305 noop = arm_noop;
10306 noop_size = sizeof (arm_noop);
10309 if (bytes & (noop_size - 1))
10311 fix = bytes & (noop_size - 1);
10312 memset (p, 0, fix);
10313 p += fix;
10314 bytes -= fix;
10317 while (bytes >= noop_size)
10319 memcpy (p, noop, noop_size);
10320 p += noop_size;
10321 bytes -= noop_size;
10322 fix += noop_size;
10325 fragP->fr_fix += fix;
10326 fragP->fr_var = noop_size;
10329 /* Called from md_do_align. Used to create an alignment
10330 frag in a code section. */
10332 void
10333 arm_frag_align_code (int n, int max)
10335 char * p;
10337 /* We assume that there will never be a requirement
10338 to support alignments greater than 32 bytes. */
10339 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
10340 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
10342 p = frag_var (rs_align_code,
10343 MAX_MEM_FOR_RS_ALIGN_CODE,
10345 (relax_substateT) max,
10346 (symbolS *) NULL,
10347 (offsetT) n,
10348 (char *) NULL);
10349 *p = 0;
10352 /* Perform target specific initialisation of a frag. */
10354 void
10355 arm_init_frag (fragS * fragP)
10357 /* Record whether this frag is in an ARM or a THUMB area. */
10358 fragP->tc_frag_data = thumb_mode;
10361 #ifdef OBJ_ELF
10362 /* When we change sections we need to issue a new mapping symbol. */
10364 void
10365 arm_elf_change_section (void)
10367 flagword flags;
10368 segment_info_type *seginfo;
10370 /* Link an unlinked unwind index table section to the .text section. */
10371 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
10372 && elf_linked_to_section (now_seg) == NULL)
10373 elf_linked_to_section (now_seg) = text_section;
10375 if (!SEG_NORMAL (now_seg))
10376 return;
10378 flags = bfd_get_section_flags (stdoutput, now_seg);
10380 /* We can ignore sections that only contain debug info. */
10381 if ((flags & SEC_ALLOC) == 0)
10382 return;
10384 seginfo = seg_info (now_seg);
10385 mapstate = seginfo->tc_segment_info_data.mapstate;
10386 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
10390 arm_elf_section_type (const char * str, size_t len)
10392 if (len == 5 && strncmp (str, "exidx", 5) == 0)
10393 return SHT_ARM_EXIDX;
10395 return -1;
10398 /* Code to deal with unwinding tables. */
10400 static void add_unwind_adjustsp (offsetT);
10402 /* Cenerate and deferred unwind frame offset. */
10404 static void
10405 flush_pending_unwind (void)
10407 offsetT offset;
10409 offset = unwind.pending_offset;
10410 unwind.pending_offset = 0;
10411 if (offset != 0)
10412 add_unwind_adjustsp (offset);
10415 /* Add an opcode to this list for this function. Two-byte opcodes should
10416 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
10417 order. */
10419 static void
10420 add_unwind_opcode (valueT op, int length)
10422 /* Add any deferred stack adjustment. */
10423 if (unwind.pending_offset)
10424 flush_pending_unwind ();
10426 unwind.sp_restored = 0;
10428 if (unwind.opcode_count + length > unwind.opcode_alloc)
10430 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
10431 if (unwind.opcodes)
10432 unwind.opcodes = xrealloc (unwind.opcodes,
10433 unwind.opcode_alloc);
10434 else
10435 unwind.opcodes = xmalloc (unwind.opcode_alloc);
10437 while (length > 0)
10439 length--;
10440 unwind.opcodes[unwind.opcode_count] = op & 0xff;
10441 op >>= 8;
10442 unwind.opcode_count++;
10446 /* Add unwind opcodes to adjust the stack pointer. */
10448 static void
10449 add_unwind_adjustsp (offsetT offset)
10451 valueT op;
10453 if (offset > 0x200)
10455 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
10456 char bytes[5];
10457 int n;
10458 valueT o;
10460 /* Long form: 0xb2, uleb128. */
10461 /* This might not fit in a word so add the individual bytes,
10462 remembering the list is built in reverse order. */
10463 o = (valueT) ((offset - 0x204) >> 2);
10464 if (o == 0)
10465 add_unwind_opcode (0, 1);
10467 /* Calculate the uleb128 encoding of the offset. */
10468 n = 0;
10469 while (o)
10471 bytes[n] = o & 0x7f;
10472 o >>= 7;
10473 if (o)
10474 bytes[n] |= 0x80;
10475 n++;
10477 /* Add the insn. */
10478 for (; n; n--)
10479 add_unwind_opcode (bytes[n - 1], 1);
10480 add_unwind_opcode (0xb2, 1);
10482 else if (offset > 0x100)
10484 /* Two short opcodes. */
10485 add_unwind_opcode (0x3f, 1);
10486 op = (offset - 0x104) >> 2;
10487 add_unwind_opcode (op, 1);
10489 else if (offset > 0)
10491 /* Short opcode. */
10492 op = (offset - 4) >> 2;
10493 add_unwind_opcode (op, 1);
10495 else if (offset < 0)
10497 offset = -offset;
10498 while (offset > 0x100)
10500 add_unwind_opcode (0x7f, 1);
10501 offset -= 0x100;
10503 op = ((offset - 4) >> 2) | 0x40;
10504 add_unwind_opcode (op, 1);
10508 /* Finish the list of unwind opcodes for this function. */
10509 static void
10510 finish_unwind_opcodes (void)
10512 valueT op;
10514 if (unwind.fp_used)
10516 /* Adjust sp as neccessary. */
10517 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
10518 flush_pending_unwind ();
10520 /* After restoring sp from the frame pointer. */
10521 op = 0x90 | unwind.fp_reg;
10522 add_unwind_opcode (op, 1);
10524 else
10525 flush_pending_unwind ();
10529 /* Start an exception table entry. If idx is nonzero this is an index table
10530 entry. */
10532 static void
10533 start_unwind_section (const segT text_seg, int idx)
10535 const char * text_name;
10536 const char * prefix;
10537 const char * prefix_once;
10538 const char * group_name;
10539 size_t prefix_len;
10540 size_t text_len;
10541 char * sec_name;
10542 size_t sec_name_len;
10543 int type;
10544 int flags;
10545 int linkonce;
10547 if (idx)
10549 prefix = ELF_STRING_ARM_unwind;
10550 prefix_once = ELF_STRING_ARM_unwind_once;
10551 type = SHT_ARM_EXIDX;
10553 else
10555 prefix = ELF_STRING_ARM_unwind_info;
10556 prefix_once = ELF_STRING_ARM_unwind_info_once;
10557 type = SHT_PROGBITS;
10560 text_name = segment_name (text_seg);
10561 if (streq (text_name, ".text"))
10562 text_name = "";
10564 if (strncmp (text_name, ".gnu.linkonce.t.",
10565 strlen (".gnu.linkonce.t.")) == 0)
10567 prefix = prefix_once;
10568 text_name += strlen (".gnu.linkonce.t.");
10571 prefix_len = strlen (prefix);
10572 text_len = strlen (text_name);
10573 sec_name_len = prefix_len + text_len;
10574 sec_name = xmalloc (sec_name_len + 1);
10575 memcpy (sec_name, prefix, prefix_len);
10576 memcpy (sec_name + prefix_len, text_name, text_len);
10577 sec_name[prefix_len + text_len] = '\0';
10579 flags = SHF_ALLOC;
10580 linkonce = 0;
10581 group_name = 0;
10583 /* Handle COMDAT group. */
10584 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
10586 group_name = elf_group_name (text_seg);
10587 if (group_name == NULL)
10589 as_bad ("Group section `%s' has no group signature",
10590 segment_name (text_seg));
10591 ignore_rest_of_line ();
10592 return;
10594 flags |= SHF_GROUP;
10595 linkonce = 1;
10598 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
10600 /* Set the setion link for index tables. */
10601 if (idx)
10602 elf_linked_to_section (now_seg) = text_seg;
10606 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
10607 personality routine data. Returns zero, or the index table value for
10608 and inline entry. */
10610 static valueT
10611 create_unwind_entry (int have_data)
10613 int size;
10614 addressT where;
10615 char *ptr;
10616 /* The current word of data. */
10617 valueT data;
10618 /* The number of bytes left in this word. */
10619 int n;
10621 finish_unwind_opcodes ();
10623 /* Remember the current text section. */
10624 unwind.saved_seg = now_seg;
10625 unwind.saved_subseg = now_subseg;
10627 start_unwind_section (now_seg, 0);
10629 if (unwind.personality_routine == NULL)
10631 if (unwind.personality_index == -2)
10633 if (have_data)
10634 as_bad (_("handerdata in cantunwind frame"));
10635 return 1; /* EXIDX_CANTUNWIND. */
10638 /* Use a default personality routine if none is specified. */
10639 if (unwind.personality_index == -1)
10641 if (unwind.opcode_count > 3)
10642 unwind.personality_index = 1;
10643 else
10644 unwind.personality_index = 0;
10647 /* Space for the personality routine entry. */
10648 if (unwind.personality_index == 0)
10650 if (unwind.opcode_count > 3)
10651 as_bad (_("too many unwind opcodes for personality routine 0"));
10653 if (!have_data)
10655 /* All the data is inline in the index table. */
10656 data = 0x80;
10657 n = 3;
10658 while (unwind.opcode_count > 0)
10660 unwind.opcode_count--;
10661 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
10662 n--;
10665 /* Pad with "finish" opcodes. */
10666 while (n--)
10667 data = (data << 8) | 0xb0;
10669 return data;
10671 size = 0;
10673 else
10674 /* We get two opcodes "free" in the first word. */
10675 size = unwind.opcode_count - 2;
10677 else
10678 /* An extra byte is required for the opcode count. */
10679 size = unwind.opcode_count + 1;
10681 size = (size + 3) >> 2;
10682 if (size > 0xff)
10683 as_bad (_("too many unwind opcodes"));
10685 frag_align (2, 0, 0);
10686 record_alignment (now_seg, 2);
10687 unwind.table_entry = expr_build_dot ();
10689 /* Allocate the table entry. */
10690 ptr = frag_more ((size << 2) + 4);
10691 where = frag_now_fix () - ((size << 2) + 4);
10693 switch (unwind.personality_index)
10695 case -1:
10696 /* ??? Should this be a PLT generating relocation? */
10697 /* Custom personality routine. */
10698 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
10699 BFD_RELOC_ARM_PREL31);
10701 where += 4;
10702 ptr += 4;
10704 /* Set the first byte to the number of additional words. */
10705 data = size - 1;
10706 n = 3;
10707 break;
10709 /* ABI defined personality routines. */
10710 case 0:
10711 /* Three opcodes bytes are packed into the first word. */
10712 data = 0x80;
10713 n = 3;
10714 break;
10716 case 1:
10717 case 2:
10718 /* The size and first two opcode bytes go in the first word. */
10719 data = ((0x80 + unwind.personality_index) << 8) | size;
10720 n = 2;
10721 break;
10723 default:
10724 /* Should never happen. */
10725 abort ();
10728 /* Pack the opcodes into words (MSB first), reversing the list at the same
10729 time. */
10730 while (unwind.opcode_count > 0)
10732 if (n == 0)
10734 md_number_to_chars (ptr, data, 4);
10735 ptr += 4;
10736 n = 4;
10737 data = 0;
10739 unwind.opcode_count--;
10740 n--;
10741 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
10744 /* Finish off the last word. */
10745 if (n < 4)
10747 /* Pad with "finish" opcodes. */
10748 while (n--)
10749 data = (data << 8) | 0xb0;
10751 md_number_to_chars (ptr, data, 4);
10754 if (!have_data)
10756 /* Add an empty descriptor if there is no user-specified data. */
10757 ptr = frag_more (4);
10758 md_number_to_chars (ptr, 0, 4);
10761 return 0;
10764 /* Convert REGNAME to a DWARF-2 register number. */
10767 tc_arm_regname_to_dw2regnum (const char *regname)
10769 int reg = arm_reg_parse ((char **) &regname, REG_TYPE_RN);
10771 if (reg == FAIL)
10772 return -1;
10774 return reg;
10777 /* Initialize the DWARF-2 unwind information for this procedure. */
10779 void
10780 tc_arm_frame_initial_instructions (void)
10782 cfi_add_CFA_def_cfa (REG_SP, 0);
10784 #endif /* OBJ_ELF */
10787 /* MD interface: Symbol and relocation handling. */
10789 /* Return the address within the segment that a PC-relative fixup is
10790 relative to. For ARM, PC-relative fixups applied to instructions
10791 are generally relative to the location of the fixup plus 8 bytes.
10792 Thumb branches are offset by 4, and Thumb loads relative to PC
10793 require special handling. */
10795 long
10796 md_pcrel_from_section (fixS * fixP, segT seg)
10798 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
10800 /* If this is pc-relative and we are going to emit a relocation
10801 then we just want to put out any pipeline compensation that the linker
10802 will need. Otherwise we want to use the calculated base. */
10803 if (fixP->fx_pcrel
10804 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
10805 || arm_force_relocation (fixP)))
10806 base = 0;
10808 switch (fixP->fx_r_type)
10810 /* PC relative addressing on the Thumb is slightly odd as the
10811 bottom two bits of the PC are forced to zero for the
10812 calculation. This happens *after* application of the
10813 pipeline offset. However, Thumb adrl already adjusts for
10814 this, so we need not do it again. */
10815 case BFD_RELOC_ARM_THUMB_ADD:
10816 return base & ~3;
10818 case BFD_RELOC_ARM_THUMB_OFFSET:
10819 case BFD_RELOC_ARM_T32_OFFSET_IMM:
10820 case BFD_RELOC_ARM_T32_ADD_PC12:
10821 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
10822 return (base + 4) & ~3;
10824 /* Thumb branches are simply offset by +4. */
10825 case BFD_RELOC_THUMB_PCREL_BRANCH7:
10826 case BFD_RELOC_THUMB_PCREL_BRANCH9:
10827 case BFD_RELOC_THUMB_PCREL_BRANCH12:
10828 case BFD_RELOC_THUMB_PCREL_BRANCH20:
10829 case BFD_RELOC_THUMB_PCREL_BRANCH23:
10830 case BFD_RELOC_THUMB_PCREL_BRANCH25:
10831 case BFD_RELOC_THUMB_PCREL_BLX:
10832 return base + 4;
10834 /* ARM mode branches are offset by +8. However, the Windows CE
10835 loader expects the relocation not to take this into account. */
10836 case BFD_RELOC_ARM_PCREL_BRANCH:
10837 case BFD_RELOC_ARM_PCREL_BLX:
10838 case BFD_RELOC_ARM_PLT32:
10839 #ifdef TE_WINCE
10840 return base;
10841 #else
10842 return base + 8;
10843 #endif
10845 /* ARM mode loads relative to PC are also offset by +8. Unlike
10846 branches, the Windows CE loader *does* expect the relocation
10847 to take this into account. */
10848 case BFD_RELOC_ARM_OFFSET_IMM:
10849 case BFD_RELOC_ARM_OFFSET_IMM8:
10850 case BFD_RELOC_ARM_HWLITERAL:
10851 case BFD_RELOC_ARM_LITERAL:
10852 case BFD_RELOC_ARM_CP_OFF_IMM:
10853 return base + 8;
10856 /* Other PC-relative relocations are un-offset. */
10857 default:
10858 return base;
10862 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
10863 Otherwise we have no need to default values of symbols. */
10865 symbolS *
10866 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
10868 #ifdef OBJ_ELF
10869 if (name[0] == '_' && name[1] == 'G'
10870 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
10872 if (!GOT_symbol)
10874 if (symbol_find (name))
10875 as_bad ("GOT already in the symbol table");
10877 GOT_symbol = symbol_new (name, undefined_section,
10878 (valueT) 0, & zero_address_frag);
10881 return GOT_symbol;
10883 #endif
10885 return 0;
10888 /* Subroutine of md_apply_fix. Check to see if an immediate can be
10889 computed as two separate immediate values, added together. We
10890 already know that this value cannot be computed by just one ARM
10891 instruction. */
10893 static unsigned int
10894 validate_immediate_twopart (unsigned int val,
10895 unsigned int * highpart)
10897 unsigned int a;
10898 unsigned int i;
10900 for (i = 0; i < 32; i += 2)
10901 if (((a = rotate_left (val, i)) & 0xff) != 0)
10903 if (a & 0xff00)
10905 if (a & ~ 0xffff)
10906 continue;
10907 * highpart = (a >> 8) | ((i + 24) << 7);
10909 else if (a & 0xff0000)
10911 if (a & 0xff000000)
10912 continue;
10913 * highpart = (a >> 16) | ((i + 16) << 7);
10915 else
10917 assert (a & 0xff000000);
10918 * highpart = (a >> 24) | ((i + 8) << 7);
10921 return (a & 0xff) | (i << 7);
10924 return FAIL;
10927 static int
10928 validate_offset_imm (unsigned int val, int hwse)
10930 if ((hwse && val > 255) || val > 4095)
10931 return FAIL;
10932 return val;
10935 /* Subroutine of md_apply_fix. Do those data_ops which can take a
10936 negative immediate constant by altering the instruction. A bit of
10937 a hack really.
10938 MOV <-> MVN
10939 AND <-> BIC
10940 ADC <-> SBC
10941 by inverting the second operand, and
10942 ADD <-> SUB
10943 CMP <-> CMN
10944 by negating the second operand. */
10946 static int
10947 negate_data_op (unsigned long * instruction,
10948 unsigned long value)
10950 int op, new_inst;
10951 unsigned long negated, inverted;
10953 negated = encode_arm_immediate (-value);
10954 inverted = encode_arm_immediate (~value);
10956 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
10957 switch (op)
10959 /* First negates. */
10960 case OPCODE_SUB: /* ADD <-> SUB */
10961 new_inst = OPCODE_ADD;
10962 value = negated;
10963 break;
10965 case OPCODE_ADD:
10966 new_inst = OPCODE_SUB;
10967 value = negated;
10968 break;
10970 case OPCODE_CMP: /* CMP <-> CMN */
10971 new_inst = OPCODE_CMN;
10972 value = negated;
10973 break;
10975 case OPCODE_CMN:
10976 new_inst = OPCODE_CMP;
10977 value = negated;
10978 break;
10980 /* Now Inverted ops. */
10981 case OPCODE_MOV: /* MOV <-> MVN */
10982 new_inst = OPCODE_MVN;
10983 value = inverted;
10984 break;
10986 case OPCODE_MVN:
10987 new_inst = OPCODE_MOV;
10988 value = inverted;
10989 break;
10991 case OPCODE_AND: /* AND <-> BIC */
10992 new_inst = OPCODE_BIC;
10993 value = inverted;
10994 break;
10996 case OPCODE_BIC:
10997 new_inst = OPCODE_AND;
10998 value = inverted;
10999 break;
11001 case OPCODE_ADC: /* ADC <-> SBC */
11002 new_inst = OPCODE_SBC;
11003 value = inverted;
11004 break;
11006 case OPCODE_SBC:
11007 new_inst = OPCODE_ADC;
11008 value = inverted;
11009 break;
11011 /* We cannot do anything. */
11012 default:
11013 return FAIL;
11016 if (value == (unsigned) FAIL)
11017 return FAIL;
11019 *instruction &= OPCODE_MASK;
11020 *instruction |= new_inst << DATA_OP_SHIFT;
11021 return value;
11024 /* Read a 32-bit thumb instruction from buf. */
11025 static unsigned long
11026 get_thumb32_insn (char * buf)
11028 unsigned long insn;
11029 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
11030 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11032 return insn;
11035 void
11036 md_apply_fix (fixS * fixP,
11037 valueT * valP,
11038 segT seg)
11040 offsetT value = * valP;
11041 offsetT newval;
11042 unsigned int newimm;
11043 unsigned long temp;
11044 int sign;
11045 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
11047 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
11049 /* Note whether this will delete the relocation. */
11050 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
11051 fixP->fx_done = 1;
11053 /* On a 64-bit host, silently truncate 'value' to 32 bits for
11054 consistency with the behavior on 32-bit hosts. Remember value
11055 for emit_reloc. */
11056 value &= 0xffffffff;
11057 value ^= 0x80000000;
11058 value -= 0x80000000;
11060 *valP = value;
11061 fixP->fx_addnumber = value;
11063 /* Same treatment for fixP->fx_offset. */
11064 fixP->fx_offset &= 0xffffffff;
11065 fixP->fx_offset ^= 0x80000000;
11066 fixP->fx_offset -= 0x80000000;
11068 switch (fixP->fx_r_type)
11070 case BFD_RELOC_NONE:
11071 /* This will need to go in the object file. */
11072 fixP->fx_done = 0;
11073 break;
11075 case BFD_RELOC_ARM_IMMEDIATE:
11076 /* We claim that this fixup has been processed here,
11077 even if in fact we generate an error because we do
11078 not have a reloc for it, so tc_gen_reloc will reject it. */
11079 fixP->fx_done = 1;
11081 if (fixP->fx_addsy
11082 && ! S_IS_DEFINED (fixP->fx_addsy))
11084 as_bad_where (fixP->fx_file, fixP->fx_line,
11085 _("undefined symbol %s used as an immediate value"),
11086 S_GET_NAME (fixP->fx_addsy));
11087 break;
11090 newimm = encode_arm_immediate (value);
11091 temp = md_chars_to_number (buf, INSN_SIZE);
11093 /* If the instruction will fail, see if we can fix things up by
11094 changing the opcode. */
11095 if (newimm == (unsigned int) FAIL
11096 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
11098 as_bad_where (fixP->fx_file, fixP->fx_line,
11099 _("invalid constant (%lx) after fixup"),
11100 (unsigned long) value);
11101 break;
11104 newimm |= (temp & 0xfffff000);
11105 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
11106 break;
11108 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11110 unsigned int highpart = 0;
11111 unsigned int newinsn = 0xe1a00000; /* nop. */
11113 newimm = encode_arm_immediate (value);
11114 temp = md_chars_to_number (buf, INSN_SIZE);
11116 /* If the instruction will fail, see if we can fix things up by
11117 changing the opcode. */
11118 if (newimm == (unsigned int) FAIL
11119 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
11121 /* No ? OK - try using two ADD instructions to generate
11122 the value. */
11123 newimm = validate_immediate_twopart (value, & highpart);
11125 /* Yes - then make sure that the second instruction is
11126 also an add. */
11127 if (newimm != (unsigned int) FAIL)
11128 newinsn = temp;
11129 /* Still No ? Try using a negated value. */
11130 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
11131 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
11132 /* Otherwise - give up. */
11133 else
11135 as_bad_where (fixP->fx_file, fixP->fx_line,
11136 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
11137 (long) value);
11138 break;
11141 /* Replace the first operand in the 2nd instruction (which
11142 is the PC) with the destination register. We have
11143 already added in the PC in the first instruction and we
11144 do not want to do it again. */
11145 newinsn &= ~ 0xf0000;
11146 newinsn |= ((newinsn & 0x0f000) << 4);
11149 newimm |= (temp & 0xfffff000);
11150 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
11152 highpart |= (newinsn & 0xfffff000);
11153 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
11155 break;
11157 case BFD_RELOC_ARM_OFFSET_IMM:
11158 case BFD_RELOC_ARM_LITERAL:
11159 sign = value >= 0;
11161 if (value < 0)
11162 value = - value;
11164 if (validate_offset_imm (value, 0) == FAIL)
11166 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
11167 as_bad_where (fixP->fx_file, fixP->fx_line,
11168 _("invalid literal constant: pool needs to be closer"));
11169 else
11170 as_bad_where (fixP->fx_file, fixP->fx_line,
11171 _("bad immediate value for offset (%ld)"),
11172 (long) value);
11173 break;
11176 newval = md_chars_to_number (buf, INSN_SIZE);
11177 newval &= 0xff7ff000;
11178 newval |= value | (sign ? INDEX_UP : 0);
11179 md_number_to_chars (buf, newval, INSN_SIZE);
11180 break;
11182 case BFD_RELOC_ARM_OFFSET_IMM8:
11183 case BFD_RELOC_ARM_HWLITERAL:
11184 sign = value >= 0;
11186 if (value < 0)
11187 value = - value;
11189 if (validate_offset_imm (value, 1) == FAIL)
11191 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
11192 as_bad_where (fixP->fx_file, fixP->fx_line,
11193 _("invalid literal constant: pool needs to be closer"));
11194 else
11195 as_bad (_("bad immediate value for half-word offset (%ld)"),
11196 (long) value);
11197 break;
11200 newval = md_chars_to_number (buf, INSN_SIZE);
11201 newval &= 0xff7ff0f0;
11202 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
11203 md_number_to_chars (buf, newval, INSN_SIZE);
11204 break;
11206 case BFD_RELOC_ARM_T32_OFFSET_U8:
11207 if (value < 0 || value > 1020 || value % 4 != 0)
11208 as_bad_where (fixP->fx_file, fixP->fx_line,
11209 _("bad immediate value for offset (%ld)"), (long) value);
11210 value /= 4;
11212 newval = md_chars_to_number (buf+2, THUMB_SIZE);
11213 newval |= value;
11214 md_number_to_chars (buf+2, newval, THUMB_SIZE);
11215 break;
11217 case BFD_RELOC_ARM_T32_OFFSET_IMM:
11218 /* This is a complicated relocation used for all varieties of Thumb32
11219 load/store instruction with immediate offset:
11221 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
11222 *4, optional writeback(W)
11223 (doubleword load/store)
11225 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
11226 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
11227 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
11228 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
11229 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
11231 Uppercase letters indicate bits that are already encoded at
11232 this point. Lowercase letters are our problem. For the
11233 second block of instructions, the secondary opcode nybble
11234 (bits 8..11) is present, and bit 23 is zero, even if this is
11235 a PC-relative operation. */
11236 newval = md_chars_to_number (buf, THUMB_SIZE);
11237 newval <<= 16;
11238 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
11240 if ((newval & 0xf0000000) == 0xe0000000)
11242 /* Doubleword load/store: 8-bit offset, scaled by 4. */
11243 if (value >= 0)
11244 newval |= (1 << 23);
11245 else
11246 value = -value;
11247 if (value % 4 != 0)
11249 as_bad_where (fixP->fx_file, fixP->fx_line,
11250 _("offset not a multiple of 4"));
11251 break;
11253 value /= 4;
11254 if (value >= 0xff)
11256 as_bad_where (fixP->fx_file, fixP->fx_line,
11257 _("offset out of range"));
11258 break;
11260 newval &= ~0xff;
11262 else if ((newval & 0x000f0000) == 0x000f0000)
11264 /* PC-relative, 12-bit offset. */
11265 if (value >= 0)
11266 newval |= (1 << 23);
11267 else
11268 value = -value;
11269 if (value >= 0xfff)
11271 as_bad_where (fixP->fx_file, fixP->fx_line,
11272 _("offset out of range"));
11273 break;
11275 newval &= ~0xfff;
11277 else if ((newval & 0x00000100) == 0x00000100)
11279 /* Writeback: 8-bit, +/- offset. */
11280 if (value >= 0)
11281 newval |= (1 << 9);
11282 else
11283 value = -value;
11284 if (value >= 0xff)
11286 as_bad_where (fixP->fx_file, fixP->fx_line,
11287 _("offset out of range"));
11288 break;
11290 newval &= ~0xff;
11292 else if ((newval & 0x00000f00) == 0x00000e00)
11294 /* T-instruction: positive 8-bit offset. */
11295 if (value < 0 || value >= 0xff)
11297 as_bad_where (fixP->fx_file, fixP->fx_line,
11298 _("offset out of range"));
11299 break;
11301 newval &= ~0xff;
11302 newval |= value;
11304 else
11306 /* Positive 12-bit or negative 8-bit offset. */
11307 int limit;
11308 if (value >= 0)
11310 newval |= (1 << 23);
11311 limit = 0xfff;
11313 else
11315 value = -value;
11316 limit = 0xff;
11318 if (value > limit)
11320 as_bad_where (fixP->fx_file, fixP->fx_line,
11321 _("offset out of range"));
11322 break;
11324 newval &= ~limit;
11327 newval |= value;
11328 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
11329 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
11330 break;
11332 case BFD_RELOC_ARM_SHIFT_IMM:
11333 newval = md_chars_to_number (buf, INSN_SIZE);
11334 if (((unsigned long) value) > 32
11335 || (value == 32
11336 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
11338 as_bad_where (fixP->fx_file, fixP->fx_line,
11339 _("shift expression is too large"));
11340 break;
11343 if (value == 0)
11344 /* Shifts of zero must be done as lsl. */
11345 newval &= ~0x60;
11346 else if (value == 32)
11347 value = 0;
11348 newval &= 0xfffff07f;
11349 newval |= (value & 0x1f) << 7;
11350 md_number_to_chars (buf, newval, INSN_SIZE);
11351 break;
11353 case BFD_RELOC_ARM_T32_IMMEDIATE:
11354 case BFD_RELOC_ARM_T32_IMM12:
11355 case BFD_RELOC_ARM_T32_ADD_PC12:
11356 /* We claim that this fixup has been processed here,
11357 even if in fact we generate an error because we do
11358 not have a reloc for it, so tc_gen_reloc will reject it. */
11359 fixP->fx_done = 1;
11361 if (fixP->fx_addsy
11362 && ! S_IS_DEFINED (fixP->fx_addsy))
11364 as_bad_where (fixP->fx_file, fixP->fx_line,
11365 _("undefined symbol %s used as an immediate value"),
11366 S_GET_NAME (fixP->fx_addsy));
11367 break;
11370 newval = md_chars_to_number (buf, THUMB_SIZE);
11371 newval <<= 16;
11372 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
11374 /* FUTURE: Implement analogue of negate_data_op for T32. */
11375 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE)
11376 newimm = encode_thumb32_immediate (value);
11377 else
11379 /* 12 bit immediate for addw/subw. */
11380 if (value < 0)
11382 value = -value;
11383 newval ^= 0x00a00000;
11385 if (value > 0xfff)
11386 newimm = (unsigned int) FAIL;
11387 else
11388 newimm = value;
11391 if (newimm == (unsigned int)FAIL)
11393 as_bad_where (fixP->fx_file, fixP->fx_line,
11394 _("invalid constant (%lx) after fixup"),
11395 (unsigned long) value);
11396 break;
11399 newval |= (newimm & 0x800) << 15;
11400 newval |= (newimm & 0x700) << 4;
11401 newval |= (newimm & 0x0ff);
11403 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
11404 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
11405 break;
11407 case BFD_RELOC_ARM_SMC:
11408 if (((unsigned long) value) > 0xffff)
11409 as_bad_where (fixP->fx_file, fixP->fx_line,
11410 _("invalid smc expression"));
11411 newval = md_chars_to_number (buf, INSN_SIZE);
11412 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
11413 md_number_to_chars (buf, newval, INSN_SIZE);
11414 break;
11416 case BFD_RELOC_ARM_SWI:
11417 if (fixP->tc_fix_data != 0)
11419 if (((unsigned long) value) > 0xff)
11420 as_bad_where (fixP->fx_file, fixP->fx_line,
11421 _("invalid swi expression"));
11422 newval = md_chars_to_number (buf, THUMB_SIZE);
11423 newval |= value;
11424 md_number_to_chars (buf, newval, THUMB_SIZE);
11426 else
11428 if (((unsigned long) value) > 0x00ffffff)
11429 as_bad_where (fixP->fx_file, fixP->fx_line,
11430 _("invalid swi expression"));
11431 newval = md_chars_to_number (buf, INSN_SIZE);
11432 newval |= value;
11433 md_number_to_chars (buf, newval, INSN_SIZE);
11435 break;
11437 case BFD_RELOC_ARM_MULTI:
11438 if (((unsigned long) value) > 0xffff)
11439 as_bad_where (fixP->fx_file, fixP->fx_line,
11440 _("invalid expression in load/store multiple"));
11441 newval = value | md_chars_to_number (buf, INSN_SIZE);
11442 md_number_to_chars (buf, newval, INSN_SIZE);
11443 break;
11445 case BFD_RELOC_ARM_PCREL_BRANCH:
11446 #ifdef OBJ_ELF
11447 case BFD_RELOC_ARM_PLT32:
11448 #endif
11450 /* We are going to store value (shifted right by two) in the
11451 instruction, in a 24 bit, signed field. Bits 0 and 1 must be
11452 clear, and bits 26 through 32 either all clear or all set. */
11453 if (value & 0x00000003)
11454 as_bad_where (fixP->fx_file, fixP->fx_line,
11455 _("misaligned branch destination"));
11456 if ((value & (offsetT)0xfe000000) != (offsetT)0
11457 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
11458 as_bad_where (fixP->fx_file, fixP->fx_line,
11459 _("branch out of range"));
11461 if (fixP->fx_done || !seg->use_rela_p)
11463 newval = md_chars_to_number (buf, INSN_SIZE);
11464 newval |= (value >> 2) & 0x00ffffff;
11465 md_number_to_chars (buf, newval, INSN_SIZE);
11467 break;
11469 case BFD_RELOC_ARM_PCREL_BLX:
11470 /* BLX allows bit 1 to be set in the branch destination, since
11471 it targets a Thumb instruction which is only required to be
11472 aligned modulo 2. Other constraints are as for B/BL. */
11473 if (value & 0x00000001)
11474 as_bad_where (fixP->fx_file, fixP->fx_line,
11475 _("misaligned BLX destination"));
11476 if ((value & (offsetT)0xfe000000) != (offsetT)0
11477 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
11478 as_bad_where (fixP->fx_file, fixP->fx_line,
11479 _("branch out of range"));
11481 if (fixP->fx_done || !seg->use_rela_p)
11483 offsetT hbit;
11484 hbit = (value >> 1) & 1;
11485 value = (value >> 2) & 0x00ffffff;
11487 newval = md_chars_to_number (buf, INSN_SIZE);
11488 newval |= value | hbit << 24;
11489 md_number_to_chars (buf, newval, INSN_SIZE);
11491 break;
11493 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
11494 /* CZB can only branch forward. */
11495 if (value & ~0x7e)
11496 as_bad_where (fixP->fx_file, fixP->fx_line,
11497 _("branch out of range"));
11499 if (fixP->fx_done || !seg->use_rela_p)
11501 newval = md_chars_to_number (buf, THUMB_SIZE);
11502 newval |= ((value & 0x2e) << 2) | ((value & 0x40) << 3);
11503 md_number_to_chars (buf, newval, THUMB_SIZE);
11505 break;
11507 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
11508 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
11509 as_bad_where (fixP->fx_file, fixP->fx_line,
11510 _("branch out of range"));
11512 if (fixP->fx_done || !seg->use_rela_p)
11514 newval = md_chars_to_number (buf, THUMB_SIZE);
11515 newval |= (value & 0x1ff) >> 1;
11516 md_number_to_chars (buf, newval, THUMB_SIZE);
11518 break;
11520 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
11521 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
11522 as_bad_where (fixP->fx_file, fixP->fx_line,
11523 _("branch out of range"));
11525 if (fixP->fx_done || !seg->use_rela_p)
11527 newval = md_chars_to_number (buf, THUMB_SIZE);
11528 newval |= (value & 0xfff) >> 1;
11529 md_number_to_chars (buf, newval, THUMB_SIZE);
11531 break;
11533 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11534 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
11535 as_bad_where (fixP->fx_file, fixP->fx_line,
11536 _("conditional branch out of range"));
11538 if (fixP->fx_done || !seg->use_rela_p)
11540 offsetT newval2;
11541 addressT S, J1, J2, lo, hi;
11543 S = (value & 0x00100000) >> 20;
11544 J2 = (value & 0x00080000) >> 19;
11545 J1 = (value & 0x00040000) >> 18;
11546 hi = (value & 0x0003f000) >> 12;
11547 lo = (value & 0x00000ffe) >> 1;
11549 newval = md_chars_to_number (buf, THUMB_SIZE);
11550 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11551 newval |= (S << 10) | hi;
11552 newval2 |= (J1 << 13) | (J2 << 11) | lo;
11553 md_number_to_chars (buf, newval, THUMB_SIZE);
11554 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
11556 break;
11558 case BFD_RELOC_THUMB_PCREL_BLX:
11559 case BFD_RELOC_THUMB_PCREL_BRANCH23:
11560 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
11561 as_bad_where (fixP->fx_file, fixP->fx_line,
11562 _("branch out of range"));
11564 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
11565 /* For a BLX instruction, make sure that the relocation is rounded up
11566 to a word boundary. This follows the semantics of the instruction
11567 which specifies that bit 1 of the target address will come from bit
11568 1 of the base address. */
11569 value = (value + 1) & ~ 1;
11571 if (fixP->fx_done || !seg->use_rela_p)
11573 offsetT newval2;
11575 newval = md_chars_to_number (buf, THUMB_SIZE);
11576 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11577 newval |= (value & 0x7fffff) >> 12;
11578 newval2 |= (value & 0xfff) >> 1;
11579 md_number_to_chars (buf, newval, THUMB_SIZE);
11580 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
11582 break;
11584 case BFD_RELOC_THUMB_PCREL_BRANCH25:
11585 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
11586 as_bad_where (fixP->fx_file, fixP->fx_line,
11587 _("branch out of range"));
11589 if (fixP->fx_done || !seg->use_rela_p)
11591 offsetT newval2;
11592 addressT S, I1, I2, lo, hi;
11594 S = (value & 0x01000000) >> 24;
11595 I1 = (value & 0x00800000) >> 23;
11596 I2 = (value & 0x00400000) >> 22;
11597 hi = (value & 0x003ff000) >> 12;
11598 lo = (value & 0x00000ffe) >> 1;
11600 I1 = !(I1 ^ S);
11601 I2 = !(I2 ^ S);
11603 newval = md_chars_to_number (buf, THUMB_SIZE);
11604 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11605 newval |= (S << 10) | hi;
11606 newval2 |= (I1 << 13) | (I2 << 11) | lo;
11607 md_number_to_chars (buf, newval, THUMB_SIZE);
11608 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
11610 break;
11612 case BFD_RELOC_8:
11613 if (fixP->fx_done || !seg->use_rela_p)
11614 md_number_to_chars (buf, value, 1);
11615 break;
11617 case BFD_RELOC_16:
11618 if (fixP->fx_done || !seg->use_rela_p)
11619 md_number_to_chars (buf, value, 2);
11620 break;
11622 #ifdef OBJ_ELF
11623 case BFD_RELOC_ARM_TLS_GD32:
11624 case BFD_RELOC_ARM_TLS_LE32:
11625 case BFD_RELOC_ARM_TLS_IE32:
11626 case BFD_RELOC_ARM_TLS_LDM32:
11627 case BFD_RELOC_ARM_TLS_LDO32:
11628 S_SET_THREAD_LOCAL (fixP->fx_addsy);
11629 /* fall through */
11631 case BFD_RELOC_ARM_GOT32:
11632 case BFD_RELOC_ARM_GOTOFF:
11633 case BFD_RELOC_ARM_TARGET2:
11634 if (fixP->fx_done || !seg->use_rela_p)
11635 md_number_to_chars (buf, 0, 4);
11636 break;
11637 #endif
11639 case BFD_RELOC_RVA:
11640 case BFD_RELOC_32:
11641 case BFD_RELOC_ARM_TARGET1:
11642 case BFD_RELOC_ARM_ROSEGREL32:
11643 case BFD_RELOC_ARM_SBREL32:
11644 case BFD_RELOC_32_PCREL:
11645 if (fixP->fx_done || !seg->use_rela_p)
11646 md_number_to_chars (buf, value, 4);
11647 break;
11649 #ifdef OBJ_ELF
11650 case BFD_RELOC_ARM_PREL31:
11651 if (fixP->fx_done || !seg->use_rela_p)
11653 newval = md_chars_to_number (buf, 4) & 0x80000000;
11654 if ((value ^ (value >> 1)) & 0x40000000)
11656 as_bad_where (fixP->fx_file, fixP->fx_line,
11657 _("rel31 relocation overflow"));
11659 newval |= value & 0x7fffffff;
11660 md_number_to_chars (buf, newval, 4);
11662 break;
11663 #endif
11665 case BFD_RELOC_ARM_CP_OFF_IMM:
11666 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
11667 if (value < -1023 || value > 1023 || (value & 3))
11668 as_bad_where (fixP->fx_file, fixP->fx_line,
11669 _("co-processor offset out of range"));
11670 cp_off_common:
11671 sign = value >= 0;
11672 if (value < 0)
11673 value = -value;
11674 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
11675 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
11676 newval = md_chars_to_number (buf, INSN_SIZE);
11677 else
11678 newval = get_thumb32_insn (buf);
11679 newval &= 0xff7fff00;
11680 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
11681 if (value == 0)
11682 newval &= ~WRITE_BACK;
11683 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
11684 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
11685 md_number_to_chars (buf, newval, INSN_SIZE);
11686 else
11687 put_thumb32_insn (buf, newval);
11688 break;
11690 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
11691 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
11692 if (value < -255 || value > 255)
11693 as_bad_where (fixP->fx_file, fixP->fx_line,
11694 _("co-processor offset out of range"));
11695 goto cp_off_common;
11697 case BFD_RELOC_ARM_THUMB_OFFSET:
11698 newval = md_chars_to_number (buf, THUMB_SIZE);
11699 /* Exactly what ranges, and where the offset is inserted depends
11700 on the type of instruction, we can establish this from the
11701 top 4 bits. */
11702 switch (newval >> 12)
11704 case 4: /* PC load. */
11705 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
11706 forced to zero for these loads; md_pcrel_from has already
11707 compensated for this. */
11708 if (value & 3)
11709 as_bad_where (fixP->fx_file, fixP->fx_line,
11710 _("invalid offset, target not word aligned (0x%08lX)"),
11711 (((unsigned int) fixP->fx_frag->fr_address
11712 + (unsigned int) fixP->fx_where) & ~3) + value);
11714 if (value & ~0x3fc)
11715 as_bad_where (fixP->fx_file, fixP->fx_line,
11716 _("invalid offset, value too big (0x%08lX)"),
11717 (long) value);
11719 newval |= value >> 2;
11720 break;
11722 case 9: /* SP load/store. */
11723 if (value & ~0x3fc)
11724 as_bad_where (fixP->fx_file, fixP->fx_line,
11725 _("invalid offset, value too big (0x%08lX)"),
11726 (long) value);
11727 newval |= value >> 2;
11728 break;
11730 case 6: /* Word load/store. */
11731 if (value & ~0x7c)
11732 as_bad_where (fixP->fx_file, fixP->fx_line,
11733 _("invalid offset, value too big (0x%08lX)"),
11734 (long) value);
11735 newval |= value << 4; /* 6 - 2. */
11736 break;
11738 case 7: /* Byte load/store. */
11739 if (value & ~0x1f)
11740 as_bad_where (fixP->fx_file, fixP->fx_line,
11741 _("invalid offset, value too big (0x%08lX)"),
11742 (long) value);
11743 newval |= value << 6;
11744 break;
11746 case 8: /* Halfword load/store. */
11747 if (value & ~0x3e)
11748 as_bad_where (fixP->fx_file, fixP->fx_line,
11749 _("invalid offset, value too big (0x%08lX)"),
11750 (long) value);
11751 newval |= value << 5; /* 6 - 1. */
11752 break;
11754 default:
11755 as_bad_where (fixP->fx_file, fixP->fx_line,
11756 "Unable to process relocation for thumb opcode: %lx",
11757 (unsigned long) newval);
11758 break;
11760 md_number_to_chars (buf, newval, THUMB_SIZE);
11761 break;
11763 case BFD_RELOC_ARM_THUMB_ADD:
11764 /* This is a complicated relocation, since we use it for all of
11765 the following immediate relocations:
11767 3bit ADD/SUB
11768 8bit ADD/SUB
11769 9bit ADD/SUB SP word-aligned
11770 10bit ADD PC/SP word-aligned
11772 The type of instruction being processed is encoded in the
11773 instruction field:
11775 0x8000 SUB
11776 0x00F0 Rd
11777 0x000F Rs
11779 newval = md_chars_to_number (buf, THUMB_SIZE);
11781 int rd = (newval >> 4) & 0xf;
11782 int rs = newval & 0xf;
11783 int subtract = !!(newval & 0x8000);
11785 /* Check for HI regs, only very restricted cases allowed:
11786 Adjusting SP, and using PC or SP to get an address. */
11787 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
11788 || (rs > 7 && rs != REG_SP && rs != REG_PC))
11789 as_bad_where (fixP->fx_file, fixP->fx_line,
11790 _("invalid Hi register with immediate"));
11792 /* If value is negative, choose the opposite instruction. */
11793 if (value < 0)
11795 value = -value;
11796 subtract = !subtract;
11797 if (value < 0)
11798 as_bad_where (fixP->fx_file, fixP->fx_line,
11799 _("immediate value out of range"));
11802 if (rd == REG_SP)
11804 if (value & ~0x1fc)
11805 as_bad_where (fixP->fx_file, fixP->fx_line,
11806 _("invalid immediate for stack address calculation"));
11807 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
11808 newval |= value >> 2;
11810 else if (rs == REG_PC || rs == REG_SP)
11812 if (subtract || value & ~0x3fc)
11813 as_bad_where (fixP->fx_file, fixP->fx_line,
11814 _("invalid immediate for address calculation (value = 0x%08lX)"),
11815 (unsigned long) value);
11816 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
11817 newval |= rd << 8;
11818 newval |= value >> 2;
11820 else if (rs == rd)
11822 if (value & ~0xff)
11823 as_bad_where (fixP->fx_file, fixP->fx_line,
11824 _("immediate value out of range"));
11825 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
11826 newval |= (rd << 8) | value;
11828 else
11830 if (value & ~0x7)
11831 as_bad_where (fixP->fx_file, fixP->fx_line,
11832 _("immediate value out of range"));
11833 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
11834 newval |= rd | (rs << 3) | (value << 6);
11837 md_number_to_chars (buf, newval, THUMB_SIZE);
11838 break;
11840 case BFD_RELOC_ARM_THUMB_IMM:
11841 newval = md_chars_to_number (buf, THUMB_SIZE);
11842 if (value < 0 || value > 255)
11843 as_bad_where (fixP->fx_file, fixP->fx_line,
11844 _("invalid immediate: %ld is too large"),
11845 (long) value);
11846 newval |= value;
11847 md_number_to_chars (buf, newval, THUMB_SIZE);
11848 break;
11850 case BFD_RELOC_ARM_THUMB_SHIFT:
11851 /* 5bit shift value (0..32). LSL cannot take 32. */
11852 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
11853 temp = newval & 0xf800;
11854 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
11855 as_bad_where (fixP->fx_file, fixP->fx_line,
11856 _("invalid shift value: %ld"), (long) value);
11857 /* Shifts of zero must be encoded as LSL. */
11858 if (value == 0)
11859 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
11860 /* Shifts of 32 are encoded as zero. */
11861 else if (value == 32)
11862 value = 0;
11863 newval |= value << 6;
11864 md_number_to_chars (buf, newval, THUMB_SIZE);
11865 break;
11867 case BFD_RELOC_VTABLE_INHERIT:
11868 case BFD_RELOC_VTABLE_ENTRY:
11869 fixP->fx_done = 0;
11870 return;
11872 case BFD_RELOC_UNUSED:
11873 default:
11874 as_bad_where (fixP->fx_file, fixP->fx_line,
11875 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
11879 /* Translate internal representation of relocation info to BFD target
11880 format. */
11882 arelent *
11883 tc_gen_reloc (asection * section ATTRIBUTE_UNUSED,
11884 fixS * fixp)
11886 arelent * reloc;
11887 bfd_reloc_code_real_type code;
11889 reloc = xmalloc (sizeof (arelent));
11891 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
11892 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11893 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11895 if (fixp->fx_pcrel)
11896 fixp->fx_offset = reloc->address;
11897 reloc->addend = fixp->fx_offset;
11899 switch (fixp->fx_r_type)
11901 case BFD_RELOC_8:
11902 if (fixp->fx_pcrel)
11904 code = BFD_RELOC_8_PCREL;
11905 break;
11908 case BFD_RELOC_16:
11909 if (fixp->fx_pcrel)
11911 code = BFD_RELOC_16_PCREL;
11912 break;
11915 case BFD_RELOC_32:
11916 if (fixp->fx_pcrel)
11918 code = BFD_RELOC_32_PCREL;
11919 break;
11922 case BFD_RELOC_NONE:
11923 case BFD_RELOC_ARM_PCREL_BRANCH:
11924 case BFD_RELOC_ARM_PCREL_BLX:
11925 case BFD_RELOC_RVA:
11926 case BFD_RELOC_THUMB_PCREL_BRANCH7:
11927 case BFD_RELOC_THUMB_PCREL_BRANCH9:
11928 case BFD_RELOC_THUMB_PCREL_BRANCH12:
11929 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11930 case BFD_RELOC_THUMB_PCREL_BRANCH23:
11931 case BFD_RELOC_THUMB_PCREL_BRANCH25:
11932 case BFD_RELOC_THUMB_PCREL_BLX:
11933 case BFD_RELOC_VTABLE_ENTRY:
11934 case BFD_RELOC_VTABLE_INHERIT:
11935 code = fixp->fx_r_type;
11936 break;
11938 case BFD_RELOC_ARM_LITERAL:
11939 case BFD_RELOC_ARM_HWLITERAL:
11940 /* If this is called then the a literal has
11941 been referenced across a section boundary. */
11942 as_bad_where (fixp->fx_file, fixp->fx_line,
11943 _("literal referenced across section boundary"));
11944 return NULL;
11946 #ifdef OBJ_ELF
11947 case BFD_RELOC_ARM_GOT32:
11948 case BFD_RELOC_ARM_GOTOFF:
11949 case BFD_RELOC_ARM_PLT32:
11950 case BFD_RELOC_ARM_TARGET1:
11951 case BFD_RELOC_ARM_ROSEGREL32:
11952 case BFD_RELOC_ARM_SBREL32:
11953 case BFD_RELOC_ARM_PREL31:
11954 case BFD_RELOC_ARM_TARGET2:
11955 case BFD_RELOC_ARM_TLS_LE32:
11956 case BFD_RELOC_ARM_TLS_LDO32:
11957 code = fixp->fx_r_type;
11958 break;
11960 case BFD_RELOC_ARM_TLS_GD32:
11961 case BFD_RELOC_ARM_TLS_IE32:
11962 case BFD_RELOC_ARM_TLS_LDM32:
11963 /* BFD will include the symbol's address in the addend.
11964 But we don't want that, so subtract it out again here. */
11965 if (!S_IS_COMMON (fixp->fx_addsy))
11966 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
11967 code = fixp->fx_r_type;
11968 break;
11969 #endif
11971 case BFD_RELOC_ARM_IMMEDIATE:
11972 as_bad_where (fixp->fx_file, fixp->fx_line,
11973 _("internal relocation (type: IMMEDIATE) not fixed up"));
11974 return NULL;
11976 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11977 as_bad_where (fixp->fx_file, fixp->fx_line,
11978 _("ADRL used for a symbol not defined in the same file"));
11979 return NULL;
11981 case BFD_RELOC_ARM_OFFSET_IMM:
11982 if (fixp->fx_addsy != NULL
11983 && !S_IS_DEFINED (fixp->fx_addsy)
11984 && S_IS_LOCAL (fixp->fx_addsy))
11986 as_bad_where (fixp->fx_file, fixp->fx_line,
11987 _("undefined local label `%s'"),
11988 S_GET_NAME (fixp->fx_addsy));
11989 return NULL;
11992 as_bad_where (fixp->fx_file, fixp->fx_line,
11993 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
11994 return NULL;
11996 default:
11998 char * type;
12000 switch (fixp->fx_r_type)
12002 case BFD_RELOC_NONE: type = "NONE"; break;
12003 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
12004 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
12005 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
12006 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
12007 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
12008 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
12009 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
12010 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
12011 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
12012 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
12013 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
12014 default: type = _("<unknown>"); break;
12016 as_bad_where (fixp->fx_file, fixp->fx_line,
12017 _("cannot represent %s relocation in this object file format"),
12018 type);
12019 return NULL;
12023 #ifdef OBJ_ELF
12024 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
12025 && GOT_symbol
12026 && fixp->fx_addsy == GOT_symbol)
12028 code = BFD_RELOC_ARM_GOTPC;
12029 reloc->addend = fixp->fx_offset = reloc->address;
12031 #endif
12033 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
12035 if (reloc->howto == NULL)
12037 as_bad_where (fixp->fx_file, fixp->fx_line,
12038 _("cannot represent %s relocation in this object file format"),
12039 bfd_get_reloc_code_name (code));
12040 return NULL;
12043 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
12044 vtable entry to be used in the relocation's section offset. */
12045 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12046 reloc->address = fixp->fx_offset;
12048 return reloc;
12051 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
12053 void
12054 cons_fix_new_arm (fragS * frag,
12055 int where,
12056 int size,
12057 expressionS * exp)
12059 bfd_reloc_code_real_type type;
12060 int pcrel = 0;
12062 /* Pick a reloc.
12063 FIXME: @@ Should look at CPU word size. */
12064 switch (size)
12066 case 1:
12067 type = BFD_RELOC_8;
12068 break;
12069 case 2:
12070 type = BFD_RELOC_16;
12071 break;
12072 case 4:
12073 default:
12074 type = BFD_RELOC_32;
12075 break;
12076 case 8:
12077 type = BFD_RELOC_64;
12078 break;
12081 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
12084 #if defined OBJ_COFF || defined OBJ_ELF
12085 void
12086 arm_validate_fix (fixS * fixP)
12088 /* If the destination of the branch is a defined symbol which does not have
12089 the THUMB_FUNC attribute, then we must be calling a function which has
12090 the (interfacearm) attribute. We look for the Thumb entry point to that
12091 function and change the branch to refer to that function instead. */
12092 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
12093 && fixP->fx_addsy != NULL
12094 && S_IS_DEFINED (fixP->fx_addsy)
12095 && ! THUMB_IS_FUNC (fixP->fx_addsy))
12097 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
12100 #endif
12103 arm_force_relocation (struct fix * fixp)
12105 #if defined (OBJ_COFF) && defined (TE_PE)
12106 if (fixp->fx_r_type == BFD_RELOC_RVA)
12107 return 1;
12108 #endif
12110 /* Resolve these relocations even if the symbol is extern or weak. */
12111 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
12112 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
12113 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
12114 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
12115 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
12116 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
12117 return 0;
12119 return generic_force_reloc (fixp);
12122 #ifdef OBJ_COFF
12123 /* This is a little hack to help the gas/arm/adrl.s test. It prevents
12124 local labels from being added to the output symbol table when they
12125 are used with the ADRL pseudo op. The ADRL relocation should always
12126 be resolved before the binbary is emitted, so it is safe to say that
12127 it is adjustable. */
12129 bfd_boolean
12130 arm_fix_adjustable (fixS * fixP)
12132 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
12133 return 1;
12134 return 0;
12136 #endif
12138 #ifdef OBJ_ELF
12139 /* Relocations against Thumb function names must be left unadjusted,
12140 so that the linker can use this information to correctly set the
12141 bottom bit of their addresses. The MIPS version of this function
12142 also prevents relocations that are mips-16 specific, but I do not
12143 know why it does this.
12145 FIXME:
12146 There is one other problem that ought to be addressed here, but
12147 which currently is not: Taking the address of a label (rather
12148 than a function) and then later jumping to that address. Such
12149 addresses also ought to have their bottom bit set (assuming that
12150 they reside in Thumb code), but at the moment they will not. */
12152 bfd_boolean
12153 arm_fix_adjustable (fixS * fixP)
12155 if (fixP->fx_addsy == NULL)
12156 return 1;
12158 if (THUMB_IS_FUNC (fixP->fx_addsy)
12159 && fixP->fx_subsy == NULL)
12160 return 0;
12162 /* We need the symbol name for the VTABLE entries. */
12163 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12164 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12165 return 0;
12167 /* Don't allow symbols to be discarded on GOT related relocs. */
12168 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
12169 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
12170 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
12171 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
12172 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
12173 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
12174 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
12175 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
12176 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
12177 return 0;
12179 return 1;
12182 const char *
12183 elf32_arm_target_format (void)
12185 #ifdef TE_SYMBIAN
12186 return (target_big_endian
12187 ? "elf32-bigarm-symbian"
12188 : "elf32-littlearm-symbian");
12189 #elif defined (TE_VXWORKS)
12190 return (target_big_endian
12191 ? "elf32-bigarm-vxworks"
12192 : "elf32-littlearm-vxworks");
12193 #else
12194 if (target_big_endian)
12195 return "elf32-bigarm";
12196 else
12197 return "elf32-littlearm";
12198 #endif
12201 void
12202 armelf_frob_symbol (symbolS * symp,
12203 int * puntp)
12205 elf_frob_symbol (symp, puntp);
12207 #endif
12209 /* MD interface: Finalization. */
12211 /* A good place to do this, although this was probably not intended
12212 for this kind of use. We need to dump the literal pool before
12213 references are made to a null symbol pointer. */
12215 void
12216 arm_cleanup (void)
12218 literal_pool * pool;
12220 for (pool = list_of_pools; pool; pool = pool->next)
12222 /* Put it at the end of the relevent section. */
12223 subseg_set (pool->section, pool->sub_section);
12224 #ifdef OBJ_ELF
12225 arm_elf_change_section ();
12226 #endif
12227 s_ltorg (0);
12231 /* Adjust the symbol table. This marks Thumb symbols as distinct from
12232 ARM ones. */
12234 void
12235 arm_adjust_symtab (void)
12237 #ifdef OBJ_COFF
12238 symbolS * sym;
12240 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
12242 if (ARM_IS_THUMB (sym))
12244 if (THUMB_IS_FUNC (sym))
12246 /* Mark the symbol as a Thumb function. */
12247 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
12248 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
12249 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
12251 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
12252 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
12253 else
12254 as_bad (_("%s: unexpected function type: %d"),
12255 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
12257 else switch (S_GET_STORAGE_CLASS (sym))
12259 case C_EXT:
12260 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
12261 break;
12262 case C_STAT:
12263 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
12264 break;
12265 case C_LABEL:
12266 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
12267 break;
12268 default:
12269 /* Do nothing. */
12270 break;
12274 if (ARM_IS_INTERWORK (sym))
12275 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
12277 #endif
12278 #ifdef OBJ_ELF
12279 symbolS * sym;
12280 char bind;
12282 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
12284 if (ARM_IS_THUMB (sym))
12286 elf_symbol_type * elf_sym;
12288 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
12289 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
12291 if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name))
12293 /* If it's a .thumb_func, declare it as so,
12294 otherwise tag label as .code 16. */
12295 if (THUMB_IS_FUNC (sym))
12296 elf_sym->internal_elf_sym.st_info =
12297 ELF_ST_INFO (bind, STT_ARM_TFUNC);
12298 else
12299 elf_sym->internal_elf_sym.st_info =
12300 ELF_ST_INFO (bind, STT_ARM_16BIT);
12304 #endif
12307 /* MD interface: Initialization. */
12309 static void
12310 set_constant_flonums (void)
12312 int i;
12314 for (i = 0; i < NUM_FLOAT_VALS; i++)
12315 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
12316 abort ();
12319 void
12320 md_begin (void)
12322 unsigned mach;
12323 unsigned int i;
12325 if ( (arm_ops_hsh = hash_new ()) == NULL
12326 || (arm_cond_hsh = hash_new ()) == NULL
12327 || (arm_shift_hsh = hash_new ()) == NULL
12328 || (arm_psr_hsh = hash_new ()) == NULL
12329 || (arm_reg_hsh = hash_new ()) == NULL
12330 || (arm_reloc_hsh = hash_new ()) == NULL)
12331 as_fatal (_("virtual memory exhausted"));
12333 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
12334 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
12335 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
12336 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
12337 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
12338 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
12339 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
12340 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
12341 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
12342 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
12343 #ifdef OBJ_ELF
12344 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
12345 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
12346 #endif
12348 set_constant_flonums ();
12350 /* Set the cpu variant based on the command-line options. We prefer
12351 -mcpu= over -march= if both are set (as for GCC); and we prefer
12352 -mfpu= over any other way of setting the floating point unit.
12353 Use of legacy options with new options are faulted. */
12354 if (legacy_cpu != -1)
12356 if (mcpu_cpu_opt != -1 || march_cpu_opt != -1)
12357 as_bad (_("use of old and new-style options to set CPU type"));
12359 mcpu_cpu_opt = legacy_cpu;
12361 else if (mcpu_cpu_opt == -1)
12362 mcpu_cpu_opt = march_cpu_opt;
12364 if (legacy_fpu != -1)
12366 if (mfpu_opt != -1)
12367 as_bad (_("use of old and new-style options to set FPU type"));
12369 mfpu_opt = legacy_fpu;
12371 else if (mfpu_opt == -1)
12373 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
12374 /* Some environments specify a default FPU. If they don't, infer it
12375 from the processor. */
12376 if (mcpu_fpu_opt != -1)
12377 mfpu_opt = mcpu_fpu_opt;
12378 else
12379 mfpu_opt = march_fpu_opt;
12380 #else
12381 mfpu_opt = FPU_DEFAULT;
12382 #endif
12385 if (mfpu_opt == -1)
12387 if (mcpu_cpu_opt == -1)
12388 mfpu_opt = FPU_DEFAULT;
12389 else if (mcpu_cpu_opt & ARM_EXT_V5)
12390 mfpu_opt = FPU_ARCH_VFP_V2;
12391 else
12392 mfpu_opt = FPU_ARCH_FPA;
12395 #ifdef CPU_DEFAULT
12396 if (mcpu_cpu_opt == -1)
12397 selected_cpu = mcpu_cpu_opt = CPU_DEFAULT;
12398 #else
12399 if (mcpu_cpu_opt == -1)
12401 mcpu_cpu_opt = ARM_ANY;
12402 selected_cpu = 0;
12404 else
12405 selected_cpu = mcpu_cpu_opt;
12406 #endif
12408 cpu_variant = mcpu_cpu_opt | mfpu_opt;
12410 arm_arch_used = thumb_arch_used = 0;
12412 #if defined OBJ_COFF || defined OBJ_ELF
12414 unsigned int flags = 0;
12416 #if defined OBJ_ELF
12417 flags = meabi_flags;
12419 switch (meabi_flags)
12421 case EF_ARM_EABI_UNKNOWN:
12422 #endif
12423 /* Set the flags in the private structure. */
12424 if (uses_apcs_26) flags |= F_APCS26;
12425 if (support_interwork) flags |= F_INTERWORK;
12426 if (uses_apcs_float) flags |= F_APCS_FLOAT;
12427 if (pic_code) flags |= F_PIC;
12428 if ((cpu_variant & FPU_ANY) == FPU_NONE
12429 || (cpu_variant & FPU_ANY) == FPU_ARCH_VFP) /* VFP layout only. */
12430 flags |= F_SOFT_FLOAT;
12432 switch (mfloat_abi_opt)
12434 case ARM_FLOAT_ABI_SOFT:
12435 case ARM_FLOAT_ABI_SOFTFP:
12436 flags |= F_SOFT_FLOAT;
12437 break;
12439 case ARM_FLOAT_ABI_HARD:
12440 if (flags & F_SOFT_FLOAT)
12441 as_bad (_("hard-float conflicts with specified fpu"));
12442 break;
12445 /* Using VFP conventions (even if soft-float). */
12446 if (cpu_variant & FPU_VFP_EXT_NONE)
12447 flags |= F_VFP_FLOAT;
12449 #if defined OBJ_ELF
12450 if (cpu_variant & FPU_ARCH_MAVERICK)
12451 flags |= EF_ARM_MAVERICK_FLOAT;
12452 break;
12454 case EF_ARM_EABI_VER4:
12455 /* No additional flags to set. */
12456 break;
12458 default:
12459 abort ();
12461 #endif
12462 bfd_set_private_flags (stdoutput, flags);
12464 /* We have run out flags in the COFF header to encode the
12465 status of ATPCS support, so instead we create a dummy,
12466 empty, debug section called .arm.atpcs. */
12467 if (atpcs)
12469 asection * sec;
12471 sec = bfd_make_section (stdoutput, ".arm.atpcs");
12473 if (sec != NULL)
12475 bfd_set_section_flags
12476 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
12477 bfd_set_section_size (stdoutput, sec, 0);
12478 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
12482 #endif
12484 /* Record the CPU type as well. */
12485 switch (cpu_variant & ARM_CPU_MASK)
12487 case ARM_2:
12488 mach = bfd_mach_arm_2;
12489 break;
12491 case ARM_3: /* Also ARM_250. */
12492 mach = bfd_mach_arm_2a;
12493 break;
12495 case ARM_6: /* Also ARM_7. */
12496 mach = bfd_mach_arm_3;
12497 break;
12499 default:
12500 mach = bfd_mach_arm_unknown;
12501 break;
12504 /* Catch special cases. */
12505 if (cpu_variant & ARM_CEXT_IWMMXT)
12506 mach = bfd_mach_arm_iWMMXt;
12507 else if (cpu_variant & ARM_CEXT_XSCALE)
12508 mach = bfd_mach_arm_XScale;
12509 else if (cpu_variant & ARM_CEXT_MAVERICK)
12510 mach = bfd_mach_arm_ep9312;
12511 else if (cpu_variant & ARM_EXT_V5E)
12512 mach = bfd_mach_arm_5TE;
12513 else if (cpu_variant & ARM_EXT_V5)
12515 if (cpu_variant & ARM_EXT_V4T)
12516 mach = bfd_mach_arm_5T;
12517 else
12518 mach = bfd_mach_arm_5;
12520 else if (cpu_variant & ARM_EXT_V4)
12522 if (cpu_variant & ARM_EXT_V4T)
12523 mach = bfd_mach_arm_4T;
12524 else
12525 mach = bfd_mach_arm_4;
12527 else if (cpu_variant & ARM_EXT_V3M)
12528 mach = bfd_mach_arm_3M;
12530 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
12533 /* Command line processing. */
12535 /* md_parse_option
12536 Invocation line includes a switch not recognized by the base assembler.
12537 See if it's a processor-specific option.
12539 This routine is somewhat complicated by the need for backwards
12540 compatibility (since older releases of gcc can't be changed).
12541 The new options try to make the interface as compatible as
12542 possible with GCC.
12544 New options (supported) are:
12546 -mcpu=<cpu name> Assemble for selected processor
12547 -march=<architecture name> Assemble for selected architecture
12548 -mfpu=<fpu architecture> Assemble for selected FPU.
12549 -EB/-mbig-endian Big-endian
12550 -EL/-mlittle-endian Little-endian
12551 -k Generate PIC code
12552 -mthumb Start in Thumb mode
12553 -mthumb-interwork Code supports ARM/Thumb interworking
12555 For now we will also provide support for:
12557 -mapcs-32 32-bit Program counter
12558 -mapcs-26 26-bit Program counter
12559 -macps-float Floats passed in FP registers
12560 -mapcs-reentrant Reentrant code
12561 -matpcs
12562 (sometime these will probably be replaced with -mapcs=<list of options>
12563 and -matpcs=<list of options>)
12565 The remaining options are only supported for back-wards compatibility.
12566 Cpu variants, the arm part is optional:
12567 -m[arm]1 Currently not supported.
12568 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
12569 -m[arm]3 Arm 3 processor
12570 -m[arm]6[xx], Arm 6 processors
12571 -m[arm]7[xx][t][[d]m] Arm 7 processors
12572 -m[arm]8[10] Arm 8 processors
12573 -m[arm]9[20][tdmi] Arm 9 processors
12574 -mstrongarm[110[0]] StrongARM processors
12575 -mxscale XScale processors
12576 -m[arm]v[2345[t[e]]] Arm architectures
12577 -mall All (except the ARM1)
12578 FP variants:
12579 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
12580 -mfpe-old (No float load/store multiples)
12581 -mvfpxd VFP Single precision
12582 -mvfp All VFP
12583 -mno-fpu Disable all floating point instructions
12585 The following CPU names are recognized:
12586 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
12587 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
12588 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
12589 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
12590 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
12591 arm10t arm10e, arm1020t, arm1020e, arm10200e,
12592 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
12596 const char * md_shortopts = "m:k";
12598 #ifdef ARM_BI_ENDIAN
12599 #define OPTION_EB (OPTION_MD_BASE + 0)
12600 #define OPTION_EL (OPTION_MD_BASE + 1)
12601 #else
12602 #if TARGET_BYTES_BIG_ENDIAN
12603 #define OPTION_EB (OPTION_MD_BASE + 0)
12604 #else
12605 #define OPTION_EL (OPTION_MD_BASE + 1)
12606 #endif
12607 #endif
12609 struct option md_longopts[] =
12611 #ifdef OPTION_EB
12612 {"EB", no_argument, NULL, OPTION_EB},
12613 #endif
12614 #ifdef OPTION_EL
12615 {"EL", no_argument, NULL, OPTION_EL},
12616 #endif
12617 {NULL, no_argument, NULL, 0}
12620 size_t md_longopts_size = sizeof (md_longopts);
12622 struct arm_option_table
12624 char *option; /* Option name to match. */
12625 char *help; /* Help information. */
12626 int *var; /* Variable to change. */
12627 int value; /* What to change it to. */
12628 char *deprecated; /* If non-null, print this message. */
12631 struct arm_option_table arm_opts[] =
12633 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
12634 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
12635 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
12636 &support_interwork, 1, NULL},
12637 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
12638 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
12639 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
12640 1, NULL},
12641 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
12642 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
12643 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
12644 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
12645 NULL},
12647 /* These are recognized by the assembler, but have no affect on code. */
12648 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
12649 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
12651 /* DON'T add any new processors to this list -- we want the whole list
12652 to go away... Add them to the processors table instead. */
12653 {"marm1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
12654 {"m1", NULL, &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
12655 {"marm2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
12656 {"m2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
12657 {"marm250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
12658 {"m250", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
12659 {"marm3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
12660 {"m3", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
12661 {"marm6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
12662 {"m6", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
12663 {"marm600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
12664 {"m600", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
12665 {"marm610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
12666 {"m610", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
12667 {"marm620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
12668 {"m620", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
12669 {"marm7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
12670 {"m7", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
12671 {"marm70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
12672 {"m70", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
12673 {"marm700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
12674 {"m700", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
12675 {"marm700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
12676 {"m700i", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
12677 {"marm710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
12678 {"m710", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
12679 {"marm710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
12680 {"m710c", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
12681 {"marm720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
12682 {"m720", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
12683 {"marm7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
12684 {"m7d", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
12685 {"marm7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
12686 {"m7di", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
12687 {"marm7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
12688 {"m7m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
12689 {"marm7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
12690 {"m7dm", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
12691 {"marm7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
12692 {"m7dmi", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
12693 {"marm7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
12694 {"m7100", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
12695 {"marm7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
12696 {"m7500", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
12697 {"marm7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
12698 {"m7500fe", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
12699 {"marm7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
12700 {"m7t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
12701 {"marm7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
12702 {"m7tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
12703 {"marm710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
12704 {"m710t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
12705 {"marm720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
12706 {"m720t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
12707 {"marm740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
12708 {"m740t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
12709 {"marm8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
12710 {"m8", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
12711 {"marm810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
12712 {"m810", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
12713 {"marm9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
12714 {"m9", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
12715 {"marm9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
12716 {"m9tdmi", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
12717 {"marm920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
12718 {"m920", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
12719 {"marm940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
12720 {"m940", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
12721 {"mstrongarm", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
12722 {"mstrongarm110", NULL, &legacy_cpu, ARM_ARCH_V4,
12723 N_("use -mcpu=strongarm110")},
12724 {"mstrongarm1100", NULL, &legacy_cpu, ARM_ARCH_V4,
12725 N_("use -mcpu=strongarm1100")},
12726 {"mstrongarm1110", NULL, &legacy_cpu, ARM_ARCH_V4,
12727 N_("use -mcpu=strongarm1110")},
12728 {"mxscale", NULL, &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
12729 {"miwmmxt", NULL, &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
12730 {"mall", NULL, &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
12732 /* Architecture variants -- don't add any more to this list either. */
12733 {"mv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
12734 {"marmv2", NULL, &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
12735 {"mv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
12736 {"marmv2a", NULL, &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
12737 {"mv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
12738 {"marmv3", NULL, &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
12739 {"mv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
12740 {"marmv3m", NULL, &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
12741 {"mv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
12742 {"marmv4", NULL, &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
12743 {"mv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
12744 {"marmv4t", NULL, &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
12745 {"mv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
12746 {"marmv5", NULL, &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
12747 {"mv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
12748 {"marmv5t", NULL, &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
12749 {"mv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
12750 {"marmv5e", NULL, &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
12752 /* Floating point variants -- don't add any more to this list either. */
12753 {"mfpe-old", NULL, &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
12754 {"mfpa10", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
12755 {"mfpa11", NULL, &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
12756 {"mno-fpu", NULL, &legacy_fpu, 0,
12757 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
12759 {NULL, NULL, NULL, 0, NULL}
12762 struct arm_cpu_option_table
12764 char *name;
12765 int value;
12766 /* For some CPUs we assume an FPU unless the user explicitly sets
12767 -mfpu=... */
12768 int default_fpu;
12769 /* The canonical name of the CPU, or NULL to use NAME converted to upper
12770 case. */
12771 const char *canonical_name;
12774 /* This list should, at a minimum, contain all the cpu names
12775 recognized by GCC. */
12776 static struct arm_cpu_option_table arm_cpus[] =
12778 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
12779 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
12780 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
12781 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
12782 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
12783 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12784 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12785 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12786 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12787 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12788 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12789 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
12790 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12791 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
12792 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12793 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
12794 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12795 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12796 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12797 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12798 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12799 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12800 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12801 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12802 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12803 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12804 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12805 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
12806 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12807 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12808 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12809 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12810 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12811 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12812 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12813 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12814 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12815 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
12816 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12817 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
12818 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12819 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12820 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12821 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
12822 /* For V5 or later processors we default to using VFP; but the user
12823 should really set the FPU type explicitly. */
12824 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
12825 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12826 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
12827 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
12828 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
12829 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
12830 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
12831 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12832 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
12833 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
12834 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12835 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12836 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
12837 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
12838 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12839 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
12840 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
12841 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12842 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
12843 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
12844 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
12845 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
12846 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
12847 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
12848 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
12849 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
12850 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
12851 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
12852 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
12853 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
12854 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
12855 /* ??? XSCALE is really an architecture. */
12856 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
12857 /* ??? iwmmxt is not a processor. */
12858 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
12859 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
12860 /* Maverick */
12861 {"ep9312", ARM_ARCH_V4T | ARM_CEXT_MAVERICK, FPU_ARCH_MAVERICK, "ARM920T"},
12862 {NULL, 0, 0, NULL}
12865 struct arm_arch_option_table
12867 char *name;
12868 int value;
12869 int default_fpu;
12872 /* This list should, at a minimum, contain all the architecture names
12873 recognized by GCC. */
12874 static struct arm_arch_option_table arm_archs[] =
12876 {"all", ARM_ANY, FPU_ARCH_FPA},
12877 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
12878 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
12879 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
12880 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
12881 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
12882 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
12883 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
12884 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
12885 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
12886 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
12887 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
12888 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
12889 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
12890 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
12891 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
12892 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
12893 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
12894 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
12895 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
12896 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
12897 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
12898 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
12899 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
12900 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
12901 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
12902 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
12903 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
12904 {NULL, 0, 0}
12907 /* ISA extensions in the co-processor space. */
12908 struct arm_option_value_table
12910 char *name;
12911 int value;
12914 static struct arm_option_value_table arm_extensions[] =
12916 {"maverick", ARM_CEXT_MAVERICK},
12917 {"xscale", ARM_CEXT_XSCALE},
12918 {"iwmmxt", ARM_CEXT_IWMMXT},
12919 {NULL, 0}
12922 /* This list should, at a minimum, contain all the fpu names
12923 recognized by GCC. */
12924 static struct arm_option_value_table arm_fpus[] =
12926 {"softfpa", FPU_NONE},
12927 {"fpe", FPU_ARCH_FPE},
12928 {"fpe2", FPU_ARCH_FPE},
12929 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
12930 {"fpa", FPU_ARCH_FPA},
12931 {"fpa10", FPU_ARCH_FPA},
12932 {"fpa11", FPU_ARCH_FPA},
12933 {"arm7500fe", FPU_ARCH_FPA},
12934 {"softvfp", FPU_ARCH_VFP},
12935 {"softvfp+vfp", FPU_ARCH_VFP_V2},
12936 {"vfp", FPU_ARCH_VFP_V2},
12937 {"vfp9", FPU_ARCH_VFP_V2},
12938 {"vfp10", FPU_ARCH_VFP_V2},
12939 {"vfp10-r0", FPU_ARCH_VFP_V1},
12940 {"vfpxd", FPU_ARCH_VFP_V1xD},
12941 {"arm1020t", FPU_ARCH_VFP_V1},
12942 {"arm1020e", FPU_ARCH_VFP_V2},
12943 {"arm1136jfs", FPU_ARCH_VFP_V2},
12944 {"arm1136jf-s", FPU_ARCH_VFP_V2},
12945 {"maverick", FPU_ARCH_MAVERICK},
12946 {NULL, 0}
12949 static struct arm_option_value_table arm_float_abis[] =
12951 {"hard", ARM_FLOAT_ABI_HARD},
12952 {"softfp", ARM_FLOAT_ABI_SOFTFP},
12953 {"soft", ARM_FLOAT_ABI_SOFT},
12954 {NULL, 0}
12957 #ifdef OBJ_ELF
12958 /* We only know how to output GNU and ver 4 (AAELF) formats. */
12959 static struct arm_option_value_table arm_eabis[] =
12961 {"gnu", EF_ARM_EABI_UNKNOWN},
12962 {"4", EF_ARM_EABI_VER4},
12963 {NULL, 0}
12965 #endif
12967 struct arm_long_option_table
12969 char * option; /* Substring to match. */
12970 char * help; /* Help information. */
12971 int (* func) (char * subopt); /* Function to decode sub-option. */
12972 char * deprecated; /* If non-null, print this message. */
12975 static int
12976 arm_parse_extension (char * str, int * opt_p)
12978 while (str != NULL && *str != 0)
12980 struct arm_option_value_table * opt;
12981 char * ext;
12982 int optlen;
12984 if (*str != '+')
12986 as_bad (_("invalid architectural extension"));
12987 return 0;
12990 str++;
12991 ext = strchr (str, '+');
12993 if (ext != NULL)
12994 optlen = ext - str;
12995 else
12996 optlen = strlen (str);
12998 if (optlen == 0)
13000 as_bad (_("missing architectural extension"));
13001 return 0;
13004 for (opt = arm_extensions; opt->name != NULL; opt++)
13005 if (strncmp (opt->name, str, optlen) == 0)
13007 *opt_p |= opt->value;
13008 break;
13011 if (opt->name == NULL)
13013 as_bad (_("unknown architectural extnsion `%s'"), str);
13014 return 0;
13017 str = ext;
13020 return 1;
13023 static int
13024 arm_parse_cpu (char * str)
13026 struct arm_cpu_option_table * opt;
13027 char * ext = strchr (str, '+');
13028 int optlen;
13030 if (ext != NULL)
13031 optlen = ext - str;
13032 else
13033 optlen = strlen (str);
13035 if (optlen == 0)
13037 as_bad (_("missing cpu name `%s'"), str);
13038 return 0;
13041 for (opt = arm_cpus; opt->name != NULL; opt++)
13042 if (strncmp (opt->name, str, optlen) == 0)
13044 mcpu_cpu_opt = opt->value;
13045 mcpu_fpu_opt = opt->default_fpu;
13046 if (opt->canonical_name)
13047 strcpy(selected_cpu_name, opt->canonical_name);
13048 else
13050 int i;
13051 for (i = 0; i < optlen; i++)
13052 selected_cpu_name[i] = TOUPPER (opt->name[i]);
13053 selected_cpu_name[i] = 0;
13056 if (ext != NULL)
13057 return arm_parse_extension (ext, &mcpu_cpu_opt);
13059 return 1;
13062 as_bad (_("unknown cpu `%s'"), str);
13063 return 0;
13066 static int
13067 arm_parse_arch (char * str)
13069 struct arm_arch_option_table *opt;
13070 char *ext = strchr (str, '+');
13071 int optlen;
13073 if (ext != NULL)
13074 optlen = ext - str;
13075 else
13076 optlen = strlen (str);
13078 if (optlen == 0)
13080 as_bad (_("missing architecture name `%s'"), str);
13081 return 0;
13084 for (opt = arm_archs; opt->name != NULL; opt++)
13085 if (streq (opt->name, str))
13087 march_cpu_opt = opt->value;
13088 march_fpu_opt = opt->default_fpu;
13089 strcpy(selected_cpu_name, opt->name);
13091 if (ext != NULL)
13092 return arm_parse_extension (ext, &march_cpu_opt);
13094 return 1;
13097 as_bad (_("unknown architecture `%s'\n"), str);
13098 return 0;
13101 static int
13102 arm_parse_fpu (char * str)
13104 struct arm_option_value_table * opt;
13106 for (opt = arm_fpus; opt->name != NULL; opt++)
13107 if (streq (opt->name, str))
13109 mfpu_opt = opt->value;
13110 return 1;
13113 as_bad (_("unknown floating point format `%s'\n"), str);
13114 return 0;
13117 static int
13118 arm_parse_float_abi (char * str)
13120 struct arm_option_value_table * opt;
13122 for (opt = arm_float_abis; opt->name != NULL; opt++)
13123 if (streq (opt->name, str))
13125 mfloat_abi_opt = opt->value;
13126 return 1;
13129 as_bad (_("unknown floating point abi `%s'\n"), str);
13130 return 0;
13133 #ifdef OBJ_ELF
13134 static int
13135 arm_parse_eabi (char * str)
13137 struct arm_option_value_table *opt;
13139 for (opt = arm_eabis; opt->name != NULL; opt++)
13140 if (streq (opt->name, str))
13142 meabi_flags = opt->value;
13143 return 1;
13145 as_bad (_("unknown EABI `%s'\n"), str);
13146 return 0;
13148 #endif
13150 struct arm_long_option_table arm_long_opts[] =
13152 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
13153 arm_parse_cpu, NULL},
13154 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
13155 arm_parse_arch, NULL},
13156 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
13157 arm_parse_fpu, NULL},
13158 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
13159 arm_parse_float_abi, NULL},
13160 #ifdef OBJ_ELF
13161 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
13162 arm_parse_eabi, NULL},
13163 #endif
13164 {NULL, NULL, 0, NULL}
13168 md_parse_option (int c, char * arg)
13170 struct arm_option_table *opt;
13171 struct arm_long_option_table *lopt;
13173 switch (c)
13175 #ifdef OPTION_EB
13176 case OPTION_EB:
13177 target_big_endian = 1;
13178 break;
13179 #endif
13181 #ifdef OPTION_EL
13182 case OPTION_EL:
13183 target_big_endian = 0;
13184 break;
13185 #endif
13187 case 'a':
13188 /* Listing option. Just ignore these, we don't support additional
13189 ones. */
13190 return 0;
13192 default:
13193 for (opt = arm_opts; opt->option != NULL; opt++)
13195 if (c == opt->option[0]
13196 && ((arg == NULL && opt->option[1] == 0)
13197 || streq (arg, opt->option + 1)))
13199 #if WARN_DEPRECATED
13200 /* If the option is deprecated, tell the user. */
13201 if (opt->deprecated != NULL)
13202 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
13203 arg ? arg : "", _(opt->deprecated));
13204 #endif
13206 if (opt->var != NULL)
13207 *opt->var = opt->value;
13209 return 1;
13213 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
13215 /* These options are expected to have an argument. */
13216 if (c == lopt->option[0]
13217 && arg != NULL
13218 && strncmp (arg, lopt->option + 1,
13219 strlen (lopt->option + 1)) == 0)
13221 #if WARN_DEPRECATED
13222 /* If the option is deprecated, tell the user. */
13223 if (lopt->deprecated != NULL)
13224 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
13225 _(lopt->deprecated));
13226 #endif
13228 /* Call the sup-option parser. */
13229 return lopt->func (arg + strlen (lopt->option) - 1);
13233 return 0;
13236 return 1;
13239 void
13240 md_show_usage (FILE * fp)
13242 struct arm_option_table *opt;
13243 struct arm_long_option_table *lopt;
13245 fprintf (fp, _(" ARM-specific assembler options:\n"));
13247 for (opt = arm_opts; opt->option != NULL; opt++)
13248 if (opt->help != NULL)
13249 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
13251 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
13252 if (lopt->help != NULL)
13253 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
13255 #ifdef OPTION_EB
13256 fprintf (fp, _("\
13257 -EB assemble code for a big-endian cpu\n"));
13258 #endif
13260 #ifdef OPTION_EL
13261 fprintf (fp, _("\
13262 -EL assemble code for a little-endian cpu\n"));
13263 #endif
13267 #ifdef OBJ_ELF
13268 /* Set the public EABI object attributes. */
13269 static void
13270 aeabi_set_public_attributes (void)
13272 int arch;
13273 int flags;
13275 /* Choose the architecture based on the capabilities of the requested cpu
13276 (if any) and/or the instructions actually used. */
13277 flags = selected_cpu | mfpu_opt | arm_arch_used | thumb_arch_used;
13278 if (flags & ARM_EXT_V6T2)
13279 arch = 8;
13280 else if (flags & ARM_EXT_V6Z)
13281 arch = 7;
13282 else if (flags & ARM_EXT_V6K)
13283 arch = 9;
13284 else if (flags & ARM_EXT_V6)
13285 arch = 6;
13286 else if (flags & ARM_EXT_V5E)
13287 arch = 4;
13288 else if (flags & (ARM_EXT_V5 | ARM_EXT_V5T))
13289 arch = 3;
13290 else if (flags & ARM_EXT_V4T)
13291 arch = 2;
13292 else if (flags & ARM_EXT_V4)
13293 arch = 1;
13294 else
13295 arch = 0;
13297 /* Tag_CPU_name. */
13298 if (selected_cpu_name[0])
13300 char *p;
13302 p = selected_cpu_name;
13303 if (strncmp(p, "armv", 4) == 0)
13305 int i;
13307 p += 4;
13308 for (i = 0; p[i]; i++)
13309 p[i] = TOUPPER (p[i]);
13311 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
13313 /* Tag_CPU_arch. */
13314 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
13315 /* Tag_ARM_ISA_use. */
13316 if (arm_arch_used)
13317 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
13318 /* Tag_THUMB_ISA_use. */
13319 if (thumb_arch_used)
13320 elf32_arm_add_eabi_attr_int (stdoutput, 9,
13321 (thumb_arch_used & ARM_EXT_V6T2) ? 2 : 1);
13322 /* Tag_VFP_arch. */
13323 if ((arm_arch_used | thumb_arch_used) & FPU_ARCH_VFP_V2)
13324 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
13325 else if ((arm_arch_used | thumb_arch_used) & FPU_ARCH_VFP_V1)
13326 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
13327 /* Tag_WMMX_arch. */
13328 if ((arm_arch_used | thumb_arch_used) & ARM_CEXT_IWMMXT)
13329 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
13332 /* Add the .ARM.attributes section. */
13333 void
13334 arm_md_end (void)
13336 segT s;
13337 char *p;
13338 addressT addr;
13339 offsetT size;
13341 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
13342 return;
13344 aeabi_set_public_attributes ();
13345 size = elf32_arm_eabi_attr_size (stdoutput);
13346 s = subseg_new (".ARM.attributes", 0);
13347 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
13348 addr = frag_now_fix ();
13349 p = frag_more (size);
13350 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
13354 /* Parse a .cpu directive. */
13356 static void
13357 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
13359 struct arm_cpu_option_table *opt;
13360 char *name;
13361 char saved_char;
13363 name = input_line_pointer;
13364 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13365 input_line_pointer++;
13366 saved_char = *input_line_pointer;
13367 *input_line_pointer = 0;
13369 /* Skip the first "all" entry. */
13370 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
13371 if (streq (opt->name, name))
13373 mcpu_cpu_opt = opt->value;
13374 selected_cpu = mcpu_cpu_opt;
13375 if (opt->canonical_name)
13376 strcpy(selected_cpu_name, opt->canonical_name);
13377 else
13379 int i;
13380 for (i = 0; opt->name[i]; i++)
13381 selected_cpu_name[i] = TOUPPER (opt->name[i]);
13382 selected_cpu_name[i] = 0;
13384 cpu_variant = mcpu_cpu_opt | mfpu_opt;
13385 *input_line_pointer = saved_char;
13386 demand_empty_rest_of_line ();
13387 return;
13389 as_bad (_("unknown cpu `%s'"), name);
13390 *input_line_pointer = saved_char;
13391 ignore_rest_of_line ();
13395 /* Parse a .arch directive. */
13397 static void
13398 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
13400 struct arm_arch_option_table *opt;
13401 char saved_char;
13402 char *name;
13404 name = input_line_pointer;
13405 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13406 input_line_pointer++;
13407 saved_char = *input_line_pointer;
13408 *input_line_pointer = 0;
13410 /* Skip the first "all" entry. */
13411 for (opt = arm_archs + 1; opt->name != NULL; opt++)
13412 if (streq (opt->name, name))
13414 mcpu_cpu_opt = opt->value;
13415 selected_cpu = mcpu_cpu_opt;
13416 strcpy(selected_cpu_name, opt->name);
13417 cpu_variant = mcpu_cpu_opt | mfpu_opt;
13418 *input_line_pointer = saved_char;
13419 demand_empty_rest_of_line ();
13420 return;
13423 as_bad (_("unknown architecture `%s'\n"), name);
13424 *input_line_pointer = saved_char;
13425 ignore_rest_of_line ();
13429 /* Parse a .fpu directive. */
13431 static void
13432 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
13434 struct arm_option_value_table *opt;
13435 char saved_char;
13436 char *name;
13438 name = input_line_pointer;
13439 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13440 input_line_pointer++;
13441 saved_char = *input_line_pointer;
13442 *input_line_pointer = 0;
13444 for (opt = arm_fpus; opt->name != NULL; opt++)
13445 if (streq (opt->name, name))
13447 mfpu_opt = opt->value;
13448 cpu_variant = mcpu_cpu_opt | mfpu_opt;
13449 *input_line_pointer = saved_char;
13450 demand_empty_rest_of_line ();
13451 return;
13454 as_bad (_("unknown floating point format `%s'\n"), name);
13455 *input_line_pointer = saved_char;
13456 ignore_rest_of_line ();
13458 #endif /* OBJ_ELF */