1 /* tc-arm.c -- Assemble for the ARM
2 Copyright (C) 1994, 95, 96, 97, 98, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
5 Modified by David Taylor (dtaylor@armltd.co.uk)
7 This file is part of GAS, the GNU Assembler.
9 GAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GAS; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 /* Need TARGET_CPU. */
40 /* Types of processor to assemble for. */
41 #define ARM_1 0x00000001
42 #define ARM_2 0x00000002
43 #define ARM_3 0x00000004
45 #define ARM_6 0x00000008
46 #define ARM_7 ARM_6 /* Same core instruction set. */
47 #define ARM_8 ARM_6 /* Same core instruction set. */
48 #define ARM_9 ARM_6 /* Same core instruction set. */
49 #define ARM_CPU_MASK 0x0000000f
51 /* The following bitmasks control CPU extensions (ARM7 onwards): */
52 #define ARM_LONGMUL 0x00000010 /* Allow long multiplies. */
53 #define ARM_HALFWORD 0x00000020 /* Allow half word loads. */
54 #define ARM_THUMB 0x00000040 /* Allow BX instruction. */
55 #define ARM_EXT_V5 0x00000080 /* Allow CLZ, etc. */
57 /* Architectures are the sum of the base and extensions. */
58 #define ARM_ARCH_V4 (ARM_7 | ARM_LONGMUL | ARM_HALFWORD)
59 #define ARM_ARCH_V4T (ARM_ARCH_V4 | ARM_THUMB)
60 #define ARM_ARCH_V5 (ARM_ARCH_V4 | ARM_EXT_V5)
61 #define ARM_ARCH_V5T (ARM_ARCH_V5 | ARM_THUMB)
63 /* Some useful combinations: */
64 #define ARM_ANY 0x00ffffff
65 #define ARM_2UP (ARM_ANY - ARM_1)
66 #define ARM_ALL ARM_2UP /* Not arm1 only. */
67 #define ARM_3UP 0x00fffffc
68 #define ARM_6UP 0x00fffff8 /* Includes ARM7. */
70 #define FPU_CORE 0x80000000
71 #define FPU_FPA10 0x40000000
72 #define FPU_FPA11 0x40000000
75 /* Some useful combinations. */
76 #define FPU_ALL 0xff000000 /* Note this is ~ARM_ANY. */
77 #define FPU_MEMMULTI 0x7f000000 /* Not fpu_core. */
81 #define CPU_DEFAULT (ARM_ARCH_V4 | ARM_THUMB)
83 #define CPU_DEFAULT ARM_ALL
88 #define FPU_DEFAULT FPU_ALL
91 #define streq(a, b) (strcmp (a, b) == 0)
92 #define skip_whitespace(str) while (*(str) == ' ') ++(str)
94 static unsigned long cpu_variant
= CPU_DEFAULT
| FPU_DEFAULT
;
95 static int target_oabi
= 0;
97 #if defined OBJ_COFF || defined OBJ_ELF
98 /* Flags stored in private area of BFD structure. */
99 static boolean uses_apcs_26
= false;
100 static boolean support_interwork
= false;
101 static boolean uses_apcs_float
= false;
102 static boolean pic_code
= false;
105 /* This array holds the chars that always start a comment. If the
106 pre-processor is disabled, these aren't very useful. */
107 CONST
char comment_chars
[] = "@";
109 /* This array holds the chars that only start a comment at the beginning of
110 a line. If the line seems to have the form '# 123 filename'
111 .line and .file directives will appear in the pre-processed output. */
112 /* Note that input_file.c hand checks for '#' at the beginning of the
113 first line of the input file. This is because the compiler outputs
114 #NO_APP at the beginning of its output. */
115 /* Also note that comments like this one will always work. */
116 CONST
char line_comment_chars
[] = "#";
118 CONST
char line_separator_chars
[] = ";";
120 /* Chars that can be used to separate mant
121 from exp in floating point numbers. */
122 CONST
char EXP_CHARS
[] = "eE";
124 /* Chars that mean this number is a floating point constant. */
128 CONST
char FLT_CHARS
[] = "rRsSfFdDxXeEpP";
130 /* Prefix characters that indicate the start of an immediate
132 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
135 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
136 symbolS
* GOT_symbol
;
139 /* Size of relocation record. */
140 CONST
int md_reloc_size
= 8;
142 /* 0: assemble for ARM,
143 1: assemble for Thumb,
144 2: assemble for Thumb even though target CPU does not support thumb
146 static int thumb_mode
= 0;
148 typedef struct arm_fix
156 unsigned long instruction
;
161 bfd_reloc_code_real_type type
;
178 struct asm_shift_properties
180 enum asm_shift_index index
;
181 unsigned long bit_field
;
182 unsigned int allows_0
: 1;
183 unsigned int allows_32
: 1;
186 static const struct asm_shift_properties shift_properties
[] =
188 { SHIFT_LSL
, 0, 1, 0},
189 { SHIFT_LSR
, 0x20, 0, 1},
190 { SHIFT_ASR
, 0x40, 0, 1},
191 { SHIFT_ROR
, 0x60, 0, 0},
192 { SHIFT_RRX
, 0x60, 0, 0}
195 struct asm_shift_name
198 const struct asm_shift_properties
* properties
;
201 static const struct asm_shift_name shift_names
[] =
203 { "asl", shift_properties
+ SHIFT_LSL
},
204 { "lsl", shift_properties
+ SHIFT_LSL
},
205 { "lsr", shift_properties
+ SHIFT_LSR
},
206 { "asr", shift_properties
+ SHIFT_ASR
},
207 { "ror", shift_properties
+ SHIFT_ROR
},
208 { "rrx", shift_properties
+ SHIFT_RRX
},
209 { "ASL", shift_properties
+ SHIFT_LSL
},
210 { "LSL", shift_properties
+ SHIFT_LSL
},
211 { "LSR", shift_properties
+ SHIFT_LSR
},
212 { "ASR", shift_properties
+ SHIFT_ASR
},
213 { "ROR", shift_properties
+ SHIFT_ROR
},
214 { "RRX", shift_properties
+ SHIFT_RRX
}
217 #define NO_SHIFT_RESTRICT 1
218 #define SHIFT_RESTRICT 0
220 #define NUM_FLOAT_VALS 8
222 CONST
char * fp_const
[] =
224 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
227 /* Number of littlenums required to hold an extended precision number. */
228 #define MAX_LITTLENUMS 6
230 LITTLENUM_TYPE fp_values
[NUM_FLOAT_VALS
][MAX_LITTLENUMS
];
240 #define CP_T_X 0x00008000
241 #define CP_T_Y 0x00400000
242 #define CP_T_Pre 0x01000000
243 #define CP_T_UD 0x00800000
244 #define CP_T_WB 0x00200000
246 #define CONDS_BIT (0x00100000)
247 #define LOAD_BIT (0x00100000)
248 #define TRANS_BIT (0x00200000)
252 CONST
char * template;
256 /* This is to save a hash look-up in the common case. */
257 #define COND_ALWAYS 0xe0000000
259 static CONST
struct asm_cond conds
[] =
263 {"cs", 0x20000000}, {"hs", 0x20000000},
264 {"cc", 0x30000000}, {"ul", 0x30000000}, {"lo", 0x30000000},
279 /* Warning: If the top bit of the set_bits is set, then the standard
280 instruction bitmask is ignored, and the new bitmask is taken from
284 CONST
char * template; /* Basic flag string. */
285 unsigned long set_bits
; /* Bits to set. */
288 static CONST
struct asm_flg s_flag
[] =
294 static CONST
struct asm_flg ldr_flags
[] =
298 {"bt", 0x00400000 | TRANS_BIT
},
305 static CONST
struct asm_flg str_flags
[] =
309 {"bt", 0x00400000 | TRANS_BIT
},
314 static CONST
struct asm_flg byte_flag
[] =
320 static CONST
struct asm_flg cmp_flags
[] =
327 static CONST
struct asm_flg ldm_flags
[] =
340 static CONST
struct asm_flg stm_flags
[] =
353 static CONST
struct asm_flg lfm_flags
[] =
360 static CONST
struct asm_flg sfm_flags
[] =
367 static CONST
struct asm_flg round_flags
[] =
375 /* The implementation of the FIX instruction is broken on some assemblers,
376 in that it accepts a precision specifier as well as a rounding specifier,
377 despite the fact that this is meaningless. To be more compatible, we
378 accept it as well, though of course it does not set any bits. */
379 static CONST
struct asm_flg fix_flags
[] =
396 static CONST
struct asm_flg except_flag
[] =
402 static CONST
struct asm_flg cplong_flag
[] =
410 CONST
char * template;
415 /* The bit that distnguishes CPSR and SPSR. */
416 #define SPSR_BIT (1 << 22)
418 /* How many bits to shift the PSR_xxx bits up by. */
421 #define PSR_c (1 << 0)
422 #define PSR_x (1 << 1)
423 #define PSR_s (1 << 2)
424 #define PSR_f (1 << 3)
426 static CONST
struct asm_psr psrs
[] =
428 {"CPSR", true, PSR_c
| PSR_f
},
429 {"CPSR_all", true, PSR_c
| PSR_f
},
430 {"SPSR", false, PSR_c
| PSR_f
},
431 {"SPSR_all", false, PSR_c
| PSR_f
},
432 {"CPSR_flg", true, PSR_f
},
433 {"CPSR_f", true, PSR_f
},
434 {"SPSR_flg", false, PSR_f
},
435 {"SPSR_f", false, PSR_f
},
436 {"CPSR_c", true, PSR_c
},
437 {"CPSR_ctl", true, PSR_c
},
438 {"SPSR_c", false, PSR_c
},
439 {"SPSR_ctl", false, PSR_c
},
440 {"CPSR_x", true, PSR_x
},
441 {"CPSR_s", true, PSR_s
},
442 {"SPSR_x", false, PSR_x
},
443 {"SPSR_s", false, PSR_s
},
444 /* Combinations of flags. */
445 {"CPSR_fs", true, PSR_f
| PSR_s
},
446 {"CPSR_fx", true, PSR_f
| PSR_x
},
447 {"CPSR_fc", true, PSR_f
| PSR_c
},
448 {"CPSR_sf", true, PSR_s
| PSR_f
},
449 {"CPSR_sx", true, PSR_s
| PSR_x
},
450 {"CPSR_sc", true, PSR_s
| PSR_c
},
451 {"CPSR_xf", true, PSR_x
| PSR_f
},
452 {"CPSR_xs", true, PSR_x
| PSR_s
},
453 {"CPSR_xc", true, PSR_x
| PSR_c
},
454 {"CPSR_cf", true, PSR_c
| PSR_f
},
455 {"CPSR_cs", true, PSR_c
| PSR_s
},
456 {"CPSR_cx", true, PSR_c
| PSR_x
},
457 {"CPSR_fsx", true, PSR_f
| PSR_s
| PSR_x
},
458 {"CPSR_fsc", true, PSR_f
| PSR_s
| PSR_c
},
459 {"CPSR_fxs", true, PSR_f
| PSR_x
| PSR_s
},
460 {"CPSR_fxc", true, PSR_f
| PSR_x
| PSR_c
},
461 {"CPSR_fcs", true, PSR_f
| PSR_c
| PSR_s
},
462 {"CPSR_fcx", true, PSR_f
| PSR_c
| PSR_x
},
463 {"CPSR_sfx", true, PSR_s
| PSR_f
| PSR_x
},
464 {"CPSR_sfc", true, PSR_s
| PSR_f
| PSR_c
},
465 {"CPSR_sxf", true, PSR_s
| PSR_x
| PSR_f
},
466 {"CPSR_sxc", true, PSR_s
| PSR_x
| PSR_c
},
467 {"CPSR_scf", true, PSR_s
| PSR_c
| PSR_f
},
468 {"CPSR_scx", true, PSR_s
| PSR_c
| PSR_x
},
469 {"CPSR_xfs", true, PSR_x
| PSR_f
| PSR_s
},
470 {"CPSR_xfc", true, PSR_x
| PSR_f
| PSR_c
},
471 {"CPSR_xsf", true, PSR_x
| PSR_s
| PSR_f
},
472 {"CPSR_xsc", true, PSR_x
| PSR_s
| PSR_c
},
473 {"CPSR_xcf", true, PSR_x
| PSR_c
| PSR_f
},
474 {"CPSR_xcs", true, PSR_x
| PSR_c
| PSR_s
},
475 {"CPSR_cfs", true, PSR_c
| PSR_f
| PSR_s
},
476 {"CPSR_cfx", true, PSR_c
| PSR_f
| PSR_x
},
477 {"CPSR_csf", true, PSR_c
| PSR_s
| PSR_f
},
478 {"CPSR_csx", true, PSR_c
| PSR_s
| PSR_x
},
479 {"CPSR_cxf", true, PSR_c
| PSR_x
| PSR_f
},
480 {"CPSR_cxs", true, PSR_c
| PSR_x
| PSR_s
},
481 {"CPSR_fsxc", true, PSR_f
| PSR_s
| PSR_x
| PSR_c
},
482 {"CPSR_fscx", true, PSR_f
| PSR_s
| PSR_c
| PSR_x
},
483 {"CPSR_fxsc", true, PSR_f
| PSR_x
| PSR_s
| PSR_c
},
484 {"CPSR_fxcs", true, PSR_f
| PSR_x
| PSR_c
| PSR_s
},
485 {"CPSR_fcsx", true, PSR_f
| PSR_c
| PSR_s
| PSR_x
},
486 {"CPSR_fcxs", true, PSR_f
| PSR_c
| PSR_x
| PSR_s
},
487 {"CPSR_sfxc", true, PSR_s
| PSR_f
| PSR_x
| PSR_c
},
488 {"CPSR_sfcx", true, PSR_s
| PSR_f
| PSR_c
| PSR_x
},
489 {"CPSR_sxfc", true, PSR_s
| PSR_x
| PSR_f
| PSR_c
},
490 {"CPSR_sxcf", true, PSR_s
| PSR_x
| PSR_c
| PSR_f
},
491 {"CPSR_scfx", true, PSR_s
| PSR_c
| PSR_f
| PSR_x
},
492 {"CPSR_scxf", true, PSR_s
| PSR_c
| PSR_x
| PSR_f
},
493 {"CPSR_xfsc", true, PSR_x
| PSR_f
| PSR_s
| PSR_c
},
494 {"CPSR_xfcs", true, PSR_x
| PSR_f
| PSR_c
| PSR_s
},
495 {"CPSR_xsfc", true, PSR_x
| PSR_s
| PSR_f
| PSR_c
},
496 {"CPSR_xscf", true, PSR_x
| PSR_s
| PSR_c
| PSR_f
},
497 {"CPSR_xcfs", true, PSR_x
| PSR_c
| PSR_f
| PSR_s
},
498 {"CPSR_xcsf", true, PSR_x
| PSR_c
| PSR_s
| PSR_f
},
499 {"CPSR_cfsx", true, PSR_c
| PSR_f
| PSR_s
| PSR_x
},
500 {"CPSR_cfxs", true, PSR_c
| PSR_f
| PSR_x
| PSR_s
},
501 {"CPSR_csfx", true, PSR_c
| PSR_s
| PSR_f
| PSR_x
},
502 {"CPSR_csxf", true, PSR_c
| PSR_s
| PSR_x
| PSR_f
},
503 {"CPSR_cxfs", true, PSR_c
| PSR_x
| PSR_f
| PSR_s
},
504 {"CPSR_cxsf", true, PSR_c
| PSR_x
| PSR_s
| PSR_f
},
505 {"SPSR_fs", false, PSR_f
| PSR_s
},
506 {"SPSR_fx", false, PSR_f
| PSR_x
},
507 {"SPSR_fc", false, PSR_f
| PSR_c
},
508 {"SPSR_sf", false, PSR_s
| PSR_f
},
509 {"SPSR_sx", false, PSR_s
| PSR_x
},
510 {"SPSR_sc", false, PSR_s
| PSR_c
},
511 {"SPSR_xf", false, PSR_x
| PSR_f
},
512 {"SPSR_xs", false, PSR_x
| PSR_s
},
513 {"SPSR_xc", false, PSR_x
| PSR_c
},
514 {"SPSR_cf", false, PSR_c
| PSR_f
},
515 {"SPSR_cs", false, PSR_c
| PSR_s
},
516 {"SPSR_cx", false, PSR_c
| PSR_x
},
517 {"SPSR_fsx", false, PSR_f
| PSR_s
| PSR_x
},
518 {"SPSR_fsc", false, PSR_f
| PSR_s
| PSR_c
},
519 {"SPSR_fxs", false, PSR_f
| PSR_x
| PSR_s
},
520 {"SPSR_fxc", false, PSR_f
| PSR_x
| PSR_c
},
521 {"SPSR_fcs", false, PSR_f
| PSR_c
| PSR_s
},
522 {"SPSR_fcx", false, PSR_f
| PSR_c
| PSR_x
},
523 {"SPSR_sfx", false, PSR_s
| PSR_f
| PSR_x
},
524 {"SPSR_sfc", false, PSR_s
| PSR_f
| PSR_c
},
525 {"SPSR_sxf", false, PSR_s
| PSR_x
| PSR_f
},
526 {"SPSR_sxc", false, PSR_s
| PSR_x
| PSR_c
},
527 {"SPSR_scf", false, PSR_s
| PSR_c
| PSR_f
},
528 {"SPSR_scx", false, PSR_s
| PSR_c
| PSR_x
},
529 {"SPSR_xfs", false, PSR_x
| PSR_f
| PSR_s
},
530 {"SPSR_xfc", false, PSR_x
| PSR_f
| PSR_c
},
531 {"SPSR_xsf", false, PSR_x
| PSR_s
| PSR_f
},
532 {"SPSR_xsc", false, PSR_x
| PSR_s
| PSR_c
},
533 {"SPSR_xcf", false, PSR_x
| PSR_c
| PSR_f
},
534 {"SPSR_xcs", false, PSR_x
| PSR_c
| PSR_s
},
535 {"SPSR_cfs", false, PSR_c
| PSR_f
| PSR_s
},
536 {"SPSR_cfx", false, PSR_c
| PSR_f
| PSR_x
},
537 {"SPSR_csf", false, PSR_c
| PSR_s
| PSR_f
},
538 {"SPSR_csx", false, PSR_c
| PSR_s
| PSR_x
},
539 {"SPSR_cxf", false, PSR_c
| PSR_x
| PSR_f
},
540 {"SPSR_cxs", false, PSR_c
| PSR_x
| PSR_s
},
541 {"SPSR_fsxc", false, PSR_f
| PSR_s
| PSR_x
| PSR_c
},
542 {"SPSR_fscx", false, PSR_f
| PSR_s
| PSR_c
| PSR_x
},
543 {"SPSR_fxsc", false, PSR_f
| PSR_x
| PSR_s
| PSR_c
},
544 {"SPSR_fxcs", false, PSR_f
| PSR_x
| PSR_c
| PSR_s
},
545 {"SPSR_fcsx", false, PSR_f
| PSR_c
| PSR_s
| PSR_x
},
546 {"SPSR_fcxs", false, PSR_f
| PSR_c
| PSR_x
| PSR_s
},
547 {"SPSR_sfxc", false, PSR_s
| PSR_f
| PSR_x
| PSR_c
},
548 {"SPSR_sfcx", false, PSR_s
| PSR_f
| PSR_c
| PSR_x
},
549 {"SPSR_sxfc", false, PSR_s
| PSR_x
| PSR_f
| PSR_c
},
550 {"SPSR_sxcf", false, PSR_s
| PSR_x
| PSR_c
| PSR_f
},
551 {"SPSR_scfx", false, PSR_s
| PSR_c
| PSR_f
| PSR_x
},
552 {"SPSR_scxf", false, PSR_s
| PSR_c
| PSR_x
| PSR_f
},
553 {"SPSR_xfsc", false, PSR_x
| PSR_f
| PSR_s
| PSR_c
},
554 {"SPSR_xfcs", false, PSR_x
| PSR_f
| PSR_c
| PSR_s
},
555 {"SPSR_xsfc", false, PSR_x
| PSR_s
| PSR_f
| PSR_c
},
556 {"SPSR_xscf", false, PSR_x
| PSR_s
| PSR_c
| PSR_f
},
557 {"SPSR_xcfs", false, PSR_x
| PSR_c
| PSR_f
| PSR_s
},
558 {"SPSR_xcsf", false, PSR_x
| PSR_c
| PSR_s
| PSR_f
},
559 {"SPSR_cfsx", false, PSR_c
| PSR_f
| PSR_s
| PSR_x
},
560 {"SPSR_cfxs", false, PSR_c
| PSR_f
| PSR_x
| PSR_s
},
561 {"SPSR_csfx", false, PSR_c
| PSR_s
| PSR_f
| PSR_x
},
562 {"SPSR_csxf", false, PSR_c
| PSR_s
| PSR_x
| PSR_f
},
563 {"SPSR_cxfs", false, PSR_c
| PSR_x
| PSR_f
| PSR_s
},
564 {"SPSR_cxsf", false, PSR_c
| PSR_x
| PSR_s
| PSR_f
},
565 /* For backwards compatability with older toolchain we also
566 support lower case versions of some of these flags. */
567 {"cpsr", true, PSR_c
| PSR_f
},
568 {"cpsr_all", true, PSR_c
| PSR_f
},
569 {"spsr", false, PSR_c
| PSR_f
},
570 {"spsr_all", false, PSR_c
| PSR_f
},
571 {"cpsr_flg", true, PSR_f
},
572 {"cpsr_f", true, PSR_f
},
573 {"spsr_flg", false, PSR_f
},
574 {"spsr_f", false, PSR_f
},
575 {"cpsr_c", true, PSR_c
},
576 {"cpsr_ctl", true, PSR_c
},
577 {"spsr_c", false, PSR_c
},
578 {"spsr_ctl", false, PSR_c
}
581 /* Functions called by parser. */
582 /* ARM instructions. */
583 static void do_arit
PARAMS ((char *, unsigned long));
584 static void do_cmp
PARAMS ((char *, unsigned long));
585 static void do_mov
PARAMS ((char *, unsigned long));
586 static void do_ldst
PARAMS ((char *, unsigned long));
587 static void do_ldmstm
PARAMS ((char *, unsigned long));
588 static void do_branch
PARAMS ((char *, unsigned long));
589 static void do_swi
PARAMS ((char *, unsigned long));
590 /* Pseudo Op codes. */
591 static void do_adr
PARAMS ((char *, unsigned long));
592 static void do_adrl
PARAMS ((char *, unsigned long));
593 static void do_nop
PARAMS ((char *, unsigned long));
595 static void do_mul
PARAMS ((char *, unsigned long));
596 static void do_mla
PARAMS ((char *, unsigned long));
598 static void do_swap
PARAMS ((char *, unsigned long));
600 static void do_msr
PARAMS ((char *, unsigned long));
601 static void do_mrs
PARAMS ((char *, unsigned long));
603 static void do_mull
PARAMS ((char *, unsigned long));
605 static void do_bx
PARAMS ((char *, unsigned long));
607 /* Coprocessor Instructions. */
608 static void do_cdp
PARAMS ((char *, unsigned long));
609 static void do_lstc
PARAMS ((char *, unsigned long));
610 static void do_co_reg
PARAMS ((char *, unsigned long));
611 static void do_fp_ctrl
PARAMS ((char *, unsigned long));
612 static void do_fp_ldst
PARAMS ((char *, unsigned long));
613 static void do_fp_ldmstm
PARAMS ((char *, unsigned long));
614 static void do_fp_dyadic
PARAMS ((char *, unsigned long));
615 static void do_fp_monadic
PARAMS ((char *, unsigned long));
616 static void do_fp_cmp
PARAMS ((char *, unsigned long));
617 static void do_fp_from_reg
PARAMS ((char *, unsigned long));
618 static void do_fp_to_reg
PARAMS ((char *, unsigned long));
620 static void fix_new_arm
PARAMS ((fragS
*, int, short, expressionS
*, int, int));
621 static int arm_reg_parse
PARAMS ((char **));
622 static CONST
struct asm_psr
* arm_psr_parse
PARAMS ((char **));
623 static void symbol_locate
PARAMS ((symbolS
*, CONST
char *, segT
, valueT
, fragS
*));
624 static int add_to_lit_pool
PARAMS ((void));
625 static unsigned validate_immediate
PARAMS ((unsigned));
626 static unsigned validate_immediate_twopart
PARAMS ((unsigned int, unsigned int *));
627 static int validate_offset_imm
PARAMS ((unsigned int, int));
628 static void opcode_select
PARAMS ((int));
629 static void end_of_line
PARAMS ((char *));
630 static int reg_required_here
PARAMS ((char **, int));
631 static int psr_required_here
PARAMS ((char **));
632 static int co_proc_number
PARAMS ((char **));
633 static int cp_opc_expr
PARAMS ((char **, int, int));
634 static int cp_reg_required_here
PARAMS ((char **, int));
635 static int fp_reg_required_here
PARAMS ((char **, int));
636 static int cp_address_offset
PARAMS ((char **));
637 static int cp_address_required_here
PARAMS ((char **));
638 static int my_get_float_expression
PARAMS ((char **));
639 static int skip_past_comma
PARAMS ((char **));
640 static int walk_no_bignums
PARAMS ((symbolS
*));
641 static int negate_data_op
PARAMS ((unsigned long *, unsigned long));
642 static int data_op2
PARAMS ((char **));
643 static int fp_op2
PARAMS ((char **));
644 static long reg_list
PARAMS ((char **));
645 static void thumb_load_store
PARAMS ((char *, int, int));
646 static int decode_shift
PARAMS ((char **, int));
647 static int ldst_extend
PARAMS ((char **, int));
648 static void thumb_add_sub
PARAMS ((char *, int));
649 static void insert_reg
PARAMS ((int));
650 static void thumb_shift
PARAMS ((char *, int));
651 static void thumb_mov_compare
PARAMS ((char *, int));
652 static void set_constant_flonums
PARAMS ((void));
653 static valueT md_chars_to_number
PARAMS ((char *, int));
654 static void insert_reg_alias
PARAMS ((char *, int));
655 static void output_inst
PARAMS ((void));
657 static bfd_reloc_code_real_type arm_parse_reloc
PARAMS ((void));
660 /* ARM instructions take 4bytes in the object file, Thumb instructions
664 /* LONGEST_INST is the longest basic instruction name without conditions or
665 flags. ARM7M has 4 of length 5. */
667 #define LONGEST_INST 5
671 /* Basic string to match. */
672 CONST
char * template;
674 /* Basic instruction code. */
677 /* Compulsory suffix that must follow conds. If "", then the
678 instruction is not conditional and must have no suffix. */
679 CONST
char * comp_suffix
;
681 /* Bits to toggle if flag 'n' set. */
682 CONST
struct asm_flg
* flags
;
684 /* Which CPU variants this exists for. */
685 unsigned long variants
;
687 /* Function to call to parse args. */
688 void (* parms
) PARAMS ((char *, unsigned long));
691 static CONST
struct asm_opcode insns
[] =
693 /* ARM Instructions. */
694 {"and", 0x00000000, NULL
, s_flag
, ARM_ANY
, do_arit
},
695 {"eor", 0x00200000, NULL
, s_flag
, ARM_ANY
, do_arit
},
696 {"sub", 0x00400000, NULL
, s_flag
, ARM_ANY
, do_arit
},
697 {"rsb", 0x00600000, NULL
, s_flag
, ARM_ANY
, do_arit
},
698 {"add", 0x00800000, NULL
, s_flag
, ARM_ANY
, do_arit
},
699 {"adc", 0x00a00000, NULL
, s_flag
, ARM_ANY
, do_arit
},
700 {"sbc", 0x00c00000, NULL
, s_flag
, ARM_ANY
, do_arit
},
701 {"rsc", 0x00e00000, NULL
, s_flag
, ARM_ANY
, do_arit
},
702 {"orr", 0x01800000, NULL
, s_flag
, ARM_ANY
, do_arit
},
703 {"bic", 0x01c00000, NULL
, s_flag
, ARM_ANY
, do_arit
},
704 {"tst", 0x01000000, NULL
, cmp_flags
, ARM_ANY
, do_cmp
},
705 {"teq", 0x01200000, NULL
, cmp_flags
, ARM_ANY
, do_cmp
},
706 {"cmp", 0x01400000, NULL
, cmp_flags
, ARM_ANY
, do_cmp
},
707 {"cmn", 0x01600000, NULL
, cmp_flags
, ARM_ANY
, do_cmp
},
708 {"mov", 0x01a00000, NULL
, s_flag
, ARM_ANY
, do_mov
},
709 {"mvn", 0x01e00000, NULL
, s_flag
, ARM_ANY
, do_mov
},
710 {"str", 0x04000000, NULL
, str_flags
, ARM_ANY
, do_ldst
},
711 {"ldr", 0x04100000, NULL
, ldr_flags
, ARM_ANY
, do_ldst
},
712 {"stm", 0x08000000, NULL
, stm_flags
, ARM_ANY
, do_ldmstm
},
713 {"ldm", 0x08100000, NULL
, ldm_flags
, ARM_ANY
, do_ldmstm
},
714 {"swi", 0x0f000000, NULL
, NULL
, ARM_ANY
, do_swi
},
716 {"bl", 0x0b000000, NULL
, NULL
, ARM_ANY
, do_branch
},
717 {"b", 0x0a000000, NULL
, NULL
, ARM_ANY
, do_branch
},
719 {"bl", 0x0bfffffe, NULL
, NULL
, ARM_ANY
, do_branch
},
720 {"b", 0x0afffffe, NULL
, NULL
, ARM_ANY
, do_branch
},
724 {"adr", 0x028f0000, NULL
, NULL
, ARM_ANY
, do_adr
},
725 {"adrl", 0x028f0000, NULL
, NULL
, ARM_ANY
, do_adrl
},
726 {"nop", 0x01a00000, NULL
, NULL
, ARM_ANY
, do_nop
},
728 /* ARM 2 multiplies. */
729 {"mul", 0x00000090, NULL
, s_flag
, ARM_2UP
, do_mul
},
730 {"mla", 0x00200090, NULL
, s_flag
, ARM_2UP
, do_mla
},
732 /* ARM 3 - swp instructions. */
733 {"swp", 0x01000090, NULL
, byte_flag
, ARM_3UP
, do_swap
},
735 /* ARM 6 Coprocessor instructions. */
736 {"mrs", 0x010f0000, NULL
, NULL
, ARM_6UP
, do_mrs
},
737 {"msr", 0x0120f000, NULL
, NULL
, ARM_6UP
, do_msr
},
738 /* ScottB: our code uses 0x0128f000 for msr.
739 NickC: but this is wrong because the bits 16 through 19 are
740 handled by the PSR_xxx defines above. */
742 /* ARM 7M long multiplies - need signed/unsigned flags! */
743 {"smull", 0x00c00090, NULL
, s_flag
, ARM_LONGMUL
, do_mull
},
744 {"umull", 0x00800090, NULL
, s_flag
, ARM_LONGMUL
, do_mull
},
745 {"smlal", 0x00e00090, NULL
, s_flag
, ARM_LONGMUL
, do_mull
},
746 {"umlal", 0x00a00090, NULL
, s_flag
, ARM_LONGMUL
, do_mull
},
748 /* ARM THUMB interworking. */
749 {"bx", 0x012fff10, NULL
, NULL
, ARM_THUMB
, do_bx
},
751 /* Floating point instructions. */
752 {"wfs", 0x0e200110, NULL
, NULL
, FPU_ALL
, do_fp_ctrl
},
753 {"rfs", 0x0e300110, NULL
, NULL
, FPU_ALL
, do_fp_ctrl
},
754 {"wfc", 0x0e400110, NULL
, NULL
, FPU_ALL
, do_fp_ctrl
},
755 {"rfc", 0x0e500110, NULL
, NULL
, FPU_ALL
, do_fp_ctrl
},
756 {"ldf", 0x0c100100, "sdep", NULL
, FPU_ALL
, do_fp_ldst
},
757 {"stf", 0x0c000100, "sdep", NULL
, FPU_ALL
, do_fp_ldst
},
758 {"lfm", 0x0c100200, NULL
, lfm_flags
, FPU_MEMMULTI
, do_fp_ldmstm
},
759 {"sfm", 0x0c000200, NULL
, sfm_flags
, FPU_MEMMULTI
, do_fp_ldmstm
},
760 {"mvf", 0x0e008100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
761 {"mnf", 0x0e108100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
762 {"abs", 0x0e208100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
763 {"rnd", 0x0e308100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
764 {"sqt", 0x0e408100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
765 {"log", 0x0e508100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
766 {"lgn", 0x0e608100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
767 {"exp", 0x0e708100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
768 {"sin", 0x0e808100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
769 {"cos", 0x0e908100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
770 {"tan", 0x0ea08100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
771 {"asn", 0x0eb08100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
772 {"acs", 0x0ec08100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
773 {"atn", 0x0ed08100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
774 {"urd", 0x0ee08100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
775 {"nrm", 0x0ef08100, "sde", round_flags
, FPU_ALL
, do_fp_monadic
},
776 {"adf", 0x0e000100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
777 {"suf", 0x0e200100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
778 {"rsf", 0x0e300100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
779 {"muf", 0x0e100100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
780 {"dvf", 0x0e400100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
781 {"rdf", 0x0e500100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
782 {"pow", 0x0e600100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
783 {"rpw", 0x0e700100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
784 {"rmf", 0x0e800100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
785 {"fml", 0x0e900100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
786 {"fdv", 0x0ea00100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
787 {"frd", 0x0eb00100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
788 {"pol", 0x0ec00100, "sde", round_flags
, FPU_ALL
, do_fp_dyadic
},
789 {"cmf", 0x0e90f110, NULL
, except_flag
, FPU_ALL
, do_fp_cmp
},
790 {"cnf", 0x0eb0f110, NULL
, except_flag
, FPU_ALL
, do_fp_cmp
},
791 /* The FPA10 data sheet suggests that the 'E' of cmfe/cnfe should not
792 be an optional suffix, but part of the instruction. To be compatible,
794 {"cmfe", 0x0ed0f110, NULL
, NULL
, FPU_ALL
, do_fp_cmp
},
795 {"cnfe", 0x0ef0f110, NULL
, NULL
, FPU_ALL
, do_fp_cmp
},
796 {"flt", 0x0e000110, "sde", round_flags
, FPU_ALL
, do_fp_from_reg
},
797 {"fix", 0x0e100110, NULL
, fix_flags
, FPU_ALL
, do_fp_to_reg
},
799 /* Generic copressor instructions. */
800 {"cdp", 0x0e000000, NULL
, NULL
, ARM_2UP
, do_cdp
},
801 {"ldc", 0x0c100000, NULL
, cplong_flag
, ARM_2UP
, do_lstc
},
802 {"stc", 0x0c000000, NULL
, cplong_flag
, ARM_2UP
, do_lstc
},
803 {"mcr", 0x0e000010, NULL
, NULL
, ARM_2UP
, do_co_reg
},
804 {"mrc", 0x0e100010, NULL
, NULL
, ARM_2UP
, do_co_reg
},
807 /* Defines for various bits that we will want to toggle. */
808 #define INST_IMMEDIATE 0x02000000
809 #define OFFSET_REG 0x02000000
810 #define HWOFFSET_IMM 0x00400000
811 #define SHIFT_BY_REG 0x00000010
812 #define PRE_INDEX 0x01000000
813 #define INDEX_UP 0x00800000
814 #define WRITE_BACK 0x00200000
815 #define LDM_TYPE_2_OR_3 0x00400000
817 #define LITERAL_MASK 0xf000f000
818 #define COND_MASK 0xf0000000
819 #define OPCODE_MASK 0xfe1fffff
820 #define DATA_OP_SHIFT 21
822 /* Codes to distinguish the arithmetic instructions. */
833 #define OPCODE_CMP 10
834 #define OPCODE_CMN 11
835 #define OPCODE_ORR 12
836 #define OPCODE_MOV 13
837 #define OPCODE_BIC 14
838 #define OPCODE_MVN 15
840 static void do_t_nop
PARAMS ((char *));
841 static void do_t_arit
PARAMS ((char *));
842 static void do_t_add
PARAMS ((char *));
843 static void do_t_asr
PARAMS ((char *));
844 static void do_t_branch9
PARAMS ((char *));
845 static void do_t_branch12
PARAMS ((char *));
846 static void do_t_branch23
PARAMS ((char *));
847 static void do_t_bx
PARAMS ((char *));
848 static void do_t_compare
PARAMS ((char *));
849 static void do_t_ldmstm
PARAMS ((char *));
850 static void do_t_ldr
PARAMS ((char *));
851 static void do_t_ldrb
PARAMS ((char *));
852 static void do_t_ldrh
PARAMS ((char *));
853 static void do_t_lds
PARAMS ((char *));
854 static void do_t_lsl
PARAMS ((char *));
855 static void do_t_lsr
PARAMS ((char *));
856 static void do_t_mov
PARAMS ((char *));
857 static void do_t_push_pop
PARAMS ((char *));
858 static void do_t_str
PARAMS ((char *));
859 static void do_t_strb
PARAMS ((char *));
860 static void do_t_strh
PARAMS ((char *));
861 static void do_t_sub
PARAMS ((char *));
862 static void do_t_swi
PARAMS ((char *));
863 static void do_t_adr
PARAMS ((char *));
865 #define T_OPCODE_MUL 0x4340
866 #define T_OPCODE_TST 0x4200
867 #define T_OPCODE_CMN 0x42c0
868 #define T_OPCODE_NEG 0x4240
869 #define T_OPCODE_MVN 0x43c0
871 #define T_OPCODE_ADD_R3 0x1800
872 #define T_OPCODE_SUB_R3 0x1a00
873 #define T_OPCODE_ADD_HI 0x4400
874 #define T_OPCODE_ADD_ST 0xb000
875 #define T_OPCODE_SUB_ST 0xb080
876 #define T_OPCODE_ADD_SP 0xa800
877 #define T_OPCODE_ADD_PC 0xa000
878 #define T_OPCODE_ADD_I8 0x3000
879 #define T_OPCODE_SUB_I8 0x3800
880 #define T_OPCODE_ADD_I3 0x1c00
881 #define T_OPCODE_SUB_I3 0x1e00
883 #define T_OPCODE_ASR_R 0x4100
884 #define T_OPCODE_LSL_R 0x4080
885 #define T_OPCODE_LSR_R 0x40c0
886 #define T_OPCODE_ASR_I 0x1000
887 #define T_OPCODE_LSL_I 0x0000
888 #define T_OPCODE_LSR_I 0x0800
890 #define T_OPCODE_MOV_I8 0x2000
891 #define T_OPCODE_CMP_I8 0x2800
892 #define T_OPCODE_CMP_LR 0x4280
893 #define T_OPCODE_MOV_HR 0x4600
894 #define T_OPCODE_CMP_HR 0x4500
896 #define T_OPCODE_LDR_PC 0x4800
897 #define T_OPCODE_LDR_SP 0x9800
898 #define T_OPCODE_STR_SP 0x9000
899 #define T_OPCODE_LDR_IW 0x6800
900 #define T_OPCODE_STR_IW 0x6000
901 #define T_OPCODE_LDR_IH 0x8800
902 #define T_OPCODE_STR_IH 0x8000
903 #define T_OPCODE_LDR_IB 0x7800
904 #define T_OPCODE_STR_IB 0x7000
905 #define T_OPCODE_LDR_RW 0x5800
906 #define T_OPCODE_STR_RW 0x5000
907 #define T_OPCODE_LDR_RH 0x5a00
908 #define T_OPCODE_STR_RH 0x5200
909 #define T_OPCODE_LDR_RB 0x5c00
910 #define T_OPCODE_STR_RB 0x5400
912 #define T_OPCODE_PUSH 0xb400
913 #define T_OPCODE_POP 0xbc00
915 #define T_OPCODE_BRANCH 0xe7fe
917 static int thumb_reg
PARAMS ((char ** str
, int hi_lo
));
919 #define THUMB_SIZE 2 /* Size of thumb instruction. */
920 #define THUMB_REG_LO 0x1
921 #define THUMB_REG_HI 0x2
922 #define THUMB_REG_ANY 0x3
924 #define THUMB_H1 0x0080
925 #define THUMB_H2 0x0040
932 #define THUMB_COMPARE 1
935 #define THUMB_STORE 1
937 #define THUMB_PP_PC_LR 0x0100
939 /* These three are used for immediate shifts, do not alter. */
941 #define THUMB_HALFWORD 1
946 /* Basic string to match. */
947 CONST
char * template;
949 /* Basic instruction code. */
954 /* Which CPU variants this exists for. */
955 unsigned long variants
;
957 /* Function to call to parse args. */
958 void (* parms
) PARAMS ((char *));
961 static CONST
struct thumb_opcode tinsns
[] =
963 {"adc", 0x4140, 2, ARM_THUMB
, do_t_arit
},
964 {"add", 0x0000, 2, ARM_THUMB
, do_t_add
},
965 {"and", 0x4000, 2, ARM_THUMB
, do_t_arit
},
966 {"asr", 0x0000, 2, ARM_THUMB
, do_t_asr
},
967 {"b", T_OPCODE_BRANCH
, 2, ARM_THUMB
, do_t_branch12
},
968 {"beq", 0xd0fe, 2, ARM_THUMB
, do_t_branch9
},
969 {"bne", 0xd1fe, 2, ARM_THUMB
, do_t_branch9
},
970 {"bcs", 0xd2fe, 2, ARM_THUMB
, do_t_branch9
},
971 {"bhs", 0xd2fe, 2, ARM_THUMB
, do_t_branch9
},
972 {"bcc", 0xd3fe, 2, ARM_THUMB
, do_t_branch9
},
973 {"bul", 0xd3fe, 2, ARM_THUMB
, do_t_branch9
},
974 {"blo", 0xd3fe, 2, ARM_THUMB
, do_t_branch9
},
975 {"bmi", 0xd4fe, 2, ARM_THUMB
, do_t_branch9
},
976 {"bpl", 0xd5fe, 2, ARM_THUMB
, do_t_branch9
},
977 {"bvs", 0xd6fe, 2, ARM_THUMB
, do_t_branch9
},
978 {"bvc", 0xd7fe, 2, ARM_THUMB
, do_t_branch9
},
979 {"bhi", 0xd8fe, 2, ARM_THUMB
, do_t_branch9
},
980 {"bls", 0xd9fe, 2, ARM_THUMB
, do_t_branch9
},
981 {"bge", 0xdafe, 2, ARM_THUMB
, do_t_branch9
},
982 {"blt", 0xdbfe, 2, ARM_THUMB
, do_t_branch9
},
983 {"bgt", 0xdcfe, 2, ARM_THUMB
, do_t_branch9
},
984 {"ble", 0xddfe, 2, ARM_THUMB
, do_t_branch9
},
985 {"bal", 0xdefe, 2, ARM_THUMB
, do_t_branch9
},
986 {"bic", 0x4380, 2, ARM_THUMB
, do_t_arit
},
987 {"bl", 0xf7fffffe, 4, ARM_THUMB
, do_t_branch23
},
988 {"bx", 0x4700, 2, ARM_THUMB
, do_t_bx
},
989 {"cmn", T_OPCODE_CMN
, 2, ARM_THUMB
, do_t_arit
},
990 {"cmp", 0x0000, 2, ARM_THUMB
, do_t_compare
},
991 {"eor", 0x4040, 2, ARM_THUMB
, do_t_arit
},
992 {"ldmia", 0xc800, 2, ARM_THUMB
, do_t_ldmstm
},
993 {"ldr", 0x0000, 2, ARM_THUMB
, do_t_ldr
},
994 {"ldrb", 0x0000, 2, ARM_THUMB
, do_t_ldrb
},
995 {"ldrh", 0x0000, 2, ARM_THUMB
, do_t_ldrh
},
996 {"ldrsb", 0x5600, 2, ARM_THUMB
, do_t_lds
},
997 {"ldrsh", 0x5e00, 2, ARM_THUMB
, do_t_lds
},
998 {"ldsb", 0x5600, 2, ARM_THUMB
, do_t_lds
},
999 {"ldsh", 0x5e00, 2, ARM_THUMB
, do_t_lds
},
1000 {"lsl", 0x0000, 2, ARM_THUMB
, do_t_lsl
},
1001 {"lsr", 0x0000, 2, ARM_THUMB
, do_t_lsr
},
1002 {"mov", 0x0000, 2, ARM_THUMB
, do_t_mov
},
1003 {"mul", T_OPCODE_MUL
, 2, ARM_THUMB
, do_t_arit
},
1004 {"mvn", T_OPCODE_MVN
, 2, ARM_THUMB
, do_t_arit
},
1005 {"neg", T_OPCODE_NEG
, 2, ARM_THUMB
, do_t_arit
},
1006 {"orr", 0x4300, 2, ARM_THUMB
, do_t_arit
},
1007 {"pop", 0xbc00, 2, ARM_THUMB
, do_t_push_pop
},
1008 {"push", 0xb400, 2, ARM_THUMB
, do_t_push_pop
},
1009 {"ror", 0x41c0, 2, ARM_THUMB
, do_t_arit
},
1010 {"sbc", 0x4180, 2, ARM_THUMB
, do_t_arit
},
1011 {"stmia", 0xc000, 2, ARM_THUMB
, do_t_ldmstm
},
1012 {"str", 0x0000, 2, ARM_THUMB
, do_t_str
},
1013 {"strb", 0x0000, 2, ARM_THUMB
, do_t_strb
},
1014 {"strh", 0x0000, 2, ARM_THUMB
, do_t_strh
},
1015 {"swi", 0xdf00, 2, ARM_THUMB
, do_t_swi
},
1016 {"sub", 0x0000, 2, ARM_THUMB
, do_t_sub
},
1017 {"tst", T_OPCODE_TST
, 2, ARM_THUMB
, do_t_arit
},
1019 {"adr", 0x0000, 2, ARM_THUMB
, do_t_adr
},
1020 {"nop", 0x46C0, 2, ARM_THUMB
, do_t_nop
}, /* mov r8,r8 */
1029 #define int_register(reg) ((reg) >= 0 && (reg) <= 15)
1030 #define cp_register(reg) ((reg) >= 32 && (reg) <= 47)
1031 #define fp_register(reg) ((reg) >= 16 && (reg) <= 23)
1037 /* These are the standard names. Users can add aliases with .req. */
1038 static CONST
struct reg_entry reg_table
[] =
1040 /* Processor Register Numbers. */
1041 {"r0", 0}, {"r1", 1}, {"r2", 2}, {"r3", 3},
1042 {"r4", 4}, {"r5", 5}, {"r6", 6}, {"r7", 7},
1043 {"r8", 8}, {"r9", 9}, {"r10", 10}, {"r11", 11},
1044 {"r12", 12}, {"r13", REG_SP
},{"r14", REG_LR
},{"r15", REG_PC
},
1045 /* APCS conventions. */
1046 {"a1", 0}, {"a2", 1}, {"a3", 2}, {"a4", 3},
1047 {"v1", 4}, {"v2", 5}, {"v3", 6}, {"v4", 7}, {"v5", 8},
1048 {"v6", 9}, {"sb", 9}, {"v7", 10}, {"sl", 10},
1049 {"fp", 11}, {"ip", 12}, {"sp", REG_SP
},{"lr", REG_LR
},{"pc", REG_PC
},
1050 /* ATPCS additions to APCS conventions. */
1051 {"wr", 7}, {"v8", 11},
1053 {"f0", 16}, {"f1", 17}, {"f2", 18}, {"f3", 19},
1054 {"f4", 20}, {"f5", 21}, {"f6", 22}, {"f7", 23},
1055 {"c0", 32}, {"c1", 33}, {"c2", 34}, {"c3", 35},
1056 {"c4", 36}, {"c5", 37}, {"c6", 38}, {"c7", 39},
1057 {"c8", 40}, {"c9", 41}, {"c10", 42}, {"c11", 43},
1058 {"c12", 44}, {"c13", 45}, {"c14", 46}, {"c15", 47},
1059 {"cr0", 32}, {"cr1", 33}, {"cr2", 34}, {"cr3", 35},
1060 {"cr4", 36}, {"cr5", 37}, {"cr6", 38}, {"cr7", 39},
1061 {"cr8", 40}, {"cr9", 41}, {"cr10", 42}, {"cr11", 43},
1062 {"cr12", 44}, {"cr13", 45}, {"cr14", 46}, {"cr15", 47},
1063 /* ATPCS additions to float register names. */
1064 {"s0",16}, {"s1",17}, {"s2",18}, {"s3",19},
1065 {"s4",20}, {"s5",21}, {"s6",22}, {"s7",23},
1066 {"d0",16}, {"d1",17}, {"d2",18}, {"d3",19},
1067 {"d4",20}, {"d5",21}, {"d6",22}, {"d7",23},
1068 /* FIXME: At some point we need to add VFP register names. */
1069 /* Array terminator. */
1073 #define BAD_ARGS _("Bad arguments to instruction")
1074 #define BAD_PC _("r15 not allowed here")
1075 #define BAD_FLAGS _("Instruction should not have flags")
1076 #define BAD_COND _("Instruction is not conditional")
1078 static struct hash_control
* arm_ops_hsh
= NULL
;
1079 static struct hash_control
* arm_tops_hsh
= NULL
;
1080 static struct hash_control
* arm_cond_hsh
= NULL
;
1081 static struct hash_control
* arm_shift_hsh
= NULL
;
1082 static struct hash_control
* arm_reg_hsh
= NULL
;
1083 static struct hash_control
* arm_psr_hsh
= NULL
;
1085 /* This table describes all the machine specific pseudo-ops the assembler
1086 has to support. The fields are:
1087 pseudo-op name without dot
1088 function to call to execute this pseudo-op
1089 Integer arg to pass to the function. */
1091 static void s_req
PARAMS ((int));
1092 static void s_align
PARAMS ((int));
1093 static void s_bss
PARAMS ((int));
1094 static void s_even
PARAMS ((int));
1095 static void s_ltorg
PARAMS ((int));
1096 static void s_arm
PARAMS ((int));
1097 static void s_thumb
PARAMS ((int));
1098 static void s_code
PARAMS ((int));
1099 static void s_force_thumb
PARAMS ((int));
1100 static void s_thumb_func
PARAMS ((int));
1101 static void s_thumb_set
PARAMS ((int));
1102 static void arm_s_text
PARAMS ((int));
1103 static void arm_s_data
PARAMS ((int));
1105 static void arm_s_section
PARAMS ((int));
1106 static void s_arm_elf_cons
PARAMS ((int));
1109 static int my_get_expression
PARAMS ((expressionS
*, char **));
1111 CONST pseudo_typeS md_pseudo_table
[] =
1113 /* Never called becasue '.req' does not start line. */
1114 { "req", s_req
, 0 },
1115 { "bss", s_bss
, 0 },
1116 { "align", s_align
, 0 },
1117 { "arm", s_arm
, 0 },
1118 { "thumb", s_thumb
, 0 },
1119 { "code", s_code
, 0 },
1120 { "force_thumb", s_force_thumb
, 0 },
1121 { "thumb_func", s_thumb_func
, 0 },
1122 { "thumb_set", s_thumb_set
, 0 },
1123 { "even", s_even
, 0 },
1124 { "ltorg", s_ltorg
, 0 },
1125 { "pool", s_ltorg
, 0 },
1126 /* Allow for the effect of section changes. */
1127 { "text", arm_s_text
, 0 },
1128 { "data", arm_s_data
, 0 },
1130 { "section", arm_s_section
, 0 },
1131 { "section.s", arm_s_section
, 0 },
1132 { "sect", arm_s_section
, 0 },
1133 { "sect.s", arm_s_section
, 0 },
1134 { "word", s_arm_elf_cons
, 4 },
1135 { "long", s_arm_elf_cons
, 4 },
1139 { "extend", float_cons
, 'x' },
1140 { "ldouble", float_cons
, 'x' },
1141 { "packed", float_cons
, 'p' },
1145 /* Stuff needed to resolve the label ambiguity
1155 symbolS
* last_label_seen
;
1156 static int label_is_thumb_function_name
= false;
1158 /* Literal stuff. */
1160 #define MAX_LITERAL_POOL_SIZE 1024
1162 typedef struct literalS
1164 struct expressionS exp
;
1165 struct arm_it
* inst
;
1168 literalT literals
[MAX_LITERAL_POOL_SIZE
];
1170 /* Next free entry in the pool. */
1171 int next_literal_pool_place
= 0;
1173 /* Next literal pool number. */
1174 int lit_pool_num
= 1;
1176 symbolS
* current_poolP
= NULL
;
1183 if (current_poolP
== NULL
)
1184 current_poolP
= symbol_create (FAKE_LABEL_NAME
, undefined_section
,
1185 (valueT
) 0, &zero_address_frag
);
1187 /* Check if this literal value is already in the pool: */
1188 while (lit_count
< next_literal_pool_place
)
1190 if (literals
[lit_count
].exp
.X_op
== inst
.reloc
.exp
.X_op
1191 && inst
.reloc
.exp
.X_op
== O_constant
1192 && (literals
[lit_count
].exp
.X_add_number
1193 == inst
.reloc
.exp
.X_add_number
)
1194 && literals
[lit_count
].exp
.X_unsigned
== inst
.reloc
.exp
.X_unsigned
)
1199 if (lit_count
== next_literal_pool_place
) /* New entry. */
1201 if (next_literal_pool_place
> MAX_LITERAL_POOL_SIZE
)
1203 inst
.error
= _("Literal Pool Overflow");
1207 literals
[next_literal_pool_place
].exp
= inst
.reloc
.exp
;
1208 lit_count
= next_literal_pool_place
++;
1211 inst
.reloc
.exp
.X_op
= O_symbol
;
1212 inst
.reloc
.exp
.X_add_number
= (lit_count
) * 4 - 8;
1213 inst
.reloc
.exp
.X_add_symbol
= current_poolP
;
1218 /* Can't use symbol_new here, so have to create a symbol and then at
1219 a later date assign it a value. Thats what these functions do. */
1222 symbol_locate (symbolP
, name
, segment
, valu
, frag
)
1224 CONST
char * name
; /* It is copied, the caller can modify. */
1225 segT segment
; /* Segment identifier (SEG_<something>). */
1226 valueT valu
; /* Symbol value. */
1227 fragS
* frag
; /* Associated fragment. */
1229 unsigned int name_length
;
1230 char * preserved_copy_of_name
;
1232 name_length
= strlen (name
) + 1; /* +1 for \0. */
1233 obstack_grow (¬es
, name
, name_length
);
1234 preserved_copy_of_name
= obstack_finish (¬es
);
1235 #ifdef STRIP_UNDERSCORE
1236 if (preserved_copy_of_name
[0] == '_')
1237 preserved_copy_of_name
++;
1240 #ifdef tc_canonicalize_symbol_name
1241 preserved_copy_of_name
=
1242 tc_canonicalize_symbol_name (preserved_copy_of_name
);
1245 S_SET_NAME (symbolP
, preserved_copy_of_name
);
1247 S_SET_SEGMENT (symbolP
, segment
);
1248 S_SET_VALUE (symbolP
, valu
);
1249 symbol_clear_list_pointers(symbolP
);
1251 symbol_set_frag (symbolP
, frag
);
1253 /* Link to end of symbol chain. */
1255 extern int symbol_table_frozen
;
1256 if (symbol_table_frozen
)
1260 symbol_append (symbolP
, symbol_lastP
, & symbol_rootP
, & symbol_lastP
);
1262 obj_symbol_new_hook (symbolP
);
1264 #ifdef tc_symbol_new_hook
1265 tc_symbol_new_hook (symbolP
);
1269 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
1270 #endif /* DEBUG_SYMS */
1273 /* Check that an immediate is valid.
1274 If so, convert it to the right format. */
1277 validate_immediate (val
)
1283 #define rotate_left(v, n) (v << n | v >> (32 - n))
1285 for (i
= 0; i
< 32; i
+= 2)
1286 if ((a
= rotate_left (val
, i
)) <= 0xff)
1287 return a
| (i
<< 7); /* 12-bit pack: [shift-cnt,const]. */
1292 /* Check to see if an immediate can be computed as two seperate immediate
1293 values, added together. We already know that this value cannot be
1294 computed by just one ARM instruction. */
1297 validate_immediate_twopart (val
, highpart
)
1299 unsigned int * highpart
;
1304 for (i
= 0; i
< 32; i
+= 2)
1305 if (((a
= rotate_left (val
, i
)) & 0xff) != 0)
1311 * highpart
= (a
>> 8) | ((i
+ 24) << 7);
1313 else if (a
& 0xff0000)
1317 * highpart
= (a
>> 16) | ((i
+ 16) << 7);
1321 assert (a
& 0xff000000);
1322 * highpart
= (a
>> 24) | ((i
+ 8) << 7);
1325 return (a
& 0xff) | (i
<< 7);
1332 validate_offset_imm (val
, hwse
)
1336 if ((hwse
&& val
> 255) || val
> 4095)
1343 int a ATTRIBUTE_UNUSED
;
1345 as_bad (_("Invalid syntax for .req directive."));
1350 int ignore ATTRIBUTE_UNUSED
;
1352 /* We don't support putting frags in the BSS segment, we fake it by
1353 marking in_bss, then looking at s_skip for clues. */
1354 subseg_set (bss_section
, 0);
1355 demand_empty_rest_of_line ();
1360 int ignore ATTRIBUTE_UNUSED
;
1362 /* Never make frag if expect extra pass. */
1364 frag_align (1, 0, 0);
1366 record_alignment (now_seg
, 1);
1368 demand_empty_rest_of_line ();
1373 int ignored ATTRIBUTE_UNUSED
;
1378 if (current_poolP
== NULL
)
1381 /* Align pool as you have word accesses.
1382 Only make a frag if we have to. */
1384 frag_align (2, 0, 0);
1386 record_alignment (now_seg
, 2);
1388 sprintf (sym_name
, "$$lit_\002%x", lit_pool_num
++);
1390 symbol_locate (current_poolP
, sym_name
, now_seg
,
1391 (valueT
) frag_now_fix (), frag_now
);
1392 symbol_table_insert (current_poolP
);
1394 ARM_SET_THUMB (current_poolP
, thumb_mode
);
1396 #if defined OBJ_COFF || defined OBJ_ELF
1397 ARM_SET_INTERWORK (current_poolP
, support_interwork
);
1400 while (lit_count
< next_literal_pool_place
)
1401 /* First output the expression in the instruction to the pool. */
1402 emit_expr (&(literals
[lit_count
++].exp
), 4); /* .word */
1404 next_literal_pool_place
= 0;
1405 current_poolP
= NULL
;
1408 /* Same as s_align_ptwo but align 0 => align 2. */
1412 int unused ATTRIBUTE_UNUSED
;
1415 register long temp_fill
;
1416 long max_alignment
= 15;
1418 temp
= get_absolute_expression ();
1419 if (temp
> max_alignment
)
1420 as_bad (_("Alignment too large: %d. assumed."), temp
= max_alignment
);
1423 as_bad (_("Alignment negative. 0 assumed."));
1427 if (*input_line_pointer
== ',')
1429 input_line_pointer
++;
1430 temp_fill
= get_absolute_expression ();
1438 /* Only make a frag if we HAVE to. */
1439 if (temp
&& !need_pass_2
)
1440 frag_align (temp
, (int) temp_fill
, 0);
1441 demand_empty_rest_of_line ();
1443 record_alignment (now_seg
, temp
);
1447 s_force_thumb (ignore
)
1448 int ignore ATTRIBUTE_UNUSED
;
1450 /* If we are not already in thumb mode go into it, EVEN if
1451 the target processor does not support thumb instructions.
1452 This is used by gcc/config/arm/lib1funcs.asm for example
1453 to compile interworking support functions even if the
1454 target processor should not support interworking. */
1459 record_alignment (now_seg
, 1);
1462 demand_empty_rest_of_line ();
1466 s_thumb_func (ignore
)
1467 int ignore ATTRIBUTE_UNUSED
;
1472 /* The following label is the name/address of the start of a Thumb function.
1473 We need to know this for the interworking support. */
1474 label_is_thumb_function_name
= true;
1476 demand_empty_rest_of_line ();
1479 /* Perform a .set directive, but also mark the alias as
1480 being a thumb function. */
1486 /* XXX the following is a duplicate of the code for s_set() in read.c
1487 We cannot just call that code as we need to get at the symbol that
1489 register char * name
;
1490 register char delim
;
1491 register char * end_name
;
1492 register symbolS
* symbolP
;
1494 /* Especial apologies for the random logic:
1495 This just grew, and could be parsed much more simply!
1497 name
= input_line_pointer
;
1498 delim
= get_symbol_end ();
1499 end_name
= input_line_pointer
;
1504 if (*input_line_pointer
!= ',')
1507 as_bad (_("Expected comma after name \"%s\""), name
);
1509 ignore_rest_of_line ();
1513 input_line_pointer
++;
1516 if (name
[0] == '.' && name
[1] == '\0')
1518 /* XXX - this should not happen to .thumb_set. */
1522 if ((symbolP
= symbol_find (name
)) == NULL
1523 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
1526 /* When doing symbol listings, play games with dummy fragments living
1527 outside the normal fragment chain to record the file and line info
1529 if (listing
& LISTING_SYMBOLS
)
1531 extern struct list_info_struct
* listing_tail
;
1532 fragS
* dummy_frag
= (fragS
*) xmalloc (sizeof (fragS
));
1534 memset (dummy_frag
, 0, sizeof (fragS
));
1535 dummy_frag
->fr_type
= rs_fill
;
1536 dummy_frag
->line
= listing_tail
;
1537 symbolP
= symbol_new (name
, undefined_section
, 0, dummy_frag
);
1538 dummy_frag
->fr_symbol
= symbolP
;
1542 symbolP
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1545 /* "set" symbols are local unless otherwise specified. */
1546 SF_SET_LOCAL (symbolP
);
1547 #endif /* OBJ_COFF */
1548 } /* Make a new symbol. */
1550 symbol_table_insert (symbolP
);
1555 && S_IS_DEFINED (symbolP
)
1556 && S_GET_SEGMENT (symbolP
) != reg_section
)
1557 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP
));
1559 pseudo_set (symbolP
);
1561 demand_empty_rest_of_line ();
1563 /* XXX Now we come to the Thumb specific bit of code. */
1565 THUMB_SET_FUNC (symbolP
, 1);
1566 ARM_SET_THUMB (symbolP
, 1);
1567 #if defined OBJ_ELF || defined OBJ_COFF
1568 ARM_SET_INTERWORK (symbolP
, support_interwork
);
1572 /* If we change section we must dump the literal pool first. */
1578 if (now_seg
!= text_section
)
1582 obj_elf_text (ignore
);
1592 if (flag_readonly_data_in_text
)
1594 if (now_seg
!= text_section
)
1597 else if (now_seg
!= data_section
)
1601 obj_elf_data (ignore
);
1609 arm_s_section (ignore
)
1614 obj_elf_section (ignore
);
1619 opcode_select (width
)
1627 if (! (cpu_variant
& ARM_THUMB
))
1628 as_bad (_("selected processor does not support THUMB opcodes"));
1631 /* No need to force the alignment, since we will have been
1632 coming from ARM mode, which is word-aligned. */
1633 record_alignment (now_seg
, 1);
1640 if ((cpu_variant
& ARM_ANY
) == ARM_THUMB
)
1641 as_bad (_("selected processor does not support ARM opcodes"));
1646 frag_align (2, 0, 0);
1648 record_alignment (now_seg
, 1);
1653 as_bad (_("invalid instruction size selected (%d)"), width
);
1659 int ignore ATTRIBUTE_UNUSED
;
1662 demand_empty_rest_of_line ();
1667 int ignore ATTRIBUTE_UNUSED
;
1670 demand_empty_rest_of_line ();
1675 int unused ATTRIBUTE_UNUSED
;
1679 temp
= get_absolute_expression ();
1684 opcode_select (temp
);
1688 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp
);
1696 skip_whitespace (str
);
1699 inst
.error
= _("Garbage following instruction");
1703 skip_past_comma (str
)
1706 char * p
= * str
, c
;
1709 while ((c
= *p
) == ' ' || c
== ',')
1712 if (c
== ',' && comma
++)
1720 return comma
? SUCCESS
: FAIL
;
1723 /* A standard register must be given at this point.
1724 SHIFT is the place to put it in inst.instruction.
1725 Restores input start point on error.
1726 Returns the reg#, or FAIL. */
1729 reg_required_here (str
, shift
)
1733 static char buff
[128]; /* XXX */
1735 char * start
= * str
;
1737 if ((reg
= arm_reg_parse (str
)) != FAIL
&& int_register (reg
))
1740 inst
.instruction
|= reg
<< shift
;
1744 /* Restore the start point, we may have got a reg of the wrong class. */
1747 /* In the few cases where we might be able to accept something else
1748 this error can be overridden. */
1749 sprintf (buff
, _("Register expected, not '%.100s'"), start
);
1755 static CONST
struct asm_psr
*
1757 register char ** ccp
;
1759 char * start
= * ccp
;
1762 CONST
struct asm_psr
* psr
;
1766 /* Skip to the end of the next word in the input stream. */
1771 while (isalpha (c
) || c
== '_');
1773 /* Terminate the word. */
1776 /* Now locate the word in the psr hash table. */
1777 psr
= (CONST
struct asm_psr
*) hash_find (arm_psr_hsh
, start
);
1779 /* Restore the input stream. */
1782 /* If we found a valid match, advance the
1783 stream pointer past the end of the word. */
1789 /* Parse the input looking for a PSR flag. */
1792 psr_required_here (str
)
1795 char * start
= * str
;
1796 CONST
struct asm_psr
* psr
;
1798 psr
= arm_psr_parse (str
);
1802 /* If this is the SPSR that is being modified, set the R bit. */
1804 inst
.instruction
|= SPSR_BIT
;
1806 /* Set the psr flags in the MSR instruction. */
1807 inst
.instruction
|= psr
->field
<< PSR_SHIFT
;
1812 /* In the few cases where we might be able to accept
1813 something else this error can be overridden. */
1814 inst
.error
= _("flag for {c}psr instruction expected");
1816 /* Restore the start point. */
1822 co_proc_number (str
)
1825 int processor
, pchar
;
1827 skip_whitespace (* str
);
1829 /* The data sheet seems to imply that just a number on its own is valid
1830 here, but the RISC iX assembler seems to accept a prefix 'p'. We will
1832 if (**str
== 'p' || **str
== 'P')
1836 if (pchar
>= '0' && pchar
<= '9')
1838 processor
= pchar
- '0';
1839 if (**str
>= '0' && **str
<= '9')
1841 processor
= processor
* 10 + *(*str
)++ - '0';
1844 inst
.error
= _("Illegal co-processor number");
1851 inst
.error
= _("Bad or missing co-processor number");
1855 inst
.instruction
|= processor
<< 8;
1860 cp_opc_expr (str
, where
, length
)
1867 skip_whitespace (* str
);
1869 memset (&expr
, '\0', sizeof (expr
));
1871 if (my_get_expression (&expr
, str
))
1873 if (expr
.X_op
!= O_constant
)
1875 inst
.error
= _("bad or missing expression");
1879 if ((expr
.X_add_number
& ((1 << length
) - 1)) != expr
.X_add_number
)
1881 inst
.error
= _("immediate co-processor expression too large");
1885 inst
.instruction
|= expr
.X_add_number
<< where
;
1890 cp_reg_required_here (str
, where
)
1895 char * start
= *str
;
1897 if ((reg
= arm_reg_parse (str
)) != FAIL
&& cp_register (reg
))
1900 inst
.instruction
|= reg
<< where
;
1904 /* In the few cases where we might be able to accept something else
1905 this error can be overridden. */
1906 inst
.error
= _("Co-processor register expected");
1908 /* Restore the start point. */
1914 fp_reg_required_here (str
, where
)
1919 char * start
= * str
;
1921 if ((reg
= arm_reg_parse (str
)) != FAIL
&& fp_register (reg
))
1924 inst
.instruction
|= reg
<< where
;
1928 /* In the few cases where we might be able to accept something else
1929 this error can be overridden. */
1930 inst
.error
= _("Floating point register expected");
1932 /* Restore the start point. */
1938 cp_address_offset (str
)
1943 skip_whitespace (* str
);
1945 if (! is_immediate_prefix (**str
))
1947 inst
.error
= _("immediate expression expected");
1953 if (my_get_expression (& inst
.reloc
.exp
, str
))
1956 if (inst
.reloc
.exp
.X_op
== O_constant
)
1958 offset
= inst
.reloc
.exp
.X_add_number
;
1962 inst
.error
= _("co-processor address must be word aligned");
1966 if (offset
> 1023 || offset
< -1023)
1968 inst
.error
= _("offset too large");
1973 inst
.instruction
|= INDEX_UP
;
1977 inst
.instruction
|= offset
>> 2;
1980 inst
.reloc
.type
= BFD_RELOC_ARM_CP_OFF_IMM
;
1986 cp_address_required_here (str
)
1998 skip_whitespace (p
);
2000 if ((reg
= reg_required_here (& p
, 16)) == FAIL
)
2003 skip_whitespace (p
);
2009 if (skip_past_comma (& p
) == SUCCESS
)
2012 write_back
= WRITE_BACK
;
2016 inst
.error
= _("pc may not be used in post-increment");
2020 if (cp_address_offset (& p
) == FAIL
)
2024 pre_inc
= PRE_INDEX
| INDEX_UP
;
2028 /* '['Rn, #expr']'[!] */
2030 if (skip_past_comma (& p
) == FAIL
)
2032 inst
.error
= _("pre-indexed expression expected");
2036 pre_inc
= PRE_INDEX
;
2038 if (cp_address_offset (& p
) == FAIL
)
2041 skip_whitespace (p
);
2045 inst
.error
= _("missing ]");
2049 skip_whitespace (p
);
2055 inst
.error
= _("pc may not be used with write-back");
2060 write_back
= WRITE_BACK
;
2066 if (my_get_expression (&inst
.reloc
.exp
, &p
))
2069 inst
.reloc
.type
= BFD_RELOC_ARM_CP_OFF_IMM
;
2070 inst
.reloc
.exp
.X_add_number
-= 8; /* PC rel adjust. */
2071 inst
.reloc
.pc_rel
= 1;
2072 inst
.instruction
|= (REG_PC
<< 16);
2073 pre_inc
= PRE_INDEX
;
2076 inst
.instruction
|= write_back
| pre_inc
;
2084 unsigned long flags
;
2086 /* Do nothing really. */
2087 inst
.instruction
|= flags
; /* This is pointless. */
2095 unsigned long flags
;
2099 /* Only one syntax. */
2100 skip_whitespace (str
);
2102 if (reg_required_here (&str
, 12) == FAIL
)
2104 inst
.error
= BAD_ARGS
;
2108 if (skip_past_comma (&str
) == FAIL
)
2110 inst
.error
= _("comma expected after register name");
2114 skip_whitespace (str
);
2116 if ( strcmp (str
, "CPSR") == 0
2117 || strcmp (str
, "SPSR") == 0
2118 /* Lower case versions for backwards compatability. */
2119 || strcmp (str
, "cpsr") == 0
2120 || strcmp (str
, "spsr") == 0)
2123 /* This is for backwards compatability with older toolchains. */
2124 else if ( strcmp (str
, "cpsr_all") == 0
2125 || strcmp (str
, "spsr_all") == 0)
2129 inst
.error
= _("{C|S}PSR expected");
2133 if (* str
== 's' || * str
== 'S')
2134 inst
.instruction
|= SPSR_BIT
;
2137 inst
.instruction
|= flags
;
2141 /* Two possible forms:
2142 "{C|S}PSR_<field>, Rm",
2143 "{C|S}PSR_f, #expression". */
2148 unsigned long flags
;
2150 skip_whitespace (str
);
2152 if (psr_required_here (& str
) == FAIL
)
2155 if (skip_past_comma (& str
) == FAIL
)
2157 inst
.error
= _("comma missing after psr flags");
2161 skip_whitespace (str
);
2163 if (reg_required_here (& str
, 0) != FAIL
)
2166 inst
.instruction
|= flags
;
2171 if (! is_immediate_prefix (* str
))
2174 _("only a register or immediate value can follow a psr flag");
2181 if (my_get_expression (& inst
.reloc
.exp
, & str
))
2184 _("only a register or immediate value can follow a psr flag");
2188 if (inst
.instruction
& ((PSR_c
| PSR_x
| PSR_s
) << PSR_SHIFT
))
2190 inst
.error
= _("can only set flag field with immediate value");
2194 flags
|= INST_IMMEDIATE
;
2196 if (inst
.reloc
.exp
.X_add_symbol
)
2198 inst
.reloc
.type
= BFD_RELOC_ARM_IMMEDIATE
;
2199 inst
.reloc
.pc_rel
= 0;
2203 unsigned value
= validate_immediate (inst
.reloc
.exp
.X_add_number
);
2205 if (value
== (unsigned) FAIL
)
2207 inst
.error
= _("Invalid constant");
2211 inst
.instruction
|= value
;
2215 inst
.instruction
|= flags
;
2219 /* Long Multiply Parser
2220 UMULL RdLo, RdHi, Rm, Rs
2221 SMULL RdLo, RdHi, Rm, Rs
2222 UMLAL RdLo, RdHi, Rm, Rs
2223 SMLAL RdLo, RdHi, Rm, Rs. */
2226 do_mull (str
, flags
)
2228 unsigned long flags
;
2230 int rdlo
, rdhi
, rm
, rs
;
2232 /* Only one format "rdlo, rdhi, rm, rs". */
2233 skip_whitespace (str
);
2235 if ((rdlo
= reg_required_here (&str
, 12)) == FAIL
)
2237 inst
.error
= BAD_ARGS
;
2241 if (skip_past_comma (&str
) == FAIL
2242 || (rdhi
= reg_required_here (&str
, 16)) == FAIL
)
2244 inst
.error
= BAD_ARGS
;
2248 if (skip_past_comma (&str
) == FAIL
2249 || (rm
= reg_required_here (&str
, 0)) == FAIL
)
2251 inst
.error
= BAD_ARGS
;
2255 /* rdhi, rdlo and rm must all be different. */
2256 if (rdlo
== rdhi
|| rdlo
== rm
|| rdhi
== rm
)
2257 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
2259 if (skip_past_comma (&str
) == FAIL
2260 || (rs
= reg_required_here (&str
, 8)) == FAIL
)
2262 inst
.error
= BAD_ARGS
;
2266 if (rdhi
== REG_PC
|| rdhi
== REG_PC
|| rdhi
== REG_PC
|| rdhi
== REG_PC
)
2268 inst
.error
= BAD_PC
;
2272 inst
.instruction
|= flags
;
2280 unsigned long flags
;
2284 /* Only one format "rd, rm, rs". */
2285 skip_whitespace (str
);
2287 if ((rd
= reg_required_here (&str
, 16)) == FAIL
)
2289 inst
.error
= BAD_ARGS
;
2295 inst
.error
= BAD_PC
;
2299 if (skip_past_comma (&str
) == FAIL
2300 || (rm
= reg_required_here (&str
, 0)) == FAIL
)
2302 inst
.error
= BAD_ARGS
;
2308 inst
.error
= BAD_PC
;
2313 as_tsktsk (_("rd and rm should be different in mul"));
2315 if (skip_past_comma (&str
) == FAIL
2316 || (rm
= reg_required_here (&str
, 8)) == FAIL
)
2318 inst
.error
= BAD_ARGS
;
2324 inst
.error
= BAD_PC
;
2328 inst
.instruction
|= flags
;
2336 unsigned long flags
;
2340 /* Only one format "rd, rm, rs, rn". */
2341 skip_whitespace (str
);
2343 if ((rd
= reg_required_here (&str
, 16)) == FAIL
)
2345 inst
.error
= BAD_ARGS
;
2351 inst
.error
= BAD_PC
;
2355 if (skip_past_comma (&str
) == FAIL
2356 || (rm
= reg_required_here (&str
, 0)) == FAIL
)
2358 inst
.error
= BAD_ARGS
;
2364 inst
.error
= BAD_PC
;
2369 as_tsktsk (_("rd and rm should be different in mla"));
2371 if (skip_past_comma (&str
) == FAIL
2372 || (rd
= reg_required_here (&str
, 8)) == FAIL
2373 || skip_past_comma (&str
) == FAIL
2374 || (rm
= reg_required_here (&str
, 12)) == FAIL
)
2376 inst
.error
= BAD_ARGS
;
2380 if (rd
== REG_PC
|| rm
== REG_PC
)
2382 inst
.error
= BAD_PC
;
2386 inst
.instruction
|= flags
;
2391 /* Returns the index into fp_values of a floating point number,
2392 or -1 if not in the table. */
2395 my_get_float_expression (str
)
2398 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2404 memset (words
, 0, MAX_LITTLENUMS
* sizeof (LITTLENUM_TYPE
));
2406 /* Look for a raw floating point number. */
2407 if ((save_in
= atof_ieee (*str
, 'x', words
)) != NULL
2408 && is_end_of_line
[(unsigned char) *save_in
])
2410 for (i
= 0; i
< NUM_FLOAT_VALS
; i
++)
2412 for (j
= 0; j
< MAX_LITTLENUMS
; j
++)
2414 if (words
[j
] != fp_values
[i
][j
])
2418 if (j
== MAX_LITTLENUMS
)
2426 /* Try and parse a more complex expression, this will probably fail
2427 unless the code uses a floating point prefix (eg "0f"). */
2428 save_in
= input_line_pointer
;
2429 input_line_pointer
= *str
;
2430 if (expression (&exp
) == absolute_section
2431 && exp
.X_op
== O_big
2432 && exp
.X_add_number
< 0)
2434 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
2436 if (gen_to_words (words
, 5, (long) 15) == 0)
2438 for (i
= 0; i
< NUM_FLOAT_VALS
; i
++)
2440 for (j
= 0; j
< MAX_LITTLENUMS
; j
++)
2442 if (words
[j
] != fp_values
[i
][j
])
2446 if (j
== MAX_LITTLENUMS
)
2448 *str
= input_line_pointer
;
2449 input_line_pointer
= save_in
;
2456 *str
= input_line_pointer
;
2457 input_line_pointer
= save_in
;
2461 /* Return true if anything in the expression is a bignum. */
2464 walk_no_bignums (sp
)
2467 if (symbol_get_value_expression (sp
)->X_op
== O_big
)
2470 if (symbol_get_value_expression (sp
)->X_add_symbol
)
2472 return (walk_no_bignums (symbol_get_value_expression (sp
)->X_add_symbol
)
2473 || (symbol_get_value_expression (sp
)->X_op_symbol
2474 && walk_no_bignums (symbol_get_value_expression (sp
)->X_op_symbol
)));
2481 my_get_expression (ep
, str
)
2488 save_in
= input_line_pointer
;
2489 input_line_pointer
= *str
;
2490 seg
= expression (ep
);
2493 if (seg
!= absolute_section
2494 && seg
!= text_section
2495 && seg
!= data_section
2496 && seg
!= bss_section
2497 && seg
!= undefined_section
)
2499 inst
.error
= _("bad_segment");
2500 *str
= input_line_pointer
;
2501 input_line_pointer
= save_in
;
2506 /* Get rid of any bignums now, so that we don't generate an error for which
2507 we can't establish a line number later on. Big numbers are never valid
2508 in instructions, which is where this routine is always called. */
2509 if (ep
->X_op
== O_big
2510 || (ep
->X_add_symbol
2511 && (walk_no_bignums (ep
->X_add_symbol
)
2513 && walk_no_bignums (ep
->X_op_symbol
)))))
2515 inst
.error
= _("Invalid constant");
2516 *str
= input_line_pointer
;
2517 input_line_pointer
= save_in
;
2521 *str
= input_line_pointer
;
2522 input_line_pointer
= save_in
;
2526 /* UNRESTRICT should be one if <shift> <register> is permitted for this
2530 decode_shift (str
, unrestrict
)
2534 struct asm_shift_name
* shift
;
2538 skip_whitespace (* str
);
2540 for (p
= * str
; isalpha (* p
); p
++)
2545 inst
.error
= _("Shift expression expected");
2551 shift
= (struct asm_shift_name
*) hash_find (arm_shift_hsh
, * str
);
2556 inst
.error
= _("Shift expression expected");
2560 assert (shift
->properties
->index
== shift_properties
[shift
->properties
->index
].index
);
2562 if (shift
->properties
->index
== SHIFT_RRX
)
2565 inst
.instruction
|= shift
->properties
->bit_field
;
2569 skip_whitespace (p
);
2571 if (unrestrict
&& reg_required_here (& p
, 8) != FAIL
)
2573 inst
.instruction
|= shift
->properties
->bit_field
| SHIFT_BY_REG
;
2577 else if (! is_immediate_prefix (* p
))
2579 inst
.error
= (unrestrict
2580 ? _("shift requires register or #expression")
2581 : _("shift requires #expression"));
2589 if (my_get_expression (& inst
.reloc
.exp
, & p
))
2592 /* Validate some simple #expressions. */
2593 if (inst
.reloc
.exp
.X_op
== O_constant
)
2595 unsigned num
= inst
.reloc
.exp
.X_add_number
;
2597 /* Reject operations greater than 32. */
2599 /* Reject a shift of 0 unless the mode allows it. */
2600 || (num
== 0 && shift
->properties
->allows_0
== 0)
2601 /* Reject a shift of 32 unless the mode allows it. */
2602 || (num
== 32 && shift
->properties
->allows_32
== 0)
2605 /* As a special case we allow ROR #0, but we issue a message
2606 reminding the programmer that this is actually an RRX. */
2607 if (num
== 0 && shift
->properties
->index
== SHIFT_ROR
)
2608 as_tsktsk (_("ROR #0 is actually RRX"));
2611 inst
.error
= _("Invalid immediate shift");
2616 /* Shifts of 32 are encoded as 0, for those shifts that
2621 inst
.instruction
|= (num
<< 7) | shift
->properties
->bit_field
;
2625 inst
.reloc
.type
= BFD_RELOC_ARM_SHIFT_IMM
;
2626 inst
.reloc
.pc_rel
= 0;
2627 inst
.instruction
|= shift
->properties
->bit_field
;
2634 /* Do those data_ops which can take a negative immediate constant
2635 by altering the instuction. A bit of a hack really.
2639 by inverting the second operand, and
2642 by negating the second operand. */
2645 negate_data_op (instruction
, value
)
2646 unsigned long * instruction
;
2647 unsigned long value
;
2650 unsigned long negated
, inverted
;
2652 negated
= validate_immediate (-value
);
2653 inverted
= validate_immediate (~value
);
2655 op
= (*instruction
>> DATA_OP_SHIFT
) & 0xf;
2658 /* First negates. */
2659 case OPCODE_SUB
: /* ADD <-> SUB */
2660 new_inst
= OPCODE_ADD
;
2665 new_inst
= OPCODE_SUB
;
2669 case OPCODE_CMP
: /* CMP <-> CMN */
2670 new_inst
= OPCODE_CMN
;
2675 new_inst
= OPCODE_CMP
;
2679 /* Now Inverted ops. */
2680 case OPCODE_MOV
: /* MOV <-> MVN */
2681 new_inst
= OPCODE_MVN
;
2686 new_inst
= OPCODE_MOV
;
2690 case OPCODE_AND
: /* AND <-> BIC */
2691 new_inst
= OPCODE_BIC
;
2696 new_inst
= OPCODE_AND
;
2700 case OPCODE_ADC
: /* ADC <-> SBC */
2701 new_inst
= OPCODE_SBC
;
2706 new_inst
= OPCODE_ADC
;
2710 /* We cannot do anything. */
2715 if (value
== (unsigned) FAIL
)
2718 *instruction
&= OPCODE_MASK
;
2719 *instruction
|= new_inst
<< DATA_OP_SHIFT
;
2730 skip_whitespace (* str
);
2732 if (reg_required_here (str
, 0) != FAIL
)
2734 if (skip_past_comma (str
) == SUCCESS
)
2735 /* Shift operation on register. */
2736 return decode_shift (str
, NO_SHIFT_RESTRICT
);
2742 /* Immediate expression. */
2743 if (is_immediate_prefix (**str
))
2748 if (my_get_expression (&inst
.reloc
.exp
, str
))
2751 if (inst
.reloc
.exp
.X_add_symbol
)
2753 inst
.reloc
.type
= BFD_RELOC_ARM_IMMEDIATE
;
2754 inst
.reloc
.pc_rel
= 0;
2758 if (skip_past_comma (str
) == SUCCESS
)
2760 /* #x, y -- ie explicit rotation by Y. */
2761 if (my_get_expression (&expr
, str
))
2764 if (expr
.X_op
!= O_constant
)
2766 inst
.error
= _("Constant expression expected");
2770 /* Rotate must be a multiple of 2. */
2771 if (((unsigned) expr
.X_add_number
) > 30
2772 || (expr
.X_add_number
& 1) != 0
2773 || ((unsigned) inst
.reloc
.exp
.X_add_number
) > 255)
2775 inst
.error
= _("Invalid constant");
2778 inst
.instruction
|= INST_IMMEDIATE
;
2779 inst
.instruction
|= inst
.reloc
.exp
.X_add_number
;
2780 inst
.instruction
|= expr
.X_add_number
<< 7;
2784 /* Implicit rotation, select a suitable one. */
2785 value
= validate_immediate (inst
.reloc
.exp
.X_add_number
);
2789 /* Can't be done. Perhaps the code reads something like
2790 "add Rd, Rn, #-n", where "sub Rd, Rn, #n" would be OK. */
2791 if ((value
= negate_data_op (&inst
.instruction
,
2792 inst
.reloc
.exp
.X_add_number
))
2795 inst
.error
= _("Invalid constant");
2800 inst
.instruction
|= value
;
2803 inst
.instruction
|= INST_IMMEDIATE
;
2808 inst
.error
= _("Register or shift expression expected");
2817 skip_whitespace (* str
);
2819 if (fp_reg_required_here (str
, 0) != FAIL
)
2823 /* Immediate expression. */
2824 if (*((*str
)++) == '#')
2830 skip_whitespace (* str
);
2832 /* First try and match exact strings, this is to guarantee
2833 that some formats will work even for cross assembly. */
2835 for (i
= 0; fp_const
[i
]; i
++)
2837 if (strncmp (*str
, fp_const
[i
], strlen (fp_const
[i
])) == 0)
2841 *str
+= strlen (fp_const
[i
]);
2842 if (is_end_of_line
[(unsigned char) **str
])
2844 inst
.instruction
|= i
+ 8;
2851 /* Just because we didn't get a match doesn't mean that the
2852 constant isn't valid, just that it is in a format that we
2853 don't automatically recognize. Try parsing it with
2854 the standard expression routines. */
2855 if ((i
= my_get_float_expression (str
)) >= 0)
2857 inst
.instruction
|= i
+ 8;
2861 inst
.error
= _("Invalid floating point immediate expression");
2865 _("Floating point register or immediate expression expected");
2871 do_arit (str
, flags
)
2873 unsigned long flags
;
2875 skip_whitespace (str
);
2877 if (reg_required_here (&str
, 12) == FAIL
2878 || skip_past_comma (&str
) == FAIL
2879 || reg_required_here (&str
, 16) == FAIL
2880 || skip_past_comma (&str
) == FAIL
2881 || data_op2 (&str
) == FAIL
)
2884 inst
.error
= BAD_ARGS
;
2888 inst
.instruction
|= flags
;
2896 unsigned long flags
;
2898 /* This is a pseudo-op of the form "adr rd, label" to be converted
2899 into a relative address of the form "add rd, pc, #label-.-8". */
2900 skip_whitespace (str
);
2902 if (reg_required_here (&str
, 12) == FAIL
2903 || skip_past_comma (&str
) == FAIL
2904 || my_get_expression (&inst
.reloc
.exp
, &str
))
2907 inst
.error
= BAD_ARGS
;
2911 /* Frag hacking will turn this into a sub instruction if the offset turns
2912 out to be negative. */
2913 inst
.reloc
.type
= BFD_RELOC_ARM_IMMEDIATE
;
2914 inst
.reloc
.exp
.X_add_number
-= 8; /* PC relative adjust. */
2915 inst
.reloc
.pc_rel
= 1;
2916 inst
.instruction
|= flags
;
2922 do_adrl (str
, flags
)
2924 unsigned long flags
;
2926 /* This is a pseudo-op of the form "adrl rd, label" to be converted
2927 into a relative address of the form:
2928 add rd, pc, #low(label-.-8)"
2929 add rd, rd, #high(label-.-8)" */
2931 skip_whitespace (str
);
2933 if (reg_required_here (& str
, 12) == FAIL
2934 || skip_past_comma (& str
) == FAIL
2935 || my_get_expression (& inst
.reloc
.exp
, & str
))
2938 inst
.error
= BAD_ARGS
;
2944 /* Frag hacking will turn this into a sub instruction if the offset turns
2945 out to be negative. */
2946 inst
.reloc
.type
= BFD_RELOC_ARM_ADRL_IMMEDIATE
;
2947 inst
.reloc
.exp
.X_add_number
-= 8; /* PC relative adjust */
2948 inst
.reloc
.pc_rel
= 1;
2949 inst
.instruction
|= flags
;
2950 inst
.size
= INSN_SIZE
* 2;
2958 unsigned long flags
;
2960 skip_whitespace (str
);
2962 if (reg_required_here (&str
, 16) == FAIL
)
2965 inst
.error
= BAD_ARGS
;
2969 if (skip_past_comma (&str
) == FAIL
2970 || data_op2 (&str
) == FAIL
)
2973 inst
.error
= BAD_ARGS
;
2977 inst
.instruction
|= flags
;
2978 if ((flags
& 0x0000f000) == 0)
2979 inst
.instruction
|= CONDS_BIT
;
2988 unsigned long flags
;
2990 skip_whitespace (str
);
2992 if (reg_required_here (&str
, 12) == FAIL
)
2995 inst
.error
= BAD_ARGS
;
2999 if (skip_past_comma (&str
) == FAIL
3000 || data_op2 (&str
) == FAIL
)
3003 inst
.error
= BAD_ARGS
;
3007 inst
.instruction
|= flags
;
3013 ldst_extend (str
, hwse
)
3024 if (my_get_expression (& inst
.reloc
.exp
, str
))
3027 if (inst
.reloc
.exp
.X_op
== O_constant
)
3029 int value
= inst
.reloc
.exp
.X_add_number
;
3031 if ((hwse
&& (value
< -255 || value
> 255))
3032 || (value
< -4095 || value
> 4095))
3034 inst
.error
= _("address offset too large");
3044 /* Halfword and signextension instructions have the
3045 immediate value split across bits 11..8 and bits 3..0. */
3047 inst
.instruction
|= (add
| HWOFFSET_IMM
3048 | ((value
>> 4) << 8) | (value
& 0xF));
3050 inst
.instruction
|= add
| value
;
3056 inst
.instruction
|= HWOFFSET_IMM
;
3057 inst
.reloc
.type
= BFD_RELOC_ARM_OFFSET_IMM8
;
3060 inst
.reloc
.type
= BFD_RELOC_ARM_OFFSET_IMM
;
3061 inst
.reloc
.pc_rel
= 0;
3074 if (reg_required_here (str
, 0) == FAIL
)
3078 inst
.instruction
|= add
;
3081 inst
.instruction
|= add
| OFFSET_REG
;
3082 if (skip_past_comma (str
) == SUCCESS
)
3083 return decode_shift (str
, SHIFT_RESTRICT
);
3091 do_ldst (str
, flags
)
3093 unsigned long flags
;
3100 /* This is not ideal, but it is the simplest way of dealing with the
3101 ARM7T halfword instructions (since they use a different
3102 encoding, but the same mnemonic): */
3103 halfword
= (flags
& 0x80000000) != 0;
3106 /* This is actually a load/store of a halfword, or a
3107 signed-extension load. */
3108 if ((cpu_variant
& ARM_HALFWORD
) == 0)
3111 = _("Processor does not support halfwords or signed bytes");
3115 inst
.instruction
= ((inst
.instruction
& COND_MASK
)
3116 | (flags
& ~COND_MASK
));
3121 skip_whitespace (str
);
3123 if ((conflict_reg
= reg_required_here (& str
, 12)) == FAIL
)
3126 inst
.error
= BAD_ARGS
;
3130 if (skip_past_comma (& str
) == FAIL
)
3132 inst
.error
= _("Address expected");
3142 skip_whitespace (str
);
3144 if ((reg
= reg_required_here (&str
, 16)) == FAIL
)
3147 /* Conflicts can occur on stores as well as loads. */
3148 conflict_reg
= (conflict_reg
== reg
);
3150 skip_whitespace (str
);
3156 if (skip_past_comma (&str
) == SUCCESS
)
3158 /* [Rn],... (post inc) */
3159 if (ldst_extend (&str
, halfword
) == FAIL
)
3162 as_warn (_("%s register same as write-back base"),
3163 ((inst
.instruction
& LOAD_BIT
)
3164 ? _("destination") : _("source")));
3170 inst
.instruction
|= HWOFFSET_IMM
;
3172 skip_whitespace (str
);
3177 as_warn (_("%s register same as write-back base"),
3178 ((inst
.instruction
& LOAD_BIT
)
3179 ? _("destination") : _("source")));
3181 inst
.instruction
|= WRITE_BACK
;
3185 if (! (flags
& TRANS_BIT
))
3192 if (skip_past_comma (&str
) == FAIL
)
3194 inst
.error
= _("pre-indexed expression expected");
3199 if (ldst_extend (&str
, halfword
) == FAIL
)
3202 skip_whitespace (str
);
3206 inst
.error
= _("missing ]");
3210 skip_whitespace (str
);
3215 as_warn (_("%s register same as write-back base"),
3216 ((inst
.instruction
& LOAD_BIT
)
3217 ? _("destination") : _("source")));
3219 inst
.instruction
|= WRITE_BACK
;
3223 else if (*str
== '=')
3225 /* Parse an "ldr Rd, =expr" instruction; this is another pseudo op. */
3228 skip_whitespace (str
);
3230 if (my_get_expression (&inst
.reloc
.exp
, &str
))
3233 if (inst
.reloc
.exp
.X_op
!= O_constant
3234 && inst
.reloc
.exp
.X_op
!= O_symbol
)
3236 inst
.error
= _("Constant expression expected");
3240 if (inst
.reloc
.exp
.X_op
== O_constant
3241 && (value
= validate_immediate (inst
.reloc
.exp
.X_add_number
)) != FAIL
)
3243 /* This can be done with a mov instruction. */
3244 inst
.instruction
&= LITERAL_MASK
;
3245 inst
.instruction
|= INST_IMMEDIATE
| (OPCODE_MOV
<< DATA_OP_SHIFT
);
3246 inst
.instruction
|= (flags
& COND_MASK
) | (value
& 0xfff);
3252 /* Insert into literal pool. */
3253 if (add_to_lit_pool () == FAIL
)
3256 inst
.error
= _("literal pool insertion failed");
3260 /* Change the instruction exp to point to the pool. */
3263 inst
.instruction
|= HWOFFSET_IMM
;
3264 inst
.reloc
.type
= BFD_RELOC_ARM_HWLITERAL
;
3267 inst
.reloc
.type
= BFD_RELOC_ARM_LITERAL
;
3268 inst
.reloc
.pc_rel
= 1;
3269 inst
.instruction
|= (REG_PC
<< 16);
3275 if (my_get_expression (&inst
.reloc
.exp
, &str
))
3280 inst
.instruction
|= HWOFFSET_IMM
;
3281 inst
.reloc
.type
= BFD_RELOC_ARM_OFFSET_IMM8
;
3284 inst
.reloc
.type
= BFD_RELOC_ARM_OFFSET_IMM
;
3286 /* PC rel adjust. */
3287 inst
.reloc
.exp
.X_add_number
-= 8;
3289 inst
.reloc
.pc_rel
= 1;
3290 inst
.instruction
|= (REG_PC
<< 16);
3294 if (pre_inc
&& (flags
& TRANS_BIT
))
3295 inst
.error
= _("Pre-increment instruction with translate");
3297 inst
.instruction
|= flags
| (pre_inc
? PRE_INDEX
: 0);
3306 char * str
= * strp
;
3310 /* We come back here if we get ranges concatenated by '+' or '|'. */
3325 skip_whitespace (str
);
3327 if ((reg
= reg_required_here (& str
, -1)) == FAIL
)
3336 inst
.error
= _("Bad range in register list");
3340 for (i
= cur_reg
+ 1; i
< reg
; i
++)
3342 if (range
& (1 << i
))
3344 (_("Warning: Duplicated register (r%d) in register list"),
3352 if (range
& (1 << reg
))
3353 as_tsktsk (_("Warning: Duplicated register (r%d) in register list"),
3355 else if (reg
<= cur_reg
)
3356 as_tsktsk (_("Warning: Register range not in ascending order"));
3361 while (skip_past_comma (&str
) != FAIL
3362 || (in_range
= 1, *str
++ == '-'));
3364 skip_whitespace (str
);
3368 inst
.error
= _("Missing `}'");
3376 if (my_get_expression (&expr
, &str
))
3379 if (expr
.X_op
== O_constant
)
3381 if (expr
.X_add_number
3382 != (expr
.X_add_number
& 0x0000ffff))
3384 inst
.error
= _("invalid register mask");
3388 if ((range
& expr
.X_add_number
) != 0)
3390 int regno
= range
& expr
.X_add_number
;
3393 regno
= (1 << regno
) - 1;
3395 (_("Warning: Duplicated register (r%d) in register list"),
3399 range
|= expr
.X_add_number
;
3403 if (inst
.reloc
.type
!= 0)
3405 inst
.error
= _("expression too complex");
3409 memcpy (&inst
.reloc
.exp
, &expr
, sizeof (expressionS
));
3410 inst
.reloc
.type
= BFD_RELOC_ARM_MULTI
;
3411 inst
.reloc
.pc_rel
= 0;
3415 skip_whitespace (str
);
3417 if (*str
== '|' || *str
== '+')
3423 while (another_range
);
3430 do_ldmstm (str
, flags
)
3432 unsigned long flags
;
3437 skip_whitespace (str
);
3439 if ((base_reg
= reg_required_here (&str
, 16)) == FAIL
)
3442 if (base_reg
== REG_PC
)
3444 inst
.error
= _("r15 not allowed as base register");
3448 skip_whitespace (str
);
3452 flags
|= WRITE_BACK
;
3456 if (skip_past_comma (&str
) == FAIL
3457 || (range
= reg_list (&str
)) == FAIL
)
3460 inst
.error
= BAD_ARGS
;
3467 flags
|= LDM_TYPE_2_OR_3
;
3470 inst
.instruction
|= flags
| range
;
3478 unsigned long flags
;
3480 skip_whitespace (str
);
3482 /* Allow optional leading '#'. */
3483 if (is_immediate_prefix (*str
))
3486 if (my_get_expression (& inst
.reloc
.exp
, & str
))
3489 inst
.reloc
.type
= BFD_RELOC_ARM_SWI
;
3490 inst
.reloc
.pc_rel
= 0;
3491 inst
.instruction
|= flags
;
3499 do_swap (str
, flags
)
3501 unsigned long flags
;
3505 skip_whitespace (str
);
3507 if ((reg
= reg_required_here (&str
, 12)) == FAIL
)
3512 inst
.error
= _("r15 not allowed in swap");
3516 if (skip_past_comma (&str
) == FAIL
3517 || (reg
= reg_required_here (&str
, 0)) == FAIL
)
3520 inst
.error
= BAD_ARGS
;
3526 inst
.error
= _("r15 not allowed in swap");
3530 if (skip_past_comma (&str
) == FAIL
3533 inst
.error
= BAD_ARGS
;
3537 skip_whitespace (str
);
3539 if ((reg
= reg_required_here (&str
, 16)) == FAIL
)
3544 inst
.error
= BAD_PC
;
3548 skip_whitespace (str
);
3552 inst
.error
= _("missing ]");
3556 inst
.instruction
|= flags
;
3562 do_branch (str
, flags
)
3564 unsigned long flags ATTRIBUTE_UNUSED
;
3566 if (my_get_expression (&inst
.reloc
.exp
, &str
))
3573 /* ScottB: February 5, 1998 - Check to see of PLT32 reloc
3574 required for the instruction. */
3576 /* arm_parse_reloc () works on input_line_pointer.
3577 We actually want to parse the operands to the branch instruction
3578 passed in 'str'. Save the input pointer and restore it later. */
3579 save_in
= input_line_pointer
;
3580 input_line_pointer
= str
;
3581 if (inst
.reloc
.exp
.X_op
== O_symbol
3583 && arm_parse_reloc () == BFD_RELOC_ARM_PLT32
)
3585 inst
.reloc
.type
= BFD_RELOC_ARM_PLT32
;
3586 inst
.reloc
.pc_rel
= 0;
3587 /* Modify str to point to after parsed operands, otherwise
3588 end_of_line() will complain about the (PLT) left in str. */
3589 str
= input_line_pointer
;
3593 inst
.reloc
.type
= BFD_RELOC_ARM_PCREL_BRANCH
;
3594 inst
.reloc
.pc_rel
= 1;
3596 input_line_pointer
= save_in
;
3599 inst
.reloc
.type
= BFD_RELOC_ARM_PCREL_BRANCH
;
3600 inst
.reloc
.pc_rel
= 1;
3601 #endif /* OBJ_ELF */
3610 unsigned long flags ATTRIBUTE_UNUSED
;
3614 skip_whitespace (str
);
3616 if ((reg
= reg_required_here (&str
, 0)) == FAIL
)
3618 inst
.error
= BAD_ARGS
;
3622 /* Note - it is not illegal to do a "bx pc". Useless, but not illegal. */
3624 as_tsktsk (_("Use of r15 in bx in ARM mode is not really useful"));
3632 unsigned long flags ATTRIBUTE_UNUSED
;
3634 /* Co-processor data operation.
3635 Format: CDP{cond} CP#,<expr>,CRd,CRn,CRm{,<expr>} */
3636 skip_whitespace (str
);
3638 if (co_proc_number (&str
) == FAIL
)
3641 inst
.error
= BAD_ARGS
;
3645 if (skip_past_comma (&str
) == FAIL
3646 || cp_opc_expr (&str
, 20,4) == FAIL
)
3649 inst
.error
= BAD_ARGS
;
3653 if (skip_past_comma (&str
) == FAIL
3654 || cp_reg_required_here (&str
, 12) == FAIL
)
3657 inst
.error
= BAD_ARGS
;
3661 if (skip_past_comma (&str
) == FAIL
3662 || cp_reg_required_here (&str
, 16) == FAIL
)
3665 inst
.error
= BAD_ARGS
;
3669 if (skip_past_comma (&str
) == FAIL
3670 || cp_reg_required_here (&str
, 0) == FAIL
)
3673 inst
.error
= BAD_ARGS
;
3677 if (skip_past_comma (&str
) == SUCCESS
)
3679 if (cp_opc_expr (&str
, 5, 3) == FAIL
)
3682 inst
.error
= BAD_ARGS
;
3692 do_lstc (str
, flags
)
3694 unsigned long flags
;
3696 /* Co-processor register load/store.
3697 Format: <LDC|STC{cond}[L] CP#,CRd,<address> */
3699 skip_whitespace (str
);
3701 if (co_proc_number (&str
) == FAIL
)
3704 inst
.error
= BAD_ARGS
;
3708 if (skip_past_comma (&str
) == FAIL
3709 || cp_reg_required_here (&str
, 12) == FAIL
)
3712 inst
.error
= BAD_ARGS
;
3716 if (skip_past_comma (&str
) == FAIL
3717 || cp_address_required_here (&str
) == FAIL
)
3720 inst
.error
= BAD_ARGS
;
3724 inst
.instruction
|= flags
;
3730 do_co_reg (str
, flags
)
3732 unsigned long flags
;
3734 /* Co-processor register transfer.
3735 Format: <MCR|MRC>{cond} CP#,<expr1>,Rd,CRn,CRm{,<expr2>} */
3737 skip_whitespace (str
);
3739 if (co_proc_number (&str
) == FAIL
)
3742 inst
.error
= BAD_ARGS
;
3746 if (skip_past_comma (&str
) == FAIL
3747 || cp_opc_expr (&str
, 21, 3) == FAIL
)
3750 inst
.error
= BAD_ARGS
;
3754 if (skip_past_comma (&str
) == FAIL
3755 || reg_required_here (&str
, 12) == FAIL
)
3758 inst
.error
= BAD_ARGS
;
3762 if (skip_past_comma (&str
) == FAIL
3763 || cp_reg_required_here (&str
, 16) == FAIL
)
3766 inst
.error
= BAD_ARGS
;
3770 if (skip_past_comma (&str
) == FAIL
3771 || cp_reg_required_here (&str
, 0) == FAIL
)
3774 inst
.error
= BAD_ARGS
;
3778 if (skip_past_comma (&str
) == SUCCESS
)
3780 if (cp_opc_expr (&str
, 5, 3) == FAIL
)
3783 inst
.error
= BAD_ARGS
;
3789 inst
.error
= BAD_COND
;
3797 do_fp_ctrl (str
, flags
)
3799 unsigned long flags ATTRIBUTE_UNUSED
;
3801 /* FP control registers.
3802 Format: <WFS|RFS|WFC|RFC>{cond} Rn */
3804 skip_whitespace (str
);
3806 if (reg_required_here (&str
, 12) == FAIL
)
3809 inst
.error
= BAD_ARGS
;
3818 do_fp_ldst (str
, flags
)
3820 unsigned long flags ATTRIBUTE_UNUSED
;
3822 skip_whitespace (str
);
3824 switch (inst
.suffix
)
3829 inst
.instruction
|= CP_T_X
;
3832 inst
.instruction
|= CP_T_Y
;
3835 inst
.instruction
|= CP_T_X
| CP_T_Y
;
3841 if (fp_reg_required_here (&str
, 12) == FAIL
)
3844 inst
.error
= BAD_ARGS
;
3848 if (skip_past_comma (&str
) == FAIL
3849 || cp_address_required_here (&str
) == FAIL
)
3852 inst
.error
= BAD_ARGS
;
3860 do_fp_ldmstm (str
, flags
)
3862 unsigned long flags
;
3866 skip_whitespace (str
);
3868 if (fp_reg_required_here (&str
, 12) == FAIL
)
3871 inst
.error
= BAD_ARGS
;
3875 /* Get Number of registers to transfer. */
3876 if (skip_past_comma (&str
) == FAIL
3877 || my_get_expression (&inst
.reloc
.exp
, &str
))
3880 inst
.error
= _("constant expression expected");
3884 if (inst
.reloc
.exp
.X_op
!= O_constant
)
3886 inst
.error
= _("Constant value required for number of registers");
3890 num_regs
= inst
.reloc
.exp
.X_add_number
;
3892 if (num_regs
< 1 || num_regs
> 4)
3894 inst
.error
= _("number of registers must be in the range [1:4]");
3901 inst
.instruction
|= CP_T_X
;
3904 inst
.instruction
|= CP_T_Y
;
3907 inst
.instruction
|= CP_T_Y
| CP_T_X
;
3921 /* The instruction specified "ea" or "fd", so we can only accept
3922 [Rn]{!}. The instruction does not really support stacking or
3923 unstacking, so we have to emulate these by setting appropriate
3924 bits and offsets. */
3925 if (skip_past_comma (&str
) == FAIL
3929 inst
.error
= BAD_ARGS
;
3934 skip_whitespace (str
);
3936 if ((reg
= reg_required_here (&str
, 16)) == FAIL
)
3939 skip_whitespace (str
);
3943 inst
.error
= BAD_ARGS
;
3955 _("R15 not allowed as base register with write-back");
3962 if (flags
& CP_T_Pre
)
3964 /* Pre-decrement. */
3965 offset
= 3 * num_regs
;
3971 /* Post-increment. */
3975 offset
= 3 * num_regs
;
3979 /* No write-back, so convert this into a standard pre-increment
3980 instruction -- aesthetically more pleasing. */
3981 flags
= CP_T_Pre
| CP_T_UD
;
3986 inst
.instruction
|= flags
| offset
;
3988 else if (skip_past_comma (&str
) == FAIL
3989 || cp_address_required_here (&str
) == FAIL
)
3992 inst
.error
= BAD_ARGS
;
4000 do_fp_dyadic (str
, flags
)
4002 unsigned long flags
;
4004 skip_whitespace (str
);
4006 switch (inst
.suffix
)
4011 inst
.instruction
|= 0x00000080;
4014 inst
.instruction
|= 0x00080000;
4020 if (fp_reg_required_here (&str
, 12) == FAIL
)
4023 inst
.error
= BAD_ARGS
;
4027 if (skip_past_comma (&str
) == FAIL
4028 || fp_reg_required_here (&str
, 16) == FAIL
)
4031 inst
.error
= BAD_ARGS
;
4035 if (skip_past_comma (&str
) == FAIL
4036 || fp_op2 (&str
) == FAIL
)
4039 inst
.error
= BAD_ARGS
;
4043 inst
.instruction
|= flags
;
4049 do_fp_monadic (str
, flags
)
4051 unsigned long flags
;
4053 skip_whitespace (str
);
4055 switch (inst
.suffix
)
4060 inst
.instruction
|= 0x00000080;
4063 inst
.instruction
|= 0x00080000;
4069 if (fp_reg_required_here (&str
, 12) == FAIL
)
4072 inst
.error
= BAD_ARGS
;
4076 if (skip_past_comma (&str
) == FAIL
4077 || fp_op2 (&str
) == FAIL
)
4080 inst
.error
= BAD_ARGS
;
4084 inst
.instruction
|= flags
;
4090 do_fp_cmp (str
, flags
)
4092 unsigned long flags
;
4094 skip_whitespace (str
);
4096 if (fp_reg_required_here (&str
, 16) == FAIL
)
4099 inst
.error
= BAD_ARGS
;
4103 if (skip_past_comma (&str
) == FAIL
4104 || fp_op2 (&str
) == FAIL
)
4107 inst
.error
= BAD_ARGS
;
4111 inst
.instruction
|= flags
;
4117 do_fp_from_reg (str
, flags
)
4119 unsigned long flags
;
4121 skip_whitespace (str
);
4123 switch (inst
.suffix
)
4128 inst
.instruction
|= 0x00000080;
4131 inst
.instruction
|= 0x00080000;
4137 if (fp_reg_required_here (&str
, 16) == FAIL
)
4140 inst
.error
= BAD_ARGS
;
4144 if (skip_past_comma (&str
) == FAIL
4145 || reg_required_here (&str
, 12) == FAIL
)
4148 inst
.error
= BAD_ARGS
;
4152 inst
.instruction
|= flags
;
4158 do_fp_to_reg (str
, flags
)
4160 unsigned long flags
;
4162 skip_whitespace (str
);
4164 if (reg_required_here (&str
, 12) == FAIL
)
4167 if (skip_past_comma (&str
) == FAIL
4168 || fp_reg_required_here (&str
, 0) == FAIL
)
4171 inst
.error
= BAD_ARGS
;
4175 inst
.instruction
|= flags
;
4180 /* Thumb specific routines. */
4182 /* Parse and validate that a register is of the right form, this saves
4183 repeated checking of this information in many similar cases.
4184 Unlike the 32-bit case we do not insert the register into the opcode
4185 here, since the position is often unknown until the full instruction
4189 thumb_reg (strp
, hi_lo
)
4195 if ((reg
= reg_required_here (strp
, -1)) == FAIL
)
4203 inst
.error
= _("lo register required");
4211 inst
.error
= _("hi register required");
4223 /* Parse an add or subtract instruction, SUBTRACT is non-zero if the opcode
4227 thumb_add_sub (str
, subtract
)
4231 int Rd
, Rs
, Rn
= FAIL
;
4233 skip_whitespace (str
);
4235 if ((Rd
= thumb_reg (&str
, THUMB_REG_ANY
)) == FAIL
4236 || skip_past_comma (&str
) == FAIL
)
4239 inst
.error
= BAD_ARGS
;
4243 if (is_immediate_prefix (*str
))
4247 if (my_get_expression (&inst
.reloc
.exp
, &str
))
4252 if ((Rs
= thumb_reg (&str
, THUMB_REG_ANY
)) == FAIL
)
4255 if (skip_past_comma (&str
) == FAIL
)
4257 /* Two operand format, shuffle the registers
4258 and pretend there are 3. */
4262 else if (is_immediate_prefix (*str
))
4265 if (my_get_expression (&inst
.reloc
.exp
, &str
))
4268 else if ((Rn
= thumb_reg (&str
, THUMB_REG_ANY
)) == FAIL
)
4272 /* We now have Rd and Rs set to registers, and Rn set to a register or FAIL;
4273 for the latter case, EXPR contains the immediate that was found. */
4276 /* All register format. */
4277 if (Rd
> 7 || Rs
> 7 || Rn
> 7)
4281 inst
.error
= _("dest and source1 must be the same register");
4285 /* Can't do this for SUB. */
4288 inst
.error
= _("subtract valid only on lo regs");
4292 inst
.instruction
= (T_OPCODE_ADD_HI
4293 | (Rd
> 7 ? THUMB_H1
: 0)
4294 | (Rn
> 7 ? THUMB_H2
: 0));
4295 inst
.instruction
|= (Rd
& 7) | ((Rn
& 7) << 3);
4299 inst
.instruction
= subtract
? T_OPCODE_SUB_R3
: T_OPCODE_ADD_R3
;
4300 inst
.instruction
|= Rd
| (Rs
<< 3) | (Rn
<< 6);
4305 /* Immediate expression, now things start to get nasty. */
4307 /* First deal with HI regs, only very restricted cases allowed:
4308 Adjusting SP, and using PC or SP to get an address. */
4309 if ((Rd
> 7 && (Rd
!= REG_SP
|| Rs
!= REG_SP
))
4310 || (Rs
> 7 && Rs
!= REG_SP
&& Rs
!= REG_PC
))
4312 inst
.error
= _("invalid Hi register with immediate");
4316 if (inst
.reloc
.exp
.X_op
!= O_constant
)
4318 /* Value isn't known yet, all we can do is store all the fragments
4319 we know about in the instruction and let the reloc hacking
4321 inst
.instruction
= (subtract
? 0x8000 : 0) | (Rd
<< 4) | Rs
;
4322 inst
.reloc
.type
= BFD_RELOC_ARM_THUMB_ADD
;
4326 int offset
= inst
.reloc
.exp
.X_add_number
;
4336 /* Quick check, in case offset is MIN_INT. */
4339 inst
.error
= _("immediate value out of range");
4348 if (offset
& ~0x1fc)
4350 inst
.error
= _("invalid immediate value for stack adjust");
4353 inst
.instruction
= subtract
? T_OPCODE_SUB_ST
: T_OPCODE_ADD_ST
;
4354 inst
.instruction
|= offset
>> 2;
4356 else if (Rs
== REG_PC
|| Rs
== REG_SP
)
4359 || (offset
& ~0x3fc))
4361 inst
.error
= _("invalid immediate for address calculation");
4364 inst
.instruction
= (Rs
== REG_PC
? T_OPCODE_ADD_PC
4366 inst
.instruction
|= (Rd
<< 8) | (offset
>> 2);
4372 inst
.error
= _("immediate value out of range");
4375 inst
.instruction
= subtract
? T_OPCODE_SUB_I8
: T_OPCODE_ADD_I8
;
4376 inst
.instruction
|= (Rd
<< 8) | offset
;
4382 inst
.error
= _("immediate value out of range");
4385 inst
.instruction
= subtract
? T_OPCODE_SUB_I3
: T_OPCODE_ADD_I3
;
4386 inst
.instruction
|= Rd
| (Rs
<< 3) | (offset
<< 6);
4395 thumb_shift (str
, shift
)
4399 int Rd
, Rs
, Rn
= FAIL
;
4401 skip_whitespace (str
);
4403 if ((Rd
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
4404 || skip_past_comma (&str
) == FAIL
)
4407 inst
.error
= BAD_ARGS
;
4411 if (is_immediate_prefix (*str
))
4413 /* Two operand immediate format, set Rs to Rd. */
4416 if (my_get_expression (&inst
.reloc
.exp
, &str
))
4421 if ((Rs
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
)
4424 if (skip_past_comma (&str
) == FAIL
)
4426 /* Two operand format, shuffle the registers
4427 and pretend there are 3. */
4431 else if (is_immediate_prefix (*str
))
4434 if (my_get_expression (&inst
.reloc
.exp
, &str
))
4437 else if ((Rn
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
)
4441 /* We now have Rd and Rs set to registers, and Rn set to a register or FAIL;
4442 for the latter case, EXPR contains the immediate that was found. */
4448 inst
.error
= _("source1 and dest must be same register");
4454 case THUMB_ASR
: inst
.instruction
= T_OPCODE_ASR_R
; break;
4455 case THUMB_LSL
: inst
.instruction
= T_OPCODE_LSL_R
; break;
4456 case THUMB_LSR
: inst
.instruction
= T_OPCODE_LSR_R
; break;
4459 inst
.instruction
|= Rd
| (Rn
<< 3);
4465 case THUMB_ASR
: inst
.instruction
= T_OPCODE_ASR_I
; break;
4466 case THUMB_LSL
: inst
.instruction
= T_OPCODE_LSL_I
; break;
4467 case THUMB_LSR
: inst
.instruction
= T_OPCODE_LSR_I
; break;
4470 if (inst
.reloc
.exp
.X_op
!= O_constant
)
4472 /* Value isn't known yet, create a dummy reloc and let reloc
4473 hacking fix it up. */
4474 inst
.reloc
.type
= BFD_RELOC_ARM_THUMB_SHIFT
;
4478 unsigned shift_value
= inst
.reloc
.exp
.X_add_number
;
4480 if (shift_value
> 32 || (shift_value
== 32 && shift
== THUMB_LSL
))
4482 inst
.error
= _("Invalid immediate for shift");
4486 /* Shifts of zero are handled by converting to LSL. */
4487 if (shift_value
== 0)
4488 inst
.instruction
= T_OPCODE_LSL_I
;
4490 /* Shifts of 32 are encoded as a shift of zero. */
4491 if (shift_value
== 32)
4494 inst
.instruction
|= shift_value
<< 6;
4497 inst
.instruction
|= Rd
| (Rs
<< 3);
4504 thumb_mov_compare (str
, move
)
4510 skip_whitespace (str
);
4512 if ((Rd
= thumb_reg (&str
, THUMB_REG_ANY
)) == FAIL
4513 || skip_past_comma (&str
) == FAIL
)
4516 inst
.error
= BAD_ARGS
;
4520 if (is_immediate_prefix (*str
))
4523 if (my_get_expression (&inst
.reloc
.exp
, &str
))
4526 else if ((Rs
= thumb_reg (&str
, THUMB_REG_ANY
)) == FAIL
)
4531 if (Rs
< 8 && Rd
< 8)
4533 if (move
== THUMB_MOVE
)
4534 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
4535 since a MOV instruction produces unpredictable results. */
4536 inst
.instruction
= T_OPCODE_ADD_I3
;
4538 inst
.instruction
= T_OPCODE_CMP_LR
;
4539 inst
.instruction
|= Rd
| (Rs
<< 3);
4543 if (move
== THUMB_MOVE
)
4544 inst
.instruction
= T_OPCODE_MOV_HR
;
4546 inst
.instruction
= T_OPCODE_CMP_HR
;
4549 inst
.instruction
|= THUMB_H1
;
4552 inst
.instruction
|= THUMB_H2
;
4554 inst
.instruction
|= (Rd
& 7) | ((Rs
& 7) << 3);
4561 inst
.error
= _("only lo regs allowed with immediate");
4565 if (move
== THUMB_MOVE
)
4566 inst
.instruction
= T_OPCODE_MOV_I8
;
4568 inst
.instruction
= T_OPCODE_CMP_I8
;
4570 inst
.instruction
|= Rd
<< 8;
4572 if (inst
.reloc
.exp
.X_op
!= O_constant
)
4573 inst
.reloc
.type
= BFD_RELOC_ARM_THUMB_IMM
;
4576 unsigned value
= inst
.reloc
.exp
.X_add_number
;
4580 inst
.error
= _("invalid immediate");
4584 inst
.instruction
|= value
;
4592 thumb_load_store (str
, load_store
, size
)
4597 int Rd
, Rb
, Ro
= FAIL
;
4599 skip_whitespace (str
);
4601 if ((Rd
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
4602 || skip_past_comma (&str
) == FAIL
)
4605 inst
.error
= BAD_ARGS
;
4612 if ((Rb
= thumb_reg (&str
, THUMB_REG_ANY
)) == FAIL
)
4615 if (skip_past_comma (&str
) != FAIL
)
4617 if (is_immediate_prefix (*str
))
4620 if (my_get_expression (&inst
.reloc
.exp
, &str
))
4623 else if ((Ro
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
)
4628 inst
.reloc
.exp
.X_op
= O_constant
;
4629 inst
.reloc
.exp
.X_add_number
= 0;
4634 inst
.error
= _("expected ']'");
4639 else if (*str
== '=')
4641 /* Parse an "ldr Rd, =expr" instruction; this is another pseudo op. */
4644 skip_whitespace (str
);
4646 if (my_get_expression (& inst
.reloc
.exp
, & str
))
4651 if ( inst
.reloc
.exp
.X_op
!= O_constant
4652 && inst
.reloc
.exp
.X_op
!= O_symbol
)
4654 inst
.error
= "Constant expression expected";
4658 if (inst
.reloc
.exp
.X_op
== O_constant
4659 && ((inst
.reloc
.exp
.X_add_number
& ~0xFF) == 0))
4661 /* This can be done with a mov instruction. */
4663 inst
.instruction
= T_OPCODE_MOV_I8
| (Rd
<< 8);
4664 inst
.instruction
|= inst
.reloc
.exp
.X_add_number
;
4668 /* Insert into literal pool. */
4669 if (add_to_lit_pool () == FAIL
)
4672 inst
.error
= "literal pool insertion failed";
4676 inst
.reloc
.type
= BFD_RELOC_ARM_THUMB_OFFSET
;
4677 inst
.reloc
.pc_rel
= 1;
4678 inst
.instruction
= T_OPCODE_LDR_PC
| (Rd
<< 8);
4679 /* Adjust ARM pipeline offset to Thumb. */
4680 inst
.reloc
.exp
.X_add_number
+= 4;
4686 if (my_get_expression (&inst
.reloc
.exp
, &str
))
4689 inst
.instruction
= T_OPCODE_LDR_PC
| (Rd
<< 8);
4690 inst
.reloc
.pc_rel
= 1;
4691 inst
.reloc
.exp
.X_add_number
-= 4; /* Pipeline offset. */
4692 inst
.reloc
.type
= BFD_RELOC_ARM_THUMB_OFFSET
;
4697 if (Rb
== REG_PC
|| Rb
== REG_SP
)
4699 if (size
!= THUMB_WORD
)
4701 inst
.error
= _("byte or halfword not valid for base register");
4704 else if (Rb
== REG_PC
&& load_store
!= THUMB_LOAD
)
4706 inst
.error
= _("R15 based store not allowed");
4709 else if (Ro
!= FAIL
)
4711 inst
.error
= _("Invalid base register for register offset");
4716 inst
.instruction
= T_OPCODE_LDR_PC
;
4717 else if (load_store
== THUMB_LOAD
)
4718 inst
.instruction
= T_OPCODE_LDR_SP
;
4720 inst
.instruction
= T_OPCODE_STR_SP
;
4722 inst
.instruction
|= Rd
<< 8;
4723 if (inst
.reloc
.exp
.X_op
== O_constant
)
4725 unsigned offset
= inst
.reloc
.exp
.X_add_number
;
4727 if (offset
& ~0x3fc)
4729 inst
.error
= _("invalid offset");
4733 inst
.instruction
|= offset
>> 2;
4736 inst
.reloc
.type
= BFD_RELOC_ARM_THUMB_OFFSET
;
4740 inst
.error
= _("invalid base register in load/store");
4743 else if (Ro
== FAIL
)
4745 /* Immediate offset. */
4746 if (size
== THUMB_WORD
)
4747 inst
.instruction
= (load_store
== THUMB_LOAD
4748 ? T_OPCODE_LDR_IW
: T_OPCODE_STR_IW
);
4749 else if (size
== THUMB_HALFWORD
)
4750 inst
.instruction
= (load_store
== THUMB_LOAD
4751 ? T_OPCODE_LDR_IH
: T_OPCODE_STR_IH
);
4753 inst
.instruction
= (load_store
== THUMB_LOAD
4754 ? T_OPCODE_LDR_IB
: T_OPCODE_STR_IB
);
4756 inst
.instruction
|= Rd
| (Rb
<< 3);
4758 if (inst
.reloc
.exp
.X_op
== O_constant
)
4760 unsigned offset
= inst
.reloc
.exp
.X_add_number
;
4762 if (offset
& ~(0x1f << size
))
4764 inst
.error
= _("Invalid offset");
4767 inst
.instruction
|= (offset
>> size
) << 6;
4770 inst
.reloc
.type
= BFD_RELOC_ARM_THUMB_OFFSET
;
4774 /* Register offset. */
4775 if (size
== THUMB_WORD
)
4776 inst
.instruction
= (load_store
== THUMB_LOAD
4777 ? T_OPCODE_LDR_RW
: T_OPCODE_STR_RW
);
4778 else if (size
== THUMB_HALFWORD
)
4779 inst
.instruction
= (load_store
== THUMB_LOAD
4780 ? T_OPCODE_LDR_RH
: T_OPCODE_STR_RH
);
4782 inst
.instruction
= (load_store
== THUMB_LOAD
4783 ? T_OPCODE_LDR_RB
: T_OPCODE_STR_RB
);
4785 inst
.instruction
|= Rd
| (Rb
<< 3) | (Ro
<< 6);
4800 /* Handle the Format 4 instructions that do not have equivalents in other
4801 formats. That is, ADC, AND, EOR, SBC, ROR, TST, NEG, CMN, ORR, MUL,
4810 skip_whitespace (str
);
4812 if ((Rd
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
4813 || skip_past_comma (&str
) == FAIL
4814 || (Rs
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
)
4816 inst
.error
= BAD_ARGS
;
4820 if (skip_past_comma (&str
) != FAIL
)
4822 /* Three operand format not allowed for TST, CMN, NEG and MVN.
4823 (It isn't allowed for CMP either, but that isn't handled by this
4825 if (inst
.instruction
== T_OPCODE_TST
4826 || inst
.instruction
== T_OPCODE_CMN
4827 || inst
.instruction
== T_OPCODE_NEG
4828 || inst
.instruction
== T_OPCODE_MVN
)
4830 inst
.error
= BAD_ARGS
;
4834 if ((Rn
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
)
4839 inst
.error
= _("dest and source1 one must be the same register");
4845 if (inst
.instruction
== T_OPCODE_MUL
4847 as_tsktsk (_("Rs and Rd must be different in MUL"));
4849 inst
.instruction
|= Rd
| (Rs
<< 3);
4857 thumb_add_sub (str
, 0);
4864 thumb_shift (str
, THUMB_ASR
);
4871 if (my_get_expression (&inst
.reloc
.exp
, &str
))
4873 inst
.reloc
.type
= BFD_RELOC_THUMB_PCREL_BRANCH9
;
4874 inst
.reloc
.pc_rel
= 1;
4882 if (my_get_expression (&inst
.reloc
.exp
, &str
))
4884 inst
.reloc
.type
= BFD_RELOC_THUMB_PCREL_BRANCH12
;
4885 inst
.reloc
.pc_rel
= 1;
4889 /* Find the real, Thumb encoded start of a Thumb function. */
4892 find_real_start (symbolP
)
4896 const char * name
= S_GET_NAME (symbolP
);
4897 symbolS
* new_target
;
4899 /* This definiton must agree with the one in gcc/config/arm/thumb.c. */
4900 #define STUB_NAME ".real_start_of"
4905 /* Names that start with '.' are local labels, not function entry points.
4906 The compiler may generate BL instructions to these labels because it
4907 needs to perform a branch to a far away location. */
4911 real_start
= malloc (strlen (name
) + strlen (STUB_NAME
) + 1);
4912 sprintf (real_start
, "%s%s", STUB_NAME
, name
);
4914 new_target
= symbol_find (real_start
);
4916 if (new_target
== NULL
)
4918 as_warn ("Failed to find real start of function: %s\n", name
);
4919 new_target
= symbolP
;
4931 if (my_get_expression (& inst
.reloc
.exp
, & str
))
4934 inst
.reloc
.type
= BFD_RELOC_THUMB_PCREL_BRANCH23
;
4935 inst
.reloc
.pc_rel
= 1;
4938 /* If the destination of the branch is a defined symbol which does not have
4939 the THUMB_FUNC attribute, then we must be calling a function which has
4940 the (interfacearm) attribute. We look for the Thumb entry point to that
4941 function and change the branch to refer to that function instead. */
4942 if ( inst
.reloc
.exp
.X_op
== O_symbol
4943 && inst
.reloc
.exp
.X_add_symbol
!= NULL
4944 && S_IS_DEFINED (inst
.reloc
.exp
.X_add_symbol
)
4945 && ! THUMB_IS_FUNC (inst
.reloc
.exp
.X_add_symbol
))
4946 inst
.reloc
.exp
.X_add_symbol
=
4947 find_real_start (inst
.reloc
.exp
.X_add_symbol
);
4956 skip_whitespace (str
);
4958 if ((reg
= thumb_reg (&str
, THUMB_REG_ANY
)) == FAIL
)
4961 /* This sets THUMB_H2 from the top bit of reg. */
4962 inst
.instruction
|= reg
<< 3;
4964 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
4965 should cause the alignment to be checked once it is known. This is
4966 because BX PC only works if the instruction is word aligned. */
4975 thumb_mov_compare (str
, THUMB_COMPARE
);
4985 skip_whitespace (str
);
4987 if ((Rb
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
)
4991 as_warn (_("Inserted missing '!': load/store multiple always writes back base register"));
4995 if (skip_past_comma (&str
) == FAIL
4996 || (range
= reg_list (&str
)) == FAIL
)
4999 inst
.error
= BAD_ARGS
;
5003 if (inst
.reloc
.type
!= BFD_RELOC_NONE
)
5005 /* This really doesn't seem worth it. */
5006 inst
.reloc
.type
= BFD_RELOC_NONE
;
5007 inst
.error
= _("Expression too complex");
5013 inst
.error
= _("only lo-regs valid in load/store multiple");
5017 inst
.instruction
|= (Rb
<< 8) | range
;
5025 thumb_load_store (str
, THUMB_LOAD
, THUMB_WORD
);
5032 thumb_load_store (str
, THUMB_LOAD
, THUMB_BYTE
);
5039 thumb_load_store (str
, THUMB_LOAD
, THUMB_HALFWORD
);
5048 skip_whitespace (str
);
5050 if ((Rd
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
5051 || skip_past_comma (&str
) == FAIL
5053 || (Rb
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
5054 || skip_past_comma (&str
) == FAIL
5055 || (Ro
= thumb_reg (&str
, THUMB_REG_LO
)) == FAIL
5059 inst
.error
= _("Syntax: ldrs[b] Rd, [Rb, Ro]");
5063 inst
.instruction
|= Rd
| (Rb
<< 3) | (Ro
<< 6);
5071 thumb_shift (str
, THUMB_LSL
);
5078 thumb_shift (str
, THUMB_LSR
);
5085 thumb_mov_compare (str
, THUMB_MOVE
);
5094 skip_whitespace (str
);
5096 if ((range
= reg_list (&str
)) == FAIL
)
5099 inst
.error
= BAD_ARGS
;
5103 if (inst
.reloc
.type
!= BFD_RELOC_NONE
)
5105 /* This really doesn't seem worth it. */
5106 inst
.reloc
.type
= BFD_RELOC_NONE
;
5107 inst
.error
= _("Expression too complex");
5113 if ((inst
.instruction
== T_OPCODE_PUSH
5114 && (range
& ~0xff) == 1 << REG_LR
)
5115 || (inst
.instruction
== T_OPCODE_POP
5116 && (range
& ~0xff) == 1 << REG_PC
))
5118 inst
.instruction
|= THUMB_PP_PC_LR
;
5123 inst
.error
= _("invalid register list to push/pop instruction");
5128 inst
.instruction
|= range
;
5136 thumb_load_store (str
, THUMB_STORE
, THUMB_WORD
);
5143 thumb_load_store (str
, THUMB_STORE
, THUMB_BYTE
);
5150 thumb_load_store (str
, THUMB_STORE
, THUMB_HALFWORD
);
5157 thumb_add_sub (str
, 1);
5164 skip_whitespace (str
);
5166 if (my_get_expression (&inst
.reloc
.exp
, &str
))
5169 inst
.reloc
.type
= BFD_RELOC_ARM_SWI
;
5180 /* This is a pseudo-op of the form "adr rd, label" to be converted
5181 into a relative address of the form "add rd, pc, #label-.-4". */
5182 skip_whitespace (str
);
5184 /* Store Rd in temporary location inside instruction. */
5185 if ((reg
= reg_required_here (&str
, 4)) == FAIL
5186 || (reg
> 7) /* For Thumb reg must be r0..r7. */
5187 || skip_past_comma (&str
) == FAIL
5188 || my_get_expression (&inst
.reloc
.exp
, &str
))
5191 inst
.error
= BAD_ARGS
;
5195 inst
.reloc
.type
= BFD_RELOC_ARM_THUMB_ADD
;
5196 inst
.reloc
.exp
.X_add_number
-= 4; /* PC relative adjust. */
5197 inst
.reloc
.pc_rel
= 1;
5198 inst
.instruction
|= REG_PC
; /* Rd is already placed into the instruction. */
5207 int len
= strlen (reg_table
[entry
].name
) + 2;
5208 char * buf
= (char *) xmalloc (len
);
5209 char * buf2
= (char *) xmalloc (len
);
5212 #ifdef REGISTER_PREFIX
5213 buf
[i
++] = REGISTER_PREFIX
;
5216 strcpy (buf
+ i
, reg_table
[entry
].name
);
5218 for (i
= 0; buf
[i
]; i
++)
5219 buf2
[i
] = islower (buf
[i
]) ? toupper (buf
[i
]) : buf
[i
];
5223 hash_insert (arm_reg_hsh
, buf
, (PTR
) & reg_table
[entry
]);
5224 hash_insert (arm_reg_hsh
, buf2
, (PTR
) & reg_table
[entry
]);
5228 insert_reg_alias (str
, regnum
)
5232 struct reg_entry
*new =
5233 (struct reg_entry
*) xmalloc (sizeof (struct reg_entry
));
5234 char *name
= xmalloc (strlen (str
) + 1);
5238 new->number
= regnum
;
5240 hash_insert (arm_reg_hsh
, name
, (PTR
) new);
5244 set_constant_flonums ()
5248 for (i
= 0; i
< NUM_FLOAT_VALS
; i
++)
5249 if (atof_ieee ((char *) fp_const
[i
], 'x', fp_values
[i
]) == NULL
)
5259 if ( (arm_ops_hsh
= hash_new ()) == NULL
5260 || (arm_tops_hsh
= hash_new ()) == NULL
5261 || (arm_cond_hsh
= hash_new ()) == NULL
5262 || (arm_shift_hsh
= hash_new ()) == NULL
5263 || (arm_reg_hsh
= hash_new ()) == NULL
5264 || (arm_psr_hsh
= hash_new ()) == NULL
)
5265 as_fatal (_("Virtual memory exhausted"));
5267 for (i
= 0; i
< sizeof (insns
) / sizeof (struct asm_opcode
); i
++)
5268 hash_insert (arm_ops_hsh
, insns
[i
].template, (PTR
) (insns
+ i
));
5269 for (i
= 0; i
< sizeof (tinsns
) / sizeof (struct thumb_opcode
); i
++)
5270 hash_insert (arm_tops_hsh
, tinsns
[i
].template, (PTR
) (tinsns
+ i
));
5271 for (i
= 0; i
< sizeof (conds
) / sizeof (struct asm_cond
); i
++)
5272 hash_insert (arm_cond_hsh
, conds
[i
].template, (PTR
) (conds
+ i
));
5273 for (i
= 0; i
< sizeof (shift_names
) / sizeof (struct asm_shift_name
); i
++)
5274 hash_insert (arm_shift_hsh
, shift_names
[i
].name
, (PTR
) (shift_names
+ i
));
5275 for (i
= 0; i
< sizeof (psrs
) / sizeof (struct asm_psr
); i
++)
5276 hash_insert (arm_psr_hsh
, psrs
[i
].template, (PTR
) (psrs
+ i
));
5278 for (i
= 0; reg_table
[i
].name
; i
++)
5281 set_constant_flonums ();
5283 #if defined OBJ_COFF || defined OBJ_ELF
5285 unsigned int flags
= 0;
5287 /* Set the flags in the private structure. */
5288 if (uses_apcs_26
) flags
|= F_APCS26
;
5289 if (support_interwork
) flags
|= F_INTERWORK
;
5290 if (uses_apcs_float
) flags
|= F_APCS_FLOAT
;
5291 if (pic_code
) flags
|= F_PIC
;
5292 if ((cpu_variant
& FPU_ALL
) == FPU_NONE
) flags
|= F_SOFT_FLOAT
;
5294 bfd_set_private_flags (stdoutput
, flags
);
5298 /* Record the CPU type as well. */
5299 switch (cpu_variant
& ARM_CPU_MASK
)
5302 mach
= bfd_mach_arm_2
;
5305 case ARM_3
: /* Also ARM_250. */
5306 mach
= bfd_mach_arm_2a
;
5310 case ARM_6
| ARM_3
| ARM_2
: /* Actually no CPU type defined. */
5311 mach
= bfd_mach_arm_4
;
5314 case ARM_7
: /* Also ARM_6. */
5315 mach
= bfd_mach_arm_3
;
5319 /* Catch special cases. */
5320 if (cpu_variant
!= (FPU_DEFAULT
| CPU_DEFAULT
))
5322 if (cpu_variant
& (ARM_EXT_V5
& ARM_THUMB
))
5323 mach
= bfd_mach_arm_5T
;
5324 else if (cpu_variant
& ARM_EXT_V5
)
5325 mach
= bfd_mach_arm_5
;
5326 else if (cpu_variant
& ARM_THUMB
)
5327 mach
= bfd_mach_arm_4T
;
5328 else if ((cpu_variant
& ARM_ARCH_V4
) == ARM_ARCH_V4
)
5329 mach
= bfd_mach_arm_4
;
5330 else if (cpu_variant
& ARM_LONGMUL
)
5331 mach
= bfd_mach_arm_3M
;
5334 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, mach
);
5337 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
5338 for use in the a.out file, and stores them in the array pointed to by buf.
5339 This knows about the endian-ness of the target machine and does
5340 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
5341 2 (short) and 4 (long) Floating numbers are put out as a series of
5342 LITTLENUMS (shorts, here at least). */
5345 md_number_to_chars (buf
, val
, n
)
5350 if (target_big_endian
)
5351 number_to_chars_bigendian (buf
, val
, n
);
5353 number_to_chars_littleendian (buf
, val
, n
);
5357 md_chars_to_number (buf
, n
)
5362 unsigned char * where
= (unsigned char *) buf
;
5364 if (target_big_endian
)
5369 result
|= (*where
++ & 255);
5377 result
|= (where
[n
] & 255);
5384 /* Turn a string in input_line_pointer into a floating point constant
5385 of type TYPE, and store the appropriate bytes in *LITP. The number
5386 of LITTLENUMS emitted is stored in *SIZEP. An error message is
5387 returned, or NULL on OK.
5389 Note that fp constants aren't represent in the normal way on the ARM.
5390 In big endian mode, things are as expected. However, in little endian
5391 mode fp constants are big-endian word-wise, and little-endian byte-wise
5392 within the words. For example, (double) 1.1 in big endian mode is
5393 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
5394 the byte sequence 99 99 f1 3f 9a 99 99 99.
5396 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
5399 md_atof (type
, litP
, sizeP
)
5405 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
5437 return _("Bad call to MD_ATOF()");
5440 t
= atof_ieee (input_line_pointer
, type
, words
);
5442 input_line_pointer
= t
;
5445 if (target_big_endian
)
5447 for (i
= 0; i
< prec
; i
++)
5449 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
5455 /* For a 4 byte float the order of elements in `words' is 1 0. For an
5456 8 byte float the order is 1 0 3 2. */
5457 for (i
= 0; i
< prec
; i
+= 2)
5459 md_number_to_chars (litP
, (valueT
) words
[i
+ 1], 2);
5460 md_number_to_chars (litP
+ 2, (valueT
) words
[i
], 2);
5468 /* The knowledge of the PC's pipeline offset is built into the insns
5472 md_pcrel_from (fixP
)
5476 && S_GET_SEGMENT (fixP
->fx_addsy
) == undefined_section
5477 && fixP
->fx_subsy
== NULL
)
5480 if (fixP
->fx_pcrel
&& (fixP
->fx_r_type
== BFD_RELOC_ARM_THUMB_ADD
))
5482 /* PC relative addressing on the Thumb is slightly odd
5483 as the bottom two bits of the PC are forced to zero
5484 for the calculation. */
5485 return (fixP
->fx_where
+ fixP
->fx_frag
->fr_address
) & ~3;
5489 /* The pattern was adjusted to accomodate CE's off-by-one fixups,
5490 so we un-adjust here to compensate for the accomodation. */
5491 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
+ 8;
5493 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
5497 /* Round up a section size to the appropriate boundary. */
5500 md_section_align (segment
, size
)
5501 segT segment ATTRIBUTE_UNUSED
;
5507 /* Round all sects to multiple of 4. */
5508 return (size
+ 3) & ~3;
5512 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
5513 Otherwise we have no need to default values of symbols. */
5516 md_undefined_symbol (name
)
5517 char * name ATTRIBUTE_UNUSED
;
5520 if (name
[0] == '_' && name
[1] == 'G'
5521 && streq (name
, GLOBAL_OFFSET_TABLE_NAME
))
5525 if (symbol_find (name
))
5526 as_bad ("GOT already in the symbol table");
5528 GOT_symbol
= symbol_new (name
, undefined_section
,
5529 (valueT
) 0, & zero_address_frag
);
5539 /* arm_reg_parse () := if it looks like a register, return its token and
5540 advance the pointer. */
5544 register char ** ccp
;
5546 char * start
= * ccp
;
5549 struct reg_entry
* reg
;
5551 #ifdef REGISTER_PREFIX
5552 if (*start
!= REGISTER_PREFIX
)
5557 #ifdef OPTIONAL_REGISTER_PREFIX
5558 if (*p
== OPTIONAL_REGISTER_PREFIX
)
5562 if (!isalpha (*p
) || !is_name_beginner (*p
))
5566 while (isalpha (c
) || isdigit (c
) || c
== '_')
5570 reg
= (struct reg_entry
*) hash_find (arm_reg_hsh
, start
);
5583 md_apply_fix3 (fixP
, val
, seg
)
5588 offsetT value
= * val
;
5590 unsigned int newimm
;
5593 char * buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
5594 arm_fix_data
* arm_data
= (arm_fix_data
*) fixP
->tc_fix_data
;
5596 assert (fixP
->fx_r_type
< BFD_RELOC_UNUSED
);
5598 /* Note whether this will delete the relocation. */
5600 /* Patch from REarnshaw to JDavis (disabled for the moment, since it
5601 doesn't work fully.) */
5602 if ((fixP
->fx_addsy
== 0 || symbol_constant_p (fixP
->fx_addsy
))
5605 if (fixP
->fx_addsy
== 0 && !fixP
->fx_pcrel
)
5609 /* If this symbol is in a different section then we need to leave it for
5610 the linker to deal with. Unfortunately, md_pcrel_from can't tell,
5611 so we have to undo it's effects here. */
5614 if (fixP
->fx_addsy
!= NULL
5615 && S_IS_DEFINED (fixP
->fx_addsy
)
5616 && S_GET_SEGMENT (fixP
->fx_addsy
) != seg
)
5619 && (fixP
->fx_r_type
== BFD_RELOC_ARM_PCREL_BRANCH
5620 || fixP
->fx_r_type
== BFD_RELOC_ARM_PCREL_BLX
5624 value
+= md_pcrel_from (fixP
);
5628 /* Remember value for emit_reloc. */
5629 fixP
->fx_addnumber
= value
;
5631 switch (fixP
->fx_r_type
)
5633 case BFD_RELOC_ARM_IMMEDIATE
:
5634 newimm
= validate_immediate (value
);
5635 temp
= md_chars_to_number (buf
, INSN_SIZE
);
5637 /* If the instruction will fail, see if we can fix things up by
5638 changing the opcode. */
5639 if (newimm
== (unsigned int) FAIL
5640 && (newimm
= negate_data_op (&temp
, value
)) == (unsigned int) FAIL
)
5642 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5643 _("invalid constant (%lx) after fixup"),
5644 (unsigned long) value
);
5648 newimm
|= (temp
& 0xfffff000);
5649 md_number_to_chars (buf
, (valueT
) newimm
, INSN_SIZE
);
5652 case BFD_RELOC_ARM_ADRL_IMMEDIATE
:
5654 unsigned int highpart
= 0;
5655 unsigned int newinsn
= 0xe1a00000; /* nop. */
5656 newimm
= validate_immediate (value
);
5657 temp
= md_chars_to_number (buf
, INSN_SIZE
);
5659 /* If the instruction will fail, see if we can fix things up by
5660 changing the opcode. */
5661 if (newimm
== (unsigned int) FAIL
5662 && (newimm
= negate_data_op (& temp
, value
)) == (unsigned int) FAIL
)
5664 /* No ? OK - try using two ADD instructions to generate
5666 newimm
= validate_immediate_twopart (value
, & highpart
);
5668 /* Yes - then make sure that the second instruction is
5670 if (newimm
!= (unsigned int) FAIL
)
5672 /* Still No ? Try using a negated value. */
5673 else if (validate_immediate_twopart (- value
, & highpart
) != (unsigned int) FAIL
)
5674 temp
= newinsn
= (temp
& OPCODE_MASK
) | OPCODE_SUB
<< DATA_OP_SHIFT
;
5675 /* Otherwise - give up. */
5678 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5679 _("Unable to compute ADRL instructions for PC offset of 0x%x"),
5684 /* Replace the first operand in the 2nd instruction (which
5685 is the PC) with the destination register. We have
5686 already added in the PC in the first instruction and we
5687 do not want to do it again. */
5688 newinsn
&= ~0xf0000;
5689 newinsn
|= ((newinsn
& 0x0f000) << 4);
5692 newimm
|= (temp
& 0xfffff000);
5693 md_number_to_chars (buf
, (valueT
) newimm
, INSN_SIZE
);
5695 highpart
|= (newinsn
& 0xfffff000);
5696 md_number_to_chars (buf
+ INSN_SIZE
, (valueT
) highpart
, INSN_SIZE
);
5700 case BFD_RELOC_ARM_OFFSET_IMM
:
5706 if (validate_offset_imm (value
, 0) == FAIL
)
5708 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5709 _("bad immediate value for offset (%ld)"),
5714 newval
= md_chars_to_number (buf
, INSN_SIZE
);
5715 newval
&= 0xff7ff000;
5716 newval
|= value
| (sign
? INDEX_UP
: 0);
5717 md_number_to_chars (buf
, newval
, INSN_SIZE
);
5720 case BFD_RELOC_ARM_OFFSET_IMM8
:
5721 case BFD_RELOC_ARM_HWLITERAL
:
5727 if (validate_offset_imm (value
, 1) == FAIL
)
5729 if (fixP
->fx_r_type
== BFD_RELOC_ARM_HWLITERAL
)
5730 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5731 _("invalid literal constant: pool needs to be closer"));
5733 as_bad (_("bad immediate value for half-word offset (%ld)"),
5738 newval
= md_chars_to_number (buf
, INSN_SIZE
);
5739 newval
&= 0xff7ff0f0;
5740 newval
|= ((value
>> 4) << 8) | (value
& 0xf) | (sign
? INDEX_UP
: 0);
5741 md_number_to_chars (buf
, newval
, INSN_SIZE
);
5744 case BFD_RELOC_ARM_LITERAL
:
5750 if (validate_offset_imm (value
, 0) == FAIL
)
5752 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5753 _("invalid literal constant: pool needs to be closer"));
5757 newval
= md_chars_to_number (buf
, INSN_SIZE
);
5758 newval
&= 0xff7ff000;
5759 newval
|= value
| (sign
? INDEX_UP
: 0);
5760 md_number_to_chars (buf
, newval
, INSN_SIZE
);
5763 case BFD_RELOC_ARM_SHIFT_IMM
:
5764 newval
= md_chars_to_number (buf
, INSN_SIZE
);
5765 if (((unsigned long) value
) > 32
5767 && (((newval
& 0x60) == 0) || (newval
& 0x60) == 0x60)))
5769 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5770 _("shift expression is too large"));
5775 /* Shifts of zero must be done as lsl. */
5777 else if (value
== 32)
5779 newval
&= 0xfffff07f;
5780 newval
|= (value
& 0x1f) << 7;
5781 md_number_to_chars (buf
, newval
, INSN_SIZE
);
5784 case BFD_RELOC_ARM_SWI
:
5785 if (arm_data
->thumb_mode
)
5787 if (((unsigned long) value
) > 0xff)
5788 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5789 _("Invalid swi expression"));
5790 newval
= md_chars_to_number (buf
, THUMB_SIZE
) & 0xff00;
5792 md_number_to_chars (buf
, newval
, THUMB_SIZE
);
5796 if (((unsigned long) value
) > 0x00ffffff)
5797 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5798 _("Invalid swi expression"));
5799 newval
= md_chars_to_number (buf
, INSN_SIZE
) & 0xff000000;
5801 md_number_to_chars (buf
, newval
, INSN_SIZE
);
5805 case BFD_RELOC_ARM_MULTI
:
5806 if (((unsigned long) value
) > 0xffff)
5807 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5808 _("Invalid expression in load/store multiple"));
5809 newval
= value
| md_chars_to_number (buf
, INSN_SIZE
);
5810 md_number_to_chars (buf
, newval
, INSN_SIZE
);
5813 case BFD_RELOC_ARM_PCREL_BRANCH
:
5814 newval
= md_chars_to_number (buf
, INSN_SIZE
);
5816 /* Sign-extend a 24-bit number. */
5817 #define SEXT24(x) ((((x) & 0xffffff) ^ (~ 0x7fffff)) + 0x800000)
5821 value
= fixP
->fx_offset
;
5824 /* We are going to store value (shifted right by two) in the
5825 instruction, in a 24 bit, signed field. Thus we need to check
5826 that none of the top 8 bits of the shifted value (top 7 bits of
5827 the unshifted, unsigned value) are set, or that they are all set. */
5828 if ((value
& ~ ((offsetT
) 0x1ffffff)) != 0
5829 && ((value
& ~ ((offsetT
) 0x1ffffff)) != ~ ((offsetT
) 0x1ffffff)))
5832 /* Normally we would be stuck at this point, since we cannot store
5833 the absolute address that is the destination of the branch in the
5834 24 bits of the branch instruction. If however, we happen to know
5835 that the destination of the branch is in the same section as the
5836 branch instruciton itself, then we can compute the relocation for
5837 ourselves and not have to bother the linker with it.
5839 FIXME: The tests for OBJ_ELF and ! target_oabi are only here
5840 because I have not worked out how to do this for OBJ_COFF or
5843 && fixP
->fx_addsy
!= NULL
5844 && S_IS_DEFINED (fixP
->fx_addsy
)
5845 && S_GET_SEGMENT (fixP
->fx_addsy
) == seg
)
5847 /* Get pc relative value to go into the branch. */
5850 /* Permit a backward branch provided that enough bits
5851 are set. Allow a forwards branch, provided that
5852 enough bits are clear. */
5853 if ( (value
& ~ ((offsetT
) 0x1ffffff)) == ~ ((offsetT
) 0x1ffffff)
5854 || (value
& ~ ((offsetT
) 0x1ffffff)) == 0)
5858 if (! fixP
->fx_done
)
5860 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5861 _("gas can't handle same-section branch dest >= 0x04000000"));
5865 value
+= SEXT24 (newval
);
5867 if ( (value
& ~ ((offsetT
) 0xffffff)) != 0
5868 && ((value
& ~ ((offsetT
) 0xffffff)) != ~ ((offsetT
) 0xffffff)))
5869 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5870 _("out of range branch"));
5872 newval
= (value
& 0x00ffffff) | (newval
& 0xff000000);
5873 md_number_to_chars (buf
, newval
, INSN_SIZE
);
5876 case BFD_RELOC_ARM_PCREL_BLX
:
5879 newval
= md_chars_to_number (buf
, INSN_SIZE
);
5883 value
= fixP
->fx_offset
;
5885 hbit
= (value
>> 1) & 1;
5886 value
= (value
>> 2) & 0x00ffffff;
5887 value
= (value
+ (newval
& 0x00ffffff)) & 0x00ffffff;
5888 newval
= value
| (newval
& 0xfe000000) | (hbit
<< 24);
5889 md_number_to_chars (buf
, newval
, INSN_SIZE
);
5893 case BFD_RELOC_THUMB_PCREL_BRANCH9
: /* Conditional branch. */
5894 newval
= md_chars_to_number (buf
, THUMB_SIZE
);
5896 addressT diff
= (newval
& 0xff) << 1;
5901 if ((value
& ~0xff) && ((value
& ~0xff) != ~0xff))
5902 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5903 _("Branch out of range"));
5904 newval
= (newval
& 0xff00) | ((value
& 0x1ff) >> 1);
5906 md_number_to_chars (buf
, newval
, THUMB_SIZE
);
5909 case BFD_RELOC_THUMB_PCREL_BRANCH12
: /* Unconditional branch. */
5910 newval
= md_chars_to_number (buf
, THUMB_SIZE
);
5912 addressT diff
= (newval
& 0x7ff) << 1;
5917 if ((value
& ~0x7ff) && ((value
& ~0x7ff) != ~0x7ff))
5918 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5919 _("Branch out of range"));
5920 newval
= (newval
& 0xf800) | ((value
& 0xfff) >> 1);
5922 md_number_to_chars (buf
, newval
, THUMB_SIZE
);
5925 case BFD_RELOC_THUMB_PCREL_BLX
:
5926 case BFD_RELOC_THUMB_PCREL_BRANCH23
:
5931 newval
= md_chars_to_number (buf
, THUMB_SIZE
);
5932 newval2
= md_chars_to_number (buf
+ THUMB_SIZE
, THUMB_SIZE
);
5933 diff
= ((newval
& 0x7ff) << 12) | ((newval2
& 0x7ff) << 1);
5934 if (diff
& 0x400000)
5937 value
= fixP
->fx_offset
;
5940 if ((value
& ~0x3fffff) && ((value
& ~0x3fffff) != ~0x3fffff))
5941 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5942 _("Branch with link out of range"));
5944 newval
= (newval
& 0xf800) | ((value
& 0x7fffff) >> 12);
5945 newval2
= (newval2
& 0xf800) | ((value
& 0xfff) >> 1);
5946 md_number_to_chars (buf
, newval
, THUMB_SIZE
);
5947 md_number_to_chars (buf
+ THUMB_SIZE
, newval2
, THUMB_SIZE
);
5952 if (fixP
->fx_done
|| fixP
->fx_pcrel
)
5953 md_number_to_chars (buf
, value
, 1);
5955 else if (!target_oabi
)
5957 value
= fixP
->fx_offset
;
5958 md_number_to_chars (buf
, value
, 1);
5964 if (fixP
->fx_done
|| fixP
->fx_pcrel
)
5965 md_number_to_chars (buf
, value
, 2);
5967 else if (!target_oabi
)
5969 value
= fixP
->fx_offset
;
5970 md_number_to_chars (buf
, value
, 2);
5976 case BFD_RELOC_ARM_GOT32
:
5977 case BFD_RELOC_ARM_GOTOFF
:
5978 md_number_to_chars (buf
, 0, 4);
5984 if (fixP
->fx_done
|| fixP
->fx_pcrel
)
5985 md_number_to_chars (buf
, value
, 4);
5987 else if (!target_oabi
)
5989 value
= fixP
->fx_offset
;
5990 md_number_to_chars (buf
, value
, 4);
5996 case BFD_RELOC_ARM_PLT32
:
5997 /* It appears the instruction is fully prepared at this point. */
6001 case BFD_RELOC_ARM_GOTPC
:
6002 md_number_to_chars (buf
, value
, 4);
6005 case BFD_RELOC_ARM_CP_OFF_IMM
:
6007 if (value
< -1023 || value
> 1023 || (value
& 3))
6008 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6009 _("Illegal value for co-processor offset"));
6012 newval
= md_chars_to_number (buf
, INSN_SIZE
) & 0xff7fff00;
6013 newval
|= (value
>> 2) | (sign
? INDEX_UP
: 0);
6014 md_number_to_chars (buf
, newval
, INSN_SIZE
);
6017 case BFD_RELOC_ARM_THUMB_OFFSET
:
6018 newval
= md_chars_to_number (buf
, THUMB_SIZE
);
6019 /* Exactly what ranges, and where the offset is inserted depends
6020 on the type of instruction, we can establish this from the
6022 switch (newval
>> 12)
6024 case 4: /* PC load. */
6025 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
6026 forced to zero for these loads, so we will need to round
6027 up the offset if the instruction address is not word
6028 aligned (since the final address produced must be, and
6029 we can only describe word-aligned immediate offsets). */
6031 if ((fixP
->fx_frag
->fr_address
+ fixP
->fx_where
+ value
) & 3)
6032 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6033 _("Invalid offset, target not word aligned (0x%08X)"),
6034 (unsigned int) (fixP
->fx_frag
->fr_address
6035 + fixP
->fx_where
+ value
));
6037 if ((value
+ 2) & ~0x3fe)
6038 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6039 _("Invalid offset, value too big (0x%08X)"), value
);
6041 /* Round up, since pc will be rounded down. */
6042 newval
|= (value
+ 2) >> 2;
6045 case 9: /* SP load/store. */
6047 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6048 _("Invalid offset, value too big (0x%08X)"), value
);
6049 newval
|= value
>> 2;
6052 case 6: /* Word load/store. */
6054 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6055 _("Invalid offset, value too big (0x%08X)"), value
);
6056 newval
|= value
<< 4; /* 6 - 2. */
6059 case 7: /* Byte load/store. */
6061 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6062 _("Invalid offset, value too big (0x%08X)"), value
);
6063 newval
|= value
<< 6;
6066 case 8: /* Halfword load/store. */
6068 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6069 _("Invalid offset, value too big (0x%08X)"), value
);
6070 newval
|= value
<< 5; /* 6 - 1. */
6074 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6075 "Unable to process relocation for thumb opcode: %lx",
6076 (unsigned long) newval
);
6079 md_number_to_chars (buf
, newval
, THUMB_SIZE
);
6082 case BFD_RELOC_ARM_THUMB_ADD
:
6083 /* This is a complicated relocation, since we use it for all of
6084 the following immediate relocations:
6088 9bit ADD/SUB SP word-aligned
6089 10bit ADD PC/SP word-aligned
6091 The type of instruction being processed is encoded in the
6098 newval
= md_chars_to_number (buf
, THUMB_SIZE
);
6100 int rd
= (newval
>> 4) & 0xf;
6101 int rs
= newval
& 0xf;
6102 int subtract
= newval
& 0x8000;
6107 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6108 _("Invalid immediate for stack address calculation"));
6109 newval
= subtract
? T_OPCODE_SUB_ST
: T_OPCODE_ADD_ST
;
6110 newval
|= value
>> 2;
6112 else if (rs
== REG_PC
|| rs
== REG_SP
)
6116 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6117 _("Invalid immediate for address calculation (value = 0x%08lX)"),
6118 (unsigned long) value
);
6119 newval
= (rs
== REG_PC
? T_OPCODE_ADD_PC
: T_OPCODE_ADD_SP
);
6121 newval
|= value
>> 2;
6126 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6127 _("Invalid 8bit immediate"));
6128 newval
= subtract
? T_OPCODE_SUB_I8
: T_OPCODE_ADD_I8
;
6129 newval
|= (rd
<< 8) | value
;
6134 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6135 _("Invalid 3bit immediate"));
6136 newval
= subtract
? T_OPCODE_SUB_I3
: T_OPCODE_ADD_I3
;
6137 newval
|= rd
| (rs
<< 3) | (value
<< 6);
6140 md_number_to_chars (buf
, newval
, THUMB_SIZE
);
6143 case BFD_RELOC_ARM_THUMB_IMM
:
6144 newval
= md_chars_to_number (buf
, THUMB_SIZE
);
6145 switch (newval
>> 11)
6147 case 0x04: /* 8bit immediate MOV. */
6148 case 0x05: /* 8bit immediate CMP. */
6149 if (value
< 0 || value
> 255)
6150 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6151 _("Invalid immediate: %ld is too large"),
6159 md_number_to_chars (buf
, newval
, THUMB_SIZE
);
6162 case BFD_RELOC_ARM_THUMB_SHIFT
:
6163 /* 5bit shift value (0..31). */
6164 if (value
< 0 || value
> 31)
6165 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6166 _("Illegal Thumb shift value: %ld"), (long) value
);
6167 newval
= md_chars_to_number (buf
, THUMB_SIZE
) & 0xf03f;
6168 newval
|= value
<< 6;
6169 md_number_to_chars (buf
, newval
, THUMB_SIZE
);
6172 case BFD_RELOC_VTABLE_INHERIT
:
6173 case BFD_RELOC_VTABLE_ENTRY
:
6177 case BFD_RELOC_NONE
:
6179 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6180 _("Bad relocation fixup type (%d)"), fixP
->fx_r_type
);
6186 /* Translate internal representation of relocation info to BFD target
6190 tc_gen_reloc (section
, fixp
)
6191 asection
* section ATTRIBUTE_UNUSED
;
6195 bfd_reloc_code_real_type code
;
6197 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
6199 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
6200 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
6201 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
6203 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
6205 if (fixp
->fx_pcrel
== 0)
6206 reloc
->addend
= fixp
->fx_offset
;
6208 reloc
->addend
= fixp
->fx_offset
= reloc
->address
;
6210 reloc
->addend
= fixp
->fx_offset
;
6213 switch (fixp
->fx_r_type
)
6218 code
= BFD_RELOC_8_PCREL
;
6225 code
= BFD_RELOC_16_PCREL
;
6232 code
= BFD_RELOC_32_PCREL
;
6236 case BFD_RELOC_ARM_PCREL_BRANCH
:
6237 case BFD_RELOC_ARM_PCREL_BLX
:
6239 case BFD_RELOC_THUMB_PCREL_BRANCH9
:
6240 case BFD_RELOC_THUMB_PCREL_BRANCH12
:
6241 case BFD_RELOC_THUMB_PCREL_BRANCH23
:
6242 case BFD_RELOC_THUMB_PCREL_BLX
:
6243 case BFD_RELOC_VTABLE_ENTRY
:
6244 case BFD_RELOC_VTABLE_INHERIT
:
6245 code
= fixp
->fx_r_type
;
6248 case BFD_RELOC_ARM_LITERAL
:
6249 case BFD_RELOC_ARM_HWLITERAL
:
6250 /* If this is called then the a literal has been referenced across
6251 a section boundary - possibly due to an implicit dump. */
6252 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6253 _("Literal referenced across section boundary (Implicit dump?)"));
6257 case BFD_RELOC_ARM_GOT32
:
6258 case BFD_RELOC_ARM_GOTOFF
:
6259 case BFD_RELOC_ARM_PLT32
:
6260 code
= fixp
->fx_r_type
;
6264 case BFD_RELOC_ARM_IMMEDIATE
:
6265 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6266 _("Internal_relocation (type %d) not fixed up (IMMEDIATE)"),
6270 case BFD_RELOC_ARM_ADRL_IMMEDIATE
:
6271 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6272 _("ADRL used for a symbol not defined in the same file"),
6276 case BFD_RELOC_ARM_OFFSET_IMM
:
6277 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6278 _("Internal_relocation (type %d) not fixed up (OFFSET_IMM)"),
6286 switch (fixp
->fx_r_type
)
6288 case BFD_RELOC_ARM_IMMEDIATE
: type
= "IMMEDIATE"; break;
6289 case BFD_RELOC_ARM_OFFSET_IMM
: type
= "OFFSET_IMM"; break;
6290 case BFD_RELOC_ARM_OFFSET_IMM8
: type
= "OFFSET_IMM8"; break;
6291 case BFD_RELOC_ARM_SHIFT_IMM
: type
= "SHIFT_IMM"; break;
6292 case BFD_RELOC_ARM_SWI
: type
= "SWI"; break;
6293 case BFD_RELOC_ARM_MULTI
: type
= "MULTI"; break;
6294 case BFD_RELOC_ARM_CP_OFF_IMM
: type
= "CP_OFF_IMM"; break;
6295 case BFD_RELOC_ARM_THUMB_ADD
: type
= "THUMB_ADD"; break;
6296 case BFD_RELOC_ARM_THUMB_SHIFT
: type
= "THUMB_SHIFT"; break;
6297 case BFD_RELOC_ARM_THUMB_IMM
: type
= "THUMB_IMM"; break;
6298 case BFD_RELOC_ARM_THUMB_OFFSET
: type
= "THUMB_OFFSET"; break;
6299 default: type
= _("<unknown>"); break;
6301 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6302 _("Can not represent %s relocation in this object file format (%d)"),
6303 type
, fixp
->fx_pcrel
);
6309 if (code
== BFD_RELOC_32_PCREL
6311 && fixp
->fx_addsy
== GOT_symbol
)
6313 code
= BFD_RELOC_ARM_GOTPC
;
6314 reloc
->addend
= fixp
->fx_offset
= reloc
->address
;
6318 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
6320 if (reloc
->howto
== NULL
)
6322 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6323 _("Can not represent %s relocation in this object file format"),
6324 bfd_get_reloc_code_name (code
));
6328 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
6329 vtable entry to be used in the relocation's section offset. */
6330 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
6331 reloc
->address
= fixp
->fx_offset
;
6337 md_estimate_size_before_relax (fragP
, segtype
)
6338 fragS
* fragP ATTRIBUTE_UNUSED
;
6339 segT segtype ATTRIBUTE_UNUSED
;
6341 as_fatal (_("md_estimate_size_before_relax\n"));
6346 output_inst
PARAMS ((void))
6352 as_bad (inst
.error
);
6356 to
= frag_more (inst
.size
);
6358 if (thumb_mode
&& (inst
.size
> THUMB_SIZE
))
6360 assert (inst
.size
== (2 * THUMB_SIZE
));
6361 md_number_to_chars (to
, inst
.instruction
>> 16, THUMB_SIZE
);
6362 md_number_to_chars (to
+ THUMB_SIZE
, inst
.instruction
, THUMB_SIZE
);
6364 else if (inst
.size
> INSN_SIZE
)
6366 assert (inst
.size
== (2 * INSN_SIZE
));
6367 md_number_to_chars (to
, inst
.instruction
, INSN_SIZE
);
6368 md_number_to_chars (to
+ INSN_SIZE
, inst
.instruction
, INSN_SIZE
);
6371 md_number_to_chars (to
, inst
.instruction
, inst
.size
);
6373 if (inst
.reloc
.type
!= BFD_RELOC_NONE
)
6374 fix_new_arm (frag_now
, to
- frag_now
->fr_literal
,
6375 inst
.size
, & inst
.reloc
.exp
, inst
.reloc
.pc_rel
,
6390 /* Align the instruction.
6391 This may not be the right thing to do but ... */
6395 listing_prev_line (); /* Defined in listing.h. */
6397 /* Align the previous label if needed. */
6398 if (last_label_seen
!= NULL
)
6400 symbol_set_frag (last_label_seen
, frag_now
);
6401 S_SET_VALUE (last_label_seen
, (valueT
) frag_now_fix ());
6402 S_SET_SEGMENT (last_label_seen
, now_seg
);
6405 memset (&inst
, '\0', sizeof (inst
));
6406 inst
.reloc
.type
= BFD_RELOC_NONE
;
6408 skip_whitespace (str
);
6410 /* Scan up to the end of the op-code, which must end in white space or
6412 for (start
= p
= str
; *p
!= '\0'; p
++)
6418 as_bad (_("No operator -- statement `%s'\n"), str
);
6424 CONST
struct thumb_opcode
* opcode
;
6428 opcode
= (CONST
struct thumb_opcode
*) hash_find (arm_tops_hsh
, str
);
6433 /* Check that this instruction is supported for this CPU. */
6434 if (thumb_mode
== 1 && (opcode
->variants
& cpu_variant
) == 0)
6436 as_bad (_("selected processor does not support this opcode"));
6440 inst
.instruction
= opcode
->value
;
6441 inst
.size
= opcode
->size
;
6442 (*opcode
->parms
) (p
);
6449 CONST
struct asm_opcode
* opcode
;
6450 unsigned long cond_code
;
6452 inst
.size
= INSN_SIZE
;
6453 /* P now points to the end of the opcode, probably white space, but we
6454 have to break the opcode up in case it contains condionals and flags;
6455 keep trying with progressively smaller basic instructions until one
6456 matches, or we run out of opcode. */
6457 q
= (p
- str
> LONGEST_INST
) ? str
+ LONGEST_INST
: p
;
6459 for (; q
!= str
; q
--)
6464 opcode
= (CONST
struct asm_opcode
*) hash_find (arm_ops_hsh
, str
);
6467 if (opcode
&& opcode
->template)
6469 unsigned long flag_bits
= 0;
6472 /* Check that this instruction is supported for this CPU. */
6473 if ((opcode
->variants
& cpu_variant
) == 0)
6476 inst
.instruction
= opcode
->value
;
6477 if (q
== p
) /* Just a simple opcode. */
6479 if (opcode
->comp_suffix
)
6481 if (*opcode
->comp_suffix
!= '\0')
6482 as_bad (_("Opcode `%s' must have suffix from list: <%s>"),
6483 str
, opcode
->comp_suffix
);
6485 /* Not a conditional instruction. */
6486 (*opcode
->parms
) (q
, 0);
6490 /* A conditional instruction with default condition. */
6491 inst
.instruction
|= COND_ALWAYS
;
6492 (*opcode
->parms
) (q
, 0);
6498 /* Not just a simple opcode. Check if extra is a
6503 CONST
struct asm_cond
*cond
;
6507 cond
= (CONST
struct asm_cond
*) hash_find (arm_cond_hsh
, r
);
6511 if (cond
->value
== 0xf0000000)
6513 _("Warning: Use of the 'nv' conditional is deprecated\n"));
6515 cond_code
= cond
->value
;
6519 cond_code
= COND_ALWAYS
;
6522 cond_code
= COND_ALWAYS
;
6524 /* Apply the conditional, or complain it's not allowed. */
6525 if (opcode
->comp_suffix
&& *opcode
->comp_suffix
== '\0')
6527 /* Instruction isn't conditional. */
6528 if (cond_code
!= COND_ALWAYS
)
6530 as_bad (_("Opcode `%s' is unconditional\n"), str
);
6535 /* Instruction is conditional: set the condition into it. */
6536 inst
.instruction
|= cond_code
;
6538 /* If there is a compulsory suffix, it should come here
6539 before any optional flags. */
6540 if (opcode
->comp_suffix
&& *opcode
->comp_suffix
!= '\0')
6542 CONST
char *s
= opcode
->comp_suffix
;
6554 as_bad (_("Opcode `%s' must have suffix from <%s>\n"),
6555 str
, opcode
->comp_suffix
);
6562 /* The remainder, if any should now be flags for the instruction;
6563 Scan these checking each one found with the opcode. */
6567 CONST
struct asm_flg
*flag
= opcode
->flags
;
6576 for (flagno
= 0; flag
[flagno
].template; flagno
++)
6578 if (streq (r
, flag
[flagno
].template))
6580 flag_bits
|= flag
[flagno
].set_bits
;
6586 if (! flag
[flagno
].template)
6593 (*opcode
->parms
) (p
, flag_bits
);
6603 /* It wasn't an instruction, but it might be a register alias of the form
6606 skip_whitespace (q
);
6611 if (*q
&& !strncmp (q
, ".req ", 4))
6614 char * copy_of_str
= str
;
6618 skip_whitespace (q
);
6620 for (r
= q
; *r
!= '\0'; r
++)
6630 regnum
= arm_reg_parse (& q
);
6633 reg
= arm_reg_parse (& str
);
6638 insert_reg_alias (str
, regnum
);
6640 as_warn (_("register '%s' does not exist\n"), q
);
6642 else if (regnum
!= FAIL
)
6645 as_warn (_("ignoring redefinition of register alias '%s'"),
6648 /* Do not warn about redefinitions to the same alias. */
6651 as_warn (_("ignoring redefinition of register alias '%s' to non-existant register '%s'"),
6655 as_warn (_("ignoring incomplete .req pseuso op"));
6662 as_bad (_("bad instruction `%s'"), start
);
6666 Invocation line includes a switch not recognized by the base assembler.
6667 See if it's a processor-specific option. These are:
6668 Cpu variants, the arm part is optional:
6669 -m[arm]1 Currently not supported.
6670 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
6671 -m[arm]3 Arm 3 processor
6672 -m[arm]6[xx], Arm 6 processors
6673 -m[arm]7[xx][t][[d]m] Arm 7 processors
6674 -m[arm]8[10] Arm 8 processors
6675 -m[arm]9[20][tdmi] Arm 9 processors
6676 -mstrongarm[110[0]] StrongARM processors
6677 -m[arm]v[2345[t]] Arm architectures
6678 -mall All (except the ARM1)
6680 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
6681 -mfpe-old (No float load/store multiples)
6682 -mno-fpu Disable all floating point instructions
6683 Run-time endian selection:
6685 -EL little endian cpu
6686 ARM Procedure Calling Standard:
6687 -mapcs-32 32 bit APCS
6688 -mapcs-26 26 bit APCS
6689 -mapcs-float Pass floats in float regs
6690 -mapcs-reentrant Position independent code
6691 -mthumb-interwork Code supports Arm/Thumb interworking
6692 -moabi Old ELF ABI */
6694 CONST
char * md_shortopts
= "m:k";
6696 struct option md_longopts
[] =
6698 #ifdef ARM_BI_ENDIAN
6699 #define OPTION_EB (OPTION_MD_BASE + 0)
6700 {"EB", no_argument
, NULL
, OPTION_EB
},
6701 #define OPTION_EL (OPTION_MD_BASE + 1)
6702 {"EL", no_argument
, NULL
, OPTION_EL
},
6704 #define OPTION_OABI (OPTION_MD_BASE +2)
6705 {"oabi", no_argument
, NULL
, OPTION_OABI
},
6708 {NULL
, no_argument
, NULL
, 0}
6711 size_t md_longopts_size
= sizeof (md_longopts
);
6714 md_parse_option (c
, arg
)
6722 #ifdef ARM_BI_ENDIAN
6724 target_big_endian
= 1;
6727 target_big_endian
= 0;
6735 if (streq (str
, "fpa10"))
6736 cpu_variant
= (cpu_variant
& ~FPU_ALL
) | FPU_FPA10
;
6737 else if (streq (str
, "fpa11"))
6738 cpu_variant
= (cpu_variant
& ~FPU_ALL
) | FPU_FPA11
;
6739 else if (streq (str
, "fpe-old"))
6740 cpu_variant
= (cpu_variant
& ~FPU_ALL
) | FPU_CORE
;
6746 if (streq (str
, "no-fpu"))
6747 cpu_variant
&= ~FPU_ALL
;
6752 if (streq (str
, "oabi"))
6758 /* Limit assembler to generating only Thumb instructions: */
6759 if (streq (str
, "thumb"))
6761 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_THUMB
;
6762 cpu_variant
= (cpu_variant
& ~FPU_ALL
) | FPU_NONE
;
6765 else if (streq (str
, "thumb-interwork"))
6767 if ((cpu_variant
& ARM_THUMB
) == 0)
6768 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_ARCH_V4T
;
6769 #if defined OBJ_COFF || defined OBJ_ELF
6770 support_interwork
= true;
6778 if (streq (str
, "all"))
6780 cpu_variant
= ARM_ALL
| FPU_ALL
;
6783 #if defined OBJ_COFF || defined OBJ_ELF
6784 if (! strncmp (str
, "apcs-", 5))
6786 /* GCC passes on all command line options starting "-mapcs-..."
6787 to us, so we must parse them here. */
6791 if (streq (str
, "32"))
6793 uses_apcs_26
= false;
6796 else if (streq (str
, "26"))
6798 uses_apcs_26
= true;
6801 else if (streq (str
, "frame"))
6803 /* Stack frames are being generated - does not affect
6807 else if (streq (str
, "stack-check"))
6809 /* Stack checking is being performed - does not affect
6810 linkage, but does require that the functions
6811 __rt_stkovf_split_small and __rt_stkovf_split_big be
6812 present in the final link. */
6816 else if (streq (str
, "float"))
6818 /* Floating point arguments are being passed in the floating
6819 point registers. This does affect linking, since this
6820 version of the APCS is incompatible with the version that
6821 passes floating points in the integer registers. */
6823 uses_apcs_float
= true;
6826 else if (streq (str
, "reentrant"))
6828 /* Reentrant code has been generated. This does affect
6829 linking, since there is no point in linking reentrant/
6830 position independent code with absolute position code. */
6835 as_bad (_("Unrecognised APCS switch -m%s"), arg
);
6839 /* Strip off optional "arm". */
6840 if (! strncmp (str
, "arm", 3))
6846 if (streq (str
, "1"))
6847 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_1
;
6853 if (streq (str
, "2"))
6854 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_2
;
6855 else if (streq (str
, "250"))
6856 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_250
;
6862 if (streq (str
, "3"))
6863 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_3
;
6869 switch (strtol (str
, NULL
, 10))
6876 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_6
;
6884 /* Eat the processor name. */
6885 switch (strtol (str
, & str
, 10))
6898 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_7
;
6904 cpu_variant
|= (ARM_THUMB
| ARM_ARCH_V4
);
6908 cpu_variant
|= ARM_LONGMUL
;
6911 case 'f': /* fe => fp enabled cpu. */
6917 case 'c': /* Left over from 710c processor name. */
6918 case 'd': /* Debug. */
6919 case 'i': /* Embedded ICE. */
6920 /* Included for completeness in ARM processor naming. */
6930 if (streq (str
, "8") || streq (str
, "810"))
6931 cpu_variant
= (cpu_variant
& ~ARM_ANY
)
6932 | ARM_8
| ARM_ARCH_V4
| ARM_LONGMUL
;
6938 if (streq (str
, "9"))
6939 cpu_variant
= (cpu_variant
& ~ARM_ANY
)
6940 | ARM_9
| ARM_ARCH_V4
| ARM_LONGMUL
| ARM_THUMB
;
6941 else if (streq (str
, "920"))
6942 cpu_variant
= (cpu_variant
& ~ARM_ANY
)
6943 | ARM_9
| ARM_ARCH_V4
| ARM_LONGMUL
;
6944 else if (streq (str
, "920t"))
6945 cpu_variant
= (cpu_variant
& ~ARM_ANY
)
6946 | ARM_9
| ARM_ARCH_V4
| ARM_LONGMUL
| ARM_THUMB
;
6947 else if (streq (str
, "9tdmi"))
6948 cpu_variant
= (cpu_variant
& ~ARM_ANY
)
6949 | ARM_9
| ARM_ARCH_V4
| ARM_LONGMUL
| ARM_THUMB
;
6955 if (streq (str
, "strongarm")
6956 || streq (str
, "strongarm110")
6957 || streq (str
, "strongarm1100"))
6958 cpu_variant
= (cpu_variant
& ~ARM_ANY
)
6959 | ARM_8
| ARM_ARCH_V4
| ARM_LONGMUL
;
6965 /* Select variant based on architecture rather than
6973 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_3
;
6976 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_2
;
6979 as_bad (_("Invalid architecture variant -m%s"), arg
);
6985 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_7
;
6989 case 'm': cpu_variant
|= ARM_LONGMUL
; break;
6992 as_bad (_("Invalid architecture variant -m%s"), arg
);
6998 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_ARCH_V4
;
7002 case 't': cpu_variant
|= ARM_THUMB
; break;
7005 as_bad (_("Invalid architecture variant -m%s"), arg
);
7011 cpu_variant
= (cpu_variant
& ~ARM_ANY
) | ARM_ARCH_V5
;
7014 case 't': cpu_variant
|= ARM_THUMB
; break;
7017 as_bad (_("Invalid architecture variant -m%s"), arg
);
7023 as_bad (_("Invalid architecture variant -m%s"), arg
);
7030 as_bad (_("Invalid processor variant -m%s"), arg
);
7036 #if defined OBJ_ELF || defined OBJ_COFF
7054 ARM Specific Assembler Options:\n\
7055 -m[arm][<processor name>] select processor variant\n\
7056 -m[arm]v[2|2a|3|3m|4|4t|5[t][e]] select architecture variant\n\
7057 -mthumb only allow Thumb instructions\n\
7058 -mthumb-interwork mark the assembled code as supporting interworking\n\
7059 -mall allow any instruction\n\
7060 -mfpa10, -mfpa11 select floating point architecture\n\
7061 -mfpe-old don't allow floating-point multiple instructions\n\
7062 -mno-fpu don't allow any floating-point instructions.\n\
7063 -k generate PIC code.\n"));
7064 #if defined OBJ_COFF || defined OBJ_ELF
7066 -mapcs-32, -mapcs-26 specify which ARM Procedure Calling Standard to use\n\
7067 -mapcs-float floating point args are passed in FP regs\n\
7068 -mapcs-reentrant the code is position independent/reentrant\n"));
7072 -moabi support the old ELF ABI\n"));
7074 #ifdef ARM_BI_ENDIAN
7076 -EB assemble code for a big endian cpu\n\
7077 -EL assemble code for a little endian cpu\n"));
7081 /* We need to be able to fix up arbitrary expressions in some statements.
7082 This is so that we can handle symbols that are an arbitrary distance from
7083 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
7084 which returns part of an address in a form which will be valid for
7085 a data instruction. We do this by pushing the expression into a symbol
7086 in the expr_section, and creating a fix for that. */
7089 fix_new_arm (frag
, where
, size
, exp
, pc_rel
, reloc
)
7098 arm_fix_data
* arm_data
;
7106 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pc_rel
, reloc
);
7110 new_fix
= fix_new (frag
, where
, size
, make_expr_symbol (exp
), 0,
7115 /* Mark whether the fix is to a THUMB instruction, or an ARM
7117 arm_data
= (arm_fix_data
*) obstack_alloc (& notes
, sizeof (arm_fix_data
));
7118 new_fix
->tc_fix_data
= (PTR
) arm_data
;
7119 arm_data
->thumb_mode
= thumb_mode
;
7124 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
7127 cons_fix_new_arm (frag
, where
, size
, exp
)
7133 bfd_reloc_code_real_type type
;
7137 FIXME: @@ Should look at CPU word size. */
7144 type
= BFD_RELOC_16
;
7148 type
= BFD_RELOC_32
;
7151 type
= BFD_RELOC_64
;
7155 fix_new_exp (frag
, where
, (int) size
, exp
, pcrel
, type
);
7158 /* A good place to do this, although this was probably not intended
7159 for this kind of use. We need to dump the literal pool before
7160 references are made to a null symbol pointer. */
7165 if (current_poolP
== NULL
)
7168 /* Put it at the end of text section. */
7169 subseg_set (text_section
, 0);
7171 listing_prev_line ();
7175 arm_start_line_hook ()
7177 last_label_seen
= NULL
;
7181 arm_frob_label (sym
)
7184 last_label_seen
= sym
;
7186 ARM_SET_THUMB (sym
, thumb_mode
);
7188 #if defined OBJ_COFF || defined OBJ_ELF
7189 ARM_SET_INTERWORK (sym
, support_interwork
);
7192 if (label_is_thumb_function_name
)
7194 /* When the address of a Thumb function is taken the bottom
7195 bit of that address should be set. This will allow
7196 interworking between Arm and Thumb functions to work
7199 THUMB_SET_FUNC (sym
, 1);
7201 label_is_thumb_function_name
= false;
7205 /* Adjust the symbol table. This marks Thumb symbols as distinct from
7209 arm_adjust_symtab ()
7214 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
7216 if (ARM_IS_THUMB (sym
))
7218 if (THUMB_IS_FUNC (sym
))
7220 /* Mark the symbol as a Thumb function. */
7221 if ( S_GET_STORAGE_CLASS (sym
) == C_STAT
7222 || S_GET_STORAGE_CLASS (sym
) == C_LABEL
) /* This can happen! */
7223 S_SET_STORAGE_CLASS (sym
, C_THUMBSTATFUNC
);
7225 else if (S_GET_STORAGE_CLASS (sym
) == C_EXT
)
7226 S_SET_STORAGE_CLASS (sym
, C_THUMBEXTFUNC
);
7228 as_bad (_("%s: unexpected function type: %d"),
7229 S_GET_NAME (sym
), S_GET_STORAGE_CLASS (sym
));
7231 else switch (S_GET_STORAGE_CLASS (sym
))
7234 S_SET_STORAGE_CLASS (sym
, C_THUMBEXT
);
7237 S_SET_STORAGE_CLASS (sym
, C_THUMBSTAT
);
7240 S_SET_STORAGE_CLASS (sym
, C_THUMBLABEL
);
7248 if (ARM_IS_INTERWORK (sym
))
7249 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_flags
= 0xFF;
7256 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
7258 if (ARM_IS_THUMB (sym
))
7260 elf_symbol_type
*elf_sym
;
7262 elf_sym
= elf_symbol (symbol_get_bfdsym (sym
));
7263 bind
= ELF_ST_BIND (elf_sym
);
7265 /* If it's a .thumb_func, declare it as so,
7266 otherwise tag label as .code 16. */
7267 if (THUMB_IS_FUNC (sym
))
7268 elf_sym
->internal_elf_sym
.st_info
=
7269 ELF_ST_INFO (bind
, STT_ARM_TFUNC
);
7271 elf_sym
->internal_elf_sym
.st_info
=
7272 ELF_ST_INFO (bind
, STT_ARM_16BIT
);
7281 if (thumb_mode
&& ! strncmp (input_line_pointer
+ 1, "data:", 5))
7283 *input_line_pointer
= '/';
7284 input_line_pointer
+= 5;
7285 *input_line_pointer
= 0;
7293 arm_canonicalize_symbol_name (name
)
7298 if (thumb_mode
&& (len
= strlen (name
)) > 5
7299 && streq (name
+ len
- 5, "/data"))
7300 *(name
+ len
- 5) = 0;
7306 arm_validate_fix (fixP
)
7309 /* If the destination of the branch is a defined symbol which does not have
7310 the THUMB_FUNC attribute, then we must be calling a function which has
7311 the (interfacearm) attribute. We look for the Thumb entry point to that
7312 function and change the branch to refer to that function instead. */
7313 if (fixP
->fx_r_type
== BFD_RELOC_THUMB_PCREL_BRANCH23
7314 && fixP
->fx_addsy
!= NULL
7315 && S_IS_DEFINED (fixP
->fx_addsy
)
7316 && ! THUMB_IS_FUNC (fixP
->fx_addsy
))
7318 fixP
->fx_addsy
= find_real_start (fixP
->fx_addsy
);
7326 /* Relocations against Thumb function names must be left unadjusted,
7327 so that the linker can use this information to correctly set the
7328 bottom bit of their addresses. The MIPS version of this function
7329 also prevents relocations that are mips-16 specific, but I do not
7330 know why it does this.
7333 There is one other problem that ought to be addressed here, but
7334 which currently is not: Taking the address of a label (rather
7335 than a function) and then later jumping to that address. Such
7336 addresses also ought to have their bottom bit set (assuming that
7337 they reside in Thumb code), but at the moment they will not. */
7340 arm_fix_adjustable (fixP
)
7343 if (fixP
->fx_addsy
== NULL
)
7346 /* Prevent all adjustments to global symbols. */
7347 if (S_IS_EXTERN (fixP
->fx_addsy
))
7350 if (S_IS_WEAK (fixP
->fx_addsy
))
7353 if (THUMB_IS_FUNC (fixP
->fx_addsy
)
7354 && fixP
->fx_subsy
== NULL
)
7357 /* We need the symbol name for the VTABLE entries. */
7358 if ( fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
7359 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
7366 elf32_arm_target_format ()
7368 if (target_big_endian
)
7371 return "elf32-bigarm-oabi";
7373 return "elf32-bigarm";
7378 return "elf32-littlearm-oabi";
7380 return "elf32-littlearm";
7385 armelf_frob_symbol (symp
, puntp
)
7389 elf_frob_symbol (symp
, puntp
);
7393 arm_force_relocation (fixp
)
7396 if ( fixp
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
7397 || fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
7398 || fixp
->fx_r_type
== BFD_RELOC_ARM_PCREL_BRANCH
7399 || fixp
->fx_r_type
== BFD_RELOC_ARM_PCREL_BLX
7400 || fixp
->fx_r_type
== BFD_RELOC_THUMB_PCREL_BLX
7401 || fixp
->fx_r_type
== BFD_RELOC_THUMB_PCREL_BRANCH23
)
7407 static bfd_reloc_code_real_type
7417 bfd_reloc_code_real_type reloc
;
7421 #define MAP(str,reloc) { str, sizeof (str) - 1, reloc }
7422 MAP ("(got)", BFD_RELOC_ARM_GOT32
),
7423 MAP ("(gotoff)", BFD_RELOC_ARM_GOTOFF
),
7424 /* ScottB: Jan 30, 1998 - Added support for parsing "var(PLT)"
7425 branch instructions generated by GCC for PLT relocs. */
7426 MAP ("(plt)", BFD_RELOC_ARM_PLT32
),
7427 { NULL
, 0, BFD_RELOC_UNUSED
}
7431 for (i
= 0, ip
= input_line_pointer
;
7432 i
< sizeof (id
) && (isalnum (*ip
) || ispunct (*ip
));
7434 id
[i
] = tolower (*ip
);
7436 for (i
= 0; reloc_map
[i
].str
; i
++)
7437 if (strncmp (id
, reloc_map
[i
].str
, reloc_map
[i
].len
) == 0)
7440 input_line_pointer
+= reloc_map
[i
].len
;
7442 return reloc_map
[i
].reloc
;
7446 s_arm_elf_cons (nbytes
)
7451 #ifdef md_flush_pending_output
7452 md_flush_pending_output ();
7455 if (is_it_end_of_statement ())
7457 demand_empty_rest_of_line ();
7461 #ifdef md_cons_align
7462 md_cons_align (nbytes
);
7467 bfd_reloc_code_real_type reloc
;
7471 if (exp
.X_op
== O_symbol
7472 && *input_line_pointer
== '('
7473 && (reloc
= arm_parse_reloc ()) != BFD_RELOC_UNUSED
)
7475 reloc_howto_type
*howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
7476 int size
= bfd_get_reloc_size (howto
);
7479 as_bad ("%s relocations do not fit in %d bytes",
7480 howto
->name
, nbytes
);
7483 register char *p
= frag_more ((int) nbytes
);
7484 int offset
= nbytes
- size
;
7486 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
7491 emit_expr (&exp
, (unsigned int) nbytes
);
7493 while (*input_line_pointer
++ == ',');
7495 /* Put terminator back into stream. */
7496 input_line_pointer
--;
7497 demand_empty_rest_of_line ();
7500 #endif /* OBJ_ELF */