forked from xcore/tool_axe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
XE.h
98 lines (86 loc) · 2.19 KB
/
XE.h
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
// Copyright (c) 2011, Richard Osborne, All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>
#ifndef _XE_h_
#define _XE_h_
#include <stdint.h>
#include <fstream>
#include <vector>
class XE;
class XESector {
public:
enum XBSectorType {
XE_SECTOR_BINARY = 1,
XE_SECTOR_ELF = 2,
XE_SECTOR_CONFIG = 3,
XE_SECTOR_GOTO = 5,
XE_SECTOR_CALL = 6,
XE_SECTOR_LAST = 0x5555,
};
private:
XE &parent;
protected:
uint64_t offset;
private:
uint16_t type;
uint64_t length;
public:
XESector(XE &xe, uint64_t off, uint16_t t, uint64_t len)
: parent(xe), offset(off), type(t), length(len) {}
uint16_t getType() const { return type; };
uint64_t getLength() const { return length; };
bool getData(char *buf) const;
XE &getParent() const { return parent; };
};
class XEElfSector : public XESector {
private:
uint16_t node;
uint16_t core;
uint64_t address;
public:
XEElfSector(XE &xe, uint64_t off, uint64_t len);
uint16_t getNode() const { return node; };
uint16_t getCore() const { return core; };
uint64_t getAddress() const { return address; };
bool getElfData(char *buf) const;
uint64_t getElfSize() const { return getLength() - 12; }
};
class XECallOrGotoSector : public XESector {
private:
uint16_t node;
uint16_t core;
uint64_t address;
public:
XECallOrGotoSector(XE &xe, uint64_t off, uint16_t t, uint64_t len);
uint16_t getNode() const { return node; };
uint16_t getCore() const { return core; };
uint64_t getAddress() const { return address; };
};
class XE {
public:
XE(const char *filename);
~XE();
const std::vector<const XESector *> &getSectors() { return sectors; }
const XESector *getConfigSector() const;
bool operator!() const {
return error;
}
void close() {
s.close();
}
private:
uint16_t version;
std::ifstream s;
std::vector<const XESector *>sectors;
bool error;
uint8_t ReadU8();
uint16_t ReadU16();
uint32_t ReadU32();
uint64_t ReadU64();
bool ReadHeader();
friend class XESector;
friend class XEElfSector;
friend class XECallOrGotoSector;
};
#endif //_XE_h_