X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=3b_sim%2Fsim.cpp;h=d9cc8c2a0c2d2065b815edab5c8da4ddc92a3fbd;hb=1968f329b10681b760faec9369aa893cd2af8d44;hp=3200e92a798370baf0ada9c066d7a80fc3d9e65c;hpb=dcb92a8020504f1b27ee01708bbac9f5bcc729eb;p=calu.git diff --git a/3b_sim/sim.cpp b/3b_sim/sim.cpp index 3200e92..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,6 +38,12 @@ #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; @@ -68,12 +95,15 @@ 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; @@ -83,6 +113,11 @@ bool ignoreBreak = false; bool exitProg = false; +void signalCpuBreak(int) +{ + global_cpu->breakNext(); +} + void doExit(const vector&) { exitProg = true; @@ -135,7 +170,7 @@ 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; } @@ -403,7 +438,7 @@ void printPROG(const vector& in) cout << std::hex << "0x" << setw(8) << setfill('0') << i << ": NOP"; } else { - cout << std::hex << "0x" << setw(8) << setfill('0') << i << ": " << std::dec << pi->toString(); + 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()) { @@ -449,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(); @@ -534,11 +575,17 @@ 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; @@ -710,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;