Commit | Line | Data |
---|---|---|
14aa9a78 | 1 | /* BFD back-end for Hitachi H8/300 COFF binaries. |
d3e572fe | 2 | Copyright 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc. |
14aa9a78 | 3 | Written by Steve Chamberlain, <sac@cygnus.com>. |
b4e42a64 SC |
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 | |
a5655244 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
b4e42a64 | 20 | |
b4e42a64 SC |
21 | #include "bfd.h" |
22 | #include "sysdep.h" | |
b4e42a64 | 23 | #include "obstack.h" |
4991ebb9 ILT |
24 | #include "libbfd.h" |
25 | #include "bfdlink.h" | |
d3e572fe | 26 | #include "genlink.h" |
e98e6ec1 SC |
27 | #include "coff/h8300.h" |
28 | #include "coff/internal.h" | |
b4e42a64 SC |
29 | #include "libcoff.h" |
30 | ||
e7d9ee90 SC |
31 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1) |
32 | ||
33 | ||
34 | /* special handling for H8/300 relocs. | |
35 | We only come here for pcrel stuff and return normally if not an -r link. | |
36 | When doing -r, we can't do any arithmetic for the pcrel stuff, because | |
37 | the code in reloc.c assumes that we can manipulate the targets of | |
38 | the pcrel branches. This isn't so, since the H8/300 can do relaxing, | |
39 | which means that the gap after the instruction may not be enough to | |
40 | contain the offset required for the branch, so we have to use the only | |
41 | the addend until the final link */ | |
42 | ||
43 | static bfd_reloc_status_type | |
44 | special (abfd, reloc_entry, symbol, data, input_section, output_bfd, | |
45 | error_message) | |
46 | bfd *abfd; | |
47 | arelent *reloc_entry; | |
48 | asymbol *symbol; | |
49 | PTR data; | |
50 | asection *input_section; | |
51 | bfd *output_bfd; | |
52 | char **error_message; | |
53 | { | |
e7d9ee90 SC |
54 | if (output_bfd == (bfd *) NULL) |
55 | return bfd_reloc_continue; | |
56 | ||
57 | return bfd_reloc_ok; | |
58 | } | |
59 | ||
14aa9a78 | 60 | static reloc_howto_type howto_table[] = |
b4e42a64 | 61 | { |
e7d9ee90 SC |
62 | HOWTO (R_RELBYTE, 0, 0, 8, false, 0, complain_overflow_bitfield, special, "8", false, 0x000000ff, 0x000000ff, false), |
63 | HOWTO (R_RELWORD, 0, 1, 16, false, 0, complain_overflow_bitfield, special, "16", false, 0x0000ffff, 0x0000ffff, false), | |
64 | HOWTO (R_RELLONG, 0, 2, 32, false, 0, complain_overflow_bitfield, special, "32", false, 0xffffffff, 0xffffffff, false), | |
65 | HOWTO (R_PCRBYTE, 0, 0, 8, true, 0, complain_overflow_signed, special, "DISP8", false, 0x000000ff, 0x000000ff, true), | |
66 | HOWTO (R_PCRWORD, 0, 1, 16, true, 0, complain_overflow_signed, special, "DISP16", false, 0x0000ffff, 0x0000ffff, true), | |
67 | HOWTO (R_PCRLONG, 0, 2, 32, true, 0, complain_overflow_signed, special, "DISP32", false, 0xffffffff, 0xffffffff, true), | |
68 | HOWTO (R_MOVB1, 0, 1, 16, false, 0, complain_overflow_bitfield, special, "16/8", false, 0x0000ffff, 0x0000ffff, false), | |
69 | HOWTO (R_MOVB2, 0, 1, 16, false, 0, complain_overflow_bitfield, special, "8/16", false, 0x0000ffff, 0x0000ffff, false), | |
70 | HOWTO (R_JMP1, 0, 1, 16, false, 0, complain_overflow_bitfield, special, "16/pcrel", false, 0x0000ffff, 0x0000ffff, false), | |
71 | HOWTO (R_JMP2, 0, 0, 8, false, 0, complain_overflow_bitfield, special, "pcrecl/16", false, 0x000000ff, 0x000000ff, false), | |
14aa9a78 ILT |
72 | |
73 | ||
e7d9ee90 SC |
74 | HOWTO (R_JMPL1, 0, 2, 32, false, 0, complain_overflow_bitfield, special, "24/pcrell", false, 0x00ffffff, 0x00ffffff, false), |
75 | HOWTO (R_JMPL_B8, 0, 0, 8, false, 0, complain_overflow_bitfield, special, "pc8/24", false, 0x000000ff, 0x000000ff, false), | |
14aa9a78 | 76 | |
e7d9ee90 SC |
77 | HOWTO (R_MOVLB1, 0, 1, 16, false, 0, complain_overflow_bitfield,special, "24/8", false, 0x0000ffff, 0x0000ffff, false), |
78 | HOWTO (R_MOVLB2, 0, 1, 16, false, 0, complain_overflow_bitfield, special, "8/24", false, 0x0000ffff, 0x0000ffff, false), | |
e98e6ec1 | 79 | |
d3e572fe ILT |
80 | /* An indirect reference to a function. This causes the function's address |
81 | to be added to the function vector in lo-mem and puts the address of | |
82 | the function vector's entry in the jsr instruction. */ | |
83 | HOWTO (R_MEM_INDIRECT, 0, 0, 8, false, 0, complain_overflow_bitfield, special, "8/indirect", false, 0x000000ff, 0x000000ff, false), | |
84 | ||
b4e42a64 SC |
85 | }; |
86 | ||
87 | ||
88 | /* Turn a howto into a reloc number */ | |
89 | ||
e98e6ec1 | 90 | #define SELECT_RELOC(x,howto) \ |
47e70c54 | 91 | { x.r_type = select_reloc(howto); } |
e98e6ec1 | 92 | |
14aa9a78 ILT |
93 | #define BADMAG(x) (H8300BADMAG(x)&& H8300HBADMAG(x)) |
94 | #define H8300 1 /* Customize coffcode.h */ | |
b4e42a64 SC |
95 | #define __A_MAGIC_SET__ |
96 | ||
97 | ||
98 | ||
99 | /* Code to swap in the reloc */ | |
e98e6ec1 SC |
100 | #define SWAP_IN_RELOC_OFFSET bfd_h_get_32 |
101 | #define SWAP_OUT_RELOC_OFFSET bfd_h_put_32 | |
b4e42a64 SC |
102 | #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \ |
103 | dst->r_stuff[0] = 'S'; \ | |
14aa9a78 ILT |
104 | dst->r_stuff[1] = 'C'; |
105 | ||
106 | ||
107 | static int | |
108 | select_reloc (howto) | |
109 | reloc_howto_type *howto; | |
110 | { | |
111 | return howto->type; | |
112 | } | |
b4e42a64 SC |
113 | |
114 | /* Code to turn a r_type into a howto ptr, uses the above howto table | |
115 | */ | |
116 | ||
14aa9a78 ILT |
117 | static void |
118 | rtype2howto (internal, dst) | |
119 | arelent *internal; | |
120 | struct internal_reloc *dst; | |
e98e6ec1 | 121 | { |
14aa9a78 ILT |
122 | switch (dst->r_type) |
123 | { | |
e98e6ec1 | 124 | case R_RELBYTE: |
14aa9a78 | 125 | internal->howto = howto_table + 0; |
e98e6ec1 SC |
126 | break; |
127 | case R_RELWORD: | |
14aa9a78 ILT |
128 | internal->howto = howto_table + 1; |
129 | break; | |
130 | case R_RELLONG: | |
131 | internal->howto = howto_table + 2; | |
132 | break; | |
e98e6ec1 | 133 | case R_PCRBYTE: |
14aa9a78 | 134 | internal->howto = howto_table + 3; |
e98e6ec1 SC |
135 | break; |
136 | case R_PCRWORD: | |
14aa9a78 ILT |
137 | internal->howto = howto_table + 4; |
138 | break; | |
139 | case R_PCRLONG: | |
140 | internal->howto = howto_table + 5; | |
e98e6ec1 SC |
141 | break; |
142 | case R_MOVB1: | |
143 | internal->howto = howto_table + 6; | |
144 | break; | |
145 | case R_MOVB2: | |
146 | internal->howto = howto_table + 7; | |
147 | break; | |
148 | case R_JMP1: | |
14aa9a78 | 149 | internal->howto = howto_table + 8; |
e98e6ec1 | 150 | break; |
e98e6ec1 | 151 | case R_JMP2: |
14aa9a78 ILT |
152 | internal->howto = howto_table + 9; |
153 | break; | |
154 | case R_JMPL1: | |
155 | internal->howto = howto_table + 10; | |
156 | break; | |
157 | case R_JMPL_B8: | |
158 | internal->howto = howto_table + 11; | |
159 | break; | |
160 | case R_MOVLB1: | |
161 | internal->howto = howto_table + 12; | |
162 | break; | |
163 | case R_MOVLB2: | |
164 | internal->howto = howto_table + 13; | |
e98e6ec1 | 165 | break; |
d3e572fe ILT |
166 | case R_MEM_INDIRECT: |
167 | internal->howto = howto_table + 14; | |
168 | break; | |
e98e6ec1 | 169 | default: |
d3e572fe | 170 | abort (); |
e98e6ec1 SC |
171 | break; |
172 | } | |
173 | } | |
174 | ||
175 | #define RTYPE2HOWTO(internal, relocentry) rtype2howto(internal,relocentry) | |
b4e42a64 SC |
176 | |
177 | ||
178 | /* Perform any necessaru magic to the addend in a reloc entry */ | |
179 | ||
180 | ||
181 | #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \ | |
182 | cache_ptr->addend = ext_reloc.r_offset; | |
183 | ||
14aa9a78 | 184 | |
e98e6ec1 SC |
185 | #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \ |
186 | reloc_processing(relent, reloc, symbols, abfd, section) | |
187 | ||
14aa9a78 | 188 | static void |
47e70c54 SC |
189 | reloc_processing (relent, reloc, symbols, abfd, section) |
190 | arelent * relent; | |
191 | struct internal_reloc *reloc; | |
192 | asymbol ** symbols; | |
193 | bfd * abfd; | |
194 | asection * section; | |
e98e6ec1 | 195 | { |
14aa9a78 ILT |
196 | relent->address = reloc->r_vaddr; |
197 | rtype2howto (relent, reloc); | |
198 | ||
199 | if (((int) reloc->r_symndx) > 0) | |
200 | { | |
201 | relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; | |
202 | } | |
203 | else | |
204 | { | |
e7d9ee90 | 205 | relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; |
14aa9a78 ILT |
206 | } |
207 | ||
208 | ||
209 | ||
210 | relent->addend = reloc->r_offset; | |
211 | ||
212 | relent->address -= section->vma; | |
213 | /* relent->section = 0;*/ | |
214 | } | |
215 | ||
216 | ||
217 | static int | |
47e70c54 SC |
218 | h8300_reloc16_estimate(abfd, input_section, reloc, shrink, link_info) |
219 | bfd *abfd; | |
14aa9a78 | 220 | asection *input_section; |
14aa9a78 ILT |
221 | arelent *reloc; |
222 | unsigned int shrink; | |
4991ebb9 | 223 | struct bfd_link_info *link_info; |
14aa9a78 ILT |
224 | { |
225 | bfd_vma value; | |
226 | bfd_vma dot; | |
227 | bfd_vma gap; | |
228 | ||
229 | /* The address of the thing to be relocated will have moved back by | |
230 | the size of the shrink - but we don't change reloc->address here, | |
231 | since we need it to know where the relocation lives in the source | |
232 | uncooked section */ | |
233 | ||
234 | /* reloc->address -= shrink; conceptual */ | |
235 | ||
236 | bfd_vma address = reloc->address - shrink; | |
e98e6ec1 SC |
237 | |
238 | ||
14aa9a78 ILT |
239 | switch (reloc->howto->type) |
240 | { | |
241 | case R_MOVB2: | |
242 | case R_JMP2: | |
243 | shrink+=2; | |
244 | break; | |
245 | ||
246 | /* Thing is a move one byte */ | |
247 | case R_MOVB1: | |
4991ebb9 ILT |
248 | value = bfd_coff_reloc16_get_value(reloc, link_info, input_section); |
249 | ||
14aa9a78 ILT |
250 | if (value >= 0xff00) |
251 | { | |
252 | ||
253 | /* Change the reloc type from 16bit, possible 8 to 8bit | |
254 | possible 16 */ | |
255 | reloc->howto = reloc->howto + 1; | |
256 | /* The place to relc moves back by one */ | |
257 | /* This will be two bytes smaller in the long run */ | |
258 | shrink +=2 ; | |
47e70c54 | 259 | bfd_perform_slip(abfd, 2, input_section, address); |
14aa9a78 ILT |
260 | } |
261 | ||
262 | break; | |
263 | /* This is the 24 bit branch which could become an 8 bitter, | |
264 | the relocation points to the first byte of the insn, not the | |
265 | actual data */ | |
266 | ||
267 | case R_JMPL1: | |
4991ebb9 | 268 | value = bfd_coff_reloc16_get_value(reloc, link_info, input_section); |
14aa9a78 ILT |
269 | |
270 | dot = input_section->output_section->vma + | |
271 | input_section->output_offset + address; | |
e98e6ec1 | 272 | |
14aa9a78 ILT |
273 | /* See if the address we're looking at within 127 bytes of where |
274 | we are, if so then we can use a small branch rather than the | |
275 | jump we were going to */ | |
276 | ||
277 | gap = value - dot ; | |
278 | ||
279 | if (-120 < (long)gap && (long)gap < 120 ) | |
280 | { | |
281 | ||
282 | /* Change the reloc type from 24bit, possible 8 to 8bit | |
283 | possible 32 */ | |
284 | reloc->howto = reloc->howto + 1; | |
285 | /* This will be two bytes smaller in the long run */ | |
286 | shrink +=2 ; | |
47e70c54 | 287 | bfd_perform_slip(abfd, 2, input_section, address); |
14aa9a78 ILT |
288 | } |
289 | break; | |
290 | ||
291 | case R_JMP1: | |
292 | ||
4991ebb9 | 293 | value = bfd_coff_reloc16_get_value(reloc, link_info, input_section); |
14aa9a78 ILT |
294 | |
295 | dot = input_section->output_section->vma + | |
296 | input_section->output_offset + address; | |
297 | ||
298 | /* See if the address we're looking at within 127 bytes of where | |
299 | we are, if so then we can use a small branch rather than the | |
300 | jump we were going to */ | |
301 | ||
302 | gap = value - (dot - shrink); | |
303 | ||
304 | ||
305 | if (-120 < (long)gap && (long)gap < 120 ) | |
306 | { | |
307 | ||
308 | /* Change the reloc type from 16bit, possible 8 to 8bit | |
309 | possible 16 */ | |
310 | reloc->howto = reloc->howto + 1; | |
311 | /* The place to relc moves back by one */ | |
312 | ||
313 | /* This will be two bytes smaller in the long run */ | |
314 | shrink +=2 ; | |
47e70c54 | 315 | bfd_perform_slip(abfd, 2, input_section, address); |
14aa9a78 ILT |
316 | } |
317 | break; | |
318 | } | |
319 | ||
e98e6ec1 | 320 | |
14aa9a78 | 321 | return shrink; |
e98e6ec1 SC |
322 | } |
323 | ||
14aa9a78 ILT |
324 | |
325 | /* First phase of a relaxing link */ | |
326 | ||
327 | /* Reloc types | |
328 | large small | |
329 | R_MOVB1 R_MOVB2 mov.b with 16bit or 8 bit address | |
330 | R_JMP1 R_JMP2 jmp or pcrel branch | |
331 | R_JMPL1 R_JMPL_B8 24jmp or pcrel branch | |
332 | R_MOVLB1 R_MOVLB2 24 or 8 bit reloc for mov.b | |
333 | ||
334 | */ | |
335 | ||
336 | static void | |
4991ebb9 ILT |
337 | h8300_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, |
338 | dst_ptr) | |
14aa9a78 | 339 | bfd *abfd; |
4991ebb9 ILT |
340 | struct bfd_link_info *link_info; |
341 | struct bfd_link_order *link_order; | |
14aa9a78 ILT |
342 | arelent *reloc; |
343 | bfd_byte *data; | |
344 | unsigned int *src_ptr; | |
345 | unsigned int *dst_ptr; | |
346 | { | |
347 | unsigned int src_address = *src_ptr; | |
348 | unsigned int dst_address = *dst_ptr; | |
4991ebb9 | 349 | asection *input_section = link_order->u.indirect.section; |
14aa9a78 ILT |
350 | |
351 | switch (reloc->howto->type) | |
352 | { | |
353 | /* A 24 bit branch which could be a 8 bit pcrel, really pointing to | |
354 | the byte before the 24bit hole, so we can treat it as a 32bit pointer */ | |
355 | case R_PCRBYTE: | |
356 | { | |
4991ebb9 | 357 | bfd_vma dot = link_order->offset |
14aa9a78 | 358 | + dst_address |
4991ebb9 ILT |
359 | + link_order->u.indirect.section->output_section->vma; |
360 | int gap = (bfd_coff_reloc16_get_value (reloc, link_info, input_section) | |
361 | - dot); | |
14aa9a78 ILT |
362 | if (gap > 127 || gap < -128) |
363 | { | |
4991ebb9 ILT |
364 | if (! ((*link_info->callbacks->reloc_overflow) |
365 | (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr), | |
366 | reloc->howto->name, reloc->addend, input_section->owner, | |
367 | input_section, reloc->address))) | |
368 | abort (); | |
14aa9a78 | 369 | } |
e7d9ee90 | 370 | gap &= ~1; |
14aa9a78 ILT |
371 | bfd_put_8 (abfd, gap, data + dst_address); |
372 | dst_address++; | |
373 | src_address++; | |
374 | ||
47e70c54 SC |
375 | break; |
376 | } | |
377 | case R_PCRWORD: | |
378 | { | |
379 | bfd_vma dot = link_order->offset | |
380 | + dst_address | |
381 | + link_order->u.indirect.section->output_section->vma; | |
382 | int gap = (bfd_coff_reloc16_get_value (reloc, link_info, input_section) | |
2f3508ad | 383 | - dot) - 1; |
47e70c54 SC |
384 | if (gap > 32767 || gap < -32768) |
385 | { | |
386 | if (! ((*link_info->callbacks->reloc_overflow) | |
387 | (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr), | |
388 | reloc->howto->name, reloc->addend, input_section->owner, | |
389 | input_section, reloc->address))) | |
390 | abort (); | |
391 | } | |
392 | ||
393 | bfd_put_16 (abfd, gap, data + dst_address); | |
394 | dst_address+=2; | |
395 | src_address+=2; | |
396 | ||
14aa9a78 ILT |
397 | break; |
398 | } | |
399 | ||
d3e572fe | 400 | case R_MEM_INDIRECT: /* Temporary */ |
14aa9a78 ILT |
401 | case R_RELBYTE: |
402 | { | |
4991ebb9 ILT |
403 | unsigned int gap = bfd_coff_reloc16_get_value (reloc, link_info, |
404 | input_section); | |
e7d9ee90 SC |
405 | if (gap < 0xff |
406 | || (gap >= 0x0000ff00 | |
407 | && gap <= 0x0000ffff) | |
408 | || ( gap >= 0x00ffff00 | |
409 | && gap <= 0x00ffffff) | |
410 | || ( gap >= 0xffffff00 | |
411 | && gap <= 0xffffffff)) | |
412 | { | |
413 | bfd_put_8 (abfd, gap, data + dst_address); | |
414 | dst_address += 1; | |
415 | src_address += 1; | |
416 | } | |
417 | else | |
14aa9a78 | 418 | { |
4991ebb9 ILT |
419 | if (! ((*link_info->callbacks->reloc_overflow) |
420 | (link_info, bfd_asymbol_name (*reloc->sym_ptr_ptr), | |
421 | reloc->howto->name, reloc->addend, input_section->owner, | |
422 | input_section, reloc->address))) | |
423 | abort (); | |
14aa9a78 | 424 | } |
14aa9a78 ILT |
425 | } |
426 | break; | |
427 | case R_JMP1: | |
428 | /* A relword which would have like to have been a pcrel */ | |
429 | case R_MOVB1: | |
430 | /* A relword which would like to have been modified but | |
431 | didn't make it */ | |
432 | case R_RELWORD: | |
4991ebb9 ILT |
433 | bfd_put_16 (abfd, |
434 | bfd_coff_reloc16_get_value (reloc, link_info, input_section), | |
14aa9a78 ILT |
435 | data + dst_address); |
436 | dst_address += 2; | |
437 | src_address += 2; | |
438 | break; | |
439 | case R_RELLONG: | |
4991ebb9 ILT |
440 | bfd_put_32 (abfd, |
441 | bfd_coff_reloc16_get_value (reloc, link_info, input_section), | |
14aa9a78 ILT |
442 | data + dst_address); |
443 | dst_address += 4; | |
444 | src_address += 4; | |
445 | break; | |
446 | ||
447 | case R_MOVB2: | |
448 | /* Special relaxed type, there will be a gap between where we | |
449 | get stuff from and where we put stuff to now | |
450 | ||
451 | for a mov.b @aa:16 -> mov.b @aa:8 | |
452 | opcode 0x6a 0x0y offset | |
453 | -> 0x2y off | |
454 | */ | |
455 | if (data[dst_address - 1] != 0x6a) | |
456 | abort (); | |
457 | switch (data[src_address] & 0xf0) | |
458 | { | |
459 | case 0x00: | |
460 | /* Src is memory */ | |
461 | data[dst_address - 1] = (data[src_address] & 0xf) | 0x20; | |
462 | break; | |
463 | case 0x80: | |
464 | /* Src is reg */ | |
465 | data[dst_address - 1] = (data[src_address] & 0xf) | 0x30; | |
466 | break; | |
467 | default: | |
468 | abort (); | |
469 | } | |
470 | ||
471 | /* the offset must fit ! after all, what was all the relaxing | |
472 | about ? */ | |
473 | ||
4991ebb9 ILT |
474 | bfd_put_8 (abfd, |
475 | bfd_coff_reloc16_get_value (reloc, link_info, input_section), | |
14aa9a78 ILT |
476 | data + dst_address); |
477 | ||
478 | /* Note the magic - src goes up by two bytes, but dst by only | |
479 | one */ | |
480 | dst_address += 1; | |
481 | src_address += 3; | |
482 | ||
483 | break; | |
484 | ||
485 | case R_JMP2: | |
486 | ||
487 | /* Speciial relaxed type */ | |
488 | { | |
4991ebb9 | 489 | bfd_vma dot = link_order->offset |
14aa9a78 | 490 | + dst_address |
4991ebb9 | 491 | + link_order->u.indirect.section->output_section->vma; |
14aa9a78 | 492 | |
4991ebb9 ILT |
493 | int gap = (bfd_coff_reloc16_get_value (reloc, link_info, input_section) |
494 | - dot - 1); | |
14aa9a78 ILT |
495 | |
496 | if ((gap & ~0xff) != 0 && ((gap & 0xff00) != 0xff00)) | |
497 | abort (); | |
498 | ||
499 | bfd_put_8 (abfd, gap, data + dst_address); | |
500 | ||
501 | switch (data[dst_address - 1]) | |
502 | { | |
503 | case 0x5e: | |
504 | /* jsr -> bsr */ | |
505 | bfd_put_8 (abfd, 0x55, data + dst_address - 1); | |
506 | break; | |
507 | case 0x5a: | |
508 | /* jmp ->bra */ | |
509 | bfd_put_8 (abfd, 0x40, data + dst_address - 1); | |
510 | break; | |
511 | ||
512 | default: | |
513 | abort (); | |
514 | } | |
515 | dst_address++; | |
516 | src_address += 3; | |
517 | ||
518 | break; | |
519 | } | |
520 | break; | |
521 | ||
522 | case R_JMPL_B8: /* 24 bit branch which is now 8 bits */ | |
523 | ||
524 | /* Speciial relaxed type */ | |
525 | { | |
4991ebb9 | 526 | bfd_vma dot = link_order->offset |
14aa9a78 | 527 | + dst_address |
4991ebb9 | 528 | + link_order->u.indirect.section->output_section->vma; |
14aa9a78 | 529 | |
4991ebb9 ILT |
530 | int gap = (bfd_coff_reloc16_get_value (reloc, link_info, input_section) |
531 | - dot - 2); | |
14aa9a78 ILT |
532 | |
533 | if ((gap & ~0xff) != 0 && ((gap & 0xff00) != 0xff00)) | |
534 | abort (); | |
535 | ||
536 | switch (data[src_address]) | |
537 | { | |
538 | case 0x5e: | |
539 | /* jsr -> bsr */ | |
540 | bfd_put_8 (abfd, 0x55, data + dst_address); | |
541 | break; | |
542 | case 0x5a: | |
543 | /* jmp ->bra */ | |
544 | bfd_put_8 (abfd, 0x40, data + dst_address); | |
545 | break; | |
546 | ||
547 | default: | |
548 | bfd_put_8 (abfd, 0xde, data + dst_address); | |
549 | break; | |
550 | } | |
551 | ||
552 | bfd_put_8 (abfd, gap, data + dst_address + 1); | |
553 | dst_address += 2; | |
554 | src_address += 4; | |
555 | ||
556 | break; | |
557 | } | |
558 | ||
559 | case R_JMPL1: | |
560 | { | |
4991ebb9 | 561 | int v = bfd_coff_reloc16_get_value (reloc, link_info, input_section); |
14aa9a78 ILT |
562 | int o = bfd_get_32 (abfd, data + src_address); |
563 | v = (v & 0x00ffffff) | (o & 0xff000000); | |
564 | bfd_put_32 (abfd, v, data + dst_address); | |
565 | dst_address += 4; | |
566 | src_address += 4; | |
567 | } | |
568 | ||
569 | break; | |
570 | ||
571 | ||
572 | /* A 24 bit mov which could be an 8 bit move, really pointing to | |
573 | the byte before the 24bit hole, so we can treat it as a 32bit pointer */ | |
574 | case R_MOVLB1: | |
575 | { | |
4991ebb9 | 576 | int v = bfd_coff_reloc16_get_value (reloc, link_info, input_section); |
14aa9a78 ILT |
577 | int o = bfd_get_32 (abfd, data + dst_address); |
578 | v = (v & 0x00ffffff) | (o & 0xff000000); | |
579 | bfd_put_32 (abfd, v, data + dst_address); | |
580 | dst_address += 4; | |
581 | src_address += 4; | |
582 | } | |
583 | ||
584 | break; | |
585 | default: | |
586 | ||
587 | abort (); | |
588 | break; | |
589 | ||
590 | } | |
591 | *src_ptr = src_address; | |
592 | *dst_ptr = dst_address; | |
593 | ||
594 | } | |
595 | ||
596 | #define coff_reloc16_extra_cases h8300_reloc16_extra_cases | |
597 | #define coff_reloc16_estimate h8300_reloc16_estimate | |
598 | ||
69b799df | 599 | #define COFF_LONG_FILENAMES |
b4e42a64 SC |
600 | #include "coffcode.h" |
601 | ||
602 | ||
14aa9a78 | 603 | #undef coff_bfd_get_relocated_section_contents |
294eaca4 | 604 | #undef coff_bfd_relax_section |
4991ebb9 ILT |
605 | #define coff_bfd_get_relocated_section_contents \ |
606 | bfd_coff_reloc16_get_relocated_section_contents | |
14aa9a78 ILT |
607 | #define coff_bfd_relax_section bfd_coff_reloc16_relax_section |
608 | ||
609 | ||
b4e42a64 | 610 | |
2f3508ad | 611 | const bfd_target h8300coff_vec = |
b4e42a64 | 612 | { |
14aa9a78 | 613 | "coff-h8300", /* name */ |
b4e42a64 | 614 | bfd_target_coff_flavour, |
d3e572fe ILT |
615 | BFD_ENDIAN_BIG, /* data byte order is big */ |
616 | BFD_ENDIAN_BIG, /* header byte order is big */ | |
b4e42a64 SC |
617 | |
618 | (HAS_RELOC | EXEC_P | /* object flags */ | |
619 | HAS_LINENO | HAS_DEBUG | | |
4991ebb9 | 620 | HAS_SYMS | HAS_LOCALS | WP_TEXT | BFD_IS_RELAXABLE ), |
14aa9a78 ILT |
621 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ |
622 | '_', /* leading char */ | |
b4e42a64 SC |
623 | '/', /* ar_pad_char */ |
624 | 15, /* ar_max_namelen */ | |
14aa9a78 ILT |
625 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, |
626 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
627 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ | |
628 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, | |
629 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
630 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ | |
631 | ||
632 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ | |
633 | bfd_generic_archive_p, _bfd_dummy_target}, | |
634 | {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ | |
635 | bfd_false}, | |
b4e42a64 | 636 | {bfd_false, coff_write_object_contents, /* bfd_write_contents */ |
14aa9a78 | 637 | _bfd_write_archive_contents, bfd_false}, |
b4e42a64 | 638 | |
6812b607 ILT |
639 | BFD_JUMP_TABLE_GENERIC (coff), |
640 | BFD_JUMP_TABLE_COPY (coff), | |
641 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
642 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
643 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
644 | BFD_JUMP_TABLE_RELOCS (coff), | |
645 | BFD_JUMP_TABLE_WRITE (coff), | |
646 | BFD_JUMP_TABLE_LINK (coff), | |
2f3508ad | 647 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
6812b607 | 648 | |
14aa9a78 | 649 | COFF_SWAP_TABLE, |
b4e42a64 | 650 | }; |