aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_machine')
-rw-r--r--qtmips_machine/core.cpp29
-rw-r--r--qtmips_machine/core.h13
-rw-r--r--qtmips_machine/qtmips_machine.pro3
-rw-r--r--qtmips_machine/utils.cpp5
-rw-r--r--qtmips_machine/utils.h4
5 files changed, 49 insertions, 5 deletions
diff --git a/qtmips_machine/core.cpp b/qtmips_machine/core.cpp
index 6315a0d..481190b 100644
--- a/qtmips_machine/core.cpp
+++ b/qtmips_machine/core.cpp
@@ -1,5 +1,6 @@
#include "core.h"
#include "programloader.h"
+#include "utils.h"
using namespace machine;
@@ -125,6 +126,14 @@ struct Core::dtDecode Core::decode(const struct dtFetch &dt) {
if (!(dec.flags & DM_SUPPORTED))
throw QTMIPS_EXCEPTION(UnsupportedInstruction, "Instruction with following opcode is not supported", QString::number(dt.inst.opcode(), 16));
+ std::uint32_t val_rs = regs->read_gp(dt.inst.rs());
+ std::uint32_t val_rt = regs->read_gp(dt.inst.rt());
+
+ emit decode_instruction_value(dt.inst.data());
+ emit decode_reg1_value(val_rs);
+ emit decode_reg2_value(val_rt);
+ emit decode_immediate_value(sign_extend(dt.inst.immediate()));
+
return {
.inst = dt.inst,
.memread = dec.flags & DM_MEMREAD,
@@ -134,8 +143,8 @@ struct Core::dtDecode Core::decode(const struct dtFetch &dt) {
.regwrite = dec.flags & DM_REGWRITE,
.aluop = dt.inst.opcode() == 0 ? (enum AluOp)dt.inst.funct() : dec.alu,
.memctl = dec.mem_ctl,
- .val_rs = regs->read_gp(dt.inst.rs()),
- .val_rt = regs->read_gp(dt.inst.rt()),
+ .val_rs = val_rs,
+ .val_rt = val_rt,
};
}
@@ -149,7 +158,14 @@ struct Core::dtExecute Core::execute(const struct dtDecode &dt) {
std::uint32_t alu_sec = dt.val_rt;
if (dt.alusrc)
- alu_sec = ((dt.inst.immediate() & 0x8000) ? 0xFFFF0000 : 0) | (dt.inst.immediate()); // Sign extend to 32bit
+ alu_sec = sign_extend(dt.inst.immediate()); // Sign extend to 32bit
+
+ std::uint32_t alu_val = alu_operate(dt.aluop, dt.val_rs, alu_sec, dt.inst.shamt(), regs);
+
+ emit execute_alu_value(alu_val);
+ emit execute_reg1_value(dt.val_rs);
+ emit execute_reg2_value(dt.val_rt);
+ emit execute_immediate_value(sign_extend(dt.inst.immediate()));
return {
.inst = dt.inst,
@@ -159,7 +175,7 @@ struct Core::dtExecute Core::execute(const struct dtDecode &dt) {
.memctl = dt.memctl,
.val_rt = dt.val_rt,
.rwrite = dt.regd ? dt.inst.rd() : dt.inst.rt(),
- .alu_val = alu_operate(dt.aluop, dt.val_rs, alu_sec, dt.inst.shamt(), regs),
+ .alu_val = alu_val,
};
}
@@ -172,6 +188,10 @@ struct Core::dtMemory Core::memory(const struct dtExecute &dt) {
else if (dt.memread)
towrite_val = mem_data->read_ctl(dt.memctl, dt.alu_val);
+ emit memory_alu_value(dt.alu_val);
+ emit memory_rt_value(dt.val_rt);
+ emit memory_mem_value(dt.memread ? towrite_val : 0);
+
return {
.inst = dt.inst,
.regwrite = dt.regwrite,
@@ -182,6 +202,7 @@ struct Core::dtMemory Core::memory(const struct dtExecute &dt) {
void Core::writeback(const struct dtMemory &dt) {
emit instruction_writeback(dt.inst);
+ emit writeback_value(dt.towrite_val);
if (dt.regwrite)
regs->write_gp(dt.rwrite, dt.towrite_val);
}
diff --git a/qtmips_machine/core.h b/qtmips_machine/core.h
index 3ea18ec..64fe409 100644
--- a/qtmips_machine/core.h
+++ b/qtmips_machine/core.h
@@ -29,6 +29,19 @@ signals:
void instruction_writeback(const machine::Instruction &inst);
void instruction_program_counter(const machine::Instruction &inst);
+ void decode_instruction_value(std::uint32_t);
+ void decode_reg1_value(std::uint32_t);
+ void decode_reg2_value(std::uint32_t);
+ void decode_immediate_value(std::uint32_t);
+ void execute_alu_value(std::uint32_t);
+ void execute_reg1_value(std::uint32_t);
+ void execute_reg2_value(std::uint32_t);
+ void execute_immediate_value(std::uint32_t);
+ void memory_alu_value(std::uint32_t);
+ void memory_rt_value(std::uint32_t);
+ void memory_mem_value(std::uint32_t);
+ void writeback_value(std::uint32_t);
+
protected:
virtual void do_step() = 0;
virtual void do_reset() = 0;
diff --git a/qtmips_machine/qtmips_machine.pro b/qtmips_machine/qtmips_machine.pro
index bdce148..503832e 100644
--- a/qtmips_machine/qtmips_machine.pro
+++ b/qtmips_machine/qtmips_machine.pro
@@ -22,7 +22,8 @@ SOURCES += \
programloader.cpp \
cache.cpp \
alu.cpp \
- machineconfig.cpp
+ machineconfig.cpp \
+ utils.cpp
HEADERS += \
qtmipsmachine.h \
diff --git a/qtmips_machine/utils.cpp b/qtmips_machine/utils.cpp
new file mode 100644
index 0000000..070dc2e
--- /dev/null
+++ b/qtmips_machine/utils.cpp
@@ -0,0 +1,5 @@
+#include "utils.h"
+
+std::uint32_t sign_extend(std::uint16_t v) {
+ return ((v & 0x8000) ? 0xFFFF0000 : 0) | v;
+}
diff --git a/qtmips_machine/utils.h b/qtmips_machine/utils.h
index 7d30364..4aa615a 100644
--- a/qtmips_machine/utils.h
+++ b/qtmips_machine/utils.h
@@ -1,10 +1,14 @@
#ifndef UTILS_H
#define UTILS_H
+#include <cstdint>
+
#if __GNUC__ >= 7
#define FALLTROUGH __attribute__((fallthrough));
#else
#define FALLTROUGH
#endif
+std::uint32_t sign_extend(std::uint16_t);
+
#endif // UTILS_H