RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
pcos.h
1#ifndef PCOS_H
2#define PCOS_H
3
4#include <array>
5#include <memory>
6#include <vector>
7#include "../common.h"
8#include "../linker/reader.h"
9#include "../linker/segment_manager.h"
10#include "../linker/writer.h"
11#include "../dumper/dumper.h"
12
13/* TODO: untested */
14
15namespace PCOS
16{
25 class CMDFormat : public virtual Linker::SegmentManager
26 {
27 public:
28 /* * * General members * * */
29
32 {
33 public:
48
49 virtual ~MemoryBlock();
50
52 virtual uint16_t GetLength() const;
57 virtual void ReadFile(Linker::Reader& rd, uint16_t length);
59 virtual void WriteFile(Linker::Writer& wr) const;
61 virtual std::unique_ptr<Dumper::Region> MakeRegion(std::string name, offset_t offset, unsigned display_width) const;
63 virtual void AddFields(Dumper::Region& region, const CMDFormat& module) const;
65 virtual void DumpContents(Dumper::Dumper& dump, offset_t file_offset, const CMDFormat& module) const;
67 void Dump(Dumper::Dumper& dump, offset_t file_offset, const CMDFormat& module) const;
68
70 static std::unique_ptr<MemoryBlock> ReadFile(Linker::Reader& rd);
71
72 explicit MemoryBlock(int type)
74 {
75 }
76 };
77
78 class LoadBlock : public MemoryBlock
79 {
80 public:
81 LoadBlock()
83 {
84 }
85
87 uint32_t block_id;
89 std::shared_ptr<Linker::Image> image;
90
91 uint16_t GetLength() const override;
92 void ReadFile(Linker::Reader& rd, uint16_t length) override;
93 void WriteFile(Linker::Writer& wr) const override;
94 std::unique_ptr<Dumper::Region> MakeRegion(std::string name, offset_t offset, unsigned display_width) const override;
95 void AddFields(Dumper::Region& region, const CMDFormat& module) const override;
96 };
97
100 {
101 public:
103 uint8_t source = 0;
105 uint8_t target = 0;
107 std::vector<uint16_t> offsets;
108
111 {
112 }
113
114 uint16_t GetLength() const override;
115 void ReadFile(Linker::Reader& rd, uint16_t length) override;
116 void WriteFile(Linker::Writer& wr) const override;
117 void AddFields(Dumper::Region& region, const CMDFormat& module) const override;
118 void DumpContents(Dumper::Dumper& dump, offset_t file_offset, const CMDFormat& module) const override;
119 };
120
123 {
124 public:
125 UnknownBlock(int type)
127 {
128 }
129
130 std::shared_ptr<Linker::Image> image;
131
132 uint16_t GetLength() const override;
133 void ReadFile(Linker::Reader& rd, uint16_t length) override;
134 void WriteFile(Linker::Writer& wr) const override;
135 std::unique_ptr<Dumper::Region> MakeRegion(std::string name, offset_t offset, unsigned display_width) const override;
136 };
137
139 uint16_t file_header_size = 0x40;
141 std::array<char, 6> linker_version;
143 enum file_type : uint8_t
144 {
149 };
153 uint32_t entry_point;
155 uint16_t stack_size;
156 // TODO: exact meaning
157 uint16_t allocation_length;
159 std::vector<std::unique_ptr<MemoryBlock>> blocks;
160
161 CMDFormat(int type = TYPE_CMD)
163 {
164 }
165
166 void ReadFile(Linker::Reader& rd) override;
167
169 offset_t WriteFile(Linker::Writer& wr) const override;
170
171 void Dump(Dumper::Dumper& dump) const override;
172
173 void CalculateValues() override;
174
176 std::string GetDefaultExtension(Linker::Module& module, std::string filename) const override;
177
178 const LoadBlock * GetLoadBlockById(uint32_t block_id) const;
179 LoadBlock * GetLoadBlockById(uint32_t block_id);
180 };
181}
182
183#endif /* PCOS_H */
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.
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
virtual std::string GetDefaultExtension(Module &module, std::string filename) const
Appends a default extension to the filename.
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
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15
Definition pcos.h:79
std::shared_ptr< Linker::Image > image
The memory resident part of the block.
Definition pcos.h:89
void WriteFile(Linker::Writer &wr) const override
Writes the contents of the block to the file, including the type and length fields.
Definition pcos.cc:93
void ReadFile(Linker::Reader &rd, uint16_t length) override
Fills the contents of this object.
Definition pcos.cc:87
void AddFields(Dumper::Region &region, const CMDFormat &module) const override
Adds block specific fields.
Definition pcos.cc:105
std::unique_ptr< Dumper::Region > MakeRegion(std::string name, offset_t offset, unsigned display_width) const override
Creates a region for displaying the block contents.
Definition pcos.cc:100
uint32_t block_id
The first 4 bytes of the block.
Definition pcos.h:87
uint16_t GetLength() const override
The length of the block, not including the type and length fields.
Definition pcos.cc:82
Represents a block of data in the file, also an end-of-block object is an instance of this type.
Definition pcos.h:32
virtual void ReadFile(Linker::Reader &rd, uint16_t length)
Fills the contents of this object.
Definition pcos.cc:17
virtual void AddFields(Dumper::Region &region, const CMDFormat &module) const
Adds block specific fields.
Definition pcos.cc:58
virtual std::unique_ptr< Dumper::Region > MakeRegion(std::string name, offset_t offset, unsigned display_width) const
Creates a region for displaying the block contents.
Definition pcos.cc:53
virtual uint16_t GetLength() const
The length of the block, not including the type and length fields.
Definition pcos.cc:12
virtual void DumpContents(Dumper::Dumper &dump, offset_t file_offset, const CMDFormat &module) const
Display block specific contents.
Definition pcos.cc:62
block_type
Every block has a type field.
Definition pcos.h:36
@ TYPE_END
Terminating block, must be the final one.
Definition pcos.h:44
@ TYPE_LOAD
A block of data to be loaded into memory.
Definition pcos.h:38
@ TYPE_SEGMENT_RELOCATION
A sequence of fixups for 16-bit memory segments.
Definition pcos.h:42
@ TYPE_OFFSET_RELOCATION
A sequence of fixups for 16-bit memory offsets.
Definition pcos.h:40
virtual void WriteFile(Linker::Writer &wr) const
Writes the contents of the block to the file, including the type and length fields.
Definition pcos.cc:21
void Dump(Dumper::Dumper &dump, offset_t file_offset, const CMDFormat &module) const
Displays the entire block.
Definition pcos.cc:66
block_type type
The type of the block.
Definition pcos.h:47
A block containing a sequence of relocations between two blocks, either the offset or segment parts.
Definition pcos.h:100
uint8_t target
The block referenced.
Definition pcos.h:105
void DumpContents(Dumper::Dumper &dump, offset_t file_offset, const CMDFormat &module) const override
Display block specific contents.
Definition pcos.cc:157
uint16_t GetLength() const override
The length of the block, not including the type and length fields.
Definition pcos.cc:125
std::vector< uint16_t > offsets
Sequence of offsets to 16-bit words that must be relocated.
Definition pcos.h:107
void AddFields(Dumper::Region &region, const CMDFormat &module) const override
Adds block specific fields.
Definition pcos.cc:151
void WriteFile(Linker::Writer &wr) const override
Writes the contents of the block to the file, including the type and length fields.
Definition pcos.cc:140
void ReadFile(Linker::Reader &rd, uint16_t length) override
Fills the contents of this object.
Definition pcos.cc:130
uint8_t source
The block where these relocations must be applied.
Definition pcos.h:103
Represents the contents of a block whose format is not known or implemented.
Definition pcos.h:123
void ReadFile(Linker::Reader &rd, uint16_t length) override
Fills the contents of this object.
Definition pcos.cc:175
void WriteFile(Linker::Writer &wr) const override
Writes the contents of the block to the file, including the type and length fields.
Definition pcos.cc:180
std::unique_ptr< Dumper::Region > MakeRegion(std::string name, offset_t offset, unsigned display_width) const override
Creates a region for displaying the block contents.
Definition pcos.cc:186
uint16_t GetLength() const override
The length of the block, not including the type and length fields.
Definition pcos.cc:170
Olivetti M20 PCOS cmd/sav executable file format.
Definition pcos.h:26
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition pcos.cc:191
file_type type
Type of executable.
Definition pcos.h:151
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition pcos.cc:236
std::vector< std::unique_ptr< MemoryBlock > > blocks
Sequence of blocks to be loaded.
Definition pcos.h:159
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition pcos.cc:265
uint16_t file_header_size
Size of header, following the first 3 bytes.
Definition pcos.h:139
file_type
Executable types.
Definition pcos.h:144
@ TYPE_CMD
Executable which gets unloaded after execution.
Definition pcos.h:146
@ TYPE_SAV
Executable that is kept resident in memory.
Definition pcos.h:148
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition pcos.cc:213
uint16_t stack_size
Size of stack.
Definition pcos.h:155
std::string GetDefaultExtension(Linker::Module &module, std::string filename) const override
Appends a default extension to the filename.
Definition pcos.cc:270
std::array< char, 6 > linker_version
String field following the first 7 bytes.
Definition pcos.h:141
uint32_t entry_point
24-bit entry point, memory block and offset
Definition pcos.h:153