* targets.c (bfd_target): Rearranged fields in target vector.
[deliverable/binutils-gdb.git] / bfd / coff-h8500.c
CommitLineData
46dd0622 1/* BFD back-end for Hitachi H8/500 COFF binaries.
47e70c54 2 Copyright 1993, 1994 Free Software Foundation, Inc.
46dd0622
SC
3 Contributed by Cygnus Support.
4 Written by Steve Chamberlain, <sac@cygnus.com>.
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22#include "bfd.h"
23#include "sysdep.h"
46dd0622 24#include "obstack.h"
4991ebb9
ILT
25#include "libbfd.h"
26#include "bfdlink.h"
46dd0622
SC
27#include "coff/h8500.h"
28#include "coff/internal.h"
29#include "libcoff.h"
46dd0622
SC
30
31static reloc_howto_type r_imm8 =
4991ebb9
ILT
32HOWTO (R_H8500_IMM8, 0, 1, 8, false, 0,
33 complain_overflow_bitfield, 0, "r_imm8", true, 0x000000ff, 0x000000ff, false);
46dd0622
SC
34
35static reloc_howto_type r_imm16 =
4991ebb9
ILT
36HOWTO (R_H8500_IMM16, 0, 1, 16, false, 0,
37 complain_overflow_bitfield, 0, "r_imm16", true, 0x0000ffff, 0x0000ffff, false);
46dd0622
SC
38
39static reloc_howto_type r_imm24 =
4991ebb9
ILT
40HOWTO (R_H8500_IMM24, 0, 1, 24, false, 0,
41 complain_overflow_bitfield, 0, "r_imm24", true, 0x00ffffff, 0x00ffffff, false);
46dd0622
SC
42
43static reloc_howto_type r_imm32 =
4991ebb9
ILT
44HOWTO (R_H8500_IMM32, 0, 1, 32, false, 0,
45 complain_overflow_bitfield, 0, "r_imm32", true, 0xffffffff, 0xffffffff, false);
46dd0622
SC
46
47
48static reloc_howto_type r_high8 =
4991ebb9 49HOWTO (R_H8500_HIGH8, 0, 1, 8, false, 0,
47e70c54 50 complain_overflow_dont, 0, "r_high8", true, 0x000000ff, 0x000000ff, false);
46dd0622
SC
51
52static reloc_howto_type r_low16 =
4991ebb9 53HOWTO (R_H8500_LOW16, 0, 1, 16, false, 0,
47e70c54 54 complain_overflow_dont, 0, "r_low16", true, 0x0000ffff, 0x0000ffff, false);
46dd0622
SC
55
56static reloc_howto_type r_pcrel8 =
4991ebb9 57HOWTO (R_H8500_PCREL8, 0, 1, 8, true, 0, complain_overflow_signed, 0, "r_pcrel8", true, 0, 0, true);
46dd0622
SC
58
59
60static reloc_howto_type r_pcrel16 =
4991ebb9 61HOWTO (R_H8500_PCREL16, 0, 1, 16, true, 0, complain_overflow_signed, 0, "r_pcrel16", true, 0, 0, true);
46dd0622
SC
62
63static reloc_howto_type r_high16 =
4991ebb9 64HOWTO (R_H8500_HIGH16, 0, 1, 8, false, 0,
47e70c54 65 complain_overflow_dont, 0, "r_high16", true, 0x000ffff, 0x0000ffff, false);
46dd0622
SC
66
67
68/* Turn a howto into a reloc number */
69
70static int
71coff_h8500_select_reloc (howto)
72 reloc_howto_type *howto;
73{
74 return howto->type;
75}
76
47e70c54 77#define SELECT_RELOC(x,howto) x.r_type = coff_h8500_select_reloc(howto)
46dd0622
SC
78
79
80#define BADMAG(x) H8500BADMAG(x)
81#define H8500 1 /* Customize coffcode.h */
82
83#define __A_MAGIC_SET__
84
85/* Code to swap in the reloc */
86#define SWAP_IN_RELOC_OFFSET bfd_h_get_32
87#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
88#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
89 dst->r_stuff[0] = 'S'; \
90 dst->r_stuff[1] = 'C';
91
92/* Code to turn a r_type into a howto ptr, uses the above howto table
93 */
94
95static void
96rtype2howto(internal, dst)
97 arelent * internal;
98 struct internal_reloc *dst;
99{
100 switch (dst->r_type)
101 {
102 default:
4991ebb9 103 fprintf (stderr, "BAD 0x%x\n", dst->r_type);
46dd0622
SC
104 case R_H8500_IMM8:
105 internal->howto = &r_imm8;
106 break;
107 case R_H8500_IMM16:
108 internal->howto = &r_imm16;
109 break;
110 case R_H8500_IMM24:
111 internal->howto = &r_imm24;
112 break;
113 case R_H8500_IMM32:
114 internal->howto = &r_imm32;
115 break;
116 case R_H8500_PCREL8:
117 internal->howto = &r_pcrel8;
118 break;
119 case R_H8500_PCREL16:
120 internal->howto = &r_pcrel16;
121 break;
122 case R_H8500_HIGH8:
123 internal->howto = &r_high8;
124 break;
125 case R_H8500_HIGH16:
126 internal->howto = &r_high16;
127 break;
128 case R_H8500_LOW16:
129 internal->howto = &r_low16;
130 break;
131 }
132}
133
134#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
135
136
137/* Perform any necessaru magic to the addend in a reloc entry */
138
139
140#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
141 cache_ptr->addend = ext_reloc.r_offset;
142
143
144#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
145 reloc_processing(relent, reloc, symbols, abfd, section)
146
147static void reloc_processing (relent, reloc, symbols, abfd, section)
148 arelent * relent;
149 struct internal_reloc *reloc;
150 asymbol ** symbols;
151 bfd * abfd;
152 asection * section;
153{
154 relent->address = reloc->r_vaddr;
155 rtype2howto (relent, reloc);
156
157 if (reloc->r_symndx > 0)
158 {
159 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
160 }
161 else
162 {
163 relent->sym_ptr_ptr = &(bfd_abs_symbol);
164 }
165
166
167 relent->addend = reloc->r_offset;
168 relent->address -= section->vma;
169}
170
171static void
4991ebb9 172extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
46dd0622 173 bfd *in_abfd;
4991ebb9
ILT
174 struct bfd_link_info *link_info;
175 struct bfd_link_order *link_order;
46dd0622
SC
176 arelent *reloc;
177 bfd_byte *data;
178 unsigned int *src_ptr;
179 unsigned int *dst_ptr;
180{
181 bfd_byte *d = data+*dst_ptr;
4991ebb9 182 asection *input_section = link_order->u.indirect.section;
46dd0622
SC
183 switch (reloc->howto->type)
184 {
185 case R_H8500_IMM8:
186 bfd_put_8 (in_abfd,
4991ebb9 187 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
46dd0622
SC
188 d);
189 (*dst_ptr) += 1;
190 (*src_ptr) += 1;
191 break;
192
193 case R_H8500_HIGH8:
194 bfd_put_8 (in_abfd,
4991ebb9
ILT
195 (bfd_coff_reloc16_get_value (reloc, link_info, input_section)
196 >> 16),
46dd0622
SC
197 d );
198 (*dst_ptr) += 1;
199 (*src_ptr) += 1;
200 break;
201
202 case R_H8500_IMM16:
203 bfd_put_16 (in_abfd,
4991ebb9 204 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
46dd0622
SC
205 d );
206 (*dst_ptr) += 2;
207 (*src_ptr) += 2;
208 break;
209
210 case R_H8500_LOW16:
211 bfd_put_16 (in_abfd,
4991ebb9 212 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
46dd0622
SC
213 d);
214
215 (*dst_ptr) += 2;
216 (*src_ptr) += 2;
217 break;
218
219 case R_H8500_HIGH16:
220 bfd_put_16 (in_abfd,
4991ebb9
ILT
221 (bfd_coff_reloc16_get_value (reloc, link_info, input_section)
222 >>16),
46dd0622
SC
223 d);
224
225 (*dst_ptr) += 2;
226 (*src_ptr) += 2;
227 break;
228
229 case R_H8500_IMM24:
230 {
4991ebb9 231 int v = bfd_coff_reloc16_get_value(reloc, link_info, input_section);
46dd0622
SC
232 int o = bfd_get_32(in_abfd, data+ *dst_ptr -1);
233 v = (v & 0x00ffffff) | (o & 0xff00000);
234 bfd_put_32 (in_abfd, v, data + *dst_ptr -1);
235 (*dst_ptr) +=3;
236 (*src_ptr)+=3;;
237 }
238 break;
239 case R_H8500_IMM32:
240 {
4991ebb9 241 int v = bfd_coff_reloc16_get_value(reloc, link_info, input_section);
46dd0622
SC
242 bfd_put_32 (in_abfd, v, data + *dst_ptr);
243 (*dst_ptr) +=4;
244 (*src_ptr)+=4;;
245 }
246 break;
247
248
249 case R_H8500_PCREL8:
250 {
4991ebb9
ILT
251 bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
252 input_section);
253 bfd_vma dot = link_order->offset
46dd0622 254 + *dst_ptr
4991ebb9 255 + link_order->u.indirect.section->output_section->vma;
46dd0622
SC
256 int gap = dst - dot - 1; /* -1 since were in the odd byte of the
257 word and the pc's been incremented */
258
259 if (gap > 128 || gap < -128)
260 {
4991ebb9
ILT
261 if (! ((*link_info->callbacks->reloc_overflow)
262 (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
263 reloc->howto->name, reloc->addend, input_section->owner,
264 input_section, reloc->address)))
265 abort ();
46dd0622
SC
266 }
267 bfd_put_8 (in_abfd, gap, data + *dst_ptr);
268 (*dst_ptr)++;
269 (*src_ptr)++;
270 break;
271 }
272 case R_H8500_PCREL16:
273 {
4991ebb9
ILT
274 bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
275 input_section);
276 bfd_vma dot = link_order->offset
46dd0622 277 + *dst_ptr
4991ebb9 278 + link_order->u.indirect.section->output_section->vma;
46dd0622
SC
279 int gap = dst - dot - 1; /* -1 since were in the odd byte of the
280 word and the pc's been incremented */
281
282 if (gap > 32767 || gap < -32768)
283 {
4991ebb9
ILT
284 if (! ((*link_info->callbacks->reloc_overflow)
285 (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
286 reloc->howto->name, reloc->addend, input_section->owner,
287 input_section, reloc->address)))
288 abort ();
46dd0622
SC
289 }
290 bfd_put_16 (in_abfd, gap, data + *dst_ptr);
291 (*dst_ptr)+=2;
292 (*src_ptr)+=2;
293 break;
294 }
295
296 default:
297 abort ();
298 }
299}
300
301#define coff_reloc16_extra_cases extra_case
302
303#include "coffcode.h"
304
305
306#undef coff_bfd_get_relocated_section_contents
307#undef coff_bfd_relax_section
4991ebb9
ILT
308#define coff_bfd_get_relocated_section_contents \
309 bfd_coff_reloc16_get_relocated_section_contents
46dd0622
SC
310#define coff_bfd_relax_section bfd_coff_reloc16_relax_section
311
312bfd_target h8500coff_vec =
313{
314 "coff-h8500", /* name */
315 bfd_target_coff_flavour,
316 true, /* data byte order is big */
317 true, /* header byte order is big */
318
319 (HAS_RELOC | EXEC_P | /* object flags */
320 HAS_LINENO | HAS_DEBUG |
4991ebb9 321 HAS_SYMS | HAS_LOCALS | WP_TEXT),
46dd0622
SC
322
323 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
324 '_', /* leading symbol underscore */
325 '/', /* ar_pad_char */
326 15, /* ar_max_namelen */
327 1, /* minimum section alignment */
4991ebb9
ILT
328 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
329 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
330 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
331 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
332 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
333 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
46dd0622
SC
334
335 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
336 bfd_generic_archive_p, _bfd_dummy_target},
337 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
338 bfd_false},
339 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
340 _bfd_write_archive_contents, bfd_false},
341
6812b607
ILT
342 BFD_JUMP_TABLE_GENERIC (coff),
343 BFD_JUMP_TABLE_COPY (coff),
344 BFD_JUMP_TABLE_CORE (_bfd_nocore),
345 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
346 BFD_JUMP_TABLE_SYMBOLS (coff),
347 BFD_JUMP_TABLE_RELOCS (coff),
348 BFD_JUMP_TABLE_WRITE (coff),
349 BFD_JUMP_TABLE_LINK (coff),
350
46dd0622
SC
351 COFF_SWAP_TABLE,
352};
This page took 0.065289 seconds and 4 git commands to generate.