1 /* BFD back-end for Renesas H8/500 COFF binaries.
2 Copyright (C) 1993-2017 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 3 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., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
27 #include "coff/h8500.h"
28 #include "coff/internal.h"
32 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
34 static reloc_howto_type r_imm8
=
35 HOWTO (R_H8500_IMM8
, 0, 1, 8, FALSE
, 0,
36 complain_overflow_bitfield
, 0, "r_imm8", TRUE
, 0x000000ff, 0x000000ff, FALSE
);
38 static reloc_howto_type r_imm16
=
39 HOWTO (R_H8500_IMM16
, 0, 1, 16, FALSE
, 0,
40 complain_overflow_bitfield
, 0, "r_imm16", TRUE
, 0x0000ffff, 0x0000ffff, FALSE
);
42 static reloc_howto_type r_imm24
=
43 HOWTO (R_H8500_IMM24
, 0, 1, 24, FALSE
, 0,
44 complain_overflow_bitfield
, 0, "r_imm24", TRUE
, 0x00ffffff, 0x00ffffff, FALSE
);
46 static reloc_howto_type r_imm32
=
47 HOWTO (R_H8500_IMM32
, 0, 1, 32, FALSE
, 0,
48 complain_overflow_bitfield
, 0, "r_imm32", TRUE
, 0xffffffff, 0xffffffff, FALSE
);
50 static reloc_howto_type r_high8
=
51 HOWTO (R_H8500_HIGH8
, 0, 1, 8, FALSE
, 0,
52 complain_overflow_dont
, 0, "r_high8", TRUE
, 0x000000ff, 0x000000ff, FALSE
);
54 static reloc_howto_type r_low16
=
55 HOWTO (R_H8500_LOW16
, 0, 1, 16, FALSE
, 0,
56 complain_overflow_dont
, 0, "r_low16", TRUE
, 0x0000ffff, 0x0000ffff, FALSE
);
58 static reloc_howto_type r_pcrel8
=
59 HOWTO (R_H8500_PCREL8
, 0, 1, 8, TRUE
, 0, complain_overflow_signed
, 0, "r_pcrel8", TRUE
, 0, 0, TRUE
);
61 static reloc_howto_type r_pcrel16
=
62 HOWTO (R_H8500_PCREL16
, 0, 1, 16, TRUE
, 0, complain_overflow_signed
, 0, "r_pcrel16", TRUE
, 0, 0, TRUE
);
64 static reloc_howto_type r_high16
=
65 HOWTO (R_H8500_HIGH16
, 0, 1, 8, FALSE
, 0,
66 complain_overflow_dont
, 0, "r_high16", TRUE
, 0x000ffff, 0x0000ffff, FALSE
);
68 /* Turn a howto into a reloc number. */
71 coff_h8500_select_reloc (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 H_GET_32
85 #define SWAP_OUT_RELOC_OFFSET 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. */
93 rtype2howto (arelent
* internal
, struct internal_reloc
*dst
)
98 internal
->howto
= NULL
;
101 internal
->howto
= &r_imm8
;
104 internal
->howto
= &r_imm16
;
107 internal
->howto
= &r_imm24
;
110 internal
->howto
= &r_imm32
;
113 internal
->howto
= &r_pcrel8
;
115 case R_H8500_PCREL16
:
116 internal
->howto
= &r_pcrel16
;
119 internal
->howto
= &r_high8
;
122 internal
->howto
= &r_high16
;
125 internal
->howto
= &r_low16
;
130 #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
132 /* Perform any necessary magic to the addend in a reloc entry. */
134 #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
135 cache_ptr->addend = ext_reloc.r_offset;
137 #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
138 reloc_processing(relent, reloc, symbols, abfd, section)
141 reloc_processing (arelent
* relent
,
142 struct internal_reloc
*reloc
,
147 relent
->address
= reloc
->r_vaddr
;
148 rtype2howto (relent
, reloc
);
150 if (reloc
->r_symndx
> 0)
151 relent
->sym_ptr_ptr
= symbols
+ obj_convert (abfd
)[reloc
->r_symndx
];
153 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
155 relent
->addend
= reloc
->r_offset
;
156 relent
->address
-= section
->vma
;
160 extra_case (bfd
*in_abfd
,
161 struct bfd_link_info
*link_info
,
162 struct bfd_link_order
*link_order
,
165 unsigned int *src_ptr
,
166 unsigned int *dst_ptr
)
168 bfd_byte
*d
= data
+*dst_ptr
;
169 asection
*input_section
= link_order
->u
.indirect
.section
;
171 switch (reloc
->howto
->type
)
175 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
183 (bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
)
192 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
200 bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
),
209 (bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
)
219 int v
= bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
);
220 int o
= bfd_get_32 (in_abfd
, data
+ *dst_ptr
-1);
221 v
= (v
& 0x00ffffff) | (o
& 0xff00000);
222 bfd_put_32 (in_abfd
, (bfd_vma
) v
, data
+ *dst_ptr
-1);
229 int v
= bfd_coff_reloc16_get_value (reloc
, link_info
, input_section
);
230 bfd_put_32 (in_abfd
, (bfd_vma
) v
, data
+ *dst_ptr
);
238 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
240 bfd_vma dot
= (*dst_ptr
241 + input_section
->output_offset
242 + input_section
->output_section
->vma
);
243 int gap
= dst
- dot
- 1; /* -1 since were in the odd byte of the
244 word and the pc's been incremented. */
246 if (gap
> 128 || gap
< -128)
247 (*link_info
->callbacks
->reloc_overflow
)
248 (link_info
, NULL
, bfd_asymbol_name (*reloc
->sym_ptr_ptr
),
249 reloc
->howto
->name
, reloc
->addend
, input_section
->owner
,
250 input_section
, reloc
->address
);
252 bfd_put_8 (in_abfd
, gap
, data
+ *dst_ptr
);
257 case R_H8500_PCREL16
:
259 bfd_vma dst
= bfd_coff_reloc16_get_value (reloc
, link_info
,
261 bfd_vma dot
= (*dst_ptr
262 + input_section
->output_offset
263 + input_section
->output_section
->vma
);
264 int gap
= dst
- dot
- 1; /* -1 since were in the odd byte of the
265 word and the pc's been incremented. */
267 if (gap
> 32767 || gap
< -32768)
268 (*link_info
->callbacks
->reloc_overflow
)
269 (link_info
, NULL
, bfd_asymbol_name (*reloc
->sym_ptr_ptr
),
270 reloc
->howto
->name
, reloc
->addend
, input_section
->owner
,
271 input_section
, reloc
->address
);
273 bfd_put_16 (in_abfd
, (bfd_vma
) gap
, data
+ *dst_ptr
);
284 #define coff_reloc16_extra_cases extra_case
286 #ifndef bfd_pe_print_pdata
287 #define bfd_pe_print_pdata NULL
290 #include "coffcode.h"
292 #undef coff_bfd_get_relocated_section_contents
293 #undef coff_bfd_relax_section
294 #define coff_bfd_get_relocated_section_contents \
295 bfd_coff_reloc16_get_relocated_section_contents
296 #define coff_bfd_relax_section bfd_coff_reloc16_relax_section
298 CREATE_BIG_COFF_TARGET_VEC (h8500_coff_vec
, "coff-h8500", 0, 0, '_', NULL
, COFF_SWAP_TABLE
)