Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #ifndef __dj_include_coff_h_
  3. #define __dj_include_coff_h_
  4.  
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8.  
  9. #ifndef __dj_ENFORCE_ANSI_FREESTANDING
  10.  
  11. #ifndef __STRICT_ANSI__
  12.  
  13. #ifndef _POSIX_SOURCE
  14.  
  15. /*** coff information for Intel 386/486.  */
  16.  
  17. /********************** FILE HEADER **********************/
  18.  
  19. struct external_filehdr {
  20.         unsigned short f_magic;         /* magic number                 */
  21.         unsigned short f_nscns;         /* number of sections           */
  22.         unsigned long f_timdat; /* time & date stamp            */
  23.         unsigned long f_symptr; /* file pointer to symtab       */
  24.         unsigned long f_nsyms;          /* number of symtab entries     */
  25.         unsigned short f_opthdr;        /* sizeof(optional hdr)         */
  26.         unsigned short f_flags;         /* flags                        */
  27. };
  28.  
  29.  
  30. /* Bits for f_flags:
  31.  *      F_RELFLG        relocation info stripped from file
  32.  *      F_EXEC          file is executable (no unresolved external references)
  33.  *      F_LNNO          line numbers stripped from file
  34.  *      F_LSYMS         local symbols stripped from file
  35.  *      F_AR32WR        file has byte ordering of an AR32WR machine (e.g. vax)
  36.  */
  37.  
  38. #define F_RELFLG        (0x0001)
  39. #define F_EXEC          (0x0002)
  40. #define F_LNNO          (0x0004)
  41. #define F_LSYMS         (0x0008)
  42.  
  43.  
  44.  
  45. #define I386MAGIC       0x14c
  46. #define I386AIXMAGIC    0x175
  47. #define I386BADMAG(x) (((x).f_magic!=I386MAGIC) && (x).f_magic!=I386AIXMAGIC)
  48.  
  49.  
  50. #define FILHDR  struct external_filehdr
  51. #define FILHSZ  sizeof(FILHDR)
  52.  
  53.  
  54. /********************** AOUT "OPTIONAL HEADER" **********************/
  55.  
  56.  
  57. typedef struct
  58. {
  59.   unsigned short        magic;          /* type of file                         */
  60.   unsigned short        vstamp;         /* version stamp                        */
  61.   unsigned long tsize;          /* text size in bytes, padded to FW bdry*/
  62.   unsigned long dsize;          /* initialized data "  "                */
  63.   unsigned long bsize;          /* uninitialized data "   "             */
  64.   unsigned long entry;          /* entry pt.                            */
  65.   unsigned long         text_start;     /* base of text used for this file */
  66.   unsigned long         data_start;     /* base of data used for this file */
  67. }
  68. AOUTHDR;
  69.  
  70.  
  71. typedef struct gnu_aout {
  72.         unsigned long info;
  73.         unsigned long tsize;
  74.         unsigned long dsize;
  75.         unsigned long bsize;
  76.         unsigned long symsize;
  77.         unsigned long entry;
  78.         unsigned long txrel;
  79.         unsigned long dtrel;
  80.         } GNU_AOUT;
  81.  
  82. #define AOUTSZ (sizeof(AOUTHDR))
  83.  
  84. #define OMAGIC          0404    /* object files, eg as output */
  85. #define ZMAGIC          0413    /* demand load format, eg normal ld output */
  86. #define STMAGIC         0401    /* target shlib */
  87. #define SHMAGIC         0443    /* host   shlib */
  88.  
  89.  
  90. /********************** SECTION HEADER **********************/
  91.  
  92.  
  93. struct external_scnhdr {
  94.         char            s_name[8];      /* section name                 */
  95.         unsigned long           s_paddr;        /* physical address, aliased s_nlib */
  96.         unsigned long           s_vaddr;        /* virtual address              */
  97.         unsigned long           s_size;         /* section size                 */
  98.         unsigned long           s_scnptr;       /* file ptr to raw data for section */
  99.         unsigned long           s_relptr;       /* file ptr to relocation       */
  100.         unsigned long           s_lnnoptr;      /* file ptr to line numbers     */
  101.         unsigned short          s_nreloc;       /* number of relocation entries */
  102.         unsigned short          s_nlnno;        /* number of line number entries*/
  103.         unsigned long           s_flags;        /* flags                        */
  104. };
  105.  
  106. #define SCNHDR  struct external_scnhdr
  107. #define SCNHSZ  sizeof(SCNHDR)
  108.  
  109. /*
  110.  * names of "special" sections
  111.  */
  112. #define _TEXT   ".text"
  113. #define _DATA   ".data"
  114. #define _BSS    ".bss"
  115. #define _COMMENT ".comment"
  116. #define _LIB ".lib"
  117.  
  118. /*
  119.  * s_flags "type"
  120.  */
  121. #define STYP_TEXT        (0x0020)       /* section contains text only */
  122. #define STYP_DATA        (0x0040)       /* section contains data only */
  123. #define STYP_BSS         (0x0080)       /* section contains bss only */
  124.  
  125. /********************** LINE NUMBERS **********************/
  126.  
  127. /* 1 line number entry for every "breakpointable" source line in a section.
  128.  * Line numbers are grouped on a per function basis; first entry in a function
  129.  * grouping will have l_lnno = 0 and in place of physical address will be the
  130.  * symbol table index of the function name.
  131.  */
  132. struct external_lineno {
  133.         union {
  134.                 unsigned long l_symndx __attribute__((packed)); /* function name symbol index, iff l_lnno == 0 */
  135.                 unsigned long l_paddr __attribute__((packed));          /* (physical) address of line number */
  136.         } l_addr;
  137.         unsigned short l_lnno;                                          /* line number */
  138. };
  139.  
  140.  
  141. #define LINENO  struct external_lineno
  142. #define LINESZ  sizeof(LINENO)
  143.  
  144.  
  145. /********************** SYMBOLS **********************/
  146.  
  147. #define E_SYMNMLEN      8       /* # characters in a symbol name        */
  148. #define E_FILNMLEN      14      /* # characters in a file name          */
  149. #define E_DIMNUM        4       /* # array dimensions in auxiliary entry */
  150.  
  151. struct external_syment
  152. {
  153.   union {
  154.     char e_name[E_SYMNMLEN];
  155.     struct {
  156.       unsigned long e_zeroes __attribute__((packed));
  157.       unsigned long e_offset __attribute__((packed));
  158.     } e;
  159.   } e;
  160.   unsigned long e_value __attribute__((packed));
  161.   short e_scnum;
  162.   unsigned short e_type;
  163.   unsigned char e_sclass;
  164.   unsigned char e_numaux;
  165. };
  166.  
  167. #define N_BTMASK        (0xf)
  168. #define N_TMASK         (0x30)
  169. #define N_BTSHFT        (4)
  170. #define N_TSHIFT        (2)
  171.  
  172. union external_auxent {
  173.         struct {
  174.                 unsigned long x_tagndx __attribute__((packed));         /* str, un, or enum tag indx */
  175.                 union {
  176.                         struct {
  177.                             unsigned short  x_lnno;                             /* declaration line number */
  178.                             unsigned short  x_size;                             /* str/union/array size */
  179.                         } x_lnsz;
  180.                         unsigned long x_fsize __attribute__((packed));          /* size of function */
  181.                 } x_misc;
  182.                 union {
  183.                         struct {                                        /* if ISFCN, tag, or .bb */
  184.                             unsigned long x_lnnoptr __attribute__((packed));    /* ptr to fcn line # */
  185.                             unsigned long x_endndx __attribute__((packed));     /* entry ndx past block end */
  186.                         } x_fcn;
  187.                         struct {                                        /* if ISARY, up to 4 dimen. */
  188.                             unsigned short x_dimen[E_DIMNUM];
  189.                         } x_ary;
  190.                 } x_fcnary;
  191.                 unsigned short x_tvndx;                                         /* tv index */
  192.         } x_sym;
  193.  
  194.         union {
  195.                 char x_fname[E_FILNMLEN];
  196.                 struct {
  197.                         unsigned long x_zeroes __attribute__((packed));
  198.                         unsigned long x_offset __attribute__((packed));
  199.                 } x_n;
  200.         } x_file;
  201.  
  202.         struct {
  203.                 unsigned long x_scnlen __attribute__((packed));         /* section length */
  204.                 unsigned short x_nreloc;                                        /* # relocation entries */
  205.                 unsigned short x_nlinno;                                        /* # line numbers */
  206.         } x_scn;
  207.  
  208.         struct {
  209.                 unsigned long x_tvfill __attribute__((packed));         /* tv fill value */
  210.                 unsigned short x_tvlen;                                         /* length of .tv */
  211.                 unsigned short x_tvran[2];                                      /* tv range */
  212.         } x_tv;         /* info about .tv section (in auxent of symbol .tv)) */
  213.  
  214.  
  215. };
  216.  
  217. #define SYMENT  struct external_syment
  218. #define SYMESZ  sizeof(SYMENT)
  219. #define AUXENT  union external_auxent
  220. #define AUXESZ  sizeof(AUXENT)
  221.  
  222.  
  223. #       define _ETEXT   "etext"
  224.  
  225.  
  226. /* Relocatable symbols have number of the section in which they are defined,
  227.    or one of the following: */
  228.  
  229. #define N_UNDEF ((short)0)      /* undefined symbol */
  230. #define N_ABS   ((short)-1)     /* value of symbol is absolute */
  231. #define N_DEBUG ((short)-2)     /* debugging symbol -- value is meaningless */
  232. #define N_TV    ((short)-3)     /* indicates symbol needs preload transfer vector */
  233. #define P_TV    ((short)-4)     /* indicates symbol needs postload transfer vector*/
  234.  
  235. /*
  236.  * Type of a symbol, in low N bits of the word
  237.  */
  238. #define T_NULL          0
  239. #define T_VOID          1       /* function argument (only used by compiler) */
  240. #define T_CHAR          2       /* character            */
  241. #define T_SHORT         3       /* short integer        */
  242. #define T_INT           4       /* integer              */
  243. #define T_LONG          5       /* long integer         */
  244. #define T_FLOAT         6       /* floating point       */
  245. #define T_DOUBLE        7       /* double word          */
  246. #define T_STRUCT        8       /* structure            */
  247. #define T_UNION         9       /* union                */
  248. #define T_ENUM          10      /* enumeration          */
  249. #define T_MOE           11      /* member of enumeration*/
  250. #define T_UCHAR         12      /* unsigned character   */
  251. #define T_USHORT        13      /* unsigned short       */
  252. #define T_UINT          14      /* unsigned integer     */
  253. #define T_ULONG         15      /* unsigned long        */
  254. #define T_LNGDBL        16      /* long double          */
  255.  
  256. /*
  257.  * derived types, in n_type
  258. */
  259. #define DT_NON          (0)     /* no derived type */
  260. #define DT_PTR          (1)     /* pointer */
  261. #define DT_FCN          (2)     /* function */
  262. #define DT_ARY          (3)     /* array */
  263.  
  264. #define BTYPE(x)        ((x) & N_BTMASK)
  265.  
  266. #define ISPTR(x)        (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
  267. #define ISFCN(x)        (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
  268. #define ISARY(x)        (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
  269. #define ISTAG(x)        ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
  270. #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  271.  
  272. /********************** STORAGE CLASSES **********************/
  273.  
  274. /* This used to be defined as -1, but now n_sclass is unsigned.  */
  275. #define C_EFCN          0xff    /* physical end of function     */
  276. #define C_NULL          0
  277. #define C_AUTO          1       /* automatic variable           */
  278. #define C_EXT           2       /* external symbol              */
  279. #define C_STAT          3       /* static                       */
  280. #define C_REG           4       /* register variable            */
  281. #define C_EXTDEF        5       /* external definition          */
  282. #define C_LABEL         6       /* label                        */
  283. #define C_ULABEL        7       /* undefined label              */
  284. #define C_MOS           8       /* member of structure          */
  285. #define C_ARG           9       /* function argument            */
  286. #define C_STRTAG        10      /* structure tag                */
  287. #define C_MOU           11      /* member of union              */
  288. #define C_UNTAG         12      /* union tag                    */
  289. #define C_TPDEF         13      /* type definition              */
  290. #define C_USTATIC       14      /* undefined static             */
  291. #define C_ENTAG         15      /* enumeration tag              */
  292. #define C_MOE           16      /* member of enumeration        */
  293. #define C_REGPARM       17      /* register parameter           */
  294. #define C_FIELD         18      /* bit field                    */
  295. #define C_AUTOARG       19      /* auto argument                */
  296. #define C_LASTENT       20      /* dummy entry (end of block)   */
  297. #define C_BLOCK         100     /* ".bb" or ".eb"               */
  298. #define C_FCN           101     /* ".bf" or ".ef"               */
  299. #define C_EOS           102     /* end of structure             */
  300. #define C_FILE          103     /* file name                    */
  301. #define C_LINE          104     /* line # reformatted as symbol table entry */
  302. #define C_ALIAS         105     /* duplicate tag                */
  303. #define C_HIDDEN        106     /* ext symbol in dmert public lib */
  304.  
  305. /********************** RELOCATION DIRECTIVES **********************/
  306.  
  307.  
  308.  
  309. struct external_reloc {
  310.   unsigned long r_vaddr __attribute__((packed));
  311.   unsigned long r_symndx __attribute__((packed));
  312.   unsigned short r_type;
  313. };
  314.  
  315.  
  316. #define RELOC struct external_reloc
  317. #define RELSZ sizeof(RELOC)
  318.  
  319. #define RELOC_REL32     20      /* 32-bit PC-relative address */
  320. #define RELOC_ADDR32    6       /* 32-bit absolute address */
  321.  
  322. #define DEFAULT_DATA_SECTION_ALIGNMENT 4
  323. #define DEFAULT_BSS_SECTION_ALIGNMENT 4
  324. #define DEFAULT_TEXT_SECTION_ALIGNMENT 4
  325. /* For new sections we havn't heard of before */
  326. #define DEFAULT_SECTION_ALIGNMENT 4
  327.  
  328. #endif /* !_POSIX_SOURCE */
  329. #endif /* !__STRICT_ANSI__ */
  330. #endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
  331.  
  332. #ifndef __dj_ENFORCE_FUNCTION_CALLS
  333. #endif /* !__dj_ENFORCE_FUNCTION_CALLS */
  334.  
  335. #ifdef __cplusplus
  336. }
  337. #endif
  338.  
  339. #endif /* !__dj_include_coff_h_ */
  340.