1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
5 Modified by David Taylor (dtaylor@armltd.co.uk)
6 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 This file is part of GAS, the GNU Assembler.
10 GAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GAS; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
28 #include "safe-ctype.h"
30 /* Need TARGET_CPU. */
39 #include "dwarf2dbg.h"
42 /* Types of processor to assemble for. */
43 #define ARM_1 0x00000001
44 #define ARM_2 0x00000002
45 #define ARM_3 0x00000004
47 #define ARM_6 0x00000008
48 #define ARM_7 ARM_6 /* Same core instruction set. */
49 #define ARM_8 ARM_6 /* Same core instruction set. */
50 #define ARM_9 ARM_6 /* Same core instruction set. */
51 #define ARM_CPU_MASK 0x0000000f
53 /* The following bitmasks control CPU extensions (ARM7 onwards): */
54 #define ARM_EXT_LONGMUL 0x00000010 /* Allow long multiplies. */
55 #define ARM_EXT_HALFWORD 0x00000020 /* Allow half word loads. */
56 #define ARM_EXT_THUMB 0x00000040 /* Allow BX instruction. */
57 #define ARM_EXT_V5 0x00000080 /* Allow CLZ, etc. */
58 #define ARM_EXT_V5E 0x00000100 /* "El Segundo". */
59 #define ARM_EXT_XSCALE 0x00000200 /* Allow MIA etc. */
60 #define ARM_EXT_MAVERICK 0x00000400 /* Use Cirrus/DSP coprocessor. */
62 /* Architectures are the sum of the base and extensions. */
63 #define ARM_ARCH_V3M ARM_EXT_LONGMUL
64 #define ARM_ARCH_V4 (ARM_ARCH_V3M | ARM_EXT_HALFWORD)
65 #define ARM_ARCH_V4T (ARM_ARCH_V4 | ARM_EXT_THUMB)
66 #define ARM_ARCH_V5 (ARM_ARCH_V4 | ARM_EXT_V5)
67 #define ARM_ARCH_V5T (ARM_ARCH_V5 | ARM_EXT_THUMB)
68 #define ARM_ARCH_V5TE (ARM_ARCH_V5T | ARM_EXT_V5E)
69 #define ARM_ARCH_XSCALE (ARM_ARCH_V5TE | ARM_EXT_XSCALE)
71 /* Some useful combinations: */
72 #define ARM_ANY 0x00ffffff
73 #define ARM_2UP (ARM_ANY - ARM_1)
74 #define ARM_ALL ARM_2UP /* Not arm1 only. */
75 #define ARM_3UP 0x00fffffc
76 #define ARM_6UP 0x00fffff8 /* Includes ARM7. */
78 #define FPU_CORE 0x80000000
79 #define FPU_FPA10 0x40000000
80 #define FPU_FPA11 0x40000000
83 /* Some useful combinations. */
84 #define FPU_ALL 0xff000000 /* Note this is ~ARM_ANY. */
85 #define FPU_MEMMULTI 0x7f000000 /* Not fpu_core. */
88 #if defined __XSCALE__
89 #define CPU_DEFAULT (ARM_9 | ARM_ARCH_XSCALE)
92 #define CPU_DEFAULT (ARM_7 | ARM_ARCH_V4T)
94 #define CPU_DEFAULT ARM_ALL
100 #define FPU_DEFAULT FPU_ALL
103 #define streq(a, b) (strcmp (a, b) == 0)
104 #define skip_whitespace(str) while (*(str) == ' ') ++(str)
106 static unsigned long cpu_variant = CPU_DEFAULT | FPU_DEFAULT;
107 static int target_oabi = 0;
109 #if defined OBJ_COFF || defined OBJ_ELF
110 /* Flags stored in private area of BFD structure. */
111 static boolean uses_apcs_26 = false;
112 static boolean atpcs = false;
113 static boolean support_interwork = false;
114 static boolean uses_apcs_float = false;
115 static boolean pic_code = false;
118 /* This array holds the chars that always start a comment. If the
119 pre-processor is disabled, these aren't very useful. */
120 const char comment_chars[] = "@;";
122 /* This array holds the chars that only start a comment at the beginning of
123 a line. If the line seems to have the form '# 123 filename'
124 .line and .file directives will appear in the pre-processed output. */
125 /* Note that input_file.c hand checks for '#' at the beginning of the
126 first line of the input file. This is because the compiler outputs
127 #NO_APP at the beginning of its output. */
128 /* Also note that comments like this one will always work. */
129 const char line_comment_chars[] = "#";
131 const char line_separator_chars[] = "|";
133 /* Chars that can be used to separate mant
134 from exp in floating point numbers. */
135 const char EXP_CHARS[] = "eE";
137 /* Chars that mean this number is a floating point constant. */
141 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
143 /* Prefix characters that indicate the start of an immediate
145 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
148 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
149 symbolS * GOT_symbol;
152 /* Size of relocation record. */
153 const int md_reloc_size = 8;
155 /* 0: assemble for ARM,
156 1: assemble for Thumb,
157 2: assemble for Thumb even though target CPU does not support thumb
159 static int thumb_mode = 0;
161 typedef struct arm_fix
169 unsigned long instruction;
174 bfd_reloc_code_real_type type;
191 struct asm_shift_properties
193 enum asm_shift_index index;
194 unsigned long bit_field;
195 unsigned int allows_0 : 1;
196 unsigned int allows_32 : 1;
199 static const struct asm_shift_properties shift_properties [] =
201 { SHIFT_LSL, 0, 1, 0},
202 { SHIFT_LSR, 0x20, 0, 1},
203 { SHIFT_ASR, 0x40, 0, 1},
204 { SHIFT_ROR, 0x60, 0, 0},
205 { SHIFT_RRX, 0x60, 0, 0}
208 struct asm_shift_name
211 const struct asm_shift_properties * properties;
214 static const struct asm_shift_name shift_names [] =
216 { "asl", shift_properties + SHIFT_LSL },
217 { "lsl", shift_properties + SHIFT_LSL },
218 { "lsr", shift_properties + SHIFT_LSR },
219 { "asr", shift_properties + SHIFT_ASR },
220 { "ror", shift_properties + SHIFT_ROR },
221 { "rrx", shift_properties + SHIFT_RRX },
222 { "ASL", shift_properties + SHIFT_LSL },
223 { "LSL", shift_properties + SHIFT_LSL },
224 { "LSR", shift_properties + SHIFT_LSR },
225 { "ASR", shift_properties + SHIFT_ASR },
226 { "ROR", shift_properties + SHIFT_ROR },
227 { "RRX", shift_properties + SHIFT_RRX }
230 #define NO_SHIFT_RESTRICT 1
231 #define SHIFT_RESTRICT 0
233 #define NUM_FLOAT_VALS 8
235 const char * fp_const[] =
237 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
240 /* Number of littlenums required to hold an extended precision number. */
241 #define MAX_LITTLENUMS 6
243 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
253 #define CP_T_X 0x00008000
254 #define CP_T_Y 0x00400000
255 #define CP_T_Pre 0x01000000
256 #define CP_T_UD 0x00800000
257 #define CP_T_WB 0x00200000
259 #define CONDS_BIT 0x00100000
260 #define LOAD_BIT 0x00100000
261 #define TRANS_BIT 0x00200000
263 #define DOUBLE_LOAD_FLAG 0x00000001
267 const char * template;
271 /* This is to save a hash look-up in the common case. */
272 #define COND_ALWAYS 0xe0000000
274 static const struct asm_cond conds[] =
278 {"cs", 0x20000000}, {"hs", 0x20000000},
279 {"cc", 0x30000000}, {"ul", 0x30000000}, {"lo", 0x30000000},
294 /* Warning: If the top bit of the set_bits is set, then the standard
295 instruction bitmask is ignored, and the new bitmask is taken from
299 const char * template; /* Basic flag string. */
300 unsigned long set_bits; /* Bits to set. */
303 static const struct asm_flg s_flag[] =
309 static const struct asm_flg ldr_flags[] =
311 {"d", DOUBLE_LOAD_FLAG},
314 {"bt", 0x00400000 | TRANS_BIT},
321 static const struct asm_flg str_flags[] =
323 {"d", DOUBLE_LOAD_FLAG},
326 {"bt", 0x00400000 | TRANS_BIT},
331 static const struct asm_flg byte_flag[] =
337 static const struct asm_flg cmp_flags[] =
344 static const struct asm_flg ldm_flags[] =
357 static const struct asm_flg stm_flags[] =
370 static const struct asm_flg lfm_flags[] =
377 static const struct asm_flg sfm_flags[] =
384 static const struct asm_flg round_flags[] =
392 /* The implementation of the FIX instruction is broken on some assemblers,
393 in that it accepts a precision specifier as well as a rounding specifier,
394 despite the fact that this is meaningless. To be more compatible, we
395 accept it as well, though of course it does not set any bits. */
396 static const struct asm_flg fix_flags[] =
413 static const struct asm_flg except_flag[] =
419 static const struct asm_flg long_flag[] =
427 const char * template;
432 /* The bit that distnguishes CPSR and SPSR. */
433 #define SPSR_BIT (1 << 22)
435 /* How many bits to shift the PSR_xxx bits up by. */
438 #define PSR_c (1 << 0)
439 #define PSR_x (1 << 1)
440 #define PSR_s (1 << 2)
441 #define PSR_f (1 << 3)
443 static const struct asm_psr psrs[] =
445 {"CPSR", true, PSR_c | PSR_f},
446 {"CPSR_all", true, PSR_c | PSR_f},
447 {"SPSR", false, PSR_c | PSR_f},
448 {"SPSR_all", false, PSR_c | PSR_f},
449 {"CPSR_flg", true, PSR_f},
450 {"CPSR_f", true, PSR_f},
451 {"SPSR_flg", false, PSR_f},
452 {"SPSR_f", false, PSR_f},
453 {"CPSR_c", true, PSR_c},
454 {"CPSR_ctl", true, PSR_c},
455 {"SPSR_c", false, PSR_c},
456 {"SPSR_ctl", false, PSR_c},
457 {"CPSR_x", true, PSR_x},
458 {"CPSR_s", true, PSR_s},
459 {"SPSR_x", false, PSR_x},
460 {"SPSR_s", false, PSR_s},
461 /* Combinations of flags. */
462 {"CPSR_fs", true, PSR_f | PSR_s},
463 {"CPSR_fx", true, PSR_f | PSR_x},
464 {"CPSR_fc", true, PSR_f | PSR_c},
465 {"CPSR_sf", true, PSR_s | PSR_f},
466 {"CPSR_sx", true, PSR_s | PSR_x},
467 {"CPSR_sc", true, PSR_s | PSR_c},
468 {"CPSR_xf", true, PSR_x | PSR_f},
469 {"CPSR_xs", true, PSR_x | PSR_s},
470 {"CPSR_xc", true, PSR_x | PSR_c},
471 {"CPSR_cf", true, PSR_c | PSR_f},
472 {"CPSR_cs", true, PSR_c | PSR_s},
473 {"CPSR_cx", true, PSR_c | PSR_x},
474 {"CPSR_fsx", true, PSR_f | PSR_s | PSR_x},
475 {"CPSR_fsc", true, PSR_f | PSR_s | PSR_c},
476 {"CPSR_fxs", true, PSR_f | PSR_x | PSR_s},
477 {"CPSR_fxc", true, PSR_f | PSR_x | PSR_c},
478 {"CPSR_fcs", true, PSR_f | PSR_c | PSR_s},
479 {"CPSR_fcx", true, PSR_f | PSR_c | PSR_x},
480 {"CPSR_sfx", true, PSR_s | PSR_f | PSR_x},
481 {"CPSR_sfc", true, PSR_s | PSR_f | PSR_c},
482 {"CPSR_sxf", true, PSR_s | PSR_x | PSR_f},
483 {"CPSR_sxc", true, PSR_s | PSR_x | PSR_c},
484 {"CPSR_scf", true, PSR_s | PSR_c | PSR_f},
485 {"CPSR_scx", true, PSR_s | PSR_c | PSR_x},
486 {"CPSR_xfs", true, PSR_x | PSR_f | PSR_s},
487 {"CPSR_xfc", true, PSR_x | PSR_f | PSR_c},
488 {"CPSR_xsf", true, PSR_x | PSR_s | PSR_f},
489 {"CPSR_xsc", true, PSR_x | PSR_s | PSR_c},
490 {"CPSR_xcf", true, PSR_x | PSR_c | PSR_f},
491 {"CPSR_xcs", true, PSR_x | PSR_c | PSR_s},
492 {"CPSR_cfs", true, PSR_c | PSR_f | PSR_s},
493 {"CPSR_cfx", true, PSR_c | PSR_f | PSR_x},
494 {"CPSR_csf", true, PSR_c | PSR_s | PSR_f},
495 {"CPSR_csx", true, PSR_c | PSR_s | PSR_x},
496 {"CPSR_cxf", true, PSR_c | PSR_x | PSR_f},
497 {"CPSR_cxs", true, PSR_c | PSR_x | PSR_s},
498 {"CPSR_fsxc", true, PSR_f | PSR_s | PSR_x | PSR_c},
499 {"CPSR_fscx", true, PSR_f | PSR_s | PSR_c | PSR_x},
500 {"CPSR_fxsc", true, PSR_f | PSR_x | PSR_s | PSR_c},
501 {"CPSR_fxcs", true, PSR_f | PSR_x | PSR_c | PSR_s},
502 {"CPSR_fcsx", true, PSR_f | PSR_c | PSR_s | PSR_x},
503 {"CPSR_fcxs", true, PSR_f | PSR_c | PSR_x | PSR_s},
504 {"CPSR_sfxc", true, PSR_s | PSR_f | PSR_x | PSR_c},
505 {"CPSR_sfcx", true, PSR_s | PSR_f | PSR_c | PSR_x},
506 {"CPSR_sxfc", true, PSR_s | PSR_x | PSR_f | PSR_c},
507 {"CPSR_sxcf", true, PSR_s | PSR_x | PSR_c | PSR_f},
508 {"CPSR_scfx", true, PSR_s | PSR_c | PSR_f | PSR_x},
509 {"CPSR_scxf", true, PSR_s | PSR_c | PSR_x | PSR_f},
510 {"CPSR_xfsc", true, PSR_x | PSR_f | PSR_s | PSR_c},
511 {"CPSR_xfcs", true, PSR_x | PSR_f | PSR_c | PSR_s},
512 {"CPSR_xsfc", true, PSR_x | PSR_s | PSR_f | PSR_c},
513 {"CPSR_xscf", true, PSR_x | PSR_s | PSR_c | PSR_f},
514 {"CPSR_xcfs", true, PSR_x | PSR_c | PSR_f | PSR_s},
515 {"CPSR_xcsf", true, PSR_x | PSR_c | PSR_s | PSR_f},
516 {"CPSR_cfsx", true, PSR_c | PSR_f | PSR_s | PSR_x},
517 {"CPSR_cfxs", true, PSR_c | PSR_f | PSR_x | PSR_s},
518 {"CPSR_csfx", true, PSR_c | PSR_s | PSR_f | PSR_x},
519 {"CPSR_csxf", true, PSR_c | PSR_s | PSR_x | PSR_f},
520 {"CPSR_cxfs", true, PSR_c | PSR_x | PSR_f | PSR_s},
521 {"CPSR_cxsf", true, PSR_c | PSR_x | PSR_s | PSR_f},
522 {"SPSR_fs", false, PSR_f | PSR_s},
523 {"SPSR_fx", false, PSR_f | PSR_x},
524 {"SPSR_fc", false, PSR_f | PSR_c},
525 {"SPSR_sf", false, PSR_s | PSR_f},
526 {"SPSR_sx", false, PSR_s | PSR_x},
527 {"SPSR_sc", false, PSR_s | PSR_c},
528 {"SPSR_xf", false, PSR_x | PSR_f},
529 {"SPSR_xs", false, PSR_x | PSR_s},
530 {"SPSR_xc", false, PSR_x | PSR_c},
531 {"SPSR_cf", false, PSR_c | PSR_f},
532 {"SPSR_cs", false, PSR_c | PSR_s},
533 {"SPSR_cx", false, PSR_c | PSR_x},
534 {"SPSR_fsx", false, PSR_f | PSR_s | PSR_x},
535 {"SPSR_fsc", false, PSR_f | PSR_s | PSR_c},
536 {"SPSR_fxs", false, PSR_f | PSR_x | PSR_s},
537 {"SPSR_fxc", false, PSR_f | PSR_x | PSR_c},
538 {"SPSR_fcs", false, PSR_f | PSR_c | PSR_s},
539 {"SPSR_fcx", false, PSR_f | PSR_c | PSR_x},
540 {"SPSR_sfx", false, PSR_s | PSR_f | PSR_x},
541 {"SPSR_sfc", false, PSR_s | PSR_f | PSR_c},
542 {"SPSR_sxf", false, PSR_s | PSR_x | PSR_f},
543 {"SPSR_sxc", false, PSR_s | PSR_x | PSR_c},
544 {"SPSR_scf", false, PSR_s | PSR_c | PSR_f},
545 {"SPSR_scx", false, PSR_s | PSR_c | PSR_x},
546 {"SPSR_xfs", false, PSR_x | PSR_f | PSR_s},
547 {"SPSR_xfc", false, PSR_x | PSR_f | PSR_c},
548 {"SPSR_xsf", false, PSR_x | PSR_s | PSR_f},
549 {"SPSR_xsc", false, PSR_x | PSR_s | PSR_c},
550 {"SPSR_xcf", false, PSR_x | PSR_c | PSR_f},
551 {"SPSR_xcs", false, PSR_x | PSR_c | PSR_s},
552 {"SPSR_cfs", false, PSR_c | PSR_f | PSR_s},
553 {"SPSR_cfx", false, PSR_c | PSR_f | PSR_x},
554 {"SPSR_csf", false, PSR_c | PSR_s | PSR_f},
555 {"SPSR_csx", false, PSR_c | PSR_s | PSR_x},
556 {"SPSR_cxf", false, PSR_c | PSR_x | PSR_f},
557 {"SPSR_cxs", false, PSR_c | PSR_x | PSR_s},
558 {"SPSR_fsxc", false, PSR_f | PSR_s | PSR_x | PSR_c},
559 {"SPSR_fscx", false, PSR_f | PSR_s | PSR_c | PSR_x},
560 {"SPSR_fxsc", false, PSR_f | PSR_x | PSR_s | PSR_c},
561 {"SPSR_fxcs", false, PSR_f | PSR_x | PSR_c | PSR_s},
562 {"SPSR_fcsx", false, PSR_f | PSR_c | PSR_s | PSR_x},
563 {"SPSR_fcxs", false, PSR_f | PSR_c | PSR_x | PSR_s},
564 {"SPSR_sfxc", false, PSR_s | PSR_f | PSR_x | PSR_c},
565 {"SPSR_sfcx", false, PSR_s | PSR_f | PSR_c | PSR_x},
566 {"SPSR_sxfc", false, PSR_s | PSR_x | PSR_f | PSR_c},
567 {"SPSR_sxcf", false, PSR_s | PSR_x | PSR_c | PSR_f},
568 {"SPSR_scfx", false, PSR_s | PSR_c | PSR_f | PSR_x},
569 {"SPSR_scxf", false, PSR_s | PSR_c | PSR_x | PSR_f},
570 {"SPSR_xfsc", false, PSR_x | PSR_f | PSR_s | PSR_c},
571 {"SPSR_xfcs", false, PSR_x | PSR_f | PSR_c | PSR_s},
572 {"SPSR_xsfc", false, PSR_x | PSR_s | PSR_f | PSR_c},
573 {"SPSR_xscf", false, PSR_x | PSR_s | PSR_c | PSR_f},
574 {"SPSR_xcfs", false, PSR_x | PSR_c | PSR_f | PSR_s},
575 {"SPSR_xcsf", false, PSR_x | PSR_c | PSR_s | PSR_f},
576 {"SPSR_cfsx", false, PSR_c | PSR_f | PSR_s | PSR_x},
577 {"SPSR_cfxs", false, PSR_c | PSR_f | PSR_x | PSR_s},
578 {"SPSR_csfx", false, PSR_c | PSR_s | PSR_f | PSR_x},
579 {"SPSR_csxf", false, PSR_c | PSR_s | PSR_x | PSR_f},
580 {"SPSR_cxfs", false, PSR_c | PSR_x | PSR_f | PSR_s},
581 {"SPSR_cxsf", false, PSR_c | PSR_x | PSR_s | PSR_f},
586 CIRRUS_REGTYPE_MVF = 1,
587 CIRRUS_REGTYPE_MVFX = 2,
588 CIRRUS_REGTYPE_MVD = 3,
589 CIRRUS_REGTYPE_MVDX = 4,
590 CIRRUS_REGTYPE_MVAX = 5,
591 CIRRUS_REGTYPE_DSPSC = 6,
592 CIRRUS_REGTYPE_ANY = 7
595 /* Functions called by parser. */
596 /* ARM instructions. */
597 static void do_arit PARAMS ((char *, unsigned long));
598 static void do_cmp PARAMS ((char *, unsigned long));
599 static void do_mov PARAMS ((char *, unsigned long));
600 static void do_ldst PARAMS ((char *, unsigned long));
601 static void do_ldmstm PARAMS ((char *, unsigned long));
602 static void do_branch PARAMS ((char *, unsigned long));
603 static void do_swi PARAMS ((char *, unsigned long));
604 /* Pseudo Op codes. */
605 static void do_adr PARAMS ((char *, unsigned long));
606 static void do_nop PARAMS ((char *, unsigned long));
608 static void do_mul PARAMS ((char *, unsigned long));
609 static void do_mla PARAMS ((char *, unsigned long));
611 static void do_swap PARAMS ((char *, unsigned long));
613 static void do_msr PARAMS ((char *, unsigned long));
614 static void do_mrs PARAMS ((char *, unsigned long));
616 static void do_mull PARAMS ((char *, unsigned long));
618 static void do_bx PARAMS ((char *, unsigned long));
620 /* ARM_EXT_XScale. */
621 static void do_mia PARAMS ((char *, unsigned long));
622 static void do_mar PARAMS ((char *, unsigned long));
623 static void do_mra PARAMS ((char *, unsigned long));
624 static void do_pld PARAMS ((char *, unsigned long));
625 static void do_ldrd PARAMS ((char *, unsigned long));
628 static void do_blx PARAMS ((char *, unsigned long));
629 static void do_bkpt PARAMS ((char *, unsigned long));
630 static void do_clz PARAMS ((char *, unsigned long));
631 static void do_lstc2 PARAMS ((char *, unsigned long));
632 static void do_cdp2 PARAMS ((char *, unsigned long));
633 static void do_co_reg2 PARAMS ((char *, unsigned long));
635 static void do_t_blx PARAMS ((char *));
636 static void do_t_bkpt PARAMS ((char *));
639 static void do_smla PARAMS ((char *, unsigned long));
640 static void do_smlal PARAMS ((char *, unsigned long));
641 static void do_smul PARAMS ((char *, unsigned long));
642 static void do_qadd PARAMS ((char *, unsigned long));
643 static void do_co_reg2c PARAMS ((char *, unsigned long));
645 /* Coprocessor Instructions. */
646 static void do_cdp PARAMS ((char *, unsigned long));
647 static void do_lstc PARAMS ((char *, unsigned long));
648 static void do_co_reg PARAMS ((char *, unsigned long));
649 static void do_fp_ctrl PARAMS ((char *, unsigned long));
650 static void do_fp_ldst PARAMS ((char *, unsigned long));
651 static void do_fp_ldmstm PARAMS ((char *, unsigned long));
652 static void do_fp_dyadic PARAMS ((char *, unsigned long));
653 static void do_fp_monadic PARAMS ((char *, unsigned long));
654 static void do_fp_cmp PARAMS ((char *, unsigned long));
655 static void do_fp_from_reg PARAMS ((char *, unsigned long));
656 static void do_fp_to_reg PARAMS ((char *, unsigned long));
658 /* ARM_EXT_MAVERICK. */
659 static void do_c_binops PARAMS ((char *, unsigned long, int));
660 static void do_c_binops_1 PARAMS ((char *, unsigned long));
661 static void do_c_binops_2 PARAMS ((char *, unsigned long));
662 static void do_c_binops_3 PARAMS ((char *, unsigned long));
663 static void do_c_triple PARAMS ((char *, unsigned long, int));
664 static void do_c_triple_4 PARAMS ((char *, unsigned long));
665 static void do_c_triple_5 PARAMS ((char *, unsigned long));
666 static void do_c_quad PARAMS ((char *, unsigned long, int));
667 static void do_c_quad_6 PARAMS ((char *, unsigned long));
668 static void do_c_dspsc PARAMS ((char *, unsigned long, int));
669 static void do_c_dspsc_1 PARAMS ((char *, unsigned long));
670 static void do_c_dspsc_2 PARAMS ((char *, unsigned long));
671 static void do_c_shift PARAMS ((char *, unsigned long, int));
672 static void do_c_shift_1 PARAMS ((char *, unsigned long));
673 static void do_c_shift_2 PARAMS ((char *, unsigned long));
674 static void do_c_ldst PARAMS ((char *, unsigned long, int));
675 static void do_c_ldst_1 PARAMS ((char *, unsigned long));
676 static void do_c_ldst_2 PARAMS ((char *, unsigned long));
677 static void do_c_ldst_3 PARAMS ((char *, unsigned long));
678 static void do_c_ldst_4 PARAMS ((char *, unsigned long));
679 static int cirrus_reg_required_here PARAMS ((char **, int, enum cirrus_regtype));
680 static int cirrus_valid_reg PARAMS ((int, enum cirrus_regtype));
681 static int cirrus_parse_offset PARAMS ((char **, int *));
683 static void fix_new_arm PARAMS ((fragS *, int, short, expressionS *, int, int));
684 static int arm_reg_parse PARAMS ((char **));
685 static const struct asm_psr * arm_psr_parse PARAMS ((char **));
686 static void symbol_locate PARAMS ((symbolS *, const char *, segT, valueT, fragS *));
687 static int add_to_lit_pool PARAMS ((void));
688 static unsigned validate_immediate PARAMS ((unsigned));
689 static unsigned validate_immediate_twopart PARAMS ((unsigned int, unsigned int *));
690 static int validate_offset_imm PARAMS ((unsigned int, int));
691 static void opcode_select PARAMS ((int));
692 static void end_of_line PARAMS ((char *));
693 static int reg_required_here PARAMS ((char **, int));
694 static int psr_required_here PARAMS ((char **));
695 static int co_proc_number PARAMS ((char **));
696 static int cp_opc_expr PARAMS ((char **, int, int));
697 static int cp_reg_required_here PARAMS ((char **, int));
698 static int fp_reg_required_here PARAMS ((char **, int));
699 static int cp_address_offset PARAMS ((char **));
700 static int cp_address_required_here PARAMS ((char **));
701 static int my_get_float_expression PARAMS ((char **));
702 static int skip_past_comma PARAMS ((char **));
703 static int walk_no_bignums PARAMS ((symbolS *));
704 static int negate_data_op PARAMS ((unsigned long *, unsigned long));
705 static int data_op2 PARAMS ((char **));
706 static int fp_op2 PARAMS ((char **));
707 static long reg_list PARAMS ((char **));
708 static void thumb_load_store PARAMS ((char *, int, int));
709 static int decode_shift PARAMS ((char **, int));
710 static int ldst_extend PARAMS ((char **, int));
711 static void thumb_add_sub PARAMS ((char *, int));
712 static void insert_reg PARAMS ((int));
713 static void thumb_shift PARAMS ((char *, int));
714 static void thumb_mov_compare PARAMS ((char *, int));
715 static void set_constant_flonums PARAMS ((void));
716 static valueT md_chars_to_number PARAMS ((char *, int));
717 static void insert_reg_alias PARAMS ((char *, int));
718 static void output_inst PARAMS ((void));
719 static int accum0_required_here PARAMS ((char **));
720 static int ld_mode_required_here PARAMS ((char **));
721 static void do_branch25 PARAMS ((char *, unsigned long));
722 static symbolS * find_real_start PARAMS ((symbolS *));
724 static bfd_reloc_code_real_type arm_parse_reloc PARAMS ((void));
727 /* ARM instructions take 4bytes in the object file, Thumb instructions
731 /* LONGEST_INST is the longest basic instruction name without
732 conditions or flags. ARM7M has 4 of length 5. El Segundo
733 has one basic instruction name of length 7 (SMLALxy). */
734 #define LONGEST_INST 10
736 /* "INSN<cond> X,Y" where X:bit12, Y:bit16. */
737 #define CIRRUS_MODE1 0x100c
739 /* "INSN<cond> X,Y" where X:bit16, Y:bit12. */
740 #define CIRRUS_MODE2 0x0c10
742 /* "INSN<cond> X,Y" where X:0, Y:bit16. */
743 #define CIRRUS_MODE3 0x1000
745 /* "INSN<cond> X,Y,Z" where X:16, Y:0, Z:12. */
746 #define CIRRUS_MODE4 0x0c0010
748 /* "INSN<cond> X,Y,Z" where X:12, Y:16, Z:0. */
749 #define CIRRUS_MODE5 0x00100c
751 /* "INSN<cond> W,X,Y,Z" where W:5, X:12, Y:16, Z:0. */
752 #define CIRRUS_MODE6 0x00100c05
756 /* Basic string to match. */
757 const char * template;
759 /* Basic instruction code. */
762 /* Compulsory suffix that must follow conds. If "", then the
763 instruction is not conditional and must have no suffix. */
764 const char * comp_suffix;
766 /* Bits to toggle if flag 'n' set. */
767 const struct asm_flg * flags;
769 /* Which CPU variants this exists for. */
770 unsigned long variants;
772 /* Function to call to parse args. */
773 void (* parms) PARAMS ((char *, unsigned long));
776 static const struct asm_opcode insns[] =
778 /* Intel XScale extensions to ARM V5 ISA. */
779 {"mia", 0x0e200010, NULL, NULL, ARM_EXT_XSCALE, do_mia},
780 {"miaph", 0x0e280010, NULL, NULL, ARM_EXT_XSCALE, do_mia},
781 {"miabb", 0x0e2c0010, NULL, NULL, ARM_EXT_XSCALE, do_mia},
782 {"miabt", 0x0e2d0010, NULL, NULL, ARM_EXT_XSCALE, do_mia},
783 {"miatb", 0x0e2e0010, NULL, NULL, ARM_EXT_XSCALE, do_mia},
784 {"miatt", 0x0e2f0010, NULL, NULL, ARM_EXT_XSCALE, do_mia},
785 {"mar", 0x0c400000, NULL, NULL, ARM_EXT_XSCALE, do_mar},
786 {"mra", 0x0c500000, NULL, NULL, ARM_EXT_XSCALE, do_mra},
787 {"pld", 0xf450f000, "", NULL, ARM_EXT_XSCALE, do_pld},
788 {"ldr", 0x000000d0, NULL, ldr_flags, ARM_ANY, do_ldrd},
789 {"str", 0x000000f0, NULL, str_flags, ARM_ANY, do_ldrd},
791 /* ARM Instructions. */
792 {"and", 0x00000000, NULL, s_flag, ARM_ANY, do_arit},
793 {"eor", 0x00200000, NULL, s_flag, ARM_ANY, do_arit},
794 {"sub", 0x00400000, NULL, s_flag, ARM_ANY, do_arit},
795 {"rsb", 0x00600000, NULL, s_flag, ARM_ANY, do_arit},
796 {"add", 0x00800000, NULL, s_flag, ARM_ANY, do_arit},
797 {"adc", 0x00a00000, NULL, s_flag, ARM_ANY, do_arit},
798 {"sbc", 0x00c00000, NULL, s_flag, ARM_ANY, do_arit},
799 {"rsc", 0x00e00000, NULL, s_flag, ARM_ANY, do_arit},
800 {"orr", 0x01800000, NULL, s_flag, ARM_ANY, do_arit},
801 {"bic", 0x01c00000, NULL, s_flag, ARM_ANY, do_arit},
802 {"tst", 0x01000000, NULL, cmp_flags, ARM_ANY, do_cmp},
803 {"teq", 0x01200000, NULL, cmp_flags, ARM_ANY, do_cmp},
804 {"cmp", 0x01400000, NULL, cmp_flags, ARM_ANY, do_cmp},
805 {"cmn", 0x01600000, NULL, cmp_flags, ARM_ANY, do_cmp},
806 {"mov", 0x01a00000, NULL, s_flag, ARM_ANY, do_mov},
807 {"mvn", 0x01e00000, NULL, s_flag, ARM_ANY, do_mov},
808 {"str", 0x04000000, NULL, str_flags, ARM_ANY, do_ldst},
809 {"ldr", 0x04100000, NULL, ldr_flags, ARM_ANY, do_ldst},
810 {"stm", 0x08000000, NULL, stm_flags, ARM_ANY, do_ldmstm},
811 {"ldm", 0x08100000, NULL, ldm_flags, ARM_ANY, do_ldmstm},
812 {"swi", 0x0f000000, NULL, NULL, ARM_ANY, do_swi},
814 {"bl", 0x0b000000, NULL, NULL, ARM_ANY, do_branch},
815 {"b", 0x0a000000, NULL, NULL, ARM_ANY, do_branch},
817 {"bl", 0x0bfffffe, NULL, NULL, ARM_ANY, do_branch},
818 {"b", 0x0afffffe, NULL, NULL, ARM_ANY, do_branch},
822 {"adr", 0x028f0000, NULL, long_flag, ARM_ANY, do_adr},
823 {"nop", 0x01a00000, NULL, NULL, ARM_ANY, do_nop},
825 /* ARM 2 multiplies. */
826 {"mul", 0x00000090, NULL, s_flag, ARM_2UP, do_mul},
827 {"mla", 0x00200090, NULL, s_flag, ARM_2UP, do_mla},
829 /* ARM 3 - swp instructions. */
830 {"swp", 0x01000090, NULL, byte_flag, ARM_3UP, do_swap},
832 /* ARM 6 Coprocessor instructions. */
833 {"mrs", 0x010f0000, NULL, NULL, ARM_6UP, do_mrs},
834 {"msr", 0x0120f000, NULL, NULL, ARM_6UP, do_msr},
835 /* ScottB: our code uses 0x0128f000 for msr.
836 NickC: but this is wrong because the bits 16 through 19 are
837 handled by the PSR_xxx defines above. */
839 /* ARM 7M long multiplies - need signed/unsigned flags! */
840 {"smull", 0x00c00090, NULL, s_flag, ARM_EXT_LONGMUL, do_mull},
841 {"umull", 0x00800090, NULL, s_flag, ARM_EXT_LONGMUL, do_mull},
842 {"smlal", 0x00e00090, NULL, s_flag, ARM_EXT_LONGMUL, do_mull},
843 {"umlal", 0x00a00090, NULL, s_flag, ARM_EXT_LONGMUL, do_mull},
845 /* ARM THUMB interworking. */
846 {"bx", 0x012fff10, NULL, NULL, ARM_EXT_THUMB, do_bx},
848 /* Floating point instructions. */
849 {"wfs", 0x0e200110, NULL, NULL, FPU_ALL, do_fp_ctrl},
850 {"rfs", 0x0e300110, NULL, NULL, FPU_ALL, do_fp_ctrl},
851 {"wfc", 0x0e400110, NULL, NULL, FPU_ALL, do_fp_ctrl},
852 {"rfc", 0x0e500110, NULL, NULL, FPU_ALL, do_fp_ctrl},
853 {"ldf", 0x0c100100, "sdep", NULL, FPU_ALL, do_fp_ldst},
854 {"stf", 0x0c000100, "sdep", NULL, FPU_ALL, do_fp_ldst},
855 {"lfm", 0x0c100200, NULL, lfm_flags, FPU_MEMMULTI, do_fp_ldmstm},
856 {"sfm", 0x0c000200, NULL, sfm_flags, FPU_MEMMULTI, do_fp_ldmstm},
857 {"mvf", 0x0e008100, "sde", round_flags, FPU_ALL, do_fp_monadic},
858 {"mnf", 0x0e108100, "sde", round_flags, FPU_ALL, do_fp_monadic},
859 {"abs", 0x0e208100, "sde", round_flags, FPU_ALL, do_fp_monadic},
860 {"rnd", 0x0e308100, "sde", round_flags, FPU_ALL, do_fp_monadic},
861 {"sqt", 0x0e408100, "sde", round_flags, FPU_ALL, do_fp_monadic},
862 {"log", 0x0e508100, "sde", round_flags, FPU_ALL, do_fp_monadic},
863 {"lgn", 0x0e608100, "sde", round_flags, FPU_ALL, do_fp_monadic},
864 {"exp", 0x0e708100, "sde", round_flags, FPU_ALL, do_fp_monadic},
865 {"sin", 0x0e808100, "sde", round_flags, FPU_ALL, do_fp_monadic},
866 {"cos", 0x0e908100, "sde", round_flags, FPU_ALL, do_fp_monadic},
867 {"tan", 0x0ea08100, "sde", round_flags, FPU_ALL, do_fp_monadic},
868 {"asn", 0x0eb08100, "sde", round_flags, FPU_ALL, do_fp_monadic},
869 {"acs", 0x0ec08100, "sde", round_flags, FPU_ALL, do_fp_monadic},
870 {"atn", 0x0ed08100, "sde", round_flags, FPU_ALL, do_fp_monadic},
871 {"urd", 0x0ee08100, "sde", round_flags, FPU_ALL, do_fp_monadic},
872 {"nrm", 0x0ef08100, "sde", round_flags, FPU_ALL, do_fp_monadic},
873 {"adf", 0x0e000100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
874 {"suf", 0x0e200100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
875 {"rsf", 0x0e300100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
876 {"muf", 0x0e100100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
877 {"dvf", 0x0e400100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
878 {"rdf", 0x0e500100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
879 {"pow", 0x0e600100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
880 {"rpw", 0x0e700100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
881 {"rmf", 0x0e800100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
882 {"fml", 0x0e900100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
883 {"fdv", 0x0ea00100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
884 {"frd", 0x0eb00100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
885 {"pol", 0x0ec00100, "sde", round_flags, FPU_ALL, do_fp_dyadic},
886 {"cmf", 0x0e90f110, NULL, except_flag, FPU_ALL, do_fp_cmp},
887 {"cnf", 0x0eb0f110, NULL, except_flag, FPU_ALL, do_fp_cmp},
888 /* The FPA10 data sheet suggests that the 'E' of cmfe/cnfe should not
889 be an optional suffix, but part of the instruction. To be compatible,
891 {"cmfe", 0x0ed0f110, NULL, NULL, FPU_ALL, do_fp_cmp},
892 {"cnfe", 0x0ef0f110, NULL, NULL, FPU_ALL, do_fp_cmp},
893 {"flt", 0x0e000110, "sde", round_flags, FPU_ALL, do_fp_from_reg},
894 {"fix", 0x0e100110, NULL, fix_flags, FPU_ALL, do_fp_to_reg},
896 /* Generic copressor instructions. */
897 {"cdp", 0x0e000000, NULL, NULL, ARM_2UP, do_cdp},
898 {"ldc", 0x0c100000, NULL, long_flag, ARM_2UP, do_lstc},
899 {"stc", 0x0c000000, NULL, long_flag, ARM_2UP, do_lstc},
900 {"mcr", 0x0e000010, NULL, NULL, ARM_2UP, do_co_reg},
901 {"mrc", 0x0e100010, NULL, NULL, ARM_2UP, do_co_reg},
903 /* ARM ISA extension 5. */
904 /* Note: blx is actually 2 opcodes, so the .value is set dynamically.
905 And it's sometimes conditional and sometimes not. */
906 {"blx", 0, NULL, NULL, ARM_EXT_V5, do_blx},
907 {"clz", 0x016f0f10, NULL, NULL, ARM_EXT_V5, do_clz},
908 {"bkpt", 0xe1200070, "", NULL, ARM_EXT_V5, do_bkpt},
909 {"ldc2", 0xfc100000, "", long_flag, ARM_EXT_V5, do_lstc2},
910 {"stc2", 0xfc000000, "", long_flag, ARM_EXT_V5, do_lstc2},
911 {"cdp2", 0xfe000000, "", NULL, ARM_EXT_V5, do_cdp2},
912 {"mcr2", 0xfe000010, "", NULL, ARM_EXT_V5, do_co_reg2},
913 {"mrc2", 0xfe100010, "", NULL, ARM_EXT_V5, do_co_reg2},
915 /* ARM ISA extension 5E, El Segundo. */
916 {"smlabb", 0x01000080, NULL, NULL, ARM_EXT_V5E, do_smla},
917 {"smlatb", 0x010000a0, NULL, NULL, ARM_EXT_V5E, do_smla},
918 {"smlabt", 0x010000c0, NULL, NULL, ARM_EXT_V5E, do_smla},
919 {"smlatt", 0x010000e0, NULL, NULL, ARM_EXT_V5E, do_smla},
921 {"smlawb", 0x01200080, NULL, NULL, ARM_EXT_V5E, do_smla},
922 {"smlawt", 0x012000c0, NULL, NULL, ARM_EXT_V5E, do_smla},
924 {"smlalbb",0x01400080, NULL, NULL, ARM_EXT_V5E, do_smlal},
925 {"smlaltb",0x014000a0, NULL, NULL, ARM_EXT_V5E, do_smlal},
926 {"smlalbt",0x014000c0, NULL, NULL, ARM_EXT_V5E, do_smlal},
927 {"smlaltt",0x014000e0, NULL, NULL, ARM_EXT_V5E, do_smlal},
929 {"smulbb", 0x01600080, NULL, NULL, ARM_EXT_V5E, do_smul},
930 {"smultb", 0x016000a0, NULL, NULL, ARM_EXT_V5E, do_smul},
931 {"smulbt", 0x016000c0, NULL, NULL, ARM_EXT_V5E, do_smul},
932 {"smultt", 0x016000e0, NULL, NULL, ARM_EXT_V5E, do_smul},
934 {"smulwb", 0x012000a0, NULL, NULL, ARM_EXT_V5E, do_smul},
935 {"smulwt", 0x012000e0, NULL, NULL, ARM_EXT_V5E, do_smul},
937 {"qadd", 0x01000050, NULL, NULL, ARM_EXT_V5E, do_qadd},
938 {"qdadd", 0x01400050, NULL, NULL, ARM_EXT_V5E, do_qadd},
939 {"qsub", 0x01200050, NULL, NULL, ARM_EXT_V5E, do_qadd},
940 {"qdsub", 0x01600050, NULL, NULL, ARM_EXT_V5E, do_qadd},
942 {"mcrr", 0x0c400000, NULL, NULL, ARM_EXT_V5E, do_co_reg2c},
943 {"mrrc", 0x0c500000, NULL, NULL, ARM_EXT_V5E, do_co_reg2c},
945 /* Cirrus DSP instructions. */
946 {"cfldrs", 0x0c100400, NULL, NULL, ARM_EXT_MAVERICK, do_c_ldst_1},
947 {"cfldrd", 0x0c500400, NULL, NULL, ARM_EXT_MAVERICK, do_c_ldst_2},
948 {"cfldr32", 0x0c100500, NULL, NULL, ARM_EXT_MAVERICK, do_c_ldst_3},
949 {"cfldr64", 0x0c500500, NULL, NULL, ARM_EXT_MAVERICK, do_c_ldst_4},
950 {"cfstrs", 0x0c000400, NULL, NULL, ARM_EXT_MAVERICK, do_c_ldst_1},
951 {"cfstrd", 0x0c400400, NULL, NULL, ARM_EXT_MAVERICK, do_c_ldst_2},
952 {"cfstr32", 0x0c000500, NULL, NULL, ARM_EXT_MAVERICK, do_c_ldst_3},
953 {"cfstr64", 0x0c400500, NULL, NULL, ARM_EXT_MAVERICK, do_c_ldst_4},
954 {"cfmvsr", 0x0e000450, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_2},
955 {"cfmvrs", 0x0e100450, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
956 {"cfmvdlr", 0x0e000410, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_2},
957 {"cfmvrdl", 0x0e100410, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
958 {"cfmvdhr", 0x0e000430, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_2},
959 {"cfmvrdh", 0x0e100430, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
960 {"cfmv64lr", 0x0e000510, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_2},
961 {"cfmvr64l", 0x0e100510, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
962 {"cfmv64hr", 0x0e000530, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_2},
963 {"cfmvr64h", 0x0e100530, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
964 {"cfmval32", 0x0e100610, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_3},
965 {"cfmv32al", 0x0e000610, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_3},
966 {"cfmvam32", 0x0e100630, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_3},
967 {"cfmv32am", 0x0e000630, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_3},
968 {"cfmvah32", 0x0e100650, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_3},
969 {"cfmv32ah", 0x0e000650, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_3},
970 {"cfmv32a", 0x0e000670, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_3},
971 {"cfmva32", 0x0e100670, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_3},
972 {"cfmv64a", 0x0e000690, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_3},
973 {"cfmva64", 0x0e100690, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_3},
974 {"cfmvsc32", 0x0e1006b0, NULL, NULL, ARM_EXT_MAVERICK, do_c_dspsc_1},
975 {"cfmv32sc", 0x0e0006b0, NULL, NULL, ARM_EXT_MAVERICK, do_c_dspsc_2},
976 {"cfcpys", 0x0e000400, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
977 {"cfcpyd", 0x0e000420, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
978 {"cfcvtsd", 0x0e000460, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
979 {"cfcvtds", 0x0e000440, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
980 {"cfcvt32s", 0x0e000480, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
981 {"cfcvt32d", 0x0e0004a0, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
982 {"cfcvt64s", 0x0e0004c0, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
983 {"cfcvt64d", 0x0e0004e0, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
984 {"cfcvts32", 0x0e100580, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
985 {"cfcvtd32", 0x0e1005a0, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
986 {"cftruncs32",0x0e1005c0, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
987 {"cftruncd32",0x0e1005e0, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
988 {"cfrshl32", 0x0e000550, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_4},
989 {"cfrshl64", 0x0e000570, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_4},
990 {"cfsh32", 0x0e000500, NULL, NULL, ARM_EXT_MAVERICK, do_c_shift_1},
991 {"cfsh64", 0x0e200500, NULL, NULL, ARM_EXT_MAVERICK, do_c_shift_2},
992 {"cfcmps", 0x0e100490, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
993 {"cfcmpd", 0x0e1004b0, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
994 {"cfcmp32", 0x0e100590, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
995 {"cfcmp64", 0x0e1005b0, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
996 {"cfabss", 0x0e300400, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
997 {"cfabsd", 0x0e300420, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
998 {"cfnegs", 0x0e300440, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
999 {"cfnegd", 0x0e300460, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
1000 {"cfadds", 0x0e300480, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1001 {"cfaddd", 0x0e3004a0, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1002 {"cfsubs", 0x0e3004c0, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1003 {"cfsubd", 0x0e3004e0, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1004 {"cfmuls", 0x0e100400, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1005 {"cfmuld", 0x0e100420, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1006 {"cfabs32", 0x0e300500, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
1007 {"cfabs64", 0x0e300520, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
1008 {"cfneg32", 0x0e300540, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
1009 {"cfneg64", 0x0e300560, NULL, NULL, ARM_EXT_MAVERICK, do_c_binops_1},
1010 {"cfadd32", 0x0e300580, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1011 {"cfadd64", 0x0e3005a0, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1012 {"cfsub32", 0x0e3005c0, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1013 {"cfsub64", 0x0e3005e0, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1014 {"cfmul32", 0x0e100500, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1015 {"cfmul64", 0x0e100520, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1016 {"cfmac32", 0x0e100540, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1017 {"cfmsc32", 0x0e100560, NULL, NULL, ARM_EXT_MAVERICK, do_c_triple_5},
1018 {"cfmadd32", 0x0e000600, NULL, NULL, ARM_EXT_MAVERICK, do_c_quad_6},
1019 {"cfmsub32", 0x0e100600, NULL, NULL, ARM_EXT_MAVERICK, do_c_quad_6},
1020 {"cfmadda32", 0x0e200600, NULL, NULL, ARM_EXT_MAVERICK, do_c_quad_6},
1021 {"cfmsuba32", 0x0e300600, NULL, NULL, ARM_EXT_MAVERICK, do_c_quad_6},
1024 /* Defines for various bits that we will want to toggle. */
1025 #define INST_IMMEDIATE 0x02000000
1026 #define OFFSET_REG 0x02000000
1027 #define HWOFFSET_IMM 0x00400000
1028 #define SHIFT_BY_REG 0x00000010
1029 #define PRE_INDEX 0x01000000
1030 #define INDEX_UP 0x00800000
1031 #define WRITE_BACK 0x00200000
1032 #define LDM_TYPE_2_OR_3 0x00400000
1034 #define LITERAL_MASK 0xf000f000
1035 #define COND_MASK 0xf0000000
1036 #define OPCODE_MASK 0xfe1fffff
1037 #define DATA_OP_SHIFT 21
1039 /* Codes to distinguish the arithmetic instructions. */
1040 #define OPCODE_AND 0
1041 #define OPCODE_EOR 1
1042 #define OPCODE_SUB 2
1043 #define OPCODE_RSB 3
1044 #define OPCODE_ADD 4
1045 #define OPCODE_ADC 5
1046 #define OPCODE_SBC 6
1047 #define OPCODE_RSC 7
1048 #define OPCODE_TST 8
1049 #define OPCODE_TEQ 9
1050 #define OPCODE_CMP 10
1051 #define OPCODE_CMN 11
1052 #define OPCODE_ORR 12
1053 #define OPCODE_MOV 13
1054 #define OPCODE_BIC 14
1055 #define OPCODE_MVN 15
1057 static void do_t_nop PARAMS ((char *));
1058 static void do_t_arit PARAMS ((char *));
1059 static void do_t_add PARAMS ((char *));
1060 static void do_t_asr PARAMS ((char *));
1061 static void do_t_branch9 PARAMS ((char *));
1062 static void do_t_branch12 PARAMS ((char *));
1063 static void do_t_branch23 PARAMS ((char *));
1064 static void do_t_bx PARAMS ((char *));
1065 static void do_t_compare PARAMS ((char *));
1066 static void do_t_ldmstm PARAMS ((char *));
1067 static void do_t_ldr PARAMS ((char *));
1068 static void do_t_ldrb PARAMS ((char *));
1069 static void do_t_ldrh PARAMS ((char *));
1070 static void do_t_lds PARAMS ((char *));
1071 static void do_t_lsl PARAMS ((char *));
1072 static void do_t_lsr PARAMS ((char *));
1073 static void do_t_mov PARAMS ((char *));
1074 static void do_t_push_pop PARAMS ((char *));
1075 static void do_t_str PARAMS ((char *));
1076 static void do_t_strb PARAMS ((char *));
1077 static void do_t_strh PARAMS ((char *));
1078 static void do_t_sub PARAMS ((char *));
1079 static void do_t_swi PARAMS ((char *));
1080 static void do_t_adr PARAMS ((char *));
1082 #define T_OPCODE_MUL 0x4340
1083 #define T_OPCODE_TST 0x4200
1084 #define T_OPCODE_CMN 0x42c0
1085 #define T_OPCODE_NEG 0x4240
1086 #define T_OPCODE_MVN 0x43c0
1088 #define T_OPCODE_ADD_R3 0x1800
1089 #define T_OPCODE_SUB_R3 0x1a00
1090 #define T_OPCODE_ADD_HI 0x4400
1091 #define T_OPCODE_ADD_ST 0xb000
1092 #define T_OPCODE_SUB_ST 0xb080
1093 #define T_OPCODE_ADD_SP 0xa800
1094 #define T_OPCODE_ADD_PC 0xa000
1095 #define T_OPCODE_ADD_I8 0x3000
1096 #define T_OPCODE_SUB_I8 0x3800
1097 #define T_OPCODE_ADD_I3 0x1c00
1098 #define T_OPCODE_SUB_I3 0x1e00
1100 #define T_OPCODE_ASR_R 0x4100
1101 #define T_OPCODE_LSL_R 0x4080
1102 #define T_OPCODE_LSR_R 0x40c0
1103 #define T_OPCODE_ASR_I 0x1000
1104 #define T_OPCODE_LSL_I 0x0000
1105 #define T_OPCODE_LSR_I 0x0800
1107 #define T_OPCODE_MOV_I8 0x2000
1108 #define T_OPCODE_CMP_I8 0x2800
1109 #define T_OPCODE_CMP_LR 0x4280
1110 #define T_OPCODE_MOV_HR 0x4600
1111 #define T_OPCODE_CMP_HR 0x4500
1113 #define T_OPCODE_LDR_PC 0x4800
1114 #define T_OPCODE_LDR_SP 0x9800
1115 #define T_OPCODE_STR_SP 0x9000
1116 #define T_OPCODE_LDR_IW 0x6800
1117 #define T_OPCODE_STR_IW 0x6000
1118 #define T_OPCODE_LDR_IH 0x8800
1119 #define T_OPCODE_STR_IH 0x8000
1120 #define T_OPCODE_LDR_IB 0x7800
1121 #define T_OPCODE_STR_IB 0x7000
1122 #define T_OPCODE_LDR_RW 0x5800
1123 #define T_OPCODE_STR_RW 0x5000
1124 #define T_OPCODE_LDR_RH 0x5a00
1125 #define T_OPCODE_STR_RH 0x5200
1126 #define T_OPCODE_LDR_RB 0x5c00
1127 #define T_OPCODE_STR_RB 0x5400
1129 #define T_OPCODE_PUSH 0xb400
1130 #define T_OPCODE_POP 0xbc00
1132 #define T_OPCODE_BRANCH 0xe7fe
1134 static int thumb_reg PARAMS ((char ** str, int hi_lo));
1136 #define THUMB_SIZE 2 /* Size of thumb instruction. */
1137 #define THUMB_REG_LO 0x1
1138 #define THUMB_REG_HI 0x2
1139 #define THUMB_REG_ANY 0x3
1141 #define THUMB_H1 0x0080
1142 #define THUMB_H2 0x0040
1148 #define THUMB_MOVE 0
1149 #define THUMB_COMPARE 1
1151 #define THUMB_LOAD 0
1152 #define THUMB_STORE 1
1154 #define THUMB_PP_PC_LR 0x0100
1156 /* These three are used for immediate shifts, do not alter. */
1157 #define THUMB_WORD 2
1158 #define THUMB_HALFWORD 1
1159 #define THUMB_BYTE 0
1163 /* Basic string to match. */
1164 const char * template;
1166 /* Basic instruction code. */
1167 unsigned long value;
1171 /* Which CPU variants this exists for. */
1172 unsigned long variants;
1174 /* Function to call to parse args. */
1175 void (* parms) PARAMS ((char *));
1178 static const struct thumb_opcode tinsns[] =
1180 {"adc", 0x4140, 2, ARM_EXT_THUMB, do_t_arit},
1181 {"add", 0x0000, 2, ARM_EXT_THUMB, do_t_add},
1182 {"and", 0x4000, 2, ARM_EXT_THUMB, do_t_arit},
1183 {"asr", 0x0000, 2, ARM_EXT_THUMB, do_t_asr},
1184 {"b", T_OPCODE_BRANCH, 2, ARM_EXT_THUMB, do_t_branch12},
1185 {"beq", 0xd0fe, 2, ARM_EXT_THUMB, do_t_branch9},
1186 {"bne", 0xd1fe, 2, ARM_EXT_THUMB, do_t_branch9},
1187 {"bcs", 0xd2fe, 2, ARM_EXT_THUMB, do_t_branch9},
1188 {"bhs", 0xd2fe, 2, ARM_EXT_THUMB, do_t_branch9},
1189 {"bcc", 0xd3fe, 2, ARM_EXT_THUMB, do_t_branch9},
1190 {"bul", 0xd3fe, 2, ARM_EXT_THUMB, do_t_branch9},
1191 {"blo", 0xd3fe, 2, ARM_EXT_THUMB, do_t_branch9},
1192 {"bmi", 0xd4fe, 2, ARM_EXT_THUMB, do_t_branch9},
1193 {"bpl", 0xd5fe, 2, ARM_EXT_THUMB, do_t_branch9},
1194 {"bvs", 0xd6fe, 2, ARM_EXT_THUMB, do_t_branch9},
1195 {"bvc", 0xd7fe, 2, ARM_EXT_THUMB, do_t_branch9},
1196 {"bhi", 0xd8fe, 2, ARM_EXT_THUMB, do_t_branch9},
1197 {"bls", 0xd9fe, 2, ARM_EXT_THUMB, do_t_branch9},
1198 {"bge", 0xdafe, 2, ARM_EXT_THUMB, do_t_branch9},
1199 {"blt", 0xdbfe, 2, ARM_EXT_THUMB, do_t_branch9},
1200 {"bgt", 0xdcfe, 2, ARM_EXT_THUMB, do_t_branch9},
1201 {"ble", 0xddfe, 2, ARM_EXT_THUMB, do_t_branch9},
1202 {"bal", 0xdefe, 2, ARM_EXT_THUMB, do_t_branch9},
1203 {"bic", 0x4380, 2, ARM_EXT_THUMB, do_t_arit},
1204 {"bl", 0xf7fffffe, 4, ARM_EXT_THUMB, do_t_branch23},
1205 {"blx", 0, 0, ARM_EXT_V5, do_t_blx},
1206 {"bkpt", 0xbe00, 2, ARM_EXT_V5, do_t_bkpt},
1207 {"bx", 0x4700, 2, ARM_EXT_THUMB, do_t_bx},
1208 {"cmn", T_OPCODE_CMN, 2, ARM_EXT_THUMB, do_t_arit},
1209 {"cmp", 0x0000, 2, ARM_EXT_THUMB, do_t_compare},
1210 {"eor", 0x4040, 2, ARM_EXT_THUMB, do_t_arit},
1211 {"ldmia", 0xc800, 2, ARM_EXT_THUMB, do_t_ldmstm},
1212 {"ldr", 0x0000, 2, ARM_EXT_THUMB, do_t_ldr},
1213 {"ldrb", 0x0000, 2, ARM_EXT_THUMB, do_t_ldrb},
1214 {"ldrh", 0x0000, 2, ARM_EXT_THUMB, do_t_ldrh},
1215 {"ldrsb", 0x5600, 2, ARM_EXT_THUMB, do_t_lds},
1216 {"ldrsh", 0x5e00, 2, ARM_EXT_THUMB, do_t_lds},
1217 {"ldsb", 0x5600, 2, ARM_EXT_THUMB, do_t_lds},
1218 {"ldsh", 0x5e00, 2, ARM_EXT_THUMB, do_t_lds},
1219 {"lsl", 0x0000, 2, ARM_EXT_THUMB, do_t_lsl},
1220 {"lsr", 0x0000, 2, ARM_EXT_THUMB, do_t_lsr},
1221 {"mov", 0x0000, 2, ARM_EXT_THUMB, do_t_mov},
1222 {"mul", T_OPCODE_MUL, 2, ARM_EXT_THUMB, do_t_arit},
1223 {"mvn", T_OPCODE_MVN, 2, ARM_EXT_THUMB, do_t_arit},
1224 {"neg", T_OPCODE_NEG, 2, ARM_EXT_THUMB, do_t_arit},
1225 {"orr", 0x4300, 2, ARM_EXT_THUMB, do_t_arit},
1226 {"pop", 0xbc00, 2, ARM_EXT_THUMB, do_t_push_pop},
1227 {"push", 0xb400, 2, ARM_EXT_THUMB, do_t_push_pop},
1228 {"ror", 0x41c0, 2, ARM_EXT_THUMB, do_t_arit},
1229 {"sbc", 0x4180, 2, ARM_EXT_THUMB, do_t_arit},
1230 {"stmia", 0xc000, 2, ARM_EXT_THUMB, do_t_ldmstm},
1231 {"str", 0x0000, 2, ARM_EXT_THUMB, do_t_str},
1232 {"strb", 0x0000, 2, ARM_EXT_THUMB, do_t_strb},
1233 {"strh", 0x0000, 2, ARM_EXT_THUMB, do_t_strh},
1234 {"swi", 0xdf00, 2, ARM_EXT_THUMB, do_t_swi},
1235 {"sub", 0x0000, 2, ARM_EXT_THUMB, do_t_sub},
1236 {"tst", T_OPCODE_TST, 2, ARM_EXT_THUMB, do_t_arit},
1238 {"adr", 0x0000, 2, ARM_EXT_THUMB, do_t_adr},
1239 {"nop", 0x46C0, 2, ARM_EXT_THUMB, do_t_nop}, /* mov r8,r8 */
1248 #define int_register(reg) ((reg) >= 0 && (reg) <= 15)
1249 #define cp_register(reg) ((reg) >= 32 && (reg) <= 47)
1250 #define fp_register(reg) ((reg) >= 16 && (reg) <= 23)
1252 #define ARM_EXT_MAVERICKSC_REG 134
1254 #define cirrus_register(reg) ((reg) >= 50 && (reg) <= 134)
1255 #define cirrus_mvf_register(reg) ((reg) >= 50 && (reg) <= 65)
1256 #define cirrus_mvd_register(reg) ((reg) >= 70 && (reg) <= 85)
1257 #define cirrus_mvfx_register(reg) ((reg) >= 90 && (reg) <= 105)
1258 #define cirrus_mvdx_register(reg) ((reg) >= 110 && (reg) <= 125)
1259 #define cirrus_mvax_register(reg) ((reg) >= 130 && (reg) <= 133)
1260 #define ARM_EXT_MAVERICKsc_register(reg) ((reg) == ARM_EXT_MAVERICKSC_REG)
1266 /* These are the standard names. Users can add aliases with .req. */
1267 static const struct reg_entry reg_table[] =
1269 /* Processor Register Numbers. */
1270 {"r0", 0}, {"r1", 1}, {"r2", 2}, {"r3", 3},
1271 {"r4", 4}, {"r5", 5}, {"r6", 6}, {"r7", 7},
1272 {"r8", 8}, {"r9", 9}, {"r10", 10}, {"r11", 11},
1273 {"r12", 12}, {"r13", REG_SP},{"r14", REG_LR},{"r15", REG_PC},
1274 /* APCS conventions. */
1275 {"a1", 0}, {"a2", 1}, {"a3", 2}, {"a4", 3},
1276 {"v1", 4}, {"v2", 5}, {"v3", 6}, {"v4", 7}, {"v5", 8},
1277 {"v6", 9}, {"sb", 9}, {"v7", 10}, {"sl", 10},
1278 {"fp", 11}, {"ip", 12}, {"sp", REG_SP},{"lr", REG_LR},{"pc", REG_PC},
1279 /* ATPCS additions to APCS conventions. */
1280 {"wr", 7}, {"v8", 11},
1282 {"f0", 16}, {"f1", 17}, {"f2", 18}, {"f3", 19},
1283 {"f4", 20}, {"f5", 21}, {"f6", 22}, {"f7", 23},
1284 {"c0", 32}, {"c1", 33}, {"c2", 34}, {"c3", 35},
1285 {"c4", 36}, {"c5", 37}, {"c6", 38}, {"c7", 39},
1286 {"c8", 40}, {"c9", 41}, {"c10", 42}, {"c11", 43},
1287 {"c12", 44}, {"c13", 45}, {"c14", 46}, {"c15", 47},
1288 {"cr0", 32}, {"cr1", 33}, {"cr2", 34}, {"cr3", 35},
1289 {"cr4", 36}, {"cr5", 37}, {"cr6", 38}, {"cr7", 39},
1290 {"cr8", 40}, {"cr9", 41}, {"cr10", 42}, {"cr11", 43},
1291 {"cr12", 44}, {"cr13", 45}, {"cr14", 46}, {"cr15", 47},
1292 /* ATPCS additions to float register names. */
1293 {"s0",16}, {"s1",17}, {"s2",18}, {"s3",19},
1294 {"s4",20}, {"s5",21}, {"s6",22}, {"s7",23},
1295 {"d0",16}, {"d1",17}, {"d2",18}, {"d3",19},
1296 {"d4",20}, {"d5",21}, {"d6",22}, {"d7",23},
1297 /* Cirrus DSP coprocessor registers. */
1298 {"mvf0", 50}, {"mvf1", 51}, {"mvf2", 52}, {"mvf3", 53},
1299 {"mvf4", 54}, {"mvf5", 55}, {"mvf6", 56}, {"mvf7", 57},
1300 {"mvf8", 58}, {"mvf9", 59}, {"mvf10", 60}, {"mvf11", 61},
1301 {"mvf12", 62},{"mvf13", 63}, {"mvf14", 64}, {"mvf15", 65},
1302 {"mvd0", 70}, {"mvd1", 71}, {"mvd2", 72}, {"mvd3", 73},
1303 {"mvd4", 74}, {"mvd5", 75}, {"mvd6", 76}, {"mvd7", 77},
1304 {"mvd8", 78}, {"mvd9", 79}, {"mvd10", 80}, {"mvd11", 81},
1305 {"mvd12", 82},{"mvd13", 83}, {"mvd14", 84}, {"mvd15", 85},
1306 {"mvfx0", 90},{"mvfx1", 91}, {"mvfx2", 92}, {"mvfx3", 93},
1307 {"mvfx4", 94},{"mvfx5", 95}, {"mvfx6", 96}, {"mvfx7", 97},
1308 {"mvfx8", 98},{"mvfx9", 99}, {"mvfx10", 100},{"mvfx11", 101},
1309 {"mvfx12", 102},{"mvfx13", 103},{"mvfx14", 104},{"mvfx15", 105},
1310 {"mvdx0", 110}, {"mvdx1", 111}, {"mvdx2", 112}, {"mvdx3", 113},
1311 {"mvdx4", 114}, {"mvdx5", 115}, {"mvdx6", 116}, {"mvdx7", 117},
1312 {"mvdx8", 118}, {"mvdx9", 119}, {"mvdx10", 120},{"mvdx11", 121},
1313 {"mvdx12", 122},{"mvdx13", 123},{"mvdx14", 124},{"mvdx15", 125},
1314 {"mvax0", 130}, {"mvax1", 131}, {"mvax2", 132}, {"mvax3", 133},
1315 {"dspsc", ARM_EXT_MAVERICKSC_REG},
1316 /* FIXME: At some point we need to add VFP register names. */
1317 /* Array terminator. */
1321 #define BAD_ARGS _("Bad arguments to instruction")
1322 #define BAD_PC _("r15 not allowed here")
1323 #define BAD_FLAGS _("Instruction should not have flags")
1324 #define BAD_COND _("Instruction is not conditional")
1325 #define ERR_NO_ACCUM _("acc0 expected")
1327 static struct hash_control * arm_ops_hsh = NULL;
1328 static struct hash_control * arm_tops_hsh = NULL;
1329 static struct hash_control * arm_cond_hsh = NULL;
1330 static struct hash_control * arm_shift_hsh = NULL;
1331 static struct hash_control * arm_reg_hsh = NULL;
1332 static struct hash_control * arm_psr_hsh = NULL;
1334 /* This table describes all the machine specific pseudo-ops the assembler
1335 has to support. The fields are:
1336 pseudo-op name without dot
1337 function to call to execute this pseudo-op
1338 Integer arg to pass to the function. */
1340 static void s_req PARAMS ((int));
1341 static void s_align PARAMS ((int));
1342 static void s_bss PARAMS ((int));
1343 static void s_even PARAMS ((int));
1344 static void s_ltorg PARAMS ((int));
1345 static void s_arm PARAMS ((int));
1346 static void s_thumb PARAMS ((int));
1347 static void s_code PARAMS ((int));
1348 static void s_force_thumb PARAMS ((int));
1349 static void s_thumb_func PARAMS ((int));
1350 static void s_thumb_set PARAMS ((int));
1351 static void arm_s_text PARAMS ((int));
1352 static void arm_s_data PARAMS ((int));
1354 static void arm_s_section PARAMS ((int));
1355 static void s_arm_elf_cons PARAMS ((int));
1358 static int my_get_expression PARAMS ((expressionS *, char **));
1360 const pseudo_typeS md_pseudo_table[] =
1362 /* Never called becasue '.req' does not start line. */
1363 { "req", s_req, 0 },
1364 { "bss", s_bss, 0 },
1365 { "align", s_align, 0 },
1366 { "arm", s_arm, 0 },
1367 { "thumb", s_thumb, 0 },
1368 { "code", s_code, 0 },
1369 { "force_thumb", s_force_thumb, 0 },
1370 { "thumb_func", s_thumb_func, 0 },
1371 { "thumb_set", s_thumb_set, 0 },
1372 { "even", s_even, 0 },
1373 { "ltorg", s_ltorg, 0 },
1374 { "pool", s_ltorg, 0 },
1375 /* Allow for the effect of section changes. */
1376 { "text", arm_s_text, 0 },
1377 { "data", arm_s_data, 0 },
1379 { "section", arm_s_section, 0 },
1380 { "section.s", arm_s_section, 0 },
1381 { "sect", arm_s_section, 0 },
1382 { "sect.s", arm_s_section, 0 },
1383 { "word", s_arm_elf_cons, 4 },
1384 { "long", s_arm_elf_cons, 4 },
1385 { "file", dwarf2_directive_file, 0 },
1386 { "loc", dwarf2_directive_loc, 0 },
1390 { "extend", float_cons, 'x' },
1391 { "ldouble", float_cons, 'x' },
1392 { "packed", float_cons, 'p' },
1396 /* Stuff needed to resolve the label ambiguity
1406 symbolS * last_label_seen;
1407 static int label_is_thumb_function_name = false;
1409 /* Literal stuff. */
1411 #define MAX_LITERAL_POOL_SIZE 1024
1413 typedef struct literalS
1415 struct expressionS exp;
1416 struct arm_it * inst;
1419 literalT literals[MAX_LITERAL_POOL_SIZE];
1421 /* Next free entry in the pool. */
1422 int next_literal_pool_place = 0;
1424 /* Next literal pool number. */
1425 int lit_pool_num = 1;
1427 symbolS * current_poolP = NULL;
1434 if (current_poolP == NULL)
1435 current_poolP = symbol_create (FAKE_LABEL_NAME, undefined_section,
1436 (valueT) 0, &zero_address_frag);
1438 /* Check if this literal value is already in the pool: */
1439 while (lit_count < next_literal_pool_place)
1441 if (literals[lit_count].exp.X_op == inst.reloc.exp.X_op
1442 && inst.reloc.exp.X_op == O_constant
1443 && (literals[lit_count].exp.X_add_number
1444 == inst.reloc.exp.X_add_number)
1445 && literals[lit_count].exp.X_unsigned == inst.reloc.exp.X_unsigned)
1448 if (literals[lit_count].exp.X_op == inst.reloc.exp.X_op
1449 && inst.reloc.exp.X_op == O_symbol
1450 && (literals[lit_count].exp.X_add_number
1451 == inst.reloc.exp.X_add_number)
1452 && (literals[lit_count].exp.X_add_symbol
1453 == inst.reloc.exp.X_add_symbol)
1454 && (literals[lit_count].exp.X_op_symbol
1455 == inst.reloc.exp.X_op_symbol))
1461 if (lit_count == next_literal_pool_place) /* New entry. */
1463 if (next_literal_pool_place >= MAX_LITERAL_POOL_SIZE)
1465 inst.error = _("Literal Pool Overflow");
1469 literals[next_literal_pool_place].exp = inst.reloc.exp;
1470 lit_count = next_literal_pool_place++;
1473 inst.reloc.exp.X_op = O_symbol;
1474 inst.reloc.exp.X_add_number = (lit_count) * 4 - 8;
1475 inst.reloc.exp.X_add_symbol = current_poolP;
1480 /* Can't use symbol_new here, so have to create a symbol and then at
1481 a later date assign it a value. Thats what these functions do. */
1484 symbol_locate (symbolP, name, segment, valu, frag)
1486 const char * name; /* It is copied, the caller can modify. */
1487 segT segment; /* Segment identifier (SEG_<something>). */
1488 valueT valu; /* Symbol value. */
1489 fragS * frag; /* Associated fragment. */
1491 unsigned int name_length;
1492 char * preserved_copy_of_name;
1494 name_length = strlen (name) + 1; /* +1 for \0. */
1495 obstack_grow (¬es, name, name_length);
1496 preserved_copy_of_name = obstack_finish (¬es);
1497 #ifdef STRIP_UNDERSCORE
1498 if (preserved_copy_of_name[0] == '_')
1499 preserved_copy_of_name++;
1502 #ifdef tc_canonicalize_symbol_name
1503 preserved_copy_of_name =
1504 tc_canonicalize_symbol_name (preserved_copy_of_name);
1507 S_SET_NAME (symbolP, preserved_copy_of_name);
1509 S_SET_SEGMENT (symbolP, segment);
1510 S_SET_VALUE (symbolP, valu);
1511 symbol_clear_list_pointers(symbolP);
1513 symbol_set_frag (symbolP, frag);
1515 /* Link to end of symbol chain. */
1517 extern int symbol_table_frozen;
1518 if (symbol_table_frozen)
1522 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
1524 obj_symbol_new_hook (symbolP);
1526 #ifdef tc_symbol_new_hook
1527 tc_symbol_new_hook (symbolP);
1531 verify_symbol_chain (symbol_rootP, symbol_lastP);
1532 #endif /* DEBUG_SYMS */
1535 /* Check that an immediate is valid.
1536 If so, convert it to the right format. */
1539 validate_immediate (val)
1545 #define rotate_left(v, n) (v << n | v >> (32 - n))
1547 for (i = 0; i < 32; i += 2)
1548 if ((a = rotate_left (val, i)) <= 0xff)
1549 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
1554 /* Check to see if an immediate can be computed as two seperate immediate
1555 values, added together. We already know that this value cannot be
1556 computed by just one ARM instruction. */
1559 validate_immediate_twopart (val, highpart)
1561 unsigned int * highpart;
1566 for (i = 0; i < 32; i += 2)
1567 if (((a = rotate_left (val, i)) & 0xff) != 0)
1573 * highpart = (a >> 8) | ((i + 24) << 7);
1575 else if (a & 0xff0000)
1579 * highpart = (a >> 16) | ((i + 16) << 7);
1583 assert (a & 0xff000000);
1584 * highpart = (a >> 24) | ((i + 8) << 7);
1587 return (a & 0xff) | (i << 7);
1594 validate_offset_imm (val, hwse)
1598 if ((hwse && val > 255) || val > 4095)
1605 int a ATTRIBUTE_UNUSED;
1607 as_bad (_("Invalid syntax for .req directive."));
1612 int ignore ATTRIBUTE_UNUSED;
1614 /* We don't support putting frags in the BSS segment, we fake it by
1615 marking in_bss, then looking at s_skip for clues. */
1616 subseg_set (bss_section, 0);
1617 demand_empty_rest_of_line ();
1622 int ignore ATTRIBUTE_UNUSED;
1624 /* Never make frag if expect extra pass. */
1626 frag_align (1, 0, 0);
1628 record_alignment (now_seg, 1);
1630 demand_empty_rest_of_line ();
1635 int ignored ATTRIBUTE_UNUSED;
1640 if (current_poolP == NULL)
1643 /* Align pool as you have word accesses.
1644 Only make a frag if we have to. */
1646 frag_align (2, 0, 0);
1648 record_alignment (now_seg, 2);
1650 sprintf (sym_name, "$$lit_\002%x", lit_pool_num++);
1652 symbol_locate (current_poolP, sym_name, now_seg,
1653 (valueT) frag_now_fix (), frag_now);
1654 symbol_table_insert (current_poolP);
1656 ARM_SET_THUMB (current_poolP, thumb_mode);
1658 #if defined OBJ_COFF || defined OBJ_ELF
1659 ARM_SET_INTERWORK (current_poolP, support_interwork);
1662 while (lit_count < next_literal_pool_place)
1663 /* First output the expression in the instruction to the pool. */
1664 emit_expr (&(literals[lit_count++].exp), 4); /* .word */
1666 next_literal_pool_place = 0;
1667 current_poolP = NULL;
1670 /* Same as s_align_ptwo but align 0 => align 2. */
1674 int unused ATTRIBUTE_UNUSED;
1677 register long temp_fill;
1678 long max_alignment = 15;
1680 temp = get_absolute_expression ();
1681 if (temp > max_alignment)
1682 as_bad (_("Alignment too large: %d. assumed."), temp = max_alignment);
1685 as_bad (_("Alignment negative. 0 assumed."));
1689 if (*input_line_pointer == ',')
1691 input_line_pointer++;
1692 temp_fill = get_absolute_expression ();
1700 /* Only make a frag if we HAVE to. */
1701 if (temp && !need_pass_2)
1702 frag_align (temp, (int) temp_fill, 0);
1703 demand_empty_rest_of_line ();
1705 record_alignment (now_seg, temp);
1709 s_force_thumb (ignore)
1710 int ignore ATTRIBUTE_UNUSED;
1712 /* If we are not already in thumb mode go into it, EVEN if
1713 the target processor does not support thumb instructions.
1714 This is used by gcc/config/arm/lib1funcs.asm for example
1715 to compile interworking support functions even if the
1716 target processor should not support interworking. */
1721 record_alignment (now_seg, 1);
1724 demand_empty_rest_of_line ();
1728 s_thumb_func (ignore)
1729 int ignore ATTRIBUTE_UNUSED;
1734 /* The following label is the name/address of the start of a Thumb function.
1735 We need to know this for the interworking support. */
1736 label_is_thumb_function_name = true;
1738 demand_empty_rest_of_line ();
1741 /* Perform a .set directive, but also mark the alias as
1742 being a thumb function. */
1748 /* XXX the following is a duplicate of the code for s_set() in read.c
1749 We cannot just call that code as we need to get at the symbol that
1751 register char * name;
1752 register char delim;
1753 register char * end_name;
1754 register symbolS * symbolP;
1756 /* Especial apologies for the random logic:
1757 This just grew, and could be parsed much more simply!
1759 name = input_line_pointer;
1760 delim = get_symbol_end ();
1761 end_name = input_line_pointer;
1766 if (*input_line_pointer != ',')
1769 as_bad (_("Expected comma after name \"%s\""), name);
1771 ignore_rest_of_line ();
1775 input_line_pointer++;
1778 if (name[0] == '.' && name[1] == '\0')
1780 /* XXX - this should not happen to .thumb_set. */
1784 if ((symbolP = symbol_find (name)) == NULL
1785 && (symbolP = md_undefined_symbol (name)) == NULL)
1788 /* When doing symbol listings, play games with dummy fragments living
1789 outside the normal fragment chain to record the file and line info
1791 if (listing & LISTING_SYMBOLS)
1793 extern struct list_info_struct * listing_tail;
1794 fragS * dummy_frag = (fragS *) xmalloc (sizeof (fragS));
1796 memset (dummy_frag, 0, sizeof (fragS));
1797 dummy_frag->fr_type = rs_fill;
1798 dummy_frag->line = listing_tail;
1799 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
1800 dummy_frag->fr_symbol = symbolP;
1804 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1807 /* "set" symbols are local unless otherwise specified. */
1808 SF_SET_LOCAL (symbolP);
1809 #endif /* OBJ_COFF */
1810 } /* Make a new symbol. */
1812 symbol_table_insert (symbolP);
1817 && S_IS_DEFINED (symbolP)
1818 && S_GET_SEGMENT (symbolP) != reg_section)
1819 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
1821 pseudo_set (symbolP);
1823 demand_empty_rest_of_line ();
1825 /* XXX Now we come to the Thumb specific bit of code. */
1827 THUMB_SET_FUNC (symbolP, 1);
1828 ARM_SET_THUMB (symbolP, 1);
1829 #if defined OBJ_ELF || defined OBJ_COFF
1830 ARM_SET_INTERWORK (symbolP, support_interwork);
1834 /* If we change section we must dump the literal pool first. */
1840 if (now_seg != text_section)
1844 obj_elf_text (ignore);
1854 if (flag_readonly_data_in_text)
1856 if (now_seg != text_section)
1859 else if (now_seg != data_section)
1863 obj_elf_data (ignore);
1871 arm_s_section (ignore)
1876 obj_elf_section (ignore);
1881 opcode_select (width)
1889 if (! (cpu_variant & ARM_EXT_THUMB))
1890 as_bad (_("selected processor does not support THUMB opcodes"));
1893 /* No need to force the alignment, since we will have been
1894 coming from ARM mode, which is word-aligned. */
1895 record_alignment (now_seg, 1);
1902 if ((cpu_variant & ARM_ANY) == ARM_EXT_THUMB)
1903 as_bad (_("selected processor does not support ARM opcodes"));
1908 frag_align (2, 0, 0);
1910 record_alignment (now_seg, 1);
1915 as_bad (_("invalid instruction size selected (%d)"), width);
1921 int ignore ATTRIBUTE_UNUSED;
1924 demand_empty_rest_of_line ();
1929 int ignore ATTRIBUTE_UNUSED;
1932 demand_empty_rest_of_line ();
1937 int unused ATTRIBUTE_UNUSED;
1941 temp = get_absolute_expression ();
1946 opcode_select (temp);
1950 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
1958 skip_whitespace (str);
1961 inst.error = _("Garbage following instruction");
1965 skip_past_comma (str)
1968 char * p = * str, c;
1971 while ((c = *p) == ' ' || c == ',')
1974 if (c == ',' && comma++)
1982 return comma ? SUCCESS : FAIL;
1985 /* A standard register must be given at this point.
1986 SHIFT is the place to put it in inst.instruction.
1987 Restores input start point on error.
1988 Returns the reg#, or FAIL. */
1991 reg_required_here (str, shift)
1995 static char buff [128]; /* XXX */
1997 char * start = * str;
1999 if ((reg = arm_reg_parse (str)) != FAIL && int_register (reg))
2002 inst.instruction |= reg << shift;
2006 /* Restore the start point, we may have got a reg of the wrong class. */
2009 /* In the few cases where we might be able to accept something else
2010 this error can be overridden. */
2011 sprintf (buff, _("Register expected, not '%.100s'"), start);
2017 static const struct asm_psr *
2019 register char ** ccp;
2021 char * start = * ccp;
2024 const struct asm_psr * psr;
2028 /* Skip to the end of the next word in the input stream. */
2033 while (ISALPHA (c) || c == '_');
2035 /* Terminate the word. */
2038 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
2039 feature for ease of use and backwards compatibility. */
2040 if (!strncmp (start, "cpsr", 4))
2041 strncpy (start, "CPSR", 4);
2042 else if (!strncmp (start, "spsr", 4))
2043 strncpy (start, "SPSR", 4);
2045 /* Now locate the word in the psr hash table. */
2046 psr = (const struct asm_psr *) hash_find (arm_psr_hsh, start);
2048 /* Restore the input stream. */
2051 /* If we found a valid match, advance the
2052 stream pointer past the end of the word. */
2058 /* Parse the input looking for a PSR flag. */
2061 psr_required_here (str)
2064 char * start = * str;
2065 const struct asm_psr * psr;
2067 psr = arm_psr_parse (str);
2071 /* If this is the SPSR that is being modified, set the R bit. */
2073 inst.instruction |= SPSR_BIT;
2075 /* Set the psr flags in the MSR instruction. */
2076 inst.instruction |= psr->field << PSR_SHIFT;
2081 /* In the few cases where we might be able to accept
2082 something else this error can be overridden. */
2083 inst.error = _("flag for {c}psr instruction expected");
2085 /* Restore the start point. */
2091 co_proc_number (str)
2094 int processor, pchar;
2096 skip_whitespace (* str);
2098 /* The data sheet seems to imply that just a number on its own is valid
2099 here, but the RISC iX assembler seems to accept a prefix 'p'. We will
2101 if (**str == 'p' || **str == 'P')
2105 if (pchar >= '0' && pchar <= '9')
2107 processor = pchar - '0';
2108 if (**str >= '0' && **str <= '9')
2110 processor = processor * 10 + *(*str)++ - '0';
2113 inst.error = _("Illegal co-processor number");
2120 inst.error = _("Bad or missing co-processor number");
2124 inst.instruction |= processor << 8;
2129 cp_opc_expr (str, where, length)
2136 skip_whitespace (* str);
2138 memset (&expr, '\0', sizeof (expr));
2140 if (my_get_expression (&expr, str))
2142 if (expr.X_op != O_constant)
2144 inst.error = _("bad or missing expression");
2148 if ((expr.X_add_number & ((1 << length) - 1)) != expr.X_add_number)
2150 inst.error = _("immediate co-processor expression too large");
2154 inst.instruction |= expr.X_add_number << where;
2159 cp_reg_required_here (str, where)
2164 char * start = *str;
2166 if ((reg = arm_reg_parse (str)) != FAIL && cp_register (reg))
2169 inst.instruction |= reg << where;
2173 /* In the few cases where we might be able to accept something else
2174 this error can be overridden. */
2175 inst.error = _("Co-processor register expected");
2177 /* Restore the start point. */
2183 fp_reg_required_here (str, where)
2188 char * start = * str;
2190 if ((reg = arm_reg_parse (str)) != FAIL && fp_register (reg))
2193 inst.instruction |= reg << where;
2197 /* In the few cases where we might be able to accept something else
2198 this error can be overridden. */
2199 inst.error = _("Floating point register expected");
2201 /* Restore the start point. */
2207 cp_address_offset (str)
2212 skip_whitespace (* str);
2214 if (! is_immediate_prefix (**str))
2216 inst.error = _("immediate expression expected");
2222 if (my_get_expression (& inst.reloc.exp, str))
2225 if (inst.reloc.exp.X_op == O_constant)
2227 offset = inst.reloc.exp.X_add_number;
2231 inst.error = _("co-processor address must be word aligned");
2235 if (offset > 1023 || offset < -1023)
2237 inst.error = _("offset too large");
2242 inst.instruction |= INDEX_UP;
2246 inst.instruction |= offset >> 2;
2249 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
2255 cp_address_required_here (str)
2267 skip_whitespace (p);
2269 if ((reg = reg_required_here (& p, 16)) == FAIL)
2272 skip_whitespace (p);
2278 if (skip_past_comma (& p) == SUCCESS)
2281 write_back = WRITE_BACK;
2285 inst.error = _("pc may not be used in post-increment");
2289 if (cp_address_offset (& p) == FAIL)
2293 pre_inc = PRE_INDEX | INDEX_UP;
2297 /* '['Rn, #expr']'[!] */
2299 if (skip_past_comma (& p) == FAIL)
2301 inst.error = _("pre-indexed expression expected");
2305 pre_inc = PRE_INDEX;
2307 if (cp_address_offset (& p) == FAIL)
2310 skip_whitespace (p);
2314 inst.error = _("missing ]");
2318 skip_whitespace (p);
2324 inst.error = _("pc may not be used with write-back");
2329 write_back = WRITE_BACK;
2335 if (my_get_expression (&inst.reloc.exp, &p))
2338 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
2339 inst.reloc.exp.X_add_number -= 8; /* PC rel adjust. */
2340 inst.reloc.pc_rel = 1;
2341 inst.instruction |= (REG_PC << 16);
2342 pre_inc = PRE_INDEX;
2345 inst.instruction |= write_back | pre_inc;
2353 unsigned long flags;
2355 /* Do nothing really. */
2356 inst.instruction |= flags; /* This is pointless. */
2364 unsigned long flags;
2368 /* Only one syntax. */
2369 skip_whitespace (str);
2371 if (reg_required_here (&str, 12) == FAIL)
2373 inst.error = BAD_ARGS;
2377 if (skip_past_comma (&str) == FAIL)
2379 inst.error = _("comma expected after register name");
2383 skip_whitespace (str);
2385 if ( strcmp (str, "CPSR") == 0
2386 || strcmp (str, "SPSR") == 0
2387 /* Lower case versions for backwards compatability. */
2388 || strcmp (str, "cpsr") == 0
2389 || strcmp (str, "spsr") == 0)
2392 /* This is for backwards compatability with older toolchains. */
2393 else if ( strcmp (str, "cpsr_all") == 0
2394 || strcmp (str, "spsr_all") == 0)
2398 inst.error = _("{C|S}PSR expected");
2402 if (* str == 's' || * str == 'S')
2403 inst.instruction |= SPSR_BIT;
2406 inst.instruction |= flags;
2410 /* Two possible forms:
2411 "{C|S}PSR_<field>, Rm",
2412 "{C|S}PSR_f, #expression". */
2417 unsigned long flags;
2419 skip_whitespace (str);
2421 if (psr_required_here (& str) == FAIL)
2424 if (skip_past_comma (& str) == FAIL)
2426 inst.error = _("comma missing after psr flags");
2430 skip_whitespace (str);
2432 if (reg_required_here (& str, 0) != FAIL)
2435 inst.instruction |= flags;
2440 if (! is_immediate_prefix (* str))
2443 _("only a register or immediate value can follow a psr flag");
2450 if (my_get_expression (& inst.reloc.exp, & str))
2453 _("only a register or immediate value can follow a psr flag");
2457 #if 0 /* The first edition of the ARM architecture manual stated that
2458 writing anything other than the flags with an immediate operation
2459 had UNPREDICTABLE effects. This constraint was removed in the
2460 second edition of the specification. */
2461 if ((cpu_variant & ARM_EXT_V5) != ARM_EXT_V5
2462 && inst.instruction & ((PSR_c | PSR_x | PSR_s) << PSR_SHIFT))
2464 inst.error = _("immediate value cannot be used to set this field");
2469 flags |= INST_IMMEDIATE;
2471 if (inst.reloc.exp.X_add_symbol)
2473 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
2474 inst.reloc.pc_rel = 0;
2478 unsigned value = validate_immediate (inst.reloc.exp.X_add_number);
2480 if (value == (unsigned) FAIL)
2482 inst.error = _("Invalid constant");
2486 inst.instruction |= value;
2490 inst.instruction |= flags;
2494 /* Long Multiply Parser
2495 UMULL RdLo, RdHi, Rm, Rs
2496 SMULL RdLo, RdHi, Rm, Rs
2497 UMLAL RdLo, RdHi, Rm, Rs
2498 SMLAL RdLo, RdHi, Rm, Rs. */
2501 do_mull (str, flags)
2503 unsigned long flags;
2505 int rdlo, rdhi, rm, rs;
2507 /* Only one format "rdlo, rdhi, rm, rs". */
2508 skip_whitespace (str);
2510 if ((rdlo = reg_required_here (&str, 12)) == FAIL)
2512 inst.error = BAD_ARGS;
2516 if (skip_past_comma (&str) == FAIL
2517 || (rdhi = reg_required_here (&str, 16)) == FAIL)
2519 inst.error = BAD_ARGS;
2523 if (skip_past_comma (&str) == FAIL
2524 || (rm = reg_required_here (&str, 0)) == FAIL)
2526 inst.error = BAD_ARGS;
2530 /* rdhi, rdlo and rm must all be different. */
2531 if (rdlo == rdhi || rdlo == rm || rdhi == rm)
2532 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
2534 if (skip_past_comma (&str) == FAIL
2535 || (rs = reg_required_here (&str, 8)) == FAIL)
2537 inst.error = BAD_ARGS;
2541 if (rdhi == REG_PC || rdhi == REG_PC || rdhi == REG_PC || rdhi == REG_PC)
2543 inst.error = BAD_PC;
2547 inst.instruction |= flags;
2555 unsigned long flags;
2559 /* Only one format "rd, rm, rs". */
2560 skip_whitespace (str);
2562 if ((rd = reg_required_here (&str, 16)) == FAIL)
2564 inst.error = BAD_ARGS;
2570 inst.error = BAD_PC;
2574 if (skip_past_comma (&str) == FAIL
2575 || (rm = reg_required_here (&str, 0)) == FAIL)
2577 inst.error = BAD_ARGS;
2583 inst.error = BAD_PC;
2588 as_tsktsk (_("rd and rm should be different in mul"));
2590 if (skip_past_comma (&str) == FAIL
2591 || (rm = reg_required_here (&str, 8)) == FAIL)
2593 inst.error = BAD_ARGS;
2599 inst.error = BAD_PC;
2603 inst.instruction |= flags;
2611 unsigned long flags;
2615 /* Only one format "rd, rm, rs, rn". */
2616 skip_whitespace (str);
2618 if ((rd = reg_required_here (&str, 16)) == FAIL)
2620 inst.error = BAD_ARGS;
2626 inst.error = BAD_PC;
2630 if (skip_past_comma (&str) == FAIL
2631 || (rm = reg_required_here (&str, 0)) == FAIL)
2633 inst.error = BAD_ARGS;
2639 inst.error = BAD_PC;
2644 as_tsktsk (_("rd and rm should be different in mla"));
2646 if (skip_past_comma (&str) == FAIL
2647 || (rd = reg_required_here (&str, 8)) == FAIL
2648 || skip_past_comma (&str) == FAIL
2649 || (rm = reg_required_here (&str, 12)) == FAIL)
2651 inst.error = BAD_ARGS;
2655 if (rd == REG_PC || rm == REG_PC)
2657 inst.error = BAD_PC;
2661 inst.instruction |= flags;
2666 /* Expects *str -> the characters "acc0", possibly with leading blanks.
2667 Advances *str to the next non-alphanumeric.
2668 Returns 0, or else FAIL (in which case sets inst.error).
2670 (In a future XScale, there may be accumulators other than zero.
2671 At that time this routine and its callers can be upgraded to suit.) */
2674 accum0_required_here (str)
2677 static char buff [128]; /* Note the address is taken. Hence, static. */
2680 int result = 0; /* The accum number. */
2682 skip_whitespace (p);
2684 *str = p; /* Advance caller's string pointer too. */
2689 *--p = 0; /* Aap nul into input buffer at non-alnum. */
2691 if (! ( streq (*str, "acc0") || streq (*str, "ACC0")))
2693 sprintf (buff, _("acc0 expected, not '%.100s'"), *str);
2698 *p = c; /* Unzap. */
2699 *str = p; /* Caller's string pointer to after match. */
2703 /* Expects **str -> after a comma. May be leading blanks.
2704 Advances *str, recognizing a load mode, and setting inst.instruction.
2705 Returns rn, or else FAIL (in which case may set inst.error
2706 and not advance str)
2708 Note: doesn't know Rd, so no err checks that require such knowledge. */
2711 ld_mode_required_here (string)
2714 char * str = * string;
2718 skip_whitespace (str);
2724 skip_whitespace (str);
2726 if ((rn = reg_required_here (& str, 16)) == FAIL)
2729 skip_whitespace (str);
2735 if (skip_past_comma (& str) == SUCCESS)
2737 /* [Rn],... (post inc) */
2738 if (ldst_extend (& str, 1) == FAIL)
2743 skip_whitespace (str);
2748 inst.instruction |= WRITE_BACK;
2751 inst.instruction |= INDEX_UP | HWOFFSET_IMM;
2757 if (skip_past_comma (& str) == FAIL)
2759 inst.error = _("pre-indexed expression expected");
2765 if (ldst_extend (& str, 1) == FAIL)
2768 skip_whitespace (str);
2770 if (* str ++ != ']')
2772 inst.error = _("missing ]");
2776 skip_whitespace (str);
2781 inst.instruction |= WRITE_BACK;
2785 else if (* str == '=') /* ldr's "r,=label" syntax */
2786 /* We should never reach here, because <text> = <expression> is
2787 caught gas/read.c read_a_source_file() as a .set operation. */
2789 else /* PC +- 8 bit immediate offset. */
2791 if (my_get_expression (& inst.reloc.exp, & str))
2794 inst.instruction |= HWOFFSET_IMM; /* The I bit. */
2795 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
2796 inst.reloc.exp.X_add_number -= 8; /* PC rel adjust. */
2797 inst.reloc.pc_rel = 1;
2798 inst.instruction |= (REG_PC << 16);
2804 inst.instruction |= (pre_inc ? PRE_INDEX : 0);
2810 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
2811 SMLAxy{cond} Rd,Rm,Rs,Rn
2812 SMLAWy{cond} Rd,Rm,Rs,Rn
2813 Error if any register is R15. */
2816 do_smla (str, flags)
2818 unsigned long flags;
2822 skip_whitespace (str);
2824 if ((rd = reg_required_here (& str, 16)) == FAIL
2825 || skip_past_comma (& str) == FAIL
2826 || (rm = reg_required_here (& str, 0)) == FAIL
2827 || skip_past_comma (& str) == FAIL
2828 || (rs = reg_required_here (& str, 8)) == FAIL
2829 || skip_past_comma (& str) == FAIL
2830 || (rn = reg_required_here (& str, 12)) == FAIL)
2831 inst.error = BAD_ARGS;
2833 else if (rd == REG_PC || rm == REG_PC || rs == REG_PC || rn == REG_PC)
2834 inst.error = BAD_PC;
2837 inst.error = BAD_FLAGS;
2843 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
2844 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
2845 Error if any register is R15.
2846 Warning if Rdlo == Rdhi. */
2849 do_smlal (str, flags)
2851 unsigned long flags;
2853 int rdlo, rdhi, rm, rs;
2855 skip_whitespace (str);
2857 if ((rdlo = reg_required_here (& str, 12)) == FAIL
2858 || skip_past_comma (& str) == FAIL
2859 || (rdhi = reg_required_here (& str, 16)) == FAIL
2860 || skip_past_comma (& str) == FAIL
2861 || (rm = reg_required_here (& str, 0)) == FAIL
2862 || skip_past_comma (& str) == FAIL
2863 || (rs = reg_required_here (& str, 8)) == FAIL)
2865 inst.error = BAD_ARGS;
2869 if (rdlo == REG_PC || rdhi == REG_PC || rm == REG_PC || rs == REG_PC)
2871 inst.error = BAD_PC;
2876 as_tsktsk (_("rdhi and rdlo must be different"));
2879 inst.error = BAD_FLAGS;
2884 /* ARM V5E (El Segundo) signed-multiply (argument parse)
2885 SMULxy{cond} Rd,Rm,Rs
2886 Error if any register is R15. */
2889 do_smul (str, flags)
2891 unsigned long flags;
2895 skip_whitespace (str);
2897 if ((rd = reg_required_here (& str, 16)) == FAIL
2898 || skip_past_comma (& str) == FAIL
2899 || (rm = reg_required_here (& str, 0)) == FAIL
2900 || skip_past_comma (& str) == FAIL
2901 || (rs = reg_required_here (& str, 8)) == FAIL)
2902 inst.error = BAD_ARGS;
2904 else if (rd == REG_PC || rm == REG_PC || rs == REG_PC)
2905 inst.error = BAD_PC;
2908 inst.error = BAD_FLAGS;
2914 /* ARM V5E (El Segundo) saturating-add/subtract (argument parse)
2915 Q[D]{ADD,SUB}{cond} Rd,Rm,Rn
2916 Error if any register is R15. */
2919 do_qadd (str, flags)
2921 unsigned long flags;
2925 skip_whitespace (str);
2927 if ((rd = reg_required_here (& str, 12)) == FAIL
2928 || skip_past_comma (& str) == FAIL
2929 || (rm = reg_required_here (& str, 0)) == FAIL
2930 || skip_past_comma (& str) == FAIL
2931 || (rn = reg_required_here (& str, 16)) == FAIL)
2932 inst.error = BAD_ARGS;
2934 else if (rd == REG_PC || rm == REG_PC || rn == REG_PC)
2935 inst.error = BAD_PC;
2938 inst.error = BAD_FLAGS;
2944 /* ARM V5E (el Segundo)
2945 MCRRcc <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
2946 MRRCcc <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
2948 These are equivalent to the XScale instructions MAR and MRA,
2949 respectively, when coproc == 0, opcode == 0, and CRm == 0.
2951 Result unpredicatable if Rd or Rn is R15. */
2954 do_co_reg2c (str, flags)
2956 unsigned long flags;
2960 skip_whitespace (str);
2962 if (co_proc_number (& str) == FAIL)
2965 inst.error = BAD_ARGS;
2969 if (skip_past_comma (& str) == FAIL
2970 || cp_opc_expr (& str, 4, 4) == FAIL)
2973 inst.error = BAD_ARGS;
2977 if (skip_past_comma (& str) == FAIL
2978 || (rd = reg_required_here (& str, 12)) == FAIL)
2981 inst.error = BAD_ARGS;
2985 if (skip_past_comma (& str) == FAIL
2986 || (rn = reg_required_here (& str, 16)) == FAIL)
2989 inst.error = BAD_ARGS;
2993 /* Unpredictable result if rd or rn is R15. */
2994 if (rd == REG_PC || rn == REG_PC)
2996 (_("Warning: Instruction unpredictable when using r15"));
2998 if (skip_past_comma (& str) == FAIL
2999 || cp_reg_required_here (& str, 0) == FAIL)
3002 inst.error = BAD_ARGS;
3007 inst.error = BAD_COND;
3012 /* ARM V5 count-leading-zeroes instruction (argument parse)
3013 CLZ{<cond>} <Rd>, <Rm>
3014 Condition defaults to COND_ALWAYS.
3015 Error if Rd or Rm are R15. */
3020 unsigned long flags;
3030 skip_whitespace (str);
3032 if (((rd = reg_required_here (& str, 12)) == FAIL)
3033 || (skip_past_comma (& str) == FAIL)
3034 || ((rm = reg_required_here (& str, 0)) == FAIL))
3035 inst.error = BAD_ARGS;
3037 else if (rd == REG_PC || rm == REG_PC )
3038 inst.error = BAD_PC;
3044 /* ARM V5 (argument parse)
3045 LDC2{L} <coproc>, <CRd>, <addressing mode>
3046 STC2{L} <coproc>, <CRd>, <addressing mode>
3047 Instruction is not conditional, and has 0xf in the codition field.
3048 Otherwise, it's the same as LDC/STC. */
3051 do_lstc2 (str, flags)
3053 unsigned long flags;
3056 inst.error = BAD_COND;
3058 skip_whitespace (str);
3060 if (co_proc_number (& str) == FAIL)
3063 inst.error = BAD_ARGS;
3065 else if (skip_past_comma (& str) == FAIL
3066 || cp_reg_required_here (& str, 12) == FAIL)
3069 inst.error = BAD_ARGS;
3071 else if (skip_past_comma (& str) == FAIL
3072 || cp_address_required_here (& str) == FAIL)
3075 inst.error = BAD_ARGS;
3081 /* ARM V5 (argument parse)
3082 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>, <opcode_2>
3083 Instruction is not conditional, and has 0xf in the condition field.
3084 Otherwise, it's the same as CDP. */
3087 do_cdp2 (str, flags)
3089 unsigned long flags;
3091 skip_whitespace (str);
3093 if (co_proc_number (& str) == FAIL)
3096 inst.error = BAD_ARGS;
3100 if (skip_past_comma (& str) == FAIL
3101 || cp_opc_expr (& str, 20,4) == FAIL)
3104 inst.error = BAD_ARGS;
3108 if (skip_past_comma (& str) == FAIL
3109 || cp_reg_required_here (& str, 12) == FAIL)
3112 inst.error = BAD_ARGS;
3116 if (skip_past_comma (& str) == FAIL
3117 || cp_reg_required_here (& str, 16) == FAIL)
3120 inst.error = BAD_ARGS;
3124 if (skip_past_comma (& str) == FAIL
3125 || cp_reg_required_here (& str, 0) == FAIL)
3128 inst.error = BAD_ARGS;
3132 if (skip_past_comma (& str) == SUCCESS)
3134 if (cp_opc_expr (& str, 5, 3) == FAIL)
3137 inst.error = BAD_ARGS;
3143 inst.error = BAD_FLAGS;
3148 /* ARM V5 (argument parse)
3149 MCR2 <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>, <opcode_2>
3150 MRC2 <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>, <opcode_2>
3151 Instruction is not conditional, and has 0xf in the condition field.
3152 Otherwise, it's the same as MCR/MRC. */
3155 do_co_reg2 (str, flags)
3157 unsigned long flags;
3159 skip_whitespace (str);
3161 if (co_proc_number (& str) == FAIL)
3164 inst.error = BAD_ARGS;
3168 if (skip_past_comma (& str) == FAIL
3169 || cp_opc_expr (& str, 21, 3) == FAIL)
3172 inst.error = BAD_ARGS;
3176 if (skip_past_comma (& str) == FAIL
3177 || reg_required_here (& str, 12) == FAIL)
3180 inst.error = BAD_ARGS;
3184 if (skip_past_comma (& str) == FAIL
3185 || cp_reg_required_here (& str, 16) == FAIL)
3188 inst.error = BAD_ARGS;
3192 if (skip_past_comma (& str) == FAIL
3193 || cp_reg_required_here (& str, 0) == FAIL)
3196 inst.error = BAD_ARGS;
3200 if (skip_past_comma (& str) == SUCCESS)
3202 if (cp_opc_expr (& str, 5, 3) == FAIL)
3205 inst.error = BAD_ARGS;
3211 inst.error = BAD_COND;
3216 /* THUMB V5 breakpoint instruction (argument parse)
3224 unsigned long number;
3226 skip_whitespace (str);
3228 /* Allow optional leading '#'. */
3229 if (is_immediate_prefix (*str))
3232 memset (& expr, '\0', sizeof (expr));
3233 if (my_get_expression (& expr, & str) || (expr.X_op != O_constant))
3235 inst.error = _("bad or missing expression");
3239 number = expr.X_add_number;
3241 /* Check it fits an 8 bit unsigned. */
3242 if (number != (number & 0xff))
3244 inst.error = _("immediate value out of range");
3248 inst.instruction |= number;
3253 /* ARM V5 branch-link-exchange (argument parse) for BLX(1) only.
3254 Expects inst.instruction is set for BLX(1).
3255 Note: this is cloned from do_branch, and the reloc changed to be a
3256 new one that can cope with setting one extra bit (the H bit). */
3259 do_branch25 (str, flags)
3261 unsigned long flags ATTRIBUTE_UNUSED;
3263 if (my_get_expression (& inst.reloc.exp, & str))
3270 /* ScottB: February 5, 1998 */
3271 /* Check to see of PLT32 reloc required for the instruction. */
3273 /* arm_parse_reloc() works on input_line_pointer.
3274 We actually want to parse the operands to the branch instruction
3275 passed in 'str'. Save the input pointer and restore it later. */
3276 save_in = input_line_pointer;
3277 input_line_pointer = str;
3279 if (inst.reloc.exp.X_op == O_symbol
3281 && arm_parse_reloc () == BFD_RELOC_ARM_PLT32)
3283 inst.reloc.type = BFD_RELOC_ARM_PLT32;
3284 inst.reloc.pc_rel = 0;
3285 /* Modify str to point to after parsed operands, otherwise
3286 end_of_line() will complain about the (PLT) left in str. */
3287 str = input_line_pointer;
3291 inst.reloc.type = BFD_RELOC_ARM_PCREL_BLX;
3292 inst.reloc.pc_rel = 1;
3295 input_line_pointer = save_in;
3298 inst.reloc.type = BFD_RELOC_ARM_PCREL_BLX;
3299 inst.reloc.pc_rel = 1;
3300 #endif /* OBJ_ELF */
3305 /* ARM V5 branch-link-exchange instruction (argument parse)
3306 BLX <target_addr> ie BLX(1)
3307 BLX{<condition>} <Rm> ie BLX(2)
3308 Unfortunately, there are two different opcodes for this mnemonic.
3309 So, the insns[].value is not used, and the code here zaps values
3310 into inst.instruction.
3311 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
3316 unsigned long flags;
3327 skip_whitespace (mystr);
3328 rm = reg_required_here (& mystr, 0);
3330 /* The above may set inst.error. Ignore his opinion. */
3335 /* Arg is a register.
3336 Use the condition code our caller put in inst.instruction.
3337 Pass ourselves off as a BX with a funny opcode. */
3338 inst.instruction |= 0x012fff30;
3343 /* This must be is BLX <target address>, no condition allowed. */
3344 if (inst.instruction != COND_ALWAYS)
3346 inst.error = BAD_COND;
3350 inst.instruction = 0xfafffffe;
3352 /* Process like a B/BL, but with a different reloc.
3353 Note that B/BL expecte fffffe, not 0, offset in the opcode table. */
3354 do_branch25 (str, flags);
3358 /* ARM V5 Thumb BLX (argument parse)
3359 BLX <target_addr> which is BLX(1)
3360 BLX <Rm> which is BLX(2)
3361 Unfortunately, there are two different opcodes for this mnemonic.
3362 So, the tinsns[].value is not used, and the code here zaps values
3363 into inst.instruction. */
3372 skip_whitespace (mystr);
3373 inst.instruction = 0x4780;
3375 /* Note that this call is to the ARM register recognizer. BLX(2)
3376 uses the ARM register space, not the Thumb one, so a call to
3377 thumb_reg() would be wrong. */
3378 rm = reg_required_here (& mystr, 3);
3383 /* It's BLX(2). The .instruction was zapped with rm & is final. */
3388 /* No ARM register. This must be BLX(1). Change the .instruction. */
3389 inst.instruction = 0xf7ffeffe;
3392 if (my_get_expression (& inst.reloc.exp, & mystr))
3395 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
3396 inst.reloc.pc_rel = 1;
3399 end_of_line (mystr);
3402 /* ARM V5 breakpoint instruction (argument parse)
3403 BKPT <16 bit unsigned immediate>
3404 Instruction is not conditional.
3405 The bit pattern given in insns[] has the COND_ALWAYS condition,
3406 and it is an error if the caller tried to override that.
3407 Note "flags" is nonzero if a flag was supplied (which is an error). */
3410 do_bkpt (str, flags)
3412 unsigned long flags;
3415 unsigned long number;
3417 skip_whitespace (str);
3419 /* Allow optional leading '#'. */
3420 if (is_immediate_prefix (* str))
3423 memset (& expr, '\0', sizeof (expr));
3425 if (my_get_expression (& expr, & str) || (expr.X_op != O_constant))
3427 inst.error = _("bad or missing expression");
3431 number = expr.X_add_number;
3433 /* Check it fits a 16 bit unsigned. */
3434 if (number != (number & 0xffff))
3436 inst.error = _("immediate value out of range");
3440 /* Top 12 of 16 bits to bits 19:8. */
3441 inst.instruction |= (number & 0xfff0) << 4;
3443 /* Bottom 4 of 16 bits to bits 3:0. */
3444 inst.instruction |= number & 0xf;
3449 inst.error = BAD_FLAGS;
3452 /* Xscale multiply-accumulate (argument parse)
3455 MIAxycc acc0,Rm,Rs. */
3460 unsigned long flags;
3468 else if (accum0_required_here (& str) == FAIL)
3469 inst.error = ERR_NO_ACCUM;
3471 else if (skip_past_comma (& str) == FAIL
3472 || (rm = reg_required_here (& str, 0)) == FAIL)
3473 inst.error = BAD_ARGS;
3475 else if (skip_past_comma (& str) == FAIL
3476 || (rs = reg_required_here (& str, 12)) == FAIL)
3477 inst.error = BAD_ARGS;
3479 /* inst.instruction has now been zapped with both rm and rs. */
3480 else if (rm == REG_PC || rs == REG_PC)
3481 inst.error = BAD_PC; /* Undefined result if rm or rs is R15. */
3487 /* Xscale move-accumulator-register (argument parse)
3489 MARcc acc0,RdLo,RdHi. */
3494 unsigned long flags;
3501 else if (accum0_required_here (& str) == FAIL)
3502 inst.error = ERR_NO_ACCUM;
3504 else if (skip_past_comma (& str) == FAIL
3505 || (rdlo = reg_required_here (& str, 12)) == FAIL)
3506 inst.error = BAD_ARGS;
3508 else if (skip_past_comma (& str) == FAIL
3509 || (rdhi = reg_required_here (& str, 16)) == FAIL)
3510 inst.error = BAD_ARGS;
3512 /* inst.instruction has now been zapped with both rdlo and rdhi. */
3513 else if (rdlo == REG_PC || rdhi == REG_PC)
3514 inst.error = BAD_PC; /* Undefined result if rdlo or rdhi is R15. */
3520 /* Xscale move-register-accumulator (argument parse)
3522 MRAcc RdLo,RdHi,acc0. */
3527 unsigned long flags;
3538 skip_whitespace (str);
3540 if ((rdlo = reg_required_here (& str, 12)) == FAIL)
3541 inst.error = BAD_ARGS;
3543 else if (skip_past_comma (& str) == FAIL
3544 || (rdhi = reg_required_here (& str, 16)) == FAIL)
3545 inst.error = BAD_ARGS;
3547 else if (skip_past_comma (& str) == FAIL
3548 || accum0_required_here (& str) == FAIL)
3549 inst.error = ERR_NO_ACCUM;
3551 /* inst.instruction has now been zapped with both rdlo and rdhi. */
3552 else if (rdlo == rdhi)
3553 inst.error = BAD_ARGS; /* Undefined result if 2 writes to same reg. */
3555 else if (rdlo == REG_PC || rdhi == REG_PC)
3556 inst.error = BAD_PC; /* Undefined result if rdlo or rdhi is R15. */
3561 /* Xscale: Preload-Cache
3565 Syntactically, like LDR with B=1, W=0, L=1. */
3570 unsigned long flags;
3580 skip_whitespace (str);
3584 inst.error = _("'[' expected after PLD mnemonic");
3589 skip_whitespace (str);
3591 if ((rd = reg_required_here (& str, 16)) == FAIL)
3594 skip_whitespace (str);
3600 skip_whitespace (str);
3602 if (skip_past_comma (& str) == SUCCESS)
3604 if (ldst_extend (& str, 0) == FAIL)
3607 else if (* str == '!') /* [Rn]! */
3609 inst.error = _("writeback used in preload instruction");
3613 inst.instruction |= INDEX_UP | PRE_INDEX;
3615 else /* [Rn, ...] */
3617 if (skip_past_comma (& str) == FAIL)
3619 inst.error = _("pre-indexed expression expected");
3623 if (ldst_extend (& str, 0) == FAIL)
3626 skip_whitespace (str);
3630 inst.error = _("missing ]");
3635 skip_whitespace (str);
3637 if (* str == '!') /* [Rn]! */
3639 inst.error = _("writeback used in preload instruction");
3643 inst.instruction |= PRE_INDEX;
3649 /* Xscale load-consecutive (argument parse)
3656 do_ldrd (str, flags)
3658 unsigned long flags;
3663 if (flags != DOUBLE_LOAD_FLAG)
3665 /* Change instruction pattern to normal ldr/str. */
3666 if (inst.instruction & 0x20)
3667 inst.instruction = (inst.instruction & COND_MASK) | 0x04000000; /* str */
3669 inst.instruction = (inst.instruction & COND_MASK) | 0x04100000; /* ldr */
3671 /* Perform a normal load/store instruction parse. */
3672 do_ldst (str, flags);
3677 if ((cpu_variant & ARM_EXT_XSCALE) != ARM_EXT_XSCALE)
3679 static char buff[128];
3682 while (ISSPACE (*str))
3686 /* Deny all knowledge. */
3687 sprintf (buff, _("bad instruction '%.100s'"), str);
3692 skip_whitespace (str);
3694 if ((rd = reg_required_here (& str, 12)) == FAIL)
3696 inst.error = BAD_ARGS;
3700 if (skip_past_comma (& str) == FAIL
3701 || (rn = ld_mode_required_here (& str)) == FAIL)
3704 inst.error = BAD_ARGS;
3708 /* inst.instruction has now been zapped with Rd and the addressing mode. */
3709 if (rd & 1) /* Unpredictable result if Rd is odd. */
3711 inst.error = _("Destination register must be even");
3715 if (rd == REG_LR || rd == 12)
3717 inst.error = _("r12 or r14 not allowed here");
3721 if (((rd == rn) || (rd + 1 == rn))
3723 ((inst.instruction & WRITE_BACK)
3724 || (!(inst.instruction & PRE_INDEX))))
3725 as_warn (_("pre/post-indexing used when modified address register is destination"));
3730 /* Returns the index into fp_values of a floating point number,
3731 or -1 if not in the table. */
3734 my_get_float_expression (str)
3737 LITTLENUM_TYPE words[MAX_LITTLENUMS];
3743 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
3745 /* Look for a raw floating point number. */
3746 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
3747 && is_end_of_line[(unsigned char) *save_in])
3749 for (i = 0; i < NUM_FLOAT_VALS; i++)
3751 for (j = 0; j < MAX_LITTLENUMS; j++)
3753 if (words[j] != fp_values[i][j])
3757 if (j == MAX_LITTLENUMS)
3765 /* Try and parse a more complex expression, this will probably fail
3766 unless the code uses a floating point prefix (eg "0f"). */
3767 save_in = input_line_pointer;
3768 input_line_pointer = *str;
3769 if (expression (&exp) == absolute_section
3770 && exp.X_op == O_big
3771 && exp.X_add_number < 0)
3773 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
3775 if (gen_to_words (words, 5, (long) 15) == 0)
3777 for (i = 0; i < NUM_FLOAT_VALS; i++)
3779 for (j = 0; j < MAX_LITTLENUMS; j++)
3781 if (words[j] != fp_values[i][j])
3785 if (j == MAX_LITTLENUMS)
3787 *str = input_line_pointer;
3788 input_line_pointer = save_in;
3795 *str = input_line_pointer;
3796 input_line_pointer = save_in;
3800 /* Return true if anything in the expression is a bignum. */
3803 walk_no_bignums (sp)
3806 if (symbol_get_value_expression (sp)->X_op == O_big)
3809 if (symbol_get_value_expression (sp)->X_add_symbol)
3811 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
3812 || (symbol_get_value_expression (sp)->X_op_symbol
3813 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3820 my_get_expression (ep, str)
3827 save_in = input_line_pointer;
3828 input_line_pointer = *str;
3829 seg = expression (ep);
3832 if (seg != absolute_section
3833 && seg != text_section
3834 && seg != data_section
3835 && seg != bss_section
3836 && seg != undefined_section)
3838 inst.error = _("bad_segment");
3839 *str = input_line_pointer;
3840 input_line_pointer = save_in;
3845 /* Get rid of any bignums now, so that we don't generate an error for which
3846 we can't establish a line number later on. Big numbers are never valid
3847 in instructions, which is where this routine is always called. */
3848 if (ep->X_op == O_big
3849 || (ep->X_add_symbol
3850 && (walk_no_bignums (ep->X_add_symbol)
3852 && walk_no_bignums (ep->X_op_symbol)))))
3854 inst.error = _("Invalid constant");
3855 *str = input_line_pointer;
3856 input_line_pointer = save_in;
3860 *str = input_line_pointer;
3861 input_line_pointer = save_in;
3865 /* UNRESTRICT should be one if <shift> <register> is permitted for this
3869 decode_shift (str, unrestrict)
3873 const struct asm_shift_name * shift;
3877 skip_whitespace (* str);
3879 for (p = * str; ISALPHA (* p); p ++)
3884 inst.error = _("Shift expression expected");
3890 shift = (const struct asm_shift_name *) hash_find (arm_shift_hsh, * str);
3895 inst.error = _("Shift expression expected");
3899 assert (shift->properties->index == shift_properties[shift->properties->index].index);
3901 if (shift->properties->index == SHIFT_RRX)
3904 inst.instruction |= shift->properties->bit_field;
3908 skip_whitespace (p);
3910 if (unrestrict && reg_required_here (& p, 8) != FAIL)
3912 inst.instruction |= shift->properties->bit_field | SHIFT_BY_REG;
3916 else if (! is_immediate_prefix (* p))
3918 inst.error = (unrestrict
3919 ? _("shift requires register or #expression")
3920 : _("shift requires #expression"));
3928 if (my_get_expression (& inst.reloc.exp, & p))
3931 /* Validate some simple #expressions. */
3932 if (inst.reloc.exp.X_op == O_constant)
3934 unsigned num = inst.reloc.exp.X_add_number;
3936 /* Reject operations greater than 32. */
3938 /* Reject a shift of 0 unless the mode allows it. */
3939 || (num == 0 && shift->properties->allows_0 == 0)
3940 /* Reject a shift of 32 unless the mode allows it. */
3941 || (num == 32 && shift->properties->allows_32 == 0)
3944 /* As a special case we allow a shift of zero for
3945 modes that do not support it to be recoded as an
3946 logical shift left of zero (ie nothing). We warn
3947 about this though. */
3950 as_warn (_("Shift of 0 ignored."));
3951 shift = & shift_names[0];
3952 assert (shift->properties->index == SHIFT_LSL);
3956 inst.error = _("Invalid immediate shift");
3961 /* Shifts of 32 are encoded as 0, for those shifts that
3966 inst.instruction |= (num << 7) | shift->properties->bit_field;
3970 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
3971 inst.reloc.pc_rel = 0;
3972 inst.instruction |= shift->properties->bit_field;
3979 /* Do those data_ops which can take a negative immediate constant
3980 by altering the instuction. A bit of a hack really.
3984 by inverting the second operand, and
3987 by negating the second operand. */
3990 negate_data_op (instruction, value)
3991 unsigned long * instruction;
3992 unsigned long value;
3995 unsigned long negated, inverted;
3997 negated = validate_immediate (-value);
3998 inverted = validate_immediate (~value);
4000 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
4003 /* First negates. */
4004 case OPCODE_SUB: /* ADD <-> SUB */
4005 new_inst = OPCODE_ADD;
4010 new_inst = OPCODE_SUB;
4014 case OPCODE_CMP: /* CMP <-> CMN */
4015 new_inst = OPCODE_CMN;
4020 new_inst = OPCODE_CMP;
4024 /* Now Inverted ops. */
4025 case OPCODE_MOV: /* MOV <-> MVN */
4026 new_inst = OPCODE_MVN;
4031 new_inst = OPCODE_MOV;
4035 case OPCODE_AND: /* AND <-> BIC */
4036 new_inst = OPCODE_BIC;
4041 new_inst = OPCODE_AND;
4045 case OPCODE_ADC: /* ADC <-> SBC */
4046 new_inst = OPCODE_SBC;
4051 new_inst = OPCODE_ADC;
4055 /* We cannot do anything. */
4060 if (value == (unsigned) FAIL)
4063 *instruction &= OPCODE_MASK;
4064 *instruction |= new_inst << DATA_OP_SHIFT;
4075 skip_whitespace (* str);
4077 if (reg_required_here (str, 0) != FAIL)
4079 if (skip_past_comma (str) == SUCCESS)
4080 /* Shift operation on register. */
4081 return decode_shift (str, NO_SHIFT_RESTRICT);
4087 /* Immediate expression. */
4088 if (is_immediate_prefix (**str))
4093 if (my_get_expression (&inst.reloc.exp, str))
4096 if (inst.reloc.exp.X_add_symbol)
4098 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4099 inst.reloc.pc_rel = 0;
4103 if (skip_past_comma (str) == SUCCESS)
4105 /* #x, y -- ie explicit rotation by Y. */
4106 if (my_get_expression (&expr, str))
4109 if (expr.X_op != O_constant)
4111 inst.error = _("Constant expression expected");
4115 /* Rotate must be a multiple of 2. */
4116 if (((unsigned) expr.X_add_number) > 30
4117 || (expr.X_add_number & 1) != 0
4118 || ((unsigned) inst.reloc.exp.X_add_number) > 255)
4120 inst.error = _("Invalid constant");
4123 inst.instruction |= INST_IMMEDIATE;
4124 inst.instruction |= inst.reloc.exp.X_add_number;
4125 inst.instruction |= expr.X_add_number << 7;
4129 /* Implicit rotation, select a suitable one. */
4130 value = validate_immediate (inst.reloc.exp.X_add_number);
4134 /* Can't be done. Perhaps the code reads something like
4135 "add Rd, Rn, #-n", where "sub Rd, Rn, #n" would be OK. */
4136 if ((value = negate_data_op (&inst.instruction,
4137 inst.reloc.exp.X_add_number))
4140 inst.error = _("Invalid constant");
4145 inst.instruction |= value;
4148 inst.instruction |= INST_IMMEDIATE;
4153 inst.error = _("Register or shift expression expected");
4162 skip_whitespace (* str);
4164 if (fp_reg_required_here (str, 0) != FAIL)
4168 /* Immediate expression. */
4169 if (*((*str)++) == '#')
4175 skip_whitespace (* str);
4177 /* First try and match exact strings, this is to guarantee
4178 that some formats will work even for cross assembly. */
4180 for (i = 0; fp_const[i]; i++)
4182 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4186 *str += strlen (fp_const[i]);
4187 if (is_end_of_line[(unsigned char) **str])
4189 inst.instruction |= i + 8;
4196 /* Just because we didn't get a match doesn't mean that the
4197 constant isn't valid, just that it is in a format that we
4198 don't automatically recognize. Try parsing it with
4199 the standard expression routines. */
4200 if ((i = my_get_float_expression (str)) >= 0)
4202 inst.instruction |= i + 8;
4206 inst.error = _("Invalid floating point immediate expression");
4210 _("Floating point register or immediate expression expected");
4216 do_arit (str, flags)
4218 unsigned long flags;
4220 skip_whitespace (str);
4222 if (reg_required_here (&str, 12) == FAIL
4223 || skip_past_comma (&str) == FAIL
4224 || reg_required_here (&str, 16) == FAIL
4225 || skip_past_comma (&str) == FAIL
4226 || data_op2 (&str) == FAIL)
4229 inst.error = BAD_ARGS;
4233 inst.instruction |= flags;
4241 unsigned long flags;
4243 skip_whitespace (str);
4245 if (reg_required_here (&str, 12) == FAIL
4246 || skip_past_comma (&str) == FAIL
4247 || my_get_expression (&inst.reloc.exp, &str))
4250 inst.error = BAD_ARGS;
4254 if (flags & 0x00400000)
4256 /* This is a pseudo-op of the form "adrl rd, label" to be converted
4257 into a relative address of the form:
4258 add rd, pc, #low(label-.-8)"
4259 add rd, rd, #high(label-.-8)" */
4260 /* Frag hacking will turn this into a sub instruction if the offset turns
4261 out to be negative. */
4262 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
4263 inst.reloc.exp.X_add_number -= 8; /* PC relative adjust */
4264 inst.reloc.pc_rel = 1;
4265 inst.instruction |= flags & ~0x00400000;
4266 inst.size = INSN_SIZE * 2;
4270 /* This is a pseudo-op of the form "adr rd, label" to be converted
4271 into a relative address of the form "add rd, pc, #label-.-8". */
4272 /* Frag hacking will turn this into a sub instruction if the offset turns
4273 out to be negative. */
4274 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4275 inst.reloc.exp.X_add_number -= 8; /* PC relative adjust. */
4276 inst.reloc.pc_rel = 1;
4277 inst.instruction |= flags;
4286 unsigned long flags;
4288 skip_whitespace (str);
4290 if (reg_required_here (&str, 16) == FAIL)
4293 inst.error = BAD_ARGS;
4297 if (skip_past_comma (&str) == FAIL
4298 || data_op2 (&str) == FAIL)
4301 inst.error = BAD_ARGS;
4305 inst.instruction |= flags;
4306 if ((flags & 0x0000f000) == 0)
4307 inst.instruction |= CONDS_BIT;
4316 unsigned long flags;
4318 skip_whitespace (str);
4320 if (reg_required_here (&str, 12) == FAIL)
4323 inst.error = BAD_ARGS;
4327 if (skip_past_comma (&str) == FAIL
4328 || data_op2 (&str) == FAIL)
4331 inst.error = BAD_ARGS;
4335 inst.instruction |= flags;
4341 ldst_extend (str, hwse)
4352 if (my_get_expression (& inst.reloc.exp, str))
4355 if (inst.reloc.exp.X_op == O_constant)
4357 int value = inst.reloc.exp.X_add_number;
4359 if ((hwse && (value < -255 || value > 255))
4360 || (value < -4095 || value > 4095))
4362 inst.error = _("address offset too large");
4372 /* Halfword and signextension instructions have the
4373 immediate value split across bits 11..8 and bits 3..0. */
4375 inst.instruction |= (add | HWOFFSET_IMM
4376 | ((value >> 4) << 8) | (value & 0xF));
4378 inst.instruction |= add | value;
4384 inst.instruction |= HWOFFSET_IMM;
4385 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
4388 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
4389 inst.reloc.pc_rel = 0;
4402 if (reg_required_here (str, 0) == FAIL)
4406 inst.instruction |= add;
4409 inst.instruction |= add | OFFSET_REG;
4410 if (skip_past_comma (str) == SUCCESS)
4411 return decode_shift (str, SHIFT_RESTRICT);
4419 do_ldst (str, flags)
4421 unsigned long flags;
4428 /* This is not ideal, but it is the simplest way of dealing with the
4429 ARM7T halfword instructions (since they use a different
4430 encoding, but the same mnemonic): */
4431 halfword = (flags & 0x80000000) != 0;
4434 /* This is actually a load/store of a halfword, or a
4435 signed-extension load. */
4436 if ((cpu_variant & ARM_EXT_HALFWORD) == 0)
4439 = _("Processor does not support halfwords or signed bytes");
4443 inst.instruction = ((inst.instruction & COND_MASK)
4444 | (flags & ~COND_MASK));
4449 skip_whitespace (str);
4451 if ((conflict_reg = reg_required_here (& str, 12)) == FAIL)
4454 inst.error = BAD_ARGS;
4458 if (skip_past_comma (& str) == FAIL)
4460 inst.error = _("Address expected");
4470 skip_whitespace (str);
4472 if ((reg = reg_required_here (&str, 16)) == FAIL)
4475 /* Conflicts can occur on stores as well as loads. */
4476 conflict_reg = (conflict_reg == reg);
4478 skip_whitespace (str);
4484 if (skip_past_comma (&str) == SUCCESS)
4486 /* [Rn],... (post inc) */
4487 if (ldst_extend (&str, halfword) == FAIL)
4491 if (flags & TRANS_BIT)
4492 as_warn (_("Rn and Rd must be different in %s"),
4493 ((inst.instruction & LOAD_BIT)
4494 ? "LDRT" : "STRT"));
4496 as_warn (_("%s register same as write-back base"),
4497 ((inst.instruction & LOAD_BIT)
4498 ? _("destination") : _("source")));
4505 inst.instruction |= HWOFFSET_IMM;
4507 skip_whitespace (str);
4512 as_warn (_("%s register same as write-back base"),
4513 ((inst.instruction & LOAD_BIT)
4514 ? _("destination") : _("source")));
4516 inst.instruction |= WRITE_BACK;
4520 if (flags & TRANS_BIT)
4523 as_warn (_("Rn and Rd must be different in %s"),
4524 ((inst.instruction & LOAD_BIT)
4525 ? "LDRT" : "STRT"));
4534 if (skip_past_comma (&str) == FAIL)
4536 inst.error = _("pre-indexed expression expected");
4541 if (ldst_extend (&str, halfword) == FAIL)
4544 skip_whitespace (str);
4548 inst.error = _("missing ]");
4552 skip_whitespace (str);
4557 as_warn (_("%s register same as write-back base"),
4558 ((inst.instruction & LOAD_BIT)
4559 ? _("destination") : _("source")));
4561 inst.instruction |= WRITE_BACK;
4565 else if (*str == '=')
4567 /* Parse an "ldr Rd, =expr" instruction; this is another pseudo op. */
4570 skip_whitespace (str);
4572 if (my_get_expression (&inst.reloc.exp, &str))
4575 if (inst.reloc.exp.X_op != O_constant
4576 && inst.reloc.exp.X_op != O_symbol)
4578 inst.error = _("Constant expression expected");
4582 if (inst.reloc.exp.X_op == O_constant)
4584 value = validate_immediate (inst.reloc.exp.X_add_number);
4588 /* This can be done with a mov instruction. */
4589 inst.instruction &= LITERAL_MASK;
4590 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
4591 inst.instruction |= (flags & COND_MASK) | (value & 0xfff);
4596 value = validate_immediate (~ inst.reloc.exp.X_add_number);
4600 /* This can be done with a mvn instruction. */
4601 inst.instruction &= LITERAL_MASK;
4602 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
4603 inst.instruction |= (flags & COND_MASK) | (value & 0xfff);
4609 /* Insert into literal pool. */
4610 if (add_to_lit_pool () == FAIL)
4613 inst.error = _("literal pool insertion failed");
4617 /* Change the instruction exp to point to the pool. */
4620 inst.instruction |= HWOFFSET_IMM;
4621 inst.reloc.type = BFD_RELOC_ARM_HWLITERAL;
4624 inst.reloc.type = BFD_RELOC_ARM_LITERAL;
4626 inst.reloc.pc_rel = 1;
4627 inst.instruction |= (REG_PC << 16);
4632 if (my_get_expression (&inst.reloc.exp, &str))
4637 inst.instruction |= HWOFFSET_IMM;
4638 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
4641 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
4643 /* PC rel adjust. */
4644 inst.reloc.exp.X_add_number -= 8;
4646 inst.reloc.pc_rel = 1;
4647 inst.instruction |= (REG_PC << 16);
4651 if (pre_inc && (flags & TRANS_BIT))
4652 inst.error = _("Pre-increment instruction with translate");
4654 inst.instruction |= flags | (pre_inc ? PRE_INDEX : 0);
4663 char * str = * strp;
4667 /* We come back here if we get ranges concatenated by '+' or '|'. */
4682 skip_whitespace (str);
4684 if ((reg = reg_required_here (& str, -1)) == FAIL)
4693 inst.error = _("Bad range in register list");
4697 for (i = cur_reg + 1; i < reg; i++)
4699 if (range & (1 << i))
4701 (_("Warning: Duplicated register (r%d) in register list"),
4709 if (range & (1 << reg))
4710 as_tsktsk (_("Warning: Duplicated register (r%d) in register list"),
4712 else if (reg <= cur_reg)
4713 as_tsktsk (_("Warning: Register range not in ascending order"));
4718 while (skip_past_comma (&str) != FAIL
4719 || (in_range = 1, *str++ == '-'));
4721 skip_whitespace (str);
4725 inst.error = _("Missing `}'");
4733 if (my_get_expression (&expr, &str))
4736 if (expr.X_op == O_constant)
4738 if (expr.X_add_number
4739 != (expr.X_add_number & 0x0000ffff))
4741 inst.error = _("invalid register mask");
4745 if ((range & expr.X_add_number) != 0)
4747 int regno = range & expr.X_add_number;
4750 regno = (1 << regno) - 1;
4752 (_("Warning: Duplicated register (r%d) in register list"),
4756 range |= expr.X_add_number;
4760 if (inst.reloc.type != 0)
4762 inst.error = _("expression too complex");
4766 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
4767 inst.reloc.type = BFD_RELOC_ARM_MULTI;
4768 inst.reloc.pc_rel = 0;
4772 skip_whitespace (str);
4774 if (*str == '|' || *str == '+')
4780 while (another_range);
4787 do_ldmstm (str, flags)
4789 unsigned long flags;
4794 skip_whitespace (str);
4796 if ((base_reg = reg_required_here (&str, 16)) == FAIL)
4799 if (base_reg == REG_PC)
4801 inst.error = _("r15 not allowed as base register");
4805 skip_whitespace (str);
4809 flags |= WRITE_BACK;
4813 if (skip_past_comma (&str) == FAIL
4814 || (range = reg_list (&str)) == FAIL)
4817 inst.error = BAD_ARGS;
4824 flags |= LDM_TYPE_2_OR_3;
4827 inst.instruction |= flags | range;
4835 unsigned long flags;
4837 skip_whitespace (str);
4839 /* Allow optional leading '#'. */
4840 if (is_immediate_prefix (*str))
4843 if (my_get_expression (& inst.reloc.exp, & str))
4846 inst.reloc.type = BFD_RELOC_ARM_SWI;
4847 inst.reloc.pc_rel = 0;
4848 inst.instruction |= flags;
4856 do_swap (str, flags)
4858 unsigned long flags;
4862 skip_whitespace (str);
4864 if ((reg = reg_required_here (&str, 12)) == FAIL)
4869 inst.error = _("r15 not allowed in swap");
4873 if (skip_past_comma (&str) == FAIL
4874 || (reg = reg_required_here (&str, 0)) == FAIL)
4877 inst.error = BAD_ARGS;
4883 inst.error = _("r15 not allowed in swap");
4887 if (skip_past_comma (&str) == FAIL
4890 inst.error = BAD_ARGS;
4894 skip_whitespace (str);
4896 if ((reg = reg_required_here (&str, 16)) == FAIL)
4901 inst.error = BAD_PC;
4905 skip_whitespace (str);
4909 inst.error = _("missing ]");
4913 inst.instruction |= flags;
4919 do_branch (str, flags)
4921 unsigned long flags ATTRIBUTE_UNUSED;
4923 if (my_get_expression (&inst.reloc.exp, &str))
4930 /* ScottB: February 5, 1998 - Check to see of PLT32 reloc
4931 required for the instruction. */
4933 /* arm_parse_reloc () works on input_line_pointer.
4934 We actually want to parse the operands to the branch instruction
4935 passed in 'str'. Save the input pointer and restore it later. */
4936 save_in = input_line_pointer;
4937 input_line_pointer = str;
4938 if (inst.reloc.exp.X_op == O_symbol
4940 && arm_parse_reloc () == BFD_RELOC_ARM_PLT32)
4942 inst.reloc.type = BFD_RELOC_ARM_PLT32;
4943 inst.reloc.pc_rel = 0;
4944 /* Modify str to point to after parsed operands, otherwise
4945 end_of_line() will complain about the (PLT) left in str. */
4946 str = input_line_pointer;
4950 inst.reloc.type = BFD_RELOC_ARM_PCREL_BRANCH;
4951 inst.reloc.pc_rel = 1;
4953 input_line_pointer = save_in;
4956 inst.reloc.type = BFD_RELOC_ARM_PCREL_BRANCH;
4957 inst.reloc.pc_rel = 1;
4958 #endif /* OBJ_ELF */
4967 unsigned long flags ATTRIBUTE_UNUSED;
4971 skip_whitespace (str);
4973 if ((reg = reg_required_here (&str, 0)) == FAIL)
4975 inst.error = BAD_ARGS;
4979 /* Note - it is not illegal to do a "bx pc". Useless, but not illegal. */
4981 as_tsktsk (_("Use of r15 in bx in ARM mode is not really useful"));
4989 unsigned long flags ATTRIBUTE_UNUSED;
4991 /* Co-processor data operation.
4992 Format: CDP{cond} CP#,<expr>,CRd,CRn,CRm{,<expr>} */
4993 skip_whitespace (str);
4995 if (co_proc_number (&str) == FAIL)
4998 inst.error = BAD_ARGS;
5002 if (skip_past_comma (&str) == FAIL
5003 || cp_opc_expr (&str, 20,4) == FAIL)
5006 inst.error = BAD_ARGS;
5010 if (skip_past_comma (&str) == FAIL
5011 || cp_reg_required_here (&str, 12) == FAIL)
5014 inst.error = BAD_ARGS;
5018 if (skip_past_comma (&str) == FAIL
5019 || cp_reg_required_here (&str, 16) == FAIL)
5022 inst.error = BAD_ARGS;
5026 if (skip_past_comma (&str) == FAIL
5027 || cp_reg_required_here (&str, 0) == FAIL)
5030 inst.error = BAD_ARGS;
5034 if (skip_past_comma (&str) == SUCCESS)
5036 if (cp_opc_expr (&str, 5, 3) == FAIL)
5039 inst.error = BAD_ARGS;
5049 do_lstc (str, flags)
5051 unsigned long flags;
5053 /* Co-processor register load/store.
5054 Format: <LDC|STC{cond}[L] CP#,CRd,<address> */
5056 skip_whitespace (str);
5058 if (co_proc_number (&str) == FAIL)
5061 inst.error = BAD_ARGS;
5065 if (skip_past_comma (&str) == FAIL
5066 || cp_reg_required_here (&str, 12) == FAIL)
5069 inst.error = BAD_ARGS;
5073 if (skip_past_comma (&str) == FAIL
5074 || cp_address_required_here (&str) == FAIL)
5077 inst.error = BAD_ARGS;
5081 inst.instruction |= flags;
5087 do_co_reg (str, flags)
5089 unsigned long flags;
5091 /* Co-processor register transfer.
5092 Format: <MCR|MRC>{cond} CP#,<expr1>,Rd,CRn,CRm{,<expr2>} */
5094 skip_whitespace (str);
5096 if (co_proc_number (&str) == FAIL)
5099 inst.error = BAD_ARGS;
5103 if (skip_past_comma (&str) == FAIL
5104 || cp_opc_expr (&str, 21, 3) == FAIL)
5107 inst.error = BAD_ARGS;
5111 if (skip_past_comma (&str) == FAIL
5112 || reg_required_here (&str, 12) == FAIL)
5115 inst.error = BAD_ARGS;
5119 if (skip_past_comma (&str) == FAIL
5120 || cp_reg_required_here (&str, 16) == FAIL)
5123 inst.error = BAD_ARGS;
5127 if (skip_past_comma (&str) == FAIL
5128 || cp_reg_required_here (&str, 0) == FAIL)
5131 inst.error = BAD_ARGS;
5135 if (skip_past_comma (&str) == SUCCESS)
5137 if (cp_opc_expr (&str, 5, 3) == FAIL)
5140 inst.error = BAD_ARGS;
5146 inst.error = BAD_COND;
5154 do_fp_ctrl (str, flags)
5156 unsigned long flags ATTRIBUTE_UNUSED;
5158 /* FP control registers.
5159 Format: <WFS|RFS|WFC|RFC>{cond} Rn */
5161 skip_whitespace (str);
5163 if (reg_required_here (&str, 12) == FAIL)
5166 inst.error = BAD_ARGS;
5175 do_fp_ldst (str, flags)
5177 unsigned long flags ATTRIBUTE_UNUSED;
5179 skip_whitespace (str);
5181 switch (inst.suffix)
5186 inst.instruction |= CP_T_X;
5189 inst.instruction |= CP_T_Y;
5192 inst.instruction |= CP_T_X | CP_T_Y;
5198 if (fp_reg_required_here (&str, 12) == FAIL)
5201 inst.error = BAD_ARGS;
5205 if (skip_past_comma (&str) == FAIL
5206 || cp_address_required_here (&str) == FAIL)
5209 inst.error = BAD_ARGS;
5217 do_fp_ldmstm (str, flags)
5219 unsigned long flags;
5223 skip_whitespace (str);
5225 if (fp_reg_required_here (&str, 12) == FAIL)
5228 inst.error = BAD_ARGS;
5232 /* Get Number of registers to transfer. */
5233 if (skip_past_comma (&str) == FAIL
5234 || my_get_expression (&inst.reloc.exp, &str))
5237 inst.error = _("constant expression expected");
5241 if (inst.reloc.exp.X_op != O_constant)
5243 inst.error = _("Constant value required for number of registers");
5247 num_regs = inst.reloc.exp.X_add_number;
5249 if (num_regs < 1 || num_regs > 4)
5251 inst.error = _("number of registers must be in the range [1:4]");
5258 inst.instruction |= CP_T_X;
5261 inst.instruction |= CP_T_Y;
5264 inst.instruction |= CP_T_Y | CP_T_X;
5278 /* The instruction specified "ea" or "fd", so we can only accept
5279 [Rn]{!}. The instruction does not really support stacking or
5280 unstacking, so we have to emulate these by setting appropriate
5281 bits and offsets. */
5282 if (skip_past_comma (&str) == FAIL
5286 inst.error = BAD_ARGS;
5291 skip_whitespace (str);
5293 if ((reg = reg_required_here (&str, 16)) == FAIL)
5296 skip_whitespace (str);
5300 inst.error = BAD_ARGS;
5312 _("R15 not allowed as base register with write-back");
5319 if (flags & CP_T_Pre)
5321 /* Pre-decrement. */
5322 offset = 3 * num_regs;
5328 /* Post-increment. */
5332 offset = 3 * num_regs;
5336 /* No write-back, so convert this into a standard pre-increment
5337 instruction -- aesthetically more pleasing. */
5338 flags = CP_T_Pre | CP_T_UD;
5343 inst.instruction |= flags | offset;
5345 else if (skip_past_comma (&str) == FAIL
5346 || cp_address_required_here (&str) == FAIL)
5349 inst.error = BAD_ARGS;
5357 do_fp_dyadic (str, flags)
5359 unsigned long flags;
5361 skip_whitespace (str);
5363 switch (inst.suffix)
5368 inst.instruction |= 0x00000080;
5371 inst.instruction |= 0x00080000;
5377 if (fp_reg_required_here (&str, 12) == FAIL)
5380 inst.error = BAD_ARGS;
5384 if (skip_past_comma (&str) == FAIL
5385 || fp_reg_required_here (&str, 16) == FAIL)
5388 inst.error = BAD_ARGS;
5392 if (skip_past_comma (&str) == FAIL
5393 || fp_op2 (&str) == FAIL)
5396 inst.error = BAD_ARGS;
5400 inst.instruction |= flags;
5406 do_fp_monadic (str, flags)
5408 unsigned long flags;
5410 skip_whitespace (str);
5412 switch (inst.suffix)
5417 inst.instruction |= 0x00000080;
5420 inst.instruction |= 0x00080000;
5426 if (fp_reg_required_here (&str, 12) == FAIL)
5429 inst.error = BAD_ARGS;
5433 if (skip_past_comma (&str) == FAIL
5434 || fp_op2 (&str) == FAIL)
5437 inst.error = BAD_ARGS;
5441 inst.instruction |= flags;
5447 do_fp_cmp (str, flags)
5449 unsigned long flags;
5451 skip_whitespace (str);
5453 if (fp_reg_required_here (&str, 16) == FAIL)
5456 inst.error = BAD_ARGS;
5460 if (skip_past_comma (&str) == FAIL
5461 || fp_op2 (&str) == FAIL)
5464 inst.error = BAD_ARGS;
5468 inst.instruction |= flags;
5474 do_fp_from_reg (str, flags)
5476 unsigned long flags;
5478 skip_whitespace (str);
5480 switch (inst.suffix)
5485 inst.instruction |= 0x00000080;
5488 inst.instruction |= 0x00080000;
5494 if (fp_reg_required_here (&str, 16) == FAIL)
5497 inst.error = BAD_ARGS;
5501 if (skip_past_comma (&str) == FAIL
5502 || reg_required_here (&str, 12) == FAIL)
5505 inst.error = BAD_ARGS;
5509 inst.instruction |= flags;
5515 do_fp_to_reg (str, flags)
5517 unsigned long flags;
5519 skip_whitespace (str);
5521 if (reg_required_here (&str, 12) == FAIL)
5524 if (skip_past_comma (&str) == FAIL
5525 || fp_reg_required_here (&str, 0) == FAIL)
5528 inst.error = BAD_ARGS;
5532 inst.instruction |= flags;
5537 /* Thumb specific routines. */
5539 /* Parse and validate that a register is of the right form, this saves
5540 repeated checking of this information in many similar cases.
5541 Unlike the 32-bit case we do not insert the register into the opcode
5542 here, since the position is often unknown until the full instruction
5546 thumb_reg (strp, hi_lo)
5552 if ((reg = reg_required_here (strp, -1)) == FAIL)
5560 inst.error = _("lo register required");
5568 inst.error = _("hi register required");
5580 /* Parse an add or subtract instruction, SUBTRACT is non-zero if the opcode
5584 thumb_add_sub (str, subtract)
5588 int Rd, Rs, Rn = FAIL;
5590 skip_whitespace (str);
5592 if ((Rd = thumb_reg (&str, THUMB_REG_ANY)) == FAIL
5593 || skip_past_comma (&str) == FAIL)
5596 inst.error = BAD_ARGS;
5600 if (is_immediate_prefix (*str))
5604 if (my_get_expression (&inst.reloc.exp, &str))
5609 if ((Rs = thumb_reg (&str, THUMB_REG_ANY)) == FAIL)
5612 if (skip_past_comma (&str) == FAIL)
5614 /* Two operand format, shuffle the registers
5615 and pretend there are 3. */
5619 else if (is_immediate_prefix (*str))
5622 if (my_get_expression (&inst.reloc.exp, &str))
5625 else if ((Rn = thumb_reg (&str, THUMB_REG_ANY)) == FAIL)
5629 /* We now have Rd and Rs set to registers, and Rn set to a register or FAIL;
5630 for the latter case, EXPR contains the immediate that was found. */
5633 /* All register format. */
5634 if (Rd > 7 || Rs > 7 || Rn > 7)
5638 inst.error = _("dest and source1 must be the same register");
5642 /* Can't do this for SUB. */
5645 inst.error = _("subtract valid only on lo regs");
5649 inst.instruction = (T_OPCODE_ADD_HI
5650 | (Rd > 7 ? THUMB_H1 : 0)
5651 | (Rn > 7 ? THUMB_H2 : 0));
5652 inst.instruction |= (Rd & 7) | ((Rn & 7) << 3);
5656 inst.instruction = subtract ? T_OPCODE_SUB_R3 : T_OPCODE_ADD_R3;
5657 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
5662 /* Immediate expression, now things start to get nasty. */
5664 /* First deal with HI regs, only very restricted cases allowed:
5665 Adjusting SP, and using PC or SP to get an address. */
5666 if ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
5667 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC))
5669 inst.error = _("invalid Hi register with immediate");
5673 if (inst.reloc.exp.X_op != O_constant)
5675 /* Value isn't known yet, all we can do is store all the fragments
5676 we know about in the instruction and let the reloc hacking
5678 inst.instruction = (subtract ? 0x8000 : 0) | (Rd << 4) | Rs;
5679 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
5683 int offset = inst.reloc.exp.X_add_number;
5693 /* Quick check, in case offset is MIN_INT. */
5696 inst.error = _("immediate value out of range");
5705 if (offset & ~0x1fc)
5707 inst.error = _("invalid immediate value for stack adjust");
5710 inst.instruction = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
5711 inst.instruction |= offset >> 2;
5713 else if (Rs == REG_PC || Rs == REG_SP)
5716 || (offset & ~0x3fc))
5718 inst.error = _("invalid immediate for address calculation");
5721 inst.instruction = (Rs == REG_PC ? T_OPCODE_ADD_PC
5723 inst.instruction |= (Rd << 8) | (offset >> 2);
5729 inst.error = _("immediate value out of range");
5732 inst.instruction = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
5733 inst.instruction |= (Rd << 8) | offset;
5739 inst.error = _("immediate value out of range");
5742 inst.instruction = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
5743 inst.instruction |= Rd | (Rs << 3) | (offset << 6);
5752 thumb_shift (str, shift)
5756 int Rd, Rs, Rn = FAIL;
5758 skip_whitespace (str);
5760 if ((Rd = thumb_reg (&str, THUMB_REG_LO)) == FAIL
5761 || skip_past_comma (&str) == FAIL)
5764 inst.error = BAD_ARGS;
5768 if (is_immediate_prefix (*str))
5770 /* Two operand immediate format, set Rs to Rd. */
5773 if (my_get_expression (&inst.reloc.exp, &str))
5778 if ((Rs = thumb_reg (&str, THUMB_REG_LO)) == FAIL)
5781 if (skip_past_comma (&str) == FAIL)
5783 /* Two operand format, shuffle the registers
5784 and pretend there are 3. */
5788 else if (is_immediate_prefix (*str))
5791 if (my_get_expression (&inst.reloc.exp, &str))
5794 else if ((Rn = thumb_reg (&str, THUMB_REG_LO)) == FAIL)
5798 /* We now have Rd and Rs set to registers, and Rn set to a register or FAIL;
5799 for the latter case, EXPR contains the immediate that was found. */
5805 inst.error = _("source1 and dest must be same register");
5811 case THUMB_ASR: inst.instruction = T_OPCODE_ASR_R; break;
5812 case THUMB_LSL: inst.instruction = T_OPCODE_LSL_R; break;
5813 case THUMB_LSR: inst.instruction = T_OPCODE_LSR_R; break;
5816 inst.instruction |= Rd | (Rn << 3);
5822 case THUMB_ASR: inst.instruction = T_OPCODE_ASR_I; break;
5823 case THUMB_LSL: inst.instruction = T_OPCODE_LSL_I; break;
5824 case THUMB_LSR: inst.instruction = T_OPCODE_LSR_I; break;
5827 if (inst.reloc.exp.X_op != O_constant)
5829 /* Value isn't known yet, create a dummy reloc and let reloc
5830 hacking fix it up. */
5831 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
5835 unsigned shift_value = inst.reloc.exp.X_add_number;
5837 if (shift_value > 32 || (shift_value == 32 && shift == THUMB_LSL))
5839 inst.error = _("Invalid immediate for shift");
5843 /* Shifts of zero are handled by converting to LSL. */
5844 if (shift_value == 0)
5845 inst.instruction = T_OPCODE_LSL_I;
5847 /* Shifts of 32 are encoded as a shift of zero. */
5848 if (shift_value == 32)
5851 inst.instruction |= shift_value << 6;
5854 inst.instruction |= Rd | (Rs << 3);
5861 thumb_mov_compare (str, move)
5867 skip_whitespace (str);
5869 if ((Rd = thumb_reg (&str, THUMB_REG_ANY)) == FAIL
5870 || skip_past_comma (&str) == FAIL)
5873 inst.error = BAD_ARGS;
5877 if (is_immediate_prefix (*str))
5880 if (my_get_expression (&inst.reloc.exp, &str))
5883 else if ((Rs = thumb_reg (&str, THUMB_REG_ANY)) == FAIL)
5888 if (Rs < 8 && Rd < 8)
5890 if (move == THUMB_MOVE)
5891 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
5892 since a MOV instruction produces unpredictable results. */
5893 inst.instruction = T_OPCODE_ADD_I3;
5895 inst.instruction = T_OPCODE_CMP_LR;
5896 inst.instruction |= Rd | (Rs << 3);
5900 if (move == THUMB_MOVE)
5901 inst.instruction = T_OPCODE_MOV_HR;
5903 inst.instruction = T_OPCODE_CMP_HR;
5906 inst.instruction |= THUMB_H1;
5909 inst.instruction |= THUMB_H2;
5911 inst.instruction |= (Rd & 7) | ((Rs & 7) << 3);
5918 inst.error = _("only lo regs allowed with immediate");
5922 if (move == THUMB_MOVE)
5923 inst.instruction = T_OPCODE_MOV_I8;
5925 inst.instruction = T_OPCODE_CMP_I8;
5927 inst.instruction |= Rd << 8;
5929 if (inst.reloc.exp.X_op != O_constant)
5930 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
5933 unsigned value = inst.reloc.exp.X_add_number;
5937 inst.error = _("invalid immediate");
5941 inst.instruction |= value;
5949 thumb_load_store (str, load_store, size)
5954 int Rd, Rb, Ro = FAIL;
5956 skip_whitespace (str);
5958 if ((Rd = thumb_reg (&str, THUMB_REG_LO)) == FAIL
5959 || skip_past_comma (&str) == FAIL)
5962 inst.error = BAD_ARGS;
5969 if ((Rb = thumb_reg (&str, THUMB_REG_ANY)) == FAIL)
5972 if (skip_past_comma (&str) != FAIL)
5974 if (is_immediate_prefix (*str))
5977 if (my_get_expression (&inst.reloc.exp, &str))
5980 else if ((Ro = thumb_reg (&str, THUMB_REG_LO)) == FAIL)
5985 inst.reloc.exp.X_op = O_constant;
5986 inst.reloc.exp.X_add_number = 0;
5991 inst.error = _("expected ']'");
5996 else if (*str == '=')
5998 /* Parse an "ldr Rd, =expr" instruction; this is another pseudo op. */
6001 skip_whitespace (str);
6003 if (my_get_expression (& inst.reloc.exp, & str))
6008 if ( inst.reloc.exp.X_op != O_constant
6009 && inst.reloc.exp.X_op != O_symbol)
6011 inst.error = "Constant expression expected";
6015 if (inst.reloc.exp.X_op == O_constant
6016 && ((inst.reloc.exp.X_add_number & ~0xFF) == 0))
6018 /* This can be done with a mov instruction. */
6020 inst.instruction = T_OPCODE_MOV_I8 | (Rd << 8);
6021 inst.instruction |= inst.reloc.exp.X_add_number;
6025 /* Insert into literal pool. */
6026 if (add_to_lit_pool () == FAIL)
6029 inst.error = "literal pool insertion failed";
6033 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6034 inst.reloc.pc_rel = 1;
6035 inst.instruction = T_OPCODE_LDR_PC | (Rd << 8);
6036 /* Adjust ARM pipeline offset to Thumb. */
6037 inst.reloc.exp.X_add_number += 4;
6043 if (my_get_expression (&inst.reloc.exp, &str))
6046 inst.instruction = T_OPCODE_LDR_PC | (Rd << 8);
6047 inst.reloc.pc_rel = 1;
6048 inst.reloc.exp.X_add_number -= 4; /* Pipeline offset. */
6049 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6054 if (Rb == REG_PC || Rb == REG_SP)
6056 if (size != THUMB_WORD)
6058 inst.error = _("byte or halfword not valid for base register");
6061 else if (Rb == REG_PC && load_store != THUMB_LOAD)
6063 inst.error = _("R15 based store not allowed");
6066 else if (Ro != FAIL)
6068 inst.error = _("Invalid base register for register offset");
6073 inst.instruction = T_OPCODE_LDR_PC;
6074 else if (load_store == THUMB_LOAD)
6075 inst.instruction = T_OPCODE_LDR_SP;
6077 inst.instruction = T_OPCODE_STR_SP;
6079 inst.instruction |= Rd << 8;
6080 if (inst.reloc.exp.X_op == O_constant)
6082 unsigned offset = inst.reloc.exp.X_add_number;
6084 if (offset & ~0x3fc)
6086 inst.error = _("invalid offset");
6090 inst.instruction |= offset >> 2;
6093 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6097 inst.error = _("invalid base register in load/store");
6100 else if (Ro == FAIL)
6102 /* Immediate offset. */
6103 if (size == THUMB_WORD)
6104 inst.instruction = (load_store == THUMB_LOAD
6105 ? T_OPCODE_LDR_IW : T_OPCODE_STR_IW);
6106 else if (size == THUMB_HALFWORD)
6107 inst.instruction = (load_store == THUMB_LOAD
6108 ? T_OPCODE_LDR_IH : T_OPCODE_STR_IH);
6110 inst.instruction = (load_store == THUMB_LOAD
6111 ? T_OPCODE_LDR_IB : T_OPCODE_STR_IB);
6113 inst.instruction |= Rd | (Rb << 3);
6115 if (inst.reloc.exp.X_op == O_constant)
6117 unsigned offset = inst.reloc.exp.X_add_number;
6119 if (offset & ~(0x1f << size))
6121 inst.error = _("Invalid offset");
6124 inst.instruction |= (offset >> size) << 6;
6127 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6131 /* Register offset. */
6132 if (size == THUMB_WORD)
6133 inst.instruction = (load_store == THUMB_LOAD
6134 ? T_OPCODE_LDR_RW : T_OPCODE_STR_RW);
6135 else if (size == THUMB_HALFWORD)
6136 inst.instruction = (load_store == THUMB_LOAD
6137 ? T_OPCODE_LDR_RH : T_OPCODE_STR_RH);
6139 inst.instruction = (load_store == THUMB_LOAD
6140 ? T_OPCODE_LDR_RB : T_OPCODE_STR_RB);
6142 inst.instruction |= Rd | (Rb << 3) | (Ro << 6);
6148 /* Given a register and a register type, return 1 if
6149 the register is of the given type, else return 0. */
6152 cirrus_valid_reg (reg, regtype)
6154 enum cirrus_regtype regtype;
6158 case CIRRUS_REGTYPE_ANY:
6161 case CIRRUS_REGTYPE_MVF:
6162 return cirrus_mvf_register (reg);
6164 case CIRRUS_REGTYPE_MVFX:
6165 return cirrus_mvfx_register (reg);
6167 case CIRRUS_REGTYPE_MVD:
6168 return cirrus_mvd_register (reg);
6170 case CIRRUS_REGTYPE_MVDX:
6171 return cirrus_mvdx_register (reg);
6173 case CIRRUS_REGTYPE_MVAX:
6174 return cirrus_mvax_register (reg);
6176 case CIRRUS_REGTYPE_DSPSC:
6177 return ARM_EXT_MAVERICKsc_register (reg);
6183 /* A register must be given at this point.
6185 If the register is a Cirrus register, convert it's reg# appropriately.
6187 Shift is the place to put it in inst.instruction.
6189 regtype is type register type expected, and is:
6195 CIRRUS_REGTYPE_DSPSC
6197 Restores input start point on err.
6198 Returns the reg#, or FAIL. */
6201 cirrus_reg_required_here (str, shift, regtype)
6204 enum cirrus_regtype regtype;
6206 static char buff [135]; /* XXX */
6208 char * start = * str;
6210 if ((reg = arm_reg_parse (str)) != FAIL
6211 && (int_register (reg)
6212 || cirrus_register (reg)))
6216 /* Calculate actual register # for opcode. */
6217 if (cirrus_register (reg)
6218 && !ARM_EXT_MAVERICKsc_register (reg)) /* Leave this one as is. */
6222 else if (reg >= 110)
6232 if (!cirrus_valid_reg (orig_reg, regtype))
6234 sprintf (buff, _("invalid register type at '%.100s'"), start);
6240 inst.instruction |= reg << shift;
6245 /* Restore the start point, we may have got a reg of the wrong class. */
6248 /* In the few cases where we might be able to accept something else
6249 this error can be overridden. */
6250 sprintf (buff, _("Cirrus register expected, not '%.100s'"), start);
6256 /* Cirrus Instructions. */
6258 /* Wrapper functions. */
6261 do_c_binops_1 (str, flags)
6263 unsigned long flags;
6265 do_c_binops (str, flags, CIRRUS_MODE1);
6269 do_c_binops_2 (str, flags)
6271 unsigned long flags;
6273 do_c_binops (str, flags, CIRRUS_MODE2);
6277 do_c_binops_3 (str, flags)
6279 unsigned long flags;
6281 do_c_binops (str, flags, CIRRUS_MODE3);
6285 do_c_triple_4 (str, flags)
6287 unsigned long flags;
6289 do_c_triple (str, flags, CIRRUS_MODE4);
6293 do_c_triple_5 (str, flags)
6295 unsigned long flags;
6297 do_c_triple (str, flags, CIRRUS_MODE5);
6301 do_c_quad_6 (str, flags)
6303 unsigned long flags;
6305 do_c_quad (str, flags, CIRRUS_MODE6);
6309 do_c_dspsc_1 (str, flags)
6311 unsigned long flags;
6313 do_c_dspsc (str, flags, CIRRUS_MODE1);
6317 do_c_dspsc_2 (str, flags)
6319 unsigned long flags;
6321 do_c_dspsc (str, flags, CIRRUS_MODE2);
6325 do_c_shift_1 (str, flags)
6327 unsigned long flags;
6329 do_c_shift (str, flags, CIRRUS_MODE1);
6333 do_c_shift_2 (str, flags)
6335 unsigned long flags;
6337 do_c_shift (str, flags, CIRRUS_MODE2);
6341 do_c_ldst_1 (str, flags)
6343 unsigned long flags;
6345 do_c_ldst (str, flags, CIRRUS_MODE1);
6349 do_c_ldst_2 (str, flags)
6351 unsigned long flags;
6353 do_c_ldst (str, flags, CIRRUS_MODE2);
6357 do_c_ldst_3 (str, flags)
6359 unsigned long flags;
6361 do_c_ldst (str, flags, CIRRUS_MODE3);
6365 do_c_ldst_4 (str, flags)
6367 unsigned long flags;
6369 do_c_ldst (str, flags, CIRRUS_MODE4);
6372 /* Isnsn like "foo X,Y". */
6375 do_c_binops (str, flags, mode)
6377 unsigned long flags;
6382 shift1 = mode & 0xff;
6383 shift2 = (mode >> 8) & 0xff;
6385 skip_whitespace (str);
6387 if (cirrus_reg_required_here (&str, shift1, CIRRUS_REGTYPE_ANY) == FAIL
6388 || skip_past_comma (&str) == FAIL
6389 || cirrus_reg_required_here (&str, shift2, CIRRUS_REGTYPE_ANY) == FAIL)
6392 inst.error = BAD_ARGS;
6397 inst.instruction |= flags;
6401 /* Isnsn like "foo X,Y,Z". */
6404 do_c_triple (str, flags, mode)
6406 unsigned long flags;
6409 int shift1, shift2, shift3;
6411 shift1 = mode & 0xff;
6412 shift2 = (mode >> 8) & 0xff;
6413 shift3 = (mode >> 16) & 0xff;
6415 skip_whitespace (str);
6417 if (cirrus_reg_required_here (&str, shift1, CIRRUS_REGTYPE_ANY) == FAIL
6418 || skip_past_comma (&str) == FAIL
6419 || cirrus_reg_required_here (&str, shift2, CIRRUS_REGTYPE_ANY) == FAIL
6420 || skip_past_comma (&str) == FAIL
6421 || cirrus_reg_required_here (&str, shift3, CIRRUS_REGTYPE_ANY) == FAIL)
6424 inst.error = BAD_ARGS;
6429 inst.instruction |= flags;
6433 /* Isnsn like "foo W,X,Y,Z".
6434 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
6437 do_c_quad (str, flags, mode)
6439 unsigned long flags;
6442 int shift1, shift2, shift3, shift4;
6443 enum cirrus_regtype rt;
6445 rt = (inst.instruction << 4 == 0xe2006000
6446 || inst.instruction << 4 == 0xe3006000) ? CIRRUS_REGTYPE_MVAX
6447 : CIRRUS_REGTYPE_MVFX;
6449 shift1 = mode & 0xff;
6450 shift2 = (mode >> 8) & 0xff;
6451 shift3 = (mode >> 16) & 0xff;
6452 shift4 = (mode >> 24) & 0xff;
6454 skip_whitespace (str);
6456 if (cirrus_reg_required_here (&str, shift1, CIRRUS_REGTYPE_MVAX) == FAIL
6457 || skip_past_comma (&str) == FAIL
6458 || cirrus_reg_required_here (&str, shift2, rt) == FAIL
6459 || skip_past_comma (&str) == FAIL
6460 || cirrus_reg_required_here (&str, shift3, CIRRUS_REGTYPE_MVFX) == FAIL
6461 || skip_past_comma (&str) == FAIL
6462 || cirrus_reg_required_here (&str, shift4, CIRRUS_REGTYPE_MVFX) == FAIL)
6465 inst.error = BAD_ARGS;
6470 inst.instruction |= flags;
6474 /* cfmvsc32<cond> DSPSC,MVFX[15:0].
6475 cfmv32sc<cond> MVFX[15:0],DSPSC. */
6478 do_c_dspsc (str, flags, mode)
6480 unsigned long flags;
6485 skip_whitespace (str);
6489 if (mode == CIRRUS_MODE1)
6492 if (cirrus_reg_required_here (&str, -1, CIRRUS_REGTYPE_DSPSC) == FAIL
6493 || skip_past_comma (&str) == FAIL
6494 || cirrus_reg_required_here (&str, 16, CIRRUS_REGTYPE_MVFX) == FAIL)
6500 if (cirrus_reg_required_here (&str, 0, CIRRUS_REGTYPE_MVFX) == FAIL
6501 || skip_past_comma (&str) == FAIL
6502 || cirrus_reg_required_here (&str, -1, CIRRUS_REGTYPE_DSPSC) == FAIL)
6509 inst.error = BAD_ARGS;
6513 inst.instruction |= flags;
6520 /* Cirrus shift immediate instructions.
6521 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
6522 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
6525 do_c_shift (str, flags, mode)
6527 unsigned long flags;
6533 skip_whitespace (str);
6537 if (cirrus_reg_required_here (&str, 12,
6538 (mode == CIRRUS_MODE1)
6539 ? CIRRUS_REGTYPE_MVFX
6540 : CIRRUS_REGTYPE_MVDX) == FAIL
6541 || skip_past_comma (&str) == FAIL
6542 || cirrus_reg_required_here (&str, 16,
6543 (mode == CIRRUS_MODE1)
6544 ? CIRRUS_REGTYPE_MVFX
6545 : CIRRUS_REGTYPE_MVDX) == FAIL
6546 || skip_past_comma (&str) == FAIL)
6549 inst.error = BAD_ARGS;
6553 /* Calculate the immediate operand.
6554 The operand is a 7bit signed number. */
6555 skip_whitespace (str);
6560 if (!isdigit (*str) && *str != '-')
6562 inst.error = _("expecting immediate, 7bit operand");
6572 for (imm = 0; *str && isdigit (*str); ++str)
6573 imm = imm * 10 + *str - '0';
6577 inst.error = _("immediate out of range");
6581 /* Make negative imm's into 7bit signed numbers. */
6588 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
6589 Bits 5-7 of the insn should have bits 4-6 of the immediate.
6590 Bit 4 should be 0. */
6591 imm = (imm & 0xf) | ((imm & 0x70) << 1);
6593 inst.instruction |= imm;
6594 inst.instruction |= flags;
6602 cirrus_parse_offset (str, negative)
6611 skip_whitespace (p);
6624 inst.error = _("offset expected");
6628 for (offset = 0; *p && isdigit (*p); ++p)
6629 offset = offset * 10 + *p - '0';
6633 inst.error = _("offset out of range");
6639 return *negative ? -offset : offset;
6642 /* Cirrus load/store instructions.
6643 <insn><cond> CRd,[Rn,<offset>]{!}.
6644 <insn><cond> CRd,[Rn],<offset>. */
6647 do_c_ldst (str, flags, mode)
6649 unsigned long flags;
6652 int offset, negative;
6653 enum cirrus_regtype rt;
6655 rt = mode == CIRRUS_MODE1 ? CIRRUS_REGTYPE_MVF
6656 : mode == CIRRUS_MODE2 ? CIRRUS_REGTYPE_MVD
6657 : mode == CIRRUS_MODE3 ? CIRRUS_REGTYPE_MVFX
6658 : mode == CIRRUS_MODE4 ? CIRRUS_REGTYPE_MVDX : CIRRUS_REGTYPE_MVF;
6660 skip_whitespace (str);
6662 if (cirrus_reg_required_here (& str, 12, rt) == FAIL
6663 || skip_past_comma (& str) == FAIL
6665 || reg_required_here (& str, 16) == FAIL)
6668 if (skip_past_comma (& str) == SUCCESS)
6670 /* You are here: "<offset>]{!}". */
6671 inst.instruction |= PRE_INDEX;
6673 offset = cirrus_parse_offset (&str, &negative);
6680 inst.error = _("missing ]");
6686 inst.instruction |= WRITE_BACK;
6692 /* You are here: "], <offset>". */
6695 inst.error = _("missing ]");
6699 if (skip_past_comma (&str) == FAIL
6700 || (offset = cirrus_parse_offset (&str, &negative), inst.error))
6703 inst.instruction |= CP_T_WB; /* Post indexed, set bit W. */
6709 inst.instruction |= CP_T_UD; /* Postive, so set bit U. */
6711 inst.instruction |= offset >> 2;
6712 inst.instruction |= flags;
6719 inst.error = BAD_ARGS;
6732 /* Handle the Format 4 instructions that do not have equivalents in other
6733 formats. That is, ADC, AND, EOR, SBC, ROR, TST, NEG, CMN, ORR, MUL,
6742 skip_whitespace (str);
6744 if ((Rd = thumb_reg (&str, THUMB_REG_LO)) == FAIL
6745 || skip_past_comma (&str) == FAIL
6746 || (Rs = thumb_reg (&str, THUMB_REG_LO)) == FAIL)
6748 inst.error = BAD_ARGS;
6752 if (skip_past_comma (&str) != FAIL)
6754 /* Three operand format not allowed for TST, CMN, NEG and MVN.
6755 (It isn't allowed for CMP either, but that isn't handled by this
6757 if (inst.instruction == T_OPCODE_TST
6758 || inst.instruction == T_OPCODE_CMN
6759 || inst.instruction == T_OPCODE_NEG
6760 || inst.instruction == T_OPCODE_MVN)
6762 inst.error = BAD_ARGS;
6766 if ((Rn = thumb_reg (&str, THUMB_REG_LO)) == FAIL)
6771 inst.error = _("dest and source1 must be the same register");
6777 if (inst.instruction == T_OPCODE_MUL
6779 as_tsktsk (_("Rs and Rd must be different in MUL"));
6781 inst.instruction |= Rd | (Rs << 3);
6789 thumb_add_sub (str, 0);
6796 thumb_shift (str, THUMB_ASR);
6803 if (my_get_expression (&inst.reloc.exp, &str))
6805 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
6806 inst.reloc.pc_rel = 1;
6814 if (my_get_expression (&inst.reloc.exp, &str))
6816 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
6817 inst.reloc.pc_rel = 1;
6821 /* Find the real, Thumb encoded start of a Thumb function. */
6824 find_real_start (symbolP)
6828 const char * name = S_GET_NAME (symbolP);
6829 symbolS * new_target;
6831 /* This definiton must agree with the one in gcc/config/arm/thumb.c. */
6832 #define STUB_NAME ".real_start_of"
6837 /* Names that start with '.' are local labels, not function entry points.
6838 The compiler may generate BL instructions to these labels because it
6839 needs to perform a branch to a far away location. */
6843 real_start = malloc (strlen (name) + strlen (STUB_NAME) + 1);
6844 sprintf (real_start, "%s%s", STUB_NAME, name);
6846 new_target = symbol_find (real_start);
6848 if (new_target == NULL)
6850 as_warn ("Failed to find real start of function: %s\n", name);
6851 new_target = symbolP;
6863 if (my_get_expression (& inst.reloc.exp, & str))
6866 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
6867 inst.reloc.pc_rel = 1;
6870 /* If the destination of the branch is a defined symbol which does not have
6871 the THUMB_FUNC attribute, then we must be calling a function which has
6872 the (interfacearm) attribute. We look for the Thumb entry point to that
6873 function and change the branch to refer to that function instead. */
6874 if ( inst.reloc.exp.X_op == O_symbol
6875 && inst.reloc.exp.X_add_symbol != NULL
6876 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
6877 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
6878 inst.reloc.exp.X_add_symbol =
6879 find_real_start (inst.reloc.exp.X_add_symbol);
6888 skip_whitespace (str);
6890 if ((reg = thumb_reg (&str, THUMB_REG_ANY)) == FAIL)
6893 /* This sets THUMB_H2 from the top bit of reg. */
6894 inst.instruction |= reg << 3;
6896 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
6897 should cause the alignment to be checked once it is known. This is
6898 because BX PC only works if the instruction is word aligned. */
6907 thumb_mov_compare (str, THUMB_COMPARE);
6917 skip_whitespace (str);
6919 if ((Rb = thumb_reg (&str, THUMB_REG_LO)) == FAIL)
6923 as_warn (_("Inserted missing '!': load/store multiple always writes back base register"));
6927 if (skip_past_comma (&str) == FAIL
6928 || (range = reg_list (&str)) == FAIL)
6931 inst.error = BAD_ARGS;
6935 if (inst.reloc.type != BFD_RELOC_NONE)
6937 /* This really doesn't seem worth it. */
6938 inst.reloc.type = BFD_RELOC_NONE;
6939 inst.error = _("Expression too complex");
6945 inst.error = _("only lo-regs valid in load/store multiple");
6949 inst.instruction |= (Rb << 8) | range;
6957 thumb_load_store (str, THUMB_LOAD, THUMB_WORD);
6964 thumb_load_store (str, THUMB_LOAD, THUMB_BYTE);
6971 thumb_load_store (str, THUMB_LOAD, THUMB_HALFWORD);
6980 skip_whitespace (str);
6982 if ((Rd = thumb_reg (&str, THUMB_REG_LO)) == FAIL
6983 || skip_past_comma (&str) == FAIL
6985 || (Rb = thumb_reg (&str, THUMB_REG_LO)) == FAIL
6986 || skip_past_comma (&str) == FAIL
6987 || (Ro = thumb_reg (&str, THUMB_REG_LO)) == FAIL
6991 inst.error = _("Syntax: ldrs[b] Rd, [Rb, Ro]");
6995 inst.instruction |= Rd | (Rb << 3) | (Ro << 6);
7003 thumb_shift (str, THUMB_LSL);
7010 thumb_shift (str, THUMB_LSR);
7017 thumb_mov_compare (str, THUMB_MOVE);
7026 skip_whitespace (str);
7028 if ((range = reg_list (&str)) == FAIL)
7031 inst.error = BAD_ARGS;
7035 if (inst.reloc.type != BFD_RELOC_NONE)
7037 /* This really doesn't seem worth it. */
7038 inst.reloc.type = BFD_RELOC_NONE;
7039 inst.error = _("Expression too complex");
7045 if ((inst.instruction == T_OPCODE_PUSH
7046 && (range & ~0xff) == 1 << REG_LR)
7047 || (inst.instruction == T_OPCODE_POP
7048 && (range & ~0xff) == 1 << REG_PC))
7050 inst.instruction |= THUMB_PP_PC_LR;
7055 inst.error = _("invalid register list to push/pop instruction");
7060 inst.instruction |= range;
7068 thumb_load_store (str, THUMB_STORE, THUMB_WORD);
7075 thumb_load_store (str, THUMB_STORE, THUMB_BYTE);
7082 thumb_load_store (str, THUMB_STORE, THUMB_HALFWORD);
7089 thumb_add_sub (str, 1);
7096 skip_whitespace (str);
7098 if (my_get_expression (&inst.reloc.exp, &str))
7101 inst.reloc.type = BFD_RELOC_ARM_SWI;
7112 /* This is a pseudo-op of the form "adr rd, label" to be converted
7113 into a relative address of the form "add rd, pc, #label-.-4". */
7114 skip_whitespace (str);
7116 /* Store Rd in temporary location inside instruction. */
7117 if ((reg = reg_required_here (&str, 4)) == FAIL
7118 || (reg > 7) /* For Thumb reg must be r0..r7. */
7119 || skip_past_comma (&str) == FAIL
7120 || my_get_expression (&inst.reloc.exp, &str))
7123 inst.error = BAD_ARGS;
7127 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
7128 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
7129 inst.reloc.pc_rel = 1;
7130 inst.instruction |= REG_PC; /* Rd is already placed into the instruction. */
7139 int len = strlen (reg_table[entry].name) + 2;
7140 char * buf = (char *) xmalloc (len);
7141 char * buf2 = (char *) xmalloc (len);
7144 #ifdef REGISTER_PREFIX
7145 buf[i++] = REGISTER_PREFIX;
7148 strcpy (buf + i, reg_table[entry].name);
7150 for (i = 0; buf[i]; i++)
7151 buf2[i] = TOUPPER (buf[i]);
7155 hash_insert (arm_reg_hsh, buf, (PTR) & reg_table[entry]);
7156 hash_insert (arm_reg_hsh, buf2, (PTR) & reg_table[entry]);
7160 insert_reg_alias (str, regnum)
7164 struct reg_entry *new =
7165 (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
7166 char *name = xmalloc (strlen (str) + 1);
7170 new->number = regnum;
7172 hash_insert (arm_reg_hsh, name, (PTR) new);
7176 set_constant_flonums ()
7180 for (i = 0; i < NUM_FLOAT_VALS; i++)
7181 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
7191 if ( (arm_ops_hsh = hash_new ()) == NULL
7192 || (arm_tops_hsh = hash_new ()) == NULL
7193 || (arm_cond_hsh = hash_new ()) == NULL
7194 || (arm_shift_hsh = hash_new ()) == NULL
7195 || (arm_reg_hsh = hash_new ()) == NULL
7196 || (arm_psr_hsh = hash_new ()) == NULL)
7197 as_fatal (_("Virtual memory exhausted"));
7199 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
7200 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
7201 for (i = 0; i < sizeof (tinsns) / sizeof (struct thumb_opcode); i++)
7202 hash_insert (arm_tops_hsh, tinsns[i].template, (PTR) (tinsns + i));
7203 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
7204 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
7205 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
7206 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
7207 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
7208 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
7210 for (i = 0; reg_table[i].name; i++)
7213 set_constant_flonums ();
7215 #if defined OBJ_COFF || defined OBJ_ELF
7217 unsigned int flags = 0;
7219 /* Set the flags in the private structure. */
7220 if (uses_apcs_26) flags |= F_APCS26;
7221 if (support_interwork) flags |= F_INTERWORK;
7222 if (uses_apcs_float) flags |= F_APCS_FLOAT;
7223 if (pic_code) flags |= F_PIC;
7224 if ((cpu_variant & FPU_ALL) == FPU_NONE) flags |= F_SOFT_FLOAT;
7226 bfd_set_private_flags (stdoutput, flags);
7228 /* We have run out flags in the COFF header to encode the
7229 status of ATPCS support, so instead we create a dummy,
7230 empty, debug section called .arm.atpcs. */
7235 sec = bfd_make_section (stdoutput, ".arm.atpcs");
7239 bfd_set_section_flags
7240 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
7241 bfd_set_section_size (stdoutput, sec, 0);
7242 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
7248 /* Record the CPU type as well. */
7249 switch (cpu_variant & ARM_CPU_MASK)
7252 mach = bfd_mach_arm_2;
7255 case ARM_3: /* Also ARM_250. */
7256 mach = bfd_mach_arm_2a;
7260 case ARM_6 | ARM_3 | ARM_2: /* Actually no CPU type defined. */
7261 mach = bfd_mach_arm_4;
7264 case ARM_7: /* Also ARM_6. */
7265 mach = bfd_mach_arm_3;
7269 /* Catch special cases. */
7270 if (cpu_variant & ARM_EXT_XSCALE)
7271 mach = bfd_mach_arm_XScale;
7272 else if (cpu_variant & ARM_EXT_V5E)
7273 mach = bfd_mach_arm_5TE;
7274 else if (cpu_variant & ARM_EXT_V5)
7276 if (cpu_variant & ARM_EXT_THUMB)
7277 mach = bfd_mach_arm_5T;
7279 mach = bfd_mach_arm_5;
7281 else if (cpu_variant & ARM_EXT_HALFWORD)
7283 if (cpu_variant & ARM_EXT_THUMB)
7284 mach = bfd_mach_arm_4T;
7286 mach = bfd_mach_arm_4;
7288 else if (cpu_variant & ARM_EXT_LONGMUL)
7289 mach = bfd_mach_arm_3M;
7291 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
7294 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
7295 for use in the a.out file, and stores them in the array pointed to by buf.
7296 This knows about the endian-ness of the target machine and does
7297 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
7298 2 (short) and 4 (long) Floating numbers are put out as a series of
7299 LITTLENUMS (shorts, here at least). */
7302 md_number_to_chars (buf, val, n)
7307 if (target_big_endian)
7308 number_to_chars_bigendian (buf, val, n);
7310 number_to_chars_littleendian (buf, val, n);
7314 md_chars_to_number (buf, n)
7319 unsigned char * where = (unsigned char *) buf;
7321 if (target_big_endian)
7326 result |= (*where++ & 255);
7334 result |= (where[n] & 255);
7341 /* Turn a string in input_line_pointer into a floating point constant
7342 of type TYPE, and store the appropriate bytes in *LITP. The number
7343 of LITTLENUMS emitted is stored in *SIZEP. An error message is
7344 returned, or NULL on OK.
7346 Note that fp constants aren't represent in the normal way on the ARM.
7347 In big endian mode, things are as expected. However, in little endian
7348 mode fp constants are big-endian word-wise, and little-endian byte-wise
7349 within the words. For example, (double) 1.1 in big endian mode is
7350 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
7351 the byte sequence 99 99 f1 3f 9a 99 99 99.
7353 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
7356 md_atof (type, litP, sizeP)
7362 LITTLENUM_TYPE words[MAX_LITTLENUMS];
7394 return _("Bad call to MD_ATOF()");
7397 t = atof_ieee (input_line_pointer, type, words);
7399 input_line_pointer = t;
7402 if (target_big_endian)
7404 for (i = 0; i < prec; i++)
7406 md_number_to_chars (litP, (valueT) words[i], 2);
7412 /* For a 4 byte float the order of elements in `words' is 1 0. For an
7413 8 byte float the order is 1 0 3 2. */
7414 for (i = 0; i < prec; i += 2)
7416 md_number_to_chars (litP, (valueT) words[i + 1], 2);
7417 md_number_to_chars (litP + 2, (valueT) words[i], 2);
7425 /* The knowledge of the PC's pipeline offset is built into the insns
7429 md_pcrel_from (fixP)
7433 && S_GET_SEGMENT (fixP->fx_addsy) == undefined_section
7434 && fixP->fx_subsy == NULL)
7437 if (fixP->fx_pcrel && (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_ADD))
7439 /* PC relative addressing on the Thumb is slightly odd
7440 as the bottom two bits of the PC are forced to zero
7441 for the calculation. */
7442 return (fixP->fx_where + fixP->fx_frag->fr_address) & ~3;
7446 /* The pattern was adjusted to accomodate CE's off-by-one fixups,
7447 so we un-adjust here to compensate for the accomodation. */
7448 return fixP->fx_where + fixP->fx_frag->fr_address + 8;
7450 return fixP->fx_where + fixP->fx_frag->fr_address;
7454 /* Round up a section size to the appropriate boundary. */
7457 md_section_align (segment, size)
7458 segT segment ATTRIBUTE_UNUSED;
7464 /* Round all sects to multiple of 4. */
7465 return (size + 3) & ~3;
7469 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
7470 Otherwise we have no need to default values of symbols. */
7473 md_undefined_symbol (name)
7474 char * name ATTRIBUTE_UNUSED;
7477 if (name[0] == '_' && name[1] == 'G'
7478 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
7482 if (symbol_find (name))
7483 as_bad ("GOT already in the symbol table");
7485 GOT_symbol = symbol_new (name, undefined_section,
7486 (valueT) 0, & zero_address_frag);
7496 /* arm_reg_parse () := if it looks like a register, return its token and
7497 advance the pointer. */
7501 register char ** ccp;
7503 char * start = * ccp;
7506 struct reg_entry * reg;
7508 #ifdef REGISTER_PREFIX
7509 if (*start != REGISTER_PREFIX)
7514 #ifdef OPTIONAL_REGISTER_PREFIX
7515 if (*p == OPTIONAL_REGISTER_PREFIX)
7519 if (!ISALPHA (*p) || !is_name_beginner (*p))
7523 while (ISALPHA (c) || ISDIGIT (c) || c == '_')
7527 reg = (struct reg_entry *) hash_find (arm_reg_hsh, start);
7540 md_apply_fix3 (fixP, val, seg)
7545 offsetT value = * val;
7547 unsigned int newimm;
7550 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
7551 arm_fix_data * arm_data = (arm_fix_data *) fixP->tc_fix_data;
7553 assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
7555 /* Note whether this will delete the relocation. */
7557 /* Patch from REarnshaw to JDavis (disabled for the moment, since it
7558 doesn't work fully.) */
7559 if ((fixP->fx_addsy == 0 || symbol_constant_p (fixP->fx_addsy))
7562 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
7566 /* If this symbol is in a different section then we need to leave it for
7567 the linker to deal with. Unfortunately, md_pcrel_from can't tell,
7568 so we have to undo it's effects here. */
7571 if (fixP->fx_addsy != NULL
7572 && S_IS_DEFINED (fixP->fx_addsy)
7573 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
7576 && (fixP->fx_r_type == BFD_RELOC_ARM_PCREL_BRANCH
7577 || fixP->fx_r_type == BFD_RELOC_ARM_PCREL_BLX
7581 value += md_pcrel_from (fixP);
7585 /* Remember value for emit_reloc. */
7586 fixP->fx_addnumber = value;
7588 switch (fixP->fx_r_type)
7590 case BFD_RELOC_ARM_IMMEDIATE:
7591 newimm = validate_immediate (value);
7592 temp = md_chars_to_number (buf, INSN_SIZE);
7594 /* If the instruction will fail, see if we can fix things up by
7595 changing the opcode. */
7596 if (newimm == (unsigned int) FAIL
7597 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
7599 as_bad_where (fixP->fx_file, fixP->fx_line,
7600 _("invalid constant (%lx) after fixup"),
7601 (unsigned long) value);
7605 newimm |= (temp & 0xfffff000);
7606 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
7609 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
7611 unsigned int highpart = 0;
7612 unsigned int newinsn = 0xe1a00000; /* nop. */
7613 newimm = validate_immediate (value);
7614 temp = md_chars_to_number (buf, INSN_SIZE);
7616 /* If the instruction will fail, see if we can fix things up by
7617 changing the opcode. */
7618 if (newimm == (unsigned int) FAIL
7619 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
7621 /* No ? OK - try using two ADD instructions to generate
7623 newimm = validate_immediate_twopart (value, & highpart);
7625 /* Yes - then make sure that the second instruction is
7627 if (newimm != (unsigned int) FAIL)
7629 /* Still No ? Try using a negated value. */
7630 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
7631 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
7632 /* Otherwise - give up. */
7635 as_bad_where (fixP->fx_file, fixP->fx_line,
7636 _("Unable to compute ADRL instructions for PC offset of 0x%lx"),
7641 /* Replace the first operand in the 2nd instruction (which
7642 is the PC) with the destination register. We have
7643 already added in the PC in the first instruction and we
7644 do not want to do it again. */
7645 newinsn &= ~ 0xf0000;
7646 newinsn |= ((newinsn & 0x0f000) << 4);
7649 newimm |= (temp & 0xfffff000);
7650 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
7652 highpart |= (newinsn & 0xfffff000);
7653 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
7657 case BFD_RELOC_ARM_OFFSET_IMM:
7663 if (validate_offset_imm (value, 0) == FAIL)
7665 as_bad_where (fixP->fx_file, fixP->fx_line,
7666 _("bad immediate value for offset (%ld)"),
7671 newval = md_chars_to_number (buf, INSN_SIZE);
7672 newval &= 0xff7ff000;
7673 newval |= value | (sign ? INDEX_UP : 0);
7674 md_number_to_chars (buf, newval, INSN_SIZE);
7677 case BFD_RELOC_ARM_OFFSET_IMM8:
7678 case BFD_RELOC_ARM_HWLITERAL:
7684 if (validate_offset_imm (value, 1) == FAIL)
7686 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
7687 as_bad_where (fixP->fx_file, fixP->fx_line,
7688 _("invalid literal constant: pool needs to be closer"));
7690 as_bad (_("bad immediate value for half-word offset (%ld)"),
7695 newval = md_chars_to_number (buf, INSN_SIZE);
7696 newval &= 0xff7ff0f0;
7697 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
7698 md_number_to_chars (buf, newval, INSN_SIZE);
7701 case BFD_RELOC_ARM_LITERAL:
7707 if (validate_offset_imm (value, 0) == FAIL)
7709 as_bad_where (fixP->fx_file, fixP->fx_line,
7710 _("invalid literal constant: pool needs to be closer"));
7714 newval = md_chars_to_number (buf, INSN_SIZE);
7715 newval &= 0xff7ff000;
7716 newval |= value | (sign ? INDEX_UP : 0);
7717 md_number_to_chars (buf, newval, INSN_SIZE);
7720 case BFD_RELOC_ARM_SHIFT_IMM:
7721 newval = md_chars_to_number (buf, INSN_SIZE);
7722 if (((unsigned long) value) > 32
7724 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
7726 as_bad_where (fixP->fx_file, fixP->fx_line,
7727 _("shift expression is too large"));
7732 /* Shifts of zero must be done as lsl. */
7734 else if (value == 32)
7736 newval &= 0xfffff07f;
7737 newval |= (value & 0x1f) << 7;
7738 md_number_to_chars (buf, newval, INSN_SIZE);
7741 case BFD_RELOC_ARM_SWI:
7742 if (arm_data->thumb_mode)
7744 if (((unsigned long) value) > 0xff)
7745 as_bad_where (fixP->fx_file, fixP->fx_line,
7746 _("Invalid swi expression"));
7747 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xff00;
7749 md_number_to_chars (buf, newval, THUMB_SIZE);
7753 if (((unsigned long) value) > 0x00ffffff)
7754 as_bad_where (fixP->fx_file, fixP->fx_line,
7755 _("Invalid swi expression"));
7756 newval = md_chars_to_number (buf, INSN_SIZE) & 0xff000000;
7758 md_number_to_chars (buf, newval, INSN_SIZE);
7762 case BFD_RELOC_ARM_MULTI:
7763 if (((unsigned long) value) > 0xffff)
7764 as_bad_where (fixP->fx_file, fixP->fx_line,
7765 _("Invalid expression in load/store multiple"));
7766 newval = value | md_chars_to_number (buf, INSN_SIZE);
7767 md_number_to_chars (buf, newval, INSN_SIZE);
7770 case BFD_RELOC_ARM_PCREL_BRANCH:
7771 newval = md_chars_to_number (buf, INSN_SIZE);
7773 /* Sign-extend a 24-bit number. */
7774 #define SEXT24(x) ((((x) & 0xffffff) ^ (~ 0x7fffff)) + 0x800000)
7778 value = fixP->fx_offset;
7781 /* We are going to store value (shifted right by two) in the
7782 instruction, in a 24 bit, signed field. Thus we need to check
7783 that none of the top 8 bits of the shifted value (top 7 bits of
7784 the unshifted, unsigned value) are set, or that they are all set. */
7785 if ((value & ~ ((offsetT) 0x1ffffff)) != 0
7786 && ((value & ~ ((offsetT) 0x1ffffff)) != ~ ((offsetT) 0x1ffffff)))
7789 /* Normally we would be stuck at this point, since we cannot store
7790 the absolute address that is the destination of the branch in the
7791 24 bits of the branch instruction. If however, we happen to know
7792 that the destination of the branch is in the same section as the
7793 branch instruciton itself, then we can compute the relocation for
7794 ourselves and not have to bother the linker with it.
7796 FIXME: The tests for OBJ_ELF and ! target_oabi are only here
7797 because I have not worked out how to do this for OBJ_COFF or
7800 && fixP->fx_addsy != NULL
7801 && S_IS_DEFINED (fixP->fx_addsy)
7802 && S_GET_SEGMENT (fixP->fx_addsy) == seg)
7804 /* Get pc relative value to go into the branch. */
7807 /* Permit a backward branch provided that enough bits
7808 are set. Allow a forwards branch, provided that
7809 enough bits are clear. */
7810 if ( (value & ~ ((offsetT) 0x1ffffff)) == ~ ((offsetT) 0x1ffffff)
7811 || (value & ~ ((offsetT) 0x1ffffff)) == 0)
7815 if (! fixP->fx_done)
7817 as_bad_where (fixP->fx_file, fixP->fx_line,
7818 _("gas can't handle same-section branch dest >= 0x04000000"));
7822 value += SEXT24 (newval);
7824 if ( (value & ~ ((offsetT) 0xffffff)) != 0
7825 && ((value & ~ ((offsetT) 0xffffff)) != ~ ((offsetT) 0xffffff)))
7826 as_bad_where (fixP->fx_file, fixP->fx_line,
7827 _("out of range branch"));
7829 newval = (value & 0x00ffffff) | (newval & 0xff000000);
7830 md_number_to_chars (buf, newval, INSN_SIZE);
7833 case BFD_RELOC_ARM_PCREL_BLX:
7836 newval = md_chars_to_number (buf, INSN_SIZE);
7840 value = fixP->fx_offset;
7842 hbit = (value >> 1) & 1;
7843 value = (value >> 2) & 0x00ffffff;
7844 value = (value + (newval & 0x00ffffff)) & 0x00ffffff;
7845 newval = value | (newval & 0xfe000000) | (hbit << 24);
7846 md_number_to_chars (buf, newval, INSN_SIZE);
7850 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
7851 newval = md_chars_to_number (buf, THUMB_SIZE);
7853 addressT diff = (newval & 0xff) << 1;
7858 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
7859 as_bad_where (fixP->fx_file, fixP->fx_line,
7860 _("Branch out of range"));
7861 newval = (newval & 0xff00) | ((value & 0x1ff) >> 1);
7863 md_number_to_chars (buf, newval, THUMB_SIZE);
7866 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
7867 newval = md_chars_to_number (buf, THUMB_SIZE);
7869 addressT diff = (newval & 0x7ff) << 1;
7874 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
7875 as_bad_where (fixP->fx_file, fixP->fx_line,
7876 _("Branch out of range"));
7877 newval = (newval & 0xf800) | ((value & 0xfff) >> 1);
7879 md_number_to_chars (buf, newval, THUMB_SIZE);
7882 case BFD_RELOC_THUMB_PCREL_BLX:
7883 case BFD_RELOC_THUMB_PCREL_BRANCH23:
7888 newval = md_chars_to_number (buf, THUMB_SIZE);
7889 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
7890 diff = ((newval & 0x7ff) << 12) | ((newval2 & 0x7ff) << 1);
7891 if (diff & 0x400000)
7894 value = fixP->fx_offset;
7897 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
7898 as_bad_where (fixP->fx_file, fixP->fx_line,
7899 _("Branch with link out of range"));
7901 newval = (newval & 0xf800) | ((value & 0x7fffff) >> 12);
7902 newval2 = (newval2 & 0xf800) | ((value & 0xfff) >> 1);
7903 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
7904 /* Remove bit zero of the adjusted offset. Bit zero can only be
7905 set if the upper insn is at a half-word boundary, since the
7906 destination address, an ARM instruction, must always be on a
7907 word boundary. The semantics of the BLX (1) instruction, however,
7908 are that bit zero in the offset must always be zero, and the
7909 corresponding bit one in the target address will be set from bit
7910 one of the source address. */
7912 md_number_to_chars (buf, newval, THUMB_SIZE);
7913 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
7918 if (fixP->fx_done || fixP->fx_pcrel)
7919 md_number_to_chars (buf, value, 1);
7921 else if (!target_oabi)
7923 value = fixP->fx_offset;
7924 md_number_to_chars (buf, value, 1);
7930 if (fixP->fx_done || fixP->fx_pcrel)
7931 md_number_to_chars (buf, value, 2);
7933 else if (!target_oabi)
7935 value = fixP->fx_offset;
7936 md_number_to_chars (buf, value, 2);
7942 case BFD_RELOC_ARM_GOT32:
7943 case BFD_RELOC_ARM_GOTOFF:
7944 md_number_to_chars (buf, 0, 4);
7950 if (fixP->fx_done || fixP->fx_pcrel)
7951 md_number_to_chars (buf, value, 4);
7953 else if (!target_oabi)
7955 value = fixP->fx_offset;
7956 md_number_to_chars (buf, value, 4);
7962 case BFD_RELOC_ARM_PLT32:
7963 /* It appears the instruction is fully prepared at this point. */
7967 case BFD_RELOC_ARM_GOTPC:
7968 md_number_to_chars (buf, value, 4);
7971 case BFD_RELOC_ARM_CP_OFF_IMM:
7973 if (value < -1023 || value > 1023 || (value & 3))
7974 as_bad_where (fixP->fx_file, fixP->fx_line,
7975 _("Illegal value for co-processor offset"));
7978 newval = md_chars_to_number (buf, INSN_SIZE) & 0xff7fff00;
7979 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
7980 md_number_to_chars (buf, newval, INSN_SIZE);
7983 case BFD_RELOC_ARM_THUMB_OFFSET:
7984 newval = md_chars_to_number (buf, THUMB_SIZE);
7985 /* Exactly what ranges, and where the offset is inserted depends
7986 on the type of instruction, we can establish this from the
7988 switch (newval >> 12)
7990 case 4: /* PC load. */
7991 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
7992 forced to zero for these loads, so we will need to round
7993 up the offset if the instruction address is not word
7994 aligned (since the final address produced must be, and
7995 we can only describe word-aligned immediate offsets). */
7997 if ((fixP->fx_frag->fr_address + fixP->fx_where + value) & 3)
7998 as_bad_where (fixP->fx_file, fixP->fx_line,
7999 _("Invalid offset, target not word aligned (0x%08X)"),
8000 (unsigned int) (fixP->fx_frag->fr_address
8001 + fixP->fx_where + value));
8003 if ((value + 2) & ~0x3fe)
8004 as_bad_where (fixP->fx_file, fixP->fx_line,
8005 _("Invalid offset, value too big (0x%08lX)"), value);
8007 /* Round up, since pc will be rounded down. */
8008 newval |= (value + 2) >> 2;
8011 case 9: /* SP load/store. */
8013 as_bad_where (fixP->fx_file, fixP->fx_line,
8014 _("Invalid offset, value too big (0x%08lX)"), value);
8015 newval |= value >> 2;
8018 case 6: /* Word load/store. */
8020 as_bad_where (fixP->fx_file, fixP->fx_line,
8021 _("Invalid offset, value too big (0x%08lX)"), value);
8022 newval |= value << 4; /* 6 - 2. */
8025 case 7: /* Byte load/store. */
8027 as_bad_where (fixP->fx_file, fixP->fx_line,
8028 _("Invalid offset, value too big (0x%08lX)"), value);
8029 newval |= value << 6;
8032 case 8: /* Halfword load/store. */
8034 as_bad_where (fixP->fx_file, fixP->fx_line,
8035 _("Invalid offset, value too big (0x%08lX)"), value);
8036 newval |= value << 5; /* 6 - 1. */
8040 as_bad_where (fixP->fx_file, fixP->fx_line,
8041 "Unable to process relocation for thumb opcode: %lx",
8042 (unsigned long) newval);
8045 md_number_to_chars (buf, newval, THUMB_SIZE);
8048 case BFD_RELOC_ARM_THUMB_ADD:
8049 /* This is a complicated relocation, since we use it for all of
8050 the following immediate relocations:
8054 9bit ADD/SUB SP word-aligned
8055 10bit ADD PC/SP word-aligned
8057 The type of instruction being processed is encoded in the
8064 newval = md_chars_to_number (buf, THUMB_SIZE);
8066 int rd = (newval >> 4) & 0xf;
8067 int rs = newval & 0xf;
8068 int subtract = newval & 0x8000;
8073 as_bad_where (fixP->fx_file, fixP->fx_line,
8074 _("Invalid immediate for stack address calculation"));
8075 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
8076 newval |= value >> 2;
8078 else if (rs == REG_PC || rs == REG_SP)
8082 as_bad_where (fixP->fx_file, fixP->fx_line,
8083 _("Invalid immediate for address calculation (value = 0x%08lX)"),
8084 (unsigned long) value);
8085 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
8087 newval |= value >> 2;
8092 as_bad_where (fixP->fx_file, fixP->fx_line,
8093 _("Invalid 8bit immediate"));
8094 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
8095 newval |= (rd << 8) | value;
8100 as_bad_where (fixP->fx_file, fixP->fx_line,
8101 _("Invalid 3bit immediate"));
8102 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
8103 newval |= rd | (rs << 3) | (value << 6);
8106 md_number_to_chars (buf, newval, THUMB_SIZE);
8109 case BFD_RELOC_ARM_THUMB_IMM:
8110 newval = md_chars_to_number (buf, THUMB_SIZE);
8111 switch (newval >> 11)
8113 case 0x04: /* 8bit immediate MOV. */
8114 case 0x05: /* 8bit immediate CMP. */
8115 if (value < 0 || value > 255)
8116 as_bad_where (fixP->fx_file, fixP->fx_line,
8117 _("Invalid immediate: %ld is too large"),
8125 md_number_to_chars (buf, newval, THUMB_SIZE);
8128 case BFD_RELOC_ARM_THUMB_SHIFT:
8129 /* 5bit shift value (0..31). */
8130 if (value < 0 || value > 31)
8131 as_bad_where (fixP->fx_file, fixP->fx_line,
8132 _("Illegal Thumb shift value: %ld"), (long) value);
8133 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf03f;
8134 newval |= value << 6;
8135 md_number_to_chars (buf, newval, THUMB_SIZE);
8138 case BFD_RELOC_VTABLE_INHERIT:
8139 case BFD_RELOC_VTABLE_ENTRY:
8143 case BFD_RELOC_NONE:
8145 as_bad_where (fixP->fx_file, fixP->fx_line,
8146 _("Bad relocation fixup type (%d)"), fixP->fx_r_type);
8152 /* Translate internal representation of relocation info to BFD target
8156 tc_gen_reloc (section, fixp)
8157 asection * section ATTRIBUTE_UNUSED;
8161 bfd_reloc_code_real_type code;
8163 reloc = (arelent *) xmalloc (sizeof (arelent));
8165 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
8166 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
8167 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
8169 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
8171 if (fixp->fx_pcrel == 0)
8172 reloc->addend = fixp->fx_offset;
8174 reloc->addend = fixp->fx_offset = reloc->address;
8176 reloc->addend = fixp->fx_offset;
8179 switch (fixp->fx_r_type)
8184 code = BFD_RELOC_8_PCREL;
8191 code = BFD_RELOC_16_PCREL;
8198 code = BFD_RELOC_32_PCREL;
8202 case BFD_RELOC_ARM_PCREL_BRANCH:
8203 case BFD_RELOC_ARM_PCREL_BLX:
8205 case BFD_RELOC_THUMB_PCREL_BRANCH9:
8206 case BFD_RELOC_THUMB_PCREL_BRANCH12:
8207 case BFD_RELOC_THUMB_PCREL_BRANCH23:
8208 case BFD_RELOC_THUMB_PCREL_BLX:
8209 case BFD_RELOC_VTABLE_ENTRY:
8210 case BFD_RELOC_VTABLE_INHERIT:
8211 code = fixp->fx_r_type;
8214 case BFD_RELOC_ARM_LITERAL:
8215 case BFD_RELOC_ARM_HWLITERAL:
8216 /* If this is called then the a literal has been referenced across
8217 a section boundary - possibly due to an implicit dump. */
8218 as_bad_where (fixp->fx_file, fixp->fx_line,
8219 _("Literal referenced across section boundary (Implicit dump?)"));
8223 case BFD_RELOC_ARM_GOT32:
8224 case BFD_RELOC_ARM_GOTOFF:
8225 case BFD_RELOC_ARM_PLT32:
8226 code = fixp->fx_r_type;
8230 case BFD_RELOC_ARM_IMMEDIATE:
8231 as_bad_where (fixp->fx_file, fixp->fx_line,
8232 _("Internal_relocation (type %d) not fixed up (IMMEDIATE)"),
8236 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
8237 as_bad_where (fixp->fx_file, fixp->fx_line,
8238 _("ADRL used for a symbol not defined in the same file"));
8241 case BFD_RELOC_ARM_OFFSET_IMM:
8242 as_bad_where (fixp->fx_file, fixp->fx_line,
8243 _("Internal_relocation (type %d) not fixed up (OFFSET_IMM)"),
8251 switch (fixp->fx_r_type)
8253 case BFD_RELOC_ARM_IMMEDIATE: type = "IMMEDIATE"; break;
8254 case BFD_RELOC_ARM_OFFSET_IMM: type = "OFFSET_IMM"; break;
8255 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
8256 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
8257 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
8258 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
8259 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8260 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
8261 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
8262 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
8263 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
8264 default: type = _("<unknown>"); break;
8266 as_bad_where (fixp->fx_file, fixp->fx_line,
8267 _("Cannot represent %s relocation in this object file format"),
8274 if (code == BFD_RELOC_32_PCREL
8276 && fixp->fx_addsy == GOT_symbol)
8278 code = BFD_RELOC_ARM_GOTPC;
8279 reloc->addend = fixp->fx_offset = reloc->address;
8283 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
8285 if (reloc->howto == NULL)
8287 as_bad_where (fixp->fx_file, fixp->fx_line,
8288 _("Can not represent %s relocation in this object file format"),
8289 bfd_get_reloc_code_name (code));
8293 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
8294 vtable entry to be used in the relocation's section offset. */
8295 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
8296 reloc->address = fixp->fx_offset;
8302 md_estimate_size_before_relax (fragP, segtype)
8303 fragS * fragP ATTRIBUTE_UNUSED;
8304 segT segtype ATTRIBUTE_UNUSED;
8306 as_fatal (_("md_estimate_size_before_relax\n"));
8311 output_inst PARAMS ((void))
8317 as_bad (inst.error);
8321 to = frag_more (inst.size);
8323 if (thumb_mode && (inst.size > THUMB_SIZE))
8325 assert (inst.size == (2 * THUMB_SIZE));
8326 md_number_to_chars (to, inst.instruction >> 16, THUMB_SIZE);
8327 md_number_to_chars (to + THUMB_SIZE, inst.instruction, THUMB_SIZE);
8329 else if (inst.size > INSN_SIZE)
8331 assert (inst.size == (2 * INSN_SIZE));
8332 md_number_to_chars (to, inst.instruction, INSN_SIZE);
8333 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
8336 md_number_to_chars (to, inst.instruction, inst.size);
8338 if (inst.reloc.type != BFD_RELOC_NONE)
8339 fix_new_arm (frag_now, to - frag_now->fr_literal,
8340 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
8344 dwarf2_emit_insn (inst.size);
8357 /* Align the instruction.
8358 This may not be the right thing to do but ... */
8362 listing_prev_line (); /* Defined in listing.h. */
8364 /* Align the previous label if needed. */
8365 if (last_label_seen != NULL)
8367 symbol_set_frag (last_label_seen, frag_now);
8368 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
8369 S_SET_SEGMENT (last_label_seen, now_seg);
8372 memset (&inst, '\0', sizeof (inst));
8373 inst.reloc.type = BFD_RELOC_NONE;
8375 skip_whitespace (str);
8377 /* Scan up to the end of the op-code, which must end in white space or
8379 for (start = p = str; *p != '\0'; p++)
8385 as_bad (_("No operator -- statement `%s'\n"), str);
8391 const struct thumb_opcode * opcode;
8395 opcode = (const struct thumb_opcode *) hash_find (arm_tops_hsh, str);
8400 /* Check that this instruction is supported for this CPU. */
8401 if (thumb_mode == 1 && (opcode->variants & cpu_variant) == 0)
8403 as_bad (_("selected processor does not support this opcode"));
8407 inst.instruction = opcode->value;
8408 inst.size = opcode->size;
8409 (*opcode->parms) (p);
8416 const struct asm_opcode * opcode;
8417 unsigned long cond_code;
8419 inst.size = INSN_SIZE;
8420 /* P now points to the end of the opcode, probably white space, but we
8421 have to break the opcode up in case it contains condionals and flags;
8422 keep trying with progressively smaller basic instructions until one
8423 matches, or we run out of opcode. */
8424 q = (p - str > LONGEST_INST) ? str + LONGEST_INST : p;
8426 for (; q != str; q--)
8431 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, str);
8434 if (opcode && opcode->template)
8436 unsigned long flag_bits = 0;
8439 /* Check that this instruction is supported for this CPU. */
8440 if ((opcode->variants & cpu_variant) == 0)
8443 inst.instruction = opcode->value;
8444 if (q == p) /* Just a simple opcode. */
8446 if (opcode->comp_suffix)
8448 if (*opcode->comp_suffix != '\0')
8449 as_bad (_("Opcode `%s' must have suffix from list: <%s>"),
8450 str, opcode->comp_suffix);
8452 /* Not a conditional instruction. */
8453 (*opcode->parms) (q, 0);
8457 /* A conditional instruction with default condition. */
8458 inst.instruction |= COND_ALWAYS;
8459 (*opcode->parms) (q, 0);
8465 /* Not just a simple opcode. Check if extra is a
8470 const struct asm_cond *cond;
8474 cond = (const struct asm_cond *) hash_find (arm_cond_hsh, r);
8478 if (cond->value == 0xf0000000)
8480 _("Warning: Use of the 'nv' conditional is deprecated\n"));
8482 cond_code = cond->value;
8486 cond_code = COND_ALWAYS;
8489 cond_code = COND_ALWAYS;
8491 /* Apply the conditional, or complain it's not allowed. */
8492 if (opcode->comp_suffix && *opcode->comp_suffix == '\0')
8494 /* Instruction isn't conditional. */
8495 if (cond_code != COND_ALWAYS)
8497 as_bad (_("Opcode `%s' is unconditional\n"), str);
8502 /* Instruction is conditional: set the condition into it. */
8503 inst.instruction |= cond_code;
8505 /* If there is a compulsory suffix, it should come here
8506 before any optional flags. */
8507 if (opcode->comp_suffix && *opcode->comp_suffix != '\0')
8509 const char *s = opcode->comp_suffix;
8521 as_bad (_("Opcode `%s' must have suffix from <%s>\n"),
8522 str, opcode->comp_suffix);
8529 /* The remainder, if any should now be flags for the instruction;
8530 Scan these checking each one found with the opcode. */
8534 const struct asm_flg *flag = opcode->flags;
8543 for (flagno = 0; flag[flagno].template; flagno++)
8545 if (streq (r, flag[flagno].template))
8547 flag_bits |= flag[flagno].set_bits;
8553 if (! flag[flagno].template)
8560 (*opcode->parms) (p, flag_bits);
8570 /* It wasn't an instruction, but it might be a register alias of the form
8573 skip_whitespace (q);
8578 if (*q && !strncmp (q, ".req ", 4))
8584 #ifdef IGNORE_OPCODE_CASE
8585 str = original_case_string;
8590 skip_whitespace (q);
8592 for (r = q; *r != '\0'; r++)
8602 regnum = arm_reg_parse (& q);
8605 reg = arm_reg_parse (& str);
8610 insert_reg_alias (str, regnum);
8612 as_warn (_("register '%s' does not exist\n"), q);
8614 else if (regnum != FAIL)
8617 as_warn (_("ignoring redefinition of register alias '%s'"),
8620 /* Do not warn about redefinitions to the same alias. */
8623 as_warn (_("ignoring redefinition of register alias '%s' to non-existant register '%s'"),
8627 as_warn (_("ignoring incomplete .req pseuso op"));
8634 as_bad (_("bad instruction `%s'"), start);
8638 Invocation line includes a switch not recognized by the base assembler.
8639 See if it's a processor-specific option. These are:
8640 Cpu variants, the arm part is optional:
8641 -m[arm]1 Currently not supported.
8642 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
8643 -m[arm]3 Arm 3 processor
8644 -m[arm]6[xx], Arm 6 processors
8645 -m[arm]7[xx][t][[d]m] Arm 7 processors
8646 -m[arm]8[10] Arm 8 processors
8647 -m[arm]9[20][tdmi] Arm 9 processors
8648 -marm9e Allow Cirrus/DSP instructions
8649 -mstrongarm[110[0]] StrongARM processors
8650 -mxscale XScale processors
8651 -m[arm]v[2345[t[e]]] Arm architectures
8652 -mall All (except the ARM1)
8654 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
8655 -mfpe-old (No float load/store multiples)
8656 -mno-fpu Disable all floating point instructions
8657 Run-time endian selection:
8659 -EL little endian cpu
8660 ARM Procedure Calling Standard:
8661 -mapcs-32 32 bit APCS
8662 -mapcs-26 26 bit APCS
8663 -mapcs-float Pass floats in float regs
8664 -mapcs-reentrant Position independent code
8665 -mthumb-interwork Code supports Arm/Thumb interworking
8666 -matpcs ARM/Thumb Procedure Call Standard
8667 -moabi Old ELF ABI */
8669 const char * md_shortopts = "m:k";
8671 struct option md_longopts[] =
8673 #ifdef ARM_BI_ENDIAN
8674 #define OPTION_EB (OPTION_MD_BASE + 0)
8675 {"EB", no_argument, NULL, OPTION_EB},
8676 #define OPTION_EL (OPTION_MD_BASE + 1)
8677 {"EL", no_argument, NULL, OPTION_EL},
8679 #define OPTION_OABI (OPTION_MD_BASE +2)
8680 {"oabi", no_argument, NULL, OPTION_OABI},
8683 {NULL, no_argument, NULL, 0}
8686 size_t md_longopts_size = sizeof (md_longopts);
8689 md_parse_option (c, arg)
8697 #ifdef ARM_BI_ENDIAN
8699 target_big_endian = 1;
8702 target_big_endian = 0;
8710 if (streq (str, "fpa10"))
8711 cpu_variant = (cpu_variant & ~FPU_ALL) | FPU_FPA10;
8712 else if (streq (str, "fpa11"))
8713 cpu_variant = (cpu_variant & ~FPU_ALL) | FPU_FPA11;
8714 else if (streq (str, "fpe-old"))
8715 cpu_variant = (cpu_variant & ~FPU_ALL) | FPU_CORE;
8721 if (streq (str, "no-fpu"))
8722 cpu_variant &= ~FPU_ALL;
8727 if (streq (str, "oabi"))
8733 /* Limit assembler to generating only Thumb instructions: */
8734 if (streq (str, "thumb"))
8736 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_EXT_THUMB;
8737 cpu_variant = (cpu_variant & ~FPU_ALL) | FPU_NONE;
8740 else if (streq (str, "thumb-interwork"))
8742 if ((cpu_variant & ARM_EXT_THUMB) == 0)
8743 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_ARCH_V4T;
8744 #if defined OBJ_COFF || defined OBJ_ELF
8745 support_interwork = true;
8753 if (streq (str, "all"))
8755 cpu_variant = ARM_ALL | FPU_ALL;
8758 #if defined OBJ_COFF || defined OBJ_ELF
8759 if (! strncmp (str, "apcs-", 5))
8761 /* GCC passes on all command line options starting "-mapcs-..."
8762 to us, so we must parse them here. */
8766 if (streq (str, "32"))
8768 uses_apcs_26 = false;
8771 else if (streq (str, "26"))
8773 uses_apcs_26 = true;
8776 else if (streq (str, "frame"))
8778 /* Stack frames are being generated - does not affect
8782 else if (streq (str, "stack-check"))
8784 /* Stack checking is being performed - does not affect
8785 linkage, but does require that the functions
8786 __rt_stkovf_split_small and __rt_stkovf_split_big be
8787 present in the final link. */
8791 else if (streq (str, "float"))
8793 /* Floating point arguments are being passed in the floating
8794 point registers. This does affect linking, since this
8795 version of the APCS is incompatible with the version that
8796 passes floating points in the integer registers. */
8798 uses_apcs_float = true;
8801 else if (streq (str, "reentrant"))
8803 /* Reentrant code has been generated. This does affect
8804 linking, since there is no point in linking reentrant/
8805 position independent code with absolute position code. */
8810 as_bad (_("Unrecognised APCS switch -m%s"), arg);
8814 if (! strcmp (str, "atpcs"))
8820 /* Strip off optional "arm". */
8821 if (! strncmp (str, "arm", 3))
8827 if (streq (str, "1"))
8828 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_1;
8834 if (streq (str, "2"))
8835 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_2;
8836 else if (streq (str, "250"))
8837 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_250;
8843 if (streq (str, "3"))
8844 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_3;
8850 switch (strtol (str, NULL, 10))
8857 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_6;
8865 /* Eat the processor name. */
8866 switch (strtol (str, & str, 10))
8879 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_7;
8885 cpu_variant |= ARM_ARCH_V4T;
8889 cpu_variant |= ARM_EXT_LONGMUL;
8892 case 'f': /* fe => fp enabled cpu. */
8898 case 'c': /* Left over from 710c processor name. */
8899 case 'd': /* Debug. */
8900 case 'i': /* Embedded ICE. */
8901 /* Included for completeness in ARM processor naming. */
8911 if (streq (str, "8") || streq (str, "810"))
8912 cpu_variant = (cpu_variant & ~ARM_ANY)
8913 | ARM_8 | ARM_ARCH_V4;
8919 if (streq (str, "9"))
8920 cpu_variant = (cpu_variant & ~ARM_ANY)
8921 | ARM_9 | ARM_ARCH_V4T;
8922 else if (streq (str, "920"))
8923 cpu_variant = (cpu_variant & ~ARM_ANY)
8924 | ARM_9 | ARM_ARCH_V4;
8925 else if (streq (str, "920t"))
8926 cpu_variant = (cpu_variant & ~ARM_ANY)
8927 | ARM_9 | ARM_ARCH_V4T;
8928 else if (streq (str, "9tdmi"))
8929 cpu_variant = (cpu_variant & ~ARM_ANY)
8930 | ARM_9 | ARM_ARCH_V4T;
8931 else if (streq (str, "9e"))
8932 cpu_variant = (cpu_variant & ~ARM_ANY)
8933 | ARM_9 | ARM_ARCH_V4T | ARM_EXT_MAVERICK;
8939 if (streq (str, "strongarm")
8940 || streq (str, "strongarm110")
8941 || streq (str, "strongarm1100"))
8942 cpu_variant = (cpu_variant & ~ARM_ANY)
8943 | ARM_8 | ARM_ARCH_V4;
8949 if (streq (str, "xscale"))
8950 cpu_variant = ARM_9 | ARM_ARCH_XSCALE;
8956 /* Select variant based on architecture rather than
8964 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_3;
8967 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_2;
8970 as_bad (_("Invalid architecture variant -m%s"), arg);
8976 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_7;
8980 case 'm': cpu_variant |= ARM_EXT_LONGMUL; break;
8983 as_bad (_("Invalid architecture variant -m%s"), arg);
8989 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_7 | ARM_ARCH_V4;
8993 case 't': cpu_variant |= ARM_EXT_THUMB; break;
8996 as_bad (_("Invalid architecture variant -m%s"), arg);
9002 cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_9 | ARM_ARCH_V5;
9005 case 't': cpu_variant |= ARM_EXT_THUMB; break;
9006 case 'e': cpu_variant |= ARM_EXT_V5E; break;
9009 as_bad (_("Invalid architecture variant -m%s"), arg);
9015 as_bad (_("Invalid architecture variant -m%s"), arg);
9022 as_bad (_("Invalid processor variant -m%s"), arg);
9028 #if defined OBJ_ELF || defined OBJ_COFF
9046 ARM Specific Assembler Options:\n\
9047 -m[arm][<processor name>] select processor variant\n\
9048 -m[arm]v[2|2a|3|3m|4|4t|5[t][e]] select architecture variant\n\
9049 -marm9e allow Cirrus/DSP instructions\n\
9050 -mthumb only allow Thumb instructions\n\
9051 -mthumb-interwork mark the assembled code as supporting interworking\n\
9052 -mall allow any instruction\n\
9053 -mfpa10, -mfpa11 select floating point architecture\n\
9054 -mfpe-old don't allow floating-point multiple instructions\n\
9055 -mno-fpu don't allow any floating-point instructions.\n\
9056 -k generate PIC code.\n"));
9057 #if defined OBJ_COFF || defined OBJ_ELF
9059 -mapcs-32, -mapcs-26 specify which ARM Procedure Calling Standard to use\n\
9060 -matpcs use ARM/Thumb Procedure Calling Standard\n\
9061 -mapcs-float floating point args are passed in FP regs\n\
9062 -mapcs-reentrant the code is position independent/reentrant\n"));
9066 -moabi support the old ELF ABI\n"));
9068 #ifdef ARM_BI_ENDIAN
9070 -EB assemble code for a big endian cpu\n\
9071 -EL assemble code for a little endian cpu\n"));
9075 /* We need to be able to fix up arbitrary expressions in some statements.
9076 This is so that we can handle symbols that are an arbitrary distance from
9077 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
9078 which returns part of an address in a form which will be valid for
9079 a data instruction. We do this by pushing the expression into a symbol
9080 in the expr_section, and creating a fix for that. */
9083 fix_new_arm (frag, where, size, exp, pc_rel, reloc)
9092 arm_fix_data * arm_data;
9100 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
9104 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
9109 /* Mark whether the fix is to a THUMB instruction, or an ARM
9111 arm_data = (arm_fix_data *) obstack_alloc (& notes, sizeof (arm_fix_data));
9112 new_fix->tc_fix_data = (PTR) arm_data;
9113 arm_data->thumb_mode = thumb_mode;
9118 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
9121 cons_fix_new_arm (frag, where, size, exp)
9127 bfd_reloc_code_real_type type;
9131 FIXME: @@ Should look at CPU word size. */
9138 type = BFD_RELOC_16;
9142 type = BFD_RELOC_32;
9145 type = BFD_RELOC_64;
9149 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
9152 /* A good place to do this, although this was probably not intended
9153 for this kind of use. We need to dump the literal pool before
9154 references are made to a null symbol pointer. */
9159 if (current_poolP == NULL)
9162 /* Put it at the end of text section. */
9163 subseg_set (text_section, 0);
9165 listing_prev_line ();
9169 arm_start_line_hook ()
9171 last_label_seen = NULL;
9175 arm_frob_label (sym)
9178 last_label_seen = sym;
9180 ARM_SET_THUMB (sym, thumb_mode);
9182 #if defined OBJ_COFF || defined OBJ_ELF
9183 ARM_SET_INTERWORK (sym, support_interwork);
9186 /* Note - do not allow local symbols (.Lxxx) to be labeled
9187 as Thumb functions. This is because these labels, whilst
9188 they exist inside Thumb code, are not the entry points for
9189 possible ARM->Thumb calls. Also, these labels can be used
9190 as part of a computed goto or switch statement. eg gcc
9191 can generate code that looks like this:
9203 The first instruction loads the address of the jump table.
9204 The second instruction converts a table index into a byte offset.
9205 The third instruction gets the jump address out of the table.
9206 The fourth instruction performs the jump.
9208 If the address stored at .Laaa is that of a symbol which has the
9209 Thumb_Func bit set, then the linker will arrange for this address
9210 to have the bottom bit set, which in turn would mean that the
9211 address computation performed by the third instruction would end
9212 up with the bottom bit set. Since the ARM is capable of unaligned
9213 word loads, the instruction would then load the incorrect address
9214 out of the jump table, and chaos would ensue. */
9215 if (label_is_thumb_function_name
9216 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
9217 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
9219 /* When the address of a Thumb function is taken the bottom
9220 bit of that address should be set. This will allow
9221 interworking between Arm and Thumb functions to work
9224 THUMB_SET_FUNC (sym, 1);
9226 label_is_thumb_function_name = false;
9230 /* Adjust the symbol table. This marks Thumb symbols as distinct from
9234 arm_adjust_symtab ()
9239 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
9241 if (ARM_IS_THUMB (sym))
9243 if (THUMB_IS_FUNC (sym))
9245 /* Mark the symbol as a Thumb function. */
9246 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
9247 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
9248 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
9250 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
9251 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
9253 as_bad (_("%s: unexpected function type: %d"),
9254 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
9256 else switch (S_GET_STORAGE_CLASS (sym))
9259 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
9262 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
9265 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
9273 if (ARM_IS_INTERWORK (sym))
9274 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
9281 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
9283 if (ARM_IS_THUMB (sym))
9285 elf_symbol_type * elf_sym;
9287 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
9288 bind = ELF_ST_BIND (elf_sym);
9290 /* If it's a .thumb_func, declare it as so,
9291 otherwise tag label as .code 16. */
9292 if (THUMB_IS_FUNC (sym))
9293 elf_sym->internal_elf_sym.st_info =
9294 ELF_ST_INFO (bind, STT_ARM_TFUNC);
9296 elf_sym->internal_elf_sym.st_info =
9297 ELF_ST_INFO (bind, STT_ARM_16BIT);
9306 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
9308 *input_line_pointer = '/';
9309 input_line_pointer += 5;
9310 *input_line_pointer = 0;
9318 arm_canonicalize_symbol_name (name)
9323 if (thumb_mode && (len = strlen (name)) > 5
9324 && streq (name + len - 5, "/data"))
9325 *(name + len - 5) = 0;
9331 arm_validate_fix (fixP)
9334 /* If the destination of the branch is a defined symbol which does not have
9335 the THUMB_FUNC attribute, then we must be calling a function which has
9336 the (interfacearm) attribute. We look for the Thumb entry point to that
9337 function and change the branch to refer to that function instead. */
9338 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
9339 && fixP->fx_addsy != NULL
9340 && S_IS_DEFINED (fixP->fx_addsy)
9341 && ! THUMB_IS_FUNC (fixP->fx_addsy))
9343 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
9351 /* This is a little hack to help the gas/arm/adrl.s test. It prevents
9352 local labels from being added to the output symbol table when they
9353 are used with the ADRL pseudo op. The ADRL relocation should always
9354 be resolved before the binbary is emitted, so it is safe to say that
9355 it is adjustable. */
9358 arm_fix_adjustable (fixP)
9361 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
9367 /* Relocations against Thumb function names must be left unadjusted,
9368 so that the linker can use this information to correctly set the
9369 bottom bit of their addresses. The MIPS version of this function
9370 also prevents relocations that are mips-16 specific, but I do not
9371 know why it does this.
9374 There is one other problem that ought to be addressed here, but
9375 which currently is not: Taking the address of a label (rather
9376 than a function) and then later jumping to that address. Such
9377 addresses also ought to have their bottom bit set (assuming that
9378 they reside in Thumb code), but at the moment they will not. */
9381 arm_fix_adjustable (fixP)
9384 if (fixP->fx_addsy == NULL)
9387 /* Prevent all adjustments to global symbols. */
9388 if (S_IS_EXTERN (fixP->fx_addsy))
9391 if (S_IS_WEAK (fixP->fx_addsy))
9394 if (THUMB_IS_FUNC (fixP->fx_addsy)
9395 && fixP->fx_subsy == NULL)
9398 /* We need the symbol name for the VTABLE entries. */
9399 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
9400 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
9407 elf32_arm_target_format ()
9409 if (target_big_endian)
9412 return "elf32-bigarm-oabi";
9414 return "elf32-bigarm";
9419 return "elf32-littlearm-oabi";
9421 return "elf32-littlearm";
9426 armelf_frob_symbol (symp, puntp)
9430 elf_frob_symbol (symp, puntp);
9434 arm_force_relocation (fixp)
9437 if ( fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
9438 || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY
9439 || fixp->fx_r_type == BFD_RELOC_ARM_PCREL_BRANCH
9440 || fixp->fx_r_type == BFD_RELOC_ARM_PCREL_BLX
9441 || fixp->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX
9442 || fixp->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23)
9448 static bfd_reloc_code_real_type
9458 bfd_reloc_code_real_type reloc;
9462 #define MAP(str,reloc) { str, sizeof (str) - 1, reloc }
9463 MAP ("(got)", BFD_RELOC_ARM_GOT32),
9464 MAP ("(gotoff)", BFD_RELOC_ARM_GOTOFF),
9465 /* ScottB: Jan 30, 1998 - Added support for parsing "var(PLT)"
9466 branch instructions generated by GCC for PLT relocs. */
9467 MAP ("(plt)", BFD_RELOC_ARM_PLT32),
9468 { NULL, 0, BFD_RELOC_UNUSED }
9472 for (i = 0, ip = input_line_pointer;
9473 i < sizeof (id) && (ISALNUM (*ip) || ISPUNCT (*ip));
9475 id[i] = TOLOWER (*ip);
9477 for (i = 0; reloc_map[i].str; i++)
9478 if (strncmp (id, reloc_map[i].str, reloc_map[i].len) == 0)
9481 input_line_pointer += reloc_map[i].len;
9483 return reloc_map[i].reloc;
9487 s_arm_elf_cons (nbytes)
9492 #ifdef md_flush_pending_output
9493 md_flush_pending_output ();
9496 if (is_it_end_of_statement ())
9498 demand_empty_rest_of_line ();
9502 #ifdef md_cons_align
9503 md_cons_align (nbytes);
9508 bfd_reloc_code_real_type reloc;
9512 if (exp.X_op == O_symbol
9513 && * input_line_pointer == '('
9514 && (reloc = arm_parse_reloc ()) != BFD_RELOC_UNUSED)
9516 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
9517 int size = bfd_get_reloc_size (howto);
9520 as_bad ("%s relocations do not fit in %d bytes",
9521 howto->name, nbytes);
9524 register char *p = frag_more ((int) nbytes);
9525 int offset = nbytes - size;
9527 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
9532 emit_expr (&exp, (unsigned int) nbytes);
9534 while (*input_line_pointer++ == ',');
9536 /* Put terminator back into stream. */
9537 input_line_pointer --;
9538 demand_empty_rest_of_line ();
9541 #endif /* OBJ_ELF */
9543 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
9544 of an rs_align_code fragment. */
9547 arm_handle_align (fragP)
9550 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
9551 static char const thumb_noop[2] = { 0xc0, 0x46 };
9552 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
9553 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
9555 int bytes, fix, noop_size;
9559 if (fragP->fr_type != rs_align_code)
9562 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
9563 p = fragP->fr_literal + fragP->fr_fix;
9566 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
9567 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
9569 if (fragP->tc_frag_data)
9571 if (target_big_endian)
9572 noop = thumb_bigend_noop;
9575 noop_size = sizeof (thumb_noop);
9579 if (target_big_endian)
9580 noop = arm_bigend_noop;
9583 noop_size = sizeof (arm_noop);
9586 if (bytes & (noop_size - 1))
9588 fix = bytes & (noop_size - 1);
9594 while (bytes >= noop_size)
9596 memcpy (p, noop, noop_size);
9602 fragP->fr_fix += fix;
9603 fragP->fr_var = noop_size;
9606 /* Called from md_do_align. Used to create an alignment
9607 frag in a code section. */
9610 arm_frag_align_code (n, max)
9616 /* We assume that there will never be a requirment
9617 to support alignments greater than 32 bytes. */
9618 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
9619 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
9621 p = frag_var (rs_align_code,
9622 MAX_MEM_FOR_RS_ALIGN_CODE,
9624 (relax_substateT) max,
9632 /* Perform target specific initialisation of a frag. */
9635 arm_init_frag (fragP)
9638 /* Record whether this frag is in an ARM or a THUMB area. */
9639 fragP->tc_frag_data = thumb_mode;