ecoff.h 14 KB

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