1 /* Copyright (C) 1990-1996
2  * This file is part of the ld86 command for Linux-86
3  * It is distributed under the GNU Library General Public License.
4  *
5  * - This may actually be BSD or Minix code, can someone clarify please. -RDB
6  */
7 
8 #ifndef __AOUT_H
9 #define __AOUT_H
10 
11 struct	exec {			/* a.out header */
12   unsigned char	a_magic[2];	/* magic number */
13   unsigned char	a_flags;	/* flags, see below */
14   unsigned char	a_cpu;		/* cpu id */
15   unsigned char	a_hdrlen;	/* length of header */
16   unsigned char	a_unused;	/* reserved for future use */
17   unsigned short a_version;	/* version stamp (not used at present) */
18   long		a_text;		/* size of text segement in bytes */
19   long		a_data;		/* size of data segment in bytes */
20   long		a_bss;		/* size of bss segment in bytes */
21   long		a_entry;	/* entry point */
22   long		a_total;	/* total memory allocated */
23   long		a_syms;		/* size of symbol table */
24 
25   /* SHORT FORM ENDS HERE */
26   long		a_trsize;	/* text relocation size */
27   long		a_drsize;	/* data relocation size */
28   long		a_tbase;	/* text relocation base */
29   long		a_dbase;	/* data relocation base */
30 };
31 
32 #define A_MAGIC0      (unsigned char) 0x01
33 #define A_MAGIC1      (unsigned char) 0x03
34 #define BADMAG(X)     ((X).a_magic[0] != A_MAGIC0 ||(X).a_magic[1] != A_MAGIC1)
35 
36 /* CPU Id of TARGET machine (byte order coded in low order two bits) */
37 #define A_NONE	0x00	/* unknown */
38 #define A_I8086	0x04	/* intel i8086/8088 */
39 #define A_M68K	0x0B	/* motorola m68000 */
40 #define A_NS16K	0x0C	/* national semiconductor 16032 */
41 #define A_I80386 0x10	/* intel i80386 */
42 #define A_SPARC	0x17	/* Sun SPARC */
43 
44 #define A_BLR(cputype)	((cputype&0x01)!=0) /* TRUE if bytes left-to-right */
45 #define A_WLR(cputype)	((cputype&0x02)!=0) /* TRUE if words left-to-right */
46 
47 /* Flags. */
48 #define A_UZP	0x01	/* unmapped zero page (pages) */
49 #define A_PAL	0x02	/* page aligned executable */
50 #define A_NSYM	0x04	/* new style symbol table */
51 #define A_STAND	0x08	/* standalone executable */
52 #define A_EXEC	0x10	/* executable */
53 #define A_SEP	0x20	/* separate I/D */
54 #define A_PURE	0x40	/* pure text */
55 #define A_TOVLY	0x80	/* text overlay */
56 
57 /* Offsets of various things. */
58 #define A_MINHDR	32
59 #define	A_TEXTPOS(X)	((long)(X).a_hdrlen)
60 #define A_DATAPOS(X)	(A_TEXTPOS(X) + (X).a_text)
61 #define	A_HASRELS(X)	((X).a_hdrlen > (unsigned char) A_MINHDR)
62 #define A_HASEXT(X)	((X).a_hdrlen > (unsigned char) (A_MINHDR +  8))
63 #define A_HASLNS(X)	((X).a_hdrlen > (unsigned char) (A_MINHDR + 16))
64 #define A_HASTOFF(X)	((X).a_hdrlen > (unsigned char) (A_MINHDR + 24))
65 #define A_TRELPOS(X)	(A_DATAPOS(X) + (X).a_data)
66 #define A_DRELPOS(X)	(A_TRELPOS(X) + (X).a_trsize)
67 #define A_SYMPOS(X)	(A_TRELPOS(X) + (A_HASRELS(X) ? \
68   			((X).a_trsize + (X).a_drsize) : 0))
69 
70 struct reloc {
71   long r_vaddr;			/* virtual address of reference */
72   unsigned short r_symndx;	/* internal segnum or extern symbol num */
73   unsigned short r_type;	/* relocation type */
74 };
75 
76 /* r_tyep values: */
77 #define R_ABBS		0
78 #define R_RELLBYTE	2
79 #define R_PCRBYTE	3
80 #define R_RELWORD	4
81 #define R_PCRWORD	5
82 #define R_RELLONG	6
83 #define R_PCRLONG	7
84 #define R_REL3BYTE	8
85 #define R_KBRANCHE	9
86 
87 /* r_symndx for internal segments */
88 #define S_ABS		((unsigned short)-1)
89 #define S_TEXT		((unsigned short)-2)
90 #define S_DATA		((unsigned short)-3)
91 #define S_BSS		((unsigned short)-4)
92 
93 struct nlist {			/* symbol table entry */
94   char n_name[8];		/* symbol name */
95   long n_value;			/* value */
96   unsigned char	n_sclass;	/* storage class */
97   unsigned char	n_numaux;	/* number of auxiliary entries (not used) */
98   unsigned short n_type;	/* language base and derived type (not used) */
99 };
100 
101 /* Low bits of storage class (section). */
102 #define	N_SECT		  07	/* section mask */
103 #define N_UNDF		  00	/* undefined */
104 #define N_ABS		  01	/* absolute */
105 #define N_TEXT		  02	/* text */
106 #define N_DATA		  03	/* data */
107 #define	N_BSS		  04	/* bss */
108 #define N_COMM		  05	/* (common) */
109 
110 /* High bits of storage class. */
111 #define N_CLASS		0370	/* storage class mask */
112 #define C_NULL
113 #define C_EXT		0020	/* external symbol */
114 #define C_STAT		0030	/* static */
115 
116 #endif /* _AOUT_H */
117