BINFILE.DOC 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. TopSpeed Binary File Formats
  2. ============================
  3. This file describes the format of TopSpeed binary files.
  4. BNF and Pascal/Modula-2-like languages are used in the
  5. descriptions.
  6. THE INFORMATION IS NOT GUARANTEED TO BE COMPLETE, UP TO DATE
  7. OR ACCURATE, it is intended to give you a flying start if you
  8. want to write utility programs which operate on the binary
  9. files. The debug format may change slightly in future versions.
  10. .OBJ/.LIB ( object file )
  11. -------------------------
  12. This is the standard Intel object file format, with extra coment
  13. records used by the 'make'. Only the subset generated by
  14. TopSpeed compilers is described here. (The linker does however
  15. support other record types such as iterated data etc.)
  16. BNF
  17. <lib file> ::= <lib-coment> { <object file> }
  18. <object file> ::= <header> { <item> } <trailer>
  19. <header> ::= 80H Length <string> Crc (* string is source name *)
  20. <trailer> ::=
  21. | 8AH Length 0 Crc (* not program entry point *)
  22. | 8AH Length 0C1H 0 <segment-index> <segment-index> 0 0 Crc
  23. (* program entry point *)
  24. <item> ::=
  25. | <lnames>
  26. | <segdef>
  27. | <grpdef>
  28. | <extdef>
  29. | [ <io-priv-coment> ] <pubdef>
  30. | <ledata> [ <fixupp> ]
  31. | <source-date-coment> (* used by make *)
  32. | <option-coment> (* used by make *)
  33. | <include-object-coment> (* used by make *)
  34. | <stack-heap-size-coment>
  35. | <shared-data-coment> (* applies to last segdef *)
  36. <lnames> ::= 96H Length { <string> } Crc
  37. <segdef> ::= 98H Length Attr SegLen <name-index> <name-index> <name-index> Crc
  38. <grpdef> ::= 9AH Length <name-index> { 0FFH <segment-index> } Crc
  39. <extdef> ::= 8CH Length { <string> Type } Crc
  40. <pubdef> ::= 90H Length <group-index> <segment-index> [ Frame ] { <string> Offset Type } Crc
  41. <ledata> ::= 0A0H Length <segment-index> Offset { Byte } Crc
  42. <fixupp> ::= 9CH Length { Locat FixDat Index [ Index ] [ Offset ] } Crc
  43. <lib-coment> ::= COMENT Length 0C700H Hash Crc (* used by make *)
  44. <source-date_coment> ::= COMENT Length 0C500H Date { Char } Crc
  45. <option-coment> ::= COMENT Length 0C900H { Char } Crc
  46. <project-command-coment> ::= COMENT Length 0CF00H { Char } Crc
  47. <include-object-coment> ::= COMENT Length 0CB00H { Char } Crc
  48. <stack-heap-size-coment> ::= COMENT Length 0CD00H HeapSize StackSize Crc
  49. <shared-data-coment> ::= COMENT Length 0CA00H Crc
  50. <io-priv-coment> ::= COMENT Length 0C800H Crc
  51. <string> ::= Len { Char }
  52. <name-index> ::= Index
  53. <group-index> ::= Index
  54. <segment-index> ::= Index
  55. Terminal symbols:
  56. Length is a 2-byte value present in every record which is
  57. the length in bytes of the record - 3.
  58. Len is a 1-byte string length.
  59. Char is a 1-byte character, which should be a printing
  60. character.
  61. Crc is a 1-byte checksum. It is either zero or -(sum of
  62. bytes in record).
  63. Index is a 2 byte value represented as 1 or 2 bytes. If getb()
  64. returns the next byte from the file, a routine to fetch an
  65. Index is as follows:
  66. tmp := CARDINAL( getb() );
  67. IF tmp < 128 THEN
  68. RETURN tmp;
  69. ELSE
  70. RETURN ( tmp - 128 ) * 256 + CARDINAL( getb() );
  71. END;
  72. <lnames>, <extdef>, <pubdef>, <segdef> and <grpdef> records
  73. implicitly define indices which are then used to refer to the
  74. objects defined. The indices start from 1.
  75. Offset is a 2-byte offset in a segment.
  76. Frame is present only when the segment index for the public is
  77. zero (an absolute public), and is normally 0.
  78. Type is a 1-byte hash value in the range 0..127 used by the
  79. JPI linker to perform type-consistency checks (note that
  80. this is a deviation from standard Intel format where this is
  81. interpreted as a type-index, but existing linkers mostly ignore
  82. this field. If there is a problem the field could be set to
  83. zero by a utility program or by disabling smart linking.
  84. Byte is a 1-byte data value.
  85. Attr is the 1-byte segment attribute.
  86. SegLen is the 2-byte length of the segment.
  87. Locat (2 bytes) defines the offset in the preceding ledata
  88. record which is to be fixed up (bits 0..9), the kind of
  89. location (bits 10..12) and whether the fixup is non-relative
  90. (bit 14). Bit 15 is always 1, Bit 13 is always 0. The
  91. location kinds are 1=>offset, 2=>segment, 3=>pointer
  92. FixDat (1 byte) defines what kind of index is used for the
  93. target of the fixup (bits 0..1), whether the offset is
  94. missing (bit 2), and what kind of index is used for the
  95. frame of the fixup (bits 4..6). The bits 3 and 7 are zero.
  96. The encoding of the index kind is 0=><segment-index>,
  97. 1=><group-index>, 2=><external-index>, 5=>no frame index,
  98. use target
  99. Hash is a 4-byte hash value used by the make system.
  100. Date is a 4-byte file date in MSDOS/OS2 format.
  101. HeapSize and StackSize are 2-byte values for the heap
  102. and stack of the program (specified by the data pragma
  103. in the main module).
  104. .EXE/.DLL ( executable file format )
  105. ------------------------------------
  106. The .exe/.dll file format is as follows:
  107. <exe file> ::= <standard exe file> <debug info> <trailer>
  108. <debug info> ::= <header> { <module info> } <end marker>
  109. <module info> ::= <module name size> <module name> <lseg count> { <lseg address> }
  110. <trailer> ::= longcard size of <standard exe file>
  111. <end marker> ::= byte 0
  112. <module name size> ::= byte size of following <module name>
  113. <lseg count> ::= word count of following <lseg address>
  114. <seg address> ::= word offset followed by word segment
  115. <header> ::= 'jpi0'
  116. where <standard exe file> is the standard Microsoft .exe/.dll
  117. format.
  118. .DBD file ( debug information )
  119. -------------------------------
  120. The BNF for a modules debug data is as follows :
  121. <module debug data> ::= Mod { <item> } EndMod
  122. <item> ::= <proc> | <var> | <type>
  123. <proc> ::= Proc { <item> } EndProc
  124. <type> ::= Signed
  125. | Unsigned
  126. | Float
  127. | Char
  128. | Boolean
  129. | Procedure
  130. | Indirect
  131. | Array <type> <type>
  132. | OpenArray <type> Aux
  133. | Pointer <type>
  134. | SubRange <type>
  135. | Set <type>
  136. | ShortPtr <type> Aux
  137. | <simple>
  138. | Rec { <field> } EndRec
  139. | (Enum|SparseEnum) { EnumVal } EndEnum
  140. .
  141. <var> ::= Var <type>
  142. <field> ::= Field <type> | BitField <type>
  143. The terminal symbols in the grammar correspond to records of the
  144. following type:
  145. TYPE DbRec = RECORD (* variable size *)
  146. recsize : SHORTCARD; (* record size in bytes, including this byte *)
  147. CASE tag: DbRecKind OF
  148. | Source:
  149. sourcename : string;
  150. | Module:
  151. lang : SHORTCARD;
  152. ofs : CARDINAL;
  153. seg : CARDINAL; (* -1 => external *)
  154. name : string;
  155. | EndModule:
  156. modulesize : t_offset;
  157. | LineNum:
  158. line : ARRAY [0..62] OF RECORD (* variable size *)
  159. ofs : CARDINAL;
  160. num : CARDINAL;
  161. END;
  162. | Rte:
  163. rteofs : CARDINAL;
  164. rtenum : CARDINAL;
  165. rtecol : CARDINAL;
  166. | Var, Aux:
  167. varflags : DbVarFlags;
  168. ofs : CARDINAL; (* 1 => no address if local or param *)
  169. seg : CARDINAL;
  170. name : string;
  171. | Field:
  172. fieldofs : CARDINAL;
  173. fieldname : string;
  174. | BitField:
  175. fieldofs : CARDINAL;
  176. bitfieldbitofs : SHORTCARD;
  177. bitfieldsize : SHORTCARD;
  178. bitfieldname : string;
  179. | Proc:
  180. procflags : DbProcFlags; (* the complete set is only in EndProc !! *)
  181. ofs : CARDINAL;
  182. seg : CARDINAL;
  183. name : string;
  184. | EndProc:
  185. procflags : DbProcFlags;
  186. procsize : t_offset;
  187. | Indirect:
  188. handle : Handle;
  189. | Rec:
  190. typesize : CARDINAL;
  191. id : Handle;
  192. | EndRec:
  193. | Enum:
  194. typesize : CARDINAL;
  195. id : Handle;
  196. | EnumVal:
  197. enumval : INTEGER;
  198. enumname : string;
  199. | EndEnum:
  200. | Subrange:
  201. typesize : CARDINAL;
  202. rangehigh, rangelow:LONGCARD;
  203. | Signed, Unsigned, Float, Char, Boolean, Pointer, Procedure,
  204. Array, OpenArray, Set, ShortPtr:
  205. typesize:CARDINAL;
  206. ELSE
  207. b:ARRAY [0..252] OF SHORTCARD;
  208. END;
  209. END;
  210. where
  211. TYPE Handle = LONGCARD;
  212. CONST Nil = MAX(Handle); (* 0FFFFFFFFH *)
  213. TYPE string = ARRAY [0..127] OF CHAR; (* variable length *)
  214. TYPE DbRecKind =
  215. ( Module, EndModule, LineNum, Rte, Var, Proc, EndProc, Indirect, Rec,
  216. EndRec, Enum, EnumVal, Field, BitField, EndEnum, Subrange, Void,
  217. Signed, Unsigned, Float, Char, Boolean, Pointer, Procedure, Array,
  218. OpenArray, Set, ShortPtr, Source, Aux
  219. );
  220. TYPE DbVarTypeEnum = ( varparam, valparam,local,nonvolatile);
  221. TYPE DbVarFlags = SET OF DbVarTypeEnum;
  222. TYPE DbProcTypeEnum = (near,NoFrame,VarArg,OptVarArg);
  223. TYPE DbProcFlags = SET OF DbProcTypeEnum;
  224. An Indirect record is a pointer to an Enumeration or Record type
  225. so that these types can be re-used.
  226. Note that the following records expect sub types to follow
  227. (i.e. be defined immediately afterwards)
  228. Array expects <Index type> + <Element type> to follow
  229. OpenArray expects <Element type> + Aux to follow
  230. Pointer expects <dereferenced type> to follow
  231. Subrange expects <base type> to follow
  232. Set expects <element type> to follow
  233. ShortPtr expects <dereferenced type> + Aux to follow
  234. The segment values correspond to segment indices in the .OBJ
  235. file, and are translated into run-time segment values using
  236. the VID information at the end of the .EXE/.DLL file.
  237. .SES, .CFG, .HLP files
  238. ----------------------
  239. not yet done
  240.