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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_68/] [or1ksim/] [cpu/] [common/] [coff.h] - Blame information for rev 513

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

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