i386.h revision 78828
1/* coff information for Intel 386/486.
2
3   Copyright 2001 Free Software Foundation, Inc.
4
5   This program 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 2 of the License, or
8   (at your option) any later version.
9
10   This program 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 program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18
19
20/********************** FILE HEADER **********************/
21
22struct external_filehdr {
23	char f_magic[2];	/* magic number			*/
24	char f_nscns[2];	/* number of sections		*/
25	char f_timdat[4];	/* time & date stamp		*/
26	char f_symptr[4];	/* file pointer to symtab	*/
27	char f_nsyms[4];	/* number of symtab entries	*/
28	char f_opthdr[2];	/* sizeof(optional hdr)		*/
29	char f_flags[2];	/* flags			*/
30};
31
32/* Bits for f_flags:
33 *	F_RELFLG	relocation info stripped from file
34 *	F_EXEC		file is executable (no unresolved external references)
35 *	F_LNNO		line numbers stripped from file
36 *	F_LSYMS		local symbols stripped from file
37 *	F_AR32WR	file has byte ordering of an AR32WR machine (e.g. vax)
38 */
39
40#define F_RELFLG	(0x0001)
41#define F_EXEC		(0x0002)
42#define F_LNNO		(0x0004)
43#define F_LSYMS		(0x0008)
44
45
46
47#define	I386MAGIC	0x14c
48#define I386PTXMAGIC	0x154
49#define I386AIXMAGIC	0x175
50
51/* This is Lynx's all-platform magic number for executables. */
52
53#define LYNXCOFFMAGIC	0415
54
55#define I386BADMAG(x) (((x).f_magic != I386MAGIC) \
56		       && (x).f_magic != I386AIXMAGIC \
57		       && (x).f_magic != I386PTXMAGIC \
58		       && (x).f_magic != LYNXCOFFMAGIC)
59
60#define	FILHDR	struct external_filehdr
61#define	FILHSZ	20
62
63
64/********************** AOUT "OPTIONAL HEADER" **********************/
65
66
67typedef struct
68{
69  char 	magic[2];		/* type of file				*/
70  char	vstamp[2];		/* version stamp			*/
71  char	tsize[4];		/* text size in bytes, padded to FW bdry*/
72  char	dsize[4];		/* initialized data "  "		*/
73  char	bsize[4];		/* uninitialized data "   "		*/
74  char	entry[4];		/* entry pt.				*/
75  char 	text_start[4];		/* base of text used for this file */
76  char 	data_start[4];		/* base of data used for this file */
77
78
79}
80AOUTHDR;
81
82
83#define AOUTSZ 28
84#define AOUTHDRSZ 28
85
86#define OMAGIC          0404    /* object files, eg as output */
87#define ZMAGIC          0413    /* demand load format, eg normal ld output */
88#define STMAGIC		0401	/* target shlib */
89#define SHMAGIC		0443	/* host   shlib */
90
91
92/* define some NT default values */
93/*  #define NT_IMAGE_BASE        0x400000 moved to internal.h */
94#define NT_SECTION_ALIGNMENT 0x1000
95#define NT_FILE_ALIGNMENT    0x200
96#define NT_DEF_RESERVE       0x100000
97#define NT_DEF_COMMIT        0x1000
98
99/********************** SECTION HEADER **********************/
100
101
102struct external_scnhdr {
103	char		s_name[8];	/* section name			*/
104	char		s_paddr[4];	/* physical address, aliased s_nlib */
105	char		s_vaddr[4];	/* virtual address		*/
106	char		s_size[4];	/* section size			*/
107	char		s_scnptr[4];	/* file ptr to raw data for section */
108	char		s_relptr[4];	/* file ptr to relocation	*/
109	char		s_lnnoptr[4];	/* file ptr to line numbers	*/
110	char		s_nreloc[2];	/* number of relocation entries	*/
111	char		s_nlnno[2];	/* number of line number entries*/
112	char		s_flags[4];	/* flags			*/
113};
114
115#define	SCNHDR	struct external_scnhdr
116#define	SCNHSZ	40
117
118/*
119 * names of "special" sections
120 */
121#define _TEXT	".text"
122#define _DATA	".data"
123#define _BSS	".bss"
124#define _COMMENT ".comment"
125#define _LIB ".lib"
126
127/********************** LINE NUMBERS **********************/
128
129/* 1 line number entry for every "breakpointable" source line in a section.
130 * Line numbers are grouped on a per function basis; first entry in a function
131 * grouping will have l_lnno = 0 and in place of physical address will be the
132 * symbol table index of the function name.
133 */
134struct external_lineno {
135	union {
136		char l_symndx[4];	/* function name symbol index, iff l_lnno == 0*/
137		char l_paddr[4];	/* (physical) address of line number	*/
138	} l_addr;
139	char l_lnno[2];	/* line number		*/
140};
141
142
143#define	LINENO	struct external_lineno
144#define	LINESZ	6
145
146
147/********************** SYMBOLS **********************/
148
149#define E_SYMNMLEN	8	/* # characters in a symbol name	*/
150#define E_FILNMLEN	14	/* # characters in a file name		*/
151#define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
152
153struct external_syment
154{
155  union {
156    char e_name[E_SYMNMLEN];
157    struct {
158      char e_zeroes[4];
159      char e_offset[4];
160    } e;
161  } e;
162  char e_value[4];
163  char e_scnum[2];
164  char e_type[2];
165  char e_sclass[1];
166  char e_numaux[1];
167};
168
169#define N_BTMASK	(0xf)
170#define N_TMASK		(0x30)
171#define N_BTSHFT	(4)
172#define N_TSHIFT	(2)
173
174union external_auxent {
175	struct {
176		char x_tagndx[4];	/* str, un, or enum tag indx */
177		union {
178			struct {
179			    char  x_lnno[2]; /* declaration line number */
180			    char  x_size[2]; /* str/union/array size */
181			} x_lnsz;
182			char x_fsize[4];	/* size of function */
183		} x_misc;
184		union {
185			struct {		/* if ISFCN, tag, or .bb */
186			    char x_lnnoptr[4];	/* ptr to fcn line # */
187			    char x_endndx[4];	/* entry ndx past block end */
188			} x_fcn;
189			struct {		/* if ISARY, up to 4 dimen. */
190			    char x_dimen[E_DIMNUM][2];
191			} x_ary;
192		} x_fcnary;
193		char x_tvndx[2];		/* tv index */
194	} x_sym;
195
196	union {
197		char x_fname[E_FILNMLEN];
198		struct {
199			char x_zeroes[4];
200			char x_offset[4];
201		} x_n;
202	} x_file;
203
204	struct {
205		char x_scnlen[4];	/* section length */
206		char x_nreloc[2];	/* # relocation entries */
207		char x_nlinno[2];	/* # line numbers */
208		char x_checksum[4];	/* section COMDAT checksum */
209		char x_associated[2];	/* COMDAT associated section index */
210		char x_comdat[1];	/* COMDAT selection number */
211	} x_scn;
212
213        struct {
214		char x_tvfill[4];	/* tv fill value */
215		char x_tvlen[2];	/* length of .tv */
216		char x_tvran[2][2];	/* tv range */
217	} x_tv;		/* info about .tv section (in auxent of symbol .tv)) */
218
219
220};
221
222#define	SYMENT	struct external_syment
223#define	SYMESZ	18
224#define	AUXENT	union external_auxent
225#define	AUXESZ	18
226
227
228#	define _ETEXT	"etext"
229
230
231/********************** RELOCATION DIRECTIVES **********************/
232
233
234
235struct external_reloc {
236  char r_vaddr[4];
237  char r_symndx[4];
238  char r_type[2];
239};
240
241
242#define RELOC struct external_reloc
243#define RELSZ 10
244
245