copyleft: gplv3 added and set repo to public
[calu.git] / 3b_sim / sim.cpp
index 3200e92a798370baf0ada9c066d7a80fc3d9e65c..d9cc8c2a0c2d2065b815edab5c8da4ddc92a3fbd 100644 (file)
@@ -1,3 +1,24 @@
+/*   `Deep Thought', a softcore CPU implemented on a FPGA
+
+    Copyright (C) 2010 Markus Hofstaetter <markus.manrow@gmx.at>
+    Copyright (C) 2010 Martin Perner <e0725782@student.tuwien.ac.at>
+    Copyright (C) 2010 Stefan Rebernig <stefan.rebernig@gmail.com>
+    Copyright (C) 2010 Manfred Schwarz <e0725898@student.tuwien.ac.at>
+    Copyright (C) 2010 Bernhard Urban <lewurm@gmail.com>
+
+    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 <http://www.gnu.org/licenses/>. */
+
 #include <iostream>
 #include <iomanip>
 #include <fstream>
 #include "CInstrFactory.hpp"
 #include "uint32_from_hex.hpp"
 
+#include "iext.hpp"
+#include "extensions/cprog.hpp"
+#include "extensions/cuart.hpp"
+
+#include <signal.h>
+
 #include "SReadline/SReadline.h"
 using namespace swift;
 
@@ -68,12 +95,15 @@ class CHelpExec
 void close_prog(const std::vector<std::string> &);
 
 CCpu* Iinstr::m_cpu;
+CCpu* Iext::m_cpu;
 disasm* Iinstr::m_disasm;
+disasm* Iext::m_disasm;
 
 CCpu* global_cpu = NULL;
 
 vector<CDat> breakpoints;
 
+
 #include <map>
 
 multimap<int,string> dataCommentsStore, progCommentsStore, dataLabelStore, progLabelStore;
@@ -83,6 +113,11 @@ bool ignoreBreak = false;
 
 bool exitProg = false;
 
+void signalCpuBreak(int)
+{
+       global_cpu->breakNext();
+}
+
 void doExit(const vector<string>&)
 {
        exitProg = true;
@@ -135,7 +170,7 @@ void execRun(const vector<string>&)
        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<string>& 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<string>&)
        global_cpu->setPerf(0);
 }
 
+void applyToExtensions(const vector<string>& in)
+{
+       global_cpu->applyToExtensions(in);
+}
+
+
 void printStatus(const vector<string>&)
 {
        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<string> commentDefer;
        vector<string> 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;