1 /* tc-sh.c -- Assemble code for the Renesas / SuperH SH
2 Copyright (C) 1993-2020 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
19 Boston, MA 02110-1301, USA. */
21 /* Written By Steve Chamberlain <sac@cygnus.com> */
26 #include "opcodes/sh-opc.h"
27 #include "safe-ctype.h"
33 #include "dwarf2dbg.h"
34 #include "dw2gencfi.h"
40 expressionS immediate
;
44 const char comment_chars
[] = "!";
45 const char line_separator_chars
[] = ";";
46 const char line_comment_chars
[] = "!#";
48 static void s_uses (int);
49 static void s_uacons (int);
52 static void sh_elf_cons (int);
54 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
58 big (int ignore ATTRIBUTE_UNUSED
)
60 if (! target_big_endian
)
61 as_bad (_("directive .big encountered when option -big required"));
63 /* Stop further messages. */
64 target_big_endian
= 1;
68 little (int ignore ATTRIBUTE_UNUSED
)
70 if (target_big_endian
)
71 as_bad (_("directive .little encountered when option -little required"));
73 /* Stop further messages. */
74 target_big_endian
= 0;
77 /* This table describes all the machine specific pseudo-ops the assembler
78 has to support. The fields are:
79 pseudo-op name without dot
80 function to call to execute this pseudo-op
81 Integer arg to pass to the function. */
83 const pseudo_typeS md_pseudo_table
[] =
86 {"long", sh_elf_cons
, 4},
87 {"int", sh_elf_cons
, 4},
88 {"word", sh_elf_cons
, 2},
89 {"short", sh_elf_cons
, 2},
95 {"form", listing_psize
, 0},
96 {"little", little
, 0},
97 {"heading", listing_title
, 0},
98 {"import", s_ignore
, 0},
99 {"page", listing_eject
, 0},
100 {"program", s_ignore
, 0},
102 {"uaword", s_uacons
, 2},
103 {"ualong", s_uacons
, 4},
104 {"uaquad", s_uacons
, 8},
105 {"2byte", s_uacons
, 2},
106 {"4byte", s_uacons
, 4},
107 {"8byte", s_uacons
, 8},
111 int sh_relax
; /* set if -relax seen */
113 /* Whether -small was seen. */
117 /* Flag to generate relocations against symbol values for local symbols. */
119 static int dont_adjust_reloc_32
;
121 /* Flag to indicate that '$' is allowed as a register prefix. */
123 static int allow_dollar_register_prefix
;
125 /* Preset architecture set, if given; zero otherwise. */
127 static unsigned int preset_target_arch
;
129 /* The bit mask of architectures that could
130 accommodate the insns seen so far. */
131 static unsigned int valid_arch
;
134 /* Whether --fdpic was given. */
138 const char EXP_CHARS
[] = "eE";
140 /* Chars that mean this number is a floating point constant. */
143 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
145 #define C(a,b) ENCODE_RELAX(a,b)
147 #define ENCODE_RELAX(what,length) (((what) << 4) + (length))
148 #define GET_WHAT(x) ((x>>4))
150 /* These are the three types of relaxable instruction. */
151 /* These are the types of relaxable instructions; except for END which is
154 #define COND_JUMP_DELAY 2
155 #define UNCOND_JUMP 3
163 #define UNDEF_WORD_DISP 4
168 /* Branch displacements are from the address of the branch plus
169 four, thus all minimum and maximum values have 4 added to them. */
172 #define COND8_LENGTH 2
174 /* There is one extra instruction before the branch, so we must add
175 two more bytes to account for it. */
176 #define COND12_F 4100
177 #define COND12_M -4090
178 #define COND12_LENGTH 6
180 #define COND12_DELAY_LENGTH 4
182 /* ??? The minimum and maximum values are wrong, but this does not matter
183 since this relocation type is not supported yet. */
184 #define COND32_F (1<<30)
185 #define COND32_M -(1<<30)
186 #define COND32_LENGTH 14
188 #define UNCOND12_F 4098
189 #define UNCOND12_M -4092
190 #define UNCOND12_LENGTH 2
192 /* ??? The minimum and maximum values are wrong, but this does not matter
193 since this relocation type is not supported yet. */
194 #define UNCOND32_F (1<<30)
195 #define UNCOND32_M -(1<<30)
196 #define UNCOND32_LENGTH 14
198 #define EMPTY { 0, 0, 0, 0 }
200 const relax_typeS md_relax_table
[C (END
, 0)] = {
201 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
202 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
205 /* C (COND_JUMP, COND8) */
206 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP
, COND12
) },
207 /* C (COND_JUMP, COND12) */
208 { COND12_F
, COND12_M
, COND12_LENGTH
, C (COND_JUMP
, COND32
), },
209 /* C (COND_JUMP, COND32) */
210 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
211 /* C (COND_JUMP, UNDEF_WORD_DISP) */
212 { 0, 0, COND32_LENGTH
, 0, },
214 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
217 /* C (COND_JUMP_DELAY, COND8) */
218 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP_DELAY
, COND12
) },
219 /* C (COND_JUMP_DELAY, COND12) */
220 { COND12_F
, COND12_M
, COND12_DELAY_LENGTH
, C (COND_JUMP_DELAY
, COND32
), },
221 /* C (COND_JUMP_DELAY, COND32) */
222 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
223 /* C (COND_JUMP_DELAY, UNDEF_WORD_DISP) */
224 { 0, 0, COND32_LENGTH
, 0, },
226 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
229 /* C (UNCOND_JUMP, UNCOND12) */
230 { UNCOND12_F
, UNCOND12_M
, UNCOND12_LENGTH
, C (UNCOND_JUMP
, UNCOND32
), },
231 /* C (UNCOND_JUMP, UNCOND32) */
232 { UNCOND32_F
, UNCOND32_M
, UNCOND32_LENGTH
, 0, },
234 /* C (UNCOND_JUMP, UNDEF_WORD_DISP) */
235 { 0, 0, UNCOND32_LENGTH
, 0, },
237 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
243 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics */
247 /* Determine whether the symbol needs any kind of PIC relocation. */
250 sh_PIC_related_p (symbolS
*sym
)
257 if (sym
== GOT_symbol
)
260 exp
= symbol_get_value_expression (sym
);
262 return (exp
->X_op
== O_PIC_reloc
263 || sh_PIC_related_p (exp
->X_add_symbol
)
264 || sh_PIC_related_p (exp
->X_op_symbol
));
267 /* Determine the relocation type to be used to represent the
268 expression, that may be rearranged. */
271 sh_check_fixup (expressionS
*main_exp
, bfd_reloc_code_real_type
*r_type_p
)
273 expressionS
*exp
= main_exp
;
275 /* This is here for backward-compatibility only. GCC used to generated:
277 f@PLT + . - (.LPCS# + 2)
279 but we'd rather be able to handle this as a PIC-related reference
280 plus/minus a symbol. However, gas' parser gives us:
282 O_subtract (O_add (f@PLT, .), .LPCS#+2)
284 so we attempt to transform this into:
286 O_subtract (f@PLT, O_subtract (.LPCS#+2, .))
288 which we can handle simply below. */
289 if (exp
->X_op
== O_subtract
)
291 if (sh_PIC_related_p (exp
->X_op_symbol
))
294 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
296 if (exp
&& sh_PIC_related_p (exp
->X_op_symbol
))
299 if (exp
&& exp
->X_op
== O_add
300 && sh_PIC_related_p (exp
->X_add_symbol
))
302 symbolS
*sym
= exp
->X_add_symbol
;
304 exp
->X_op
= O_subtract
;
305 exp
->X_add_symbol
= main_exp
->X_op_symbol
;
307 main_exp
->X_op_symbol
= main_exp
->X_add_symbol
;
308 main_exp
->X_add_symbol
= sym
;
310 main_exp
->X_add_number
+= exp
->X_add_number
;
311 exp
->X_add_number
= 0;
316 else if (exp
->X_op
== O_add
&& sh_PIC_related_p (exp
->X_op_symbol
))
319 if (exp
->X_op
== O_symbol
|| exp
->X_op
== O_add
|| exp
->X_op
== O_subtract
)
321 if (exp
->X_add_symbol
&& exp
->X_add_symbol
== GOT_symbol
)
323 *r_type_p
= BFD_RELOC_SH_GOTPC
;
326 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
331 if (exp
->X_op
== O_PIC_reloc
)
336 case BFD_RELOC_UNUSED
:
337 *r_type_p
= exp
->X_md
;
340 case BFD_RELOC_SH_DISP20
:
343 case BFD_RELOC_32_GOT_PCREL
:
344 *r_type_p
= BFD_RELOC_SH_GOT20
;
347 case BFD_RELOC_32_GOTOFF
:
348 *r_type_p
= BFD_RELOC_SH_GOTOFF20
;
351 case BFD_RELOC_SH_GOTFUNCDESC
:
352 *r_type_p
= BFD_RELOC_SH_GOTFUNCDESC20
;
355 case BFD_RELOC_SH_GOTOFFFUNCDESC
:
356 *r_type_p
= BFD_RELOC_SH_GOTOFFFUNCDESC20
;
368 exp
->X_op
= O_symbol
;
371 main_exp
->X_add_symbol
= exp
->X_add_symbol
;
372 main_exp
->X_add_number
+= exp
->X_add_number
;
376 return (sh_PIC_related_p (exp
->X_add_symbol
)
377 || sh_PIC_related_p (exp
->X_op_symbol
));
382 /* Add expression EXP of SIZE bytes to offset OFF of fragment FRAG. */
385 sh_cons_fix_new (fragS
*frag
, int off
, int size
, expressionS
*exp
,
386 bfd_reloc_code_real_type r_type
)
388 r_type
= BFD_RELOC_UNUSED
;
390 if (sh_check_fixup (exp
, &r_type
))
391 as_bad (_("Invalid PIC expression."));
393 if (r_type
== BFD_RELOC_UNUSED
)
397 r_type
= BFD_RELOC_8
;
401 r_type
= BFD_RELOC_16
;
405 r_type
= BFD_RELOC_32
;
409 r_type
= BFD_RELOC_64
;
418 as_bad (_("unsupported BFD relocation size %u"), size
);
419 r_type
= BFD_RELOC_UNUSED
;
422 fix_new_exp (frag
, off
, size
, exp
, 0, r_type
);
425 /* The regular cons() function, that reads constants, doesn't support
426 suffixes such as @GOT, @GOTOFF and @PLT, that generate
427 machine-specific relocation types. So we must define it here. */
428 /* Clobbers input_line_pointer, checks end-of-line. */
429 /* NBYTES 1=.byte, 2=.word, 4=.long */
431 sh_elf_cons (int nbytes
)
435 if (is_it_end_of_statement ())
437 demand_empty_rest_of_line ();
442 md_cons_align (nbytes
);
448 emit_expr (&exp
, (unsigned int) nbytes
);
450 while (*input_line_pointer
++ == ',');
452 input_line_pointer
--; /* Put terminator back into stream. */
453 if (*input_line_pointer
== '#' || *input_line_pointer
== '!')
455 while (! is_end_of_line
[(unsigned char) *input_line_pointer
++]);
458 demand_empty_rest_of_line ();
461 /* The regular frag_offset_fixed_p doesn't work for rs_align_test
465 align_test_frag_offset_fixed_p (const fragS
*frag1
, const fragS
*frag2
,
471 /* Start with offset initialised to difference between the two frags.
472 Prior to assigning frag addresses this will be zero. */
473 off
= frag1
->fr_address
- frag2
->fr_address
;
480 /* Maybe frag2 is after frag1. */
482 while (frag
->fr_type
== rs_fill
483 || frag
->fr_type
== rs_align_test
)
485 if (frag
->fr_type
== rs_fill
)
486 off
+= frag
->fr_fix
+ frag
->fr_offset
* frag
->fr_var
;
489 frag
= frag
->fr_next
;
499 /* Maybe frag1 is after frag2. */
500 off
= frag1
->fr_address
- frag2
->fr_address
;
502 while (frag
->fr_type
== rs_fill
503 || frag
->fr_type
== rs_align_test
)
505 if (frag
->fr_type
== rs_fill
)
506 off
-= frag
->fr_fix
+ frag
->fr_offset
* frag
->fr_var
;
509 frag
= frag
->fr_next
;
522 /* Optimize a difference of symbols which have rs_align_test frag if
526 sh_optimize_expr (expressionS
*l
, operatorT op
, expressionS
*r
)
531 && l
->X_op
== O_symbol
532 && r
->X_op
== O_symbol
533 && S_GET_SEGMENT (l
->X_add_symbol
) == S_GET_SEGMENT (r
->X_add_symbol
)
534 && (SEG_NORMAL (S_GET_SEGMENT (l
->X_add_symbol
))
535 || r
->X_add_symbol
== l
->X_add_symbol
)
536 && align_test_frag_offset_fixed_p (symbol_get_frag (l
->X_add_symbol
),
537 symbol_get_frag (r
->X_add_symbol
),
540 offsetT symval_diff
= S_GET_VALUE (l
->X_add_symbol
)
541 - S_GET_VALUE (r
->X_add_symbol
);
542 subtract_from_result (l
, r
->X_add_number
, r
->X_extrabit
);
543 subtract_from_result (l
, frag_off
/ OCTETS_PER_BYTE
, 0);
544 add_to_result (l
, symval_diff
, symval_diff
< 0);
545 l
->X_op
= O_constant
;
553 /* This function is called once, at assembler startup time. This should
554 set up all the tables, etc that the MD part of the assembler needs. */
559 const sh_opcode_info
*opcode
;
560 const char *prev_name
= "";
561 unsigned int target_arch
;
564 = preset_target_arch
? preset_target_arch
: arch_sh_up
& ~arch_sh_has_dsp
;
565 valid_arch
= target_arch
;
567 opcode_hash_control
= hash_new ();
569 /* Insert unique names into hash table. */
570 for (opcode
= sh_table
; opcode
->name
; opcode
++)
572 if (strcmp (prev_name
, opcode
->name
) != 0)
574 if (!SH_MERGE_ARCH_SET_VALID (opcode
->arch
, target_arch
))
576 prev_name
= opcode
->name
;
577 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
584 static int reg_x
, reg_y
;
588 #define IDENT_CHAR(c) (ISALNUM (c) || (c) == '_')
590 /* Try to parse a reg name. Return the number of chars consumed. */
593 parse_reg_without_prefix (char *src
, sh_arg_type
*mode
, int *reg
)
595 char l0
= TOLOWER (src
[0]);
596 char l1
= l0
? TOLOWER (src
[1]) : 0;
598 /* We use ! IDENT_CHAR for the next character after the register name, to
599 make sure that we won't accidentally recognize a symbol name such as
600 'sram' or sr_ram as being a reference to the register 'sr'. */
606 if (src
[2] >= '0' && src
[2] <= '5'
607 && ! IDENT_CHAR ((unsigned char) src
[3]))
610 *reg
= 10 + src
[2] - '0';
614 if (l1
>= '0' && l1
<= '9'
615 && ! IDENT_CHAR ((unsigned char) src
[2]))
621 if (l1
>= '0' && l1
<= '7' && strncasecmp (&src
[2], "_bank", 5) == 0
622 && ! IDENT_CHAR ((unsigned char) src
[7]))
629 if (l1
== 'e' && ! IDENT_CHAR ((unsigned char) src
[2]))
634 if (l1
== 's' && ! IDENT_CHAR ((unsigned char) src
[2]))
645 if (! IDENT_CHAR ((unsigned char) src
[2]))
651 if (TOLOWER (src
[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
660 if (! IDENT_CHAR ((unsigned char) src
[2]))
666 if (TOLOWER (src
[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
674 if (l1
== 'x' && src
[2] >= '0' && src
[2] <= '1'
675 && ! IDENT_CHAR ((unsigned char) src
[3]))
678 *reg
= 4 + (l1
- '0');
681 if (l1
== 'y' && src
[2] >= '0' && src
[2] <= '1'
682 && ! IDENT_CHAR ((unsigned char) src
[3]))
685 *reg
= 6 + (l1
- '0');
688 if (l1
== 's' && src
[2] >= '0' && src
[2] <= '3'
689 && ! IDENT_CHAR ((unsigned char) src
[3]))
694 *reg
= n
| ((~n
& 2) << 1);
699 if (l0
== 'i' && l1
&& ! IDENT_CHAR ((unsigned char) src
[2]))
721 if (l0
== 'x' && l1
>= '0' && l1
<= '1'
722 && ! IDENT_CHAR ((unsigned char) src
[2]))
725 *reg
= A_X0_NUM
+ l1
- '0';
729 if (l0
== 'y' && l1
>= '0' && l1
<= '1'
730 && ! IDENT_CHAR ((unsigned char) src
[2]))
733 *reg
= A_Y0_NUM
+ l1
- '0';
737 if (l0
== 'm' && l1
>= '0' && l1
<= '1'
738 && ! IDENT_CHAR ((unsigned char) src
[2]))
741 *reg
= l1
== '0' ? A_M0_NUM
: A_M1_NUM
;
747 && TOLOWER (src
[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src
[3]))
753 if (l0
== 's' && l1
== 'p' && TOLOWER (src
[2]) == 'c'
754 && ! IDENT_CHAR ((unsigned char) src
[3]))
760 if (l0
== 's' && l1
== 'g' && TOLOWER (src
[2]) == 'r'
761 && ! IDENT_CHAR ((unsigned char) src
[3]))
767 if (l0
== 'd' && l1
== 's' && TOLOWER (src
[2]) == 'r'
768 && ! IDENT_CHAR ((unsigned char) src
[3]))
774 if (l0
== 'd' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
775 && ! IDENT_CHAR ((unsigned char) src
[3]))
781 if (l0
== 's' && l1
== 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
787 if (l0
== 's' && l1
== 'p' && ! IDENT_CHAR ((unsigned char) src
[2]))
794 if (l0
== 'p' && l1
== 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
799 if (l0
== 'p' && l1
== 'c' && ! IDENT_CHAR ((unsigned char) src
[2]))
801 /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0'
802 and use an uninitialized immediate. */
806 if (l0
== 'g' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
807 && ! IDENT_CHAR ((unsigned char) src
[3]))
812 if (l0
== 'v' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
813 && ! IDENT_CHAR ((unsigned char) src
[3]))
819 if (l0
== 't' && l1
== 'b' && TOLOWER (src
[2]) == 'r'
820 && ! IDENT_CHAR ((unsigned char) src
[3]))
825 if (l0
== 'm' && l1
== 'a' && TOLOWER (src
[2]) == 'c'
826 && ! IDENT_CHAR ((unsigned char) src
[4]))
828 if (TOLOWER (src
[3]) == 'l')
833 if (TOLOWER (src
[3]) == 'h')
839 if (l0
== 'm' && l1
== 'o' && TOLOWER (src
[2]) == 'd'
840 && ! IDENT_CHAR ((unsigned char) src
[3]))
845 if (l0
== 'f' && l1
== 'r')
849 if (src
[3] >= '0' && src
[3] <= '5'
850 && ! IDENT_CHAR ((unsigned char) src
[4]))
853 *reg
= 10 + src
[3] - '0';
857 if (src
[2] >= '0' && src
[2] <= '9'
858 && ! IDENT_CHAR ((unsigned char) src
[3]))
861 *reg
= (src
[2] - '0');
865 if (l0
== 'd' && l1
== 'r')
869 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
870 && ! IDENT_CHAR ((unsigned char) src
[4]))
873 *reg
= 10 + src
[3] - '0';
877 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
878 && ! IDENT_CHAR ((unsigned char) src
[3]))
881 *reg
= (src
[2] - '0');
885 if (l0
== 'x' && l1
== 'd')
889 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
890 && ! IDENT_CHAR ((unsigned char) src
[4]))
893 *reg
= 11 + src
[3] - '0';
897 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
898 && ! IDENT_CHAR ((unsigned char) src
[3]))
901 *reg
= (src
[2] - '0') + 1;
905 if (l0
== 'f' && l1
== 'v')
907 if (src
[2] == '1'&& src
[3] == '2' && ! IDENT_CHAR ((unsigned char) src
[4]))
913 if ((src
[2] == '0' || src
[2] == '4' || src
[2] == '8')
914 && ! IDENT_CHAR ((unsigned char) src
[3]))
917 *reg
= (src
[2] - '0');
921 if (l0
== 'f' && l1
== 'p' && TOLOWER (src
[2]) == 'u'
922 && TOLOWER (src
[3]) == 'l'
923 && ! IDENT_CHAR ((unsigned char) src
[4]))
929 if (l0
== 'f' && l1
== 'p' && TOLOWER (src
[2]) == 's'
930 && TOLOWER (src
[3]) == 'c'
931 && TOLOWER (src
[4]) == 'r' && ! IDENT_CHAR ((unsigned char) src
[5]))
937 if (l0
== 'x' && l1
== 'm' && TOLOWER (src
[2]) == 't'
938 && TOLOWER (src
[3]) == 'r'
939 && TOLOWER (src
[4]) == 'x' && ! IDENT_CHAR ((unsigned char) src
[5]))
948 /* Like parse_reg_without_prefix, but this version supports
949 $-prefixed register names if enabled by the user. */
952 parse_reg (char *src
, sh_arg_type
*mode
, int *reg
)
955 unsigned int consumed
;
959 if (allow_dollar_register_prefix
)
970 consumed
= parse_reg_without_prefix (src
, mode
, reg
);
975 return consumed
+ prefix
;
979 parse_exp (char *s
, sh_operand_info
*op
)
984 save
= input_line_pointer
;
985 input_line_pointer
= s
;
986 expression (&op
->immediate
);
987 if (op
->immediate
.X_op
== O_absent
)
988 as_bad (_("missing operand"));
989 new_pointer
= input_line_pointer
;
990 input_line_pointer
= save
;
994 /* The many forms of operand:
997 @Rn Register indirect
1010 pr, gbr, vbr, macl, mach
1014 parse_at (char *src
, sh_operand_info
*op
)
1021 src
= parse_at (src
, op
);
1022 if (op
->type
== A_DISP_TBR
)
1023 op
->type
= A_DISP2_TBR
;
1025 as_bad (_("illegal double indirection"));
1027 else if (src
[0] == '-')
1029 /* Must be predecrement. */
1032 len
= parse_reg (src
, &mode
, &(op
->reg
));
1033 if (mode
!= A_REG_N
)
1034 as_bad (_("illegal register after @-"));
1039 else if (src
[0] == '(')
1041 /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
1044 len
= parse_reg (src
, &mode
, &(op
->reg
));
1045 if (len
&& mode
== A_REG_N
)
1050 as_bad (_("must be @(r0,...)"));
1055 /* Now can be rn or gbr. */
1056 len
= parse_reg (src
, &mode
, &(op
->reg
));
1066 op
->type
= A_R0_GBR
;
1068 else if (mode
== A_REG_N
)
1070 op
->type
= A_IND_R0_REG_N
;
1074 as_bad (_("syntax error in @(r0,...)"));
1079 as_bad (_("syntax error in @(r0...)"));
1084 /* Must be an @(disp,.. thing). */
1085 src
= parse_exp (src
, op
);
1088 /* Now can be rn, gbr or pc. */
1089 len
= parse_reg (src
, &mode
, &op
->reg
);
1092 if (mode
== A_REG_N
)
1094 op
->type
= A_DISP_REG_N
;
1096 else if (mode
== A_GBR
)
1098 op
->type
= A_DISP_GBR
;
1100 else if (mode
== A_TBR
)
1102 op
->type
= A_DISP_TBR
;
1104 else if (mode
== A_PC
)
1106 /* We want @(expr, pc) to uniformly address . + expr,
1107 no matter if expr is a constant, or a more complex
1108 expression, e.g. sym-. or sym1-sym2.
1109 However, we also used to accept @(sym,pc)
1110 as addressing sym, i.e. meaning the same as plain sym.
1111 Some existing code does use the @(sym,pc) syntax, so
1112 we give it the old semantics for now, but warn about
1113 its use, so that users have some time to fix their code.
1115 Note that due to this backward compatibility hack,
1116 we'll get unexpected results when @(offset, pc) is used,
1117 and offset is a symbol that is set later to an an address
1118 difference, or an external symbol that is set to an
1119 address difference in another source file, so we want to
1120 eventually remove it. */
1121 if (op
->immediate
.X_op
== O_symbol
)
1123 op
->type
= A_DISP_PC
;
1124 as_warn (_("Deprecated syntax."));
1128 op
->type
= A_DISP_PC_ABS
;
1129 /* Such operands don't get corrected for PC==.+4, so
1130 make the correction here. */
1131 op
->immediate
.X_add_number
-= 4;
1136 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
1141 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
1146 as_bad (_("expecting )"));
1152 src
+= parse_reg (src
, &mode
, &(op
->reg
));
1153 if (mode
!= A_REG_N
)
1154 as_bad (_("illegal register after @"));
1161 l0
= TOLOWER (src
[0]);
1162 l1
= TOLOWER (src
[1]);
1164 if ((l0
== 'r' && l1
== '8')
1165 || (l0
== 'i' && (l1
== 'x' || l1
== 's')))
1168 op
->type
= AX_PMOD_N
;
1170 else if ( (l0
== 'r' && l1
== '9')
1171 || (l0
== 'i' && l1
== 'y'))
1174 op
->type
= AY_PMOD_N
;
1186 get_operand (char **ptr
, sh_operand_info
*op
)
1189 sh_arg_type mode
= (sh_arg_type
) -1;
1195 *ptr
= parse_exp (src
, op
);
1200 else if (src
[0] == '@')
1202 *ptr
= parse_at (src
, op
);
1205 len
= parse_reg (src
, &mode
, &(op
->reg
));
1214 /* Not a reg, the only thing left is a displacement. */
1215 *ptr
= parse_exp (src
, op
);
1216 op
->type
= A_DISP_PC
;
1222 get_operands (sh_opcode_info
*info
, char *args
, sh_operand_info
*operand
)
1227 /* The pre-processor will eliminate whitespace in front of '@'
1228 after the first argument; we may be called multiple times
1229 from assemble_ppi, so don't insist on finding whitespace here. */
1233 get_operand (&ptr
, operand
+ 0);
1240 get_operand (&ptr
, operand
+ 1);
1241 /* ??? Hack: psha/pshl have a varying operand number depending on
1242 the type of the first operand. We handle this by having the
1243 three-operand version first and reducing the number of operands
1244 parsed to two if we see that the first operand is an immediate.
1245 This works because no insn with three operands has an immediate
1246 as first operand. */
1247 if (info
->arg
[2] && operand
[0].type
!= A_IMM
)
1253 get_operand (&ptr
, operand
+ 2);
1257 operand
[2].type
= 0;
1262 operand
[1].type
= 0;
1263 operand
[2].type
= 0;
1268 operand
[0].type
= 0;
1269 operand
[1].type
= 0;
1270 operand
[2].type
= 0;
1275 /* Passed a pointer to a list of opcodes which use different
1276 addressing modes, return the opcode which matches the opcodes
1279 static sh_opcode_info
*
1280 get_specific (sh_opcode_info
*opcode
, sh_operand_info
*operands
)
1282 sh_opcode_info
*this_try
= opcode
;
1283 const char *name
= opcode
->name
;
1286 while (opcode
->name
)
1288 this_try
= opcode
++;
1289 if ((this_try
->name
!= name
) && (strcmp (this_try
->name
, name
) != 0))
1291 /* We've looked so far down the table that we've run out of
1292 opcodes with the same name. */
1296 /* Look at both operands needed by the opcodes and provided by
1297 the user - since an arg test will often fail on the same arg
1298 again and again, we'll try and test the last failing arg the
1299 first on each opcode try. */
1300 for (n
= 0; this_try
->arg
[n
]; n
++)
1302 sh_operand_info
*user
= operands
+ n
;
1303 sh_arg_type arg
= this_try
->arg
[n
];
1308 if (user
->type
== A_DISP_PC_ABS
)
1319 if (user
->type
!= arg
)
1323 /* opcode needs r0 */
1324 if (user
->type
!= A_REG_N
|| user
->reg
!= 0)
1328 if (user
->type
!= A_R0_GBR
|| user
->reg
!= 0)
1332 if (user
->type
!= F_REG_N
|| user
->reg
!= 0)
1340 case A_IND_R0_REG_N
:
1349 /* Opcode needs rn */
1350 if (user
->type
!= arg
)
1355 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
1371 if (user
->type
!= arg
)
1376 if (user
->type
!= arg
)
1382 if (user
->type
!= A_INC_N
)
1384 if (user
->reg
!= 15)
1390 if (user
->type
!= A_DEC_N
)
1392 if (user
->reg
!= 15)
1401 case A_IND_R0_REG_M
:
1404 /* Opcode needs rn */
1405 if (user
->type
!= arg
- A_REG_M
+ A_REG_N
)
1411 if (user
->type
!= A_DEC_N
)
1413 if (user
->reg
< 2 || user
->reg
> 5)
1419 if (user
->type
!= A_INC_N
)
1421 if (user
->reg
< 2 || user
->reg
> 5)
1427 if (user
->type
!= A_IND_N
)
1429 if (user
->reg
< 2 || user
->reg
> 5)
1435 if (user
->type
!= AX_PMOD_N
)
1437 if (user
->reg
< 2 || user
->reg
> 5)
1443 if (user
->type
!= A_INC_N
)
1445 if (user
->reg
< 4 || user
->reg
> 5)
1451 if (user
->type
!= A_IND_N
)
1453 if (user
->reg
< 4 || user
->reg
> 5)
1459 if (user
->type
!= AX_PMOD_N
)
1461 if (user
->reg
< 4 || user
->reg
> 5)
1467 if (user
->type
!= A_INC_N
)
1469 if ((user
->reg
< 4 || user
->reg
> 5)
1470 && (user
->reg
< 0 || user
->reg
> 1))
1476 if (user
->type
!= A_IND_N
)
1478 if ((user
->reg
< 4 || user
->reg
> 5)
1479 && (user
->reg
< 0 || user
->reg
> 1))
1485 if (user
->type
!= AX_PMOD_N
)
1487 if ((user
->reg
< 4 || user
->reg
> 5)
1488 && (user
->reg
< 0 || user
->reg
> 1))
1494 if (user
->type
!= A_INC_N
)
1496 if (user
->reg
< 6 || user
->reg
> 7)
1502 if (user
->type
!= A_IND_N
)
1504 if (user
->reg
< 6 || user
->reg
> 7)
1510 if (user
->type
!= AY_PMOD_N
)
1512 if (user
->reg
< 6 || user
->reg
> 7)
1518 if (user
->type
!= A_INC_N
)
1520 if ((user
->reg
< 6 || user
->reg
> 7)
1521 && (user
->reg
< 2 || user
->reg
> 3))
1527 if (user
->type
!= A_IND_N
)
1529 if ((user
->reg
< 6 || user
->reg
> 7)
1530 && (user
->reg
< 2 || user
->reg
> 3))
1536 if (user
->type
!= AY_PMOD_N
)
1538 if ((user
->reg
< 6 || user
->reg
> 7)
1539 && (user
->reg
< 2 || user
->reg
> 3))
1545 if (user
->type
!= DSP_REG_N
)
1547 if (user
->reg
!= A_A0_NUM
1548 && user
->reg
!= A_A1_NUM
)
1554 if (user
->type
!= DSP_REG_N
)
1576 if (user
->type
!= DSP_REG_N
)
1598 if (user
->type
!= DSP_REG_N
)
1620 if (user
->type
!= DSP_REG_N
)
1642 if (user
->type
!= DSP_REG_N
)
1664 if (user
->type
!= DSP_REG_N
)
1686 if (user
->type
!= DSP_REG_N
)
1708 if (user
->type
!= DSP_REG_N
)
1730 if (user
->type
!= DSP_REG_N
)
1752 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_A0_NUM
)
1756 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X0_NUM
)
1760 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X1_NUM
)
1764 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y0_NUM
)
1768 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y1_NUM
)
1778 /* Opcode needs rn */
1779 if (user
->type
!= arg
- F_REG_M
+ F_REG_N
)
1784 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
1789 if (user
->type
!= XMTRX_M4
)
1795 printf (_("unhandled %d\n"), arg
);
1798 if (SH_MERGE_ARCH_SET_VALID (valid_arch
, arch_sh2a_nofpu_up
)
1799 && ( arg
== A_DISP_REG_M
1800 || arg
== A_DISP_REG_N
))
1802 /* Check a few key IMM* fields for overflow. */
1804 long val
= user
->immediate
.X_add_number
;
1806 for (opf
= 0; opf
< 4; opf
++)
1807 switch (this_try
->nibbles
[opf
])
1811 if (val
< 0 || val
> 15)
1816 if (val
< 0 || val
> 15 * 2)
1821 if (val
< 0 || val
> 15 * 4)
1829 if ( !SH_MERGE_ARCH_SET_VALID (valid_arch
, this_try
->arch
))
1831 valid_arch
= SH_MERGE_ARCH_SET (valid_arch
, this_try
->arch
);
1841 insert (char *where
, bfd_reloc_code_real_type how
, int pcrel
,
1842 sh_operand_info
*op
)
1844 fix_new_exp (frag_now
,
1845 where
- frag_now
->fr_literal
,
1853 insert4 (char * where
, bfd_reloc_code_real_type how
, int pcrel
,
1854 sh_operand_info
* op
)
1856 fix_new_exp (frag_now
,
1857 where
- frag_now
->fr_literal
,
1864 build_relax (sh_opcode_info
*opcode
, sh_operand_info
*op
)
1866 int high_byte
= target_big_endian
? 0 : 1;
1869 if (opcode
->arg
[0] == A_BDISP8
)
1871 int what
= (opcode
->nibbles
[1] & 4) ? COND_JUMP_DELAY
: COND_JUMP
;
1872 p
= frag_var (rs_machine_dependent
,
1873 md_relax_table
[C (what
, COND32
)].rlx_length
,
1874 md_relax_table
[C (what
, COND8
)].rlx_length
,
1876 op
->immediate
.X_add_symbol
,
1877 op
->immediate
.X_add_number
,
1879 p
[high_byte
] = (opcode
->nibbles
[0] << 4) | (opcode
->nibbles
[1]);
1881 else if (opcode
->arg
[0] == A_BDISP12
)
1883 p
= frag_var (rs_machine_dependent
,
1884 md_relax_table
[C (UNCOND_JUMP
, UNCOND32
)].rlx_length
,
1885 md_relax_table
[C (UNCOND_JUMP
, UNCOND12
)].rlx_length
,
1887 op
->immediate
.X_add_symbol
,
1888 op
->immediate
.X_add_number
,
1890 p
[high_byte
] = (opcode
->nibbles
[0] << 4);
1895 /* Insert ldrs & ldre with fancy relocations that relaxation can recognize. */
1898 insert_loop_bounds (char *output
, sh_operand_info
*operand
)
1902 /* Since the low byte of the opcode will be overwritten by the reloc, we
1903 can just stash the high byte into both bytes and ignore endianness. */
1906 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
1907 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
1911 static int count
= 0;
1913 expressionS
*symval
;
1915 /* If the last loop insn is a two-byte-insn, it is in danger of being
1916 swapped with the insn after it. To prevent this, create a new
1917 symbol - complete with SH_LABEL reloc - after the last loop insn.
1918 If the last loop insn is four bytes long, the symbol will be
1919 right in the middle, but four byte insns are not swapped anyways. */
1920 /* A REPEAT takes 6 bytes. The SH has a 32 bit address space.
1921 Hence a 9 digit number should be enough to count all REPEATs. */
1922 sprintf (name
, "_R%x", count
++ & 0x3fffffff);
1923 end_sym
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1924 /* Make this a local symbol. */
1926 SF_SET_LOCAL (end_sym
);
1927 #endif /* OBJ_COFF */
1928 symbol_table_insert (end_sym
);
1929 symval
= symbol_get_value_expression (end_sym
);
1930 *symval
= operand
[1].immediate
;
1931 symval
->X_add_number
+= 2;
1932 fix_new (frag_now
, frag_now_fix (), 2, end_sym
, 0, 1, BFD_RELOC_SH_LABEL
);
1935 output
= frag_more (2);
1938 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
1939 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
1941 return frag_more (2);
1944 /* Now we know what sort of opcodes it is, let's build the bytes. */
1947 build_Mytes (sh_opcode_info
*opcode
, sh_operand_info
*operand
)
1952 unsigned int size
= 2;
1953 int low_byte
= target_big_endian
? 1 : 0;
1955 bfd_reloc_code_real_type r_type
;
1957 int unhandled_pic
= 0;
1970 for (indx
= 0; indx
< 3; indx
++)
1971 if (opcode
->arg
[indx
] == A_IMM
1972 && operand
[indx
].type
== A_IMM
1973 && (operand
[indx
].immediate
.X_op
== O_PIC_reloc
1974 || sh_PIC_related_p (operand
[indx
].immediate
.X_add_symbol
)
1975 || sh_PIC_related_p (operand
[indx
].immediate
.X_op_symbol
)))
1979 if (SH_MERGE_ARCH_SET (opcode
->arch
, arch_op32
))
1981 output
= frag_more (4);
1986 output
= frag_more (2);
1988 for (indx
= 0; indx
< max_index
; indx
++)
1990 sh_nibble_type i
= opcode
->nibbles
[indx
];
2007 if (reg_n
< 2 || reg_n
> 5)
2008 as_bad (_("Invalid register: 'r%d'"), reg_n
);
2009 nbuf
[indx
] = (reg_n
& 3) | 4;
2012 nbuf
[indx
] = reg_n
| (reg_m
>> 2);
2015 nbuf
[indx
] = reg_b
| 0x08;
2018 nbuf
[indx
] = reg_n
| 0x01;
2024 insert (output
+ low_byte
, BFD_RELOC_SH_IMM3
, 0, operand
);
2030 insert (output
+ low_byte
, BFD_RELOC_SH_IMM3U
, 0, operand
);
2033 insert (output
+ 2, BFD_RELOC_SH_DISP12
, 0, operand
);
2036 insert (output
+ 2, BFD_RELOC_SH_DISP12BY2
, 0, operand
);
2039 insert (output
+ 2, BFD_RELOC_SH_DISP12BY4
, 0, operand
);
2042 insert (output
+ 2, BFD_RELOC_SH_DISP12BY8
, 0, operand
);
2045 insert (output
+ 2, BFD_RELOC_SH_DISP12
, 0, operand
+1);
2048 insert (output
+ 2, BFD_RELOC_SH_DISP12BY2
, 0, operand
+1);
2051 insert (output
+ 2, BFD_RELOC_SH_DISP12BY4
, 0, operand
+1);
2054 insert (output
+ 2, BFD_RELOC_SH_DISP12BY8
, 0, operand
+1);
2059 r_type
= BFD_RELOC_SH_DISP20
;
2061 if (sh_check_fixup (&operand
->immediate
, &r_type
))
2062 as_bad (_("Invalid PIC expression."));
2065 insert4 (output
, r_type
, 0, operand
);
2068 insert4 (output
, BFD_RELOC_SH_DISP20BY8
, 0, operand
);
2071 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
);
2074 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
);
2077 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
);
2080 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
+ 1);
2083 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
+ 1);
2086 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
+ 1);
2089 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
);
2092 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
);
2096 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
);
2099 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
+ 1);
2102 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
+ 1);
2105 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
+ 1);
2108 insert (output
, BFD_RELOC_SH_PCRELIMM8BY4
,
2109 operand
->type
!= A_DISP_PC_ABS
, operand
);
2112 insert (output
, BFD_RELOC_SH_PCRELIMM8BY2
,
2113 operand
->type
!= A_DISP_PC_ABS
, operand
);
2116 output
= insert_loop_bounds (output
, operand
);
2117 nbuf
[indx
] = opcode
->nibbles
[3];
2121 printf (_("failed for %d\n"), i
);
2127 as_bad (_("misplaced PIC operand"));
2129 if (!target_big_endian
)
2131 output
[1] = (nbuf
[0] << 4) | (nbuf
[1]);
2132 output
[0] = (nbuf
[2] << 4) | (nbuf
[3]);
2136 output
[0] = (nbuf
[0] << 4) | (nbuf
[1]);
2137 output
[1] = (nbuf
[2] << 4) | (nbuf
[3]);
2139 if (SH_MERGE_ARCH_SET (opcode
->arch
, arch_op32
))
2141 if (!target_big_endian
)
2143 output
[3] = (nbuf
[4] << 4) | (nbuf
[5]);
2144 output
[2] = (nbuf
[6] << 4) | (nbuf
[7]);
2148 output
[2] = (nbuf
[4] << 4) | (nbuf
[5]);
2149 output
[3] = (nbuf
[6] << 4) | (nbuf
[7]);
2155 /* Find an opcode at the start of *STR_P in the hash table, and set
2156 *STR_P to the first character after the last one read. */
2158 static sh_opcode_info
*
2159 find_cooked_opcode (char **str_p
)
2162 unsigned char *op_start
;
2163 unsigned char *op_end
;
2165 unsigned int nlen
= 0;
2167 /* Drop leading whitespace. */
2171 /* Find the op code end.
2172 The pre-processor will eliminate whitespace in front of
2173 any '@' after the first argument; we may be called from
2174 assemble_ppi, so the opcode might be terminated by an '@'. */
2175 for (op_start
= op_end
= (unsigned char *) str
;
2177 && nlen
< sizeof (name
) - 1
2178 && !is_end_of_line
[*op_end
] && *op_end
!= ' ' && *op_end
!= '@';
2181 unsigned char c
= op_start
[nlen
];
2183 /* The machine independent code will convert CMP/EQ into cmp/EQ
2184 because it thinks the '/' is the end of the symbol. Moreover,
2185 all but the first sub-insn is a parallel processing insn won't
2186 be capitalized. Instead of hacking up the machine independent
2187 code, we just deal with it here. */
2194 *str_p
= (char *) op_end
;
2197 as_bad (_("can't find opcode "));
2199 return (sh_opcode_info
*) hash_find (opcode_hash_control
, name
);
2202 /* Assemble a parallel processing insn. */
2203 #define DDT_BASE 0xf000 /* Base value for double data transfer insns */
2206 assemble_ppi (char *op_end
, sh_opcode_info
*opcode
)
2218 sh_operand_info operand
[3];
2220 /* Some insn ignore one or more register fields, e.g. psts machl,a0.
2221 Make sure we encode a defined insn pattern. */
2226 if (opcode
->arg
[0] != A_END
)
2227 op_end
= get_operands (opcode
, op_end
, operand
);
2229 opcode
= get_specific (opcode
, operand
);
2232 /* Couldn't find an opcode which matched the operands. */
2233 char *where
= frag_more (2);
2238 as_bad (_("invalid operands for opcode"));
2242 if (opcode
->nibbles
[0] != PPI
)
2243 as_bad (_("insn can't be combined with parallel processing insn"));
2245 switch (opcode
->nibbles
[1])
2250 as_bad (_("multiple movx specifications"));
2255 as_bad (_("multiple movy specifications"));
2261 as_bad (_("multiple movx specifications"));
2262 if ((reg_n
< 4 || reg_n
> 5)
2263 && (reg_n
< 0 || reg_n
> 1))
2264 as_bad (_("invalid movx address register"));
2265 if (movy
&& movy
!= DDT_BASE
)
2266 as_bad (_("insn cannot be combined with non-nopy"));
2267 movx
= ((((reg_n
& 1) != 0) << 9)
2268 + (((reg_n
& 4) == 0) << 8)
2270 + (opcode
->nibbles
[2] << 4)
2271 + opcode
->nibbles
[3]
2277 as_bad (_("multiple movy specifications"));
2278 if ((reg_n
< 6 || reg_n
> 7)
2279 && (reg_n
< 2 || reg_n
> 3))
2280 as_bad (_("invalid movy address register"));
2281 if (movx
&& movx
!= DDT_BASE
)
2282 as_bad (_("insn cannot be combined with non-nopx"));
2283 movy
= ((((reg_n
& 1) != 0) << 8)
2284 + (((reg_n
& 4) == 0) << 9)
2286 + (opcode
->nibbles
[2] << 4)
2287 + opcode
->nibbles
[3]
2293 as_bad (_("multiple movx specifications"));
2295 as_bad (_("previous movy requires nopx"));
2296 if (reg_n
< 4 || reg_n
> 5)
2297 as_bad (_("invalid movx address register"));
2298 if (opcode
->nibbles
[2] & 8)
2300 if (reg_m
== A_A1_NUM
)
2302 else if (reg_m
!= A_A0_NUM
)
2303 as_bad (_("invalid movx dsp register"));
2308 as_bad (_("invalid movx dsp register"));
2311 movx
+= ((reg_n
- 4) << 9) + (opcode
->nibbles
[2] << 2) + DDT_BASE
;
2316 as_bad (_("multiple movy specifications"));
2318 as_bad (_("previous movx requires nopy"));
2319 if (opcode
->nibbles
[2] & 8)
2321 /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode,
2324 if (reg_m
== A_A1_NUM
)
2326 else if (reg_m
!= A_A0_NUM
)
2327 as_bad (_("invalid movy dsp register"));
2332 as_bad (_("invalid movy dsp register"));
2335 if (reg_n
< 6 || reg_n
> 7)
2336 as_bad (_("invalid movy address register"));
2337 movy
+= ((reg_n
- 6) << 8) + opcode
->nibbles
[2] + DDT_BASE
;
2341 if (operand
[0].immediate
.X_op
!= O_constant
)
2342 as_bad (_("dsp immediate shift value not constant"));
2343 field_b
= ((opcode
->nibbles
[2] << 12)
2344 | (operand
[0].immediate
.X_add_number
& 127) << 4
2351 goto try_another_opcode
;
2356 as_bad (_("multiple parallel processing specifications"));
2357 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
2358 + (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
2359 switch (opcode
->nibbles
[4])
2367 field_b
+= opcode
->nibbles
[4] << 4;
2375 as_bad (_("multiple condition specifications"));
2376 cond
= opcode
->nibbles
[2] << 8;
2378 goto skip_cond_check
;
2382 as_bad (_("multiple parallel processing specifications"));
2383 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
2384 + cond
+ (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
2386 switch (opcode
->nibbles
[4])
2394 field_b
+= opcode
->nibbles
[4] << 4;
2403 if ((field_b
& 0xef00) == 0xa100)
2405 /* pclr Dz pmuls Se,Sf,Dg */
2406 else if ((field_b
& 0xff00) == 0x8d00
2407 && (SH_MERGE_ARCH_SET_VALID (valid_arch
, arch_sh4al_dsp_up
)))
2409 valid_arch
= SH_MERGE_ARCH_SET (valid_arch
, arch_sh4al_dsp_up
);
2413 as_bad (_("insn cannot be combined with pmuls"));
2414 switch (field_b
& 0xf)
2417 field_b
+= 0 - A_X0_NUM
;
2420 field_b
+= 1 - A_Y0_NUM
;
2423 field_b
+= 2 - A_A0_NUM
;
2426 field_b
+= 3 - A_A1_NUM
;
2429 as_bad (_("bad combined pmuls output operand"));
2431 /* Generate warning if the destination register for padd / psub
2432 and pmuls is the same ( only for A0 or A1 ).
2433 If the last nibble is 1010 then A0 is used in both
2434 padd / psub and pmuls. If it is 1111 then A1 is used
2435 as destination register in both padd / psub and pmuls. */
2437 if ((((field_b
| reg_efg
) & 0x000F) == 0x000A)
2438 || (((field_b
| reg_efg
) & 0x000F) == 0x000F))
2439 as_warn (_("destination register is same for parallel insns"));
2441 field_b
+= 0x4000 + reg_efg
;
2448 as_bad (_("condition not followed by conditionalizable insn"));
2454 opcode
= find_cooked_opcode (&op_end
);
2458 (_("unrecognized characters at end of parallel processing insn")));
2463 move_code
= movx
| movy
;
2466 /* Parallel processing insn. */
2467 unsigned long ppi_code
= (movx
| movy
| 0xf800) << 16 | field_b
;
2469 output
= frag_more (4);
2471 if (! target_big_endian
)
2473 output
[3] = ppi_code
>> 8;
2474 output
[2] = ppi_code
;
2478 output
[2] = ppi_code
>> 8;
2479 output
[3] = ppi_code
;
2481 move_code
|= 0xf800;
2485 /* Just a double data transfer. */
2486 output
= frag_more (2);
2489 if (! target_big_endian
)
2491 output
[1] = move_code
>> 8;
2492 output
[0] = move_code
;
2496 output
[0] = move_code
>> 8;
2497 output
[1] = move_code
;
2502 /* This is the guts of the machine-dependent assembler. STR points to a
2503 machine dependent instruction. This function is supposed to emit
2504 the frags/bytes it assembles to. */
2507 md_assemble (char *str
)
2510 sh_operand_info operand
[3];
2511 sh_opcode_info
*opcode
;
2512 unsigned int size
= 0;
2513 char *initial_str
= str
;
2515 opcode
= find_cooked_opcode (&str
);
2520 /* The opcode is not in the hash table.
2521 This means we definitely have an assembly failure,
2522 but the instruction may be valid in another CPU variant.
2523 In this case emit something better than 'unknown opcode'.
2524 Search the full table in sh-opc.h to check. */
2526 char *name
= initial_str
;
2527 int name_length
= 0;
2528 const sh_opcode_info
*op
;
2529 bfd_boolean found
= FALSE
;
2531 /* Identify opcode in string. */
2532 while (ISSPACE (*name
))
2535 while (name
[name_length
] != '\0' && !ISSPACE (name
[name_length
]))
2538 /* Search for opcode in full list. */
2539 for (op
= sh_table
; op
->name
; op
++)
2541 if (strncasecmp (op
->name
, name
, name_length
) == 0
2542 && op
->name
[name_length
] == '\0')
2550 as_bad (_("opcode not valid for this cpu variant"));
2552 as_bad (_("unknown opcode"));
2558 && ! seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2560 /* Output a CODE reloc to tell the linker that the following
2561 bytes are instructions, not data. */
2562 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
2564 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 1;
2567 if (opcode
->nibbles
[0] == PPI
)
2569 size
= assemble_ppi (op_end
, opcode
);
2573 if (opcode
->arg
[0] == A_BDISP12
2574 || opcode
->arg
[0] == A_BDISP8
)
2576 /* Since we skip get_specific here, we have to check & update
2578 if (SH_MERGE_ARCH_SET_VALID (valid_arch
, opcode
->arch
))
2579 valid_arch
= SH_MERGE_ARCH_SET (valid_arch
, opcode
->arch
);
2581 as_bad (_("Delayed branches not available on SH1"));
2582 parse_exp (op_end
+ 1, &operand
[0]);
2583 build_relax (opcode
, &operand
[0]);
2585 /* All branches are currently 16 bit. */
2590 if (opcode
->arg
[0] == A_END
)
2592 /* Ignore trailing whitespace. If there is any, it has already
2593 been compressed to a single space. */
2599 op_end
= get_operands (opcode
, op_end
, operand
);
2601 opcode
= get_specific (opcode
, operand
);
2605 /* Couldn't find an opcode which matched the operands. */
2606 char *where
= frag_more (2);
2611 as_bad (_("invalid operands for opcode"));
2616 as_bad (_("excess operands: '%s'"), op_end
);
2618 size
= build_Mytes (opcode
, operand
);
2623 dwarf2_emit_insn (size
);
2626 /* This routine is called each time a label definition is seen. It
2627 emits a BFD_RELOC_SH_LABEL reloc if necessary. */
2630 sh_frob_label (symbolS
*sym
)
2632 static fragS
*last_label_frag
;
2633 static int last_label_offset
;
2636 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2640 offset
= frag_now_fix ();
2641 if (frag_now
!= last_label_frag
2642 || offset
!= last_label_offset
)
2644 fix_new (frag_now
, offset
, 2, &abs_symbol
, 0, 0, BFD_RELOC_SH_LABEL
);
2645 last_label_frag
= frag_now
;
2646 last_label_offset
= offset
;
2650 dwarf2_emit_label (sym
);
2653 /* This routine is called when the assembler is about to output some
2654 data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */
2657 sh_flush_pending_output (void)
2660 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
2662 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
2664 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 0;
2669 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
2674 /* Various routines to kill one day. */
2677 md_atof (int type
, char *litP
, int *sizeP
)
2679 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
2682 /* Handle the .uses pseudo-op. This pseudo-op is used just before a
2683 call instruction. It refers to a label of the instruction which
2684 loads the register which the call uses. We use it to generate a
2685 special reloc for the linker. */
2688 s_uses (int ignore ATTRIBUTE_UNUSED
)
2693 as_warn (_(".uses pseudo-op seen when not relaxing"));
2697 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
2699 as_bad (_("bad .uses format"));
2700 ignore_rest_of_line ();
2704 fix_new_exp (frag_now
, frag_now_fix (), 2, &ex
, 1, BFD_RELOC_SH_USES
);
2706 demand_empty_rest_of_line ();
2711 OPTION_RELAX
= OPTION_MD_BASE
,
2718 OPTION_ALLOW_REG_PREFIX
,
2723 OPTION_DUMMY
/* Not used. This is just here to make it easy to add and subtract options from this enum. */
2726 const char *md_shortopts
= "";
2727 struct option md_longopts
[] =
2729 {"relax", no_argument
, NULL
, OPTION_RELAX
},
2730 {"big", no_argument
, NULL
, OPTION_BIG
},
2731 {"little", no_argument
, NULL
, OPTION_LITTLE
},
2732 /* The next two switches are here because the
2733 generic parts of the linker testsuite uses them. */
2734 {"EB", no_argument
, NULL
, OPTION_BIG
},
2735 {"EL", no_argument
, NULL
, OPTION_LITTLE
},
2736 {"small", no_argument
, NULL
, OPTION_SMALL
},
2737 {"dsp", no_argument
, NULL
, OPTION_DSP
},
2738 {"isa", required_argument
, NULL
, OPTION_ISA
},
2739 {"renesas", no_argument
, NULL
, OPTION_RENESAS
},
2740 {"allow-reg-prefix", no_argument
, NULL
, OPTION_ALLOW_REG_PREFIX
},
2742 { "h-tick-hex", no_argument
, NULL
, OPTION_H_TICK_HEX
},
2745 {"fdpic", no_argument
, NULL
, OPTION_FDPIC
},
2748 {NULL
, no_argument
, NULL
, 0}
2750 size_t md_longopts_size
= sizeof (md_longopts
);
2753 md_parse_option (int c
, const char *arg ATTRIBUTE_UNUSED
)
2762 target_big_endian
= 1;
2766 target_big_endian
= 0;
2774 preset_target_arch
= arch_sh_up
& ~(arch_sh_sp_fpu
|arch_sh_dp_fpu
);
2777 case OPTION_RENESAS
:
2778 dont_adjust_reloc_32
= 1;
2781 case OPTION_ALLOW_REG_PREFIX
:
2782 allow_dollar_register_prefix
= 1;
2786 if (strcasecmp (arg
, "dsp") == 0)
2787 preset_target_arch
= arch_sh_up
& ~(arch_sh_sp_fpu
|arch_sh_dp_fpu
);
2788 else if (strcasecmp (arg
, "fp") == 0)
2789 preset_target_arch
= arch_sh_up
& ~arch_sh_has_dsp
;
2790 else if (strcasecmp (arg
, "any") == 0)
2791 preset_target_arch
= arch_sh_up
;
2794 extern const bfd_arch_info_type bfd_sh_arch
;
2795 bfd_arch_info_type
const *bfd_arch
= &bfd_sh_arch
;
2797 preset_target_arch
= 0;
2798 for (; bfd_arch
; bfd_arch
=bfd_arch
->next
)
2800 int len
= strlen(bfd_arch
->printable_name
);
2802 if (strncasecmp (bfd_arch
->printable_name
, arg
, len
) != 0)
2805 if (arg
[len
] == '\0')
2806 preset_target_arch
=
2807 sh_get_arch_from_bfd_mach (bfd_arch
->mach
);
2808 else if (strcasecmp(&arg
[len
], "-up") == 0)
2809 preset_target_arch
=
2810 sh_get_arch_up_from_bfd_mach (bfd_arch
->mach
);
2816 if (!preset_target_arch
)
2817 as_bad (_("Invalid argument to --isa option: %s"), arg
);
2821 case OPTION_H_TICK_HEX
:
2822 enable_h_tick_hex
= 1;
2829 #endif /* OBJ_ELF */
2839 md_show_usage (FILE *stream
)
2841 fprintf (stream
, _("\
2843 --little generate little endian code\n\
2844 --big generate big endian code\n\
2845 --relax alter jump instructions for long displacements\n\
2846 --renesas disable optimization with section symbol for\n\
2847 compatibility with Renesas assembler.\n\
2848 --small align sections to 4 byte boundaries, not 16\n\
2849 --dsp enable sh-dsp insns, and disable floating-point ISAs.\n\
2850 --allow-reg-prefix allow '$' as a register name prefix.\n\
2851 --isa=[any use most appropriate isa\n\
2852 | dsp same as '-dsp'\n\
2855 extern const bfd_arch_info_type bfd_sh_arch
;
2856 bfd_arch_info_type
const *bfd_arch
= &bfd_sh_arch
;
2858 for (; bfd_arch
; bfd_arch
=bfd_arch
->next
)
2860 fprintf (stream
, "\n | %s", bfd_arch
->printable_name
);
2861 fprintf (stream
, "\n | %s-up", bfd_arch
->printable_name
);
2864 fprintf (stream
, "]\n");
2866 fprintf (stream
, _("\
2867 --fdpic generate an FDPIC object file\n"));
2868 #endif /* OBJ_ELF */
2871 /* This struct is used to pass arguments to sh_count_relocs through
2872 bfd_map_over_sections. */
2874 struct sh_count_relocs
2876 /* Symbol we are looking for. */
2878 /* Count of relocs found. */
2882 /* Count the number of fixups in a section which refer to a particular
2883 symbol. This is called via bfd_map_over_sections. */
2886 sh_count_relocs (bfd
*abfd ATTRIBUTE_UNUSED
, segT sec
, void *data
)
2888 struct sh_count_relocs
*info
= (struct sh_count_relocs
*) data
;
2889 segment_info_type
*seginfo
;
2893 seginfo
= seg_info (sec
);
2894 if (seginfo
== NULL
)
2898 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
2900 if (fix
->fx_addsy
== sym
)
2908 /* Handle the count relocs for a particular section.
2909 This is called via bfd_map_over_sections. */
2912 sh_frob_section (bfd
*abfd ATTRIBUTE_UNUSED
, segT sec
,
2913 void *ignore ATTRIBUTE_UNUSED
)
2915 segment_info_type
*seginfo
;
2918 seginfo
= seg_info (sec
);
2919 if (seginfo
== NULL
)
2922 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
2927 struct sh_count_relocs info
;
2929 if (fix
->fx_r_type
!= BFD_RELOC_SH_USES
)
2932 /* The BFD_RELOC_SH_USES reloc should refer to a defined local
2933 symbol in the same section. */
2934 sym
= fix
->fx_addsy
;
2936 || fix
->fx_subsy
!= NULL
2937 || fix
->fx_addnumber
!= 0
2938 || S_GET_SEGMENT (sym
) != sec
2939 || S_IS_EXTERNAL (sym
))
2941 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2942 _(".uses does not refer to a local symbol in the same section"));
2946 /* Look through the fixups again, this time looking for one
2947 at the same location as sym. */
2948 val
= S_GET_VALUE (sym
);
2949 for (fscan
= seginfo
->fix_root
;
2951 fscan
= fscan
->fx_next
)
2952 if (val
== fscan
->fx_frag
->fr_address
+ fscan
->fx_where
2953 && fscan
->fx_r_type
!= BFD_RELOC_SH_ALIGN
2954 && fscan
->fx_r_type
!= BFD_RELOC_SH_CODE
2955 && fscan
->fx_r_type
!= BFD_RELOC_SH_DATA
2956 && fscan
->fx_r_type
!= BFD_RELOC_SH_LABEL
)
2960 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2961 _("can't find fixup pointed to by .uses"));
2965 if (fscan
->fx_tcbit
)
2967 /* We've already done this one. */
2971 /* The variable fscan should also be a fixup to a local symbol
2972 in the same section. */
2973 sym
= fscan
->fx_addsy
;
2975 || fscan
->fx_subsy
!= NULL
2976 || fscan
->fx_addnumber
!= 0
2977 || S_GET_SEGMENT (sym
) != sec
2978 || S_IS_EXTERNAL (sym
))
2980 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2981 _(".uses target does not refer to a local symbol in the same section"));
2985 /* Now we look through all the fixups of all the sections,
2986 counting the number of times we find a reference to sym. */
2989 bfd_map_over_sections (stdoutput
, sh_count_relocs
, &info
);
2994 /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym.
2995 We have already adjusted the value of sym to include the
2996 fragment address, so we undo that adjustment here. */
2997 subseg_change (sec
, 0);
2998 fix_new (fscan
->fx_frag
,
2999 S_GET_VALUE (sym
) - fscan
->fx_frag
->fr_address
,
3000 4, &abs_symbol
, info
.count
, 0, BFD_RELOC_SH_COUNT
);
3004 /* This function is called after the symbol table has been completed,
3005 but before the relocs or section contents have been written out.
3006 If we have seen any .uses pseudo-ops, they point to an instruction
3007 which loads a register with the address of a function. We look
3008 through the fixups to find where the function address is being
3009 loaded from. We then generate a COUNT reloc giving the number of
3010 times that function address is referred to. The linker uses this
3011 information when doing relaxing, to decide when it can eliminate
3012 the stored function address entirely. */
3020 bfd_map_over_sections (stdoutput
, sh_frob_section
, NULL
);
3023 /* Called after relaxing. Set the correct sizes of the fragments, and
3024 create relocs so that md_apply_fix will fill in the correct values. */
3027 md_convert_frag (bfd
*headers ATTRIBUTE_UNUSED
, segT seg
, fragS
*fragP
)
3031 switch (fragP
->fr_subtype
)
3033 case C (COND_JUMP
, COND8
):
3034 case C (COND_JUMP_DELAY
, COND8
):
3035 subseg_change (seg
, 0);
3036 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
3037 1, BFD_RELOC_SH_PCDISP8BY2
);
3042 case C (UNCOND_JUMP
, UNCOND12
):
3043 subseg_change (seg
, 0);
3044 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
3045 1, BFD_RELOC_SH_PCDISP12BY2
);
3050 case C (UNCOND_JUMP
, UNCOND32
):
3051 case C (UNCOND_JUMP
, UNDEF_WORD_DISP
):
3052 if (fragP
->fr_symbol
== NULL
)
3053 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3054 _("displacement overflows 12-bit field"));
3055 else if (S_IS_DEFINED (fragP
->fr_symbol
))
3056 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3057 _("displacement to defined symbol %s overflows 12-bit field"),
3058 S_GET_NAME (fragP
->fr_symbol
));
3060 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3061 _("displacement to undefined symbol %s overflows 12-bit field"),
3062 S_GET_NAME (fragP
->fr_symbol
));
3063 /* Stabilize this frag, so we don't trip an assert. */
3064 fragP
->fr_fix
+= fragP
->fr_var
;
3068 case C (COND_JUMP
, COND12
):
3069 case C (COND_JUMP_DELAY
, COND12
):
3070 /* A bcond won't fit, so turn it into a b!cond; bra disp; nop. */
3071 /* I found that a relax failure for gcc.c-torture/execute/930628-1.c
3072 was due to gas incorrectly relaxing an out-of-range conditional
3073 branch with delay slot. It turned:
3074 bf.s L6 (slot mov.l r12,@(44,r0))
3077 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6)
3079 32: 10 cb mov.l r12,@(44,r0)
3080 Therefore, branches with delay slots have to be handled
3081 differently from ones without delay slots. */
3083 unsigned char *buffer
=
3084 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
3085 int highbyte
= target_big_endian
? 0 : 1;
3086 int lowbyte
= target_big_endian
? 1 : 0;
3087 int delay
= fragP
->fr_subtype
== C (COND_JUMP_DELAY
, COND12
);
3089 /* Toggle the true/false bit of the bcond. */
3090 buffer
[highbyte
] ^= 0x2;
3092 /* If this is a delayed branch, we may not put the bra in the
3093 slot. So we change it to a non-delayed branch, like that:
3094 b! cond slot_label; bra disp; slot_label: slot_insn
3095 ??? We should try if swapping the conditional branch and
3096 its delay-slot insn already makes the branch reach. */
3098 /* Build a relocation to six / four bytes farther on. */
3099 subseg_change (seg
, 0);
3100 fix_new (fragP
, fragP
->fr_fix
, 2, section_symbol (seg
),
3101 fragP
->fr_address
+ fragP
->fr_fix
+ (delay
? 4 : 6),
3102 1, BFD_RELOC_SH_PCDISP8BY2
);
3104 /* Set up a jump instruction. */
3105 buffer
[highbyte
+ 2] = 0xa0;
3106 buffer
[lowbyte
+ 2] = 0;
3107 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
3108 fragP
->fr_offset
, 1, BFD_RELOC_SH_PCDISP12BY2
);
3112 buffer
[highbyte
] &= ~0x4; /* Removes delay slot from branch. */
3117 /* Fill in a NOP instruction. */
3118 buffer
[highbyte
+ 4] = 0x0;
3119 buffer
[lowbyte
+ 4] = 0x9;
3128 case C (COND_JUMP
, COND32
):
3129 case C (COND_JUMP_DELAY
, COND32
):
3130 case C (COND_JUMP
, UNDEF_WORD_DISP
):
3131 case C (COND_JUMP_DELAY
, UNDEF_WORD_DISP
):
3132 if (fragP
->fr_symbol
== NULL
)
3133 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3134 _("displacement overflows 8-bit field"));
3135 else if (S_IS_DEFINED (fragP
->fr_symbol
))
3136 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3137 _("displacement to defined symbol %s overflows 8-bit field"),
3138 S_GET_NAME (fragP
->fr_symbol
));
3140 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3141 _("displacement to undefined symbol %s overflows 8-bit field "),
3142 S_GET_NAME (fragP
->fr_symbol
));
3143 /* Stabilize this frag, so we don't trip an assert. */
3144 fragP
->fr_fix
+= fragP
->fr_var
;
3152 if (donerelax
&& !sh_relax
)
3153 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
3154 _("overflow in branch to %s; converted into longer instruction sequence"),
3155 (fragP
->fr_symbol
!= NULL
3156 ? S_GET_NAME (fragP
->fr_symbol
)
3161 md_section_align (segT seg ATTRIBUTE_UNUSED
, valueT size
)
3165 #else /* ! OBJ_ELF */
3166 return ((size
+ (1 << bfd_section_alignment (seg
)) - 1)
3167 & -(1 << bfd_section_alignment (seg
)));
3168 #endif /* ! OBJ_ELF */
3171 /* This static variable is set by s_uacons to tell sh_cons_align that
3172 the expression does not need to be aligned. */
3174 static int sh_no_align_cons
= 0;
3176 /* This handles the unaligned space allocation pseudo-ops, such as
3177 .uaword. .uaword is just like .word, but the value does not need
3181 s_uacons (int bytes
)
3183 /* Tell sh_cons_align not to align this value. */
3184 sh_no_align_cons
= 1;
3188 /* If a .word, et. al., pseud-op is seen, warn if the value is not
3189 aligned correctly. Note that this can cause warnings to be issued
3190 when assembling initialized structured which were declared with the
3191 packed attribute. FIXME: Perhaps we should require an option to
3192 enable this warning? */
3195 sh_cons_align (int nbytes
)
3199 if (sh_no_align_cons
)
3201 /* This is an unaligned pseudo-op. */
3202 sh_no_align_cons
= 0;
3207 while ((nbytes
& 1) == 0)
3216 if (now_seg
== absolute_section
)
3218 if ((abs_section_offset
& ((1 << nalign
) - 1)) != 0)
3219 as_warn (_("misaligned data"));
3223 frag_var (rs_align_test
, 1, 1, (relax_substateT
) 0,
3224 (symbolS
*) NULL
, (offsetT
) nalign
, (char *) NULL
);
3226 record_alignment (now_seg
, nalign
);
3229 /* When relaxing, we need to output a reloc for any .align directive
3230 that requests alignment to a four byte boundary or larger. This is
3231 also where we check for misaligned data. */
3234 sh_handle_align (fragS
*frag
)
3236 int bytes
= frag
->fr_next
->fr_address
- frag
->fr_address
- frag
->fr_fix
;
3238 if (frag
->fr_type
== rs_align_code
)
3240 static const unsigned char big_nop_pattern
[] = { 0x00, 0x09 };
3241 static const unsigned char little_nop_pattern
[] = { 0x09, 0x00 };
3243 char *p
= frag
->fr_literal
+ frag
->fr_fix
;
3252 if (target_big_endian
)
3254 memcpy (p
, big_nop_pattern
, sizeof big_nop_pattern
);
3255 frag
->fr_var
= sizeof big_nop_pattern
;
3259 memcpy (p
, little_nop_pattern
, sizeof little_nop_pattern
);
3260 frag
->fr_var
= sizeof little_nop_pattern
;
3263 else if (frag
->fr_type
== rs_align_test
)
3266 as_bad_where (frag
->fr_file
, frag
->fr_line
, _("misaligned data"));
3270 && (frag
->fr_type
== rs_align
3271 || frag
->fr_type
== rs_align_code
)
3272 && frag
->fr_address
+ frag
->fr_fix
> 0
3273 && frag
->fr_offset
> 1
3274 && now_seg
!= bss_section
)
3275 fix_new (frag
, frag
->fr_fix
, 2, &abs_symbol
, frag
->fr_offset
, 0,
3276 BFD_RELOC_SH_ALIGN
);
3279 /* See whether the relocation should be resolved locally. */
3282 sh_local_pcrel (fixS
*fix
)
3285 && (fix
->fx_r_type
== BFD_RELOC_SH_PCDISP8BY2
3286 || fix
->fx_r_type
== BFD_RELOC_SH_PCDISP12BY2
3287 || fix
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY2
3288 || fix
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY4
3289 || fix
->fx_r_type
== BFD_RELOC_8_PCREL
3290 || fix
->fx_r_type
== BFD_RELOC_SH_SWITCH16
3291 || fix
->fx_r_type
== BFD_RELOC_SH_SWITCH32
));
3294 /* See whether we need to force a relocation into the output file.
3295 This is used to force out switch and PC relative relocations when
3299 sh_force_relocation (fixS
*fix
)
3301 /* These relocations can't make it into a DSO, so no use forcing
3302 them for global symbols. */
3303 if (sh_local_pcrel (fix
))
3306 /* Make sure some relocations get emitted. */
3307 if (fix
->fx_r_type
== BFD_RELOC_SH_LOOP_START
3308 || fix
->fx_r_type
== BFD_RELOC_SH_LOOP_END
3309 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_GD_32
3310 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LD_32
3311 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_IE_32
3312 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LDO_32
3313 || fix
->fx_r_type
== BFD_RELOC_SH_TLS_LE_32
3314 || generic_force_reloc (fix
))
3320 return (fix
->fx_pcrel
3321 || SWITCH_TABLE (fix
)
3322 || fix
->fx_r_type
== BFD_RELOC_SH_COUNT
3323 || fix
->fx_r_type
== BFD_RELOC_SH_ALIGN
3324 || fix
->fx_r_type
== BFD_RELOC_SH_CODE
3325 || fix
->fx_r_type
== BFD_RELOC_SH_DATA
3326 || fix
->fx_r_type
== BFD_RELOC_SH_LABEL
);
3331 sh_fix_adjustable (fixS
*fixP
)
3333 if (fixP
->fx_r_type
== BFD_RELOC_32_PLT_PCREL
3334 || fixP
->fx_r_type
== BFD_RELOC_32_GOT_PCREL
3335 || fixP
->fx_r_type
== BFD_RELOC_SH_GOT20
3336 || fixP
->fx_r_type
== BFD_RELOC_SH_GOTPC
3337 || fixP
->fx_r_type
== BFD_RELOC_SH_GOTFUNCDESC
3338 || fixP
->fx_r_type
== BFD_RELOC_SH_GOTFUNCDESC20
3339 || fixP
->fx_r_type
== BFD_RELOC_SH_GOTOFFFUNCDESC
3340 || fixP
->fx_r_type
== BFD_RELOC_SH_GOTOFFFUNCDESC20
3341 || fixP
->fx_r_type
== BFD_RELOC_SH_FUNCDESC
3342 || ((fixP
->fx_r_type
== BFD_RELOC_32
) && dont_adjust_reloc_32
)
3343 || fixP
->fx_r_type
== BFD_RELOC_RVA
)
3346 /* We need the symbol name for the VTABLE entries */
3347 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
3348 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
3355 sh_elf_final_processing (void)
3359 /* Set file-specific flags to indicate if this code needs
3360 a processor with the sh-dsp / sh2e ISA to execute. */
3361 val
= sh_find_elf_flags (valid_arch
);
3363 elf_elfheader (stdoutput
)->e_flags
&= ~EF_SH_MACH_MASK
;
3364 elf_elfheader (stdoutput
)->e_flags
|= val
;
3367 elf_elfheader (stdoutput
)->e_flags
|= EF_SH_FDPIC
;
3372 /* Return the target format for uClinux. */
3375 sh_uclinux_target_format (void)
3378 return (!target_big_endian
? "elf32-sh-fdpic" : "elf32-shbig-fdpic");
3380 return (!target_big_endian
? "elf32-shl" : "elf32-sh");
3384 /* Apply fixup FIXP to SIZE-byte field BUF given that VAL is its
3385 assembly-time value. If we're generating a reloc for FIXP,
3386 see whether the addend should be stored in-place or whether
3387 it should be in an ELF r_addend field. */
3390 apply_full_field_fix (fixS
*fixP
, char *buf
, bfd_vma val
, int size
)
3392 reloc_howto_type
*howto
;
3394 if (fixP
->fx_addsy
!= NULL
|| fixP
->fx_pcrel
)
3396 howto
= bfd_reloc_type_lookup (stdoutput
, fixP
->fx_r_type
);
3397 if (howto
&& !howto
->partial_inplace
)
3399 fixP
->fx_addnumber
= val
;
3403 md_number_to_chars (buf
, val
, size
);
3406 /* Apply a fixup to the object file. */
3409 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
3411 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3412 int lowbyte
= target_big_endian
? 1 : 0;
3413 int highbyte
= target_big_endian
? 0 : 1;
3414 long val
= (long) *valP
;
3418 /* A difference between two symbols, the second of which is in the
3419 current section, is transformed in a PC-relative relocation to
3420 the other symbol. We have to adjust the relocation type here. */
3423 switch (fixP
->fx_r_type
)
3429 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
3432 /* Currently, we only support 32-bit PCREL relocations.
3433 We'd need a new reloc type to handle 16_PCREL, and
3434 8_PCREL is already taken for R_SH_SWITCH8, which
3435 apparently does something completely different than what
3438 bfd_set_error (bfd_error_bad_value
);
3442 bfd_set_error (bfd_error_bad_value
);
3447 /* The function adjust_reloc_syms won't convert a reloc against a weak
3448 symbol into a reloc against a section, but bfd_install_relocation
3449 will screw up if the symbol is defined, so we have to adjust val here
3450 to avoid the screw up later.
3452 For ordinary relocs, this does not happen for ELF, since for ELF,
3453 bfd_install_relocation uses the "special function" field of the
3454 howto, and does not execute the code that needs to be undone, as long
3455 as the special function does not return bfd_reloc_continue.
3456 It can happen for GOT- and PLT-type relocs the way they are
3457 described in elf32-sh.c as they use bfd_elf_generic_reloc, but it
3458 doesn't matter here since those relocs don't use VAL; see below. */
3459 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
3460 && fixP
->fx_addsy
!= NULL
3461 && S_IS_WEAK (fixP
->fx_addsy
))
3462 val
-= S_GET_VALUE (fixP
->fx_addsy
);
3464 if (SWITCH_TABLE (fixP
))
3465 val
-= S_GET_VALUE (fixP
->fx_subsy
);
3469 switch (fixP
->fx_r_type
)
3471 case BFD_RELOC_SH_IMM3
:
3473 * buf
= (* buf
& 0xf8) | (val
& 0x7);
3475 case BFD_RELOC_SH_IMM3U
:
3477 * buf
= (* buf
& 0x8f) | ((val
& 0x7) << 4);
3479 case BFD_RELOC_SH_DISP12
:
3481 buf
[lowbyte
] = val
& 0xff;
3482 buf
[highbyte
] |= (val
>> 8) & 0x0f;
3484 case BFD_RELOC_SH_DISP12BY2
:
3487 buf
[lowbyte
] = (val
>> 1) & 0xff;
3488 buf
[highbyte
] |= (val
>> 9) & 0x0f;
3490 case BFD_RELOC_SH_DISP12BY4
:
3493 buf
[lowbyte
] = (val
>> 2) & 0xff;
3494 buf
[highbyte
] |= (val
>> 10) & 0x0f;
3496 case BFD_RELOC_SH_DISP12BY8
:
3499 buf
[lowbyte
] = (val
>> 3) & 0xff;
3500 buf
[highbyte
] |= (val
>> 11) & 0x0f;
3502 case BFD_RELOC_SH_DISP20
:
3503 if (! target_big_endian
)
3507 buf
[1] = (buf
[1] & 0x0f) | ((val
>> 12) & 0xf0);
3508 buf
[2] = (val
>> 8) & 0xff;
3509 buf
[3] = val
& 0xff;
3511 case BFD_RELOC_SH_DISP20BY8
:
3512 if (!target_big_endian
)
3517 buf
[1] = (buf
[1] & 0x0f) | ((val
>> 20) & 0xf0);
3518 buf
[2] = (val
>> 16) & 0xff;
3519 buf
[3] = (val
>> 8) & 0xff;
3522 case BFD_RELOC_SH_IMM4
:
3524 *buf
= (*buf
& 0xf0) | (val
& 0xf);
3527 case BFD_RELOC_SH_IMM4BY2
:
3530 *buf
= (*buf
& 0xf0) | ((val
>> 1) & 0xf);
3533 case BFD_RELOC_SH_IMM4BY4
:
3536 *buf
= (*buf
& 0xf0) | ((val
>> 2) & 0xf);
3539 case BFD_RELOC_SH_IMM8BY2
:
3545 case BFD_RELOC_SH_IMM8BY4
:
3552 case BFD_RELOC_SH_IMM8
:
3553 /* Sometimes the 8 bit value is sign extended (e.g., add) and
3554 sometimes it is not (e.g., and). We permit any 8 bit value.
3555 Note that adding further restrictions may invalidate
3556 reasonable looking assembly code, such as ``and -0x1,r0''. */
3562 case BFD_RELOC_SH_PCRELIMM8BY4
:
3563 /* If we are dealing with a known destination ... */
3564 if ((fixP
->fx_addsy
== NULL
|| S_IS_DEFINED (fixP
->fx_addsy
))
3565 && (fixP
->fx_subsy
== NULL
|| S_IS_DEFINED (fixP
->fx_addsy
)))
3567 /* Don't silently move the destination due to misalignment.
3568 The absolute address is the fragment base plus the offset into
3569 the fragment plus the pc relative offset to the label. */
3570 if ((fixP
->fx_frag
->fr_address
+ fixP
->fx_where
+ val
) & 3)
3571 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3572 _("offset to unaligned destination"));
3574 /* The displacement cannot be zero or backward even if aligned.
3575 Allow -2 because val has already been adjusted somewhere. */
3577 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("negative offset"));
3580 /* The lower two bits of the PC are cleared before the
3581 displacement is added in. We can assume that the destination
3582 is on a 4 byte boundary. If this instruction is also on a 4
3583 byte boundary, then we want
3585 and target - here is a multiple of 4.
3586 Otherwise, we are on a 2 byte boundary, and we want
3587 (target - (here - 2)) / 4
3588 and target - here is not a multiple of 4. Computing
3589 (target - (here - 2)) / 4 == (target - here + 2) / 4
3590 works for both cases, since in the first case the addition of
3591 2 will be removed by the division. target - here is in the
3593 val
= (val
+ 2) / 4;
3595 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3599 case BFD_RELOC_SH_PCRELIMM8BY2
:
3602 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3606 case BFD_RELOC_SH_PCDISP8BY2
:
3608 if (val
< -0x80 || val
> 0x7f)
3609 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3613 case BFD_RELOC_SH_PCDISP12BY2
:
3615 if (val
< -0x800 || val
> 0x7ff)
3616 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
3617 buf
[lowbyte
] = val
& 0xff;
3618 buf
[highbyte
] |= (val
>> 8) & 0xf;
3622 case BFD_RELOC_32_PCREL
:
3623 apply_full_field_fix (fixP
, buf
, val
, 4);
3627 apply_full_field_fix (fixP
, buf
, val
, 2);
3630 case BFD_RELOC_SH_USES
:
3631 /* Pass the value into sh_reloc(). */
3632 fixP
->fx_addnumber
= val
;
3635 case BFD_RELOC_SH_COUNT
:
3636 case BFD_RELOC_SH_ALIGN
:
3637 case BFD_RELOC_SH_CODE
:
3638 case BFD_RELOC_SH_DATA
:
3639 case BFD_RELOC_SH_LABEL
:
3640 /* Nothing to do here. */
3643 case BFD_RELOC_SH_LOOP_START
:
3644 case BFD_RELOC_SH_LOOP_END
:
3646 case BFD_RELOC_VTABLE_INHERIT
:
3647 case BFD_RELOC_VTABLE_ENTRY
:
3652 case BFD_RELOC_32_PLT_PCREL
:
3653 /* Make the jump instruction point to the address of the operand. At
3654 runtime we merely add the offset to the actual PLT entry. */
3655 * valP
= 0xfffffffc;
3656 val
= fixP
->fx_offset
;
3658 val
-= S_GET_VALUE (fixP
->fx_subsy
);
3659 apply_full_field_fix (fixP
, buf
, val
, 4);
3662 case BFD_RELOC_SH_GOTPC
:
3663 /* This is tough to explain. We end up with this one if we have
3664 operands that look like "_GLOBAL_OFFSET_TABLE_+[.-.L284]".
3665 The goal here is to obtain the absolute address of the GOT,
3666 and it is strongly preferable from a performance point of
3667 view to avoid using a runtime relocation for this. There are
3668 cases where you have something like:
3670 .long _GLOBAL_OFFSET_TABLE_+[.-.L66]
3672 and here no correction would be required. Internally in the
3673 assembler we treat operands of this form as not being pcrel
3674 since the '.' is explicitly mentioned, and I wonder whether
3675 it would simplify matters to do it this way. Who knows. In
3676 earlier versions of the PIC patches, the pcrel_adjust field
3677 was used to store the correction, but since the expression is
3678 not pcrel, I felt it would be confusing to do it this way. */
3680 apply_full_field_fix (fixP
, buf
, val
, 4);
3683 case BFD_RELOC_SH_TLS_GD_32
:
3684 case BFD_RELOC_SH_TLS_LD_32
:
3685 case BFD_RELOC_SH_TLS_IE_32
:
3686 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
3688 case BFD_RELOC_32_GOT_PCREL
:
3689 case BFD_RELOC_SH_GOT20
:
3690 case BFD_RELOC_SH_GOTPLT32
:
3691 case BFD_RELOC_SH_GOTFUNCDESC
:
3692 case BFD_RELOC_SH_GOTFUNCDESC20
:
3693 case BFD_RELOC_SH_GOTOFFFUNCDESC
:
3694 case BFD_RELOC_SH_GOTOFFFUNCDESC20
:
3695 case BFD_RELOC_SH_FUNCDESC
:
3696 * valP
= 0; /* Fully resolved at runtime. No addend. */
3697 apply_full_field_fix (fixP
, buf
, 0, 4);
3700 case BFD_RELOC_SH_TLS_LDO_32
:
3701 case BFD_RELOC_SH_TLS_LE_32
:
3702 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
3704 case BFD_RELOC_32_GOTOFF
:
3705 case BFD_RELOC_SH_GOTOFF20
:
3706 apply_full_field_fix (fixP
, buf
, val
, 4);
3716 if ((val
& ((1 << shift
) - 1)) != 0)
3717 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("misaligned offset"));
3721 val
= ((val
>> shift
)
3722 | ((long) -1 & ~ ((long) -1 >> shift
)));
3725 /* Extend sign for 64-bit host. */
3726 val
= ((val
& 0xffffffff) ^ 0x80000000) - 0x80000000;
3727 if (max
!= 0 && (val
< min
|| val
> max
))
3728 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("offset out of range"));
3730 /* Stop the generic code from trying to overflow check the value as well.
3731 It may not have the correct value anyway, as we do not store val back
3733 fixP
->fx_no_overflow
= 1;
3735 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
3739 /* Called just before address relaxation. Return the length
3740 by which a fragment must grow to reach it's destination. */
3743 md_estimate_size_before_relax (fragS
*fragP
, segT segment_type
)
3747 switch (fragP
->fr_subtype
)
3752 case C (UNCOND_JUMP
, UNDEF_DISP
):
3753 /* Used to be a branch to somewhere which was unknown. */
3754 if (!fragP
->fr_symbol
)
3756 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
3758 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
3760 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
3764 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNDEF_WORD_DISP
);
3768 case C (COND_JUMP
, UNDEF_DISP
):
3769 case C (COND_JUMP_DELAY
, UNDEF_DISP
):
3770 what
= GET_WHAT (fragP
->fr_subtype
);
3771 /* Used to be a branch to somewhere which was unknown. */
3772 if (fragP
->fr_symbol
3773 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
3775 /* Got a symbol and it's defined in this segment, become byte
3776 sized - maybe it will fix up. */
3777 fragP
->fr_subtype
= C (what
, COND8
);
3779 else if (fragP
->fr_symbol
)
3781 /* It's got a segment, but it's not ours, so it will always be long. */
3782 fragP
->fr_subtype
= C (what
, UNDEF_WORD_DISP
);
3786 /* We know the abs value. */
3787 fragP
->fr_subtype
= C (what
, COND8
);
3791 case C (UNCOND_JUMP
, UNCOND12
):
3792 case C (UNCOND_JUMP
, UNCOND32
):
3793 case C (UNCOND_JUMP
, UNDEF_WORD_DISP
):
3794 case C (COND_JUMP
, COND8
):
3795 case C (COND_JUMP
, COND12
):
3796 case C (COND_JUMP
, COND32
):
3797 case C (COND_JUMP
, UNDEF_WORD_DISP
):
3798 case C (COND_JUMP_DELAY
, COND8
):
3799 case C (COND_JUMP_DELAY
, COND12
):
3800 case C (COND_JUMP_DELAY
, COND32
):
3801 case C (COND_JUMP_DELAY
, UNDEF_WORD_DISP
):
3802 /* When relaxing a section for the second time, we don't need to
3803 do anything besides return the current size. */
3807 fragP
->fr_var
= md_relax_table
[fragP
->fr_subtype
].rlx_length
;
3808 return fragP
->fr_var
;
3811 /* Put number into target byte order. */
3814 md_number_to_chars (char *ptr
, valueT use
, int nbytes
)
3816 if (! target_big_endian
)
3817 number_to_chars_littleendian (ptr
, use
, nbytes
);
3819 number_to_chars_bigendian (ptr
, use
, nbytes
);
3822 /* This version is used in obj-coff.c eg. for the sh-hms target. */
3825 md_pcrel_from (fixS
*fixP
)
3827 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
+ 2;
3831 md_pcrel_from_section (fixS
*fixP
, segT sec
)
3833 if (! sh_local_pcrel (fixP
)
3834 && fixP
->fx_addsy
!= (symbolS
*) NULL
3835 && (generic_force_reloc (fixP
)
3836 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
3838 /* The symbol is undefined (or is defined but not in this section,
3839 or we're not sure about it being the final definition). Let the
3840 linker figure it out. We need to adjust the subtraction of a
3841 symbol to the position of the relocated data, though. */
3842 return fixP
->fx_subsy
? fixP
->fx_where
+ fixP
->fx_frag
->fr_address
: 0;
3845 return md_pcrel_from (fixP
);
3848 /* Create a reloc. */
3851 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
3854 bfd_reloc_code_real_type r_type
;
3856 rel
= XNEW (arelent
);
3857 rel
->sym_ptr_ptr
= XNEW (asymbol
*);
3858 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3859 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3861 r_type
= fixp
->fx_r_type
;
3863 if (SWITCH_TABLE (fixp
))
3865 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
3866 rel
->addend
= rel
->address
- S_GET_VALUE(fixp
->fx_subsy
);
3867 if (r_type
== BFD_RELOC_16
)
3868 r_type
= BFD_RELOC_SH_SWITCH16
;
3869 else if (r_type
== BFD_RELOC_8
)
3870 r_type
= BFD_RELOC_8_PCREL
;
3871 else if (r_type
== BFD_RELOC_32
)
3872 r_type
= BFD_RELOC_SH_SWITCH32
;
3876 else if (r_type
== BFD_RELOC_SH_USES
)
3877 rel
->addend
= fixp
->fx_addnumber
;
3878 else if (r_type
== BFD_RELOC_SH_COUNT
)
3879 rel
->addend
= fixp
->fx_offset
;
3880 else if (r_type
== BFD_RELOC_SH_ALIGN
)
3881 rel
->addend
= fixp
->fx_offset
;
3882 else if (r_type
== BFD_RELOC_VTABLE_INHERIT
3883 || r_type
== BFD_RELOC_VTABLE_ENTRY
)
3884 rel
->addend
= fixp
->fx_offset
;
3885 else if (r_type
== BFD_RELOC_SH_LOOP_START
3886 || r_type
== BFD_RELOC_SH_LOOP_END
)
3887 rel
->addend
= fixp
->fx_offset
;
3888 else if (r_type
== BFD_RELOC_SH_LABEL
&& fixp
->fx_pcrel
)
3891 rel
->address
= rel
->addend
= fixp
->fx_offset
;
3894 rel
->addend
= fixp
->fx_addnumber
;
3896 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
3898 if (rel
->howto
== NULL
)
3900 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3901 _("Cannot represent relocation type %s"),
3902 bfd_get_reloc_code_name (r_type
));
3903 /* Set howto to a garbage value so that we can keep going. */
3904 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
3905 gas_assert (rel
->howto
!= NULL
);
3908 else if (rel
->howto
->type
== R_SH_IND12W
)
3909 rel
->addend
+= fixp
->fx_offset
- 4;
3916 inline static char *
3917 sh_end_of_match (char *cont
, const char *what
)
3919 int len
= strlen (what
);
3921 if (strncasecmp (cont
, what
, strlen (what
)) == 0
3922 && ! is_part_of_name (cont
[len
]))
3929 sh_parse_name (char const *name
,
3931 enum expr_mode mode
,
3934 char *next
= input_line_pointer
;
3939 exprP
->X_op_symbol
= NULL
;
3941 if (strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
3944 GOT_symbol
= symbol_find_or_make (name
);
3946 exprP
->X_add_symbol
= GOT_symbol
;
3948 /* If we have an absolute symbol or a reg, then we know its
3950 segment
= S_GET_SEGMENT (exprP
->X_add_symbol
);
3951 if (mode
!= expr_defer
&& segment
== absolute_section
)
3953 exprP
->X_op
= O_constant
;
3954 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
3955 exprP
->X_add_symbol
= NULL
;
3957 else if (mode
!= expr_defer
&& segment
== reg_section
)
3959 exprP
->X_op
= O_register
;
3960 exprP
->X_add_number
= S_GET_VALUE (exprP
->X_add_symbol
);
3961 exprP
->X_add_symbol
= NULL
;
3965 exprP
->X_op
= O_symbol
;
3966 exprP
->X_add_number
= 0;
3972 exprP
->X_add_symbol
= symbol_find_or_make (name
);
3974 if (*nextcharP
!= '@')
3976 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTOFF")))
3977 reloc_type
= BFD_RELOC_32_GOTOFF
;
3978 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTPLT")))
3979 reloc_type
= BFD_RELOC_SH_GOTPLT32
;
3980 else if ((next_end
= sh_end_of_match (next
+ 1, "GOT")))
3981 reloc_type
= BFD_RELOC_32_GOT_PCREL
;
3982 else if ((next_end
= sh_end_of_match (next
+ 1, "PLT")))
3983 reloc_type
= BFD_RELOC_32_PLT_PCREL
;
3984 else if ((next_end
= sh_end_of_match (next
+ 1, "TLSGD")))
3985 reloc_type
= BFD_RELOC_SH_TLS_GD_32
;
3986 else if ((next_end
= sh_end_of_match (next
+ 1, "TLSLDM")))
3987 reloc_type
= BFD_RELOC_SH_TLS_LD_32
;
3988 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTTPOFF")))
3989 reloc_type
= BFD_RELOC_SH_TLS_IE_32
;
3990 else if ((next_end
= sh_end_of_match (next
+ 1, "TPOFF")))
3991 reloc_type
= BFD_RELOC_SH_TLS_LE_32
;
3992 else if ((next_end
= sh_end_of_match (next
+ 1, "DTPOFF")))
3993 reloc_type
= BFD_RELOC_SH_TLS_LDO_32
;
3994 else if ((next_end
= sh_end_of_match (next
+ 1, "PCREL")))
3995 reloc_type
= BFD_RELOC_32_PCREL
;
3996 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTFUNCDESC")))
3997 reloc_type
= BFD_RELOC_SH_GOTFUNCDESC
;
3998 else if ((next_end
= sh_end_of_match (next
+ 1, "GOTOFFFUNCDESC")))
3999 reloc_type
= BFD_RELOC_SH_GOTOFFFUNCDESC
;
4000 else if ((next_end
= sh_end_of_match (next
+ 1, "FUNCDESC")))
4001 reloc_type
= BFD_RELOC_SH_FUNCDESC
;
4005 *input_line_pointer
= *nextcharP
;
4006 input_line_pointer
= next_end
;
4007 *nextcharP
= *input_line_pointer
;
4008 *input_line_pointer
= '\0';
4010 exprP
->X_op
= O_PIC_reloc
;
4011 exprP
->X_add_number
= 0;
4012 exprP
->X_md
= reloc_type
;
4018 sh_cfi_frame_initial_instructions (void)
4020 cfi_add_CFA_def_cfa (15, 0);
4024 sh_regname_to_dw2regnum (char *regname
)
4026 unsigned int regnum
= -1;
4030 static struct { const char *name
; int dw2regnum
; } regnames
[] =
4032 { "pr", 17 }, { "t", 18 }, { "gbr", 19 }, { "mach", 20 },
4033 { "macl", 21 }, { "fpul", 23 }
4036 for (i
= 0; i
< ARRAY_SIZE (regnames
); ++i
)
4037 if (strcmp (regnames
[i
].name
, regname
) == 0)
4038 return regnames
[i
].dw2regnum
;
4040 if (regname
[0] == 'r')
4043 regnum
= strtoul (p
, &q
, 10);
4044 if (p
== q
|| *q
|| regnum
>= 16)
4047 else if (regname
[0] == 'f' && regname
[1] == 'r')
4050 regnum
= strtoul (p
, &q
, 10);
4051 if (p
== q
|| *q
|| regnum
>= 16)
4055 else if (regname
[0] == 'x' && regname
[1] == 'd')
4058 regnum
= strtoul (p
, &q
, 10);
4059 if (p
== q
|| *q
|| regnum
>= 8)
4065 #endif /* OBJ_ELF */