1 /* Another try at encapsulating bsd object files in coff.
2 Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
3 Written by Pace Willisson 12/9/88
5 This file is obsolete. It needs to be converted to just define a bunch
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 * This time, we will only use the coff headers to tell the kernel
24 * how to exec the file. Therefore, the only fields that need to
25 * be filled in are the scnptr and vaddr for the text and data
26 * sections, and the vaddr for the bss. As far as coff is concerned,
27 * there is no symbol table, relocation, or line numbers.
29 * A normal bsd header (struct exec) is placed after the coff headers,
30 * and before the real text. I defined a the new fields 'a_machtype'
31 * and a_flags. If a_machtype is M_386, and a_flags & A_ENCAP is
32 * true, then the bsd header is preceeded by a coff header. Macros
33 * like N_TXTOFF and N_TXTADDR use this field to find the bsd header.
35 * The only problem is to track down the bsd exec header. The
36 * macros HEADER_OFFSET, etc do this. Look at nm.c, dis.c, etc
39 #ifndef A_OUT_ENCAP_H_SEEN
40 #define A_OUT_ENCAP_H_SEEN
42 #include "a.out.gnu.h"
44 #define N_FLAGS_COFF_ENCAPSULATE 0x20 /* coff header precedes bsd header */
46 /* Describe the COFF header used for encapsulation. */
51 unsigned short f_magic;
52 unsigned short f_nscns;
56 unsigned short f_opthdr;
57 unsigned short f_flags;
76 unsigned short s_nreloc;
77 unsigned short s_nlnno;
79 } scns[3]; /* text, data, bss */
82 /* Describe some of the parameters of the encapsulation,
83 including how to find the encapsulated BSD header. */
85 #if TARGET == TARGET_I386
86 #define COFF_MAGIC 0514 /* I386MAGIC */
88 #if TARGET == TARGET_M68K
89 #define COFF_MAGIC 0520 /* MC68MAGIC */
91 #if TARGET == TARGET_SPARC
92 #define COFF_MAGIC UNKNOWN!!! /* Used by TTI */
94 #if TARGET == TARGET_AM29K
95 #define COFF_MAGIC 0x17A /* Used by asm29k cross-tools */
99 short __header_offset_temp;
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. */
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))
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))
125 #define HEADER_OFFSET(f) 0
126 #define HEADER_OFFSET_FD(fd) 0
129 #define HEADER_SEEK(f) (fseek ((f), HEADER_OFFSET((f)), 1))
130 #define HEADER_SEEK_FD(fd) (lseek ((fd), HEADER_OFFSET_FD((fd)), 1))
133 /* Describe the characteristics of the BSD header
134 that appears inside the encapsulation. */
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.
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.
150 The _N_HDROFF gets sizeof struct exec added to it, so we have
151 to compensate here. See <a.out.gnu.h>. */
153 #define _N_HDROFF(x) ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
154 sizeof (struct coffheader) : -sizeof (struct exec))
156 /* Address of text segment in memory after it is loaded. */
157 #define N_TXTADDR(x) \
159 ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \
160 sizeof (struct coffheader) + sizeof (struct exec) : 0))
163 Perhaps it is to give a size that is acceptable to any machine? */
165 #define SEGMENT_SIZE 0x400000
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))
172 #endif /* A_OUT_ENCAP_H_SEEN */