1 /* BFD back-end for Hitachi H8/500 COFF binaries.
2 Copyright 1993 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4 Written by Steve Chamberlain, <sac@cygnus.com>.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "coff/h8500.h"
28 #include "coff/internal.h"
31 static reloc_howto_type r_imm8
=
32 HOWTO (R_H8500_IMM8
, 0, 1, 8, false, 0,
33 complain_overflow_bitfield
, 0, "r_imm8", true, 0x000000ff, 0x000000ff, false);
35 static reloc_howto_type r_imm16
=
36 HOWTO (R_H8500_IMM16
, 0, 1, 16, false, 0,
37 complain_overflow_bitfield
, 0, "r_imm16", true, 0x0000ffff, 0x0000ffff, false);
39 static reloc_howto_type r_imm24
=
40 HOWTO (R_H8500_IMM24
, 0, 1, 24, false, 0,
41 complain_overflow_bitfield
, 0, "r_imm24", true, 0x00ffffff, 0x00ffffff, false);
43 static reloc_howto_type r_imm32
=
44 HOWTO (R_H8500_IMM32
, 0, 1, 32, false, 0,
45 complain_overflow_bitfield
, 0, "r_imm32", true, 0xffffffff, 0xffffffff, false);
48 static reloc_howto_type r_high8
=
49 HOWTO (R_H8500_HIGH8
, 0, 1, 8, false, 0,
50 complain_overflow_bitfield
, 0, "r_high8", true, 0x000000ff, 0x000000ff, false);
52 static reloc_howto_type r_low16
=
53 HOWTO (R_H8500_LOW16
, 0, 1, 16, false, 0,
54 complain_overflow_bitfield
, 0, "r_low16", true, 0x0000ffff, 0x0000ffff, false);
56 static reloc_howto_type r_pcrel8
=
57 HOWTO (R_H8500_PCREL8
, 0, 1, 8, true, 0, complain_overflow_signed
, 0, "r_pcrel8", true, 0, 0, true);
60 static reloc_howto_type r_pcrel16
=
61 HOWTO (R_H8500_PCREL16
, 0, 1, 16, true, 0, complain_overflow_signed
, 0, "r_pcrel16", true, 0, 0, true);
63 static reloc_howto_type r_high16
=
64 HOWTO (R_H8500_HIGH16
, 0, 1, 8, false, 0,
65 complain_overflow_bitfield
, 0, "r_high16", true, 0x000ffff, 0x0000ffff, false);
68 /* Turn a howto into a reloc number */
71 coff_h8500_select_reloc (howto
)
72 reloc_howto_type
*howto
;
77 #define SELECT_RELOC(x,howto) x= coff_h8500_select_reloc(howto)
80 #define BADMAG(x) H8500BADMAG(x)
81 #define H8500 1 /* Customize coffcode.h */
83 #define __A_MAGIC_SET__
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';
92 /* Code to turn a r_type into a howto ptr, uses the above howto table
96 rtype2howto(internal
, dst
)
98 struct internal_reloc
*dst
;
103 fprintf (stderr
, "BAD 0x%x\n", dst
->r_type
);
105 internal
->howto
= &r_imm8
;
108 internal
->howto
= &r_imm16
;
111 internal
->howto
= &r_imm24
;
114 internal
->howto
= &r_imm32
;
117 internal
->howto
= &r_pcrel8
;
119 case R_H8500_PCREL16
:
120 internal
->howto
= &r_pcrel16
;
123 internal
->howto
= &r_high8
;
126 internal
->howto
= &r_high16
;
129 internal
->howto
= &r_low16
;
134 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
137 /* Perform any necessaru magic to the addend in a reloc entry */
140 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
141 cache_ptr->addend = ext_reloc.r_offset;
144 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
145 reloc_processing(relent, reloc, symbols, abfd, section)
147 static void reloc_processing (relent
, reloc
, symbols
, abfd
, section
)
149 struct internal_reloc
*reloc
;
154 relent
->address
= reloc
->r_vaddr
;
155 rtype2howto (relent
, reloc
);
157 if (reloc
->r_symndx
> 0)
159 relent
->sym_ptr_ptr
= symbols
+ obj_convert (abfd
)[reloc
->r_symndx
];
163 relent
->sym_ptr_ptr
= &(bfd_abs_symbol
);
167 relent
->addend
= reloc
->r_offset
;
168 relent
->address
-= section
->vma
;
172 extra_case (in_abfd
, link_info
, link_order
, reloc
, data
, src_ptr
, dst_ptr
)
174 struct bfd_link_info
*link_info
;
175 struct bfd_link_order
*link_order
;
178 unsigned int *src_ptr
;
179 unsigned int *dst_ptr
;
181 bfd_byte
*d
= data
+*dst_ptr
;
182 asection
*input_section
= link_order
->u
.indirect
.section
;
183 switch (reloc
->howto
->type
)
187 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
195 (bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
)
204 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
212 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
221 (bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
)
231 int v
= bfd_coff_reloc16_get_value(reloc
, link_info
, input_section
);
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);
241 int v
= bfd_coff_reloc16_get_value(reloc
, link_info
, input_section
);
242 bfd_put_32 (in_abfd
, v
, data
+ *dst_ptr
);
251 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
253 bfd_vma dot
= link_order
->offset
255 + link_order
->u
.indirect
.section
->output_section
->vma
;
256 int gap
= dst
- dot
- 1; /* -1 since were in the odd byte of the
257 word and the pc's been incremented */
259 if (gap
> 128 || gap
< -128)
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
)))
267 bfd_put_8 (in_abfd
, gap
, data
+ *dst_ptr
);
272 case R_H8500_PCREL16
:
274 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
276 bfd_vma dot
= link_order
->offset
278 + link_order
->u
.indirect
.section
->output_section
->vma
;
279 int gap
= dst
- dot
- 1; /* -1 since were in the odd byte of the
280 word and the pc's been incremented */
282 if (gap
> 32767 || gap
< -32768)
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
)))
290 bfd_put_16 (in_abfd
, gap
, data
+ *dst_ptr
);
301 #define coff_reloc16_extra_cases extra_case
303 #include "coffcode.h"
306 #undef coff_bfd_get_relocated_section_contents
307 #undef coff_bfd_relax_section
308 #define coff_bfd_get_relocated_section_contents \
309 bfd_coff_reloc16_get_relocated_section_contents
310 #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
312 bfd_target h8500coff_vec
=
314 "coff-h8500", /* name */
315 bfd_target_coff_flavour
,
316 true, /* data byte order is big */
317 true, /* header byte order is big */
319 (HAS_RELOC
| EXEC_P
| /* object flags */
320 HAS_LINENO
| HAS_DEBUG
|
321 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
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 */
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 */
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 */
339 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
340 _bfd_write_archive_contents
, bfd_false
},