OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [include/] [coff.h] - Blame information for rev 120

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 51 julius
 
2
/* This file is derived from the GAS 2.1.4 assembler control file.
3
   The GAS product is under the GNU Public License, version 2 or later.
4
   As such, this file is also under that license.
5
 
6
   If the file format changes in the COFF object, this file should be
7
   subsequently updated to reflect the changes.
8
 
9
   The actual loader module only uses a few of these structures. The full
10
   set is documented here because I received the full set. If you wish
11
   more information about COFF, then O'Reilly has a very excellent book.
12
*/
13
 
14
 
15
#define  E_SYMNMLEN  8   /* Number of characters in a symbol name         */
16
#define  E_FILNMLEN 14   /* Number of characters in a file name           */
17
#define  E_DIMNUM    4   /* Number of array dimensions in auxiliary entry */
18
 
19
/*
20
 * These defines are byte order independent. There is no alignment of fields
21
 * permitted in the structures. Therefore they are declared as characters
22
 * and the values loaded from the character positions. It also makes it
23
 * nice to have it "endian" independent.
24
 */
25
#if !defined(WORDS_BIGENDIAN)
26
/* Load a short int from the following tables with little-endian formats */
27
#define COFF_SHORT_L SWAP_ENDIAN_SHORT
28
/* Load a long int from the following tables with little-endian formats */
29
#define COFF_LONG_L SWAP_ENDIAN_LONG
30
/* Load a short int from the following tables with big-endian formats */
31
#define COFF_SHORT_H KEEP_ENDIAN_SHORT
32
/* Load a long int from the following tables with big-endian formats */
33
#define COFF_LONG_H KEEP_ENDIAN_LONG
34
#else
35
#define COFF_SHORT_L KEEP_ENDIAN_SHORT
36
#define COFF_LONG_L KEEP_ENDIAN_LONG
37
#define COFF_SHORT_H SWAP_ENDIAN_SHORT
38
#define COFF_LONG_H SWAP_ENDIAN_LONG
39
#endif
40
 
41
#define SWAP_ENDIAN_SHORT(ps) ((short)(((unsigned short)((unsigned char)ps[1])<<8)|\
42
                                  ((unsigned short)((unsigned char)ps[0]))))
43
 
44
#define SWAP_ENDIAN_LONG(ps) (((long)(((unsigned long)((unsigned char)ps[3])<<24) |\
45
                                 ((unsigned long)((unsigned char)ps[2])<<16) |\
46
                                 ((unsigned long)((unsigned char)ps[1])<<8)  |\
47
                                 ((unsigned long)((unsigned char)ps[0])))))
48
 
49
#define KEEP_ENDIAN_SHORT(ps) ((short)(((unsigned short)((unsigned char)ps[0])<<8)|\
50
                                  ((unsigned short)((unsigned char)ps[1]))))
51
 
52
#define KEEP_ENDIAN_LONG(ps) (((long)(((unsigned long)((unsigned char)ps[0])<<24) |\
53
                                 ((unsigned long)((unsigned char)ps[1])<<16) |\
54
                                 ((unsigned long)((unsigned char)ps[2])<<8)  |\
55
                                 ((unsigned long)((unsigned char)ps[3])))))
56
 
57
/* These may be overridden later by brain dead implementations which generate
58
   a big-endian header with little-endian data. In that case, generate a
59
   replacement macro which tests a flag and uses either of the two above
60
   as appropriate. */
61
 
62
#define COFF_LONG(v)   COFF_LONG_L(v)
63
#define COFF_SHORT(v)  COFF_SHORT_L(v)
64
 
65
/*** coff information for Intel 386/486.  */
66
 
67
 
68
/*
69
 *   Bits for f_flags:
70
 *
71
 *      F_RELFLG        relocation info stripped from file
72
 *      F_EXEC          file is executable  (i.e. no unresolved external
73
 *                      references)
74
 *      F_LNNO          line numbers stripped from file
75
 *      F_LSYMS         local symbols stripped from file
76
 *      F_MINMAL        this is a minimal object file (".m") output of fextract
77
 *      F_UPDATE        this is a fully bound update file, output of ogen
78
 *      F_SWABD         this file has had its bytes swabbed (in names)
79
 *      F_AR16WR        this file has the byte ordering of an AR16WR
80
 *                      (e.g. 11/70) machine
81
 *      F_AR32WR        this file has the byte ordering of an AR32WR machine
82
 *                      (e.g. vax and iNTEL 386)
83
 *      F_AR32W         this file has the byte ordering of an AR32W machine
84
 *                      (e.g. 3b,maxi)
85
 *      F_PATCH         file contains "patch" list in optional header
86
 *      F_NODF          (minimal file only) no decision functions for
87
 *                      replaced functions
88
 */
89
 
90
#define  COFF_F_RELFLG          0000001
91
#define  COFF_F_EXEC            0000002
92
#define  COFF_F_LNNO            0000004
93
#define  COFF_F_LSYMS           0000010
94
#define  COFF_F_MINMAL          0000020
95
#define  COFF_F_UPDATE          0000040
96
#define  COFF_F_SWABD           0000100
97
#define  COFF_F_AR16WR          0000200
98
#define  COFF_F_AR32WR          0000400
99
#define  COFF_F_AR32W           0001000
100
#define  COFF_F_PATCH           0002000
101
#define  COFF_F_NODF            0002000
102
 
103
#define COFF_I386MAGIC          0x14c   /* Linux's system    */
104
 
105
#if 0   /* Perhaps, someday, these formats may be used.      */
106
#define COFF_I386PTXMAGIC       0x154
107
#define COFF_I386AIXMAGIC       0x175   /* IBM's AIX system  */
108
#define COFF_I386BADMAG(x) ((COFF_SHORT((x).f_magic) != COFF_I386MAGIC) \
109
                          && COFF_SHORT((x).f_magic) != COFF_I386PTXMAGIC \
110
                          && COFF_SHORT((x).f_magic) != COFF_I386AIXMAGIC)
111
#else
112
#define COFF_I386BADMAG(x) (COFF_SHORT((x).f_magic) != COFF_I386MAGIC)
113
#endif
114
 
115
/********************** FILE HEADER **********************/
116
 
117
struct coff_filehdr
118
{
119
  char f_magic[2];      // magic number                 
120
  char f_nscns[2];      // number of sections           
121
  char f_timdat[4];     // time & date stamp            
122
  char f_symptr[4];     // file pointer to symtab       
123
  char f_nsyms[4];      // number of symtab entries     
124
  char f_opthdr[2];     // sizeof(optional hdr)         
125
  char f_flags[2];      // flags                        
126
};
127
 
128
#define COFF_FILHDR     struct coff_filehdr
129
#define COFF_FILHSZ     sizeof(COFF_FILHDR)
130
 
131
/********************** AOUT "OPTIONAL HEADER" **********************/
132
 
133
/* Linux COFF must have this "optional" header. Standard COFF has no entry
134
   location for the "entry" point. They normally would start with the first
135
   location of the .text section. This is not a good idea for linux. So,
136
   the use of this "optional" header is not optional. It is required.
137
 
138
   Do not be tempted to assume that the size of the optional header is
139
   a constant and simply index the next byte by the size of this structure.
140
   Use the 'f_opthdr' field in the main coff header for the size of the
141
   structure actually written to the file!!
142
*/
143
 
144
//typedef struct 
145
struct COFF_aouthdr
146
{
147
  char  magic[2];               /* type of file                          */
148
  char  vstamp[2];              /* version stamp                         */
149
  char  tsize[4];               /* text size in bytes, padded to FW bdry */
150
  char  dsize[4];               /* initialized   data "   "              */
151
  char  bsize[4];               /* uninitialized data "   "              */
152
  char  entry[4];               /* entry pt.                             */
153
  char  text_start[4];          /* base of text used for this file       */
154
  char  data_start[4];          /* base of data used for this file       */
155
};
156
 
157
#define COFF_AOUTHDR COFF_aouthdr
158
#define COFF_AOUTSZ (sizeof(COFF_AOUTHDR))
159
 
160
#define COFF_STMAGIC    0401
161
#define COFF_OMAGIC     0404
162
#define COFF_JMAGIC     0407    /* dirty text and data image, can't share  */
163
#define COFF_DMAGIC     0410    /* dirty text segment, data aligned        */
164
#define COFF_ZMAGIC     0413    /* The proper magic number for executables  */
165
#define COFF_SHMAGIC    0443    /* shared library header                   */
166
 
167
/********************** STORAGE CLASSES **********************/
168
 
169
/* This used to be defined as -1, but now n_sclass is unsigned.  */
170
#define C_EFCN          0xff    /* physical end of function     */
171
#define C_NULL          0
172
#define C_AUTO          1       /* automatic variable           */
173
#define C_EXT           2       /* external symbol              */
174
#define C_STAT          3       /* static                       */
175
#define C_REG           4       /* register variable            */
176
#define C_EXTDEF        5       /* external definition          */
177
#define C_LABEL         6       /* label                        */
178
#define C_ULABEL        7       /* undefined label              */
179
#define C_MOS           8       /* member of structure          */
180
#define C_ARG           9       /* function argument            */
181
#define C_STRTAG        10      /* structure tag                */
182
#define C_MOU           11      /* member of union              */
183
#define C_UNTAG         12      /* union tag                    */
184
#define C_TPDEF         13      /* type definition              */
185
#define C_USTATIC       14      /* undefined static             */
186
#define C_ENTAG         15      /* enumeration tag              */
187
#define C_MOE           16      /* member of enumeration        */
188
#define C_REGPARM       17      /* register parameter           */
189
#define C_FIELD         18      /* bit field                    */
190
#define C_AUTOARG       19      /* auto argument                */
191
#define C_LASTENT       20      /* dummy entry (end of block)   */
192
#define C_BLOCK         100     /* ".bb" or ".eb"               */
193
#define C_FCN           101     /* ".bf" or ".ef"               */
194
#define C_EOS           102     /* end of structure             */
195
#define C_FILE          103     /* file name                    */
196
#define C_LINE          104     /* line # reformatted as symbol table entry */
197
#define C_ALIAS         105     /* duplicate tag                */
198
#define C_HIDDEN        106     /* ext symbol in dmert public lib */
199
 
200
#define C_WEAKEXT       127     /* weak symbol -- GNU extension */
201
 
202
/* New storage classes for TI COFF */
203
#define C_UEXT          19      /* Tentative external definition */
204
#define C_STATLAB       20      /* Static load time label */
205
#define C_EXTLAB        21      /* External load time label */
206
#define C_SYSTEM        23      /* System Wide variable */
207
 
208
/* New storage classes for WINDOWS_NT   */
209
#define C_SECTION       104     /* section name */
210
#define C_NT_WEAK       105     /* weak external */
211
 
212
 /* New storage classes for 80960 */
213
 
214
/* C_LEAFPROC is obsolete.  Use C_LEAFEXT or C_LEAFSTAT */
215
#define C_LEAFPROC      108     /* Leaf procedure, "call" via BAL */
216
 
217
#define C_SCALL         107     /* Procedure reachable via system call */
218
#define C_LEAFEXT       108     /* External leaf */
219
#define C_LEAFSTAT      113     /* Static leaf */
220
#define C_OPTVAR        109     /* Optimized variable           */
221
#define C_DEFINE        110     /* Preprocessor #define         */
222
#define C_PRAGMA        111     /* Advice to compiler or linker */
223
#define C_SEGMENT       112     /* 80960 segment name           */
224
 
225
  /* Storage classes for m88k */
226
#define C_SHADOW        107     /* shadow symbol                */
227
#define C_VERSION       108     /* coff version symbol          */
228
 
229
 /* New storage classes for RS/6000 */
230
#define C_HIDEXT        107     /* Un-named external symbol */
231
#define C_BINCL         108     /* Marks beginning of include file */
232
#define C_EINCL         109     /* Marks ending of include file */
233
 
234
 /* storage classes for stab symbols for RS/6000 */
235
#define C_GSYM          (0x80)
236
#define C_LSYM          (0x81)
237
#define C_PSYM          (0x82)
238
#define C_RSYM          (0x83)
239
#define C_RPSYM         (0x84)
240
#define C_STSYM         (0x85)
241
#define C_TCSYM         (0x86)
242
#define C_BCOMM         (0x87)
243
#define C_ECOML         (0x88)
244
#define C_ECOMM         (0x89)
245
#define C_DECL          (0x8c)
246
#define C_ENTRY         (0x8d)
247
#define C_FUN           (0x8e)
248
#define C_BSTAT         (0x8f)
249
#define C_ESTAT         (0x90)
250
 
251
/* Storage classes for Thumb symbols */
252
#define C_THUMBEXT      (128 + C_EXT)           /* 130 */
253
#define C_THUMBSTAT     (128 + C_STAT)          /* 131 */
254
#define C_THUMBLABEL    (128 + C_LABEL)         /* 134 */
255
#define C_THUMBEXTFUNC  (C_THUMBEXT  + 20)      /* 150 */
256
#define C_THUMBSTATFUNC (C_THUMBSTAT + 20)      /* 151 */
257
 
258
/********************** SECTION HEADER **********************/
259
 
260
struct COFF_scnhdr {
261
  char          s_name[8];      /* section name                     */
262
  char          s_paddr[4];     /* physical address, aliased s_nlib */
263
  char          s_vaddr[4];     /* virtual address                  */
264
  char          s_size[4];      /* section size                     */
265
  char          s_scnptr[4];    /* file ptr to raw data for section */
266
  char          s_relptr[4];    /* file ptr to relocation           */
267
  char          s_lnnoptr[4];   /* file ptr to line numbers         */
268
  char          s_nreloc[2];    /* number of relocation entries     */
269
  char          s_nlnno[2];     /* number of line number entries    */
270
  char          s_flags[4];     /* flags                            */
271
};
272
 
273
#define COFF_SCNHDR     struct COFF_scnhdr
274
#define COFF_SCNHSZ     sizeof(COFF_SCNHDR)
275
 
276
/*
277
 * names of "special" sections
278
 */
279
 
280
#define COFF_TEXT       ".text"
281
#define COFF_DATA       ".data"
282
#define COFF_BSS        ".bss"
283
#define COFF_COMMENT    ".comment"
284
#define COFF_LIB        ".lib"
285
 
286
#define COFF_SECT_TEXT  0      /* Section for instruction code             */
287
#define COFF_SECT_DATA  1      /* Section for initialized globals          */
288
#define COFF_SECT_BSS   2      /* Section for un-initialized globals       */
289
#define COFF_SECT_REQD  3      /* Minimum number of sections for good file */
290
 
291
#define COFF_STYP_REG     0x00 /* regular segment                          */
292
#define COFF_STYP_DSECT   0x01 /* dummy segment                            */
293
#define COFF_STYP_NOLOAD  0x02 /* no-load segment                          */
294
#define COFF_STYP_GROUP   0x04 /* group segment                            */
295
#define COFF_STYP_PAD     0x08 /* .pad segment                             */
296
#define COFF_STYP_COPY    0x10 /* copy section                             */
297
#define COFF_STYP_TEXT    0x20 /* .text segment                            */
298
#define COFF_STYP_DATA    0x40 /* .data segment                            */
299
#define COFF_STYP_BSS     0x80 /* .bss segment                             */
300
#define COFF_STYP_INFO   0x200 /* .comment section                         */
301
#define COFF_STYP_OVER   0x400 /* overlay section                          */
302
#define COFF_STYP_LIB    0x800 /* library section                          */
303
 
304
/*
305
 * Shared libraries have the following section header in the data field for
306
 * each library.
307
 */
308
 
309
struct COFF_slib {
310
  char          sl_entsz[4];    /* Size of this entry               */
311
  char          sl_pathndx[4];  /* size of the header field         */
312
};
313
 
314
#define COFF_SLIBHD     struct COFF_slib
315
#define COFF_SLIBSZ     sizeof(COFF_SLIBHD)
316
 
317
/********************** LINE NUMBERS **********************/
318
 
319
/* 1 line number entry for every "breakpointable" source line in a section.
320
 * Line numbers are grouped on a per function basis; first entry in a function
321
 * grouping will have l_lnno = 0 and in place of physical address will be the
322
 * symbol table index of the function name.
323
 */
324
 
325
struct COFF_lineno {
326
  union {
327
    char l_symndx[4];   /* function name symbol index, iff l_lnno == 0*/
328
    char l_paddr[4];    /* (physical) address of line number    */
329
  } l_addr;
330
  char l_lnno[2];       /* line number          */
331
};
332
 
333
#define COFF_LINENO     struct COFF_lineno
334
#define COFF_LINESZ     6
335
 
336
/********************** SYMBOLS **********************/
337
 
338
#define COFF_E_SYMNMLEN  8      /* # characters in a short symbol name  */
339
#define COFF_E_FILNMLEN 14      /* # characters in a file name          */
340
#define COFF_E_DIMNUM    4      /* # array dimensions in auxiliary entry */
341
 
342
/*
343
 *  All symbols and sections have the following definition
344
 */
345
 
346
struct COFF_syment
347
{
348
  union {
349
    char e_name[E_SYMNMLEN];    /* Symbol name (first 8 characters) */
350
    struct {
351
      char e_zeroes[4];         /* Leading zeros */
352
      char e_offset[4];         /* Offset if this is a header section */
353
    } e;
354
  } e;
355
 
356
  char e_value[4];              /* Value (address) of the segment */
357
  char e_scnum[2];              /* Section number */
358
  char e_type[2];               /* Type of section */
359
  char e_sclass[1];             /* Loader class */
360
  char e_numaux[1];             /* Number of auxiliary entries which follow */
361
};
362
 
363
#define COFF_N_BTMASK   (0xf)   /* Mask for important class bits */
364
#define COFF_N_TMASK    (0x30)  /* Mask for important type bits  */
365
#define COFF_N_BTSHFT   (4)     /* # bits to shift class field   */
366
#define COFF_N_TSHIFT   (2)     /* # bits to shift type field    */
367
 
368
/*
369
 *  Auxiliary entries because the main table is too limiting.
370
 */
371
 
372
union COFF_auxent {
373
 
374
/*
375
 *  Debugger information
376
 */
377
 
378
  struct {
379
    char x_tagndx[4];           /* str, un, or enum tag indx */
380
    union {
381
      struct {
382
        char  x_lnno[2];        /* declaration line number */
383
        char  x_size[2];        /* str/union/array size */
384
      } x_lnsz;
385
      char x_fsize[4];          /* size of function */
386
    } x_misc;
387
 
388
    union {
389
      struct {                  /* if ISFCN, tag, or .bb */
390
        char x_lnnoptr[4];      /* ptr to fcn line # */
391
        char x_endndx[4];       /* entry ndx past block end */
392
      } x_fcn;
393
 
394
      struct {                  /* if ISARY, up to 4 dimen. */
395
        char x_dimen[E_DIMNUM][2];
396
      } x_ary;
397
    } x_fcnary;
398
 
399
    char x_tvndx[2];    /* tv index */
400
  } x_sym;
401
 
402
/*
403
 *   Source file names (debugger information)
404
 */
405
 
406
  union {
407
    char x_fname[E_FILNMLEN];
408
    struct {
409
      char x_zeroes[4];
410
      char x_offset[4];
411
    } x_n;
412
  } x_file;
413
 
414
/*
415
 *   Section information
416
 */
417
 
418
  struct {
419
    char x_scnlen[4];   /* section length */
420
    char x_nreloc[2];   /* # relocation entries */
421
    char x_nlinno[2];   /* # line numbers */
422
  } x_scn;
423
 
424
/*
425
 *   Transfer vector (branch table)
426
 */
427
 
428
  struct {
429
    char x_tvfill[4];   /* tv fill value */
430
    char x_tvlen[2];    /* length of .tv */
431
    char x_tvran[2][2]; /* tv range */
432
  } x_tv;               /* info about .tv section (in auxent of symbol .tv)) */
433
};
434
 
435
#define COFF_SYMENT     struct COFF_syment
436
#define COFF_SYMESZ     18      
437
#define COFF_AUXENT     union COFF_auxent
438
#define COFF_AUXESZ     18
439
 
440
#define COFF_ETEXT      "etext"
441
 
442
/********************** RELOCATION DIRECTIVES **********************/
443
 
444
struct COFF_reloc {
445
  char r_vaddr[4];        /* Virtual address of item    */
446
  char r_symndx[4];       /* Symbol index in the symtab */
447
  char r_type[2];         /* Relocation type            */
448
};
449
 
450
#define COFF_RELOC struct COFF_reloc
451
#define COFF_RELSZ 10
452
 
453
#define COFF_DEF_DATA_SECTION_ALIGNMENT  4
454
#define COFF_DEF_BSS_SECTION_ALIGNMENT   4
455
#define COFF_DEF_TEXT_SECTION_ALIGNMENT  4
456
 
457
/* For new sections we haven't heard of before */
458
#define COFF_DEF_SECTION_ALIGNMENT       4

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.