Back to index

cell-binutils  2.17cvs20070401
adobe.h
Go to the documentation of this file.
00001 /* `a.out.adobe' differences from standard a.out files
00002 
00003    Copyright 2001 Free Software Foundation, Inc.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2 of the License, or
00008    (at your option) any later version.
00009    
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014    
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00018 
00019 #ifndef __A_OUT_ADOBE_H__
00020 #define __A_OUT_ADOBE_H__
00021 
00022 #define       BYTES_IN_WORD 4
00023 
00024 /* Struct external_exec is the same.  */
00025 
00026 /* This is the layout on disk of the 32-bit or 64-bit exec header. */
00027 
00028 struct external_exec 
00029 {
00030   bfd_byte e_info[4];              /* magic number and stuff          */
00031   bfd_byte e_text[BYTES_IN_WORD]; /* length of text section in bytes  */
00032   bfd_byte e_data[BYTES_IN_WORD]; /* length of data section in bytes  */
00033   bfd_byte e_bss[BYTES_IN_WORD]; /* length of bss area in bytes              */
00034   bfd_byte e_syms[BYTES_IN_WORD]; /* length of symbol table in bytes  */
00035   bfd_byte e_entry[BYTES_IN_WORD]; /* start address                   */
00036   bfd_byte e_trsize[BYTES_IN_WORD]; /* length of text relocation info */
00037   bfd_byte e_drsize[BYTES_IN_WORD]; /* length of data relocation info        */
00038 };
00039 
00040 #define       EXEC_BYTES_SIZE      (4 + BYTES_IN_WORD * 7)
00041 
00042 /* Magic numbers for a.out files */
00043 
00044 #undef ZMAGIC
00045 #define       ZMAGIC 0xAD0BE              /* Cute, eh?  */
00046 #undef OMAGIC
00047 #undef NMAGIC
00048 
00049 #define N_BADMAG(x)    ((x).a_info != ZMAGIC)
00050 
00051 /* By default, segment size is constant.  But some machines override this
00052    to be a function of the a.out header (e.g. machine type).  */
00053 #ifndef       N_SEGSIZE
00054 #define       N_SEGSIZE(x)  SEGMENT_SIZE
00055 #endif
00056 #undef N_SEGSIZE   /* FIXMEXXXX */
00057 
00058 /* Segment information for the a.out.Adobe format is specified after the
00059    file header.  It contains N segment descriptors, followed by one with
00060    a type of zero.  
00061 
00062    The actual text of the segments starts at N_TXTOFF in the file,
00063    regardless of how many or how few segment headers there are.  */
00064 
00065 struct external_segdesc {
00066        unsigned char e_type[1];
00067        unsigned char e_size[3];
00068        unsigned char e_virtbase[4];
00069        unsigned char e_filebase[4];
00070 };
00071 
00072 struct internal_segdesc {
00073        unsigned int  a_type:8;     /* Segment type N_TEXT, N_DATA, 0 */
00074        unsigned int  a_size:24;    /* Segment size */
00075        bfd_vma              a_virtbase;   /* Virtual address */
00076        unsigned int  a_filebase;   /* Base address in object file */
00077 };
00078 
00079 #define N_TXTADDR(x) \
00080 
00081 /* This is documented to be at 1024, but appears to really be at 2048.
00082    FIXME?!  */
00083 #define N_TXTOFF(x)  2048
00084 
00085 #define       N_TXTSIZE(x) ((x).a_text)
00086 
00087 #define N_DATADDR(x)
00088 
00089 #define N_BSSADDR(x)
00090 
00091 /* Offsets of the various portions of the file after the text segment.  */
00092 
00093 #define N_DATOFF(x)  ( N_TXTOFF(x) + N_TXTSIZE(x) )
00094 #define N_TRELOFF(x) ( N_DATOFF(x) + (x).a_data )
00095 #define N_DRELOFF(x) ( N_TRELOFF(x) + (x).a_trsize )
00096 #define N_SYMOFF(x)  ( N_DRELOFF(x) + (x).a_drsize )
00097 #define N_STROFF(x)  ( N_SYMOFF(x) + (x).a_syms )
00098 
00099 /* Symbols */
00100 struct external_nlist {
00101   bfd_byte e_strx[BYTES_IN_WORD];  /* index into string table of name */
00102   bfd_byte e_type[1];                     /* type of symbol */
00103   bfd_byte e_other[1];                    /* misc info (usually empty) */
00104   bfd_byte e_desc[2];                     /* description field */
00105   bfd_byte e_value[BYTES_IN_WORD]; /* value of symbol */
00106 };
00107 
00108 #define EXTERNAL_NLIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD)
00109 
00110 struct internal_nlist {
00111   unsigned long n_strx;                   /* index into string table of name */
00112   unsigned char n_type;                   /* type of symbol */
00113   unsigned char n_other;           /* misc info (usually empty) */
00114   unsigned short n_desc;           /* description field */
00115   bfd_vma n_value;                 /* value of symbol */
00116 };
00117 
00118 /* The n_type field is the symbol type, containing:  */
00119 
00120 #define N_UNDF       0      /* Undefined symbol */
00121 #define N_ABS        2      /* Absolute symbol -- defined at particular addr */
00122 #define N_TEXT       4      /* Text sym -- defined at offset in text seg */
00123 #define N_DATA       6      /* Data sym -- defined at offset in data seg */
00124 #define N_BSS        8      /* BSS  sym -- defined at offset in zero'd seg */
00125 #define       N_COMM 0x12   /* Common symbol (visible after shared lib dynlink) */
00126 #define N_FN  0x1f   /* File name of .o file */
00127 #define       N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */
00128 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
00129    N_DATA, or N_BSS.  When the low-order bit of other types is set,
00130    (e.g. N_WARNING versus N_FN), they are two different types.  */
00131 #define N_EXT        1      /* External symbol (as opposed to local-to-this-file) */
00132 #define N_TYPE  0x1e
00133 #define N_STAB       0xe0   /* If any of these bits are on, it's a debug symbol */
00134 
00135 #define N_INDR 0x0a
00136 
00137 /* The following symbols refer to set elements.
00138    All the N_SET[ATDB] symbols with the same name form one set.
00139    Space is allocated for the set in the text section, and each set
00140    elements value is stored into one word of the space.
00141    The first word of the space is the length of the set (number of elements).
00142 
00143    The address of the set is made into an N_SETV symbol
00144    whose name is the same as the name of the set.
00145    This symbol acts like a N_DATA global symbol
00146    in that it can satisfy undefined external references.  */
00147 
00148 /* These appear as input to LD, in a .o file.  */
00149 #define       N_SETA 0x14          /* Absolute set element symbol */
00150 #define       N_SETT 0x16          /* Text set element symbol */
00151 #define       N_SETD 0x18          /* Data set element symbol */
00152 #define       N_SETB 0x1A          /* Bss set element symbol */
00153 
00154 /* This is output from LD.  */
00155 #define N_SETV       0x1C          /* Pointer to set vector in data area.  */
00156 
00157 /* Warning symbol. The text gives a warning message, the next symbol
00158    in the table will be undefined. When the symbol is referenced, the
00159    message is printed.  */
00160 
00161 #define       N_WARNING 0x1e
00162 
00163 /* Relocations 
00164 
00165   There       are two types of relocation flavours for a.out systems,
00166   standard and extended. The standard form is used on systems where the
00167   instruction has room for all the bits of an offset to the operand, whilst
00168   the extended form is used when an address operand has to be split over n
00169   instructions. Eg, on the 68k, each move instruction can reference
00170   the target with a displacement of 16 or 32 bits. On the sparc, move
00171   instructions use an offset of 14 bits, so the offset is stored in
00172   the reloc field, and the data in the section is ignored.
00173 */
00174 
00175 /* This structure describes a single relocation to be performed.
00176    The text-relocation section of the file is a vector of these structures,
00177    all of which apply to the text section.
00178    Likewise, the data-relocation section applies to the data section.  */
00179 
00180 struct reloc_std_external {
00181   bfd_byte r_address[BYTES_IN_WORD];      /* offset of of data to relocate */
00182   bfd_byte r_index[3];      /* symbol table index of symbol    */
00183   bfd_byte r_type[1];       /* relocation type                 */
00184 };
00185 
00186 #define       RELOC_STD_BITS_PCREL_BIG    0x80
00187 #define       RELOC_STD_BITS_PCREL_LITTLE 0x01
00188 
00189 #define       RELOC_STD_BITS_LENGTH_BIG   0x60
00190 #define       RELOC_STD_BITS_LENGTH_SH_BIG       5      /* To shift to units place */
00191 #define       RELOC_STD_BITS_LENGTH_LITTLE       0x06
00192 #define       RELOC_STD_BITS_LENGTH_SH_LITTLE    1
00193 
00194 #define       RELOC_STD_BITS_EXTERN_BIG   0x10
00195 #define       RELOC_STD_BITS_EXTERN_LITTLE       0x08
00196 
00197 #define       RELOC_STD_BITS_BASEREL_BIG  0x08
00198 #define       RELOC_STD_BITS_BASEREL_LITTLE      0x08
00199 
00200 #define       RELOC_STD_BITS_JMPTABLE_BIG 0x04
00201 #define       RELOC_STD_BITS_JMPTABLE_LITTLE     0x04
00202 
00203 #define       RELOC_STD_BITS_RELATIVE_BIG 0x02
00204 #define       RELOC_STD_BITS_RELATIVE_LITTLE     0x02
00205 
00206 #define       RELOC_STD_SIZE       (BYTES_IN_WORD + 3 + 1)            /* Bytes per relocation entry */
00207 
00208 struct reloc_std_internal
00209 {
00210   bfd_vma r_address;        /* Address (within segment) to be relocated.  */
00211   /* The meaning of r_symbolnum depends on r_extern.  */
00212   unsigned int r_symbolnum:24;
00213   /* Nonzero means value is a pc-relative offset
00214      and it should be relocated for changes in its own address
00215      as well as for changes in the symbol or section specified.  */
00216   unsigned int r_pcrel:1;
00217   /* Length (as exponent of 2) of the field to be relocated.
00218      Thus, a value of 2 indicates 1<<2 bytes.  */
00219   unsigned int r_length:2;
00220   /* 1 => relocate with value of symbol.
00221      r_symbolnum is the index of the symbol
00222      in files the symbol table.
00223      0 => relocate with the address of a segment.
00224      r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
00225      (the N_EXT bit may be set also, but signifies nothing).  */
00226   unsigned int r_extern:1;
00227   /* The next three bits are for SunOS shared libraries, and seem to
00228      be undocumented.  */
00229   unsigned int r_baserel:1; /* Linkage table relative */
00230   unsigned int r_jmptable:1;       /* pc-relative to jump table */
00231   unsigned int r_relative:1;       /* "relative relocation" */
00232   /* unused */
00233   unsigned int r_pad:1;            /* Padding -- set to zero */
00234 };
00235 
00236 
00237 /* EXTENDED RELOCS  */
00238 
00239 struct reloc_ext_external {
00240   bfd_byte r_address[BYTES_IN_WORD];      /* offset of of data to relocate   */
00241   bfd_byte r_index[3];      /* symbol table index of symbol    */
00242   bfd_byte r_type[1];       /* relocation type                 */
00243   bfd_byte r_addend[BYTES_IN_WORD];       /* datum addend                           */
00244 };
00245 
00246 #define       RELOC_EXT_BITS_EXTERN_BIG   0x80
00247 #define       RELOC_EXT_BITS_EXTERN_LITTLE       0x01
00248 
00249 #define       RELOC_EXT_BITS_TYPE_BIG            0x1F
00250 #define       RELOC_EXT_BITS_TYPE_SH_BIG  0
00251 #define       RELOC_EXT_BITS_TYPE_LITTLE  0xF8
00252 #define       RELOC_EXT_BITS_TYPE_SH_LITTLE      3
00253 
00254 /* Bytes per relocation entry */
00255 #define       RELOC_EXT_SIZE       (BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD)
00256 
00257 enum reloc_type
00258 {
00259   /* simple relocations */
00260   RELOC_8,                  /* data[0:7] = addend + sv         */
00261   RELOC_16,                 /* data[0:15] = addend + sv               */
00262   RELOC_32,                 /* data[0:31] = addend + sv               */
00263   /* pc-rel displacement */
00264   RELOC_DISP8,                     /* data[0:7] = addend - pc + sv    */
00265   RELOC_DISP16,                    /* data[0:15] = addend - pc + sv   */
00266   RELOC_DISP32,                    /* data[0:31] = addend - pc + sv   */
00267   /* Special */
00268   RELOC_WDISP30,            /* data[0:29] = (addend + sv - pc)>>2     */
00269   RELOC_WDISP22,            /* data[0:21] = (addend + sv - pc)>>2     */
00270   RELOC_HI22,               /* data[0:21] = (addend + sv)>>10  */
00271   RELOC_22,                 /* data[0:21] = (addend + sv)             */
00272   RELOC_13,                 /* data[0:12] = (addend + sv)             */
00273   RELOC_LO10,               /* data[0:9] = (addend + sv)              */
00274   RELOC_SFA_BASE,           
00275   RELOC_SFA_OFF13,
00276   /* P.I.C. (base-relative) */
00277   RELOC_BASE10,             /* Not sure - maybe we can do this the */
00278   RELOC_BASE13,                    /* right way now */
00279   RELOC_BASE22,
00280   /* for some sort of pc-rel P.I.C. (?) */
00281   RELOC_PC10,
00282   RELOC_PC22,
00283   /* P.I.C. jump table */
00284   RELOC_JMP_TBL,
00285   /* reputedly for shared libraries somehow */
00286   RELOC_SEGOFF16,
00287   RELOC_GLOB_DAT,
00288   RELOC_JMP_SLOT,
00289   RELOC_RELATIVE,
00290 
00291   RELOC_11,   
00292   RELOC_WDISP2_14,
00293   RELOC_WDISP19,
00294   RELOC_HHI22,                     /* data[0:21] = (addend + sv) >> 42     */
00295   RELOC_HLO10,                     /* data[0:9] = (addend + sv) >> 32      */
00296   
00297   /* 29K relocation types */
00298   RELOC_JUMPTARG,
00299   RELOC_CONST,
00300   RELOC_CONSTH,
00301   
00302   NO_RELOC
00303   };
00304 
00305 
00306 struct reloc_internal {
00307   bfd_vma r_address;        /* offset of of data to relocate   */
00308   long r_index;             /* symbol table index of symbol    */
00309   enum reloc_type r_type;   /* relocation type                 */
00310   bfd_vma r_addend;         /* datum addend                           */
00311 };
00312 
00313 #endif                      /* __A_OUT_ADOBE_H__ */