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 int GetDisplayOptions() const;
63 virtual std::unique_ptr<Dumper::Region> MakeRegion(std::string name, offset_t offset, unsigned display_width) const;
65 virtual void AddFields(Dumper::Region& region, const CMDFormat& module) const;
67 virtual void DumpContents(Dumper::Dumper& dump, offset_t file_offset, const CMDFormat& module) const;
69 void Dump(Dumper::Dumper& dump, offset_t file_offset, const CMDFormat& module) const;
70
72 static std::unique_ptr<MemoryBlock> ReadFile(Linker::Reader& rd);
73
74 explicit MemoryBlock(int type)
76 {
77 }
78 };
79
80 class LoadBlock : public MemoryBlock
81 {
82 public:
83 LoadBlock()
85 {
86 }
87
89 uint32_t block_id;
91 std::shared_ptr<Linker::Contents> image;
92
93 uint16_t GetLength() const override;
94 void ReadFile(Linker::Reader& rd, uint16_t length) override;
95 void WriteFile(Linker::Writer& wr) const override;
96 int GetDisplayOptions() const override;
97 std::unique_ptr<Dumper::Region> MakeRegion(std::string name, offset_t offset, unsigned display_width) const override;
98 void AddFields(Dumper::Region& region, const CMDFormat& module) const override;
99 };
100
103 {
104 public:
106 uint8_t source = 0;
108 uint8_t target = 0;
110 std::vector<uint16_t> offsets;
111
114 {
115 }
116
117 uint16_t GetLength() const override;
118 void ReadFile(Linker::Reader& rd, uint16_t length) override;
119 void WriteFile(Linker::Writer& wr) const override;
120 int GetDisplayOptions() const override;
121 void AddFields(Dumper::Region& region, const CMDFormat& module) const override;
122 void DumpContents(Dumper::Dumper& dump, offset_t file_offset, const CMDFormat& module) const override;
123 };
124
127 {
128 public:
129 UnknownBlock(int type)
131 {
132 }
133
134 std::shared_ptr<Linker::Contents> image;
135
136 uint16_t GetLength() const override;
137 void ReadFile(Linker::Reader& rd, uint16_t length) override;
138 void WriteFile(Linker::Writer& wr) const override;
139 std::unique_ptr<Dumper::Region> MakeRegion(std::string name, offset_t offset, unsigned display_width) const override;
140 };
141
143 uint16_t file_header_size = 0x40;
145 std::array<char, 6> linker_version;
147 enum file_type : uint8_t
148 {
153 };
157 uint32_t entry_point;
159 uint16_t stack_size;
160 // TODO: exact meaning
161 uint16_t allocation_length;
163 std::vector<std::unique_ptr<MemoryBlock>> blocks;
164
165 CMDFormat(int type = TYPE_CMD)
167 {
168 }
169
170 void ReadFile(Linker::Reader& rd) override;
171
173 offset_t WriteFile(Linker::Writer& wr) const override;
174
175 void Dump(Dumper::Dumper& dump) const override;
176
177 void CalculateValues() override;
178
180 std::string GetDefaultExtension(Linker::Module& module, std::string filename) const override;
181
182 const LoadBlock * GetLoadBlockById(uint32_t block_id) const;
183 LoadBlock * GetLoadBlockById(uint32_t block_id);
184 };
185}
186
187#endif /* PCOS_H */
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:828
A record that represents a region within the file.
Definition dumper.h:721
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:20
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:81
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:100
void ReadFile(Linker::Reader &rd, uint16_t length) override
Fills the contents of this object.
Definition pcos.cc:94
void AddFields(Dumper::Region &region, const CMDFormat &module) const override
Adds block specific fields.
Definition pcos.cc:117
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:112
uint32_t block_id
The first 4 bytes of the block.
Definition pcos.h:89
int GetDisplayOptions() const override
Filters for display.
Definition pcos.cc:107
uint16_t GetLength() const override
The length of the block, not including the type and length fields.
Definition pcos.cc:89
std::shared_ptr< Linker::Contents > image
The memory resident part of the block.
Definition pcos.h:91
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:63
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:58
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:67
virtual int GetDisplayOptions() const
Filters for display.
Definition pcos.cc:53
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:71
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:103
uint8_t target
The block referenced.
Definition pcos.h:108
void DumpContents(Dumper::Dumper &dump, offset_t file_offset, const CMDFormat &module) const override
Display block specific contents.
Definition pcos.cc:174
uint16_t GetLength() const override
The length of the block, not including the type and length fields.
Definition pcos.cc:137
std::vector< uint16_t > offsets
Sequence of offsets to 16-bit words that must be relocated.
Definition pcos.h:110
int GetDisplayOptions() const override
Filters for display.
Definition pcos.cc:152
void AddFields(Dumper::Region &region, const CMDFormat &module) const override
Adds block specific fields.
Definition pcos.cc:168
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:157
void ReadFile(Linker::Reader &rd, uint16_t length) override
Fills the contents of this object.
Definition pcos.cc:142
uint8_t source
The block where these relocations must be applied.
Definition pcos.h:106
Represents the contents of a block whose format is not known or implemented.
Definition pcos.h:127
void ReadFile(Linker::Reader &rd, uint16_t length) override
Fills the contents of this object.
Definition pcos.cc:192
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:197
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:203
uint16_t GetLength() const override
The length of the block, not including the type and length fields.
Definition pcos.cc:187
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:208
file_type type
Type of executable.
Definition pcos.h:155
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition pcos.cc:253
std::vector< std::unique_ptr< MemoryBlock > > blocks
Sequence of blocks to be loaded.
Definition pcos.h:163
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition pcos.cc:284
uint16_t file_header_size
Size of header, following the first 3 bytes.
Definition pcos.h:143
file_type
Executable types.
Definition pcos.h:148
@ TYPE_CMD
Executable which gets unloaded after execution.
Definition pcos.h:150
@ TYPE_SAV
Executable that is kept resident in memory.
Definition pcos.h:152
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition pcos.cc:230
uint16_t stack_size
Size of stack.
Definition pcos.h:159
std::string GetDefaultExtension(Linker::Module &module, std::string filename) const override
Appends a default extension to the filename.
Definition pcos.cc:289
std::array< char, 6 > linker_version
String field following the first 7 bytes.
Definition pcos.h:145
uint32_t entry_point
24-bit entry point, memory block and offset
Definition pcos.h:157