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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [cpu/] [common/] [coff.h] - Blame information for rev 275

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

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