omfbase.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. {
  2. Copyright (c) 2015 by Nikolay Nikolov
  3. Contains Relocatable Object Module Format (OMF) definitions
  4. This is the object format used on the i8086-msdos platform.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit omfbase;
  19. {$i fpcdefs.inc}
  20. interface
  21. {$H+}
  22. uses
  23. cclasses,
  24. owbase;
  25. const
  26. { OMF record types }
  27. RT_THEADR = $80; { Translator Header Record }
  28. RT_LHEADR = $82; { Library Module Header Record }
  29. RT_COMENT = $88; { Comment Record }
  30. RT_MODEND = $8A; { Module End Record }
  31. RT_MODEND32 = $8B;
  32. RT_EXTDEF = $8C; { External Names Definition Record }
  33. RT_PUBDEF = $90; { Public Names Definition Record }
  34. RT_PUBDEF32 = $91;
  35. RT_LINNUM = $94; { Line Numbers Record }
  36. RT_LINNUM32 = $95;
  37. RT_LNAMES = $96; { List of Names Record }
  38. RT_SEGDEF = $98; { Segment Definition Record }
  39. RT_SEGDEF32 = $99;
  40. RT_GRPDEF = $9A; { Group Definition Record }
  41. RT_FIXUPP = $9C; { Fixup Record }
  42. RT_FIXUPP32 = $9D;
  43. RT_LEDATA = $A0; { Logical Enumerated Data Record }
  44. RT_LEDATA32 = $A1;
  45. RT_LIDATA = $A2; { Logical Iterated Data Record }
  46. RT_LIDATA32 = $A3;
  47. RT_COMDEF = $B0; { Communal Names Definition Record }
  48. RT_BAKPAT = $B2; { Backpatch Record }
  49. RT_BAKPAT32 = $B3;
  50. RT_LEXTDEF = $B4; { Local External Names Definition Record }
  51. RT_LEXTDEF32 = $B5;
  52. RT_LPUBDEF = $B6; { Local Public Names Definition Record }
  53. RT_LPUBDEF32 = $B7;
  54. RT_LCOMDEF = $B8; { Local Communal Names Definition Record }
  55. RT_CEXTDEF = $BC; { COMDAT External Names Definition Record }
  56. RT_COMDAT = $C2; { Initialized Communal Data Record }
  57. RT_COMDAT32 = $C3;
  58. RT_LINSYM = $C4; { Symbol Line Numbers Record }
  59. RT_LINSYM32 = $C5;
  60. RT_ALIAS = $C6; { Alias Definition Record }
  61. RT_NBKPAT = $C8; { Named Backpatch Record }
  62. RT_NBKPAT32 = $C9;
  63. RT_LLNAMES = $CA; { Local Logical Names Definition Record }
  64. RT_VERNUM = $CC; { OMF Version Number Record }
  65. RT_VENDEXT = $CE; { Vendor-specific OMF Extension Record }
  66. { OMF comment class }
  67. CC_Translator = $00; { language translator (compiler or assembler) name }
  68. CC_IntelCopyright = $01;
  69. CC_IntelReservedRangeStart = $02;
  70. CC_IntelReservedRangeEnd = $9B;
  71. CC_LibrarySpecifierObsolete = $81;
  72. CC_MsDosVersionObsolete = $9C;
  73. CC_MemoryModel = $9D;
  74. CC_DOSSEG = $9E;
  75. CC_DefaultLibrarySearchName = $9F;
  76. CC_OmfExtension = $A0;
  77. CC_NewOmfExtension = $A1;
  78. CC_LinkPassSeparator = $A2;
  79. CC_LIBMOD = $A3;
  80. CC_EXESTR = $A4;
  81. CC_INCERR = $A6;
  82. CC_NOPAD = $A7;
  83. CC_WKEXT = $A8;
  84. CC_LZEXT = $A9;
  85. CC_Comment = $DA;
  86. CC_Compiler = $DB;
  87. CC_Date = $DC;
  88. CC_Timestamp = $DD;
  89. CC_User = $DF;
  90. CC_DependencyFileBorland = $E9;
  91. CC_CommandLineMicrosoft = $FF;
  92. type
  93. TOmfSegmentAlignment = (
  94. saAbsolute = 0,
  95. saRelocatableByteAligned = 1,
  96. saRelocatableWordAligned = 2,
  97. saRelocatableParaAligned = 3,
  98. saRelocatablePageAligned = 4, { 32-bit linkers extension }
  99. saRelocatableDWordAligned = 5, { 32-bit linkers extension }
  100. saNotSupported = 6,
  101. saNotDefined = 7);
  102. TOmfSegmentCombination = (
  103. scPrivate = 0,
  104. scReserved1 = 1,
  105. scPublic = 2,
  106. scReserved3 = 3,
  107. scPublic4 = 4, { same as scPublic }
  108. scStack = 5,
  109. scCommon = 6,
  110. scPublic7 = 7); { same as scPublic }
  111. TOmfSegmentUse = (suUse16, suUse32);
  112. { TOmfOrderedNameCollection }
  113. TOmfOrderedNameCollection = class
  114. private
  115. FStringList: array of string;
  116. function GetCount: Integer;
  117. function GetString(Index: Integer): string;
  118. procedure SetString(Index: Integer; AValue: string);
  119. public
  120. function Add(const S: string): Integer;
  121. procedure Clear;
  122. property Strings [Index: Integer]: string read GetString write SetString; default;
  123. property Count: Integer read GetCount;
  124. end;
  125. { TOmfRawRecord }
  126. TOmfRawRecord = class
  127. private
  128. function GetChecksumByte: Byte;
  129. function GetRecordLength: Word;
  130. function GetRecordType: Byte;
  131. procedure SetChecksumByte(AValue: Byte);
  132. procedure SetRecordLength(AValue: Word);
  133. procedure SetRecordType(AValue: Byte);
  134. public
  135. RawData: array [-3..65535] of Byte;
  136. property RecordType: Byte read GetRecordType write SetRecordType;
  137. property RecordLength: Word read GetRecordLength write SetRecordLength;
  138. function ReadStringAt(Offset: Integer; out s: string): Integer;
  139. function WriteStringAt(Offset: Integer; s: string): Integer;
  140. function ReadIndexedRef(Offset: Integer; out IndexedRef: Integer): Integer;
  141. function WriteIndexedRef(Offset: Integer; IndexedRef: Integer): Integer;
  142. procedure CalculateChecksumByte;
  143. function VerifyChecksumByte: boolean;
  144. property ChecksumByte: Byte read GetChecksumByte write SetChecksumByte;
  145. procedure ReadFrom(aReader: TObjectReader);
  146. procedure WriteTo(aWriter: TObjectWriter);
  147. end;
  148. { TOmfParsedRecord }
  149. TOmfParsedRecord = class
  150. public
  151. procedure DecodeFrom(RawRecord: TOmfRawRecord);virtual;abstract;
  152. procedure EncodeTo(RawRecord: TOmfRawRecord);virtual;abstract;
  153. end;
  154. { TOmfRecord_THEADR }
  155. TOmfRecord_THEADR = class(TOmfParsedRecord)
  156. private
  157. FModuleName: string;
  158. public
  159. procedure DecodeFrom(RawRecord: TOmfRawRecord);override;
  160. procedure EncodeTo(RawRecord: TOmfRawRecord);override;
  161. property ModuleName: string read FModuleName write FModuleName;
  162. end;
  163. { TOmfRecord_COMENT }
  164. TOmfRecord_COMENT = class(TOmfParsedRecord)
  165. private
  166. FCommentType: Byte;
  167. FCommentClass: Byte;
  168. FCommentString: string;
  169. function GetNoList: Boolean;
  170. function GetNoPurge: Boolean;
  171. procedure SetNoList(AValue: Boolean);
  172. procedure SetNoPurge(AValue: Boolean);
  173. public
  174. procedure DecodeFrom(RawRecord: TOmfRawRecord);override;
  175. procedure EncodeTo(RawRecord: TOmfRawRecord);override;
  176. property CommentType: Byte read FCommentType write FCommentType;
  177. property CommentClass: Byte read FCommentClass write FCommentClass;
  178. property CommentString: string read FCommentString write FCommentString;
  179. property NoPurge: Boolean read GetNoPurge write SetNoPurge;
  180. property NoList: Boolean read GetNoList write SetNoList;
  181. end;
  182. { TOmfRecord_LNAMES }
  183. TOmfRecord_LNAMES = class(TOmfParsedRecord)
  184. private
  185. FNames: TOmfOrderedNameCollection;
  186. FNextIndex: Integer;
  187. public
  188. constructor Create;
  189. procedure DecodeFrom(RawRecord: TOmfRawRecord);override;
  190. procedure EncodeTo(RawRecord: TOmfRawRecord);override;
  191. property Names: TOmfOrderedNameCollection read FNames write FNames;
  192. property NextIndex: Integer read FNextIndex write FNextIndex;
  193. end;
  194. { TOmfRecord_SEGDEF }
  195. TOmfRecord_SEGDEF = class(TOmfParsedRecord)
  196. FAlignment: TOmfSegmentAlignment;
  197. FCombination: TOmfSegmentCombination;
  198. FUse: TOmfSegmentUse;
  199. FFrameNumber: Word;
  200. FOffset: Byte;
  201. FIs32Bit: Boolean;
  202. FSegmentLength: Int64; { int64, because it can be 2**32 }
  203. FSegmentNameIndex: Integer;
  204. FClassNameIndex: Integer;
  205. FOverlayNameIndex: Integer;
  206. public
  207. procedure DecodeFrom(RawRecord: TOmfRawRecord);override;
  208. procedure EncodeTo(RawRecord: TOmfRawRecord);override;
  209. property Alignment: TOmfSegmentAlignment read FAlignment write FAlignment;
  210. property Combination: TOmfSegmentCombination read FCombination write FCombination;
  211. property Use: TOmfSegmentUse read FUse write FUse;
  212. property FrameNumber: Word read FFrameNumber write FFrameNumber;
  213. property Offset: Byte read FOffset write FOffset;
  214. property Is32Bit: Boolean read FIs32Bit write FIs32Bit;
  215. property SegmentLength: Int64 read FSegmentLength write FSegmentLength;
  216. property SegmentNameIndex: Integer read FSegmentNameIndex write FSegmentNameIndex;
  217. property ClassNameIndex: Integer read FClassNameIndex write FClassNameIndex;
  218. property OverlayNameIndex: Integer read FOverlayNameIndex write FOverlayNameIndex;
  219. end;
  220. implementation
  221. uses
  222. verbose;
  223. { TOmfOrderedNameCollection }
  224. function TOmfOrderedNameCollection.GetString(Index: Integer): string;
  225. begin
  226. Result:=FStringList[Index-1];
  227. end;
  228. function TOmfOrderedNameCollection.GetCount: Integer;
  229. begin
  230. Result:=Length(FStringList);
  231. end;
  232. procedure TOmfOrderedNameCollection.SetString(Index: Integer; AValue: string);
  233. begin
  234. FStringList[Index-1]:=AValue;
  235. end;
  236. function TOmfOrderedNameCollection.Add(const S: string): Integer;
  237. begin
  238. Result:=Length(FStringList)+1;
  239. SetLength(FStringList,Result);
  240. FStringList[Result-1]:=S;
  241. end;
  242. procedure TOmfOrderedNameCollection.Clear;
  243. begin
  244. SetLength(FStringList,0);
  245. end;
  246. { TOmfRawRecord }
  247. function TOmfRawRecord.GetRecordType: Byte;
  248. begin
  249. Result:=RawData[-3];
  250. end;
  251. procedure TOmfRawRecord.SetRecordType(AValue: Byte);
  252. begin
  253. RawData[-3]:=AValue;
  254. end;
  255. function TOmfRawRecord.GetRecordLength: Word;
  256. begin
  257. Result:=RawData[-2] or (RawData[-1] shl 8);
  258. end;
  259. procedure TOmfRawRecord.SetRecordLength(AValue: Word);
  260. begin
  261. RawData[-2]:=Byte(AValue);
  262. RawData[-1]:=Byte(AValue shr 8);
  263. end;
  264. function TOmfRawRecord.ReadStringAt(Offset: Integer; out s: string): Integer;
  265. var
  266. len: Byte;
  267. begin
  268. len:=RawData[Offset];
  269. Result:=Offset+len+1;
  270. if result>RecordLength then
  271. internalerror(2015033103);
  272. SetLength(s, len);
  273. UniqueString(s);
  274. Move(RawData[Offset+1],s[1],len);
  275. end;
  276. function TOmfRawRecord.WriteStringAt(Offset: Integer; s: string): Integer;
  277. begin
  278. if Length(s)>255 then
  279. internalerror(2015033101);
  280. result:=Offset+Length(s)+1;
  281. if result>High(RawData) then
  282. internalerror(2015033102);
  283. RawData[Offset]:=Length(s);
  284. Move(s[1], RawData[Offset+1], Length(s));
  285. end;
  286. function TOmfRawRecord.ReadIndexedRef(Offset: Integer; out IndexedRef: Integer): Integer;
  287. begin
  288. Result:=Offset+1;
  289. if result>RecordLength then
  290. internalerror(2015033103);
  291. IndexedRef:=RawData[Offset];
  292. if IndexedRef<=$7f then
  293. exit;
  294. Result:=Offset+2;
  295. if result>RecordLength then
  296. internalerror(2015033103);
  297. IndexedRef:=((IndexedRef and $7f) shl 8)+RawData[Offset+1];
  298. end;
  299. function TOmfRawRecord.WriteIndexedRef(Offset: Integer; IndexedRef: Integer): Integer;
  300. begin
  301. if (IndexedRef<0) or (IndexedRef>$7FFF) then
  302. internalerror(2015040303);
  303. if IndexedRef<=$7f then
  304. begin
  305. Result:=Offset+1;
  306. if Result>High(RawData) then
  307. internalerror(2015033102);
  308. RawData[Offset]:=IndexedRef;
  309. end
  310. else
  311. begin
  312. Result:=Offset+2;
  313. if Result>High(RawData) then
  314. internalerror(2015033102);
  315. RawData[Offset]:=$80+(IndexedRef shr 8);
  316. RawData[Offset+1]:=Byte(IndexedRef);
  317. end;
  318. end;
  319. function TOmfRawRecord.GetChecksumByte: Byte;
  320. begin
  321. if RecordLength>0 then
  322. Result:=RawData[RecordLength-1]
  323. else
  324. Result:=0;
  325. end;
  326. procedure TOmfRawRecord.SetChecksumByte(AValue: Byte);
  327. begin
  328. if RecordLength>0 then
  329. RawData[RecordLength-1]:=AValue;
  330. end;
  331. procedure TOmfRawRecord.CalculateChecksumByte;
  332. var
  333. I: Integer;
  334. b: Byte;
  335. begin
  336. b:=0;
  337. for I:=-3 to RecordLength-2 do
  338. b:=byte(b+RawData[I]);
  339. SetChecksumByte($100-b);
  340. end;
  341. function TOmfRawRecord.VerifyChecksumByte: boolean;
  342. var
  343. I: Integer;
  344. b: Byte;
  345. begin
  346. { according to the OMF spec, some tools always write a 0 rather than
  347. computing the checksum, so it should also be accepted as correct }
  348. if ChecksumByte=0 then
  349. exit(true);
  350. b:=0;
  351. for I:=-3 to RecordLength-1 do
  352. b:=byte(b+RawData[I]);
  353. Result:=(b=0);
  354. end;
  355. procedure TOmfRawRecord.ReadFrom(aReader: TObjectReader);
  356. begin
  357. aReader.read(RawData, 3);
  358. aReader.read(RawData[0], RecordLength);
  359. end;
  360. procedure TOmfRawRecord.WriteTo(aWriter: TObjectWriter);
  361. begin
  362. aWriter.write(RawData, RecordLength+3);
  363. end;
  364. { TOmfRecord_THEADR }
  365. procedure TOmfRecord_THEADR.DecodeFrom(RawRecord: TOmfRawRecord);
  366. begin
  367. RawRecord.ReadStringAt(0,FModuleName);
  368. end;
  369. procedure TOmfRecord_THEADR.EncodeTo(RawRecord: TOmfRawRecord);
  370. var
  371. NextOfs: Integer;
  372. begin
  373. RawRecord.RecordType:=RT_THEADR;
  374. NextOfs:=RawRecord.WriteStringAt(0,ModuleName);
  375. RawRecord.RecordLength:=NextOfs+1;
  376. RawRecord.CalculateChecksumByte;
  377. end;
  378. { TOmfRecord_COMENT }
  379. function TOmfRecord_COMENT.GetNoList: Boolean;
  380. begin
  381. Result:=(CommentType and $40)<>0;
  382. end;
  383. function TOmfRecord_COMENT.GetNoPurge: Boolean;
  384. begin
  385. Result:=(CommentType and $80)<>0;
  386. end;
  387. procedure TOmfRecord_COMENT.SetNoList(AValue: Boolean);
  388. begin
  389. if AValue then
  390. CommentType:=CommentType or $40
  391. else
  392. CommentType:=CommentType and $BF;
  393. end;
  394. procedure TOmfRecord_COMENT.SetNoPurge(AValue: Boolean);
  395. begin
  396. if AValue then
  397. CommentType:=CommentType or $80
  398. else
  399. CommentType:=CommentType and $7F;
  400. end;
  401. procedure TOmfRecord_COMENT.DecodeFrom(RawRecord: TOmfRawRecord);
  402. begin
  403. if RawRecord.RecordLength<3 then
  404. internalerror(2015033104);
  405. CommentType:=RawRecord.RawData[0];
  406. CommentClass:=RawRecord.RawData[1];
  407. SetLength(FCommentString,RawRecord.RecordLength-3);
  408. UniqueString(FCommentString);
  409. Move(RawRecord.RawData[2],FCommentString[1],Length(FCommentString));
  410. end;
  411. procedure TOmfRecord_COMENT.EncodeTo(RawRecord: TOmfRawRecord);
  412. begin
  413. RawRecord.RecordType:=RT_COMENT;
  414. if (Length(FCommentString)+3)>High(RawRecord.RawData) then
  415. internalerror(2015033105);
  416. RawRecord.RecordLength:=Length(FCommentString)+3;
  417. RawRecord.RawData[0]:=CommentType;
  418. RawRecord.RawData[1]:=CommentClass;
  419. Move(FCommentString[1],RawRecord.RawData[2],Length(FCommentString));
  420. RawRecord.CalculateChecksumByte;
  421. end;
  422. { TOmfRecord_LNAMES }
  423. constructor TOmfRecord_LNAMES.Create;
  424. begin
  425. FNextIndex:=1;
  426. end;
  427. procedure TOmfRecord_LNAMES.DecodeFrom(RawRecord: TOmfRawRecord);
  428. begin
  429. {TODO: implement}
  430. internalerror(2015040101);
  431. end;
  432. procedure TOmfRecord_LNAMES.EncodeTo(RawRecord: TOmfRawRecord);
  433. const
  434. RecordLengthLimit = 1024;
  435. var
  436. Len,LastIncludedIndex,NextOfs,I: Integer;
  437. begin
  438. RawRecord.RecordType:=RT_LNAMES;
  439. { find out how many strings can we include until we reach the length limit }
  440. Len:=1;
  441. LastIncludedIndex:=NextIndex-1;
  442. repeat
  443. Inc(LastIncludedIndex);
  444. Inc(Len,Length(Names[LastIncludedIndex])+1);
  445. until (LastIncludedIndex>=Names.Count) or ((Len+Length(Names[LastIncludedIndex+1])+1)>=RecordLengthLimit);
  446. { write the strings... }
  447. NextOfs:=0;
  448. for I:=NextIndex to LastIncludedIndex do
  449. NextOfs:=RawRecord.WriteStringAt(NextOfs,Names[I]);
  450. RawRecord.RecordLength:=Len;
  451. RawRecord.CalculateChecksumByte;
  452. { update NextIndex }
  453. NextIndex:=LastIncludedIndex+1;
  454. end;
  455. { TOmfRecord_SEGDEF }
  456. procedure TOmfRecord_SEGDEF.DecodeFrom(RawRecord: TOmfRawRecord);
  457. var
  458. B: Byte;
  459. Big: Boolean;
  460. NextOfs: Integer;
  461. MinLen: Integer;
  462. begin
  463. if not (RawRecord.RecordType in [RT_SEGDEF,RT_SEGDEF32]) then
  464. internalerror(2015040301);
  465. Is32Bit:=RawRecord.RecordType=RT_SEGDEF32;
  466. MinLen:=7; { b(1)+seglength(2..4)+segnameindex(1..2)+classnameindex(1..2)+overlaynameindex(1..2)+checksum }
  467. if Is32Bit then
  468. inc(MinLen,2);
  469. if RawRecord.RecordLength<MinLen then
  470. internalerror(2015040305);
  471. B:=RawRecord.RawData[0];
  472. Alignment:=TOmfSegmentAlignment(B shr 5);
  473. Combination:=TOmfSegmentCombination((B shr 2) and 7);
  474. Big:=(B and 2)<>0;
  475. Use:=TOmfSegmentUse(B and 1);
  476. NextOfs:=1;
  477. if Alignment=saAbsolute then
  478. begin
  479. inc(MinLen,3);
  480. if RawRecord.RecordLength<MinLen then
  481. internalerror(2015040305);
  482. FrameNumber:=RawRecord.RawData[1]+(RawRecord.RawData[2] shl 8);
  483. Offset:=RawRecord.RawData[3];
  484. NextOfs:=4;
  485. end
  486. else
  487. begin
  488. FrameNumber:=0;
  489. Offset:=0;
  490. end;
  491. if Is32Bit then
  492. begin
  493. SegmentLength:=RawRecord.RawData[NextOfs]+
  494. (RawRecord.RawData[NextOfs+1] shl 8)+
  495. (RawRecord.RawData[NextOfs+2] shl 16)+
  496. (RawRecord.RawData[NextOfs+3] shl 24);
  497. if Big then
  498. if SegmentLength=0 then
  499. SegmentLength:=4294967296
  500. else
  501. internalerror(2015040306);
  502. Inc(NextOfs,4);
  503. end
  504. else
  505. begin
  506. SegmentLength:=RawRecord.RawData[NextOfs]+(RawRecord.RawData[NextOfs+1] shl 8);
  507. if Big then
  508. if SegmentLength=0 then
  509. SegmentLength:=65536
  510. else
  511. internalerror(2015040306);
  512. Inc(NextOfs,2);
  513. end;
  514. NextOfs:=RawRecord.ReadIndexedRef(NextOfs,FSegmentNameIndex);
  515. NextOfs:=RawRecord.ReadIndexedRef(NextOfs,FClassNameIndex);
  516. NextOfs:=RawRecord.ReadIndexedRef(NextOfs,FOverlayNameIndex);
  517. end;
  518. procedure TOmfRecord_SEGDEF.EncodeTo(RawRecord: TOmfRawRecord);
  519. var
  520. Big: Boolean;
  521. NextOfs: Integer;
  522. begin
  523. if Is32Bit then
  524. begin
  525. RawRecord.RecordType:=RT_SEGDEF32;
  526. if SegmentLength>4294967296 then
  527. internalerror(2015040302);
  528. Big:=SegmentLength=4294967296;
  529. end
  530. else
  531. begin
  532. RawRecord.RecordType:=RT_SEGDEF;
  533. if SegmentLength>65536 then
  534. internalerror(2015040302);
  535. Big:=SegmentLength=65536;
  536. end;
  537. RawRecord.RawData[0]:=(Ord(Alignment) shl 5) or (Ord(Combination) shl 2) or (Ord(Big) shl 1) or Ord(Use);
  538. NextOfs:=1;
  539. if Alignment=saAbsolute then
  540. begin
  541. RawRecord.RawData[1]:=Byte(FrameNumber);
  542. RawRecord.RawData[2]:=Byte(FrameNumber shr 8);
  543. RawRecord.RawData[3]:=Offset;
  544. NextOfs:=4;
  545. end;
  546. if Is32Bit then
  547. begin
  548. RawRecord.RawData[NextOfs]:=Byte(SegmentLength);
  549. RawRecord.RawData[NextOfs+1]:=Byte(SegmentLength shr 8);
  550. RawRecord.RawData[NextOfs+2]:=Byte(SegmentLength shr 16);
  551. RawRecord.RawData[NextOfs+3]:=Byte(SegmentLength shr 24);
  552. Inc(NextOfs,4);
  553. end
  554. else
  555. begin
  556. RawRecord.RawData[NextOfs]:=Byte(SegmentLength);
  557. RawRecord.RawData[NextOfs+1]:=Byte(SegmentLength shr 8);
  558. Inc(NextOfs,2);
  559. end;
  560. NextOfs:=RawRecord.WriteIndexedRef(NextOfs,SegmentNameIndex);
  561. NextOfs:=RawRecord.WriteIndexedRef(NextOfs,ClassNameIndex);
  562. NextOfs:=RawRecord.WriteIndexedRef(NextOfs,OverlayNameIndex);
  563. RawRecord.RecordLength:=NextOfs+1;
  564. RawRecord.CalculateChecksumByte;
  565. end;
  566. end.