RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
omf.h
1#ifndef OMF_H
2#define OMF_H
3
4#include <variant>
5#include "../common.h"
6#include "../dumper/dumper.h"
7#include "../linker/format.h"
8#include "../linker/reader.h"
9#include "../linker/writer.h"
10
11/* TODO: unimplemented */
12
13/* Intel Object Module format (input only) */
14
15namespace OMF
16{
19 {
20 public:
21 Linker::Writer * wr;
22 uint8_t checksum = 0;
23
25 : wr(&wr)
26 {
27 }
28
29 void WriteWord(size_t bytes, uint64_t value)
30 {
31 wr->WriteWord(bytes, value);
32 for(size_t offset = 0; offset < bytes; offset++, value >>= 8)
33 {
34 checksum -= value;
35 }
36 }
37
38 size_t WriteData(const std::vector<uint8_t>& data)
39 {
40 size_t bytes = wr->WriteData(data);
41 for(size_t offset = 0; offset < bytes; offset++)
42 {
43 checksum -= data[offset];
44 }
45 return bytes;
46 }
47
48 size_t WriteData(std::string text)
49 {
50 wr->WriteData(text);
51 for(size_t offset = 0; offset < text.size(); offset++)
52 {
53 checksum -= text[offset];
54 }
55 return text.size();
56 }
57
58 void Skip(offset_t count)
59 {
60 wr->Skip(count);
61 }
62 };
63
67 class OMFFormat : public virtual Linker::Format
68 {
69 public:
70 virtual ~OMFFormat() = default;
71
73 static std::string ReadString(Linker::Reader& rd, size_t max_bytes = size_t(-1));
74
76 static void WriteString(ChecksumWriter& wr, std::string text);
77
84 class Record
85 {
86 public:
88 offset_t record_offset;
90 uint16_t record_length;
92 uint8_t record_type;
93
94 Record(uint8_t record_type = 0)
96 {
97 }
98
99 virtual ~Record() = default;
100
102 virtual void ReadRecordContents(OMFFormat * omf, Linker::Reader& rd) = 0;
103
105 virtual uint16_t GetRecordSize(OMFFormat * omf) const = 0;
106
108 virtual void WriteRecordContents(OMFFormat * omf, ChecksumWriter& wr) const = 0;
109
111 virtual void WriteRecord(OMFFormat * omf, Linker::Writer& wr) const;
112 };
113
115 class UnknownRecord : public Record
116 {
117 public:
119 std::vector<uint8_t> data;
120
121 UnknownRecord(uint8_t record_type = 0)
123 {
124 }
125
126 void ReadRecordContents(OMFFormat * omf, Linker::Reader& rd) override;
127 uint16_t GetRecordSize(OMFFormat * omf) const override;
128 void WriteRecordContents(OMFFormat * omf, ChecksumWriter& wr) const override;
129 };
130
132 std::vector<std::shared_ptr<Record>> records;
133 };
134
138 class OMF86Format : public virtual OMFFormat, public virtual Linker::InputFormat
139 {
140 public:
141 class Module;
144
145 /* * * General members * * */
146
161
164
166 static constexpr unsigned int FlagIntel = 0x10;
168 static constexpr unsigned int FlagPharLap = 0x20;
170 static constexpr unsigned int FlagTIS = 0x30;
171
173 typedef uint16_t index_t;
174
176 static index_t ReadIndex(Linker::Reader& rd);
177
179 static void WriteIndex(ChecksumWriter& wr, index_t index);
180
182 static size_t IndexSize(index_t index);
183
185 enum
186 {
201 };
202
204 typedef uint16_t FrameNumber;
205
207 struct UsesSource { };
208
210 struct UsesTarget { };
211
213 struct UsesAbsolute { };
214
217 {
218 public:
219 index_t index;
220 std::string text;
221
222 NameIndex(index_t index = 0)
223 : index(index)
224 {
225 }
226
227 void CalculateValues(OMF86Format * omf, Module * mod);
228 void ResolveReferences(OMF86Format * omf, Module * mod);
229 };
230
233 {
234 public:
235 index_t index;
236 std::shared_ptr<SegmentDefinitionRecord> record;
237
238 SegmentIndex(index_t index = 0)
239 : index(index)
240 {
241 }
242
243 void CalculateValues(OMF86Format * omf, Module * mod);
244 void ResolveReferences(OMF86Format * omf, Module * mod);
245 };
246
249 {
250 public:
251 index_t index;
252 std::shared_ptr<GroupDefinitionRecord> record;
253
254 GroupIndex(index_t index = 0)
255 : index(index)
256 {
257 }
258
259 void CalculateValues(OMF86Format * omf, Module * mod);
260 void ResolveReferences(OMF86Format * omf, Module * mod);
261 };
262
266
269 {
270 public:
271 index_t index;
272 std::shared_ptr<TypeDefinitionRecord> record;
273
274 TypeIndex(index_t index = 0)
275 : index(index)
276 {
277 }
278
279 void CalculateValues(OMF86Format * omf, Module * mod);
280 void ResolveReferences(OMF86Format * omf, Module * mod);
281 };
282
285 {
286 public:
287 index_t index;
288 std::shared_ptr<BlockDefinitionRecord> record;
289
290 BlockIndex(index_t index = 0)
291 : index(index)
292 {
293 }
294
295 void CalculateValues(OMF86Format * omf, Module * mod);
296 void ResolveReferences(OMF86Format * omf, Module * mod);
297 };
298
301 {
302 public:
303 index_t index;
304 std::shared_ptr<OverlayDefinitionRecord> record;
305
306 OverlayIndex(index_t index = 0)
307 : index(index)
308 {
309 }
310
311 void CalculateValues(OMF86Format * omf, Module * mod);
312 void ResolveReferences(OMF86Format * omf, Module * mod);
313 };
314
317 {
318 public:
321 {
324
327
329 FarCommon = 0x61,
330
333 };
334
336 bool local = false;
338 bool name_is_index = false;
341 TypeIndex type;
342 common_type_t common_type = External;
343
344 union
345 {
346 uint8_t segment_index;
347 struct
348 {
349 uint32_t length;
350 } near;
351 struct
352 {
353 uint32_t number;
354 uint32_t element_size;
355 } far;
356 } value;
357
359 {
360 value.far.number = value.far.element_size = 0;
361 }
362
364 static uint32_t ReadLength(OMF86Format * omf, Linker::Reader& rd);
366 static uint32_t GetLengthSize(OMF86Format * omf, uint32_t length);
368 static void WriteLength(OMF86Format * omf, ChecksumWriter& wr, uint32_t length);
369
371 static ExternalName ReadExternalName(OMF86Format * omf, Linker::Reader& rd, bool local);
373 static ExternalName ReadCommonName(OMF86Format * omf, Linker::Reader& rd, bool local);
375 static ExternalName ReadComdatExternalName(OMF86Format * omf, Linker::Reader& rd);
376
378 uint16_t GetExternalNameSize(OMF86Format * omf) const;
380 void WriteExternalName(OMF86Format * omf, ChecksumWriter& wr) const;
381
382 void CalculateValues(OMF86Format * omf, Module * mod);
383 void ResolveReferences(OMF86Format * omf, Module * mod);
384 };
385
388 {
389 public:
390 index_t index;
391 ExternalName name;
392
393 ExternalIndex(index_t index = 0)
394 : index(index)
395 {
396 }
397
398 void CalculateValues(OMF86Format * omf, Module * mod);
399 void ResolveReferences(OMF86Format * omf, Module * mod);
400 };
401
404 {
405 public:
407 struct Location
408 {
409 GroupIndex group;
410 SegmentIndex segment;
411 };
412
414 std::variant<Location, FrameNumber> location;
415
416 void Read(OMF86Format * omf, Linker::Reader& rd);
417 uint16_t GetSize(OMF86Format * omf) const;
418 void Write(OMF86Format * omf, ChecksumWriter& wr) const;
419
420 void CalculateValues(OMF86Format * omf, Module * mod);
421 void ResolveReferences(OMF86Format * omf, Module * mod);
422 };
423
426 {
427 public:
429 bool local;
431 std::string name;
433 uint32_t offset;
436
437 static SymbolDefinition ReadSymbol(OMF86Format * omf, Linker::Reader& rd, bool local, bool is32bit);
438 uint16_t GetSymbolSize(OMF86Format * omf, bool is32bit) const;
439 void WriteSymbol(OMF86Format * omf, ChecksumWriter& wr, bool is32bit) const;
440
441 void CalculateValues(OMF86Format * omf, Module * mod);
442 void ResolveReferences(OMF86Format * omf, Module * mod);
443 };
444
447 {
448 public:
450 uint16_t number;
452 uint32_t offset;
453
454 static LineNumber ReadLineNumber(OMF86Format * omf, Linker::Reader& rd, bool is32bit);
455 void WriteLineNumber(OMF86Format * omf, ChecksumWriter& wr, bool is32bit) const;
456 };
457
466 {
467 public:
469 uint16_t repeat_count;
470
472 typedef std::vector<std::shared_ptr<DataBlock>> Blocks;
474 typedef std::vector<uint8_t> Data;
475
477 std::variant<Data, Blocks> content;
478
480 static std::shared_ptr<DataBlock> ReadEnumeratedDataBlock(OMF86Format * omf, Linker::Reader& rd, uint16_t data_length);
482 uint16_t GetEnumeratedDataBlockSize(OMF86Format * omf) const;
485
487 static std::shared_ptr<DataBlock> ReadIteratedDataBlock(OMF86Format * omf, Linker::Reader& rd, bool is32bit);
489 uint16_t GetIteratedDataBlockSize(OMF86Format * omf, bool is32bit) const;
491 void WriteIteratedDataBlock(OMF86Format * omf, ChecksumWriter& wr, bool is32bit) const;
492 };
493
496 {
497 public:
499 typedef unsigned ThreadNumber;
500
502 std::variant<ThreadNumber, SegmentIndex, GroupIndex, ExternalIndex, FrameNumber> target = ThreadNumber(0);
504 std::variant<ThreadNumber, SegmentIndex, GroupIndex, ExternalIndex, FrameNumber, UsesSource, UsesTarget, UsesAbsolute> frame = ThreadNumber(0);
506 uint32_t displacement;
507
508 void Read(OMF86Format * omf, Linker::Reader& rd, size_t displacement_size);
509 uint16_t GetSize(OMF86Format * omf, bool is32bit) const;
510 void Write(OMF86Format * omf, ChecksumWriter& wr, bool is32bit) const;
511
512 void CalculateValues(OMF86Format * omf, Module * mod);
513 void ResolveReferences(OMF86Format * omf, Module * mod);
514 };
515
518 {
519 public:
522 {
523 RHEADR = 0x6E, // Intel 4.0
524 REGINT = 0x70, // Intel 4.0
525 REDATA = 0x72, // Intel 4.0
526 RIDATA = 0x74, // Intel 4.0
527 OVLDEF = 0x76, // Intel 4.0
528 ENDREC = 0x78, // Intel 4.0
529 BLKDEF = 0x7A, // Intel 4.0
530 BLKEND = 0x7C, // Intel 4.0
531 DEBSYM = 0x7E, // Intel 4.0
532 THEADR = 0x80,
533 LHEADR = 0x82,
534 PEDATA = 0x84, // Intel 4.0
535 PIDATA = 0x86, // Intel 4.0
536 COMENT = 0x88,
537 MODEND16 = 0x8A,
538 MODEND = 0x8A,
539 MODEND32 = 0x8B, // TIS 1.1
540 EXTDEF = 0x8C,
541 TYPDEF = 0x8E, // Intel 4.0
542 PUBDEF16 = 0x90,
543 PUBDEF = 0x90,
544 PUBDEF32 = 0x91, // TIS 1.1
545 LOCSYM = 0x92, // Intel 4.0
546 LINNUM = 0x94, // Intel 4.0
547 LNAMES = 0x96,
548 SEGDEF = 0x98, // Intel 4.0
549 GRPDEF = 0x9A, // Intel 4.0
550 FIXUPP16 = 0x9C,
551 FIXUPP = 0x9C,
552 FIXUPP32 = 0x9D, // TIS 1.1
553 LEDATA16 = 0xA0,
554 LEDATA = 0xA0,
555 LEDATA32 = 0xA1, // TIS 1.1
556 LIDATA16 = 0xA2,
557 LIDATA = 0xA2,
558 LIDATA32 = 0xA3, // TIS 1.1
559 LIBHED = 0xA4, // Intel 4.0
560 LIBNAM = 0xA6, // Intel 4.0
561 LIBLOC = 0xA8, // Intel 4.0
562 LIBDIC = 0xAA, // Intel 4.0
563 COMDEF = 0xB0, // TIS 1.1, since Microsoft LINK 3.5
564 BAKPAT16 = 0xB2, // TIS 1.1, since Microsoft QuickC 1.0
565 BAKPAT = 0xB2, // TIS 1.1
566 BAKPAT32 = 0xB3, // TIS 1.1
567 LEXTDEF16 = 0xB4, // TIS 1.1, since Microsoft C 5.0
568 LEXTDEF = 0xB4, // TIS 1.1
569 LEXTDEF32 = 0xB5, // TIS 1.1
570 LPUBDEF16 = 0xB6, // TIS 1.1, since Microsoft C 5.0
571 LPUBDEF = 0xB6, // TIS 1.1
572 LPUBDEF32 = 0xB7, // TIS 1.1
573 LCOMDEF = 0xB8, // TIS 1.1, since Microsoft C 5.0
574 CEXTDEF = 0xBC, // TIS 1.1, since Microsoft C 7.0
575 COMDAT16 = 0xC2, // TIS 1.1, since Microsoft C 7.0
576 COMDAT = 0xC2, // TIS 1.1
577 COMDAT32 = 0xC3, // TIS 1.1
578 LINSYM16 = 0xC4, // TIS 1.1, since Microsoft C 7.0
579 LINSYM = 0xC4, // TIS 1.1
580 LINSYM32 = 0xC5, // TIS 1.1
581 ALIAS = 0xC6, // TIS 1.1, since Microsoft LINK 5.13
582 NBKPAT16 = 0xC8, // TIS 1.1, since Microsoft C 7.0
583 NBKPAT = 0xC8, // TIS 1.1
584 NBKPAT32 = 0xC9, // TIS 1.1
585 LLNAMES = 0xCA, // TIS 1.1, since Microsoft C 7.0
586 VERNUM = 0xCC, // TIS 1.1
587 VENDEXT = 0xCE, // TIS 1.1
588 LibraryHeader = 0xF0, // TIS 1.1
589 LibraryEnd = 0xF1, // TIS 1.1
590 };
591
592 Record()
593 {
594 }
595
597 : OMFFormat::Record(record_type)
598 {
599 }
600
602 void ReadRecordContents(OMFFormat * omf, Linker::Reader& rd) override;
604 uint16_t GetRecordSize(OMFFormat * omf) const override;
606 void WriteRecordContents(OMFFormat * omf, ChecksumWriter& wr) const override;
607
609 virtual void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) = 0;
611 virtual uint16_t GetRecordSize(OMF86Format * omf) const = 0;
613 virtual void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const = 0;
614
616 virtual void CalculateValues(OMF86Format * omf, Module * mod);
618 virtual void ResolveReferences(OMF86Format * omf, Module * mod);
619
621 bool Is32Bit(OMF86Format * omf) const;
622
624 size_t GetOffsetSize(OMF86Format * omf) const;
625
627 static std::shared_ptr<OMFFormat::Record> ReadRecord(OMF86Format * omf, Linker::Reader& rd);
628 };
629
631 class EmptyRecord : public Record
632 {
633 public:
635 : Record()
636 {
637 }
638
641 {
642 }
643
645 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
647 uint16_t GetRecordSize(OMF86Format * omf) const override;
649 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
650 };
651
654 {
655 public:
657 std::string name;
658
660 : Record()
661 {
662 }
663
666 {
667 }
668
670 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
672 uint16_t GetRecordSize(OMF86Format * omf) const override;
674 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
675 };
676
679 {
680 public:
683
685 enum module_type_t : uint8_t
686 {
687 AbsoluteModule = 0,
688 RelocatableModule = 1,
689 PICModule = 2,
690 LTLModule = 3,
691 };
692
702 uint32_t overlay_record_offset; // TODO: resolve record index
703
705 uint32_t static_size;
712
715 {
716 }
717
720 {
721 }
722
724 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
726 uint16_t GetRecordSize(OMF86Format * omf) const override;
728 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
729 };
730
733 {
734 public:
736 Module * module;
738 std::vector<std::string> names;
742 uint16_t lname_count = 0;
743
745 : Record()
746 {
747 }
748
751 {
752 }
753
755 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
757 uint16_t GetRecordSize(OMF86Format * omf) const override;
759 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
760
761 void CalculateValues(OMF86Format * omf, Module * mod) override;
762 void ResolveReferences(OMF86Format * omf, Module * mod) override;
763 };
764
766 class SegmentDefinitionRecord : public Record, public std::enable_shared_from_this<SegmentDefinitionRecord>
767 {
768 public:
796
799
801 typedef uint32_t Absolute;
802
804 struct Relocatable { };
805
808 {
809 public:
810 bool group_member;
811 uint16_t maximum_segment_length;
812 uint16_t group_offset;
813 };
814
816 std::variant<Relocatable, Absolute, LoadTimeLocatable> location = Relocatable{};
817
819 enum combination_t : uint8_t
820 {
827 Combination_Public = Combination_Append,
830 Combination_Public4 = FlagTIS | 4,
837 Combination_Common = FlagTIS | 6,
840 Combination_Public7 = FlagTIS | 4,
841 };
842
845
847 bool page_resident = false; // Intel
849 bool use32 = false;
850
857
860 {
861 AccessReadOnly = 0,
862 AccessExecuteOnly = 1,
863 AccessExecuteRead = 2,
864 AccessReadWrite = 3,
865 };
866
868 std::optional<access_t> access;
869
871 : Record()
872 {
873 }
874
877 {
878 }
879
881 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
883 uint16_t GetRecordSize(OMF86Format * omf) const override;
885 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
886
887 void CalculateValues(OMF86Format * omf, Module * mod) override;
888 void ResolveReferences(OMF86Format * omf, Module * mod) override;
889 };
890
892 class GroupDefinitionRecord : public Record, public std::enable_shared_from_this<GroupDefinitionRecord>
893 {
894 public:
897 {
898 public:
901 {
902 public:
903 NameIndex segment_name;
904 NameIndex class_name;
905 NameIndex overlay_name;
906 };
907
910 {
911 public:
912 uint32_t maximum_group_length;
913 uint32_t group_length;
914 };
915
917 typedef uint32_t Absolute;
918
920 static constexpr uint8_t Absolute_type = 0xFA;
922 static constexpr uint8_t LoadTimeLocatable_type = 0xFB;
924 static constexpr uint8_t SegmentClassOverlayNames_type = 0xFD;
926 static constexpr uint8_t ExternalIndex_type = 0xFE;
928 static constexpr uint8_t SegmentIndex_type = 0xFF;
929
931 std::variant<ExternalIndex, SegmentIndex, SegmentClassOverlayNames, LoadTimeLocatable, Absolute> component = ExternalIndex();
932
933 static Component ReadComponent(OMF86Format * omf, Linker::Reader& rd);
934 uint16_t GetComponentSize(OMF86Format * omf) const;
935 void WriteComponent(OMF86Format * omf, ChecksumWriter& wr) const;
936
937 void CalculateValues(OMF86Format * omf, Module * mod);
938 void ResolveReferences(OMF86Format * omf, Module * mod);
939 };
940
944 std::vector<Component> components;
945
947 : Record()
948 {
949 }
950
953 {
954 }
955
957 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
959 uint16_t GetRecordSize(OMF86Format * omf) const override;
961 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
962
963 void CalculateValues(OMF86Format * omf, Module * mod) override;
964 void ResolveReferences(OMF86Format * omf, Module * mod) override;
965 };
966
974 class TypeDefinitionRecord : public Record, public std::enable_shared_from_this<TypeDefinitionRecord>
975 {
976 public:
979 {
980 public:
982 bool nice;
983
985 struct Null { };
987 struct Repeat { };
988
990 std::variant<uint32_t, int32_t, std::string, TypeIndex, Null, Repeat> leaf = Null();
991
993 static constexpr uint8_t NullLeaf = 0x80;
995 static constexpr uint8_t StringLeaf = 0x82;
997 static constexpr uint8_t IndexLeaf = 0x83;
999 static constexpr uint8_t RepeatLeaf = 0x85;
1001 static constexpr uint8_t NumericLeaf16 = 0x81;
1003 static constexpr uint8_t NumericLeaf24 = 0x84;
1005 static constexpr uint8_t SignedNumericLeaf8 = 0x86;
1007 static constexpr uint8_t SignedNumericLeaf16 = 0x87;
1009 static constexpr uint8_t SignedNumericLeaf32 = 0x88;
1010
1011 static LeafDescriptor ReadLeaf(OMF86Format * omf, Linker::Reader& rd);
1012 uint16_t GetLeafSize(OMF86Format * omf) const;
1013 void WriteLeaf(OMF86Format * omf, ChecksumWriter& wr) const;
1014
1015 void CalculateValues(OMF86Format * omf, Module * mod);
1016 void ResolveReferences(OMF86Format * omf, Module * mod);
1017 };
1018
1020 std::string name;
1022 std::vector<LeafDescriptor> leafs;
1023
1024 enum
1025 {
1026 Far = 0x61, // Far(Array(...)) - Microsoft
1027 Near = 0x62, // Near(Array | Structure | Scalar, length in bits) - Microsoft
1028 Interrupt = 0x63,
1029 File = 0x64,
1030 Packed = 0x65,
1031 Unpacked = 0x66,
1032 Set = 0x67,
1033 Chameleon = 0x69,
1034 Boolean = 0x6A,
1035 True = 0x6B,
1036 False = 0x6C,
1037 Char = 0x6D,
1038 Integer = 0x6E,
1039 Const = 0x6F,
1040 Label = 0x71, // Label(nil, Short | Long)
1041 Long = 0x72,
1042 Short = 0x73,
1043 Procedure = 0x74, // Procedure(nil, @type, Short | Long, parameter count, @List(...))
1044 Parameter = 0x75, // Parameter(@type)
1045 Dimension = 0x76,
1046 Array = 0x77, // Array(length, @type)
1047 Structure = 0x79, // Structure(length, component count, @List(...))
1048 Pointer = 0x7A,
1049 Scalar = 0x7B, // Scalar(length, UnsignedInteger | SignedInteger | Real | @Pointer)
1050 UnsignedInteger = 0x7C,
1051 SignedInteger = 0x7D,
1052 Real = 0x7E,
1053 List = 0x7F, // List(...)
1054 };
1055
1057 : Record()
1058 {
1059 }
1060
1061 TypeDefinitionRecord(record_type_t record_type)
1062 : Record(record_type)
1063 {
1064 }
1065
1067 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1069 uint16_t GetRecordSize(OMF86Format * omf) const override;
1071 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1072
1073 void CalculateValues(OMF86Format * omf, Module * mod) override;
1074 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1075 };
1076
1079 {
1080 public:
1083
1085 std::vector<SymbolDefinition> symbols;
1086
1088 : Record()
1089 {
1090 }
1091
1094 {
1095 }
1096
1098 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1100 uint16_t GetRecordSize(OMF86Format * omf) const override;
1102 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1103
1104 void CalculateValues(OMF86Format * omf, Module * mod) override;
1105 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1106 };
1107
1110 {
1111 public:
1113 Module * module;
1117 uint16_t extdef_count = 0;
1118
1120 : Record()
1121 {
1122 }
1123
1126 {
1127 }
1128
1130 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1132 uint16_t GetRecordSize(OMF86Format * omf) const override;
1134 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1135
1136 void CalculateValues(OMF86Format * omf, Module * mod) override;
1137 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1138 };
1139
1142 {
1143 public:
1146
1148 std::vector<LineNumber> lines;
1149
1151 : Record()
1152 {
1153 }
1154
1157 {
1158 }
1159
1161 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1163 uint16_t GetRecordSize(OMF86Format * omf) const override;
1165 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1166
1167 void CalculateValues(OMF86Format * omf, Module * mod) override;
1168 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1169 };
1170
1172 class BlockDefinitionRecord : public Record, public std::enable_shared_from_this<BlockDefinitionRecord>
1173 {
1174 public:
1178 std::string name;
1180 uint16_t offset;
1182 uint16_t length;
1185 {
1192 };
1196 uint16_t return_address_offset; // only for procedures
1199
1201 : Record()
1202 {
1203 }
1204
1207 {
1208 }
1209
1211 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1213 uint16_t GetRecordSize(OMF86Format * omf) const override;
1215 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1216
1217 void CalculateValues(OMF86Format * omf, Module * mod) override;
1218 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1219 };
1220
1223 {
1224 public:
1225 enum frame_type_t : uint8_t
1226 {
1227 Location = 0x00,
1228 Frame16 = 0x80,
1229 Frame32 = 0xC0,
1230 };
1231 frame_type_t frame_type;
1232
1233 static constexpr uint8_t SymbolBaseMethod = 0x00;
1234 static constexpr uint8_t ExternalMethod = 0x01;
1235 static constexpr uint8_t BlockMethod = 0x02;
1236
1237 std::variant<BaseSpecification, ExternalIndex, BlockIndex> base = ExternalIndex();
1238
1239 std::vector<SymbolDefinition> names;
1240
1242 : Record()
1243 {
1244 }
1245
1248 {
1249 }
1250
1252 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1254 uint16_t GetRecordSize(OMF86Format * omf) const override;
1256 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1257
1258 void CalculateValues(OMF86Format * omf, Module * mod) override;
1259 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1260 };
1261
1264 {
1265 public:
1269 uint16_t offset;
1271 std::shared_ptr<DataBlock> data;
1272
1274 : Record()
1275 {
1276 }
1277
1280 {
1281 }
1282
1284 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1286 uint16_t GetRecordSize(OMF86Format * omf) const override;
1288 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1289
1290 void CalculateValues(OMF86Format * omf, Module * mod) override;
1291 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1292 };
1293
1296 {
1297 public:
1299 uint32_t address;
1301 std::shared_ptr<DataBlock> data;
1302
1304 : Record()
1305 {
1306 }
1307
1310 {
1311 }
1312
1314 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1316 uint16_t GetRecordSize(OMF86Format * omf) const override;
1318 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1319 };
1320
1323 {
1324 public:
1328 uint32_t offset;
1330 std::shared_ptr<DataBlock> data;
1331
1333 : Record()
1334 {
1335 }
1336
1339 {
1340 }
1341
1343 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1345 uint16_t GetRecordSize(OMF86Format * omf) const override;
1347 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1348
1349 void CalculateValues(OMF86Format * omf, Module * mod) override;
1350 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1351 };
1352
1354 class FixupRecord : public Record
1355 {
1356 public:
1359 {
1360 public:
1364 bool frame;
1366 std::variant<SegmentIndex, GroupIndex, ExternalIndex, FrameNumber, UsesSource, UsesTarget, UsesAbsolute> reference = FrameNumber(0);
1367
1368 static Thread Read(OMF86Format * omf, Linker::Reader& rd, uint8_t leading_data_byte);
1369 uint16_t GetSize(OMF86Format * omf) const;
1370 void Write(OMF86Format * omf, ChecksumWriter& wr) const;
1371
1372 void CalculateValues(OMF86Format * omf, Module * mod);
1373 void ResolveReferences(OMF86Format * omf, Module * mod);
1374 };
1375
1376 class Fixup
1377 {
1378 public:
1381
1408
1412 uint16_t offset;
1415
1416 static Fixup Read(OMF86Format * omf, Linker::Reader& rd, uint8_t leading_data_byte, bool is32bit);
1417 uint16_t GetSize(OMF86Format * omf, bool is32bit) const;
1418 void Write(OMF86Format * omf, ChecksumWriter& wr, bool is32bit) const;
1419
1420 void CalculateValues(OMF86Format * omf, Module * mod);
1421 void ResolveReferences(OMF86Format * omf, Module * mod);
1422 };
1423
1425 std::vector<std::variant<Thread, Fixup>> fixup_data;
1426
1427 FixupRecord()
1428 : Record()
1429 {
1430 }
1431
1434 {
1435 }
1436
1438 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1440 uint16_t GetRecordSize(OMF86Format * omf) const override;
1442 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1443
1444 void CalculateValues(OMF86Format * omf, Module * mod) override;
1445 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1446 };
1447
1449 class OverlayDefinitionRecord : public Record, public std::enable_shared_from_this<OverlayDefinitionRecord>
1450 {
1451 public:
1453 std::string name;
1455 uint32_t location;
1459 std::optional<OverlayIndex> shared_overlay;
1461 std::optional<OverlayIndex> adjacent_overlay;
1462
1464 : Record()
1465 {
1466 }
1467
1470 {
1471 }
1472
1474 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1476 uint16_t GetRecordSize(OMF86Format * omf) const override;
1478 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1479
1480 void CalculateValues(OMF86Format * omf, Module * mod) override;
1481 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1482 };
1483
1485 class EndRecord : public Record
1486 {
1487 public:
1489 enum block_type_t : uint8_t
1490 {
1491 Overlay = 0,
1492 Block = 1,
1493 };
1496
1497 EndRecord()
1498 : Record()
1499 {
1500 }
1501
1504 {
1505 }
1506
1508 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1510 uint16_t GetRecordSize(OMF86Format * omf) const override;
1512 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1513 };
1514
1517 {
1518 public:
1521 {
1522 public:
1535
1538 {
1539 public:
1543 uint16_t offset;
1544 };
1548 std::variant<Reference, InitialValue> value = Reference();
1549
1550 static Register ReadRegister(OMF86Format * omf, Linker::Reader& rd);
1551 uint16_t GetRegisterSize(OMF86Format * omf) const;
1552 void WriteRegister(OMF86Format * omf, ChecksumWriter& wr) const;
1553
1554 void CalculateValues(OMF86Format * omf, Module * mod);
1555 void ResolveReferences(OMF86Format * omf, Module * mod);
1556 };
1557
1559 std::vector<Register> registers;
1560
1562 : Record()
1563 {
1564 }
1565
1568 {
1569 }
1570
1572 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1574 uint16_t GetRecordSize(OMF86Format * omf) const override;
1576 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1577
1578 void CalculateValues(OMF86Format * omf, Module * mod) override;
1579 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1580 };
1581
1584 {
1585 public:
1589 std::optional<std::variant<Reference, std::tuple<uint16_t, uint16_t>>> start_address;
1590
1592 : Record()
1593 {
1594 }
1595
1598 {
1599 }
1600
1602 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1604 uint16_t GetRecordSize(OMF86Format * omf) const override;
1606 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1607 };
1608
1611 {
1612 public:
1618 uint16_t byte_number;
1619
1621 : Record()
1622 {
1623 }
1624
1627 {
1628 }
1629
1631 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1633 uint16_t GetRecordSize(OMF86Format * omf) const override;
1635 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1636 };
1637
1640 {
1641 public:
1643 std::vector<std::string> names;
1644
1646 : Record()
1647 {
1648 }
1649
1652 {
1653 }
1654
1656 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1658 uint16_t GetRecordSize(OMF86Format * omf) const override;
1660 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1661 };
1662
1665 {
1666 public:
1668 {
1669 public:
1673 uint16_t byte_number;
1674
1675 static Location ReadLocation(Linker::Reader& rd);
1676 void WriteLocation(ChecksumWriter& wr) const;
1677 };
1678
1680 std::vector<Location> locations;
1681
1683 : Record()
1684 {
1685 }
1686
1689 {
1690 }
1691
1693 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1695 uint16_t GetRecordSize(OMF86Format * omf) const override;
1697 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1698 };
1699
1702 {
1703 public:
1704 class Group
1705 {
1706 public:
1708 std::vector<std::string> names;
1709
1710 void ReadGroup(Linker::Reader& rd);
1711 uint16_t GetGroupSize() const;
1712 void WriteGroup(ChecksumWriter& wr) const;
1713 };
1714
1716 std::vector<Group> groups;
1717
1719 : Record()
1720 {
1721 }
1722
1725 {
1726 }
1727
1729 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1731 uint16_t GetRecordSize(OMF86Format * omf) const override;
1733 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1734 };
1735
1736 // TODO: document
1738 {
1739 public:
1741 {
1742 public:
1743 uint32_t offset;
1744 uint32_t value;
1745 };
1746
1747 SegmentIndex segment;
1748 enum location_type_t : uint8_t
1749 {
1750 Location8bit = 0,
1751 Location16bit = 1,
1752 Location32bit = 2,
1753 Location32bit_IBM = 9,
1754 };
1755 uint8_t type;
1756 std::vector<OffsetValuePair> offset_value_pairs;
1757
1759 : Record()
1760 {
1761 }
1762
1763 BackpatchRecord(record_type_t record_type)
1764 : Record(record_type)
1765 {
1766 }
1767
1769 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1771 uint16_t GetRecordSize(OMF86Format * omf) const override;
1773 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1774
1775 void CalculateValues(OMF86Format * omf, Module * mod) override;
1776 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1777 };
1778
1780 {
1781 public:
1783 {
1784 public:
1785 uint32_t offset;
1786 uint32_t value;
1787 };
1788
1789 enum location_type_t : uint8_t
1790 {
1791 Location8bit = 0,
1792 Location16bit = 1,
1793 Location32bit = 2,
1794 Location32bit_IBM = 9,
1795 };
1796 uint8_t type;
1797 NameIndex name;
1798 std::vector<OffsetValuePair> offset_value_pairs;
1799
1801 : Record()
1802 {
1803 }
1804
1805 NamedBackpatchRecord(record_type_t record_type)
1806 : Record(record_type)
1807 {
1808 }
1809
1811 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1813 uint16_t GetRecordSize(OMF86Format * omf) const override;
1815 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1816
1817 void CalculateValues(OMF86Format * omf, Module * mod) override;
1818 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1819 };
1820
1822 {
1823 public:
1824 bool continued;
1825 bool iterated;
1826 bool local;
1827 bool code_segment;
1828
1829 enum selection_criterion_t : uint8_t
1830 {
1831 SelectNoMatch = 0x00,
1832 SelectPickAny = 0x10,
1833 SelectSameSize = 0x20,
1834 SelectExactMatch = 0x30,
1835 };
1836 static constexpr uint8_t SelectionCriterionMask = 0xF0;
1837 selection_criterion_t selection_criterion;
1838
1839 enum allocation_type_t : uint8_t
1840 {
1841 AllocateExplicit = 0x00,
1842 AllocateFarCode = 0x01,
1843 AllocateFarData = 0x02,
1844 AllocateCode32 = 0x03,
1845 AllocateData32 = 0x04,
1846 };
1847 static constexpr uint8_t AllocationTypeMask = 0x0F;
1848 allocation_type_t allocation_type;
1849
1852
1853 uint32_t offset;
1854 TypeIndex type;
1855 BaseSpecification base; // unclear
1856 NameIndex name;
1857 std::shared_ptr<DataBlock> data;
1858
1860 : Record()
1861 {
1862 }
1863
1866 {
1867 }
1868
1870 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1872 uint16_t GetRecordSize(OMF86Format * omf) const override;
1874 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1875
1876 void CalculateValues(OMF86Format * omf, Module * mod) override;
1877 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1878 };
1879
1881 {
1882 public:
1883 bool continued;
1884 NameIndex name;
1885 std::vector<LineNumber> line_numbers;
1886
1888 : Record()
1889 {
1890 }
1891
1894 {
1895 }
1896
1898 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1900 uint16_t GetRecordSize(OMF86Format * omf) const override;
1902 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1903
1904 void CalculateValues(OMF86Format * omf, Module * mod) override;
1905 void ResolveReferences(OMF86Format * omf, Module * mod) override;
1906 };
1907
1909 {
1910 public:
1912 {
1913 public:
1914 std::string alias_name;
1915 std::string substitute_name;
1916
1917 static AliasDefinition ReadAliasDefinition(OMF86Format * omf, Linker::Reader& rd);
1918 uint16_t GetAliasDefinitionSize(OMF86Format * omf) const;
1919 void WriteAliasDefinition(OMF86Format * omf, ChecksumWriter& wr) const;
1920 };
1921 std::vector<AliasDefinition> alias_definitions;
1922
1924 : Record()
1925 {
1926 }
1927
1930 {
1931 }
1932
1934 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1936 uint16_t GetRecordSize(OMF86Format * omf) const override;
1938 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1939 };
1940
1942 {
1943 public:
1944 std::string version;
1945
1947 : Record()
1948 {
1949 }
1950
1953 {
1954 }
1955
1957 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1959 uint16_t GetRecordSize(OMF86Format * omf) const override;
1961 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1962 };
1963
1965 {
1966 public:
1967 uint16_t vendor_number;
1968 std::string extension;
1969
1971 : Record()
1972 {
1973 }
1974
1977 {
1978 }
1979
1981 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
1983 uint16_t GetRecordSize(OMF86Format * omf) const override;
1985 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
1986 };
1987
1988 class CommentRecord : public Record
1989 {
1990 public:
1991 bool no_purge;
1992 bool no_list;
1993 enum comment_class_t : uint8_t
1994 {
1995 Translator = 0x00,
1996 IntelCopyright = 0x01,
1997 LibrarySpecifier = 0x81,
1998 MSDOSVersion = 0x9C,
1999 MemoryModel = 0x9D,
2000 DOSSEG = 0x9E,
2001 DefaultLibrarySearchName = 0x9F,
2002 OMFExtension = 0xA0,
2003 NewOMFExtension = 0xA1,
2004 LinkPassSeparator = 0xA2,
2005 LIBMOD = 0xA3,
2006 EXESTR = 0xA4,
2007 INCERR = 0xA6,
2008 NOPAD = 0xA7,
2009 WKEXT = 0xA8,
2010 LZEXT = 0xA9,
2011 Comment = 0xDA,
2012 Compiler = 0xDB,
2013 Date = 0xDC,
2014 TimeStamp = 0xDD,
2015 User = 0xDF,
2016 DependencyFile = 0xE9,
2017 CommandLine = 0xFF,
2018 };
2019 comment_class_t comment_class;
2020
2022 : Record(COMENT)
2023 {
2024 }
2025
2026 CommentRecord(comment_class_t comment_class = comment_class_t(0))
2027 : Record(COMENT), comment_class(comment_class)
2028 {
2029 }
2030
2031 virtual void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) = 0;
2032 virtual uint16_t GetCommentSize(OMF86Format * omf) const = 0;
2033 virtual void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const = 0;
2034
2035 static std::shared_ptr<CommentRecord> ReadCommentRecord(OMF86Format * omf, Linker::Reader& rd, uint16_t record_length);
2037 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
2039 uint16_t GetRecordSize(OMF86Format * omf) const override;
2041 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
2042
2044 class EmptyCommentRecord;
2045 class TextCommentRecord;
2046 };
2047
2049 {
2050 public:
2051 std::vector<uint8_t> data;
2052
2053 GenericCommentRecord(comment_class_t comment_class = comment_class_t(0))
2054 : CommentRecord(comment_class)
2055 {
2056 }
2057
2058 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2059 uint16_t GetCommentSize(OMF86Format * omf) const override;
2060 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2061 };
2062
2064 {
2065 public:
2066 EmptyCommentRecord(comment_class_t comment_class = comment_class_t(0))
2067 : CommentRecord(comment_class)
2068 {
2069 }
2070
2071 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2072 uint16_t GetCommentSize(OMF86Format * omf) const override;
2073 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2074 };
2075
2077 {
2078 public:
2079 std::string name;
2080
2081 TextCommentRecord(comment_class_t comment_class = comment_class_t(0))
2082 : CommentRecord(comment_class)
2083 {
2084 }
2085
2086 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2087 uint16_t GetCommentSize(OMF86Format * omf) const override;
2088 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2089 };
2090
2092 {
2093 public:
2094 std::vector<SegmentIndex> segments;
2095
2097 : CommentRecord(NOPAD)
2098 {
2099 }
2100
2101 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2102 uint16_t GetCommentSize(OMF86Format * omf) const override;
2103 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2104
2105 void CalculateValues(OMF86Format * omf, Module * mod) override;
2106 void ResolveReferences(OMF86Format * omf, Module * mod) override;
2107 };
2108
2110 {
2111 public:
2113 {
2114 public:
2115 ExternalIndex definition;
2116 ExternalIndex default_resolution;
2117
2118 static ExternalAssociation ReadAssociation(OMF86Format * omf, Linker::Reader& rd);
2119 uint16_t GetAssociationSize(OMF86Format * omf) const;
2120 void WriteAssociation(OMF86Format * omf, ChecksumWriter& wr) const;
2121
2122 void CalculateValues(OMF86Format * omf, Module * mod);
2123 void ResolveReferences(OMF86Format * omf, Module * mod);
2124 };
2125
2126 std::vector<ExternalAssociation> associations;
2127
2128 ExternalAssociationRecord(comment_class_t comment_class = comment_class_t(0))
2129 : CommentRecord(comment_class)
2130 {
2131 }
2132
2133 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2134 uint16_t GetCommentSize(OMF86Format * omf) const override;
2135 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2136
2137 void CalculateValues(OMF86Format * omf, Module * mod) override;
2138 void ResolveReferences(OMF86Format * omf, Module * mod) override;
2139 };
2140
2142 {
2143 public:
2144 enum extension_type_t : uint8_t
2145 {
2146 IMPDEF = 0x01,
2147 EXPDEF = 0x02,
2148 INCDEF = 0x03,
2149 ProtectedModeLibrary = 0x04,
2150 LNKDIR = 0x05,
2151 BigEndian = 0x06,
2152 PRECOMP = 0x07,
2153 };
2154 extension_type_t subtype;
2155
2156 OMFExtensionRecord(extension_type_t subtype = extension_type_t(0))
2157 : CommentRecord(OMFExtension), subtype(subtype)
2158 {
2159 }
2160
2163 };
2164
2166 {
2167 public:
2168 std::vector<uint8_t> data;
2169
2170 GenericOMFExtensionRecord(extension_type_t extension_type = extension_type_t(0))
2171 : OMFExtensionRecord(extension_type)
2172 {
2173 }
2174
2175 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2176 uint16_t GetCommentSize(OMF86Format * omf) const override;
2177 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2178 };
2179
2181 {
2182 public:
2183 EmptyOMFExtensionRecord(extension_type_t extension_type = extension_type_t(0))
2184 : OMFExtensionRecord(extension_type)
2185 {
2186 }
2187
2188 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2189 uint16_t GetCommentSize(OMF86Format * omf) const override;
2190 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2191 };
2192
2194 {
2195 public:
2196 std::string internal_name;
2197 std::string module_name;
2198 std::variant<std::string, uint16_t> entry_ident;
2199
2201 : OMFExtensionRecord(IMPDEF)
2202 {
2203 }
2204
2205 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2206 uint16_t GetCommentSize(OMF86Format * omf) const override;
2207 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2208 };
2209
2211 {
2212 public:
2213 bool resident_name;
2214 bool no_data;
2215 uint8_t parameter_count;
2216 std::string exported_name;
2217 std::string internal_name;
2218 std::optional<uint16_t> ordinal;
2219
2221 : OMFExtensionRecord(EXPDEF)
2222 {
2223 }
2224
2225 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2226 uint16_t GetCommentSize(OMF86Format * omf) const override;
2227 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2228 };
2229
2231 {
2232 public:
2233 uint16_t extdef_delta;
2234 uint16_t linnum_delta;
2235 uint16_t padding_byte_count;
2236
2238 : OMFExtensionRecord(INCDEF)
2239 {
2240 }
2241
2242 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2243 uint16_t GetCommentSize(OMF86Format * omf) const override;
2244 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2245 };
2246
2248 {
2249 public:
2250 bool new_executable;
2251 bool omit_codeview_publics;
2252 bool run_mpc;
2253 uint8_t pseudocode_version;
2254 uint8_t codeview_version;
2255
2256 static constexpr uint8_t FlagNewExecutable = 0x01;
2257 static constexpr uint8_t FlagOmitCodeViewPublics = 0x02;
2258 static constexpr uint8_t FlagRunMPC = 0x04;
2259
2261 : OMFExtensionRecord(LNKDIR)
2262 {
2263 }
2264
2265 void ReadComment(OMF86Format * omf, Linker::Reader& rd, uint16_t comment_length) override;
2266 uint16_t GetCommentSize(OMF86Format * omf) const override;
2267 void WriteComment(OMF86Format * omf, ChecksumWriter& wr) const override;
2268 };
2269
2271 {
2272 public:
2273 uint32_t dictionary_offset;
2274 uint16_t dictionary_size;
2275 bool case_sensitive;
2276
2278 : Record()
2279 {
2280 }
2281
2284 {
2285 }
2286
2288 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
2290 uint16_t GetRecordSize(OMF86Format * omf) const override;
2292 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
2293
2294 void WriteRecord(OMFFormat * omf, Linker::Writer& wr) const override;
2295 };
2296
2298 {
2299 public:
2301 : Record()
2302 {
2303 }
2304
2307 {
2308 }
2309
2311 void ReadRecordContents(OMF86Format * omf, Linker::Reader& rd) override;
2313 uint16_t GetRecordSize(OMF86Format * omf) const override;
2315 void WriteRecordContents(OMF86Format * omf, ChecksumWriter& wr) const override;
2316
2317 void WriteRecord(OMFFormat * omf, Linker::Writer& wr) const override;
2318 };
2319
2322 {
2323 public:
2325 size_t first_record = 0;
2327 size_t record_count = 0;
2328
2330 std::vector<std::string> lnames;
2332 std::vector<std::shared_ptr<SegmentDefinitionRecord>> segdefs;
2334 std::vector<std::shared_ptr<GroupDefinitionRecord>> grpdefs;
2336 std::vector<std::shared_ptr<TypeDefinitionRecord>> typdefs;
2338 std::vector<std::shared_ptr<BlockDefinitionRecord>> blkdefs;
2340 std::vector<std::shared_ptr<OverlayDefinitionRecord>> ovldefs;
2342 std::vector<ExternalName> extdefs; // also includes comdefs and cextdefs
2343 // TODO: CalculateValue/etc. for ExternalName
2344 };
2345
2347 std::vector<Module> modules;
2348
2349 // TIS library fields
2350 uint16_t page_size;
2351
2352 void ReadFile(Linker::Reader& rd) override;
2354 offset_t WriteFile(Linker::Writer& wr) const override;
2355 void Dump(Dumper::Dumper& dump) const override;
2357 void GenerateModule(Linker::Module& module) const override;
2358 /* TODO */
2359 };
2360}
2361
2362#endif /* OMF_H */
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:586
A class to encode a general file format.
Definition format.h:29
offset_t WriteFile(Writer &wr) const override=0
Stores data in memory to file.
A class that provides a general interface to loading a module.
Definition format.h:193
virtual void GenerateModule(ModuleCollector &linker, std::string file_name, bool is_library=false) const
Loads the information into a module object.
Definition format.cc:215
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15
void WriteData(size_t count, const void *data)
Write out a sequence of bytes.
Definition writer.cc:7
void Skip(offset_t offset)
Jump to a distance in the output stream.
Definition writer.cc:103
void WriteWord(size_t bytes, uint64_t value, EndianType endiantype)
Read a word.
Definition writer.cc:66
Convenience class to calculate the checksum of a record while writing it.
Definition omf.h:19
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:3447
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:3438
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:3457
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:3117
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:3101
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:3096
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:3083
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:3112
Specification for the group and segment of some reference, and the frame if both are 0.
Definition omf.h:404
std::variant< Location, FrameNumber > location
The actual location of the reference.
Definition omf.h:414
A record that defines a block, used for BLKDEF records (Intel only)
Definition omf.h:1173
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2020
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:2042
block_type_t
Type of the block, if it is a procedure.
Definition omf.h:1185
@ NotProcedure
Block is not a procedure.
Definition omf.h:1187
@ NearProcedure
Block is a near procedure.
Definition omf.h:1189
@ FarProcedure
Block is a far procedure.
Definition omf.h:1191
block_type_t procedure
Whether this block is a procedure, and whether it is a near or far procedure.
Definition omf.h:1194
uint16_t length
Length of the block.
Definition omf.h:1182
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2002
TypeIndex type
Type of block or procedure, only used if name != "".
Definition omf.h:1198
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:2047
std::string name
The name of the block or empty.
Definition omf.h:1178
uint16_t return_address_offset
Offset, relative to the frame pointer (BP), to the return address of the procedure in the calling fra...
Definition omf.h:1196
uint16_t offset
Offset to the first byte of the block.
Definition omf.h:1180
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2025
BaseSpecification base
The first byte of the segment containing the block.
Definition omf.h:1176
A rich container for indexes referring to a BLKDEF record.
Definition omf.h:285
Definition omf.h:1989
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:3600
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:3605
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:3610
Represents a sequence of data, with optional repeated parts, used by RelocatableDataRecord,...
Definition omf.h:466
std::vector< std::shared_ptr< DataBlock > > Blocks
If the contents are a sequence of blocks (iterated only)
Definition omf.h:472
uint16_t repeat_count
Number of times the data should be appear. Should be 1 for enumerated data.
Definition omf.h:469
uint16_t GetIteratedDataBlockSize(OMF86Format *omf, bool is32bit) const
Gets the size of an encoded iterated record in bytes.
Definition omf.cc:492
void WriteIteratedDataBlock(OMF86Format *omf, ChecksumWriter &wr, bool is32bit) const
Writes the contents of an iterated record into a file.
Definition omf.cc:514
static std::shared_ptr< DataBlock > ReadIteratedDataBlock(OMF86Format *omf, Linker::Reader &rd, bool is32bit)
Parses the contents of an iterated record.
Definition omf.cc:462
static std::shared_ptr< DataBlock > ReadEnumeratedDataBlock(OMF86Format *omf, Linker::Reader &rd, uint16_t data_length)
Parses the contents of an enumerated record.
Definition omf.cc:451
void WriteEnumeratedDataBlock(OMF86Format *omf, ChecksumWriter &wr) const
Writes the contents of an enumerated record into a file.
Definition omf.cc:509
std::variant< Data, Blocks > content
The actual contents of the block, whether iterated or enumerated.
Definition omf.h:477
std::vector< uint8_t > Data
If the contents are a sequence of bytes (either iterated or enumerated)
Definition omf.h:474
uint16_t GetEnumeratedDataBlockSize(OMF86Format *omf) const
Gets the size of an encoded enumerated record in bytes.
Definition omf.cc:487
Record to store debug symbols, used for DEBSYM (Intel only)
Definition omf.h:1223
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:2158
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2054
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2114
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2086
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:2142
A record type that has no contents, aside from the type, length and checksum, used for BLKEND.
Definition omf.h:632
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:1031
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:1036
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:1027
Record to signal termination of an overloay or block, used for ENDBLK (Intel only)
Definition omf.h:1486
block_type_t
Type of block that is terminated by an EndRecord.
Definition omf.h:1490
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2689
block_type_t block_type
Type of block this record terminates.
Definition omf.h:1495
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2684
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2679
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:3772
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:3780
A rich container for indexes referring to symbols in an EXTDEF, LEXTDEF, COMDEF, LCOMDEF,...
Definition omf.h:388
An external name declaration, appearing in an EXTDEF, LEXTDEF, COMDEF, LCOMDEF or CEXTDEF record.
Definition omf.h:317
void WriteExternalName(OMF86Format *omf, ChecksumWriter &wr) const
Writes this entry to file.
Definition omf.cc:284
NameIndex name
Name of the symbol.
Definition omf.h:340
static void WriteLength(OMF86Format *omf, ChecksumWriter &wr, uint32_t length)
Writes a length value, for near or far elements.
Definition omf.cc:180
static ExternalName ReadCommonName(OMF86Format *omf, Linker::Reader &rd, bool local)
Parse a COMDEF or LCOMDEF entry.
Definition omf.cc:213
static uint32_t GetLengthSize(OMF86Format *omf, uint32_t length)
Determines the number of bytes needed for a length value, for near or far elements.
Definition omf.cc:168
static uint32_t ReadLength(OMF86Format *omf, Linker::Reader &rd)
Read a length value, for near or far elements.
Definition omf.cc:149
bool local
Signals if a symbol is local.
Definition omf.h:336
bool name_is_index
Set if name.index contains a valid value, for CEXTDEF entries.
Definition omf.h:338
common_type_t
Type of a common symbol.
Definition omf.h:321
@ NearCommon
Near variable.
Definition omf.h:332
@ FarCommon
Far variable.
Definition omf.h:329
@ SegmentIndexCommon
Borland segment index.
Definition omf.h:326
@ External
Not a common symbol, appears in an EXTDEF, LEXTDEF or CEXTDEF record.
Definition omf.h:323
uint16_t GetExternalNameSize(OMF86Format *omf) const
Returns the number of bytes required to write this entry.
Definition omf.cc:256
static ExternalName ReadExternalName(OMF86Format *omf, Linker::Reader &rd, bool local)
Parse an EXTDEF or LEXTDEF entry.
Definition omf.cc:203
static ExternalName ReadComdatExternalName(OMF86Format *omf, Linker::Reader &rd)
Parse a CEXTDEF entry.
Definition omf.cc:246
A record defining several external or common symbols, used for EXTDEF, LEXTDEF, CEXTDEF,...
Definition omf.h:1110
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:1925
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:1952
Module *ExternalIndex first_extdef
The module object this record appears in.
Definition omf.h:1115
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:1935
uint16_t extdef_count
Number of external or common symbols defined in this record.
Definition omf.h:1117
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:1907
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:1943
uint16_t offset
Offset to value to be relocated, relative to the latest data block.
Definition omf.h:1412
relocation_type_t type
The type of the relocation value.
Definition omf.h:1410
relocation_type_t
Types for the value that needs to be relocated.
Definition omf.h:1384
@ RelocationOffset32_LoaderResolved
A 32-bit loader-resolved value (TIS assignment)
Definition omf.h:1406
@ RelocationHighByte
Most significant 8 bits of a 16-bit value.
Definition omf.h:1394
@ RelocationOffset16
A 16-bit value or the 16-bit offset portion of a far address.
Definition omf.h:1388
@ RelocationSegment
The segment portion of a far address.
Definition omf.h:1390
@ RelocationPointer32
A 32-bit far address, consisting of a 16-bit segment portion and a 16-bit offset portion.
Definition omf.h:1392
@ RelocationOffset32_PharLap
A 32-bit value or the 32-bit offset portion of a far address (Phar Lap assignment)
Definition omf.h:1398
@ RelocationLowByte
Least significant 8 bits of value.
Definition omf.h:1386
@ RelocationOffset16_LoaderResolved
A 16-bit loader-resolved value (TIS assignment)
Definition omf.h:1396
@ RelocationOffset32
A 32-bit value or the 32-bit offset portion of a far address (TIS assignment)
Definition omf.h:1402
@ RelocationPointer48
A 48-bit far address, consisting of a 16-bit segment portion and a 32-bit offset portion (TIS assignm...
Definition omf.h:1404
@ RelocationPointer48_PharLap
A 48-bit far address, consisting of a 16-bit segment portion and a 32-bit offset portion (Phar Lap as...
Definition omf.h:1400
Reference ref
Reference of this relocation.
Definition omf.h:1414
bool segment_relative
Set if segment relative, self relative otherwise.
Definition omf.h:1380
Threads are intermediary storage for relocation targets and frames, this class represents a thread as...
Definition omf.h:1359
unsigned thread_number
The thread number which gets assigned to, a value from 0 to 3.
Definition omf.h:1362
bool frame
Set if this is a frame thread, it is a target thread otherwise.
Definition omf.h:1364
std::variant< SegmentIndex, GroupIndex, ExternalIndex, FrameNumber, UsesSource, UsesTarget, UsesAbsolute > reference
The frame or target reference.
Definition omf.h:1366
A record containing relocation data, used for FIXUPP.
Definition omf.h:1355
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2510
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:2582
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2527
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:2567
std::vector< std::variant< Thread, Fixup > > fixup_data
Sequence of thread assignments and relocations.
Definition omf.h:1425
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2548
Represents the data required for a load-time locatable group (Intel only)
Definition omf.h:910
Represents the data required for identifying a the segment by the name, class name and overlay name (...
Definition omf.h:901
Represents a component of the group.
Definition omf.h:897
static constexpr uint8_t SegmentIndex_type
The type prefix for a segment (the only type defined by TIS)
Definition omf.h:928
static constexpr uint8_t Absolute_type
The type prefix for the address of the group (Intel only)
Definition omf.h:920
static constexpr uint8_t SegmentClassOverlayNames_type
The type prefix for segment, class, overlay name triplets (Intel only)
Definition omf.h:924
static constexpr uint8_t LoadTimeLocatable_type
The type prefix for a load time locatable group (Intel only)
Definition omf.h:922
uint32_t Absolute
Represents the data required for an absolute group (Intel only)
Definition omf.h:917
static constexpr uint8_t ExternalIndex_type
The type prefix for the segment of an external symbol (Intel only)
Definition omf.h:926
std::variant< ExternalIndex, SegmentIndex, SegmentClassOverlayNames, LoadTimeLocatable, Absolute > component
The contents of the component.
Definition omf.h:931
A record that defines a segment group, used for GRPDEF records.
Definition omf.h:893
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:1569
std::vector< Component > components
The components of the group, such as member segments or load address.
Definition omf.h:944
NameIndex name
Name of the group.
Definition omf.h:942
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:1597
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:1580
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:1589
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:1558
A rich container for indexes referring to a GRPDEF record.
Definition omf.h:249
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:3210
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:3276
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:3314
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:3251
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:3324
std::vector< std::string > names
List of public symbols for one library module.
Definition omf.h:1708
All public symbols of all modules, used for LIBDIC (Intel only)
Definition omf.h:1702
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:3053
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:3073
std::vector< Group > groups
List of public symbols, grouped by library modules.
Definition omf.h:1716
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:3063
Library header record, used for LIBHED (Intel only)
Definition omf.h:1611
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2945
uint16_t module_count
Number of modules contained.
Definition omf.h:1614
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2940
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2933
uint16_t byte_number
Offset to the first byte of the library module, as a block:byte pair.
Definition omf.h:1618
uint16_t block_number
Offset to the first byte of the library module, as a block:byte pair.
Definition omf.h:1616
Library module offsets, used for LIBLOC (Intel only)
Definition omf.h:1665
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2999
std::vector< Location > locations
List of starting locations, one for each library module.
Definition omf.h:1680
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:3013
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:3008
Library module names, used for LIBNAM (Intel only)
Definition omf.h:1640
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2973
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2954
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2963
std::vector< std::string > names
List of module names.
Definition omf.h:1643
void WriteRecord(OMFFormat *omf, Linker::Writer &wr) const override
Writes the full record.
Definition omf.cc:4053
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:4048
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:4038
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:4043
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:4017
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:4001
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:4012
void WriteRecord(OMFFormat *omf, Linker::Writer &wr) const override
Writes the full record.
Definition omf.cc:4022
Represents a line number, used by LineNumbersRecord and SymbolLineNumbersRecord.
Definition omf.h:447
uint32_t offset
The offset in memory where the line starts.
Definition omf.h:452
uint16_t number
The line number value.
Definition omf.h:450
Stores as debugging data the line number information, used for LINNUM.
Definition omf.h:1142
BaseSpecification base
The first byte of the segment containing the line.
Definition omf.h:1145
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:1980
std::vector< LineNumber > lines
List of lines.
Definition omf.h:1148
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:1963
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:1990
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:1973
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:1995
A list of names to be referenced, used for LNAMES and LLNAMES records.
Definition omf.h:733
index_t first_lname
Index of the first name in the module.
Definition omf.h:740
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:1115
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:1125
Module *std::vector< std::string > names
The module object this record appears in.
Definition omf.h:738
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:1100
uint16_t lname_count
Number of names appearing in this record.
Definition omf.h:742
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:1138
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:1133
Logical enumerated or iterated data, used for LEDATA and LIDATA.
Definition omf.h:1323
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2265
std::shared_ptr< DataBlock > data
The data contents.
Definition omf.h:1330
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2277
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:2289
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2252
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:2294
SegmentIndex segment
Segment that contains this data.
Definition omf.h:1326
uint32_t offset
Offset within segment where the data starts.
Definition omf.h:1328
Terminates a module, used for MODEND.
Definition omf.h:1584
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2854
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2877
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2898
bool main_module
Set if this is a main module.
Definition omf.h:1587
std::optional< std::variant< Reference, std::tuple< uint16_t, uint16_t > > > start_address
Optional starting address, either a reference, or a segment:offset pair.
Definition omf.h:1589
A header record, used for THEADR and LHEADR.
Definition omf.h:654
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:1050
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:1042
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:1055
std::string name
The name of the record.
Definition omf.h:657
Represents a single module inside the OMF file.
Definition omf.h:2322
std::vector< std::shared_ptr< BlockDefinitionRecord > > blkdefs
List of blocks declared in the module.
Definition omf.h:2338
std::vector< std::shared_ptr< GroupDefinitionRecord > > grpdefs
List of groups declared in the module.
Definition omf.h:2334
std::vector< ExternalName > extdefs
List of external symbols declared in the module.
Definition omf.h:2342
std::vector< std::string > lnames
List of names declared in the module.
Definition omf.h:2330
std::vector< std::shared_ptr< TypeDefinitionRecord > > typdefs
List of types declared in the module.
Definition omf.h:2336
size_t first_record
The index of the first record inside the file, stored in the OMF86Format objects.
Definition omf.h:2325
std::vector< std::shared_ptr< OverlayDefinitionRecord > > ovldefs
List of overlays declared in the module.
Definition omf.h:2340
std::vector< std::shared_ptr< SegmentDefinitionRecord > > segdefs
List of segments declared in the module.
Definition omf.h:2332
size_t record_count
The number of records belonging to this module.
Definition omf.h:2327
A rich container for indexes referring to a LNAME/LLNAME declaration.
Definition omf.h:217
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:3148
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:3124
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:3200
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:3192
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:3168
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:3706
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:3702
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:3467
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:3477
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:3472
A record that defines an overlay, used for OVLDEF records.
Definition omf.h:1450
size_t first_data_record_index
Index of the first overlay data record within the file.
Definition omf.h:1457
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:2653
std::optional< OverlayIndex > shared_overlay
Must be loaded at the same location as the shared overlay.
Definition omf.h:1459
std::string name
Name of the overlay.
Definition omf.h:1453
uint32_t location
Offset to the first overlay data record within the file.
Definition omf.h:1455
std::optional< OverlayIndex > adjacent_overlay
Must be loaded adjacent to the adjacent overlay.
Definition omf.h:1461
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:2665
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2629
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2624
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2599
A rich container for indexes referring to a OVLDEF record.
Definition omf.h:301
Physical enumerated or iterated data, used for PEDATA and PIDATA (Intel only)
Definition omf.h:1296
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2219
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2230
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2240
uint32_t address
Physical address where data starts.
Definition omf.h:1299
std::shared_ptr< DataBlock > data
The data contents.
Definition omf.h:1301
A header record for an R-Module, used for RHEADR (not part of TIS OMF)
Definition omf.h:679
uint32_t maximum_dynamic_storage
Maximum memory size to allocate on load.
Definition omf.h:711
uint32_t dynamic_storage
Memory size to allocate on load.
Definition omf.h:709
module_type_t module_type
The type of the module.
Definition omf.h:694
uint16_t group_record_count
Number of group definition records in module.
Definition omf.h:698
module_type_t
Represents the type of the module.
Definition omf.h:686
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:1079
uint32_t static_size
Total size of LTL segments.
Definition omf.h:705
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:1084
uint16_t segment_record_count
Number of segment definition records in module.
Definition omf.h:696
uint32_t maximum_static_size
Maximum size needed for all LTL segments.
Definition omf.h:707
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:1062
uint32_t overlay_record_offset
Offset to the first overlay definition record from the start of the file or 0.
Definition omf.h:702
uint16_t overlay_record_count
Number of overlay definition records in module.
Definition omf.h:700
Module * mod
The module object this record appears in.
Definition omf.h:682
Record type appearing specifically in an OMF86 file.
Definition omf.h:518
record_type_t
The recognized record types in an OMF86 file.
Definition omf.h:522
void ReadRecordContents(OMFFormat *omf, Linker::Reader &rd) override
Converts omf to OMF86Format and calls the other implementation of ReadRecordContents.
Definition omf.cc:844
virtual void ResolveReferences(OMF86Format *omf, Module *mod)
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:863
void WriteRecordContents(OMFFormat *omf, ChecksumWriter &wr) const override
Converts omf to OMF86Format and calls the other implementation of WriteRecordContents.
Definition omf.cc:854
bool Is32Bit(OMF86Format *omf) const
Records are 32-bit if the least significant bit of their record type is set.
Definition omf.cc:834
virtual void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd)=0
Reads the record contents, except for the type, length and checksum.
virtual void CalculateValues(OMF86Format *omf, Module *mod)
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:859
virtual void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const =0
Writes the record contents, except for the type, length and checksum.
static std::shared_ptr< OMFFormat::Record > ReadRecord(OMF86Format *omf, Linker::Reader &rd)
Parses and returns an instance of the next record.
Definition omf.cc:867
uint16_t GetRecordSize(OMFFormat *omf) const override
Converts omf to OMF86Format and calls the other implementation of GetRecordSize.
Definition omf.cc:849
size_t GetOffsetSize(OMF86Format *omf) const
The number of bytes in an offset appearing inside the record, 2 for 16-bit records,...
Definition omf.cc:839
virtual uint16_t GetRecordSize(OMF86Format *omf) const =0
Calculates the required bytes to write the record, might be less than record_length.
Represents a reference for a relocation.
Definition omf.h:496
std::variant< ThreadNumber, SegmentIndex, GroupIndex, ExternalIndex, FrameNumber, UsesSource, UsesTarget, UsesAbsolute > frame
The frame for a reference, or a thread number.
Definition omf.h:504
unsigned ThreadNumber
A number between 0 and 3.
Definition omf.h:499
std::variant< ThreadNumber, SegmentIndex, GroupIndex, ExternalIndex, FrameNumber > target
The target for a reference, or a thread number.
Definition omf.h:502
uint32_t displacement
Displacement to be added to the value.
Definition omf.h:506
Used to initialize the register.
Definition omf.h:1538
uint16_t offset
An offset, needed for CS:IP and SS:SP.
Definition omf.h:1543
BaseSpecification base
The segment base.
Definition omf.h:1541
A single initialization entry.
Definition omf.h:1521
std::variant< Reference, InitialValue > value
The initial value of the register.
Definition omf.h:1548
register_t
Register type that can be initialized.
Definition omf.h:1525
@ DS
The DS segment register, the default data segment.
Definition omf.h:1531
@ ES
The ES segment register.
Definition omf.h:1533
@ CS_IP
The CS and IP register pair, it signifies the starting address as a far pointer.
Definition omf.h:1527
@ SS_SP
The SS and SP register pair, it signifies the initial stack as a far pointer.
Definition omf.h:1529
register_t reg_id
The register to initialize.
Definition omf.h:1546
Initialization values for registers, used for REGINT (Intel only)
Definition omf.h:1517
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:2844
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2828
std::vector< Register > registers
List of registers to be initialized.
Definition omf.h:1559
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2818
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:2836
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2809
Relocatable enumerated or iterated data, used for REDATA and RIDATA (Intel only)
Definition omf.h:1264
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:2197
std::shared_ptr< DataBlock > data
The data contents.
Definition omf.h:1271
uint16_t offset
Offset within paragraph where data starts.
Definition omf.h:1269
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:2212
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:2176
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:2207
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:2187
BaseSpecification base
Reference to paragraph that contains this data.
Definition omf.h:1267
Additional data for LTL segment, not part of TIS.
Definition omf.h:808
A record that defines a segment, used for SEGDEF records.
Definition omf.h:767
combination_t
Describes how two segments of the same name and class name should be combined.
Definition omf.h:820
@ Combination_Join_High
Merges the two segments at their highest address, adds their sizes (Intel interpretation)
Definition omf.h:832
@ Combination_Private
Do not combine segments, also known as Private.
Definition omf.h:822
@ Combination_Stack
Same as Public, but for stack segments.
Definition omf.h:834
@ Combination_Join_Low
Merges the two segments at their lowest address, adds their sizes (Intel interpretation)
Definition omf.h:829
@ Combination_Merge_High
Merges the two segments at their highest address, their size is the maximum (Intel interpretation)
Definition omf.h:839
@ Combination_Merge_Low
Merges the two segments at their lowest address, their size is the maximum (Intel interpretation)
Definition omf.h:836
@ Combination_Append
Appends the segments, also known as Public.
Definition omf.h:826
@ Combination_Merge_Highest
Like Combination_Merge_High, but also places the segment above all other segments (not used by TIS)
Definition omf.h:824
NameIndex class_name
The name of the segment's class (not used for AlignUnnamed)
Definition omf.h:854
NameIndex segment_name
The name of the segment (not used for AlignUnnamed)
Definition omf.h:852
combination_t combination
How segments of the same type should be combined.
Definition omf.h:844
alignment_t alignment
Alignment of segment.
Definition omf.h:798
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:1396
bool use32
Set if the USE32 directive is used for the segment. The field appears in different places for Phar La...
Definition omf.h:849
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:1386
std::variant< Relocatable, Absolute, LoadTimeLocatable > location
Information on where the segment should be placed at runtime.
Definition omf.h:816
uint64_t segment_length
The length of the segment (maximum 0x100000000)
Definition omf.h:770
bool page_resident
Set if the segment should not cross a 256 byte page boundary (only Intel)
Definition omf.h:847
access_t
Represents an additional field used by Phar Lap.
Definition omf.h:860
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:1326
NameIndex overlay_name
The name of the overlay the segment appears in (not used for AlignUnnamed)
Definition omf.h:856
std::optional< access_t > access
Represents the value of a Phar Lap specific extension word.
Definition omf.h:868
alignment_t
Alignment type for a segment.
Definition omf.h:773
@ Align16
Relocatable segment, paragraph (16-byte) aligned.
Definition omf.h:781
@ Align256
Relocatable segment, page (256-byte) aligned, as defined by Intel.
Definition omf.h:788
@ AlignLTL16
Load-time locatable or, if not part of a group, paragraph (16-byte) aligned (Intel only)
Definition omf.h:785
@ Align2
Relocatable segment, word (2-byte) aligned.
Definition omf.h:779
@ Align32
Relocatable segment, double word (4-byte) aligned, type 5 as defined by TIS.
Definition omf.h:794
@ Align4096
Relocatable segment, page (4096-byte) aligned, as used by IBM.
Definition omf.h:790
@ AlignUnnamed
Unnamed absolute portion of the memory address space, type 5 as defined by Intel.
Definition omf.h:792
@ AlignAbsolute
Absolute segment, its position in memory is fixed.
Definition omf.h:775
@ AlignPage
Relocatable segment, page aligned, exact size depends on OMF version.
Definition omf.h:783
@ Align1
Relocatable segment, byte aligned.
Definition omf.h:777
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:1145
uint32_t Absolute
Additional data used for absolute segments, type 0 or 5 if Intel version is used.
Definition omf.h:801
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:1297
A rich container for indexes referring to a SEGDEF record.
Definition omf.h:233
Represents a symbol definition, used by SymbolDefinitionsRecord and DebugSymbolsRecord.
Definition omf.h:426
std::string name
The name of the symbol.
Definition omf.h:431
bool local
Set to true if the symbol is local.
Definition omf.h:429
uint32_t offset
The offset (value) of the symbol.
Definition omf.h:433
TypeIndex type
The type of the symbol, or 0.
Definition omf.h:435
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:3336
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:3407
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:3378
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:3359
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:3399
A record that defines a symbol, used by PUBDEF, LPUBDEF, LOCSYM.
Definition omf.h:1079
std::vector< SymbolDefinition > symbols
A list of symbols.
Definition omf.h:1085
BaseSpecification base
The first byte of the segment containing the symbol.
Definition omf.h:1082
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:1857
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:1889
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:1868
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:1879
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:1897
A single item in a type definition.
Definition omf.h:979
static constexpr uint8_t RepeatLeaf
Type byte for a repeat leaf leaf.
Definition omf.h:999
static constexpr uint8_t NumericLeaf24
Type byte for an unsigned 24-bit leaf.
Definition omf.h:1003
bool nice
Set to false if "easy", true if "nice".
Definition omf.h:982
std::variant< uint32_t, int32_t, std::string, TypeIndex, Null, Repeat > leaf
The actual contents of the leaf.
Definition omf.h:990
static constexpr uint8_t StringLeaf
Type byte for a string leaf.
Definition omf.h:995
static constexpr uint8_t NullLeaf
Type byte for a null leaf.
Definition omf.h:993
static constexpr uint8_t SignedNumericLeaf16
Type byte for an signed 16-bit leaf.
Definition omf.h:1007
static constexpr uint8_t NumericLeaf16
Type byte for an unsigned 16-bit leaf.
Definition omf.h:1001
static constexpr uint8_t SignedNumericLeaf32
Type byte for an signed 32-bit leaf.
Definition omf.h:1009
static constexpr uint8_t IndexLeaf
Type byte for an index leaf, usually a type index.
Definition omf.h:997
static constexpr uint8_t SignedNumericLeaf8
Type byte for an signed 8-bit leaf.
Definition omf.h:1005
A record that defines a data type, used for TYPDEF records.
Definition omf.h:975
void CalculateValues(OMF86Format *omf, Module *mod) override
Updates all fields that will be used for writing an OMF module, should be called before output.
Definition omf.cc:1839
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:1808
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:1820
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:1792
void ResolveReferences(OMF86Format *omf, Module *mod) override
Resolves any fields read from an OMF module, should be called after inpnut.
Definition omf.cc:1847
std::vector< LeafDescriptor > leafs
The parameters of this type.
Definition omf.h:1022
std::string name
The name of this type.
Definition omf.h:1020
A rich container for indexes referring to a TYPDEF record.
Definition omf.h:269
void ReadRecordContents(OMF86Format *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:3484
void WriteRecordContents(OMF86Format *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:3495
uint16_t GetRecordSize(OMF86Format *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:3490
Intel Relocatable Object Module format, used by various 16/32-bit DOS based compilers and linkers,...
Definition omf.h:139
static constexpr unsigned int FlagIntel
Flag binary or'ed to certain values to mark Intel interpretation.
Definition omf.h:166
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition omf.cc:4110
std::vector< Module > modules
List of modules appearing in an OMF file, typically only one for an object file.
Definition omf.h:2347
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition omf.cc:4103
static void WriteIndex(ChecksumWriter &wr, index_t index)
Produces a 1 or 2 byte index value.
Definition omf.cc:4073
static size_t IndexSize(index_t index)
Determines if the index value requires 1 or 2 bytes to store.
Definition omf.cc:4086
static constexpr unsigned int FlagPharLap
Flag binary or'ed to certain values to mark Phar Lap interpretation.
Definition omf.h:168
@ MethodGroup
References a group defined in a module, for either targets or frames.
Definition omf.h:190
@ MethodFrame
References a physical paragraph address in a module, for either targets or frames.
Definition omf.h:194
@ MethodAbsolute
No frame is provided, intended for Intel 8089, only the Intel version supports it,...
Definition omf.h:200
@ MethodExternal
References a external symbol declared in a module, for either targets or frames.
Definition omf.h:192
@ MethodSegment
References a segment defined in a module, for either targets or frames.
Definition omf.h:188
@ MethodSource
References the frame of the relocation source, only for frames.
Definition omf.h:196
@ MethodTarget
References the frame of the relocation target, only for frames.
Definition omf.h:198
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition omf.cc:4098
uint16_t index_t
An index referring to an element or definition in the file, typically stored as 1 or 2 bytes.
Definition omf.h:173
void GenerateModule(Linker::Module &module) const override
Loads the information into a module object, a convenience method when there is a single module genera...
Definition omf.cc:4121
static constexpr unsigned int FlagTIS
Flag binary or'ed to certain values to mark TIS interpretation.
Definition omf.h:170
omf_version_t
Represents the various variants of the OMF file format, some of them are incompatible.
Definition omf.h:149
@ OMF_VERSION_INTEL_40
The original Intel definition, version 4.0 (including any extensions that are compatible)
Definition omf.h:151
@ OMF_VERSION_TIS_11
Version 1.1 produced and consolidated by the Tool Interface Standard.
Definition omf.h:159
@ OMF_VERSION_PHARLAP
Phar Lap's extensions, mostly concerning 32-bit (partly incompatible with later versions)
Definition omf.h:153
@ OMF_VERSION_IBM
Format generated by IBM's tools (partly incompatible with other versions)
Definition omf.h:157
@ OMF_VERSION_MICROSOFT
Format generated by Microsoft's tools (partly incompatible with other versions)
Definition omf.h:155
uint16_t FrameNumber
Represents a MethodFrame value.
Definition omf.h:204
omf_version_t omf_version
The variant of the OMF format, needed to handle certain fields.
Definition omf.h:163
static index_t ReadIndex(Linker::Reader &rd)
Parses a 1 or 2 byte index value.
Definition omf.cc:4063
Base class representing OMF record types.
Definition omf.h:85
virtual void ReadRecordContents(OMFFormat *omf, Linker::Reader &rd)=0
Reads the record contents, except for the type, length and checksum.
virtual uint16_t GetRecordSize(OMFFormat *omf) const =0
Calculates the required bytes to write the record, might be less than record_length.
uint16_t record_length
Length of record body file, excluding the type byte and 2-byte length field.
Definition omf.h:90
offset_t record_offset
Offset of record within the file.
Definition omf.h:88
uint8_t record_type
A byte value identifying the type of record.
Definition omf.h:92
virtual void WriteRecordContents(OMFFormat *omf, ChecksumWriter &wr) const =0
Writes the record contents, except for the type, length and checksum.
virtual void WriteRecord(OMFFormat *omf, Linker::Writer &wr) const
Writes the full record.
Definition omf.cc:25
An unparsed record type, if the format is not recognized.
Definition omf.h:116
std::vector< uint8_t > data
Contents of the record, without the type, length and checksum.
Definition omf.h:119
uint16_t GetRecordSize(OMFFormat *omf) const override
Calculates the required bytes to write the record, might be less than record_length.
Definition omf.cc:42
void WriteRecordContents(OMFFormat *omf, ChecksumWriter &wr) const override
Writes the record contents, except for the type, length and checksum.
Definition omf.cc:47
void ReadRecordContents(OMFFormat *omf, Linker::Reader &rd) override
Reads the record contents, except for the type, length and checksum.
Definition omf.cc:36
Base class for a family of Intel Relocatable Object formats.
Definition omf.h:68
std::vector< std::shared_ptr< Record > > records
The ordered collection of records contained in the file.
Definition omf.h:132
static std::string ReadString(Linker::Reader &rd, size_t max_bytes=size_t(-1))
Reads a string prefixed with a length byte.
Definition omf.cc:11
static void WriteString(ChecksumWriter &wr, std::string text)
Writes a string prefixed with a length byte.
Definition omf.cc:17
Type representing the group and segment of some reference.
Definition omf.h:408
uint16_t byte_number
Offset to the first byte of the library module, as a block:byte pair.
Definition omf.h:1673
uint16_t block_number
Offset to the first byte of the library module, as a block:byte pair.
Definition omf.h:1671
Type representing a relocatable segment.
Definition omf.h:804
Represents a null leaf.
Definition omf.h:985
Represents a final repeat leaf, meaning that the data in this type should be repeated indefinitely.
Definition omf.h:987
Represents a MethodAbsolute value.
Definition omf.h:213
Represents a MethodSource value.
Definition omf.h:207
Represents a MethodTarget value.
Definition omf.h:210