1 /* Generic ECOFF support. 2 This does not include symbol information, found in sym.h and 3 symconst.h. 4 5 Copyright (C) 2001-2016 Free Software Foundation, Inc. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 20 MA 02110-1301, USA. */ 21 22 #ifndef ECOFF_H 23 #define ECOFF_H 24 25 /* Mips magic numbers used in filehdr. MIPS_MAGIC_LITTLE is used on 26 little endian machines. MIPS_MAGIC_BIG is used on big endian 27 machines. Where is MIPS_MAGIC_1 from? */ 28 #define MIPS_MAGIC_1 0x0180 29 #define MIPS_MAGIC_LITTLE 0x0162 30 #define MIPS_MAGIC_BIG 0x0160 31 32 /* These are the magic numbers used for MIPS code compiled at ISA 33 level 2. */ 34 #define MIPS_MAGIC_LITTLE2 0x0166 35 #define MIPS_MAGIC_BIG2 0x0163 36 37 /* These are the magic numbers used for MIPS code compiled at ISA 38 level 3. */ 39 #define MIPS_MAGIC_LITTLE3 0x142 40 #define MIPS_MAGIC_BIG3 0x140 41 42 /* Alpha magic numbers used in filehdr. */ 43 #define ALPHA_MAGIC 0x183 44 #define ALPHA_MAGIC_BSD 0x185 45 /* A compressed version of an ALPHA_MAGIC file created by DEC's tools. */ 46 #define ALPHA_MAGIC_COMPRESSED 0x188 47 48 /* Magic numbers used in a.out header. */ 49 #define ECOFF_AOUT_OMAGIC 0407 /* not demand paged (ld -N). */ 50 #define ECOFF_AOUT_ZMAGIC 0413 /* demand load format, eg normal ld output */ 51 52 /* Names of special sections. */ 53 #define _TEXT ".text" 54 #define _DATA ".data" 55 #define _BSS ".bss" 56 #define _RDATA ".rdata" 57 #define _SDATA ".sdata" 58 #define _SBSS ".sbss" 59 #define _LITA ".lita" 60 #define _LIT4 ".lit4" 61 #define _LIT8 ".lit8" 62 #define _LIB ".lib" 63 #define _INIT ".init" 64 #define _FINI ".fini" 65 #define _PDATA ".pdata" 66 #define _XDATA ".xdata" 67 #define _GOT ".got" 68 #define _HASH ".hash" 69 #define _DYNSYM ".dynsym" 70 #define _DYNSTR ".dynstr" 71 #define _RELDYN ".rel.dyn" 72 #define _CONFLIC ".conflic" 73 #define _COMMENT ".comment" 74 #define _LIBLIST ".liblist" 75 #define _DYNAMIC ".dynamic" 76 #define _RCONST ".rconst" 77 78 /* ECOFF uses some additional section flags. */ 79 #define STYP_RDATA 0x100 80 #define STYP_SDATA 0x200 81 #define STYP_SBSS 0x400 82 #define STYP_GOT 0x1000 83 #define STYP_DYNAMIC 0x2000 84 #define STYP_DYNSYM 0x4000 85 #define STYP_RELDYN 0x8000 86 #define STYP_DYNSTR 0x10000 87 #define STYP_HASH 0x20000 88 #define STYP_LIBLIST 0x40000 89 #define STYP_CONFLIC 0x100000 90 #define STYP_ECOFF_FINI 0x1000000 91 #define STYP_EXTENDESC 0x2000000 /* 0x02FFF000 bits => scn type, rest clr */ 92 #define STYP_LITA 0x4000000 93 #define STYP_LIT8 0x8000000 94 #define STYP_LIT4 0x10000000 95 #define STYP_ECOFF_LIB 0x40000000 96 #define STYP_ECOFF_INIT 0x80000000 97 #define STYP_OTHER_LOAD (STYP_ECOFF_INIT | STYP_ECOFF_FINI) 98 99 /* extended section types */ 100 #define STYP_COMMENT 0x2100000 101 #define STYP_RCONST 0x2200000 102 #define STYP_XDATA 0x2400000 103 #define STYP_PDATA 0x2800000 104 105 /* The linker needs a section to hold small common variables while 106 linking. There is no convenient way to create it when the linker 107 needs it, so we always create one for each BFD. We then avoid 108 writing it out. */ 109 #define SCOMMON ".scommon" 110 111 /* If the extern bit in a reloc is 1, then r_symndx is an index into 112 the external symbol table. If the extern bit is 0, then r_symndx 113 indicates a section, and is one of the following values. */ 114 #define RELOC_SECTION_NONE 0 115 #define RELOC_SECTION_TEXT 1 116 #define RELOC_SECTION_RDATA 2 117 #define RELOC_SECTION_DATA 3 118 #define RELOC_SECTION_SDATA 4 119 #define RELOC_SECTION_SBSS 5 120 #define RELOC_SECTION_BSS 6 121 #define RELOC_SECTION_INIT 7 122 #define RELOC_SECTION_LIT8 8 123 #define RELOC_SECTION_LIT4 9 124 #define RELOC_SECTION_XDATA 10 125 #define RELOC_SECTION_PDATA 11 126 #define RELOC_SECTION_FINI 12 127 #define RELOC_SECTION_LITA 13 128 #define RELOC_SECTION_ABS 14 129 #define RELOC_SECTION_RCONST 15 130 131 #define NUM_RELOC_SECTIONS 16 132 133 /********************** STABS **********************/ 134 135 /* gcc uses mips-tfile to output type information in special stabs 136 entries. These must match the corresponding definition in 137 gcc/config/mips.h. At some point, these should probably go into a 138 shared include file, but currently gcc and gdb do not share any 139 directories. */ 140 #define CODE_MASK 0x8F300 141 #define ECOFF_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK) 142 #define ECOFF_MARK_STAB(code) ((code)+CODE_MASK) 143 #define ECOFF_UNMARK_STAB(code) ((code)-CODE_MASK) 144 #define STABS_SYMBOL "@stabs" 145 146 /********************** COFF **********************/ 147 148 /* gcc also uses mips-tfile to output COFF debugging information. 149 These are the values it uses when outputting the .type directive. 150 These should also be in a shared include file. */ 151 #define N_BTMASK (017) 152 #define N_TMASK (060) 153 #define N_BTSHFT (4) 154 #define N_TSHIFT (2) 155 156 /********************** AUX **********************/ 157 158 /* The auxiliary type information is the same on all known ECOFF 159 targets. I can't see any reason that it would ever change, so I am 160 going to gamble and define the external structures here, in the 161 target independent ECOFF header file. The internal forms are 162 defined in coff/sym.h, which was originally donated by MIPS 163 Computer Systems. */ 164 165 /* Type information external record */ 166 167 struct tir_ext { 168 unsigned char t_bits1[1]; 169 unsigned char t_tq45[1]; 170 unsigned char t_tq01[1]; 171 unsigned char t_tq23[1]; 172 }; 173 174 #define TIR_BITS1_FBITFIELD_BIG ((unsigned int) 0x80) 175 #define TIR_BITS1_FBITFIELD_LITTLE ((unsigned int) 0x01) 176 177 #define TIR_BITS1_CONTINUED_BIG ((unsigned int) 0x40) 178 #define TIR_BITS1_CONTINUED_LITTLE ((unsigned int) 0x02) 179 180 #define TIR_BITS1_BT_BIG ((unsigned int) 0x3F) 181 #define TIR_BITS1_BT_SH_BIG 0 182 #define TIR_BITS1_BT_LITTLE ((unsigned int) 0xFC) 183 #define TIR_BITS1_BT_SH_LITTLE 2 184 185 #define TIR_BITS_TQ4_BIG ((unsigned int) 0xF0) 186 #define TIR_BITS_TQ4_SH_BIG 4 187 #define TIR_BITS_TQ5_BIG ((unsigned int) 0x0F) 188 #define TIR_BITS_TQ5_SH_BIG 0 189 #define TIR_BITS_TQ4_LITTLE ((unsigned int) 0x0F) 190 #define TIR_BITS_TQ4_SH_LITTLE 0 191 #define TIR_BITS_TQ5_LITTLE ((unsigned int) 0xF0) 192 #define TIR_BITS_TQ5_SH_LITTLE 4 193 194 #define TIR_BITS_TQ0_BIG ((unsigned int) 0xF0) 195 #define TIR_BITS_TQ0_SH_BIG 4 196 #define TIR_BITS_TQ1_BIG ((unsigned int) 0x0F) 197 #define TIR_BITS_TQ1_SH_BIG 0 198 #define TIR_BITS_TQ0_LITTLE ((unsigned int) 0x0F) 199 #define TIR_BITS_TQ0_SH_LITTLE 0 200 #define TIR_BITS_TQ1_LITTLE ((unsigned int) 0xF0) 201 #define TIR_BITS_TQ1_SH_LITTLE 4 202 203 #define TIR_BITS_TQ2_BIG ((unsigned int) 0xF0) 204 #define TIR_BITS_TQ2_SH_BIG 4 205 #define TIR_BITS_TQ3_BIG ((unsigned int) 0x0F) 206 #define TIR_BITS_TQ3_SH_BIG 0 207 #define TIR_BITS_TQ2_LITTLE ((unsigned int) 0x0F) 208 #define TIR_BITS_TQ2_SH_LITTLE 0 209 #define TIR_BITS_TQ3_LITTLE ((unsigned int) 0xF0) 210 #define TIR_BITS_TQ3_SH_LITTLE 4 211 212 /* Relative symbol external record */ 213 214 struct rndx_ext { 215 unsigned char r_bits[4]; 216 }; 217 218 #define RNDX_BITS0_RFD_SH_LEFT_BIG 4 219 #define RNDX_BITS1_RFD_BIG ((unsigned int) 0xF0) 220 #define RNDX_BITS1_RFD_SH_BIG 4 221 222 #define RNDX_BITS0_RFD_SH_LEFT_LITTLE 0 223 #define RNDX_BITS1_RFD_LITTLE ((unsigned int) 0x0F) 224 #define RNDX_BITS1_RFD_SH_LEFT_LITTLE 8 225 226 #define RNDX_BITS1_INDEX_BIG ((unsigned int) 0x0F) 227 #define RNDX_BITS1_INDEX_SH_LEFT_BIG 16 228 #define RNDX_BITS2_INDEX_SH_LEFT_BIG 8 229 #define RNDX_BITS3_INDEX_SH_LEFT_BIG 0 230 231 #define RNDX_BITS1_INDEX_LITTLE ((unsigned int) 0xF0) 232 #define RNDX_BITS1_INDEX_SH_LITTLE 4 233 #define RNDX_BITS2_INDEX_SH_LEFT_LITTLE 4 234 #define RNDX_BITS3_INDEX_SH_LEFT_LITTLE 12 235 236 /* Auxiliary symbol information external record */ 237 238 union aux_ext { 239 struct tir_ext a_ti; 240 struct rndx_ext a_rndx; 241 unsigned char a_dnLow[4]; 242 unsigned char a_dnHigh[4]; 243 unsigned char a_isym[4]; 244 unsigned char a_iss[4]; 245 unsigned char a_width[4]; 246 unsigned char a_count[4]; 247 }; 248 249 #define AUX_GET_ANY(bigend, ax, field) \ 250 ((bigend) ? bfd_getb32 ((ax)->field) : bfd_getl32 ((ax)->field)) 251 252 #define AUX_GET_DNLOW(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_dnLow) 253 #define AUX_GET_DNHIGH(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_dnHigh) 254 #define AUX_GET_ISYM(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_isym) 255 #define AUX_GET_ISS(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_iss) 256 #define AUX_GET_WIDTH(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_width) 257 #define AUX_GET_COUNT(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_count) 258 259 #define AUX_PUT_ANY(bigend, val, ax, field) \ 260 ((bigend) \ 261 ? (bfd_putb32 ((bfd_vma) (val), (ax)->field), 0) \ 262 : (bfd_putl32 ((bfd_vma) (val), (ax)->field), 0)) 263 264 #define AUX_PUT_DNLOW(bigend, val, ax) \ 265 AUX_PUT_ANY ((bigend), (val), (ax), a_dnLow) 266 #define AUX_PUT_DNHIGH(bigend, val, ax) \ 267 AUX_PUT_ANY ((bigend), (val), (ax), a_dnHigh) 268 #define AUX_PUT_ISYM(bigend, val, ax) \ 269 AUX_PUT_ANY ((bigend), (val), (ax), a_isym) 270 #define AUX_PUT_ISS(bigend, val, ax) \ 271 AUX_PUT_ANY ((bigend), (val), (ax), a_iss) 272 #define AUX_PUT_WIDTH(bigend, val, ax) \ 273 AUX_PUT_ANY ((bigend), (val), (ax), a_width) 274 #define AUX_PUT_COUNT(bigend, val, ax) \ 275 AUX_PUT_ANY ((bigend), (val), (ax), a_count) 276 277 /********************** SYMBOLS **********************/ 278 279 /* For efficiency, gdb deals directly with the unswapped symbolic 280 information (that way it only takes the time to swap information 281 that it really needs to read). gdb originally retrieved the 282 information directly from the BFD backend information, but that 283 strategy, besides being sort of ugly, does not work for MIPS ELF, 284 which also uses ECOFF debugging information. This structure holds 285 pointers to the (mostly) unswapped symbolic information. */ 286 287 struct ecoff_debug_info 288 { 289 /* The swapped ECOFF symbolic header. */ 290 HDRR symbolic_header; 291 292 /* Pointers to the unswapped symbolic information. Note that the 293 pointers to external structures point to different sorts of 294 information on different ECOFF targets. The ecoff_debug_swap 295 structure provides the sizes of the structures and the functions 296 needed to swap the information in and out. These pointers are 297 all pointers to arrays, not single structures. They will be NULL 298 if there are no instances of the relevant structure. These 299 fields are also used by the assembler to output ECOFF debugging 300 information. */ 301 unsigned char *line; 302 void *external_dnr; /* struct dnr_ext */ 303 void *external_pdr; /* struct pdr_ext */ 304 void *external_sym; /* struct sym_ext */ 305 void *external_opt; /* struct opt_ext */ 306 union aux_ext *external_aux; 307 char *ss; 308 char *ssext; 309 void *external_fdr; /* struct fdr_ext */ 310 void *external_rfd; /* struct rfd_ext */ 311 void *external_ext; /* struct ext_ext */ 312 313 /* These fields are used when linking. They may disappear at some 314 point. */ 315 char *ssext_end; 316 void *external_ext_end; 317 318 /* When linking, this field holds a mapping from the input FDR 319 numbers to the output numbers, and is used when writing out the 320 external symbols. It is NULL if no mapping is required. */ 321 RFDT *ifdmap; 322 323 /* The swapped FDR information. Currently this is never NULL, but 324 code using this structure should probably double-check in case 325 this changes in the future. This is a pointer to an array, not a 326 single structure. */ 327 FDR *fdr; 328 }; 329 330 /* These structures are used by the ECOFF find_nearest_line function. */ 331 332 struct ecoff_fdrtab_entry 333 { 334 /* Base address in .text of this FDR. */ 335 bfd_vma base_addr; 336 FDR *fdr; 337 }; 338 339 struct ecoff_find_line 340 { 341 /* Allocated memory to hold function and file names. */ 342 char *find_buffer; 343 344 /* FDR table, sorted by address: */ 345 long fdrtab_len; 346 struct ecoff_fdrtab_entry *fdrtab; 347 348 /* Cache entry for most recently found line information. The sect 349 field is NULL if this cache does not contain valid information. */ 350 struct 351 { 352 asection *sect; 353 bfd_vma start; 354 bfd_vma stop; 355 const char *filename; 356 const char *functionname; 357 unsigned int line_num; 358 } cache; 359 }; 360 361 /********************** SWAPPING **********************/ 362 363 /* The generic ECOFF code needs to be able to swap debugging 364 information in and out in the specific format used by a particular 365 ECOFF implementation. This structure provides the information 366 needed to do this. */ 367 368 struct ecoff_debug_swap 369 { 370 /* Symbol table magic number. */ 371 int sym_magic; 372 /* Alignment of debugging information. E.g., 4. */ 373 bfd_size_type debug_align; 374 /* Sizes of external symbolic information. */ 375 bfd_size_type external_hdr_size; 376 bfd_size_type external_dnr_size; 377 bfd_size_type external_pdr_size; 378 bfd_size_type external_sym_size; 379 bfd_size_type external_opt_size; 380 bfd_size_type external_fdr_size; 381 bfd_size_type external_rfd_size; 382 bfd_size_type external_ext_size; 383 /* Functions to swap in external symbolic data. */ 384 void (*swap_hdr_in) (bfd *, void *, HDRR *); 385 void (*swap_dnr_in) (bfd *, void *, DNR *); 386 void (*swap_pdr_in) (bfd *, void *, PDR *); 387 void (*swap_sym_in) (bfd *, void *, SYMR *); 388 void (*swap_opt_in) (bfd *, void *, OPTR *); 389 void (*swap_fdr_in) (bfd *, void *, FDR *); 390 void (*swap_rfd_in) (bfd *, void *, RFDT *); 391 void (*swap_ext_in) (bfd *, void *, EXTR *); 392 void (*swap_tir_in) (int, const struct tir_ext *, TIR *); 393 void (*swap_rndx_in) (int, const struct rndx_ext *, RNDXR *); 394 /* Functions to swap out external symbolic data. */ 395 void (*swap_hdr_out) (bfd *, const HDRR *, void *); 396 void (*swap_dnr_out) (bfd *, const DNR *, void *); 397 void (*swap_pdr_out) (bfd *, const PDR *, void *); 398 void (*swap_sym_out) (bfd *, const SYMR *, void *); 399 void (*swap_opt_out) (bfd *, const OPTR *, void *); 400 void (*swap_fdr_out) (bfd *, const FDR *, void *); 401 void (*swap_rfd_out) (bfd *, const RFDT *, void *); 402 void (*swap_ext_out) (bfd *, const EXTR *, void *); 403 void (*swap_tir_out) (int, const TIR *, struct tir_ext *); 404 void (*swap_rndx_out) (int, const RNDXR *, struct rndx_ext *); 405 /* Function to read symbol data and set up pointers in 406 ecoff_debug_info structure. The section argument is used for 407 ELF, not straight ECOFF. */ 408 bfd_boolean (*read_debug_info) (bfd *, asection *, struct ecoff_debug_info *); 409 }; 410 411 #endif /* ! defined (ECOFF_H) */ 412