xref: /openbsd-src/gnu/usr.bin/binutils-2.17/include/aout/encap.h (revision 3d8817e467ea46cf4772788d6804dd293abfb01a)
1*3d8817e4Smiod /* Yet Another Try at encapsulating bsd object files in coff.
2*3d8817e4Smiod    Copyright 1988, 1989, 1991 Free Software Foundation, Inc.
3*3d8817e4Smiod    Written by Pace Willisson 12/9/88
4*3d8817e4Smiod 
5*3d8817e4Smiod    This file is obsolete.  It needs to be converted to just define a bunch
6*3d8817e4Smiod    of stuff that BFD can use to do coff-encapsulated files.  --gnu@cygnus.com
7*3d8817e4Smiod 
8*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
9*3d8817e4Smiod it under the terms of the GNU General Public License as published by
10*3d8817e4Smiod the Free Software Foundation; either version 2 of the License, or
11*3d8817e4Smiod (at your option) any later version.
12*3d8817e4Smiod 
13*3d8817e4Smiod This program is distributed in the hope that it will be useful,
14*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
15*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*3d8817e4Smiod GNU General Public License for more details.
17*3d8817e4Smiod 
18*3d8817e4Smiod You should have received a copy of the GNU General Public License
19*3d8817e4Smiod along with this program; if not, write to the Free Software
20*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
21*3d8817e4Smiod 
22*3d8817e4Smiod /*
23*3d8817e4Smiod  * We only use the coff headers to tell the kernel
24*3d8817e4Smiod  * how to exec the file.  Therefore, the only fields that need to
25*3d8817e4Smiod  * be filled in are the scnptr and vaddr for the text and data
26*3d8817e4Smiod  * sections, and the vaddr for the bss.  As far as coff is concerned,
27*3d8817e4Smiod  * there is no symbol table, relocation, or line numbers.
28*3d8817e4Smiod  *
29*3d8817e4Smiod  * A normal bsd header (struct exec) is placed after the coff headers,
30*3d8817e4Smiod  * and before the real text.  I defined a the new fields 'a_machtype'
31*3d8817e4Smiod  * and a_flags.  If a_machtype is M_386, and a_flags & A_ENCAP is
32*3d8817e4Smiod  * true, then the bsd header is preceeded by a coff header.  Macros
33*3d8817e4Smiod  * like N_TXTOFF and N_TXTADDR use this field to find the bsd header.
34*3d8817e4Smiod  *
35*3d8817e4Smiod  * The only problem is to track down the bsd exec header.  The
36*3d8817e4Smiod  * macros HEADER_OFFSET, etc do this.
37*3d8817e4Smiod  */
38*3d8817e4Smiod 
39*3d8817e4Smiod #define N_FLAGS_COFF_ENCAPSULATE 0x20 /* coff header precedes bsd header */
40*3d8817e4Smiod 
41*3d8817e4Smiod /* Describe the COFF header used for encapsulation.  */
42*3d8817e4Smiod 
43*3d8817e4Smiod struct coffheader
44*3d8817e4Smiod {
45*3d8817e4Smiod   /* filehdr */
46*3d8817e4Smiod   unsigned short f_magic;
47*3d8817e4Smiod   unsigned short f_nscns;
48*3d8817e4Smiod   long f_timdat;
49*3d8817e4Smiod   long f_symptr;
50*3d8817e4Smiod   long f_nsyms;
51*3d8817e4Smiod   unsigned short f_opthdr;
52*3d8817e4Smiod   unsigned short f_flags;
53*3d8817e4Smiod   /* aouthdr */
54*3d8817e4Smiod   short magic;
55*3d8817e4Smiod   short vstamp;
56*3d8817e4Smiod   long tsize;
57*3d8817e4Smiod   long dsize;
58*3d8817e4Smiod   long bsize;
59*3d8817e4Smiod   long entry;
60*3d8817e4Smiod   long text_start;
61*3d8817e4Smiod   long data_start;
62*3d8817e4Smiod   struct coffscn
63*3d8817e4Smiod     {
64*3d8817e4Smiod       char s_name[8];
65*3d8817e4Smiod       long s_paddr;
66*3d8817e4Smiod       long s_vaddr;
67*3d8817e4Smiod       long s_size;
68*3d8817e4Smiod       long s_scnptr;
69*3d8817e4Smiod       long s_relptr;
70*3d8817e4Smiod       long s_lnnoptr;
71*3d8817e4Smiod       unsigned short s_nreloc;
72*3d8817e4Smiod       unsigned short s_nlnno;
73*3d8817e4Smiod       long s_flags;
74*3d8817e4Smiod     } scns[3];
75*3d8817e4Smiod };
76*3d8817e4Smiod 
77*3d8817e4Smiod /* Describe some of the parameters of the encapsulation,
78*3d8817e4Smiod    including how to find the encapsulated BSD header.  */
79*3d8817e4Smiod 
80*3d8817e4Smiod /* FIXME, this is dumb.  The same tools can't handle a.outs for different
81*3d8817e4Smiod    architectures, just because COFF_MAGIC is different; so you need a
82*3d8817e4Smiod    separate GNU nm for every architecture!!?  Unfortunately, it needs to
83*3d8817e4Smiod    be this way, since the COFF_MAGIC value is determined by the kernel
84*3d8817e4Smiod    we're trying to fool here.  */
85*3d8817e4Smiod 
86*3d8817e4Smiod #define COFF_MAGIC_I386 0514 /* I386MAGIC */
87*3d8817e4Smiod #define COFF_MAGIC_M68K 0520 /* MC68MAGIC */
88*3d8817e4Smiod 
89*3d8817e4Smiod #ifdef COFF_MAGIC
90*3d8817e4Smiod short __header_offset_temp;
91*3d8817e4Smiod #define HEADER_OFFSET(f) \
92*3d8817e4Smiod 	(__header_offset_temp = 0, \
93*3d8817e4Smiod 	 fread ((char *)&__header_offset_temp, sizeof (short), 1, (f)), \
94*3d8817e4Smiod 	 fseek ((f), -sizeof (short), 1), \
95*3d8817e4Smiod 	 __header_offset_temp==COFF_MAGIC ? sizeof(struct coffheader) : 0)
96*3d8817e4Smiod #else
97*3d8817e4Smiod #define HEADER_OFFSET(f) 0
98*3d8817e4Smiod #endif
99*3d8817e4Smiod 
100*3d8817e4Smiod #define HEADER_SEEK(f) (fseek ((f), HEADER_OFFSET((f)), 1))
101*3d8817e4Smiod 
102*3d8817e4Smiod /* Describe the characteristics of the BSD header
103*3d8817e4Smiod    that appears inside the encapsulation.  */
104*3d8817e4Smiod 
105*3d8817e4Smiod /* Encapsulated coff files that are linked ZMAGIC have a text segment
106*3d8817e4Smiod    offset just past the header (and a matching TXTADDR), excluding
107*3d8817e4Smiod    the headers from the text segment proper but keeping the physical
108*3d8817e4Smiod    layout and the virtual memory layout page-aligned.
109*3d8817e4Smiod 
110*3d8817e4Smiod    Non-encapsulated a.out files that are linked ZMAGIC have a text
111*3d8817e4Smiod    segment that starts at 0 and an N_TXTADR similarly offset to 0.
112*3d8817e4Smiod    They too are page-aligned with each other, but they include the
113*3d8817e4Smiod    a.out header as part of the text.
114*3d8817e4Smiod 
115*3d8817e4Smiod    The _N_HDROFF gets sizeof struct exec added to it, so we have
116*3d8817e4Smiod    to compensate here.  See <a.out.gnu.h>.  */
117*3d8817e4Smiod 
118*3d8817e4Smiod #undef _N_HDROFF
119*3d8817e4Smiod #undef N_TXTADDR
120*3d8817e4Smiod #undef N_DATADDR
121*3d8817e4Smiod 
122*3d8817e4Smiod #define _N_HDROFF(x) ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
123*3d8817e4Smiod 		      sizeof (struct coffheader) : 0)
124*3d8817e4Smiod 
125*3d8817e4Smiod /* Address of text segment in memory after it is loaded.  */
126*3d8817e4Smiod #define N_TXTADDR(x) \
127*3d8817e4Smiod 	((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
128*3d8817e4Smiod 	 sizeof (struct coffheader) + sizeof (struct exec) : 0)
129*3d8817e4Smiod #define SEGMENT_SIZE 0x400000
130*3d8817e4Smiod 
131*3d8817e4Smiod #define N_DATADDR(x) \
132*3d8817e4Smiod 	((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
133*3d8817e4Smiod 	 (SEGMENT_SIZE + ((N_TXTADDR(x)+(x).a_text-1) & ~(SEGMENT_SIZE-1))) : \
134*3d8817e4Smiod 	 (N_TXTADDR(x)+(x).a_text))
135