-
Notifications
You must be signed in to change notification settings - Fork 21
/
data_atomic.h
132 lines (112 loc) · 3.38 KB
/
data_atomic.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// data_atomic.h -- May 9, 2009
// by geohot
// part of "The Embedded Disassembler"
// released under GPLv3, see http://gplv3.fsf.org/
//
// This is the level under data
// Nothing should be included
// These are the lowest level data structures in EDA
// Currently, thats just the changelists
//
// They should all be serializable to XML
#ifndef EDA_DATAATOMIC_H_
#define EDA_DATAATOMIC_H_
#ifdef __linux
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#endif
#include <sstream>
#include <string>
#include <vector>
#include <map>
using namespace std;
namespace eda {
class Address; // Can't actually call address
class JSON;
// LHS Condition Bytes Value
#define StatelessChangelistIterator map<pair<string, string>, pair<int, string> >::iterator
// This is a changelist that is "position independent" and "state independent"
// Should be initted as a string
// A StatelessData is now a string
class StatelessChangelist {
public:
StatelessChangelist() {}
// This adds an assignment of the form
// if(rhs.first)
// (lhs.second)lhs.first = rhs.second;
// lhs.second is number of bits
void add_change(const string& lhs, const string& cond, int bytes, const string& value);
// Returns first change in list
bool get_first_change(StatelessChangelistIterator* a);
bool get_next_change(StatelessChangelistIterator* a);
int get_size();
void SerializeToXML(ostringstream& out);
void SerializeToJSON(JSON* json);
//private:
// int is bytecount, not bitcount
map<pair<string, string>, pair<int, string> > changes_;
};
#define ChangelistIterator map<Address*, uint8_t>::iterator
// This is a set of instructions to modify explicit memory
class Changelist {
public:
Changelist(int changelist_number, Address* owner) :
changelist_number_(changelist_number),
owner_(owner) {};
// This adds an assignment of the form
// lhs = rhs;
void add_change(Address* target, uint8_t data);
void add_read(Address* source);
// owner_ accessor
Address* get_owner();
int get_changelist_number();
int get_size();
// Returns first change in list
bool get_first_change(ChangelistIterator* a);
bool get_next_change(ChangelistIterator* a);
void SerializeToXML(ostringstream& out);
void SerializeToJSON(JSON* json);
private:
// This is every change the changelist makes
// Addresses are stored in their pointer form so no moving or renaming
// affects them
vector<Address*> read_; // Everything this changelist read
map<Address*, uint8_t> changes_;
int changelist_number_;
Address* owner_;
};
// O -- opcode
// o -- subopcode
// F -- flags
// C -- condition
// R -- register
// I -- immed
// P -- PC offset immed
// p -- dereferenced PC offset immed
class ParsedInstruction {
public:
// Is this valid c++?
// Should be like printf for strings
ParsedInstruction() {
format_ = "";
Init();
}
ParsedInstruction(Address* parent) : parent_(parent) {
format_ = "";
Init();
}
void Init();
ParsedInstruction(const string& format, const vector<string>& args) : format_(format), args_(args) {}
void SerializeToXML(ostringstream& out);
void SerializeToJSON(JSON* json);
string GetConsoleString();
string format_;
vector<string> args_;
private:
// It'd be sweet if this was a string with formatting
static map<char, string> web_lookup_;
Address* parent_;
};
}
#endif