X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=3b_sim%2Fsim.cpp;h=09808a0d25ba085233574376b3971ee181c4854f;hb=ad798a166d5abd342b031251f4a9931b81b2812d;hp=24c6dcd407af20062d2cce2b708f0bcfef8ac080;hpb=8dcde224e54a74119f72edd49a903c94e14f45e9;p=calu.git diff --git a/3b_sim/sim.cpp b/3b_sim/sim.cpp index 24c6dcd..09808a0 100644 --- a/3b_sim/sim.cpp +++ b/3b_sim/sim.cpp @@ -17,11 +17,15 @@ #include "CInstrFactory.hpp" #include "uint32_from_hex.hpp" +#include "iext.hpp" +#include "extensions/cprog.hpp" +#include "extensions/cuart.hpp" + #include "SReadline/SReadline.h" using namespace swift; -#define RAM_END (1000) -#define PROG_END (1000) +#define RAM_END (0x3000) +#define PROG_END (0x3000) #define REG_COUNT (16) typedef boost::function &)> Func; @@ -68,16 +72,27 @@ class CHelpExec void close_prog(const std::vector &); CCpu* Iinstr::m_cpu; +CCpu* Iext::m_cpu; +disasm* Iinstr::m_disasm; +disasm* Iext::m_disasm; CCpu* global_cpu = NULL; vector breakpoints; + +#include + +multimap dataCommentsStore, progCommentsStore, dataLabelStore, progLabelStore; +map dataLineCommentStore, progLineCommentStore; + bool ignoreBreak = false; +bool exitProg = false; + void doExit(const vector&) { - exit(EXIT_SUCCESS); + exitProg = true; } unsigned int convertStringToNum(const std::string& in) @@ -111,7 +126,7 @@ void execStep(const vector& in) } else { ignoreBreak = true; - cout << "Breakpoint 0x" << std::hex << setw(8) << setfill('0') << *breakp << std::hex << " hit" << endl; + cout << color(white,red) << "Breakpoint" << color(white,black) << " 0x" << std::hex << setw(8) << setfill('0') << *breakp << std::hex << " hit" << endl; break; } } @@ -133,7 +148,7 @@ void execRun(const vector&) } else { ignoreBreak = true; - cout << "Breakpoint 0x" << std::hex << setw(8) << setfill('0') << *breakp << std::hex << " hit" << endl; + cout << color(white,red) << "Breakpoint" << color(white,black) << " 0x" << std::hex << setw(8) << setfill('0') << *breakp << std::hex << " hit" << endl; return; } } @@ -273,10 +288,29 @@ void printRAM(const vector& in) } } for(i = start*BYTE_COUNT; i <= end*BYTE_COUNT; i += BYTE_COUNT) { + { + auto range = dataLabelStore.equal_range(i); + for(auto iter = range.first; iter != range.second; ++iter) { + cout << color(yellow,black) << iter->second << ":" << color(white,black) << endl; + } + } + { + auto range = dataCommentsStore.equal_range(i); + for(auto iter = range.first; iter != range.second; ++iter) { + cout << color(blue,black) << ";" << iter->second << color(white,black) << endl; + } + } cout << std::hex << "0x" << setw(8) << setfill('0') << i << ": 0x"; cout << std::hex << setw(8) << setfill('0') << global_cpu->getRAM(i) << " "; cout << std::dec << setw(10) << setfill(' ') << global_cpu->getRAM(i) << " "; - cout << std::dec << setw(10) << setfill(' ') << (int)global_cpu->getRAM(i) << endl; + cout << std::dec << setw(10) << setfill(' ') << (int)global_cpu->getRAM(i); + + auto iter = dataLineCommentStore.find(i); + if(iter != dataLineCommentStore.end()) { + cout << color(blue,black) << " ;" << iter->second << color(white,black); + } + cout << endl; + } } @@ -315,7 +349,11 @@ void printPROG(const vector& in) * 1) make 2 columns */ - if(in.size() >= 2) { + if(in.size() >= 2 && in[1][0] == 'c') { + start = global_cpu->getCurPC() / BYTE_COUNT; + end = start + 9; + } + else if(in.size() >= 2) { try { start = convertStringToNum(in[1]); if(start < 0 || start > (PROG_END-1)) { @@ -351,15 +389,34 @@ void printPROG(const vector& in) return; } } + for(i = start*BYTE_COUNT; i <= end*BYTE_COUNT; i += BYTE_COUNT) { + { + auto range = progLabelStore.equal_range(i); + for(auto iter = range.first; iter != range.second; ++iter) { + cout << color(yellow,black) << iter->second << ":" << color(white,black) << endl; + } + } + { + auto range = progCommentsStore.equal_range(i); + for(auto iter = range.first; iter != range.second; ++iter) { + cout << color(blue,black) << ";" << iter->second << color(white,black) << endl; + } + } + Iinstr* pi = global_cpu->getProg(i); if(pi == NULL) { - cout << std::hex << "0x" << setw(8) << setfill('0') << i << ": NOP" << endl; + cout << std::hex << "0x" << setw(8) << setfill('0') << i << ": NOP"; } else { - cout << std::hex << "0x" << setw(8) << setfill('0') << i << ": " << std::dec << pi->toString() << endl; + cout << std::hex << "0x" << setw(8) << setfill('0') << i << ": " << std::dec << global_cpu->colorifyInstr(pi->toString()); } + auto iter = progLineCommentStore.find(i); + if(iter != progLineCommentStore.end()) { + cout << color(blue,black) << " ;" << iter->second << color(white,black); + } + cout << endl; } } @@ -388,6 +445,23 @@ void listBreaks(const vector&) } } +void getPerf(const vector&) +{ + cout << "current perfcounter is " << std::dec << global_cpu->getPerf() << endl; +} + +void resetPerf(const vector&) +{ + cout << "reset perfcounter" << endl; + global_cpu->setPerf(0); +} + +void applyToExtensions(const vector& in) +{ + global_cpu->applyToExtensions(in); +} + + void printStatus(const vector&) { CDat stackp = global_cpu->getStack(); @@ -474,13 +548,22 @@ int main(int argc, char* argv[]) global_cpu = &cpu; Iinstr::setCPU(&cpu); + Iext::setCPU(&cpu); + + disasm disasm(instr); + + Iinstr::setDisasm(&disasm); + Iext::setDisasm(&disasm); + global_cpu->registerExtension(new Cprog()); + global_cpu->registerExtension(new Cuart()); + vector commentDefer; + vector labelDefer; std::string str = ""; int addr = 0; boost::char_separator sep(";", "", boost::keep_empty_tokens); boost::tokenizer > tokens(str, sep); - disasm disasm(instr); while(getline(inFile, str)) { int count = 0; tokens.assign(str); @@ -503,6 +586,15 @@ int main(int argc, char* argv[]) if(count == 1) { try { addr = lexical_cast(*tok_iter); + for(unsigned int i = 0; i < commentDefer.size(); i++) { + dataCommentsStore.insert(pair(addr, commentDefer.at(i))); + } + for(unsigned int i = 0; i < labelDefer.size(); i++) { + dataLabelStore.insert(pair(addr, labelDefer.at(i))); + } + + commentDefer.clear(); + labelDefer.clear(); } catch(bad_lexical_cast& e) { cerr << e.what() << endl; @@ -519,11 +611,30 @@ int main(int argc, char* argv[]) exit(EXIT_FAILURE); } } + else if(count == 4) { + if((*tok_iter).size() > 0) { + dataLabelStore.insert(pair(addr, *tok_iter)); + } + } + else if(count == 5) { + if((*tok_iter).size() > 0) { + dataLineCommentStore.insert(pair(addr, *tok_iter)); + } + } break; case 1: if(count == 1) { try { addr = lexical_cast(*tok_iter); + for(unsigned int i = 0; i < commentDefer.size(); i++) { + progCommentsStore.insert(pair(addr, commentDefer.at(i))); + } + for(unsigned int i = 0; i < labelDefer.size(); i++) { + progLabelStore.insert(pair(addr, labelDefer.at(i))); + } + + commentDefer.clear(); + labelDefer.clear(); } catch(bad_lexical_cast& e) { cerr << e.what() << endl; @@ -534,10 +645,27 @@ int main(int argc, char* argv[]) Iinstr *pi = disasm.decode(*tok_iter); cpu.setProg(addr, pi); } + else if(count == 4) { + if((*tok_iter).size() > 0) { + progLabelStore.insert(pair(addr, *tok_iter)); + } + } + else if(count == 5) { + if((*tok_iter).size() > 0) { + progLineCommentStore.insert(pair(addr, *tok_iter)); + } + } + break; case 2: + if((*tok_iter).size() > 0) { + commentDefer.push_back(*tok_iter); + } + break; case 3: - cerr << "ignoring labels and comments for now" << endl; + if((*tok_iter).size() > 0) { + labelDefer.push_back(*tok_iter); + } break; default: cerr << "i was to lazy to implement the other format types for now" << endl; @@ -565,18 +693,18 @@ int main(int argc, char* argv[]) cout << i << " : " << std::hex << i << std::dec << " " << data << endl; } */ - cpu.setRegister(1, 4); +/* cpu.setRegister(1, 4); cpu.setRegister(2, 0); cpu.setRAM(0,5); - cpu.setRAM(4,50); + cpu.setRAM(4,0x66334455); cpu.setRAM(8,32); cpu.setRAM(12,45); - +*/ // following: job of the bootloader //set stackpointer cpu.setStack(500); //set return to nowhere for ret - cpu.setRAM(500,50); + cpu.setRAM(500,500); SReadline Reader; @@ -598,7 +726,9 @@ int main(int argc, char* argv[]) Completers.push_back(CompleterElement("setreg [s] [num]",&setReg, "Sets Register s to num.")); Completers.push_back(CompleterElement("setdata [s] [num]",&setRam, "Sets RAM-Addr s to num.")); Completers.push_back(CompleterElement("status",&printStatus, "Prints status of CPU.")); - + Completers.push_back(CompleterElement("getperf",&getPerf, "Prints performance counter.")); + Completers.push_back(CompleterElement("resetperf",&resetPerf, "Resets performance counter to 0.")); + Completers.push_back(CompleterElement("extension",&applyToExtensions, "Write to extensions.")); Reader.RegisterCompletions(Completers); string UserInput; @@ -611,7 +741,7 @@ int main(int argc, char* argv[]) Func lastFunc = NULL; - while(1) { + while(!exitProg) { UserInput = Reader.GetLine("> ", Tokens, EndOfInput); if(EndOfInput) { break;