* config/m32r/m32r.mt (GDBSERVER_LIBS): Added ../../intl/libintl.a.
[deliverable/binutils-gdb.git] / bfd / coff-h8500.c
CommitLineData
252b5132
RH
1/* BFD back-end for Hitachi H8/500 COFF binaries.
2 Copyright 1993, 94, 95, 1997 Free Software Foundation, Inc.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22#include "bfd.h"
23#include "sysdep.h"
24#include "libbfd.h"
25#include "bfdlink.h"
26#include "coff/h8500.h"
27#include "coff/internal.h"
28#include "libcoff.h"
29
30#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1)
31
32static reloc_howto_type r_imm8 =
33HOWTO (R_H8500_IMM8, 0, 1, 8, false, 0,
34 complain_overflow_bitfield, 0, "r_imm8", true, 0x000000ff, 0x000000ff, false);
35
36static reloc_howto_type r_imm16 =
37HOWTO (R_H8500_IMM16, 0, 1, 16, false, 0,
38 complain_overflow_bitfield, 0, "r_imm16", true, 0x0000ffff, 0x0000ffff, false);
39
40static reloc_howto_type r_imm24 =
41HOWTO (R_H8500_IMM24, 0, 1, 24, false, 0,
42 complain_overflow_bitfield, 0, "r_imm24", true, 0x00ffffff, 0x00ffffff, false);
43
44static reloc_howto_type r_imm32 =
45HOWTO (R_H8500_IMM32, 0, 1, 32, false, 0,
46 complain_overflow_bitfield, 0, "r_imm32", true, 0xffffffff, 0xffffffff, false);
47
252b5132
RH
48static reloc_howto_type r_high8 =
49HOWTO (R_H8500_HIGH8, 0, 1, 8, false, 0,
50 complain_overflow_dont, 0, "r_high8", true, 0x000000ff, 0x000000ff, false);
51
52static reloc_howto_type r_low16 =
53HOWTO (R_H8500_LOW16, 0, 1, 16, false, 0,
54 complain_overflow_dont, 0, "r_low16", true, 0x0000ffff, 0x0000ffff, false);
55
56static reloc_howto_type r_pcrel8 =
57HOWTO (R_H8500_PCREL8, 0, 1, 8, true, 0, complain_overflow_signed, 0, "r_pcrel8", true, 0, 0, true);
58
252b5132
RH
59static reloc_howto_type r_pcrel16 =
60HOWTO (R_H8500_PCREL16, 0, 1, 16, true, 0, complain_overflow_signed, 0, "r_pcrel16", true, 0, 0, true);
61
62static reloc_howto_type r_high16 =
63HOWTO (R_H8500_HIGH16, 0, 1, 8, false, 0,
64 complain_overflow_dont, 0, "r_high16", true, 0x000ffff, 0x0000ffff, false);
65
252b5132
RH
66/* Turn a howto into a reloc number */
67
5fcfd273 68static int
252b5132
RH
69coff_h8500_select_reloc (howto)
70 reloc_howto_type *howto;
71{
72 return howto->type;
73}
74
75#define SELECT_RELOC(x,howto) x.r_type = coff_h8500_select_reloc(howto)
76
252b5132
RH
77#define BADMAG(x) H8500BADMAG(x)
78#define H8500 1 /* Customize coffcode.h */
79
80#define __A_MAGIC_SET__
81
82/* Code to swap in the reloc */
83#define SWAP_IN_RELOC_OFFSET bfd_h_get_32
84#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
85#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
86 dst->r_stuff[0] = 'S'; \
87 dst->r_stuff[1] = 'C';
88
89/* Code to turn a r_type into a howto ptr, uses the above howto table
90 */
91
92static void
93rtype2howto(internal, dst)
94 arelent * internal;
95 struct internal_reloc *dst;
96{
97 switch (dst->r_type)
98 {
99 default:
100 abort ();
101 break;
102 case R_H8500_IMM8:
103 internal->howto = &r_imm8;
104 break;
105 case R_H8500_IMM16:
106 internal->howto = &r_imm16;
107 break;
108 case R_H8500_IMM24:
109 internal->howto = &r_imm24;
110 break;
111 case R_H8500_IMM32:
112 internal->howto = &r_imm32;
113 break;
114 case R_H8500_PCREL8:
115 internal->howto = &r_pcrel8;
116 break;
117 case R_H8500_PCREL16:
118 internal->howto = &r_pcrel16;
119 break;
120 case R_H8500_HIGH8:
121 internal->howto = &r_high8;
122 break;
123 case R_H8500_HIGH16:
124 internal->howto = &r_high16;
125 break;
126 case R_H8500_LOW16:
127 internal->howto = &r_low16;
128 break;
129 }
130}
131
132#define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry)
133
252b5132
RH
134/* Perform any necessary magic to the addend in a reloc entry */
135
252b5132
RH
136#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
137 cache_ptr->addend = ext_reloc.r_offset;
138
252b5132
RH
139#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
140 reloc_processing(relent, reloc, symbols, abfd, section)
141
142static void reloc_processing (relent, reloc, symbols, abfd, section)
143 arelent * relent;
144 struct internal_reloc *reloc;
145 asymbol ** symbols;
146 bfd * abfd;
147 asection * section;
148{
149 relent->address = reloc->r_vaddr;
150 rtype2howto (relent, reloc);
151
152 if (reloc->r_symndx > 0)
153 {
154 relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
155 }
156 else
157 {
158 relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
159 }
160
252b5132
RH
161 relent->addend = reloc->r_offset;
162 relent->address -= section->vma;
163}
164
165static void
166extra_case (in_abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)
167 bfd *in_abfd;
168 struct bfd_link_info *link_info;
169 struct bfd_link_order *link_order;
170 arelent *reloc;
171 bfd_byte *data;
172 unsigned int *src_ptr;
173 unsigned int *dst_ptr;
174{
175 bfd_byte *d = data+*dst_ptr;
176 asection *input_section = link_order->u.indirect.section;
177 switch (reloc->howto->type)
178 {
179 case R_H8500_IMM8:
180 bfd_put_8 (in_abfd,
181 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
182 d);
183 (*dst_ptr) += 1;
184 (*src_ptr) += 1;
185 break;
186
187 case R_H8500_HIGH8:
188 bfd_put_8 (in_abfd,
189 (bfd_coff_reloc16_get_value (reloc, link_info, input_section)
190 >> 16),
191 d );
192 (*dst_ptr) += 1;
193 (*src_ptr) += 1;
194 break;
195
196 case R_H8500_IMM16:
197 bfd_put_16 (in_abfd,
198 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
199 d );
200 (*dst_ptr) += 2;
201 (*src_ptr) += 2;
202 break;
203
204 case R_H8500_LOW16:
205 bfd_put_16 (in_abfd,
206 bfd_coff_reloc16_get_value (reloc, link_info, input_section),
207 d);
208
209 (*dst_ptr) += 2;
210 (*src_ptr) += 2;
211 break;
5fcfd273 212
252b5132
RH
213 case R_H8500_HIGH16:
214 bfd_put_16 (in_abfd,
215 (bfd_coff_reloc16_get_value (reloc, link_info, input_section)
216 >>16),
217 d);
218
219 (*dst_ptr) += 2;
220 (*src_ptr) += 2;
221 break;
222
223 case R_H8500_IMM24:
224 {
225 int v = bfd_coff_reloc16_get_value(reloc, link_info, input_section);
6e301b2b 226 int o = bfd_get_32 (in_abfd, data+ *dst_ptr -1);
252b5132
RH
227 v = (v & 0x00ffffff) | (o & 0xff00000);
228 bfd_put_32 (in_abfd, v, data + *dst_ptr -1);
229 (*dst_ptr) +=3;
230 (*src_ptr)+=3;;
231 }
232 break;
233 case R_H8500_IMM32:
234 {
235 int v = bfd_coff_reloc16_get_value(reloc, link_info, input_section);
236 bfd_put_32 (in_abfd, v, data + *dst_ptr);
237 (*dst_ptr) +=4;
238 (*src_ptr)+=4;;
239 }
240 break;
241
252b5132
RH
242 case R_H8500_PCREL8:
243 {
244 bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
245 input_section);
246 bfd_vma dot = link_order->offset
247 + *dst_ptr
248 + link_order->u.indirect.section->output_section->vma;
249 int gap = dst - dot - 1; /* -1 since were in the odd byte of the
250 word and the pc's been incremented */
251
252 if (gap > 128 || gap < -128)
253 {
254 if (! ((*link_info->callbacks->reloc_overflow)
255 (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
256 reloc->howto->name, reloc->addend, input_section->owner,
257 input_section, reloc->address)))
258 abort ();
259 }
260 bfd_put_8 (in_abfd, gap, data + *dst_ptr);
261 (*dst_ptr)++;
262 (*src_ptr)++;
263 break;
264 }
265 case R_H8500_PCREL16:
266 {
267 bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
268 input_section);
269 bfd_vma dot = link_order->offset
270 + *dst_ptr
271 + link_order->u.indirect.section->output_section->vma;
272 int gap = dst - dot - 1; /* -1 since were in the odd byte of the
273 word and the pc's been incremented */
274
275 if (gap > 32767 || gap < -32768)
276 {
277 if (! ((*link_info->callbacks->reloc_overflow)
278 (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr),
279 reloc->howto->name, reloc->addend, input_section->owner,
280 input_section, reloc->address)))
281 abort ();
282 }
283 bfd_put_16 (in_abfd, gap, data + *dst_ptr);
284 (*dst_ptr)+=2;
285 (*src_ptr)+=2;
286 break;
287 }
288
289 default:
290 abort ();
291 }
292}
293
294#define coff_reloc16_extra_cases extra_case
295
296#include "coffcode.h"
297
252b5132
RH
298#undef coff_bfd_get_relocated_section_contents
299#undef coff_bfd_relax_section
300#define coff_bfd_get_relocated_section_contents \
301 bfd_coff_reloc16_get_relocated_section_contents
302#define coff_bfd_relax_section bfd_coff_reloc16_relax_section
303
c3c89269 304CREATE_BIG_COFF_TARGET_VEC (h8500coff_vec, "coff-h8500", 0, 0, '_', NULL)
This page took 0.084171 seconds and 4 git commands to generate.