external.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* external.h -- External COFF structures
  2. Copyright (C) 2001-2015 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  14. MA 02110-1301, USA. */
  15. #ifndef COFF_EXTERNAL_H
  16. #define COFF_EXTERNAL_H
  17. #ifndef DO_NOT_DEFINE_FILHDR
  18. /********************** FILE HEADER **********************/
  19. struct external_filehdr
  20. {
  21. char f_magic[2]; /* magic number */
  22. char f_nscns[2]; /* number of sections */
  23. char f_timdat[4]; /* time & date stamp */
  24. char f_symptr[4]; /* file pointer to symtab */
  25. char f_nsyms[4]; /* number of symtab entries */
  26. char f_opthdr[2]; /* sizeof(optional hdr) */
  27. char f_flags[2]; /* flags */
  28. };
  29. #define FILHDR struct external_filehdr
  30. #define FILHSZ 20
  31. #endif
  32. #ifndef DO_NOT_DEFINE_AOUTHDR
  33. /********************** AOUT "OPTIONAL HEADER" **********************/
  34. typedef struct external_aouthdr
  35. {
  36. char magic[2]; /* type of file */
  37. char vstamp[2]; /* version stamp */
  38. char tsize[4]; /* text size in bytes, padded to FW bdry*/
  39. char dsize[4]; /* initialized data " " */
  40. char bsize[4]; /* uninitialized data " " */
  41. char entry[4]; /* entry pt. */
  42. char text_start[4]; /* base of text used for this file */
  43. char data_start[4]; /* base of data used for this file */
  44. } ATTRIBUTE_PACKED
  45. AOUTHDR;
  46. #define AOUTHDRSZ 28
  47. #define AOUTSZ 28
  48. typedef struct external_aouthdr64
  49. {
  50. char magic[2]; /* Type of file. */
  51. char vstamp[2]; /* Version stamp. */
  52. char tsize[4]; /* Text size in bytes, padded to FW bdry*/
  53. char dsize[4]; /* Initialized data " ". */
  54. char bsize[4]; /* Uninitialized data " ". */
  55. char entry[4]; /* Entry pt. */
  56. char text_start[4]; /* Base of text used for this file. */
  57. }
  58. AOUTHDR64;
  59. #define AOUTHDRSZ64 24
  60. #endif /* not DO_NOT_DEFINE_AOUTHDR */
  61. #ifndef DO_NOT_DEFINE_SCNHDR
  62. /********************** SECTION HEADER **********************/
  63. struct external_scnhdr
  64. {
  65. char s_name[8]; /* section name */
  66. char s_paddr[4]; /* physical address, aliased s_nlib */
  67. char s_vaddr[4]; /* virtual address */
  68. char s_size[4]; /* section size */
  69. char s_scnptr[4]; /* file ptr to raw data for section */
  70. char s_relptr[4]; /* file ptr to relocation */
  71. char s_lnnoptr[4]; /* file ptr to line numbers */
  72. char s_nreloc[2]; /* number of relocation entries */
  73. char s_nlnno[2]; /* number of line number entries */
  74. char s_flags[4]; /* flags */
  75. };
  76. #define SCNHDR struct external_scnhdr
  77. #define SCNHSZ 40
  78. /* Names of "special" sections. */
  79. #define _TEXT ".text"
  80. #define _DATA ".data"
  81. #define _BSS ".bss"
  82. #define _COMMENT ".comment"
  83. #define _LIB ".lib"
  84. #endif /* not DO_NOT_DEFINE_SCNHDR */
  85. #ifndef DO_NOT_DEFINE_LINENO
  86. /********************** LINE NUMBERS **********************/
  87. #ifndef L_LNNO_SIZE
  88. #error L_LNNO_SIZE needs to be defined
  89. #endif
  90. /* 1 line number entry for every "breakpointable" source line in a section.
  91. Line numbers are grouped on a per function basis; first entry in a function
  92. grouping will have l_lnno = 0 and in place of physical address will be the
  93. symbol table index of the function name. */
  94. struct external_lineno
  95. {
  96. union
  97. {
  98. char l_symndx[4]; /* function name symbol index, iff l_lnno == 0*/
  99. char l_paddr[4]; /* (physical) address of line number */
  100. } l_addr;
  101. char l_lnno[L_LNNO_SIZE]; /* line number */
  102. };
  103. #define LINENO struct external_lineno
  104. #define LINESZ (4 + L_LNNO_SIZE)
  105. #if L_LNNO_SIZE == 4
  106. #define GET_LINENO_LNNO(abfd, ext) H_GET_32 (abfd, (ext->l_lnno))
  107. #define PUT_LINENO_LNNO(abfd, val, ext) H_PUT_32 (abfd, val, (ext->l_lnno))
  108. #endif
  109. #if L_LNNO_SIZE == 2
  110. #define GET_LINENO_LNNO(abfd, ext) H_GET_16 (abfd, (ext->l_lnno))
  111. #define PUT_LINENO_LNNO(abfd, val, ext) H_PUT_16 (abfd, val, (ext->l_lnno))
  112. #endif
  113. #endif /* not DO_NOT_DEFINE_LINENO */
  114. #ifndef DO_NOT_DEFINE_SYMENT
  115. /********************** SYMBOLS **********************/
  116. #define E_SYMNMLEN 8 /* # characters in a symbol name */
  117. #ifndef E_FILNMLEN
  118. #define E_FILNMLEN 14
  119. #endif
  120. #define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
  121. struct external_syment
  122. {
  123. union
  124. {
  125. char e_name[E_SYMNMLEN];
  126. struct
  127. {
  128. char e_zeroes[4];
  129. char e_offset[4];
  130. } e;
  131. } e;
  132. char e_value[4];
  133. char e_scnum[2];
  134. char e_type[2];
  135. char e_sclass[1];
  136. char e_numaux[1];
  137. } ATTRIBUTE_PACKED ;
  138. #define SYMENT struct external_syment
  139. #define SYMESZ 18
  140. #ifndef N_BTMASK
  141. #define N_BTMASK 0xf
  142. #endif
  143. #ifndef N_TMASK
  144. #define N_TMASK 0x30
  145. #endif
  146. #ifndef N_BTSHFT
  147. #define N_BTSHFT 4
  148. #endif
  149. #ifndef N_TSHIFT
  150. #define N_TSHIFT 2
  151. #endif
  152. #endif /* not DO_NOT_DEFINE_SYMENT */
  153. #ifndef DO_NOT_DEFINE_AUXENT
  154. union external_auxent
  155. {
  156. struct
  157. {
  158. char x_tagndx[4]; /* str, un, or enum tag indx */
  159. union
  160. {
  161. struct
  162. {
  163. char x_lnno[2]; /* declaration line number */
  164. char x_size[2]; /* str/union/array size */
  165. } x_lnsz;
  166. char x_fsize[4]; /* size of function */
  167. } x_misc;
  168. union
  169. {
  170. struct /* if ISFCN, tag, or .bb */
  171. {
  172. char x_lnnoptr[4]; /* ptr to fcn line # */
  173. char x_endndx[4]; /* entry ndx past block end */
  174. } x_fcn;
  175. struct /* if ISARY, up to 4 dimen. */
  176. {
  177. char x_dimen[E_DIMNUM][2];
  178. } x_ary;
  179. } x_fcnary;
  180. char x_tvndx[2]; /* tv index */
  181. } x_sym;
  182. union
  183. {
  184. char x_fname[E_FILNMLEN];
  185. struct
  186. {
  187. char x_zeroes[4];
  188. char x_offset[4];
  189. } x_n;
  190. } x_file;
  191. struct
  192. {
  193. char x_scnlen[4]; /* section length */
  194. char x_nreloc[2]; /* # relocation entries */
  195. char x_nlinno[2]; /* # line numbers */
  196. #ifdef INCLUDE_COMDAT_FIELDS_IN_AUXENT
  197. char x_checksum[4]; /* section COMDAT checksum */
  198. char x_associated[2]; /* COMDAT associated section index */
  199. char x_comdat[1]; /* COMDAT selection number */
  200. #endif
  201. } x_scn;
  202. struct
  203. {
  204. char x_tvfill[4]; /* tv fill value */
  205. char x_tvlen[2]; /* length of .tv */
  206. char x_tvran[2][2]; /* tv range */
  207. } x_tv; /* info about .tv section (in auxent of symbol .tv)) */
  208. } ATTRIBUTE_PACKED ;
  209. #define AUXENT union external_auxent
  210. #define AUXESZ 18
  211. #define _ETEXT "etext"
  212. #endif /* not DO_NOT_DEFINE_AUXENT */
  213. #endif /* COFF_EXTERNAL_H */