a.out.h

Go to the documentation of this file.
00001 #ifndef __A_OUT_GNU_H__
00002 #define __A_OUT_GNU_H__
00003 
00004 #define __GNU_EXEC_MACROS__
00005 
00006 #ifndef __STRUCT_EXEC_OVERRIDE__
00007 
00008 struct exec
00009 {
00010   unsigned long a_info;         ///< Use macros N_MAGIC, etc for access 
00011   unsigned a_text;              ///< length of text, in bytes 
00012   unsigned a_data;              ///< length of data, in bytes 
00013   unsigned a_bss;               ///< length of uninitialized data area for file, in bytes 
00014   unsigned a_syms;              ///< length of symbol table data in file, in bytes 
00015   unsigned a_entry;             ///< start address 
00016   unsigned a_trsize;            ///< length of relocation info for text, in bytes 
00017   unsigned a_drsize;            ///< length of relocation info for data, in bytes 
00018 };
00019 
00020 #endif // __STRUCT_EXEC_OVERRIDE__ 
00021 
00022 /// these go in the N_MACHTYPE field 
00023 enum machine_type {
00024 #if defined (M_OLDSUN2)
00025   M__OLDSUN2 = M_OLDSUN2,
00026 #else
00027   M_OLDSUN2 = 0,
00028 #endif
00029 #if defined (M_68010)
00030   M__68010 = M_68010,
00031 #else
00032   M_68010 = 1,
00033 #endif
00034 #if defined (M_68020)
00035   M__68020 = M_68020,
00036 #else
00037   M_68020 = 2,
00038 #endif
00039 #if defined (M_SPARC)
00040   M__SPARC = M_SPARC,
00041 #else
00042   M_SPARC = 3,
00043 #endif
00044   /// skip a bunch so we don't run into any of sun's numbers 
00045   M_386 = 100,
00046 };
00047 
00048 #if !defined (N_MAGIC)
00049 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
00050 #endif
00051 #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
00052 #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
00053 #define N_SET_INFO(exec, magic, type, flags) \
00054         ((exec).a_info = ((magic) & 0xffff) \
00055          | (((int)(type) & 0xff) << 16) \
00056          | (((flags) & 0xff) << 24))
00057 #define N_SET_MAGIC(exec, magic) \
00058         ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
00059 
00060 #define N_SET_MACHTYPE(exec, machtype) \
00061         ((exec).a_info = \
00062          ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
00063 
00064 #define N_SET_FLAGS(exec, flags) \
00065         ((exec).a_info = \
00066          ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
00067 
00068 /// Code indicating object file or impure executable.  
00069 #define OMAGIC 0407
00070 /// Code indicating pure executable.  
00071 #define NMAGIC 0410
00072 /// Code indicating demand-paged executable.  
00073 #define ZMAGIC 0413
00074 /**
00075 *
00076  This indicates a demand-paged executable with the header in the text. 
00077 
00078 
00079 */
00080 #define QMAGIC 0314
00081 
00082 /// Code indicating core file.  
00083 #define CMAGIC 0421
00084 
00085 #if !defined (N_BADMAG)
00086 #define N_BADMAG(x)       (N_MAGIC(x) != OMAGIC         \
00087                         && N_MAGIC(x) != NMAGIC         \
00088                         && N_MAGIC(x) != ZMAGIC \
00089                         && N_MAGIC(x) != QMAGIC)
00090 #endif
00091 
00092 #define _N_HDROFF(x) (1024 - sizeof (struct exec))
00093 
00094 #if !defined (N_TXTOFF)
00095 #define N_TXTOFF(x) \
00096  (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \
00097   (N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
00098 #endif
00099 
00100 #if !defined (N_DATOFF)
00101 #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
00102 #endif
00103 
00104 #if !defined (N_TRELOFF)
00105 #define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
00106 #endif
00107 
00108 #if !defined (N_DRELOFF)
00109 #define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
00110 #endif
00111 
00112 #if !defined (N_SYMOFF)
00113 #define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
00114 #endif
00115 
00116 #if !defined (N_STROFF)
00117 #define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
00118 #endif
00119 
00120 /// Address of text segment in memory after it is loaded.  
00121 #if !defined (N_TXTADDR)
00122 #define N_TXTADDR(x) (N_MAGIC(x) == QMAGIC ? PAGE_SIZE : 0)
00123 #endif
00124 
00125 /**
00126 *
00127  Address of data segment in memory after it is loaded.
00128    Note that it is up to you to define SEGMENT_SIZE
00129 
00130 
00131 */
00132 #if defined(vax) || defined(hp300) || defined(pyr)
00133 #define SEGMENT_SIZE page_size
00134 #endif
00135 #ifdef  sony
00136 #define SEGMENT_SIZE    0x2000
00137 #endif  // Sony.  
00138 #ifdef is68k
00139 #define SEGMENT_SIZE 0x20000
00140 #endif
00141 #if defined(m68k) && defined(PORTAR)
00142 #define PAGE_SIZE 0x400
00143 #define SEGMENT_SIZE PAGE_SIZE
00144 #endif
00145 
00146 #ifdef linux
00147 #include <linux/page.h>
00148 #define SEGMENT_SIZE    1024
00149 #endif
00150 
00151 #define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
00152 
00153 #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
00154 
00155 #ifndef N_DATADDR
00156 #define N_DATADDR(x) \
00157     (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
00158      : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
00159 #endif
00160 
00161 /// Address of bss segment in memory after it is loaded.  
00162 #if !defined (N_BSSADDR)
00163 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
00164 #endif
00165 
00166 #if !defined (N_NLIST_DECLARED)
00167 struct nlist {
00168   union {
00169     char *n_name;
00170     struct nlist *n_next;
00171     long n_strx;
00172   } n_un;
00173   unsigned char n_type;
00174   char n_other;
00175   short n_desc;
00176   unsigned long n_value;
00177 };
00178 #endif // no N_NLIST_DECLARED.  
00179 
00180 #if !defined (N_UNDF)
00181 #define N_UNDF 0
00182 #endif
00183 #if !defined (N_ABS)
00184 #define N_ABS 2
00185 #endif
00186 #if !defined (N_TEXT)
00187 #define N_TEXT 4
00188 #endif
00189 #if !defined (N_DATA)
00190 #define N_DATA 6
00191 #endif
00192 #if !defined (N_BSS)
00193 #define N_BSS 8
00194 #endif
00195 #if !defined (N_FN)
00196 #define N_FN 15
00197 #endif
00198 
00199 #if !defined (N_EXT)
00200 #define N_EXT 1
00201 #endif
00202 #if !defined (N_TYPE)
00203 #define N_TYPE 036
00204 #endif
00205 #if !defined (N_STAB)
00206 #define N_STAB 0340
00207 #endif
00208 
00209 /**
00210 *
00211  The following type indicates the definition of a symbol as being
00212    an indirect reference to another symbol.  The other symbol
00213    appears as an undefined reference, immediately following this symbol.
00214 
00215    Indirection is asymmetrical.  The other symbol's value will be used
00216    to satisfy requests for the indirect symbol, but not vice versa.
00217    If the other symbol does not have a definition, libraries will
00218 
00219 
00220 */
00221 #define N_INDR 0xa
00222 
00223 /**
00224 *
00225  The following symbols refer to set elements.
00226    All the N_SET[ATDB] symbols with the same name form one set.
00227    Space is allocated for the set in the text section, and each set
00228    element's value is stored into one word of the space.
00229    The first word of the space is the length of the set (number of elements).
00230 
00231    The address of the set is made into an N_SETV symbol
00232    whose name is the same as the name of the set.
00233    This symbol acts like a N_DATA global symbol
00234 
00235 
00236 */
00237 
00238 /// These appear as input to LD, in a .o file.  
00239 #define N_SETA  0x14            ///< Absolute set element symbol 
00240 #define N_SETT  0x16            ///< Text set element symbol 
00241 #define N_SETD  0x18            ///< Data set element symbol 
00242 #define N_SETB  0x1A            ///< Bss set element symbol 
00243 
00244 /// This is output from LD.  
00245 #define N_SETV  0x1C            ///< Pointer to set vector in data area.  
00246 
00247 #if !defined (N_RELOCATION_INFO_DECLARED)
00248 /**
00249 *
00250  This structure describes a single relocation to be performed.
00251    The text-relocation section of the file is a vector of these structures,
00252    all of which apply to the text section.
00253 
00254 
00255 */
00256 
00257 struct relocation_info
00258 {
00259   /// Address (within segment) to be relocated.  
00260   int r_address;
00261   /// The meaning of r_symbolnum depends on r_extern.  
00262   unsigned int r_symbolnum:24;
00263 /**
00264 *
00265  Nonzero means value is a pc-relative offset
00266      and it should be relocated for changes in its own address
00267 
00268 
00269 */
00270   unsigned int r_pcrel:1;
00271 /**
00272 *
00273  Length (as exponent of 2) of the field to be relocated.
00274 
00275 
00276 */
00277   unsigned int r_length:2;
00278 /**
00279 *
00280  1 => relocate with value of symbol.
00281           r_symbolnum is the index of the symbol
00282           in file's the symbol table.
00283      0 => relocate with the address of a segment.
00284           r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
00285 
00286 
00287 */
00288   unsigned int r_extern:1;
00289 /**
00290 *
00291  Four bits that aren't used, but when writing an object file
00292 
00293 
00294 */
00295 #ifdef NS32K
00296   unsigned r_bsr:1;
00297   unsigned r_disp:1;
00298   unsigned r_pad:2;
00299 #else
00300   unsigned int r_pad:4;
00301 #endif
00302 };
00303 #endif // no N_RELOCATION_INFO_DECLARED.  
00304 
00305 
00306 #endif // __A_OUT_GNU_H__ 

Generated on Mon May 1 21:46:59 2006 for KernelAPI by  doxygen 1.4.6-5