1 /* BFD back-end for Hitachi H8/500 COFF binaries.
2 Copyright 1993, 1994, 1995, 1997, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support.
5 Written by Steve Chamberlain, <sac@cygnus.com>.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "coff/h8500.h"
28 #include "coff/internal.h"
31 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
33 static reloc_howto_type r_imm8
=
34 HOWTO (R_H8500_IMM8
, 0, 1, 8, false, 0,
35 complain_overflow_bitfield
, 0, "r_imm8", true, 0x000000ff, 0x000000ff, false);
37 static reloc_howto_type r_imm16
=
38 HOWTO (R_H8500_IMM16
, 0, 1, 16, false, 0,
39 complain_overflow_bitfield
, 0, "r_imm16", true, 0x0000ffff, 0x0000ffff, false);
41 static reloc_howto_type r_imm24
=
42 HOWTO (R_H8500_IMM24
, 0, 1, 24, false, 0,
43 complain_overflow_bitfield
, 0, "r_imm24", true, 0x00ffffff, 0x00ffffff, false);
45 static reloc_howto_type r_imm32
=
46 HOWTO (R_H8500_IMM32
, 0, 1, 32, false, 0,
47 complain_overflow_bitfield
, 0, "r_imm32", true, 0xffffffff, 0xffffffff, false);
49 static reloc_howto_type r_high8
=
50 HOWTO (R_H8500_HIGH8
, 0, 1, 8, false, 0,
51 complain_overflow_dont
, 0, "r_high8", true, 0x000000ff, 0x000000ff, false);
53 static reloc_howto_type r_low16
=
54 HOWTO (R_H8500_LOW16
, 0, 1, 16, false, 0,
55 complain_overflow_dont
, 0, "r_low16", true, 0x0000ffff, 0x0000ffff, false);
57 static reloc_howto_type r_pcrel8
=
58 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_dont
, 0, "r_high16", true, 0x000ffff, 0x0000ffff, false);
67 /* Turn a howto into a reloc number */
70 coff_h8500_select_reloc (howto
)
71 reloc_howto_type
*howto
;
76 #define SELECT_RELOC(x,howto) x.r_type = coff_h8500_select_reloc(howto)
78 #define BADMAG(x) H8500BADMAG(x)
79 #define H8500 1 /* Customize coffcode.h */
81 #define __A_MAGIC_SET__
83 /* Code to swap in the reloc */
84 #define SWAP_IN_RELOC_OFFSET bfd_h_get_32
85 #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
86 #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
87 dst->r_stuff[0] = 'S'; \
88 dst->r_stuff[1] = 'C';
90 /* Code to turn a r_type into a howto ptr, uses the above howto table
94 rtype2howto(internal
, dst
)
96 struct internal_reloc
*dst
;
104 internal
->howto
= &r_imm8
;
107 internal
->howto
= &r_imm16
;
110 internal
->howto
= &r_imm24
;
113 internal
->howto
= &r_imm32
;
116 internal
->howto
= &r_pcrel8
;
118 case R_H8500_PCREL16
:
119 internal
->howto
= &r_pcrel16
;
122 internal
->howto
= &r_high8
;
125 internal
->howto
= &r_high16
;
128 internal
->howto
= &r_low16
;
133 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
135 /* Perform any necessary magic to the addend in a reloc entry */
137 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
138 cache_ptr->addend = ext_reloc.r_offset;
140 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
141 reloc_processing(relent, reloc, symbols, abfd, section)
143 static void reloc_processing (relent
, reloc
, symbols
, abfd
, section
)
145 struct internal_reloc
*reloc
;
150 relent
->address
= reloc
->r_vaddr
;
151 rtype2howto (relent
, reloc
);
153 if (reloc
->r_symndx
> 0)
155 relent
->sym_ptr_ptr
= symbols
+ obj_convert (abfd
)[reloc
->r_symndx
];
159 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
162 relent
->addend
= reloc
->r_offset
;
163 relent
->address
-= section
->vma
;
167 extra_case (in_abfd
, link_info
, link_order
, reloc
, data
, src_ptr
, dst_ptr
)
169 struct bfd_link_info
*link_info
;
170 struct bfd_link_order
*link_order
;
173 unsigned int *src_ptr
;
174 unsigned int *dst_ptr
;
176 bfd_byte
*d
= data
+*dst_ptr
;
177 asection
*input_section
= link_order
->u
.indirect
.section
;
178 switch (reloc
->howto
->type
)
182 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
190 (bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
)
199 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
207 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
216 (bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
)
226 int v
= bfd_coff_reloc16_get_value(reloc
, link_info
, input_section
);
227 int o
= bfd_get_32 (in_abfd
, data
+ *dst_ptr
-1);
228 v
= (v
& 0x00ffffff) | (o
& 0xff00000);
229 bfd_put_32 (in_abfd
, v
, data
+ *dst_ptr
-1);
236 int v
= bfd_coff_reloc16_get_value(reloc
, link_info
, input_section
);
237 bfd_put_32 (in_abfd
, v
, data
+ *dst_ptr
);
245 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
247 bfd_vma dot
= link_order
->offset
249 + link_order
->u
.indirect
.section
->output_section
->vma
;
250 int gap
= dst
- dot
- 1; /* -1 since were in the odd byte of the
251 word and the pc's been incremented */
253 if (gap
> 128 || gap
< -128)
255 if (! ((*link_info
->callbacks
->reloc_overflow
)
256 (link_info
, bfd_asymbol_name (*reloc
->sym_ptr_ptr
),
257 reloc
->howto
->name
, reloc
->addend
, input_section
->owner
,
258 input_section
, reloc
->address
)))
261 bfd_put_8 (in_abfd
, gap
, data
+ *dst_ptr
);
266 case R_H8500_PCREL16
:
268 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
270 bfd_vma dot
= link_order
->offset
272 + link_order
->u
.indirect
.section
->output_section
->vma
;
273 int gap
= dst
- dot
- 1; /* -1 since were in the odd byte of the
274 word and the pc's been incremented */
276 if (gap
> 32767 || gap
< -32768)
278 if (! ((*link_info
->callbacks
->reloc_overflow
)
279 (link_info
, bfd_asymbol_name (*reloc
->sym_ptr_ptr
),
280 reloc
->howto
->name
, reloc
->addend
, input_section
->owner
,
281 input_section
, reloc
->address
)))
284 bfd_put_16 (in_abfd
, gap
, data
+ *dst_ptr
);
295 #define coff_reloc16_extra_cases extra_case
297 #include "coffcode.h"
299 #undef coff_bfd_get_relocated_section_contents
300 #undef coff_bfd_relax_section
301 #define coff_bfd_get_relocated_section_contents \
302 bfd_coff_reloc16_get_relocated_section_contents
303 #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
305 CREATE_BIG_COFF_TARGET_VEC (h8500coff_vec
, "coff-h8500", 0, 0, '_', NULL
)