5#include "../linker/linker.h"
18 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
21 std::string stub_file;
23 std::shared_ptr<Linker::Segment> image;
25 static const uint32_t REL32 = 0x80000000;
30 uint32_t offset : 31, rel32 : 1;
35 : offset(offset), rel32(rel32)
44 bool operator ==(
const Relocation& other)
const;
46 bool operator <(
const Relocation& other)
const;
49 offset_t image_size = 0;
50 std::set<Relocation> relocations;
51 offset_t header_size = 0;
52 offset_t bss_pages = 0;
53 offset_t extra_pages = 0;
56 offset_t relocation_offset = 0;
58 MPFormat(
bool has_relocations =
false)
59 : has_relocations(has_relocations)
63 using LinkerManager::SetLinkScript;
65 void SetOptions(std::map<std::string, std::string>& options)
override;
67 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
93 bool FormatSupportsStackSection()
const override;
97 const bool is_multisegmented;
100 uint16_t header_size = 0;
101 uint32_t file_size = 0;
103 uint32_t runtime_parameters_offset = 0;
104 uint32_t runtime_parameters_size = 0;
105 uint32_t relocation_table_offset = 0;
106 uint32_t relocation_table_size = 0;
107 uint32_t segment_information_table_offset = 0;
108 uint32_t segment_information_table_size = 0;
109 uint16_t segment_information_table_entry_size = 0;
110 uint32_t load_image_offset = 0;
111 uint32_t load_image_size = 0;
112 uint32_t symbol_table_offset = 0;
113 uint32_t symbol_table_size = 0;
114 uint32_t gdt_address = 0;
115 uint32_t gdt_size = 0;
116 uint32_t ldt_address = 0;
117 uint32_t ldt_size = 0;
118 uint32_t idt_address = 0;
119 uint32_t idt_size = 0;
120 uint32_t tss_address = 0;
121 uint32_t tss_size = 0;
122 uint32_t minimum_extra = 0;
123 uint32_t maximum_extra = 0;
124 uint32_t base_load_offset = 0;
132 uint32_t memory_requirements = 0;
133 uint32_t stack_size = 0;
135 P3Format(
bool is_multisegmented,
bool is_32bit =
true)
136 : is_multisegmented(is_multisegmented), is_32bit(is_32bit)
143 uint16_t min_realmode_param = 0, max_realmode_param = 0, min_int_buffer_size_kb = 0, max_int_buffer_size_kb = 0, int_stack_count = 0, int_stack_size_kb = 0;
144 uint32_t realmode_area_end = 0;
145 uint16_t call_buffer_size_kb = 0, flags = 0, ring = 0;
147 void CalculateValues();
154 using LinkerManager::SetLinkScript;
156 void SetOptions(std::map<std::string, std::string>& options)
override;
169 Flat(
bool is_32bit =
true)
174 std::shared_ptr<Linker::Segment> image;
176 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
195 uint32_t address = 0;
197 virtual uint32_t GetStoredSize() = 0;
198 virtual uint32_t GetLoadedSize() = 0;
205 std::weak_ptr<AbstractSegment> image;
224 Descriptor(uint32_t access, std::weak_ptr<AbstractSegment> image = std::weak_ptr<AbstractSegment>())
225 : image(image), access(access)
229 void CalculateValues();
237 std::vector<Descriptor> descriptors;
239 uint32_t GetStoredSize()
override;
241 uint32_t GetLoadedSize()
override;
245 void CalculateValues();
248 std::shared_ptr<DescriptorTable> gdt;
249 std::shared_ptr<DescriptorTable> idt;
250 std::shared_ptr<DescriptorTable> ldt;
257 uint32_t esp0 = 0, esp1 = 0, esp2 = 0;
258 uint32_t cr3 = 0, eip = 0, eflags = 0, eax = 0, ecx = 0, edx = 0, ebx = 0, esp = 0, ebp = 0, esi = 0, edi = 0;
259 uint16_t ss0 = 0, ss1 = 0, ss2 = 0, es = 0, cs = 0, ss = 0, ds = 0, fs = 0, gs = 0, ldtr = 0, iopb = 0;
267 uint32_t GetStoredSize()
override;
269 uint32_t GetLoadedSize()
override;
274 std::shared_ptr<TaskStateSegment> tss;
280 std::shared_ptr<Linker::Segment> segment;
285 uint32_t base_offset = 0;
287 Segment(std::shared_ptr<Linker::Segment> segment, uint32_t access, uint16_t selector)
288 : segment(segment), access(access), selector(selector)
292 uint32_t GetStoredSize()
override;
294 uint32_t GetLoadedSize()
override;
309 std::shared_ptr<Segment> segment;
312 Relocation(std::shared_ptr<Segment> segment, uint32_t offset)
313 : segment(segment), offset(offset)
317 bool operator ==(
const Relocation& other)
const;
319 bool operator <(
const Relocation& other)
const;
324 std::vector<std::shared_ptr<AbstractSegment>> segments;
325 std::map<std::shared_ptr<Linker::Segment>, std::shared_ptr<Segment>> segment_associations;
326 std::set<Relocation> relocations;
327 std::shared_ptr<Segment> code;
328 std::shared_ptr<Segment> data;
330 void OnNewSegment(std::shared_ptr<Linker::Segment> linker_segment)
override;
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 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