copyleft: gplv3 added and set repo to public
[calu.git] / 3b_sim / sim.cpp
index 0e1a0aef071cfb6bc7b2304dcb938c2b5d29eb56..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>
@@ -19,6 +40,9 @@
 
 #include "iext.hpp"
 #include "extensions/cprog.hpp"
+#include "extensions/cuart.hpp"
+
+#include <signal.h>
 
 #include "SReadline/SReadline.h"
 using namespace swift;
@@ -89,6 +113,11 @@ bool ignoreBreak = false;
 
 bool exitProg = false;
 
+void signalCpuBreak(int)
+{
+       global_cpu->breakNext();
+}
+
 void doExit(const vector<string>&)
 {
        exitProg = true;
@@ -141,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;
                        }
@@ -455,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();
@@ -540,6 +575,7 @@ int main(int argc, char* argv[])
 
        global_cpu = &cpu;
 
+       signal(SIGINT, signalCpuBreak);
        Iinstr::setCPU(&cpu);
        Iext::setCPU(&cpu);
 
@@ -549,6 +585,7 @@ int main(int argc, char* argv[])
        Iext::setDisasm(&disasm);
 
        global_cpu->registerExtension(new Cprog());
+       global_cpu->registerExtension(new Cuart());
 
        vector<string> commentDefer;
        vector<string> labelDefer;
@@ -720,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;