Back to index

cell-binutils  2.17cvs20070401
encap.h
Go to the documentation of this file.
00001 /* Yet Another Try at encapsulating bsd object files in coff.
00002    Copyright 1988, 1989, 1991 Free Software Foundation, Inc.
00003    Written by Pace Willisson 12/9/88
00004 
00005    This file is obsolete.  It needs to be converted to just define a bunch
00006    of stuff that BFD can use to do coff-encapsulated files.  --gnu@cygnus.com
00007 
00008 This program is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2 of the License, or
00011 (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00021 
00022 /*
00023  * We only use the coff headers to tell the kernel
00024  * how to exec the file.  Therefore, the only fields that need to 
00025  * be filled in are the scnptr and vaddr for the text and data
00026  * sections, and the vaddr for the bss.  As far as coff is concerned,
00027  * there is no symbol table, relocation, or line numbers.
00028  *
00029  * A normal bsd header (struct exec) is placed after the coff headers,
00030  * and before the real text.  I defined a the new fields 'a_machtype'
00031  * and a_flags.  If a_machtype is M_386, and a_flags & A_ENCAP is
00032  * true, then the bsd header is preceeded by a coff header.  Macros
00033  * like N_TXTOFF and N_TXTADDR use this field to find the bsd header.
00034  * 
00035  * The only problem is to track down the bsd exec header.  The
00036  * macros HEADER_OFFSET, etc do this.
00037  */
00038 
00039 #define N_FLAGS_COFF_ENCAPSULATE 0x20 /* coff header precedes bsd header */
00040 
00041 /* Describe the COFF header used for encapsulation.  */
00042 
00043 struct coffheader
00044 {
00045   /* filehdr */
00046   unsigned short f_magic;
00047   unsigned short f_nscns;
00048   long f_timdat;
00049   long f_symptr;
00050   long f_nsyms;
00051   unsigned short f_opthdr;
00052   unsigned short f_flags;
00053   /* aouthdr */
00054   short magic;
00055   short vstamp;
00056   long tsize;
00057   long dsize;
00058   long bsize;
00059   long entry;
00060   long text_start;
00061   long data_start;
00062   struct coffscn
00063     {
00064       char s_name[8];
00065       long s_paddr;
00066       long s_vaddr;
00067       long s_size;
00068       long s_scnptr;
00069       long s_relptr;
00070       long s_lnnoptr;
00071       unsigned short s_nreloc;
00072       unsigned short s_nlnno;
00073       long s_flags;
00074     } scns[3];
00075 };
00076 
00077 /* Describe some of the parameters of the encapsulation,
00078    including how to find the encapsulated BSD header.  */
00079 
00080 /* FIXME, this is dumb.  The same tools can't handle a.outs for different
00081    architectures, just because COFF_MAGIC is different; so you need a
00082    separate GNU nm for every architecture!!?  Unfortunately, it needs to
00083    be this way, since the COFF_MAGIC value is determined by the kernel
00084    we're trying to fool here.  */
00085    
00086 #define COFF_MAGIC_I386 0514 /* I386MAGIC */
00087 #define COFF_MAGIC_M68K 0520 /* MC68MAGIC */
00088 
00089 #ifdef COFF_MAGIC
00090 short __header_offset_temp;
00091 #define HEADER_OFFSET(f) \
00092        (__header_offset_temp = 0, \
00093         fread ((char *)&__header_offset_temp, sizeof (short), 1, (f)), \
00094         fseek ((f), -sizeof (short), 1), \
00095         __header_offset_temp==COFF_MAGIC ? sizeof(struct coffheader) : 0)
00096 #else
00097 #define HEADER_OFFSET(f) 0
00098 #endif
00099 
00100 #define HEADER_SEEK(f) (fseek ((f), HEADER_OFFSET((f)), 1))
00101 
00102 /* Describe the characteristics of the BSD header
00103    that appears inside the encapsulation.  */
00104 
00105 /* Encapsulated coff files that are linked ZMAGIC have a text segment
00106    offset just past the header (and a matching TXTADDR), excluding
00107    the headers from the text segment proper but keeping the physical
00108    layout and the virtual memory layout page-aligned.
00109 
00110    Non-encapsulated a.out files that are linked ZMAGIC have a text
00111    segment that starts at 0 and an N_TXTADR similarly offset to 0.
00112    They too are page-aligned with each other, but they include the
00113    a.out header as part of the text. 
00114 
00115    The _N_HDROFF gets sizeof struct exec added to it, so we have
00116    to compensate here.  See <a.out.gnu.h>.  */
00117 
00118 #undef _N_HDROFF
00119 #undef N_TXTADDR
00120 #undef N_DATADDR
00121 
00122 #define _N_HDROFF(x) ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
00123                     sizeof (struct coffheader) : 0)
00124 
00125 /* Address of text segment in memory after it is loaded.  */
00126 #define N_TXTADDR(x) \
00127        ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
00128         sizeof (struct coffheader) + sizeof (struct exec) : 0)
00129 #define SEGMENT_SIZE 0x400000
00130 
00131 #define N_DATADDR(x) \
00132        ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
00133         (SEGMENT_SIZE + ((N_TXTADDR(x)+(x).a_text-1) & ~(SEGMENT_SIZE-1))) : \
00134         (N_TXTADDR(x)+(x).a_text))