1 /* tc-sh.c -- Assemble code for the Hitachi Super-H
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Written By Steve Chamberlain <sac@cygnus.com> */
29 #include "opcodes/sh-opc.h"
31 #include "struc-symbol.h"
37 #include "dwarf2dbg.h"
39 const char comment_chars
[] = "!";
40 const char line_separator_chars
[] = ";";
41 const char line_comment_chars
[] = "!#";
43 static void s_uses
PARAMS ((int));
45 static void sh_count_relocs
PARAMS ((bfd
*, segT
, PTR
));
46 static void sh_frob_section
PARAMS ((bfd
*, segT
, PTR
));
49 void s_align_bytes ();
50 static void s_uacons
PARAMS ((int));
51 static sh_opcode_info
*find_cooked_opcode
PARAMS ((char **));
52 static unsigned int assemble_ppi
PARAMS ((char *, sh_opcode_info
*));
55 static void sh_elf_cons
PARAMS ((int));
57 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
64 int ignore ATTRIBUTE_UNUSED
;
67 target_big_endian
= 0;
70 /* This table describes all the machine specific pseudo-ops the assembler
71 has to support. The fields are:
72 pseudo-op name without dot
73 function to call to execute this pseudo-op
74 Integer arg to pass to the function. */
76 const pseudo_typeS md_pseudo_table
[] =
79 {"long", sh_elf_cons
, 4},
80 {"int", sh_elf_cons
, 4},
81 {"word", sh_elf_cons
, 2},
82 {"short", sh_elf_cons
, 2},
87 {"form", listing_psize
, 0},
88 {"little", little
, 0},
89 {"heading", listing_title
, 0},
90 {"import", s_ignore
, 0},
91 {"page", listing_eject
, 0},
92 {"program", s_ignore
, 0},
94 {"uaword", s_uacons
, 2},
95 {"ualong", s_uacons
, 4},
96 {"uaquad", s_uacons
, 8},
97 {"2byte", s_uacons
, 2},
98 {"4byte", s_uacons
, 4},
99 {"8byte", s_uacons
, 8},
100 {"file", dwarf2_directive_file
, 0 },
101 {"loc", dwarf2_directive_loc
, 0 },
105 /*int md_reloc_size; */
107 int sh_relax
; /* set if -relax seen */
109 /* Whether -small was seen. */
113 /* Whether -dsp was seen. */
117 /* The bit mask of architectures that could
118 accomodate the insns seen so far. */
119 static int valid_arch
;
121 const char EXP_CHARS
[] = "eE";
123 /* Chars that mean this number is a floating point constant. */
126 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
128 #define C(a,b) ENCODE_RELAX(a,b)
130 #define ENCODE_RELAX(what,length) (((what) << 4) + (length))
131 #define GET_WHAT(x) ((x>>4))
133 /* These are the three types of relaxable instrction. */
135 #define COND_JUMP_DELAY 2
136 #define UNCOND_JUMP 3
145 #define UNDEF_WORD_DISP 4
150 /* Branch displacements are from the address of the branch plus
151 four, thus all minimum and maximum values have 4 added to them. */
154 #define COND8_LENGTH 2
156 /* There is one extra instruction before the branch, so we must add
157 two more bytes to account for it. */
158 #define COND12_F 4100
159 #define COND12_M -4090
160 #define COND12_LENGTH 6
162 #define COND12_DELAY_LENGTH 4
164 /* ??? The minimum and maximum values are wrong, but this does not matter
165 since this relocation type is not supported yet. */
166 #define COND32_F (1<<30)
167 #define COND32_M -(1<<30)
168 #define COND32_LENGTH 14
170 #define UNCOND12_F 4098
171 #define UNCOND12_M -4092
172 #define UNCOND12_LENGTH 2
174 /* ??? The minimum and maximum values are wrong, but this does not matter
175 since this relocation type is not supported yet. */
176 #define UNCOND32_F (1<<30)
177 #define UNCOND32_M -(1<<30)
178 #define UNCOND32_LENGTH 14
180 #define EMPTY { 0, 0, 0, 0 }
182 const relax_typeS md_relax_table
[C (END
, 0)] = {
183 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
184 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
187 /* C (COND_JUMP, COND8) */
188 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP
, COND12
) },
189 /* C (COND_JUMP, COND12) */
190 { COND12_F
, COND12_M
, COND12_LENGTH
, C (COND_JUMP
, COND32
), },
191 /* C (COND_JUMP, COND32) */
192 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
193 EMPTY
, EMPTY
, EMPTY
, EMPTY
,
194 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
197 /* C (COND_JUMP_DELAY, COND8) */
198 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP_DELAY
, COND12
) },
199 /* C (COND_JUMP_DELAY, COND12) */
200 { COND12_F
, COND12_M
, COND12_DELAY_LENGTH
, C (COND_JUMP_DELAY
, COND32
), },
201 /* C (COND_JUMP_DELAY, COND32) */
202 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
203 EMPTY
, EMPTY
, EMPTY
, EMPTY
,
204 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
207 /* C (UNCOND_JUMP, UNCOND12) */
208 { UNCOND12_F
, UNCOND12_M
, UNCOND12_LENGTH
, C (UNCOND_JUMP
, UNCOND32
), },
209 /* C (UNCOND_JUMP, UNCOND32) */
210 { UNCOND32_F
, UNCOND32_M
, UNCOND32_LENGTH
, 0, },
211 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
212 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
217 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics */
221 /* Parse @got, etc. and return the desired relocation.
222 If we have additional arithmetic expression, then we fill in new_exp_p. */
223 static bfd_reloc_code_real_type
224 sh_elf_suffix (str_p
, exp_p
, new_exp_p
)
226 expressionS
*exp_p
, *new_exp_p
;
231 bfd_reloc_code_real_type reloc
;
241 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
243 static struct map_bfd mapping
[] = {
244 MAP ("got", BFD_RELOC_32_GOT_PCREL
),
245 MAP ("plt", BFD_RELOC_32_PLT_PCREL
),
246 MAP ("gotoff", BFD_RELOC_32_GOTOFF
),
247 { (char *)0, 0, BFD_RELOC_UNUSED
}
251 return BFD_RELOC_UNUSED
;
253 for (ch
= *str
, str2
= ident
;
254 (str2
< ident
+ sizeof (ident
) - 1
255 && (isalnum (ch
) || ch
== '@'));
258 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
265 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
266 if (ch
== ptr
->string
[0]
267 && len
== ptr
->length
268 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
270 /* Now check for identifier@suffix+constant */
271 if (*str
== '-' || *str
== '+')
273 char *orig_line
= input_line_pointer
;
275 input_line_pointer
= str
;
276 expression (new_exp_p
);
277 if (new_exp_p
->X_op
== O_constant
)
279 exp_p
->X_add_number
+= new_exp_p
->X_add_number
;
280 str
= input_line_pointer
;
282 if (new_exp_p
->X_op
== O_subtract
)
283 str
= input_line_pointer
;
285 if (&input_line_pointer
!= str_p
)
286 input_line_pointer
= orig_line
;
293 return BFD_RELOC_UNUSED
;
296 /* The regular cons() function, that reads constants, doesn't support
297 suffixes such as @GOT, @GOTOFF and @PLT, that generate
298 machine-specific relocation types. So we must define it here. */
299 /* Clobbers input_line_pointer, checks end-of-line. */
302 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
304 expressionS exp
, new_exp
;
305 bfd_reloc_code_real_type reloc
;
308 if (is_it_end_of_statement ())
310 demand_empty_rest_of_line ();
317 new_exp
.X_op
= O_absent
;
318 new_exp
.X_add_symbol
= new_exp
.X_op_symbol
= NULL
;
319 /* If the _GLOBAL_OFFSET_TABLE_ symbol hasn't been found yet,
320 use the name of the symbol to tell whether it's the
321 _GLOBAL_OFFSET_TABLE_. If it has, comparing the symbols is
323 if (! GOT_symbol
&& exp
.X_add_symbol
)
324 name
= S_GET_NAME (exp
.X_add_symbol
);
327 /* Check whether this expression involves the
328 _GLOBAL_OFFSET_TABLE_ symbol, by itself or added to a
329 difference of two other symbols. */
330 if (((GOT_symbol
&& GOT_symbol
== exp
.X_add_symbol
)
331 || (! GOT_symbol
&& name
332 && strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0))
333 && (exp
.X_op
== O_symbol
334 || (exp
.X_op
== O_add
335 && ((symbol_get_value_expression (exp
.X_op_symbol
)->X_op
)
338 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
340 int size
= bfd_get_reloc_size (reloc_howto
);
342 if (GOT_symbol
== NULL
)
343 GOT_symbol
= symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME
);
346 as_bad (_("%s relocations do not fit in %d bytes\n"),
347 reloc_howto
->name
, nbytes
);
350 register char *p
= frag_more ((int) nbytes
);
351 int offset
= nbytes
- size
;
353 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
,
354 size
, &exp
, 0, TC_RELOC_GLOBAL_OFFSET_TABLE
);
357 /* Check if this symbol involves one of the magic suffixes, such
358 as @GOT, @GOTOFF or @PLT, and determine which relocation type
360 else if ((exp
.X_op
== O_symbol
|| (exp
.X_op
== O_add
&& exp
.X_op_symbol
))
361 && *input_line_pointer
== '@'
362 && ((reloc
= sh_elf_suffix (&input_line_pointer
, &exp
, &new_exp
))
363 != BFD_RELOC_UNUSED
))
365 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
367 int size
= bfd_get_reloc_size (reloc_howto
);
369 /* Force a GOT to be generated. */
370 if (GOT_symbol
== NULL
)
371 GOT_symbol
= symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME
);
374 as_bad (_("%s relocations do not fit in %d bytes\n"),
375 reloc_howto
->name
, nbytes
);
378 register char *p
= frag_more ((int) nbytes
);
379 int offset
= nbytes
- size
;
381 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
383 if (new_exp
.X_op
!= O_absent
)
384 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
385 &new_exp
, 0, BFD_RELOC_32
);
389 emit_expr (&exp
, (unsigned int) nbytes
);
391 while (*input_line_pointer
++ == ',');
393 input_line_pointer
--; /* Put terminator back into stream. */
394 if (*input_line_pointer
== '#' || *input_line_pointer
== '!')
396 while (! is_end_of_line
[(unsigned char) *input_line_pointer
++]);
399 demand_empty_rest_of_line ();
404 /* This function is called once, at assembler startup time. This should
405 set up all the tables, etc that the MD part of the assembler needs. */
410 sh_opcode_info
*opcode
;
411 char *prev_name
= "";
415 /* The WinCE OS only supports little endian executables. */
416 target_big_endian
= 0;
419 target_big_endian
= 1;
422 target_arch
= arch_sh1_up
& ~(sh_dsp
? arch_sh3e_up
: arch_sh_dsp_up
);
423 valid_arch
= target_arch
;
425 opcode_hash_control
= hash_new ();
427 /* Insert unique names into hash table. */
428 for (opcode
= sh_table
; opcode
->name
; opcode
++)
430 if (strcmp (prev_name
, opcode
->name
))
432 if (! (opcode
->arch
& target_arch
))
434 prev_name
= opcode
->name
;
435 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
439 /* Make all the opcodes with the same name point to the same
441 opcode
->name
= prev_name
;
448 static int reg_x
, reg_y
;
456 expressionS immediate
;
460 #define IDENT_CHAR(c) (isalnum (c) || (c) == '_')
462 /* Try to parse a reg name. Return the number of chars consumed. */
465 parse_reg (src
, mode
, reg
)
470 char l0
= tolower (src
[0]);
471 char l1
= l0
? tolower (src
[1]) : 0;
473 /* We use ! IDENT_CHAR for the next character after the register name, to
474 make sure that we won't accidentally recognize a symbol name such as
475 'sram' or sr_ram as being a reference to the register 'sr'. */
481 if (src
[2] >= '0' && src
[2] <= '5'
482 && ! IDENT_CHAR ((unsigned char) src
[3]))
485 *reg
= 10 + src
[2] - '0';
489 if (l1
>= '0' && l1
<= '9'
490 && ! IDENT_CHAR ((unsigned char) src
[2]))
496 if (l1
>= '0' && l1
<= '7' && strncasecmp (&src
[2], "_bank", 5) == 0
497 && ! IDENT_CHAR ((unsigned char) src
[7]))
504 if (l1
== 'e' && ! IDENT_CHAR ((unsigned char) src
[2]))
509 if (l1
== 's' && ! IDENT_CHAR ((unsigned char) src
[2]))
520 if (! IDENT_CHAR ((unsigned char) src
[2]))
526 if (tolower (src
[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
535 if (! IDENT_CHAR ((unsigned char) src
[2]))
541 if (tolower (src
[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
549 if (l1
== 'x' && src
[2] >= '0' && src
[2] <= '1'
550 && ! IDENT_CHAR ((unsigned char) src
[3]))
553 *reg
= 4 + (l1
- '0');
556 if (l1
== 'y' && src
[2] >= '0' && src
[2] <= '1'
557 && ! IDENT_CHAR ((unsigned char) src
[3]))
560 *reg
= 6 + (l1
- '0');
563 if (l1
== 's' && src
[2] >= '0' && src
[2] <= '3'
564 && ! IDENT_CHAR ((unsigned char) src
[3]))
569 *reg
= n
| ((~n
& 2) << 1);
574 if (l0
== 'i' && l1
&& ! IDENT_CHAR ((unsigned char) src
[3]))
596 if (l0
== 'x' && l1
>= '0' && l1
<= '1'
597 && ! IDENT_CHAR ((unsigned char) src
[2]))
600 *reg
= A_X0_NUM
+ l1
- '0';
604 if (l0
== 'y' && l1
>= '0' && l1
<= '1'
605 && ! IDENT_CHAR ((unsigned char) src
[2]))
608 *reg
= A_Y0_NUM
+ l1
- '0';
612 if (l0
== 'm' && l1
>= '0' && l1
<= '1'
613 && ! IDENT_CHAR ((unsigned char) src
[2]))
616 *reg
= l1
== '0' ? A_M0_NUM
: A_M1_NUM
;
622 && tolower (src
[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src
[3]))
628 if (l0
== 's' && l1
== 'p' && tolower (src
[2]) == 'c'
629 && ! IDENT_CHAR ((unsigned char) src
[3]))
635 if (l0
== 's' && l1
== 'g' && tolower (src
[2]) == 'r'
636 && ! IDENT_CHAR ((unsigned char) src
[3]))
642 if (l0
== 'd' && l1
== 's' && tolower (src
[2]) == 'r'
643 && ! IDENT_CHAR ((unsigned char) src
[3]))
649 if (l0
== 'd' && l1
== 'b' && tolower (src
[2]) == 'r'
650 && ! IDENT_CHAR ((unsigned char) src
[3]))
656 if (l0
== 's' && l1
== 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
662 if (l0
== 's' && l1
== 'p' && ! IDENT_CHAR ((unsigned char) src
[2]))
669 if (l0
== 'p' && l1
== 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
674 if (l0
== 'p' && l1
== 'c' && ! IDENT_CHAR ((unsigned char) src
[2]))
676 /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0'
677 and use an uninitialized immediate. */
681 if (l0
== 'g' && l1
== 'b' && tolower (src
[2]) == 'r'
682 && ! IDENT_CHAR ((unsigned char) src
[3]))
687 if (l0
== 'v' && l1
== 'b' && tolower (src
[2]) == 'r'
688 && ! IDENT_CHAR ((unsigned char) src
[3]))
694 if (l0
== 'm' && l1
== 'a' && tolower (src
[2]) == 'c'
695 && ! IDENT_CHAR ((unsigned char) src
[4]))
708 if (l0
== 'm' && l1
== 'o' && tolower (src
[2]) == 'd'
709 && ! IDENT_CHAR ((unsigned char) src
[4]))
714 if (l0
== 'f' && l1
== 'r')
718 if (src
[3] >= '0' && src
[3] <= '5'
719 && ! IDENT_CHAR ((unsigned char) src
[4]))
722 *reg
= 10 + src
[3] - '0';
726 if (src
[2] >= '0' && src
[2] <= '9'
727 && ! IDENT_CHAR ((unsigned char) src
[3]))
730 *reg
= (src
[2] - '0');
734 if (l0
== 'd' && l1
== 'r')
738 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
739 && ! IDENT_CHAR ((unsigned char) src
[4]))
742 *reg
= 10 + src
[3] - '0';
746 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
747 && ! IDENT_CHAR ((unsigned char) src
[3]))
750 *reg
= (src
[2] - '0');
754 if (l0
== 'x' && l1
== 'd')
758 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
759 && ! IDENT_CHAR ((unsigned char) src
[4]))
762 *reg
= 11 + src
[3] - '0';
766 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
767 && ! IDENT_CHAR ((unsigned char) src
[3]))
770 *reg
= (src
[2] - '0') + 1;
774 if (l0
== 'f' && l1
== 'v')
776 if (src
[2] == '1'&& src
[3] == '2' && ! IDENT_CHAR ((unsigned char) src
[4]))
782 if ((src
[2] == '0' || src
[2] == '4' || src
[2] == '8')
783 && ! IDENT_CHAR ((unsigned char) src
[3]))
786 *reg
= (src
[2] - '0');
790 if (l0
== 'f' && l1
== 'p' && tolower (src
[2]) == 'u'
791 && tolower (src
[3]) == 'l'
792 && ! IDENT_CHAR ((unsigned char) src
[4]))
798 if (l0
== 'f' && l1
== 'p' && tolower (src
[2]) == 's'
799 && tolower (src
[3]) == 'c'
800 && tolower (src
[4]) == 'r' && ! IDENT_CHAR ((unsigned char) src
[5]))
806 if (l0
== 'x' && l1
== 'm' && tolower (src
[2]) == 't'
807 && tolower (src
[3]) == 'r'
808 && tolower (src
[4]) == 'x' && ! IDENT_CHAR ((unsigned char) src
[5]))
822 /* JF: '.' is pseudo symbol with value of current location
823 in current segment. */
824 fake
= FAKE_LABEL_NAME
;
825 return symbol_new (fake
,
827 (valueT
) frag_now_fix (),
839 save
= input_line_pointer
;
840 input_line_pointer
= s
;
841 expression (&op
->immediate
);
842 if (op
->immediate
.X_op
== O_absent
)
843 as_bad (_("missing operand"));
844 new = input_line_pointer
;
845 input_line_pointer
= save
;
849 /* The many forms of operand:
852 @Rn Register indirect
865 pr, gbr, vbr, macl, mach
878 /* Must be predecrement. */
881 len
= parse_reg (src
, &mode
, &(op
->reg
));
883 as_bad (_("illegal register after @-"));
888 else if (src
[0] == '(')
890 /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
893 len
= parse_reg (src
, &mode
, &(op
->reg
));
894 if (len
&& mode
== A_REG_N
)
899 as_bad (_("must be @(r0,...)"));
903 /* Now can be rn or gbr */
904 len
= parse_reg (src
, &mode
, &(op
->reg
));
909 else if (mode
== A_REG_N
)
911 op
->type
= A_IND_R0_REG_N
;
915 as_bad (_("syntax error in @(r0,...)"));
920 /* Must be an @(disp,.. thing) */
921 src
= parse_exp (src
, op
);
924 /* Now can be rn, gbr or pc */
925 len
= parse_reg (src
, &mode
, &op
->reg
);
930 op
->type
= A_DISP_REG_N
;
932 else if (mode
== A_GBR
)
934 op
->type
= A_DISP_GBR
;
936 else if (mode
== A_PC
)
938 /* Turn a plain @(4,pc) into @(.+4,pc). */
939 if (op
->immediate
.X_op
== O_constant
)
941 op
->immediate
.X_add_symbol
= dot();
942 op
->immediate
.X_op
= O_symbol
;
944 op
->type
= A_DISP_PC
;
948 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
953 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
958 as_bad (_("expecting )"));
964 src
+= parse_reg (src
, &mode
, &(op
->reg
));
967 as_bad (_("illegal register after @"));
972 if ((src
[0] == 'r' && src
[1] == '8')
973 || (src
[0] == 'i' && (src
[1] == 'x' || src
[1] == 's')))
978 if ((src
[0] == 'r' && src
[1] == '9')
979 || (src
[0] == 'i' && src
[1] == 'y'))
982 op
->type
= A_PMODY_N
;
996 get_operand (ptr
, op
)
1007 *ptr
= parse_exp (src
, op
);
1012 else if (src
[0] == '@')
1014 *ptr
= parse_at (src
, op
);
1017 len
= parse_reg (src
, &mode
, &(op
->reg
));
1026 /* Not a reg, the only thing left is a displacement. */
1027 *ptr
= parse_exp (src
, op
);
1028 op
->type
= A_DISP_PC
;
1034 get_operands (info
, args
, operand
)
1035 sh_opcode_info
*info
;
1037 sh_operand_info
*operand
;
1042 /* The pre-processor will eliminate whitespace in front of '@'
1043 after the first argument; we may be called multiple times
1044 from assemble_ppi, so don't insist on finding whitespace here. */
1048 get_operand (&ptr
, operand
+ 0);
1055 get_operand (&ptr
, operand
+ 1);
1056 /* ??? Hack: psha/pshl have a varying operand number depending on
1057 the type of the first operand. We handle this by having the
1058 three-operand version first and reducing the number of operands
1059 parsed to two if we see that the first operand is an immediate.
1060 This works because no insn with three operands has an immediate
1061 as first operand. */
1062 if (info
->arg
[2] && operand
[0].type
!= A_IMM
)
1068 get_operand (&ptr
, operand
+ 2);
1072 operand
[2].type
= 0;
1077 operand
[1].type
= 0;
1078 operand
[2].type
= 0;
1083 operand
[0].type
= 0;
1084 operand
[1].type
= 0;
1085 operand
[2].type
= 0;
1090 /* Passed a pointer to a list of opcodes which use different
1091 addressing modes, return the opcode which matches the opcodes
1094 static sh_opcode_info
*
1095 get_specific (opcode
, operands
)
1096 sh_opcode_info
*opcode
;
1097 sh_operand_info
*operands
;
1099 sh_opcode_info
*this_try
= opcode
;
1100 char *name
= opcode
->name
;
1103 while (opcode
->name
)
1105 this_try
= opcode
++;
1106 if (this_try
->name
!= name
)
1108 /* We've looked so far down the table that we've run out of
1109 opcodes with the same name. */
1113 /* Look at both operands needed by the opcodes and provided by
1114 the user - since an arg test will often fail on the same arg
1115 again and again, we'll try and test the last failing arg the
1116 first on each opcode try. */
1117 for (n
= 0; this_try
->arg
[n
]; n
++)
1119 sh_operand_info
*user
= operands
+ n
;
1120 sh_arg_type arg
= this_try
->arg
[n
];
1132 if (user
->type
!= arg
)
1136 /* opcode needs r0 */
1137 if (user
->type
!= A_REG_N
|| user
->reg
!= 0)
1141 if (user
->type
!= A_R0_GBR
|| user
->reg
!= 0)
1145 if (user
->type
!= F_REG_N
|| user
->reg
!= 0)
1153 case A_IND_R0_REG_N
:
1164 /* Opcode needs rn */
1165 if (user
->type
!= arg
)
1170 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
1185 if (user
->type
!= arg
)
1190 if (user
->type
!= arg
)
1199 case A_IND_R0_REG_M
:
1202 /* Opcode needs rn */
1203 if (user
->type
!= arg
- A_REG_M
+ A_REG_N
)
1209 if (user
->type
!= DSP_REG_N
)
1231 if (user
->type
!= DSP_REG_N
)
1253 if (user
->type
!= DSP_REG_N
)
1275 if (user
->type
!= DSP_REG_N
)
1297 if (user
->type
!= DSP_REG_N
)
1319 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_A0_NUM
)
1323 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X0_NUM
)
1327 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X1_NUM
)
1331 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y0_NUM
)
1335 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y1_NUM
)
1345 /* Opcode needs rn */
1346 if (user
->type
!= arg
- F_REG_M
+ F_REG_N
)
1351 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
1356 if (user
->type
!= XMTRX_M4
)
1362 printf (_("unhandled %d\n"), arg
);
1366 if ( !(valid_arch
& this_try
->arch
))
1368 valid_arch
&= this_try
->arch
;
1378 check (operand
, low
, high
)
1379 expressionS
*operand
;
1383 if (operand
->X_op
!= O_constant
1384 || operand
->X_add_number
< low
1385 || operand
->X_add_number
> high
)
1387 as_bad (_("operand must be absolute in range %d..%d"), low
, high
);
1389 return operand
->X_add_number
;
1393 insert (where
, how
, pcrel
, op
)
1397 sh_operand_info
*op
;
1399 fix_new_exp (frag_now
,
1400 where
- frag_now
->fr_literal
,
1408 build_relax (opcode
, op
)
1409 sh_opcode_info
*opcode
;
1410 sh_operand_info
*op
;
1412 int high_byte
= target_big_endian
? 0 : 1;
1415 if (opcode
->arg
[0] == A_BDISP8
)
1417 int what
= (opcode
->nibbles
[1] & 4) ? COND_JUMP_DELAY
: COND_JUMP
;
1418 p
= frag_var (rs_machine_dependent
,
1419 md_relax_table
[C (what
, COND32
)].rlx_length
,
1420 md_relax_table
[C (what
, COND8
)].rlx_length
,
1422 op
->immediate
.X_add_symbol
,
1423 op
->immediate
.X_add_number
,
1425 p
[high_byte
] = (opcode
->nibbles
[0] << 4) | (opcode
->nibbles
[1]);
1427 else if (opcode
->arg
[0] == A_BDISP12
)
1429 p
= frag_var (rs_machine_dependent
,
1430 md_relax_table
[C (UNCOND_JUMP
, UNCOND32
)].rlx_length
,
1431 md_relax_table
[C (UNCOND_JUMP
, UNCOND12
)].rlx_length
,
1433 op
->immediate
.X_add_symbol
,
1434 op
->immediate
.X_add_number
,
1436 p
[high_byte
] = (opcode
->nibbles
[0] << 4);
1441 /* Insert ldrs & ldre with fancy relocations that relaxation can recognize. */
1444 insert_loop_bounds (output
, operand
)
1446 sh_operand_info
*operand
;
1451 /* Since the low byte of the opcode will be overwritten by the reloc, we
1452 can just stash the high byte into both bytes and ignore endianness. */
1455 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
1456 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
1460 static int count
= 0;
1462 /* If the last loop insn is a two-byte-insn, it is in danger of being
1463 swapped with the insn after it. To prevent this, create a new
1464 symbol - complete with SH_LABEL reloc - after the last loop insn.
1465 If the last loop insn is four bytes long, the symbol will be
1466 right in the middle, but four byte insns are not swapped anyways. */
1467 /* A REPEAT takes 6 bytes. The SH has a 32 bit address space.
1468 Hence a 9 digit number should be enough to count all REPEATs. */
1470 sprintf (name
, "_R%x", count
++ & 0x3fffffff);
1471 end_sym
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1472 /* Make this a local symbol. */
1474 SF_SET_LOCAL (end_sym
);
1475 #endif /* OBJ_COFF */
1476 symbol_table_insert (end_sym
);
1477 end_sym
->sy_value
= operand
[1].immediate
;
1478 end_sym
->sy_value
.X_add_number
+= 2;
1479 fix_new (frag_now
, frag_now_fix (), 2, end_sym
, 0, 1, BFD_RELOC_SH_LABEL
);
1482 output
= frag_more (2);
1485 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
1486 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
1488 return frag_more (2);
1491 /* Now we know what sort of opcodes it is, let's build the bytes. */
1494 build_Mytes (opcode
, operand
)
1495 sh_opcode_info
*opcode
;
1496 sh_operand_info
*operand
;
1501 char *output
= frag_more (2);
1502 unsigned int size
= 2;
1503 int low_byte
= target_big_endian
? 1 : 0;
1509 for (index
= 0; index
< 4; index
++)
1511 sh_nibble_type i
= opcode
->nibbles
[index
];
1521 nbuf
[index
] = reg_n
;
1524 nbuf
[index
] = reg_m
;
1527 if (reg_n
< 2 || reg_n
> 5)
1528 as_bad (_("Invalid register: 'r%d'"), reg_n
);
1529 nbuf
[index
] = (reg_n
& 3) | 4;
1532 nbuf
[index
] = reg_n
| (reg_m
>> 2);
1535 nbuf
[index
] = reg_b
| 0x08;
1538 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
);
1541 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
);
1544 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
);
1547 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
+ 1);
1550 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
+ 1);
1553 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
+ 1);
1556 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
);
1559 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
);
1562 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
);
1565 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
+ 1);
1568 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
+ 1);
1571 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
+ 1);
1574 insert (output
, BFD_RELOC_SH_PCRELIMM8BY4
, 1, operand
);
1577 insert (output
, BFD_RELOC_SH_PCRELIMM8BY2
, 1, operand
);
1580 output
= insert_loop_bounds (output
, operand
);
1581 nbuf
[index
] = opcode
->nibbles
[3];
1585 printf (_("failed for %d\n"), i
);
1589 if (!target_big_endian
)
1591 output
[1] = (nbuf
[0] << 4) | (nbuf
[1]);
1592 output
[0] = (nbuf
[2] << 4) | (nbuf
[3]);
1596 output
[0] = (nbuf
[0] << 4) | (nbuf
[1]);
1597 output
[1] = (nbuf
[2] << 4) | (nbuf
[3]);
1602 /* Find an opcode at the start of *STR_P in the hash table, and set
1603 *STR_P to the first character after the last one read. */
1605 static sh_opcode_info
*
1606 find_cooked_opcode (str_p
)
1610 unsigned char *op_start
;
1611 unsigned char *op_end
;
1615 /* Drop leading whitespace. */
1619 /* Find the op code end.
1620 The pre-processor will eliminate whitespace in front of
1621 any '@' after the first argument; we may be called from
1622 assemble_ppi, so the opcode might be terminated by an '@'. */
1623 for (op_start
= op_end
= (unsigned char *) (str
);
1626 && !is_end_of_line
[*op_end
] && *op_end
!= ' ' && *op_end
!= '@';
1629 unsigned char c
= op_start
[nlen
];
1631 /* The machine independent code will convert CMP/EQ into cmp/EQ
1632 because it thinks the '/' is the end of the symbol. Moreover,
1633 all but the first sub-insn is a parallel processing insn won't
1634 be capitailzed. Instead of hacking up the machine independent
1635 code, we just deal with it here. */
1636 c
= isupper (c
) ? tolower (c
) : c
;
1645 as_bad (_("can't find opcode "));
1647 return (sh_opcode_info
*) hash_find (opcode_hash_control
, name
);
1650 /* Assemble a parallel processing insn. */
1651 #define DDT_BASE 0xf000 /* Base value for double data transfer insns */
1654 assemble_ppi (op_end
, opcode
)
1656 sh_opcode_info
*opcode
;
1666 /* Some insn ignore one or more register fields, e.g. psts machl,a0.
1667 Make sure we encode a defined insn pattern. */
1673 sh_operand_info operand
[3];
1675 if (opcode
->arg
[0] != A_END
)
1676 op_end
= get_operands (opcode
, op_end
, operand
);
1677 opcode
= get_specific (opcode
, operand
);
1680 /* Couldn't find an opcode which matched the operands. */
1681 char *where
= frag_more (2);
1686 as_bad (_("invalid operands for opcode"));
1690 if (opcode
->nibbles
[0] != PPI
)
1691 as_bad (_("insn can't be combined with parallel processing insn"));
1693 switch (opcode
->nibbles
[1])
1698 as_bad (_("multiple movx specifications"));
1703 as_bad (_("multiple movy specifications"));
1709 as_bad (_("multiple movx specifications"));
1710 if (reg_n
< 4 || reg_n
> 5)
1711 as_bad (_("invalid movx address register"));
1712 if (opcode
->nibbles
[2] & 8)
1714 if (reg_m
== A_A1_NUM
)
1716 else if (reg_m
!= A_A0_NUM
)
1717 as_bad (_("invalid movx dsp register"));
1722 as_bad (_("invalid movx dsp register"));
1725 movx
+= ((reg_n
- 4) << 9) + (opcode
->nibbles
[2] << 2) + DDT_BASE
;
1730 as_bad (_("multiple movy specifications"));
1731 if (opcode
->nibbles
[2] & 8)
1733 /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode,
1736 if (reg_m
== A_A1_NUM
)
1738 else if (reg_m
!= A_A0_NUM
)
1739 as_bad (_("invalid movy dsp register"));
1744 as_bad (_("invalid movy dsp register"));
1747 if (reg_n
< 6 || reg_n
> 7)
1748 as_bad (_("invalid movy address register"));
1749 movy
+= ((reg_n
- 6) << 8) + opcode
->nibbles
[2] + DDT_BASE
;
1753 if (operand
[0].immediate
.X_op
!= O_constant
)
1754 as_bad (_("dsp immediate shift value not constant"));
1755 field_b
= ((opcode
->nibbles
[2] << 12)
1756 | (operand
[0].immediate
.X_add_number
& 127) << 4
1761 as_bad (_("multiple parallel processing specifications"));
1762 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
1763 + (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
1767 as_bad (_("multiple condition specifications"));
1768 cond
= opcode
->nibbles
[2] << 8;
1770 goto skip_cond_check
;
1774 as_bad (_("multiple parallel processing specifications"));
1775 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
1776 + cond
+ (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
1782 if ((field_b
& 0xef00) != 0xa100)
1783 as_bad (_("insn cannot be combined with pmuls"));
1785 switch (field_b
& 0xf)
1788 field_b
+= 0 - A_X0_NUM
;
1791 field_b
+= 1 - A_Y0_NUM
;
1794 field_b
+= 2 - A_A0_NUM
;
1797 field_b
+= 3 - A_A1_NUM
;
1800 as_bad (_("bad padd / psub pmuls output operand"));
1803 field_b
+= 0x4000 + reg_efg
;
1810 as_bad (_("condition not followed by conditionalizable insn"));
1816 opcode
= find_cooked_opcode (&op_end
);
1820 (_("unrecognized characters at end of parallel processing insn")));
1825 move_code
= movx
| movy
;
1828 /* Parallel processing insn. */
1829 unsigned long ppi_code
= (movx
| movy
| 0xf800) << 16 | field_b
;
1831 output
= frag_more (4);
1833 if (! target_big_endian
)
1835 output
[3] = ppi_code
>> 8;
1836 output
[2] = ppi_code
;
1840 output
[2] = ppi_code
>> 8;
1841 output
[3] = ppi_code
;
1843 move_code
|= 0xf800;
1847 /* Just a double data transfer. */
1848 output
= frag_more (2);
1851 if (! target_big_endian
)
1853 output
[1] = move_code
>> 8;
1854 output
[0] = move_code
;
1858 output
[0] = move_code
>> 8;
1859 output
[1] = move_code
;
1864 /* This is the guts of the machine-dependent assembler. STR points to a
1865 machine dependent instruction. This function is supposed to emit
1866 the frags/bytes it assembles to. */
1872 unsigned char *op_end
;
1873 sh_operand_info operand
[3];
1874 sh_opcode_info
*opcode
;
1875 unsigned int size
= 0;
1877 opcode
= find_cooked_opcode (&str
);
1882 as_bad (_("unknown opcode"));
1887 && ! seg_info (now_seg
)->tc_segment_info_data
.in_code
)
1889 /* Output a CODE reloc to tell the linker that the following
1890 bytes are instructions, not data. */
1891 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
1893 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 1;
1896 if (opcode
->nibbles
[0] == PPI
)
1898 size
= assemble_ppi (op_end
, opcode
);
1902 if (opcode
->arg
[0] == A_BDISP12
1903 || opcode
->arg
[0] == A_BDISP8
)
1905 parse_exp (op_end
+ 1, &operand
[0]);
1906 build_relax (opcode
, &operand
[0]);
1910 if (opcode
->arg
[0] == A_END
)
1912 /* Ignore trailing whitespace. If there is any, it has already
1913 been compressed to a single space. */
1919 op_end
= get_operands (opcode
, op_end
, operand
);
1921 opcode
= get_specific (opcode
, operand
);
1925 /* Couldn't find an opcode which matched the operands. */
1926 char *where
= frag_more (2);
1931 as_bad (_("invalid operands for opcode"));
1936 as_bad (_("excess operands: '%s'"), op_end
);
1938 size
= build_Mytes (opcode
, operand
);
1943 dwarf2_emit_insn (size
);
1946 /* This routine is called each time a label definition is seen. It
1947 emits a BFD_RELOC_SH_LABEL reloc if necessary. */
1952 static fragS
*last_label_frag
;
1953 static int last_label_offset
;
1956 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
1960 offset
= frag_now_fix ();
1961 if (frag_now
!= last_label_frag
1962 || offset
!= last_label_offset
)
1964 fix_new (frag_now
, offset
, 2, &abs_symbol
, 0, 0, BFD_RELOC_SH_LABEL
);
1965 last_label_frag
= frag_now
;
1966 last_label_offset
= offset
;
1971 /* This routine is called when the assembler is about to output some
1972 data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */
1975 sh_flush_pending_output ()
1978 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
1980 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
1982 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 0;
1987 md_undefined_symbol (name
)
1991 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. Otherwise we
1992 have no need to default values of symbols. */
1993 if (strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
1997 if (symbol_find (name
))
1998 as_bad ("GOT already in the symbol table");
2000 GOT_symbol
= symbol_new (name
, undefined_section
,
2001 (valueT
)0, & zero_address_frag
);
2006 #endif /* OBJ_ELF */
2012 #ifndef BFD_ASSEMBLER
2015 tc_crawl_symbol_chain (headers
)
2016 object_headers
*headers
;
2018 printf (_("call to tc_crawl_symbol_chain \n"));
2022 tc_headers_hook (headers
)
2023 object_headers
*headers
;
2025 printf (_("call to tc_headers_hook \n"));
2031 /* Various routines to kill one day. */
2032 /* Equal to MAX_PRECISION in atof-ieee.c. */
2033 #define MAX_LITTLENUMS 6
2035 /* Turn a string in input_line_pointer into a floating point constant
2036 of type TYPE, and store the appropriate bytes in *LITP. The number
2037 of LITTLENUMS emitted is stored in *SIZEP . An error message is
2038 returned, or NULL on OK. */
2041 md_atof (type
, litP
, sizeP
)
2047 LITTLENUM_TYPE words
[4];
2063 return _("bad call to md_atof");
2066 t
= atof_ieee (input_line_pointer
, type
, words
);
2068 input_line_pointer
= t
;
2072 if (! target_big_endian
)
2074 for (i
= prec
- 1; i
>= 0; i
--)
2076 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2082 for (i
= 0; i
< prec
; i
++)
2084 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2092 /* Handle the .uses pseudo-op. This pseudo-op is used just before a
2093 call instruction. It refers to a label of the instruction which
2094 loads the register which the call uses. We use it to generate a
2095 special reloc for the linker. */
2099 int ignore ATTRIBUTE_UNUSED
;
2104 as_warn (_(".uses pseudo-op seen when not relaxing"));
2108 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
2110 as_bad (_("bad .uses format"));
2111 ignore_rest_of_line ();
2115 fix_new_exp (frag_now
, frag_now_fix (), 2, &ex
, 1, BFD_RELOC_SH_USES
);
2117 demand_empty_rest_of_line ();
2120 CONST
char *md_shortopts
= "";
2121 struct option md_longopts
[] =
2123 #define OPTION_RELAX (OPTION_MD_BASE)
2124 #define OPTION_LITTLE (OPTION_MD_BASE + 1)
2125 #define OPTION_SMALL (OPTION_LITTLE + 1)
2126 #define OPTION_DSP (OPTION_SMALL + 1)
2128 {"relax", no_argument
, NULL
, OPTION_RELAX
},
2129 {"little", no_argument
, NULL
, OPTION_LITTLE
},
2130 {"small", no_argument
, NULL
, OPTION_SMALL
},
2131 {"dsp", no_argument
, NULL
, OPTION_DSP
},
2132 {NULL
, no_argument
, NULL
, 0}
2134 size_t md_longopts_size
= sizeof (md_longopts
);
2137 md_parse_option (c
, arg
)
2139 char *arg ATTRIBUTE_UNUSED
;
2149 target_big_endian
= 0;
2168 md_show_usage (stream
)
2171 fprintf (stream
, _("\
2173 -little generate little endian code\n\
2174 -relax alter jump instructions for long displacements\n\
2175 -small align sections to 4 byte boundaries, not 16\n\
2176 -dsp enable sh-dsp insns, and disable sh3e / sh4 insns.\n"));
2180 tc_Nout_fix_to_chars ()
2182 printf (_("call to tc_Nout_fix_to_chars \n"));
2186 /* This struct is used to pass arguments to sh_count_relocs through
2187 bfd_map_over_sections. */
2189 struct sh_count_relocs
2191 /* Symbol we are looking for. */
2193 /* Count of relocs found. */
2197 /* Count the number of fixups in a section which refer to a particular
2198 symbol. When using BFD_ASSEMBLER, this is called via
2199 bfd_map_over_sections. */
2202 sh_count_relocs (abfd
, sec
, data
)
2203 bfd
*abfd ATTRIBUTE_UNUSED
;
2207 struct sh_count_relocs
*info
= (struct sh_count_relocs
*) data
;
2208 segment_info_type
*seginfo
;
2212 seginfo
= seg_info (sec
);
2213 if (seginfo
== NULL
)
2217 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
2219 if (fix
->fx_addsy
== sym
)
2227 /* Handle the count relocs for a particular section. When using
2228 BFD_ASSEMBLER, this is called via bfd_map_over_sections. */
2231 sh_frob_section (abfd
, sec
, ignore
)
2232 bfd
*abfd ATTRIBUTE_UNUSED
;
2234 PTR ignore ATTRIBUTE_UNUSED
;
2236 segment_info_type
*seginfo
;
2239 seginfo
= seg_info (sec
);
2240 if (seginfo
== NULL
)
2243 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
2248 struct sh_count_relocs info
;
2250 if (fix
->fx_r_type
!= BFD_RELOC_SH_USES
)
2253 /* The BFD_RELOC_SH_USES reloc should refer to a defined local
2254 symbol in the same section. */
2255 sym
= fix
->fx_addsy
;
2257 || fix
->fx_subsy
!= NULL
2258 || fix
->fx_addnumber
!= 0
2259 || S_GET_SEGMENT (sym
) != sec
2260 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
2261 || S_GET_STORAGE_CLASS (sym
) == C_EXT
2263 || S_IS_EXTERNAL (sym
))
2265 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2266 _(".uses does not refer to a local symbol in the same section"));
2270 /* Look through the fixups again, this time looking for one
2271 at the same location as sym. */
2272 val
= S_GET_VALUE (sym
);
2273 for (fscan
= seginfo
->fix_root
;
2275 fscan
= fscan
->fx_next
)
2276 if (val
== fscan
->fx_frag
->fr_address
+ fscan
->fx_where
2277 && fscan
->fx_r_type
!= BFD_RELOC_SH_ALIGN
2278 && fscan
->fx_r_type
!= BFD_RELOC_SH_CODE
2279 && fscan
->fx_r_type
!= BFD_RELOC_SH_DATA
2280 && fscan
->fx_r_type
!= BFD_RELOC_SH_LABEL
)
2284 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2285 _("can't find fixup pointed to by .uses"));
2289 if (fscan
->fx_tcbit
)
2291 /* We've already done this one. */
2295 /* The variable fscan should also be a fixup to a local symbol
2296 in the same section. */
2297 sym
= fscan
->fx_addsy
;
2299 || fscan
->fx_subsy
!= NULL
2300 || fscan
->fx_addnumber
!= 0
2301 || S_GET_SEGMENT (sym
) != sec
2302 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
2303 || S_GET_STORAGE_CLASS (sym
) == C_EXT
2305 || S_IS_EXTERNAL (sym
))
2307 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2308 _(".uses target does not refer to a local symbol in the same section"));
2312 /* Now we look through all the fixups of all the sections,
2313 counting the number of times we find a reference to sym. */
2316 #ifdef BFD_ASSEMBLER
2317 bfd_map_over_sections (stdoutput
, sh_count_relocs
, (PTR
) &info
);
2322 for (iscan
= SEG_E0
; iscan
< SEG_UNKNOWN
; iscan
++)
2323 sh_count_relocs ((bfd
*) NULL
, iscan
, (PTR
) &info
);
2330 /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym.
2331 We have already adjusted the value of sym to include the
2332 fragment address, so we undo that adjustment here. */
2333 subseg_change (sec
, 0);
2334 fix_new (symbol_get_frag (sym
),
2335 S_GET_VALUE (sym
) - symbol_get_frag (sym
)->fr_address
,
2336 4, &abs_symbol
, info
.count
, 0, BFD_RELOC_SH_COUNT
);
2340 /* This function is called after the symbol table has been completed,
2341 but before the relocs or section contents have been written out.
2342 If we have seen any .uses pseudo-ops, they point to an instruction
2343 which loads a register with the address of a function. We look
2344 through the fixups to find where the function address is being
2345 loaded from. We then generate a COUNT reloc giving the number of
2346 times that function address is referred to. The linker uses this
2347 information when doing relaxing, to decide when it can eliminate
2348 the stored function address entirely. */
2356 #ifdef BFD_ASSEMBLER
2357 bfd_map_over_sections (stdoutput
, sh_frob_section
, (PTR
) NULL
);
2362 for (iseg
= SEG_E0
; iseg
< SEG_UNKNOWN
; iseg
++)
2363 sh_frob_section ((bfd
*) NULL
, iseg
, (PTR
) NULL
);
2368 /* Called after relaxing. Set the correct sizes of the fragments, and
2369 create relocs so that md_apply_fix will fill in the correct values. */
2372 md_convert_frag (headers
, seg
, fragP
)
2373 #ifdef BFD_ASSEMBLER
2374 bfd
*headers ATTRIBUTE_UNUSED
;
2376 object_headers
*headers
;
2383 switch (fragP
->fr_subtype
)
2385 case C (COND_JUMP
, COND8
):
2386 case C (COND_JUMP_DELAY
, COND8
):
2387 subseg_change (seg
, 0);
2388 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
2389 1, BFD_RELOC_SH_PCDISP8BY2
);
2394 case C (UNCOND_JUMP
, UNCOND12
):
2395 subseg_change (seg
, 0);
2396 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
2397 1, BFD_RELOC_SH_PCDISP12BY2
);
2402 case C (UNCOND_JUMP
, UNCOND32
):
2403 case C (UNCOND_JUMP
, UNDEF_WORD_DISP
):
2404 if (fragP
->fr_symbol
== NULL
)
2405 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2406 _("displacement overflows 12-bit field"));
2407 else if (S_IS_DEFINED (fragP
->fr_symbol
))
2408 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2409 _("displacement to defined symbol %s overflows 12-bit field"),
2410 S_GET_NAME (fragP
->fr_symbol
));
2412 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2413 _("displacement to undefined symbol %s overflows 12-bit field"),
2414 S_GET_NAME (fragP
->fr_symbol
));
2415 /* Stabilize this frag, so we don't trip an assert. */
2416 fragP
->fr_fix
+= fragP
->fr_var
;
2420 case C (COND_JUMP
, COND12
):
2421 case C (COND_JUMP_DELAY
, COND12
):
2422 /* A bcond won't fit, so turn it into a b!cond; bra disp; nop. */
2423 /* I found that a relax failure for gcc.c-torture/execute/930628-1.c
2424 was due to gas incorrectly relaxing an out-of-range conditional
2425 branch with delay slot. It turned:
2426 bf.s L6 (slot mov.l r12,@(44,r0))
2429 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6)
2431 32: 10 cb mov.l r12,@(44,r0)
2432 Therefore, branches with delay slots have to be handled
2433 differently from ones without delay slots. */
2435 unsigned char *buffer
=
2436 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
2437 int highbyte
= target_big_endian
? 0 : 1;
2438 int lowbyte
= target_big_endian
? 1 : 0;
2439 int delay
= fragP
->fr_subtype
== C (COND_JUMP_DELAY
, COND12
);
2441 /* Toggle the true/false bit of the bcond. */
2442 buffer
[highbyte
] ^= 0x2;
2444 /* If this is a dalayed branch, we may not put the the bra in the
2445 slot. So we change it to a non-delayed branch, like that:
2446 b! cond slot_label; bra disp; slot_label: slot_insn
2447 ??? We should try if swapping the conditional branch and
2448 its delay-slot insn already makes the branch reach. */
2450 /* Build a relocation to six / four bytes farther on. */
2451 subseg_change (seg
, 0);
2452 fix_new (fragP
, fragP
->fr_fix
, 2,
2453 #ifdef BFD_ASSEMBLER
2454 section_symbol (seg
),
2456 seg_info (seg
)->dot
,
2458 fragP
->fr_address
+ fragP
->fr_fix
+ (delay
? 4 : 6),
2459 1, BFD_RELOC_SH_PCDISP8BY2
);
2461 /* Set up a jump instruction. */
2462 buffer
[highbyte
+ 2] = 0xa0;
2463 buffer
[lowbyte
+ 2] = 0;
2464 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
2465 fragP
->fr_offset
, 1, BFD_RELOC_SH_PCDISP12BY2
);
2469 buffer
[highbyte
] &= ~0x4; /* Removes delay slot from branch. */
2474 /* Fill in a NOP instruction. */
2475 buffer
[highbyte
+ 4] = 0x0;
2476 buffer
[lowbyte
+ 4] = 0x9;
2485 case C (COND_JUMP
, COND32
):
2486 case C (COND_JUMP_DELAY
, COND32
):
2487 case C (COND_JUMP
, UNDEF_WORD_DISP
):
2488 case C (COND_JUMP_DELAY
, UNDEF_WORD_DISP
):
2489 if (fragP
->fr_symbol
== NULL
)
2490 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2491 _("displacement overflows 8-bit field"));
2492 else if (S_IS_DEFINED (fragP
->fr_symbol
))
2493 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2494 _("displacement to defined symbol %s overflows 8-bit field"),
2495 S_GET_NAME (fragP
->fr_symbol
));
2497 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2498 _("displacement to undefined symbol %s overflows 8-bit field "),
2499 S_GET_NAME (fragP
->fr_symbol
));
2500 /* Stabilize this frag, so we don't trip an assert. */
2501 fragP
->fr_fix
+= fragP
->fr_var
;
2509 if (donerelax
&& !sh_relax
)
2510 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
2511 _("overflow in branch to %s; converted into longer instruction sequence"),
2512 (fragP
->fr_symbol
!= NULL
2513 ? S_GET_NAME (fragP
->fr_symbol
)
2518 md_section_align (seg
, size
)
2519 segT seg ATTRIBUTE_UNUSED
;
2522 #ifdef BFD_ASSEMBLER
2525 #else /* ! OBJ_ELF */
2526 return ((size
+ (1 << bfd_get_section_alignment (stdoutput
, seg
)) - 1)
2527 & (-1 << bfd_get_section_alignment (stdoutput
, seg
)));
2528 #endif /* ! OBJ_ELF */
2529 #else /* ! BFD_ASSEMBLER */
2530 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
2531 & (-1 << section_alignment
[(int) seg
]));
2532 #endif /* ! BFD_ASSEMBLER */
2535 /* This static variable is set by s_uacons to tell sh_cons_align that
2536 the expession does not need to be aligned. */
2538 static int sh_no_align_cons
= 0;
2540 /* This handles the unaligned space allocation pseudo-ops, such as
2541 .uaword. .uaword is just like .word, but the value does not need
2548 /* Tell sh_cons_align not to align this value. */
2549 sh_no_align_cons
= 1;
2553 /* If a .word, et. al., pseud-op is seen, warn if the value is not
2554 aligned correctly. Note that this can cause warnings to be issued
2555 when assembling initialized structured which were declared with the
2556 packed attribute. FIXME: Perhaps we should require an option to
2557 enable this warning? */
2560 sh_cons_align (nbytes
)
2566 if (sh_no_align_cons
)
2568 /* This is an unaligned pseudo-op. */
2569 sh_no_align_cons
= 0;
2574 while ((nbytes
& 1) == 0)
2583 if (now_seg
== absolute_section
)
2585 if ((abs_section_offset
& ((1 << nalign
) - 1)) != 0)
2586 as_warn (_("misaligned data"));
2590 p
= frag_var (rs_align_test
, 1, 1, (relax_substateT
) 0,
2591 (symbolS
*) NULL
, (offsetT
) nalign
, (char *) NULL
);
2593 record_alignment (now_seg
, nalign
);
2596 /* When relaxing, we need to output a reloc for any .align directive
2597 that requests alignment to a four byte boundary or larger. This is
2598 also where we check for misaligned data. */
2601 sh_handle_align (frag
)
2604 int bytes
= frag
->fr_next
->fr_address
- frag
->fr_address
- frag
->fr_fix
;
2606 if (frag
->fr_type
== rs_align_code
)
2608 static const unsigned char big_nop_pattern
[] = { 0x00, 0x09 };
2609 static const unsigned char little_nop_pattern
[] = { 0x09, 0x00 };
2611 char *p
= frag
->fr_literal
+ frag
->fr_fix
;
2620 if (target_big_endian
)
2622 memcpy (p
, big_nop_pattern
, sizeof big_nop_pattern
);
2623 frag
->fr_var
= sizeof big_nop_pattern
;
2627 memcpy (p
, little_nop_pattern
, sizeof little_nop_pattern
);
2628 frag
->fr_var
= sizeof little_nop_pattern
;
2631 else if (frag
->fr_type
== rs_align_test
)
2634 as_warn_where (frag
->fr_file
, frag
->fr_line
, _("misaligned data"));
2638 && (frag
->fr_type
== rs_align
2639 || frag
->fr_type
== rs_align_code
)
2640 && frag
->fr_address
+ frag
->fr_fix
> 0
2641 && frag
->fr_offset
> 1
2642 && now_seg
!= bss_section
)
2643 fix_new (frag
, frag
->fr_fix
, 2, &abs_symbol
, frag
->fr_offset
, 0,
2644 BFD_RELOC_SH_ALIGN
);
2647 /* This macro decides whether a particular reloc is an entry in a
2648 switch table. It is used when relaxing, because the linker needs
2649 to know about all such entries so that it can adjust them if
2652 #ifdef BFD_ASSEMBLER
2653 #define SWITCH_TABLE_CONS(fix) (0)
2655 #define SWITCH_TABLE_CONS(fix) \
2656 ((fix)->fx_r_type == 0 \
2657 && ((fix)->fx_size == 2 \
2658 || (fix)->fx_size == 1 \
2659 || (fix)->fx_size == 4))
2662 #define SWITCH_TABLE(fix) \
2663 ((fix)->fx_addsy != NULL \
2664 && (fix)->fx_subsy != NULL \
2665 && S_GET_SEGMENT ((fix)->fx_addsy) == text_section \
2666 && S_GET_SEGMENT ((fix)->fx_subsy) == text_section \
2667 && ((fix)->fx_r_type == BFD_RELOC_32 \
2668 || (fix)->fx_r_type == BFD_RELOC_16 \
2669 || (fix)->fx_r_type == BFD_RELOC_8 \
2670 || SWITCH_TABLE_CONS (fix)))
2672 /* See whether we need to force a relocation into the output file.
2673 This is used to force out switch and PC relative relocations when
2677 sh_force_relocation (fix
)
2681 if (fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2682 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
2683 || fix
->fx_r_type
== BFD_RELOC_SH_LOOP_START
2684 || fix
->fx_r_type
== BFD_RELOC_SH_LOOP_END
)
2690 return (fix
->fx_pcrel
2691 || SWITCH_TABLE (fix
)
2692 || fix
->fx_r_type
== BFD_RELOC_SH_COUNT
2693 || fix
->fx_r_type
== BFD_RELOC_SH_ALIGN
2694 || fix
->fx_r_type
== BFD_RELOC_SH_CODE
2695 || fix
->fx_r_type
== BFD_RELOC_SH_DATA
2696 || fix
->fx_r_type
== BFD_RELOC_SH_LABEL
);
2701 sh_fix_adjustable (fixP
)
2705 if (fixP
->fx_addsy
== NULL
)
2708 if (fixP
->fx_r_type
== BFD_RELOC_SH_PCDISP8BY2
2709 || fixP
->fx_r_type
== BFD_RELOC_SH_PCDISP12BY2
2710 || fixP
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY2
2711 || fixP
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY4
2712 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
2713 || fixP
->fx_r_type
== BFD_RELOC_SH_SWITCH16
2714 || fixP
->fx_r_type
== BFD_RELOC_SH_SWITCH32
)
2717 if (! TC_RELOC_RTSYM_LOC_FIXUP (fixP
)
2718 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
2719 || fixP
->fx_r_type
== BFD_RELOC_RVA
)
2722 /* We need the symbol name for the VTABLE entries */
2723 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2724 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2731 sh_elf_final_processing ()
2735 /* Set file-specific flags to indicate if this code needs
2736 a processor with the sh-dsp / sh3e ISA to execute. */
2737 if (valid_arch
& arch_sh1
)
2739 else if (valid_arch
& arch_sh2
)
2741 else if (valid_arch
& arch_sh_dsp
)
2743 else if (valid_arch
& arch_sh3
)
2745 else if (valid_arch
& arch_sh3_dsp
)
2747 else if (valid_arch
& arch_sh3e
)
2749 else if (valid_arch
& arch_sh4
)
2754 elf_elfheader (stdoutput
)->e_flags
&= ~EF_SH_MACH_MASK
;
2755 elf_elfheader (stdoutput
)->e_flags
|= val
;
2759 /* Apply a fixup to the object file. */
2761 #ifdef BFD_ASSEMBLER
2763 md_apply_fix (fixP
, valp
)
2768 md_apply_fix (fixP
, val
)
2773 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2774 int lowbyte
= target_big_endian
? 1 : 0;
2775 int highbyte
= target_big_endian
? 0 : 1;
2776 #ifdef BFD_ASSEMBLER
2782 #ifdef BFD_ASSEMBLER
2783 /* A difference between two symbols, the second of which is in the
2784 current section, is transformed in a PC-relative relocation to
2785 the other symbol. We have to adjust the relocation type here. */
2788 switch (fixP
->fx_r_type
)
2794 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2797 /* Currently, we only support 32-bit PCREL relocations.
2798 We'd need a new reloc type to handle 16_PCREL, and
2799 8_PCREL is already taken for R_SH_SWITCH8, which
2800 apparently does something completely different than what
2803 bfd_set_error (bfd_error_bad_value
);
2807 bfd_set_error (bfd_error_bad_value
);
2812 /* The function adjust_reloc_syms won't convert a reloc against a weak
2813 symbol into a reloc against a section, but bfd_install_relocation
2814 will screw up if the symbol is defined, so we have to adjust val here
2815 to avoid the screw up later.
2817 For ordinary relocs, this does not happen for ELF, since for ELF,
2818 bfd_install_relocation uses the "special function" field of the
2819 howto, and does not execute the code that needs to be undone, as long
2820 as the special function does not return bfd_reloc_continue.
2821 It can happen for GOT- and PLT-type relocs the way they are
2822 described in elf32-sh.c as they use bfd_elf_generic_reloc, but it
2823 doesn't matter here since those relocs don't use VAL; see below. */
2824 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
2825 && fixP
->fx_addsy
!= NULL
2826 && S_IS_WEAK (fixP
->fx_addsy
))
2827 val
-= S_GET_VALUE (fixP
->fx_addsy
);
2830 #ifndef BFD_ASSEMBLER
2831 if (fixP
->fx_r_type
== 0)
2833 if (fixP
->fx_size
== 2)
2834 fixP
->fx_r_type
= BFD_RELOC_16
;
2835 else if (fixP
->fx_size
== 4)
2836 fixP
->fx_r_type
= BFD_RELOC_32
;
2837 else if (fixP
->fx_size
== 1)
2838 fixP
->fx_r_type
= BFD_RELOC_8
;
2846 switch (fixP
->fx_r_type
)
2848 case BFD_RELOC_SH_IMM4
:
2850 *buf
= (*buf
& 0xf0) | (val
& 0xf);
2853 case BFD_RELOC_SH_IMM4BY2
:
2856 *buf
= (*buf
& 0xf0) | ((val
>> 1) & 0xf);
2859 case BFD_RELOC_SH_IMM4BY4
:
2862 *buf
= (*buf
& 0xf0) | ((val
>> 2) & 0xf);
2865 case BFD_RELOC_SH_IMM8BY2
:
2871 case BFD_RELOC_SH_IMM8BY4
:
2878 case BFD_RELOC_SH_IMM8
:
2879 /* Sometimes the 8 bit value is sign extended (e.g., add) and
2880 sometimes it is not (e.g., and). We permit any 8 bit value.
2881 Note that adding further restrictions may invalidate
2882 reasonable looking assembly code, such as ``and -0x1,r0''. */
2888 case BFD_RELOC_SH_PCRELIMM8BY4
:
2889 /* The lower two bits of the PC are cleared before the
2890 displacement is added in. We can assume that the destination
2891 is on a 4 byte bounday. If this instruction is also on a 4
2892 byte boundary, then we want
2894 and target - here is a multiple of 4.
2895 Otherwise, we are on a 2 byte boundary, and we want
2896 (target - (here - 2)) / 4
2897 and target - here is not a multiple of 4. Computing
2898 (target - (here - 2)) / 4 == (target - here + 2) / 4
2899 works for both cases, since in the first case the addition of
2900 2 will be removed by the division. target - here is in the
2902 val
= (val
+ 2) / 4;
2904 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
2908 case BFD_RELOC_SH_PCRELIMM8BY2
:
2911 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
2915 case BFD_RELOC_SH_PCDISP8BY2
:
2917 if (val
< -0x80 || val
> 0x7f)
2918 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
2922 case BFD_RELOC_SH_PCDISP12BY2
:
2924 if (val
< -0x800 || val
> 0x7ff)
2925 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
2926 buf
[lowbyte
] = val
& 0xff;
2927 buf
[highbyte
] |= (val
>> 8) & 0xf;
2931 case BFD_RELOC_32_PCREL
:
2932 md_number_to_chars (buf
, val
, 4);
2936 md_number_to_chars (buf
, val
, 2);
2939 case BFD_RELOC_SH_USES
:
2940 /* Pass the value into sh_coff_reloc_mangle. */
2941 fixP
->fx_addnumber
= val
;
2944 case BFD_RELOC_SH_COUNT
:
2945 case BFD_RELOC_SH_ALIGN
:
2946 case BFD_RELOC_SH_CODE
:
2947 case BFD_RELOC_SH_DATA
:
2948 case BFD_RELOC_SH_LABEL
:
2949 /* Nothing to do here. */
2952 case BFD_RELOC_SH_LOOP_START
:
2953 case BFD_RELOC_SH_LOOP_END
:
2955 case BFD_RELOC_VTABLE_INHERIT
:
2956 case BFD_RELOC_VTABLE_ENTRY
:
2958 #ifdef BFD_ASSEMBLER
2965 case BFD_RELOC_32_PLT_PCREL
:
2966 /* Make the jump instruction point to the address of the operand. At
2967 runtime we merely add the offset to the actual PLT entry. */
2971 case BFD_RELOC_SH_GOTPC
:
2972 /* This is tough to explain. We end up with this one if we have
2973 operands that look like "_GLOBAL_OFFSET_TABLE_+[.-.L284]".
2974 The goal here is to obtain the absolute address of the GOT,
2975 and it is strongly preferable from a performance point of
2976 view to avoid using a runtime relocation for this. There are
2977 cases where you have something like:
2979 .long _GLOBAL_OFFSET_TABLE_+[.-.L66]
2981 and here no correction would be required. Internally in the
2982 assembler we treat operands of this form as not being pcrel
2983 since the '.' is explicitly mentioned, and I wonder whether
2984 it would simplify matters to do it this way. Who knows. In
2985 earlier versions of the PIC patches, the pcrel_adjust field
2986 was used to store the correction, but since the expression is
2987 not pcrel, I felt it would be confusing to do it this way. */
2989 md_number_to_chars (buf
, val
, 4);
2992 case BFD_RELOC_32_GOT_PCREL
:
2993 *valp
= 0; /* Fully resolved at runtime. No addend. */
2994 md_number_to_chars (buf
, 0, 4);
2997 case BFD_RELOC_32_GOTOFF
:
3007 if ((val
& ((1 << shift
) - 1)) != 0)
3008 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("misaligned offset"));
3012 val
= ((val
>> shift
)
3013 | ((long) -1 & ~ ((long) -1 >> shift
)));
3015 if (max
!= 0 && (val
< min
|| val
> max
))
3016 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("offset out of range"));
3018 #ifdef BFD_ASSEMBLER
3023 /* Called just before address relaxation. Return the length
3024 by which a fragment must grow to reach it's destination. */
3027 md_estimate_size_before_relax (fragP
, segment_type
)
3028 register fragS
*fragP
;
3029 register segT segment_type
;
3031 switch (fragP
->fr_subtype
)
3033 case C (UNCOND_JUMP
, UNDEF_DISP
):
3034 /* Used to be a branch to somewhere which was unknown. */
3035 if (!fragP
->fr_symbol
)
3037 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
3038 fragP
->fr_var
= md_relax_table
[C (UNCOND_JUMP
, UNCOND12
)].rlx_length
;
3040 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
3042 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
3043 fragP
->fr_var
= md_relax_table
[C (UNCOND_JUMP
, UNCOND12
)].rlx_length
;
3047 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNDEF_WORD_DISP
);
3048 fragP
->fr_var
= md_relax_table
[C (UNCOND_JUMP
, UNCOND32
)].rlx_length
;
3049 return md_relax_table
[C (UNCOND_JUMP
, UNCOND32
)].rlx_length
;
3055 case C (COND_JUMP
, UNDEF_DISP
):
3056 case C (COND_JUMP_DELAY
, UNDEF_DISP
):
3057 /* Used to be a branch to somewhere which was unknown. */
3058 if (fragP
->fr_symbol
3059 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
3061 int what
= GET_WHAT (fragP
->fr_subtype
);
3062 /* Got a symbol and it's defined in this segment, become byte
3063 sized - maybe it will fix up. */
3064 fragP
->fr_subtype
= C (what
, COND8
);
3065 fragP
->fr_var
= md_relax_table
[C (what
, COND8
)].rlx_length
;
3067 else if (fragP
->fr_symbol
)
3069 int what
= GET_WHAT (fragP
->fr_subtype
);
3070 /* Its got a segment, but its not ours, so it will always be long. */
3071 fragP
->fr_subtype
= C (what
, UNDEF_WORD_DISP
);
3072 fragP
->fr_var
= md_relax_table
[C (what
, COND32
)].rlx_length
;
3073 return md_relax_table
[C (what
, COND32
)].rlx_length
;
3077 int what
= GET_WHAT (fragP
->fr_subtype
);
3078 /* We know the abs value. */
3079 fragP
->fr_subtype
= C (what
, COND8
);
3080 fragP
->fr_var
= md_relax_table
[C (what
, COND8
)].rlx_length
;
3085 return fragP
->fr_var
;
3088 /* Put number into target byte order. */
3091 md_number_to_chars (ptr
, use
, nbytes
)
3096 if (! target_big_endian
)
3097 number_to_chars_littleendian (ptr
, use
, nbytes
);
3099 number_to_chars_bigendian (ptr
, use
, nbytes
);
3103 md_pcrel_from (fixP
)
3106 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
+ 2;
3112 tc_coff_sizemachdep (frag
)
3115 return md_relax_table
[frag
->fr_subtype
].rlx_length
;
3118 #endif /* OBJ_COFF */
3120 #ifndef BFD_ASSEMBLER
3123 /* Map BFD relocs to SH COFF relocs. */
3127 bfd_reloc_code_real_type bfd_reloc
;
3131 static const struct reloc_map coff_reloc_map
[] =
3133 { BFD_RELOC_32
, R_SH_IMM32
},
3134 { BFD_RELOC_16
, R_SH_IMM16
},
3135 { BFD_RELOC_8
, R_SH_IMM8
},
3136 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_PCDISP8BY2
},
3137 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_PCDISP
},
3138 { BFD_RELOC_SH_IMM4
, R_SH_IMM4
},
3139 { BFD_RELOC_SH_IMM4BY2
, R_SH_IMM4BY2
},
3140 { BFD_RELOC_SH_IMM4BY4
, R_SH_IMM4BY4
},
3141 { BFD_RELOC_SH_IMM8
, R_SH_IMM8
},
3142 { BFD_RELOC_SH_IMM8BY2
, R_SH_IMM8BY2
},
3143 { BFD_RELOC_SH_IMM8BY4
, R_SH_IMM8BY4
},
3144 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_PCRELIMM8BY2
},
3145 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_PCRELIMM8BY4
},
3146 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
3147 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
3148 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
3149 { BFD_RELOC_SH_USES
, R_SH_USES
},
3150 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
3151 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
3152 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
3153 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
3154 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
3155 { BFD_RELOC_UNUSED
, 0 }
3158 /* Adjust a reloc for the SH. This is similar to the generic code,
3159 but does some minor tweaking. */
3162 sh_coff_reloc_mangle (seg
, fix
, intr
, paddr
)
3163 segment_info_type
*seg
;
3165 struct internal_reloc
*intr
;
3168 symbolS
*symbol_ptr
= fix
->fx_addsy
;
3171 intr
->r_vaddr
= paddr
+ fix
->fx_frag
->fr_address
+ fix
->fx_where
;
3173 if (! SWITCH_TABLE (fix
))
3175 const struct reloc_map
*rm
;
3177 for (rm
= coff_reloc_map
; rm
->bfd_reloc
!= BFD_RELOC_UNUSED
; rm
++)
3178 if (rm
->bfd_reloc
== (bfd_reloc_code_real_type
) fix
->fx_r_type
)
3180 if (rm
->bfd_reloc
== BFD_RELOC_UNUSED
)
3181 as_bad_where (fix
->fx_file
, fix
->fx_line
,
3182 _("Can not represent %s relocation in this object file format"),
3183 bfd_get_reloc_code_name (fix
->fx_r_type
));
3184 intr
->r_type
= rm
->sh_reloc
;
3191 if (fix
->fx_r_type
== BFD_RELOC_16
)
3192 intr
->r_type
= R_SH_SWITCH16
;
3193 else if (fix
->fx_r_type
== BFD_RELOC_8
)
3194 intr
->r_type
= R_SH_SWITCH8
;
3195 else if (fix
->fx_r_type
== BFD_RELOC_32
)
3196 intr
->r_type
= R_SH_SWITCH32
;
3200 /* For a switch reloc, we set r_offset to the difference between
3201 the reloc address and the subtrahend. When the linker is
3202 doing relaxing, it can use the determine the starting and
3203 ending points of the switch difference expression. */
3204 intr
->r_offset
= intr
->r_vaddr
- S_GET_VALUE (fix
->fx_subsy
);
3207 /* PC relative relocs are always against the current section. */
3208 if (symbol_ptr
== NULL
)
3210 switch (fix
->fx_r_type
)
3212 case BFD_RELOC_SH_PCRELIMM8BY2
:
3213 case BFD_RELOC_SH_PCRELIMM8BY4
:
3214 case BFD_RELOC_SH_PCDISP8BY2
:
3215 case BFD_RELOC_SH_PCDISP12BY2
:
3216 case BFD_RELOC_SH_USES
:
3217 symbol_ptr
= seg
->dot
;
3224 if (fix
->fx_r_type
== BFD_RELOC_SH_USES
)
3226 /* We can't store the offset in the object file, since this
3227 reloc does not take up any space, so we store it in r_offset.
3228 The fx_addnumber field was set in md_apply_fix. */
3229 intr
->r_offset
= fix
->fx_addnumber
;
3231 else if (fix
->fx_r_type
== BFD_RELOC_SH_COUNT
)
3233 /* We can't store the count in the object file, since this reloc
3234 does not take up any space, so we store it in r_offset. The
3235 fx_offset field was set when the fixup was created in
3236 sh_coff_frob_file. */
3237 intr
->r_offset
= fix
->fx_offset
;
3238 /* This reloc is always absolute. */
3241 else if (fix
->fx_r_type
== BFD_RELOC_SH_ALIGN
)
3243 /* Store the alignment in the r_offset field. */
3244 intr
->r_offset
= fix
->fx_offset
;
3245 /* This reloc is always absolute. */
3248 else if (fix
->fx_r_type
== BFD_RELOC_SH_CODE
3249 || fix
->fx_r_type
== BFD_RELOC_SH_DATA
3250 || fix
->fx_r_type
== BFD_RELOC_SH_LABEL
)
3252 /* These relocs are always absolute. */
3256 /* Turn the segment of the symbol into an offset. */
3257 if (symbol_ptr
!= NULL
)
3259 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
3261 intr
->r_symndx
= dot
->sy_number
;
3263 intr
->r_symndx
= symbol_ptr
->sy_number
;
3266 intr
->r_symndx
= -1;
3269 #endif /* OBJ_COFF */
3270 #endif /* ! BFD_ASSEMBLER */
3272 #ifdef BFD_ASSEMBLER
3274 /* Create a reloc. */
3277 tc_gen_reloc (section
, fixp
)
3278 asection
*section ATTRIBUTE_UNUSED
;
3282 bfd_reloc_code_real_type r_type
;
3284 rel
= (arelent
*) xmalloc (sizeof (arelent
));
3285 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3286 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3287 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3289 r_type
= fixp
->fx_r_type
;
3291 if (SWITCH_TABLE (fixp
))
3293 rel
->addend
= rel
->address
- S_GET_VALUE (fixp
->fx_subsy
);
3294 if (r_type
== BFD_RELOC_16
)
3295 r_type
= BFD_RELOC_SH_SWITCH16
;
3296 else if (r_type
== BFD_RELOC_8
)
3297 r_type
= BFD_RELOC_8_PCREL
;
3298 else if (r_type
== BFD_RELOC_32
)
3299 r_type
= BFD_RELOC_SH_SWITCH32
;
3303 else if (r_type
== BFD_RELOC_SH_USES
)
3304 rel
->addend
= fixp
->fx_addnumber
;
3305 else if (r_type
== BFD_RELOC_SH_COUNT
)
3306 rel
->addend
= fixp
->fx_offset
;
3307 else if (r_type
== BFD_RELOC_SH_ALIGN
)
3308 rel
->addend
= fixp
->fx_offset
;
3309 else if (r_type
== BFD_RELOC_VTABLE_INHERIT
3310 || r_type
== BFD_RELOC_VTABLE_ENTRY
)
3311 rel
->addend
= fixp
->fx_offset
;
3312 else if (r_type
== BFD_RELOC_SH_LOOP_START
3313 || r_type
== BFD_RELOC_SH_LOOP_END
)
3314 rel
->addend
= fixp
->fx_offset
;
3315 else if (r_type
== BFD_RELOC_SH_LABEL
&& fixp
->fx_pcrel
)
3318 rel
->address
= rel
->addend
= fixp
->fx_offset
;
3320 else if (fixp
->fx_pcrel
)
3321 rel
->addend
= fixp
->fx_addnumber
;
3322 else if (r_type
== BFD_RELOC_32
|| r_type
== BFD_RELOC_32_GOTOFF
)
3323 rel
->addend
= fixp
->fx_addnumber
;
3327 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
3328 if (rel
->howto
== NULL
)
3330 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3331 _("Cannot represent relocation type %s"),
3332 bfd_get_reloc_code_name (r_type
));
3333 /* Set howto to a garbage value so that we can keep going. */
3334 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
3335 assert (rel
->howto
!= NULL
);
3341 #endif /* BFD_ASSEMBLER */