RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
cpm8k.h
1#ifndef CPM8K_H
2#define CPM8K_H
3
4#include <map>
5#include <set>
6#include <string>
7#include "../common.h"
8#include "../dumper/dumper.h"
9#include "../linker/module.h"
10#include "../linker/segment.h"
11#include "../linker/segment_manager.h"
12#include "../linker/writer.h"
13
14namespace DigitalResearch
15{
19 class CPM8KFormat : public virtual Linker::SegmentManager
20 {
21 public:
22 /* * * General members * * */
23
27 class Segment
28 {
29 public:
33 uint8_t number = 0xFF;
38 {
39 BSS = 1,
40 STACK,
41 CODE,
42 RODATA,
43 DATA,
44 MIXED,
45 MIXED_PROTECTABLE,
46 };
54 uint16_t length = 0;
58 std::shared_ptr<Linker::Image> image = nullptr;
59
60 void Clear();
61
62 bool IsPresent() const;
63 };
64
96
97 struct Symbol
98 {
99 /* TODO */
100 };
101
102 enum magic_type
103 {
104 MAGIC_SEGMENTED_OBJECT = 0xEE00,
105 MAGIC_SEGMENTED = 0xEE01,
106 MAGIC_NONSHARED_OBJECT = 0xEE02,
107 MAGIC_NONSHARED = 0xEE03,
108 MAGIC_SHARED_OBJECT = 0xEE06,
109 MAGIC_SHARED = 0xEE07,
110 MAGIC_SPLIT_OBJECT = 0xEE0A,
111 MAGIC_SPLIT = 0xEE0B,
112 };
113
115 char signature[2];
117 uint16_t segment_count = 0;
119 uint32_t total_size = 0;
121 uint32_t relocation_size = 0;
123 uint32_t symbol_table_size = 0;
124
125 std::vector<Segment> segments;
126 std::vector<Relocation> relocations;
127 std::vector<Symbol> symbols;
128
129 magic_type GetSignature() const;
130
131 void SetSignature(magic_type magic);
132
133 void Clear() override;
134
135 CPM8KFormat(magic_type magic = MAGIC_NONSHARED)
136 {
137 SetSignature(magic);
138 }
139
140 void ReadFile(Linker::Reader& rd) override;
141
142 offset_t ImageSize() const override;
143
145 offset_t WriteFile(Linker::Writer& wr) const override;
146
147 void Dump(Dumper::Dumper& dump) const override;
148
149 void CalculateValues() override;
150
151 /* * * Writer members * * */
152
154 std::shared_ptr<Linker::Segment> bss_segment;
155
156 bool FormatSupportsSegmentation() const override;
157
158 std::vector<std::shared_ptr<Linker::Segment>>& Segments();
159
160 unsigned GetSegmentNumber(std::shared_ptr<Linker::Segment> segment);
161
162 void SetOptions(std::map<std::string, std::string>& options) override;
163
164 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
165
166 bool IsCombined() const;
167
168 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
169
170 void Link(Linker::Module& module);
171
172 void ProcessModule(Linker::Module& module) override;
173
174 void GenerateFile(std::string filename, Linker::Module& module) override;
175
177 std::string GetDefaultExtension(Linker::Module& module, std::string filename) const override;
178 };
179}
180
181#endif /* CPM8K_H */
Represents a segment within the module.
Definition cpm8k.h:28
segment_type
The type of a segment.
Definition cpm8k.h:38
std::shared_ptr< Linker::Image > image
Storage for segment.
Definition cpm8k.h:58
segment_type type
The type of the segment.
Definition cpm8k.h:50
uint8_t number
Each segment has an associated number. For 0xFF, the linker can assign a value. For segmented executa...
Definition cpm8k.h:33
uint16_t length
Length of segment in bytes.
Definition cpm8k.h:54
CP/M-8000 .z8k file format.
Definition cpm8k.h:20
char signature[2]
The magic number at the beginning of the executable file.
Definition cpm8k.h:115
bool FormatSupportsSegmentation() const override
Whether the format supports multiple segments.
Definition cpm8k.cc:176
uint32_t total_size
Total number of bytes in all the segments combined.
Definition cpm8k.h:119
uint16_t segment_count
Number of segments in the segment_array.
Definition cpm8k.h:117
std::string GetDefaultExtension(Linker::Module &module, std::string filename) const override
Appends a default extension to the filename.
Definition cpm8k.cc:465
uint32_t relocation_size
Total size of relocations.
Definition cpm8k.h:121
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition cpm8k.cc:147
uint32_t symbol_table_size
Total size of symbols.
Definition cpm8k.h:123
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition cpm8k.cc:65
void Clear() override
Resets all fields to their default values, deallocate memory.
Definition cpm8k.cc:55
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition cpm8k.cc:117
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition cpm8k.cc:455
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition cpm8k.cc:158
std::shared_ptr< Linker::Segment > bss_segment
Segment to collect bss.
Definition cpm8k.h:154
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition cpm8k.cc:197
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition cpm8k.cc:408
offset_t ImageSize() const override
Retrieves size of stored data.
Definition cpm8k.cc:99
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:586
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
@ SEG_OFFSET
A 16-bit offset to segment.
Definition cpm8k.h:74
@ SEG_LONG_SEGMENTED
A 32-bit segmented address of segment.
Definition cpm8k.h:78
@ SEG_SHORT_SEGMENTED
A 16-bit segmented address of segment.
Definition cpm8k.h:76
@ EXT_LONG_SEGMENTED
A 32-bit segmented address of external item.
Definition cpm8k.h:84
@ EXT_SHORT_SEGMENTED
A 16-bit segmented address of external item.
Definition cpm8k.h:82
@ EXT_OFFSET
A 16-bit offset to external item.
Definition cpm8k.h:80
uint8_t segment
The source segment of the relocation.
Definition cpm8k.h:70
uint16_t offset
Source offset of relocation.
Definition cpm8k.h:90
uint16_t target
The segment or symbol number that the relocation references.
Definition cpm8k.h:94