RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
xenix.h
1#ifndef XENIX_H
2#define XENIX_H
3
4#include "../common.h"
5#include "../dumper/dumper.h"
6#include "../linker/reader.h"
7#include "../linker/segment_manager.h"
8#include "../linker/writer.h"
9
10/* TODO: unimplemented */
11
12/* b.out and x.out file formats */
13namespace Xenix
14{
18 class BOutFormat : public virtual Linker::SegmentManager
19 {
20 public:
21 void ReadFile(Linker::Reader& rd) override;
23 offset_t WriteFile(Linker::Writer& wr) const override;
24 void Dump(Dumper::Dumper& dump) const override;
25 /* TODO */
26 };
27
31 class XOutFormat : public virtual Linker::SegmentManager
32 {
33 public:
34 class Segment
35 {
36 public:
37 enum segment_type : uint16_t
38 {
39 Null = 0x00,
40 Text = 0x01,
41 Data = 0x02,
42 SymbolTable = 0x03,
43 Relocation = 0x04,
44 SegmentStringTable = 0x05,
45 GroupDefinition = 0x06,
46 IteratedData = 0x40,
47 TSS = 0x41,
48 LODFIX = 0x42,
49 DescriptorNames = 0x43,
50 DebugText = 0x44,
51 DebugRelocation = 0x45,
52 OverlayTable = 0x46,
53 SymbolStringTable = 0x48,
54 };
55 segment_type type = Null;
56 uint16_t attributes = 0;
57
58 uint16_t number = 0;
59 uint8_t log2_align = 0;
60 uint8_t reserved1 = 0;
61 offset_t offset = 0;
62 uint32_t file_size = 0;
63 uint32_t memory_size = 0;
64 uint32_t base_address = 0;
65 uint16_t name_offset = 0;
66 //std::string name; // TODO
67 uint16_t reserved2 = 0;
68 uint32_t reserved3 = 0;
69
70 std::shared_ptr<Linker::Contents> contents;
71
72 static constexpr uint16_t Attribute_Iterated = 0x0001;
73 static constexpr uint16_t Attribute_Huge = 0x0002;
74 static constexpr uint16_t Attribute_ImplicitBss = 0x0004;
75 static constexpr uint16_t Attribute_Pure = 0x0008;
76 static constexpr uint16_t Attribute_ExpandDown = 0x0010;
77 static constexpr uint16_t Attribute_Private = 0x0020;
78 static constexpr uint16_t Attribute_32Bit = 0x0040;
79 static constexpr uint16_t Attribute_MemoryImage = 0x8000;
80
81 static constexpr uint16_t Attribute_SymbolTable_Bell = 0x0000;
82 static constexpr uint16_t Attribute_SymbolTable_XOut = 0x0001;
83 static constexpr uint16_t Attribute_SymbolTable_IslandDebugger = 0x0002;
84
85 static constexpr uint16_t Attribute_Relocation_XOutSegmented = 0x0001;
86 static constexpr uint16_t Attribute_Relocation_8086Segmented = 0x0002;
87
88 void Calculate(XOutFormat& xout);
89 static Segment ReadHeader(Linker::Reader& rd, XOutFormat& xout);
90 void ReadContents(Linker::Reader& rd, XOutFormat& xout);
91 void WriteHeader(Linker::Writer& wr, const XOutFormat& xout) const;
92 void WriteContents(Linker::Writer& wr, const XOutFormat& xout) const;
93 void Dump(Dumper::Dumper& dump, const XOutFormat& xout, uint32_t index) const;
94 };
95
96 enum cpu_type
97 {
98 CPU_None = 0,
99 CPU_PDP11 = 1,
100 CPU_PDP11_23 = 2,
101 CPU_Z8K = 3,
102 CPU_8086 = 4,
103 CPU_68K = 5,
104 CPU_Z80 = 6,
105 CPU_VAX = 7,
106 CPU_NS32K = 8,
107 CPU_80286 = 9,
108 CPU_80386 = 10,
109 CPU_80186 = 11,
110 };
111
112 enum relocation_format_type
113 {
114 REL_X_OUT_LONG = 0,
115 REL_X_OUT_SHORT = 1,
116 REL_B_OUT = 2,
117 REL_A_OUT = 3,
118 REL_8086_REL = 4,
119 REL_8086_ABS = 5,
120 };
121
122 enum symbol_format_type
123 {
124 SYM_X_OUT = 0,
125 SYM_B_OUT = 1,
126 SYM_A_OUT = 2,
127 SYM_8086_REL = 3,
128 SYM_8086_ABS = 4,
129 SYM_STRING_TABLE = 5,
130 };
131
132 uint16_t header_size = 0;
133 uint32_t text_size = 0;
134 uint32_t data_size = 0;
135 uint32_t bss_size = 0;
136 uint32_t symbol_table_size = 0;
137 uint32_t relocation_size = 0;
138 uint32_t entry_address = 0;
139 cpu_type cpu = CPU_None;
140 ::EndianType endiantype = ::LittleEndian;
141 relocation_format_type relocation_format;
142 symbol_format_type symbol_format;
143 uint16_t runtime_environment = 0;
144
145 // extended header
146 uint32_t text_relocation_size = 0;
147 uint32_t data_relocation_size = 0;
148 uint32_t text_base_address = 0;
149 uint32_t data_base_address = 0;
150 uint32_t stack_size = 0;
151 uint32_t segment_table_offset = 0;
152 uint32_t segment_table_size = 0;
153 uint32_t machine_dependent_table_offset = 0;
154 uint32_t machine_dependent_table_size = 0;
155 enum machine_dependent_table_format_type : uint8_t
156 {
157 MDT_None = 0,
158 MDT_286LDT = 1,
159 };
160 machine_dependent_table_format_type machine_dependent_table_format = MDT_None;
161 uint32_t page_size = 0;
162 enum operating_system_type : uint8_t
163 {
164 OS_None = 0,
165 OS_Xenix = 1,
166 OS_iRMX = 2,
167 OS_ConcurrentCPM = 3,
168 };
169 operating_system_type operating_system = OS_None;
170 enum system_version_type : uint8_t
171 {
172 SystemVersion_Xenix2 = 0,
173 SystemVersion_Xenix3 = 1,
174 SystemVersion_Xenix5 = 2,
175 };
176 system_version_type system_version = SystemVersion_Xenix2;
177 uint16_t entry_segment = 0;
178 uint16_t header_reserved1 = 0;
179
180 std::vector<Segment> segments;
181
182 uint8_t GetCPUByte() const;
183 uint8_t GetRelSymByte() const;
184#if 0
186 offset_t GetPageSize() const;
187#endif
188
189 static constexpr uint16_t Flag_Executable = 0x0001;
190 static constexpr uint16_t Flag_SeparateInsData = 0x0002;
191 static constexpr uint16_t Flag_PureText = 0x0004;
192 static constexpr uint16_t Flag_FixedStack = 0x0008;
193 static constexpr uint16_t Flag_TextOverlay = 0x0010;
194 static constexpr uint16_t Flag_LargeData = 0x0020;
195 static constexpr uint16_t Flag_LargeText = 0x0040;
196 static constexpr uint16_t Flag_FloatingPoint = 0x0080;
197 static constexpr uint16_t Flag_VirtualModule = 0x0100;
198 static constexpr uint16_t Flag_HugeData = 0x0100;
199 static constexpr uint16_t Flag_Iterated = 0x0200;
200 static constexpr uint16_t Flag_Absolute = 0x0400;
201 static constexpr uint16_t Flag_SegmentTable = 0x0800;
202 static constexpr uint16_t Flag_AdvisoryLocking = 0x1000;
203 static constexpr uint16_t Flag_Xenix53Required = 0x2000;
204
205 static constexpr uint16_t Flag_Xenix2x = 0x4000;
206 static constexpr uint16_t Flag_Xenix3x = 0x8000;
207 static constexpr uint16_t Flag_Xenix5x = 0xC000;
208
209 void Clear() override;
210 void CalculateValues() override;
211 void ReadFile(Linker::Reader& rd) override;
213 offset_t WriteFile(Linker::Writer& wr) const override;
214 void Dump(Dumper::Dumper& dump) const override;
215 /* TODO */
216 };
217}
218
219#endif /* XENIX_H */
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:773
offset_t WriteFile(Writer &wr) const override=0
Stores data in memory to file.
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:20
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
Xenix b.out executable.
Definition xenix.h:19
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition xenix.cc:10
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition xenix.cc:22
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition xenix.cc:15
Definition xenix.h:35
Xenix x.out executable.
Definition xenix.h:32
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition xenix.cc:520
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition xenix.cc:255
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition xenix.cc:382
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition xenix.cc:219
void Clear() override
Resets all fields to their default values, deallocate memory.
Definition xenix.cc:197