1 /* tc-sh.c -- Assemble code for the Hitachi Super-H
2 Copyright (C) 1993, 94, 95, 96, 1997, 1998 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. */
22 Written By Steve Chamberlain
31 #include "opcodes/sh-opc.h"
33 const char comment_chars[] = "!";
34 const char line_separator_chars[] = ";";
35 const char line_comment_chars[] = "!#";
37 static void s_uses PARAMS ((int));
39 static void sh_count_relocs PARAMS ((bfd *, segT, PTR));
40 static void sh_frob_section PARAMS ((bfd *, segT, PTR));
42 /* This table describes all the machine specific pseudo-ops the assembler
43 has to support. The fields are:
44 pseudo-op name without dot
45 function to call to execute this pseudo-op
46 Integer arg to pass to the function
50 void s_align_bytes ();
51 static void s_uacons PARAMS ((int));
60 target_big_endian = 0;
63 const pseudo_typeS md_pseudo_table[] =
67 {"form", listing_psize, 0},
68 {"little", little, 0},
69 {"heading", listing_title, 0},
70 {"import", s_ignore, 0},
71 {"page", listing_eject, 0},
72 {"program", s_ignore, 0},
74 {"uaword", s_uacons, 2},
75 {"ualong", s_uacons, 4},
79 /*int md_reloc_size; */
81 int sh_relax; /* set if -relax seen */
83 /* Whether -small was seen. */
87 const char EXP_CHARS[] = "eE";
89 /* Chars that mean this number is a floating point constant */
92 const char FLT_CHARS[] = "rRsSfFdDxXpP";
94 #define C(a,b) ENCODE_RELAX(a,b)
96 #define JREG 14 /* Register used as a temp when relaxing */
97 #define ENCODE_RELAX(what,length) (((what) << 4) + (length))
98 #define GET_WHAT(x) ((x>>4))
100 /* These are the two types of relaxable instrction */
102 #define UNCOND_JUMP 2
110 #define UNDEF_WORD_DISP 4
116 /* Branch displacements are from the address of the branch plus
117 four, thus all minimum and maximum values have 4 added to them. */
120 #define COND8_LENGTH 2
122 /* There is one extra instruction before the branch, so we must add
123 two more bytes to account for it. */
124 #define COND12_F 4100
125 #define COND12_M -4090
126 #define COND12_LENGTH 6
128 /* ??? The minimum and maximum values are wrong, but this does not matter
129 since this relocation type is not supported yet. */
130 #define COND32_F (1<<30)
131 #define COND32_M -(1<<30)
132 #define COND32_LENGTH 14
134 #define UNCOND12_F 4098
135 #define UNCOND12_M -4092
136 #define UNCOND12_LENGTH 2
138 /* ??? The minimum and maximum values are wrong, but this does not matter
139 since this relocation type is not supported yet. */
140 #define UNCOND32_F (1<<30)
141 #define UNCOND32_M -(1<<30)
142 #define UNCOND32_LENGTH 14
144 const relax_typeS md_relax_table[C (END, 0)] = {
145 { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
146 { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
149 /* C (COND_JUMP, COND8) */
150 { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP, COND12) },
151 /* C (COND_JUMP, COND12) */
152 { COND12_F, COND12_M, COND12_LENGTH, C (COND_JUMP, COND32), },
153 /* C (COND_JUMP, COND32) */
154 { COND32_F, COND32_M, COND32_LENGTH, 0, },
155 { 0 }, { 0 }, { 0 }, { 0 },
156 { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
159 /* C (UNCOND_JUMP, UNCOND12) */
160 { UNCOND12_F, UNCOND12_M, UNCOND12_LENGTH, C (UNCOND_JUMP, UNCOND32), },
161 /* C (UNCOND_JUMP, UNCOND32) */
162 { UNCOND32_F, UNCOND32_M, UNCOND32_LENGTH, 0, },
163 { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
164 { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 },
167 static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
170 This function is called once, at assembler startup time. This should
171 set up all the tables, etc that the MD part of the assembler needs
177 sh_opcode_info *opcode;
178 char *prev_name = "";
181 target_big_endian = 1;
183 opcode_hash_control = hash_new ();
185 /* Insert unique names into hash table */
186 for (opcode = sh_table; opcode->name; opcode++)
188 if (strcmp (prev_name, opcode->name))
190 prev_name = opcode->name;
191 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
195 /* Make all the opcodes with the same name point to the same
197 opcode->name = prev_name;
206 static expressionS immediate; /* absolute expression */
216 /* try and parse a reg name, returns number of chars consumed */
218 parse_reg (src, mode, reg)
223 /* We use !isalnum for the next character after the register name, to
224 make sure that we won't accidentally recognize a symbol name such as
225 'sram' as being a reference to the register 'sr'. */
229 if (src[1] >= '0' && src[1] <= '7' && strncmp(&src[2], "_bank", 5) == 0
230 && ! isalnum (src[7]))
233 *reg = (src[1] - '0');
242 if (src[2] >= '0' && src[2] <= '5' && ! isalnum (src[3]))
245 *reg = 10 + src[2] - '0';
249 if (src[1] >= '0' && src[1] <= '9' && ! isalnum (src[2]))
252 *reg = (src[1] - '0');
257 if (src[0] == 's' && src[1] == 's' && src[2] == 'r' && ! isalnum (src[3]))
263 if (src[0] == 's' && src[1] == 'p' && src[2] == 'c' && ! isalnum (src[3]))
269 if (src[0] == 's' && src[1] == 'g' && src[2] == 'r' && ! isalnum (src[3]))
275 if (src[0] == 'd' && src[1] == 'b' && src[2] == 'r' && ! isalnum (src[3]))
281 if (src[0] == 's' && src[1] == 'r' && ! isalnum (src[2]))
287 if (src[0] == 's' && src[1] == 'p' && ! isalnum (src[2]))
294 if (src[0] == 'p' && src[1] == 'r' && ! isalnum (src[2]))
299 if (src[0] == 'p' && src[1] == 'c' && ! isalnum (src[2]))
304 if (src[0] == 'g' && src[1] == 'b' && src[2] == 'r' && ! isalnum (src[3]))
309 if (src[0] == 'v' && src[1] == 'b' && src[2] == 'r' && ! isalnum (src[3]))
315 if (src[0] == 'm' && src[1] == 'a' && src[2] == 'c' && ! isalnum (src[4]))
328 if (src[0] == 'f' && src[1] == 'r')
332 if (src[3] >= '0' && src[3] <= '5' && ! isalnum (src[4]))
335 *reg = 10 + src[3] - '0';
339 if (src[2] >= '0' && src[2] <= '9' && ! isalnum (src[3]))
342 *reg = (src[2] - '0');
346 if (src[0] == 'd' && src[1] == 'r')
350 if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1)
351 && ! isalnum (src[4]))
354 *reg = 10 + src[3] - '0';
358 if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1)
359 && ! isalnum (src[3]))
362 *reg = (src[2] - '0');
366 if (src[0] == 'x' && src[1] == 'd')
370 if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1)
371 && ! isalnum (src[4]))
374 *reg = 11 + src[3] - '0';
378 if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1)
379 && ! isalnum (src[3]))
382 *reg = (src[2] - '0') + 1;
386 if (src[0] == 'f' && src[1] == 'v')
388 if (src[2] == '1'&& src[3] == '2' && ! isalnum (src[4]))
394 if ((src[2] == '0' || src[2] == '4' || src[2] == '8') && ! isalnum (src[3]))
397 *reg = (src[2] - '0');
401 if (src[0] == 'f' && src[1] == 'p' && src[2] == 'u' && src[3] == 'l'
402 && ! isalnum (src[4]))
408 if (src[0] == 'f' && src[1] == 'p' && src[2] == 's' && src[3] == 'c'
409 && src[4] == 'r' && ! isalnum (src[5]))
415 if (src[0] == 'x' && src[1] == 'm' && src[2] == 't' && src[3] == 'r'
416 && src[4] == 'x' && ! isalnum (src[5]))
425 static symbolS *dot()
429 /* JF: '.' is pseudo symbol with value of current location
430 in current segment. */
431 fake = FAKE_LABEL_NAME;
432 return symbol_new (fake,
434 (valueT) frag_now_fix (),
448 save = input_line_pointer;
449 input_line_pointer = s;
450 expression (&immediate);
451 if (immediate.X_op == O_absent)
452 as_bad (_("missing operand"));
453 new = input_line_pointer;
454 input_line_pointer = save;
459 /* The many forms of operand:
462 @Rn Register indirect
475 pr, gbr, vbr, macl, mach
490 /* Must be predecrement */
493 len = parse_reg (src, &mode, &(op->reg));
495 as_bad (_("illegal register after @-"));
500 else if (src[0] == '(')
502 /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or
505 len = parse_reg (src, &mode, &(op->reg));
506 if (len && mode == A_REG_N)
511 as_bad (_("must be @(r0,...)"));
515 /* Now can be rn or gbr */
516 len = parse_reg (src, &mode, &(op->reg));
521 else if (mode == A_REG_N)
523 op->type = A_IND_R0_REG_N;
527 as_bad (_("syntax error in @(r0,...)"));
532 /* Must be an @(disp,.. thing) */
533 src = parse_exp (src);
536 /* Now can be rn, gbr or pc */
537 len = parse_reg (src, &mode, &op->reg);
542 op->type = A_DISP_REG_N;
544 else if (mode == A_GBR)
546 op->type = A_DISP_GBR;
548 else if (mode == A_DISP_PC)
550 /* Turn a plain @(4,pc) into @(.+4,pc) */
551 if (immediate.X_op == O_constant) {
552 immediate.X_add_symbol = dot();
553 immediate.X_op = O_symbol;
555 op->type = A_DISP_PC;
559 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
564 as_bad (_("syntax error in @(disp,[Rn, gbr, pc])"));
569 as_bad (_("expecting )"));
575 src += parse_reg (src, &mode, &(op->reg));
578 as_bad (_("illegal register after @"));
594 get_operand (ptr, op)
605 *ptr = parse_exp (src);
610 else if (src[0] == '@')
612 *ptr = parse_at (src, op);
615 len = parse_reg (src, &mode, &(op->reg));
624 /* Not a reg, the only thing left is a displacement */
625 *ptr = parse_exp (src);
626 op->type = A_DISP_PC;
633 get_operands (info, args, operand)
634 sh_opcode_info *info;
636 sh_operand_info *operand;
644 get_operand (&ptr, operand + 0);
651 get_operand (&ptr, operand + 1);
658 get_operand (&ptr, operand + 2);
680 /* Passed a pointer to a list of opcodes which use different
681 addressing modes, return the opcode which matches the opcodes
687 get_specific (opcode, operands)
688 sh_opcode_info *opcode;
689 sh_operand_info *operands;
691 sh_opcode_info *this_try = opcode;
692 char *name = opcode->name;
697 if (this_try->name != name)
699 /* We've looked so far down the table that we've run out of
700 opcodes with the same name */
703 /* look at both operands needed by the opcodes and provided by
704 the user - since an arg test will often fail on the same arg
705 again and again, we'll try and test the last failing arg the
706 first on each opcode try */
708 for (n = 0; this_try->arg[n]; n++)
710 sh_operand_info *user = operands + n;
711 sh_arg_type arg = this_try->arg[n];
722 if (user->type != arg)
726 /* opcode needs r0 */
727 if (user->type != A_REG_N || user->reg != 0)
731 if (user->type != A_R0_GBR || user->reg != 0)
735 if (user->type != F_REG_N || user->reg != 0)
751 /* Opcode needs rn */
752 if (user->type != arg)
757 if (user->type != F_REG_N && user->type != D_REG_N)
762 if (user->type != D_REG_N && user->type != X_REG_N)
773 if (user->type != arg)
778 if (user->type != arg)
789 /* Opcode needs rn */
790 if (user->type != arg - A_REG_M + A_REG_N)
801 /* Opcode needs rn */
802 if (user->type != arg - F_REG_M + F_REG_N)
807 if (user->type != D_REG_N && user->type != X_REG_N)
812 if (user->type != XMTRX_M4)
818 printf (_("unhandled %d\n"), arg);
830 check (operand, low, high)
831 expressionS *operand;
835 if (operand->X_op != O_constant
836 || operand->X_add_number < low
837 || operand->X_add_number > high)
839 as_bad (_("operand must be absolute in range %d..%d"), low, high);
841 return operand->X_add_number;
846 insert (where, how, pcrel)
851 fix_new_exp (frag_now,
852 where - frag_now->fr_literal,
861 sh_opcode_info *opcode;
863 int high_byte = target_big_endian ? 0 : 1;
866 if (opcode->arg[0] == A_BDISP8)
868 p = frag_var (rs_machine_dependent,
869 md_relax_table[C (COND_JUMP, COND32)].rlx_length,
870 md_relax_table[C (COND_JUMP, COND8)].rlx_length,
872 immediate.X_add_symbol,
873 immediate.X_add_number,
875 p[high_byte] = (opcode->nibbles[0] << 4) | (opcode->nibbles[1]);
877 else if (opcode->arg[0] == A_BDISP12)
879 p = frag_var (rs_machine_dependent,
880 md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length,
881 md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length,
883 immediate.X_add_symbol,
884 immediate.X_add_number,
886 p[high_byte] = (opcode->nibbles[0] << 4);
891 /* Now we know what sort of opcodes it is, lets build the bytes -
894 build_Mytes (opcode, operand)
895 sh_opcode_info *opcode;
896 sh_operand_info *operand;
901 char *output = frag_more (2);
902 int low_byte = target_big_endian ? 1 : 0;
908 for (index = 0; index < 4; index++)
910 sh_nibble_type i = opcode->nibbles[index];
926 nbuf[index] = reg_n | (reg_m >> 2);
929 nbuf[index] = reg_b | 0x08;
932 insert (output + low_byte, BFD_RELOC_SH_IMM4, 0);
935 insert (output + low_byte, BFD_RELOC_SH_IMM4BY4, 0);
938 insert (output + low_byte, BFD_RELOC_SH_IMM4BY2, 0);
941 insert (output + low_byte, BFD_RELOC_SH_IMM4, 0);
944 insert (output + low_byte, BFD_RELOC_SH_IMM8BY4, 0);
947 insert (output + low_byte, BFD_RELOC_SH_IMM8BY2, 0);
950 insert (output + low_byte, BFD_RELOC_SH_IMM8, 0);
953 insert (output, BFD_RELOC_SH_PCRELIMM8BY4, 1);
956 insert (output, BFD_RELOC_SH_PCRELIMM8BY2, 1);
959 printf (_("failed for %d\n"), i);
963 if (! target_big_endian) {
964 output[1] = (nbuf[0] << 4) | (nbuf[1]);
965 output[0] = (nbuf[2] << 4) | (nbuf[3]);
968 output[0] = (nbuf[0] << 4) | (nbuf[1]);
969 output[1] = (nbuf[2] << 4) | (nbuf[3]);
973 /* This is the guts of the machine-dependent assembler. STR points to a
974 machine dependent instruction. This function is supposed to emit
975 the frags/bytes it assembles to.
982 unsigned char *op_start;
983 unsigned char *op_end;
984 sh_operand_info operand[3];
985 sh_opcode_info *opcode;
988 /* Drop leading whitespace */
992 /* find the op code end */
993 for (op_start = op_end = (unsigned char *) (str);
996 && !is_end_of_line[*op_end] && *op_end != ' ';
999 name[nlen] = op_start[nlen];
1006 as_bad (_("can't find opcode "));
1009 opcode = (sh_opcode_info *) hash_find (opcode_hash_control, name);
1013 as_bad (_("unknown opcode"));
1018 && ! seg_info (now_seg)->tc_segment_info_data.in_code)
1020 /* Output a CODE reloc to tell the linker that the following
1021 bytes are instructions, not data. */
1022 fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0,
1024 seg_info (now_seg)->tc_segment_info_data.in_code = 1;
1027 if (opcode->arg[0] == A_BDISP12
1028 || opcode->arg[0] == A_BDISP8)
1030 parse_exp (op_end + 1);
1031 build_relax (opcode);
1035 if (opcode->arg[0] != A_END)
1037 get_operands (opcode, op_end, operand);
1039 opcode = get_specific (opcode, operand);
1043 /* Couldn't find an opcode which matched the operands */
1044 char *where = frag_more (2);
1048 as_bad (_("invalid operands for opcode"));
1052 build_Mytes (opcode, operand);
1057 /* This routine is called each time a label definition is seen. It
1058 emits a BFD_RELOC_SH_LABEL reloc if necessary. */
1063 static fragS *last_label_frag;
1064 static int last_label_offset;
1067 && seg_info (now_seg)->tc_segment_info_data.in_code)
1071 offset = frag_now_fix ();
1072 if (frag_now != last_label_frag
1073 || offset != last_label_offset)
1075 fix_new (frag_now, offset, 2, &abs_symbol, 0, 0, BFD_RELOC_SH_LABEL);
1076 last_label_frag = frag_now;
1077 last_label_offset = offset;
1082 /* This routine is called when the assembler is about to output some
1083 data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */
1086 sh_flush_pending_output ()
1089 && seg_info (now_seg)->tc_segment_info_data.in_code)
1091 fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0,
1093 seg_info (now_seg)->tc_segment_info_data.in_code = 0;
1098 DEFUN (md_undefined_symbol, (name),
1107 DEFUN (tc_crawl_symbol_chain, (headers),
1108 object_headers * headers)
1110 printf (_("call to tc_crawl_symbol_chain \n"));
1114 DEFUN (tc_headers_hook, (headers),
1115 object_headers * headers)
1117 printf (_("call to tc_headers_hook \n"));
1122 /* Various routines to kill one day */
1123 /* Equal to MAX_PRECISION in atof-ieee.c */
1124 #define MAX_LITTLENUMS 6
1126 /* Turn a string in input_line_pointer into a floating point constant of type
1127 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1128 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1131 md_atof (type, litP, sizeP)
1137 LITTLENUM_TYPE words[4];
1153 return _("bad call to md_atof");
1156 t = atof_ieee (input_line_pointer, type, words);
1158 input_line_pointer = t;
1162 if (! target_big_endian)
1164 for (i = prec - 1; i >= 0; i--)
1166 md_number_to_chars (litP, (valueT) words[i], 2);
1172 for (i = 0; i < prec; i++)
1174 md_number_to_chars (litP, (valueT) words[i], 2);
1182 /* Handle the .uses pseudo-op. This pseudo-op is used just before a
1183 call instruction. It refers to a label of the instruction which
1184 loads the register which the call uses. We use it to generate a
1185 special reloc for the linker. */
1194 as_warn (_(".uses pseudo-op seen when not relaxing"));
1198 if (ex.X_op != O_symbol || ex.X_add_number != 0)
1200 as_bad (_("bad .uses format"));
1201 ignore_rest_of_line ();
1205 fix_new_exp (frag_now, frag_now_fix (), 2, &ex, 1, BFD_RELOC_SH_USES);
1207 demand_empty_rest_of_line ();
1210 CONST char *md_shortopts = "";
1211 struct option md_longopts[] = {
1213 #define OPTION_RELAX (OPTION_MD_BASE)
1214 #define OPTION_LITTLE (OPTION_MD_BASE + 1)
1215 #define OPTION_SMALL (OPTION_LITTLE + 1)
1217 {"relax", no_argument, NULL, OPTION_RELAX},
1218 {"little", no_argument, NULL, OPTION_LITTLE},
1219 {"small", no_argument, NULL, OPTION_SMALL},
1220 {NULL, no_argument, NULL, 0}
1222 size_t md_longopts_size = sizeof(md_longopts);
1225 md_parse_option (c, arg)
1237 target_big_endian = 0;
1252 md_show_usage (stream)
1255 fprintf(stream, _("\
1257 -little generate little endian code\n\
1258 -relax alter jump instructions for long displacements\n\
1259 -small align sections to 4 byte boundaries, not 16\n"));
1262 int md_short_jump_size;
1265 tc_Nout_fix_to_chars ()
1267 printf (_("call to tc_Nout_fix_to_chars \n"));
1272 md_create_short_jump (ptr, from_Nddr, to_Nddr, frag, to_symbol)
1279 as_fatal (_("failed sanity check."));
1283 md_create_long_jump (ptr, from_Nddr, to_Nddr, frag, to_symbol)
1285 addressT from_Nddr, to_Nddr;
1289 as_fatal (_("failed sanity check."));
1292 /* This struct is used to pass arguments to sh_count_relocs through
1293 bfd_map_over_sections. */
1295 struct sh_count_relocs
1297 /* Symbol we are looking for. */
1299 /* Count of relocs found. */
1303 /* Count the number of fixups in a section which refer to a particular
1304 symbol. When using BFD_ASSEMBLER, this is called via
1305 bfd_map_over_sections. */
1309 sh_count_relocs (abfd, sec, data)
1314 struct sh_count_relocs *info = (struct sh_count_relocs *) data;
1315 segment_info_type *seginfo;
1319 seginfo = seg_info (sec);
1320 if (seginfo == NULL)
1324 for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next)
1326 if (fix->fx_addsy == sym)
1334 /* Handle the count relocs for a particular section. When using
1335 BFD_ASSEMBLER, this is called via bfd_map_over_sections. */
1339 sh_frob_section (abfd, sec, ignore)
1344 segment_info_type *seginfo;
1347 seginfo = seg_info (sec);
1348 if (seginfo == NULL)
1351 for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next)
1356 struct sh_count_relocs info;
1358 if (fix->fx_r_type != BFD_RELOC_SH_USES)
1361 /* The BFD_RELOC_SH_USES reloc should refer to a defined local
1362 symbol in the same section. */
1363 sym = fix->fx_addsy;
1365 || fix->fx_subsy != NULL
1366 || fix->fx_addnumber != 0
1367 || S_GET_SEGMENT (sym) != sec
1368 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
1369 || S_GET_STORAGE_CLASS (sym) == C_EXT
1371 || S_IS_EXTERNAL (sym))
1373 as_warn_where (fix->fx_file, fix->fx_line,
1374 _(".uses does not refer to a local symbol in the same section"));
1378 /* Look through the fixups again, this time looking for one
1379 at the same location as sym. */
1380 val = S_GET_VALUE (sym);
1381 for (fscan = seginfo->fix_root;
1383 fscan = fscan->fx_next)
1384 if (val == fscan->fx_frag->fr_address + fscan->fx_where
1385 && fscan->fx_r_type != BFD_RELOC_SH_ALIGN
1386 && fscan->fx_r_type != BFD_RELOC_SH_CODE
1387 && fscan->fx_r_type != BFD_RELOC_SH_DATA
1388 && fscan->fx_r_type != BFD_RELOC_SH_LABEL)
1392 as_warn_where (fix->fx_file, fix->fx_line,
1393 _("can't find fixup pointed to by .uses"));
1397 if (fscan->fx_tcbit)
1399 /* We've already done this one. */
1403 /* fscan should also be a fixup to a local symbol in the same
1405 sym = fscan->fx_addsy;
1407 || fscan->fx_subsy != NULL
1408 || fscan->fx_addnumber != 0
1409 || S_GET_SEGMENT (sym) != sec
1410 #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF)
1411 || S_GET_STORAGE_CLASS (sym) == C_EXT
1413 || S_IS_EXTERNAL (sym))
1415 as_warn_where (fix->fx_file, fix->fx_line,
1416 _(".uses target does not refer to a local symbol in the same section"));
1420 /* Now we look through all the fixups of all the sections,
1421 counting the number of times we find a reference to sym. */
1424 #ifdef BFD_ASSEMBLER
1425 bfd_map_over_sections (stdoutput, sh_count_relocs, (PTR) &info);
1430 for (iscan = SEG_E0; iscan < SEG_UNKNOWN; iscan++)
1431 sh_count_relocs ((bfd *) NULL, iscan, (PTR) &info);
1438 /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym.
1439 We have already adjusted the value of sym to include the
1440 fragment address, so we undo that adjustment here. */
1441 subseg_change (sec, 0);
1442 fix_new (sym->sy_frag, S_GET_VALUE (sym) - sym->sy_frag->fr_address,
1443 4, &abs_symbol, info.count, 0, BFD_RELOC_SH_COUNT);
1447 /* This function is called after the symbol table has been completed,
1448 but before the relocs or section contents have been written out.
1449 If we have seen any .uses pseudo-ops, they point to an instruction
1450 which loads a register with the address of a function. We look
1451 through the fixups to find where the function address is being
1452 loaded from. We then generate a COUNT reloc giving the number of
1453 times that function address is referred to. The linker uses this
1454 information when doing relaxing, to decide when it can eliminate
1455 the stored function address entirely. */
1463 #ifdef BFD_ASSEMBLER
1464 bfd_map_over_sections (stdoutput, sh_frob_section, (PTR) NULL);
1469 for (iseg = SEG_E0; iseg < SEG_UNKNOWN; iseg++)
1470 sh_frob_section ((bfd *) NULL, iseg, (PTR) NULL);
1475 /* Called after relaxing. Set the correct sizes of the fragments, and
1476 create relocs so that md_apply_fix will fill in the correct values. */
1479 md_convert_frag (headers, seg, fragP)
1480 #ifdef BFD_ASSEMBLER
1483 object_headers *headers;
1490 switch (fragP->fr_subtype)
1492 case C (COND_JUMP, COND8):
1493 subseg_change (seg, 0);
1494 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
1495 1, BFD_RELOC_SH_PCDISP8BY2);
1500 case C (UNCOND_JUMP, UNCOND12):
1501 subseg_change (seg, 0);
1502 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
1503 1, BFD_RELOC_SH_PCDISP12BY2);
1508 case C (UNCOND_JUMP, UNCOND32):
1509 case C (UNCOND_JUMP, UNDEF_WORD_DISP):
1510 if (fragP->fr_symbol == NULL)
1511 as_bad (_("at 0x%lx, displacement overflows 12-bit field"),
1512 (unsigned long) fragP->fr_address);
1513 else if (S_IS_DEFINED (fragP->fr_address))
1514 as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 12-bit field"),
1515 (unsigned long) fragP->fr_address,
1516 S_GET_NAME (fragP->fr_symbol));
1518 as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 12-bit field"),
1519 (unsigned long) fragP->fr_address,
1520 S_GET_NAME (fragP->fr_symbol));
1522 #if 0 /* This code works, but generates poor code and the compiler
1523 should never produce a sequence that requires it to be used. */
1525 /* A jump wont fit in 12 bits, make code which looks like
1531 int t = buffer[0] & 0x10;
1533 buffer[highbyte] = 0xa0; /* branch over move and disp */
1534 buffer[lowbyte] = 3;
1535 buffer[highbyte+2] = 0xd0 | JREG; /* Build mov insn */
1536 buffer[lowbyte+2] = 0x00;
1538 buffer[highbyte+4] = 0; /* space for 32 bit jump disp */
1539 buffer[lowbyte+4] = 0;
1540 buffer[highbyte+6] = 0;
1541 buffer[lowbyte+6] = 0;
1543 buffer[highbyte+8] = 0x40 | JREG; /* Build jmp @JREG */
1544 buffer[lowbyte+8] = t ? 0xb : 0x2b;
1546 buffer[highbyte+10] = 0x20; /* build nop */
1547 buffer[lowbyte+10] = 0x0b;
1549 /* Make reloc for the long disp */
1557 fragP->fr_fix += UNCOND32_LENGTH;
1564 case C (COND_JUMP, COND12):
1565 /* A bcond won't fit, so turn it into a b!cond; bra disp; nop */
1567 unsigned char *buffer =
1568 (unsigned char *) (fragP->fr_fix + fragP->fr_literal);
1569 int highbyte = target_big_endian ? 0 : 1;
1570 int lowbyte = target_big_endian ? 1 : 0;
1572 /* Toggle the true/false bit of the bcond. */
1573 buffer[highbyte] ^= 0x2;
1575 /* Build a relocation to six bytes farther on. */
1576 subseg_change (seg, 0);
1577 fix_new (fragP, fragP->fr_fix, 2,
1578 #ifdef BFD_ASSEMBLER
1579 section_symbol (seg),
1581 seg_info (seg)->dot,
1583 fragP->fr_address + fragP->fr_fix + 6,
1584 1, BFD_RELOC_SH_PCDISP8BY2);
1586 /* Set up a jump instruction. */
1587 buffer[highbyte + 2] = 0xa0;
1588 buffer[lowbyte + 2] = 0;
1589 fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
1590 fragP->fr_offset, 1, BFD_RELOC_SH_PCDISP12BY2);
1592 /* Fill in a NOP instruction. */
1593 buffer[highbyte + 4] = 0x0;
1594 buffer[lowbyte + 4] = 0x9;
1602 case C (COND_JUMP, COND32):
1603 case C (COND_JUMP, UNDEF_WORD_DISP):
1604 if (fragP->fr_symbol == NULL)
1605 as_bad (_("at 0x%lx, displacement overflows 8-bit field"),
1606 (unsigned long) fragP->fr_address);
1607 else if (S_IS_DEFINED (fragP->fr_symbol))
1608 as_bad (_("at 0x%lx, displacement to defined symbol %s overflows 8-bit field "),
1609 (unsigned long) fragP->fr_address,
1610 S_GET_NAME (fragP->fr_symbol));
1612 as_bad (_("at 0x%lx, displacement to undefined symbol %s overflows 8-bit field "),
1613 (unsigned long) fragP->fr_address,
1614 S_GET_NAME (fragP->fr_symbol));
1616 #if 0 /* This code works, but generates poor code, and the compiler
1617 should never produce a sequence that requires it to be used. */
1619 /* A bcond won't fit and it won't go into a 12 bit
1620 displacement either, the code sequence looks like:
1629 buffer[0] ^= 0x2; /* Toggle T/F bit */
1631 buffer[1] = 5; /* branch over mov, jump, nop and ptr */
1632 buffer[2] = 0xd0 | JREG; /* Build mov insn */
1634 buffer[4] = 0x40 | JREG; /* Build jmp @JREG */
1636 buffer[6] = 0x20; /* build nop */
1638 buffer[8] = 0; /* space for 32 bit jump disp */
1644 /* Make reloc for the long disp */
1652 fragP->fr_fix += COND32_LENGTH;
1663 if (donerelax && !sh_relax)
1664 as_warn_where (fragP->fr_file, fragP->fr_line,
1665 _("overflow in branch to %s; converted into longer instruction sequence"),
1666 (fragP->fr_symbol != NULL
1667 ? S_GET_NAME (fragP->fr_symbol)
1672 DEFUN (md_section_align, (seg, size),
1676 #ifdef BFD_ASSEMBLER
1679 #else /* ! OBJ_ELF */
1680 return ((size + (1 << bfd_get_section_alignment (stdoutput, seg)) - 1)
1681 & (-1 << bfd_get_section_alignment (stdoutput, seg)));
1682 #endif /* ! OBJ_ELF */
1683 #else /* ! BFD_ASSEMBLER */
1684 return ((size + (1 << section_alignment[(int) seg]) - 1)
1685 & (-1 << section_alignment[(int) seg]));
1686 #endif /* ! BFD_ASSEMBLER */
1689 /* This static variable is set by s_uacons to tell sh_cons_align that
1690 the expession does not need to be aligned. */
1692 static int sh_no_align_cons = 0;
1694 /* This handles the unaligned space allocation pseudo-ops, such as
1695 .uaword. .uaword is just like .word, but the value does not need
1702 /* Tell sh_cons_align not to align this value. */
1703 sh_no_align_cons = 1;
1707 /* If a .word, et. al., pseud-op is seen, warn if the value is not
1708 aligned correctly. Note that this can cause warnings to be issued
1709 when assembling initialized structured which were declared with the
1710 packed attribute. FIXME: Perhaps we should require an option to
1711 enable this warning? */
1714 sh_cons_align (nbytes)
1720 if (sh_no_align_cons)
1722 /* This is an unaligned pseudo-op. */
1723 sh_no_align_cons = 0;
1728 while ((nbytes & 1) == 0)
1737 if (now_seg == absolute_section)
1739 if ((abs_section_offset & ((1 << nalign) - 1)) != 0)
1740 as_warn (_("misaligned data"));
1744 p = frag_var (rs_align_code, 1, 1, (relax_substateT) 0,
1745 (symbolS *) NULL, (offsetT) nalign, (char *) NULL);
1747 record_alignment (now_seg, nalign);
1750 /* When relaxing, we need to output a reloc for any .align directive
1751 that requests alignment to a four byte boundary or larger. This is
1752 also where we check for misaligned data. */
1755 sh_handle_align (frag)
1759 && frag->fr_type == rs_align
1760 && frag->fr_address + frag->fr_fix > 0
1761 && frag->fr_offset > 1
1762 && now_seg != bss_section)
1763 fix_new (frag, frag->fr_fix, 2, &abs_symbol, frag->fr_offset, 0,
1764 BFD_RELOC_SH_ALIGN);
1766 if (frag->fr_type == rs_align_code
1767 && frag->fr_next->fr_address - frag->fr_address - frag->fr_fix != 0)
1768 as_warn_where (frag->fr_file, frag->fr_line, _("misaligned data"));
1771 /* This macro decides whether a particular reloc is an entry in a
1772 switch table. It is used when relaxing, because the linker needs
1773 to know about all such entries so that it can adjust them if
1776 #ifdef BFD_ASSEMBLER
1777 #define SWITCH_TABLE_CONS(fix) (0)
1779 #define SWITCH_TABLE_CONS(fix) \
1780 ((fix)->fx_r_type == 0 \
1781 && ((fix)->fx_size == 2 \
1782 || (fix)->fx_size == 1 \
1783 || (fix)->fx_size == 4))
1786 #define SWITCH_TABLE(fix) \
1787 ((fix)->fx_addsy != NULL \
1788 && (fix)->fx_subsy != NULL \
1789 && S_GET_SEGMENT ((fix)->fx_addsy) == text_section \
1790 && S_GET_SEGMENT ((fix)->fx_subsy) == text_section \
1791 && ((fix)->fx_r_type == BFD_RELOC_32 \
1792 || (fix)->fx_r_type == BFD_RELOC_16 \
1793 || (fix)->fx_r_type == BFD_RELOC_8 \
1794 || SWITCH_TABLE_CONS (fix)))
1796 /* See whether we need to force a relocation into the output file.
1797 This is used to force out switch and PC relative relocations when
1801 sh_force_relocation (fix)
1807 return (fix->fx_pcrel
1808 || SWITCH_TABLE (fix)
1809 || fix->fx_r_type == BFD_RELOC_SH_COUNT
1810 || fix->fx_r_type == BFD_RELOC_SH_ALIGN
1811 || fix->fx_r_type == BFD_RELOC_SH_CODE
1812 || fix->fx_r_type == BFD_RELOC_SH_DATA
1813 || fix->fx_r_type == BFD_RELOC_SH_LABEL);
1816 /* Apply a fixup to the object file. */
1818 #ifdef BFD_ASSEMBLER
1820 md_apply_fix (fixP, valp)
1825 md_apply_fix (fixP, val)
1830 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1831 int lowbyte = target_big_endian ? 1 : 0;
1832 int highbyte = target_big_endian ? 0 : 1;
1833 #ifdef BFD_ASSEMBLER
1839 #ifndef BFD_ASSEMBLER
1840 if (fixP->fx_r_type == 0)
1842 if (fixP->fx_size == 2)
1843 fixP->fx_r_type = BFD_RELOC_16;
1844 else if (fixP->fx_size == 4)
1845 fixP->fx_r_type = BFD_RELOC_32;
1846 else if (fixP->fx_size == 1)
1847 fixP->fx_r_type = BFD_RELOC_8;
1855 switch (fixP->fx_r_type)
1857 case BFD_RELOC_SH_IMM4:
1859 *buf = (*buf & 0xf0) | (val & 0xf);
1862 case BFD_RELOC_SH_IMM4BY2:
1865 *buf = (*buf & 0xf0) | ((val >> 1) & 0xf);
1868 case BFD_RELOC_SH_IMM4BY4:
1871 *buf = (*buf & 0xf0) | ((val >> 2) & 0xf);
1874 case BFD_RELOC_SH_IMM8BY2:
1880 case BFD_RELOC_SH_IMM8BY4:
1887 case BFD_RELOC_SH_IMM8:
1888 /* Sometimes the 8 bit value is sign extended (e.g., add) and
1889 sometimes it is not (e.g., and). We permit any 8 bit value.
1890 Note that adding further restrictions may invalidate
1891 reasonable looking assembly code, such as ``and -0x1,r0''. */
1897 case BFD_RELOC_SH_PCRELIMM8BY4:
1898 /* The lower two bits of the PC are cleared before the
1899 displacement is added in. We can assume that the destination
1900 is on a 4 byte bounday. If this instruction is also on a 4
1901 byte boundary, then we want
1903 and target - here is a multiple of 4.
1904 Otherwise, we are on a 2 byte boundary, and we want
1905 (target - (here - 2)) / 4
1906 and target - here is not a multiple of 4. Computing
1907 (target - (here - 2)) / 4 == (target - here + 2) / 4
1908 works for both cases, since in the first case the addition of
1909 2 will be removed by the division. target - here is in the
1911 val = (val + 2) / 4;
1913 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
1917 case BFD_RELOC_SH_PCRELIMM8BY2:
1920 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
1924 case BFD_RELOC_SH_PCDISP8BY2:
1926 if (val < -0x80 || val > 0x7f)
1927 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
1931 case BFD_RELOC_SH_PCDISP12BY2:
1933 if (val < -0x800 || val >= 0x7ff)
1934 as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far"));
1935 buf[lowbyte] = val & 0xff;
1936 buf[highbyte] |= (val >> 8) & 0xf;
1940 if (! target_big_endian)
1957 if (! target_big_endian)
1969 case BFD_RELOC_SH_USES:
1970 /* Pass the value into sh_coff_reloc_mangle. */
1971 fixP->fx_addnumber = val;
1974 case BFD_RELOC_SH_COUNT:
1975 case BFD_RELOC_SH_ALIGN:
1976 case BFD_RELOC_SH_CODE:
1977 case BFD_RELOC_SH_DATA:
1978 case BFD_RELOC_SH_LABEL:
1979 /* Nothing to do here. */
1988 if ((val & ((1 << shift) - 1)) != 0)
1989 as_bad_where (fixP->fx_file, fixP->fx_line, _("misaligned offset"));
1993 val = ((val >> shift)
1994 | ((long) -1 & ~ ((long) -1 >> shift)));
1996 if (max != 0 && (val < min || val > max))
1997 as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range"));
1999 #ifdef BFD_ASSEMBLER
2004 int md_long_jump_size;
2006 /* Called just before address relaxation. Return the length
2007 by which a fragment must grow to reach it's destination. */
2010 md_estimate_size_before_relax (fragP, segment_type)
2011 register fragS *fragP;
2012 register segT segment_type;
2014 switch (fragP->fr_subtype)
2016 case C (UNCOND_JUMP, UNDEF_DISP):
2017 /* used to be a branch to somewhere which was unknown */
2018 if (!fragP->fr_symbol)
2020 fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12);
2021 fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length;
2023 else if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
2025 fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12);
2026 fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length;
2030 fragP->fr_subtype = C (UNCOND_JUMP, UNDEF_WORD_DISP);
2031 fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length;
2032 return md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length;
2038 case C (COND_JUMP, UNDEF_DISP):
2039 /* used to be a branch to somewhere which was unknown */
2040 if (fragP->fr_symbol
2041 && S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
2043 /* Got a symbol and it's defined in this segment, become byte
2044 sized - maybe it will fix up */
2045 fragP->fr_subtype = C (COND_JUMP, COND8);
2046 fragP->fr_var = md_relax_table[C (COND_JUMP, COND8)].rlx_length;
2048 else if (fragP->fr_symbol)
2050 /* Its got a segment, but its not ours, so it will always be long */
2051 fragP->fr_subtype = C (COND_JUMP, UNDEF_WORD_DISP);
2052 fragP->fr_var = md_relax_table[C (COND_JUMP, COND32)].rlx_length;
2053 return md_relax_table[C (COND_JUMP, COND32)].rlx_length;
2057 /* We know the abs value */
2058 fragP->fr_subtype = C (COND_JUMP, COND8);
2059 fragP->fr_var = md_relax_table[C (COND_JUMP, COND8)].rlx_length;
2064 return fragP->fr_var;
2067 /* Put number into target byte order */
2070 md_number_to_chars (ptr, use, nbytes)
2075 if (! target_big_endian)
2076 number_to_chars_littleendian (ptr, use, nbytes);
2078 number_to_chars_bigendian (ptr, use, nbytes);
2082 md_pcrel_from (fixP)
2085 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address + 2;
2091 tc_coff_sizemachdep (frag)
2094 return md_relax_table[frag->fr_subtype].rlx_length;
2097 #endif /* OBJ_COFF */
2099 /* When we align the .text section, insert the correct NOP pattern. */
2102 sh_do_align (n, fill, len, max)
2109 #ifdef BFD_ASSEMBLER
2110 && (now_seg->flags & SEC_CODE) != 0
2112 && now_seg != data_section
2113 && now_seg != bss_section
2117 static const unsigned char big_nop_pattern[] = { 0x00, 0x09 };
2118 static const unsigned char little_nop_pattern[] = { 0x09, 0x00 };
2120 /* First align to a 2 byte boundary, in case there is an odd
2122 frag_align (1, 0, 0);
2123 if (target_big_endian)
2124 frag_align_pattern (n, big_nop_pattern, sizeof big_nop_pattern, max);
2126 frag_align_pattern (n, little_nop_pattern, sizeof little_nop_pattern,
2134 #ifndef BFD_ASSEMBLER
2137 /* Map BFD relocs to SH COFF relocs. */
2141 bfd_reloc_code_real_type bfd_reloc;
2145 static const struct reloc_map coff_reloc_map[] =
2147 { BFD_RELOC_32, R_SH_IMM32 },
2148 { BFD_RELOC_16, R_SH_IMM16 },
2149 { BFD_RELOC_8, R_SH_IMM8 },
2150 { BFD_RELOC_SH_PCDISP8BY2, R_SH_PCDISP8BY2 },
2151 { BFD_RELOC_SH_PCDISP12BY2, R_SH_PCDISP },
2152 { BFD_RELOC_SH_IMM4, R_SH_IMM4 },
2153 { BFD_RELOC_SH_IMM4BY2, R_SH_IMM4BY2 },
2154 { BFD_RELOC_SH_IMM4BY4, R_SH_IMM4BY4 },
2155 { BFD_RELOC_SH_IMM8, R_SH_IMM8 },
2156 { BFD_RELOC_SH_IMM8BY2, R_SH_IMM8BY2 },
2157 { BFD_RELOC_SH_IMM8BY4, R_SH_IMM8BY4 },
2158 { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_PCRELIMM8BY2 },
2159 { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_PCRELIMM8BY4 },
2160 { BFD_RELOC_8_PCREL, R_SH_SWITCH8 },
2161 { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 },
2162 { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 },
2163 { BFD_RELOC_SH_USES, R_SH_USES },
2164 { BFD_RELOC_SH_COUNT, R_SH_COUNT },
2165 { BFD_RELOC_SH_ALIGN, R_SH_ALIGN },
2166 { BFD_RELOC_SH_CODE, R_SH_CODE },
2167 { BFD_RELOC_SH_DATA, R_SH_DATA },
2168 { BFD_RELOC_SH_LABEL, R_SH_LABEL },
2169 { BFD_RELOC_UNUSED, 0 }
2172 /* Adjust a reloc for the SH. This is similar to the generic code,
2173 but does some minor tweaking. */
2176 sh_coff_reloc_mangle (seg, fix, intr, paddr)
2177 segment_info_type *seg;
2179 struct internal_reloc *intr;
2182 symbolS *symbol_ptr = fix->fx_addsy;
2185 intr->r_vaddr = paddr + fix->fx_frag->fr_address + fix->fx_where;
2187 if (! SWITCH_TABLE (fix))
2189 const struct reloc_map *rm;
2191 for (rm = coff_reloc_map; rm->bfd_reloc != BFD_RELOC_UNUSED; rm++)
2192 if (rm->bfd_reloc == (bfd_reloc_code_real_type) fix->fx_r_type)
2194 if (rm->bfd_reloc == BFD_RELOC_UNUSED)
2195 as_bad_where (fix->fx_file, fix->fx_line,
2196 _("Can not represent %s relocation in this object file format"),
2197 bfd_get_reloc_code_name (fix->fx_r_type));
2198 intr->r_type = rm->sh_reloc;
2205 if (fix->fx_r_type == BFD_RELOC_16)
2206 intr->r_type = R_SH_SWITCH16;
2207 else if (fix->fx_r_type == BFD_RELOC_8)
2208 intr->r_type = R_SH_SWITCH8;
2209 else if (fix->fx_r_type == BFD_RELOC_32)
2210 intr->r_type = R_SH_SWITCH32;
2214 /* For a switch reloc, we set r_offset to the difference between
2215 the reloc address and the subtrahend. When the linker is
2216 doing relaxing, it can use the determine the starting and
2217 ending points of the switch difference expression. */
2218 intr->r_offset = intr->r_vaddr - S_GET_VALUE (fix->fx_subsy);
2221 /* PC relative relocs are always against the current section. */
2222 if (symbol_ptr == NULL)
2224 switch (fix->fx_r_type)
2226 case BFD_RELOC_SH_PCRELIMM8BY2:
2227 case BFD_RELOC_SH_PCRELIMM8BY4:
2228 case BFD_RELOC_SH_PCDISP8BY2:
2229 case BFD_RELOC_SH_PCDISP12BY2:
2230 case BFD_RELOC_SH_USES:
2231 symbol_ptr = seg->dot;
2238 if (fix->fx_r_type == BFD_RELOC_SH_USES)
2240 /* We can't store the offset in the object file, since this
2241 reloc does not take up any space, so we store it in r_offset.
2242 The fx_addnumber field was set in md_apply_fix. */
2243 intr->r_offset = fix->fx_addnumber;
2245 else if (fix->fx_r_type == BFD_RELOC_SH_COUNT)
2247 /* We can't store the count in the object file, since this reloc
2248 does not take up any space, so we store it in r_offset. The
2249 fx_offset field was set when the fixup was created in
2250 sh_coff_frob_file. */
2251 intr->r_offset = fix->fx_offset;
2252 /* This reloc is always absolute. */
2255 else if (fix->fx_r_type == BFD_RELOC_SH_ALIGN)
2257 /* Store the alignment in the r_offset field. */
2258 intr->r_offset = fix->fx_offset;
2259 /* This reloc is always absolute. */
2262 else if (fix->fx_r_type == BFD_RELOC_SH_CODE
2263 || fix->fx_r_type == BFD_RELOC_SH_DATA
2264 || fix->fx_r_type == BFD_RELOC_SH_LABEL)
2266 /* These relocs are always absolute. */
2270 /* Turn the segment of the symbol into an offset. */
2271 if (symbol_ptr != NULL)
2273 dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot;
2275 intr->r_symndx = dot->sy_number;
2277 intr->r_symndx = symbol_ptr->sy_number;
2280 intr->r_symndx = -1;
2283 #endif /* OBJ_COFF */
2284 #endif /* ! BFD_ASSEMBLER */
2286 #ifdef BFD_ASSEMBLER
2288 /* Create a reloc. */
2291 tc_gen_reloc (section, fixp)
2296 bfd_reloc_code_real_type r_type;
2298 rel = (arelent *) xmalloc (sizeof (arelent));
2299 rel->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2300 rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
2302 r_type = fixp->fx_r_type;
2304 if (SWITCH_TABLE (fixp))
2306 rel->addend = rel->address - S_GET_VALUE (fixp->fx_subsy);
2307 if (r_type == BFD_RELOC_16)
2308 r_type = BFD_RELOC_SH_SWITCH16;
2309 else if (r_type == BFD_RELOC_8)
2310 r_type = BFD_RELOC_8_PCREL;
2311 else if (r_type == BFD_RELOC_32)
2312 r_type = BFD_RELOC_SH_SWITCH32;
2316 else if (r_type == BFD_RELOC_SH_USES)
2317 rel->addend = fixp->fx_addnumber;
2318 else if (r_type == BFD_RELOC_SH_COUNT)
2319 rel->addend = fixp->fx_offset;
2320 else if (r_type == BFD_RELOC_SH_ALIGN)
2321 rel->addend = fixp->fx_offset;
2322 else if (fixp->fx_pcrel)
2323 rel->addend = fixp->fx_addnumber;
2327 rel->howto = bfd_reloc_type_lookup (stdoutput, r_type);
2328 if (rel->howto == NULL)
2330 as_bad_where (fixp->fx_file, fixp->fx_line,
2331 _("Cannot represent relocation type %s"),
2332 bfd_get_reloc_code_name (r_type));
2333 /* Set howto to a garbage value so that we can keep going. */
2334 rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
2335 assert (rel->howto != NULL);
2341 #endif /* BFD_ASSEMBLER */