Back to index

cell-binutils  2.17cvs20070401
aout_gnu.h
Go to the documentation of this file.
00001 /* This file is aout_gnu.h
00002 
00003    Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 2000, 2002
00004    Free Software Foundation, Inc.
00005 
00006    This file is part of GAS, the GNU Assembler.
00007 
00008    GAS is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2, or (at your option)
00011    any later version.
00012 
00013    GAS is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with GAS; see the file COPYING.  If not, write to
00020    the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00021 
00022 #ifndef __A_OUT_GNU_H__
00023 #define __A_OUT_GNU_H__
00024 
00025 /* There are two main flavours of a.out, one which uses the standard
00026    relocations, and one which uses extended relocations.
00027 
00028    Today, the extended reloc uses are
00029    TC_SPARC
00030 
00031    each must define the enum reloc_type
00032 
00033 */
00034 
00035 #define USE_EXTENDED_RELOC defined(TC_SPARC)
00036 
00037 #if defined(TC_SPARC)
00038 enum reloc_type
00039   {
00040     RELOC_8, RELOC_16, RELOC_32,/* simple relocations */
00041     RELOC_DISP8, RELOC_DISP16, RELOC_DISP32,     /* pc-rel displacement */
00042     RELOC_WDISP30, RELOC_WDISP22,
00043     RELOC_HI22, RELOC_22,
00044     RELOC_13, RELOC_LO10,
00045     RELOC_SFA_BASE, RELOC_SFA_OFF13,
00046     RELOC_BASE10, RELOC_BASE13, RELOC_BASE22,    /* P.I.C. (base-relative) */
00047     RELOC_PC10, RELOC_PC22, /* for some sort of pc-rel P.I.C. (?) */
00048     RELOC_JMP_TBL,          /* P.I.C. jump table */
00049     RELOC_SEGOFF16,         /* reputedly for shared libraries somehow */
00050     RELOC_GLOB_DAT, RELOC_JMP_SLOT, RELOC_RELATIVE,
00051     RELOC_10, RELOC_11,
00052     RELOC_WDISP2_14,
00053     RELOC_WDISP19,
00054     RELOC_HHI22,
00055     RELOC_HLO10,
00056 
00057     /* 29K relocation types */
00058     RELOC_JUMPTARG, RELOC_CONST, RELOC_CONSTH,
00059 
00060     RELOC_WDISP14, RELOC_WDISP21,
00061 
00062     NO_RELOC
00063   };
00064 
00065 #endif /* TC_SPARC */
00066 
00067 #define __GNU_EXEC_MACROS__
00068 
00069 #ifndef __STRUCT_EXEC_OVERRIDE__
00070 
00071 /* This is the layout on disk of a Unix V7, Berkeley, SunOS, Vax Ultrix
00072    "struct exec".  Don't assume that on this machine, the "struct exec"
00073    will lay out the same sizes or alignments.  */
00074 
00075 struct exec_bytes
00076   {
00077     unsigned char a_info[4];
00078     unsigned char a_text[4];
00079     unsigned char a_data[4];
00080     unsigned char a_bss[4];
00081     unsigned char a_syms[4];
00082     unsigned char a_entry[4];
00083     unsigned char a_trsize[4];
00084     unsigned char a_drsize[4];
00085   };
00086 
00087 /* How big the "struct exec" is on disk */
00088 #define       EXEC_BYTES_SIZE      (8 * 4)
00089 
00090 /* This is the layout in memory of a "struct exec" while we process it.  */
00091 
00092 struct exec
00093 {
00094   unsigned long a_info;            /* Use macros N_MAGIC, etc for access */
00095   unsigned a_text;          /* length of text, in bytes */
00096   unsigned a_data;          /* length of data, in bytes */
00097   unsigned a_bss;           /* length of uninitialized data area for file, in bytes */
00098   unsigned a_syms;          /* length of symbol table data in file, in bytes */
00099   unsigned a_entry;         /* start address */
00100   unsigned a_trsize;        /* length of relocation info for text, in bytes */
00101   unsigned a_drsize;        /* length of relocation info for data, in bytes */
00102 };
00103 
00104 #endif /* __STRUCT_EXEC_OVERRIDE__ */
00105 
00106 /* these go in the N_MACHTYPE field */
00107 /* These symbols could be defined by code from Suns...punt 'em */
00108 #undef M_UNKNOWN
00109 #undef M_68010
00110 #undef M_68020
00111 #undef M_SPARC
00112 enum machine_type
00113   {
00114     M_UNKNOWN = 0,
00115     M_68010 = 1,
00116     M_68020 = 2,
00117     M_SPARC = 3,
00118     /* skip a bunch so we don't run into any of sun's numbers */
00119     M_386 = 100,
00120     M_29K = 101,
00121     M_RS6000 = 102,         /* IBM RS/6000 */
00122     M_VAX4K_NETBSD = 150,
00123     /* HP/BSD formats */
00124     M_HP200 = 200,          /* hp200 (68010) BSD binary */
00125     M_HP300 = 300,          /* hp300 (68020+68881) BSD binary */
00126     M_HPUX23 = 0x020C              /* hp200/300 HPUX binary */
00127   };
00128 
00129 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
00130 #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
00131 #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
00132 #define N_SET_INFO(exec, magic, type, flags) \
00133     ((exec).a_info = ((magic) & 0xffff) \
00134      | (((int)(type) & 0xff) << 16) \
00135      | (((flags) & 0xff) << 24))
00136 #define N_SET_MAGIC(exec, magic) \
00137     ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
00138 
00139 #define N_SET_MACHTYPE(exec, machtype) \
00140     ((exec).a_info = \
00141      ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
00142 
00143 #define N_SET_FLAGS(exec, flags) \
00144     ((exec).a_info = \
00145      ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
00146 
00147 /* Code indicating object file or impure executable.  */
00148 #ifndef OMAGIC
00149 #define OMAGIC 0407
00150 #endif
00151 /* Code indicating pure executable.  */
00152 #define NMAGIC 0410
00153 /* Code indicating demand-paged executable.  */
00154 #define ZMAGIC 0413
00155 
00156 /* Virtual Address of text segment from the a.out file.  For OMAGIC,
00157    (almost always "unlinked .o's" these days), should be zero.
00158    For linked files, should reflect reality if we know it.  */
00159 
00160 #ifndef N_TXTADDR
00161 #define N_TXTADDR(x) (N_MAGIC(x)==OMAGIC? 0 : TEXT_START_ADDR)
00162 #endif
00163 
00164 #ifndef N_BADMAG
00165 #define N_BADMAG(x)    (N_MAGIC(x) != OMAGIC            \
00166                         && N_MAGIC(x) != NMAGIC         \
00167                         && N_MAGIC(x) != ZMAGIC)
00168 #endif
00169 
00170 /* By default, segment size is constant.  But on some machines, it can
00171    be a function of the a.out header (e.g. machine type).  */
00172 #ifndef       N_SEGSIZE
00173 #define       N_SEGSIZE(x)  SEGMENT_SIZE
00174 #endif
00175 
00176 /* This complexity is for encapsulated COFF support */
00177 #ifndef _N_HDROFF
00178 #define _N_HDROFF(x) (N_SEGSIZE(x) - sizeof (struct exec))
00179 #endif
00180 
00181 #ifndef N_TXTOFF
00182 #define N_TXTOFF(x)  (N_MAGIC(x) == ZMAGIC ?     \
00183                       _N_HDROFF((x)) + sizeof (struct exec) :  \
00184                       sizeof (struct exec))
00185 #endif
00186 
00187 #ifndef N_DATOFF
00188 #define N_DATOFF(x)  ( N_TXTOFF(x) + (x).a_text )
00189 #endif
00190 
00191 #ifndef N_TRELOFF
00192 #define N_TRELOFF(x) ( N_DATOFF(x) + (x).a_data )
00193 #endif
00194 
00195 #ifndef N_DRELOFF
00196 #define N_DRELOFF(x) ( N_TRELOFF(x) + (x).a_trsize )
00197 #endif
00198 
00199 #ifndef N_SYMOFF
00200 #define N_SYMOFF(x)  ( N_DRELOFF(x) + (x).a_drsize )
00201 #endif
00202 
00203 #ifndef N_STROFF
00204 #define N_STROFF(x)  ( N_SYMOFF(x) + (x).a_syms )
00205 #endif
00206 
00207 /* Address of text segment in memory after it is loaded.  */
00208 #ifndef N_TXTADDR
00209 #define       N_TXTADDR(x)  0
00210 #endif
00211 
00212 #ifndef N_DATADDR
00213 #define N_DATADDR(x) \
00214     (N_MAGIC(x)==OMAGIC? (N_TXTADDR(x)+(x).a_text) \
00215      :  (N_SEGSIZE(x) + ((N_TXTADDR(x)+(x).a_text-1) & ~(N_SEGSIZE(x)-1))))
00216 #endif
00217 
00218 /* Address of bss segment in memory after it is loaded.  */
00219 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
00220 
00221 struct nlist
00222   {
00223     union
00224       {
00225        char *n_name;
00226        struct nlist *n_next;
00227        long n_strx;
00228       }
00229     n_un;
00230     unsigned char n_type;
00231     char n_other;
00232     short n_desc;
00233     unsigned long n_value;
00234   };
00235 
00236 #define N_UNDF 0
00237 #define N_ABS 2
00238 #define N_TEXT 4
00239 #define N_DATA 6
00240 #define N_BSS 8
00241 #define       N_COMM 0x12          /* common (visible in shared lib commons) */
00242 #define N_FN 0x1F           /* File name of a .o file */
00243 
00244 /* Note: N_EXT can only usefully be OR-ed with N_UNDF, N_ABS, N_TEXT,
00245    N_DATA, or N_BSS.  When the low-order bit of other types is set,
00246    (e.g. N_WARNING versus N_FN), they are two different types.  */
00247 #define N_EXT 1
00248 #define N_TYPE 036
00249 #define N_STAB 0340
00250 
00251 /* The following type indicates the definition of a symbol as being
00252    an indirect reference to another symbol.  The other symbol
00253    appears as an undefined reference, immediately following this symbol.
00254 
00255    Indirection is asymmetrical.  The other symbol's value will be used
00256    to satisfy requests for the indirect symbol, but not vice versa.
00257    If the other symbol does not have a definition, libraries will
00258    be searched to find a definition.  */
00259 
00260 #define N_INDR 0xa
00261 
00262 /* The following symbols refer to set elements.
00263    All the N_SET[ATDB] symbols with the same name form one set.
00264    Space is allocated for the set in the text section, and each set
00265    element's value is stored into one word of the space.
00266    The first word of the space is the length of the set (number of elements).
00267 
00268    The address of the set is made into an N_SETV symbol
00269    whose name is the same as the name of the set.
00270    This symbol acts like a N_DATA global symbol
00271    in that it can satisfy undefined external references.  */
00272 
00273 /* These appear as input to LD, in a .o file.  */
00274 #define       N_SETA 0x14          /* Absolute set element symbol */
00275 #define       N_SETT 0x16          /* Text set element symbol */
00276 #define       N_SETD 0x18          /* Data set element symbol */
00277 #define       N_SETB 0x1A          /* Bss set element symbol */
00278 
00279 /* This is output from LD.  */
00280 #define N_SETV       0x1C          /* Pointer to set vector in data area.  */
00281 
00282 /* Warning symbol. The text gives a warning message, the next symbol
00283    in the table will be undefined. When the symbol is referenced, the
00284    message is printed.  */
00285 
00286 #define       N_WARNING 0x1e
00287 
00288 /* Weak symbols.  These are a GNU extension to the a.out format.  The
00289    semantics are those of ELF weak symbols.  Weak symbols are always
00290    externally visible.  The N_WEAK? values are squeezed into the
00291    available slots.  The value of a N_WEAKU symbol is 0.  The values
00292    of the other types are the definitions.  */
00293 #define N_WEAKU      0x0d          /* Weak undefined symbol.  */
00294 #define N_WEAKA 0x0e        /* Weak absolute symbol.  */
00295 #define N_WEAKT 0x0f        /* Weak text symbol.  */
00296 #define N_WEAKD 0x10        /* Weak data symbol.  */
00297 #define N_WEAKB 0x11        /* Weak bss symbol.  */
00298 
00299 /* This structure describes a single relocation to be performed.
00300    The text-relocation section of the file is a vector of these structures,
00301    all of which apply to the text section.
00302    Likewise, the data-relocation section applies to the data section.  */
00303 
00304 /* The following enum and struct were borrowed from SunOS's
00305    /usr/include/sun4/a.out.h  and extended to handle
00306    other machines.  It is currently used on SPARC and AMD 29000.
00307 
00308    reloc_ext_bytes is how it looks on disk.  reloc_info_extended is
00309    how we might process it on a native host.  */
00310 #if USE_EXTENDED_RELOC
00311 
00312 struct reloc_ext_bytes
00313   {
00314     unsigned char r_address[4];
00315     unsigned char r_index[3];
00316     unsigned char r_bits[1];
00317     unsigned char r_addend[4];
00318   };
00319 
00320 #define       RELOC_EXT_BITS_EXTERN_BIG   0x80
00321 #define       RELOC_EXT_BITS_EXTERN_LITTLE       0x01
00322 
00323 #define       RELOC_EXT_BITS_TYPE_BIG            0x1F
00324 #define       RELOC_EXT_BITS_TYPE_SH_BIG  0
00325 #define       RELOC_EXT_BITS_TYPE_LITTLE  0xF8
00326 #define       RELOC_EXT_BITS_TYPE_SH_LITTLE      3
00327 
00328 #define       RELOC_EXT_SIZE       12     /* Bytes per relocation entry */
00329 
00330 struct reloc_info_extended
00331 {
00332   unsigned long r_address;
00333   unsigned int r_index:24;
00334 # define      r_symbolnum  r_index
00335   unsigned r_extern:1;
00336   unsigned:2;
00337   /*  RS/6000 compiler does not support enum bitfield
00338            enum reloc_type r_type:5; */
00339   enum reloc_type r_type;
00340   long int r_addend;
00341 };
00342 
00343 #else
00344 
00345 /* The standard, old-fashioned, Berkeley compatible relocation struct */
00346 
00347 #ifdef TC_I860
00348 /* NOTE: three bits max, see struct reloc_info_i860.r_type */
00349 enum i860_reloc_type
00350   {
00351     NO_RELOC = 0, BRADDR, LOW0, LOW1, LOW2, LOW3, LOW4, SPLIT0, SPLIT1, SPLIT2, RELOC_32,
00352   };
00353 
00354 typedef enum i860_reloc_type reloc_type;
00355 
00356 /* NOTE: two bits max, see reloc_info_i860.r_type */
00357 enum highlow_type
00358   {
00359     NO_SPEC = 0, PAIR, HIGH, HIGHADJ,
00360   };
00361 
00362 struct reloc_info_i860
00363 {
00364   unsigned long r_address;
00365   /*
00366         * Using bit fields here is a bad idea because the order is not portable. :-(
00367         */
00368   unsigned int r_symbolnum:24;
00369   unsigned int r_pcrel:1;
00370   unsigned int r_extern:1;
00371   /* combining the two field simplifies the argument passing in "new_fix()" */
00372   /* and is compatible with the existing Sparc #ifdef's */
00373   /* r_type:  highlow_type - bits 5,4; reloc_type - bits 3-0 */
00374   unsigned int r_type:6;
00375   long r_addend;
00376 };
00377 
00378 #endif /* TC_I860 */
00379 
00380 struct reloc_std_bytes
00381   {
00382     unsigned char r_address[4];
00383     unsigned char r_index[3];
00384     unsigned char r_bits[1];
00385   };
00386 
00387 #define       RELOC_STD_BITS_PCREL_BIG    0x80
00388 #define       RELOC_STD_BITS_PCREL_LITTLE 0x01
00389 
00390 #define       RELOC_STD_BITS_LENGTH_BIG   0x60
00391 #define       RELOC_STD_BITS_LENGTH_SH_BIG       5      /* To shift to units place */
00392 #define       RELOC_STD_BITS_LENGTH_LITTLE       0x06
00393 #define       RELOC_STD_BITS_LENGTH_SH_LITTLE    1
00394 
00395 #define       RELOC_STD_BITS_EXTERN_BIG   0x10
00396 #define       RELOC_STD_BITS_EXTERN_LITTLE       0x08
00397 
00398 #define       RELOC_STD_BITS_BASEREL_BIG  0x08
00399 #define       RELOC_STD_BITS_BASEREL_LITTLE      0x08
00400 
00401 #define       RELOC_STD_BITS_JMPTABLE_BIG 0x04
00402 #define       RELOC_STD_BITS_JMPTABLE_LITTLE     0x04
00403 
00404 #define       RELOC_STD_BITS_RELATIVE_BIG 0x02
00405 #define       RELOC_STD_BITS_RELATIVE_LITTLE     0x02
00406 
00407 #define       RELOC_STD_SIZE       8      /* Bytes per relocation entry */
00408 
00409 #endif /* USE_EXTENDED_RELOC */
00410 
00411 #ifndef CUSTOM_RELOC_FORMAT
00412 struct relocation_info
00413 {
00414   /* Address (within segment) to be relocated.  */
00415   int r_address;
00416   /* The meaning of r_symbolnum depends on r_extern.  */
00417   unsigned int r_symbolnum:24;
00418   /* Nonzero means value is a pc-relative offset
00419           and it should be relocated for changes in its own address
00420           as well as for changes in the symbol or section specified.  */
00421   unsigned int r_pcrel:1;
00422   /* Length (as exponent of 2) of the field to be relocated.
00423           Thus, a value of 2 indicates 1<<2 bytes.  */
00424   unsigned int r_length:2;
00425   /* 1 => relocate with value of symbol.
00426           r_symbolnum is the index of the symbol
00427           in file's the symbol table.
00428           0 => relocate with the address of a segment.
00429           r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
00430           (the N_EXT bit may be set also, but signifies nothing).  */
00431   unsigned int r_extern:1;
00432   /* The next three bits are for SunOS shared libraries, and seem to
00433           be undocumented.  */
00434 #ifdef TC_NS32K
00435   unsigned int r_bsr:1;
00436   unsigned int r_disp:2;
00437 #else
00438   unsigned int r_baserel:1; /* Linkage table relative */
00439   unsigned int r_jmptable:1;       /* pc-relative to jump table */
00440   unsigned int r_relative:1;       /* "relative relocation" */
00441 #endif /* TC_NS32K */
00442   /* unused */
00443   unsigned int r_pad:1;            /* Padding -- set to zero */
00444 };
00445 
00446 #endif /* CUSTOM_RELOC_FORMAT */
00447 
00448 #endif /* __A_OUT_GNU_H__ */
00449 
00450 /* end of aout_gnu.h */