This is the mail archive of the gas2@sourceware.cygnus.com mailing list for the gas2 project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Here's an updated version of the patch I sent a few days ago; it fixes the file size kludge and a few other minor problems. This patch is based on yesterday's snapshot. Also, I included ChangeLog entries this time. (Sorry I missed that before.) Please try to get this in ASAP; Mach now depends on it. Thanks! Bryan diff -ur gas-950226/bfd/ChangeLog gas-950226-new/bfd/ChangeLog --- gas-950226/bfd/ChangeLog Sun Feb 26 08:16:25 1995 +++ gas-950226-new/bfd/ChangeLog Mon Feb 27 13:12:23 1995 @@ -1,3 +1,18 @@ +Mon Feb 27 08:36:39 1995 Bryan Ford <baford@cs.utah.edu> + + * binary.c: Add support for reading binary files. + Loads the raw contents of the file into a data section + and wraps some symbols around it. '_binary_<filename>_start' + and '_binary_<filename>_end' indicate the start and end + of the data, while '_binary_<filename>_size' is an + absolute symbol whose value is the size of the data. + <filename> is the name of the binary input file, + with all non-alphanumeric characters converted to underscores. + + * archures.c: When checking for architecture compatibility, + assume the user knows what he's doing if one of the architectures + is 'unknown', instead of producing a bogus error. + Wed Feb 22 14:40:26 1995 Ian Lance Taylor <ian@cygnus.com> * libaout.h (NAME(aout,slurp_reloc_table)): Change declaration to diff -ur gas-950226/bfd/archures.c gas-950226-new/bfd/archures.c --- gas-950226/bfd/archures.c Sun Feb 26 08:16:26 1995 +++ gas-950226-new/bfd/archures.c Mon Feb 27 09:20:18 1995 @@ -238,6 +238,14 @@ CONST bfd *abfd; CONST bfd *bbfd; { + /* If either architecture is unknown, + then all we can do is assume the user knows what he's doing. */ + if (abfd->arch_info->arch == bfd_arch_unknown) + return bbfd->arch_info; + if (bbfd->arch_info->arch == bfd_arch_unknown) + return abfd->arch_info; + + /* Otherwise architecture-specific code has to decide. */ return abfd->arch_info->compatible(abfd->arch_info,bbfd->arch_info); } diff -ur gas-950226/bfd/binary.c gas-950226-new/bfd/binary.c --- gas-950226/bfd/binary.c Wed Oct 19 12:08:55 1994 +++ gas-950226-new/bfd/binary.c Mon Feb 27 08:40:42 1995 @@ -31,10 +31,16 @@ the file. objcopy cooperates by specially setting the start address to zero by default. */ +#include <ctype.h> + #include "bfd.h" #include "sysdep.h" #include "libbfd.h" +/* Any bfd we create by reading a binary file has three symbols: + a start symbol, an end symbol, and an absolute length symbol. */ +#define BIN_SYMS 3 + static boolean binary_mkobject PARAMS ((bfd *)); static asymbol *binary_make_empty_symbol PARAMS ((bfd *)); static boolean binary_set_section_contents @@ -50,15 +56,29 @@ } /* Most of the symbol routines can just return an error. */ -#define binary_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound -#define binary_get_symtab _bfd_nosymbols_get_symtab +#define binary_close_and_cleanup _bfd_generic_close_and_cleanup +#define binary_bfd_free_cached_info _bfd_generic_bfd_free_cached_info +#define binary_new_section_hook _bfd_generic_new_section_hook + #define binary_print_symbol _bfd_nosymbols_print_symbol -#define binary_get_symbol_info _bfd_nosymbols_get_symbol_info -#define binary_bfd_is_local_label _bfd_nosymbols_bfd_is_local_label +#define binary_bfd_is_local_label bfd_generic_is_local_label #define binary_get_lineno _bfd_nosymbols_get_lineno #define binary_find_nearest_line _bfd_nosymbols_find_nearest_line #define binary_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol +#define binary_get_reloc_upper_bound \ + ((long (*) PARAMS ((bfd *, asection *))) bfd_0l) +#define binary_canonicalize_reloc \ + ((long (*) PARAMS ((bfd *, asection *, arelent **, asymbol **))) bfd_0l) +#define binary_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup + +#define binary_bfd_get_relocated_section_contents \ + bfd_generic_get_relocated_section_contents +#define binary_bfd_relax_section bfd_generic_relax_section +#define binary_bfd_link_hash_table_create _bfd_generic_link_hash_table_create +#define binary_bfd_link_add_symbols _bfd_generic_link_add_symbols +#define binary_bfd_final_link _bfd_generic_final_link + /* We do have to provide a routine to make an empty symbol. */ static asymbol * @@ -108,6 +128,164 @@ return _bfd_generic_set_section_contents (abfd, sec, data, offset, size); } +/* Check whether an existing file is a binary file. + Pretty easy - _every_ file is as far as we're concerned. :-) + However, only "recognize" the file + if the input target was explicitly set to "binary", + not if we're doing an automatic target search. */ + +static const bfd_target * +binary_object_p (abfd) + bfd *abfd; +{ + struct stat statbuf; + + if (abfd->target_defaulted) + return NULL; + + abfd->symcount = BIN_SYMS; + + /* Find the file size. */ + if (bfd_stat (abfd, &statbuf) < 0) + return NULL; + + /* One data section. */ + { + asection *sec; + char *secname; + + secname = (char *) bfd_alloc (abfd, strlen (".data") + 1); + strcpy (secname, ".data"); + sec = bfd_make_section (abfd, secname); + if (sec == NULL) + return NULL; + sec->flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS; + sec->vma = 0; + sec->_raw_size = statbuf.st_size; + sec->filepos = 0; + + abfd->tdata.any = (PTR)sec; + } + + return abfd->xvec; +} + +/* Get the contents of "the" section. */ + +static boolean +binary_get_section_contents (abfd, section, location, offset, count) + bfd *abfd; + asection *section; + PTR location; + file_ptr offset; + bfd_size_type count; +{ + if ((bfd_seek (abfd, offset, SEEK_SET) != 0) + || (bfd_read (location, 1, count, abfd) != count)) + return false; + return true; +} + +/* Return the amount of memory needed to read the symbol table. */ + +static long +binary_get_symtab_upper_bound (abfd) + bfd *abfd; +{ + return (BIN_SYMS + 1) * sizeof (asymbol *); +} + +void +binary_get_symbol_info (ignore_abfd, symbol, ret) + bfd *ignore_abfd; + asymbol *symbol; + symbol_info *ret; +{ + bfd_symbol_info (symbol, ret); +} + +/* Create a symbol name based on the bfd's filename. */ +static char *mangle_name(abfd, suffix) + bfd *abfd; + char *suffix; +{ + int size = strlen(bfd_get_filename(abfd)) + strlen(suffix) + 10; + char *buf = (char*) bfd_alloc (abfd, size); + char *p; + + if (buf == NULL) + { + bfd_set_error (bfd_error_no_memory); + return false; + } + + sprintf(buf, "_binary_%s_%s", bfd_get_filename(abfd), suffix); + + /* Change any non-alphanumeric characters to underscores. */ + for (p = buf; *p; p++) + if (!isalnum(*p)) + *p = '_'; + + return buf; +} + +/* Return the symbol table. */ + +static long +binary_get_symtab (abfd, alocation) + bfd *abfd; + asymbol **alocation; +{ + asection *sec = (asection*)abfd->tdata.any; + asymbol *syms; + unsigned int i; + + syms = (asymbol *) bfd_alloc (abfd, BIN_SYMS * sizeof (asymbol)); + if (syms == NULL) + { + bfd_set_error (bfd_error_no_memory); + return false; + } + + /* Start symbol. */ + syms[0].the_bfd = abfd; + syms[0].name = mangle_name(abfd, "start"); + syms[0].value = 0; + syms[0].flags = BSF_GLOBAL; + syms[0].section = sec; + syms[0].udata.p = NULL; + + /* End symbol. */ + syms[1].the_bfd = abfd; + syms[1].name = mangle_name(abfd, "end"); + syms[1].value = sec->_raw_size; + syms[1].flags = BSF_GLOBAL; + syms[1].section = sec; + syms[1].udata.p = NULL; + + /* End symbol. */ + syms[2].the_bfd = abfd; + syms[2].name = mangle_name(abfd, "size"); + syms[2].value = sec->_raw_size; + syms[2].flags = BSF_GLOBAL; + syms[2].section = bfd_abs_section_ptr; + syms[2].udata.p = NULL; + + for (i = 0; i < BIN_SYMS; i++) + *alocation++ = syms++; + *alocation = NULL; + + return BIN_SYMS; +} + +static int +binary_sizeof_headers (abfd, exec) + bfd *abfd; + boolean exec; +{ + return 0; +} + const bfd_target binary_vec = { "binary", /* name */ @@ -129,7 +307,7 @@ bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ { /* bfd_check_format */ _bfd_dummy_target, - _bfd_dummy_target, + binary_object_p, /* bfd_check_format */ _bfd_dummy_target, _bfd_dummy_target, }, @@ -146,14 +324,14 @@ bfd_false, }, - BFD_JUMP_TABLE_GENERIC (_bfd_generic), + BFD_JUMP_TABLE_GENERIC (binary), BFD_JUMP_TABLE_COPY (_bfd_generic), BFD_JUMP_TABLE_CORE (_bfd_nocore), BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive), BFD_JUMP_TABLE_SYMBOLS (binary), - BFD_JUMP_TABLE_RELOCS (_bfd_norelocs), + BFD_JUMP_TABLE_RELOCS (binary), BFD_JUMP_TABLE_WRITE (binary), - BFD_JUMP_TABLE_LINK (_bfd_nolink), + BFD_JUMP_TABLE_LINK (binary), BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), NULL diff -ur gas-950226/include/opcode/ChangeLog gas-950226-new/include/opcode/ChangeLog --- gas-950226/include/opcode/ChangeLog Sun Feb 26 08:20:21 1995 +++ gas-950226-new/include/opcode/ChangeLog Mon Feb 27 08:44:01 1995 @@ -1,3 +1,7 @@ +Mon Feb 27 08:36:39 1995 Bryan Ford <baford@cs.utah.edu> + + * i386.h: added missing Data16/Data32 flags to a few instructions. + Fri Feb 24 19:13:37 1995 Ian Lance Taylor <ian@cygnus.com> * mips.h (M_DLA_AB, M_DLI): Define. diff -ur gas-950226/include/opcode/i386.h gas-950226-new/include/opcode/i386.h --- gas-950226/include/opcode/i386.h Mon Feb 6 12:00:43 1995 +++ gas-950226-new/include/opcode/i386.h Mon Feb 27 08:32:07 1995 @@ -101,6 +101,8 @@ {"sahf", 0, 0x9e, _, NoModrm, { 0, 0, 0} }, {"pushf", 0, 0x9c, _, NoModrm|Data32, { 0, 0, 0} }, {"popf", 0, 0x9d, _, NoModrm|Data32, { 0, 0, 0} }, +{"pushfl", 0, 0x9c, _, NoModrm|Data32, { 0, 0, 0} }, +{"popfl", 0, 0x9d, _, NoModrm|Data32, { 0, 0, 0} }, {"pushfw", 0, 0x9c, _, NoModrm|Data16, { 0, 0, 0} }, {"popfw", 0, 0x9d, _, NoModrm|Data16, { 0, 0, 0} }, {"stc", 0, 0xf9, _, NoModrm, { 0, 0, 0} }, @@ -280,8 +282,10 @@ {"lret", 1, 0xca, _, NoModrm|Data32, { Imm16, 0, 0} }, {"lretw", 0, 0xcb, _, NoModrm|Data16, { 0, 0, 0} }, {"lretw", 1, 0xca, _, NoModrm|Data16, { Imm16, 0, 0} }, -{"enter", 2, 0xc8, _, NoModrm, { Imm16, Imm8, 0} }, -{"leave", 0, 0xc9, _, NoModrm, { 0, 0, 0} }, +{"enter", 2, 0xc8, _, NoModrm|Data32, { Imm16, Imm8, 0} }, +{"leave", 0, 0xc9, _, NoModrm|Data32, { 0, 0, 0} }, +{"enterw", 2, 0xc8, _, NoModrm|Data16, { Imm16, Imm8, 0} }, +{"leavew", 0, 0xc9, _, NoModrm|Data16, { 0, 0, 0} }, /* conditional jumps */ {"jo", 1, 0x70, _, Jump, { Disp, 0, 0} },