7#include "../dumper/dumper.h"
8#include "../linker/module.h"
9#include "../linker/segment.h"
10#include "../linker/segment_manager.h"
11#include "../linker/writer.h"
66 OMF_VERSION_0 = 0x0000,
67 OMF_VERSION_1 = 0x0100,
68 OMF_VERSION_2 = 0x0200,
69 OMF_VERSION_2_1 = 0x0201,
115 ::EndianType GetEndianType()
const;
138 size_t ReadData(
size_t bytes, offset_t offset,
void * buffer)
const;
139 offset_t
ReadUnsigned(
size_t bytes, offset_t offset)
const;
155 Multiplication = 0x03,
157 IntegerRemainder = 0x05,
164 LessOrEqualTo = 0x0C,
165 GreaterOrEqualTo = 0x0D,
174 LocationCounterOperand = 0x80,
175 ConstantOperand = 0x81,
176 WeakLabelReferenceOperand = 0x82,
177 LabelReferenceOperand = 0x83,
178 LengthOfLabelReferenceOperand = 0x84,
179 TypeOfLabelReferenceOperand = 0x85,
180 CountOfLabelReferenceOperand = 0x86,
181 RelativeOffsetOperand = 0x87,
192 std::optional<std::variant<offset_t, std::string>>
value;
202 operands.emplace_back(std::move(operand));
205 Expression(
int operation, std::unique_ptr<Expression>& operand1, std::unique_ptr<Expression>& operand2)
208 operands.emplace_back(std::move(operand1));
209 operands.emplace_back(std::move(operand2));
222 offset_t GetLength(
const Segment& segment)
const;
229 void PopElementsInto(
size_t count, std::vector<std::unique_ptr<Expression>>& target);
251 typedef precedence::precedence_type precedence_type;
263 OPC_CONST_BASE = 0x00,
264 OPC_CONST_FIRST = 0x01,
265 OPC_CONST_LAST = 0xDF,
286 OPC_C_INTERSEG = 0xF6,
324 virtual void ReadData(
size_t bytes, offset_t offset,
void * buffer)
const;
331 std::shared_ptr<Linker::Image> image;
333 DataRecord(record_type type, std::shared_ptr<Linker::Image> image)
334 :
Record(type), image(image)
348 void ReadData(
size_t bytes, offset_t offset,
void * buffer)
const override;
358 :
Record(type), value(value)
367 void ReadData(
size_t bytes, offset_t offset,
void * buffer)
const override;
384 RelocationRecord(record_type type, uint8_t size, int8_t shift, offset_t source, offset_t target)
385 :
Record(type), size(size), shift(shift), source(source), target(target)
400 uint16_t file_number = 0;
401 uint16_t segment_number = 0;
413 IntersegmentRelocationRecord(record_type type, uint8_t size, uint8_t shift, offset_t source, uint16_t file_number, uint16_t segment_number, offset_t target)
414 :
RelocationRecord(type, size, shift, source, target), file_number(file_number), segment_number(segment_number)
431 :
Record(type), name(name)
446 uint16_t line_length = 0;
457 OP_REF_ADDRESS_DC =
'K',
458 OP_SOFT_REF_DC =
'L',
459 OP_INSTRUCTION =
'M',
460 OP_ASM_DIRECTIVE =
'N',
464 OP_ARITHMETIC_SYMBOL =
'X',
465 OP_BOOL_SYMBOL =
'Y',
468 operation_type operation = operation_type(0);
469 uint16_t private_flag = 0;
476 LabelRecord(record_type type, std::string name, uint16_t line_length,
int operation, uint16_t private_flag)
477 :
Record(type), name(name), line_length(line_length), operation(operation_type(operation)), private_flag(private_flag)
491 std::unique_ptr<Expression> expression;
498 LabelExpressionRecord(record_type type, std::string name, uint16_t line_length,
int operation, uint16_t private_flag, std::unique_ptr<Expression> expression)
499 :
LabelRecord(type, name, line_length, operation, private_flag), expression(std::move(expression))
521 RangeRecord(record_type type, offset_t start, offset_t end)
522 :
Record(type), start(start), end(end)
537 std::unique_ptr<Expression> expression;
544 ExpressionRecord(record_type type, uint8_t size, std::unique_ptr<Expression> expression)
545 :
Record(type), size(size), expression(std::move(expression))
554 void ReadData(
size_t bytes, offset_t offset,
void * buffer)
const override;
583 uint16_t segment_number;
592 EntryRecord(record_type type, uint16_t segment_number, offset_t location, std::string name)
593 :
Record(type), segment_number(segment_number), location(location), name(name)
607 enum super_record_type
612 SUPER_INTERSEG13 = SUPER_INTERSEG1 - 1 + 13,
613 SUPER_INTERSEG25 = SUPER_INTERSEG1 - 1 + 25,
614 SUPER_INTERSEG36 = SUPER_INTERSEG1 - 1 + 36,
617 super_record_type super_type = super_record_type(0);
619 std::vector<uint16_t> offsets;
621 SuperCompactRecord(record_type type, super_record_type super_type = super_record_type(0))
622 :
Record(type), super_type(super_type)
630 void WritePatchList(
Linker::Writer& wr,
const std::vector<uint8_t>& patches)
const;
643 std::vector<std::unique_ptr<Record>> records;
649 std::unique_ptr<Record> makeEND();
650 std::unique_ptr<Record> makeCONST(std::shared_ptr<Linker::Image> image);
651 std::unique_ptr<Record> makeCONST(
size_t length);
652 std::unique_ptr<Record> makeALIGN(offset_t
align = 0);
653 std::unique_ptr<Record> makeORG(offset_t value = 0);
654 std::unique_ptr<Record> makeRELOC(uint8_t size, uint8_t shift, offset_t source, offset_t target);
655 std::unique_ptr<Record> makeRELOC();
656 std::unique_ptr<Record> makeINTERSEG(uint8_t size, uint8_t shift, offset_t source, uint16_t file_number, uint16_t
segment_number, offset_t target);
657 std::unique_ptr<Record> makeINTERSEG();
658 std::unique_ptr<Record> makeUSING(std::string name =
"");
659 std::unique_ptr<Record> makeSTRONG(std::string name =
"");
660 std::unique_ptr<Record> makeGLOBAL();
661 std::unique_ptr<Record> makeGLOBAL(std::string name, uint16_t line_length,
int operation, uint16_t private_flag);
662 std::unique_ptr<Record> makeGEQU();
663 std::unique_ptr<Record> makeGEQU(std::string name, uint16_t line_length,
int operation, uint16_t private_flag, std::unique_ptr<Expression> expression);
664 std::unique_ptr<Record> makeMEM();
665 std::unique_ptr<Record> makeMEM(offset_t start, offset_t end);
666 std::unique_ptr<Record> makeEXPR();
667 std::unique_ptr<Record> makeEXPR(uint8_t size, std::unique_ptr<Expression> expression);
668 std::unique_ptr<Record> makeZEXPR();
669 std::unique_ptr<Record> makeZEXPR(uint8_t size, std::unique_ptr<Expression> expression);
670 std::unique_ptr<Record> makeBEXPR();
671 std::unique_ptr<Record> makeBEXPR(uint8_t size, std::unique_ptr<Expression> expression);
672 std::unique_ptr<Record> makeRELEXPR();
673 std::unique_ptr<Record> makeRELEXPR(uint8_t size, offset_t origin, std::unique_ptr<Expression> expression);
674 std::unique_ptr<Record> makeLOCAL();
675 std::unique_ptr<Record> makeLOCAL(std::string name, uint16_t line_length,
int operation, uint16_t private_flag);
676 std::unique_ptr<Record> makeEQU();
677 std::unique_ptr<Record> makeEQU(std::string name, uint16_t line_length,
int operation, uint16_t private_flag, std::unique_ptr<Expression> expression);
678 std::unique_ptr<Record> makeDS(offset_t count = 0);
679 std::unique_ptr<Record> makeLCONST();
680 std::unique_ptr<Record> makeLCONST(std::shared_ptr<Linker::Image> image);
681 std::unique_ptr<Record> makeLEXPR();
682 std::unique_ptr<Record> makeLEXPR(uint8_t size, std::unique_ptr<Expression> expression);
683 std::unique_ptr<Record> makeENTRY();
684 std::unique_ptr<Record> makeENTRY(uint16_t
segment_number, offset_t location, std::string name);
685 std::unique_ptr<Record> makecRELOC(uint8_t size, uint8_t shift, uint16_t source, uint16_t target);
686 std::unique_ptr<Record> makecRELOC();
687 std::unique_ptr<Record> makecINTERSEG(uint8_t size, uint8_t shift, uint16_t source, uint16_t
segment_number, uint16_t target);
688 std::unique_ptr<Record> makecINTERSEG();
689 std::unique_ptr<Record> makeSUPER(SuperCompactRecord::super_record_type super_type = SuperCompactRecord::super_record_type(0));
692 std::vector<std::unique_ptr<Segment>> segments;
Represents an ENTRY record.
Definition gsos.h:581
void AddFields(Dumper::Dumper &dump, Dumper::Region ®ion, const OMFFormat &omf, const Segment &segment, unsigned index, offset_t file_offset, offset_t address) const override
Adds any further fields to the file region that encompasses this record.
Definition gsos.cc:1267
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:1247
A region within a file that can be dumped, decompiled, and it may contain fixups.
Definition dumper.h:524
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:586
A record that represents a region within the file.
Definition dumper.h:485
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
A helper class to collect sections into segments.
Definition segment_manager.h:32
offset_t current_address
Holds the current address value when there is no current_segment.
Definition segment_manager.h:37
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15