Commit | Line | Data |
---|---|---|
cd6213ff | 1 | /* BFD back-end for Texas Instruments TMS320C80 Multimedia Video Processor (MVP). |
69f3f9f7 | 2 | Copyright 1996, 1997 Free Software Foundation, Inc. |
cd6213ff FF |
3 | |
4 | Written by Fred Fish (fnf@cygnus.com) | |
5 | ||
6 | There is nothing new under the sun. This file draws a lot on other | |
7 | coff files. | |
8 | ||
9 | This file is part of BFD, the Binary File Descriptor library. | |
10 | ||
11 | This program is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2 of the License, or | |
14 | (at your option) any later version. | |
15 | ||
16 | This program is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
22 | along with this program; if not, write to the Free Software | |
23 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
5a608f5b FF |
24 | |
25 | #include "bfd.h" | |
8ac5f940 | 26 | #include "bfdlink.h" |
5a608f5b FF |
27 | #include "sysdep.h" |
28 | #include "libbfd.h" | |
5a608f5b FF |
29 | #include "coff/tic80.h" |
30 | #include "coff/internal.h" | |
31 | #include "libcoff.h" | |
32 | ||
4507d858 | 33 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2) |
5a608f5b | 34 | |
8ac5f940 ILT |
35 | static void rtype2howto |
36 | PARAMS ((arelent *cache_ptr, struct internal_reloc *dst)); | |
37 | static bfd_reloc_status_type ppbase_reloc | |
38 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
39 | static bfd_reloc_status_type glob15_reloc | |
40 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
41 | static bfd_reloc_status_type glob16_reloc | |
42 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
43 | static bfd_reloc_status_type local16_reloc | |
44 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
45 | static boolean coff_tic80_relocate_section | |
46 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
47 | struct internal_reloc *, struct internal_syment *, asection **)); | |
4507d858 FF |
48 | |
49 | static reloc_howto_type tic80_howto_table[] = | |
50 | { | |
51 | ||
52 | HOWTO (R_RELLONG, /* type */ | |
53 | 0, /* rightshift */ | |
54 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
55 | 32, /* bitsize */ | |
56 | false, /* pc_relative */ | |
57 | 0, /* bitpos */ | |
58 | complain_overflow_bitfield, /* complain_on_overflow */ | |
59 | NULL, /* special_function */ | |
8ac5f940 | 60 | "RELLONG", /* name */ |
4507d858 FF |
61 | true, /* partial_inplace */ |
62 | 0xffffffff, /* src_mask */ | |
63 | 0xffffffff, /* dst_mask */ | |
64 | false), /* pcrel_offset */ | |
65 | ||
66 | HOWTO (R_MPPCR, /* type */ | |
8ac5f940 | 67 | 2, /* rightshift */ |
4507d858 FF |
68 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
69 | 32, /* bitsize */ | |
70 | true, /* pc_relative */ | |
71 | 0, /* bitpos */ | |
8ac5f940 | 72 | complain_overflow_signed, /* complain_on_overflow */ |
4507d858 FF |
73 | NULL, /* special_function */ |
74 | "MPPCR", /* name */ | |
75 | true, /* partial_inplace */ | |
76 | 0xffffffff, /* src_mask */ | |
77 | 0xffffffff, /* dst_mask */ | |
78 | true), /* pcrel_offset */ | |
69f3f9f7 MA |
79 | |
80 | HOWTO (R_ABS, /* type */ | |
81 | 0, /* rightshift */ | |
82 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
83 | 32, /* bitsize */ | |
84 | false, /* pc_relative */ | |
85 | 0, /* bitpos */ | |
86 | complain_overflow_bitfield, /* complain_on_overflow */ | |
87 | NULL, /* special_function */ | |
88 | "ABS", /* name */ | |
89 | true, /* partial_inplace */ | |
90 | 0xffffffff, /* src_mask */ | |
91 | 0xffffffff, /* dst_mask */ | |
92 | false), /* pcrel_offset */ | |
8ac5f940 ILT |
93 | |
94 | HOWTO (R_PPBASE, /* type */ | |
95 | 0, /* rightshift */ | |
96 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
97 | 32, /* bitsize */ | |
98 | false, /* pc_relative */ | |
99 | 0, /* bitpos */ | |
546d7a90 | 100 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
101 | ppbase_reloc, /* special_function */ |
102 | "PPBASE", /* name */ | |
103 | true, /* partial_inplace */ | |
104 | 0xffffffff, /* src_mask */ | |
105 | 0xffffffff, /* dst_mask */ | |
106 | false), /* pcrel_offset */ | |
107 | ||
108 | HOWTO (R_PPLBASE, /* type */ | |
109 | 0, /* rightshift */ | |
110 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
111 | 32, /* bitsize */ | |
112 | false, /* pc_relative */ | |
113 | 0, /* bitpos */ | |
546d7a90 | 114 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
115 | ppbase_reloc, /* special_function */ |
116 | "PPLBASE", /* name */ | |
117 | true, /* partial_inplace */ | |
118 | 0xffffffff, /* src_mask */ | |
119 | 0xffffffff, /* dst_mask */ | |
120 | false), /* pcrel_offset */ | |
121 | ||
122 | HOWTO (R_PP15, /* type */ | |
123 | 0, /* rightshift */ | |
124 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
125 | 15, /* bitsize */ | |
126 | false, /* pc_relative */ | |
127 | 6, /* bitpos */ | |
546d7a90 | 128 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
129 | glob15_reloc, /* special_function */ |
130 | "PP15", /* name */ | |
131 | true, /* partial_inplace */ | |
132 | 0x1ffc0, /* src_mask */ | |
133 | 0x1ffc0, /* dst_mask */ | |
134 | false), /* pcrel_offset */ | |
135 | ||
136 | HOWTO (R_PP15W, /* type */ | |
137 | 2, /* rightshift */ | |
138 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
139 | 15, /* bitsize */ | |
140 | false, /* pc_relative */ | |
141 | 6, /* bitpos */ | |
546d7a90 | 142 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
143 | glob15_reloc, /* special_function */ |
144 | "PP15W", /* name */ | |
145 | true, /* partial_inplace */ | |
146 | 0x1ffc0, /* src_mask */ | |
147 | 0x1ffc0, /* dst_mask */ | |
148 | false), /* pcrel_offset */ | |
149 | ||
150 | HOWTO (R_PP15H, /* type */ | |
151 | 1, /* rightshift */ | |
152 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
153 | 15, /* bitsize */ | |
154 | false, /* pc_relative */ | |
155 | 6, /* bitpos */ | |
546d7a90 | 156 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
157 | glob15_reloc, /* special_function */ |
158 | "PP15H", /* name */ | |
159 | true, /* partial_inplace */ | |
160 | 0x1ffc0, /* src_mask */ | |
161 | 0x1ffc0, /* dst_mask */ | |
162 | false), /* pcrel_offset */ | |
163 | ||
164 | HOWTO (R_PP16B, /* type */ | |
165 | 0, /* rightshift */ | |
166 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
167 | 16, /* bitsize */ | |
168 | false, /* pc_relative */ | |
169 | 6, /* bitpos */ | |
546d7a90 | 170 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
171 | glob16_reloc, /* special_function */ |
172 | "PP16B", /* name */ | |
173 | true, /* partial_inplace */ | |
174 | 0x3ffc0, /* src_mask */ | |
175 | 0x3ffc0, /* dst_mask */ | |
176 | false), /* pcrel_offset */ | |
177 | ||
178 | HOWTO (R_PPL15, /* type */ | |
179 | 0, /* rightshift */ | |
180 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
181 | 15, /* bitsize */ | |
182 | false, /* pc_relative */ | |
183 | 0, /* bitpos */ | |
546d7a90 | 184 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
185 | NULL, /* special_function */ |
186 | "PPL15", /* name */ | |
187 | true, /* partial_inplace */ | |
188 | 0x7fff, /* src_mask */ | |
189 | 0x7fff, /* dst_mask */ | |
190 | false), /* pcrel_offset */ | |
191 | ||
192 | HOWTO (R_PPL15W, /* type */ | |
193 | 2, /* rightshift */ | |
194 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
195 | 15, /* bitsize */ | |
196 | false, /* pc_relative */ | |
197 | 0, /* bitpos */ | |
546d7a90 | 198 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
199 | NULL, /* special_function */ |
200 | "PPL15W", /* name */ | |
201 | true, /* partial_inplace */ | |
202 | 0x7fff, /* src_mask */ | |
203 | 0x7fff, /* dst_mask */ | |
204 | false), /* pcrel_offset */ | |
205 | ||
206 | HOWTO (R_PPL15H, /* type */ | |
207 | 1, /* rightshift */ | |
208 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
209 | 15, /* bitsize */ | |
210 | false, /* pc_relative */ | |
211 | 0, /* bitpos */ | |
546d7a90 | 212 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
213 | NULL, /* special_function */ |
214 | "PPL15H", /* name */ | |
215 | true, /* partial_inplace */ | |
216 | 0x7fff, /* src_mask */ | |
217 | 0x7fff, /* dst_mask */ | |
218 | false), /* pcrel_offset */ | |
219 | ||
220 | HOWTO (R_PPL16B, /* type */ | |
221 | 0, /* rightshift */ | |
222 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
223 | 16, /* bitsize */ | |
224 | false, /* pc_relative */ | |
225 | 0, /* bitpos */ | |
546d7a90 | 226 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
227 | local16_reloc, /* special_function */ |
228 | "PPL16B", /* name */ | |
229 | true, /* partial_inplace */ | |
230 | 0xffff, /* src_mask */ | |
231 | 0xffff, /* dst_mask */ | |
232 | false), /* pcrel_offset */ | |
233 | ||
234 | HOWTO (R_PPN15, /* type */ | |
235 | 0, /* rightshift */ | |
236 | -2, /* size (0 = byte, 1 = short, 2 = long) */ | |
237 | 15, /* bitsize */ | |
238 | false, /* pc_relative */ | |
239 | 6, /* bitpos */ | |
546d7a90 | 240 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
241 | glob15_reloc, /* special_function */ |
242 | "PPN15", /* name */ | |
243 | true, /* partial_inplace */ | |
244 | 0x1ffc0, /* src_mask */ | |
245 | 0x1ffc0, /* dst_mask */ | |
246 | false), /* pcrel_offset */ | |
247 | ||
248 | HOWTO (R_PPN15W, /* type */ | |
249 | 2, /* rightshift */ | |
250 | -2, /* size (0 = byte, 1 = short, 2 = long) */ | |
251 | 15, /* bitsize */ | |
252 | false, /* pc_relative */ | |
253 | 6, /* bitpos */ | |
546d7a90 | 254 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
255 | glob15_reloc, /* special_function */ |
256 | "PPN15W", /* name */ | |
257 | true, /* partial_inplace */ | |
258 | 0x1ffc0, /* src_mask */ | |
259 | 0x1ffc0, /* dst_mask */ | |
260 | false), /* pcrel_offset */ | |
261 | ||
262 | HOWTO (R_PPN15H, /* type */ | |
263 | 1, /* rightshift */ | |
264 | -2, /* size (0 = byte, 1 = short, 2 = long) */ | |
265 | 15, /* bitsize */ | |
266 | false, /* pc_relative */ | |
267 | 6, /* bitpos */ | |
546d7a90 | 268 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
269 | glob15_reloc, /* special_function */ |
270 | "PPN15H", /* name */ | |
271 | true, /* partial_inplace */ | |
272 | 0x1ffc0, /* src_mask */ | |
273 | 0x1ffc0, /* dst_mask */ | |
274 | false), /* pcrel_offset */ | |
275 | ||
276 | HOWTO (R_PPN16B, /* type */ | |
277 | 0, /* rightshift */ | |
278 | -2, /* size (0 = byte, 1 = short, 2 = long) */ | |
279 | 16, /* bitsize */ | |
280 | false, /* pc_relative */ | |
281 | 6, /* bitpos */ | |
546d7a90 | 282 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
283 | glob16_reloc, /* special_function */ |
284 | "PPN16B", /* name */ | |
285 | true, /* partial_inplace */ | |
286 | 0x3ffc0, /* src_mask */ | |
287 | 0x3ffc0, /* dst_mask */ | |
288 | false), /* pcrel_offset */ | |
289 | ||
290 | HOWTO (R_PPLN15, /* type */ | |
291 | 0, /* rightshift */ | |
292 | -2, /* size (0 = byte, 1 = short, 2 = long) */ | |
293 | 15, /* bitsize */ | |
294 | false, /* pc_relative */ | |
295 | 0, /* bitpos */ | |
546d7a90 | 296 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
297 | NULL, /* special_function */ |
298 | "PPLN15", /* name */ | |
299 | true, /* partial_inplace */ | |
300 | 0x7fff, /* src_mask */ | |
301 | 0x7fff, /* dst_mask */ | |
302 | false), /* pcrel_offset */ | |
303 | ||
304 | HOWTO (R_PPLN15W, /* type */ | |
305 | 2, /* rightshift */ | |
306 | -2, /* size (0 = byte, 1 = short, 2 = long) */ | |
307 | 15, /* bitsize */ | |
308 | false, /* pc_relative */ | |
309 | 0, /* bitpos */ | |
546d7a90 | 310 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
311 | NULL, /* special_function */ |
312 | "PPLN15W", /* name */ | |
313 | true, /* partial_inplace */ | |
314 | 0x7fff, /* src_mask */ | |
315 | 0x7fff, /* dst_mask */ | |
316 | false), /* pcrel_offset */ | |
317 | ||
318 | HOWTO (R_PPLN15H, /* type */ | |
319 | 1, /* rightshift */ | |
320 | -2, /* size (0 = byte, 1 = short, 2 = long) */ | |
321 | 15, /* bitsize */ | |
322 | false, /* pc_relative */ | |
323 | 0, /* bitpos */ | |
546d7a90 | 324 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
325 | NULL, /* special_function */ |
326 | "PPLN15H", /* name */ | |
327 | true, /* partial_inplace */ | |
328 | 0x7fff, /* src_mask */ | |
329 | 0x7fff, /* dst_mask */ | |
330 | false), /* pcrel_offset */ | |
331 | ||
332 | HOWTO (R_PPLN16B, /* type */ | |
333 | 0, /* rightshift */ | |
334 | -2, /* size (0 = byte, 1 = short, 2 = long) */ | |
335 | 15, /* bitsize */ | |
336 | false, /* pc_relative */ | |
337 | 0, /* bitpos */ | |
546d7a90 | 338 | complain_overflow_dont, /* complain_on_overflow */ |
8ac5f940 ILT |
339 | local16_reloc, /* special_function */ |
340 | "PPLN16B", /* name */ | |
341 | true, /* partial_inplace */ | |
342 | 0xffff, /* src_mask */ | |
343 | 0xffff, /* dst_mask */ | |
344 | false) /* pcrel_offset */ | |
4507d858 | 345 | }; |
8ac5f940 ILT |
346 | \f |
347 | /* Special relocation functions, used when the output file is not | |
348 | itself a COFF TIc80 file. */ | |
349 | ||
350 | /* This special function is used for the base address type | |
351 | relocations. */ | |
352 | ||
353 | static bfd_reloc_status_type | |
354 | ppbase_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | |
355 | error_message) | |
356 | bfd *abfd; | |
357 | arelent *reloc_entry; | |
358 | asymbol *symbol_in; | |
359 | PTR data; | |
360 | asection *input_section; | |
361 | bfd *output_bfd; | |
362 | char **error_message; | |
363 | { | |
364 | /* FIXME. */ | |
365 | abort (); | |
366 | } | |
367 | ||
368 | /* This special function is used for the global 15 bit relocations. */ | |
369 | ||
370 | static bfd_reloc_status_type | |
371 | glob15_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | |
372 | error_message) | |
373 | bfd *abfd; | |
374 | arelent *reloc_entry; | |
375 | asymbol *symbol_in; | |
376 | PTR data; | |
377 | asection *input_section; | |
378 | bfd *output_bfd; | |
379 | char **error_message; | |
380 | { | |
381 | /* FIXME. */ | |
382 | abort (); | |
383 | } | |
384 | ||
385 | /* This special function is used for the global 16 bit relocations. */ | |
386 | ||
387 | static bfd_reloc_status_type | |
388 | glob16_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | |
389 | error_message) | |
390 | bfd *abfd; | |
391 | arelent *reloc_entry; | |
392 | asymbol *symbol_in; | |
393 | PTR data; | |
394 | asection *input_section; | |
395 | bfd *output_bfd; | |
396 | char **error_message; | |
397 | { | |
398 | /* FIXME. */ | |
399 | abort (); | |
400 | } | |
4507d858 | 401 | |
8ac5f940 ILT |
402 | /* This special function is used for the local 16 bit relocations. */ |
403 | ||
404 | static bfd_reloc_status_type | |
405 | local16_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | |
406 | error_message) | |
407 | bfd *abfd; | |
408 | arelent *reloc_entry; | |
409 | asymbol *symbol_in; | |
410 | PTR data; | |
411 | asection *input_section; | |
412 | bfd *output_bfd; | |
413 | char **error_message; | |
414 | { | |
415 | /* FIXME. */ | |
416 | abort (); | |
417 | } | |
418 | \f | |
4507d858 | 419 | /* Code to turn an external r_type into a pointer to an entry in the howto_table. |
69f3f9f7 MA |
420 | If passed an r_type we don't recognize the abort rather than silently failing |
421 | to generate an output file. */ | |
4507d858 FF |
422 | |
423 | static void | |
424 | rtype2howto (cache_ptr, dst) | |
425 | arelent *cache_ptr; | |
426 | struct internal_reloc *dst; | |
427 | { | |
8ac5f940 ILT |
428 | unsigned int i; |
429 | ||
430 | for (i = 0; i < sizeof tic80_howto_table / sizeof tic80_howto_table[0]; i++) | |
4507d858 | 431 | { |
8ac5f940 ILT |
432 | if (tic80_howto_table[i].type == dst->r_type) |
433 | { | |
434 | cache_ptr->howto = tic80_howto_table + i; | |
435 | return; | |
436 | } | |
4507d858 | 437 | } |
8ac5f940 ILT |
438 | |
439 | (*_bfd_error_handler) ("Unrecognized reloc type 0x%x", | |
440 | (unsigned int) dst->r_type); | |
441 | cache_ptr->howto = tic80_howto_table + 0; | |
4507d858 FF |
442 | } |
443 | ||
444 | #define RTYPE2HOWTO(cache_ptr, dst) rtype2howto (cache_ptr, dst) | |
445 | #define coff_rtype_to_howto coff_tic80_rtype_to_howto | |
446 | ||
447 | static reloc_howto_type * | |
448 | coff_tic80_rtype_to_howto (abfd, sec, rel, h, sym, addendp) | |
449 | bfd *abfd; | |
450 | asection *sec; | |
451 | struct internal_reloc *rel; | |
452 | struct coff_link_hash_entry *h; | |
453 | struct internal_syment *sym; | |
454 | bfd_vma *addendp; | |
455 | { | |
456 | arelent genrel; | |
457 | ||
458 | if (rel -> r_symndx == -1 && addendp != NULL) | |
459 | { | |
460 | /* This is a TI "internal relocation", which means that the relocation | |
461 | amount is the amount by which the current section is being relocated | |
462 | in the output section. */ | |
463 | *addendp = (sec -> output_section -> vma + sec -> output_offset) - sec -> vma; | |
464 | } | |
465 | RTYPE2HOWTO (&genrel, rel); | |
466 | return genrel.howto; | |
467 | } | |
5a608f5b FF |
468 | |
469 | #ifndef BADMAG | |
470 | #define BADMAG(x) TIC80BADMAG(x) | |
471 | #endif | |
8ac5f940 ILT |
472 | \f |
473 | #define coff_relocate_section coff_tic80_relocate_section | |
474 | ||
475 | /* We need a special relocation routine to handle the PP relocs. Most | |
476 | of this is a copy of _bfd_coff_generic_relocate_section. */ | |
477 | ||
478 | static boolean | |
479 | coff_tic80_relocate_section (output_bfd, info, input_bfd, | |
480 | input_section, contents, relocs, syms, | |
481 | sections) | |
482 | bfd *output_bfd; | |
483 | struct bfd_link_info *info; | |
484 | bfd *input_bfd; | |
485 | asection *input_section; | |
486 | bfd_byte *contents; | |
487 | struct internal_reloc *relocs; | |
488 | struct internal_syment *syms; | |
489 | asection **sections; | |
490 | { | |
491 | struct internal_reloc *rel; | |
492 | struct internal_reloc *relend; | |
493 | ||
494 | rel = relocs; | |
495 | relend = rel + input_section->reloc_count; | |
496 | for (; rel < relend; rel++) | |
497 | { | |
498 | long symndx; | |
499 | struct coff_link_hash_entry *h; | |
500 | struct internal_syment *sym; | |
501 | bfd_vma addend; | |
502 | bfd_vma val; | |
503 | reloc_howto_type *howto; | |
504 | bfd_reloc_status_type rstat; | |
505 | bfd_vma addr; | |
5a608f5b | 506 | |
8ac5f940 ILT |
507 | symndx = rel->r_symndx; |
508 | ||
509 | if (symndx == -1) | |
510 | { | |
511 | h = NULL; | |
512 | sym = NULL; | |
513 | } | |
514 | else | |
515 | { | |
516 | h = obj_coff_sym_hashes (input_bfd)[symndx]; | |
517 | sym = syms + symndx; | |
518 | } | |
519 | ||
520 | /* COFF treats common symbols in one of two ways. Either the | |
521 | size of the symbol is included in the section contents, or it | |
522 | is not. We assume that the size is not included, and force | |
523 | the rtype_to_howto function to adjust the addend as needed. */ | |
524 | ||
525 | if (sym != NULL && sym->n_scnum != 0) | |
526 | addend = - sym->n_value; | |
527 | else | |
528 | addend = 0; | |
529 | ||
530 | howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h, | |
531 | sym, &addend); | |
532 | if (howto == NULL) | |
533 | return false; | |
534 | ||
535 | val = 0; | |
536 | ||
537 | if (h == NULL) | |
538 | { | |
539 | asection *sec; | |
540 | ||
541 | if (symndx == -1) | |
542 | { | |
543 | sec = bfd_abs_section_ptr; | |
544 | val = 0; | |
545 | } | |
546 | else | |
547 | { | |
548 | sec = sections[symndx]; | |
549 | val = (sec->output_section->vma | |
550 | + sec->output_offset | |
551 | + sym->n_value); | |
552 | if (! obj_pe (output_bfd)) | |
553 | val -= sec->vma; | |
554 | } | |
555 | } | |
556 | else | |
557 | { | |
558 | if (h->root.type == bfd_link_hash_defined | |
559 | || h->root.type == bfd_link_hash_defweak) | |
560 | { | |
561 | asection *sec; | |
562 | ||
563 | sec = h->root.u.def.section; | |
564 | val = (h->root.u.def.value | |
565 | + sec->output_section->vma | |
566 | + sec->output_offset); | |
567 | } | |
568 | ||
569 | else if (! info->relocateable) | |
570 | { | |
571 | if (! ((*info->callbacks->undefined_symbol) | |
572 | (info, h->root.root.string, input_bfd, input_section, | |
573 | rel->r_vaddr - input_section->vma))) | |
574 | return false; | |
575 | } | |
576 | } | |
577 | ||
578 | addr = rel->r_vaddr - input_section->vma; | |
579 | ||
580 | /* FIXME: This code assumes little endian, but the PP can | |
581 | apparently be bi-endian. I don't know if the bi-endianness | |
582 | applies to the instruction set or just to the data. */ | |
583 | switch (howto->type) | |
584 | { | |
585 | default: | |
586 | case R_ABS: | |
587 | case R_RELLONGX: | |
588 | case R_PPL15: | |
589 | case R_PPL15W: | |
590 | case R_PPL15H: | |
591 | case R_PPLN15: | |
592 | case R_PPLN15W: | |
593 | case R_PPLN15H: | |
594 | rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
595 | contents, addr, val, addend); | |
596 | break; | |
597 | ||
598 | case R_PP15: | |
599 | case R_PP15W: | |
600 | case R_PP15H: | |
601 | case R_PPN15: | |
602 | case R_PPN15W: | |
603 | case R_PPN15H: | |
604 | /* Offset the address so that we can use 4 byte relocations. */ | |
605 | rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
606 | contents + 2, addr, val, addend); | |
607 | break; | |
608 | ||
609 | case R_PP16B: | |
610 | case R_PPN16B: | |
611 | { | |
612 | /* The most significant bit is stored in bit 6. */ | |
613 | bfd_byte hold; | |
614 | ||
615 | hold = contents[addr + 4]; | |
616 | contents[addr + 4] &=~ 0x20; | |
617 | contents[addr + 4] |= (contents[addr] >> 1) & 0x20; | |
618 | rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
619 | contents + 2, addr, | |
620 | val, addend); | |
621 | contents[addr] &=~ 0x40; | |
622 | contents[addr] |= (contents[addr + 4] << 1) & 0x40; | |
623 | contents[addr + 4] &=~ 0x20; | |
624 | contents[addr + 4] |= hold & 0x20; | |
625 | break; | |
626 | } | |
627 | ||
628 | case R_PPL16B: | |
629 | case R_PPLN16B: | |
630 | { | |
631 | /* The most significant bit is stored in bit 28. */ | |
632 | bfd_byte hold; | |
633 | ||
634 | hold = contents[addr + 1]; | |
635 | contents[addr + 1] &=~ 0x80; | |
636 | contents[addr + 1] |= (contents[addr + 3] << 3) & 0x80; | |
637 | rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
638 | contents, addr, | |
639 | val, addend); | |
640 | contents[addr + 3] &= ~0x10; | |
641 | contents[addr + 3] |= (contents[addr + 1] >> 3) & 0x10; | |
642 | contents[addr + 1] &=~ 0x80; | |
643 | contents[addr + 1] |= hold & 0x80; | |
644 | break; | |
645 | } | |
646 | ||
647 | case R_PPBASE: | |
648 | /* Parameter RAM is from 0x1000000 to 0x1000800. */ | |
649 | contents[addr] &=~ 0x3; | |
650 | if (val >= 0x1000000 && val < 0x1000800) | |
651 | contents[addr] |= 0x3; | |
652 | else | |
653 | contents[addr] |= 0x2; | |
654 | rstat = bfd_reloc_ok; | |
655 | break; | |
656 | ||
657 | case R_PPLBASE: | |
658 | /* Parameter RAM is from 0x1000000 to 0x1000800. */ | |
659 | contents[addr + 2] &= ~0xc0; | |
660 | if (val >= 0x1000000 && val < 0x1000800) | |
661 | contents[addr + 2] |= 0xc0; | |
662 | else | |
663 | contents[addr + 2] |= 0x80; | |
664 | rstat = bfd_reloc_ok; | |
665 | break; | |
666 | } | |
667 | ||
668 | switch (rstat) | |
669 | { | |
670 | default: | |
671 | abort (); | |
672 | case bfd_reloc_ok: | |
673 | break; | |
674 | case bfd_reloc_outofrange: | |
675 | (*_bfd_error_handler) | |
676 | ("%s: bad reloc address 0x%lx in section `%s'", | |
677 | bfd_get_filename (input_bfd), | |
678 | (unsigned long) rel->r_vaddr, | |
679 | bfd_get_section_name (input_bfd, input_section)); | |
680 | return false; | |
681 | case bfd_reloc_overflow: | |
682 | { | |
683 | const char *name; | |
684 | char buf[SYMNMLEN + 1]; | |
685 | ||
686 | if (symndx == -1) | |
687 | name = "*ABS*"; | |
688 | else if (h != NULL) | |
689 | name = h->root.root.string; | |
690 | else | |
691 | { | |
692 | name = _bfd_coff_internal_syment_name (input_bfd, sym, buf); | |
693 | if (name == NULL) | |
694 | return false; | |
695 | } | |
696 | ||
697 | if (! ((*info->callbacks->reloc_overflow) | |
698 | (info, name, howto->name, (bfd_vma) 0, input_bfd, | |
699 | input_section, rel->r_vaddr - input_section->vma))) | |
700 | return false; | |
701 | } | |
702 | } | |
703 | } | |
704 | return true; | |
705 | } | |
706 | \f | |
5a608f5b FF |
707 | #define TIC80 1 /* Customize coffcode.h */ |
708 | #include "coffcode.h" | |
709 | ||
710 | const bfd_target | |
5a608f5b | 711 | tic80coff_vec = |
5a608f5b | 712 | { |
5a608f5b | 713 | "coff-tic80", /* name */ |
5a608f5b | 714 | bfd_target_coff_flavour, |
0716c2e9 FF |
715 | BFD_ENDIAN_LITTLE, /* data byte order is little (arch supports both) */ |
716 | BFD_ENDIAN_LITTLE, /* header byte order is little */ | |
5a608f5b FF |
717 | |
718 | (HAS_RELOC | EXEC_P | /* object flags */ | |
719 | HAS_LINENO | HAS_DEBUG | | |
720 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
721 | ||
722 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
d667d8f2 | 723 | '_', /* leading underscore */ |
5a608f5b FF |
724 | '/', /* ar_pad_char */ |
725 | 15, /* ar_max_namelen */ | |
4507d858 FF |
726 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
727 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
728 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ | |
0716c2e9 FF |
729 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
730 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
731 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ | |
5a608f5b FF |
732 | |
733 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ | |
734 | bfd_generic_archive_p, _bfd_dummy_target}, | |
735 | {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ | |
736 | bfd_false}, | |
737 | {bfd_false, coff_write_object_contents, /* bfd_write_contents */ | |
738 | _bfd_write_archive_contents, bfd_false}, | |
739 | ||
740 | BFD_JUMP_TABLE_GENERIC (coff), | |
741 | BFD_JUMP_TABLE_COPY (coff), | |
742 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
743 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
744 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
745 | BFD_JUMP_TABLE_RELOCS (coff), | |
746 | BFD_JUMP_TABLE_WRITE (coff), | |
747 | BFD_JUMP_TABLE_LINK (coff), | |
748 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
749 | ||
750 | COFF_SWAP_TABLE | |
751 | }; |