RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
bwexp.h
1#ifndef BWEXP_H
2#define BWEXP_H
3
4#include "../common.h"
5#include "../linker/linker.h"
6#include "mzexe.h"
7
8namespace DOS16M
9{
14 {
15 public:
16 void ReadFile(Linker::Reader& rd) override;
17
18 bool FormatSupportsSegmentation() const override;
19
20 bool FormatIs16bit() const override;
21
22 unsigned FormatAdditionalSectionFlags(std::string section_name) const override;
23
25 {
26 public:
27 enum access_type
28 {
29 TYPE_DATA = 0x92,
30 TYPE_CODE = 0x9A,
31 };
32 access_type access;
33
34 enum flag_type
35 {
36 FLAG_EMPTY = 0x2000,
37 FLAG_TRANSPARENT = 0x8000,
38 };
39 flag_type flags;
40
41 uint32_t address = 0;
42 uint32_t total_length;
43
44 AbstractSegment(unsigned access = TYPE_DATA, unsigned flags = 0, uint32_t total_length = 0)
45 : access((access_type)access), flags((flag_type)flags), total_length(total_length)
46 {
47 }
48
52 uint32_t GetTotalSize();
53
57 virtual void SetTotalSize(uint32_t new_value);
58
62 virtual uint32_t GetSize(BWFormat& bw) = 0;
66 virtual void WriteContent(Linker::Writer& wr, BWFormat& bw) = 0;
67
71 void WriteHeader(Linker::Writer& wr, BWFormat& bw);
72 };
73
74 class Segment : public AbstractSegment
75 {
76 public:
77 std::shared_ptr<Linker::Segment> image;
78
79 Segment(std::shared_ptr<Linker::Segment> segment, unsigned access = TYPE_DATA, unsigned flags = 0)
80 : AbstractSegment(access, flags, segment->TotalSize()), image(segment)
81 {
82 }
83
84 void SetTotalSize(uint32_t new_value) override;
85
86 uint32_t GetSize(BWFormat& bw) override;
87
88 void WriteContent(Linker::Writer& wr, BWFormat& bw) override;
89 };
90
92 {
93 public:
94 DummySegment(uint32_t total_length, unsigned access = TYPE_DATA, unsigned flags = 0)
95 : AbstractSegment(access, flags, total_length)
96 {
97 }
98
99 void SetTotalSize(uint32_t new_value) override;
100
101 uint32_t GetSize(BWFormat& bw) override;
102
103 void WriteContent(Linker::Writer& wr, BWFormat& bw) override;
104 };
105
107 {
108 public:
109 uint16_t index;
110
111 RelocationSegment(uint16_t index)
112 : AbstractSegment(TYPE_DATA), index(index)
113 {
114 }
115
119 void SetTotalSize(uint32_t new_value) override;
120
121 uint32_t GetSize(BWFormat& bw) override;
122
123 void WriteContent(Linker::Writer& wr, BWFormat& bw) override;
124 };
125
130 {
131 RelocationsNone,
132 RelocationsType1,
133 RelocationsType2,
134 };
135 relocations_type option_relocations = RelocationsType2;
136 bool option_force_relocations = true;
137
138 enum exp_flag_type
139 {
140 EXP_FLAG_RELOCATABLE = 0x0001,
141 };
142 exp_flag_type exp_flags = exp_flag_type(0);
143
144 enum option_type
145 {
146 OPTION_RELOCATIONS = 0x1000,
147 };
148 option_type options = option_type(0);
149
150 std::map<uint16_t, std::set<uint16_t> > relocations;
151
152 offset_t MeasureRelocations();
153
154 using LinkerManager::SetLinkScript;
155
156 void SetOptions(std::map<std::string, std::string>& options) override;
157
158 offset_t file_size = 0;
159 offset_t min_extra = 0;
160 offset_t max_extra = 0;
161 uint16_t ss = 0, sp = 0, cs = 0, ip = 0, relocsel = 0;
162 uint16_t runtime_gdt_length = 0xFFFF;
163 uint16_t version = 0;
164 uint32_t next_header_offset = 0;
165 uint32_t debug_info_offset = 0; /* TODO: ??? */
166 uint16_t first_selector = 0x0080; /* TODO: make dynamic */
167 uint32_t private_xm = 0; /* TODO: make parameter */
168 uint16_t ext_reserve = 0; /* TODO: ??? */
169 uint16_t transparent_stack = 0; /* TODO: ??? */
170 uint32_t program_size = 0; /* TODO: ??? */
171 uint8_t default_memory_strategy = 0; /* TODO: ??? */
172 uint16_t transfer_buffer_size = 0; /* TODO: ??? */
173 std::string exp_name; /* TODO: ??? */
174
175 std::vector<std::unique_ptr<AbstractSegment>> segments;
176 std::map<std::shared_ptr<Linker::Segment>, size_t> segment_indices;
177 int default_data = 0;
178
179 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
180
181 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
182
183 void Link(Linker::Module& module);
184
185 size_t GetDefaultDataIndex();
186
187 void ProcessModule(Linker::Module& module) override;
188
189 void CalculateValues() override;
190
191 void WriteFile(Linker::Writer& wr) override;
192
193 std::string GetDefaultExtension(Linker::Module& module, std::string filename) override;
194 };
195}
196
197#endif /* BWEXP_H */
uint32_t GetTotalSize()
Retrieves the total size of the segment, including the bss.
Definition bwexp.cc:33
virtual void SetTotalSize(uint32_t new_value)
Modifies the total size of the segment, including the bss. Note that this is not guaranteed to work f...
Definition bwexp.cc:38
virtual void WriteContent(Linker::Writer &wr, BWFormat &bw)=0
Produces the binary contents of the segment.
virtual uint32_t GetSize(BWFormat &bw)=0
Retrieves size of segment. Some subclasses might calculate this dynamically.
void WriteHeader(Linker::Writer &wr, BWFormat &bw)
Produces the GDT entry for the header.
Definition bwexp.cc:50
Definition bwexp.h:92
void SetTotalSize(uint32_t new_value) override
Modifies the total size of the segment, including the bss. Note that this is not guaranteed to work f...
Definition bwexp.cc:82
uint32_t GetSize(BWFormat &bw) override
Retrieves size of segment. Some subclasses might calculate this dynamically.
Definition bwexp.cc:87
void WriteContent(Linker::Writer &wr, BWFormat &bw) override
Produces the binary contents of the segment.
Definition bwexp.cc:92
void WriteContent(Linker::Writer &wr, BWFormat &bw) override
Produces the binary contents of the segment.
Definition bwexp.cc:122
uint32_t GetSize(BWFormat &bw) override
Retrieves size of segment. Some subclasses might calculate this dynamically.
Definition bwexp.cc:101
void SetTotalSize(uint32_t new_value) override
Invalid call, the size of a relocation segment is calculated dynamically and cannot be changed via a ...
Definition bwexp.cc:96
Definition bwexp.h:75
void WriteContent(Linker::Writer &wr, BWFormat &bw) override
Produces the binary contents of the segment.
Definition bwexp.cc:74
uint32_t GetSize(BWFormat &bw) override
Retrieves size of segment. Some subclasses might calculate this dynamically.
Definition bwexp.cc:69
void SetTotalSize(uint32_t new_value) override
Modifies the total size of the segment, including the bss. Note that this is not guaranteed to work f...
Definition bwexp.cc:63
Rational Systems DOS/16M "BW" .exp file.
Definition bwexp.h:14
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition bwexp.cc:360
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition bwexp.cc:207
relocations_type
BW .exp files support two versions of relocations.
Definition bwexp.h:130
std::string GetDefaultExtension(Linker::Module &module, std::string filename) override
Appends a default extension to the filename.
Definition bwexp.cc:453
bool FormatSupportsSegmentation() const override
Whether the format supports multiple segments.
Definition bwexp.cc:11
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition bwexp.cc:400
bool FormatIs16bit() const override
Whether the format is 16-bit or not.
Definition bwexp.cc:16
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition bwexp.cc:6
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition bwexp.cc:285
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
Definition mzexe.h:279