Skip to content

Commit

Permalink
EDA glides, FunctionCache moved to Memory
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed Apr 19, 2009
1 parent be7e235 commit 2ca0ae6
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 116 deletions.
76 changes: 59 additions & 17 deletions Controller/ARM/CoreARM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,45 @@ void CoreARM::fastAnalyse(Data addr, Function *currentFunction, bool first)
Data a;
mBank->lock(LOCKED_CORE);

//info << "analysing " << std::hex << addr << std::endl;
InstructionIterator working;
std::map<Data,Instruction *>::iterator impblue;
#ifdef VERBOSE
info << "analysing " << std::hex << addr << std::endl;
#endif
do
{

//see if we've been here before, if so, die
//also possibly set landing pad
//also possibly add a blue implicit
impblue=currentFunction->mInstructions.find(addr);
if(impblue!=currentFunction->mInstructions.end()) {
if(first==true) { //mark as landingPad
impblue->second->mLandingPad=true;
}
//instruction already here
//adding implicit
impblue=currentFunction->mInstructions.find(addr-4);
//if instruction is found in function and it isn't a branch, add the implicit blue line
if(impblue!=currentFunction->mInstructions.end() && impblue->second->mBranch==false)
currentFunction->mBranchData.push_back(Branch(BRANCH_FOLLOW, addr-4, addr));
#ifdef VERBOSE
info << "repeat at " << std::hex << addr << std::endl;
#endif
goto done;
}


//info << " disassembling" << addr << std::endl;
if(!(mBank->mem()->exists(addr)))
{
//info << "memory isn't real: " << addr << std::endl;
#ifdef VERBOSE
info << "memory isn't real: " << addr << std::endl;
#endif
goto done;
}


working=disassemble(addr);
if(first==true) { //mark as landingPad
working->second.mLandingPad=true;
Expand All @@ -60,32 +89,45 @@ void CoreARM::fastAnalyse(Data addr, Function *currentFunction, bool first)
} while(working->second.mBranch==false);
addr-=4;
a=working->second.mAction.resolveToRegisterWithRegister(15, addr+8);
//info << std::hex << "found next branch at " << addr << " to " << a << std::endl;
#ifdef VERBOSE
info << std::hex << "found next branch at " << addr << " to " << a << std::endl;
#endif
if(working->second.mConditional) //if conditional, continue here as well
{
if(mBank->mInstructionCache.find(addr+4)==mBank->mInstructionCache.end()) {
currentFunction->mBranchData.push_back(Branch(BRANCH_CONDITIONFAIL, addr, addr+4));
if(currentFunction->mInstructions.find(addr+4)==currentFunction->mInstructions.end()) {
//not in icache already
currentFunction->mBranchData.push_back(Branch(BRANCH_CONDITIONFAIL, addr, addr+4));
fastAnalyse(addr+4, currentFunction, true); //recurse..weeeee
}
}
//for normal branches + conditionals
if(mBank->mInstructionCache.find(a)==mBank->mInstructionCache.end()) {
//not in icache already
//if linked, add it to the function cache
if(working->second.mLinkedBranch==true) {
fastAnalyse(addr+4, currentFunction, false); //continue here, since it'll be back
//info << "function found at: " << a << std::endl;
fastAnalyse(a, mBank->mFunctionCache.add(a), false); //and do the new function

//not in icache already
//if linked, add it to the function cache
if(working->second.mLinkedBranch==true) {
fastAnalyse(addr+4, currentFunction, false); //continue here, since it'll be back
if(mBank->mem()->inFunction(a)==0) //is function not done
{
info << "function found at: " << a << std::endl;
fastAnalyse(a, mBank->mem()->addFunction(a), false); //and do the new function
}
}
else
{
if(working->second.mConditional)
currentFunction->mBranchData.push_back(Branch(BRANCH_CONDITIONPASS, addr, a));
else
{
if(working->second.mConditional)
currentFunction->mBranchData.push_back(Branch(BRANCH_CONDITIONPASS, addr, a));
else
currentFunction->mBranchData.push_back(Branch(BRANCH_FOLLOW, addr, a));
fastAnalyse(a, currentFunction, true);
//branching from current addr to branch location
currentFunction->mBranchData.push_back(Branch(BRANCH_FOLLOW, addr, a));
//branching from branch location-4 to branch location, possibly
//conditionals should have been done already and pushed
/*impblue=currentFunction->mInstructions.find(a-4);
//if instruction is found in function and it isn't a branch, add the implicit blue line
if(impblue!=currentFunction->mInstructions.end() && impblue->second->mBranch==false)
currentFunction->mBranchData.push_back(Branch(BRANCH_FOLLOW, a-4, a));*/
}
fastAnalyse(a, currentFunction, true);
}
done:
mBank->unlock(LOCKED_CORE);
Expand Down
3 changes: 3 additions & 0 deletions Controller/ARM/InstructionARM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ bool InstructionARM::initBranches()
//********************Data********************
// **First**
int bl=((i->bbl.offset&0x800000)?(0xFC000000):0)|(i->bbl.offset<<2);

mString.add((Data)(bl+8),DT_OFFSETADDRESS);

if(bl<0) mString << registersARM(REG_PC) << "-" << (0-(Data)bl);
else if(bl>0) mString << registersARM(REG_PC) << "+" << (Data)bl;
else mString << registersARM(REG_PC);
Expand Down
2 changes: 1 addition & 1 deletion Core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void Core::runLoop()
}
else if(event.mCommand==CORE_ANALYSE)
{
fastAnalyse((Data)event.mParam, mBank->mFunctionCache.add((Data)event.mParam), false);
fastAnalyse((Data)event.mParam, mBank->mem()->addFunction((Data)event.mParam), false);
}
//info << "i've got mail: " << event.mParam << endl;
}
Expand Down
35 changes: 0 additions & 35 deletions Model/FunctionCache.cc

This file was deleted.

45 changes: 45 additions & 0 deletions Model/Memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ File& Memory::operator[](Data address)
}
}

std::string Memory::getName(Data address)
{
std::map<Data, std::string>::iterator walk;
walk=mNames.find(address);
if(walk!=mNames.end()) return walk->second;
else {
std::stringstream ss;
ss << "loc_" << std::hex << address;
return ss.str();
}
}

void Memory::setName(Data address, std::string name)
{
std::map<Data, std::string>::iterator nameiter=mNames.find(address);
if(nameiter!=mNames.end()) mReverseNames.erase(nameiter->second);
mNames.insert(std::make_pair(address, name)); //does insert overwrite?
mReverseNames.insert(std::make_pair(name, address));
}

Data Memory::lookupName(std::string name)
{
return mReverseNames.find(name)->second;
}

bool Memory::exists(Data address) {
//info << "Checking existence of " << address << std::endl;
std::map<int, std::vector<File> >::iterator addr;
Expand Down Expand Up @@ -158,3 +183,23 @@ int Memory::fileSize(FILE *f)
return end;
}

//deal with functions in Memory
Function *Memory::addFunction(int start)
{
std::stringstream name;
name << std::hex << "sub_" << start;
setName(start, name.str()); //name the function in the memory space
return &(mFunctionStore.insert(std::make_pair(start,Function(start))).first->second);
}

Function* Memory::inFunction(Data addr)
{
//return function with this instruction in it
//doesn't work yet
FunctionIterator a=mFunctionStore.find(addr);
if(a!=mFunctionStore.end())
return &(a->second);
else
return 0;
}

27 changes: 25 additions & 2 deletions Model/ParsedInstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// released under GPLv3, see http://gplv3.fsf.org/

#include "ParsedInstruction.h"
#include "Memory.h"
#include <vector>
#include <string>

Expand Down Expand Up @@ -34,11 +35,23 @@ void ParsedInstruction::consolePrint()
#define DT_DECIMAL 7
#define DT_SUBOPCODE 8
#define DT_SIGNED 9
#define DT_OFFSETADDRESS 10 //isn't
#define DT_OFFSETDATA 11
*/

const char divLookup[10][30] = {"opcode", "flag", "register", "immed", "formatting", "flag", "symbol", "immed","subopcode","immed"};
const char divLookup[12][30] = {"opcode", "flag", "register", "immed", "formatting", "flag", "symbol", "immed","subopcode","immed","location","immed"};

std::string ParsedInstruction::webPrint(Data address)
Data ParsedInstruction::stoi(std::string s)
//convert string to Data
{
Data ret;
std::istringstream ss(s);
ss >> std::hex >> ret;
return ret;
}

std::string ParsedInstruction::webPrint(Data address, Memory *mem)
//needs memory for things like pc dereffing and names
{
std::stringstream ss;
ss << std::hex << "<div class=\"instruction\" id=\"" << address << "\">";
Expand All @@ -48,6 +61,16 @@ std::string ParsedInstruction::webPrint(Data address)
while(walk!=mString.end())
{
ss << "<span class=\"" << divLookup[walk->second] << "\">";
if(walk->second==DT_OFFSETADDRESS) { //address is pc
/*ss << "<span class=\"" << divLookup[walk->second] << "\" ondblclick=\"refreshFunction('" <<
mem->getName(address+stoi(walk->first)) <<"')\">";*/
ss << mem->getName(address+stoi(walk->first)) << "</span>"; //really should be namelookup
break;
}

if(walk->second==DT_OFFSETDATA) {
ss << "=";
}
ss << walk->first;
ss << "</span>";
if(walk->second==DT_CONDITION) {
Expand Down
3 changes: 2 additions & 1 deletion View/FrontEndConsole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ bool FrontEndConsole::lexer(string cmd)
}
else if(argv[0]=="dumpfcache") {
mBank->lock(LOCKED_SERVER);
mBank->mFunctionCache.debugPrint();
//mBank->mFunctionCache.debugPrint();
cout << "broken" << endl;
mBank->unlock(LOCKED_SERVER);
}
else
Expand Down
28 changes: 19 additions & 9 deletions View/FrontEndServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ bool FrontEndServer::lexer(int fd,std::string cmd)
std::stringstream response;
response << XML_HEADER << "<top>" << std::endl;

FunctionIterator walk=mBank->mFunctionCache.mStore.begin();
while(walk!=mBank->mFunctionCache.mStore.end()) {
FunctionIterator walk=mBank->mem()->mFunctionStore.begin();
while(walk!=mBank->mem()->mFunctionStore.end()) {
response << std::hex << "<function address=\""
<< walk->first << "\">" << walk->second.mName << "</function>" << std::endl;
<< walk->first << "\">" << mBank->mem()->getName(walk->first) << "</function>" << std::endl;
++walk;
}

Expand All @@ -172,13 +172,23 @@ bool FrontEndServer::lexer(int fd,std::string cmd)
std::stringstream response;
//response << XML_HEADER << "<top><instructiondata>" << std::endl;

Function *f=mBank->mFunctionCache.inFunction(hexstrtoint(argv[2]));
Function *f=mBank->mem()->inFunction(mBank->mem()->lookupName(argv[2]));
std::map<Data,Instruction *>::iterator walk=f->mInstructions.begin();
response << "<html><div class=\"codebox\">" << std::endl;
response << "<html><div class=\"codebox\" id=\"" <<
mBank->mem()->getName(walk->first) << "\">" << std::endl;

//next line should really get name
response << std::hex << "<div class=\"addr\">" <<
mBank->mem()->getName(walk->first) << "</div>" << std::endl;

while(walk!=f->mInstructions.end()) {
if(walk->second->mLandingPad==true)
response << "</div>" << std::endl << "<div class=\"codebox\">" << std::endl;
response << walk->second->mString.webPrint(walk->first);
if(walk->second->mLandingPad==true) {
response << "</div>" << std::endl << "<div class=\"codebox\" id=\"" <<
mBank->mem()->getName(walk->first) << "\">" << std::endl;
response << std::hex << "<div class=\"addr\">" <<
mBank->mem()->getName(walk->first) << "</div>" << std::endl;
}
response << walk->second->mString.webPrint(walk->first, mBank->mem());
++walk;
}
response << "</div></html>";
Expand All @@ -191,7 +201,7 @@ bool FrontEndServer::lexer(int fd,std::string cmd)
std::stringstream response;
response << XML_HEADER << "<top>" << std::endl;

Function *f=mBank->mFunctionCache.inFunction(hexstrtoint(argv[2]));
Function *f=mBank->mem()->inFunction(mBank->mem()->lookupName(argv[2]));
std::vector<Branch>::iterator walk=f->mBranchData.begin();
while(walk!=f->mBranchData.end()) {
response << (*walk).getXML() << std::endl;
Expand Down
6 changes: 6 additions & 0 deletions data/eda.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ body {
/*max-width: 300px;*/
/*max-height: 400px;*/
font: 14px Lucida Console;
/*font-weight: 600;*/
display: inline-block;
vertical-align: top;
}
Expand Down Expand Up @@ -130,6 +131,7 @@ body {
width: auto;
white-space: nowrap;
text-align: left;
color: gray;
/*padding-top: 5px;*/
}

Expand Down Expand Up @@ -176,4 +178,8 @@ body {

.immed {
color: green;
}

.location {
color: gray;
}
Loading

0 comments on commit 2ca0ae6

Please sign in to comment.