aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-13 18:37:51 +0100
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-13 18:37:51 +0100
commit93c5ade08250e419b7dbc3177db6fba93163fd34 (patch)
treeb28d4f1bb4c36edbd60bf634d0d71a6d880b592d /qtmips_machine
parent9f1ddc2b38469d5028aec5ba7b68131d711f2622 (diff)
downloadqtmips-93c5ade08250e419b7dbc3177db6fba93163fd34.tar.gz
qtmips-93c5ade08250e419b7dbc3177db6fba93163fd34.tar.bz2
qtmips-93c5ade08250e419b7dbc3177db6fba93163fd34.zip
Include simple serial port terminal and prepare empty peripheral dock.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_machine')
-rw-r--r--qtmips_machine/core.cpp2
-rw-r--r--qtmips_machine/qtmips_machine.pro6
-rw-r--r--qtmips_machine/qtmipsmachine.cpp25
-rw-r--r--qtmips_machine/qtmipsmachine.h6
-rw-r--r--qtmips_machine/serialport.cpp72
-rw-r--r--qtmips_machine/serialport.h65
6 files changed, 167 insertions, 9 deletions
diff --git a/qtmips_machine/core.cpp b/qtmips_machine/core.cpp
index 5c8d8f3..d4a3ce6 100644
--- a/qtmips_machine/core.cpp
+++ b/qtmips_machine/core.cpp
@@ -603,7 +603,7 @@ void CorePipelined::do_step(bool skip_break) {
if (HAZARD(dt_e)) {
// Hazard with instruction in execute stage
if (hazard_unit == MachineConfig::HU_STALL_FORWARD) {
- if (dt_e.memread) // TODO extend by branch instructions
+ if (dt_e.memread)
stall = true;
else {
// Forward result value
diff --git a/qtmips_machine/qtmips_machine.pro b/qtmips_machine/qtmips_machine.pro
index 286847f..e63c8a1 100644
--- a/qtmips_machine/qtmips_machine.pro
+++ b/qtmips_machine/qtmips_machine.pro
@@ -25,7 +25,8 @@ SOURCES += \
machineconfig.cpp \
utils.cpp \
physaddrspace.cpp \
- peripheral.cpp
+ peripheral.cpp \
+ serialport.cpp
HEADERS += \
qtmipsmachine.h \
@@ -41,4 +42,5 @@ HEADERS += \
utils.h \
machinedefs.h \
physaddrspace.h \
- peripheral.h
+ peripheral.h \
+ serialport.h
diff --git a/qtmips_machine/qtmipsmachine.cpp b/qtmips_machine/qtmipsmachine.cpp
index 81f733b..61cac0c 100644
--- a/qtmips_machine/qtmipsmachine.cpp
+++ b/qtmips_machine/qtmipsmachine.cpp
@@ -51,14 +51,14 @@ QtMipsMachine::QtMipsMachine(const MachineConfig &cc) : QObject(), mcnf(&cc) {
if (program.get_executable_entry())
regs->pc_abs_jmp(program.get_executable_entry());
mem = new Memory(*mem_program_only);
- cpu_mem = mem;
-#if 1
+
physaddrspace = new PhysAddrSpace();
physaddrspace->insert_range(mem, 0x00000000, 0xefffffff, false);
- MemoryAccess *periph = new SimplePeripheral();
- physaddrspace->insert_range(periph, 0xffffc000, 0xffffcfff, true);
cpu_mem = physaddrspace;
-#endif
+
+ ser_port = new SerialPort();
+ addressapce_insert_range(ser_port, 0xffffc000, 0xffffc0ff, true);
+
cch_program = new Cache(cpu_mem, &cc.cache_program(), cc.memory_access_time_read(), cc.memory_access_time_write());
cch_data = new Cache(cpu_mem, &cc.cache_data(), cc.memory_access_time_read(), cc.memory_access_time_write());
@@ -132,6 +132,10 @@ Cache *QtMipsMachine::cache_data_rw() {
return cch_data;
}
+SerialPort *QtMipsMachine::serial_port() {
+ return ser_port;
+}
+
const Core *QtMipsMachine::core() {
return cr;
}
@@ -180,7 +184,7 @@ void QtMipsMachine::step_internal(bool skip_break) {
do {
cr->step(skip_break);
} while(time_chunk != 0 && stat == ST_BUSY &&
- start_time.msecsTo(QTime::currentTime()) < time_chunk);
+ start_time.msecsTo(QTime::currentTime()) < (int)time_chunk);
} catch (QtMipsException &e) {
run_t->stop();
set_status(ST_TRAPPED);
@@ -229,6 +233,15 @@ void QtMipsMachine::register_exception_handler(ExceptionCause excause,
cr->register_exception_handler(excause, exhandler);
}
+bool QtMipsMachine::addressapce_insert_range(MemoryAccess *mem_acces,
+ std::uint32_t start_addr, std::uint32_t last_addr,
+ bool move_ownership) {
+ if (physaddrspace == nullptr)
+ return false;
+ return physaddrspace->insert_range(mem_acces, start_addr, last_addr,
+ move_ownership);
+}
+
void QtMipsMachine::insert_hwbreak(std::uint32_t address) {
if (cr != nullptr)
cr->insert_hwbreak(address);
diff --git a/qtmips_machine/qtmipsmachine.h b/qtmips_machine/qtmipsmachine.h
index 2a191f0..3680a71 100644
--- a/qtmips_machine/qtmipsmachine.h
+++ b/qtmips_machine/qtmipsmachine.h
@@ -47,6 +47,7 @@
#include <cache.h>
#include <physaddrspace.h>
#include <peripheral.h>
+#include <serialport.h>
namespace machine {
@@ -65,6 +66,7 @@ public:
const Cache *cache_program();
const Cache *cache_data();
Cache *cache_data_rw();
+ SerialPort *serial_port();
const Core *core();
const CoreSingle *core_singe();
const CorePipelined *core_pipelined();
@@ -80,6 +82,9 @@ public:
bool exited();
void register_exception_handler(ExceptionCause excause, ExceptionHandler *exhandler);
+ bool addressapce_insert_range(MemoryAccess *mem_acces, std::uint32_t start_addr,
+ std::uint32_t last_addr, bool move_ownership);
+
void insert_hwbreak(std::uint32_t address);
void remove_hwbreak(std::uint32_t address);
bool is_hwbreak(std::uint32_t address);
@@ -107,6 +112,7 @@ private:
Registers *regs;
Memory *mem, *mem_program_only;
PhysAddrSpace *physaddrspace;
+ SerialPort *ser_port;
Cache *cch_program, *cch_data;
Core *cr;
diff --git a/qtmips_machine/serialport.cpp b/qtmips_machine/serialport.cpp
new file mode 100644
index 0000000..0fc0ad2
--- /dev/null
+++ b/qtmips_machine/serialport.cpp
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*******************************************************************************
+ * QtMips - MIPS 32-bit Architecture Subset Simulator
+ *
+ * Implemented to support following courses:
+ *
+ * B35APO - Computer Architectures
+ * https://cw.fel.cvut.cz/wiki/courses/b35apo
+ *
+ * B4M35PAP - Advanced Computer Architectures
+ * https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start
+ *
+ * Copyright (c) 2017-2019 Karel Koci<cynerd@email.cz>
+ * Copyright (c) 2019 Pavel Pisa <pisa@cmp.felk.cvut.cz>
+ *
+ * Faculty of Electrical Engineering (http://www.fel.cvut.cz)
+ * Czech Technical University (http://www.cvut.cz/)
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ ******************************************************************************/
+
+#include "serialport.h"
+
+using namespace machine;
+
+SerialPort::SerialPort() {
+
+}
+
+SerialPort::~SerialPort() {
+
+}
+
+bool SerialPort::wword(std::uint32_t address, std::uint32_t value) {
+#if 0
+ printf("SerialPort::wword address 0x%08lx data 0x%08lx\n",
+ (unsigned long)address, (unsigned long)value);
+#endif
+ emit write_notification(address, value);
+
+ if (address == 0x04)
+ emit tx_byte(value & 0xff);
+
+ return true;
+}
+
+std::uint32_t SerialPort::rword(std::uint32_t address, bool debug_access) const {
+ (void)debug_access;
+ std::uint32_t value = 0x00000000;
+#if 0
+ printf("SerialPort::rword address 0x%08lx\n",
+ (unsigned long)address);
+#endif
+
+ emit read_notification(address, &value);
+
+ return value;
+}
diff --git a/qtmips_machine/serialport.h b/qtmips_machine/serialport.h
new file mode 100644
index 0000000..2b14a7e
--- /dev/null
+++ b/qtmips_machine/serialport.h
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*******************************************************************************
+ * QtMips - MIPS 32-bit Architecture Subset Simulator
+ *
+ * Implemented to support following courses:
+ *
+ * B35APO - Computer Architectures
+ * https://cw.fel.cvut.cz/wiki/courses/b35apo
+ *
+ * B4M35PAP - Advanced Computer Architectures
+ * https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start
+ *
+ * Copyright (c) 2017-2019 Karel Koci<cynerd@email.cz>
+ * Copyright (c) 2019 Pavel Pisa <pisa@cmp.felk.cvut.cz>
+ *
+ * Faculty of Electrical Engineering (http://www.fel.cvut.cz)
+ * Czech Technical University (http://www.cvut.cz/)
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ ******************************************************************************/
+
+#ifndef SERIALPORT_H
+#define SERIALPORT_H
+
+#include <QObject>
+#include <QMap>
+#include <cstdint>
+#include <qtmipsexception.h>
+#include "peripheral.h"
+
+namespace machine {
+
+class SerialPort : public MemoryAccess {
+ Q_OBJECT
+public:
+ SerialPort();
+ ~SerialPort();
+
+signals:
+ void tx_byte(unsigned int data);
+ void write_notification(std::uint32_t address, std::uint32_t value);
+ void read_notification(std::uint32_t address, std::uint32_t *value) const;
+
+public:
+ bool wword(std::uint32_t address, std::uint32_t value);
+ std::uint32_t rword(std::uint32_t address, bool debug_access = false) const;
+};
+
+}
+
+#endif // SERIALPORT_H