aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorJohn Gilmore <gnu@cygnus>1991-10-11 10:45:56 +0000
committerJohn Gilmore <gnu@cygnus>1991-10-11 10:45:56 +0000
commit2c3f93e56d9df879f5decff21182c7b53ce085e3 (patch)
tree71dd75e146b55f93738f1b85ca8f6ca3af47138f /bfd
parent5b2765bf130e083b75c6e2e343ee99c40c93ca47 (diff)
downloadgdb-2c3f93e56d9df879f5decff21182c7b53ce085e3.zip
gdb-2c3f93e56d9df879f5decff21182c7b53ce085e3.tar.gz
gdb-2c3f93e56d9df879f5decff21182c7b53ce085e3.tar.bz2
Initial revision
Diffstat (limited to 'bfd')
-rw-r--r--bfd/aout-encap.c328
-rw-r--r--bfd/hosts/sparc-ll.h123
2 files changed, 451 insertions, 0 deletions
diff --git a/bfd/aout-encap.c b/bfd/aout-encap.c
new file mode 100644
index 0000000..dc6ba10
--- /dev/null
+++ b/bfd/aout-encap.c
@@ -0,0 +1,328 @@
+/* BFD back-end for a.out files encapsulated with COFF headers.
+ Copyright (C) 1990-1991 Free Software Foundation, Inc.
+
+This file is part of BFD, the Binary File Descriptor library.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* THIS MODULE IS NOT FINISHED. IT PROBABLY DOESN'T EVEN COMPILE. */
+
+#if 0
+#define PAGE_SIZE 4096
+#define SEGMENT_SIZE PAGE_SIZE
+#define TEXT_START_ADDR 0
+#define ARCH 32
+#define BYTES_IN_WORD 4
+#endif
+
+#include "bfd.h"
+#include <sysdep.h>
+#include "libbfd.h"
+#include "aout64.h"
+
+/**From: bothner@cs.wisc.edu***********************************************/
+#undef N_TXTOFF
+#define N_TXTOFF(x) ( (N_MAGIC((x)) == ZMAGIC) ? PAGE_SIZE : EXEC_BYTES_SIZE)
+/**************************************************************************/
+
+#include "stab.gnu.h"
+#include "ar.h"
+#include "libaout.h" /* BFD a.out internal data structures */
+
+bfd_target *encap_callback ();
+
+bfd_target *
+DEFUN(encap_object_p,(abfd),
+ bfd *abfd)
+{
+ unsigned char magicbuf[4]; /* Raw bytes of magic number from file */
+ unsigned long magic; /* Swapped magic number */
+ short coff_magic;
+ struct external_exec exec_bytes;
+ struct internal_exec exec;
+
+ bfd_error = system_call_error;
+
+ if (bfd_read ((PTR)magicbuf, 1, sizeof (magicbuf), abfd) !=
+ sizeof (magicbuf))
+ return 0;
+
+ coff_magic = bfd_h_get_16 (abfd, magicbuf);
+ if (coff_magic != COFF_MAGIC)
+ return 0; /* Not an encap coff file */
+
+ __header_offset_temp==COFF_MAGIC ? sizeof(struct coffheader) : 0)
+ (fseek ((f), HEADER_OFFSET((f)), 1))
+
+ magic = bfd_h_get_32 (abfd, magicbuf);
+
+ if (N_BADMAG (*((struct internal_exec *) &magic))) return 0;
+
+ struct external_exec exec_bytes;
+ if (bfd_read ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd)
+ != EXEC_BYTES_SIZE) {
+ bfd_error = wrong_format;
+ return 0;
+ }
+ NAME(aout,swap_exec_header_in)(abfd, &exec_bytes, &exec);
+
+ return aout_32_some_aout_object_p (abfd, &exec, encap_callback);
+}
+
+/* Finish up the reading of a encapsulated-coff a.out file header */
+bfd_target *
+DEFUN(encap_callback,(abfd),
+ bfd *abfd)
+{
+ struct internal_exec *execp = exec_hdr (abfd);
+
+ WORK_OUT_FILE_POSITIONS(abfd, execp) ;
+
+ /* If we have a coff header, it can give us better values for
+ text_start and exec_data_start. This is particularly useful
+ for remote debugging of embedded systems. */
+ if (N_FLAGS(exec_aouthdr) & N_FLAGS_COFF_ENCAPSULATE)
+ {
+ struct coffheader ch;
+ int val;
+ val = lseek (execchan, -(sizeof (AOUTHDR) + sizeof (ch)), 1);
+ if (val == -1)
+ perror_with_name (filename);
+ val = myread (execchan, &ch, sizeof (ch));
+ if (val < 0)
+ perror_with_name (filename);
+ text_start = ch.text_start;
+ exec_data_start = ch.data_start;
+ } else
+ {
+ text_start =
+ IS_OBJECT_FILE (exec_aouthdr) ? 0 : N_TXTADDR (exec_aouthdr);
+ exec_data_start = IS_OBJECT_FILE (exec_aouthdr)
+ ? exec_aouthdr.a_text : N_DATADDR (exec_aouthdr);
+ }
+
+ /* Determine the architecture and machine type of the object file. */
+ bfd_default_set_arch_mach(abfd, bfd_arch_m68k, 0); /* FIXME */
+
+ return abfd->xvec;
+}
+
+/* Write an object file in Encapsulated COFF format.
+ Section contents have already been written. We write the
+ file header, symbols, and relocation. */
+
+boolean
+DEFUN(encap_write_object_contents,(abfd),
+ bfd *abfd)
+{
+ bfd_size_type data_pad = 0;
+ struct external_exec exec_bytes;
+ struct internal_exec *execp = exec_hdr (abfd);
+
+/****** FIXME: Fragments from the old GNU LD program for dealing with
+ encap coff. */
+struct coffheader coffheader;
+int need_coff_header;
+
+ /* Determine whether to count the header as part of
+ the text size, and initialize the text size accordingly.
+ This depends on the kind of system and on the output format selected. */
+
+ N_SET_MAGIC (outheader, magic);
+#ifdef INITIALIZE_HEADER
+ INITIALIZE_HEADER;
+#endif
+
+ text_size = sizeof (struct exec);
+#ifdef COFF_ENCAPSULATE
+ if (relocatable_output == 0 && file_table[0].just_syms_flag == 0)
+ {
+ need_coff_header = 1;
+ /* set this flag now, since it will change the values of N_TXTOFF, etc */
+ N_SET_FLAGS (outheader, N_FLAGS_COFF_ENCAPSULATE);
+ text_size += sizeof (struct coffheader);
+ }
+#endif
+
+#ifdef COFF_ENCAPSULATE
+ if (need_coff_header)
+ {
+ /* We are encapsulating BSD format within COFF format. */
+ struct coffscn *tp, *dp, *bp;
+
+ tp = &coffheader.scns[0];
+ dp = &coffheader.scns[1];
+ bp = &coffheader.scns[2];
+
+ strcpy (tp->s_name, ".text");
+ tp->s_paddr = text_start;
+ tp->s_vaddr = text_start;
+ tp->s_size = text_size;
+ tp->s_scnptr = sizeof (struct coffheader) + sizeof (struct exec);
+ tp->s_relptr = 0;
+ tp->s_lnnoptr = 0;
+ tp->s_nreloc = 0;
+ tp->s_nlnno = 0;
+ tp->s_flags = 0x20;
+ strcpy (dp->s_name, ".data");
+ dp->s_paddr = data_start;
+ dp->s_vaddr = data_start;
+ dp->s_size = data_size;
+ dp->s_scnptr = tp->s_scnptr + tp->s_size;
+ dp->s_relptr = 0;
+ dp->s_lnnoptr = 0;
+ dp->s_nreloc = 0;
+ dp->s_nlnno = 0;
+ dp->s_flags = 0x40;
+ strcpy (bp->s_name, ".bss");
+ bp->s_paddr = dp->s_vaddr + dp->s_size;
+ bp->s_vaddr = bp->s_paddr;
+ bp->s_size = bss_size;
+ bp->s_scnptr = 0;
+ bp->s_relptr = 0;
+ bp->s_lnnoptr = 0;
+ bp->s_nreloc = 0;
+ bp->s_nlnno = 0;
+ bp->s_flags = 0x80;
+
+ coffheader.f_magic = COFF_MAGIC;
+ coffheader.f_nscns = 3;
+ /* store an unlikely time so programs can
+ * tell that there is a bsd header
+ */
+ coffheader.f_timdat = 1;
+ coffheader.f_symptr = 0;
+ coffheader.f_nsyms = 0;
+ coffheader.f_opthdr = 28;
+ coffheader.f_flags = 0x103;
+ /* aouthdr */
+ coffheader.magic = ZMAGIC;
+ coffheader.vstamp = 0;
+ coffheader.tsize = tp->s_size;
+ coffheader.dsize = dp->s_size;
+ coffheader.bsize = bp->s_size;
+ coffheader.entry = outheader.a_entry;
+ coffheader.text_start = tp->s_vaddr;
+ coffheader.data_start = dp->s_vaddr;
+ }
+#endif
+
+#ifdef COFF_ENCAPSULATE
+ if (need_coff_header)
+ mywrite (&coffheader, sizeof coffheader, 1, outdesc);
+#endif
+
+#ifndef COFF_ENCAPSULATE
+ padfile (N_TXTOFF (outheader) - sizeof outheader, outdesc);
+#endif
+
+ text_size -= N_TXTOFF (outheader);
+ WRITE_HEADERS(abfd, execp);
+ return true;
+}
+
+/* Transfer vectors for Encapsulated-(aout-in)-coff */
+
+/* We use BFD generic archive files. */
+#define newsos_openr_next_archived_file bfd_generic_openr_next_archived_file
+#define newsos_generic_stat_arch_elt bfd_generic_stat_arch_elt
+#define newsos_slurp_armap bfd_slurp_bsd_armap
+#define newsos_slurp_extended_name_table bfd_true
+#define newsos_write_armap bsd_write_armap
+#define newsos_truncate_arname bfd_bsd_truncate_arname
+
+/* We don't support core files yet. FIXME. */
+#define newsos_core_file_failing_command _bfd_dummy_core_file_failing_command
+#define newsos_core_file_failing_signal _bfd_dummy_core_file_failing_signal
+#define newsos_core_file_matches_executable_p \
+ _bfd_dummy_core_file_matches_executable_p
+#define newsos_core_file_p _bfd_dummy_target
+
+#define newsos_bfd_debug_info_start bfd_void
+#define newsos_bfd_debug_info_end bfd_void
+#define newsos_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
+
+#define newsos_mkobject aout_32_mkobject
+#define newsos_close_and_cleanup aout_32_close_and_cleanup
+#define newsos_set_section_contents aout_32_set_section_contents
+#define newsos_get_section_contents aout_32_get_section_contents
+#define newsos_new_section_hook aout_32_new_section_hook
+#define newsos_get_symtab_upper_bound aout_32_get_symtab_upper_bound
+#define newsos_get_symtab aout_32_get_symtab
+#define newsos_get_reloc_upper_bound aout_32_get_reloc_upper_bound
+#define newsos_canonicalize_reloc aout_32_canonicalize_reloc
+#define newsos_make_empty_symbol aout_32_make_empty_symbol
+#define newsos_print_symbol aout_32_print_symbol
+#define newsos_get_lineno aout_32_get_lineno
+#define newsos_set_arch_mach aout_32_set_arch_mach
+#define newsos_find_nearest_line aout_32_find_nearest_line
+#define newsos_sizeof_headers aout_32_sizeof_headers
+
+
+/* We define our own versions of these routines. */
+
+
+bfd_target encap_big_vec = /* "Encapsulated coff": a.out with COFF header prefix */
+{
+ "a.out-encap", /* name */
+ bfd_target_aout_flavour,
+ true, /* target byte order */
+ true, /* target headers byte order */
+ (HAS_RELOC | EXEC_P | /* object flags */
+ HAS_LINENO | HAS_DEBUG |
+ HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
+ (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
+ ' ', /* ar_pad_char */
+ 16, /* ar_max_namelen */
+ 1, /* minimum alignment */
+ _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
+ _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
+
+ {_bfd_dummy_target, newsos3_object_p, /* bfd_check_format */
+ bfd_generic_archive_p, newsos_core_file_p},
+ {bfd_false, newsos_mkobject, /* bfd_set_format */
+ _bfd_generic_mkarchive, bfd_false},
+ {bfd_false, newsos3_write_object_contents, /* bfd_write_contents */
+ _bfd_write_archive_contents, bfd_false},
+
+ JUMP_TABLE(newsos)
+};
+
+/* Little-endian "encapsulated coff": a.out with COFF header prefix */
+bfd_target encap_little_vec =
+{
+ "a.out-encap-little", /* name */
+ bfd_target_aout_flavour,
+ false, /* target byte order */
+ false, /* target headers byte order */
+ (HAS_RELOC | EXEC_P | /* object flags */
+ HAS_LINENO | HAS_DEBUG |
+ HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
+ (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
+ ' ', /* ar_pad_char */
+ 16, /* ar_max_namelen */
+ 1, /* minimum alignment */
+ _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
+ _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putb16, /* hdrs */
+
+ {_bfd_dummy_target, newsos3_object_p, /* bfd_check_format */
+ bfd_generic_archive_p, newsos_core_file_p},
+ {bfd_false, newsos_mkobject, /* bfd_set_format */
+ _bfd_generic_mkarchive, bfd_false},
+ {bfd_false, newsos3_write_object_contents, /* bfd_write_contents */
+ _bfd_write_archive_contents, bfd_false},
+
+ JUMP_TABLE(newsos)
+};
diff --git a/bfd/hosts/sparc-ll.h b/bfd/hosts/sparc-ll.h
new file mode 100644
index 0000000..50a2945
--- /dev/null
+++ b/bfd/hosts/sparc-ll.h
@@ -0,0 +1,123 @@
+/* Host definition file for Sun-4 running with gcc, using "long long"
+ for addresses, to handle 64-bit target systems. */
+
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ctype.h>
+#include <string.h>
+#include <sys/file.h>
+#ifndef O_ACCMODE
+#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
+#endif
+#define SEEK_SET 0
+#define SEEK_CUR 1
+
+/* Make the basic types 64-bit quantities on the host */
+#define HOST_64_BIT long long
+
+extern PROTO(int, abort,(void));
+extern PROTO(int, close,(int));
+extern PROTO(int, fcntl,(int des, int cmd, int e));
+extern PROTO(int, fprintf,(FILE *,char *,...));
+extern PROTO(int, printf,(char *,...));
+extern PROTO(int, qsort,(void *data,int els, int siz, int func()));
+extern PROTO(void, exit,(int));
+extern PROTO(int, fseek,(FILE*, int, int));
+extern PROTO(int, fclose,(FILE*));
+extern PROTO(void, bcopy,(char*,char*,int));
+extern PROTO(int, bcmp,(char *, char *, int));
+extern PROTO(void, bzero,(char *, int));
+extern PROTO(PTR,memset,(PTR, int,unsigned int));
+#ifndef __GNUC__
+PROTO(PTR, memcpy,(PTR,CONST PTR,unsigned int));
+#else
+/* PROTO(char *, memcpy,(char *,CONST char *,unsigned int)); */
+#endif
+
+extern PROTO(int,getuid,());
+extern PROTO(int,getgid,());
+extern char * strchr();
+extern PROTO(void, perror,(CONST char *));
+extern char *getenv();
+extern char *memchr();
+extern char *strrchr();
+extern int chmod();
+extern int fread();
+extern int fstat();
+extern int fwrite();
+extern int sscanf();
+extern int stat();
+extern int strtol();
+#ifndef DONTDECLARE_MALLOC
+extern PROTO(PTR,malloc,(unsigned));
+extern PROTO(PTR ,realloc, (PTR, unsigned));
+#endif
+
+extern PROTO(int, free,(PTR));
+
+
+extern char *strrchr();
+extern char *ctime();
+extern int _flsbuf();
+extern int fclose();
+extern int time();
+extern int utimes();
+extern int vfprintf();
+extern long atol();
+extern char *getenv();
+extern int fputc();
+extern int unlink();
+
+
+/* EXACT TYPES */
+typedef char int8e_type;
+typedef unsigned char uint8e_type;
+typedef short int16e_type;
+typedef unsigned short uint16e_type;
+typedef int int32e_type;
+typedef unsigned int uint32e_type;
+
+
+#ifdef __GNUC__
+typedef unsigned long long uint64e_type;
+
+#else
+typedef struct {
+ uint32e_type low, high;
+} uint64e_type;
+
+#endif
+/* CORRECT SIZE OR GREATER */
+typedef char int8_type;
+typedef unsigned char uint8_type;
+typedef short int16_type;
+typedef unsigned short uint16_type;
+typedef int int32_type;
+typedef unsigned int uint32_type;
+
+#ifdef __GNUC__
+typedef unsigned long long uint64_type;
+typedef long long int64_type;
+#else
+typedef struct {
+ uint32e_type low, high;
+} uint64_type;
+
+typedef struct {
+ uint32e_type low, high;
+} int64_type;
+
+#endif
+
+
+#define BYTES_IN_PRINTF_INT 4
+#ifndef __GNUC__
+#define uint64_typeLOW(x) (uint32_type)(((x).low))
+#define uint64_typeHIGH(x) (uint32_type)(((x).high))
+#else
+#define uint64_typeLOW(x) (uint32_type)(((x) & 0xffffffff))
+#define uint64_typeHIGH(x) (uint32_type)(((x) >> 32) & 0xffffffff)
+#endif