1 #ifndef __A_OUT_GNU_H__
2 #define __A_OUT_GNU_H__
3 
4 #ifdef	__cplusplus
5 extern "C" {
6 #endif
7 
8 #define __GNU_EXEC_MACROS__
9 
10 #ifndef __STRUCT_EXEC_OVERRIDE__
11 
12 struct exec
13 {
14   unsigned long a_info;		/* Use macros N_MAGIC, etc for access */
15   unsigned a_text;		/* size of text, in bytes */
16   unsigned a_data;		/* size of data, in bytes */
17   unsigned a_bss;		/* size of uninitialized data area, in bytes */
18   unsigned a_syms;		/* length of symbol table data, in bytes */
19   unsigned a_entry;		/* start address */
20   unsigned a_trsize;		/* size of reloc info for text, in bytes */
21   unsigned a_drsize;		/* size of reloc info for data, in bytes */
22 
23 #if defined (sequent) && defined (i386)
24   struct gdtbl
25     {				/* Global Descriptor Table */
26       unsigned g_code[2];
27       unsigned g_data[2];
28       unsigned g_desc[2];
29     } a_gdtbl;
30    unsigned a_shdata;		/* size of initialized shared data */
31    unsigned a_shbss;		/* size of uninitialized shared data */
32    unsigned a_shdrsize;		/* size of shared data relocation */
33    unsigned a_bootstrap[11];	/* bootstrap for standalone */
34    unsigned a_reserved[3];	/* reserved for future use */
35    unsigned a_version;		/* object version */
36 #endif /* Sequent Symmetry, Dynix 3.x */
37 };
38 
39 #endif /* __STRUCT_EXEC_OVERRIDE__ */
40 
41 /* these go in the N_MACHTYPE field */
42 enum machine_type {
43 #if defined (M_OLDSUN2)
44   M__OLDSUN2 = M_OLDSUN2,
45 #else
46   M_OLDSUN2 = 0,
47 #endif
48 #if defined (M_68010)
49   M__68010 = M_68010,
50 #else
51   M_68010 = 1,
52 #endif
53 #if defined (M_68020)
54   M__68020 = M_68020,
55 #else
56   M_68020 = 2,
57 #endif
58 #if defined (M_SPARC)
59   M__SPARC = M_SPARC,
60 #else
61   M_SPARC = 3,
62 #endif
63   /* skip a bunch so we don't run into any of sun's numbers */
64   M_386 = 100
65 };
66 
67 #if defined (sequent) && defined (i386)
68 
69 /* Dynix 3 wants the magic number to be the whole first longword.  */
70 
71 #define N_MAGIC(exec)		((exec).a_info)
72 #define N_MACHTYPE(exec)	0
73 #define N_FLAGS(exec)		0
74 #define N_SET_INFO(exec, magic, type, flags) N_SET_MAGIC ((exec), (magic))
75 #define N_SET_MAGIC(exec, magic)	((exec).a_info = (magic))
76 #define N_SET_MACHTYPE(exec, machtype)	((void) 0)
77 #define N_SET_FLAGS(exec, flags)	((void) 0)
78 #define	OMAGIC		0x12eb	/* impure format - for .o's */
79 #define	ZMAGIC		0x22eb	/* demand load format - zero at zero */
80 #define NMAGIC		you lose /* syntax error -- no pure format */
81 #define N_BADMAG(x)	(N_MAGIC(x) != OMAGIC && N_MAGIC(x) != ZMAGIC)
82 #define N_ADDRADJ(x)	(N_MAGIC(x) == ZMAGIC ? SEGMENT_SIZE : 0)
83 #define N_DATOFF(x)	(N_TXTOFF(x) + (x).a_text - N_ADDRADJ(x))
84 #define N_TRELOFF(x)	(N_DATOFF(x) + (x).a_data + (x).a_shdata)
85 #define N_SYMOFF(x)	(N_DRELOFF(x) + (x).a_drsize + (x).a_shdrsize)
86 #define N_TXTADDR(x)	SEGMENT_SIZE
87 #define N_COMM		0x0a	/** conflicts with N_INDR **/
88 #define N_FN		0x0c
89 /* Note that the Dynix binutils believe that N_SET[TDB] are
90    N_SH{DATA,BSS,COMM} -- be wary when mixing GNU & Dynix objects.  */
91 #define PAGE_SIZE	4096
92 #define SEGMENT_SIZE	PAGE_SIZE
93 
94 #else /* !(sequent && i386) */
95 
96 #if !defined (N_MAGIC)
97 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
98 #endif
99 #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
100 #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
101 #define N_SET_INFO(exec, magic, type, flags) \
102 	((exec).a_info = ((magic) & 0xffff) \
103 	 | (((int)(type) & 0xff) << 16) \
104 	 | (((flags) & 0xff) << 24))
105 #define N_SET_MAGIC(exec, magic) \
106 	((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
107 
108 #define N_SET_MACHTYPE(exec, machtype) \
109 	((exec).a_info = \
110 	 ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
111 
112 #define N_SET_FLAGS(exec, flags) \
113 	((exec).a_info = \
114 	 ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
115 
116 #endif	/* sequent && i386 */
117 
118 #ifndef OMAGIC
119 /* Code indicating object file or impure executable.  */
120 #define OMAGIC 0407
121 /* Code indicating pure executable.  */
122 #define NMAGIC 0410
123 /* Code indicating demand-paged executable.  */
124 #define ZMAGIC 0413
125 #endif /* not OMAGIC */
126 
127 #if !defined (N_BADMAG)
128 #define N_BADMAG(x)					\
129  (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC		\
130   && N_MAGIC(x) != ZMAGIC)
131 #endif
132 
133 #define _N_BADMAG(x)					\
134  (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC		\
135   && N_MAGIC(x) != ZMAGIC)
136 
137 #ifndef	sparc
138 #define _N_HDROFF(x) (SEGMENT_SIZE - sizeof (struct exec))
139 #else
140 #define _N_HDROFF(x) (- sizeof (struct exec))
141 #endif
142 
143 #if !defined (N_TXTOFF)
144 #define N_TXTOFF(x) \
145  (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : sizeof (struct exec))
146 #endif
147 
148 #if !defined (N_DATOFF)
149 #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
150 #endif
151 
152 #if !defined (N_TRELOFF)
153 #define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
154 #endif
155 
156 #if !defined (N_DRELOFF)
157 #define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
158 #endif
159 
160 #if !defined (N_SYMOFF)
161 #define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
162 #endif
163 
164 #if !defined (N_STROFF)
165 #define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
166 #endif
167 
168 /* Address of text segment in memory after it is loaded.  */
169 #if !defined (N_TXTADDR)
170 #define N_TXTADDR(x) 0
171 #endif
172 
173 /* Address of data segment in memory after it is loaded.
174    Note that it is up to you to define SEGMENT_SIZE
175    on machines not listed here.  */
176 #if	defined (hp300) || defined (mips)
177 #define	PAGE_SIZE	4096
178 #endif
179 #if	defined (sparc) || defined (NeXT)
180 #define	PAGE_SIZE	0x2000
181 #endif
182 #if	defined (sony) || (defined (sun) && defined (mc68000))
183 #define	SEGMENT_SIZE	0x2000
184 #endif	/* Sony or 68k Sun.  */
185 #ifdef is68k
186 #define SEGMENT_SIZE 0x20000
187 #endif
188 #if defined(m68k) && defined(PORTAR)
189 #define PAGE_SIZE 0x400
190 #endif
191 #if defined(i386) && !defined(sequent)
192 /* For COFF encapsulation.  */
193 #define SEGMENT_SIZE 0x400000
194 #endif
195 #ifndef	SEGMENT_SIZE
196 /* This used to be first in this paragraph and under:
197    if (defined(vax) || defined(hp300) || defined(pyr) || defined(sparc) \
198      || (defined(m68k) && defined(PORTAR)) \
199      || defined (NeXT) || defined (mips)) */
200 #define SEGMENT_SIZE PAGE_SIZE
201 #endif
202 #ifndef	PAGE_SIZE
203 /* This value is for i386-minix, but that has no predefine.
204    Making it default will only cause confusion on machines
205    which have no proper value defined.  */
206 #define	PAGE_SIZE 16
207 #endif
208 
209 #define	PAGSIZ	PAGE_SIZE
210 #define	SEGSIZ	SEGMENT_SIZE
211 
212 #define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
213 
214 #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
215 
216 #ifndef N_DATADDR
217 #define N_DATADDR(x) \
218     (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
219      : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
220 #endif
221 
222 /* Address of bss segment in memory after it is loaded.  */
223 #if !defined (N_BSSADDR)
224 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
225 #endif
226 
227 #if !defined (N_NLIST_DECLARED)
228 struct nlist {
229   union {
230     char *n_name;
231     struct nlist *n_next;
232     long n_strx;
233   } n_un;
234   unsigned char n_type;
235   char n_other;
236   short n_desc;
237   unsigned long n_value;
238 };
239 #endif /* no N_NLIST_DECLARED.  */
240 
241 #if !defined (N_UNDF)
242 #define N_UNDF 0
243 #endif
244 #if !defined (N_ABS)
245 #define N_ABS 2
246 #endif
247 #if !defined (N_TEXT)
248 #define N_TEXT 4
249 #endif
250 #if !defined (N_DATA)
251 #define N_DATA 6
252 #endif
253 #if !defined (N_BSS)
254 #define N_BSS 8
255 #endif
256 #if !defined (N_COMM)
257 #define N_COMM 18
258 #endif
259 #if !defined (N_FN)
260 #define N_FN 15
261 #endif
262 
263 #if !defined (N_EXT)
264 #define N_EXT 1
265 #endif
266 #if !defined (N_TYPE)
267 #define N_TYPE 036
268 #endif
269 #if !defined (N_STAB)
270 #define N_STAB 0340
271 #endif
272 
273 /* The following type indicates the definition of a symbol as being
274    an indirect reference to another symbol.  The other symbol
275    appears as an undefined reference, immediately following this symbol.
276 
277    Indirection is asymmetrical.  The other symbol's value will be used
278    to satisfy requests for the indirect symbol, but not vice versa.
279    If the other symbol does not have a definition, libraries will
280    be searched to find a definition.  */
281 #define N_INDR 0xa
282 
283 /* The following symbols refer to set elements.
284    All the N_SET[ATDB] symbols with the same name form one set.
285    Space is allocated for the set in the text section, and each set
286    element's value is stored into one word of the space.
287    The first word of the space is the length of the set (number of elements).
288 
289    The address of the set is made into an N_SETV symbol
290    whose name is the same as the name of the set.
291    This symbol acts like a N_DATA global symbol
292    in that it can satisfy undefined external references.  */
293 
294 /* These appear as input to LD, in a .o file.  */
295 #define	N_SETA	0x14		/* Absolute set element symbol */
296 #define	N_SETT	0x16		/* Text set element symbol */
297 #define	N_SETD	0x18		/* Data set element symbol */
298 #define	N_SETB	0x1A		/* Bss set element symbol */
299 
300 /* This is output from LD.  */
301 #define N_SETV	0x1C		/* Pointer to set vector in data area.  */
302 
303 #if !defined (N_RELOCATION_INFO_DECLARED)
304 /* This structure describes a single relocation to be performed.
305    The text-relocation section of the file is a vector of these structures,
306    all of which apply to the text section.
307    Likewise, the data-relocation section applies to the data section.  */
308 
309 struct relocation_info
310 {
311   /* Address (within segment) to be relocated.  */
312   int r_address;
313   /* The meaning of r_symbolnum depends on r_extern.  */
314   unsigned int r_symbolnum:24;
315   /* Nonzero means value is a pc-relative offset
316      and it should be relocated for changes in its own address
317      as well as for changes in the symbol or section specified.  */
318   unsigned int r_pcrel:1;
319   /* Length (as exponent of 2) of the field to be relocated.
320      Thus, a value of 2 indicates 1<<2 bytes.  */
321   unsigned int r_length:2;
322   /* 1 => relocate with value of symbol.
323           r_symbolnum is the index of the symbol
324 	  in file's the symbol table.
325      0 => relocate with the address of a segment.
326           r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
327 	  (the N_EXT bit may be set also, but signifies nothing).  */
328   unsigned int r_extern:1;
329   /* Four bits that aren't used, but when writing an object file
330      it is desirable to clear them.  */
331   unsigned int r_pad:4;
332 };
333 #endif /* no N_RELOCATION_INFO_DECLARED.  */
334 
335 #ifdef	__cplusplus
336 }
337 #endif
338 
339 #endif /* __A_OUT_GNU_H__ */
340