]>
Commit | Line | Data |
---|---|---|
e89f2fbe | 1 | /* BFD library support routines for the Hitachi H8/300 architecture. |
d01a0278 | 2 | Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc. |
e89f2fbe SC |
3 | Hacked by Steve Chamberlain of Cygnus Support. |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
e89f2fbe | 21 | #include "bfd.h" |
3b4f1a5d | 22 | #include "sysdep.h" |
e89f2fbe SC |
23 | #include "libbfd.h" |
24 | ||
d01a0278 | 25 | #if 0 /* not used currently */ |
b08a0748 | 26 | /* |
e89f2fbe SC |
27 | Relocations for the H8 |
28 | ||
29 | */ | |
b08a0748 | 30 | static bfd_reloc_status_type |
d01a0278 ILT |
31 | howto16_callback (abfd, reloc_entry, symbol_in, data, |
32 | ignore_input_section, ignore_bfd) | |
33 | bfd * abfd; | |
34 | arelent * reloc_entry; | |
35 | struct symbol_cache_entry *symbol_in; | |
36 | PTR data; | |
37 | asection * ignore_input_section; | |
38 | bfd * ignore_bfd; | |
e89f2fbe SC |
39 | { |
40 | long relocation = 0; | |
41 | bfd_vma addr = reloc_entry->address; | |
b08a0748 | 42 | long x = bfd_get_16 (abfd, (bfd_byte *) data + addr); |
e89f2fbe | 43 | |
b08a0748 | 44 | HOWTO_PREPARE (relocation, symbol_in); |
e89f2fbe SC |
45 | |
46 | x = (x + relocation + reloc_entry->addend); | |
47 | ||
b08a0748 | 48 | bfd_put_16 (abfd, x, (bfd_byte *) data + addr); |
e89f2fbe SC |
49 | return bfd_reloc_ok; |
50 | } | |
51 | ||
52 | ||
b08a0748 | 53 | static bfd_reloc_status_type |
d01a0278 ILT |
54 | howto8_callback (abfd, reloc_entry, symbol_in, data, |
55 | ignore_input_section, ignore_bfd) | |
56 | bfd * abfd; | |
57 | arelent * reloc_entry; | |
58 | struct symbol_cache_entry *symbol_in; | |
59 | PTR data; | |
60 | asection * ignore_input_section; | |
61 | bfd * ignore_bfd; | |
e89f2fbe SC |
62 | { |
63 | long relocation = 0; | |
64 | bfd_vma addr = reloc_entry->address; | |
b08a0748 | 65 | long x = bfd_get_8 (abfd, (bfd_byte *) data + addr); |
e89f2fbe | 66 | |
b08a0748 | 67 | HOWTO_PREPARE (relocation, symbol_in); |
e89f2fbe SC |
68 | |
69 | x = (x + relocation + reloc_entry->addend); | |
70 | ||
b08a0748 | 71 | bfd_put_8 (abfd, x, (bfd_byte *) data + addr); |
e89f2fbe SC |
72 | return bfd_reloc_ok; |
73 | } | |
74 | ||
75 | ||
b08a0748 | 76 | static bfd_reloc_status_type |
d01a0278 ILT |
77 | howto8_FFnn_callback (abfd, reloc_entry, symbol_in, data, |
78 | ignore_input_section, ignore_bfd) | |
79 | bfd * abfd; | |
80 | arelent * reloc_entry; | |
81 | struct symbol_cache_entry *symbol_in; | |
82 | PTR data; | |
83 | asection * ignore_input_section; | |
84 | bfd * ignore_bfd; | |
e89f2fbe SC |
85 | { |
86 | long relocation = 0; | |
87 | bfd_vma addr = reloc_entry->address; | |
88 | ||
b08a0748 SC |
89 | long x = bfd_get_8 (abfd, (bfd_byte *) data + addr); |
90 | abort (); | |
91 | HOWTO_PREPARE (relocation, symbol_in); | |
e89f2fbe SC |
92 | |
93 | x = (x + relocation + reloc_entry->addend); | |
94 | ||
b08a0748 | 95 | bfd_put_8 (abfd, x, (bfd_byte *) data + addr); |
e89f2fbe SC |
96 | return bfd_reloc_ok; |
97 | } | |
98 | ||
b08a0748 | 99 | static bfd_reloc_status_type |
d01a0278 ILT |
100 | howto8_pcrel_callback (abfd, reloc_entry, symbol_in, data, |
101 | ignore_input_section, ignore_bfd) | |
102 | bfd * abfd; | |
103 | arelent * reloc_entry; | |
104 | struct symbol_cache_entry *symbol_in; | |
105 | PTR data; | |
106 | asection * ignore_input_section; | |
107 | bfd * ignore_bfd; | |
e89f2fbe SC |
108 | { |
109 | long relocation = 0; | |
110 | bfd_vma addr = reloc_entry->address; | |
b08a0748 SC |
111 | long x = bfd_get_8 (abfd, (bfd_byte *) data + addr); |
112 | abort (); | |
113 | HOWTO_PREPARE (relocation, symbol_in); | |
e89f2fbe SC |
114 | |
115 | x = (x + relocation + reloc_entry->addend); | |
116 | ||
b08a0748 | 117 | bfd_put_8 (abfd, x, (bfd_byte *) data + addr); |
e89f2fbe SC |
118 | return bfd_reloc_ok; |
119 | } | |
120 | ||
e89f2fbe | 121 | static reloc_howto_type howto_16 |
b08a0748 | 122 | = NEWHOWTO (howto16_callback, "abs16", 1, false, false); |
e89f2fbe | 123 | static reloc_howto_type howto_8 |
b08a0748 | 124 | = NEWHOWTO (howto8_callback, "abs8", 0, false, false); |
e89f2fbe SC |
125 | |
126 | static reloc_howto_type howto_8_FFnn | |
b08a0748 | 127 | = NEWHOWTO (howto8_FFnn_callback, "ff00+abs8", 0, false, false); |
e89f2fbe SC |
128 | |
129 | static reloc_howto_type howto_8_pcrel | |
b08a0748 | 130 | = NEWHOWTO (howto8_pcrel_callback, "pcrel8", 0, false, true); |
e89f2fbe | 131 | |
d01a0278 ILT |
132 | static reloc_howto_type * |
133 | local_bfd_reloc_type_lookup (arch, code) | |
134 | CONST struct bfd_arch_info *arch; | |
135 | bfd_reloc_code_real_type code; | |
136 | { | |
b08a0748 SC |
137 | switch (code) |
138 | { | |
139 | case BFD_RELOC_16: | |
140 | return &howto_16; | |
141 | case BFD_RELOC_8_FFnn: | |
142 | return &howto_8_FFnn; | |
143 | case BFD_RELOC_8: | |
144 | return &howto_8; | |
145 | case BFD_RELOC_8_PCREL: | |
146 | return &howto_8_pcrel; | |
147 | default: | |
148 | return (reloc_howto_type *) NULL; | |
149 | } | |
e89f2fbe | 150 | } |
d01a0278 | 151 | #endif |
b08a0748 SC |
152 | |
153 | int bfd_default_scan_num_mach (); | |
154 | ||
155 | static boolean | |
d01a0278 ILT |
156 | h8300_scan (info, string) |
157 | CONST struct bfd_arch_info *info; | |
158 | CONST char *string; | |
b08a0748 | 159 | { |
d01a0278 | 160 | if (*string != 'h' && *string != 'H') |
b08a0748 SC |
161 | return false; |
162 | ||
163 | string++; | |
164 | if (*string != '8') | |
165 | return false; | |
166 | ||
167 | string++; | |
168 | if (*string == '/') | |
169 | string++; | |
170 | ||
171 | if (*string != '3') | |
172 | return false; | |
173 | string++; | |
174 | if (*string != '0') | |
175 | return false; | |
176 | string++; | |
177 | if (*string != '0') | |
178 | return false; | |
179 | string++; | |
180 | if (*string == '-') | |
181 | string++; | |
d01a0278 | 182 | if (*string == 'h' || *string == 'H') |
b08a0748 SC |
183 | { |
184 | return (info->mach == bfd_mach_h8300h); | |
185 | } | |
186 | else | |
187 | { | |
188 | return info->mach == bfd_mach_h8300; | |
189 | } | |
e89f2fbe SC |
190 | } |
191 | ||
e89f2fbe | 192 | |
d01a0278 | 193 | /* This routine is provided two arch_infos and works out the |
b08a0748 SC |
194 | machine which would be compatible with both and returns a pointer |
195 | to its info structure */ | |
196 | ||
d01a0278 ILT |
197 | static CONST bfd_arch_info_type * |
198 | compatible (in, out) | |
199 | CONST bfd_arch_info_type * in; | |
200 | CONST bfd_arch_info_type * out; | |
b2c91bd9 | 201 | { |
b08a0748 SC |
202 | /* If the output is non-H and the input is -H, that's bad */ |
203 | if (in->mach == bfd_mach_h8300h && | |
204 | out->mach == bfd_mach_h8300) | |
205 | return 0; | |
206 | ||
207 | /* If either is an -H, the answer is -H */ | |
208 | if (in->mach == bfd_mach_h8300h) | |
209 | return in; | |
210 | return out; | |
b2c91bd9 | 211 | } |
3b4f1a5d | 212 | |
b08a0748 SC |
213 | static bfd_arch_info_type h8300_info_struct = |
214 | { | |
215 | 16, /* 16 bits in a word */ | |
216 | 16, /* 16 bits in an address */ | |
217 | 8, /* 8 bits in a byte */ | |
218 | bfd_arch_h8300, | |
219 | bfd_mach_h8300, | |
220 | "H8/300", /* arch_name */ | |
221 | "H8/300", /* printable name */ | |
222 | 1, | |
223 | true, /* the default machine */ | |
224 | compatible, | |
225 | h8300_scan, | |
226 | 0, | |
227 | /* local_bfd_reloc_type_lookup, */ | |
228 | 0, | |
229 | }; | |
230 | ||
231 | ||
232 | static bfd_arch_info_type h8300h_info_struct = | |
233 | { | |
234 | 32, /* 32 bits in a word */ | |
235 | 32, /* 32 bits in an address */ | |
236 | 8, /* 8 bits in a byte */ | |
237 | bfd_arch_h8300, | |
238 | bfd_mach_h8300h, | |
239 | "H8/300H", /* arch_name */ | |
240 | "H8/300H", /* printable name */ | |
241 | 1, | |
242 | false, /* the default machine */ | |
243 | compatible, | |
244 | h8300_scan, | |
245 | 0, | |
246 | /* local_bfd_reloc_type_lookup, */ | |
247 | 0, | |
248 | }; | |
e89f2fbe | 249 | |
3b4f1a5d | 250 | void |
d01a0278 | 251 | bfd_h8300_arch() |
e89f2fbe | 252 | { |
b08a0748 SC |
253 | bfd_arch_linkin (&h8300_info_struct); |
254 | bfd_arch_linkin (&h8300h_info_struct); | |
e89f2fbe | 255 | } |