Back to index

cell-binutils  2.17cvs20070401
ecoff.h
Go to the documentation of this file.
00001 /* Generic ECOFF support.
00002    This does not include symbol information, found in sym.h and
00003    symconst.h.
00004 
00005    Copyright 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 
00021 #ifndef ECOFF_H
00022 #define ECOFF_H
00023 
00024 /* Mips magic numbers used in filehdr.  MIPS_MAGIC_LITTLE is used on
00025    little endian machines.  MIPS_MAGIC_BIG is used on big endian
00026    machines.  Where is MIPS_MAGIC_1 from?  */
00027 #define MIPS_MAGIC_1 0x0180
00028 #define MIPS_MAGIC_LITTLE 0x0162
00029 #define MIPS_MAGIC_BIG 0x0160
00030 
00031 /* These are the magic numbers used for MIPS code compiled at ISA
00032    level 2.  */
00033 #define MIPS_MAGIC_LITTLE2 0x0166
00034 #define MIPS_MAGIC_BIG2 0x0163
00035 
00036 /* These are the magic numbers used for MIPS code compiled at ISA
00037    level 3.  */
00038 #define MIPS_MAGIC_LITTLE3 0x142
00039 #define MIPS_MAGIC_BIG3 0x140
00040 
00041 /* Alpha magic numbers used in filehdr.  */
00042 #define ALPHA_MAGIC 0x183
00043 #define ALPHA_MAGIC_BSD 0x185
00044 /* A compressed version of an ALPHA_MAGIC file created by DEC's tools.  */
00045 #define ALPHA_MAGIC_COMPRESSED 0x188
00046 
00047 /* Magic numbers used in a.out header.  */
00048 #define ECOFF_AOUT_OMAGIC 0407     /* not demand paged (ld -N).  */
00049 #define ECOFF_AOUT_ZMAGIC 0413     /* demand load format, eg normal ld output */
00050 
00051 /* Names of special sections.  */
00052 #define _TEXT   ".text"
00053 #define _DATA   ".data"
00054 #define _BSS    ".bss"
00055 #define _RDATA       ".rdata"
00056 #define _SDATA       ".sdata"
00057 #define _SBSS ".sbss"
00058 #define _LITA ".lita"
00059 #define _LIT4 ".lit4"
00060 #define _LIT8 ".lit8"
00061 #define _LIB  ".lib"
00062 #define _INIT ".init"
00063 #define _FINI ".fini"
00064 #define _PDATA       ".pdata"
00065 #define _XDATA       ".xdata"
00066 #define _GOT  ".got"
00067 #define _HASH ".hash"
00068 #define _DYNSYM      ".dynsym"
00069 #define _DYNSTR      ".dynstr"
00070 #define _RELDYN      ".rel.dyn"
00071 #define _CONFLIC ".conflic"
00072 #define _COMMENT ".comment"
00073 #define _LIBLIST ".liblist"
00074 #define _DYNAMIC ".dynamic"
00075 #define _RCONST      ".rconst"
00076 
00077 /* ECOFF uses some additional section flags.  */
00078 #define STYP_RDATA        0x100
00079 #define STYP_SDATA        0x200
00080 #define STYP_SBSS         0x400
00081 #define STYP_GOT         0x1000
00082 #define STYP_DYNAMIC     0x2000
00083 #define STYP_DYNSYM      0x4000
00084 #define STYP_RELDYN      0x8000
00085 #define STYP_DYNSTR     0x10000
00086 #define STYP_HASH       0x20000
00087 #define STYP_LIBLIST    0x40000
00088 #define STYP_CONFLIC   0x100000
00089 #define STYP_ECOFF_FINI      0x1000000
00090 #define STYP_EXTENDESC       0x2000000 /* 0x02FFF000 bits => scn type, rest clr */
00091 #define STYP_LITA     0x4000000
00092 #define STYP_LIT8     0x8000000
00093 #define STYP_LIT4    0x10000000
00094 #define STYP_ECOFF_LIB      0x40000000
00095 #define STYP_ECOFF_INIT 0x80000000
00096 #define STYP_OTHER_LOAD (STYP_ECOFF_INIT | STYP_ECOFF_FINI)
00097 
00098 /* extended section types */
00099 #define STYP_COMMENT  0x2100000
00100 #define STYP_RCONST   0x2200000
00101 #define STYP_XDATA    0x2400000
00102 #define STYP_PDATA    0x2800000
00103 
00104 /* The linker needs a section to hold small common variables while
00105    linking.  There is no convenient way to create it when the linker
00106    needs it, so we always create one for each BFD.  We then avoid
00107    writing it out.  */
00108 #define SCOMMON ".scommon"
00109 
00110 /* If the extern bit in a reloc is 1, then r_symndx is an index into
00111    the external symbol table.  If the extern bit is 0, then r_symndx
00112    indicates a section, and is one of the following values.  */
00113 #define RELOC_SECTION_NONE  0
00114 #define RELOC_SECTION_TEXT  1
00115 #define RELOC_SECTION_RDATA 2
00116 #define RELOC_SECTION_DATA  3
00117 #define RELOC_SECTION_SDATA 4
00118 #define RELOC_SECTION_SBSS  5
00119 #define RELOC_SECTION_BSS   6
00120 #define RELOC_SECTION_INIT  7
00121 #define RELOC_SECTION_LIT8  8
00122 #define RELOC_SECTION_LIT4  9
00123 #define RELOC_SECTION_XDATA    10
00124 #define RELOC_SECTION_PDATA    11
00125 #define RELOC_SECTION_FINI     12
00126 #define RELOC_SECTION_LITA     13
00127 #define RELOC_SECTION_ABS      14
00128 #define RELOC_SECTION_RCONST   15
00129 
00130 #define NUM_RELOC_SECTIONS     16
00131 
00132 /********************** STABS **********************/
00133 
00134 /* gcc uses mips-tfile to output type information in special stabs
00135    entries.  These must match the corresponding definition in
00136    gcc/config/mips.h.  At some point, these should probably go into a
00137    shared include file, but currently gcc and gdb do not share any
00138    directories. */
00139 #define CODE_MASK 0x8F300
00140 #define ECOFF_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
00141 #define ECOFF_MARK_STAB(code) ((code)+CODE_MASK)
00142 #define ECOFF_UNMARK_STAB(code) ((code)-CODE_MASK)
00143 #define STABS_SYMBOL "@stabs"
00144 
00145 /********************** COFF **********************/
00146 
00147 /* gcc also uses mips-tfile to output COFF debugging information.
00148    These are the values it uses when outputting the .type directive.
00149    These should also be in a shared include file.  */
00150 #define N_BTMASK     (017)
00151 #define N_TMASK             (060)
00152 #define N_BTSHFT     (4)
00153 #define N_TSHIFT     (2)
00154 
00155 /********************** AUX **********************/
00156 
00157 /* The auxiliary type information is the same on all known ECOFF
00158    targets.  I can't see any reason that it would ever change, so I am
00159    going to gamble and define the external structures here, in the
00160    target independent ECOFF header file.  The internal forms are
00161    defined in coff/sym.h, which was originally donated by MIPS
00162    Computer Systems.  */
00163 
00164 /* Type information external record */
00165 
00166 struct tir_ext {
00167        unsigned char t_bits1[1];
00168        unsigned char t_tq45[1];
00169        unsigned char t_tq01[1];
00170        unsigned char t_tq23[1];
00171 };
00172 
00173 #define       TIR_BITS1_FBITFIELD_BIG            ((unsigned int) 0x80)
00174 #define       TIR_BITS1_FBITFIELD_LITTLE  ((unsigned int) 0x01)
00175 
00176 #define       TIR_BITS1_CONTINUED_BIG            ((unsigned int) 0x40)
00177 #define       TIR_BITS1_CONTINUED_LITTLE  ((unsigned int) 0x02)
00178 
00179 #define       TIR_BITS1_BT_BIG            ((unsigned int) 0x3F)
00180 #define       TIR_BITS1_BT_SH_BIG         0
00181 #define       TIR_BITS1_BT_LITTLE         ((unsigned int) 0xFC)
00182 #define       TIR_BITS1_BT_SH_LITTLE             2
00183 
00184 #define       TIR_BITS_TQ4_BIG            ((unsigned int) 0xF0)
00185 #define       TIR_BITS_TQ4_SH_BIG         4
00186 #define       TIR_BITS_TQ5_BIG            ((unsigned int) 0x0F)
00187 #define       TIR_BITS_TQ5_SH_BIG         0
00188 #define       TIR_BITS_TQ4_LITTLE         ((unsigned int) 0x0F)
00189 #define       TIR_BITS_TQ4_SH_LITTLE             0
00190 #define       TIR_BITS_TQ5_LITTLE         ((unsigned int) 0xF0)
00191 #define       TIR_BITS_TQ5_SH_LITTLE             4
00192 
00193 #define       TIR_BITS_TQ0_BIG            ((unsigned int) 0xF0)
00194 #define       TIR_BITS_TQ0_SH_BIG         4
00195 #define       TIR_BITS_TQ1_BIG            ((unsigned int) 0x0F)
00196 #define       TIR_BITS_TQ1_SH_BIG         0
00197 #define       TIR_BITS_TQ0_LITTLE         ((unsigned int) 0x0F)
00198 #define       TIR_BITS_TQ0_SH_LITTLE             0
00199 #define       TIR_BITS_TQ1_LITTLE         ((unsigned int) 0xF0)
00200 #define       TIR_BITS_TQ1_SH_LITTLE             4
00201 
00202 #define       TIR_BITS_TQ2_BIG            ((unsigned int) 0xF0)
00203 #define       TIR_BITS_TQ2_SH_BIG         4
00204 #define       TIR_BITS_TQ3_BIG            ((unsigned int) 0x0F)
00205 #define       TIR_BITS_TQ3_SH_BIG         0
00206 #define       TIR_BITS_TQ2_LITTLE         ((unsigned int) 0x0F)
00207 #define       TIR_BITS_TQ2_SH_LITTLE             0
00208 #define       TIR_BITS_TQ3_LITTLE         ((unsigned int) 0xF0)
00209 #define       TIR_BITS_TQ3_SH_LITTLE             4
00210 
00211 /* Relative symbol external record */
00212 
00213 struct rndx_ext {
00214        unsigned char r_bits[4];
00215 };
00216 
00217 #define       RNDX_BITS0_RFD_SH_LEFT_BIG  4
00218 #define       RNDX_BITS1_RFD_BIG          ((unsigned int) 0xF0)
00219 #define       RNDX_BITS1_RFD_SH_BIG              4
00220 
00221 #define       RNDX_BITS0_RFD_SH_LEFT_LITTLE      0
00222 #define       RNDX_BITS1_RFD_LITTLE              ((unsigned int) 0x0F)
00223 #define       RNDX_BITS1_RFD_SH_LEFT_LITTLE      8
00224 
00225 #define       RNDX_BITS1_INDEX_BIG        ((unsigned int) 0x0F)
00226 #define       RNDX_BITS1_INDEX_SH_LEFT_BIG       16
00227 #define       RNDX_BITS2_INDEX_SH_LEFT_BIG       8
00228 #define       RNDX_BITS3_INDEX_SH_LEFT_BIG       0
00229 
00230 #define       RNDX_BITS1_INDEX_LITTLE            ((unsigned int) 0xF0)
00231 #define       RNDX_BITS1_INDEX_SH_LITTLE  4
00232 #define       RNDX_BITS2_INDEX_SH_LEFT_LITTLE    4
00233 #define       RNDX_BITS3_INDEX_SH_LEFT_LITTLE    12
00234 
00235 /* Auxiliary symbol information external record */
00236 
00237 union aux_ext {
00238        struct tir_ext       a_ti;
00239        struct rndx_ext      a_rndx;
00240        unsigned char a_dnLow[4];
00241        unsigned char a_dnHigh[4];
00242        unsigned char a_isym[4];
00243        unsigned char a_iss[4];
00244        unsigned char a_width[4];
00245        unsigned char a_count[4];
00246 };
00247 
00248 #define AUX_GET_ANY(bigend, ax, field) \
00249   ((bigend) ? bfd_getb32 ((ax)->field) : bfd_getl32 ((ax)->field))
00250 
00251 #define       AUX_GET_DNLOW(bigend, ax)   AUX_GET_ANY ((bigend), (ax), a_dnLow)
00252 #define       AUX_GET_DNHIGH(bigend, ax)  AUX_GET_ANY ((bigend), (ax), a_dnHigh)
00253 #define       AUX_GET_ISYM(bigend, ax)    AUX_GET_ANY ((bigend), (ax), a_isym)
00254 #define AUX_GET_ISS(bigend, ax)           AUX_GET_ANY ((bigend), (ax), a_iss)
00255 #define AUX_GET_WIDTH(bigend, ax)  AUX_GET_ANY ((bigend), (ax), a_width)
00256 #define AUX_GET_COUNT(bigend, ax)  AUX_GET_ANY ((bigend), (ax), a_count)
00257 
00258 #define AUX_PUT_ANY(bigend, val, ax, field) \
00259   ((bigend) \
00260    ? (bfd_putb32 ((bfd_vma) (val), (ax)->field), 0) \
00261    : (bfd_putl32 ((bfd_vma) (val), (ax)->field), 0))
00262 
00263 #define AUX_PUT_DNLOW(bigend, val, ax) \
00264   AUX_PUT_ANY ((bigend), (val), (ax), a_dnLow)
00265 #define AUX_PUT_DNHIGH(bigend, val, ax) \
00266   AUX_PUT_ANY ((bigend), (val), (ax), a_dnHigh)
00267 #define AUX_PUT_ISYM(bigend, val, ax) \
00268   AUX_PUT_ANY ((bigend), (val), (ax), a_isym)
00269 #define AUX_PUT_ISS(bigend, val, ax) \
00270   AUX_PUT_ANY ((bigend), (val), (ax), a_iss)
00271 #define AUX_PUT_WIDTH(bigend, val, ax) \
00272   AUX_PUT_ANY ((bigend), (val), (ax), a_width)
00273 #define AUX_PUT_COUNT(bigend, val, ax) \
00274   AUX_PUT_ANY ((bigend), (val), (ax), a_count)
00275 
00276 /********************** SYMBOLS **********************/
00277 
00278 /* For efficiency, gdb deals directly with the unswapped symbolic
00279    information (that way it only takes the time to swap information
00280    that it really needs to read).  gdb originally retrieved the
00281    information directly from the BFD backend information, but that
00282    strategy, besides being sort of ugly, does not work for MIPS ELF,
00283    which also uses ECOFF debugging information.  This structure holds
00284    pointers to the (mostly) unswapped symbolic information.  */
00285 
00286 struct ecoff_debug_info
00287 {
00288   /* The swapped ECOFF symbolic header.  */
00289   HDRR symbolic_header;
00290 
00291   /* Pointers to the unswapped symbolic information.  Note that the
00292      pointers to external structures point to different sorts of
00293      information on different ECOFF targets.  The ecoff_debug_swap
00294      structure provides the sizes of the structures and the functions
00295      needed to swap the information in and out.  These pointers are
00296      all pointers to arrays, not single structures.  They will be NULL
00297      if there are no instances of the relevant structure.  These
00298      fields are also used by the assembler to output ECOFF debugging
00299      information.  */
00300   unsigned char *line;
00301   void *external_dnr;       /* struct dnr_ext */
00302   void *external_pdr;       /* struct pdr_ext */
00303   void *external_sym;       /* struct sym_ext */
00304   void *external_opt;       /* struct opt_ext */
00305   union aux_ext *external_aux;
00306   char *ss;
00307   char *ssext;
00308   void *external_fdr;       /* struct fdr_ext */
00309   void *external_rfd;       /* struct rfd_ext */
00310   void *external_ext;       /* struct ext_ext */
00311 
00312   /* These fields are used when linking.  They may disappear at some
00313      point.  */
00314   char *ssext_end;
00315   void *external_ext_end;
00316 
00317   /* When linking, this field holds a mapping from the input FDR
00318      numbers to the output numbers, and is used when writing out the
00319      external symbols.  It is NULL if no mapping is required.  */
00320   RFDT *ifdmap;
00321 
00322   /* The swapped FDR information.  Currently this is never NULL, but
00323      code using this structure should probably double-check in case
00324      this changes in the future.  This is a pointer to an array, not a
00325      single structure.  */
00326   FDR *fdr;
00327 };
00328 
00329 /* These structures are used by the ECOFF find_nearest_line function.  */
00330 
00331 struct ecoff_fdrtab_entry
00332 {
00333   /* Base address in .text of this FDR.  */
00334   bfd_vma base_addr;
00335   FDR *fdr;
00336 };
00337 
00338 struct ecoff_find_line
00339 {
00340   /* Allocated memory to hold function and file names.  */
00341   char *find_buffer;
00342 
00343   /* FDR table, sorted by address: */
00344   long fdrtab_len;
00345   struct ecoff_fdrtab_entry *fdrtab;
00346 
00347   /* Cache entry for most recently found line information.  The sect
00348      field is NULL if this cache does not contain valid information.  */
00349   struct
00350     {
00351       asection *sect;
00352       bfd_vma start;
00353       bfd_vma stop;
00354       const char *filename;
00355       const char *functionname;
00356       unsigned int line_num;
00357     } cache;
00358 };
00359 
00360 /********************** SWAPPING **********************/
00361 
00362 /* The generic ECOFF code needs to be able to swap debugging
00363    information in and out in the specific format used by a particular
00364    ECOFF implementation.  This structure provides the information
00365    needed to do this.  */
00366 
00367 struct ecoff_debug_swap
00368 {
00369   /* Symbol table magic number.  */
00370   int sym_magic;
00371   /* Alignment of debugging information.  E.g., 4.  */
00372   bfd_size_type debug_align;
00373   /* Sizes of external symbolic information.  */
00374   bfd_size_type external_hdr_size;
00375   bfd_size_type external_dnr_size;
00376   bfd_size_type external_pdr_size;
00377   bfd_size_type external_sym_size;
00378   bfd_size_type external_opt_size;
00379   bfd_size_type external_fdr_size;
00380   bfd_size_type external_rfd_size;
00381   bfd_size_type external_ext_size;
00382   /* Functions to swap in external symbolic data.  */
00383   void (*swap_hdr_in) (bfd *, void *, HDRR *);
00384   void (*swap_dnr_in) (bfd *, void *, DNR *);
00385   void (*swap_pdr_in) (bfd *, void *, PDR *);
00386   void (*swap_sym_in) (bfd *, void *, SYMR *);
00387   void (*swap_opt_in) (bfd *, void *, OPTR *);
00388   void (*swap_fdr_in) (bfd *, void *, FDR *);
00389   void (*swap_rfd_in) (bfd *, void *, RFDT *);
00390   void (*swap_ext_in) (bfd *, void *, EXTR *);
00391   void (*swap_tir_in) (int, const struct tir_ext *, TIR *);
00392   void (*swap_rndx_in) (int, const struct rndx_ext *, RNDXR *);
00393   /* Functions to swap out external symbolic data.  */
00394   void (*swap_hdr_out) (bfd *, const HDRR *, void *);
00395   void (*swap_dnr_out) (bfd *, const DNR *, void *);
00396   void (*swap_pdr_out) (bfd *, const PDR *, void *);
00397   void (*swap_sym_out) (bfd *, const SYMR *, void *);
00398   void (*swap_opt_out) (bfd *, const OPTR *, void *);
00399   void (*swap_fdr_out) (bfd *, const FDR *, void *);
00400   void (*swap_rfd_out) (bfd *, const RFDT *, void *);
00401   void (*swap_ext_out) (bfd *, const EXTR *, void *);
00402   void (*swap_tir_out) (int, const TIR *, struct tir_ext *);
00403   void (*swap_rndx_out) (int, const RNDXR *, struct rndx_ext *);
00404   /* Function to read symbol data and set up pointers in
00405      ecoff_debug_info structure.  The section argument is used for
00406      ELF, not straight ECOFF.  */
00407   bfd_boolean (*read_debug_info) (bfd *, asection *, struct ecoff_debug_info *);
00408 };
00409 
00410 #endif /* ! defined (ECOFF_H) */