]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - include/a.out.encap.h
as rich copied from mike
[thirdparty/binutils-gdb.git] / include / a.out.encap.h
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 #ifndef A_OUT_ENCAP_H_SEEN
37 #define A_OUT_ENCAP_H_SEEN
38
39 #include "a.out.gnu.h"
40
41 /* Figure out what our target machine is */
42 #include "target.h"
43
44 #define N_FLAGS_COFF_ENCAPSULATE 0x20 /* coff header precedes bsd header */
45
46 /* Describe the COFF header used for encapsulation. */
47
48 struct coffheader
49 {
50 /* filehdr */
51 unsigned short f_magic;
52 unsigned short f_nscns;
53 long f_timdat;
54 long f_symptr;
55 long f_nsyms;
56 unsigned short f_opthdr;
57 unsigned short f_flags;
58 /* aouthdr */
59 short magic;
60 short vstamp;
61 long tsize;
62 long dsize;
63 long bsize;
64 long entry;
65 long text_start;
66 long data_start;
67 struct coffscn
68 {
69 char s_name[8];
70 long s_paddr;
71 long s_vaddr;
72 long s_size;
73 long s_scnptr;
74 long s_relptr;
75 long s_lnnoptr;
76 unsigned short s_nreloc;
77 unsigned short s_nlnno;
78 long s_flags;
79 } scns[3]; /* text, data, bss */
80 };
81 \f
82 /* Describe some of the parameters of the encapsulation,
83 including how to find the encapsulated BSD header. */
84
85 #if TARGET == TARGET_I386
86 #define COFF_MAGIC 0514 /* I386MAGIC */
87 #endif
88 #if TARGET == TARGET_M68K
89 #define COFF_MAGIC 0520 /* MC68MAGIC */
90 #endif
91 #if TARGET == TARGET_SPARC
92 #define COFF_MAGIC UNKNOWN!!! /* Used by TTI */
93 #endif
94 #if TARGET == TARGET_AM29K
95 #define COFF_MAGIC 0x17A /* Used by asm29k cross-tools */
96 #endif
97
98 #ifdef COFF_MAGIC
99 short __header_offset_temp;
100
101 /* FIXME, this is dumb. The same tools can't handle a.outs for different
102 architectures, just because COFF_MAGIC is different; so you need a
103 separate GNU nm for every architecture!!? Also note that for
104 expediency, this macros accepts COFF_MAGIC in either byte order.
105 The right thing to do is to call read_aout_header to handle all this. */
106
107 #define HEADER_OFFSET(f) \
108 (__header_offset_temp = 0, \
109 fread ((char *)&__header_offset_temp, sizeof (short), 1, (f)), \
110 fseek ((f), -sizeof (short), 1), \
111 (__header_offset_temp==COFF_MAGIC || __header_offset_temp == \
112 ((COFF_MAGIC >> 8)|((COFF_MAGIC&0xFF)<<8)) \
113 ? sizeof(struct coffheader) : 0))
114
115 #define HEADER_OFFSET_FD(fd) \
116 (__header_offset_temp = 0, \
117 read (fd, (char *)&__header_offset_temp, sizeof (short)), \
118 lseek ((fd), -sizeof (short), 1), \
119 (__header_offset_temp==COFF_MAGIC || __header_offset_temp == \
120 ((COFF_MAGIC >> 8)|((COFF_MAGIC&0xFF)<<8)) \
121 ? sizeof(struct coffheader) : 0))
122
123
124 #else
125 #define HEADER_OFFSET(f) 0
126 #define HEADER_OFFSET_FD(fd) 0
127 #endif
128
129 #define HEADER_SEEK(f) (fseek ((f), HEADER_OFFSET((f)), 1))
130 #define HEADER_SEEK_FD(fd) (lseek ((fd), HEADER_OFFSET_FD((fd)), 1))
131
132 \f
133 /* Describe the characteristics of the BSD header
134 that appears inside the encapsulation. */
135
136 #undef _N_HDROFF
137 #undef N_TXTADDR
138 #undef N_DATADDR
139
140 /* Encapsulated coff files that are linked ZMAGIC have a text segment
141 offset just past the header (and a matching TXTADDR), excluding
142 the headers from the text segment proper but keeping the physical
143 layout and the virtual memory layout page-aligned.
144
145 Non-encapsulated a.out files that are linked ZMAGIC have a text
146 segment that starts at 0 and an N_TXTADR similarly offset to 0.
147 They too are page-aligned with each other, but they include the
148 a.out header as part of the text.
149
150 The _N_HDROFF gets sizeof struct exec added to it, so we have
151 to compensate here. See <a.out.gnu.h>. */
152
153 #define _N_HDROFF(x) ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
154 sizeof (struct coffheader) : -sizeof (struct exec))
155
156 /* Address of text segment in memory after it is loaded. */
157 #define N_TXTADDR(x) \
158 (TEXT_START_ADDR + \
159 ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
160 sizeof (struct coffheader) + sizeof (struct exec) : 0))
161
162 /* I have no idea what this is doing here. -- gnu@toad.com 20Mar90
163 Perhaps it is to give a size that is acceptable to any machine? */
164 #undef SEGMENT_SIZE
165 #define SEGMENT_SIZE 0x400000
166
167 #define N_DATADDR(x) \
168 ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
169 (SEGMENT_SIZE + ((N_TXTADDR(x)+(x).a_text-1) & ~(SEGMENT_SIZE-1))) : \
170 (N_TXTADDR(x)+(x).a_text))
171
172 #endif /* A_OUT_ENCAP_H_SEEN */