coff.pp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. { Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
  2. ( MvdV: GPL/LGPL, I can't exactly make out from that file what this is, and
  3. it doesn't matter for me, since FPC is also GPL/LGPL)
  4. FPC Pascal conversion by Marco van de Voort (C) 2001.
  5. }
  6. Unit coff;
  7. interface
  8. {$packrecords C}
  9. type cushort =word;
  10. culong =cardinal;
  11. cshort =integer;
  12. cuchar =byte;
  13. {** coff information for Intel 386/486. }
  14. {********************* FILE HEADER *********************}
  15. TYPE External_FileHDR = Record
  16. f_magic : cushort; { magic number }
  17. f_nscns : cushort; { number of sections }
  18. f_timdat : culong; { time & date stamp }
  19. f_symptr : culong; { file pointer to symtab }
  20. f_nsyms : culong; { number of symtab entries }
  21. f_opthdr : cushort; { sizeof(optional hdr) }
  22. f_flags : cushort; { flags }
  23. end;
  24. { Bits for f_flags:
  25. * F_RELFLG relocation info stripped from file
  26. * F_EXEC file is executable (no unresolved external references)
  27. * F_LNNO line numbers stripped from file
  28. * F_LSYMS local symbols stripped from file
  29. * F_AR32WR file has byte ordering of an AR32WR machine (e.g. vax)
  30. }
  31. FILHDR = external_filehdr;
  32. Const
  33. F_RELFLG =00001;
  34. F_EXEC =00002;
  35. F_LNNO =00004;
  36. F_LSYMS =00008;
  37. I386MAGIC =$14c;
  38. I386AIXMAGIC =$175;
  39. // I386BADMAG(x) (((x).f_magic!=I386MAGIC) && (x).f_magic!=I386AIXMAGIC)
  40. FILHSZ = sizeof(FILHDR);
  41. {********************* AOUT "OPTIONAL HEADER" *********************}
  42. TYPE AOUTHDR = Record
  43. magic : cushort; { type of file }
  44. vstamp : cushort; { version stamp }
  45. tsize : culong; { text size in bytes, padded to FW bdry}
  46. dsize : culong; { initialized data " " }
  47. bsize : culong; { uninitialized data " " }
  48. entry : culong; { entry pt. }
  49. text_start : culong; { base of text used for this file }
  50. data_start : culong; { base of data used for this file }
  51. end;
  52. gnu_aout = Record
  53. info,
  54. tsize,
  55. dsize,
  56. bsize,
  57. symsize,
  58. entry,
  59. txrel,
  60. dtrel : culong;
  61. end;
  62. const
  63. AOUTSZ =sizeof(AOUTHDR);
  64. OMAGIC =0404; { object files, eg as output }
  65. ZMAGIC =0413; { demand load format, eg normal ld output }
  66. STMAGIC =0401; { target shlib }
  67. SHMAGIC =0443; { host shlib }
  68. {********************* SECTION HEADER *********************}
  69. type external_scnhdr = Record
  70. s_name : array[0..7] OF CHAR; { section name }
  71. s_paddr, { physical address, aliased s_nlib }
  72. s_vaddr, { virtual address }
  73. s_size, { section size }
  74. s_scnptr, { file ptr to raw data for section }
  75. s_relptr, { file ptr to relocation }
  76. s_lnnoptr : culong; { file ptr to line numbers }
  77. s_nreloc, { number of relocation entries }
  78. s_nlnno : cushort; { number of line number entries}
  79. s_flags : culong; { flags }
  80. end;
  81. SCNHDR = external_scnhdr;
  82. const SCNHSZ=sizeof(SCNHDR);
  83. {
  84. * names of "special" sections
  85. }
  86. CONST
  87. special_TEXT ='.text';
  88. special_DATA ='.data';
  89. special_BSS ='.bss';
  90. special_COMMENT ='.comment';
  91. special_LIB ='.lib';
  92. {
  93. * s_flags "type"
  94. }
  95. STYP_TEXT =$20; { section contains text only }
  96. STYP_DATA =$40; { section contains data only }
  97. STYP_BSS =$80; { section contains bss only }
  98. {********************* LINE NUMBERS *********************}
  99. { 1 line number entry for every "breakpointable" source line in a section.
  100. * Line numbers are grouped on a per function basis; first entry in a function
  101. * grouping will have l_lnno = 0 and in place of physical address will be the
  102. * symbol table index of the function name.
  103. }
  104. type aux_lineno = Packed Record
  105. case boolean of
  106. false:( l_symndx:culong); { function name symbol index, iff l_lnno == 0 }
  107. true:( l_paddr :culong); { (physical) address of line number }
  108. end;
  109. external_lineno = packed record {should be 6 bytes, check!}
  110. l_addr : aux_lineno;
  111. l_lnno : cushort; { line number }
  112. end;
  113. lineno=external_lineno;
  114. const LINESZ =sizeof(LINENO);
  115. {********************* SYMBOLS *********************}
  116. E_SYMNMLEN =8; { # characters in a symbol name }
  117. E_FILNMLEN =14; { # characters in a file name }
  118. E_DIMNUM =4; { # array dimensions in auxiliary entry }
  119. type aux_aux_external_syment = packed record
  120. e_zeroes : culong;
  121. e_offset : culong;
  122. end;
  123. aux_external_syment = packed record
  124. case boolean of
  125. false: (e_name : array[0..E_SYMNMLEN-1] OF Char);
  126. true : (e:aux_aux_external_syment);
  127. end;
  128. external_syment = packed record {packed, check if necessary!}
  129. e : aux_external_syment;
  130. e_value : culong;
  131. e_scnum : cshort;
  132. e_type : cushort;
  133. e_sclass : cuchar;
  134. e_numaux : cuchar;
  135. end;
  136. CONST
  137. N_BTMASK =$F;
  138. N_TMASK =$30;
  139. N_BTSHFT =$4;
  140. N_TSHIFT =$2;
  141. type tx_lnsz = packed record
  142. x_lnno,
  143. x_size : cushort;
  144. end;
  145. tx_misc = packed record
  146. case boolean of
  147. false : (x_lnsz : tx_lnsz);
  148. true : (x_fsize : culong);
  149. end;
  150. tx_fcn = packed record
  151. x_lnnoptr,
  152. x_endndx : culong;
  153. end;
  154. tx_ary = packed record
  155. x_dimen : array[0..E_DIMNUM-1] OF cushort;
  156. end;
  157. tx_fcnary = packed record
  158. case boolean of
  159. false : ( x_fcn : tx_fcn);
  160. true : ( x_ary : tx_ary);
  161. end;
  162. tx_sym = packed record
  163. x_tagndx : culong;
  164. x_misc : tx_misc;
  165. x_fcnary : tx_fcnary;
  166. x_tvndx : cushort;
  167. end;
  168. tx_n = packed record
  169. x_zeroes,
  170. x_offset : culong;
  171. end;
  172. tx_file = packed record
  173. case boolean of
  174. false: ( x_fname : array [0..E_FILNMLEN-1] of char);
  175. true : (x_n : tx_n);
  176. end;
  177. tx_scn = packed record
  178. x_scnlen : culong;
  179. x_nreloc,
  180. x_nlinno : cushort;
  181. end;
  182. tx_tv = packed record
  183. x_tvfill : culong;
  184. x_tvlen : cushort;
  185. x_tvran : array[0..1] of cushort;
  186. end;
  187. external_auxent = packed record
  188. case byte of
  189. 0: (x_sym : tx_sym);
  190. 1: (x_file: tx_file);
  191. 2: (x_scn : tx_scn);
  192. 3: (x_tv : tx_tv);
  193. end;
  194. SYMENT= external_syment;
  195. AUXENT= external_auxent;
  196. const
  197. SYMESZ = SIZEOF(SYMENT);
  198. AUXESZ = SIZEOF(AUXENT);
  199. { define _ETEXT "etext"}
  200. { Relocatable symbols have number of the section in which they are defined,
  201. or one of the following: }
  202. N_UNDEF = 0; { undefined symbol }
  203. N_ABS =-1; { value of symbol is absolute }
  204. N_DEBUG =-2; { debugging symbol -- value is meaningless }
  205. N_TV =-3; { indicates symbol needs preload transfer vector }
  206. P_TV =-4; { indicates symbol needs postload transfer vector}
  207. {
  208. * Type of a symbol, in low N bits of the word
  209. }
  210. T_NULL =0;
  211. T_VOID =1; { function argument (only used by compiler) }
  212. T_CHAR =2; { character }
  213. T_SHORT =3; { short integer }
  214. T_INT =4; { integer }
  215. T_LONG =5; { long integer }
  216. T_FLOAT =6; { floating point }
  217. T_DOUBLE =7; { double word }
  218. T_STRUCT =8; { structure }
  219. T_UNION =9; { union }
  220. T_ENUM =10; { enumeration }
  221. T_MOE =11; { member of enumeration}
  222. T_UCHAR =12; { unsigned character }
  223. T_USHORT =13; { unsigned short }
  224. T_UINT =14; { unsigned integer }
  225. T_ULONG =15; { unsigned long }
  226. T_LNGDBL =16; { long double }
  227. {
  228. * derived types, in n_type
  229. }
  230. DT_NON =0; { no derived type }
  231. DT_PTR =1; { pointer }
  232. DT_FCN =2; { function }
  233. DT_ARY =3; { array }
  234. {
  235. \\ BTYPE(x) ((x) & N_BTMASK)
  236. \\ ISPTR(x) (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
  237. \\ ISFCN(x) (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
  238. \\ ISARY(x) (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
  239. \\ ISTAG(x) ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
  240. \\ DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  241. }
  242. {********************* STORAGE CLASSES *********************}
  243. { This used to be defined as -1, but now n_sclass is unsigned. }
  244. C_EFCN =$ff; { physical end of function }
  245. C_NULL =0;
  246. C_AUTO =1; { automatic variable }
  247. C_EXT =2; { external symbol }
  248. C_STAT =3; { static }
  249. C_REG =4; { register variable }
  250. C_EXTDEF =5; { external definition }
  251. C_LABEL =6; { label }
  252. C_ULABEL =7; { undefined label }
  253. C_MOS =8; { member of structure }
  254. C_ARG =9; { function argument }
  255. C_STRTAG =10; { structure tag }
  256. C_MOU =11; { member of union }
  257. C_UNTAG =12; { union tag }
  258. C_TPDEF =13; { type definition }
  259. C_USTATIC =14; { undefined static }
  260. C_ENTAG =15; { enumeration tag }
  261. C_MOE =16; { member of enumeration }
  262. C_REGPARM =17; { register parameter }
  263. C_FIELD =18; { bit field }
  264. C_AUTOARG =19; { auto argument }
  265. C_LASTENT =20; { dummy entry (end of block) }
  266. C_BLOCK =100; { ".bb" or ".eb" }
  267. C_FCN =101; { ".bf" or ".ef" }
  268. C_EOS =102; { end of structure }
  269. C_FILE =103; { file name }
  270. C_LINE =104; { line # reformatted as symbol table entry }
  271. C_ALIAS =105; { duplicate tag }
  272. C_HIDDEN =106; { ext symbol in dmert public lib }
  273. {********************* RELOCATION DIRECTIVES *********************}
  274. type external_reloc = packed record
  275. r_vaddr,
  276. r_symndx : culong;
  277. r_type : cushort;
  278. end;
  279. RELOC = external_reloc;
  280. PRELOC= ^RELOC; {not in original header}
  281. const
  282. RELSZ =sizeof(RELOC);
  283. RELOC_REL32 =20; { 32-bit PC-relative address }
  284. RELOC_ADDR32 =6; { 32-bit absolute address }
  285. DEFAULT_DATA_SECTION_ALIGNMENT =4;
  286. DEFAULT_BSS_SECTION_ALIGNMENT =4;
  287. DEFAULT_TEXT_SECTION_ALIGNMENT =4;
  288. { For new sections we havn't heard of before }
  289. DEFAULT_SECTION_ALIGNMENT =4;
  290. Implementation
  291. end.