DOS 3.30 source code leak

2555 lines
68 KiB

5 years ago
  1. _ _ | | _ _
  2. Microsoft Relocatable Object Module Formats
  3. _ __________________________________________________
  4. 7.1 Introduction
  5. This chapter presents the object record formats that define the relocatable
  6. object language for the 8086, 80186, and 80286 microprocessors. The 8086
  7. object language is the output of all language translators that have an 8086
  8. processor and that will be linked by the Microsoft linker. The 8086 object
  9. language is used for input and output for object language processors such
  10. as linkers and librarians, and is used in the XENIX, PC-DOS, and MS-DOS
  11. operating systems.
  12. The 8086 object module formats let you specify relocatable memory
  13. images that may be linked together. These formats also allow efficient use
  14. of the memory mapping facilities of the 8086 family of microprocessors.
  15. The following table lists the record formats (each described in this
  16. chapter) that Microsoft supports (the abbreviations appear in
  17. parentheses):
  18. Table 7.1
  19. Object Module Record Formats
  20. _ _________________________________________________________________________
  21. Symbol Definition Records
  22. Public Names Definition Record (PUBDEF)
  23. Communal Names Definition Record (COMDEF)
  24. Local Symbols Record (LOCSYM)
  25. External Names Definition Record (EXTDEF)
  26. Line Numbers Record (LINNUM)
  27. Data Records
  28. Logical Enumerated Data Record (LEDATA)
  29. Logical Iterated Data Record (LIDATA)
  30. T-Module Header Record (THEADR)
  31. L-Module Header Record (LHEADR)
  32. List of Names Record (LNAMES)
  33. Segment Definition Record (SEGDEF)
  34. Group Definition Record (GRPDEF)
  35. Fixup Record (FIXUPP)
  36. Module End Record (MODEND)
  37. Comment Record (COMENT)
  38. _ _________________________________________________________________________
  39. 3
  40. _ _ | | _ _
  41. _ _ | | _ _
  42. _ ______________
  43. _ ________________________________________________________________
  44. Note
  45. If an object module contains any undefined values, the behavior of the
  46. Microsoft linker is undefined. All undefined values should be con-
  47. sidered reserved by Microsoft for future use.
  48. _ ________________________________________________________________
  49. 7.1.1 Definition of Terms
  50. The following terms are fundamental to 8086 relocation and linkage:
  51. OMF - Object Module Formats
  52. MAS - Memory Address Space
  53. The 8086 MAS is one megabyte (1,048,576 bytes). Note that the MAS is
  54. distinguished from actual memory, which may occupy only a portion of
  55. the MAS.
  56. Module
  57. A module is an "inseparable" collection of object code and other informa-
  58. tion produced by a translator.
  59. T-Module
  60. A T-module is a module created by a translator, such as Pascal or FOR-
  61. TRAN.
  62. The following restrictions apply to object modules:
  63. o Every module should have a name. Translators provide default
  64. names (possibly filenames or null names) for T-modules if neither
  65. the source code nor the user specifies otherwise.
  66. o Every T-module in a collection of linked modules should have a
  67. different name so that symbolic debugging systems can distinguish
  68. the various line numbers and local symbols. The Microsoft linker
  69. does not require or enforce this restriction.
  70. 4
  71. _ _ | | _ _
  72. _ _ | | _ _
  73. Microsoft Relocatable Object Module Formats
  74. _ __________________________________________________
  75. Frame
  76. A frame is a contiguous region of 64K of memory address space (MAS),
  77. beginning on a paragraph boundary (i.e., on a multiple of 16 bytes) or on a
  78. selector on the 80286 processor. This concept is useful because the con-
  79. tents of the four 8086 segment registers define four (possibly overlapping)
  80. frames; no 16-bit address in the 8086 code can access a memory location
  81. outside the current four frames.
  82. LSEG (Logical Segment)
  83. A logical segment (LSEG) is a contiguous region of memory whose contents
  84. are determined at translation time (except for address-binding). Neither
  85. the size nor the location in MAS are necessarily determined during transla-
  86. tion: the size, although partially fixed, may not be final because the linker
  87. may combine the LSEG when linking with other LSEGs, forming a single
  88. LSEG. So that it can fit in a frame, an LSEG must not be larger than
  89. 64K. Thus, a 16-bit offset, from the base of a frame that covers the LSEG,
  90. may address any byte in that LSEG.
  91. PSEG (Physical Segment)
  92. This term is equivalent to frame. Some prefer "PSEG" to "frame" because
  93. the terms PSEG and LSEG reflect the "physical" and "logical" nature of
  94. the underlying segments.
  95. Frame Number
  96. Every frame begins on a paragraph boundary. The "paragraphs" in MAS
  97. can be numbered from 0 through 65,535. These numbers, each of which
  98. defines a frame, are called frame numbers.
  99. Group
  100. A group is a collection of LSEGs defined at translation time, whose final
  101. locations in MAS have been constrained so that at least one frame exists
  102. that covers (contains) every LSEG in the collection.
  103. The notation "Gr A(X,Y,Z,)" means that LSEGs X, Y, and Z form a group
  104. named A. That X, Y, and Z are all LSEGs in the same group does not
  105. imply any ordering of X, Y, and Z in MAS, nor does it imply any contiguity
  106. between X, Y, and Z.
  107. 5
  108. _ _ | | _ _
  109. _ _ | | _ _
  110. _ ______________
  111. The Microsoft linker does not currently allow an LSEG to be a member of
  112. more than one group.
  113. Canonic
  114. On the 8086 processor, any location in MAS is contained in exactly 4096
  115. distinct frames, but one of these frames can be distinguished because it
  116. has a higher frame number. This frame is called the canonic frame of the
  117. location. In other words, the canonic frame of a given byte is the frame
  118. chosen so that the byte's offset from that frame lies in the range 0 to 15
  119. (decimal).
  120. For example, suppose FOO is a symbol defining a memory location. You
  121. would then refer to this frame as the "canonic frame of FOO." Similarly, if
  122. S is any set of memory locations, then a unique frame exists that has the
  123. lowest frame number in the set of canonic frames of the locations in S.
  124. This unique frame is called the canonic frame of the set S. You might
  125. refer similarly to the canonic frame of an LSEG or of a group of LSEGs.
  126. Segment Name
  127. LSEGs are assigned Segment Names at translation time. These names
  128. serve two purposes:
  129. o During linking they play a role in determining which LSEGs are
  130. combined with other LSEGs.
  131. o They are used in assembly source code to specify membership in
  132. groups.
  133. Class Name
  134. The translator may optionally assign class names to LSEGs during transla-
  135. tion. Classes define a partition on LSEGs: two LSEGs are in the same
  136. class if they have the same class name.
  137. The Microsoft linker applies the following semantics to class names: the
  138. class name "CODE", or any class name whose suffix is "CODE", implies
  139. that all segments of that class contain only code and may be considered
  140. read-only. Such segments may be overlaid if you specify the module con-
  141. taining the segment as part of an overlay.
  142. 6
  143. _ _ | | _ _
  144. _ _ | | _ _
  145. Microsoft Relocatable Object Module Formats
  146. _ __________________________________________________
  147. Overlay Name
  148. The linker may optionally assign an overlay name to LSEGs. The overlay
  149. name of an LSEG is ignored by Microsoft language linkers for version 3.00
  150. and later languages, but the standard MS-DOS linker supports it.
  151. Complete Name
  152. The complete name of an LSEG consists of the segment name, class name,
  153. and overlay name. The linker combines LSEGs from different modules if
  154. their complete names are identical.
  155. 7.2 Module Identification and Attributes
  156. A module header record, which provides a module name, is always the first
  157. record in a module. In addition to having a name, a module may represent
  158. a main program and may have a specified starting address. When linking
  159. multiple modules together, you should give only one module with the main
  160. attribute. If more than one main module appears, the first takes
  161. precedence.
  162. In summary, modules may or may not be main and may or may not have a
  163. starting address.
  164. 7.2.1 Segment Definition
  165. A module is a collection of object code defined by a sequence of records
  166. that a translator produces. The object code represents contiguous regions
  167. of memory whose contents the linker determines during translation.
  168. These regions are LSEGs. A module defines the attributes of each LSEG.
  169. The segment definition record (SEGDEF) is responsible for maintaining all
  170. LSEG information (name, length, memory alignment, etc.). The linker
  171. requires the LSEG information when you combine multiple LSEGs and
  172. when it establishes segment addressability. The SEGDEF records must
  173. follow the first header record.
  174. 7.2.2 Addressing a Segment
  175. The 8086 addressing mechanism provides segment base registers from
  176. which you may address a 64K-byte region of memory (a Frame). There is
  177. one code segment base register (CS), two data segment base registers (DS,
  178. ES), and one stack segment base register (SS).
  179. 7
  180. _ _ | | _ _
  181. _ _ | | _ _
  182. _ ______________
  183. The possible number of LSEGs that may make up a memory image far
  184. exceeds the number of available base registers. Thus, base registers may
  185. require frequent loading. This would be the case in a modular program
  186. with many small data and/or code LSEGs.
  187. Since such frequent loading of base registers is undesirable, it is a good
  188. strategy to collect many small LSEGs together into a single unit that will
  189. fit in one memory frame. Then all the LSEGs may be addressed using the
  190. same base register value. This addressable unit is a group and has been
  191. defined earlier in Section 7.1.1, "Definition of Terms."
  192. To establish addressability of objects within a group, you must explicitly
  193. define each group in the module. The group definition record (GRPDEF)
  194. lists constituent segments by their segment names.
  195. The GRPDEF records within a module must follow all SEGDEF records
  196. because GRPDEF records will reference SEGDEF records in defining a
  197. Group. The GRPDEF records must also precede all other records except
  198. header records, which the linker must process first.
  199. 7.2.3 Symbol Definition
  200. The Microsoft linker supports three different types of records belonging to
  201. the class of symbol definition records. The types are public names
  202. definition records (PUBDEFs), communal names definition records (COM-
  203. DEFs), and external names definition records (EXTDEFs). You use these
  204. record types to define globally visible procedures and data items and to
  205. resolve external references.
  206. 7.2.4 Indices
  207. "Index" fields appear throughout this chapter. An index is an integer that
  208. selects a particular item from a collection of items; for example: name
  209. index, segment index, group index, external index, type index, etc.
  210. _ ________________________________________________________________
  211. Note
  212. An index is normally a positive number. The index value zero is
  213. reserved, and may carry a special meaning depending on the type of
  214. index (for example, a segment index of zero specifies the "Unnamed"
  215. absolute pseudo-segment; a type index of zero specifies the "Untyped
  216. type.")
  217. _ ________________________________________________________________
  218. In general, indices must assume values that are quite large (that is, much
  219. 8
  220. _ _ | | _ _
  221. _ _ | | _ _
  222. Microsoft Relocatable Object Module Formats
  223. _ __________________________________________________
  224. larger than 255). Nevertheless, a great number of object files contain no
  225. indices with values greater than 50 or 100. Therefore, indices are encoded
  226. in one or two bytes, as required.
  227. The high-order (left-most) bit of the first (and possibly the only) byte
  228. determines whether the index occupies one byte or two. If the bit is 0, the
  229. index is a number between 0 and 127, occupying one byte. If the bit is 1,
  230. the index is a number between 0 and 32K-1, occupying two bytes, and is
  231. determined as follows: the low-order eight bits are in the second byte, and
  232. the high-order seven bits are in the first byte.
  233. 7.3 Conceptual Framework for Fixups
  234. A fixup is a modification to object code that achieves address binding that
  235. a translator requested and a linker performed.
  236. _ ________________________________________________________________
  237. Note
  238. This is the linker's definition of fixup. Nevertheless, the linker can
  239. modify object code (make a "fixup") that does not conform to this
  240. definition. For example, binding code to either hardware or software
  241. floating-point subroutines is a modification to an operation code,
  242. which is treated as an address. The previous definition of fixup is not
  243. intended to disallow or discourage modifications to the object code.
  244. _ ________________________________________________________________
  245. 8086-family translators need four kinds of data to specify a fixup:
  246. o The place and type of a Location to be fixed up.
  247. o One of two possible fixup modes.
  248. o A target, which is the memory address that Location must refer to.
  249. o A frame that defines a context in which the reference takes place.
  250. Location \(em There are five types of Locations: a pointer, a base, an offset, a
  251. hibyte, and a lobyte.
  252. The vertical alignment of the following figure illustrates four points
  253. (remember that the high-order byte of a word in 8086 memory is the byte
  254. with the higher address):
  255. o A base is the high-order word of a pointer (the linker doesn't care
  256. whether the low-order word of the pointer is present).
  257. 9
  258. _ _ | | _ _
  259. _ _ | | _ _
  260. _ ______________
  261. o An offset is the low-order word of a pointer (the linker doesn't care
  262. whether the high-order word follows).
  263. o A hibyte is the high-order half of an offset (the linker doesn't care
  264. whether the low-order half precedes).
  265. o A lobyte is the low-order half of an offset (the linker doesn't care
  266. whether the high-order half follows).
  267. +----+----+----+----+
  268. Pointer: | |
  269. +----+----+----+----+
  270. +----+----+
  271. Base: | |
  272. +----+----+
  273. +----+----+
  274. Offset: | |
  275. +----+----+
  276. +----+
  277. Hibyte: | |
  278. +----+
  279. +----+
  280. Lobyte: | |
  281. +----+
  282. Figure 7.1 Location Types
  283. A Location is specified by two kinds of data: the Location type, and where
  284. the Location is (the location of the Location?).
  285. The Location type is specified by the LOC field in the FIXUPP record's
  286. LOCAT field; where the Location is is specified by the Data Record Offset
  287. field in the same LOCAT field.
  288. Mode \(em The Microsoft linker supports two kinds of fixups: self-relative
  289. and segment-relative.
  290. Self-relative fixups support the 8-bit and 16-bit offsets used in CALL,
  291. JUMP, and SHORT-JUMP instructions. Segment-relative fixups support
  292. all other addressing modes of the 8086.
  293. Target \(em The target is the location in MAS that the linker references.
  294. (More explicitly, the linker considers the target the lowest byte in the
  295. object that it is referencing.) The linker specifies a target by one of six
  296. methods. There are three "primary" methods and three "secondary" ones.
  297. Each primary method of specifying a target uses two kinds of data: an
  298. index number X, and a displacement D.
  299. 10
  300. _ _ | | _ _
  301. _ _ | | _ _
  302. Microsoft Relocatable Object Module Formats
  303. _ __________________________________________________
  304. _ ________________________________________________________________
  305. (T0) X is a segment index. The target is the Dth byte in the LSEG that
  306. the segment index identifies.
  307. (T1) X is a group index. The target is the Dth byte in the LSEG that
  308. the group index identifies.
  309. (T2) X is an external index. The external index identifies the external
  310. name that (eventually) gives the address of a byte. The Dth byte
  311. following this byte is the target.
  312. Each secondary method of specifying a target uses only one item of data
  313. \(em the index number X; this assumes an implicit displacement equal to
  314. zero.
  315. _ ________________________________________________________________
  316. (T4) X is a segment index. The target is the 0th (first) byte in the
  317. LSEG that the segment index identifies.
  318. (T5) X is a group index. The target is the 0th (first) byte in the LSEG
  319. in the specified group located (eventually) lowest in MAS.
  320. (T6) X is an external index. The target is the byte whose address is the
  321. external name that the external index identifies.
  322. The following nomenclature describes a target:
  323. _ ________________________________________________________________
  324. Target: SI(segment name), displacement [T0]
  325. Target: GI(group name), displacement [T1]
  326. Target: EI(symbol name), displacement [T2]
  327. Target: SI (segment name) [T4]
  328. Target: GI (group name) [T5]
  329. Target: EI (symbol name) [T6]
  330. The following examples illustrate how this notation is used:
  331. _ ________________________________________________________________
  332. Target: SI(CODE), 1024 The 1025th byte in the segment
  333. CODE.
  334. Target: GI(DATAAREA) The location in MAS of a group
  335. called DATAAREA.
  336. Target: EI(SIN) The address of the external subrou-
  337. tine SIN.
  338. Target: EI(PAYSCHEDULE), 24 The 24th byte following the location
  339. of an external data structure called
  340. PAYSCHEDULE.
  341. 11
  342. _ _ | | _ _
  343. _ _ | | _ _
  344. _ ______________
  345. Frame \(em Every 8086 memory reference is to a location contained within a
  346. frame. This frame is designated by the content of a segment register. For
  347. the linker to form a correct, usable memory reference, it must know what
  348. the target is, and to which frame the reference is being made. Thus, every
  349. fixup specifies such a frame, in one of six methods. Some methods use
  350. data, X, which is in the index number. Other methods require no data.
  351. The five methods of specifying frames are as follows:
  352. _ ________________________________________________________________
  353. (F0) X is a segment index. The frame is the canonic frame of the LSEG
  354. that the segment index defines.
  355. (F1) X is a group index. The frame is the canonic frame defined by the
  356. group (that is, the canonic frame defined by the LSEG in the group
  357. located (eventually) lowest in MAS).
  358. (F2) X is an external index. The frame is determined when the linker
  359. finds the external name's public definition. There are two cases:
  360. _ _________________________________________________________
  361. (F2a) The linker defines the symbol relative to some LSEG, and
  362. there is no associated group. The linker also specifies the
  363. LSEG's canonic frame.
  364. (F2c) Regardless of how the linker defines the symbol, there is an
  365. associated group. And the linker specifies the canonic
  366. frame of the group. (The Group Index field of the PUBDEF
  367. record specifies the group.)
  368. (F4) No X. The frame is the canonic frame of the LSEG that contains
  369. Location.
  370. (F5) No X. The target determines the frame. There are three cases:
  371. _ _________________________________________________________
  372. (F5a) The target specifies a segment index: in this case, the frame
  373. is determined as in (F0).
  374. (F5b) The target specifies a group index: in this case, the frame is
  375. determined as in (F1).
  376. (F5c) The target specifies an external index: in this case, the
  377. frame is determined as in (F2).
  378. The nomenclature that describes frames is similar to the above nomencla-
  379. ture for targets.
  380. _ ________________________________________________________________
  381. Frame: SI (segment name) [F0]
  382. Frame: GI (group name) [F1]
  383. 12
  384. _ _ | | _ _
  385. _ _ | | _ _
  386. Microsoft Relocatable Object Module Formats
  387. _ __________________________________________________
  388. Frame: EI (symbol name) [F2]
  389. Frame: Location [F4]
  390. Frame: target [F5]
  391. Frame: None [F6]
  392. For an 8086 memory reference, the frame specified by a self-relative refer-
  393. ence is usually the canonic frame of the LSEG that contains Location.
  394. Also, the frame specified by a segment-relative reference is the canonic
  395. frame of the LSEG that contains the target.
  396. 7.3.1 Self-Relative Fixup
  397. A self-relative fixup works as follows: Location implicitly defines a
  398. memory address\(emnamely, the address of the byte following Location
  399. (because at the time of a self-relative reference, the 8086 IP (Instruction
  400. Pointer) is pointing to the byte following the reference).
  401. For 8086 self-relative references, if either the Location or the target is out-
  402. side the specified frame, the linker gives a warning. Otherwise, there is a
  403. unique l6-bit displacement that, when added to the address implicitly
  404. defined by Location, yields the relative position of the target in the frame.
  405. o If Location is an offset, the linker adds the displacement to Loca-
  406. tion (modulo 65,536) and reports no errors.
  407. o If Location is a lobyte, the displacement must be within the range
  408. {-128:127}; otherwise, the linker gives a warning. The linker adds
  409. the displacement to Location (modulo 256).
  410. o If Location is a base, pointer, or hibyte, it is unclear what the
  411. translator intended, so the linker's action is undefined.
  412. 7.3.2 Segment-Relative Fixup
  413. A segment-relative fixup operates as follows: a nonnegative 16-bit number,
  414. FBVAL, is defined as the frame number of the frame or selector value that
  415. the fixup specifies. A signed 20-bit number, FOVAL, is defined as the dis-
  416. tance from the base of the frame to the target. If this signed 20-bit
  417. number is less than 0 or greater than 65,535, the linker reports an error.
  418. Otherwise, the linker uses FBVAL and FOVAL to fix up Location in the
  419. following fashion:
  420. o If Location is a pointer, the linker adds FBVAL (modulo 65,536) to
  421. the high-order word of pointer, and adds FOVAL (modulo 65,536)
  422. to the low-order word of pointer.
  423. 13
  424. _ _ | | _ _
  425. _ _ | | _ _
  426. _ ______________
  427. o If Location is a base, the linker adds FBVAL (modulo 65,536) to
  428. the base and ignores FOVAL.
  429. o If Location is an offset, the linker adds FOVAL (modulo 65,536) to
  430. the offset and ignores FBVAL.
  431. o If Location is a hibyte, the linker adds (FOVAL/256) (modulo 256)
  432. to the hibyte and ignores FBVAL. (The division indicated is
  433. integer division; that is, the linker discards the remainder.)
  434. o If Location is a lobyte, the linker adds (FOVAL modulo 256)
  435. (modulo 256) to the lobyte and ignores FBVAL.
  436. 7.4 Record Sequence
  437. A object code file must contain a sequence of (one or more) modules, or a
  438. library containing zero or more modules. The following syntax shows the
  439. valid record ordering necessary to form a module. In addition, the given
  440. semantic rules provide information about how to interpret the record
  441. sequence.
  442. _ ________________________________________________________________
  443. Note
  444. The description language used in the following syntax is defined in
  445. WIRTH: CACM, November 1977, vol. 20, no. 11, pp. 822-823. The
  446. character strings represented by capital letters are not literals but
  447. identifiers, and are further defined in the record format section.
  448. _ ________________________________________________________________
  449. object file = tmodule
  450. tmodule = {THEADR | LHEADR} seg-grp {component} modtail
  451. seg_grp = {LNAMES} {SEGDEF} {EXTDEF | GRPDEF}
  452. component = data | debug_record
  453. data = content_def | thread_def |
  454. PUBDEF | EXTDEF | COMDEF | LOCSYM
  455. debug_record = LINNUM
  456. content_def = data_record {FIXUPP}
  457. thread_def = FIXUPP (containing only Thread fields)
  458. data_record = LIDATA | LEDATA
  459. 14
  460. _ _ | | _ _
  461. _ _ | | _ _
  462. Microsoft Relocatable Object Module Formats
  463. _ __________________________________________________
  464. modtail = MODEND
  465. The following rules apply:
  466. o A FIXUPP record always refers to the previous data record.
  467. o All LNAMES, SEGDEF, GRPDEF, and EXTDEF records must pre-
  468. cede all records that refer to them.
  469. o Comment records may appear anywhere in a file, except as the first
  470. or last record in a file or module, or within a content_def.
  471. 7.5 Introducing the Record Formats
  472. The following pages present diagrams of record formats in schematic form.
  473. Here is a sample record format that illustrates the various conventions:
  474. 7.5.1 Sample Record Format (SAMREC)
  475. -----------------------///---------||||-----------
  476. | | | | | |
  477. | REC | Record | Name | Number | CHK |
  478. | TYP | Length | | | SUM |
  479. | xxH | | | | |
  480. | | | | | |
  481. ----------------------///----------||||-----------
  482. | |
  483. +----rpt-----+
  484. The Title and Official Abbreviation
  485. At the top of the figure is the name of the record format described, with
  486. its official abbreviation. To promote uniformity among various programs,
  487. including translators and debuggers, use the abbreviation in both code and
  488. documentation. The abbreviation of the record format is always six
  489. letters.
  490. The Boxes
  491. Each format is drawn with boxes of two sizes. The narrow boxes represent
  492. single bytes. The wide boxes each represent two bytes. The wide boxes
  493. with three slashes in the top and bottom represent a variable number of
  494. bytes, one or more, depending upon content. The wide boxes with four
  495. vertical bars in the top and bottom represent four-byte fields.
  496. 15
  497. _ _ | | _ _
  498. _ _ | | _ _
  499. _ ______________
  500. RECTYP
  501. The first byte in each record contains a value between 0 and 255, indicat-
  502. ing the record type.
  503. Record Length
  504. The second field in each record contains the number of bytes in the record,
  505. exclusive of the first two fields, where a field is a 16-bit number\(ema low
  506. byte followed by a high byte.
  507. Name
  508. Any field that indicates a name has the following internal structure: the
  509. first byte contains a number between 0 and 127, inclusive, indicating the
  510. number of remaining bytes in the field. The remaining bytes are inter-
  511. preted as a byte string.
  512. Most translators constrain the character set to a subset of the ASCII char-
  513. acter set.
  514. Number
  515. A four-byte number field represents a 32-bit unsigned integer, where the
  516. first eight bits (least-significant) are stored in the first byte (lowest
  517. address), the next eight bits are stored in the second byte, and so on.
  518. Repeated or Conditional Fields
  519. Some portions of a record format contain a field or series of fields that
  520. may be repeated one or more times. Such portions are indicated by the
  521. "repeated" or "rpt" brackets below the boxes.
  522. Similarly, some portions of a record format are present only if some given
  523. condition is true; these fields are indicated by similar "conditional" or
  524. "cond" brackets below the boxes.
  525. CHKSUM
  526. The last field in each record is a check sum, which contains the two's com-
  527. plement of the sum (modulo 256) of all other bytes in the record. There-
  528. fore, the sum (modulo 256) of all bytes in the record is zero.
  529. 16
  530. _ _ | | _ _
  531. _ _ | | _ _
  532. Microsoft Relocatable Object Module Formats
  533. _ __________________________________________________
  534. Bit Fields
  535. Sometimes descriptions of contents of fields are at the bit level. Boxes
  536. with vertical lines drawn through them represent bytes or words; the verti-
  537. cal lines indicate bit boundaries. Thus, the following byte representation
  538. has three bit fields of three, one, and four bits, respectively.
  539. ---------------------------------
  540. | | | | | | | | |
  541. | | | |
  542. | | | | | | | | |
  543. ---------------------------------
  544. 3 1 4
  545. 7.5.2 T-Module Header Record (THEADR)
  546. -----------------------///-----------
  547. | | | | |
  548. | REC | Record | T- | CHK |
  549. | TYP | Length | Module | SUM |
  550. | 80H | | Name | |
  551. | | | | |
  552. ----------------------///------------
  553. T-Module Name
  554. The T-Module Name field contains the name for the T-module.
  555. 7.5.3 L-Module Header Record (LHEADR)
  556. -----------------------///-----------
  557. | | | | |
  558. | REC | Record | L- | CHK |
  559. | TYP | Length | Module | SUM |
  560. | 82H | | Name | |
  561. | | | | |
  562. ----------------------///------------
  563. L-Module Name
  564. The L-Module Name field contains the name for the L-module.
  565. Every module output from a translator must have a T-module or L-module
  566. header record. The linker requires a THEADR or LHEADR record to come
  567. first in the module and ignores any others. The LHEADR record is identi-
  568. cal to the THEADR record, except it has a record type of 82H.
  569. 17
  570. _ _ | | _ _
  571. _ _ | | _ _
  572. _ ______________
  573. 7.5.4 List of Names Record (LNAMES)
  574. -----------------------///-----------
  575. | | | | |
  576. | REC | Record | Name | CHK |
  577. | TYP | Length | | SUM |
  578. | 96H | | | |
  579. | | | | |
  580. ----------------------///------------
  581. | |
  582. +----rpt-----+
  583. The LNAMES record contains a list of names that the following SEGDEF
  584. and GRPDEF records may use as the names of segments, classes, and/or
  585. groups.
  586. The order of LNAMES records in a module and the order of names within
  587. each LNAMES record imply a mapping of these names to numbers: 1, 2, 3,
  588. etc. These numbers are used as "Name Indices" in the Segment Name
  589. Index, Class Name Index, and Group Name Index fields of the SEGDEF
  590. and GRPDEF records.
  591. Name
  592. This repeatable field provides a name, which may have zero length.
  593. 7.5.5 Segment Definition Record (SEGDEF)
  594. -----------------///-----------------///-----///---///------
  595. | | | | | | | | |
  596. |REC| Record | Segment | Segment | Segment |Class|Over |CHK|
  597. |TYP| Length | ATTR | Length | Name |Name |Lay |SUM|
  598. |98H| | | | Index |Index|Name | |
  599. | | | | | | |Index| |
  600. -----------------///-----------------///-----///---///------
  601. Segment index values 1 through 32,767, which are used in other record
  602. types to refer to specific LSEGs, are defined implicitly by the sequence in
  603. which SEGDEF records appear in the object file.
  604. SEG ATTR
  605. The SEG ATTR field provides information on various attributes of a seg-
  606. ment, and has the following format:
  607. ------------------------
  608. | | | |
  609. | ACB | Frame | Off- |
  610. 18
  611. _ _ | | _ _
  612. _ _ | | _ _
  613. Microsoft Relocatable Object Module Formats
  614. _ __________________________________________________
  615. | P | Number | Set |
  616. | | | |
  617. | | | |
  618. -------------r----------
  619. | |
  620. +---conditional--+
  621. The ACBP byte contains four numbers\(emthe A, C, B, and P attribute
  622. specifications. This byte has the following format:
  623. ---------------------------------
  624. | | | | | | | | |
  625. | A | C | B | P |
  626. | | | | | | | | |
  627. ---------------------------------
  628. A (Alignment) is a 3-bit subfield that specifies the alignment attribute of
  629. the LSEG. The semantics are defined as follows:
  630. _ ________________________________________________________________
  631. A=0 SEGDEF describes an absolute LSEG.
  632. A=1 SEGDEF describes a relocatable, byte-aligned LSEG.
  633. A=2 SEGDEF describes a relocatable, word-aligned LSEG.
  634. A=3 SEGDEF describes a relocatable, paragraph-aligned LSEG.
  635. A=4 SEGDEF describes a relocatable, page(256-byte)-aligned LSEG.
  636. If A=0, the Frame Number and Offset fields are present. With the Micro-
  637. soft linker, you may use absolute segments for addressing only; for exam-
  638. ple, to define the starting address of a ROM and to define symbolic names
  639. for addresses within the ROM. The linker ignores any data that belongs
  640. to an absolute LSEG, and issues a warning if absolute segments are
  641. defined for a program that runs in protected mode.
  642. C (Combination) is a 3-bit subfield that specifies the Combination attri-
  643. bute of the LSEG. Absolute segments (A=0) must have combination zero
  644. (C=0). For relocatable segments, the C field encodes a number
  645. (0,1,2,3,4,5,6, or 7) that indicates how the segment can be combined. One
  646. way to interpret this attribute is to consider how two LSEGs are com-
  647. bined.
  648. For example, suppose that X and Y are LSEGs, and that Z is the LSEG
  649. resulting from the combination of X and Y. Let LX and LY be the lengths
  650. of X and Y, and let MXY denote the maximum of LX, LY. Now, to accom-
  651. modate the alignment attribute of Y, let G be the length of any gap
  652. required between the X and Y components of Z. Then, let LZ denote the
  653. length of the (combined) LSEG, Z; let dx (0\(<=dx<LX) be the offset in X of
  654. a byte, and similarly, let dy be the offset (of a byte) in Y.
  655. 19
  656. _ _ | | _ _
  657. _ _ | | _ _
  658. _ ______________
  659. The following table gives the length LZ of the combined LSEG, Z, and the
  660. offsets dx' and dy' in Z for the bytes corresponding to dx in X, and to dy in
  661. Y.
  662. Table 7.2
  663. Combination Attribute Example
  664. _ _________________________________________________________________________
  665. C LZ dx' dy'
  666. _ ____________________________________________
  667. 2 LX+LY+G dx dy+LX+G "Public"
  668. 5 LX+LY+G dx dy+LX+G "Stack"
  669. 6 MXY dx dy "Common"
  670. _ _________________________________________________________________________
  671. Table 7.2 has no lines for C=0, 1, 3, 4, or 7. C=0 indicates that the relo-
  672. catable LSEG may not be combined; C=1 and C=3 are undefined. C=4
  673. and C=7 are treated the same as C=2.
  674. B (Big) is a 1-bit subfield, which, if set to 1, indicates that the segment
  675. length is exactly 64K (65,536 bytes). In this case, the Segment Length
  676. field must contain zero.
  677. The P field must always be zero.
  678. The Frame Number and Offset fields (present only for absolute segments,
  679. A=0) specify the placement in MAS of the absolute segment. Offset is in
  680. the range between 0 and 15, inclusive. If you want an offset value larger
  681. than 15, you should adjust the frame number.
  682. Segment Length
  683. The Segment Length field gives a segment's length in bytes. This length
  684. may be zero. If it is, the linker does not delete the segment from the
  685. module. The Segment Length field is only large enough to hold numbers
  686. from 0 to 64K-1, inclusive. To give the segment a length of 64K, you
  687. must use the B attribute bit in the ACBP field (see SEG ATTR in this sec-
  688. tion).
  689. Segment Name Index
  690. The segment name is a name that a programmer or translator assigns to
  691. the segment; for example, CODE, DATA, TAXDATA,
  692. MODULENAME_CODE, or STACK. The Segment Name Index field pro-
  693. vides the segment name by indexing into the list of names provided by the
  694. LNAMES record.
  695. 20
  696. _ _ | | _ _
  697. _ _ | | _ _
  698. Microsoft Relocatable Object Module Formats
  699. _ __________________________________________________
  700. Class Name Index
  701. The class name is a name the programmer or translator assigns to a seg-
  702. ment. If none is assigned, the name is null, and has a length of zero. The
  703. purpose of a class name is to let the programmer define a "handle" to
  704. order the LSEGs in MAS; for example, RED, WHITE, BLUE; or ROM
  705. FASTRAM, DISPLAYRAM. The Class Name Index field provides the
  706. class name by indexing into the list of names provided by the LNAMES
  707. record.
  708. Overlay Name Index
  709. The overlay name is a name that the translator and/or the linker, at the
  710. programmer's request, applies to a segment. The overlay name, like the
  711. class name, may be null. The Overlay Name Index field provides the over-
  712. lay name by indexing into the list of names provided by the LNAMES
  713. record.
  714. _ ________________________________________________________________
  715. Note
  716. Microsoft language linkers (versions 3.00 and later) ignore the Overlay
  717. Name Index field, but the standard MS-DOS linker supports it.
  718. _ ________________________________________________________________
  719. 7.5.6 Group Definition Record (GRPDEF)
  720. -----------------------///---------///------------
  721. | | | | | |
  722. | REC | Record | Group | Group | CHK |
  723. | TYP | Length | Name | Component | SUM |
  724. | 9AH | | Index | Descriptor | |
  725. | | | | | |
  726. --------------------///----------///--------------
  727. | |
  728. +--repeated--+
  729. Group Name Index
  730. The linker may reference a collection of LSEGs with the group name.
  731. Most importantly, when the LSEGs are eventually fixed in MAS, a frame
  732. must exist that "covers" every LSEG of the group.
  733. The Group Name Index field provides the group name by indexing into the
  734. list of names provided by the LNAMES record.
  735. 21
  736. _ _ | | _ _
  737. _ _ | | _ _
  738. _ ______________
  739. Group Component Descriptor
  740. This repeatable field has the following format:
  741. -----------///-----
  742. | | |
  743. | FFH | Segment |
  744. | | Index |
  745. | | |
  746. | | |
  747. -------------------
  748. The first byte of the Group Component Descriptor field contains 0FFH;
  749. the descriptor contains one field, which is a segment index that selects the
  750. LSEG described by a preceding SEGDEF record.
  751. 7.5.7 Public Names Definition Record
  752. (PUBDEF)
  753. ---------------------///------///--------------///---------
  754. | | | | | | | |
  755. | REC| Record | Public | Public |Public | Type | CHK |
  756. | TYP| Length | Base | Name |Offset | Index | SUM |
  757. | 90H| | | | | | |
  758. | | | | | | | |
  759. ---------------------///-----///--------------///----------
  760. | |
  761. +---------repeated--------+
  762. The PUBDEF record provides a list of one or more public names. For each
  763. name, three kinds of data are provided: (1) a base value for the name, (2)
  764. the offset value of the name, and (3) the type of entity represented by the
  765. name.
  766. Public Base
  767. The Public Base field has the following format:
  768. -----///---------///-----------------
  769. | | | |
  770. | Group | Segment | Frame |
  771. | Index | Index | Number |
  772. | | | |
  773. -----///---------///-----------------
  774. | |
  775. +conditional+
  776. The Group Index field has a format given earlier, and contains a number
  777. between 0 and 32,767, inclusive. A nonzero value in the Group Index field
  778. associates a group with the public symbol, and is used as described in case
  779. 22
  780. _ _ | | _ _
  781. _ _ | | _ _
  782. Microsoft Relocatable Object Module Formats
  783. _ __________________________________________________
  784. (F2c) of Section 7.3, "Conceptual Framework for Fixups." A zero value in
  785. the Group Index field indicates that there is no associated group.
  786. The Segment Index field has a format given earlier, and contains a number
  787. between 0 and 32,767, inclusive.
  788. A nonzero value in the Segment Index field selects an LSEG. In this case,
  789. the location of each public symbol defined in the record is taken as a non-
  790. negative displacement (given by a Public Offset field) from the first byte of
  791. the selected LSEG. Also, the Frame Number field must be absent.
  792. A zero value in the Segment Index field means that the defined symbols are
  793. absolute, and that the absolute addresses of the symbols are the values in
  794. the Public Offset field. The Group Index field is ignored.
  795. The Frame Number field contains a frame number only if the value of the
  796. Segment Index field is zero. The linker ignores this field.
  797. A nonzero value in the Group Index field selects some group. This group is
  798. taken as the "frame of reference" for references to all public symbols
  799. defined in this record. That is, the linker performs the following actions:
  800. o The linker converts any fixup of the form:
  801. Target: EI(P)
  802. Frame: Target
  803. (where P is a public symbol in this PUBDEF record) to a fixup of
  804. the form:
  805. Target: SI(L),d
  806. Frame: GI(G)
  807. where SI(L) and d are provided by the Segment Index and Public
  808. Offset fields. (The "normal" action would have the frame specifier
  809. in the new fixup be the same as in the old fixup: Frame:Target.)
  810. o When the linker converts the value of a public symbol, as defined
  811. by the Segment Index, Public Offset, and (optionally) Frame
  812. Number fields, to a {base,offset} pair, the base part is the base of
  813. the indicated group.
  814. A zero value in the Group Index field selects no group. The linker does not
  815. alter the frame specification of fixups referencing the symbol, and takes, as
  816. the base part of the absolute value of the public symbol, the canonic frame
  817. of the segment (either LSEG or PSEG) determined by the Segment Index
  818. field.
  819. 23
  820. _ _ | | _ _
  821. _ _ | | _ _
  822. _ ______________
  823. Public Name
  824. The Public Name field gives the name of the object whose location in MAS
  825. the linker makes available to other modules. The name must contain one
  826. or more characters.
  827. Public Offset
  828. The Public Offset field is a 16-bit value. It is either the offset of the public
  829. symbol with respect to an LSEG (if the segment index is greater than
  830. zero), or the offset of the public symbol with respect to the specified frame
  831. (if the segment index is equal to zero).
  832. Type Index
  833. The Type Index field identifies a single preceding TYPDEF (Type
  834. Definition Record), which contains a descriptor for the type of entity
  835. represented by the public symbol. The linker ignores this field.
  836. 7.5.8 Communal Names Definition Record
  837. (COMDEF)
  838. -----------------///---------///-----------------------------
  839. | | | | | | | |
  840. | REC | REC | Communal | Type | Data | Communal | CHK |
  841. | TYP | LEN | Name | Index | Seg | Length | SUM |
  842. | B0H | | | | Type | | |
  843. | | | | | | | |
  844. ------------+----///---------///----------------------+------
  845. | |
  846. +-------repeated--------------------------+
  847. The COMDEF record provides a list of one or more Communal Names,
  848. which define communal variables. A communal variable is an unitialized
  849. public variable whose final size and location are not fixed during compil-
  850. ing.
  851. Communal variables are similar to FORTRAN common blocks in that if
  852. you are linking object modules that each declare a communal variable,
  853. then the size of that variable is the largest of the declared variables. In
  854. the C language, all uninitialized public variables are communal. The fol-
  855. lowing example shows three different declarations of the same C communal
  856. variable:
  857. char foo[4]; /* In file a.c */
  858. char foo[1]; /* In file b.c */
  859. char foo[1024]; /* In file c.c */
  860. 24
  861. _ _ | | _ _
  862. _ _ | | _ _
  863. Microsoft Relocatable Object Module Formats
  864. _ __________________________________________________
  865. If the objects produced from a.c, b.c, and c.c are linked together, the linker
  866. allocates 1024 bytes for the character array "foo."
  867. _ ________________________________________________________________
  868. Note
  869. This record requires that a COMENT record from the Microsoft Exten-
  870. sion class appear before it in the object module.
  871. _ ________________________________________________________________
  872. Communal Name
  873. The Communal Name field gives the communal variable name, and must
  874. contain one or more characters.
  875. Communal names are treated as external names when an external name is
  876. requested elsewhere in the module. Communal names are ordered together
  877. with external names for the purpose of referring to an external name by its
  878. index. (See the description of the EXTDEF record later in this section for
  879. more details on external names.)
  880. Type Index
  881. The Type Index field is ignored by the Microsoft linker.
  882. Data Segment Type
  883. The Data Segment Type field is a single byte that describes the data seg-
  884. ment in which the communal variable resides. It can contain the following
  885. values:
  886. 62H (NEAR) = the communal variable is in the default data segment.
  887. 61H (FAR) = the communal variable is not in the default data segment.
  888. Communal Length
  889. The Communal Length field describes the length of the communal variable
  890. according to its data segment type.
  891. If its value is NEAR (62H), the field represents the length in bytes.
  892. If its value is FAR (61H), the field represents:
  893. +----///----+-----///------+
  894. | Number of | Element size |
  895. 25
  896. _ _ | | _ _
  897. _ _ | | _ _
  898. _ ______________
  899. | elements | in bytes |
  900. +----///----+-----///------+
  901. The format of all the length fields is as follows:
  902. -------
  903. | |
  904. | 0 |
  905. | to |
  906. | 128 |
  907. | |
  908. -------
  909. -------------------
  910. | | |
  911. | | 0 |
  912. | 129 | to |
  913. |(81H)| 64K-1 |
  914. | | |
  915. -------------------
  916. -------------------------
  917. | | |
  918. | | 0 |
  919. | 132 | to |
  920. |(84H)| 16M-1 |
  921. | | |
  922. -------------------------
  923. -------------------------
  924. | | |
  925. | | -2G-1 |
  926. | 136 | to |
  927. |(88H)| 2G-1 |
  928. | | |
  929. -------------------------
  930. The first format (single byte), containing a value between 0 and 127,
  931. represents the number given.
  932. The second format, with a leading byte containing 129, represents the
  933. number contained in the following two bytes.
  934. The third format, with a leading byte containing 132, represents the
  935. number contained in the following three bytes.
  936. The fourth format, with a leading byte containing 136, represents the
  937. number contained in the following four bytes with its sign extended if
  938. necessary.
  939. 26
  940. _ _ | | _ _
  941. _ _ | | _ _
  942. Microsoft Relocatable Object Module Formats
  943. _ __________________________________________________
  944. Link-Time Semantics:
  945. A PUBDEF matching a communal variable definition overrides the com-
  946. munal variable definition. Two communal variable definitions match if
  947. the names in their definitions match. If two matching definitions disagree
  948. whether a communal variable is NEAR or FAR, the linker assumes the
  949. variable is NEAR.
  950. If the variable is NEAR, then its size is the largest of the sizes specified for
  951. it. If the variable is FAR, the linker issues a warning if the array element
  952. sizes conflict. If these sizes don't conflict, the variable's size is the element
  953. size multiplied by the largest number of elements specified. In addition,
  954. the sum of the sizes of all NEAR variables must not exceed 64K bytes, and
  955. the sum of the sizes of all FAR variables must not exceed the size of the
  956. machine's addressable memory space.
  957. HUGE Communal Variables:
  958. A FAR communal variable that is larger than 64K bytes (a HUGE commu-
  959. nal variable) resides in segments that are contiguous (on an 8086) or that
  960. have consecutive selectors (on an 80286). No other data items reside in
  961. the segments occupied by a HUGE communal variable.
  962. If the linker finds matching HUGE and NEAR communal variable
  963. definitions, it issues a warning message, since it is impossible for a NEAR
  964. variable to be larger than 64K bytes.
  965. 7.5.9 Local Symbols Record (LOCSYM)
  966. ---------------------///------///--------------///---------
  967. | | | | | | | |
  968. | REC| Record | Local | Local | Local | Type | CHK |
  969. | TYP| Length | Base | Name |Offset | Index | SUM |
  970. | 92H| | | | | | |
  971. | | | | | | | |
  972. ---------------------///-----///--------------///----------
  973. | |
  974. +---------repeated--------+
  975. The LOCSYM record provides information for the definition of a local
  976. symbol, one that is visible only within the module in which it is defined.
  977. The form and meaning of each of the fields is identical to those in the
  978. PUBDEF record.
  979. _ ________________________________________________________________
  980. Note
  981. 27
  982. _ _ | | _ _
  983. _ _ | | _ _
  984. _ ______________
  985. The LOCSYM record requires that a COMENT record from the Micro-
  986. soft Extensions class appear before it in the object module. Also, it is
  987. only recognized by Microsoft language linkers later than version 3.07.
  988. _ ________________________________________________________________
  989. 7.5.10 External Names Definition Record
  990. (EXTDEF)
  991. -----------------------///---------///-----------
  992. | | | | | |
  993. | REC | Record | External | Type | CHK |
  994. | TYP | Length | Name | Index | SUM |
  995. | 8CH | | | | |
  996. | | | | | |
  997. -----------------------///---------///-----------
  998. | |
  999. +-------repeated--------+
  1000. The EXTDEF record provides a list of external names, and for each name,
  1001. the type of object it represents. The linker assigns to each external name
  1002. the value provided by an identical public name or local name (if such a
  1003. name is found).
  1004. External Name
  1005. The External Name field provides the external object name, which must
  1006. have nonzero length.
  1007. Including a name in an EXTDEF record is an implicit request to link the
  1008. object file to a module containing the same name declared as a public sym-
  1009. bol, unless the name is defined as a local symbol within the same module
  1010. as the EXTDEF. This request determines whether the external name is
  1011. referenced within some FIXUPP record in the module.
  1012. The order of EXTDEF records in a module and the order of external
  1013. names within each EXTDEF record, together with COMDEF records and
  1014. communal names, implies a mapping on the set of all external names
  1015. requested by the module; for example: 1, 2, 3, etc. So to refer to a particu-
  1016. lar external name, the linker uses these numbers as "external indices" in
  1017. the Target Datum and/or Frame Datum fields of FIXUPP records.
  1018. External indices may not reference forward. For example, an EXTDEF
  1019. defining the kth object must precede any record referring to that object
  1020. with index k.
  1021. 28
  1022. _ _ | | _ _
  1023. _ _ | | _ _
  1024. Microsoft Relocatable Object Module Formats
  1025. _ __________________________________________________
  1026. Type Index
  1027. The Type Index field is ignored by the Microsoft linker, except for linker
  1028. versions earlier than 3.05, and for object modules lacking the COMENT
  1029. record from the Microsoft Extensions class, in which case, refer to Section
  1030. 7.6 "Microsoft Type Representation for Communal Variables."
  1031. 7.5.11 Line Numbers Record (LINNUM)
  1032. ----------------------///-----------------------------------
  1033. | | | | | |
  1034. | REC | Record | Line | Line | Line | CHK |
  1035. | TYP | Length | Number | Number | Number | SUM |
  1036. | 94H | | Base | | Offset | |
  1037. | | | | | | |
  1038. ----------------------///-----------------------------------
  1039. | |
  1040. +--------repeated-------+
  1041. The LINNUM record allows a translator to relate a line number in source
  1042. code to the corresponding line in translated code.
  1043. Line Number Base
  1044. The Line Number Base field has the following format:
  1045. -----///---------///-----
  1046. | | |
  1047. | Group | Segment |
  1048. | Index | Index |
  1049. | | |
  1050. -----///---------///-----
  1051. The Group Index field is ignored by the Microsoft linker.
  1052. The Segment Index field determines the location of the first byte of code
  1053. corresponding to some source line number.
  1054. Line Number
  1055. The Line Number field provides a binary line number between 0 and
  1056. 32,767, inclusive. If the high-order bit is not zero, the number is con-
  1057. sidered undefined.
  1058. 29
  1059. _ _ | | _ _
  1060. _ _ | | _ _
  1061. _ ______________
  1062. Line Number Offset
  1063. The Line Number Offset field is a 16-bit value, which is the offset of the
  1064. line number with respect to an LSEG (if the segment index is greater than
  1065. zero).
  1066. 7.5.12 Logical Enumerated Data Record
  1067. (LEDATA)
  1068. -----------------------///-----------------------------
  1069. | | | | | | |
  1070. | REC | Record | Segment | Enumerated| | CHK |
  1071. | TYP | Length | Index | Data | DAT | SUM |
  1072. | A0H | | | offset | | |
  1073. | | | | | | |
  1074. -----------------------///-----------------------------
  1075. | |
  1076. +-rpt-+
  1077. The LEDATA record provides contiguous data from which the linker may
  1078. construct a portion of an 8086 memory image.
  1079. Segment Index
  1080. The Segment Index field, which must be nonzero, specifies an index rela-
  1081. tive to the SEGDEF records that precede the LEDATA record.
  1082. Enumerated Data Offset
  1083. The Enumerated Data Offset field specifies an offset that is relative to the
  1084. base of the LSEG specified by the segment index. The field also defines the
  1085. relative location of the first byte of the DAT field. Successive data bytes
  1086. in the DAT field occupy successively higher locations of memory.
  1087. DAT
  1088. The DAT field provides up to 1024 consecutive bytes of relocatable or
  1089. absolute data.
  1090. 30
  1091. _ _ | | _ _
  1092. _ _ | | _ _
  1093. Microsoft Relocatable Object Module Formats
  1094. _ __________________________________________________
  1095. 7.5.13 Logical Iterated Data Record (LIDATA)
  1096. ----------------------///---------------------///-----------
  1097. | | | | | | |
  1098. | REC | Record | Segment | Iterated | Iterated | CHK |
  1099. | TYP | Length | Index | Data | Data | SUM |
  1100. | A2H | | | Offset | Block | |
  1101. | | | | | | |
  1102. ----------------------///---------------------///-----------
  1103. | |
  1104. +-repeated--+
  1105. The LIDATA record provides contiguous data from which the linker may
  1106. construct a portion of an 8086 memory image.
  1107. Segment Index
  1108. The Segment Index field, which must be nonzero, specifies an index that is
  1109. relative to the SEGDEF records that precede the LIDATA record.
  1110. Iterated Data Offset
  1111. The Iterated Data Offset field specifies an offset that is relative to the base
  1112. of the LSEG specified by the segment index. It also defines the relative
  1113. location of the first byte in the iterated data block. Successive data bytes
  1114. in the iterated data block occupy successively higher locations of memory.
  1115. Iterated Data Block
  1116. This repeated field is a structure specifying the repeated data bytes. It has
  1117. the following format:
  1118. -----------------------------///-----
  1119. | | | |
  1120. | Repeat | Block | |
  1121. | Count | Count | Content |
  1122. | | | |
  1123. | | | |
  1124. -----------------------------///-----
  1125. 31
  1126. _ _ | | _ _
  1127. _ _ | | _ _
  1128. _ ______________
  1129. _ ________________________________________________________________
  1130. Note
  1131. The linker cannot handle LIDATA records whose iterated Data Blocks
  1132. are larger than 512 bytes.
  1133. _ ________________________________________________________________
  1134. Repeat Count
  1135. The Repeat Count field specifies the number of times to repeat the Con-
  1136. tent portion of this iterated data block. The value of the Repeat Count
  1137. field must be nonzero.
  1138. Block Count
  1139. The Block Count field specifies the number of iterated data blocks in the
  1140. Content portion of this iterated data block. If the Block Count field has a
  1141. value of zero, the Content portion of the iterated data block is interpreted
  1142. as data bytes. If the field is nonzero, the Content portion is interpreted as
  1143. that number of iterated data blocks.
  1144. Content
  1145. The Content field may be interpreted in one of two ways, depending on
  1146. the value of the previous Block Count field.
  1147. If the Block Count field is zero, this field is a 1-byte count followed by the
  1148. indicated number of data bytes. But if the Block Count field is nonzero,
  1149. the Content field is interpreted as the first byte of another iterated data
  1150. block.
  1151. 7.5.14 Fixupp Record (FIXUPP)
  1152. -----------------------///-----------
  1153. | | | | |
  1154. | REC | Record | Thread | CHK |
  1155. | TYP | Length | or | SUM |
  1156. | 9CH | | Fixup | |
  1157. | | | | |
  1158. -----------------------///-----------
  1159. | |
  1160. +----rpt----+
  1161. The FIXUPP record specifies zero or more fixups. Each fixup requests a
  1162. modification (fixup) to a Location within the previous data record. A data
  1163. record may be followed by more than one FIXUPP record that refers to it.
  1164. 32
  1165. _ _ | | _ _
  1166. _ _ | | _ _
  1167. Microsoft Relocatable Object Module Formats
  1168. _ __________________________________________________
  1169. Each fixup is specified by a Fixup field that specifies four kinds of data: a
  1170. Location, a mode, a target, and a frame. The frame and target may be
  1171. specified completely within the Fixup field, or by reference to a preceding
  1172. Thread field.
  1173. A Thread field specifies a default target or frame that subsequently may be
  1174. referred to. Eight threads are provided\(emfour for frame specification and
  1175. four for target specification. Once a thread has specified a target or frame,
  1176. any Fixup fields that follow (in the same or following FIXUPP records)
  1177. may refer to that target or frame until another Thread field with the same
  1178. type (target or frame) and thread number (0-3) appears (in the same or in
  1179. another FIXUPP record).
  1180. Thread
  1181. The Thread field has the following format:
  1182. -----------///-----
  1183. | | |
  1184. | TRD | Index |
  1185. | DAT | |
  1186. | | |
  1187. -----------///-----
  1188. | |
  1189. +conditional+
  1190. The TRD DAT (Thread Data) field is a byte with the following internal
  1191. structure:
  1192. ---------------------------------
  1193. | | | | | | | | |
  1194. | 0 | D | 0 | Method | THRED |
  1195. | | | | | | | | |
  1196. ---------------------------------
  1197. The D field is one bit and defines the type of thread being used. If D=0,
  1198. this bit defines a target thread, and if D=1, it defines a frame thread.
  1199. Method is a 3-bit field containing a number between 0 and 3 (if D=0) or a
  1200. number between 0 and 6 (if D=1).
  1201. If D=0, then Method = (0, 1, 2, 4, 5, 6)mod 4, where 0, 1, 2, 4, 5, 6 indi-
  1202. cate methods T0, T1, T2, T4, T5, and T6 of specifying a target. Thus,
  1203. Method indicates the kind of index or frame number required to specify
  1204. the target, without indicating whether the target is specified by a primary
  1205. or secondary method.
  1206. 33
  1207. _ _ | | _ _
  1208. _ _ | | _ _
  1209. _ ______________
  1210. If D=1, then Method = 0, 1, 2, 4, 5, corresponding to methods F0, F1, F2,
  1211. F4, F5 of specifying a frame. Here, Method indicates the kind (if any) of
  1212. index required to specify the frame.
  1213. The THRED field contains a number between 0 and 3, inclusive, and asso-
  1214. ciates a thread number to the frame or target defined by the Thread field.
  1215. The Index field contains a segment index, group index, or external index
  1216. depending on the specification in the Method field. If Method specifies F4
  1217. or F5, this field will not be present.
  1218. Fixup
  1219. The Fixup field has the following format:
  1220. -----------------------///---------///---------///-----
  1221. | | | | | |
  1222. | LOCAT | FIX | Frame | Target | Target |
  1223. | | DAT | Datum | Datum | Dis- |
  1224. | | | | | Placement |
  1225. | | | | | |
  1226. -----------------------///---------///---------///-----
  1227. | | | |
  1228. +conditional+conditional+conditional+
  1229. The LOCAT field is a byte pair with the following format:
  1230. -----------------------------------------------------------------
  1231. | | | | | | | | | | | | | | | | |
  1232. | 1 | M | 0 | LOC | D a t a R e c o r d O f f s e t |
  1233. | | | | | | | | | | | | | | | | |
  1234. -----------------------------------------------------------------
  1235. | | |
  1236. +------------lo byte------------+------------hi byte------------+
  1237. M is a 1-bit field that specifies the mode of the fixups: self-relative (if
  1238. M=0) or segment-relative (if M=1).
  1239. _ ________________________________________________________________
  1240. Note
  1241. Self-relative fixups may not be applied to LIDATA records.
  1242. _ ________________________________________________________________
  1243. LOC is a 3-bit field indicating that the byte(s) in the preceding data record
  1244. to be fixed up are a lobyte (if LOC=0), an offset (if LOC=1), a base (if
  1245. LOC=2), a pointer (if LOC=3), a hibyte (if LOC=4), or a "loader-
  1246. resolved" offset (if LOC=5). Any other values in LOC are invalid.
  1247. 34
  1248. _ _ | | _ _
  1249. _ _ | | _ _
  1250. Microsoft Relocatable Object Module Formats
  1251. _ __________________________________________________
  1252. The Data Record Offset field contains a number between 0 and 1023,
  1253. inclusive, that gives the relative position of the lowest order byte of Loca-
  1254. tion (the actual bytes being fixed up) within the preceding data record.
  1255. The Data Record Offset value is relative to the first byte in the data fields
  1256. in the data records.
  1257. _ ________________________________________________________________
  1258. Note
  1259. If the preceding data record is an LIDATA record, it is possible for the
  1260. Data Record Offset value to designate a location within a Repeat
  1261. Count field or a Block Count field of the Iterated Data Block field.
  1262. Such a reference is an error. The linker's action on such a malformed
  1263. record is undefined.
  1264. _ ________________________________________________________________
  1265. The FIX DAT field is a byte with the following format:
  1266. ---------------------------------
  1267. | | | | | | | | |
  1268. | F | Frame | T | P | TARGT |
  1269. | | | | | | | | |
  1270. ---------------------------------
  1271. F is a 1-bit subfield that specifies whether the frame for this Fixup is
  1272. specified by a thread (if F=1) or explicitly (if F=0).
  1273. The Frame field contains a number that is interpreted in one of two ways,
  1274. as indicated by the F bit. If F is zero, the Frame field contains a number
  1275. between 0 and 5, inclusive, corresponding to methods F0,...,F5 for specify-
  1276. ing a frame. If F=1, then the Frame field contains a thread number (0-3).
  1277. It specifies the frame most recently defined by a Thread field that defined a
  1278. frame thread with the same thread number. (Note that the Thread field
  1279. may appear in the same FIXUPP record, or in an earlier one.)
  1280. T is a 1-bit field that specifies whether the target specified for this fixup is
  1281. defined by reference to a thread (T=1), or is given explicitly in the Fixup
  1282. field (T=0).
  1283. P is a 1-bit field that indicates whether the Target is specified by a pri-
  1284. mary method (requires a target displacement, if P=0) or by a secondary
  1285. method (requires no target displacement, if P=1). Since a target thread
  1286. does not have a primary/secondary attribute, the P bit is the only field
  1287. that contains the target specification attribute.
  1288. TARGT is interpreted as a 2-bit field. When T=0, it provides a number
  1289. between 0 and 3, inclusive, corresponding to methods T0, T1, T2 or T4,
  1290. T5, T6, depending on the value of P (where P is interpreted as the high-
  1291. order bit of T0, T1, T2, T4, T5, or T6). When a thread specifies the
  1292. 35
  1293. _ _ | | _ _
  1294. _ _ | | _ _
  1295. _ ______________
  1296. target (if T=1), then the TARGET field specifies a thread number (0-3).
  1297. The Frame Datum field is the "referent" portion of a frame specification,
  1298. and is a segment index, group index, or external index. The Frame Datum
  1299. field is present only when the frame is not specified by a thread (if F=0) or
  1300. explicitly by methods F4, F5, or F6.
  1301. The Target Datum field is the "referent" portion of a target specification,
  1302. and is a segment index, group index, or external index. The Target Datum
  1303. field is present only when a thread does not specify the target (if T=0).
  1304. The Target Displacement field is the 2-byte displacement required by pri-
  1305. mary methods of specifying targets. This field is present if P=0.
  1306. _ ________________________________________________________________
  1307. Note
  1308. All these methods are described in Section 7.3, "Conceptual Frame-
  1309. work for Fixups."
  1310. _ ________________________________________________________________
  1311. 7.5.15 Module End Record (MODEND)
  1312. -----------------------------///-----------
  1313. | | | | | |
  1314. | REC | Record | MOD | START | CHK |
  1315. | TYP | Length | TYP | ADDRS | SUM |
  1316. | 8AH | | | | |
  1317. | | | | | |
  1318. -----------------------------///-----------
  1319. | |
  1320. +conditional+
  1321. The MODEND record serves two purposes. It denotes the end of a module
  1322. and indicates whether the module that just ended specifies an entry point
  1323. to begin execution. If it does not, the linker specifies the execution
  1324. address.
  1325. 36
  1326. _ _ | | _ _
  1327. _ _ | | _ _
  1328. Microsoft Relocatable Object Module Formats
  1329. _ __________________________________________________
  1330. MOD TYP
  1331. The MOD TYP field specifies the attributes of the module. The bit alloca-
  1332. tion and associated meanings are as follows:
  1333. ---------------------------------
  1334. | | | | | | | | |
  1335. | MATTR | 0 | 0 | 0 | 0 | 0 | 1 |
  1336. | | | | | | | | |
  1337. ---------------------------------
  1338. MATTR is a 2-bit field that specifies the following module attributes:
  1339. MATTR Module Attribute
  1340. _ _______________________________________________
  1341. 0 Non-main module with no START ADDRS
  1342. 1 Non-main module with START ADDRS
  1343. 2 Main module with no START ADDRS
  1344. 3 Main module with START ADDRS
  1345. The START ADDRS field (present only if MATTR is 1 or 3) has the fol-
  1346. lowing format:
  1347. -----------///---------///-----------------
  1348. | | | | |
  1349. | END | Frame | Target | Target |
  1350. | DAT | Datum | Datum | Dis- |
  1351. | | | | Placement |
  1352. | | | | |
  1353. -----------///---------///-----------------
  1354. | | | |
  1355. +conditional+conditional+conditional+
  1356. The starting address of a module has all the attributes of any other logical
  1357. reference found in a module. The mapping of a logical starting address to
  1358. a physical starting address is done in the same manner as mapping any
  1359. other logical address to a physical address, as specified in the discussion of
  1360. fixups and the FIXUPP record. The fields of the START ADDRS field
  1361. have the same semantics as the FIX DAT, Frame Datum, Target Datum,
  1362. and Target Displacement fields in the FIXUPP record. Only primary fixup
  1363. methods are allowed. Frame method F4 is not allowed.
  1364. 37
  1365. _ _ | | _ _
  1366. _ _ | | _ _
  1367. _ ______________
  1368. 7.5.16 Comment Record (COMENT)
  1369. -----------------------------------///-----------
  1370. | | | | | |
  1371. | REC | Record | Comment | | CHK |
  1372. | TYP | Length | Type | Comment | SUM |
  1373. | 88H | | | | |
  1374. | | | | | |
  1375. -----------------------------------///-----------
  1376. The COMENT record allows translators to include comments in object
  1377. text.
  1378. Comment Type
  1379. The Comment Type field indicates the type of comment that this record
  1380. carries, allowing you to structure comments for processes that selectively
  1381. act on comments.
  1382. The format of the Comment Type field is as follows:
  1383. --------------------------------------------------------
  1384. | N | N | | | | | | | Comment |
  1385. | P | L | 0 | 0 | 0 | 0 | 0 | 0 | Class |
  1386. --------------------------------------------------------
  1387. The NP (NOPURGE) bit, if set to 1, indicates that this comment cannot
  1388. be purged by object file utility programs that can delete Comment records.
  1389. The NL (NOLIST) bit, if set to 1, indicates that the text in the Comment
  1390. field should not appear in the listing file of object file utility programs that
  1391. can list object Comment records.
  1392. The Comment Class field is a byte defined as follows:
  1393. _ ________________________________________________________________
  1394. 0 Language Translator Comment (obsolete)
  1395. If the comment field contains one of the strings "MS
  1396. PASCAL" or "FORTRAN 77," then the comment
  1397. record enables the dsallocation switch on the Micro-
  1398. soft linker.
  1399. 156(9CH) DOS Version
  1400. The Comment field contains a 2-byte integer that
  1401. specifies the DOS level number.
  1402. 157(9DH) Memory Model
  1403. Indicates the memory model of the object module.
  1404. The Comment field contains a single byte with the
  1405. 38
  1406. _ _ | | _ _
  1407. _ _ | | _ _
  1408. Microsoft Relocatable Object Module Formats
  1409. _ __________________________________________________
  1410. values S, M, L, or H, for SMALL, MEDIUM, LARGE,
  1411. or HUGE, respectively. This Comment record is used
  1412. only by the Microsoft XENIX linker.
  1413. 158(9EH) Force Segment Ordering
  1414. Causes the linker to use a special segment ordering for
  1415. executable files. This comment record has the same
  1416. effect as giving the dosseg switch to Microsoft
  1417. language versions of the linker.
  1418. 159(9FH) Library Specifier
  1419. 129(81H) Library Specifier (obsolete)
  1420. Specifies a library to add to the Microsoft linker's
  1421. library search list. The Comment field contains the
  1422. name of the library. Note that unlike all other name
  1423. specifications, the library name is not prefixed with its
  1424. length but is determined by the record length. The
  1425. nodefaultlibrarysearch switch causes the linker to
  1426. ignore these comment records. The 159(9FH) class
  1427. record is ignored by XENIX versions of the Microsoft
  1428. linker.
  1429. 161(A1H) Microsoft Extensions
  1430. Indicates that the object module contains extensions
  1431. to the original Microsoft adaptation of the Intel Relo-
  1432. catable Object Module Format, such as the COMDEF
  1433. and LOCSYM records.
  1434. Comment
  1435. The Comment field provides the commentary information.
  1436. 7.6 Microsoft Type Representations
  1437. for Communal Variables
  1438. _ ________________________________________________________________
  1439. Note
  1440. Object modules not containing the COMENT record from the Micro-
  1441. soft Extensions class can represent communal variable definitions only
  1442. with the obsolete method described here. Also, Microsoft language
  1443. linkers earlier than version 3.05 can recognize this method only. The
  1444. newer method uses the Communal Variable Definitions (COMDEF)
  1445. record.
  1446. 39
  1447. _ _ | | _ _
  1448. _ _ | | _ _
  1449. _ ______________
  1450. _ ________________________________________________________________
  1451. A communal variable is defined in the object text by an EXTDEF record
  1452. and the TYPDEF record to which it refers.
  1453. The TYPDEF record of a communal variable has the following format:
  1454. -------------------------///-----------
  1455. | REC | Record | | Eight | CHK |
  1456. | TYP | Length | 0 | Leaf | SUM |
  1457. | 8EH | | | Descriptor | |
  1458. -------------------------///-----------
  1459. The Eight Leaf Descriptor field has the following format:
  1460. ---------///------
  1461. | E | Leaf |
  1462. | N | Descriptor |
  1463. ---------///------
  1464. The EN bitfield specifies whether the next eight leaves in the Leaf Descrip-
  1465. tor field are EASY (if EN = 0) or NICE (if EN = l). This byte is always
  1466. zero for TYPDEFs of communal variables.
  1467. The Leaf Descriptor field has one of the following two formats. The for-
  1468. mat for communal variables in the default data segment (NEAR variables)
  1469. is as follows:
  1470. ------------------///-----///-----
  1471. | NEAR | VAR | Length | VAR |
  1472. | 62H | TYP | In | SUBTYP |
  1473. | | | Bits | |
  1474. ------------------///------///----
  1475. | |
  1476. +--------+
  1477. (optional)
  1478. The VARTYP (Variable Type) field may be either SCALAR (7BH),
  1479. STRUCT (79H), or ARRAY (77H). The linker ignores the VAR SUBTYP
  1480. field (if one exists). The format for communal variables not in the default
  1481. data segment (FAR variables) is as follows:
  1482. -----------------///-------///----
  1483. | FAR | VAR | Number | Element |
  1484. | 61H | TYP | of | Type |
  1485. | | 77H | Elements | Index |
  1486. -----------------///-------///----
  1487. The VARTYP field must be ARRAY (77H). The Length in Bits field
  1488. specifies the Number of Elements, and the Element Type Index is an index
  1489. to a previously defined TYPDEF record whose format is that of a NEAR
  1490. 40
  1491. _ _ | | _ _
  1492. _ _ | | _ _
  1493. Microsoft Relocatable Object Module Formats
  1494. _ __________________________________________________
  1495. communal variable.
  1496. The format for the Length in Bits or Number of Elements fields is the
  1497. same as the format of the Communal Length field of the COMDEF record.
  1498. Link-Time Semantics:
  1499. All EXTDEF records referencing a TYPDEF record of one of the previ-
  1500. ously described formats are treated as communal variables. All others are
  1501. treated as externally defined symbols for which a matching PUBDEF
  1502. record is expected.
  1503. For more information, see "Link-Time Semantics" Section 7.5.8, "Commu-
  1504. nal Names Definition Record (COMDEF)."
  1505. 41
  1506. _ _ | | _ _
  1507. _ _ | | _ _
  1508. _ ______________
  1509. Chapter 7
  1510. Microsoft Relocatable
  1511. Object Module Formats
  1512. _ ________________________________________________________________
  1513. 7.1 Introduction 3
  1514. 7.1.1 Definition of Terms 4
  1515. 7.2 Module Identification and Attributes 7
  1516. 7.2.1 Segment Definition 7
  1517. 7.2.2 Addressing a Segment 7
  1518. 7.2.3 Symbol Definition 8
  1519. 7.2.4 Indices 8
  1520. 7.3 Conceptual Framework for Fixups 9
  1521. 7.3.1 Self-Relative Fixup 13
  1522. 7.3.2 Segment-Relative Fixup 13
  1523. 7.4 Record Sequence 14
  1524. 7.5 Introducing the Record Formats 15
  1525. 7.5.1 Sample Record Format (SAMREC) 15
  1526. 7.5.2 T-Module Header Record (THEADR) 17
  1527. 7.5.3 L-Module Header Record (LHEADR) 17
  1528. 7.5.4 List of Names Record (LNAMES) 18
  1529. 7.5.5 Segment Definition Record (SEGDEF) 18
  1530. 7.5.6 Group Definition Record (GRPDEF) 21
  1531. 7.5.7 Public Names Definition Record
  1532. (PUBDEF) 22
  1533. 7.5.8 Communal Names Definition Record
  1534. (COMDEF) 24
  1535. 7.5.9 Local Symbols Record (LOCSYM) 27
  1536. 7.5.10 External Names Definition Record
  1537. (EXTDEF) 28
  1538. 7.5.11 Line Numbers Record (LINNUM) 29
  1539. 1
  1540. _ _ | | _ _
  1541. _ _ | | _ _
  1542. _ ______________
  1543. 7.5.12 Logical Enumerated Data Record
  1544. (LEDATA) 30
  1545. 7.5.13 Logical Iterated Data Record (LIDATA) 31
  1546. 7.5.14 Fixupp Record (FIXUPP) 32
  1547. 7.5.15 Module End Record (MODEND) 36
  1548. 7.5.16 Comment Record (COMENT) 38
  1549. 7.6 Microsoft Type Representations
  1550. for Communal Variables 39
  1551. 2
  1552. _ _ | | _ _
  1553. _ _ | | _ _
  1554. _ ______________
  1555. 41
  1556. _ _ | | _ _