Skip to content

Commit

Permalink
thumbby
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Jun 21, 2009
1 parent 0728a61 commit de49b3e
Show file tree
Hide file tree
Showing 16 changed files with 383 additions and 109 deletions.
6 changes: 5 additions & 1 deletion Address.cc
Expand Up @@ -24,20 +24,24 @@ void Address::Clear32() {
void Address::SerializeToXML(ostringstream& out) {
out << "<Address>" << std::hex;
out << "<name>" << name_ << "</name>";
out << "<size>" << size_ << "</size>";
if(location_ != 0xFFFFFFFF) {
out << "<location>" << immed(location_) << "</location>";
}
//LOG(DEBUG) << " wrote location";
out << "<values>";
for(map<int, uint8_t>::iterator it = datamap_.begin(); it != datamap_.end(); ++it) {
if(it->first != 0) {
uint32_t data;
get32(it->first, &data);
get(it->first, &data);
out << std::dec << "<C_" << it->first << ">" << std::hex << data << "</C_" << std::dec << it->first << ">";
}
}
//LOG(DEBUG) << " wrote values";
out << "</values>";
if(instruction_ != NULL)
instruction_->SerializeToXML(out);
//LOG(DEBUG) << " wrote instruction";
out << "</Address>";
}

Expand Down
5 changes: 4 additions & 1 deletion Data/backend.js
Expand Up @@ -8,7 +8,10 @@ function send_request() {
var xml = ret.html.substr(38);
//document.getElementById("response").value = xml;
//alert(ret.xml.documentElement);
document.getElementById("response").value = view_xml(ret.xml.documentElement, 0);
if(ret.xml == null)
document.getElementById("response").value = xml;
else
document.getElementById("response").value = view_xml(ret.xml.documentElement, 0);

} else
document.getElementById("response").value = ret.html;
Expand Down
15 changes: 10 additions & 5 deletions Data/script/actions.js
Expand Up @@ -44,13 +44,18 @@ function highlight(h) {
}

function send_step_request() {
var ret = xx("STEP", "/Address/[`PC`]-8", "");
if(selected.length == 1) {
var ret = xx("STEP", "/Address/[`PC`]-4/"+selected[0].value, "");
} else {
var ret = xx("STEP", "/Address/[`PC`]-4", "");
}
//document.getElementById("response").value = view_xml(ret.xml.documentElement, 0);
send_reg_request();
}

function LoadAddressFlat(address) {
if(address_cache[address] == null) {
//xx("DISASSEMBLE", "/Address/"+immed(address), "").xml;
var ret = xx("READ", "/Address/"+immed(address), "").xml;
address_cache[address] = ret;
} else {
Expand Down Expand Up @@ -88,12 +93,12 @@ function LoadAreaFlat(start) {
var i;
var output = document.getElementById("flatfile");
output.innerHTML = "";
for(i=start; i < start+0x100; i+=4) {
for(i=start; i < start+0x100; i+=2) {
output.appendChild(LoadAddressFlat(i));
}
}

window.addEventListener("load", function(e) { LoadAreaFlat(0x400228); }, false);
window.addEventListener("load", function(e) { LoadAreaFlat(0x1800F998); }, false);

window.addEventListener("keypress", function(e) {
if(e.keyCode == 112) {
Expand Down Expand Up @@ -134,9 +139,9 @@ window.addEventListener("mousewheel", function(e) {
//alert(file.firstChild.nodeName);
file.removeChild(file.firstChild);
file.appendChild(LoadAddressFlat(address_view+0x100));
address_view += 4;
address_view += 2;
} else {
address_view -= 4;
address_view -= 2;
file.insertBefore(LoadAddressFlat(address_view), file.firstChild);
file.removeChild(file.lastChild);
}
Expand Down
11 changes: 11 additions & 0 deletions Data/script/selection.js
Expand Up @@ -8,6 +8,17 @@ var selected = [];

window.addEventListener("mousedown", function(e) {
// deselect all
var good = false;
var node = e.target.parentNode;
while(node != null) {
if(node.id == "flatfile") {
good = true;
break;
}
node = node.parentNode;
}

if(good == false) return false;
if(e.ctrlKey == false) {
var i;
for(i in selected) {
Expand Down
45 changes: 31 additions & 14 deletions FactoryOwner.cc
Expand Up @@ -64,6 +64,10 @@ bool FactoryOwner::HandlePostRequest(const std::vector<string>& argv, std::strin
bool FactoryOwner::HandleReadRequest(const std::vector<string>& argv, std::string* out) {
if(argv[0] == "Address" && argv.size() >= 2) {
Address* a = memory_.ResolveToAddress(0, argv[1]);
/*if(a != 0 && a->get_instruction() == NULL) { // Auto-Disassembly
instruction_factory_->Process(a);
LOG(INFO) << "Disassembled";
}*/
if (a != 0 && argv.size() >= 3) {
if(argv[2] == "Name") {
(*out) += a->get_name();
Expand Down Expand Up @@ -101,7 +105,9 @@ bool FactoryOwner::HandleReadRequest(const std::vector<string>& argv, std::strin
} else if(a != 0) {
ostringstream ss;
ss << kXMLHeader;
LOG(DEBUG) << "making xml";
a->SerializeToXML(ss);
LOG(DEBUG) << "done making xml";
(*out) += ss.str();
} else {
LOG(INFO) << "Address not found";
Expand Down Expand Up @@ -184,23 +190,34 @@ bool FactoryOwner::HandleRenameRequest(const std::vector<string>& argv, std::str

bool FactoryOwner::HandleStepRequest(const std::vector<string>& argv, std::string* out) {
if(argv[0] == "Address" && argv.size() >= 2) {
Address* stop;
Address* a = memory_.ResolveToAddress(0, argv[1]);
if (a != 0) {
if(a->get_instruction() == NULL) {
instruction_factory_->Process(a);
LOG(INFO) << "Disassembled";
if(argv.size() == 3) { // Run until
stop = memory_.ResolveToAddress(0, argv[2]);
while (a != stop) {
if(a->get_instruction() == NULL) instruction_factory_->Process(a);
Changelist* c = changelist_factory_.CreateFromStatelessChangelist(a, *a->get_instruction()->change_, &memory_);
memory_.Commit(c);
a = memory_.ResolveToAddress(0, argv[1]);
}
StatelessChangelist* slcl = a->get_instruction()->change_;
DebugPrint(slcl);
LOG(DEBUG) << "got address, creating changelist";
Changelist* c = changelist_factory_.CreateFromStatelessChangelist(a, *slcl, &memory_);
LOG(DEBUG) << "changelist created";
memory_.Commit(c);
} else {
if (a != 0) {
if(a->get_instruction() == NULL) {
instruction_factory_->Process(a);
LOG(INFO) << "Disassembled";
}
StatelessChangelist* slcl = a->get_instruction()->change_;
DebugPrint(slcl);
LOG(DEBUG) << "got address, creating changelist";
Changelist* c = changelist_factory_.CreateFromStatelessChangelist(a, *slcl, &memory_);
LOG(DEBUG) << "changelist created";
memory_.Commit(c);

ostringstream ss;
ss << kXMLHeader;
c->SerializeToXML(ss);
(*out) = ss.str();
ostringstream ss;
ss << kXMLHeader;
c->SerializeToXML(ss);
(*out) = ss.str();
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Instruction.cc
Expand Up @@ -12,7 +12,9 @@ using namespace std;
void Instruction::SerializeToXML(ostringstream& out) {
out << std::hex << "<Instruction>";
parsed_->SerializeToXML(out);
//LOG(DEBUG) << " wrote parsed";
change_->SerializeToXML(out);
//LOG(DEBUG) << " wrote change";
out << "<metadata>";
for(vector<Address*>::iterator it = control_inputs_.begin(); it != control_inputs_.end(); ++it) {
out << "<input>0x" << (*it)->get_location() << "</input>";
Expand Down
66 changes: 36 additions & 30 deletions InstructionFactory.cc
Expand Up @@ -45,6 +45,9 @@ void InstructionFactory::FastAnalyseRecurse(Memory* m, Address* location, Addres
Address* target = m->ResolveToAddress(0, change->first.first);
if(target == link_register_) {
lr_condition = change->first.second;
if(lr_condition == "1") { // if the linked branch always happens
pc_changes.push_back(change); //add the link register change to the PC changes
}
} else if(target == program_counter_) {
pc_changes.push_back(change);
}
Expand All @@ -54,38 +57,41 @@ void InstructionFactory::FastAnalyseRecurse(Memory* m, Address* location, Addres
for(int i = 0; i < pc_changes.size(); i++) {
// Check to see if this change targets the program counter
//LOG(INFO) << std::hex << "branch of " << location->get_location();
if(m->ResolveToAddress(0, pc_changes[i]->first.first) == temp_program_counter) {
//LOG(INFO) << "is program counter";
// If so, evaluate it in this frame
uint32_t next_pc = m->ResolveToNumber(static_changelist_number, pc_changes[i]->second.second);
if(next_pc == 0xFFFFFFF) continue; // This is a hack
temp_program_counter->set32(++(*changelist_number), next_pc);
ostringstream o; o << "0x" << std::hex << TranslateToProgramCounter(next_pc);
//LOG(INFO) << "targetting " << o.str();
Address* next_address = m->ResolveToAddress(0, o.str());
if(next_address != NULL) {
if(pc_changes[i]->first.second == lr_condition) { // This is a linked branch
this_instruction->control_indirect_outputs_.push_back(next_address);
if(next_address->get_instruction() == NULL) {
Process(next_address);
next_address->get_instruction()->control_indirect_inputs_.push_back(location);
FastAnalyseRecurse(m, next_address, temp_program_counter, changelist_number);
} else {
next_address->get_instruction()->control_indirect_inputs_.push_back(location);
}
} else { // This is direct
this_instruction->control_outputs_.push_back(next_address);
if(next_address->get_instruction() == NULL) {
Process(next_address);
next_address->get_instruction()->control_inputs_.push_back(location);
FastAnalyseRecurse(m, next_address, temp_program_counter, changelist_number);
} else {
next_address->get_instruction()->control_inputs_.push_back(location);
}
//LOG(INFO) << "is program counter";
// If so, evaluate it in this frame
uint32_t next_pc = m->ResolveToNumber(static_changelist_number, pc_changes[i]->second.second);
if(next_pc == 0xFFFFFFF) continue; // This is a hack
temp_program_counter->set32(++(*changelist_number), next_pc);
ostringstream o; o << "0x" << std::hex << TranslateToProgramCounter(next_pc);
//LOG(INFO) << "targetting " << o.str();
Address* next_address = m->ResolveToAddress(0, o.str());
if(next_address != NULL) {
if(m->ResolveToAddress(0, pc_changes[i]->first.first) == link_register_) { // This is the lr return address
if(next_address->get_instruction() == NULL) {
Process(next_address);
FastAnalyseRecurse(m, next_address, temp_program_counter, changelist_number);
}
} else if(pc_changes[i]->first.second == lr_condition) { // This is a linked branch
this_instruction->control_indirect_outputs_.push_back(next_address);
if(next_address->get_instruction() == NULL) {
Process(next_address);
next_address->get_instruction()->control_indirect_inputs_.push_back(location);
FastAnalyseRecurse(m, next_address, temp_program_counter, changelist_number);
} else {
next_address->get_instruction()->control_indirect_inputs_.push_back(location);
}
} else { // This is direct
this_instruction->control_outputs_.push_back(next_address);
if(next_address->get_instruction() == NULL) {
Process(next_address);
next_address->get_instruction()->control_inputs_.push_back(location);
FastAnalyseRecurse(m, next_address, temp_program_counter, changelist_number);
} else {
next_address->get_instruction()->control_inputs_.push_back(location);
}
} else {
LOG(INFO) << "invalid address: " << o.str();
}
} else {
LOG(INFO) << "invalid address: " << o.str();
}
}
}
63 changes: 48 additions & 15 deletions InstructionFactoryISDF.cc
Expand Up @@ -34,8 +34,11 @@ InstructionFactoryISDF::InstructionFactoryISDF(string filename, Memory* m) {
if(first_word == "Registers") {
vector<string> registers;
StringSplit(' ', line, &registers);
for (int i = 1; i < registers.size(); i++) {
registers_.push_back(make_pair(registers[i], m->AllocateSegment(registers[i], 4)));
int size = stoi(registers[1])/8;
for (int i = 2; i < registers.size(); i++) {
Address* this_address = m->AllocateSegment(registers[i], size);
this_address->set_size(size);
registers_.push_back(make_pair(registers[i], this_address));
}
} else if(first_word == "DefaultChange") {
// 0 is Change, 1 is bits, 2 is target, 3... is change
Expand All @@ -62,19 +65,39 @@ InstructionFactoryISDF::InstructionFactoryISDF(string filename, Memory* m) {
}
if(current != NULL) instructioncomprehensions_.push_back(current);
LOG(INFO) << "read " << current_line_ << " lines of comprehension";

map<char, uint32_t> psuedo_local_scope;
program_counter_ = memory_->ResolveToAddress(0, EvalulateStringInScope(global_scope_, psuedo_local_scope, "{ProgramCounter}"));
link_register_ = memory_->ResolveToAddress(0, EvalulateStringInScope(global_scope_, psuedo_local_scope, "{LinkRegister}"));
stack_pointer_ = memory_->ResolveToAddress(0, EvalulateStringInScope(global_scope_, psuedo_local_scope, "{StackPointer}"));
program_counter_offset_ = memory_->ResolveToNumber(0, EvalulateStringInScope(global_scope_, psuedo_local_scope, "{ProgramCounterOffset}"));
}

Address* InstructionFactoryISDF::Process(Address* start) {
uint32_t opcode;
Address* ret = start->get32(0, &opcode); // hmm, bad size
void InstructionFactoryISDF::StateToXML(std::ostringstream& out) {
out << std::hex;
out << "<Core>";
out << "<ProgramCounter>" << GetProgramCounter() << "</ProgramCounter>";
out << "<StackPointer>" << GetStackPointer() << "</StackPointer>";
out << "<registers>";

for(vector<pair<string, Address*> >::iterator it = registers_.begin(); it!=registers_.end(); ++it) {
uint32_t data;
it->second->get(0, &data);
out << "<" << it->first << ">" << data << "</" << it->first << ">";
}

out << "</registers>";
out << "</Core>";
}

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

StatelessChangelist* change = new StatelessChangelist;
ParsedInstruction* parsed = new ParsedInstruction;
ParsedInstruction* parsed = new ParsedInstruction(start);

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

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

start->set_instruction(new Instruction(parsed, change, start, 4));
return ret;
uint32_t data;
return start->get(0, &data);
}

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

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

Expand All @@ -206,7 +233,13 @@ bool InstructionComprehension::Execute(uint32_t data, map<string, string>* globa
}
// Evaluate global scope
for(map<string, string>::iterator it = global_scope_additions_.begin(); it != global_scope_additions_.end(); ++it) {
(*global_scope)[it->first] = parent_->EvalulateStringInScope(*global_scope, local_scope, it->second);
string varname = it->first;
if(varname[varname.length()-1] == '+') {
(*global_scope)[varname.substr(0,varname.length()-1)] += parent_->EvalulateStringInScope(*global_scope, local_scope, it->second);
} else {
(*global_scope)[varname] += parent_->EvalulateStringInScope(*global_scope, local_scope, it->second);
}

LOG(DEBUG) << "added " << it->first << " to the global scope: " << (*global_scope)[it->first];
}
// Add Parsed
Expand Down Expand Up @@ -251,7 +284,7 @@ string InstructionFactoryISDF::EvalulateStringInScope(const map<string, string>&
// Find {...} shit and replace it
// {{...}} is registers
// {|...|} is eval to hex number
LOG(DEBUG) << "eval start: " << evalme;
//LOG(DEBUG) << "eval start: " << evalme;
string out = "";
int p = 0;
int last = 0;
Expand All @@ -274,7 +307,7 @@ string InstructionFactoryISDF::EvalulateStringInScope(const map<string, string>&
}
} else if(parsethis[1] == '|') { // Hex
string dataeval = EvalulateStringInScope(global_scope, local_scope, parsethis.substr(2, parsethis.length()-4) );
LOG(DEBUG) << " resolving: " << dataeval;
//LOG(DEBUG) << " resolving: " << dataeval;
replace = immed(memory_->ResolveToNumber(0, dataeval));
} else {
string variable = parsethis.substr(1, parsethis.length()-2);
Expand All @@ -291,14 +324,14 @@ string InstructionFactoryISDF::EvalulateStringInScope(const map<string, string>&
}
}
}
LOG(DEBUG) << " parsing \"" << parsethis << "\" to \"" << replace << "\"";
//LOG(DEBUG) << " parsing \"" << parsethis << "\" to \"" << replace << "\"";
out += evalme.substr(last, p-last) + replace;

p = close+1;
last = p;
}

out += evalme.substr(last);
LOG(DEBUG) << "eval done: \"" << evalme << "\" to \"" << out << "\"";
//LOG(DEBUG) << "eval done: \"" << evalme << "\" to \"" << out << "\"";
return out;
}

0 comments on commit de49b3e

Please sign in to comment.