forked from farbrausch/fr_public
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rdf.hpp
118 lines (91 loc) · 2.1 KB
/
rdf.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Written by Fabian "ryg" Giesen.
// I hereby place this code in the public domain.
#ifndef __RDF_HPP__
#define __RDF_HPP__
#include "_types.hpp"
/****************************************************************************/
class RDFObject
{
friend class RDFLinker;
struct Reloc
{
sInt Segment,RefSegment;
sInt Offset;
sInt Length;
};
struct Import
{
sInt Segment;
sChar Label[32];
sU32 Address; // set by RDFLinker
};
struct Export
{
sInt Flags;
sInt Segment;
sInt Offset;
sChar Label[32];
};
struct Segment
{
sInt Type;
sInt Number;
sInt Length;
sU8 *Data;
sU32 BaseAddress; // set by RDFLinker
sU8 *LinkedData; // set by RDFLinker
};
sArray<Reloc> Relocs;
sArray<Import> Imports;
sArray<Export> Exports;
sArray<Segment> Segments;
sInt DataSize,HeaderSize;
sInt BSSSize;
const Segment *GetSegment(sInt number) const;
sU32 GetSegAddress(sInt number) const;
public:
RDFObject();
RDFObject(const sU8 *rdfFile);
~RDFObject();
void Clear();
sBool Read(const sU8 *rdfFile);
void Dump() const;
};
/****************************************************************************/
class RDFLinker
{
struct Stage
{
sU32 BaseAddress;
sArray<RDFObject *> Objects;
sInt CodeSize;
sInt DataSize;
sInt BSSSize;
sU8 *LinkedImage;
};
struct Symbol
{
sChar Name[32];
sU32 Address;
sInt Stage;
};
sArray<Stage> Stages;
sArray<Symbol> Symbols;
sU32 BSSBase;
Symbol *FindSymbol(const sChar *name,sInt stage);
public:
RDFLinker();
~RDFLinker();
sInt AddStage(sU32 baseAddress);
void AddObject(sInt stage,RDFObject *object);
void AddSymbol(const sChar *name,sU32 address,sInt stage);
void SetStageBase(sInt stage,sU32 baseAddress);
void SetBSSBase(sU32 baseAddress);
sInt GetResult(sInt stage,sU8 *&data);
sU32 GetSymAddress(const sChar *name,sInt stage);
void Clear();
sBool CalcSizes(sU32 &totalInit,sU32 &totalUninit);
sBool Link(); // only after CalcSizes
};
/****************************************************************************/
#endif