~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to ext/armips/Archs/MIPS/PsxRelocator.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#pragma once
 
2
#include "Util/ByteArray.h"
 
3
#include "Core/SymbolTable.h"
 
4
#include "Mips.h"
 
5
#include "Commands/CAssemblerCommand.h"
 
6
 
 
7
enum class PsxRelocationType { WordLiteral, UpperImmediate, LowerImmediate, FunctionCall };
 
8
enum class PsxRelocationRefType { SymblId, SegmentOffset };
 
9
 
 
10
struct PsxRelocation
 
11
{
 
12
        PsxRelocationType type;
 
13
        PsxRelocationRefType refType;
 
14
        int segmentOffset;
 
15
        int referenceId;
 
16
        int referencePos;
 
17
        int relativeOffset;
 
18
        int filePos;
 
19
};
 
20
 
 
21
struct PsxSegment
 
22
{
 
23
        std::wstring name;
 
24
        int id;
 
25
        ByteArray data;
 
26
        std::vector<PsxRelocation> relocations;
 
27
};
 
28
 
 
29
 
 
30
enum class PsxSymbolType { Internal, InternalID, External, BSS, Function };
 
31
 
 
32
struct PsxSymbol
 
33
{
 
34
        PsxSymbolType type;
 
35
        std::wstring name;
 
36
        int segment;
 
37
        int offset;
 
38
        int id;
 
39
        int size;
 
40
        Label* label;
 
41
};
 
42
 
 
43
struct PsxRelocatorFile
 
44
{
 
45
        std::wstring name;
 
46
        std::vector<PsxSegment> segments;
 
47
        std::vector<PsxSymbol> symbols;
 
48
};
 
49
 
 
50
class PsxRelocator
 
51
{
 
52
public:
 
53
        bool init(const std::wstring& inputName);
 
54
        bool relocate(int& memoryAddress);
 
55
        bool hasDataChanged() { return dataChanged; };
 
56
        const ByteArray& getData() const { return outputData; };
 
57
        void writeSymbols(SymbolData& symData) const;
 
58
private:
 
59
        size_t loadString(ByteArray& data, size_t pos, std::wstring& dest);
 
60
        bool parseObject(ByteArray data, PsxRelocatorFile& dest);
 
61
        bool relocateFile(PsxRelocatorFile& file, int& relocationAddress);
 
62
        
 
63
        ByteArray outputData;
 
64
        std::vector<PsxRelocatorFile> files;
 
65
        MipsElfRelocator* reloc;
 
66
        bool dataChanged;
 
67
};
 
68
 
 
69
class DirectivePsxObjImport: public CAssemblerCommand
 
70
{
 
71
public:
 
72
        DirectivePsxObjImport(const std::wstring& fileName);
 
73
        ~DirectivePsxObjImport() { };
 
74
        virtual bool Validate();
 
75
        virtual void Encode() const;
 
76
        virtual void writeTempData(TempData& tempData) const { };
 
77
        virtual void writeSymData(SymbolData& symData) const;
 
78
private:
 
79
        PsxRelocator rel;
 
80
};
 
 
b'\\ No newline at end of file'