]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for VERSAdos-E objects. |
24a35864 | 2 | Copyright 1995, 1996, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
252b5132 RH |
3 | Written by Steve Chamberlain of Cygnus Support <[email protected]>. |
4 | ||
5 | Versados is a Motorola trademark. | |
6 | ||
7 | This file is part of BFD, the Binary File Descriptor library. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program; if not, write to the Free Software | |
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
22 | ||
23 | /* | |
24 | SUBSECTION | |
25 | VERSAdos-E relocateable object file format | |
26 | ||
27 | DESCRIPTION | |
28 | ||
29 | This module supports reading of VERSAdos relocateable | |
30 | object files. | |
31 | ||
32 | A VERSAdos file looks like contains | |
33 | ||
34 | o Indentification Record | |
35 | o External Symbol Definition Record | |
36 | o Object Text Recrod | |
37 | o End Record | |
38 | ||
252b5132 RH |
39 | */ |
40 | ||
41 | #include "bfd.h" | |
42 | #include "sysdep.h" | |
43 | #include "libbfd.h" | |
44 | #include "libiberty.h" | |
45 | ||
252b5132 RH |
46 | static boolean versados_mkobject PARAMS ((bfd *)); |
47 | static boolean versados_scan PARAMS ((bfd *)); | |
48 | static const bfd_target *versados_object_p PARAMS ((bfd *)); | |
24a35864 | 49 | static asymbol *versados_new_symbol PARAMS ((bfd *, int, const char *, bfd_vma, asection *)); |
dc810e39 | 50 | static char *new_symbol_string PARAMS ((bfd *, const char *)); |
24a35864 AJ |
51 | static const bfd_target *versados_object_p PARAMS ((bfd *)); |
52 | static boolean versados_pass_2 PARAMS ((bfd *)); | |
53 | static boolean versados_get_section_contents | |
54 | PARAMS ((bfd *, asection *, void *, file_ptr, bfd_size_type)); | |
55 | static boolean versados_set_section_contents | |
56 | PARAMS ((bfd *, sec_ptr, void *, file_ptr, bfd_size_type)); | |
57 | static int versados_sizeof_headers PARAMS ((bfd *, boolean)); | |
58 | static asymbol *versados_make_empty_symbol PARAMS ((bfd *)); | |
59 | static long int versados_get_symtab_upper_bound PARAMS ((bfd *)); | |
60 | static long int versados_get_symtab PARAMS ((bfd *, asymbol **)); | |
dc810e39 AM |
61 | static void versados_get_symbol_info |
62 | PARAMS ((bfd *, asymbol *, symbol_info *)); | |
63 | static void versados_print_symbol | |
64 | PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type)); | |
65 | static long versados_get_reloc_upper_bound | |
66 | PARAMS ((bfd *, sec_ptr)); | |
67 | static long versados_canonicalize_reloc | |
68 | PARAMS ((bfd *, sec_ptr, arelent **, asymbol **)); | |
252b5132 | 69 | |
252b5132 RH |
70 | #define VHEADER '1' |
71 | #define VESTDEF '2' | |
72 | #define VOTR '3' | |
73 | #define VEND '4' | |
74 | ||
252b5132 RH |
75 | #define ES_BASE 17 /* first symbol has esdid 17 */ |
76 | ||
77 | /* Per file target dependent information */ | |
78 | ||
79 | /* one for each section */ | |
80 | struct esdid | |
81 | { | |
82 | asection *section; /* ptr to bfd version */ | |
83 | unsigned char *contents; /* used to build image */ | |
84 | int pc; | |
85 | int relocs; /* reloc count, valid end of pass 1 */ | |
86 | int donerel; /* have relocs been translated */ | |
87 | }; | |
88 | ||
89 | typedef struct versados_data_struct | |
90 | { | |
91 | int es_done; /* count of symbol index, starts at ES_BASE */ | |
92 | asymbol *symbols; /* pointer to local symbols */ | |
93 | char *strings; /* strings of all the above */ | |
94 | int stringlen; /* len of string table (valid end of pass1) */ | |
95 | int nsecsyms; /* number of sections */ | |
96 | ||
97 | int ndefs; /* number of exported symbols (they dont get esdids) */ | |
98 | int nrefs; /* number of imported symbols (valid end of pass1) */ | |
99 | ||
100 | int ref_idx; /* current processed value of the above */ | |
101 | int def_idx; | |
102 | ||
103 | int pass_2_done; | |
104 | ||
105 | struct esdid e[16]; /* per section info */ | |
106 | int alert; /* to see if we're trampling */ | |
107 | asymbol *rest[256 - 16]; /* per symbol info */ | |
108 | ||
109 | } | |
110 | tdata_type; | |
111 | ||
112 | #define VDATA(abfd) (abfd->tdata.versados_data) | |
113 | #define EDATA(abfd, n) (abfd->tdata.versados_data->e[n]) | |
114 | #define RDATA(abfd, n) (abfd->tdata.versados_data->rest[n]) | |
115 | ||
116 | struct ext_otr | |
117 | { | |
118 | unsigned char size; | |
119 | char type; | |
120 | unsigned char map[4]; | |
121 | unsigned char esdid; | |
122 | unsigned char data[200]; | |
123 | }; | |
124 | ||
125 | struct ext_vheader | |
126 | { | |
127 | unsigned char size; | |
128 | char type; /* record type */ | |
129 | char name[10]; /* module name */ | |
130 | char rev; /* module rev number */ | |
131 | char lang; | |
132 | char vol[4]; | |
133 | char user[2]; | |
134 | char cat[8]; | |
135 | char fname[8]; | |
136 | char ext[2]; | |
137 | char time[3]; | |
138 | char date[3]; | |
139 | char rest[211]; | |
140 | }; | |
141 | ||
142 | struct ext_esd | |
143 | { | |
144 | unsigned char size; | |
145 | char type; | |
146 | unsigned char esd_entries[1]; | |
147 | }; | |
148 | #define ESD_ABS 0 | |
149 | #define ESD_COMMON 1 | |
150 | #define ESD_STD_REL_SEC 2 | |
151 | #define ESD_SHRT_REL_SEC 3 | |
152 | #define ESD_XDEF_IN_SEC 4 | |
153 | #define ESD_XREF_SYM 7 | |
154 | #define ESD_XREF_SEC 6 | |
155 | #define ESD_XDEF_IN_ABS 5 | |
156 | union ext_any | |
157 | { | |
158 | unsigned char size; | |
159 | struct ext_vheader header; | |
160 | struct ext_esd esd; | |
161 | struct ext_otr otr; | |
162 | }; | |
163 | ||
24a35864 AJ |
164 | static int get_record PARAMS ((bfd *, union ext_any *)); |
165 | static int get_4 PARAMS ((unsigned char **)); | |
166 | static void get_10 PARAMS ((unsigned char **, char *)); | |
167 | static void process_esd PARAMS ((bfd *, struct ext_esd *, int)); | |
168 | static int get_offset PARAMS ((int, unsigned char *)); | |
169 | static void process_otr PARAMS ((bfd *, struct ext_otr *, int)); | |
170 | ||
558e161f | 171 | /* Initialize by filling in the hex conversion array. */ |
252b5132 RH |
172 | |
173 | /* Set up the tdata information. */ | |
174 | ||
175 | static boolean | |
176 | versados_mkobject (abfd) | |
177 | bfd *abfd; | |
178 | { | |
179 | if (abfd->tdata.versados_data == NULL) | |
180 | { | |
dc810e39 AM |
181 | bfd_size_type amt = sizeof (tdata_type); |
182 | tdata_type *tdata = (tdata_type *) bfd_alloc (abfd, amt); | |
252b5132 RH |
183 | if (tdata == NULL) |
184 | return false; | |
185 | abfd->tdata.versados_data = tdata; | |
186 | tdata->symbols = NULL; | |
187 | VDATA (abfd)->alert = 0x12345678; | |
188 | } | |
189 | ||
190 | bfd_default_set_arch_mach (abfd, bfd_arch_m68k, 0); | |
191 | return true; | |
192 | } | |
193 | ||
252b5132 RH |
194 | /* Report a problem in an S record file. FIXME: This probably should |
195 | not call fprintf, but we really do need some mechanism for printing | |
196 | error messages. */ | |
197 | ||
252b5132 RH |
198 | static asymbol * |
199 | versados_new_symbol (abfd, snum, name, val, sec) | |
200 | bfd *abfd; | |
201 | int snum; | |
202 | const char *name; | |
203 | bfd_vma val; | |
204 | asection *sec; | |
205 | { | |
206 | asymbol *n = VDATA (abfd)->symbols + snum; | |
207 | n->name = name; | |
208 | n->value = val; | |
209 | n->section = sec; | |
210 | n->the_bfd = abfd; | |
211 | n->flags = 0; | |
212 | return n; | |
213 | } | |
214 | ||
252b5132 RH |
215 | static int |
216 | get_record (abfd, ptr) | |
217 | bfd *abfd; | |
218 | union ext_any *ptr; | |
219 | { | |
dc810e39 AM |
220 | if (bfd_bread (&ptr->size, (bfd_size_type) 1, abfd) != 1 |
221 | || (bfd_bread ((char *) ptr + 1, (bfd_size_type) ptr->size, abfd) | |
222 | != ptr->size)) | |
252b5132 RH |
223 | return 0; |
224 | return 1; | |
225 | } | |
226 | ||
24a35864 | 227 | static int |
252b5132 RH |
228 | get_4 (pp) |
229 | unsigned char **pp; | |
230 | { | |
231 | unsigned char *p = *pp; | |
232 | *pp += 4; | |
233 | return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3] << 0); | |
234 | } | |
235 | ||
24a35864 | 236 | static void |
252b5132 RH |
237 | get_10 (pp, name) |
238 | unsigned char **pp; | |
239 | char *name; | |
240 | { | |
241 | char *p = (char *) *pp; | |
242 | int len = 10; | |
243 | *pp += len; | |
244 | while (*p != ' ' | |
245 | && len) | |
246 | { | |
247 | *name++ = *p++; | |
248 | len--; | |
249 | } | |
250 | *name = 0; | |
251 | } | |
252 | ||
253 | static char * | |
254 | new_symbol_string (abfd, name) | |
255 | bfd *abfd; | |
dc810e39 | 256 | const char *name; |
252b5132 RH |
257 | { |
258 | char *n = VDATA (abfd)->strings; | |
259 | strcpy (VDATA (abfd)->strings, name); | |
260 | VDATA (abfd)->strings += strlen (VDATA (abfd)->strings) + 1; | |
261 | return n; | |
262 | } | |
263 | ||
252b5132 RH |
264 | static void |
265 | process_esd (abfd, esd, pass) | |
266 | bfd *abfd; | |
267 | struct ext_esd *esd; | |
268 | int pass; | |
269 | { | |
270 | /* Read through the ext def for the est entries */ | |
271 | int togo = esd->size - 2; | |
272 | bfd_vma size; | |
273 | bfd_vma start; | |
274 | asection *sec; | |
275 | char name[11]; | |
276 | unsigned char *ptr = esd->esd_entries; | |
277 | unsigned char *end = ptr + togo; | |
278 | while (ptr < end) | |
279 | { | |
280 | int scn = *ptr & 0xf; | |
281 | int typ = (*ptr >> 4) & 0xf; | |
282 | ||
283 | /* Declare this section */ | |
284 | sprintf (name, "%d", scn); | |
285 | sec = bfd_make_section_old_way (abfd, strdup (name)); | |
286 | sec->target_index = scn; | |
287 | EDATA (abfd, scn).section = sec; | |
288 | ptr++; | |
289 | switch (typ) | |
290 | { | |
291 | default: | |
292 | abort (); | |
293 | case ESD_XREF_SEC: | |
294 | case ESD_XREF_SYM: | |
295 | { | |
296 | int snum = VDATA (abfd)->ref_idx++; | |
297 | get_10 (&ptr, name); | |
298 | if (pass == 1) | |
299 | { | |
300 | VDATA (abfd)->stringlen += strlen (name) + 1; | |
301 | } | |
302 | else | |
303 | { | |
304 | int esidx; | |
305 | asymbol *s; | |
306 | char *n = new_symbol_string (abfd, name); | |
dc810e39 AM |
307 | s = versados_new_symbol (abfd, snum, n, (bfd_vma) 0, |
308 | bfd_und_section_ptr); | |
252b5132 RH |
309 | esidx = VDATA (abfd)->es_done++; |
310 | RDATA (abfd, esidx - ES_BASE) = s; | |
311 | } | |
312 | } | |
313 | break; | |
314 | ||
252b5132 RH |
315 | case ESD_ABS: |
316 | size = get_4 (&ptr); | |
317 | start = get_4 (&ptr); | |
318 | break; | |
319 | case ESD_STD_REL_SEC: | |
320 | case ESD_SHRT_REL_SEC: | |
321 | { | |
322 | sec->_raw_size = get_4 (&ptr); | |
323 | sec->flags |= SEC_ALLOC; | |
324 | } | |
325 | break; | |
326 | case ESD_XDEF_IN_ABS: | |
327 | sec = (asection *) & bfd_abs_section; | |
328 | case ESD_XDEF_IN_SEC: | |
329 | { | |
330 | int snum = VDATA (abfd)->def_idx++; | |
dc810e39 | 331 | bfd_vma val; |
252b5132 RH |
332 | get_10 (&ptr, name); |
333 | val = get_4 (&ptr); | |
334 | if (pass == 1) | |
335 | { | |
336 | /* Just remember the symbol */ | |
337 | VDATA (abfd)->stringlen += strlen (name) + 1; | |
338 | } | |
339 | else | |
340 | { | |
341 | asymbol *s; | |
342 | char *n = new_symbol_string (abfd, name); | |
dc810e39 AM |
343 | s = versados_new_symbol (abfd, snum + VDATA (abfd)->nrefs, n, |
344 | val, sec); | |
252b5132 RH |
345 | s->flags |= BSF_GLOBAL; |
346 | } | |
347 | } | |
348 | break; | |
349 | } | |
350 | } | |
351 | } | |
352 | ||
353 | #define R_RELWORD 1 | |
354 | #define R_RELLONG 2 | |
355 | #define R_RELWORD_NEG 3 | |
356 | #define R_RELLONG_NEG 4 | |
357 | ||
358 | reloc_howto_type versados_howto_table[] = | |
359 | { | |
360 | HOWTO (R_RELWORD, 0, 1, 16, false, | |
361 | 0, complain_overflow_dont, 0, | |
362 | "+v16", true, 0x0000ffff, 0x0000ffff, false), | |
363 | HOWTO (R_RELLONG, 0, 2, 32, false, | |
364 | 0, complain_overflow_dont, 0, | |
365 | "+v32", true, 0xffffffff, 0xffffffff, false), | |
366 | ||
367 | HOWTO (R_RELWORD_NEG, 0, -1, 16, false, | |
368 | 0, complain_overflow_dont, 0, | |
369 | "-v16", true, 0x0000ffff, 0x0000ffff, false), | |
370 | HOWTO (R_RELLONG_NEG, 0, -2, 32, false, | |
371 | 0, complain_overflow_dont, 0, | |
372 | "-v32", true, 0xffffffff, 0xffffffff, false), | |
373 | }; | |
374 | ||
252b5132 RH |
375 | static int |
376 | get_offset (len, ptr) | |
377 | int len; | |
378 | unsigned char *ptr; | |
379 | { | |
380 | int val = 0; | |
381 | if (len) | |
382 | { | |
383 | int i; | |
384 | val = *ptr++; | |
385 | if (val & 0x80) | |
386 | val |= ~0xff; | |
387 | for (i = 1; i < len; i++) | |
388 | val = (val << 8) | *ptr++; | |
389 | } | |
390 | ||
391 | return val; | |
392 | } | |
393 | ||
394 | static void | |
395 | process_otr (abfd, otr, pass) | |
396 | bfd *abfd; | |
397 | struct ext_otr *otr; | |
398 | int pass; | |
399 | { | |
400 | unsigned long shift; | |
401 | unsigned char *srcp = otr->data; | |
402 | unsigned char *endp = (unsigned char *) otr + otr->size; | |
403 | unsigned int bits = (otr->map[0] << 24) | |
404 | | (otr->map[1] << 16) | |
405 | | (otr->map[2] << 8) | |
406 | | (otr->map[3] << 0); | |
407 | ||
408 | struct esdid *esdid = &EDATA (abfd, otr->esdid - 1); | |
409 | unsigned char *contents = esdid->contents; | |
410 | int need_contents = 0; | |
411 | unsigned int dst_idx = esdid->pc; | |
412 | ||
dc810e39 | 413 | for (shift = ((unsigned long) 1 << 31); shift && srcp < endp; shift >>= 1) |
252b5132 RH |
414 | { |
415 | if (bits & shift) | |
416 | { | |
417 | int flag = *srcp++; | |
418 | int esdids = (flag >> 5) & 0x7; | |
419 | int sizeinwords = ((flag >> 3) & 1) ? 2 : 1; | |
420 | int offsetlen = flag & 0x7; | |
421 | int j; | |
422 | ||
252b5132 RH |
423 | if (esdids == 0) |
424 | { | |
425 | /* A zero esdid means the new pc is the offset given */ | |
426 | dst_idx += get_offset (offsetlen, srcp); | |
427 | srcp += offsetlen; | |
428 | } | |
429 | else | |
430 | { | |
431 | int val = get_offset (offsetlen, srcp + esdids); | |
432 | if (pass == 1) | |
433 | need_contents = 1; | |
434 | else | |
435 | for (j = 0; j < sizeinwords * 2; j++) | |
436 | { | |
437 | contents[dst_idx + (sizeinwords * 2) - j - 1] = val; | |
438 | val >>= 8; | |
439 | } | |
440 | ||
441 | for (j = 0; j < esdids; j++) | |
442 | { | |
443 | int esdid = *srcp++; | |
444 | ||
445 | if (esdid) | |
446 | { | |
447 | int rn = EDATA (abfd, otr->esdid - 1).relocs++; | |
448 | if (pass == 1) | |
449 | { | |
558e161f | 450 | /* this is the first pass over the data, |
252b5132 RH |
451 | just remember that we need a reloc */ |
452 | } | |
453 | else | |
454 | { | |
455 | arelent *n = | |
456 | EDATA (abfd, otr->esdid - 1).section->relocation + rn; | |
457 | n->address = dst_idx; | |
458 | ||
459 | n->sym_ptr_ptr = (asymbol **) esdid; | |
460 | n->addend = 0; | |
461 | n->howto = versados_howto_table + ((j & 1) * 2) + (sizeinwords - 1); | |
462 | } | |
463 | } | |
464 | } | |
465 | srcp += offsetlen; | |
466 | dst_idx += sizeinwords * 2; | |
467 | } | |
468 | } | |
469 | else | |
470 | { | |
471 | need_contents = 1; | |
472 | if (dst_idx < esdid->section->_raw_size) | |
473 | if (pass == 2) | |
474 | { | |
475 | /* absolute code, comes in 16 bit lumps */ | |
476 | contents[dst_idx] = srcp[0]; | |
477 | contents[dst_idx + 1] = srcp[1]; | |
478 | } | |
479 | dst_idx += 2; | |
480 | srcp += 2; | |
481 | } | |
482 | } | |
483 | EDATA (abfd, otr->esdid - 1).pc = dst_idx; | |
484 | ||
485 | if (!contents && need_contents) | |
dc810e39 AM |
486 | { |
487 | bfd_size_type size = esdid->section->_raw_size; | |
488 | esdid->contents = (unsigned char *) bfd_alloc (abfd, size); | |
489 | } | |
252b5132 RH |
490 | } |
491 | ||
492 | static boolean | |
493 | versados_scan (abfd) | |
494 | bfd *abfd; | |
495 | { | |
496 | int loop = 1; | |
497 | int i; | |
498 | int j; | |
499 | int nsecs = 0; | |
dc810e39 | 500 | bfd_size_type amt; |
252b5132 | 501 | |
bfde9f99 | 502 | VDATA (abfd)->stringlen = 0; |
252b5132 RH |
503 | VDATA (abfd)->nrefs = 0; |
504 | VDATA (abfd)->ndefs = 0; | |
505 | VDATA (abfd)->ref_idx = 0; | |
506 | VDATA (abfd)->def_idx = 0; | |
bfde9f99 | 507 | VDATA (abfd)->pass_2_done = 0; |
252b5132 RH |
508 | |
509 | while (loop) | |
510 | { | |
511 | union ext_any any; | |
512 | if (!get_record (abfd, &any)) | |
513 | return true; | |
514 | switch (any.header.type) | |
515 | { | |
516 | case VHEADER: | |
517 | break; | |
518 | case VEND: | |
519 | loop = 0; | |
520 | break; | |
521 | case VESTDEF: | |
522 | process_esd (abfd, &any.esd, 1); | |
523 | break; | |
524 | case VOTR: | |
525 | process_otr (abfd, &any.otr, 1); | |
526 | break; | |
527 | } | |
528 | } | |
529 | ||
530 | /* Now allocate space for the relocs and sections */ | |
531 | ||
532 | VDATA (abfd)->nrefs = VDATA (abfd)->ref_idx; | |
533 | VDATA (abfd)->ndefs = VDATA (abfd)->def_idx; | |
534 | VDATA (abfd)->ref_idx = 0; | |
535 | VDATA (abfd)->def_idx = 0; | |
536 | ||
537 | abfd->symcount = VDATA (abfd)->nrefs + VDATA (abfd)->ndefs; | |
538 | ||
539 | for (i = 0; i < 16; i++) | |
540 | { | |
541 | struct esdid *esdid = &EDATA (abfd, i); | |
542 | if (esdid->section) | |
543 | { | |
dc810e39 AM |
544 | amt = (bfd_size_type) esdid->relocs * sizeof (arelent); |
545 | esdid->section->relocation = (arelent *) bfd_alloc (abfd, amt); | |
252b5132 RH |
546 | |
547 | esdid->pc = 0; | |
548 | ||
549 | if (esdid->contents) | |
550 | esdid->section->flags |= SEC_HAS_CONTENTS | SEC_LOAD; | |
551 | ||
552 | esdid->section->reloc_count = esdid->relocs; | |
553 | if (esdid->relocs) | |
554 | esdid->section->flags |= SEC_RELOC; | |
555 | ||
556 | esdid->relocs = 0; | |
557 | ||
558 | /* Add an entry into the symbol table for it */ | |
559 | nsecs++; | |
560 | VDATA (abfd)->stringlen += strlen (esdid->section->name) + 1; | |
561 | } | |
562 | } | |
563 | ||
564 | abfd->symcount += nsecs; | |
565 | ||
dc810e39 AM |
566 | amt = abfd->symcount; |
567 | amt *= sizeof (asymbol); | |
568 | VDATA (abfd)->symbols = (asymbol *) bfd_alloc (abfd, amt); | |
252b5132 | 569 | |
dc810e39 AM |
570 | amt = VDATA (abfd)->stringlen; |
571 | VDATA (abfd)->strings = bfd_alloc (abfd, amt); | |
252b5132 RH |
572 | |
573 | if ((VDATA (abfd)->symbols == NULL && abfd->symcount > 0) | |
574 | || (VDATA (abfd)->strings == NULL && VDATA (abfd)->stringlen > 0)) | |
575 | return false; | |
576 | ||
577 | /* Actually fill in the section symbols, | |
578 | we stick them at the end of the table */ | |
579 | ||
580 | for (j = VDATA (abfd)->nrefs + VDATA (abfd)->ndefs, i = 0; i < 16; i++) | |
581 | { | |
582 | struct esdid *esdid = &EDATA (abfd, i); | |
583 | asection *sec = esdid->section; | |
584 | if (sec) | |
585 | { | |
586 | asymbol *s = VDATA (abfd)->symbols + j; | |
587 | s->name = new_symbol_string (abfd, sec->name); | |
588 | s->section = sec; | |
589 | s->flags = BSF_LOCAL; | |
590 | s->value = 0; | |
591 | s->the_bfd = abfd; | |
592 | j++; | |
593 | } | |
594 | } | |
595 | if (abfd->symcount) | |
596 | abfd->flags |= HAS_SYMS; | |
597 | ||
598 | /* Set this to nsecs - since we've already planted the section | |
599 | symbols */ | |
600 | VDATA (abfd)->nsecsyms = nsecs; | |
601 | ||
602 | VDATA (abfd)->ref_idx = 0; | |
603 | ||
604 | return 1; | |
605 | } | |
606 | ||
252b5132 RH |
607 | /* Check whether an existing file is a versados file. */ |
608 | ||
609 | static const bfd_target * | |
610 | versados_object_p (abfd) | |
611 | bfd *abfd; | |
612 | { | |
613 | struct ext_vheader ext; | |
614 | unsigned char len; | |
615 | ||
616 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) | |
617 | return NULL; | |
618 | ||
dc810e39 | 619 | if (bfd_bread (&len, (bfd_size_type) 1, abfd) != 1) |
252b5132 RH |
620 | { |
621 | if (bfd_get_error () != bfd_error_system_call) | |
622 | bfd_set_error (bfd_error_wrong_format); | |
623 | return NULL; | |
624 | } | |
625 | ||
dc810e39 | 626 | if (bfd_bread (&ext.type, (bfd_size_type) len, abfd) != len) |
252b5132 RH |
627 | { |
628 | if (bfd_get_error () != bfd_error_system_call) | |
629 | bfd_set_error (bfd_error_wrong_format); | |
630 | return NULL; | |
631 | } | |
632 | ||
633 | /* We guess that the language field will never be larger than 10. | |
634 | In sample files, it is always either 0 or 1. Checking for this | |
635 | prevents confusion with Intel Hex files. */ | |
636 | if (ext.type != VHEADER | |
637 | || ext.lang > 10) | |
638 | { | |
639 | bfd_set_error (bfd_error_wrong_format); | |
640 | return NULL; | |
641 | } | |
642 | ||
643 | /* OK, looks like a record, build the tdata and read in. */ | |
644 | ||
645 | if (!versados_mkobject (abfd) | |
646 | || !versados_scan (abfd)) | |
647 | return NULL; | |
648 | ||
649 | return abfd->xvec; | |
650 | } | |
651 | ||
252b5132 RH |
652 | static boolean |
653 | versados_pass_2 (abfd) | |
654 | bfd *abfd; | |
655 | { | |
656 | union ext_any any; | |
657 | ||
658 | if (VDATA (abfd)->pass_2_done) | |
659 | return 1; | |
660 | ||
dc810e39 | 661 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) |
252b5132 RH |
662 | return 0; |
663 | ||
664 | VDATA (abfd)->es_done = ES_BASE; | |
665 | ||
252b5132 RH |
666 | /* read records till we get to where we want to be */ |
667 | ||
668 | while (1) | |
669 | { | |
670 | get_record (abfd, &any); | |
671 | switch (any.header.type) | |
672 | { | |
673 | case VEND: | |
674 | VDATA (abfd)->pass_2_done = 1; | |
675 | return 1; | |
676 | case VESTDEF: | |
677 | process_esd (abfd, &any.esd, 2); | |
678 | break; | |
679 | case VOTR: | |
680 | process_otr (abfd, &any.otr, 2); | |
681 | break; | |
682 | } | |
683 | } | |
684 | } | |
685 | ||
686 | static boolean | |
687 | versados_get_section_contents (abfd, section, location, offset, count) | |
688 | bfd *abfd; | |
689 | asection *section; | |
690 | PTR location; | |
691 | file_ptr offset; | |
692 | bfd_size_type count; | |
693 | { | |
694 | if (!versados_pass_2 (abfd)) | |
695 | return false; | |
696 | ||
697 | memcpy (location, | |
698 | EDATA (abfd, section->target_index).contents + offset, | |
699 | (size_t) count); | |
700 | ||
701 | return true; | |
702 | } | |
703 | ||
704 | #define versados_get_section_contents_in_window \ | |
705 | _bfd_generic_get_section_contents_in_window | |
706 | ||
707 | static boolean | |
708 | versados_set_section_contents (abfd, section, location, offset, bytes_to_do) | |
5f771d47 ILT |
709 | bfd *abfd ATTRIBUTE_UNUSED; |
710 | sec_ptr section ATTRIBUTE_UNUSED; | |
711 | PTR location ATTRIBUTE_UNUSED; | |
712 | file_ptr offset ATTRIBUTE_UNUSED; | |
713 | bfd_size_type bytes_to_do ATTRIBUTE_UNUSED; | |
252b5132 RH |
714 | { |
715 | return false; | |
716 | } | |
717 | ||
252b5132 RH |
718 | static int |
719 | versados_sizeof_headers (abfd, exec) | |
5f771d47 ILT |
720 | bfd *abfd ATTRIBUTE_UNUSED; |
721 | boolean exec ATTRIBUTE_UNUSED; | |
252b5132 RH |
722 | { |
723 | return 0; | |
724 | } | |
725 | ||
726 | static asymbol * | |
727 | versados_make_empty_symbol (abfd) | |
728 | bfd *abfd; | |
729 | { | |
dc810e39 AM |
730 | asymbol *new; |
731 | ||
732 | new = (asymbol *) bfd_zalloc (abfd, (bfd_size_type) sizeof (asymbol)); | |
252b5132 RH |
733 | if (new) |
734 | new->the_bfd = abfd; | |
735 | return new; | |
736 | } | |
737 | ||
738 | /* Return the amount of memory needed to read the symbol table. */ | |
739 | ||
740 | static long | |
741 | versados_get_symtab_upper_bound (abfd) | |
742 | bfd *abfd; | |
743 | { | |
744 | return (bfd_get_symcount (abfd) + 1) * sizeof (asymbol *); | |
745 | } | |
746 | ||
747 | /* Return the symbol table. */ | |
748 | ||
749 | static long | |
750 | versados_get_symtab (abfd, alocation) | |
751 | bfd *abfd; | |
752 | asymbol **alocation; | |
753 | { | |
754 | unsigned int symcount = bfd_get_symcount (abfd); | |
755 | unsigned int i; | |
756 | asymbol *s; | |
757 | ||
758 | versados_pass_2 (abfd); | |
759 | ||
760 | for (i = 0, s = VDATA (abfd)->symbols; | |
761 | i < symcount; | |
762 | s++, i++) | |
763 | { | |
764 | *alocation++ = s; | |
765 | } | |
766 | ||
767 | *alocation = NULL; | |
768 | ||
769 | return symcount; | |
770 | } | |
771 | ||
dc810e39 | 772 | static void |
252b5132 | 773 | versados_get_symbol_info (ignore_abfd, symbol, ret) |
5f771d47 | 774 | bfd *ignore_abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
775 | asymbol *symbol; |
776 | symbol_info *ret; | |
777 | { | |
778 | bfd_symbol_info (symbol, ret); | |
779 | } | |
780 | ||
dc810e39 | 781 | static void |
60b89a18 L |
782 | versados_print_symbol (abfd, afile, symbol, how) |
783 | bfd *abfd; | |
252b5132 RH |
784 | PTR afile; |
785 | asymbol *symbol; | |
786 | bfd_print_symbol_type how; | |
787 | { | |
788 | FILE *file = (FILE *) afile; | |
789 | switch (how) | |
790 | { | |
791 | case bfd_print_symbol_name: | |
792 | fprintf (file, "%s", symbol->name); | |
793 | break; | |
794 | default: | |
60b89a18 | 795 | bfd_print_symbol_vandf (abfd, (PTR) file, symbol); |
252b5132 RH |
796 | fprintf (file, " %-5s %s", |
797 | symbol->section->name, | |
798 | symbol->name); | |
799 | ||
800 | } | |
801 | } | |
802 | ||
dc810e39 | 803 | static long |
252b5132 | 804 | versados_get_reloc_upper_bound (abfd, asect) |
5f771d47 | 805 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
806 | sec_ptr asect; |
807 | { | |
808 | return (asect->reloc_count + 1) * sizeof (arelent *); | |
809 | } | |
810 | ||
dc810e39 | 811 | static long |
252b5132 RH |
812 | versados_canonicalize_reloc (abfd, section, relptr, symbols) |
813 | bfd *abfd; | |
814 | sec_ptr section; | |
815 | arelent **relptr; | |
816 | asymbol **symbols; | |
817 | { | |
818 | unsigned int count; | |
819 | arelent *src; | |
820 | ||
821 | versados_pass_2 (abfd); | |
822 | src = section->relocation; | |
823 | if (!EDATA (abfd, section->target_index).donerel) | |
824 | { | |
825 | EDATA (abfd, section->target_index).donerel = 1; | |
826 | /* translate from indexes to symptr ptrs */ | |
827 | for (count = 0; count < section->reloc_count; count++) | |
828 | { | |
829 | int esdid = (int) src[count].sym_ptr_ptr; | |
830 | ||
831 | if (esdid == 0) | |
832 | { | |
833 | src[count].sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr; | |
834 | } | |
835 | else if (esdid < ES_BASE) /* Section relative thing */ | |
836 | { | |
837 | struct esdid *e = &EDATA (abfd, esdid - 1); | |
838 | if (!section) | |
839 | { | |
840 | /** relocation relative to section which was | |
841 | never declared ! */ | |
842 | } | |
843 | src[count].sym_ptr_ptr = e->section->symbol_ptr_ptr; | |
844 | } | |
845 | else | |
846 | { | |
847 | src[count].sym_ptr_ptr = symbols + esdid - ES_BASE; | |
848 | } | |
849 | ||
850 | } | |
851 | } | |
852 | ||
853 | for (count = 0; count < section->reloc_count; count++) | |
854 | { | |
855 | *relptr++ = src++; | |
856 | } | |
857 | *relptr = 0; | |
858 | return section->reloc_count; | |
859 | } | |
860 | ||
861 | #define versados_close_and_cleanup _bfd_generic_close_and_cleanup | |
862 | #define versados_bfd_free_cached_info _bfd_generic_bfd_free_cached_info | |
863 | #define versados_new_section_hook _bfd_generic_new_section_hook | |
864 | ||
865 | #define versados_bfd_is_local_label_name bfd_generic_is_local_label_name | |
866 | #define versados_get_lineno _bfd_nosymbols_get_lineno | |
867 | #define versados_find_nearest_line _bfd_nosymbols_find_nearest_line | |
868 | #define versados_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol | |
869 | #define versados_read_minisymbols _bfd_generic_read_minisymbols | |
870 | #define versados_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol | |
871 | ||
872 | #define versados_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup | |
873 | ||
874 | #define versados_set_arch_mach bfd_default_set_arch_mach | |
875 | ||
876 | #define versados_bfd_get_relocated_section_contents \ | |
877 | bfd_generic_get_relocated_section_contents | |
878 | #define versados_bfd_relax_section bfd_generic_relax_section | |
879 | #define versados_bfd_gc_sections bfd_generic_gc_sections | |
8550eb6e | 880 | #define versados_bfd_merge_sections bfd_generic_merge_sections |
252b5132 RH |
881 | #define versados_bfd_link_hash_table_create _bfd_generic_link_hash_table_create |
882 | #define versados_bfd_link_add_symbols _bfd_generic_link_add_symbols | |
883 | #define versados_bfd_final_link _bfd_generic_final_link | |
884 | #define versados_bfd_link_split_section _bfd_generic_link_split_section | |
885 | ||
886 | const bfd_target versados_vec = | |
887 | { | |
888 | "versados", /* name */ | |
889 | bfd_target_versados_flavour, | |
890 | BFD_ENDIAN_BIG, /* target byte order */ | |
891 | BFD_ENDIAN_BIG, /* target headers byte order */ | |
892 | (HAS_RELOC | EXEC_P | /* object flags */ | |
893 | HAS_LINENO | HAS_DEBUG | | |
894 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
895 | (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS | |
896 | | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
897 | 0, /* leading underscore */ | |
898 | ' ', /* ar_pad_char */ | |
899 | 16, /* ar_max_namelen */ | |
900 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, | |
901 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
902 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ | |
903 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, | |
904 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
905 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ | |
906 | ||
907 | { | |
908 | _bfd_dummy_target, | |
909 | versados_object_p, /* bfd_check_format */ | |
910 | _bfd_dummy_target, | |
911 | _bfd_dummy_target, | |
912 | }, | |
913 | { | |
914 | bfd_false, | |
915 | versados_mkobject, | |
916 | _bfd_generic_mkarchive, | |
917 | bfd_false, | |
918 | }, | |
919 | { /* bfd_write_contents */ | |
920 | bfd_false, | |
921 | bfd_false, | |
922 | _bfd_write_archive_contents, | |
923 | bfd_false, | |
924 | }, | |
925 | ||
926 | BFD_JUMP_TABLE_GENERIC (versados), | |
927 | BFD_JUMP_TABLE_COPY (_bfd_generic), | |
928 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
929 | BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), | |
930 | BFD_JUMP_TABLE_SYMBOLS (versados), | |
931 | BFD_JUMP_TABLE_RELOCS (versados), | |
932 | BFD_JUMP_TABLE_WRITE (versados), | |
933 | BFD_JUMP_TABLE_LINK (versados), | |
934 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
935 | ||
c3c89269 | 936 | NULL, |
558e161f | 937 | |
252b5132 RH |
938 | (PTR) 0 |
939 | }; |