RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
aout.h
1#ifndef AOUT_H
2#define AOUT_H
3
4#include "mzexe.h"
5#include "../common.h"
6#include "../linker/linker.h"
7#include "../linker/module.h"
8#include "../linker/segment.h"
9#include "../linker/writer.h"
10
11/* TODO: UNIX v1 a.out
12 magic
13 header_size + text_size + data_size
14 symtab_size
15 relocations_size
16 bss_size
17 0
18
19TODO: PDP-11 a.out
20*/
21
22namespace AOut
23{
48 {
49 public:
50 /* * * General members * * */
51 ::EndianType endiantype;
52 unsigned word_size;
53
54 enum magic_type
55 {
56 OMAGIC = 0x0107,
57 NMAGIC = 0x0108,
58 ZMAGIC = 0x010B,
59 QMAGIC = 0x00CC,
60 };
61 magic_type magic = magic_type(0);
62
63 enum cpu_type
64 {
65 UNKNOWN = 0x00,
66 M68010 = 0x01,
67 M68020 = 0x02,
68 SPARC = 0x03,
69 I80386 = 0x64,
70 ARM = 0x67, /* according to BFD */
71 MIPS1 = 0x97,
72 MIPS2 = 0x98,
73 PDP11 = 0xFF, /* not a real magic number */
74 };
75 cpu_type cpu = UNKNOWN;
76
77 ::EndianType GetEndianType() const;
78
79 unsigned GetWordSize() const;
80
81 uint32_t code_size = 0;
82 uint32_t data_size = 0;
83 uint32_t bss_size = 0;
84 uint32_t symbol_table_size = 0;
85 uint32_t entry_address = 0;
86 uint32_t code_relocation_size = 0;
87 uint32_t data_relocation_size = 0;
88 std::map<uint32_t, uint32_t> code_relocations, data_relocations; /* only used by PDOS386 OMAGIC */
89
90 std::shared_ptr<Linker::Writable> code, data, bss;
91
92 private:
93 bool AttemptFetchMagic(uint8_t signature[4]);
94
95 bool AttemptReadFile(Linker::Reader& rd, uint8_t signature[4], offset_t image_size);
96
97 public:
98 class Symbol
99 {
100 public:
101 std::string name;
102 uint16_t unknown = 0;
103 uint16_t name_offset = 0;
104 uint16_t type = 0;
105 uint16_t value = 0;
106 };
107
108 std::vector<Symbol> symbols;
109
110 void ReadFile(Linker::Reader& rd) override;
111
112 void WriteFile(Linker::Writer& wr) override;
113
114 /* * * Reader * * */
115
116 private:
117 void GenerateModule(Linker::Module& module) const;
118
119 public:
120 void ProduceModule(Linker::Module& module, Linker::Reader& rd) override;
121
122 /* * * Writer * * */
123
124 enum system_type
125 {
126 UNIX, /* also Linux */ /* TODO */
127 DJGPP1, /* early DJGPP */
128 PDOS386, /* http://pdos.sourceforge.net/ */
129 };
130 system_type system = system_type(0);
131
132 static std::shared_ptr<AOutFormat> CreateWriter(system_type system, magic_type magic);
133
134 static std::shared_ptr<AOutFormat> CreateWriter(system_type system);
135
142 static magic_type GetDefaultMagic(system_type system);
143
144 void SetOptions(std::map<std::string, std::string>& options) override;
145
146 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
147
148 void CreateDefaultSegments();
149
150 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
151
152 void Link(Linker::Module& module);
153
154 std::shared_ptr<Linker::Segment> GetCodeSegment();
155
156 std::shared_ptr<Linker::Segment> GetDataSegment();
157
158 std::shared_ptr<Linker::Segment> GetBssSegment();
159
160 void ProcessModule(Linker::Module& module) override;
161
162 void CalculateValues() override;
163
164 using LinkerManager::SetLinkScript;
165
166 void GenerateFile(std::string filename, Linker::Module& module) override;
167
168 std::string GetDefaultExtension(Linker::Module& module, std::string filename) override;
169
170 std::string GetDefaultExtension(Linker::Module& module) override;
171 };
172
173}
174
175#endif /* AOUT_H */
Definition aout.h:99
UNIX/Linux a.out binary file format.
Definition aout.h:48
void ProduceModule(Linker::Module &module, Linker::Reader &rd) override
Reads a file and loads the information into a module object.
Definition aout.cc:559
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition aout.cc:345
std::string GetDefaultExtension(Linker::Module &module, std::string filename) override
Appends a default extension to the filename.
Definition aout.cc:825
static magic_type GetDefaultMagic(system_type system)
Default magic number associated with the system.
Definition aout.cc:580
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition aout.cc:693
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition aout.cc:592
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition aout.cc:796
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition aout.cc:145
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 aout.cc:599
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition aout.cc:808
A class that provides a general interface to loading a module.
Definition format.h:161
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:248