RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
gsos.h
1#ifndef GSOS_H
2#define GSOS_H
3
4#include <optional>
5#include <variant>
6#include "../common.h"
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"
12
13/* TODO: most of this code is not tested, it can parse and dump executable binaries */
14
15namespace Apple
16{
23 class OMFFormat : public virtual Linker::SegmentManager
24 {
25 public:
26 class Segment
27 {
28 public:
30 offset_t segment_offset = 0;
32 offset_t total_segment_size = 0;
34 offset_t bss_size = 0;
36 offset_t total_size = 0;
38 {
40 SEG_CODE = 0x00,
42 SEG_DATA = 0x01,
50 SEG_INIT = 0x10,
55 };
59 uint16_t flags = 0;
61 uint8_t label_length = 0;
63 uint8_t number_length = 4;
64 enum omf_version
65 {
66 OMF_VERSION_0 = 0x0000, // TODO: unsure
67 OMF_VERSION_1 = 0x0100,
68 OMF_VERSION_2 = 0x0200,
69 OMF_VERSION_2_1 = 0x0201,
70 };
72 omf_version version = OMF_VERSION_2;
74 offset_t bank_size = 0;
76 offset_t base_address = 0;
78 offset_t align = 0x100;
80 uint8_t endiantype = 0;
82 uint8_t language_card_bank = 0;
84 uint16_t segment_number = 0;
86 offset_t entry = 0;
88 offset_t segment_name_offset = 0x2C;
90 offset_t segment_data_offset = 0;
92 offset_t temp_org = 0;
96 std::string segment_name;
97
99 static const uint16_t FLAG_BANK_RELATIVE = 0x0100;
101 static const uint16_t FLAG_SKIP_SEGMENT = 0x0200;
103 static const uint16_t FLAG_RELOAD = 0x0400;
105 static const uint16_t FLAG_ABSOLUTE_BANK = 0x0800;
107 static const uint16_t FLAG_NO_SPECIAL_MEMORY = 0x1000;
109 static const uint16_t FLAG_POSITION_INDEPENDENT = 0x2000;
111 static const uint16_t FLAG_PRIVATE = 0x4000;
113 static const uint16_t FLAG_DYNAMIC = 0x8000;
114
115 ::EndianType GetEndianType() const;
116
118 offset_t ReadUnsigned(Linker::Reader& rd) const;
120 void WriteWord(Linker::Writer& wr, offset_t value) const;
121
123 std::string ReadLabel(Linker::Reader& rd) const;
125 void WriteLabel(Linker::Writer& wr, std::string text) const;
126
133 offset_t CalculateValues(uint16_t segment_number, offset_t current_offset);
134 void ReadFile(Linker::Reader& rd);
135 void WriteFile(Linker::Writer& wr) const;
136 void Dump(Dumper::Dumper& dump, const OMFFormat& omf, unsigned segment_index) const;
137
138 size_t ReadData(size_t bytes, offset_t offset, void * buffer) const;
139 offset_t ReadUnsigned(size_t bytes, offset_t offset) const;
140
142 {
143 public:
144 // TODO: untested
145
151 {
152 End = 0x00,
153 Addition = 0x01,
154 Subtraction = 0x02,
155 Multiplication = 0x03,
156 Division = 0x04,
157 IntegerRemainder = 0x05,
158 Negation = 0x06,
159 BitShift = 0x07,
160 And = 0x08,
161 Or = 0x09,
162 EOr = 0x0A,
163 Not = 0x0B,
164 LessOrEqualTo = 0x0C,
165 GreaterOrEqualTo = 0x0D,
166 NotEqual = 0x0E,
167 LessThan = 0x0F,
168 GreaterThan = 0x10,
169 EqualTo = 0x11,
170 BitAnd = 0x12,
171 BitOr = 0x13,
172 BitEOr = 0x14,
173 BitNot = 0x15,
174 LocationCounterOperand = 0x80,
175 ConstantOperand = 0x81,
176 WeakLabelReferenceOperand = 0x82,
177 LabelReferenceOperand = 0x83,
178 LengthOfLabelReferenceOperand = 0x84,
179 TypeOfLabelReferenceOperand = 0x85,
180 CountOfLabelReferenceOperand = 0x86,
181 RelativeOffsetOperand = 0x87,
182
185 };
186
190 std::vector<std::unique_ptr<Expression>> operands;
192 std::optional<std::variant<offset_t, std::string>> value;
193
196 {
197 }
198
199 Expression(int operation, std::unique_ptr<Expression>& operand)
201 {
202 operands.emplace_back(std::move(operand));
203 }
204
205 Expression(int operation, std::unique_ptr<Expression>& operand1, std::unique_ptr<Expression>& operand2)
207 {
208 operands.emplace_back(std::move(operand1));
209 operands.emplace_back(std::move(operand2));
210 }
211
212 Expression(int operation, offset_t value)
214 {
215 }
216
217 Expression(int operation, std::string value)
219 {
220 }
221
222 offset_t GetLength(const Segment& segment) const;
223 void ReadFile(Segment& segment, Linker::Reader& rd);
224 void WriteFile(const Segment& segment, Linker::Writer& wr) const;
226 std::string GetStandardNotation() const;
227 protected:
229 void PopElementsInto(size_t count, std::vector<std::unique_ptr<Expression>>& target);
231 uint8_t ReadSingleOperation(Segment& segment, Linker::Reader& rd);
232
234 {
235 enum precedence_type
236 {
237 Or,
238 EOr,
239 And,
240 LessThan,
241 EqualTo,
242 BitOr,
243 BitEOr,
244 BitAnd,
245 BitShift,
246 Addition,
247 Multiplication,
248 Negation,
249 };
250 };
251 typedef precedence::precedence_type precedence_type;
252 void GetStandardNotation(std::ostream& out, precedence_type precedence) const;
253 };
254
256 class Record
257 {
258 public:
259 enum record_type
260 {
261 // E: executable, O: object, L: library
262 OPC_END = 0x00, // EOL
263 OPC_CONST_BASE = 0x00,
264 OPC_CONST_FIRST = 0x01, // O
265 OPC_CONST_LAST = 0xDF, // O
266 OPC_ALIGN = 0xE0, // O
267 OPC_ORG = 0xE1, // O
268 OPC_RELOC = 0xE2, // E
269 OPC_INTERSEG = 0xE3, // E
270 OPC_USING = 0xE4, // O
271 OPC_STRONG = 0xE5, // O
272 OPC_GLOBAL = 0xE6, // O
273 OPC_GEQU = 0xE7, // O
274 OPC_MEM = 0xE8, // O
275 OPC_EXPR = 0xEB, // O
276 OPC_ZEXPR = 0xEC, // O
277 OPC_BEXPR = 0xED, // O
278 OPC_RELEXPR = 0xEE, // O
279 OPC_LOCAL = 0xEF, // O
280 OPC_EQU = 0xF0, // O
281 OPC_DS = 0xF1, // EOL
282 OPC_LCONST = 0xF2, // EOL
283 OPC_LEXPR = 0xF3, // O
284 OPC_ENTRY = 0xF4, // L
285 OPC_C_RELOC = 0xF5, // E
286 OPC_C_INTERSEG = 0xF6, // E
287 OPC_SUPER = 0xF7, // E (V2)
288 };
289 record_type type;
290
291 Record(record_type type)
292 : type(type)
293 {
294 }
295
296 virtual ~Record() = default;
301 virtual offset_t GetLength(const Segment& segment) const;
306 virtual offset_t GetMemoryLength(const Segment& segment, offset_t current_address) const;
307 virtual void ReadFile(Segment& segment, Linker::Reader& rd);
308 virtual void WriteFile(const Segment& segment, Linker::Writer& wr) const;
318 virtual void Dump(Dumper::Dumper& dump, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const;
320 virtual void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const;
322 virtual void AddSignals(Dumper::Block& block, offset_t current_segment_offset) const;
324 virtual void ReadData(size_t bytes, offset_t offset, void * buffer) const;
325 };
326
328 class DataRecord : public Record
329 {
330 public:
331 std::shared_ptr<Linker::Image> image;
332
333 DataRecord(record_type type, std::shared_ptr<Linker::Image> image)
334 : Record(type), image(image)
335 {
336 }
337
338 DataRecord(record_type type)
339 : Record(type)
340 {
341 }
342
343 offset_t GetLength(const Segment& segment) const override;
344 offset_t GetMemoryLength(const Segment& segment, offset_t current_address) const override;
345 void ReadFile(Segment& segment, Linker::Reader& rd) override;
346 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
347 void Dump(Dumper::Dumper& dump, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
348 void ReadData(size_t bytes, offset_t offset, void * buffer) const override;
349 };
350
352 class ValueRecord : public Record
353 {
354 public:
355 offset_t value;
356
357 ValueRecord(record_type type, offset_t value)
358 : Record(type), value(value)
359 {
360 }
361
362 offset_t GetLength(const Segment& segment) const override;
363 offset_t GetMemoryLength(const Segment& segment, offset_t current_address) const override;
364 void ReadFile(Segment& segment, Linker::Reader& rd) override;
365 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
366 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
367 void ReadData(size_t bytes, offset_t offset, void * buffer) const override;
368 };
369
372 {
373 public:
374 uint8_t size = 0;
375 int8_t shift = 0;
376 offset_t source = 0;
377 offset_t target = 0;
378
379 RelocationRecord(record_type type)
380 : Record(type)
381 {
382 }
383
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)
386 {
387 }
388
389 offset_t GetLength(const Segment& segment) const override;
390 void ReadFile(Segment& segment, Linker::Reader& rd) override;
391 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
392 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
393 void AddSignals(Dumper::Block& block, offset_t current_segment_offset) const override;
394 };
395
398 {
399 public:
400 uint16_t file_number = 0;
401 uint16_t segment_number = 0;
402
404 : RelocationRecord(record_type(0))
405 {
406 }
407
408 IntersegmentRelocationRecord(record_type type)
409 : RelocationRecord(type)
410 {
411 }
412
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)
415 {
416 }
417
418 offset_t GetLength(const Segment& segment) const override;
419 void ReadFile(Segment& segment, Linker::Reader& rd) override;
420 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
421 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
422 };
423
425 class StringRecord : public Record
426 {
427 public:
428 std::string name;
429
430 StringRecord(record_type type, std::string name)
431 : Record(type), name(name)
432 {
433 }
434
435 offset_t GetLength(const Segment& segment) const override;
436 void ReadFile(Segment& segment, Linker::Reader& rd) override;
437 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
438 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
439 };
440
442 class LabelRecord : public Record
443 {
444 public:
445 std::string name;
446 uint16_t line_length = 0;
447 enum operation_type
448 {
449 OP_ADDRESS_DC = 'A',
450 OP_BOOL_DC = 'B',
451 OP_CHAR_DC = 'C',
452 OP_DOUBLE_DC = 'D',
453 OP_FLOAT_DC = 'E',
454 OP_EQU_GEQU = 'G',
455 OP_HEX_DC = 'H',
456 OP_INT_DC = 'I',
457 OP_REF_ADDRESS_DC = 'K',
458 OP_SOFT_REF_DC = 'L',
459 OP_INSTRUCTION = 'M',
460 OP_ASM_DIRECTIVE = 'N',
461 OP_ORG = 'O',
462 OP_ALIGN = 'P',
463 OP_DS = 'S',
464 OP_ARITHMETIC_SYMBOL = 'X',
465 OP_BOOL_SYMBOL = 'Y',
466 OP_CHAR_SYMBOL = 'Z'
467 };
468 operation_type operation = operation_type(0);
469 uint16_t private_flag = 0;
470
471 LabelRecord(record_type type)
472 : Record(type)
473 {
474 }
475
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)
478 {
479 }
480
481 offset_t GetLength(const Segment& segment) const override;
482 void ReadFile(Segment& segment, Linker::Reader& rd) override;
483 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
484 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
485 };
486
489 {
490 public:
491 std::unique_ptr<Expression> expression;
492
493 LabelExpressionRecord(record_type type)
494 : LabelRecord(type)
495 {
496 }
497
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))
500 {
501 }
502
503 offset_t GetLength(const Segment& segment) const override;
504 void ReadFile(Segment& segment, Linker::Reader& rd) override;
505 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
506 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
507 };
508
510 class RangeRecord : public Record
511 {
512 public:
513 offset_t start = 0;
514 offset_t end = 0;
515
516 RangeRecord(record_type type)
517 : Record(type)
518 {
519 }
520
521 RangeRecord(record_type type, offset_t start, offset_t end)
522 : Record(type), start(start), end(end)
523 {
524 }
525
526 offset_t GetLength(const Segment& segment) const override;
527 void ReadFile(Segment& segment, Linker::Reader& rd) override;
528 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
529 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
530 };
531
534 {
535 public:
536 uint8_t size = 0;
537 std::unique_ptr<Expression> expression;
538
539 ExpressionRecord(record_type type)
540 : Record(type)
541 {
542 }
543
544 ExpressionRecord(record_type type, uint8_t size, std::unique_ptr<Expression> expression)
545 : Record(type), size(size), expression(std::move(expression))
546 {
547 }
548
549 offset_t GetLength(const Segment& segment) const override;
550 offset_t GetMemoryLength(const Segment& segment, offset_t current_address) const override;
551 void ReadFile(Segment& segment, Linker::Reader& rd) override;
552 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
553 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
554 void ReadData(size_t bytes, offset_t offset, void * buffer) const override;
555 };
556
559 {
560 public:
561 offset_t origin = 0;
562
563 RelativeExpressionRecord(record_type type)
564 : ExpressionRecord(type)
565 {
566 }
567
568 RelativeExpressionRecord(record_type type, uint8_t size, offset_t origin, std::unique_ptr<Expression> expression)
569 : ExpressionRecord(type, size, std::move(expression)), origin(origin)
570 {
571 }
572
573 offset_t GetLength(const Segment& segment) const override;
574 void ReadFile(Segment& segment, Linker::Reader& rd) override;
575 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
576 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
577 };
578
580 class EntryRecord : public Record
581 {
582 public:
583 uint16_t segment_number;
584 offset_t location;
585 std::string name;
586
587 EntryRecord(record_type type)
588 : Record(type)
589 {
590 }
591
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)
594 {
595 }
596
597 offset_t GetLength(const Segment& segment) const override;
598 void ReadFile(Segment& segment, Linker::Reader& rd) override;
599 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
600 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
601 };
602
605 {
606 public:
607 enum super_record_type
608 {
609 SUPER_RELOC2,
610 SUPER_RELOC3,
611 SUPER_INTERSEG1,
612 SUPER_INTERSEG13 = SUPER_INTERSEG1 - 1 + 13,
613 SUPER_INTERSEG25 = SUPER_INTERSEG1 - 1 + 25,
614 SUPER_INTERSEG36 = SUPER_INTERSEG1 - 1 + 36,
615 };
616
617 super_record_type super_type = super_record_type(0);
618
619 std::vector<uint16_t> offsets;
620
621 SuperCompactRecord(record_type type, super_record_type super_type = super_record_type(0))
622 : Record(type), super_type(super_type)
623 {
624 }
625
626 offset_t GetLength(const Segment& segment) const override;
627 void ReadFile(Segment& segment, Linker::Reader& rd) override;
628 void WriteFile(const Segment& segment, Linker::Writer& wr) const override;
629 private:
630 void WritePatchList(Linker::Writer& wr, const std::vector<uint8_t>& patches) const;
631
632 public:
633 void Dump(Dumper::Dumper& dump, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
634 void AddFields(Dumper::Dumper& dump, Dumper::Region& region, const OMFFormat& omf, const Segment& segment, unsigned index, offset_t file_offset, offset_t address) const override;
635 void AddSignals(Dumper::Block& block, offset_t current_segment_offset) const override;
636
638 bool GetRelocation(IntersegmentRelocationRecord& relocation, unsigned index) const;
640 bool GetRelocation(IntersegmentRelocationRecord& relocation, unsigned index, const Segment& segment) const;
641 };
642
643 std::vector<std::unique_ptr<Record>> records;
644
645 std::unique_ptr<Expression> ReadExpression(Linker::Reader& rd);
646
647 std::unique_ptr<Record> ReadRecord(Linker::Reader& rd);
648
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));
690 };
691
692 std::vector<std::unique_ptr<Segment>> segments;
693
694 void CalculateValues() override;
695 void ReadFile(Linker::Reader& rd) override;
697 offset_t WriteFile(Linker::Writer& wr) const override;
698 offset_t ImageSize() const override;
699 void Dump(Dumper::Dumper& dump) const override;
700 /* TODO */
701 };
702}
703
704#endif /* GSOS_H */
Represents a CONST or LCONST record, containing a sequence of bytes.
Definition gsos.h:329
void Dump(Dumper::Dumper &dump, const OMFFormat &omf, const Segment &segment, unsigned index, offset_t file_offset, offset_t address) const override
Displays information pertaining to this record.
Definition gsos.cc:865
void ReadData(size_t bytes, offset_t offset, void *buffer) const override
Attempts to read data from the in-memory image, if possible, it can be assumed that offset + bytes <=...
Definition gsos.cc:878
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:821
offset_t GetMemoryLength(const Segment &segment, offset_t current_address) const override
Returns the amount of memory the record occupies when loaded into memory. Most records have a length ...
Definition gsos.cc:833
Represents an ENTRY record.
Definition gsos.h:581
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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
Represents an EXPR, ZEXPR, BEXPR or LEXPR record.
Definition gsos.h:534
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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:1210
void ReadData(size_t bytes, offset_t offset, void *buffer) const override
Attempts to read data from the in-memory image, if possible, it can be assumed that offset + bytes <=...
Definition gsos.cc:1216
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:1187
offset_t GetMemoryLength(const Segment &segment, offset_t current_address) const override
Returns the amount of memory the record occupies when loaded into memory. Most records have a length ...
Definition gsos.cc:1192
std::optional< std::variant< offset_t, std::string > > value
A value corresponding to an operation, such as an integer constant or a label name.
Definition gsos.h:192
std::vector< std::unique_ptr< Expression > > operands
The operands the operation takes.
Definition gsos.h:190
void PopElementsInto(size_t count, std::vector< std::unique_ptr< Expression > > &target)
Removes elements from the top of the operands stack and copies them into target. On stack underflow,...
Definition gsos.cc:432
uint8_t ReadSingleOperation(Segment &segment, Linker::Reader &rd)
Reads a single byte of operation (plus optional number and label) and modifies the current list of op...
Definition gsos.cc:447
operation_type
Represents an operation inside an expression in the object file.
Definition gsos.h:151
@ StackUnderflow
A symbolic value to represent a stack underflow condition, it should not be printed back into a binar...
Definition gsos.h:184
std::string GetStandardNotation() const
Converts expression into a C-like syntax.
Definition gsos.cc:425
operation_type operation
The type of operation, End means that the result is the last operand.
Definition gsos.h:188
Represents an INTERSEG or cINTERSEG record, containing an intersegment relocation.
Definition gsos.h:398
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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:1045
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:993
Represents an EQU or GEQU record.
Definition gsos.h:489
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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:1157
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:1133
Represents a LOCAL or GLOBAL record.
Definition gsos.h:443
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:1077
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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:1099
Represents a MEM record.
Definition gsos.h:511
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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:1181
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:1163
A single record inside the segment body, also represents an END record.
Definition gsos.h:257
virtual void Dump(Dumper::Dumper &dump, const OMFFormat &omf, const Segment &segment, unsigned index, offset_t file_offset, offset_t address) const
Displays information pertaining to this record.
Definition gsos.cc:772
virtual void AddFields(Dumper::Dumper &dump, Dumper::Region &region, const OMFFormat &omf, const Segment &segment, unsigned index, offset_t file_offset, offset_t address) const
Adds any further fields to the file region that encompasses this record.
Definition gsos.cc:809
virtual void AddSignals(Dumper::Block &block, offset_t current_segment_offset) const
If this is a relocation record, add the relocation signals to the block.
Definition gsos.cc:813
virtual void ReadData(size_t bytes, offset_t offset, void *buffer) const
Attempts to read data from the in-memory image, if possible, it can be assumed that offset + bytes <=...
Definition gsos.cc:817
virtual offset_t GetMemoryLength(const Segment &segment, offset_t current_address) const
Returns the amount of memory the record occupies when loaded into memory. Most records have a length ...
Definition gsos.cc:758
virtual offset_t GetLength(const Segment &segment) const
Returns the size of the record, as stored in the file.
Definition gsos.cc:753
Represents a RELEXPR record.
Definition gsos.h:559
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:1221
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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:1241
Represents a RELOC or cRELOC record, containing an intrasegment relocation.
Definition gsos.h:372
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:932
void AddSignals(Dumper::Block &block, offset_t current_segment_offset) const override
If this is a relocation record, add the relocation signals to the block.
Definition gsos.cc:985
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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:977
Represents a USING or STRONG record, containing a string.
Definition gsos.h:426
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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:1072
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:1056
Represents a SUPER record.
Definition gsos.h:605
void Dump(Dumper::Dumper &dump, const OMFFormat &omf, const Segment &segment, unsigned index, offset_t file_offset, offset_t address) const override
Displays information pertaining to this record.
Definition gsos.cc:1379
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:1273
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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:1402
bool GetRelocation(IntersegmentRelocationRecord &relocation, unsigned index) const
Expands the super compact relocation into a full relocation, without filling in the target fields.
Definition gsos.cc:1427
void AddSignals(Dumper::Block &block, offset_t current_segment_offset) const override
If this is a relocation record, add the relocation signals to the block.
Definition gsos.cc:1416
Represents an ALIGN, ORG or DS record, containing an integer.
Definition gsos.h:353
offset_t GetMemoryLength(const Segment &segment, offset_t current_address) const override
Returns the amount of memory the record occupies when loaded into memory. Most records have a length ...
Definition gsos.cc:889
offset_t GetLength(const Segment &segment) const override
Returns the size of the record, as stored in the file.
Definition gsos.cc:884
void ReadData(size_t bytes, offset_t offset, void *buffer) const override
Attempts to read data from the in-memory image, if possible, it can be assumed that offset + bytes <=...
Definition gsos.cc:927
void AddFields(Dumper::Dumper &dump, Dumper::Region &region, 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:914
Definition gsos.h:27
offset_t segment_offset
Offset of segment within file.
Definition gsos.h:30
void WriteLabel(Linker::Writer &wr, std::string text) const
Writes a string the size of label_length, or variable length if it is 0.
Definition gsos.cc:41
uint8_t label_length
(LABLEN) Label length, or 0 for variable length labels
Definition gsos.h:61
offset_t total_size
(LENGTH) Total size of segment when loaded into memory, including the additional zeroes
Definition gsos.h:36
void WriteWord(Linker::Writer &wr, offset_t value) const
Writes a number the size of number_length.
Definition gsos.cc:26
offset_t bss_size
(RESSPC) Additional zeroes to append to segment
Definition gsos.h:34
offset_t base_address
(ORG) Base address of segment
Definition gsos.h:76
uint8_t language_card_bank
(LCBANK) Language card bank
Definition gsos.h:82
uint8_t number_length
(NUMLEN) Number length, must be 4
Definition gsos.h:63
omf_version version
(VERSION, REVISION) OMF file format version
Definition gsos.h:72
static const uint16_t FLAG_NO_SPECIAL_MEMORY
Segment flag: Do not load in special memory (version 2 only)
Definition gsos.h:107
std::string linker_segment_name
(LOADNAME) Name of segment according to linker
Definition gsos.h:94
offset_t align
(ALIGN) Segment alignment
Definition gsos.h:78
static const uint16_t FLAG_PRIVATE
Segment flag: Private.
Definition gsos.h:111
static const uint16_t FLAG_ABSOLUTE_BANK
Segment flag: Absolute bank segment (version 2 only)
Definition gsos.h:105
offset_t temp_org
(tempOrg) (only version 2.1, optional)
Definition gsos.h:92
static const uint16_t FLAG_RELOAD
Segment flag: Reload segment (version 2 only)
Definition gsos.h:103
segment_kind kind
(KIND) Segment type
Definition gsos.h:57
offset_t total_segment_size
(BYTECNT/BLKCNT) Total size of the segment, including the header, as stored in file
Definition gsos.h:32
std::string segment_name
(LOADNAME) Name of segment
Definition gsos.h:96
offset_t entry
(ENTRY) Entry point (not present in version 0)
Definition gsos.h:86
uint8_t endiantype
(NUMSEX) Endianness, must be 0 for LittleEndian
Definition gsos.h:80
offset_t bank_size
(BANKSIZE) Maximum bank size of segment
Definition gsos.h:74
static const uint16_t FLAG_POSITION_INDEPENDENT
Segment flag: Position independent.
Definition gsos.h:109
offset_t segment_data_offset
(DISPDATA) Offset to segment data, typically appearing after segment_name (not present in version 0)
Definition gsos.h:90
static const uint16_t FLAG_BANK_RELATIVE
Segment flag: Bank relative (version 2 only)
Definition gsos.h:99
static const uint16_t FLAG_DYNAMIC
Segment flag: Dynamic.
Definition gsos.h:113
static const uint16_t FLAG_SKIP_SEGMENT
Segment flag: Skip segment (version 2 only)
Definition gsos.h:101
uint16_t flags
(KIND) Segment flags
Definition gsos.h:59
uint16_t segment_number
(SEGNUM) Segment number (not present in version 0)
Definition gsos.h:84
offset_t ReadUnsigned(Linker::Reader &rd) const
Reads a number the size of number_length.
Definition gsos.cc:21
offset_t segment_name_offset
(DISPNAME) Offset to linker_segment_name (LOADNAME), (not present in version 0)
Definition gsos.h:88
segment_kind
Definition gsos.h:38
@ SEG_CODE
Code segment.
Definition gsos.h:40
@ SEG_DIRPAGE
Direct page/stack segment.
Definition gsos.h:54
@ SEG_JUMPTABLE
Jump table segment.
Definition gsos.h:44
@ SEG_INIT
Initialization segment.
Definition gsos.h:50
@ SEG_PATHNAME
Pathname segment.
Definition gsos.h:46
@ SEG_DATA
Data segment.
Definition gsos.h:42
@ SEG_LIBDICT
Library dictionary segment.
Definition gsos.h:48
@ SEG_ABSBANK
Absolute bank segment (version 1 only)
Definition gsos.h:52
std::string ReadLabel(Linker::Reader &rd) const
Reads a string the size of label_length, or variable length if it is 0.
Definition gsos.cc:31
Apple GS/OS OMF file format.
Definition gsos.h:24
offset_t ImageSize() const override
Retrieves size of stored data.
Definition gsos.cc:730
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition gsos.cc:707
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition gsos.cc:720
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition gsos.cc:698
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition gsos.cc:737
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
offset_t WriteFile(Writer &wr) const override=0
Stores data in memory to file.
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