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"
38 const char comment_chars[] = "!";
39 const char line_separator_chars[] = ";";
40 const char line_comment_chars[] = "!#";
42 static void s_uses PARAMS ((int));
44 static void sh_count_relocs PARAMS ((bfd *, segT, PTR));
45 static void sh_frob_section PARAMS ((bfd *, segT, PTR));
48 void s_align_bytes ();
49 static void s_uacons PARAMS ((int));
50 static sh_opcode_info *find_cooked_opcode PARAMS ((char **));
51 static unsigned int assemble_ppi PARAMS ((char *, sh_opcode_info *));
54 static void sh_elf_cons PARAMS ((int));
56 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
63 int ignore ATTRIBUTE_UNUSED;
66 target_big_endian = 0;
69 /* This table describes all the machine specific pseudo-ops the assembler
70 has to support. The fields are:
71 pseudo-op name without dot
72 function to call to execute this pseudo-op
73 Integer arg to pass to the function. */
75 const pseudo_typeS md_pseudo_table[] =
78 {"long", sh_elf_cons, 4},
79 {"int", sh_elf_cons, 4},
80 {"word", sh_elf_cons, 2},
81 {"short", sh_elf_cons, 2},
86 {"form", listing_psize, 0},
87 {"little", little, 0},
88 {"heading", listing_title, 0},
89 {"import", s_ignore, 0},
90 {"page", listing_eject, 0},
91 {"program", s_ignore, 0},
93 {"uaword", s_uacons, 2},
94 {"ualong", s_uacons, 4},
95 { "file", dwarf2_directive_file, 0 },
96 { "loc", dwarf2_directive_loc, 0 },
100 /*int md_reloc_size; */
102 int sh_relax; /* set if -relax seen */
104 /* Whether -small was seen. */
108 /* Whether -dsp was seen. */
112 /* The bit mask of architectures that could
113 accomodate the insns seen so far. */
114 static int valid_arch;
116 const char EXP_CHARS[] = "eE";
118 /* Chars that mean this number is a floating point constant. */
121 const char FLT_CHARS[] = "rRsSfFdDxXpP";
123 #define C(a,b) ENCODE_RELAX(a,b)
125 #define ENCODE_RELAX(what,length) (((what) << 4) + (length))
126 #define GET_WHAT(x) ((x>>4))
128 /* These are the three types of relaxable instrction. */
130 #define COND_JUMP_DELAY 2
131 #define UNCOND_JUMP 3
140 #define UNDEF_WORD_DISP 4
145 /* Branch displacements are from the address of the branch plus
146 four, thus all minimum and maximum values have 4 added to them. */
149 #define COND8_LENGTH 2
151 /* There is one extra instruction before the branch, so we must add
152 two more bytes to account for it. */
153 #define COND12_F 4100
154 #define COND12_M -4090
155 #define COND12_LENGTH 6
157 #define COND12_DELAY_LENGTH 4
159 /* ??? The minimum and maximum values are wrong, but this does not matter
160 since this relocation type is not supported yet. */
161 #define COND32_F (1<<30)
162 #define COND32_M -(1<<30)
163 #define COND32_LENGTH 14
165 #define UNCOND12_F 4098
166 #define UNCOND12_M -4092
167 #define UNCOND12_LENGTH 2
169 /* ??? The minimum and maximum values are wrong, but this does not matter
170 since this relocation type is not supported yet. */
171 #define UNCOND32_F (1<<30)
172 #define UNCOND32_M -(1<<30)
173 #define UNCOND32_LENGTH 14
175 #define EMPTY { 0, 0, 0, 0 }
177 const relax_typeS md_relax_table[C (END, 0)] = {
178 EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
179 EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
182 /* C (COND_JUMP, COND8) */
183 { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP, COND12) },
184 /* C (COND_JUMP, COND12) */
185 { COND12_F, COND12_M, COND12_LENGTH, C (COND_JUMP, COND32), },
186 /* C (COND_JUMP, COND32) */
187 { COND32_F, COND32_M, COND32_LENGTH, 0, },
188 EMPTY, EMPTY, EMPTY, EMPTY,
189 EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
192 /* C (COND_JUMP_DELAY, COND8) */
193 { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP_DELAY, COND12) },
194 /* C (COND_JUMP_DELAY, COND12) */
195 { COND12_F, COND12_M, COND12_DELAY_LENGTH, C (COND_JUMP_DELAY, COND32), },
196 /* C (COND_JUMP_DELAY, COND32) */
197 { COND32_F, COND32_M, COND32_LENGTH, 0, },
198 EMPTY, EMPTY, EMPTY, EMPTY,
199 EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
202 /* C (UNCOND_JUMP, UNCOND12) */
203 { UNCOND12_F, UNCOND12_M, UNCOND12_LENGTH, C (UNCOND_JUMP, UNCOND32), },
204 /* C (UNCOND_JUMP, UNCOND32) */
205 { UNCOND32_F, UNCOND32_M, UNCOND32_LENGTH, 0, },
206 EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
207 EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
212 static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
216 /* Parse @got, etc. and return the desired relocation.
217 If we have additional arithmetic expression, then we fill in new_exp_p. */
218 static bfd_reloc_code_real_type
219 sh_elf_suffix (str_p, exp_p, new_exp_p)
221 expressionS *exp_p, *new_exp_p;
226 bfd_reloc_code_real_type reloc;
236 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
238 static struct map_bfd mapping[] = {
239 MAP ("got", BFD_RELOC_32_GOT_PCREL),
240 MAP ("plt", BFD_RELOC_32_PLT_PCREL),
241 MAP ("gotoff", BFD_RELOC_32_GOTOFF),
242 { (char *)0, 0, BFD_RELOC_UNUSED }
246 return BFD_RELOC_UNUSED;
248 for (ch = *str, str2 = ident;
249 (str2 < ident + sizeof (ident) - 1
250 && (isalnum (ch) || ch == '@'));
253 *str2++ = (islower (ch)) ? ch : tolower (ch);
260 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
261 if (ch == ptr->string[0]
262 && len == ptr->length
263 && memcmp (ident, ptr->string, ptr->length) == 0)
265 /* Now check for identifier@suffix+constant */
266 if (*str == '-' || *str == '+')
268 char *orig_line = input_line_pointer;
270 input_line_pointer = str;
271 expression (new_exp_p);
272 if (new_exp_p->X_op == O_constant)
274 exp_p->X_add_number += new_exp_p->X_add_number;
275 str = input_line_pointer;
277 if (new_exp_p->X_op == O_subtract)
278 str = input_line_pointer;
280 if (&input_line_pointer != str_p)
281 input_line_pointer = orig_line;
288 return BFD_RELOC_UNUSED;
291 /* The regular cons() function, that reads constants, doesn't support
292 suffixes such as @GOT, @GOTOFF and @PLT, that generate
293 machine-specific relocation types. So we must define it here. */
294 /* Clobbers input_line_pointer, checks end-of-line. */
297 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
299 expressionS exp, new_exp;
300 bfd_reloc_code_real_type reloc;
303 if (is_it_end_of_statement ())
305 demand_empty_rest_of_line ();
312 new_exp.X_op = O_absent;
313 new_exp.X_add_symbol = new_exp.X_op_symbol = NULL;
314 /* If the _GLOBAL_OFFSET_TABLE_ symbol hasn't been found yet,
315 use the name of the symbol to tell whether it's the
316 _GLOBAL_OFFSET_TABLE_. If it has, comparing the symbols is
318 if (! GOT_symbol && exp.X_add_symbol)
319 name = S_GET_NAME (exp.X_add_symbol);
322 /* Check whether this expression involves the
323 _GLOBAL_OFFSET_TABLE_ symbol, by itself or added to a
324 difference of two other symbols. */
325 if (((GOT_symbol && GOT_symbol == exp.X_add_symbol)
326 || (! GOT_symbol && name
327 && strcmp (name, GLOBAL_OFFSET_TABLE_NAME) == 0))
328 && (exp.X_op == O_symbol
329 || (exp.X_op == O_add
330 && ((symbol_get_value_expression (exp.X_op_symbol)->X_op)
333 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput,
335 int size = bfd_get_reloc_size (reloc_howto);
337 if (GOT_symbol == NULL)
338 GOT_symbol = symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME);
341 as_bad (_("%s relocations do not fit in %d bytes\n"),
342 reloc_howto->name, nbytes);
345 register char *p = frag_more ((int) nbytes);
346 int offset = nbytes - size;
348 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
349 size, &exp, 0, TC_RELOC_GLOBAL_OFFSET_TABLE);
352 /* Check if this symbol involves one of the magic suffixes, such
353 as @GOT, @GOTOFF or @PLT, and determine which relocation type
355 else if ((exp.X_op == O_symbol || (exp.X_op == O_add && exp.X_op_symbol))
356 && *input_line_pointer == '@'
357 && ((reloc = sh_elf_suffix (&input_line_pointer, &exp, &new_exp))
358 != BFD_RELOC_UNUSED))
360 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput,
362 int size = bfd_get_reloc_size (reloc_howto);
364 /* Force a GOT to be generated. */
365 if (GOT_symbol == NULL)
366 GOT_symbol = symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME);
369 as_bad (_("%s relocations do not fit in %d bytes\n"),
370 reloc_howto->name, nbytes);
373 register char *p = frag_more ((int) nbytes);
374 int offset = nbytes - size;
376 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
378 if (new_exp.X_op != O_absent)
379 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
380 &new_exp, 0, BFD_RELOC_32);
384 emit_expr (&exp, (unsigned int) nbytes);
386 while (*input_line_pointer++ == ',');
388 input_line_pointer--; /* Put terminator back into stream. */
389 if (*input_line_pointer == '#' || *input_line_pointer == '!')
391 while (! is_end_of_line[*input_line_pointer++]);
394 demand_empty_rest_of_line ();
399 /* This function is called once, at assembler startup time. This should
400 set up all the tables, etc that the MD part of the assembler needs. */
405 sh_opcode_info *opcode;
406 char *prev_name = "";
410 /* The WinCE OS only supports little endian executables. */
411 target_big_endian = 0;
414 target_big_endian = 1;
417 target_arch = arch_sh1_up & ~(sh_dsp ? arch_sh3e_up : arch_sh_dsp_up);
418 valid_arch = target_arch;
420 opcode_hash_control = hash_new ();
422 /* Insert unique names into hash table. */
423 for (opcode = sh_table; opcode->name; opcode++)
425 if (strcmp (prev_name, opcode->name))
427 if (! (opcode->arch & target_arch))
429 prev_name = opcode->name;
430 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
434 /* Make all the opcodes with the same name point to the same
436 opcode->name = prev_name;
443 static int reg_x, reg_y;
451 expressionS immediate;
455 #define IDENT_CHAR(c) (isalnum (c) || (c) == '_')
457 /* Try to parse a reg name. Return the number of chars consumed. */
460 parse_reg (src, mode, reg)
465 /* We use ! IDENT_CHAR for the next character after the register name, to
466 make sure that we won't accidentally recognize a symbol name such as
467 'sram' or sr_ram as being a reference to the register 'sr'. */
473 if (src[2] >= '0' && src[2] <= '5'
474 && ! IDENT_CHAR ((unsigned char) src[3]))
477 *reg = 10 + src[2] - '0';
481 if (src[1] >= '0' && src[1] <= '9'
482 && ! IDENT_CHAR ((unsigned char) src[2]))
485 *reg = (src[1] - '0');
488 if (src[1] >= '0' && src[1] <= '7' && strncmp (&src[2], "_bank", 5) == 0
489 && ! IDENT_CHAR ((unsigned char) src[7]))
492 *reg = (src[1] - '0');
496 if (src[1] == 'e' && ! IDENT_CHAR ((unsigned char) src[2]))
501 if (src[1] == 's' && ! IDENT_CHAR ((unsigned char) src[2]))
512 if (! IDENT_CHAR ((unsigned char) src[2]))
518 if (src[2] == 'g' && ! IDENT_CHAR ((unsigned char) src[3]))
527 if (! IDENT_CHAR ((unsigned char) src[2]))
533 if (src[2] == 'g' && ! IDENT_CHAR ((unsigned char) src[3]))
541 if (src[1] == 'x' && src[2] >= '0' && src[2] <= '1'
542 && ! IDENT_CHAR ((unsigned char) src[3]))
545 *reg = 4 + (src[1] - '0');
548 if (src[1] == 'y' && src[2] >= '0' && src[2] <= '1'
549 && ! IDENT_CHAR ((unsigned char) src[3]))
552 *reg = 6 + (src[1] - '0');
555 if (src[1] == 's' && src[2] >= '0' && src[2] <= '3'
556 && ! IDENT_CHAR ((unsigned char) src[3]))
558 int n = src[1] - '0';
561 *reg = n | ((~n & 2) << 1);
566 if (src[0] == 'i' && src[1] && ! IDENT_CHAR ((unsigned char) src[3]))
588 if (src[0] == 'x' && src[1] >= '0' && src[1] <= '1'
589 && ! IDENT_CHAR ((unsigned char) src[2]))
592 *reg = A_X0_NUM + src[1] - '0';
596 if (src[0] == 'y' && src[1] >= '0' && src[1] <= '1'
597 && ! IDENT_CHAR ((unsigned char) src[2]))
600 *reg = A_Y0_NUM + src[1] - '0';
604 if (src[0] == 'm' && src[1] >= '0' && src[1] <= '1'
605 && ! IDENT_CHAR ((unsigned char) src[2]))
608 *reg = src[1] == '0' ? A_M0_NUM : A_M1_NUM;
614 && src[2] == 'r' && ! IDENT_CHAR ((unsigned char) src[3]))
620 if (src[0] == 's' && src[1] == 'p' && src[2] == 'c'
621 && ! IDENT_CHAR ((unsigned char) src[3]))
627 if (src[0] == 's' && src[1] == 'g' && src[2] == 'r'
628 && ! IDENT_CHAR ((unsigned char) src[3]))
634 if (src[0] == 'd' && src[1] == 's' && src[2] == 'r'
635 && ! IDENT_CHAR ((unsigned char) src[3]))
641 if (src[0] == 'd' && src[1] == 'b' && src[2] == 'r'
642 && ! IDENT_CHAR ((unsigned char) src[3]))
648 if (src[0] == 's' && src[1] == 'r' && ! IDENT_CHAR ((unsigned char) src[2]))
654 if (src[0] == 's' && src[1] == 'p' && ! IDENT_CHAR ((unsigned char) src[2]))
661 if (src[0] == 'p' && src[1] == 'r' && ! IDENT_CHAR ((unsigned char) src[2]))
666 if (src[0] == 'p' && src[1] == 'c' && ! IDENT_CHAR ((unsigned char) src[2]))
668 /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0'
669 and use an uninitialized immediate. */
673 if (src[0] == 'g' && src[1] == 'b' && src[2] == 'r'
674 && ! IDENT_CHAR ((unsigned char) src[3]))
679 if (src[0] == 'v' && src[1] == 'b' && src[2] == 'r'
680 && ! IDENT_CHAR ((unsigned char) src[3]))
686 if (src[0] == 'm' && src[1] == 'a' && src[2] == 'c'
687 && ! IDENT_CHAR ((unsigned char) src[4]))
700 if (src[0] == 'm' && src[1] == 'o' && src[2] == 'd'
701 && ! IDENT_CHAR ((unsigned char) src[4]))
706 if (src[0] == 'f' && src[1] == 'r')
710 if (src[3] >= '0' && src[3] <= '5'
711 && ! IDENT_CHAR ((unsigned char) src[4]))
714 *reg = 10 + src[3] - '0';
718 if (src[2] >= '0' && src[2] <= '9'
719 && ! IDENT_CHAR ((unsigned char) src[3]))
722 *reg = (src[2] - '0');
726 if (src[0] == 'd' && src[1] == 'r')
730 if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1)
731 && ! IDENT_CHAR ((unsigned char) src[4]))
734 *reg = 10 + src[3] - '0';
738 if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1)
739 && ! IDENT_CHAR ((unsigned char) src[3]))
742 *reg = (src[2] - '0');
746 if (src[0] == 'x' && src[1] == 'd')
750 if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1)
751 && ! IDENT_CHAR ((unsigned char) src[4]))
754 *reg = 11 + src[3] - '0';
758 if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1)
759 && ! IDENT_CHAR ((unsigned char) src[3]))
762 *reg = (src[2] - '0') + 1;
766 if (src[0] == 'f' && src[1] == 'v')
768 if (src[2] == '1'&& src[3] == '2' && ! IDENT_CHAR ((unsigned char) src[4]))
774 if ((src[2] == '0' || src[2] == '4' || src[2] == '8')
775 && ! IDENT_CHAR ((unsigned char) src[3]))
778 *reg = (src[2] - '0');
782 if (src[0] == 'f' && src[1] == 'p' && src[2] == 'u' && src[3] == 'l'
783 && ! IDENT_CHAR ((unsigned char) src[4]))
789 if (src[0] == 'f' && src[1] == 'p' && src[2] == 's' && src[3] == 'c'
790 && src[4] == 'r' && ! IDENT_CHAR ((unsigned char) src[5]))
796 if (src[0] == 'x' && src[1] == 'm' && src[2] == 't' && src[3] == 'r'
797 && src[4] == 'x' && ! IDENT_CHAR ((unsigned char) src[5]))
811 /* JF: '.' is pseudo symbol with value of current location
812 in current segment. */
813 fake = FAKE_LABEL_NAME;
814 return symbol_new (fake,
816 (valueT) frag_now_fix (),
828 save = input_line_pointer;
829 input_line_pointer = s;
830 expression (&op->immediate);
831 if (op->immediate.X_op == O_absent)
832 as_bad (_("missing operand"));
833 new = input_line_pointer;
834 input_line_pointer = save;
838 /* The many forms of operand:
841 @Rn Register indirect
854 pr, gbr, vbr, macl, mach
867 /* Must be predecrement. */
870 len = parse_reg (src, &mode, &(op->reg));
872 as_bad (_("illegal register after @-"));
877 else if (src[0] == '(')
879 /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
882 len = parse_reg (src, &mode, &(op->reg));
883 if (len && mode == A_REG_N)
888 as_bad (_("must be @(r0,...)"));
892 /* Now can be rn or gbr */
893 len = parse_reg (src, &mode, &(op->reg));
898 else if (mode == A_REG_N)
900 op->type = A_IND_R0_REG_N;
904 as_bad (_("syntax error in @(r0,...)"));
909 /* Must be an @(disp,.. thing) */
910 src = parse_exp (src, op);
913 /* Now can be rn, gbr or pc */
914 len = parse_reg (src, &mode, &op->reg);
919 op->type = A_DISP_REG_N;
921 else if (mode == A_GBR)
923 op->type = A_DISP_GBR;
925 else if (mode == A_PC)
927 /* Turn a plain @(4,pc) into @(.+4,pc). */
928 if (op->immediate.X_op == O_constant)
930 op->immediate.X_add_symbol = dot();
931 op->immediate.X_op = O_symbol;
933 op->type = A_DISP_PC;
937 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
942 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
947 as_bad (_("expecting )"));
953 src += parse_reg (src, &mode, &(op->reg));
956 as_bad (_("illegal register after @"));
961 if ((src[0] == 'r' && src[1] == '8')
962 || (src[0] == 'i' && (src[1] == 'x' || src[1] == 's')))
967 if ((src[0] == 'r' && src[1] == '9')
968 || (src[0] == 'i' && src[1] == 'y'))
971 op->type = A_PMODY_N;
985 get_operand (ptr, op)
996 *ptr = parse_exp (src, op);
1001 else if (src[0] == '@')
1003 *ptr = parse_at (src, op);
1006 len = parse_reg (src, &mode, &(op->reg));
1015 /* Not a reg, the only thing left is a displacement. */
1016 *ptr = parse_exp (src, op);
1017 op->type = A_DISP_PC;
1023 get_operands (info, args, operand)
1024 sh_opcode_info *info;
1026 sh_operand_info *operand;
1031 /* The pre-processor will eliminate whitespace in front of '@'
1032 after the first argument; we may be called multiple times
1033 from assemble_ppi, so don't insist on finding whitespace here. */
1037 get_operand (&ptr, operand + 0);
1044 get_operand (&ptr, operand + 1);
1045 /* ??? Hack: psha/pshl have a varying operand number depending on
1046 the type of the first operand. We handle this by having the
1047 three-operand version first and reducing the number of operands
1048 parsed to two if we see that the first operand is an immediate.
1049 This works because no insn with three operands has an immediate
1050 as first operand. */
1051 if (info->arg[2] && operand[0].type != A_IMM)
1057 get_operand (&ptr, operand + 2);
1061 operand[2].type = 0;
1066 operand[1].type = 0;
1067 operand[2].type = 0;
1072 operand[0].type = 0;
1073 operand[1].type = 0;
1074 operand[2].type = 0;
1079 /* Passed a pointer to a list of opcodes which use different
1080 addressing modes, return the opcode which matches the opcodes
1083 static sh_opcode_info *
1084 get_specific (opcode, operands)
1085 sh_opcode_info *opcode;
1086 sh_operand_info *operands;
1088 sh_opcode_info *this_try = opcode;
1089 char *name = opcode->name;
1092 while (opcode->name)
1094 this_try = opcode++;
1095 if (this_try->name != name)
1097 /* We've looked so far down the table that we've run out of
1098 opcodes with the same name. */
1102 /* Look at both operands needed by the opcodes and provided by
1103 the user - since an arg test will often fail on the same arg
1104 again and again, we'll try and test the last failing arg the
1105 first on each opcode try. */
1106 for (n = 0; this_try->arg[n]; n++)
1108 sh_operand_info *user = operands + n;
1109 sh_arg_type arg = this_try->arg[n];
1121 if (user->type != arg)
1125 /* opcode needs r0 */
1126 if (user->type != A_REG_N || user->reg != 0)
1130 if (user->type != A_R0_GBR || user->reg != 0)
1134 if (user->type != F_REG_N || user->reg != 0)
1142 case A_IND_R0_REG_N:
1153 /* Opcode needs rn */
1154 if (user->type != arg)
1159 if (user->type != D_REG_N && user->type != X_REG_N)
1174 if (user->type != arg)
1179 if (user->type != arg)
1188 case A_IND_R0_REG_M:
1191 /* Opcode needs rn */
1192 if (user->type != arg - A_REG_M + A_REG_N)
1198 if (user->type != DSP_REG_N)
1220 if (user->type != DSP_REG_N)
1242 if (user->type != DSP_REG_N)
1264 if (user->type != DSP_REG_N)
1286 if (user->type != DSP_REG_N)
1308 if (user->type != DSP_REG_N || user->reg != A_A0_NUM)
1312 if (user->type != DSP_REG_N || user->reg != A_X0_NUM)
1316 if (user->type != DSP_REG_N || user->reg != A_X1_NUM)
1320 if (user->type != DSP_REG_N || user->reg != A_Y0_NUM)
1324 if (user->type != DSP_REG_N || user->reg != A_Y1_NUM)
1334 /* Opcode needs rn */
1335 if (user->type != arg - F_REG_M + F_REG_N)
1340 if (user->type != D_REG_N && user->type != X_REG_N)
1345 if (user->type != XMTRX_M4)
1351 printf (_("unhandled %d\n"), arg);
1355 if ( !(valid_arch & this_try->arch))
1357 valid_arch &= this_try->arch;
1367 check (operand, low, high)
1368 expressionS *operand;
1372 if (operand->X_op != O_constant
1373 || operand->X_add_number < low
1374 || operand->X_add_number > high)
1376 as_bad (_("operand must be absolute in range %d..%d"), low, high);
1378 return operand->X_add_number;
1382 insert (where, how, pcrel, op)
1386 sh_operand_info *op;
1388 fix_new_exp (frag_now,
1389 where - frag_now->fr_literal,
1397 build_relax (opcode, op)
1398 sh_opcode_info *opcode;
1399 sh_operand_info *op;
1401 int high_byte = target_big_endian ? 0 : 1;
1404 if (opcode->arg[0] == A_BDISP8)
1406 int what = (opcode->nibbles[1] & 4) ? COND_JUMP_DELAY : COND_JUMP;
1407 p = frag_var (rs_machine_dependent,
1408 md_relax_table[C (what, COND32)].rlx_length,
1409 md_relax_table[C (what, COND8)].rlx_length,
1411 op->immediate.X_add_symbol,
1412 op->immediate.X_add_number,
1414 p[high_byte] = (opcode->nibbles[0] << 4) | (opcode->nibbles[1]);
1416 else if (opcode->arg[0] == A_BDISP12)
1418 p = frag_var (rs_machine_dependent,
1419 md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length,
1420 md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length,
1422 op->immediate.X_add_symbol,
1423 op->immediate.X_add_number,
1425 p[high_byte] = (opcode->nibbles[0] << 4);
1430 /* Insert ldrs & ldre with fancy relocations that relaxation can recognize. */
1433 insert_loop_bounds (output, operand)
1435 sh_operand_info *operand;
1440 /* Since the low byte of the opcode will be overwritten by the reloc, we
1441 can just stash the high byte into both bytes and ignore endianness. */
1444 insert (output, BFD_RELOC_SH_LOOP_START, 1, operand);
1445 insert (output, BFD_RELOC_SH_LOOP_END, 1, operand + 1);
1449 static int count = 0;
1451 /* If the last loop insn is a two-byte-insn, it is in danger of being
1452 swapped with the insn after it. To prevent this, create a new
1453 symbol - complete with SH_LABEL reloc - after the last loop insn.
1454 If the last loop insn is four bytes long, the symbol will be
1455 right in the middle, but four byte insns are not swapped anyways. */
1456 /* A REPEAT takes 6 bytes. The SH has a 32 bit address space.
1457 Hence a 9 digit number should be enough to count all REPEATs. */
1459 sprintf (name, "_R%x", count++ & 0x3fffffff);
1460 end_sym = symbol_new (name, undefined_section, 0, &zero_address_frag);
1461 /* Make this a local symbol. */
1463 SF_SET_LOCAL (end_sym);
1464 #endif /* OBJ_COFF */
1465 symbol_table_insert (end_sym);
1466 end_sym->sy_value = operand[1].immediate;
1467 end_sym->sy_value.X_add_number += 2;
1468 fix_new (frag_now, frag_now_fix (), 2, end_sym, 0, 1, BFD_RELOC_SH_LABEL);
1471 output = frag_more (2);
1474 insert (output, BFD_RELOC_SH_LOOP_START, 1, operand);
1475 insert (output, BFD_RELOC_SH_LOOP_END, 1, operand + 1);
1477 return frag_more (2);
1480 /* Now we know what sort of opcodes it is, let's build the bytes. */
1483 build_Mytes (opcode, operand)
1484 sh_opcode_info *opcode;
1485 sh_operand_info *operand;
1490 char *output = frag_more (2);
1491 unsigned int size = 2;
1492 int low_byte = target_big_endian ? 1 : 0;
1498 for (index = 0; index < 4; index++)
1500 sh_nibble_type i = opcode->nibbles[index];
1510 nbuf[index] = reg_n;
1513 nbuf[index] = reg_m;
1516 if (reg_n < 2 || reg_n > 5)
1517 as_bad (_("Invalid register: 'r%d'"), reg_n);
1518 nbuf[index] = (reg_n & 3) | 4;
1521 nbuf[index] = reg_n | (reg_m >> 2);
1524 nbuf[index] = reg_b | 0x08;
1527 insert (output + low_byte, BFD_RELOC_SH_IMM4BY4, 0, operand);
1530 insert (output + low_byte, BFD_RELOC_SH_IMM4BY2, 0, operand);
1533 insert (output + low_byte, BFD_RELOC_SH_IMM4, 0, operand);
1536 insert (output + low_byte, BFD_RELOC_SH_IMM4BY4, 0, operand + 1);
1539 insert (output + low_byte, BFD_RELOC_SH_IMM4BY2, 0, operand + 1);
1542 insert (output + low_byte, BFD_RELOC_SH_IMM4, 0, operand + 1);
1545 insert (output + low_byte, BFD_RELOC_SH_IMM8BY4, 0, operand);
1548 insert (output + low_byte, BFD_RELOC_SH_IMM8BY2, 0, operand);
1551 insert (output + low_byte, BFD_RELOC_SH_IMM8, 0, operand);
1554 insert (output + low_byte, BFD_RELOC_SH_IMM8BY4, 0, operand + 1);
1557 insert (output + low_byte, BFD_RELOC_SH_IMM8BY2, 0, operand + 1);
1560 insert (output + low_byte, BFD_RELOC_SH_IMM8, 0, operand + 1);
1563 insert (output, BFD_RELOC_SH_PCRELIMM8BY4, 1, operand);
1566 insert (output, BFD_RELOC_SH_PCRELIMM8BY2, 1, operand);
1569 output = insert_loop_bounds (output, operand);
1570 nbuf[index] = opcode->nibbles[3];
1574 printf (_("failed for %d\n"), i);
1578 if (!target_big_endian)
1580 output[1] = (nbuf[0] << 4) | (nbuf[1]);
1581 output[0] = (nbuf[2] << 4) | (nbuf[3]);
1585 output[0] = (nbuf[0] << 4) | (nbuf[1]);
1586 output[1] = (nbuf[2] << 4) | (nbuf[3]);
1591 /* Find an opcode at the start of *STR_P in the hash table, and set
1592 *STR_P to the first character after the last one read. */
1594 static sh_opcode_info *
1595 find_cooked_opcode (str_p)
1599 unsigned char *op_start;
1600 unsigned char *op_end;
1604 /* Drop leading whitespace. */
1608 /* Find the op code end.
1609 The pre-processor will eliminate whitespace in front of
1610 any '@' after the first argument; we may be called from
1611 assemble_ppi, so the opcode might be terminated by an '@'. */
1612 for (op_start = op_end = (unsigned char *) (str);
1615 && !is_end_of_line[*op_end] && *op_end != ' ' && *op_end != '@';
1618 unsigned char c = op_start[nlen];
1620 /* The machine independent code will convert CMP/EQ into cmp/EQ
1621 because it thinks the '/' is the end of the symbol. Moreover,
1622 all but the first sub-insn is a parallel processing insn won't
1623 be capitailzed. Instead of hacking up the machine independent
1624 code, we just deal with it here. */
1625 c = isupper (c) ? tolower (c) : c;
1634 as_bad (_("can't find opcode "));
1636 return (sh_opcode_info *) hash_find (opcode_hash_control, name);
1639 /* Assemble a parallel processing insn. */
1640 #define DDT_BASE 0xf000 /* Base value for double data transfer insns */
1643 assemble_ppi (op_end, opcode)
1645 sh_opcode_info *opcode;
1655 /* Some insn ignore one or more register fields, e.g. psts machl,a0.
1656 Make sure we encode a defined insn pattern. */
1662 sh_operand_info operand[3];
1664 if (opcode->arg[0] != A_END)
1665 op_end = get_operands (opcode, op_end, operand);
1666 opcode = get_specific (opcode, operand);
1669 /* Couldn't find an opcode which matched the operands. */
1670 char *where = frag_more (2);
1675 as_bad (_("invalid operands for opcode"));
1679 if (opcode->nibbles[0] != PPI)
1680 as_bad (_("insn can't be combined with parallel processing insn"));
1682 switch (opcode->nibbles[1])
1687 as_bad (_("multiple movx specifications"));
1692 as_bad (_("multiple movy specifications"));
1698 as_bad (_("multiple movx specifications"));
1699 if (reg_n < 4 || reg_n > 5)
1700 as_bad (_("invalid movx address register"));
1701 if (opcode->nibbles[2] & 8)
1703 if (reg_m == A_A1_NUM)
1705 else if (reg_m != A_A0_NUM)
1706 as_bad (_("invalid movx dsp register"));
1711 as_bad (_("invalid movx dsp register"));
1714 movx += ((reg_n - 4) << 9) + (opcode->nibbles[2] << 2) + DDT_BASE;
1719 as_bad (_("multiple movy specifications"));
1720 if (opcode->nibbles[2] & 8)
1722 /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode,
1725 if (reg_m == A_A1_NUM)
1727 else if (reg_m != A_A0_NUM)
1728 as_bad (_("invalid movy dsp register"));
1733 as_bad (_("invalid movy dsp register"));
1736 if (reg_n < 6 || reg_n > 7)
1737 as_bad (_("invalid movy address register"));
1738 movy += ((reg_n - 6) << 8) + opcode->nibbles[2] + DDT_BASE;
1742 if (operand[0].immediate.X_op != O_constant)
1743 as_bad (_("dsp immediate shift value not constant"));
1744 field_b = ((opcode->nibbles[2] << 12)
1745 | (operand[0].immediate.X_add_number & 127) << 4
1750 as_bad (_("multiple parallel processing specifications"));
1751 field_b = ((opcode->nibbles[2] << 12) + (opcode->nibbles[3] << 8)
1752 + (reg_x << 6) + (reg_y << 4) + reg_n);
1756 as_bad (_("multiple condition specifications"));
1757 cond = opcode->nibbles[2] << 8;
1759 goto skip_cond_check;
1763 as_bad (_("multiple parallel processing specifications"));
1764 field_b = ((opcode->nibbles[2] << 12) + (opcode->nibbles[3] << 8)
1765 + cond + (reg_x << 6) + (reg_y << 4) + reg_n);
1771 if ((field_b & 0xef00) != 0xa100)
1772 as_bad (_("insn cannot be combined with pmuls"));
1774 switch (field_b & 0xf)
1777 field_b += 0 - A_X0_NUM;
1780 field_b += 1 - A_Y0_NUM;
1783 field_b += 2 - A_A0_NUM;
1786 field_b += 3 - A_A1_NUM;
1789 as_bad (_("bad padd / psub pmuls output operand"));
1792 field_b += 0x4000 + reg_efg;
1799 as_bad (_("condition not followed by conditionalizable insn"));
1805 opcode = find_cooked_opcode (&op_end);
1809 (_("unrecognized characters at end of parallel processing insn")));
1814 move_code = movx | movy;
1817 /* Parallel processing insn. */
1818 unsigned long ppi_code = (movx | movy | 0xf800) << 16 | field_b;
1820 output = frag_more (4);
1822 if (! target_big_endian)
1824 output[3] = ppi_code >> 8;
1825 output[2] = ppi_code;
1829 output[2] = ppi_code >> 8;
1830 output[3] = ppi_code;
1832 move_code |= 0xf800;
1836 /* Just a double data transfer. */
1837 output = frag_more (2);
1840 if (! target_big_endian)
1842 output[1] = move_code >> 8;
1843 output[0] = move_code;
1847 output[0] = move_code >> 8;
1848 output[1] = move_code;
1853 /* This is the guts of the machine-dependent assembler. STR points to a
1854 machine dependent instruction. This function is supposed to emit
1855 the frags/bytes it assembles to. */
1861 unsigned char *op_end;
1862 sh_operand_info operand[3];
1863 sh_opcode_info *opcode;
1866 opcode = find_cooked_opcode (&str);
1871 as_bad (_("unknown opcode"));
1876 && ! seg_info (now_seg)->tc_segment_info_data.in_code)
1878 /* Output a CODE reloc to tell the linker that the following
1879 bytes are instructions, not data. */
1880 fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0,
1882 seg_info (now_seg)->tc_segment_info_data.in_code = 1;
1885 if (opcode->nibbles[0] == PPI)
1887 size = assemble_ppi (op_end, opcode);
1891 if (opcode->arg[0] == A_BDISP12
1892 || opcode->arg[0] == A_BDISP8)
1894 parse_exp (op_end + 1, &operand[0]);
1895 build_relax (opcode, &operand[0]);
1899 if (opcode->arg[0] == A_END)
1901 /* Ignore trailing whitespace. If there is any, it has already
1902 been compressed to a single space. */
1908 op_end = get_operands (opcode, op_end, operand);
1910 opcode = get_specific (opcode, operand);
1914 /* Couldn't find an opcode which matched the operands. */
1915 char *where = frag_more (2);
1920 as_bad (_("invalid operands for opcode"));
1925 as_bad (_("excess operands: '%s'"), op_end);
1927 size = build_Mytes (opcode, operand);
1932 if (debug_type == DEBUG_DWARF2)
1933 dwarf2_generate_asm_lineno (size);
1936 /* This routine is called each time a label definition is seen. It
1937 emits a BFD_RELOC_SH_LABEL reloc if necessary. */
1942 static fragS *last_label_frag;
1943 static int last_label_offset;
1946 && seg_info (now_seg)->tc_segment_info_data.in_code)
1950 offset = frag_now_fix ();
1951 if (frag_now != last_label_frag
1952 || offset != last_label_offset)
1954 fix_new (frag_now, offset, 2, &abs_symbol, 0, 0, BFD_RELOC_SH_LABEL);
1955 last_label_frag = frag_now;
1956 last_label_offset = offset;
1961 /* This routine is called when the assembler is about to output some
1962 data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */
1965 sh_flush_pending_output ()
1968 && seg_info (now_seg)->tc_segment_info_data.in_code)
1970 fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0,
1972 seg_info (now_seg)->tc_segment_info_data.in_code = 0;
1977 md_undefined_symbol (name)
1981 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. Otherwise we
1982 have no need to default values of symbols. */
1983 if (strcmp (name, GLOBAL_OFFSET_TABLE_NAME) == 0)
1987 if (symbol_find (name))
1988 as_bad ("GOT already in the symbol table");
1990 GOT_symbol = symbol_new (name, undefined_section,
1991 (valueT)0, & zero_address_frag);
1996 #endif /* OBJ_ELF */
2002 #ifndef BFD_ASSEMBLER
2005 tc_crawl_symbol_chain (headers)
2006 object_headers *headers;
2008 printf (_("call to tc_crawl_symbol_chain \n"));
2012 tc_headers_hook (headers)
2013 object_headers *headers;
2015 printf (_("call to tc_headers_hook \n"));
2021 /* Various routines to kill one day. */
2022 /* Equal to MAX_PRECISION in atof-ieee.c. */
2023 #define MAX_LITTLENUMS 6
2025 /* Turn a string in input_line_pointer into a floating point constant
2026 of type TYPE, and store the appropriate bytes in *LITP. The number
2027 of LITTLENUMS emitted is stored in *SIZEP . An error message is
2028 returned, or NULL on OK. */
2031 md_atof (type, litP, sizeP)
2037 LITTLENUM_TYPE words[4];
2053 return _("bad call to md_atof");
2056 t = atof_ieee (input_line_pointer, type, words);
2058 input_line_pointer = t;
2062 if (! target_big_endian)
2064 for (i = prec - 1; i >= 0; i--)
2066 md_number_to_chars (litP, (valueT) words[i], 2);
2072 for (i = 0; i < prec; i++)
2074 md_number_to_chars (litP, (valueT) words[i], 2);
2082 /* Handle the .uses pseudo-op. This pseudo-op is used just before a
2083 call instruction. It refers to a label of the instruction which
2084 loads the register which the call uses. We use it to generate a
2085 special reloc for the linker. */
2089 int ignore ATTRIBUTE_UNUSED;
2094 as_warn (_(".uses pseudo-op seen when not relaxing"));
2098 if (ex.X_op != O_symbol || ex.X_add_number != 0)
2100 as_bad (_("bad .uses format"));
2101 ignore_rest_of_line ();
2105 fix_new_exp (frag_now, frag_now_fix (), 2, &ex, 1, BFD_RELOC_SH_USES);
2107 demand_empty_rest_of_line ();
2110 CONST char *md_shortopts = "";
2111 struct option md_longopts[] =
2113 #define OPTION_RELAX (OPTION_MD_BASE)
2114 #define OPTION_LITTLE (OPTION_MD_BASE + 1)
2115 #define OPTION_SMALL (OPTION_LITTLE + 1)
2116 #define OPTION_DSP (OPTION_SMALL + 1)
2118 {"relax", no_argument, NULL, OPTION_RELAX},
2119 {"little", no_argument, NULL, OPTION_LITTLE},
2120 {"small", no_argument, NULL, OPTION_SMALL},
2121 {"dsp", no_argument, NULL, OPTION_DSP},
2122 {NULL, no_argument, NULL, 0}
2124 size_t md_longopts_size = sizeof (md_longopts);
2127 md_parse_option (c, arg)
2129 char *arg ATTRIBUTE_UNUSED;
2139 target_big_endian = 0;
2158 md_show_usage (stream)
2161 fprintf (stream, _("\
2163 -little generate little endian code\n\
2164 -relax alter jump instructions for long displacements\n\
2165 -small align sections to 4 byte boundaries, not 16\n\
2166 -dsp enable sh-dsp insns, and disable sh3e / sh4 insns.\n"));
2170 tc_Nout_fix_to_chars ()
2172 printf (_("call to tc_Nout_fix_to_chars \n"));
2176 /* This struct is used to pass arguments to sh_count_relocs through
2177 bfd_map_over_sections. */
2179 struct sh_count_relocs
2181 /* Symbol we are looking for. */
2183 /* Count of relocs found. */
2187 /* Count the number of fixups in a section which refer to a particular
2188 symbol. When using BFD_ASSEMBLER, this is called via
2189 bfd_map_over_sections. */
2192 sh_count_relocs (abfd, sec, data)
2193 bfd *abfd ATTRIBUTE_UNUSED;
2197 struct sh_count_relocs *info = (struct sh_count_relocs *) data;
2198 segment_info_type *seginfo;
2202 seginfo = seg_info (sec);
2203 if (seginfo == NULL)
2207 for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next)
2209 if (fix->fx_addsy == sym)
2217 /* Handle the count relocs for a particular section. When using
2218 BFD_ASSEMBLER, this is called via bfd_map_over_sections. */
2221 sh_frob_section (abfd, sec, ignore)
2222 bfd *abfd ATTRIBUTE_UNUSED;
2224 PTR ignore ATTRIBUTE_UNUSED;
2226 segment_info_type *seginfo;
2229 seginfo = seg_info (sec);
2230 if (seginfo == NULL)
2233 for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next)
2238 struct sh_count_relocs info;
2240 if (fix->fx_r_type != BFD_RELOC_SH_USES)
2243 /* The BFD_RELOC_SH_USES reloc should refer to a defined local
2244 symbol in the same section. */
2245 sym = fix->fx_addsy;
2247 || fix->fx_subsy != NULL
2248 || fix->fx_addnumber != 0
2249 || S_GET_SEGMENT (sym) != sec
2250 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
2251 || S_GET_STORAGE_CLASS (sym) == C_EXT
2253 || S_IS_EXTERNAL (sym))
2255 as_warn_where (fix->fx_file, fix->fx_line,
2256 _(".uses does not refer to a local symbol in the same section"));
2260 /* Look through the fixups again, this time looking for one
2261 at the same location as sym. */
2262 val = S_GET_VALUE (sym);
2263 for (fscan = seginfo->fix_root;
2265 fscan = fscan->fx_next)
2266 if (val == fscan->fx_frag->fr_address + fscan->fx_where
2267 && fscan->fx_r_type != BFD_RELOC_SH_ALIGN
2268 && fscan->fx_r_type != BFD_RELOC_SH_CODE
2269 && fscan->fx_r_type != BFD_RELOC_SH_DATA
2270 && fscan->fx_r_type != BFD_RELOC_SH_LABEL)
2274 as_warn_where (fix->fx_file, fix->fx_line,
2275 _("can't find fixup pointed to by .uses"));
2279 if (fscan->fx_tcbit)
2281 /* We've already done this one. */
2285 /* The variable fscan should also be a fixup to a local symbol
2286 in the same section. */
2287 sym = fscan->fx_addsy;
2289 || fscan->fx_subsy != NULL
2290 || fscan->fx_addnumber != 0
2291 || S_GET_SEGMENT (sym) != sec
2292 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
2293 || S_GET_STORAGE_CLASS (sym) == C_EXT
2295 || S_IS_EXTERNAL (sym))
2297 as_warn_where (fix->fx_file, fix->fx_line,
2298 _(".uses target does not refer to a local symbol in the same section"));
2302 /* Now we look through all the fixups of all the sections,
2303 counting the number of times we find a reference to sym. */
2306 #ifdef BFD_ASSEMBLER
2307 bfd_map_over_sections (stdoutput, sh_count_relocs, (PTR) &info);
2312 for (iscan = SEG_E0; iscan < SEG_UNKNOWN; iscan++)
2313 sh_count_relocs ((bfd *) NULL, iscan, (PTR) &info);
2320 /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym.
2321 We have already adjusted the value of sym to include the
2322 fragment address, so we undo that adjustment here. */
2323 subseg_change (sec, 0);
2324 fix_new (symbol_get_frag (sym),
2325 S_GET_VALUE (sym) - symbol_get_frag (sym)->fr_address,
2326 4, &abs_symbol, info.count, 0, BFD_RELOC_SH_COUNT);
2330 /* This function is called after the symbol table has been completed,
2331 but before the relocs or section contents have been written out.
2332 If we have seen any .uses pseudo-ops, they point to an instruction
2333 which loads a register with the address of a function. We look
2334 through the fixups to find where the function address is being
2335 loaded from. We then generate a COUNT reloc giving the number of
2336 times that function address is referred to. The linker uses this
2337 information when doing relaxing, to decide when it can eliminate
2338 the stored function address entirely. */
2346 #ifdef BFD_ASSEMBLER
2347 bfd_map_over_sections (stdoutput, sh_frob_section, (PTR) NULL);
2352 for (iseg = SEG_E0; iseg < SEG_UNKNOWN; iseg++)
2353 sh_frob_section ((bfd *) NULL, iseg, (PTR) NULL);
2358 /* Called after relaxing. Set the correct sizes of the fragments, and
2359 create relocs so that md_apply_fix will fill in the correct values. */
2362 md_convert_frag (headers, seg, fragP)
2363 #ifdef BFD_ASSEMBLER
2364 bfd *headers ATTRIBUTE_UNUSED;
2366 object_headers *headers;
2373 switch (fragP->fr_subtype)
2375 case C (COND_JUMP, COND8):
2376 case C (COND_JUMP_DELAY, COND8):
2377 subseg_change (seg, 0);
2378 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
2379 1, BFD_RELOC_SH_PCDISP8BY2);
2384 case C (UNCOND_JUMP, UNCOND12):
2385 subseg_change (seg, 0);
2386 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
2387 1, BFD_RELOC_SH_PCDISP12BY2);
2392 case C (UNCOND_JUMP, UNCOND32):
2393 case C (UNCOND_JUMP, UNDEF_WORD_DISP):
2394 if (fragP->fr_symbol == NULL)
2395 as_bad (_("at 0x%lx, displacement overflows 12-bit field"),
2396 (unsigned long) fragP->fr_address);
2397 else if (S_IS_DEFINED (fragP->fr_symbol))
2398 as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 12-bit field"),
2399 (unsigned long) fragP->fr_address,
2400 S_GET_NAME (fragP->fr_symbol));
2402 as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 12-bit field"),
2403 (unsigned long) fragP->fr_address,
2404 S_GET_NAME (fragP->fr_symbol));
2408 case C (COND_JUMP, COND12):
2409 case C (COND_JUMP_DELAY, COND12):
2410 /* A bcond won't fit, so turn it into a b!cond; bra disp; nop. */
2411 /* I found that a relax failure for gcc.c-torture/execute/930628-1.c
2412 was due to gas incorrectly relaxing an out-of-range conditional
2413 branch with delay slot. It turned:
2414 bf.s L6 (slot mov.l r12,@(44,r0))
2417 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6)
2419 32: 10 cb mov.l r12,@(44,r0)
2420 Therefore, branches with delay slots have to be handled
2421 differently from ones without delay slots. */
2423 unsigned char *buffer =
2424 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
2425 int highbyte = target_big_endian ? 0 : 1;
2426 int lowbyte = target_big_endian ? 1 : 0;
2427 int delay = fragP->fr_subtype == C (COND_JUMP_DELAY, COND12);
2429 /* Toggle the true/false bit of the bcond. */
2430 buffer[highbyte] ^= 0x2;
2432 /* If this is a dalayed branch, we may not put the the bra in the
2433 slot. So we change it to a non-delayed branch, like that:
2434 b! cond slot_label; bra disp; slot_label: slot_insn
2435 ??? We should try if swapping the conditional branch and
2436 its delay-slot insn already makes the branch reach. */
2438 /* Build a relocation to six / four bytes farther on. */
2439 subseg_change (seg, 0);
2440 fix_new (fragP, fragP->fr_fix, 2,
2441 #ifdef BFD_ASSEMBLER
2442 section_symbol (seg),
2444 seg_info (seg)->dot,
2446 fragP->fr_address + fragP->fr_fix + (delay ? 4 : 6),
2447 1, BFD_RELOC_SH_PCDISP8BY2);
2449 /* Set up a jump instruction. */
2450 buffer[highbyte + 2] = 0xa0;
2451 buffer[lowbyte + 2] = 0;
2452 fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
2453 fragP->fr_offset, 1, BFD_RELOC_SH_PCDISP12BY2);
2457 buffer[highbyte] &= ~0x4; /* Removes delay slot from branch. */
2462 /* Fill in a NOP instruction. */
2463 buffer[highbyte + 4] = 0x0;
2464 buffer[lowbyte + 4] = 0x9;
2473 case C (COND_JUMP, COND32):
2474 case C (COND_JUMP_DELAY, COND32):
2475 case C (COND_JUMP, UNDEF_WORD_DISP):
2476 case C (COND_JUMP_DELAY, UNDEF_WORD_DISP):
2477 if (fragP->fr_symbol == NULL)
2478 as_bad (_("at 0x%lx, displacement overflows 8-bit field"),
2479 (unsigned long) fragP->fr_address);
2480 else if (S_IS_DEFINED (fragP->fr_symbol))
2481 as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 8-bit field "),
2482 (unsigned long) fragP->fr_address,
2483 S_GET_NAME (fragP->fr_symbol));
2485 as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 8-bit field "),
2486 (unsigned long) fragP->fr_address,
2487 S_GET_NAME (fragP->fr_symbol));
2494 if (donerelax && !sh_relax)
2495 as_warn_where (fragP->fr_file, fragP->fr_line,
2496 _("overflow in branch to %s; converted into longer instruction sequence"),
2497 (fragP->fr_symbol != NULL
2498 ? S_GET_NAME (fragP->fr_symbol)
2503 md_section_align (seg, size)
2507 #ifdef BFD_ASSEMBLER
2510 #else /* ! OBJ_ELF */
2511 return ((size + (1 << bfd_get_section_alignment (stdoutput, seg)) - 1)
2512 & (-1 << bfd_get_section_alignment (stdoutput, seg)));
2513 #endif /* ! OBJ_ELF */
2514 #else /* ! BFD_ASSEMBLER */
2515 return ((size + (1 << section_alignment[(int) seg]) - 1)
2516 & (-1 << section_alignment[(int) seg]));
2517 #endif /* ! BFD_ASSEMBLER */
2520 /* This static variable is set by s_uacons to tell sh_cons_align that
2521 the expession does not need to be aligned. */
2523 static int sh_no_align_cons = 0;
2525 /* This handles the unaligned space allocation pseudo-ops, such as
2526 .uaword. .uaword is just like .word, but the value does not need
2533 /* Tell sh_cons_align not to align this value. */
2534 sh_no_align_cons = 1;
2538 /* If a .word, et. al., pseud-op is seen, warn if the value is not
2539 aligned correctly. Note that this can cause warnings to be issued
2540 when assembling initialized structured which were declared with the
2541 packed attribute. FIXME: Perhaps we should require an option to
2542 enable this warning? */
2545 sh_cons_align (nbytes)
2551 if (sh_no_align_cons)
2553 /* This is an unaligned pseudo-op. */
2554 sh_no_align_cons = 0;
2559 while ((nbytes & 1) == 0)
2568 if (now_seg == absolute_section)
2570 if ((abs_section_offset & ((1 << nalign) - 1)) != 0)
2571 as_warn (_("misaligned data"));
2575 p = frag_var (rs_align_code, 1, 1, (relax_substateT) 0,
2576 (symbolS *) NULL, (offsetT) nalign, (char *) NULL);
2578 record_alignment (now_seg, nalign);
2581 /* When relaxing, we need to output a reloc for any .align directive
2582 that requests alignment to a four byte boundary or larger. This is
2583 also where we check for misaligned data. */
2586 sh_handle_align (frag)
2590 && frag->fr_type == rs_align
2591 && frag->fr_address + frag->fr_fix > 0
2592 && frag->fr_offset > 1
2593 && now_seg != bss_section)
2594 fix_new (frag, frag->fr_fix, 2, &abs_symbol, frag->fr_offset, 0,
2595 BFD_RELOC_SH_ALIGN);
2597 if (frag->fr_type == rs_align_code
2598 && frag->fr_next->fr_address - frag->fr_address - frag->fr_fix != 0)
2599 as_warn_where (frag->fr_file, frag->fr_line, _("misaligned data"));
2602 /* This macro decides whether a particular reloc is an entry in a
2603 switch table. It is used when relaxing, because the linker needs
2604 to know about all such entries so that it can adjust them if
2607 #ifdef BFD_ASSEMBLER
2608 #define SWITCH_TABLE_CONS(fix) (0)
2610 #define SWITCH_TABLE_CONS(fix) \
2611 ((fix)->fx_r_type == 0 \
2612 && ((fix)->fx_size == 2 \
2613 || (fix)->fx_size == 1 \
2614 || (fix)->fx_size == 4))
2617 #define SWITCH_TABLE(fix) \
2618 ((fix)->fx_addsy != NULL \
2619 && (fix)->fx_subsy != NULL \
2620 && S_GET_SEGMENT ((fix)->fx_addsy) == text_section \
2621 && S_GET_SEGMENT ((fix)->fx_subsy) == text_section \
2622 && ((fix)->fx_r_type == BFD_RELOC_32 \
2623 || (fix)->fx_r_type == BFD_RELOC_16 \
2624 || (fix)->fx_r_type == BFD_RELOC_8 \
2625 || SWITCH_TABLE_CONS (fix)))
2627 /* See whether we need to force a relocation into the output file.
2628 This is used to force out switch and PC relative relocations when
2632 sh_force_relocation (fix)
2636 if (fix->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2637 || fix->fx_r_type == BFD_RELOC_VTABLE_ENTRY
2638 || fix->fx_r_type == BFD_RELOC_SH_LOOP_START
2639 || fix->fx_r_type == BFD_RELOC_SH_LOOP_END)
2645 return (fix->fx_pcrel
2646 || SWITCH_TABLE (fix)
2647 || fix->fx_r_type == BFD_RELOC_SH_COUNT
2648 || fix->fx_r_type == BFD_RELOC_SH_ALIGN
2649 || fix->fx_r_type == BFD_RELOC_SH_CODE
2650 || fix->fx_r_type == BFD_RELOC_SH_DATA
2651 || fix->fx_r_type == BFD_RELOC_SH_LABEL);
2656 sh_fix_adjustable (fixP)
2660 if (fixP->fx_addsy == NULL)
2663 if (fixP->fx_r_type == BFD_RELOC_SH_PCDISP8BY2
2664 || fixP->fx_r_type == BFD_RELOC_SH_PCDISP12BY2
2665 || fixP->fx_r_type == BFD_RELOC_SH_PCRELIMM8BY2
2666 || fixP->fx_r_type == BFD_RELOC_SH_PCRELIMM8BY4
2667 || fixP->fx_r_type == BFD_RELOC_8_PCREL
2668 || fixP->fx_r_type == BFD_RELOC_SH_SWITCH16
2669 || fixP->fx_r_type == BFD_RELOC_SH_SWITCH32)
2672 if (! TC_RELOC_RTSYM_LOC_FIXUP (fixP)
2673 || fixP->fx_r_type == BFD_RELOC_32_GOTOFF
2674 || fixP->fx_r_type == BFD_RELOC_RVA)
2677 /* We need the symbol name for the VTABLE entries */
2678 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2679 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2686 sh_elf_final_processing ()
2690 /* Set file-specific flags to indicate if this code needs
2691 a processor with the sh-dsp / sh3e ISA to execute. */
2692 if (valid_arch & arch_sh1)
2694 else if (valid_arch & arch_sh2)
2696 else if (valid_arch & arch_sh_dsp)
2698 else if (valid_arch & arch_sh3)
2700 else if (valid_arch & arch_sh3_dsp)
2702 else if (valid_arch & arch_sh3e)
2704 else if (valid_arch & arch_sh4)
2709 elf_elfheader (stdoutput)->e_flags &= ~EF_SH_MACH_MASK;
2710 elf_elfheader (stdoutput)->e_flags |= val;
2714 /* Apply a fixup to the object file. */
2716 #ifdef BFD_ASSEMBLER
2718 md_apply_fix (fixP, valp)
2723 md_apply_fix (fixP, val)
2728 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2729 int lowbyte = target_big_endian ? 1 : 0;
2730 int highbyte = target_big_endian ? 0 : 1;
2731 #ifdef BFD_ASSEMBLER
2737 #ifdef BFD_ASSEMBLER
2738 /* A difference between two symbols, the second of which is in the
2739 current section, is transformed in a PC-relative relocation to
2740 the other symbol. We have to adjust the relocation type here. */
2743 switch (fixP->fx_r_type)
2749 fixP->fx_r_type = BFD_RELOC_32_PCREL;
2752 /* Currently, we only support 32-bit PCREL relocations.
2753 We'd need a new reloc type to handle 16_PCREL, and
2754 8_PCREL is already taken for R_SH_SWITCH8, which
2755 apparently does something completely different than what
2758 bfd_set_error (bfd_error_bad_value);
2762 bfd_set_error (bfd_error_bad_value);
2767 /* The function adjust_reloc_syms won't convert a reloc against a weak
2768 symbol into a reloc against a section, but bfd_install_relocation
2769 will screw up if the symbol is defined, so we have to adjust val here
2770 to avoid the screw up later. */
2771 if (fixP->fx_addsy != NULL
2772 && S_IS_WEAK (fixP->fx_addsy))
2773 val -= S_GET_VALUE (fixP->fx_addsy);
2776 #ifndef BFD_ASSEMBLER
2777 if (fixP->fx_r_type == 0)
2779 if (fixP->fx_size == 2)
2780 fixP->fx_r_type = BFD_RELOC_16;
2781 else if (fixP->fx_size == 4)
2782 fixP->fx_r_type = BFD_RELOC_32;
2783 else if (fixP->fx_size == 1)
2784 fixP->fx_r_type = BFD_RELOC_8;
2792 switch (fixP->fx_r_type)
2794 case BFD_RELOC_SH_IMM4:
2796 *buf = (*buf & 0xf0) | (val & 0xf);
2799 case BFD_RELOC_SH_IMM4BY2:
2802 *buf = (*buf & 0xf0) | ((val >> 1) & 0xf);
2805 case BFD_RELOC_SH_IMM4BY4:
2808 *buf = (*buf & 0xf0) | ((val >> 2) & 0xf);
2811 case BFD_RELOC_SH_IMM8BY2:
2817 case BFD_RELOC_SH_IMM8BY4:
2824 case BFD_RELOC_SH_IMM8:
2825 /* Sometimes the 8 bit value is sign extended (e.g., add) and
2826 sometimes it is not (e.g., and). We permit any 8 bit value.
2827 Note that adding further restrictions may invalidate
2828 reasonable looking assembly code, such as ``and -0x1,r0''. */
2834 case BFD_RELOC_SH_PCRELIMM8BY4:
2835 /* The lower two bits of the PC are cleared before the
2836 displacement is added in. We can assume that the destination
2837 is on a 4 byte bounday. If this instruction is also on a 4
2838 byte boundary, then we want
2840 and target - here is a multiple of 4.
2841 Otherwise, we are on a 2 byte boundary, and we want
2842 (target - (here - 2)) / 4
2843 and target - here is not a multiple of 4. Computing
2844 (target - (here - 2)) / 4 == (target - here + 2) / 4
2845 works for both cases, since in the first case the addition of
2846 2 will be removed by the division. target - here is in the
2848 val = (val + 2) / 4;
2850 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
2854 case BFD_RELOC_SH_PCRELIMM8BY2:
2857 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
2861 case BFD_RELOC_SH_PCDISP8BY2:
2863 if (val < -0x80 || val > 0x7f)
2864 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
2868 case BFD_RELOC_SH_PCDISP12BY2:
2870 if (val < -0x800 || val >= 0x7ff)
2871 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
2872 buf[lowbyte] = val & 0xff;
2873 buf[highbyte] |= (val >> 8) & 0xf;
2877 case BFD_RELOC_32_PCREL:
2878 md_number_to_chars (buf, val, 4);
2882 md_number_to_chars (buf, val, 2);
2885 case BFD_RELOC_SH_USES:
2886 /* Pass the value into sh_coff_reloc_mangle. */
2887 fixP->fx_addnumber = val;
2890 case BFD_RELOC_SH_COUNT:
2891 case BFD_RELOC_SH_ALIGN:
2892 case BFD_RELOC_SH_CODE:
2893 case BFD_RELOC_SH_DATA:
2894 case BFD_RELOC_SH_LABEL:
2895 /* Nothing to do here. */
2898 case BFD_RELOC_SH_LOOP_START:
2899 case BFD_RELOC_SH_LOOP_END:
2901 case BFD_RELOC_VTABLE_INHERIT:
2902 case BFD_RELOC_VTABLE_ENTRY:
2904 #ifdef BFD_ASSEMBLER
2911 case BFD_RELOC_32_PLT_PCREL:
2912 /* Make the jump instruction point to the address of the operand. At
2913 runtime we merely add the offset to the actual PLT entry. */
2917 case BFD_RELOC_SH_GOTPC:
2918 /* This is tough to explain. We end up with this one if we have
2919 operands that look like "_GLOBAL_OFFSET_TABLE_+[.-.L284]".
2920 The goal here is to obtain the absolute address of the GOT,
2921 and it is strongly preferable from a performance point of
2922 view to avoid using a runtime relocation for this. There are
2923 cases where you have something like:
2925 .long _GLOBAL_OFFSET_TABLE_+[.-.L66]
2927 and here no correction would be required. Internally in the
2928 assembler we treat operands of this form as not being pcrel
2929 since the '.' is explicitly mentioned, and I wonder whether
2930 it would simplify matters to do it this way. Who knows. In
2931 earlier versions of the PIC patches, the pcrel_adjust field
2932 was used to store the correction, but since the expression is
2933 not pcrel, I felt it would be confusing to do it this way. */
2935 md_number_to_chars (buf, val, 4);
2938 case BFD_RELOC_32_GOT_PCREL:
2939 *valp = 0; /* Fully resolved at runtime. No addend. */
2940 md_number_to_chars (buf, 0, 4);
2943 case BFD_RELOC_32_GOTOFF:
2953 if ((val & ((1 << shift) - 1)) != 0)
2954 as_bad_where (fixP->fx_file, fixP->fx_line, _("misaligned offset"));
2958 val = ((val >> shift)
2959 | ((long) -1 & ~ ((long) -1 >> shift)));
2961 if (max != 0 && (val < min || val > max))
2962 as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range"));
2964 #ifdef BFD_ASSEMBLER
2969 /* Called just before address relaxation. Return the length
2970 by which a fragment must grow to reach it's destination. */
2973 md_estimate_size_before_relax (fragP, segment_type)
2974 register fragS *fragP;
2975 register segT segment_type;
2977 switch (fragP->fr_subtype)
2979 case C (UNCOND_JUMP, UNDEF_DISP):
2980 /* Used to be a branch to somewhere which was unknown. */
2981 if (!fragP->fr_symbol)
2983 fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12);
2984 fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length;
2986 else if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
2988 fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12);
2989 fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length;
2993 fragP->fr_subtype = C (UNCOND_JUMP, UNDEF_WORD_DISP);
2994 fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length;
2995 return md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length;
3001 case C (COND_JUMP, UNDEF_DISP):
3002 case C (COND_JUMP_DELAY, UNDEF_DISP):
3003 /* Used to be a branch to somewhere which was unknown. */
3004 if (fragP->fr_symbol
3005 && S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
3007 int what = GET_WHAT (fragP->fr_subtype);
3008 /* Got a symbol and it's defined in this segment, become byte
3009 sized - maybe it will fix up. */
3010 fragP->fr_subtype = C (what, COND8);
3011 fragP->fr_var = md_relax_table[C (what, COND8)].rlx_length;
3013 else if (fragP->fr_symbol)
3015 int what = GET_WHAT (fragP->fr_subtype);
3016 /* Its got a segment, but its not ours, so it will always be long. */
3017 fragP->fr_subtype = C (what, UNDEF_WORD_DISP);
3018 fragP->fr_var = md_relax_table[C (what, COND32)].rlx_length;
3019 return md_relax_table[C (what, COND32)].rlx_length;
3023 int what = GET_WHAT (fragP->fr_subtype);
3024 /* We know the abs value. */
3025 fragP->fr_subtype = C (what, COND8);
3026 fragP->fr_var = md_relax_table[C (what, COND8)].rlx_length;
3031 return fragP->fr_var;
3034 /* Put number into target byte order. */
3037 md_number_to_chars (ptr, use, nbytes)
3042 if (! target_big_endian)
3043 number_to_chars_littleendian (ptr, use, nbytes);
3045 number_to_chars_bigendian (ptr, use, nbytes);
3049 md_pcrel_from (fixP)
3052 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address + 2;
3058 tc_coff_sizemachdep (frag)
3061 return md_relax_table[frag->fr_subtype].rlx_length;
3064 #endif /* OBJ_COFF */
3066 /* When we align the .text section, insert the correct NOP pattern. */
3069 sh_do_align (n, fill, len, max)
3072 int len ATTRIBUTE_UNUSED;
3076 && subseg_text_p (now_seg)
3079 static const unsigned char big_nop_pattern[] = { 0x00, 0x09 };
3080 static const unsigned char little_nop_pattern[] = { 0x09, 0x00 };
3082 /* First align to a 2 byte boundary, in case there is an odd
3084 frag_align (1, 0, 0);
3085 if (target_big_endian)
3086 frag_align_pattern (n, big_nop_pattern, sizeof big_nop_pattern, max);
3088 frag_align_pattern (n, little_nop_pattern, sizeof little_nop_pattern,
3096 #ifndef BFD_ASSEMBLER
3099 /* Map BFD relocs to SH COFF relocs. */
3103 bfd_reloc_code_real_type bfd_reloc;
3107 static const struct reloc_map coff_reloc_map[] =
3109 { BFD_RELOC_32, R_SH_IMM32 },
3110 { BFD_RELOC_16, R_SH_IMM16 },
3111 { BFD_RELOC_8, R_SH_IMM8 },
3112 { BFD_RELOC_SH_PCDISP8BY2, R_SH_PCDISP8BY2 },
3113 { BFD_RELOC_SH_PCDISP12BY2, R_SH_PCDISP },
3114 { BFD_RELOC_SH_IMM4, R_SH_IMM4 },
3115 { BFD_RELOC_SH_IMM4BY2, R_SH_IMM4BY2 },
3116 { BFD_RELOC_SH_IMM4BY4, R_SH_IMM4BY4 },
3117 { BFD_RELOC_SH_IMM8, R_SH_IMM8 },
3118 { BFD_RELOC_SH_IMM8BY2, R_SH_IMM8BY2 },
3119 { BFD_RELOC_SH_IMM8BY4, R_SH_IMM8BY4 },
3120 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_PCRELIMM8BY2 },
3121 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_PCRELIMM8BY4 },
3122 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
3123 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
3124 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
3125 { BFD_RELOC_SH_USES, R_SH_USES },
3126 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
3127 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
3128 { BFD_RELOC_SH_CODE, R_SH_CODE },
3129 { BFD_RELOC_SH_DATA, R_SH_DATA },
3130 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
3131 { BFD_RELOC_UNUSED, 0 }
3134 /* Adjust a reloc for the SH. This is similar to the generic code,
3135 but does some minor tweaking. */
3138 sh_coff_reloc_mangle (seg, fix, intr, paddr)
3139 segment_info_type *seg;
3141 struct internal_reloc *intr;
3144 symbolS *symbol_ptr = fix->fx_addsy;
3147 intr->r_vaddr = paddr + fix->fx_frag->fr_address + fix->fx_where;
3149 if (! SWITCH_TABLE (fix))
3151 const struct reloc_map *rm;
3153 for (rm = coff_reloc_map; rm->bfd_reloc != BFD_RELOC_UNUSED; rm++)
3154 if (rm->bfd_reloc == (bfd_reloc_code_real_type) fix->fx_r_type)
3156 if (rm->bfd_reloc == BFD_RELOC_UNUSED)
3157 as_bad_where (fix->fx_file, fix->fx_line,
3158 _("Can not represent %s relocation in this object file format"),
3159 bfd_get_reloc_code_name (fix->fx_r_type));
3160 intr->r_type = rm->sh_reloc;
3167 if (fix->fx_r_type == BFD_RELOC_16)
3168 intr->r_type = R_SH_SWITCH16;
3169 else if (fix->fx_r_type == BFD_RELOC_8)
3170 intr->r_type = R_SH_SWITCH8;
3171 else if (fix->fx_r_type == BFD_RELOC_32)
3172 intr->r_type = R_SH_SWITCH32;
3176 /* For a switch reloc, we set r_offset to the difference between
3177 the reloc address and the subtrahend. When the linker is
3178 doing relaxing, it can use the determine the starting and
3179 ending points of the switch difference expression. */
3180 intr->r_offset = intr->r_vaddr - S_GET_VALUE (fix->fx_subsy);
3183 /* PC relative relocs are always against the current section. */
3184 if (symbol_ptr == NULL)
3186 switch (fix->fx_r_type)
3188 case BFD_RELOC_SH_PCRELIMM8BY2:
3189 case BFD_RELOC_SH_PCRELIMM8BY4:
3190 case BFD_RELOC_SH_PCDISP8BY2:
3191 case BFD_RELOC_SH_PCDISP12BY2:
3192 case BFD_RELOC_SH_USES:
3193 symbol_ptr = seg->dot;
3200 if (fix->fx_r_type == BFD_RELOC_SH_USES)
3202 /* We can't store the offset in the object file, since this
3203 reloc does not take up any space, so we store it in r_offset.
3204 The fx_addnumber field was set in md_apply_fix. */
3205 intr->r_offset = fix->fx_addnumber;
3207 else if (fix->fx_r_type == BFD_RELOC_SH_COUNT)
3209 /* We can't store the count in the object file, since this reloc
3210 does not take up any space, so we store it in r_offset. The
3211 fx_offset field was set when the fixup was created in
3212 sh_coff_frob_file. */
3213 intr->r_offset = fix->fx_offset;
3214 /* This reloc is always absolute. */
3217 else if (fix->fx_r_type == BFD_RELOC_SH_ALIGN)
3219 /* Store the alignment in the r_offset field. */
3220 intr->r_offset = fix->fx_offset;
3221 /* This reloc is always absolute. */
3224 else if (fix->fx_r_type == BFD_RELOC_SH_CODE
3225 || fix->fx_r_type == BFD_RELOC_SH_DATA
3226 || fix->fx_r_type == BFD_RELOC_SH_LABEL)
3228 /* These relocs are always absolute. */
3232 /* Turn the segment of the symbol into an offset. */
3233 if (symbol_ptr != NULL)
3235 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
3237 intr->r_symndx = dot->sy_number;
3239 intr->r_symndx = symbol_ptr->sy_number;
3242 intr->r_symndx = -1;
3245 #endif /* OBJ_COFF */
3246 #endif /* ! BFD_ASSEMBLER */
3248 #ifdef BFD_ASSEMBLER
3250 /* Create a reloc. */
3253 tc_gen_reloc (section, fixp)
3254 asection *section ATTRIBUTE_UNUSED;
3258 bfd_reloc_code_real_type r_type;
3260 rel = (arelent *) xmalloc (sizeof (arelent));
3261 rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3262 *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
3263 rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
3265 r_type = fixp->fx_r_type;
3267 if (SWITCH_TABLE (fixp))
3269 rel->addend = rel->address - S_GET_VALUE (fixp->fx_subsy);
3270 if (r_type == BFD_RELOC_16)
3271 r_type = BFD_RELOC_SH_SWITCH16;
3272 else if (r_type == BFD_RELOC_8)
3273 r_type = BFD_RELOC_8_PCREL;
3274 else if (r_type == BFD_RELOC_32)
3275 r_type = BFD_RELOC_SH_SWITCH32;
3279 else if (r_type == BFD_RELOC_SH_USES)
3280 rel->addend = fixp->fx_addnumber;
3281 else if (r_type == BFD_RELOC_SH_COUNT)
3282 rel->addend = fixp->fx_offset;
3283 else if (r_type == BFD_RELOC_SH_ALIGN)
3284 rel->addend = fixp->fx_offset;
3285 else if (r_type == BFD_RELOC_VTABLE_INHERIT
3286 || r_type == BFD_RELOC_VTABLE_ENTRY)
3287 rel->addend = fixp->fx_offset;
3288 else if (r_type == BFD_RELOC_SH_LOOP_START
3289 || r_type == BFD_RELOC_SH_LOOP_END)
3290 rel->addend = fixp->fx_offset;
3291 else if (r_type == BFD_RELOC_SH_LABEL && fixp->fx_pcrel)
3294 rel->address = rel->addend = fixp->fx_offset;
3296 else if (fixp->fx_pcrel)
3297 rel->addend = fixp->fx_addnumber;
3298 else if (r_type == BFD_RELOC_32 || r_type == BFD_RELOC_32_GOTOFF)
3299 rel->addend = fixp->fx_addnumber;
3303 rel->howto = bfd_reloc_type_lookup (stdoutput, r_type);
3304 if (rel->howto == NULL)
3306 as_bad_where (fixp->fx_file, fixp->fx_line,
3307 _("Cannot represent relocation type %s"),
3308 bfd_get_reloc_code_name (r_type));
3309 /* Set howto to a garbage value so that we can keep going. */
3310 rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
3311 assert (rel->howto != NULL);
3317 #endif /* BFD_ASSEMBLER */
3322 if (debug_type == DEBUG_DWARF2)