RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
cpm68k.h
1#ifndef CPM68K_H
2#define CPM68K_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#include "../dumper/dumper.h"
13
14namespace DigitalResearch
15{
27 {
28 public:
29 /* * * General members * * */
30
35 {
47 MAGIC_CRUNCHED, /* Concurrent DOS 68K only */
48 };
49
51 char signature[2] = { 0x60, 0x1A };
52
56 uint32_t code_size = 0;
60 uint32_t data_size = 0;
64 uint32_t bss_size = 0;
68 uint32_t symbol_table_size = 0;
72 uint32_t stack_size = 0;
73
77 uint32_t code_address = 0;
81 uint32_t program_flags = 0; /* TODO: make parameter */
82
90 uint32_t data_address = 0;
94 uint32_t bss_address = 0;
98 offset_t file_size = 0;
99
103 std::shared_ptr<Linker::Writable> code = nullptr;
107 std::shared_ptr<Linker::Writable> data = nullptr;
108
109 /* filled in automatically */
111 {
115 size_t size;
119 unsigned segment;
120 operator size_t() const;
121 };
125 std::map<uint32_t, Relocation> relocations;
126
127 magic_type GetSignature() const;
128
129 void SetSignature(magic_type magic);
130
161
166
167 void Clear() override;
168
170 : system(system)
171 {
172 }
173
175 : system(system)
176 {
177 SetSignature(magic);
178 }
179
180 void ReadFile(Linker::Reader& rd) override;
181
182 template <typename SizeType>
183 static void CDOS68K_WriteRelocations(Linker::Writer& wr, std::map<uint32_t, SizeType> relocations)
184 {
185 /* TODO: test */
186 offset_t last_relocation = 0;
187 for(auto it : relocations)
188 {
189 offset_t difference = it.first - last_relocation;
190 uint8_t highbit = it.second/*.size*/ == 2 ? 0x80 : 0x00;
191 if(difference != 0 && difference <= 0x7C)
192 {
193 wr.WriteWord(1, highbit | difference);
194 }
195 else if(difference < 0x100)
196 {
197 wr.WriteWord(1, highbit | 0x7D);
198 wr.WriteWord(1, difference);
199 }
200 else if(difference < 0x10000)
201 {
202 wr.WriteWord(1, highbit | 0x7E);
203 wr.WriteWord(2, difference);
204 }
205 else
206 {
207 wr.WriteWord(1, highbit | 0x7F);
208 wr.WriteWord(4, difference);
209 }
210 }
211 }
212
213 void WriteFile(Linker::Writer& wr) override;
214
215 void Dump(Dumper::Dumper& dump) override;
216
217 void CalculateValues() override;
218
219 /* * * Writer members * * */
220
225
227 std::shared_ptr<Linker::Segment> bss_segment;
229 std::shared_ptr<Linker::Segment> stack_segment;
230
232 std::shared_ptr<Linker::Segment> CodeSegment();
233
235 std::shared_ptr<Linker::Segment> DataSegment();
236
237 unsigned FormatAdditionalSectionFlags(std::string section_name) const override;
238
239 using LinkerManager::SetLinkScript;
240
241 void SetOptions(std::map<std::string, std::string>& options) override;
242
243 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
244
245 void CreateDefaultSegments();
246
247 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
248
249 void Link(Linker::Module& module);
250
251 void ProcessModule(Linker::Module& module) override;
252
253 void GenerateFile(std::string filename, Linker::Module& module) override;
254
255 std::string GetDefaultExtension(Linker::Module& module, std::string filename) override;
256 };
257
258}
259
260#endif /* CPM68K_H */
The native executable format for the Motorola 68000 port of CP/M.
Definition cpm68k.h:27
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition cpm68k.cc:881
offset_t file_size
Size of entire file, not used for generation.
Definition cpm68k.h:98
void OnNewSegment(std::shared_ptr< Linker::Segment > segment) override
Callback function when allocating a new segment When the linker script runs, it creates segments cons...
Definition cpm68k.cc:617
uint32_t stack_size
Size of the stack segment. Only used by Concurrent DOS 68K.
Definition cpm68k.h:72
uint32_t code_address
Load address of the code/text segment. Not used by GEMDOS which stores the program flags at this offs...
Definition cpm68k.h:77
std::shared_ptr< Linker::Segment > bss_segment
Segment to collect bss.
Definition cpm68k.h:227
uint32_t bss_size
Size of the uninitialized data (bss) segment. Human68k includes the stack in it.
Definition cpm68k.h:64
std::string GetDefaultExtension(Linker::Module &module, std::string filename) override
Appends a default extension to the filename.
Definition cpm68k.cc:903
std::shared_ptr< Linker::Segment > CodeSegment()
Return code segment (if it exists)
Definition cpm68k.cc:523
uint32_t program_flags
Program flags, used by GEMDOS.
Definition cpm68k.h:81
uint32_t bss_address
Load address of the uninitialized data (bss) segment. Only relevant for non-contiguous executables (C...
Definition cpm68k.h:94
std::map< uint32_t, Relocation > relocations
Relocations, not used for Human68k.
Definition cpm68k.h:125
bool option_no_relocation
Makes sure no relocations are placed into the output file.
Definition cpm68k.h:224
uint16_t relocations_suppressed
Set to a non-0 value when relocations are suppressed. Typically this can be 1, but Human68k specifica...
Definition cpm68k.h:86
magic_type
Represents the magic number at the beginning of the executable file.
Definition cpm68k.h:35
@ MAGIC_CONTIGUOUS
Contiguous executables (magic value 0x601A in big endian) must load the code, data,...
Definition cpm68k.h:39
@ MAGIC_CRUNCHED
Contiguous executables with crunched relocations (magic value 0x601C in big endian),...
Definition cpm68k.h:47
@ MAGIC_NONCONTIGUOUS
Non-contiguous executables (magic value 0x601B in big endian) can load the code, data,...
Definition cpm68k.h:43
std::shared_ptr< Linker::Segment > stack_segment
Segment to collect stack (Concurrent DOS 68K only)
Definition cpm68k.h:229
void Clear() override
Resets all fields to their default values, deallocate memory.
Definition cpm68k.cc:44
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition cpm68k.cc:545
system_type system
The system which will load the executable.
Definition cpm68k.h:165
std::shared_ptr< Linker::Segment > DataSegment()
Return data segment (if it exists)
Definition cpm68k.cc:528
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition cpm68k.cc:495
void Dump(Dumper::Dumper &dump) override
Display file contents in a nice manner.
Definition cpm68k.cc:397
system_type
Different systems have different relocation formats and expectations as to what segments should be pr...
Definition cpm68k.h:135
@ SYSTEM_GEMDOS
Digital Research GEMDOS, Atari TOS, only contiguous, text load address field replaced by program fiel...
Definition cpm68k.h:151
@ SYSTEM_UNKNOWN
Unknown system: use GEMDOS with no relocations.
Definition cpm68k.h:139
@ SYSTEM_CDOS68K
Digital Research Concurrent DOS 68K, non-contiguous not allowed, but relocations can be in CP/M-68K f...
Definition cpm68k.h:159
@ SYSTEM_GEMDOS_EARLY
Digital Research GEMDOS, only contiguous, relocations always present, header is an unusual 0x1E bytes...
Definition cpm68k.h:147
@ SYSTEM_HUMAN68K
Sharp Corporation & Hudson Soft Human68k .z executable, only contiguous, no relocations or symbol tab...
Definition cpm68k.h:155
@ SYSTEM_CPM68K
Digital Research CP/M-68K, uses CP/M-68K relocations.
Definition cpm68k.h:143
uint32_t code_size
Size of the code/text segment.
Definition cpm68k.h:56
char signature[2]
The magic number at the beginning of the executable file, one of 0x601A (contiguous),...
Definition cpm68k.h:51
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition cpm68k.cc:784
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition cpm68k.cc:55
std::shared_ptr< Linker::Writable > code
Storage for code segment.
Definition cpm68k.h:103
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition cpm68k.cc:295
uint32_t symbol_table_size
Size of the symbol table.
Definition cpm68k.h:68
std::shared_ptr< Linker::Writable > data
Storage for data segment.
Definition cpm68k.h:107
uint32_t data_size
Size of the initialized data segment.
Definition cpm68k.h:60
uint32_t data_address
Load address of the initialized data segment. Only relevant for non-contiguous executables (CP/M-68K)...
Definition cpm68k.h:90
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
void WriteWord(size_t bytes, uint64_t value, EndianType endiantype)
Read a word.
Definition writer.cc:65
unsigned segment
Segment value, as required by CP/M-68K, they take the value that is stored in file: 1 for data,...
Definition cpm68k.h:119
size_t size
Size of value to relocate.
Definition cpm68k.h:115