coff.h

Go to the documentation of this file.
00001 /**
00002 *
00003  This file is derrived from the GAS 2.1.4 assembler control file.
00004    The GAS product is under the GNU Public License, version 2 or later.
00005    As such, this file is also uder that license.
00006 
00007    If the file format changes in the COFF object, this file should be
00008    subsequently updated to reflect the changes.
00009 
00010    The actual loader module only uses a few of these structures. The full
00011    set is documented here because I received the full set. If you wish
00012    more information about COFF, then O'Rielly has a very excellent book.
00013 
00014 
00015 */
00016 
00017 #define  E_SYMNMLEN  8   ///< Number of characters in a symbol name         
00018 #define  E_FILNMLEN 14   ///< Number of characters in a file name           
00019 #define  E_DIMNUM    4   ///< Number of array dimensions in auxiliary entry 
00020 
00021 /**
00022 *
00023 
00024  * These defines are byte order independant. There is no alignment of fields
00025  * permitted in the structures. Therefore they are declared as characters
00026  * and the values loaded from the character positions. It also makes it
00027  * nice to have it "endian" independant.
00028 
00029 
00030 */
00031  
00032 /// Load a short int from the following tables with little-endian formats 
00033 #define COFF_SHORT_L(ps) ((short)(((unsigned short)((unsigned char)ps[1])<<8)|\
00034                                   ((unsigned short)((unsigned char)ps[0]))))
00035 
00036 /// Load a long int from the following tables with little-endian formats 
00037 #define COFF_LONG_L(ps) (((long)(((unsigned long)((unsigned char)ps[3])<<24) |\
00038                                  ((unsigned long)((unsigned char)ps[2])<<16) |\
00039                                  ((unsigned long)((unsigned char)ps[1])<<8)  |\
00040                                  ((unsigned long)((unsigned char)ps[0])))))
00041  
00042 /// Load a short int from the following tables with big-endian formats 
00043 #define COFF_SHORT_H(ps) ((short)(((unsigned short)((unsigned char)ps[0])<<8)|\
00044                                   ((unsigned short)((unsigned char)ps[1]))))
00045 
00046 /// Load a long int from the following tables with big-endian formats 
00047 #define COFF_LONG_H(ps) (((long)(((unsigned long)((unsigned char)ps[0])<<24) |\
00048                                  ((unsigned long)((unsigned char)ps[1])<<16) |\
00049                                  ((unsigned long)((unsigned char)ps[2])<<8)  |\
00050                                  ((unsigned long)((unsigned char)ps[3])))))
00051 
00052 /**
00053 *
00054  These may be overriden later by brain dead implementations which generate
00055    a big-endian header with little-endian data. In that case, generate a
00056    replacement macro which tests a flag and uses either of the two above
00057 
00058 
00059 */
00060 
00061 #define COFF_LONG(v)   COFF_LONG_L(v)
00062 #define COFF_SHORT(v)  COFF_SHORT_L(v)
00063 
00064 ///** coff information for Intel 386/486.  
00065 
00066 ///********************* FILE HEADER *********************
00067 
00068 struct COFF_filehdr {
00069         char f_magic[2];        ///< magic number                       
00070         char f_nscns[2];        ///< number of sections         
00071         char f_timdat[4];       ///< time & date stamp          
00072         char f_symptr[4];       ///< file pointer to symtab     
00073         char f_nsyms[4];        ///< number of symtab entries   
00074         char f_opthdr[2];       ///< sizeof(optional hdr)               
00075         char f_flags[2];        ///< flags                      
00076 };
00077 
00078 /**
00079 *
00080 
00081  *   Bits for f_flags:
00082  *
00083  *      F_RELFLG        relocation info stripped from file
00084  *      F_EXEC          file is executable  (i.e. no unresolved externel
00085  *                      references)
00086  *      F_LNNO          line nunbers stripped from file
00087  *      F_LSYMS         local symbols stripped from file
00088  *      F_MINMAL        this is a minimal object file (".m") output of fextract
00089  *      F_UPDATE        this is a fully bound update file, output of ogen
00090  *      F_SWABD         this file has had its bytes swabbed (in names)
00091  *      F_AR16WR        this file has the byte ordering of an AR16WR
00092  *                      (e.g. 11/70) machine
00093  *      F_AR32WR        this file has the byte ordering of an AR32WR machine
00094  *                      (e.g. vax and iNTEL 386)
00095  *      F_AR32W         this file has the byte ordering of an AR32W machine
00096  *                      (e.g. 3b,maxi)
00097  *      F_PATCH         file contains "patch" list in optional header
00098  *      F_NODF          (minimal file only) no decision functions for
00099  *                      replaced functions
00100 
00101 
00102 */
00103 
00104 #define  COFF_F_RELFLG          0000001
00105 #define  COFF_F_EXEC            0000002
00106 #define  COFF_F_LNNO            0000004
00107 #define  COFF_F_LSYMS           0000010
00108 #define  COFF_F_MINMAL          0000020
00109 #define  COFF_F_UPDATE          0000040
00110 #define  COFF_F_SWABD           0000100
00111 #define  COFF_F_AR16WR          0000200
00112 #define  COFF_F_AR32WR          0000400
00113 #define  COFF_F_AR32W           0001000
00114 #define  COFF_F_PATCH           0002000
00115 #define  COFF_F_NODF            0002000
00116 
00117 #define COFF_I386MAGIC          0x14c   ///< Linux's system    
00118 
00119 #if 0   ///< Perhaps, someday, these formats may be used.      
00120 #define COFF_I386PTXMAGIC       0x154
00121 #define COFF_I386AIXMAGIC       0x175   ///< IBM's AIX system  
00122 #define COFF_I386BADMAG(x) ((COFF_SHORT((x).f_magic) != COFF_I386MAGIC) \
00123                           && COFF_SHORT((x).f_magic) != COFF_I386PTXMAGIC \
00124                           && COFF_SHORT((x).f_magic) != COFF_I386AIXMAGIC)
00125 #else
00126 #define COFF_I386BADMAG(x) (COFF_SHORT((x).f_magic) != COFF_I386MAGIC)
00127 #endif
00128 
00129 #define COFF_FILHDR     struct COFF_filehdr
00130 #define COFF_FILHSZ     sizeof(COFF_FILHDR)
00131 
00132 ///********************* AOUT "OPTIONAL HEADER" *********************
00133 
00134 /**
00135 *
00136  Linux COFF must have this "optional" header. Standard COFF has no entry
00137    location for the "entry" point. They normally would start with the first
00138    location of the .text section. This is not a good idea for linux. So,
00139    the use of this "optional" header is not optional. It is required.
00140 
00141    Do not be tempted to assume that the size of the optional header is
00142    a constant and simply index the next byte by the size of this structure.
00143    Use the 'f_opthdr' field in the main coff header for the size of the
00144    structure actually written to the file!!
00145 
00146 
00147 */
00148 
00149 typedef struct 
00150 {
00151   char  magic[2];               ///< type of file                                
00152   char  vstamp[2];              ///< version stamp                       
00153   char  tsize[4];               ///< text size in bytes, padded to FW bdry 
00154   char  dsize[4];               ///< initialized   data "   "            
00155   char  bsize[4];               ///< uninitialized data "   "            
00156   char  entry[4];               ///< entry pt.                           
00157   char  text_start[4];          ///< base of text used for this file       
00158   char  data_start[4];          ///< base of data used for this file       
00159 }
00160 COFF_AOUTHDR;
00161 
00162 #define COFF_AOUTSZ (sizeof(COFF_AOUTHDR))
00163 
00164 #define COFF_STMAGIC    0401
00165 #define COFF_OMAGIC     0404
00166 #define COFF_JMAGIC     0407    ///< dirty text and data image, can't share  
00167 #define COFF_DMAGIC     0410    ///< dirty text segment, data aligned        
00168 #define COFF_ZMAGIC     0413    ///< The proper magic number for executabls  
00169 #define COFF_SHMAGIC    0443    ///< shared library header                   
00170 
00171 ///********************* SECTION HEADER *********************
00172 
00173 struct COFF_scnhdr {
00174   char          s_name[8];      ///< section name                           
00175   char          s_paddr[4];     ///< physical address, aliased s_nlib 
00176   char          s_vaddr[4];     ///< virtual address                
00177   char          s_size[4];      ///< section size                           
00178   char          s_scnptr[4];    ///< file ptr to raw data for section 
00179   char          s_relptr[4];    ///< file ptr to relocation         
00180   char          s_lnnoptr[4];   ///< file ptr to line numbers       
00181   char          s_nreloc[2];    ///< number of relocation entries           
00182   char          s_nlnno[2];     ///< number of line number entries    
00183   char          s_flags[4];     ///< flags                          
00184 };
00185 
00186 #define COFF_SCNHDR     struct COFF_scnhdr
00187 #define COFF_SCNHSZ     sizeof(COFF_SCNHDR)
00188 
00189 /**
00190 *
00191 
00192  * names of "special" sections
00193 
00194 
00195 */
00196 
00197 #define COFF_TEXT       ".text"
00198 #define COFF_DATA       ".data"
00199 #define COFF_BSS        ".bss"
00200 #define COFF_COMMENT    ".comment"
00201 #define COFF_LIB        ".lib"
00202 
00203 #define COFF_SECT_TEXT  0      ///< Section for instruction code             
00204 #define COFF_SECT_DATA  1      ///< Section for initialized globals          
00205 #define COFF_SECT_BSS   2      ///< Section for un-initialized globals       
00206 #define COFF_SECT_REQD  3      ///< Minimum number of sections for good file 
00207 
00208 #define COFF_STYP_REG     0x00 ///< regular segment                          
00209 #define COFF_STYP_DSECT   0x01 ///< dummy segment                            
00210 #define COFF_STYP_NOLOAD  0x02 ///< no-load segment                          
00211 #define COFF_STYP_GROUP   0x04 ///< group segment                            
00212 #define COFF_STYP_PAD     0x08 ///< .pad segment                             
00213 #define COFF_STYP_COPY    0x10 ///< copy section                             
00214 #define COFF_STYP_TEXT    0x20 ///< .text segment                            
00215 #define COFF_STYP_DATA    0x40 ///< .data segment                            
00216 #define COFF_STYP_BSS     0x80 ///< .bss segment                             
00217 #define COFF_STYP_INFO   0x200 ///< .comment section                         
00218 #define COFF_STYP_OVER   0x400 ///< overlay section                          
00219 #define COFF_STYP_LIB    0x800 ///< library section                          
00220 
00221 /**
00222 *
00223 
00224  * Shared libraries have the following section header in the data field for
00225  * each library.
00226 
00227 
00228 */
00229 
00230 struct COFF_slib {
00231   char          sl_entsz[4];    ///< Size of this entry               
00232   char          sl_pathndx[4];  ///< size of the header field         
00233 };
00234 
00235 #define COFF_SLIBHD     struct COFF_slib
00236 #define COFF_SLIBSZ     sizeof(COFF_SLIBHD)
00237 
00238 ///********************* LINE NUMBERS *********************
00239 
00240 /**
00241 *
00242  1 line number entry for every "breakpointable" source line in a section.
00243  * Line numbers are grouped on a per function basis; first entry in a function
00244  * grouping will have l_lnno = 0 and in place of physical address will be the
00245  * symbol table index of the function name.
00246 
00247 
00248 */
00249 
00250 struct COFF_lineno {
00251   union {
00252     char l_symndx[4];   ///< function name symbol index, iff l_lnno == 0
00253     char l_paddr[4];    ///< (physical) address of line number  
00254   } l_addr;
00255   char l_lnno[2];       ///< line number                
00256 };
00257 
00258 #define COFF_LINENO     struct COFF_lineno
00259 #define COFF_LINESZ     6
00260 
00261 ///********************* SYMBOLS *********************
00262 
00263 #define COFF_E_SYMNMLEN  8      ///< # characters in a short symbol name        
00264 #define COFF_E_FILNMLEN 14      ///< # characters in a file name                
00265 #define COFF_E_DIMNUM    4      ///< # array dimensions in auxiliary entry 
00266 
00267 /**
00268 *
00269 
00270  *  All symbols and sections have the following definition
00271 
00272 
00273 */
00274 
00275 struct COFF_syment 
00276 {
00277   union {
00278     char e_name[E_SYMNMLEN];    ///< Symbol name (first 8 characters) 
00279     struct {
00280       char e_zeroes[4];         ///< Leading zeros 
00281       char e_offset[4];         ///< Offset if this is a header section 
00282     } e;
00283   } e;
00284 
00285   char e_value[4];              ///< Value (address) of the segment 
00286   char e_scnum[2];              ///< Section number 
00287   char e_type[2];               ///< Type of section 
00288   char e_sclass[1];             ///< Loader class 
00289   char e_numaux[1];             ///< Number of auxiliary entries which follow 
00290 };
00291 
00292 #define COFF_N_BTMASK   (0xf)   ///< Mask for important class bits 
00293 #define COFF_N_TMASK    (0x30)  ///< Mask for important type bits  
00294 #define COFF_N_BTSHFT   (4)     ///< # bits to shift class field   
00295 #define COFF_N_TSHIFT   (2)     ///< # bits to shift type field    
00296 
00297 /**
00298 *
00299 
00300  *  Auxiliary entries because the main table is too limiting.
00301 
00302 
00303 */
00304   
00305 union COFF_auxent {
00306 
00307 /**
00308 *
00309 
00310  *  Debugger information
00311 
00312 
00313 */
00314 
00315   struct {
00316     char x_tagndx[4];           ///< str, un, or enum tag indx 
00317     union {
00318       struct {
00319         char  x_lnno[2];        ///< declaration line number 
00320         char  x_size[2];        ///< str/union/array size 
00321       } x_lnsz;
00322       char x_fsize[4];          ///< size of function 
00323     } x_misc;
00324 
00325     union {
00326       struct {                  ///< if ISFCN, tag, or .bb 
00327         char x_lnnoptr[4];      ///< ptr to fcn line # 
00328         char x_endndx[4];       ///< entry ndx past block end 
00329       } x_fcn;
00330 
00331       struct {                  ///< if ISARY, up to 4 dimen. 
00332         char x_dimen[E_DIMNUM][2];
00333       } x_ary;
00334     } x_fcnary;
00335 
00336     char x_tvndx[2];    ///< tv index 
00337   } x_sym;
00338 
00339 /**
00340 *
00341 
00342  *   Source file names (debugger information)
00343 
00344 
00345 */
00346 
00347   union {
00348     char x_fname[E_FILNMLEN];
00349     struct {
00350       char x_zeroes[4];
00351       char x_offset[4];
00352     } x_n;
00353   } x_file;
00354 
00355 /**
00356 *
00357 
00358  *   Section information
00359 
00360 
00361 */
00362 
00363   struct {
00364     char x_scnlen[4];   ///< section length 
00365     char x_nreloc[2];   ///< # relocation entries 
00366     char x_nlinno[2];   ///< # line numbers 
00367   } x_scn;
00368 
00369 /**
00370 *
00371 
00372  *   Transfer vector (branch table)
00373 
00374 
00375 */
00376   
00377   struct {
00378     char x_tvfill[4];   ///< tv fill value 
00379     char x_tvlen[2];    ///< length of .tv 
00380     char x_tvran[2][2]; ///< tv range 
00381   } x_tv;               ///< info about .tv section (in auxent of symbol .tv)) 
00382 };
00383 
00384 #define COFF_SYMENT     struct COFF_syment
00385 #define COFF_SYMESZ     18      
00386 #define COFF_AUXENT     union COFF_auxent
00387 #define COFF_AUXESZ     18
00388 
00389 #define COFF_ETEXT      "etext"
00390 
00391 ///********************* RELOCATION DIRECTIVES *********************
00392 
00393 struct COFF_reloc {
00394   char r_vaddr[4];        ///< Virtual address of item    
00395   char r_symndx[4];       ///< Symbol index in the symtab 
00396   char r_type[2];         ///< Relocation type            
00397 };
00398 
00399 #define COFF_RELOC struct COFF_reloc
00400 #define COFF_RELSZ 10
00401 
00402 #define COFF_DEF_DATA_SECTION_ALIGNMENT  4
00403 #define COFF_DEF_BSS_SECTION_ALIGNMENT   4
00404 #define COFF_DEF_TEXT_SECTION_ALIGNMENT  4
00405 
00406 /// For new sections we havn't heard of before 
00407 #define COFF_DEF_SECTION_ALIGNMENT       4

Generated on Mon May 1 21:47:00 2006 for KernelAPI by  doxygen 1.4.6-5