Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4973 right-hear 1
#ifndef __MENUET_COFF_H
2
#define __MENUET_COFF_H
3
 
4
#ifdef __cplusplus
5
extern "C" {
6
#endif
7
 
8
/********************** FILE HEADER **********************/
9
 
10
struct external_filehdr {
11
	unsigned short f_magic;		/* magic number			*/
12
	unsigned short f_nscns;		/* number of sections		*/
13
	unsigned long f_timdat;	/* time & date stamp		*/
14
	unsigned long f_symptr;	/* file pointer to symtab	*/
15
	unsigned long f_nsyms;		/* number of symtab entries	*/
16
	unsigned short f_opthdr;	/* sizeof(optional hdr)		*/
17
	unsigned short f_flags;		/* flags			*/
18
};
19
 
20
/* Bits for f_flags:
21
 *	F_RELFLG	relocation info stripped from file
22
 *	F_EXEC		file is executable (no unresolved external references)
23
 *	F_LNNO		line numbers stripped from file
24
 *	F_LSYMS		local symbols stripped from file
25
 *	F_AR32WR	file has byte ordering of an AR32WR machine (e.g. vax)
26
 */
27
 
28
#define F_RELFLG	(0x0001)
29
#define F_EXEC		(0x0002)
30
#define F_LNNO		(0x0004)
31
#define F_LSYMS		(0x0008)
32
 
33
#define	I386MAGIC	0x14c
34
#define I386AIXMAGIC	0x175
35
#define I386BADMAG(x) (((x).f_magic!=I386MAGIC) && (x).f_magic!=I386AIXMAGIC)
36
 
37
#define	FILHDR	struct external_filehdr
38
#define	FILHSZ	sizeof(FILHDR)
39
 
40
/********************** AOUT "OPTIONAL HEADER" **********************/
41
 
42
typedef struct
43
{
44
  unsigned short 	magic;		/* type of file				*/
45
  unsigned short	vstamp;		/* version stamp			*/
46
  unsigned long	tsize;		/* text size in bytes, padded to FW bdry*/
47
  unsigned long	dsize;		/* initialized data "  "		*/
48
  unsigned long	bsize;		/* uninitialized data "   "		*/
49
  unsigned long	entry;		/* entry pt.				*/
50
  unsigned long 	text_start;	/* base of text used for this file */
51
  unsigned long 	data_start;	/* base of data used for this file */
52
} AOUTHDR;
53
 
54
typedef struct gnu_aout {
55
	unsigned long info;
56
	unsigned long tsize;
57
	unsigned long dsize;
58
	unsigned long bsize;
59
	unsigned long symsize;
60
	unsigned long entry;
61
	unsigned long txrel;
62
	unsigned long dtrel;
63
} GNU_AOUT;
64
 
65
#define AOUTSZ (sizeof(AOUTHDR))
66
 
67
#define OMAGIC          0404    /* object files, eg as output */
68
#define ZMAGIC          0413    /* demand load format, eg normal ld output */
69
#define STMAGIC		0401	/* target shlib */
70
#define SHMAGIC		0443	/* host   shlib */
71
 
72
 
73
/********************** SECTION HEADER **********************/
74
 
75
struct external_scnhdr {
76
	char		s_name[8];	/* section name			*/
77
	unsigned long		s_paddr;	/* physical address, aliased s_nlib */
78
	unsigned long		s_vaddr;	/* virtual address		*/
79
	unsigned long		s_size;		/* section size			*/
80
	unsigned long		s_scnptr;	/* file ptr to raw data for section */
81
	unsigned long		s_relptr;	/* file ptr to relocation	*/
82
	unsigned long		s_lnnoptr;	/* file ptr to line numbers	*/
83
	unsigned short		s_nreloc;	/* number of relocation entries	*/
84
	unsigned short		s_nlnno;	/* number of line number entries*/
85
	unsigned long		s_flags;	/* flags			*/
86
};
87
 
88
#define	SCNHDR	struct external_scnhdr
89
#define	SCNHSZ	sizeof(SCNHDR)
90
 
91
/*
92
 * names of "special" sections
93
 */
94
#define _TEXT	".text"
95
#define _DATA	".data"
96
#define _BSS	".bss"
97
#define _COMMENT ".comment"
98
#define _LIB ".lib"
99
 
100
/*
101
 * s_flags "type"
102
 */
103
#define STYP_TEXT	 (0x0020)	/* section contains text only */
104
#define STYP_DATA	 (0x0040)	/* section contains data only */
105
#define STYP_BSS	 (0x0080)	/* section contains bss only */
106
 
107
/********************** LINE NUMBERS **********************/
108
 
109
/* 1 line number entry for every "breakpointable" source line in a section.
110
 * Line numbers are grouped on a per function basis; first entry in a function
111
 * grouping will have l_lnno = 0 and in place of physical address will be the
112
 * symbol table index of the function name.
113
 */
114
struct external_lineno {
115
	union {
116
		unsigned long l_symndx __attribute__((packed));	/* function name symbol index, iff l_lnno == 0 */
117
		unsigned long l_paddr __attribute__((packed));		/* (physical) address of line number */
118
	} l_addr;
119
	unsigned short l_lnno;						/* line number */
120
};
121
 
122
 
123
#define	LINENO	struct external_lineno
124
#define	LINESZ	sizeof(LINENO)
125
 
126
 
127
/********************** SYMBOLS **********************/
128
 
129
#define E_SYMNMLEN	8	/* # characters in a symbol name	*/
130
#define E_FILNMLEN	14	/* # characters in a file name		*/
131
#define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
132
 
133
struct external_syment
134
{
135
  union {
136
    char e_name[E_SYMNMLEN];
137
    struct {
138
      unsigned long e_zeroes __attribute__((packed));
139
      unsigned long e_offset __attribute__((packed));
140
    } e;
141
  } e;
142
  unsigned long e_value __attribute__((packed));
143
  short e_scnum;
144
  unsigned short e_type;
145
  unsigned char e_sclass;
146
  unsigned char e_numaux;
147
} __attribute__((packed));
148
 
149
#define N_BTMASK	(0xf)
150
#define N_TMASK		(0x30)
151
#define N_BTSHFT	(4)
152
#define N_TSHIFT	(2)
153
 
154
union external_auxent
155
{
156
 struct
157
 {
158
  unsigned long x_tagndx __attribute__((packed));		/* str, un, or enum tag indx */
159
  union
160
  {
161
   struct
162
   {
163
    unsigned short  x_lnno;				/* declaration line number */
164
    unsigned short  x_size; 				/* str/union/array size */
165
   } x_lnsz;
166
   unsigned long x_fsize __attribute__((packed));		/* size of function */
167
  } x_misc;
168
  union
169
  {
170
   struct
171
   {					/* if ISFCN, tag, or .bb */
172
    unsigned long x_lnnoptr __attribute__((packed));	/* ptr to fcn line # */
173
    unsigned long x_endndx __attribute__((packed));	/* entry ndx past block end */
174
   } x_fcn;
175
   struct {					/* if ISARY, up to 4 dimen. */
176
    unsigned short x_dimen[E_DIMNUM];
177
   } x_ary;
178
  } x_fcnary;
179
  unsigned short x_tvndx;						/* tv index */
180
 } x_sym;
181
 union
182
 {
183
  char x_fname[E_FILNMLEN];
184
  struct
185
  {
186
   unsigned long x_zeroes __attribute__((packed));
187
   unsigned long x_offset __attribute__((packed));
188
  } x_n;
189
 } x_file;
190
 struct
191
 {
192
  unsigned long x_scnlen __attribute__((packed));		/* section length */
193
  unsigned short x_nreloc;					/* # relocation entries */
194
  unsigned short x_nlinno;					/* # line numbers */
195
 } x_scn;
196
 struct
197
 {
198
  unsigned long x_tvfill __attribute__((packed));		/* tv fill value */
199
  unsigned short x_tvlen;						/* length of .tv */
200
  unsigned short x_tvran[2];					/* tv range */
201
 } x_tv;		/* info about .tv section (in auxent of symbol .tv)) */
202
};
203
 
204
#define	SYMENT	struct external_syment
205
#define	SYMESZ	sizeof(SYMENT)
206
#define	AUXENT	union external_auxent
207
#define	AUXESZ	sizeof(AUXENT)
208
 
209
#define _ETEXT	"etext"
210
 
211
/* Relocatable symbols have number of the section in which they are defined,
212
   or one of the following: */
213
 
214
#define N_UNDEF	((short)0)	/* undefined symbol */
215
#define N_ABS	((short)-1)	/* value of symbol is absolute */
216
#define N_DEBUG	((short)-2)	/* debugging symbol -- value is meaningless */
217
#define N_TV	((short)-3)	/* indicates symbol needs preload transfer vector */
218
#define P_TV	((short)-4)	/* indicates symbol needs postload transfer vector*/
219
 
220
/*
221
 * Type of a symbol, in low N bits of the word
222
 */
223
#define T_NULL		0
224
#define T_VOID		1	/* function argument (only used by compiler) */
225
#define T_CHAR		2	/* character		*/
226
#define T_SHORT		3	/* short integer	*/
227
#define T_INT		4	/* integer		*/
228
#define T_LONG		5	/* long integer		*/
229
#define T_FLOAT		6	/* floating point	*/
230
#define T_DOUBLE	7	/* double word		*/
231
#define T_STRUCT	8	/* structure 		*/
232
#define T_UNION		9	/* union 		*/
233
#define T_ENUM		10	/* enumeration 		*/
234
#define T_MOE		11	/* member of enumeration*/
235
#define T_UCHAR		12	/* unsigned character	*/
236
#define T_USHORT	13	/* unsigned short	*/
237
#define T_UINT		14	/* unsigned integer	*/
238
#define T_ULONG		15	/* unsigned long	*/
239
#define T_LNGDBL	16	/* long double		*/
240
 
241
/*
242
 * derived types, in n_type
243
*/
244
#define DT_NON		(0)	/* no derived type */
245
#define DT_PTR		(1)	/* pointer */
246
#define DT_FCN		(2)	/* function */
247
#define DT_ARY		(3)	/* array */
248
 
249
#define BTYPE(x)	((x) & N_BTMASK)
250
 
251
#define ISPTR(x)	(((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
252
#define ISFCN(x)	(((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
253
#define ISARY(x)	(((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
254
#define ISTAG(x)	((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
255
#define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
256
 
257
/********************** STORAGE CLASSES **********************/
258
 
259
/* This used to be defined as -1, but now n_sclass is unsigned.  */
260
#define C_EFCN		0xff	/* physical end of function	*/
261
#define C_NULL		0
262
#define C_AUTO		1	/* automatic variable		*/
263
#define C_EXT		2	/* external symbol		*/
264
#define C_STAT		3	/* static			*/
265
#define C_REG		4	/* register variable		*/
266
#define C_EXTDEF	5	/* external definition		*/
267
#define C_LABEL		6	/* label			*/
268
#define C_ULABEL	7	/* undefined label		*/
269
#define C_MOS		8	/* member of structure		*/
270
#define C_ARG		9	/* function argument		*/
271
#define C_STRTAG	10	/* structure tag		*/
272
#define C_MOU		11	/* member of union		*/
273
#define C_UNTAG		12	/* union tag			*/
274
#define C_TPDEF		13	/* type definition		*/
275
#define C_USTATIC	14	/* undefined static		*/
276
#define C_ENTAG		15	/* enumeration tag		*/
277
#define C_MOE		16	/* member of enumeration	*/
278
#define C_REGPARM	17	/* register parameter		*/
279
#define C_FIELD		18	/* bit field			*/
280
#define C_AUTOARG	19	/* auto argument		*/
281
#define C_LASTENT	20	/* dummy entry (end of block)	*/
282
#define C_BLOCK		100	/* ".bb" or ".eb"		*/
283
#define C_FCN		101	/* ".bf" or ".ef"		*/
284
#define C_EOS		102	/* end of structure		*/
285
#define C_FILE		103	/* file name			*/
286
#define C_LINE		104	/* line # reformatted as symbol table entry */
287
#define C_ALIAS	 	105	/* duplicate tag		*/
288
#define C_HIDDEN	106	/* ext symbol in dmert public lib */
289
 
290
/********************** RELOCATION DIRECTIVES **********************/
291
 
292
struct external_reloc {
293
  unsigned long r_vaddr __attribute__((packed));
294
  unsigned long r_symndx __attribute__((packed));
295
  unsigned short r_type;
296
};
297
 
298
 
299
#define RELOC struct external_reloc
300
#define RELSZ sizeof(RELOC)
301
 
302
#define RELOC_REL32	20	/* 32-bit PC-relative address */
303
#define RELOC_ADDR32	6	/* 32-bit absolute address */
304
 
305
#define DEFAULT_DATA_SECTION_ALIGNMENT 4
306
#define DEFAULT_BSS_SECTION_ALIGNMENT 4
307
#define DEFAULT_TEXT_SECTION_ALIGNMENT 4
308
/* For new sections we havn't heard of before */
309
#define DEFAULT_SECTION_ALIGNMENT 4
310
 
311
#ifdef __cplusplus
312
}
313
#endif
314
 
315
#endif