RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
hunk.h
1#ifndef HUNK_H
2#define HUNK_H
3
4#include "../common.h"
5#include "../linker/linker.h"
6#include "../linker/module.h"
7#include "../linker/segment.h"
8#include "../linker/writer.h"
9
10namespace Amiga
11{
18 {
19 public:
31
32 unsigned FormatAdditionalSectionFlags(std::string section_name) const override;
33
34 void ReadFile(Linker::Reader& rd) override;
35
36 enum
37 {
38 HUNK_CODE = 0x3E9,
39 HUNK_DATA = 0x3EA,
40 HUNK_BSS = 0x3EB,
41 HUNK_RELOC32 = 0x3EC,
42 HUNK_END = 0x3F2,
43 HUNK_HEADER = 0x3F3,
44 HUNK_PPC_CODE = 0x4E9,
45 };
46 uint32_t cpu = HUNK_CODE;
47
48 class Hunk
49 {
50 public:
51 uint32_t hunk_type;
52 enum flag_type
53 {
54 LoadAny = 0x00000000,
55 LoadPublic = 0x00000001, /* default, not stored */
56 LoadChipMem = 0x00000002,
57 LoadFastMem = 0x00000004,
58 LoadLocalMem = 0x00000008,
59 Load24BitDma = 0x00000010,
60 LoadClear = 0x00010000,
61 };
62 flag_type flags;
63 std::shared_ptr<Linker::Segment> image;
64
65 Hunk(uint32_t hunk_type, std::string name = "image", unsigned flags = LoadAny)
66 : hunk_type(hunk_type), flags((flag_type)flags), image(std::make_shared<Linker::Segment>(name))
67 {
68 }
69
70 Hunk(uint32_t hunk_type, std::shared_ptr<Linker::Segment> segment, unsigned flags = LoadAny)
71 : hunk_type(hunk_type), flags((flag_type)flags), image(segment)
72 {
73 }
74
75 std::map<uint32_t, std::vector<uint32_t> > relocations;
76
77 uint32_t GetSizeField();
78
79 bool RequiresAdditionalFlags();
80
81 uint32_t GetAdditionalFlags();
82 };
83
84 std::vector<Hunk> hunks;
85 std::map<std::shared_ptr<Linker::Segment>, size_t> segment_index; /* makes it easier to lookup the indices of segments */
86
87 using LinkerManager::SetLinkScript;
88
89 void SetOptions(std::map<std::string, std::string>& options) override;
90
91 void AddHunk(const Hunk& hunk);
92
93 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
94
95 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
96
97 void Link(Linker::Module& module);
98
99 void ProcessModule(Linker::Module& module) override;
100
101 void CalculateValues() override;
102
103 void WriteFile(Linker::Writer& wr) override;
104
105 void GenerateFile(std::string filename, Linker::Module& module) override;
106
107 std::string GetDefaultExtension(Linker::Module& module) override;
108
109 };
110
111}
112
113#endif /* HUNK_H */
Definition hunk.h:49
AmigaOS/TRIPOS Hunk files.
Definition hunk.h:18
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition hunk.cc:48
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition hunk.cc:169
std::string GetDefaultExtension(Linker::Module &module) override
Provides a default filename for the output file.
Definition hunk.cc:283
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition hunk.cc:273
void WriteFile(Linker::Writer &wr) override
Stores data in memory to file.
Definition hunk.cc:219
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition hunk.cc:215
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 hunk.cc:62
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition hunk.cc:24
flags
Definition hunk.h:21
@ ChipMemory
Section to be stored in chip memory.
Definition hunk.h:29
@ FastMemory
Section to be stored in fast memory.
Definition hunk.h:25
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
@ CustomFlag
Other flags.
Definition section.h:101
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15