s3e: fix build break
[calu.git] / 3b_sim / sim.cpp
index 6cd72b16cce203b21229d2e44ade6b6a195eac20..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,7 +95,9 @@ 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;
 
@@ -84,6 +113,11 @@ bool ignoreBreak = false;
 
 bool exitProg = false;
 
+void signalCpuBreak(int)
+{
+       global_cpu->breakNext();
+}
+
 void doExit(const vector<string>&)
 {
        exitProg = true;
@@ -136,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;
                        }
@@ -450,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();
@@ -535,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;
@@ -711,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;