1 /* tc-sh.c -- Assemble code for the Hitachi Super-H
2 Copyright (C) 1993, 94, 95, 96, 97, 98, 99, 2000 Free Software Foundation.
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 2, 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Written By Steve Chamberlain <sac@cygnus.com> */
28 #include "opcodes/sh-opc.h"
30 #include "struc-symbol.h"
36 #include "dwarf2dbg.h"
37 struct dwarf2_line_info debug_line
;
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 { "file", dwarf2_directive_file
, 0 },
97 { "loc", dwarf2_directive_loc
, 0 },
101 /*int md_reloc_size; */
103 int sh_relax
; /* set if -relax seen */
105 /* Whether -small was seen. */
109 /* Whether -dsp was seen. */
113 /* The bit mask of architectures that could
114 accomodate the insns seen so far. */
115 static int valid_arch
;
117 const char EXP_CHARS
[] = "eE";
119 /* Chars that mean this number is a floating point constant. */
122 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
124 #define C(a,b) ENCODE_RELAX(a,b)
126 #define ENCODE_RELAX(what,length) (((what) << 4) + (length))
127 #define GET_WHAT(x) ((x>>4))
129 /* These are the three types of relaxable instrction. */
131 #define COND_JUMP_DELAY 2
132 #define UNCOND_JUMP 3
141 #define UNDEF_WORD_DISP 4
146 /* Branch displacements are from the address of the branch plus
147 four, thus all minimum and maximum values have 4 added to them. */
150 #define COND8_LENGTH 2
152 /* There is one extra instruction before the branch, so we must add
153 two more bytes to account for it. */
154 #define COND12_F 4100
155 #define COND12_M -4090
156 #define COND12_LENGTH 6
158 #define COND12_DELAY_LENGTH 4
160 /* ??? The minimum and maximum values are wrong, but this does not matter
161 since this relocation type is not supported yet. */
162 #define COND32_F (1<<30)
163 #define COND32_M -(1<<30)
164 #define COND32_LENGTH 14
166 #define UNCOND12_F 4098
167 #define UNCOND12_M -4092
168 #define UNCOND12_LENGTH 2
170 /* ??? The minimum and maximum values are wrong, but this does not matter
171 since this relocation type is not supported yet. */
172 #define UNCOND32_F (1<<30)
173 #define UNCOND32_M -(1<<30)
174 #define UNCOND32_LENGTH 14
176 #define EMPTY { 0, 0, 0, 0 }
178 const relax_typeS md_relax_table
[C (END
, 0)] = {
179 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
180 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
183 /* C (COND_JUMP, COND8) */
184 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP
, COND12
) },
185 /* C (COND_JUMP, COND12) */
186 { COND12_F
, COND12_M
, COND12_LENGTH
, C (COND_JUMP
, COND32
), },
187 /* C (COND_JUMP, COND32) */
188 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
189 EMPTY
, EMPTY
, EMPTY
, EMPTY
,
190 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
193 /* C (COND_JUMP_DELAY, COND8) */
194 { COND8_F
, COND8_M
, COND8_LENGTH
, C (COND_JUMP_DELAY
, COND12
) },
195 /* C (COND_JUMP_DELAY, COND12) */
196 { COND12_F
, COND12_M
, COND12_DELAY_LENGTH
, C (COND_JUMP_DELAY
, COND32
), },
197 /* C (COND_JUMP_DELAY, COND32) */
198 { COND32_F
, COND32_M
, COND32_LENGTH
, 0, },
199 EMPTY
, EMPTY
, EMPTY
, EMPTY
,
200 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
203 /* C (UNCOND_JUMP, UNCOND12) */
204 { UNCOND12_F
, UNCOND12_M
, UNCOND12_LENGTH
, C (UNCOND_JUMP
, UNCOND32
), },
205 /* C (UNCOND_JUMP, UNCOND32) */
206 { UNCOND32_F
, UNCOND32_M
, UNCOND32_LENGTH
, 0, },
207 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
208 EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
, EMPTY
,
213 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics */
217 /* Parse @got, etc. and return the desired relocation.
218 If we have additional arithmetic expression, then we fill in new_exp_p. */
219 static bfd_reloc_code_real_type
220 sh_elf_suffix (str_p
, exp_p
, new_exp_p
)
222 expressionS
*exp_p
, *new_exp_p
;
227 bfd_reloc_code_real_type reloc
;
237 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
239 static struct map_bfd mapping
[] = {
240 MAP ("got", BFD_RELOC_32_GOT_PCREL
),
241 MAP ("plt", BFD_RELOC_32_PLT_PCREL
),
242 MAP ("gotoff", BFD_RELOC_32_GOTOFF
),
243 { (char *)0, 0, BFD_RELOC_UNUSED
}
247 return BFD_RELOC_UNUSED
;
249 for (ch
= *str
, str2
= ident
;
250 (str2
< ident
+ sizeof (ident
) - 1
251 && (isalnum (ch
) || ch
== '@'));
254 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
261 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
262 if (ch
== ptr
->string
[0]
263 && len
== ptr
->length
264 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
266 /* Now check for identifier@suffix+constant */
267 if (*str
== '-' || *str
== '+')
269 char *orig_line
= input_line_pointer
;
271 input_line_pointer
= str
;
272 expression (new_exp_p
);
273 if (new_exp_p
->X_op
== O_constant
)
275 exp_p
->X_add_number
+= new_exp_p
->X_add_number
;
276 str
= input_line_pointer
;
278 if (new_exp_p
->X_op
== O_subtract
)
279 str
= input_line_pointer
;
281 if (&input_line_pointer
!= str_p
)
282 input_line_pointer
= orig_line
;
289 return BFD_RELOC_UNUSED
;
292 /* The regular cons() function, that reads constants, doesn't support
293 suffixes such as @GOT, @GOTOFF and @PLT, that generate
294 machine-specific relocation types. So we must define it here. */
295 /* Clobbers input_line_pointer, checks end-of-line. */
298 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
300 expressionS exp
, new_exp
;
301 bfd_reloc_code_real_type reloc
;
304 if (is_it_end_of_statement ())
306 demand_empty_rest_of_line ();
313 new_exp
.X_op
= O_absent
;
314 new_exp
.X_add_symbol
= new_exp
.X_op_symbol
= NULL
;
315 /* If the _GLOBAL_OFFSET_TABLE_ symbol hasn't been found yet,
316 use the name of the symbol to tell whether it's the
317 _GLOBAL_OFFSET_TABLE_. If it has, comparing the symbols is
319 if (! GOT_symbol
&& exp
.X_add_symbol
)
320 name
= S_GET_NAME (exp
.X_add_symbol
);
323 /* Check whether this expression involves the
324 _GLOBAL_OFFSET_TABLE_ symbol, by itself or added to a
325 difference of two other symbols. */
326 if (((GOT_symbol
&& GOT_symbol
== exp
.X_add_symbol
)
327 || (! GOT_symbol
&& name
328 && strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0))
329 && (exp
.X_op
== O_symbol
330 || (exp
.X_op
== O_add
331 && ((symbol_get_value_expression (exp
.X_op_symbol
)->X_op
)
334 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
336 int size
= bfd_get_reloc_size (reloc_howto
);
338 if (GOT_symbol
== NULL
)
339 GOT_symbol
= symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME
);
342 as_bad (_("%s relocations do not fit in %d bytes\n"),
343 reloc_howto
->name
, nbytes
);
346 register char *p
= frag_more ((int) nbytes
);
347 int offset
= nbytes
- size
;
349 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
,
350 size
, &exp
, 0, TC_RELOC_GLOBAL_OFFSET_TABLE
);
353 /* Check if this symbol involves one of the magic suffixes, such
354 as @GOT, @GOTOFF or @PLT, and determine which relocation type
356 else if ((exp
.X_op
== O_symbol
|| (exp
.X_op
== O_add
&& exp
.X_op_symbol
))
357 && *input_line_pointer
== '@'
358 && ((reloc
= sh_elf_suffix (&input_line_pointer
, &exp
, &new_exp
))
359 != BFD_RELOC_UNUSED
))
361 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
,
363 int size
= bfd_get_reloc_size (reloc_howto
);
365 /* Force a GOT to be generated. */
366 if (GOT_symbol
== NULL
)
367 GOT_symbol
= symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME
);
370 as_bad (_("%s relocations do not fit in %d bytes\n"),
371 reloc_howto
->name
, nbytes
);
374 register char *p
= frag_more ((int) nbytes
);
375 int offset
= nbytes
- size
;
377 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
379 if (new_exp
.X_op
!= O_absent
)
380 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
381 &new_exp
, 0, BFD_RELOC_32
);
385 emit_expr (&exp
, (unsigned int) nbytes
);
387 while (*input_line_pointer
++ == ',');
389 input_line_pointer
--; /* Put terminator back into stream. */
390 if (*input_line_pointer
== '#' || *input_line_pointer
== '!')
392 while (! is_end_of_line
[*input_line_pointer
++]);
395 demand_empty_rest_of_line ();
400 /* This function is called once, at assembler startup time. This should
401 set up all the tables, etc that the MD part of the assembler needs. */
406 sh_opcode_info
*opcode
;
407 char *prev_name
= "";
411 /* The WinCE OS only supports little endian executables. */
412 target_big_endian
= 0;
415 target_big_endian
= 1;
418 target_arch
= arch_sh1_up
& ~(sh_dsp
? arch_sh3e_up
: arch_sh_dsp_up
);
419 valid_arch
= target_arch
;
421 opcode_hash_control
= hash_new ();
423 /* Insert unique names into hash table. */
424 for (opcode
= sh_table
; opcode
->name
; opcode
++)
426 if (strcmp (prev_name
, opcode
->name
))
428 if (! (opcode
->arch
& target_arch
))
430 prev_name
= opcode
->name
;
431 hash_insert (opcode_hash_control
, opcode
->name
, (char *) opcode
);
435 /* Make all the opcodes with the same name point to the same
437 opcode
->name
= prev_name
;
444 static int reg_x
, reg_y
;
452 expressionS immediate
;
456 #define IDENT_CHAR(c) (isalnum (c) || (c) == '_')
458 /* Try to parse a reg name. Return the number of chars consumed. */
461 parse_reg (src
, mode
, reg
)
466 /* We use ! IDENT_CHAR for the next character after the register name, to
467 make sure that we won't accidentally recognize a symbol name such as
468 'sram' or sr_ram as being a reference to the register 'sr'. */
474 if (src
[2] >= '0' && src
[2] <= '5'
475 && ! IDENT_CHAR ((unsigned char) src
[3]))
478 *reg
= 10 + src
[2] - '0';
482 if (src
[1] >= '0' && src
[1] <= '9'
483 && ! IDENT_CHAR ((unsigned char) src
[2]))
486 *reg
= (src
[1] - '0');
489 if (src
[1] >= '0' && src
[1] <= '7' && strncmp (&src
[2], "_bank", 5) == 0
490 && ! IDENT_CHAR ((unsigned char) src
[7]))
493 *reg
= (src
[1] - '0');
497 if (src
[1] == 'e' && ! IDENT_CHAR ((unsigned char) src
[2]))
502 if (src
[1] == 's' && ! IDENT_CHAR ((unsigned char) src
[2]))
513 if (! IDENT_CHAR ((unsigned char) src
[2]))
519 if (src
[2] == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
528 if (! IDENT_CHAR ((unsigned char) src
[2]))
534 if (src
[2] == 'g' && ! IDENT_CHAR ((unsigned char) src
[3]))
542 if (src
[1] == 'x' && src
[2] >= '0' && src
[2] <= '1'
543 && ! IDENT_CHAR ((unsigned char) src
[3]))
546 *reg
= 4 + (src
[1] - '0');
549 if (src
[1] == 'y' && src
[2] >= '0' && src
[2] <= '1'
550 && ! IDENT_CHAR ((unsigned char) src
[3]))
553 *reg
= 6 + (src
[1] - '0');
556 if (src
[1] == 's' && src
[2] >= '0' && src
[2] <= '3'
557 && ! IDENT_CHAR ((unsigned char) src
[3]))
559 int n
= src
[1] - '0';
562 *reg
= n
| ((~n
& 2) << 1);
567 if (src
[0] == 'i' && src
[1] && ! IDENT_CHAR ((unsigned char) src
[3]))
589 if (src
[0] == 'x' && src
[1] >= '0' && src
[1] <= '1'
590 && ! IDENT_CHAR ((unsigned char) src
[2]))
593 *reg
= A_X0_NUM
+ src
[1] - '0';
597 if (src
[0] == 'y' && src
[1] >= '0' && src
[1] <= '1'
598 && ! IDENT_CHAR ((unsigned char) src
[2]))
601 *reg
= A_Y0_NUM
+ src
[1] - '0';
605 if (src
[0] == 'm' && src
[1] >= '0' && src
[1] <= '1'
606 && ! IDENT_CHAR ((unsigned char) src
[2]))
609 *reg
= src
[1] == '0' ? A_M0_NUM
: A_M1_NUM
;
615 && src
[2] == 'r' && ! IDENT_CHAR ((unsigned char) src
[3]))
621 if (src
[0] == 's' && src
[1] == 'p' && src
[2] == 'c'
622 && ! IDENT_CHAR ((unsigned char) src
[3]))
628 if (src
[0] == 's' && src
[1] == 'g' && src
[2] == 'r'
629 && ! IDENT_CHAR ((unsigned char) src
[3]))
635 if (src
[0] == 'd' && src
[1] == 's' && src
[2] == 'r'
636 && ! IDENT_CHAR ((unsigned char) src
[3]))
642 if (src
[0] == 'd' && src
[1] == 'b' && src
[2] == 'r'
643 && ! IDENT_CHAR ((unsigned char) src
[3]))
649 if (src
[0] == 's' && src
[1] == 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
655 if (src
[0] == 's' && src
[1] == 'p' && ! IDENT_CHAR ((unsigned char) src
[2]))
662 if (src
[0] == 'p' && src
[1] == 'r' && ! IDENT_CHAR ((unsigned char) src
[2]))
667 if (src
[0] == 'p' && src
[1] == 'c' && ! IDENT_CHAR ((unsigned char) src
[2]))
669 /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0'
670 and use an uninitialized immediate. */
674 if (src
[0] == 'g' && src
[1] == 'b' && src
[2] == 'r'
675 && ! IDENT_CHAR ((unsigned char) src
[3]))
680 if (src
[0] == 'v' && src
[1] == 'b' && src
[2] == 'r'
681 && ! IDENT_CHAR ((unsigned char) src
[3]))
687 if (src
[0] == 'm' && src
[1] == 'a' && src
[2] == 'c'
688 && ! IDENT_CHAR ((unsigned char) src
[4]))
701 if (src
[0] == 'm' && src
[1] == 'o' && src
[2] == 'd'
702 && ! IDENT_CHAR ((unsigned char) src
[4]))
707 if (src
[0] == 'f' && src
[1] == 'r')
711 if (src
[3] >= '0' && src
[3] <= '5'
712 && ! IDENT_CHAR ((unsigned char) src
[4]))
715 *reg
= 10 + src
[3] - '0';
719 if (src
[2] >= '0' && src
[2] <= '9'
720 && ! IDENT_CHAR ((unsigned char) src
[3]))
723 *reg
= (src
[2] - '0');
727 if (src
[0] == 'd' && src
[1] == 'r')
731 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
732 && ! IDENT_CHAR ((unsigned char) src
[4]))
735 *reg
= 10 + src
[3] - '0';
739 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
740 && ! IDENT_CHAR ((unsigned char) src
[3]))
743 *reg
= (src
[2] - '0');
747 if (src
[0] == 'x' && src
[1] == 'd')
751 if (src
[3] >= '0' && src
[3] <= '4' && ! ((src
[3] - '0') & 1)
752 && ! IDENT_CHAR ((unsigned char) src
[4]))
755 *reg
= 11 + src
[3] - '0';
759 if (src
[2] >= '0' && src
[2] <= '8' && ! ((src
[2] - '0') & 1)
760 && ! IDENT_CHAR ((unsigned char) src
[3]))
763 *reg
= (src
[2] - '0') + 1;
767 if (src
[0] == 'f' && src
[1] == 'v')
769 if (src
[2] == '1'&& src
[3] == '2' && ! IDENT_CHAR ((unsigned char) src
[4]))
775 if ((src
[2] == '0' || src
[2] == '4' || src
[2] == '8')
776 && ! IDENT_CHAR ((unsigned char) src
[3]))
779 *reg
= (src
[2] - '0');
783 if (src
[0] == 'f' && src
[1] == 'p' && src
[2] == 'u' && src
[3] == 'l'
784 && ! IDENT_CHAR ((unsigned char) src
[4]))
790 if (src
[0] == 'f' && src
[1] == 'p' && src
[2] == 's' && src
[3] == 'c'
791 && src
[4] == 'r' && ! IDENT_CHAR ((unsigned char) src
[5]))
797 if (src
[0] == 'x' && src
[1] == 'm' && src
[2] == 't' && src
[3] == 'r'
798 && src
[4] == 'x' && ! IDENT_CHAR ((unsigned char) src
[5]))
812 /* JF: '.' is pseudo symbol with value of current location
813 in current segment. */
814 fake
= FAKE_LABEL_NAME
;
815 return symbol_new (fake
,
817 (valueT
) frag_now_fix (),
829 save
= input_line_pointer
;
830 input_line_pointer
= s
;
831 expression (&op
->immediate
);
832 if (op
->immediate
.X_op
== O_absent
)
833 as_bad (_("missing operand"));
834 new = input_line_pointer
;
835 input_line_pointer
= save
;
839 /* The many forms of operand:
842 @Rn Register indirect
855 pr, gbr, vbr, macl, mach
868 /* Must be predecrement. */
871 len
= parse_reg (src
, &mode
, &(op
->reg
));
873 as_bad (_("illegal register after @-"));
878 else if (src
[0] == '(')
880 /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
883 len
= parse_reg (src
, &mode
, &(op
->reg
));
884 if (len
&& mode
== A_REG_N
)
889 as_bad (_("must be @(r0,...)"));
893 /* Now can be rn or gbr */
894 len
= parse_reg (src
, &mode
, &(op
->reg
));
899 else if (mode
== A_REG_N
)
901 op
->type
= A_IND_R0_REG_N
;
905 as_bad (_("syntax error in @(r0,...)"));
910 /* Must be an @(disp,.. thing) */
911 src
= parse_exp (src
, op
);
914 /* Now can be rn, gbr or pc */
915 len
= parse_reg (src
, &mode
, &op
->reg
);
920 op
->type
= A_DISP_REG_N
;
922 else if (mode
== A_GBR
)
924 op
->type
= A_DISP_GBR
;
926 else if (mode
== A_PC
)
928 /* Turn a plain @(4,pc) into @(.+4,pc). */
929 if (op
->immediate
.X_op
== O_constant
)
931 op
->immediate
.X_add_symbol
= dot();
932 op
->immediate
.X_op
= O_symbol
;
934 op
->type
= A_DISP_PC
;
938 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
943 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
948 as_bad (_("expecting )"));
954 src
+= parse_reg (src
, &mode
, &(op
->reg
));
957 as_bad (_("illegal register after @"));
962 if ((src
[0] == 'r' && src
[1] == '8')
963 || (src
[0] == 'i' && (src
[1] == 'x' || src
[1] == 's')))
968 if ((src
[0] == 'r' && src
[1] == '9')
969 || (src
[0] == 'i' && src
[1] == 'y'))
972 op
->type
= A_PMODY_N
;
986 get_operand (ptr
, op
)
997 *ptr
= parse_exp (src
, op
);
1002 else if (src
[0] == '@')
1004 *ptr
= parse_at (src
, op
);
1007 len
= parse_reg (src
, &mode
, &(op
->reg
));
1016 /* Not a reg, the only thing left is a displacement. */
1017 *ptr
= parse_exp (src
, op
);
1018 op
->type
= A_DISP_PC
;
1024 get_operands (info
, args
, operand
)
1025 sh_opcode_info
*info
;
1027 sh_operand_info
*operand
;
1032 /* The pre-processor will eliminate whitespace in front of '@'
1033 after the first argument; we may be called multiple times
1034 from assemble_ppi, so don't insist on finding whitespace here. */
1038 get_operand (&ptr
, operand
+ 0);
1045 get_operand (&ptr
, operand
+ 1);
1046 /* ??? Hack: psha/pshl have a varying operand number depending on
1047 the type of the first operand. We handle this by having the
1048 three-operand version first and reducing the number of operands
1049 parsed to two if we see that the first operand is an immediate.
1050 This works because no insn with three operands has an immediate
1051 as first operand. */
1052 if (info
->arg
[2] && operand
[0].type
!= A_IMM
)
1058 get_operand (&ptr
, operand
+ 2);
1062 operand
[2].type
= 0;
1067 operand
[1].type
= 0;
1068 operand
[2].type
= 0;
1073 operand
[0].type
= 0;
1074 operand
[1].type
= 0;
1075 operand
[2].type
= 0;
1080 /* Passed a pointer to a list of opcodes which use different
1081 addressing modes, return the opcode which matches the opcodes
1084 static sh_opcode_info
*
1085 get_specific (opcode
, operands
)
1086 sh_opcode_info
*opcode
;
1087 sh_operand_info
*operands
;
1089 sh_opcode_info
*this_try
= opcode
;
1090 char *name
= opcode
->name
;
1093 while (opcode
->name
)
1095 this_try
= opcode
++;
1096 if (this_try
->name
!= name
)
1098 /* We've looked so far down the table that we've run out of
1099 opcodes with the same name. */
1103 /* Look at both operands needed by the opcodes and provided by
1104 the user - since an arg test will often fail on the same arg
1105 again and again, we'll try and test the last failing arg the
1106 first on each opcode try. */
1107 for (n
= 0; this_try
->arg
[n
]; n
++)
1109 sh_operand_info
*user
= operands
+ n
;
1110 sh_arg_type arg
= this_try
->arg
[n
];
1122 if (user
->type
!= arg
)
1126 /* opcode needs r0 */
1127 if (user
->type
!= A_REG_N
|| user
->reg
!= 0)
1131 if (user
->type
!= A_R0_GBR
|| user
->reg
!= 0)
1135 if (user
->type
!= F_REG_N
|| user
->reg
!= 0)
1143 case A_IND_R0_REG_N
:
1154 /* Opcode needs rn */
1155 if (user
->type
!= arg
)
1160 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
1175 if (user
->type
!= arg
)
1180 if (user
->type
!= arg
)
1189 case A_IND_R0_REG_M
:
1192 /* Opcode needs rn */
1193 if (user
->type
!= arg
- A_REG_M
+ A_REG_N
)
1199 if (user
->type
!= DSP_REG_N
)
1221 if (user
->type
!= DSP_REG_N
)
1243 if (user
->type
!= DSP_REG_N
)
1265 if (user
->type
!= DSP_REG_N
)
1287 if (user
->type
!= DSP_REG_N
)
1309 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_A0_NUM
)
1313 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X0_NUM
)
1317 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_X1_NUM
)
1321 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y0_NUM
)
1325 if (user
->type
!= DSP_REG_N
|| user
->reg
!= A_Y1_NUM
)
1335 /* Opcode needs rn */
1336 if (user
->type
!= arg
- F_REG_M
+ F_REG_N
)
1341 if (user
->type
!= D_REG_N
&& user
->type
!= X_REG_N
)
1346 if (user
->type
!= XMTRX_M4
)
1352 printf (_("unhandled %d\n"), arg
);
1356 if ( !(valid_arch
& this_try
->arch
))
1358 valid_arch
&= this_try
->arch
;
1368 check (operand
, low
, high
)
1369 expressionS
*operand
;
1373 if (operand
->X_op
!= O_constant
1374 || operand
->X_add_number
< low
1375 || operand
->X_add_number
> high
)
1377 as_bad (_("operand must be absolute in range %d..%d"), low
, high
);
1379 return operand
->X_add_number
;
1383 insert (where
, how
, pcrel
, op
)
1387 sh_operand_info
*op
;
1389 fix_new_exp (frag_now
,
1390 where
- frag_now
->fr_literal
,
1398 build_relax (opcode
, op
)
1399 sh_opcode_info
*opcode
;
1400 sh_operand_info
*op
;
1402 int high_byte
= target_big_endian
? 0 : 1;
1405 if (opcode
->arg
[0] == A_BDISP8
)
1407 int what
= (opcode
->nibbles
[1] & 4) ? COND_JUMP_DELAY
: COND_JUMP
;
1408 p
= frag_var (rs_machine_dependent
,
1409 md_relax_table
[C (what
, COND32
)].rlx_length
,
1410 md_relax_table
[C (what
, COND8
)].rlx_length
,
1412 op
->immediate
.X_add_symbol
,
1413 op
->immediate
.X_add_number
,
1415 p
[high_byte
] = (opcode
->nibbles
[0] << 4) | (opcode
->nibbles
[1]);
1417 else if (opcode
->arg
[0] == A_BDISP12
)
1419 p
= frag_var (rs_machine_dependent
,
1420 md_relax_table
[C (UNCOND_JUMP
, UNCOND32
)].rlx_length
,
1421 md_relax_table
[C (UNCOND_JUMP
, UNCOND12
)].rlx_length
,
1423 op
->immediate
.X_add_symbol
,
1424 op
->immediate
.X_add_number
,
1426 p
[high_byte
] = (opcode
->nibbles
[0] << 4);
1431 /* Insert ldrs & ldre with fancy relocations that relaxation can recognize. */
1434 insert_loop_bounds (output
, operand
)
1436 sh_operand_info
*operand
;
1441 /* Since the low byte of the opcode will be overwritten by the reloc, we
1442 can just stash the high byte into both bytes and ignore endianness. */
1445 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
1446 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
1450 static int count
= 0;
1452 /* If the last loop insn is a two-byte-insn, it is in danger of being
1453 swapped with the insn after it. To prevent this, create a new
1454 symbol - complete with SH_LABEL reloc - after the last loop insn.
1455 If the last loop insn is four bytes long, the symbol will be
1456 right in the middle, but four byte insns are not swapped anyways. */
1457 /* A REPEAT takes 6 bytes. The SH has a 32 bit address space.
1458 Hence a 9 digit number should be enough to count all REPEATs. */
1460 sprintf (name
, "_R%x", count
++ & 0x3fffffff);
1461 end_sym
= symbol_new (name
, undefined_section
, 0, &zero_address_frag
);
1462 /* Make this a local symbol. */
1464 SF_SET_LOCAL (end_sym
);
1465 #endif /* OBJ_COFF */
1466 symbol_table_insert (end_sym
);
1467 end_sym
->sy_value
= operand
[1].immediate
;
1468 end_sym
->sy_value
.X_add_number
+= 2;
1469 fix_new (frag_now
, frag_now_fix (), 2, end_sym
, 0, 1, BFD_RELOC_SH_LABEL
);
1472 output
= frag_more (2);
1475 insert (output
, BFD_RELOC_SH_LOOP_START
, 1, operand
);
1476 insert (output
, BFD_RELOC_SH_LOOP_END
, 1, operand
+ 1);
1478 return frag_more (2);
1481 /* Now we know what sort of opcodes it is, let's build the bytes. */
1484 build_Mytes (opcode
, operand
)
1485 sh_opcode_info
*opcode
;
1486 sh_operand_info
*operand
;
1491 char *output
= frag_more (2);
1492 unsigned int size
= 2;
1493 int low_byte
= target_big_endian
? 1 : 0;
1499 for (index
= 0; index
< 4; index
++)
1501 sh_nibble_type i
= opcode
->nibbles
[index
];
1511 nbuf
[index
] = reg_n
;
1514 nbuf
[index
] = reg_m
;
1517 if (reg_n
< 2 || reg_n
> 5)
1518 as_bad (_("Invalid register: 'r%d'"), reg_n
);
1519 nbuf
[index
] = (reg_n
& 3) | 4;
1522 nbuf
[index
] = reg_n
| (reg_m
>> 2);
1525 nbuf
[index
] = reg_b
| 0x08;
1528 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
);
1531 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
);
1534 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
);
1537 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY4
, 0, operand
+ 1);
1540 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4BY2
, 0, operand
+ 1);
1543 insert (output
+ low_byte
, BFD_RELOC_SH_IMM4
, 0, operand
+ 1);
1546 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
);
1549 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
);
1552 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
);
1555 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY4
, 0, operand
+ 1);
1558 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8BY2
, 0, operand
+ 1);
1561 insert (output
+ low_byte
, BFD_RELOC_SH_IMM8
, 0, operand
+ 1);
1564 insert (output
, BFD_RELOC_SH_PCRELIMM8BY4
, 1, operand
);
1567 insert (output
, BFD_RELOC_SH_PCRELIMM8BY2
, 1, operand
);
1570 output
= insert_loop_bounds (output
, operand
);
1571 nbuf
[index
] = opcode
->nibbles
[3];
1575 printf (_("failed for %d\n"), i
);
1579 if (!target_big_endian
)
1581 output
[1] = (nbuf
[0] << 4) | (nbuf
[1]);
1582 output
[0] = (nbuf
[2] << 4) | (nbuf
[3]);
1586 output
[0] = (nbuf
[0] << 4) | (nbuf
[1]);
1587 output
[1] = (nbuf
[2] << 4) | (nbuf
[3]);
1592 /* Find an opcode at the start of *STR_P in the hash table, and set
1593 *STR_P to the first character after the last one read. */
1595 static sh_opcode_info
*
1596 find_cooked_opcode (str_p
)
1600 unsigned char *op_start
;
1601 unsigned char *op_end
;
1605 /* Drop leading whitespace. */
1609 /* Find the op code end.
1610 The pre-processor will eliminate whitespace in front of
1611 any '@' after the first argument; we may be called from
1612 assemble_ppi, so the opcode might be terminated by an '@'. */
1613 for (op_start
= op_end
= (unsigned char *) (str
);
1616 && !is_end_of_line
[*op_end
] && *op_end
!= ' ' && *op_end
!= '@';
1619 unsigned char c
= op_start
[nlen
];
1621 /* The machine independent code will convert CMP/EQ into cmp/EQ
1622 because it thinks the '/' is the end of the symbol. Moreover,
1623 all but the first sub-insn is a parallel processing insn won't
1624 be capitailzed. Instead of hacking up the machine independent
1625 code, we just deal with it here. */
1626 c
= isupper (c
) ? tolower (c
) : c
;
1635 as_bad (_("can't find opcode "));
1637 return (sh_opcode_info
*) hash_find (opcode_hash_control
, name
);
1640 /* Assemble a parallel processing insn. */
1641 #define DDT_BASE 0xf000 /* Base value for double data transfer insns */
1644 assemble_ppi (op_end
, opcode
)
1646 sh_opcode_info
*opcode
;
1656 /* Some insn ignore one or more register fields, e.g. psts machl,a0.
1657 Make sure we encode a defined insn pattern. */
1663 sh_operand_info operand
[3];
1665 if (opcode
->arg
[0] != A_END
)
1666 op_end
= get_operands (opcode
, op_end
, operand
);
1667 opcode
= get_specific (opcode
, operand
);
1670 /* Couldn't find an opcode which matched the operands. */
1671 char *where
= frag_more (2);
1676 as_bad (_("invalid operands for opcode"));
1680 if (opcode
->nibbles
[0] != PPI
)
1681 as_bad (_("insn can't be combined with parallel processing insn"));
1683 switch (opcode
->nibbles
[1])
1688 as_bad (_("multiple movx specifications"));
1693 as_bad (_("multiple movy specifications"));
1699 as_bad (_("multiple movx specifications"));
1700 if (reg_n
< 4 || reg_n
> 5)
1701 as_bad (_("invalid movx address register"));
1702 if (opcode
->nibbles
[2] & 8)
1704 if (reg_m
== A_A1_NUM
)
1706 else if (reg_m
!= A_A0_NUM
)
1707 as_bad (_("invalid movx dsp register"));
1712 as_bad (_("invalid movx dsp register"));
1715 movx
+= ((reg_n
- 4) << 9) + (opcode
->nibbles
[2] << 2) + DDT_BASE
;
1720 as_bad (_("multiple movy specifications"));
1721 if (opcode
->nibbles
[2] & 8)
1723 /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode,
1726 if (reg_m
== A_A1_NUM
)
1728 else if (reg_m
!= A_A0_NUM
)
1729 as_bad (_("invalid movy dsp register"));
1734 as_bad (_("invalid movy dsp register"));
1737 if (reg_n
< 6 || reg_n
> 7)
1738 as_bad (_("invalid movy address register"));
1739 movy
+= ((reg_n
- 6) << 8) + opcode
->nibbles
[2] + DDT_BASE
;
1743 if (operand
[0].immediate
.X_op
!= O_constant
)
1744 as_bad (_("dsp immediate shift value not constant"));
1745 field_b
= ((opcode
->nibbles
[2] << 12)
1746 | (operand
[0].immediate
.X_add_number
& 127) << 4
1751 as_bad (_("multiple parallel processing specifications"));
1752 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
1753 + (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
1757 as_bad (_("multiple condition specifications"));
1758 cond
= opcode
->nibbles
[2] << 8;
1760 goto skip_cond_check
;
1764 as_bad (_("multiple parallel processing specifications"));
1765 field_b
= ((opcode
->nibbles
[2] << 12) + (opcode
->nibbles
[3] << 8)
1766 + cond
+ (reg_x
<< 6) + (reg_y
<< 4) + reg_n
);
1772 if ((field_b
& 0xef00) != 0xa100)
1773 as_bad (_("insn cannot be combined with pmuls"));
1775 switch (field_b
& 0xf)
1778 field_b
+= 0 - A_X0_NUM
;
1781 field_b
+= 1 - A_Y0_NUM
;
1784 field_b
+= 2 - A_A0_NUM
;
1787 field_b
+= 3 - A_A1_NUM
;
1790 as_bad (_("bad padd / psub pmuls output operand"));
1793 field_b
+= 0x4000 + reg_efg
;
1800 as_bad (_("condition not followed by conditionalizable insn"));
1806 opcode
= find_cooked_opcode (&op_end
);
1810 (_("unrecognized characters at end of parallel processing insn")));
1815 move_code
= movx
| movy
;
1818 /* Parallel processing insn. */
1819 unsigned long ppi_code
= (movx
| movy
| 0xf800) << 16 | field_b
;
1821 output
= frag_more (4);
1823 if (! target_big_endian
)
1825 output
[3] = ppi_code
>> 8;
1826 output
[2] = ppi_code
;
1830 output
[2] = ppi_code
>> 8;
1831 output
[3] = ppi_code
;
1833 move_code
|= 0xf800;
1837 /* Just a double data transfer. */
1838 output
= frag_more (2);
1841 if (! target_big_endian
)
1843 output
[1] = move_code
>> 8;
1844 output
[0] = move_code
;
1848 output
[0] = move_code
>> 8;
1849 output
[1] = move_code
;
1854 /* This is the guts of the machine-dependent assembler. STR points to a
1855 machine dependent instruction. This function is supposed to emit
1856 the frags/bytes it assembles to. */
1862 unsigned char *op_end
;
1863 sh_operand_info operand
[3];
1864 sh_opcode_info
*opcode
;
1867 opcode
= find_cooked_opcode (&str
);
1872 as_bad (_("unknown opcode"));
1877 && ! seg_info (now_seg
)->tc_segment_info_data
.in_code
)
1879 /* Output a CODE reloc to tell the linker that the following
1880 bytes are instructions, not data. */
1881 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
1883 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 1;
1886 if (opcode
->nibbles
[0] == PPI
)
1888 size
= assemble_ppi (op_end
, opcode
);
1892 if (opcode
->arg
[0] == A_BDISP12
1893 || opcode
->arg
[0] == A_BDISP8
)
1895 parse_exp (op_end
+ 1, &operand
[0]);
1896 build_relax (opcode
, &operand
[0]);
1900 if (opcode
->arg
[0] == A_END
)
1902 /* Ignore trailing whitespace. If there is any, it has already
1903 been compressed to a single space. */
1909 op_end
= get_operands (opcode
, op_end
, operand
);
1911 opcode
= get_specific (opcode
, operand
);
1915 /* Couldn't find an opcode which matched the operands. */
1916 char *where
= frag_more (2);
1921 as_bad (_("invalid operands for opcode"));
1926 as_bad (_("excess operands: '%s'"), op_end
);
1928 size
= build_Mytes (opcode
, operand
);
1933 if (debug_type
== DEBUG_DWARF2
)
1937 /* First update the notion of the current source line. */
1938 dwarf2_where (&debug_line
);
1940 /* We want the offset of the start of this instruction within the
1941 the current frag. may be used later */
1942 addr
= frag_now
->fr_address
+ frag_now_fix () - size
;
1944 /* And record the information. */
1945 dwarf2_gen_line_info (addr
, &debug_line
);
1949 /* This routine is called each time a label definition is seen. It
1950 emits a BFD_RELOC_SH_LABEL reloc if necessary. */
1955 static fragS
*last_label_frag
;
1956 static int last_label_offset
;
1959 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
1963 offset
= frag_now_fix ();
1964 if (frag_now
!= last_label_frag
1965 || offset
!= last_label_offset
)
1967 fix_new (frag_now
, offset
, 2, &abs_symbol
, 0, 0, BFD_RELOC_SH_LABEL
);
1968 last_label_frag
= frag_now
;
1969 last_label_offset
= offset
;
1974 /* This routine is called when the assembler is about to output some
1975 data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */
1978 sh_flush_pending_output ()
1981 && seg_info (now_seg
)->tc_segment_info_data
.in_code
)
1983 fix_new (frag_now
, frag_now_fix (), 2, &abs_symbol
, 0, 0,
1985 seg_info (now_seg
)->tc_segment_info_data
.in_code
= 0;
1990 md_undefined_symbol (name
)
1994 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. Otherwise we
1995 have no need to default values of symbols. */
1996 if (strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
2000 if (symbol_find (name
))
2001 as_bad ("GOT already in the symbol table");
2003 GOT_symbol
= symbol_new (name
, undefined_section
,
2004 (valueT
)0, & zero_address_frag
);
2009 #endif /* OBJ_ELF */
2015 #ifndef BFD_ASSEMBLER
2018 tc_crawl_symbol_chain (headers
)
2019 object_headers
*headers
;
2021 printf (_("call to tc_crawl_symbol_chain \n"));
2025 tc_headers_hook (headers
)
2026 object_headers
*headers
;
2028 printf (_("call to tc_headers_hook \n"));
2034 /* Various routines to kill one day. */
2035 /* Equal to MAX_PRECISION in atof-ieee.c. */
2036 #define MAX_LITTLENUMS 6
2038 /* Turn a string in input_line_pointer into a floating point constant
2039 of type TYPE, and store the appropriate bytes in *LITP. The number
2040 of LITTLENUMS emitted is stored in *SIZEP . An error message is
2041 returned, or NULL on OK. */
2044 md_atof (type
, litP
, sizeP
)
2050 LITTLENUM_TYPE words
[4];
2066 return _("bad call to md_atof");
2069 t
= atof_ieee (input_line_pointer
, type
, words
);
2071 input_line_pointer
= t
;
2075 if (! target_big_endian
)
2077 for (i
= prec
- 1; i
>= 0; i
--)
2079 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2085 for (i
= 0; i
< prec
; i
++)
2087 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2095 /* Handle the .uses pseudo-op. This pseudo-op is used just before a
2096 call instruction. It refers to a label of the instruction which
2097 loads the register which the call uses. We use it to generate a
2098 special reloc for the linker. */
2102 int ignore ATTRIBUTE_UNUSED
;
2107 as_warn (_(".uses pseudo-op seen when not relaxing"));
2111 if (ex
.X_op
!= O_symbol
|| ex
.X_add_number
!= 0)
2113 as_bad (_("bad .uses format"));
2114 ignore_rest_of_line ();
2118 fix_new_exp (frag_now
, frag_now_fix (), 2, &ex
, 1, BFD_RELOC_SH_USES
);
2120 demand_empty_rest_of_line ();
2123 CONST
char *md_shortopts
= "";
2124 struct option md_longopts
[] =
2126 #define OPTION_RELAX (OPTION_MD_BASE)
2127 #define OPTION_LITTLE (OPTION_MD_BASE + 1)
2128 #define OPTION_SMALL (OPTION_LITTLE + 1)
2129 #define OPTION_DSP (OPTION_SMALL + 1)
2131 {"relax", no_argument
, NULL
, OPTION_RELAX
},
2132 {"little", no_argument
, NULL
, OPTION_LITTLE
},
2133 {"small", no_argument
, NULL
, OPTION_SMALL
},
2134 {"dsp", no_argument
, NULL
, OPTION_DSP
},
2135 {NULL
, no_argument
, NULL
, 0}
2137 size_t md_longopts_size
= sizeof (md_longopts
);
2140 md_parse_option (c
, arg
)
2142 char *arg ATTRIBUTE_UNUSED
;
2152 target_big_endian
= 0;
2171 md_show_usage (stream
)
2174 fprintf (stream
, _("\
2176 -little generate little endian code\n\
2177 -relax alter jump instructions for long displacements\n\
2178 -small align sections to 4 byte boundaries, not 16\n\
2179 -dsp enable sh-dsp insns, and disable sh3e / sh4 insns.\n"));
2183 tc_Nout_fix_to_chars ()
2185 printf (_("call to tc_Nout_fix_to_chars \n"));
2189 /* This struct is used to pass arguments to sh_count_relocs through
2190 bfd_map_over_sections. */
2192 struct sh_count_relocs
2194 /* Symbol we are looking for. */
2196 /* Count of relocs found. */
2200 /* Count the number of fixups in a section which refer to a particular
2201 symbol. When using BFD_ASSEMBLER, this is called via
2202 bfd_map_over_sections. */
2205 sh_count_relocs (abfd
, sec
, data
)
2206 bfd
*abfd ATTRIBUTE_UNUSED
;
2210 struct sh_count_relocs
*info
= (struct sh_count_relocs
*) data
;
2211 segment_info_type
*seginfo
;
2215 seginfo
= seg_info (sec
);
2216 if (seginfo
== NULL
)
2220 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
2222 if (fix
->fx_addsy
== sym
)
2230 /* Handle the count relocs for a particular section. When using
2231 BFD_ASSEMBLER, this is called via bfd_map_over_sections. */
2234 sh_frob_section (abfd
, sec
, ignore
)
2235 bfd
*abfd ATTRIBUTE_UNUSED
;
2237 PTR ignore ATTRIBUTE_UNUSED
;
2239 segment_info_type
*seginfo
;
2242 seginfo
= seg_info (sec
);
2243 if (seginfo
== NULL
)
2246 for (fix
= seginfo
->fix_root
; fix
!= NULL
; fix
= fix
->fx_next
)
2251 struct sh_count_relocs info
;
2253 if (fix
->fx_r_type
!= BFD_RELOC_SH_USES
)
2256 /* The BFD_RELOC_SH_USES reloc should refer to a defined local
2257 symbol in the same section. */
2258 sym
= fix
->fx_addsy
;
2260 || fix
->fx_subsy
!= NULL
2261 || fix
->fx_addnumber
!= 0
2262 || S_GET_SEGMENT (sym
) != sec
2263 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
2264 || S_GET_STORAGE_CLASS (sym
) == C_EXT
2266 || S_IS_EXTERNAL (sym
))
2268 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2269 _(".uses does not refer to a local symbol in the same section"));
2273 /* Look through the fixups again, this time looking for one
2274 at the same location as sym. */
2275 val
= S_GET_VALUE (sym
);
2276 for (fscan
= seginfo
->fix_root
;
2278 fscan
= fscan
->fx_next
)
2279 if (val
== fscan
->fx_frag
->fr_address
+ fscan
->fx_where
2280 && fscan
->fx_r_type
!= BFD_RELOC_SH_ALIGN
2281 && fscan
->fx_r_type
!= BFD_RELOC_SH_CODE
2282 && fscan
->fx_r_type
!= BFD_RELOC_SH_DATA
2283 && fscan
->fx_r_type
!= BFD_RELOC_SH_LABEL
)
2287 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2288 _("can't find fixup pointed to by .uses"));
2292 if (fscan
->fx_tcbit
)
2294 /* We've already done this one. */
2298 /* The variable fscan should also be a fixup to a local symbol
2299 in the same section. */
2300 sym
= fscan
->fx_addsy
;
2302 || fscan
->fx_subsy
!= NULL
2303 || fscan
->fx_addnumber
!= 0
2304 || S_GET_SEGMENT (sym
) != sec
2305 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
2306 || S_GET_STORAGE_CLASS (sym
) == C_EXT
2308 || S_IS_EXTERNAL (sym
))
2310 as_warn_where (fix
->fx_file
, fix
->fx_line
,
2311 _(".uses target does not refer to a local symbol in the same section"));
2315 /* Now we look through all the fixups of all the sections,
2316 counting the number of times we find a reference to sym. */
2319 #ifdef BFD_ASSEMBLER
2320 bfd_map_over_sections (stdoutput
, sh_count_relocs
, (PTR
) &info
);
2325 for (iscan
= SEG_E0
; iscan
< SEG_UNKNOWN
; iscan
++)
2326 sh_count_relocs ((bfd
*) NULL
, iscan
, (PTR
) &info
);
2333 /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym.
2334 We have already adjusted the value of sym to include the
2335 fragment address, so we undo that adjustment here. */
2336 subseg_change (sec
, 0);
2337 fix_new (symbol_get_frag (sym
),
2338 S_GET_VALUE (sym
) - symbol_get_frag (sym
)->fr_address
,
2339 4, &abs_symbol
, info
.count
, 0, BFD_RELOC_SH_COUNT
);
2343 /* This function is called after the symbol table has been completed,
2344 but before the relocs or section contents have been written out.
2345 If we have seen any .uses pseudo-ops, they point to an instruction
2346 which loads a register with the address of a function. We look
2347 through the fixups to find where the function address is being
2348 loaded from. We then generate a COUNT reloc giving the number of
2349 times that function address is referred to. The linker uses this
2350 information when doing relaxing, to decide when it can eliminate
2351 the stored function address entirely. */
2359 #ifdef BFD_ASSEMBLER
2360 bfd_map_over_sections (stdoutput
, sh_frob_section
, (PTR
) NULL
);
2365 for (iseg
= SEG_E0
; iseg
< SEG_UNKNOWN
; iseg
++)
2366 sh_frob_section ((bfd
*) NULL
, iseg
, (PTR
) NULL
);
2371 /* Called after relaxing. Set the correct sizes of the fragments, and
2372 create relocs so that md_apply_fix will fill in the correct values. */
2375 md_convert_frag (headers
, seg
, fragP
)
2376 #ifdef BFD_ASSEMBLER
2377 bfd
*headers ATTRIBUTE_UNUSED
;
2379 object_headers
*headers
;
2386 switch (fragP
->fr_subtype
)
2388 case C (COND_JUMP
, COND8
):
2389 case C (COND_JUMP_DELAY
, COND8
):
2390 subseg_change (seg
, 0);
2391 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
2392 1, BFD_RELOC_SH_PCDISP8BY2
);
2397 case C (UNCOND_JUMP
, UNCOND12
):
2398 subseg_change (seg
, 0);
2399 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
2400 1, BFD_RELOC_SH_PCDISP12BY2
);
2405 case C (UNCOND_JUMP
, UNCOND32
):
2406 case C (UNCOND_JUMP
, UNDEF_WORD_DISP
):
2407 if (fragP
->fr_symbol
== NULL
)
2408 as_bad (_("at 0x%lx, displacement overflows 12-bit field"),
2409 (unsigned long) fragP
->fr_address
);
2410 else if (S_IS_DEFINED (fragP
->fr_symbol
))
2411 as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 12-bit field"),
2412 (unsigned long) fragP
->fr_address
,
2413 S_GET_NAME (fragP
->fr_symbol
));
2415 as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 12-bit field"),
2416 (unsigned long) fragP
->fr_address
,
2417 S_GET_NAME (fragP
->fr_symbol
));
2421 case C (COND_JUMP
, COND12
):
2422 case C (COND_JUMP_DELAY
, COND12
):
2423 /* A bcond won't fit, so turn it into a b!cond; bra disp; nop. */
2424 /* I found that a relax failure for gcc.c-torture/execute/930628-1.c
2425 was due to gas incorrectly relaxing an out-of-range conditional
2426 branch with delay slot. It turned:
2427 bf.s L6 (slot mov.l r12,@(44,r0))
2430 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6)
2432 32: 10 cb mov.l r12,@(44,r0)
2433 Therefore, branches with delay slots have to be handled
2434 differently from ones without delay slots. */
2436 unsigned char *buffer
=
2437 (unsigned char *) (fragP
->fr_fix
+ fragP
->fr_literal
);
2438 int highbyte
= target_big_endian
? 0 : 1;
2439 int lowbyte
= target_big_endian
? 1 : 0;
2440 int delay
= fragP
->fr_subtype
== C (COND_JUMP_DELAY
, COND12
);
2442 /* Toggle the true/false bit of the bcond. */
2443 buffer
[highbyte
] ^= 0x2;
2445 /* If this is a dalayed branch, we may not put the the bra in the
2446 slot. So we change it to a non-delayed branch, like that:
2447 b! cond slot_label; bra disp; slot_label: slot_insn
2448 ??? We should try if swapping the conditional branch and
2449 its delay-slot insn already makes the branch reach. */
2451 /* Build a relocation to six / four bytes farther on. */
2452 subseg_change (seg
, 0);
2453 fix_new (fragP
, fragP
->fr_fix
, 2,
2454 #ifdef BFD_ASSEMBLER
2455 section_symbol (seg
),
2457 seg_info (seg
)->dot
,
2459 fragP
->fr_address
+ fragP
->fr_fix
+ (delay
? 4 : 6),
2460 1, BFD_RELOC_SH_PCDISP8BY2
);
2462 /* Set up a jump instruction. */
2463 buffer
[highbyte
+ 2] = 0xa0;
2464 buffer
[lowbyte
+ 2] = 0;
2465 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
2466 fragP
->fr_offset
, 1, BFD_RELOC_SH_PCDISP12BY2
);
2470 buffer
[highbyte
] &= ~0x4; /* Removes delay slot from branch. */
2475 /* Fill in a NOP instruction. */
2476 buffer
[highbyte
+ 4] = 0x0;
2477 buffer
[lowbyte
+ 4] = 0x9;
2486 case C (COND_JUMP
, COND32
):
2487 case C (COND_JUMP_DELAY
, COND32
):
2488 case C (COND_JUMP
, UNDEF_WORD_DISP
):
2489 case C (COND_JUMP_DELAY
, UNDEF_WORD_DISP
):
2490 if (fragP
->fr_symbol
== NULL
)
2491 as_bad (_("at 0x%lx, displacement overflows 8-bit field"),
2492 (unsigned long) fragP
->fr_address
);
2493 else if (S_IS_DEFINED (fragP
->fr_symbol
))
2494 as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 8-bit field "),
2495 (unsigned long) fragP
->fr_address
,
2496 S_GET_NAME (fragP
->fr_symbol
));
2498 as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 8-bit field "),
2499 (unsigned long) fragP
->fr_address
,
2500 S_GET_NAME (fragP
->fr_symbol
));
2507 if (donerelax
&& !sh_relax
)
2508 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
2509 _("overflow in branch to %s; converted into longer instruction sequence"),
2510 (fragP
->fr_symbol
!= NULL
2511 ? S_GET_NAME (fragP
->fr_symbol
)
2516 md_section_align (seg
, size
)
2520 #ifdef BFD_ASSEMBLER
2523 #else /* ! OBJ_ELF */
2524 return ((size
+ (1 << bfd_get_section_alignment (stdoutput
, seg
)) - 1)
2525 & (-1 << bfd_get_section_alignment (stdoutput
, seg
)));
2526 #endif /* ! OBJ_ELF */
2527 #else /* ! BFD_ASSEMBLER */
2528 return ((size
+ (1 << section_alignment
[(int) seg
]) - 1)
2529 & (-1 << section_alignment
[(int) seg
]));
2530 #endif /* ! BFD_ASSEMBLER */
2533 /* This static variable is set by s_uacons to tell sh_cons_align that
2534 the expession does not need to be aligned. */
2536 static int sh_no_align_cons
= 0;
2538 /* This handles the unaligned space allocation pseudo-ops, such as
2539 .uaword. .uaword is just like .word, but the value does not need
2546 /* Tell sh_cons_align not to align this value. */
2547 sh_no_align_cons
= 1;
2551 /* If a .word, et. al., pseud-op is seen, warn if the value is not
2552 aligned correctly. Note that this can cause warnings to be issued
2553 when assembling initialized structured which were declared with the
2554 packed attribute. FIXME: Perhaps we should require an option to
2555 enable this warning? */
2558 sh_cons_align (nbytes
)
2564 if (sh_no_align_cons
)
2566 /* This is an unaligned pseudo-op. */
2567 sh_no_align_cons
= 0;
2572 while ((nbytes
& 1) == 0)
2581 if (now_seg
== absolute_section
)
2583 if ((abs_section_offset
& ((1 << nalign
) - 1)) != 0)
2584 as_warn (_("misaligned data"));
2588 p
= frag_var (rs_align_code
, 1, 1, (relax_substateT
) 0,
2589 (symbolS
*) NULL
, (offsetT
) nalign
, (char *) NULL
);
2591 record_alignment (now_seg
, nalign
);
2594 /* When relaxing, we need to output a reloc for any .align directive
2595 that requests alignment to a four byte boundary or larger. This is
2596 also where we check for misaligned data. */
2599 sh_handle_align (frag
)
2603 && frag
->fr_type
== rs_align
2604 && frag
->fr_address
+ frag
->fr_fix
> 0
2605 && frag
->fr_offset
> 1
2606 && now_seg
!= bss_section
)
2607 fix_new (frag
, frag
->fr_fix
, 2, &abs_symbol
, frag
->fr_offset
, 0,
2608 BFD_RELOC_SH_ALIGN
);
2610 if (frag
->fr_type
== rs_align_code
2611 && frag
->fr_next
->fr_address
- frag
->fr_address
- frag
->fr_fix
!= 0)
2612 as_warn_where (frag
->fr_file
, frag
->fr_line
, _("misaligned data"));
2615 /* This macro decides whether a particular reloc is an entry in a
2616 switch table. It is used when relaxing, because the linker needs
2617 to know about all such entries so that it can adjust them if
2620 #ifdef BFD_ASSEMBLER
2621 #define SWITCH_TABLE_CONS(fix) (0)
2623 #define SWITCH_TABLE_CONS(fix) \
2624 ((fix)->fx_r_type == 0 \
2625 && ((fix)->fx_size == 2 \
2626 || (fix)->fx_size == 1 \
2627 || (fix)->fx_size == 4))
2630 #define SWITCH_TABLE(fix) \
2631 ((fix)->fx_addsy != NULL \
2632 && (fix)->fx_subsy != NULL \
2633 && S_GET_SEGMENT ((fix)->fx_addsy) == text_section \
2634 && S_GET_SEGMENT ((fix)->fx_subsy) == text_section \
2635 && ((fix)->fx_r_type == BFD_RELOC_32 \
2636 || (fix)->fx_r_type == BFD_RELOC_16 \
2637 || (fix)->fx_r_type == BFD_RELOC_8 \
2638 || SWITCH_TABLE_CONS (fix)))
2640 /* See whether we need to force a relocation into the output file.
2641 This is used to force out switch and PC relative relocations when
2645 sh_force_relocation (fix
)
2649 if (fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2650 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
2651 || fix
->fx_r_type
== BFD_RELOC_SH_LOOP_START
2652 || fix
->fx_r_type
== BFD_RELOC_SH_LOOP_END
)
2658 return (fix
->fx_pcrel
2659 || SWITCH_TABLE (fix
)
2660 || fix
->fx_r_type
== BFD_RELOC_SH_COUNT
2661 || fix
->fx_r_type
== BFD_RELOC_SH_ALIGN
2662 || fix
->fx_r_type
== BFD_RELOC_SH_CODE
2663 || fix
->fx_r_type
== BFD_RELOC_SH_DATA
2664 || fix
->fx_r_type
== BFD_RELOC_SH_LABEL
);
2669 sh_fix_adjustable (fixP
)
2673 if (fixP
->fx_addsy
== NULL
)
2676 if (fixP
->fx_r_type
== BFD_RELOC_SH_PCDISP8BY2
2677 || fixP
->fx_r_type
== BFD_RELOC_SH_PCDISP12BY2
2678 || fixP
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY2
2679 || fixP
->fx_r_type
== BFD_RELOC_SH_PCRELIMM8BY4
2680 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
2681 || fixP
->fx_r_type
== BFD_RELOC_SH_SWITCH16
2682 || fixP
->fx_r_type
== BFD_RELOC_SH_SWITCH32
)
2685 if (! TC_RELOC_RTSYM_LOC_FIXUP (fixP
)
2686 || fixP
->fx_r_type
== BFD_RELOC_32_GOTOFF
2687 || fixP
->fx_r_type
== BFD_RELOC_RVA
)
2690 /* We need the symbol name for the VTABLE entries */
2691 if (fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2692 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2699 sh_elf_final_processing ()
2703 /* Set file-specific flags to indicate if this code needs
2704 a processor with the sh-dsp / sh3e ISA to execute. */
2705 if (valid_arch
& arch_sh1
)
2707 else if (valid_arch
& arch_sh2
)
2709 else if (valid_arch
& arch_sh_dsp
)
2711 else if (valid_arch
& arch_sh3
)
2713 else if (valid_arch
& arch_sh3_dsp
)
2715 else if (valid_arch
& arch_sh3e
)
2717 else if (valid_arch
& arch_sh4
)
2722 elf_elfheader (stdoutput
)->e_flags
&= ~EF_SH_MACH_MASK
;
2723 elf_elfheader (stdoutput
)->e_flags
|= val
;
2727 /* Apply a fixup to the object file. */
2729 #ifdef BFD_ASSEMBLER
2731 md_apply_fix (fixP
, valp
)
2736 md_apply_fix (fixP
, val
)
2741 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2742 int lowbyte
= target_big_endian
? 1 : 0;
2743 int highbyte
= target_big_endian
? 0 : 1;
2744 #ifdef BFD_ASSEMBLER
2750 #ifdef BFD_ASSEMBLER
2751 /* A difference between two symbols, the second of which is in the
2752 current section, is transformed in a PC-relative relocation to
2753 the other symbol. We have to adjust the relocation type here. */
2756 switch (fixP
->fx_r_type
)
2762 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2765 /* Currently, we only support 32-bit PCREL relocations.
2766 We'd need a new reloc type to handle 16_PCREL, and
2767 8_PCREL is already taken for R_SH_SWITCH8, which
2768 apparently does something completely different than what
2771 bfd_set_error (bfd_error_bad_value
);
2775 bfd_set_error (bfd_error_bad_value
);
2780 /* The function adjust_reloc_syms won't convert a reloc against a weak
2781 symbol into a reloc against a section, but bfd_install_relocation
2782 will screw up if the symbol is defined, so we have to adjust val here
2783 to avoid the screw up later. */
2784 if (fixP
->fx_addsy
!= NULL
2785 && S_IS_WEAK (fixP
->fx_addsy
))
2786 val
-= S_GET_VALUE (fixP
->fx_addsy
);
2789 #ifndef BFD_ASSEMBLER
2790 if (fixP
->fx_r_type
== 0)
2792 if (fixP
->fx_size
== 2)
2793 fixP
->fx_r_type
= BFD_RELOC_16
;
2794 else if (fixP
->fx_size
== 4)
2795 fixP
->fx_r_type
= BFD_RELOC_32
;
2796 else if (fixP
->fx_size
== 1)
2797 fixP
->fx_r_type
= BFD_RELOC_8
;
2805 switch (fixP
->fx_r_type
)
2807 case BFD_RELOC_SH_IMM4
:
2809 *buf
= (*buf
& 0xf0) | (val
& 0xf);
2812 case BFD_RELOC_SH_IMM4BY2
:
2815 *buf
= (*buf
& 0xf0) | ((val
>> 1) & 0xf);
2818 case BFD_RELOC_SH_IMM4BY4
:
2821 *buf
= (*buf
& 0xf0) | ((val
>> 2) & 0xf);
2824 case BFD_RELOC_SH_IMM8BY2
:
2830 case BFD_RELOC_SH_IMM8BY4
:
2837 case BFD_RELOC_SH_IMM8
:
2838 /* Sometimes the 8 bit value is sign extended (e.g., add) and
2839 sometimes it is not (e.g., and). We permit any 8 bit value.
2840 Note that adding further restrictions may invalidate
2841 reasonable looking assembly code, such as ``and -0x1,r0''. */
2847 case BFD_RELOC_SH_PCRELIMM8BY4
:
2848 /* The lower two bits of the PC are cleared before the
2849 displacement is added in. We can assume that the destination
2850 is on a 4 byte bounday. If this instruction is also on a 4
2851 byte boundary, then we want
2853 and target - here is a multiple of 4.
2854 Otherwise, we are on a 2 byte boundary, and we want
2855 (target - (here - 2)) / 4
2856 and target - here is not a multiple of 4. Computing
2857 (target - (here - 2)) / 4 == (target - here + 2) / 4
2858 works for both cases, since in the first case the addition of
2859 2 will be removed by the division. target - here is in the
2861 val
= (val
+ 2) / 4;
2863 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
2867 case BFD_RELOC_SH_PCRELIMM8BY2
:
2870 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
2874 case BFD_RELOC_SH_PCDISP8BY2
:
2876 if (val
< -0x80 || val
> 0x7f)
2877 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
2881 case BFD_RELOC_SH_PCDISP12BY2
:
2883 if (val
< -0x800 || val
>= 0x7ff)
2884 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("pcrel too far"));
2885 buf
[lowbyte
] = val
& 0xff;
2886 buf
[highbyte
] |= (val
>> 8) & 0xf;
2890 case BFD_RELOC_32_PCREL
:
2891 md_number_to_chars (buf
, val
, 4);
2895 md_number_to_chars (buf
, val
, 2);
2898 case BFD_RELOC_SH_USES
:
2899 /* Pass the value into sh_coff_reloc_mangle. */
2900 fixP
->fx_addnumber
= val
;
2903 case BFD_RELOC_SH_COUNT
:
2904 case BFD_RELOC_SH_ALIGN
:
2905 case BFD_RELOC_SH_CODE
:
2906 case BFD_RELOC_SH_DATA
:
2907 case BFD_RELOC_SH_LABEL
:
2908 /* Nothing to do here. */
2911 case BFD_RELOC_SH_LOOP_START
:
2912 case BFD_RELOC_SH_LOOP_END
:
2914 case BFD_RELOC_VTABLE_INHERIT
:
2915 case BFD_RELOC_VTABLE_ENTRY
:
2917 #ifdef BFD_ASSEMBLER
2924 case BFD_RELOC_32_PLT_PCREL
:
2925 /* Make the jump instruction point to the address of the operand. At
2926 runtime we merely add the offset to the actual PLT entry. */
2930 case BFD_RELOC_SH_GOTPC
:
2931 /* This is tough to explain. We end up with this one if we have
2932 operands that look like "_GLOBAL_OFFSET_TABLE_+[.-.L284]".
2933 The goal here is to obtain the absolute address of the GOT,
2934 and it is strongly preferable from a performance point of
2935 view to avoid using a runtime relocation for this. There are
2936 cases where you have something like:
2938 .long _GLOBAL_OFFSET_TABLE_+[.-.L66]
2940 and here no correction would be required. Internally in the
2941 assembler we treat operands of this form as not being pcrel
2942 since the '.' is explicitly mentioned, and I wonder whether
2943 it would simplify matters to do it this way. Who knows. In
2944 earlier versions of the PIC patches, the pcrel_adjust field
2945 was used to store the correction, but since the expression is
2946 not pcrel, I felt it would be confusing to do it this way. */
2948 md_number_to_chars (buf
, val
, 4);
2951 case BFD_RELOC_32_GOT_PCREL
:
2952 *valp
= 0; /* Fully resolved at runtime. No addend. */
2953 md_number_to_chars (buf
, 0, 4);
2956 case BFD_RELOC_32_GOTOFF
:
2966 if ((val
& ((1 << shift
) - 1)) != 0)
2967 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("misaligned offset"));
2971 val
= ((val
>> shift
)
2972 | ((long) -1 & ~ ((long) -1 >> shift
)));
2974 if (max
!= 0 && (val
< min
|| val
> max
))
2975 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("offset out of range"));
2977 #ifdef BFD_ASSEMBLER
2982 /* Called just before address relaxation. Return the length
2983 by which a fragment must grow to reach it's destination. */
2986 md_estimate_size_before_relax (fragP
, segment_type
)
2987 register fragS
*fragP
;
2988 register segT segment_type
;
2990 switch (fragP
->fr_subtype
)
2992 case C (UNCOND_JUMP
, UNDEF_DISP
):
2993 /* Used to be a branch to somewhere which was unknown. */
2994 if (!fragP
->fr_symbol
)
2996 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
2997 fragP
->fr_var
= md_relax_table
[C (UNCOND_JUMP
, UNCOND12
)].rlx_length
;
2999 else if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
3001 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNCOND12
);
3002 fragP
->fr_var
= md_relax_table
[C (UNCOND_JUMP
, UNCOND12
)].rlx_length
;
3006 fragP
->fr_subtype
= C (UNCOND_JUMP
, UNDEF_WORD_DISP
);
3007 fragP
->fr_var
= md_relax_table
[C (UNCOND_JUMP
, UNCOND32
)].rlx_length
;
3008 return md_relax_table
[C (UNCOND_JUMP
, UNCOND32
)].rlx_length
;
3014 case C (COND_JUMP
, UNDEF_DISP
):
3015 case C (COND_JUMP_DELAY
, UNDEF_DISP
):
3016 /* Used to be a branch to somewhere which was unknown. */
3017 if (fragP
->fr_symbol
3018 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
3020 int what
= GET_WHAT (fragP
->fr_subtype
);
3021 /* Got a symbol and it's defined in this segment, become byte
3022 sized - maybe it will fix up. */
3023 fragP
->fr_subtype
= C (what
, COND8
);
3024 fragP
->fr_var
= md_relax_table
[C (what
, COND8
)].rlx_length
;
3026 else if (fragP
->fr_symbol
)
3028 int what
= GET_WHAT (fragP
->fr_subtype
);
3029 /* Its got a segment, but its not ours, so it will always be long. */
3030 fragP
->fr_subtype
= C (what
, UNDEF_WORD_DISP
);
3031 fragP
->fr_var
= md_relax_table
[C (what
, COND32
)].rlx_length
;
3032 return md_relax_table
[C (what
, COND32
)].rlx_length
;
3036 int what
= GET_WHAT (fragP
->fr_subtype
);
3037 /* We know the abs value. */
3038 fragP
->fr_subtype
= C (what
, COND8
);
3039 fragP
->fr_var
= md_relax_table
[C (what
, COND8
)].rlx_length
;
3044 return fragP
->fr_var
;
3047 /* Put number into target byte order. */
3050 md_number_to_chars (ptr
, use
, nbytes
)
3055 if (! target_big_endian
)
3056 number_to_chars_littleendian (ptr
, use
, nbytes
);
3058 number_to_chars_bigendian (ptr
, use
, nbytes
);
3062 md_pcrel_from (fixP
)
3065 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
+ 2;
3071 tc_coff_sizemachdep (frag
)
3074 return md_relax_table
[frag
->fr_subtype
].rlx_length
;
3077 #endif /* OBJ_COFF */
3079 /* When we align the .text section, insert the correct NOP pattern. */
3082 sh_do_align (n
, fill
, len
, max
)
3085 int len ATTRIBUTE_UNUSED
;
3089 && subseg_text_p (now_seg
)
3092 static const unsigned char big_nop_pattern
[] = { 0x00, 0x09 };
3093 static const unsigned char little_nop_pattern
[] = { 0x09, 0x00 };
3095 /* First align to a 2 byte boundary, in case there is an odd
3097 frag_align (1, 0, 0);
3098 if (target_big_endian
)
3099 frag_align_pattern (n
, big_nop_pattern
, sizeof big_nop_pattern
, max
);
3101 frag_align_pattern (n
, little_nop_pattern
, sizeof little_nop_pattern
,
3109 #ifndef BFD_ASSEMBLER
3112 /* Map BFD relocs to SH COFF relocs. */
3116 bfd_reloc_code_real_type bfd_reloc
;
3120 static const struct reloc_map coff_reloc_map
[] =
3122 { BFD_RELOC_32
, R_SH_IMM32
},
3123 { BFD_RELOC_16
, R_SH_IMM16
},
3124 { BFD_RELOC_8
, R_SH_IMM8
},
3125 { BFD_RELOC_SH_PCDISP8BY2
, R_SH_PCDISP8BY2
},
3126 { BFD_RELOC_SH_PCDISP12BY2
, R_SH_PCDISP
},
3127 { BFD_RELOC_SH_IMM4
, R_SH_IMM4
},
3128 { BFD_RELOC_SH_IMM4BY2
, R_SH_IMM4BY2
},
3129 { BFD_RELOC_SH_IMM4BY4
, R_SH_IMM4BY4
},
3130 { BFD_RELOC_SH_IMM8
, R_SH_IMM8
},
3131 { BFD_RELOC_SH_IMM8BY2
, R_SH_IMM8BY2
},
3132 { BFD_RELOC_SH_IMM8BY4
, R_SH_IMM8BY4
},
3133 { BFD_RELOC_SH_PCRELIMM8BY2
, R_SH_PCRELIMM8BY2
},
3134 { BFD_RELOC_SH_PCRELIMM8BY4
, R_SH_PCRELIMM8BY4
},
3135 { BFD_RELOC_8_PCREL
, R_SH_SWITCH8
},
3136 { BFD_RELOC_SH_SWITCH16
, R_SH_SWITCH16
},
3137 { BFD_RELOC_SH_SWITCH32
, R_SH_SWITCH32
},
3138 { BFD_RELOC_SH_USES
, R_SH_USES
},
3139 { BFD_RELOC_SH_COUNT
, R_SH_COUNT
},
3140 { BFD_RELOC_SH_ALIGN
, R_SH_ALIGN
},
3141 { BFD_RELOC_SH_CODE
, R_SH_CODE
},
3142 { BFD_RELOC_SH_DATA
, R_SH_DATA
},
3143 { BFD_RELOC_SH_LABEL
, R_SH_LABEL
},
3144 { BFD_RELOC_UNUSED
, 0 }
3147 /* Adjust a reloc for the SH. This is similar to the generic code,
3148 but does some minor tweaking. */
3151 sh_coff_reloc_mangle (seg
, fix
, intr
, paddr
)
3152 segment_info_type
*seg
;
3154 struct internal_reloc
*intr
;
3157 symbolS
*symbol_ptr
= fix
->fx_addsy
;
3160 intr
->r_vaddr
= paddr
+ fix
->fx_frag
->fr_address
+ fix
->fx_where
;
3162 if (! SWITCH_TABLE (fix
))
3164 const struct reloc_map
*rm
;
3166 for (rm
= coff_reloc_map
; rm
->bfd_reloc
!= BFD_RELOC_UNUSED
; rm
++)
3167 if (rm
->bfd_reloc
== (bfd_reloc_code_real_type
) fix
->fx_r_type
)
3169 if (rm
->bfd_reloc
== BFD_RELOC_UNUSED
)
3170 as_bad_where (fix
->fx_file
, fix
->fx_line
,
3171 _("Can not represent %s relocation in this object file format"),
3172 bfd_get_reloc_code_name (fix
->fx_r_type
));
3173 intr
->r_type
= rm
->sh_reloc
;
3180 if (fix
->fx_r_type
== BFD_RELOC_16
)
3181 intr
->r_type
= R_SH_SWITCH16
;
3182 else if (fix
->fx_r_type
== BFD_RELOC_8
)
3183 intr
->r_type
= R_SH_SWITCH8
;
3184 else if (fix
->fx_r_type
== BFD_RELOC_32
)
3185 intr
->r_type
= R_SH_SWITCH32
;
3189 /* For a switch reloc, we set r_offset to the difference between
3190 the reloc address and the subtrahend. When the linker is
3191 doing relaxing, it can use the determine the starting and
3192 ending points of the switch difference expression. */
3193 intr
->r_offset
= intr
->r_vaddr
- S_GET_VALUE (fix
->fx_subsy
);
3196 /* PC relative relocs are always against the current section. */
3197 if (symbol_ptr
== NULL
)
3199 switch (fix
->fx_r_type
)
3201 case BFD_RELOC_SH_PCRELIMM8BY2
:
3202 case BFD_RELOC_SH_PCRELIMM8BY4
:
3203 case BFD_RELOC_SH_PCDISP8BY2
:
3204 case BFD_RELOC_SH_PCDISP12BY2
:
3205 case BFD_RELOC_SH_USES
:
3206 symbol_ptr
= seg
->dot
;
3213 if (fix
->fx_r_type
== BFD_RELOC_SH_USES
)
3215 /* We can't store the offset in the object file, since this
3216 reloc does not take up any space, so we store it in r_offset.
3217 The fx_addnumber field was set in md_apply_fix. */
3218 intr
->r_offset
= fix
->fx_addnumber
;
3220 else if (fix
->fx_r_type
== BFD_RELOC_SH_COUNT
)
3222 /* We can't store the count in the object file, since this reloc
3223 does not take up any space, so we store it in r_offset. The
3224 fx_offset field was set when the fixup was created in
3225 sh_coff_frob_file. */
3226 intr
->r_offset
= fix
->fx_offset
;
3227 /* This reloc is always absolute. */
3230 else if (fix
->fx_r_type
== BFD_RELOC_SH_ALIGN
)
3232 /* Store the alignment in the r_offset field. */
3233 intr
->r_offset
= fix
->fx_offset
;
3234 /* This reloc is always absolute. */
3237 else if (fix
->fx_r_type
== BFD_RELOC_SH_CODE
3238 || fix
->fx_r_type
== BFD_RELOC_SH_DATA
3239 || fix
->fx_r_type
== BFD_RELOC_SH_LABEL
)
3241 /* These relocs are always absolute. */
3245 /* Turn the segment of the symbol into an offset. */
3246 if (symbol_ptr
!= NULL
)
3248 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
3250 intr
->r_symndx
= dot
->sy_number
;
3252 intr
->r_symndx
= symbol_ptr
->sy_number
;
3255 intr
->r_symndx
= -1;
3258 #endif /* OBJ_COFF */
3259 #endif /* ! BFD_ASSEMBLER */
3261 #ifdef BFD_ASSEMBLER
3263 /* Create a reloc. */
3266 tc_gen_reloc (section
, fixp
)
3267 asection
*section ATTRIBUTE_UNUSED
;
3271 bfd_reloc_code_real_type r_type
;
3273 rel
= (arelent
*) xmalloc (sizeof (arelent
));
3274 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3275 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3276 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3278 r_type
= fixp
->fx_r_type
;
3280 if (SWITCH_TABLE (fixp
))
3282 rel
->addend
= rel
->address
- S_GET_VALUE (fixp
->fx_subsy
);
3283 if (r_type
== BFD_RELOC_16
)
3284 r_type
= BFD_RELOC_SH_SWITCH16
;
3285 else if (r_type
== BFD_RELOC_8
)
3286 r_type
= BFD_RELOC_8_PCREL
;
3287 else if (r_type
== BFD_RELOC_32
)
3288 r_type
= BFD_RELOC_SH_SWITCH32
;
3292 else if (r_type
== BFD_RELOC_SH_USES
)
3293 rel
->addend
= fixp
->fx_addnumber
;
3294 else if (r_type
== BFD_RELOC_SH_COUNT
)
3295 rel
->addend
= fixp
->fx_offset
;
3296 else if (r_type
== BFD_RELOC_SH_ALIGN
)
3297 rel
->addend
= fixp
->fx_offset
;
3298 else if (r_type
== BFD_RELOC_VTABLE_INHERIT
3299 || r_type
== BFD_RELOC_VTABLE_ENTRY
)
3300 rel
->addend
= fixp
->fx_offset
;
3301 else if (r_type
== BFD_RELOC_SH_LOOP_START
3302 || r_type
== BFD_RELOC_SH_LOOP_END
)
3303 rel
->addend
= fixp
->fx_offset
;
3304 else if (r_type
== BFD_RELOC_SH_LABEL
&& fixp
->fx_pcrel
)
3307 rel
->address
= rel
->addend
= fixp
->fx_offset
;
3309 else if (fixp
->fx_pcrel
)
3310 rel
->addend
= fixp
->fx_addnumber
;
3311 else if (r_type
== BFD_RELOC_32
|| r_type
== BFD_RELOC_32_GOTOFF
)
3312 rel
->addend
= fixp
->fx_addnumber
;
3316 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, r_type
);
3317 if (rel
->howto
== NULL
)
3319 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3320 _("Cannot represent relocation type %s"),
3321 bfd_get_reloc_code_name (r_type
));
3322 /* Set howto to a garbage value so that we can keep going. */
3323 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
3324 assert (rel
->howto
!= NULL
);
3330 #endif /* BFD_ASSEMBLER */
3335 if (debug_type
== DEBUG_DWARF2
)