Subversion Repositories Kolibri OS

Rev

Rev 647 | Details | Compare with Previous | Last modification | View Log | RSS feed

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