Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /* This file is derived from the GAS 2.1.4 assembler control file.
0003    The GAS product is under the GNU General Public License, version 2 or later.
0004    As such, this file is also under that license.
0005 
0006    If the file format changes in the COFF object, this file should be
0007    subsequently updated to reflect the changes.
0008 
0009    The actual loader module only uses a few of these structures. The full
0010    set is documented here because I received the full set. If you wish
0011    more information about COFF, then O'Reilly has a very excellent book.
0012 */
0013 
0014 #ifndef _UAPI_LINUX_COFF_H
0015 #define _UAPI_LINUX_COFF_H
0016 
0017 #define  E_SYMNMLEN  8   /* Number of characters in a symbol name         */
0018 #define  E_FILNMLEN 14   /* Number of characters in a file name           */
0019 #define  E_DIMNUM    4   /* Number of array dimensions in auxiliary entry */
0020 
0021 /*
0022  * These defines are byte order independent. There is no alignment of fields
0023  * permitted in the structures. Therefore they are declared as characters
0024  * and the values loaded from the character positions. It also makes it
0025  * nice to have it "endian" independent.
0026  */
0027  
0028 /* Load a short int from the following tables with little-endian formats */
0029 #define COFF_SHORT_L(ps) ((short)(((unsigned short)((unsigned char)ps[1])<<8)|\
0030                   ((unsigned short)((unsigned char)ps[0]))))
0031 
0032 /* Load a long int from the following tables with little-endian formats */
0033 #define COFF_LONG_L(ps) (((long)(((unsigned long)((unsigned char)ps[3])<<24) |\
0034                  ((unsigned long)((unsigned char)ps[2])<<16) |\
0035                  ((unsigned long)((unsigned char)ps[1])<<8)  |\
0036                  ((unsigned long)((unsigned char)ps[0])))))
0037  
0038 /* Load a short int from the following tables with big-endian formats */
0039 #define COFF_SHORT_H(ps) ((short)(((unsigned short)((unsigned char)ps[0])<<8)|\
0040                   ((unsigned short)((unsigned char)ps[1]))))
0041 
0042 /* Load a long int from the following tables with big-endian formats */
0043 #define COFF_LONG_H(ps) (((long)(((unsigned long)((unsigned char)ps[0])<<24) |\
0044                  ((unsigned long)((unsigned char)ps[1])<<16) |\
0045                  ((unsigned long)((unsigned char)ps[2])<<8)  |\
0046                  ((unsigned long)((unsigned char)ps[3])))))
0047 
0048 /* These may be overridden later by brain dead implementations which generate
0049    a big-endian header with little-endian data. In that case, generate a
0050    replacement macro which tests a flag and uses either of the two above
0051    as appropriate. */
0052 
0053 #define COFF_LONG(v)   COFF_LONG_L(v)
0054 #define COFF_SHORT(v)  COFF_SHORT_L(v)
0055 
0056 /*** coff information for Intel 386/486.  */
0057 
0058 /********************** FILE HEADER **********************/
0059 
0060 struct COFF_filehdr {
0061     char f_magic[2];    /* magic number         */
0062     char f_nscns[2];    /* number of sections       */
0063     char f_timdat[4];   /* time & date stamp        */
0064     char f_symptr[4];   /* file pointer to symtab   */
0065     char f_nsyms[4];    /* number of symtab entries */
0066     char f_opthdr[2];   /* sizeof(optional hdr)     */
0067     char f_flags[2];    /* flags            */
0068 };
0069 
0070 /*
0071  *   Bits for f_flags:
0072  *
0073  *  F_RELFLG    relocation info stripped from file
0074  *  F_EXEC      file is executable  (i.e. no unresolved external
0075  *          references)
0076  *  F_LNNO      line numbers stripped from file
0077  *  F_LSYMS     local symbols stripped from file
0078  *  F_MINMAL    this is a minimal object file (".m") output of fextract
0079  *  F_UPDATE    this is a fully bound update file, output of ogen
0080  *  F_SWABD     this file has had its bytes swabbed (in names)
0081  *  F_AR16WR    this file has the byte ordering of an AR16WR
0082  *          (e.g. 11/70) machine
0083  *  F_AR32WR    this file has the byte ordering of an AR32WR machine
0084  *          (e.g. vax and iNTEL 386)
0085  *  F_AR32W     this file has the byte ordering of an AR32W machine
0086  *          (e.g. 3b,maxi)
0087  *  F_PATCH     file contains "patch" list in optional header
0088  *  F_NODF      (minimal file only) no decision functions for
0089  *          replaced functions
0090  */
0091 
0092 #define  COFF_F_RELFLG      0000001
0093 #define  COFF_F_EXEC        0000002
0094 #define  COFF_F_LNNO        0000004
0095 #define  COFF_F_LSYMS       0000010
0096 #define  COFF_F_MINMAL      0000020
0097 #define  COFF_F_UPDATE      0000040
0098 #define  COFF_F_SWABD       0000100
0099 #define  COFF_F_AR16WR      0000200
0100 #define  COFF_F_AR32WR      0000400
0101 #define  COFF_F_AR32W       0001000
0102 #define  COFF_F_PATCH       0002000
0103 #define  COFF_F_NODF        0002000
0104 
0105 #define COFF_I386MAGIC          0x14c   /* Linux's system    */
0106 
0107 #if 0   /* Perhaps, someday, these formats may be used.      */
0108 #define COFF_I386PTXMAGIC   0x154
0109 #define COFF_I386AIXMAGIC   0x175   /* IBM's AIX system  */
0110 #define COFF_I386BADMAG(x) ((COFF_SHORT((x).f_magic) != COFF_I386MAGIC) \
0111               && COFF_SHORT((x).f_magic) != COFF_I386PTXMAGIC \
0112               && COFF_SHORT((x).f_magic) != COFF_I386AIXMAGIC)
0113 #else
0114 #define COFF_I386BADMAG(x) (COFF_SHORT((x).f_magic) != COFF_I386MAGIC)
0115 #endif
0116 
0117 #define COFF_FILHDR struct COFF_filehdr
0118 #define COFF_FILHSZ sizeof(COFF_FILHDR)
0119 
0120 /********************** AOUT "OPTIONAL HEADER" **********************/
0121 
0122 /* Linux COFF must have this "optional" header. Standard COFF has no entry
0123    location for the "entry" point. They normally would start with the first
0124    location of the .text section. This is not a good idea for linux. So,
0125    the use of this "optional" header is not optional. It is required.
0126 
0127    Do not be tempted to assume that the size of the optional header is
0128    a constant and simply index the next byte by the size of this structure.
0129    Use the 'f_opthdr' field in the main coff header for the size of the
0130    structure actually written to the file!!
0131 */
0132 
0133 typedef struct 
0134 {
0135   char  magic[2];       /* type of file              */
0136   char  vstamp[2];      /* version stamp             */
0137   char  tsize[4];       /* text size in bytes, padded to FW bdry */
0138   char  dsize[4];       /* initialized   data "   "      */
0139   char  bsize[4];       /* uninitialized data "   "      */
0140   char  entry[4];       /* entry pt.                 */
0141   char  text_start[4];      /* base of text used for this file       */
0142   char  data_start[4];      /* base of data used for this file       */
0143 }
0144 COFF_AOUTHDR;
0145 
0146 #define COFF_AOUTSZ (sizeof(COFF_AOUTHDR))
0147 
0148 #define COFF_STMAGIC    0401
0149 #define COFF_OMAGIC     0404
0150 #define COFF_JMAGIC     0407    /* dirty text and data image, can't share  */
0151 #define COFF_DMAGIC     0410    /* dirty text segment, data aligned        */
0152 #define COFF_ZMAGIC     0413    /* The proper magic number for executables  */
0153 #define COFF_SHMAGIC    0443    /* shared library header                   */
0154 
0155 /********************** SECTION HEADER **********************/
0156 
0157 struct COFF_scnhdr {
0158   char      s_name[8];  /* section name             */
0159   char      s_paddr[4]; /* physical address, aliased s_nlib */
0160   char      s_vaddr[4]; /* virtual address          */
0161   char      s_size[4];  /* section size             */
0162   char      s_scnptr[4];    /* file ptr to raw data for section */
0163   char      s_relptr[4];    /* file ptr to relocation       */
0164   char      s_lnnoptr[4];   /* file ptr to line numbers     */
0165   char      s_nreloc[2];    /* number of relocation entries     */
0166   char      s_nlnno[2]; /* number of line number entries    */
0167   char      s_flags[4]; /* flags                */
0168 };
0169 
0170 #define COFF_SCNHDR struct COFF_scnhdr
0171 #define COFF_SCNHSZ sizeof(COFF_SCNHDR)
0172 
0173 /*
0174  * names of "special" sections
0175  */
0176 
0177 #define COFF_TEXT   ".text"
0178 #define COFF_DATA   ".data"
0179 #define COFF_BSS    ".bss"
0180 #define COFF_COMMENT    ".comment"
0181 #define COFF_LIB        ".lib"
0182 
0183 #define COFF_SECT_TEXT  0      /* Section for instruction code             */
0184 #define COFF_SECT_DATA  1      /* Section for initialized globals          */
0185 #define COFF_SECT_BSS   2      /* Section for un-initialized globals       */
0186 #define COFF_SECT_REQD  3      /* Minimum number of sections for good file */
0187 
0188 #define COFF_STYP_REG     0x00 /* regular segment                          */
0189 #define COFF_STYP_DSECT   0x01 /* dummy segment                            */
0190 #define COFF_STYP_NOLOAD  0x02 /* no-load segment                          */
0191 #define COFF_STYP_GROUP   0x04 /* group segment                            */
0192 #define COFF_STYP_PAD     0x08 /* .pad segment                             */
0193 #define COFF_STYP_COPY    0x10 /* copy section                             */
0194 #define COFF_STYP_TEXT    0x20 /* .text segment                            */
0195 #define COFF_STYP_DATA    0x40 /* .data segment                            */
0196 #define COFF_STYP_BSS     0x80 /* .bss segment                             */
0197 #define COFF_STYP_INFO   0x200 /* .comment section                         */
0198 #define COFF_STYP_OVER   0x400 /* overlay section                          */
0199 #define COFF_STYP_LIB    0x800 /* library section                          */
0200 
0201 /*
0202  * Shared libraries have the following section header in the data field for
0203  * each library.
0204  */
0205 
0206 struct COFF_slib {
0207   char      sl_entsz[4];    /* Size of this entry               */
0208   char      sl_pathndx[4];  /* size of the header field         */
0209 };
0210 
0211 #define COFF_SLIBHD struct COFF_slib
0212 #define COFF_SLIBSZ sizeof(COFF_SLIBHD)
0213 
0214 /********************** LINE NUMBERS **********************/
0215 
0216 /* 1 line number entry for every "breakpointable" source line in a section.
0217  * Line numbers are grouped on a per function basis; first entry in a function
0218  * grouping will have l_lnno = 0 and in place of physical address will be the
0219  * symbol table index of the function name.
0220  */
0221 
0222 struct COFF_lineno {
0223   union {
0224     char l_symndx[4];   /* function name symbol index, iff l_lnno == 0*/
0225     char l_paddr[4];    /* (physical) address of line number    */
0226   } l_addr;
0227   char l_lnno[2];   /* line number      */
0228 };
0229 
0230 #define COFF_LINENO struct COFF_lineno
0231 #define COFF_LINESZ 6
0232 
0233 /********************** SYMBOLS **********************/
0234 
0235 #define COFF_E_SYMNMLEN  8  /* # characters in a short symbol name  */
0236 #define COFF_E_FILNMLEN 14  /* # characters in a file name      */
0237 #define COFF_E_DIMNUM    4  /* # array dimensions in auxiliary entry */
0238 
0239 /*
0240  *  All symbols and sections have the following definition
0241  */
0242 
0243 struct COFF_syment 
0244 {
0245   union {
0246     char e_name[E_SYMNMLEN];    /* Symbol name (first 8 characters) */
0247     struct {
0248       char e_zeroes[4];         /* Leading zeros */
0249       char e_offset[4];         /* Offset if this is a header section */
0250     } e;
0251   } e;
0252 
0253   char e_value[4];              /* Value (address) of the segment */
0254   char e_scnum[2];              /* Section number */
0255   char e_type[2];               /* Type of section */
0256   char e_sclass[1];             /* Loader class */
0257   char e_numaux[1];             /* Number of auxiliary entries which follow */
0258 };
0259 
0260 #define COFF_N_BTMASK   (0xf)   /* Mask for important class bits */
0261 #define COFF_N_TMASK    (0x30)  /* Mask for important type bits  */
0262 #define COFF_N_BTSHFT   (4)     /* # bits to shift class field   */
0263 #define COFF_N_TSHIFT   (2)     /* # bits to shift type field    */
0264 
0265 /*
0266  *  Auxiliary entries because the main table is too limiting.
0267  */
0268   
0269 union COFF_auxent {
0270 
0271 /*
0272  *  Debugger information
0273  */
0274 
0275   struct {
0276     char x_tagndx[4];           /* str, un, or enum tag indx */
0277     union {
0278       struct {
0279     char  x_lnno[2];        /* declaration line number */
0280     char  x_size[2];        /* str/union/array size */
0281       } x_lnsz;
0282       char x_fsize[4];          /* size of function */
0283     } x_misc;
0284 
0285     union {
0286       struct {              /* if ISFCN, tag, or .bb */
0287     char x_lnnoptr[4];  /* ptr to fcn line # */
0288     char x_endndx[4];   /* entry ndx past block end */
0289       } x_fcn;
0290 
0291       struct {              /* if ISARY, up to 4 dimen. */
0292     char x_dimen[E_DIMNUM][2];
0293       } x_ary;
0294     } x_fcnary;
0295 
0296     char x_tvndx[2];    /* tv index */
0297   } x_sym;
0298 
0299 /*
0300  *   Source file names (debugger information)
0301  */
0302 
0303   union {
0304     char x_fname[E_FILNMLEN];
0305     struct {
0306       char x_zeroes[4];
0307       char x_offset[4];
0308     } x_n;
0309   } x_file;
0310 
0311 /*
0312  *   Section information
0313  */
0314 
0315   struct {
0316     char x_scnlen[4];   /* section length */
0317     char x_nreloc[2];   /* # relocation entries */
0318     char x_nlinno[2];   /* # line numbers */
0319   } x_scn;
0320 
0321 /*
0322  *   Transfer vector (branch table)
0323  */
0324   
0325   struct {
0326     char x_tvfill[4];   /* tv fill value */
0327     char x_tvlen[2];    /* length of .tv */
0328     char x_tvran[2][2]; /* tv range */
0329   } x_tv;       /* info about .tv section (in auxent of symbol .tv)) */
0330 };
0331 
0332 #define COFF_SYMENT struct COFF_syment
0333 #define COFF_SYMESZ 18  
0334 #define COFF_AUXENT union COFF_auxent
0335 #define COFF_AUXESZ 18
0336 
0337 #define COFF_ETEXT  "etext"
0338 
0339 /********************** RELOCATION DIRECTIVES **********************/
0340 
0341 struct COFF_reloc {
0342   char r_vaddr[4];        /* Virtual address of item    */
0343   char r_symndx[4];       /* Symbol index in the symtab */
0344   char r_type[2];         /* Relocation type            */
0345 };
0346 
0347 #define COFF_RELOC struct COFF_reloc
0348 #define COFF_RELSZ 10
0349 
0350 #define COFF_DEF_DATA_SECTION_ALIGNMENT  4
0351 #define COFF_DEF_BSS_SECTION_ALIGNMENT   4
0352 #define COFF_DEF_TEXT_SECTION_ALIGNMENT  4
0353 
0354 /* For new sections we haven't heard of before */
0355 #define COFF_DEF_SECTION_ALIGNMENT       4
0356 
0357 #endif /* _UAPI_LINUX_COFF_H */