home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / binutils-1.8.x.tar.gz / binutils-1.8.x.tar / binutils / a.out.encap.h next >
C/C++ Source or Header  |  1990-04-09  |  4KB  |  135 lines

  1. /* Another try at encapsulating bsd object files in coff.
  2.    Copyright (C) 1988, 1989, Free Software Foundation, Inc.
  3.    Written by Pace Willisson 12/9/88
  4.  
  5.    This file is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 1, or (at your option)
  8.    any later version.
  9.  
  10.    This file is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this file; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.    
  19. /*
  20.  * This time, we will only use the coff headers to tell the kernel
  21.  * how to exec the file.  Therefore, the only fields that need to 
  22.  * be filled in are the scnptr and vaddr for the text and data
  23.  * sections, and the vaddr for the bss.  As far as coff is concerned,
  24.  * there is no symbol table, relocation, or line numbers.
  25.  *
  26.  * A normal bsd header (struct exec) is placed after the coff headers,
  27.  * and before the real text.  I defined a the new fields 'a_machtype'
  28.  * and a_flags.  If a_machtype is M_386, and a_flags & A_ENCAP is
  29.  * true, then the bsd header is preceeded by a coff header.  Macros
  30.  * like N_TXTOFF and N_TXTADDR use this field to find the bsd header.
  31.  * 
  32.  * The only problem is to track down the bsd exec header.  The
  33.  * macros HEADER_OFFSET, etc do this.  Look at nm.c, dis.c, etc
  34.  * for examples.
  35.  */
  36.  
  37. #if !defined (A_OUT_ENCAP_H)
  38. #define A_OUT_ENCAP_H 1
  39.  
  40. #include "a.out.gnu.h"
  41.  
  42. #define N_FLAGS_COFF_ENCAPSULATE 0x20 /* coff header precedes bsd header */
  43.  
  44. /* Describe the COFF header used for encapsulation.  */
  45.  
  46. struct coffheader
  47. {
  48.   /* filehdr */
  49.   unsigned short f_magic;
  50.   unsigned short f_nscns;
  51.   long f_timdat;
  52.   long f_symptr;
  53.   long f_nsyms;
  54.   unsigned short f_opthdr;
  55.   unsigned short f_flags;
  56.   /* aouthdr */
  57.   short magic;
  58.   short vstamp;
  59.   long tsize;
  60.   long dsize;
  61.   long bsize;
  62.   long entry;
  63.   long text_start;
  64.   long data_start;
  65.   struct coffscn
  66.     {
  67.       char s_name[8];
  68.       long s_paddr;
  69.       long s_vaddr;
  70.       long s_size;
  71.       long s_scnptr;
  72.       long s_relptr;
  73.       long s_lnnoptr;
  74.       unsigned short s_nreloc;
  75.       unsigned short s_nlnno;
  76.       long s_flags;
  77.     } scns[3];
  78. };
  79.  
  80. /* Describe some of the parameters of the encapsulation,
  81.    including how to find the encapsulated BSD header.  */
  82.  
  83. #ifdef i386
  84. #define COFF_MAGIC 0514 /* I386MAGIC */
  85. #endif
  86. #ifdef m68k
  87. #define COFF_MAGIC 0520 /* MC68MAGIC */
  88. #endif
  89.  
  90. #ifdef COFF_MAGIC
  91. short __header_offset_temp;
  92. #define HEADER_OFFSET(f) \
  93.     (__header_offset_temp = 0, \
  94.      fread ((char *)&__header_offset_temp, sizeof (short), 1, (f)), \
  95.      fseek ((f), -sizeof (short), 1), \
  96.      __header_offset_temp==COFF_MAGIC ? sizeof(struct coffheader) : 0)
  97.  
  98. #define HEADER_OFFSET_FD(fd) \
  99.     (__header_offset_temp = 0, \
  100.      read ((fd), (char *)&__header_offset_temp, sizeof (short)), \
  101.      lseek ((fd), -sizeof (short), 1), \
  102.      __header_offset_temp==COFF_MAGIC ? sizeof(struct coffheader) : 0)
  103.  
  104.  
  105. #else
  106. #define HEADER_OFFSET(f) 0
  107. #define HEADER_OFFSET_FD(fd) 0
  108. #endif
  109.  
  110. #define HEADER_SEEK(f) (fseek ((f), HEADER_OFFSET((f)), 1))
  111. #define HEADER_SEEK_FD(fd) (lseek ((fd), HEADER_OFFSET_FD((fd)), 1))
  112.  
  113.  
  114. /* Describe the characteristics of the BSD header
  115.    that appears inside the encapsulation.  */
  116.  
  117. #undef _N_HDROFF
  118. #undef N_TXTADDR
  119. #undef N_DATADDR
  120.  
  121. #define _N_HDROFF(x) ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
  122.               sizeof (struct coffheader) : 0)
  123.  
  124. /* Address of text segment in memory after it is loaded.  */
  125. #define N_TXTADDR(x) \
  126.     ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
  127.      sizeof (struct coffheader) + sizeof (struct exec) : 0)
  128. #define SEGMENT_SIZE 0x400000
  129.  
  130. #define N_DATADDR(x) \
  131.     ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
  132.      (SEGMENT_SIZE + ((N_TXTADDR(x)+(x).a_text-1) & ~(SEGMENT_SIZE-1))) : \
  133.      (N_TXTADDR(x)+(x).a_text))
  134. #endif /* a.out.encap.h not already included.  */
  135.