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 "../linker/linker.h"
9#include "../linker/module.h"
10#include "../linker/segment.h"
11#include "../linker/writer.h"
12
13namespace DigitalResearch
14{
19 {
20 public:
21 /* * * General members * * */
22
26 class Segment
27 {
28 public:
32 uint8_t number = 0xFF;
37 {
38 BSS = 1,
39 STACK,
40 CODE,
41 RODATA,
42 DATA,
43 MIXED,
44 MIXED_PROTECTABLE,
45 };
53 uint16_t length = 0;
57 std::shared_ptr<Linker::Writable> image = nullptr;
58
59 void Clear();
60
61 bool IsPresent() const;
62 };
63
95
96 struct Symbol
97 {
98 /* TODO */
99 };
100
101 enum magic_type
102 {
103 MAGIC_SEGMENTED_OBJECT = 0xEE00,
104 MAGIC_SEGMENTED = 0xEE01,
105 MAGIC_NONSHARED_OBJECT = 0xEE02,
106 MAGIC_NONSHARED = 0xEE03,
107 MAGIC_SHARED_OBJECT = 0xEE06,
108 MAGIC_SHARED = 0xEE07,
109 MAGIC_SPLIT_OBJECT = 0xEE0A,
110 MAGIC_SPLIT = 0xEE0B,
111 };
112
114 char signature[2];
116 uint16_t segment_count = 0;
118 uint32_t total_size = 0;
120 uint32_t relocation_size = 0;
122 uint32_t symbol_table_size = 0;
123
124 std::vector<Segment> segments;
125 std::vector<Relocation> relocations;
126 std::vector<Symbol> symbols;
127
128 magic_type GetSignature() const;
129
130 void SetSignature(magic_type magic);
131
132 void Clear() override;
133
134 CPM8KFormat(magic_type magic = MAGIC_NONSHARED)
135 {
136 SetSignature(magic);
137 }
138
139 void ReadFile(Linker::Reader& rd) override;
140
141 void WriteFile(Linker::Writer& wr) override;
142
143 void Dump(Dumper::Dumper& dump) override;
144
145 void CalculateValues() override;
146
147 /* * * Writer members * * */
148
150 std::shared_ptr<Linker::Segment> bss_segment;
151
152 bool FormatSupportsSegmentation() const override;
153
154 std::vector<std::shared_ptr<Linker::Segment>>& Segments();
155
156 unsigned GetSegmentNumber(std::shared_ptr<Linker::Segment> segment);
157
158 using LinkerManager::SetLinkScript;
159
160 void SetOptions(std::map<std::string, std::string>& options) override;
161
162 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
163
164 bool IsCombined();
165
166 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
167
168 void Link(Linker::Module& module);
169
170 void ProcessModule(Linker::Module& module) override;
171
172 void GenerateFile(std::string filename, Linker::Module& module) override;
173
174 std::string GetDefaultExtension(Linker::Module& module, std::string filename) override;
175 };
176}
177
178#endif /* CPM8K_H */
Represents a segment within the module.
Definition cpm8k.h:27
segment_type
The type of a segment.
Definition cpm8k.h:37
std::shared_ptr< Linker::Writable > image
Storage for segment.
Definition cpm8k.h:57
segment_type type
The type of the segment.
Definition cpm8k.h:49
uint8_t number
Each segment has an associated number. For 0xFF, the linker can assign a value. For segmented executa...
Definition cpm8k.h:32
uint16_t length
Length of segment in bytes.
Definition cpm8k.h:53
CP/M-8000 .z8k file format.
Definition cpm8k.h:19
char signature[2]
The magic number at the beginning of the executable file.
Definition cpm8k.h:114
bool FormatSupportsSegmentation() const override
Whether the format supports multiple segments.
Definition cpm8k.cc:146
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition cpm8k.cc:95
uint32_t total_size
Total number of bytes in all the segments combined.
Definition cpm8k.h:118
uint16_t segment_count
Number of segments in the segment_array.
Definition cpm8k.h:116
std::string GetDefaultExtension(Linker::Module &module, std::string filename) override
Appends a default extension to the filename.
Definition cpm8k.cc:435
uint32_t relocation_size
Total size of relocations.
Definition cpm8k.h:120
uint32_t symbol_table_size
Total size of symbols.
Definition cpm8k.h:122
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition cpm8k.cc:61
void Clear() override
Resets all fields to their default values, deallocate memory.
Definition cpm8k.cc:51
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition cpm8k.cc:425
void Dump(Dumper::Dumper &dump) override
Display file contents in a nice manner.
Definition cpm8k.cc:123
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition cpm8k.cc:128
std::shared_ptr< Linker::Segment > bss_segment
Segment to collect bss.
Definition cpm8k.h:150
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition cpm8k.cc:167
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition cpm8k.cc:378
A class to control the output of a file analysis.
Definition dumper.h:550
A helper class to collect sections into segments.
Definition linker.h:19
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:20
A class that provides a general interface to setting up generation for a format.
Definition format.h:56
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
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:73
@ SEG_LONG_SEGMENTED
A 32-bit segmented address of segment.
Definition cpm8k.h:77
@ SEG_SHORT_SEGMENTED
A 16-bit segmented address of segment.
Definition cpm8k.h:75
@ EXT_LONG_SEGMENTED
A 32-bit segmented address of external item.
Definition cpm8k.h:83
@ EXT_SHORT_SEGMENTED
A 16-bit segmented address of external item.
Definition cpm8k.h:81
@ EXT_OFFSET
A 16-bit offset to external item.
Definition cpm8k.h:79
uint8_t segment
The source segment of the relocation.
Definition cpm8k.h:69
uint16_t offset
Source offset of relocation.
Definition cpm8k.h:89
uint16_t target
The segment or symbol number that the relocation references.
Definition cpm8k.h:93