Skip to content

Commit de49b3e

Browse files
author
unknown
committed
thumbby
1 parent 0728a61 commit de49b3e

16 files changed

+383
-109
lines changed

Address.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,24 @@ void Address::Clear32() {
2424
void Address::SerializeToXML(ostringstream& out) {
2525
out << "<Address>" << std::hex;
2626
out << "<name>" << name_ << "</name>";
27+
out << "<size>" << size_ << "</size>";
2728
if(location_ != 0xFFFFFFFF) {
2829
out << "<location>" << immed(location_) << "</location>";
2930
}
31+
//LOG(DEBUG) << " wrote location";
3032
out << "<values>";
3133
for(map<int, uint8_t>::iterator it = datamap_.begin(); it != datamap_.end(); ++it) {
3234
if(it->first != 0) {
3335
uint32_t data;
34-
get32(it->first, &data);
36+
get(it->first, &data);
3537
out << std::dec << "<C_" << it->first << ">" << std::hex << data << "</C_" << std::dec << it->first << ">";
3638
}
3739
}
40+
//LOG(DEBUG) << " wrote values";
3841
out << "</values>";
3942
if(instruction_ != NULL)
4043
instruction_->SerializeToXML(out);
44+
//LOG(DEBUG) << " wrote instruction";
4145
out << "</Address>";
4246
}
4347

Data/backend.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ function send_request() {
88
var xml = ret.html.substr(38);
99
//document.getElementById("response").value = xml;
1010
//alert(ret.xml.documentElement);
11-
document.getElementById("response").value = view_xml(ret.xml.documentElement, 0);
11+
if(ret.xml == null)
12+
document.getElementById("response").value = xml;
13+
else
14+
document.getElementById("response").value = view_xml(ret.xml.documentElement, 0);
1215

1316
} else
1417
document.getElementById("response").value = ret.html;

Data/script/actions.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,18 @@ function highlight(h) {
4444
}
4545

4646
function send_step_request() {
47-
var ret = xx("STEP", "/Address/[`PC`]-8", "");
47+
if(selected.length == 1) {
48+
var ret = xx("STEP", "/Address/[`PC`]-4/"+selected[0].value, "");
49+
} else {
50+
var ret = xx("STEP", "/Address/[`PC`]-4", "");
51+
}
4852
//document.getElementById("response").value = view_xml(ret.xml.documentElement, 0);
4953
send_reg_request();
5054
}
5155

5256
function LoadAddressFlat(address) {
5357
if(address_cache[address] == null) {
58+
//xx("DISASSEMBLE", "/Address/"+immed(address), "").xml;
5459
var ret = xx("READ", "/Address/"+immed(address), "").xml;
5560
address_cache[address] = ret;
5661
} else {
@@ -88,12 +93,12 @@ function LoadAreaFlat(start) {
8893
var i;
8994
var output = document.getElementById("flatfile");
9095
output.innerHTML = "";
91-
for(i=start; i < start+0x100; i+=4) {
96+
for(i=start; i < start+0x100; i+=2) {
9297
output.appendChild(LoadAddressFlat(i));
9398
}
9499
}
95100

96-
window.addEventListener("load", function(e) { LoadAreaFlat(0x400228); }, false);
101+
window.addEventListener("load", function(e) { LoadAreaFlat(0x1800F998); }, false);
97102

98103
window.addEventListener("keypress", function(e) {
99104
if(e.keyCode == 112) {
@@ -134,9 +139,9 @@ window.addEventListener("mousewheel", function(e) {
134139
//alert(file.firstChild.nodeName);
135140
file.removeChild(file.firstChild);
136141
file.appendChild(LoadAddressFlat(address_view+0x100));
137-
address_view += 4;
142+
address_view += 2;
138143
} else {
139-
address_view -= 4;
144+
address_view -= 2;
140145
file.insertBefore(LoadAddressFlat(address_view), file.firstChild);
141146
file.removeChild(file.lastChild);
142147
}

Data/script/selection.js

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ var selected = [];
88

99
window.addEventListener("mousedown", function(e) {
1010
// deselect all
11+
var good = false;
12+
var node = e.target.parentNode;
13+
while(node != null) {
14+
if(node.id == "flatfile") {
15+
good = true;
16+
break;
17+
}
18+
node = node.parentNode;
19+
}
20+
21+
if(good == false) return false;
1122
if(e.ctrlKey == false) {
1223
var i;
1324
for(i in selected) {

FactoryOwner.cc

+31-14
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ bool FactoryOwner::HandlePostRequest(const std::vector<string>& argv, std::strin
6464
bool FactoryOwner::HandleReadRequest(const std::vector<string>& argv, std::string* out) {
6565
if(argv[0] == "Address" && argv.size() >= 2) {
6666
Address* a = memory_.ResolveToAddress(0, argv[1]);
67+
/*if(a != 0 && a->get_instruction() == NULL) { // Auto-Disassembly
68+
instruction_factory_->Process(a);
69+
LOG(INFO) << "Disassembled";
70+
}*/
6771
if (a != 0 && argv.size() >= 3) {
6872
if(argv[2] == "Name") {
6973
(*out) += a->get_name();
@@ -101,7 +105,9 @@ bool FactoryOwner::HandleReadRequest(const std::vector<string>& argv, std::strin
101105
} else if(a != 0) {
102106
ostringstream ss;
103107
ss << kXMLHeader;
108+
LOG(DEBUG) << "making xml";
104109
a->SerializeToXML(ss);
110+
LOG(DEBUG) << "done making xml";
105111
(*out) += ss.str();
106112
} else {
107113
LOG(INFO) << "Address not found";
@@ -184,23 +190,34 @@ bool FactoryOwner::HandleRenameRequest(const std::vector<string>& argv, std::str
184190

185191
bool FactoryOwner::HandleStepRequest(const std::vector<string>& argv, std::string* out) {
186192
if(argv[0] == "Address" && argv.size() >= 2) {
193+
Address* stop;
187194
Address* a = memory_.ResolveToAddress(0, argv[1]);
188-
if (a != 0) {
189-
if(a->get_instruction() == NULL) {
190-
instruction_factory_->Process(a);
191-
LOG(INFO) << "Disassembled";
195+
if(argv.size() == 3) { // Run until
196+
stop = memory_.ResolveToAddress(0, argv[2]);
197+
while (a != stop) {
198+
if(a->get_instruction() == NULL) instruction_factory_->Process(a);
199+
Changelist* c = changelist_factory_.CreateFromStatelessChangelist(a, *a->get_instruction()->change_, &memory_);
200+
memory_.Commit(c);
201+
a = memory_.ResolveToAddress(0, argv[1]);
192202
}
193-
StatelessChangelist* slcl = a->get_instruction()->change_;
194-
DebugPrint(slcl);
195-
LOG(DEBUG) << "got address, creating changelist";
196-
Changelist* c = changelist_factory_.CreateFromStatelessChangelist(a, *slcl, &memory_);
197-
LOG(DEBUG) << "changelist created";
198-
memory_.Commit(c);
203+
} else {
204+
if (a != 0) {
205+
if(a->get_instruction() == NULL) {
206+
instruction_factory_->Process(a);
207+
LOG(INFO) << "Disassembled";
208+
}
209+
StatelessChangelist* slcl = a->get_instruction()->change_;
210+
DebugPrint(slcl);
211+
LOG(DEBUG) << "got address, creating changelist";
212+
Changelist* c = changelist_factory_.CreateFromStatelessChangelist(a, *slcl, &memory_);
213+
LOG(DEBUG) << "changelist created";
214+
memory_.Commit(c);
199215

200-
ostringstream ss;
201-
ss << kXMLHeader;
202-
c->SerializeToXML(ss);
203-
(*out) = ss.str();
216+
ostringstream ss;
217+
ss << kXMLHeader;
218+
c->SerializeToXML(ss);
219+
(*out) = ss.str();
220+
}
204221
}
205222
}
206223
}

Instruction.cc

+2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ using namespace std;
1212
void Instruction::SerializeToXML(ostringstream& out) {
1313
out << std::hex << "<Instruction>";
1414
parsed_->SerializeToXML(out);
15+
//LOG(DEBUG) << " wrote parsed";
1516
change_->SerializeToXML(out);
17+
//LOG(DEBUG) << " wrote change";
1618
out << "<metadata>";
1719
for(vector<Address*>::iterator it = control_inputs_.begin(); it != control_inputs_.end(); ++it) {
1820
out << "<input>0x" << (*it)->get_location() << "</input>";

InstructionFactory.cc

+36-30
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ void InstructionFactory::FastAnalyseRecurse(Memory* m, Address* location, Addres
4545
Address* target = m->ResolveToAddress(0, change->first.first);
4646
if(target == link_register_) {
4747
lr_condition = change->first.second;
48+
if(lr_condition == "1") { // if the linked branch always happens
49+
pc_changes.push_back(change); //add the link register change to the PC changes
50+
}
4851
} else if(target == program_counter_) {
4952
pc_changes.push_back(change);
5053
}
@@ -54,38 +57,41 @@ void InstructionFactory::FastAnalyseRecurse(Memory* m, Address* location, Addres
5457
for(int i = 0; i < pc_changes.size(); i++) {
5558
// Check to see if this change targets the program counter
5659
//LOG(INFO) << std::hex << "branch of " << location->get_location();
57-
if(m->ResolveToAddress(0, pc_changes[i]->first.first) == temp_program_counter) {
58-
//LOG(INFO) << "is program counter";
59-
// If so, evaluate it in this frame
60-
uint32_t next_pc = m->ResolveToNumber(static_changelist_number, pc_changes[i]->second.second);
61-
if(next_pc == 0xFFFFFFF) continue; // This is a hack
62-
temp_program_counter->set32(++(*changelist_number), next_pc);
63-
ostringstream o; o << "0x" << std::hex << TranslateToProgramCounter(next_pc);
64-
//LOG(INFO) << "targetting " << o.str();
65-
Address* next_address = m->ResolveToAddress(0, o.str());
66-
if(next_address != NULL) {
67-
if(pc_changes[i]->first.second == lr_condition) { // This is a linked branch
68-
this_instruction->control_indirect_outputs_.push_back(next_address);
69-
if(next_address->get_instruction() == NULL) {
70-
Process(next_address);
71-
next_address->get_instruction()->control_indirect_inputs_.push_back(location);
72-
FastAnalyseRecurse(m, next_address, temp_program_counter, changelist_number);
73-
} else {
74-
next_address->get_instruction()->control_indirect_inputs_.push_back(location);
75-
}
76-
} else { // This is direct
77-
this_instruction->control_outputs_.push_back(next_address);
78-
if(next_address->get_instruction() == NULL) {
79-
Process(next_address);
80-
next_address->get_instruction()->control_inputs_.push_back(location);
81-
FastAnalyseRecurse(m, next_address, temp_program_counter, changelist_number);
82-
} else {
83-
next_address->get_instruction()->control_inputs_.push_back(location);
84-
}
60+
//LOG(INFO) << "is program counter";
61+
// If so, evaluate it in this frame
62+
uint32_t next_pc = m->ResolveToNumber(static_changelist_number, pc_changes[i]->second.second);
63+
if(next_pc == 0xFFFFFFF) continue; // This is a hack
64+
temp_program_counter->set32(++(*changelist_number), next_pc);
65+
ostringstream o; o << "0x" << std::hex << TranslateToProgramCounter(next_pc);
66+
//LOG(INFO) << "targetting " << o.str();
67+
Address* next_address = m->ResolveToAddress(0, o.str());
68+
if(next_address != NULL) {
69+
if(m->ResolveToAddress(0, pc_changes[i]->first.first) == link_register_) { // This is the lr return address
70+
if(next_address->get_instruction() == NULL) {
71+
Process(next_address);
72+
FastAnalyseRecurse(m, next_address, temp_program_counter, changelist_number);
73+
}
74+
} else if(pc_changes[i]->first.second == lr_condition) { // This is a linked branch
75+
this_instruction->control_indirect_outputs_.push_back(next_address);
76+
if(next_address->get_instruction() == NULL) {
77+
Process(next_address);
78+
next_address->get_instruction()->control_indirect_inputs_.push_back(location);
79+
FastAnalyseRecurse(m, next_address, temp_program_counter, changelist_number);
80+
} else {
81+
next_address->get_instruction()->control_indirect_inputs_.push_back(location);
82+
}
83+
} else { // This is direct
84+
this_instruction->control_outputs_.push_back(next_address);
85+
if(next_address->get_instruction() == NULL) {
86+
Process(next_address);
87+
next_address->get_instruction()->control_inputs_.push_back(location);
88+
FastAnalyseRecurse(m, next_address, temp_program_counter, changelist_number);
89+
} else {
90+
next_address->get_instruction()->control_inputs_.push_back(location);
8591
}
86-
} else {
87-
LOG(INFO) << "invalid address: " << o.str();
8892
}
93+
} else {
94+
LOG(INFO) << "invalid address: " << o.str();
8995
}
9096
}
9197
}

InstructionFactoryISDF.cc

+48-15
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ InstructionFactoryISDF::InstructionFactoryISDF(string filename, Memory* m) {
3434
if(first_word == "Registers") {
3535
vector<string> registers;
3636
StringSplit(' ', line, &registers);
37-
for (int i = 1; i < registers.size(); i++) {
38-
registers_.push_back(make_pair(registers[i], m->AllocateSegment(registers[i], 4)));
37+
int size = stoi(registers[1])/8;
38+
for (int i = 2; i < registers.size(); i++) {
39+
Address* this_address = m->AllocateSegment(registers[i], size);
40+
this_address->set_size(size);
41+
registers_.push_back(make_pair(registers[i], this_address));
3942
}
4043
} else if(first_word == "DefaultChange") {
4144
// 0 is Change, 1 is bits, 2 is target, 3... is change
@@ -62,19 +65,39 @@ InstructionFactoryISDF::InstructionFactoryISDF(string filename, Memory* m) {
6265
}
6366
if(current != NULL) instructioncomprehensions_.push_back(current);
6467
LOG(INFO) << "read " << current_line_ << " lines of comprehension";
68+
69+
map<char, uint32_t> psuedo_local_scope;
70+
program_counter_ = memory_->ResolveToAddress(0, EvalulateStringInScope(global_scope_, psuedo_local_scope, "{ProgramCounter}"));
71+
link_register_ = memory_->ResolveToAddress(0, EvalulateStringInScope(global_scope_, psuedo_local_scope, "{LinkRegister}"));
72+
stack_pointer_ = memory_->ResolveToAddress(0, EvalulateStringInScope(global_scope_, psuedo_local_scope, "{StackPointer}"));
73+
program_counter_offset_ = memory_->ResolveToNumber(0, EvalulateStringInScope(global_scope_, psuedo_local_scope, "{ProgramCounterOffset}"));
6574
}
6675

67-
Address* InstructionFactoryISDF::Process(Address* start) {
68-
uint32_t opcode;
69-
Address* ret = start->get32(0, &opcode); // hmm, bad size
76+
void InstructionFactoryISDF::StateToXML(std::ostringstream& out) {
77+
out << std::hex;
78+
out << "<Core>";
79+
out << "<ProgramCounter>" << GetProgramCounter() << "</ProgramCounter>";
80+
out << "<StackPointer>" << GetStackPointer() << "</StackPointer>";
81+
out << "<registers>";
82+
83+
for(vector<pair<string, Address*> >::iterator it = registers_.begin(); it!=registers_.end(); ++it) {
84+
uint32_t data;
85+
it->second->get(0, &data);
86+
out << "<" << it->first << ">" << data << "</" << it->first << ">";
87+
}
88+
89+
out << "</registers>";
90+
out << "</Core>";
91+
}
7092

93+
Address* InstructionFactoryISDF::Process(Address* start) {
7194
map<string, string> global_scope_copy = global_scope_;
7295

7396
StatelessChangelist* change = new StatelessChangelist;
74-
ParsedInstruction* parsed = new ParsedInstruction;
97+
ParsedInstruction* parsed = new ParsedInstruction(start);
7598

7699
for(vector<InstructionComprehension*>::iterator it = instructioncomprehensions_.begin(); it != instructioncomprehensions_.end(); ++it) {
77-
if((*it)->Execute(opcode, &global_scope_copy, change, parsed) == true) break;
100+
if((*it)->Execute(start, &global_scope_copy, change, parsed) == true) break;
78101
}
79102

80103
for(map<string, pair<int, string> >::iterator it = default_changes_.begin(); it != default_changes_.end(); ++it) {
@@ -100,7 +123,8 @@ Address* InstructionFactoryISDF::Process(Address* start) {
100123
LOG(DEBUG) << "Parsed -- " << parsed->GetConsoleString();
101124

102125
start->set_instruction(new Instruction(parsed, change, start, 4));
103-
return ret;
126+
uint32_t data;
127+
return start->get(0, &data);
104128
}
105129

106130
// Okay, I know I'm not supposed to work in the constructor...
@@ -190,9 +214,12 @@ void InstructionComprehension::AddLine(const string& linein) {
190214
}
191215
}
192216

193-
bool InstructionComprehension::Execute(uint32_t data, map<string, string>* global_scope, StatelessChangelist* change, ParsedInstruction* parsed) {
217+
bool InstructionComprehension::Execute(Address* opcode, map<string, string>* global_scope, StatelessChangelist* change, ParsedInstruction* parsed) {
218+
opcode->set_size(bitsize_/8);
219+
uint32_t data;
220+
opcode->get(0, &data);
194221
if( (data & mask_) != data_) {
195-
//LOG(DEBUG) << std::hex << "No match on data " << data << " with data " << data_ << " and mask " << mask_;
222+
//LOG(DEBUG) << std::hex << "No match on data " << data << " with data " << data_ << " and mask " << mask_ << " and bitsize " << bitsize_;
196223
return false;
197224
}
198225

@@ -206,7 +233,13 @@ bool InstructionComprehension::Execute(uint32_t data, map<string, string>* globa
206233
}
207234
// Evaluate global scope
208235
for(map<string, string>::iterator it = global_scope_additions_.begin(); it != global_scope_additions_.end(); ++it) {
209-
(*global_scope)[it->first] = parent_->EvalulateStringInScope(*global_scope, local_scope, it->second);
236+
string varname = it->first;
237+
if(varname[varname.length()-1] == '+') {
238+
(*global_scope)[varname.substr(0,varname.length()-1)] += parent_->EvalulateStringInScope(*global_scope, local_scope, it->second);
239+
} else {
240+
(*global_scope)[varname] += parent_->EvalulateStringInScope(*global_scope, local_scope, it->second);
241+
}
242+
210243
LOG(DEBUG) << "added " << it->first << " to the global scope: " << (*global_scope)[it->first];
211244
}
212245
// Add Parsed
@@ -251,7 +284,7 @@ string InstructionFactoryISDF::EvalulateStringInScope(const map<string, string>&
251284
// Find {...} shit and replace it
252285
// {{...}} is registers
253286
// {|...|} is eval to hex number
254-
LOG(DEBUG) << "eval start: " << evalme;
287+
//LOG(DEBUG) << "eval start: " << evalme;
255288
string out = "";
256289
int p = 0;
257290
int last = 0;
@@ -274,7 +307,7 @@ string InstructionFactoryISDF::EvalulateStringInScope(const map<string, string>&
274307
}
275308
} else if(parsethis[1] == '|') { // Hex
276309
string dataeval = EvalulateStringInScope(global_scope, local_scope, parsethis.substr(2, parsethis.length()-4) );
277-
LOG(DEBUG) << " resolving: " << dataeval;
310+
//LOG(DEBUG) << " resolving: " << dataeval;
278311
replace = immed(memory_->ResolveToNumber(0, dataeval));
279312
} else {
280313
string variable = parsethis.substr(1, parsethis.length()-2);
@@ -291,14 +324,14 @@ string InstructionFactoryISDF::EvalulateStringInScope(const map<string, string>&
291324
}
292325
}
293326
}
294-
LOG(DEBUG) << " parsing \"" << parsethis << "\" to \"" << replace << "\"";
327+
//LOG(DEBUG) << " parsing \"" << parsethis << "\" to \"" << replace << "\"";
295328
out += evalme.substr(last, p-last) + replace;
296329

297330
p = close+1;
298331
last = p;
299332
}
300333

301334
out += evalme.substr(last);
302-
LOG(DEBUG) << "eval done: \"" << evalme << "\" to \"" << out << "\"";
335+
//LOG(DEBUG) << "eval done: \"" << evalme << "\" to \"" << out << "\"";
303336
return out;
304337
}

0 commit comments

Comments
 (0)