1 /* BFD back-end for VERSAdos-E objects.
3 Versados is a Motorola trademark.
5 Copyright 1995 Free Software Foundation, Inc.
6 Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 VERSAdos-E relocateable object file format
30 This module supports reading of VERSAdos relocateable
33 A VERSAdos file looks like contains
35 o Indentification Record
36 o External Symbol Definition Record
46 #include "libiberty.h"
49 static boolean versados_mkobject
PARAMS ((bfd
*));
50 static boolean versados_scan
PARAMS ((bfd
*));
51 static const bfd_target
*versados_object_p
PARAMS ((bfd
*));
60 #define ES_BASE 17 /* first symbol has esdid 17 */
62 /* Per file target dependent information */
64 /* one for each section */
67 asection
*section
; /* ptr to bfd version */
68 unsigned char *contents
; /* used to build image */
70 int relocs
; /* reloc count, valid end of pass 1 */
71 int donerel
; /* have relocs been translated */
74 typedef struct versados_data_struct
76 int es_done
; /* count of symbol index, starts at ES_BASE */
77 asymbol
*symbols
; /* pointer to local symbols */
78 char *strings
; /* strings of all the above */
79 int stringlen
; /* len of string table (valid end of pass1) */
80 int nsyms
; /* number of symbols (valid end of pass1) */
81 int nsecsyms
; /* number of sections */
85 struct esdid e
[16]; /* per section info */
86 int alert
; /* to see if we're trampling */
87 asymbol
*rest
[256 - 16]; /* per symbol info */
92 #define VDATA(abfd) (abfd->tdata.versados_data)
93 #define EDATA(abfd, n) (abfd->tdata.versados_data->e[n])
94 #define RDATA(abfd, n) (abfd->tdata.versados_data->rest[n])
102 unsigned char data
[200];
108 char type
; /* record type */
109 char name
[10]; /* module name */
110 char rev
; /* module rev number */
126 unsigned char esd_entries
[1];
129 #define EST_SHRT_REL_SEC 1
130 #define EST_STD_REL_SEC 2
131 #define ESD_XDEF_IN_SEC 4
132 #define ESD_XREF_SYM 7
136 struct ext_vheader header
;
141 /* Initialize by filling in the hex conversion array. */
147 /* Set up the tdata information. */
150 versados_mkobject (abfd
)
153 if (abfd
->tdata
.versados_data
== NULL
)
155 tdata_type
*tdata
= (tdata_type
*) bfd_alloc (abfd
, sizeof (tdata_type
));
158 bfd_set_error (bfd_error_no_memory
);
161 abfd
->tdata
.versados_data
= tdata
;
162 tdata
->symbols
= NULL
;
163 VDATA(abfd
)->alert
= 0x12345678;
166 bfd_default_set_arch_mach (abfd
, bfd_arch_m68k
, 0);
171 /* Report a problem in an S record file. FIXME: This probably should
172 not call fprintf, but we really do need some mechanism for printing
178 versados_new_symbol (abfd
, snum
, name
, val
, sec
)
185 asymbol
*n
= VDATA (abfd
)->symbols
+ snum
;
196 get_record (abfd
, ptr
)
200 bfd_read (&ptr
->size
, 1, 1, abfd
);
201 if (bfd_read ((char *) ptr
+ 1, 1, ptr
->size
, abfd
) != ptr
->size
)
210 unsigned char *p
= *pp
;
212 return (p
[0] << 24) | (p
[1] << 16) | (p
[2] << 8) | (p
[3] << 0);
220 char *p
= (char *) *pp
;
233 new_symbol_string (abfd
, name
)
237 char *n
= VDATA (abfd
)->strings
;
238 strcpy (VDATA (abfd
)->strings
, name
);
239 VDATA (abfd
)->strings
+= strlen (VDATA (abfd
)->strings
) + 1;
245 process_esd (abfd
, esd
, pass
)
250 /* Read through the ext def for the est entries */
251 int togo
= esd
->size
- 2;
256 unsigned char *ptr
= esd
->esd_entries
;
257 unsigned char *end
= ptr
+ togo
;
260 int scn
= *ptr
& 0xf;
261 int typ
= (*ptr
>> 4) & 0xf;
263 /* Declare this section */
264 sprintf (name
, "%d", scn
);
265 sec
= bfd_make_section_old_way (abfd
, strdup (name
));
266 sec
->target_index
= scn
;
267 EDATA (abfd
, scn
).section
= sec
;
276 int snum
= VDATA (abfd
)->nsyms
++;
280 VDATA (abfd
)->stringlen
+= strlen (name
) + 1;
286 char *n
= new_symbol_string (abfd
, name
);
287 s
= versados_new_symbol (abfd
, snum
, n
, 0,
288 &bfd_und_section
, scn
);
289 esidx
= VDATA (abfd
)->es_done
++;
290 RDATA (abfd
, esidx
- ES_BASE
) = s
;
296 start
= get_4 (&ptr
);
298 case EST_STD_REL_SEC
:
299 case EST_SHRT_REL_SEC
:
301 sec
->_raw_size
= get_4 (&ptr
);
302 sec
->flags
|= SEC_HAS_CONTENTS
| SEC_LOAD
| SEC_ALLOC
;
305 case ESD_XDEF_IN_SEC
:
307 int snum
= VDATA (abfd
)->nsyms
++;
313 /* Just remember the symbol */
314 VDATA (abfd
)->stringlen
+= strlen (name
) + 1;
319 char *n
= new_symbol_string (abfd
, name
);
320 s
= versados_new_symbol (abfd
, snum
, n
, val
, sec
, scn
);
321 s
->flags
|= BSF_GLOBAL
;
331 #define R_RELWORD_NEG 3
332 #define R_RELLONG_NEG 4
334 reloc_howto_type versados_howto_table
[] =
336 HOWTO (R_RELWORD
, 0, 1, 16, false,
337 0, complain_overflow_bitfield
, 0,
338 "+v16", true, 0x0000ffff, 0x0000ffff, false),
339 HOWTO (R_RELLONG
, 0, 2, 32, false,
340 0, complain_overflow_bitfield
, 0,
341 "+v32", true, 0xffffffff, 0xffffffff, false),
343 HOWTO (R_RELWORD_NEG
, 0, -1, 16, false,
344 0, complain_overflow_bitfield
, 0,
345 "-v16", true, 0x0000ffff, 0x0000ffff, false),
346 HOWTO (R_RELLONG_NEG
, 0, -2, 32, false,
347 0, complain_overflow_bitfield
, 0,
348 "-v32", true, 0xffffffff, 0xffffffff, false),
353 process_otr (abfd
, otr
, pass
)
360 unsigned char *srcp
= otr
->data
;
361 unsigned char *endp
= (unsigned char *) otr
+ otr
->size
;
362 unsigned int bits
= (otr
->map
[0] << 24)
363 | (otr
->map
[1] << 16)
365 | (otr
->map
[3] << 0);
367 unsigned char *contents
= EDATA (abfd
, otr
->esdid
- 1).contents
;
369 int dst_idx
= EDATA (abfd
, otr
->esdid
- 1).pc
;
370 for (shift
= (1 << 31); srcp
< endp
; shift
>>= 1)
375 int esdids
= (flag
>> 5) & 3;
376 int sizeinwords
= ((flag
>> 3) & 1) ? 2 : 1;
377 int offsetlen
= flag
& 7;
380 for (j
= 0; j
< esdids
; j
++)
383 /* don't process zero esdids */
386 int rn
= EDATA (abfd
, otr
->esdid
- 1).relocs
++;
389 /* this is the first pass over the data,
390 just remember that we need a reloc */
395 EDATA (abfd
, otr
->esdid
- 1).section
->relocation
+ rn
;
396 n
->address
= dst_idx
;
398 n
->sym_ptr_ptr
= (asymbol
**) esdid
;
401 = versados_howto_table
412 /* MSB is sign extended */
413 val
= srcp
[0] | ((srcp
[0] & 0x80) ? ~0xff : 0);
414 for (j
= 1; j
< offsetlen
; j
++)
424 /* Insert addend into stream */
429 contents
[dst_idx
++] = val
>> 24;
430 contents
[dst_idx
++] = val
>> 16;
433 contents
[dst_idx
++] = val
>> 8;
434 contents
[dst_idx
++] = val
>> 0;
443 /* absolute code, comes in 16 bit lumps */
444 contents
[dst_idx
] = srcp
[0];
445 contents
[dst_idx
+ 1] = srcp
[1];
451 EDATA (abfd
, otr
->esdid
- 1).pc
= dst_idx
;
466 if (!get_record (abfd
, &any
))
468 switch (any
.header
.type
)
476 process_esd (abfd
, &any
.esd
, 1);
479 process_otr (abfd
, &any
.otr
, 1);
484 /* Now allocate space for the relocs and sections */
486 for (i
= 0; i
< 16; i
++)
488 struct esdid
*esdid
= &EDATA (abfd
, i
);
491 esdid
->section
->relocation
492 = (arelent
*) bfd_alloc (abfd
, sizeof (arelent
) * esdid
->relocs
);
495 = (unsigned char *) bfd_alloc (abfd
, esdid
->section
->_raw_size
);
498 esdid
->section
->reloc_count
= esdid
->relocs
;
500 esdid
->section
->flags
|= SEC_RELOC
;
503 /* Add an entry into the symbol table for it */
505 VDATA (abfd
)->stringlen
+= strlen (esdid
->section
->name
) + 1;
508 VDATA (abfd
)->symbols
= (asymbol
*) bfd_alloc (abfd
,
509 sizeof (asymbol
) * abfd
->symcount
);
510 VDATA (abfd
)->strings
= bfd_alloc (abfd
, VDATA (abfd
)->stringlen
);
511 abfd
->symcount
= VDATA (abfd
)->nsyms
;
513 /* Actually fill in the section symbols */
515 for (j
= 0, i
= 0; i
< 16; i
++)
517 struct esdid
*esdid
= &EDATA (abfd
, i
);
518 asection
*sec
= esdid
->section
;
521 asymbol
*s
= VDATA (abfd
)->symbols
+ j
;
522 s
->name
= new_symbol_string (abfd
, sec
->name
);
524 s
->flags
= BSF_LOCAL
;
532 abfd
->flags
|= HAS_SYMS
;
533 VDATA (abfd
)->nsecsyms
= j
;
534 VDATA (abfd
)->nsyms
= j
;
540 /* Check whether an existing file is a versados file. */
542 static const bfd_target
*
543 versados_object_p (abfd
)
546 struct ext_vheader ext
;
549 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
))
553 bfd_read (&len
, 1, 1, abfd
);
554 if (bfd_read (&ext
.type
, 1, len
, abfd
) != len
557 bfd_set_error (bfd_error_wrong_format
);
561 /* ok, looks like a record, build the tdata and read
564 if (!versados_mkobject (abfd
)
565 || !versados_scan (abfd
))
573 versados_pass_2 (abfd
)
578 if (VDATA (abfd
)->pass_2_done
)
581 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
584 VDATA (abfd
)->es_done
= ES_BASE
;
586 /* read records till we get to where we want to be */
590 get_record (abfd
, &any
);
591 switch (any
.header
.type
)
594 VDATA (abfd
)->pass_2_done
= 1;
597 process_esd (abfd
, &any
.esd
, 2);
600 process_otr (abfd
, &any
.otr
, 2);
607 versados_get_section_contents (abfd
, section
, location
, offset
, count
)
614 if (!versados_pass_2 (abfd
))
618 EDATA (abfd
, section
->target_index
).contents
+ offset
,
625 versados_set_section_contents (abfd
, section
, location
, offset
, bytes_to_do
)
630 bfd_size_type bytes_to_do
;
638 versados_sizeof_headers (abfd
, exec
)
646 versados_make_empty_symbol (abfd
)
649 asymbol
*new = (asymbol
*) bfd_zalloc (abfd
, sizeof (asymbol
));
655 /* Return the amount of memory needed to read the symbol table. */
658 versados_get_symtab_upper_bound (abfd
)
661 return (bfd_get_symcount (abfd
) + 1) * sizeof (asymbol
*);
664 /* Return the symbol table. */
667 versados_get_symtab (abfd
, alocation
)
671 unsigned int symcount
= bfd_get_symcount (abfd
);
675 versados_pass_2 (abfd
);
677 for (i
= 0, s
= VDATA (abfd
)->symbols
;
691 versados_get_symbol_info (ignore_abfd
, symbol
, ret
)
696 bfd_symbol_info (symbol
, ret
);
701 versados_print_symbol (ignore_abfd
, afile
, symbol
, how
)
705 bfd_print_symbol_type how
;
707 FILE *file
= (FILE *) afile
;
710 case bfd_print_symbol_name
:
711 fprintf (file
, "%s", symbol
->name
);
714 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
715 fprintf (file
, " %-5s %s",
716 symbol
->section
->name
,
723 versados_get_reloc_upper_bound (abfd
, asect
)
727 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
732 versados_canonicalize_reloc (abfd
, section
, relptr
, symbols
)
741 versados_pass_2 (abfd
);
742 src
= section
->relocation
;
743 if (!EDATA (abfd
, section
->target_index
).donerel
)
745 EDATA (abfd
, section
->target_index
).donerel
= 1;
746 /* translate from indexes to symptr ptrs */
747 for (count
= 0; count
< section
->reloc_count
; count
++)
749 int esdid
= (int) src
[count
].sym_ptr_ptr
;
750 if (esdid
< ES_BASE
) /* Section relative thing */
752 src
[count
].sym_ptr_ptr
753 = EDATA (abfd
, esdid
- 1).section
->symbol_ptr_ptr
;
757 src
[count
].sym_ptr_ptr
758 = symbols
+ esdid
- 17 + VDATA (abfd
)->nsecsyms
;
764 for (count
= 0; count
< section
->reloc_count
; count
++)
769 return section
->reloc_count
;
772 #define versados_close_and_cleanup _bfd_generic_close_and_cleanup
773 #define versados_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
774 #define versados_new_section_hook _bfd_generic_new_section_hook
776 #define versados_bfd_is_local_label bfd_generic_is_local_label
777 #define versados_get_lineno _bfd_nosymbols_get_lineno
778 #define versados_find_nearest_line _bfd_nosymbols_find_nearest_line
779 #define versados_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
781 #define versados_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
783 #define versados_set_arch_mach bfd_default_set_arch_mach
785 #define versados_bfd_get_relocated_section_contents \
786 bfd_generic_get_relocated_section_contents
787 #define versados_bfd_relax_section bfd_generic_relax_section
788 #define versados_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
789 #define versados_bfd_link_add_symbols _bfd_generic_link_add_symbols
790 #define versados_bfd_final_link _bfd_generic_final_link
791 #define versados_bfd_link_split_section _bfd_generic_link_split_section
793 const bfd_target versados_vec
=
795 "versados", /* name */
796 bfd_target_versados_flavour
,
797 true, /* target byte order */
798 true, /* target headers byte order */
799 (HAS_RELOC
| EXEC_P
| /* object flags */
800 HAS_LINENO
| HAS_DEBUG
|
801 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
802 (SEC_CODE
| SEC_DATA
| SEC_ROM
| SEC_HAS_CONTENTS
803 | SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
804 0, /* leading underscore */
805 ' ', /* ar_pad_char */
806 16, /* ar_max_namelen */
807 1, /* minimum alignment */
808 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
809 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
810 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
811 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
812 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
813 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
817 versados_object_p
, /* bfd_check_format */
824 _bfd_generic_mkarchive
,
827 { /* bfd_write_contents */
830 _bfd_write_archive_contents
,
834 BFD_JUMP_TABLE_GENERIC (versados
),
835 BFD_JUMP_TABLE_COPY (_bfd_generic
),
836 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
837 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
838 BFD_JUMP_TABLE_SYMBOLS (versados
),
839 BFD_JUMP_TABLE_RELOCS (versados
),
840 BFD_JUMP_TABLE_WRITE (versados
),
841 BFD_JUMP_TABLE_LINK (versados
),
842 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),