1 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
2 #ifndef __dj_include_coff_h_
3 #define __dj_include_coff_h_
9 //#ifndef __dj_ENFORCE_ANSI_FREESTANDING
11 //#ifndef __STRICT_ANSI__
13 //#ifndef _POSIX_SOURCE
15 /*** coff information for Intel 386/486. */
17 /********************** FILE HEADER **********************/
19 struct external_filehdr
{
20 unsigned short f_magic
; /* magic number */
21 unsigned short f_nscns
; /* number of sections */
22 unsigned long f_timdat
; /* time & date stamp */
23 unsigned long f_symptr
; /* file pointer to symtab */
24 unsigned long f_nsyms
; /* number of symtab entries */
25 unsigned short f_opthdr
; /* sizeof(optional hdr) */
26 unsigned short f_flags
; /* flags */
31 * F_RELFLG relocation info stripped from file
32 * F_EXEC file is executable (no unresolved external references)
33 * F_LNNO line numbers stripped from file
34 * F_LSYMS local symbols stripped from file
35 * F_AR32WR file has byte ordering of an AR32WR machine (e.g. vax)
38 #define F_RELFLG (0x0001)
39 #define F_EXEC (0x0002)
40 #define F_LNNO (0x0004)
41 #define F_LSYMS (0x0008)
45 #define I386MAGIC 0x14c
46 #define I386AIXMAGIC 0x175
47 #define I386BADMAG(x) (((x).f_magic!=I386MAGIC) && (x).f_magic!=I386AIXMAGIC)
50 #define FILHDR struct external_filehdr
51 #define FILHSZ sizeof(FILHDR)
54 /********************** AOUT "OPTIONAL HEADER" **********************/
59 unsigned short magic
; /* type of file */
60 unsigned short vstamp
; /* version stamp */
61 unsigned long tsize
; /* text size in bytes, padded to FW bdry*/
62 unsigned long dsize
; /* initialized data " " */
63 unsigned long bsize
; /* uninitialized data " " */
64 unsigned long entry
; /* entry pt. */
65 unsigned long text_start
; /* base of text used for this file */
66 unsigned long data_start
; /* base of data used for this file */
71 typedef struct gnu_aout
{
76 unsigned long symsize
;
82 #define AOUTSZ (sizeof(AOUTHDR))
84 #define OMAGIC 0404 /* object files, eg as output */
85 #define ZMAGIC 0413 /* demand load format, eg normal ld output */
86 #define STMAGIC 0401 /* target shlib */
87 #define SHMAGIC 0443 /* host shlib */
90 /********************** SECTION HEADER **********************/
93 struct external_scnhdr
{
94 char s_name
[8]; /* section name */
95 unsigned long s_paddr
; /* physical address, aliased s_nlib */
96 unsigned long s_vaddr
; /* virtual address */
97 unsigned long s_size
; /* section size */
98 unsigned long s_scnptr
; /* file ptr to raw data for section */
99 unsigned long s_relptr
; /* file ptr to relocation */
100 unsigned long s_lnnoptr
; /* file ptr to line numbers */
101 unsigned short s_nreloc
; /* number of relocation entries */
102 unsigned short s_nlnno
; /* number of line number entries*/
103 unsigned long s_flags
; /* flags */
106 #define SCNHDR struct external_scnhdr
107 #define SCNHSZ sizeof(SCNHDR)
110 * names of "special" sections
112 #define _TEXT ".text"
113 #define _DATA ".data"
115 #define _COMMENT ".comment"
121 #define STYP_TEXT (0x0020) /* section contains text only */
122 #define STYP_DATA (0x0040) /* section contains data only */
123 #define STYP_BSS (0x0080) /* section contains bss only */
125 /********************** LINE NUMBERS **********************/
127 /* 1 line number entry for every "breakpointable" source line in a section.
128 * Line numbers are grouped on a per function basis; first entry in a function
129 * grouping will have l_lnno = 0 and in place of physical address will be the
130 * symbol table index of the function name.
132 struct external_lineno
{
134 unsigned long l_symndx
__attribute__((packed
)); /* function name symbol index, iff l_lnno == 0 */
135 unsigned long l_paddr
__attribute__((packed
)); /* (physical) address of line number */
137 unsigned short l_lnno
; /* line number */
141 #define LINENO struct external_lineno
142 #define LINESZ sizeof(LINENO)
145 /********************** SYMBOLS **********************/
147 #define E_SYMNMLEN 8 /* # characters in a symbol name */
148 #define E_FILNMLEN 14 /* # characters in a file name */
149 #define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
151 struct external_syment
154 char e_name
[E_SYMNMLEN
];
156 unsigned long e_zeroes
__attribute__((packed
));
157 unsigned long e_offset
__attribute__((packed
));
160 unsigned long e_value
__attribute__((packed
));
162 unsigned short e_type
;
163 unsigned char e_sclass
;
164 unsigned char e_numaux
;
167 #define N_BTMASK (0xf)
168 #define N_TMASK (0x30)
172 union external_auxent
{
174 unsigned long x_tagndx
__attribute__((packed
)); /* str, un, or enum tag indx */
177 unsigned short x_lnno
; /* declaration line number */
178 unsigned short x_size
; /* str/union/array size */
180 unsigned long x_fsize
__attribute__((packed
)); /* size of function */
183 struct { /* if ISFCN, tag, or .bb */
184 unsigned long x_lnnoptr
__attribute__((packed
)); /* ptr to fcn line # */
185 unsigned long x_endndx
__attribute__((packed
)); /* entry ndx past block end */
187 struct { /* if ISARY, up to 4 dimen. */
188 unsigned short x_dimen
[E_DIMNUM
];
191 unsigned short x_tvndx
; /* tv index */
195 char x_fname
[E_FILNMLEN
];
197 unsigned long x_zeroes
__attribute__((packed
));
198 unsigned long x_offset
__attribute__((packed
));
203 unsigned long x_scnlen
__attribute__((packed
)); /* section length */
204 unsigned short x_nreloc
; /* # relocation entries */
205 unsigned short x_nlinno
; /* # line numbers */
209 unsigned long x_tvfill
__attribute__((packed
)); /* tv fill value */
210 unsigned short x_tvlen
; /* length of .tv */
211 unsigned short x_tvran
[2]; /* tv range */
212 } x_tv
; /* info about .tv section (in auxent of symbol .tv)) */
217 #define SYMENT struct external_syment
218 #define SYMESZ sizeof(SYMENT)
219 #define AUXENT union external_auxent
220 #define AUXESZ sizeof(AUXENT)
223 # define _ETEXT "etext"
226 /* Relocatable symbols have number of the section in which they are defined,
227 or one of the following: */
229 #define N_UNDEF ((short)0) /* undefined symbol */
230 #define N_ABS ((short)-1) /* value of symbol is absolute */
231 #define N_DEBUG ((short)-2) /* debugging symbol -- value is meaningless */
232 #define N_TV ((short)-3) /* indicates symbol needs preload transfer vector */
233 #define P_TV ((short)-4) /* indicates symbol needs postload transfer vector*/
236 * Type of a symbol, in low N bits of the word
239 #define T_VOID 1 /* function argument (only used by compiler) */
240 #define T_CHAR 2 /* character */
241 #define T_SHORT 3 /* short integer */
242 #define T_INT 4 /* integer */
243 #define T_LONG 5 /* long integer */
244 #define T_FLOAT 6 /* floating point */
245 #define T_DOUBLE 7 /* double word */
246 #define T_STRUCT 8 /* structure */
247 #define T_UNION 9 /* union */
248 #define T_ENUM 10 /* enumeration */
249 #define T_MOE 11 /* member of enumeration*/
250 #define T_UCHAR 12 /* unsigned character */
251 #define T_USHORT 13 /* unsigned short */
252 #define T_UINT 14 /* unsigned integer */
253 #define T_ULONG 15 /* unsigned long */
254 #define T_LNGDBL 16 /* long double */
257 * derived types, in n_type
259 #define DT_NON (0) /* no derived type */
260 #define DT_PTR (1) /* pointer */
261 #define DT_FCN (2) /* function */
262 #define DT_ARY (3) /* array */
264 #define BTYPE(x) ((x) & N_BTMASK)
266 #define ISPTR(x) (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
267 #define ISFCN(x) (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
268 #define ISARY(x) (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
269 #define ISTAG(x) ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
270 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
272 /********************** STORAGE CLASSES **********************/
274 /* This used to be defined as -1, but now n_sclass is unsigned. */
275 #define C_EFCN 0xff /* physical end of function */
277 #define C_AUTO 1 /* automatic variable */
278 #define C_EXT 2 /* external symbol */
279 #define C_STAT 3 /* static */
280 #define C_REG 4 /* register variable */
281 #define C_EXTDEF 5 /* external definition */
282 #define C_LABEL 6 /* label */
283 #define C_ULABEL 7 /* undefined label */
284 #define C_MOS 8 /* member of structure */
285 #define C_ARG 9 /* function argument */
286 #define C_STRTAG 10 /* structure tag */
287 #define C_MOU 11 /* member of union */
288 #define C_UNTAG 12 /* union tag */
289 #define C_TPDEF 13 /* type definition */
290 #define C_USTATIC 14 /* undefined static */
291 #define C_ENTAG 15 /* enumeration tag */
292 #define C_MOE 16 /* member of enumeration */
293 #define C_REGPARM 17 /* register parameter */
294 #define C_FIELD 18 /* bit field */
295 #define C_AUTOARG 19 /* auto argument */
296 #define C_LASTENT 20 /* dummy entry (end of block) */
297 #define C_BLOCK 100 /* ".bb" or ".eb" */
298 #define C_FCN 101 /* ".bf" or ".ef" */
299 #define C_EOS 102 /* end of structure */
300 #define C_FILE 103 /* file name */
301 #define C_LINE 104 /* line # reformatted as symbol table entry */
302 #define C_ALIAS 105 /* duplicate tag */
303 #define C_HIDDEN 106 /* ext symbol in dmert public lib */
305 /********************** RELOCATION DIRECTIVES **********************/
309 struct external_reloc
{
310 unsigned long r_vaddr
__attribute__((packed
));
311 unsigned long r_symndx
__attribute__((packed
));
312 unsigned short r_type
;
316 #define RELOC struct external_reloc
317 #define RELSZ sizeof(RELOC)
319 #define RELOC_REL32 20 /* 32-bit PC-relative address */
320 #define RELOC_ADDR32 6 /* 32-bit absolute address */
322 #define DEFAULT_DATA_SECTION_ALIGNMENT 4
323 #define DEFAULT_BSS_SECTION_ALIGNMENT 4
324 #define DEFAULT_TEXT_SECTION_ALIGNMENT 4
325 /* For new sections we havn't heard of before */
326 #define DEFAULT_SECTION_ALIGNMENT 4
328 //#endif /* !_POSIX_SOURCE */
329 //#endif /* !__STRICT_ANSI__ */
330 //#endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
332 #ifndef __dj_ENFORCE_FUNCTION_CALLS
333 #endif /* !__dj_ENFORCE_FUNCTION_CALLS */
339 #endif /* !__dj_include_coff_h_ */