forked from swizl/tinycc_zh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coff.h
446 lines (392 loc) · 21.9 KB
/
coff.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/**************************************************************************/
/* COFF.H */
/* COFF data structures and related definitions used by the linker */
/**************************************************************************/
/*------------------------------------------------------------------------*/
/* COFF FILE HEADER */
/*------------------------------------------------------------------------*/
½á¹¹ filehdr {
ÎÞ·û ¶Ì f_magic; /* magic number */
ÎÞ·û ¶Ì f_nscns; /* number of sections */
³¤ f_timdat; /* time & date stamp */
³¤ f_symptr; /* file pointer to symtab */
³¤ f_nsyms; /* number of symtab entries */
ÎÞ·û ¶Ì f_opthdr; /* Ç󳤶È(optional hdr) */
ÎÞ·û ¶Ì f_flags; /* flags */
ÎÞ·û ¶Ì f_TargetID; /* for C6x = 0x0099 */
};
/*------------------------------------------------------------------------*/
/* File header flags */
/*------------------------------------------------------------------------*/
#¶¨Òå F_RELFLG 0x01 /* relocation info stripped from file */
#¶¨Òå F_EXEC 0x02 /* file is executable (no unresolved refs) */
#¶¨Òå F_LNNO 0x04 /* line numbers stripped from file */
#¶¨Òå F_LSYMS 0x08 /* local symbols stripped from file */
#¶¨Òå F_GSP10 0x10 /* 34010 version */
#¶¨Òå F_GSP20 0x20 /* 34020 version */
#¶¨Òå F_SWABD 0x40 /* bytes swabbed (in names) */
#¶¨Òå F_AR16WR 0x80 /* byte ordering of an AR16WR (PDP-11) */
#¶¨Òå F_LITTLE 0x100 /* byte ordering of an AR32WR (vax) */
#¶¨Òå F_BIG 0x200 /* byte ordering of an AR32W (3B, maxi) */
#¶¨Òå F_PATCH 0x400 /* contains "patch" list in optional header */
#¶¨Òå F_NODF 0x400
#¶¨Òå F_VERSION (F_GSP10 | F_GSP20)
#¶¨Òå F_BYTE_ORDER (F_LITTLE | F_BIG)
#¶¨Òå FILHDR ½á¹¹ filehdr
/* #¶¨Òå FILHSZ Ç󳤶È(FILHDR) */
#¶¨Òå FILHSZ 22 /* above rounds to align on 4 bytes which causes problems */
#¶¨Òå COFF_C67_MAGIC 0x00c2
/*------------------------------------------------------------------------*/
/* Macros to recognize magic numbers */
/*------------------------------------------------------------------------*/
#¶¨Òå ISMAGIC(x) (((ÎÞ·û ¶Ì)(x))==(ÎÞ·û ¶Ì)magic)
#¶¨Òå ISARCHIVE(x) ((((ÎÞ·û ¶Ì)(x))==(ÎÞ·û ¶Ì)ARTYPE))
#¶¨Òå BADMAGIC(x) (((ÎÞ·û ¶Ì)(x) & 0x8080) && !ISMAGIC(x))
/*------------------------------------------------------------------------*/
/* OPTIONAL FILE HEADER */
/*------------------------------------------------------------------------*/
ÀàÐͶ¨Òå ½á¹¹ aouthdr {
¶Ì magic; /* see magic.h */
¶Ì vstamp; /* version stamp */
³¤ tsize; /* text size in bytes, padded to FW bdry*/
³¤ dsize; /* initialized data " " */
³¤ bsize; /* uninitialized data " " */
³¤ entrypt; /* entry pt. */
³¤ text_start; /* base of text used for this file */
³¤ data_start; /* base of data used for this file */
} AOUTHDR;
#¶¨Òå AOUTSZ Ç󳤶È(AOUTHDR)
/*----------------------------------------------------------------------*/
/* When a UNIX aout header is to be built in the optional header, */
/* the following magic numbers can appear in that header: */
/* */
/* AOUT1MAGIC : default : readonly sharable text segment */
/* AOUT2MAGIC: : writable text segment */
/* PAGEMAGIC : : configured for paging */
/*----------------------------------------------------------------------*/
#¶¨Òå AOUT1MAGIC 0410
#¶¨Òå AOUT2MAGIC 0407
#¶¨Òå PAGEMAGIC 0413
/*------------------------------------------------------------------------*/
/* COMMON ARCHIVE FILE STRUCTURES */
/* */
/* ARCHIVE File Organization: */
/* _______________________________________________ */
/* |__________ARCHIVE_MAGIC_STRING_______________| */
/* |__________ARCHIVE_FILE_MEMBER_1______________| */
/* | | */
/* | Archive File Header "ar_hdr" | */
/* |.............................................| */
/* | Member Contents | */
/* | 1. External symbol directory | */
/* | 2. Text file | */
/* |_____________________________________________| */
/* |________ARCHIVE_FILE_MEMBER_2________________| */
/* | "ar_hdr" | */
/* |.............................................| */
/* | Member Contents (.o or text file) | */
/* |_____________________________________________| */
/* | . . . | */
/* | . . . | */
/* | . . . | */
/* |_____________________________________________| */
/* |________ARCHIVE_FILE_MEMBER_n________________| */
/* | "ar_hdr" | */
/* |.............................................| */
/* | Member Contents | */
/* |_____________________________________________| */
/* */
/*------------------------------------------------------------------------*/
#¶¨Òå COFF_ARMAG "!<arch>\n"
#¶¨Òå SARMAG 8
#¶¨Òå ARFMAG "`\n"
½á¹¹ ar_hdr /* archive file member header - printable ascii */
{
×Ö ar_name[16]; /* file member name - `/' terminated */
×Ö ar_date[12]; /* file member date - decimal */
×Ö ar_uid[6]; /* file member user id - decimal */
×Ö ar_gid[6]; /* file member group id - decimal */
×Ö ar_mode[8]; /* file member mode - octal */
×Ö ar_size[10]; /* file member size - decimal */
×Ö ar_fmag[2]; /* ARFMAG - string to end header */
};
/*------------------------------------------------------------------------*/
/* SECTION HEADER */
/*------------------------------------------------------------------------*/
½á¹¹ scnhdr {
×Ö s_name[8]; /* section name */
³¤ s_paddr; /* physical address */
³¤ s_vaddr; /* virtual address */
³¤ s_size; /* section size */
³¤ s_scnptr; /* file ptr to raw data for section */
³¤ s_relptr; /* file ptr to relocation */
³¤ s_lnnoptr; /* file ptr to line numbers */
ÎÞ·û Õû s_nreloc; /* number of relocation entries */
ÎÞ·û Õû s_nlnno; /* number of line number entries */
ÎÞ·û Õû s_flags; /* flags */
ÎÞ·û ¶Ì s_reserved; /* reserved byte */
ÎÞ·û ¶Ì s_page; /* memory page id */
};
#¶¨Òå SCNHDR ½á¹¹ scnhdr
#¶¨Òå SCNHSZ Ç󳤶È(SCNHDR)
/*------------------------------------------------------------------------*/
/* Define constants for names of "special" sections */
/*------------------------------------------------------------------------*/
/* #¶¨Òå _TEXT ".text" */
#¶¨Òå _DATA ".data"
#¶¨Òå _BSS ".bss"
#¶¨Òå _CINIT ".cinit"
#¶¨Òå _TV ".tv"
/*------------------------------------------------------------------------*/
/* The low 4 bits of s_flags is used as a section "type" */
/*------------------------------------------------------------------------*/
#¶¨Òå STYP_REG 0x00 /* "regular" : allocated, relocated, loaded */
#¶¨Òå STYP_DSECT 0x01 /* "dummy" : not allocated, relocated, not loaded */
#¶¨Òå STYP_NOLOAD 0x02 /* "noload" : allocated, relocated, not loaded */
#¶¨Òå STYP_GROUP 0x04 /* "grouped" : formed of input sections */
#¶¨Òå STYP_PAD 0x08 /* "padding" : not allocated, not relocated, loaded */
#¶¨Òå STYP_COPY 0x10 /* "copy" : used for C init tables -
not allocated, relocated,
loaded; reloc & lineno
entries processed normally */
#¶¨Òå STYP_TEXT 0x20 /* section contains text only */
#¶¨Òå STYP_DATA 0x40 /* section contains data only */
#¶¨Òå STYP_BSS 0x80 /* section contains bss only */
#¶¨Òå STYP_ALIGN 0x100 /* align flag passed by old version assemblers */
#¶¨Òå ALIGN_MASK 0x0F00 /* part of s_flags that is used for align vals */
#¶¨Òå ALIGNSIZE(x) (1 << ((x & ALIGN_MASK) >> 8))
/*------------------------------------------------------------------------*/
/* RELOCATION ENTRIES */
/*------------------------------------------------------------------------*/
½á¹¹ reloc
{
³¤ r_vaddr; /* (virtual) address of reference */
¶Ì r_symndx; /* index into symbol table */
ÎÞ·û ¶Ì r_disp; /* additional bits for address calculation */
ÎÞ·û ¶Ì r_type; /* relocation type */
};
#¶¨Òå RELOC ½á¹¹ reloc
#¶¨Òå RELSZ 10 /* Ç󳤶È(RELOC) */
/*--------------------------------------------------------------------------*/
/* define all relocation types */
/*--------------------------------------------------------------------------*/
#¶¨Òå R_ABS 0 /* absolute address - no relocation */
#¶¨Òå R_DIR16 01 /* UNUSED */
#¶¨Òå R_REL16 02 /* UNUSED */
#¶¨Òå R_DIR24 04 /* UNUSED */
#¶¨Òå R_REL24 05 /* 24 bits, direct */
#¶¨Òå R_DIR32 06 /* UNUSED */
#¶¨Òå R_RELBYTE 017 /* 8 bits, direct */
#¶¨Òå R_RELWORD 020 /* 16 bits, direct */
#¶¨Òå R_RELLONG 021 /* 32 bits, direct */
#¶¨Òå R_PCRBYTE 022 /* 8 bits, PC-relative */
#¶¨Òå R_PCRWORD 023 /* 16 bits, PC-relative */
#¶¨Òå R_PCRLONG 024 /* 32 bits, PC-relative */
#¶¨Òå R_OCRLONG 030 /* GSP: 32 bits, one's complement direct */
#¶¨Òå R_GSPPCR16 031 /* GSP: 16 bits, PC relative (in words) */
#¶¨Òå R_GSPOPR32 032 /* GSP: 32 bits, direct big-endian */
#¶¨Òå R_PARTLS16 040 /* Brahma: 16 bit offset of 24 bit address*/
#¶¨Òå R_PARTMS8 041 /* Brahma: 8 bit page of 24 bit address */
#¶¨Òå R_PARTLS7 050 /* DSP: 7 bit offset of 16 bit address */
#¶¨Òå R_PARTMS9 051 /* DSP: 9 bit page of 16 bit address */
#¶¨Òå R_REL13 052 /* DSP: 13 bits, direct */
/*------------------------------------------------------------------------*/
/* LINE NUMBER ENTRIES */
/*------------------------------------------------------------------------*/
½á¹¹ lineno
{
ÁªºÏ
{
³¤ l_symndx ; /* sym. table index of function name
iff l_lnno == 0 */
³¤ l_paddr ; /* (physical) address of line number */
} l_addr ;
ÎÞ·û ¶Ì l_lnno ; /* line number */
};
#¶¨Òå LINENO ½á¹¹ lineno
#¶¨Òå LINESZ 6 /* Ç󳤶È(LINENO) */
/*------------------------------------------------------------------------*/
/* STORAGE CLASSES */
/*------------------------------------------------------------------------*/
#¶¨Òå C_EFCN -1 /* physical end of function */
#¶¨Òå C_NULL 0
#¶¨Òå C_AUTO 1 /* automatic variable */
#¶¨Òå C_EXT 2 /* external symbol */
#¶¨Òå C_STAT 3 /* static */
#¶¨Òå C_REG 4 /* register variable */
#¶¨Òå C_EXTDEF 5 /* external definition */
#¶¨Òå C_LABEL 6 /* label */
#¶¨Òå C_ULABEL 7 /* undefined label */
#¶¨Òå C_MOS 8 /* member of structure */
#¶¨Òå C_ARG 9 /* function argument */
#¶¨Òå C_STRTAG 10 /* structure tag */
#¶¨Òå C_MOU 11 /* member of union */
#¶¨Òå C_UNTAG 12 /* union tag */
#¶¨Òå C_TPDEF 13 /* type definition */
#¶¨Òå C_USTATIC 14 /* undefined static */
#¶¨Òå C_ENTAG 15 /* enumeration tag */
#¶¨Òå C_MOE 16 /* member of enumeration */
#¶¨Òå C_REGPARM 17 /* register parameter */
#¶¨Òå C_FIELD 18 /* bit field */
#¶¨Òå C_BLOCK 100 /* ".bb" or ".eb" */
#¶¨Òå C_FCN 101 /* ".bf" or ".ef" */
#¶¨Òå C_EOS 102 /* end of structure */
#¶¨Òå C_FILE 103 /* file name */
#¶¨Òå C_LINE 104 /* dummy sclass for line number entry */
#¶¨Òå C_ALIAS 105 /* duplicate tag */
#¶¨Òå C_HIDDEN 106 /* special storage class for external */
/* symbols in dmert public libraries */
/*------------------------------------------------------------------------*/
/* SYMBOL TABLE ENTRIES */
/*------------------------------------------------------------------------*/
#¶¨Òå SYMNMLEN 8 /* Number of characters in a symbol name */
#¶¨Òå FILNMLEN 14 /* Number of characters in a file name */
#¶¨Òå DIMNUM 4 /* Number of array dimensions in auxiliary entry */
½á¹¹ syment
{
ÁªºÏ
{
×Ö _n_name[SYMNMLEN]; /* old COFF version */
½á¹¹
{
³¤ _n_zeroes; /* new == 0 */
³¤ _n_offset; /* offset into string table */
} _n_n;
×Ö *_n_nptr[2]; /* allows for overlaying */
} _n;
³¤ n_value; /* value of symbol */
¶Ì n_scnum; /* section number */
ÎÞ·û ¶Ì n_type; /* type and derived type */
×Ö n_sclass; /* storage class */
×Ö n_numaux; /* number of aux. entries */
};
#¶¨Òå n_name _n._n_name
#¶¨Òå n_nptr _n._n_nptr[1]
#¶¨Òå n_zeroes _n._n_n._n_zeroes
#¶¨Òå n_offset _n._n_n._n_offset
/*------------------------------------------------------------------------*/
/* Relocatable symbols have a section number of the */
/* section in which they are defined. Otherwise, section */
/* numbers have the following meanings: */
/*------------------------------------------------------------------------*/
#¶¨Òå N_UNDEF 0 /* undefined symbol */
#¶¨Òå N_ABS -1 /* value of symbol is absolute */
#¶¨Òå N_DEBUG -2 /* special debugging symbol */
#¶¨Òå N_TV (ÎÞ·û ¶Ì)-3 /* needs transfer vector (preload) */
#¶¨Òå P_TV (ÎÞ·û ¶Ì)-4 /* needs transfer vector (postload) */
/*------------------------------------------------------------------------*/
/* The fundamental type of a symbol packed into the low */
/* 4 bits of the word. */
/*------------------------------------------------------------------------*/
#¶¨Òå _EF ".ef"
#¶¨Òå T_NULL 0 /* no type info */
#¶¨Òå T_ARG 1 /* function argument (only used by compiler) */
#¶¨Òå T_CHAR 2 /* character */
#¶¨Òå T_SHORT 3 /* short integer */
#¶¨Òå T_INT 4 /* integer */
#¶¨Òå T_LONG 5 /* long integer */
#¶¨Òå T_FLOAT 6 /* floating point */
#¶¨Òå T_DOUBLE 7 /* double word */
#¶¨Òå T_STRUCT 8 /* structure */
#¶¨Òå T_UNION 9 /* union */
#¶¨Òå T_ENUM 10 /* enumeration */
#¶¨Òå T_MOE 11 /* member of enumeration */
#¶¨Òå T_UCHAR 12 /* unsigned character */
#¶¨Òå T_USHORT 13 /* unsigned short */
#¶¨Òå T_UINT 14 /* unsigned integer */
#¶¨Òå T_ULONG 15 /* unsigned long */
/*------------------------------------------------------------------------*/
/* derived types are: */
/*------------------------------------------------------------------------*/
#¶¨Òå DT_NON 0 /* no derived type */
#¶¨Òå DT_PTR 1 /* pointer */
#¶¨Òå DT_FCN 2 /* function */
#¶¨Òå DT_ARY 3 /* array */
#¶¨Òå MKTYPE(basic, d1,d2,d3,d4,d5,d6) \
((basic) | ((d1) << 4) | ((d2) << 6) | ((d3) << 8) |\
((d4) << 10) | ((d5) << 12) | ((d6) << 14))
/*------------------------------------------------------------------------*/
/* type packing constants and macros */
/*------------------------------------------------------------------------*/
#¶¨Òå N_BTMASK_COFF 017
#¶¨Òå N_TMASK_COFF 060
#¶¨Òå N_TMASK1_COFF 0300
#¶¨Òå N_TMASK2_COFF 0360
#¶¨Òå N_BTSHFT_COFF 4
#¶¨Òå N_TSHIFT_COFF 2
#¶¨Òå BTYPE_COFF(x) ((x) & N_BTMASK_COFF)
#¶¨Òå ISINT(x) (((x) >= T_CHAR && (x) <= T_LONG) || \
((x) >= T_UCHAR && (x) <= T_ULONG) || (x) == T_ENUM)
#¶¨Òå ISFLT_COFF(x) ((x) == T_DOUBLE || (x) == T_FLOAT)
#¶¨Òå ISPTR_COFF(x) (((x) & N_TMASK_COFF) == (DT_PTR << N_BTSHFT_COFF))
#¶¨Òå ISFCN_COFF(x) (((x) & N_TMASK_COFF) == (DT_FCN << N_BTSHFT_COFF))
#¶¨Òå ISARY_COFF(x) (((x) & N_TMASK_COFF) == (DT_ARY << N_BTSHFT_COFF))
#¶¨Òå ISTAG_COFF(x) ((x)==C_STRTAG || (x)==C_UNTAG || (x)==C_ENTAG)
#¶¨Òå INCREF_COFF(x) ((((x)&~N_BTMASK_COFF)<<N_TSHIFT_COFF)|(DT_PTR<<N_BTSHFT_COFF)|(x&N_BTMASK_COFF))
#¶¨Òå DECREF_COFF(x) ((((x)>>N_TSHIFT_COFF)&~N_BTMASK_COFF)|((x)&N_BTMASK_COFF))
/*------------------------------------------------------------------------*/
/* AUXILIARY SYMBOL ENTRY */
/*------------------------------------------------------------------------*/
ÁªºÏ auxent
{
½á¹¹
{
³¤ x_tagndx; /* str, un, or enum tag indx */
ÁªºÏ
{
½á¹¹
{
ÎÞ·û ¶Ì x_lnno; /* declaration line number */
ÎÞ·û ¶Ì x_size; /* str, union, array size */
} x_lnsz;
³¤ x_fsize; /* size of function */
} x_misc;
ÁªºÏ
{
½á¹¹ /* if ISFCN, tag, or .bb */
{
³¤ x_lnnoptr; /* ptr to fcn line # */
³¤ x_endndx; /* entry ndx past block end */
} x_fcn;
½á¹¹ /* if ISARY, up to 4 dimen. */
{
ÎÞ·û ¶Ì x_dimen[DIMNUM];
} x_ary;
} x_fcnary;
ÎÞ·û ¶Ì x_regcount; /* number of registers used by func */
} x_sym;
½á¹¹
{
×Ö x_fname[FILNMLEN];
} x_file;
½á¹¹
{
³¤ x_scnlen; /* section length */
ÎÞ·û ¶Ì x_nreloc; /* number of relocation entries */
ÎÞ·û ¶Ì x_nlinno; /* number of line numbers */
} x_scn;
};
#¶¨Òå SYMENT ½á¹¹ syment
#¶¨Òå SYMESZ 18 /* Ç󳤶È(SYMENT) */
#¶¨Òå AUXENT ÁªºÏ auxent
#¶¨Òå AUXESZ 18 /* Ç󳤶È(AUXENT) */
/*------------------------------------------------------------------------*/
/* NAMES OF "SPECIAL" SYMBOLS */
/*------------------------------------------------------------------------*/
#¶¨Òå _STEXT ".text"
#¶¨Òå _ETEXT "etext"
#¶¨Òå _SDATA ".data"
#¶¨Òå _EDATA "edata"
#¶¨Òå _SBSS ".bss"
#¶¨Òå _END "end"
#¶¨Òå _CINITPTR "cinit"
/*--------------------------------------------------------------------------*/
/* ENTRY POINT SYMBOLS */
/*--------------------------------------------------------------------------*/
#¶¨Òå _START "_start"
#¶¨Òå _MAIN "_main"
/* _CSTART "_c_int00" (defined in params.h) */
#¶¨Òå _TVORIG "_tvorig"
#¶¨Òå _TORIGIN "_torigin"
#¶¨Òå _DORIGIN "_dorigin"
#¶¨Òå _SORIGIN "_sorigin"