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 "../dumper/dumper.h"
6#include "../linker/segment_manager.h"
7#include "mzexe.h"
8
9namespace DOS16M
10{
14 class BWFormat : public virtual Linker::SegmentManager
15 {
16 public:
17 void ReadFile(Linker::Reader& rd) override;
18
19 bool FormatSupportsSegmentation() const override;
20
21 bool FormatIs16bit() const override;
22
23 unsigned FormatAdditionalSectionFlags(std::string section_name) const override;
24
26 {
27 public:
28 enum access_type
29 {
30 TYPE_DATA = 0x92,
31 TYPE_CODE = 0x9A,
32 };
33 access_type access;
34
35 enum flag_type
36 {
37 FLAG_EMPTY = 0x2000,
38 FLAG_TRANSPARENT = 0x8000,
39 };
40 flag_type flags;
41
42 uint32_t address = 0;
43 uint32_t total_length;
44
45 AbstractSegment(unsigned access = TYPE_DATA, unsigned flags = 0, uint32_t total_length = 0)
46 : access(access_type(access)), flags(flag_type(flags)), total_length(total_length)
47 {
48 }
49
50 virtual ~AbstractSegment();
51
55 uint32_t GetTotalSize();
56
60 virtual void SetTotalSize(uint32_t new_value);
61
65 virtual uint32_t GetSize(const BWFormat& bw) const = 0;
69 virtual void WriteContent(Linker::Writer& wr, const BWFormat& bw) const = 0;
70
74 void Prepare(BWFormat& bw);
75
79 void WriteHeader(Linker::Writer& wr, const BWFormat& bw) const;
80 };
81
82 class Segment : public AbstractSegment
83 {
84 public:
85 std::shared_ptr<Linker::Segment> image;
86
87 Segment(std::shared_ptr<Linker::Segment> segment, unsigned access = TYPE_DATA, unsigned flags = 0)
88 : AbstractSegment(access, flags, segment->TotalSize()), image(segment)
89 {
90 }
91
92 void SetTotalSize(uint32_t new_value) override;
93
94 uint32_t GetSize(const BWFormat& bw) const override;
95
96 void WriteContent(Linker::Writer& wr, const BWFormat& bw) const override;
97 };
98
100 {
101 public:
102 DummySegment(uint32_t total_length, unsigned access = TYPE_DATA, unsigned flags = 0)
103 : AbstractSegment(access, flags, total_length)
104 {
105 }
106
107 void SetTotalSize(uint32_t new_value) override;
108
109 uint32_t GetSize(const BWFormat& bw) const override;
110
111 void WriteContent(Linker::Writer& wr, const BWFormat& bw) const override;
112 };
113
115 {
116 public:
117 uint16_t index;
118
119 RelocationSegment(uint16_t index)
120 : AbstractSegment(TYPE_DATA), index(index)
121 {
122 }
123
127 void SetTotalSize(uint32_t new_value) override;
128
129 uint32_t GetSize(const BWFormat& bw) const override;
130
131 void WriteContent(Linker::Writer& wr, const BWFormat& bw) const override;
132 };
133
138 {
139 RelocationsNone,
140 RelocationsType1,
141 RelocationsType2,
142 };
143 relocations_type option_relocations = RelocationsType2;
144 bool option_force_relocations = true;
145
146 enum exp_flag_type
147 {
148 EXP_FLAG_RELOCATABLE = 0x0001,
149 };
150 exp_flag_type exp_flags = exp_flag_type(0);
151
152 enum option_type
153 {
154 OPTION_RELOCATIONS = 0x1000,
155 };
156 option_type options = option_type(0);
157
158 std::map<uint16_t, std::set<uint16_t> > relocations;
159
160 offset_t MeasureRelocations() const;
161
162 void SetOptions(std::map<std::string, std::string>& options) override;
163
164 offset_t file_size = 0;
165 offset_t min_extra = 0;
166 offset_t max_extra = 0;
167 uint16_t ss = 0, sp = 0, cs = 0, ip = 0, relocsel = 0;
168 uint16_t runtime_gdt_length = 0xFFFF;
169 uint16_t version = 0;
170 uint32_t next_header_offset = 0;
171 uint32_t debug_info_offset = 0; /* TODO: ??? */
172 uint16_t first_selector = 0x0080; /* TODO: make dynamic */
173 uint32_t private_xm = 0; /* TODO: make parameter */
174 uint16_t ext_reserve = 0; /* TODO: ??? */
175 uint16_t transparent_stack = 0; /* TODO: ??? */
176 uint32_t program_size = 0; /* TODO: ??? */
177 uint8_t default_memory_strategy = 0; /* TODO: ??? */
178 uint16_t transfer_buffer_size = 0; /* TODO: ??? */
179 std::string exp_name; /* TODO: ??? */
180
181 mutable Microsoft::MZStubWriter stub;
182
183 std::vector<std::unique_ptr<AbstractSegment>> segments;
184 std::map<std::shared_ptr<Linker::Segment>, size_t> segment_indices;
185 int default_data = 0;
186
187 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
188
189 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
190
191 void Link(Linker::Module& module);
192
193 size_t GetDefaultDataIndex();
194
195 void ProcessModule(Linker::Module& module) override;
196
197 void CalculateValues() override;
198
199 offset_t ImageSize() const override;
200
202 offset_t WriteFile(Linker::Writer& wr) const override;
203
204 void Dump(Dumper::Dumper& dump) const override;
205
207 std::string GetDefaultExtension(Linker::Module& module, std::string filename) const override;
208 };
209}
210
211#endif /* BWEXP_H */
virtual void WriteContent(Linker::Writer &wr, const BWFormat &bw) const =0
Produces the binary contents of the segment.
virtual uint32_t GetSize(const BWFormat &bw) const =0
Retrieves size of segment. Some subclasses might calculate this dynamically.
uint32_t GetTotalSize()
Retrieves the total size of the segment, including the bss.
Definition bwexp.cc:39
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:44
void Prepare(BWFormat &bw)
Sets up any values before it can be written to file.
Definition bwexp.cc:56
void WriteHeader(Linker::Writer &wr, const BWFormat &bw) const
Produces the GDT entry for the header.
Definition bwexp.cc:65
Definition bwexp.h:100
uint32_t GetSize(const BWFormat &bw) const override
Retrieves size of segment. Some subclasses might calculate this dynamically.
Definition bwexp.cc:98
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:93
void WriteContent(Linker::Writer &wr, const BWFormat &bw) const override
Produces the binary contents of the segment.
Definition bwexp.cc:103
uint32_t GetSize(const BWFormat &bw) const override
Retrieves size of segment. Some subclasses might calculate this dynamically.
Definition bwexp.cc:112
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:107
void WriteContent(Linker::Writer &wr, const BWFormat &bw) const override
Produces the binary contents of the segment.
Definition bwexp.cc:133
Definition bwexp.h:83
uint32_t GetSize(const BWFormat &bw) const override
Retrieves size of segment. Some subclasses might calculate this dynamically.
Definition bwexp.cc:80
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:74
void WriteContent(Linker::Writer &wr, const BWFormat &bw) const override
Produces the binary contents of the segment.
Definition bwexp.cc:85
Rational Systems DOS/16M "BW" .exp file.
Definition bwexp.h:15
std::string GetDefaultExtension(Linker::Module &module, std::string filename) const override
Appends a default extension to the filename.
Definition bwexp.cc:487
offset_t ImageSize() const override
Retrieves size of stored data.
Definition bwexp.cc:416
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition bwexp.cc:371
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition bwexp.cc:218
relocations_type
BW .exp files support two versions of relocations.
Definition bwexp.h:138
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition bwexp.cc:476
bool FormatSupportsSegmentation() const override
Whether the format supports multiple segments.
Definition bwexp.cc:13
bool FormatIs16bit() const override
Whether the format is 16-bit or not.
Definition bwexp.cc:18
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition bwexp.cc:421
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition bwexp.cc:8
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition bwexp.cc:296
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
Definition mzexe.h:279