X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=3b_sim%2Fsim.cpp;h=d9cc8c2a0c2d2065b815edab5c8da4ddc92a3fbd;hb=HEAD;hp=2102c5a98682f31394273b8f5aea65cea1f492e8;hpb=9e8a37bd8a173779f661ded4ac91cbd9932b744b;p=calu.git diff --git a/3b_sim/sim.cpp b/3b_sim/sim.cpp index 2102c5a..d9cc8c2 100644 --- a/3b_sim/sim.cpp +++ b/3b_sim/sim.cpp @@ -1,3 +1,24 @@ +/* `Deep Thought', a softcore CPU implemented on a FPGA + + Copyright (C) 2010 Markus Hofstaetter + Copyright (C) 2010 Martin Perner + Copyright (C) 2010 Stefan Rebernig + Copyright (C) 2010 Manfred Schwarz + Copyright (C) 2010 Bernhard Urban + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + #include #include #include @@ -17,11 +38,17 @@ #include "CInstrFactory.hpp" #include "uint32_from_hex.hpp" +#include "iext.hpp" +#include "extensions/cprog.hpp" +#include "extensions/cuart.hpp" + +#include + #include "SReadline/SReadline.h" using namespace swift; -#define RAM_END (0x1000) -#define PROG_END (0x1000) +#define RAM_END (0x3000) +#define PROG_END (0x3000) #define REG_COUNT (16) typedef boost::function &)> Func; @@ -68,16 +95,29 @@ 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 signalCpuBreak(int) +{ + global_cpu->breakNext(); +} + void doExit(const vector&) { exitProg = true; @@ -114,7 +154,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; } } @@ -130,13 +170,13 @@ void execRun(const vector&) while(1) { try { auto breakp = find(breakpoints.begin(), breakpoints.end(), global_cpu->getNextPC()); - if(breakp == breakpoints.end() || ignoreBreak) { + if((breakp == breakpoints.end() || ignoreBreak) && !global_cpu->shouldBreak() ) { global_cpu->tick(); ignoreBreak = false; } 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; } } @@ -276,10 +316,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; + } } @@ -361,13 +420,31 @@ void printPROG(const vector& in) 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; } } @@ -407,6 +484,12 @@ void resetPerf(const vector&) global_cpu->setPerf(0); } +void applyToExtensions(const vector& in) +{ + global_cpu->applyToExtensions(in); +} + + void printStatus(const vector&) { CDat stackp = global_cpu->getStack(); @@ -492,12 +575,20 @@ int main(int argc, char* argv[]) global_cpu = &cpu; + signal(SIGINT, signalCpuBreak); 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); @@ -524,6 +615,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; @@ -540,11 +640,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; @@ -555,10 +674,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; @@ -621,7 +757,7 @@ int main(int argc, char* argv[]) 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;