aboutsummaryrefslogtreecommitdiff
path: root/riscv
diff options
context:
space:
mode:
authorScott Johnson <scott.johnson@arilinc.com>2021-09-22 17:27:47 -0700
committerScott Johnson <scott.johnson@arilinc.com>2021-09-26 17:17:52 -0700
commit2c9648735e5f7ba6d3e68bd20f6b9b599743016c (patch)
tree8d731c9a15b1c78c867fb3ec6c8a5da70121d30a /riscv
parent428c2aa1f074e8280fb9fc799e38c7289abc7c74 (diff)
downloadspike-2c9648735e5f7ba6d3e68bd20f6b9b599743016c.zip
spike-2c9648735e5f7ba6d3e68bd20f6b9b599743016c.tar.gz
spike-2c9648735e5f7ba6d3e68bd20f6b9b599743016c.tar.bz2
Convert dscratch0/1 to csr_t
Diffstat (limited to 'riscv')
-rw-r--r--riscv/csrs.cc11
-rw-r--r--riscv/csrs.h7
-rw-r--r--riscv/processor.cc20
-rw-r--r--riscv/processor.h1
4 files changed, 20 insertions, 19 deletions
diff --git a/riscv/csrs.cc b/riscv/csrs.cc
index 479dd27..0badeaa 100644
--- a/riscv/csrs.cc
+++ b/riscv/csrs.cc
@@ -1036,3 +1036,14 @@ bool tdata2_csr_t::unlogged_write(const reg_t val) noexcept {
vals[state->tselect->read()] = val;
return true;
}
+
+
+debug_mode_csr_t::debug_mode_csr_t(processor_t* const proc, const reg_t addr):
+ basic_csr_t(proc, addr, 0) {
+}
+
+void debug_mode_csr_t::verify_permissions(insn_t insn, bool write) const {
+ basic_csr_t::verify_permissions(insn, write);
+ if (!state->debug_mode)
+ throw trap_illegal_instruction(insn.bits());
+}
diff --git a/riscv/csrs.h b/riscv/csrs.h
index 058fb42..c293554 100644
--- a/riscv/csrs.h
+++ b/riscv/csrs.h
@@ -527,6 +527,13 @@ class tdata2_csr_t: public csr_t {
std::vector<reg_t> vals;
};
+// For CSRs that are only writable from debug mode
+class debug_mode_csr_t: public basic_csr_t {
+ public:
+ debug_mode_csr_t(processor_t* const proc, const reg_t addr);
+ virtual void verify_permissions(insn_t insn, bool write) const override;
+};
+
typedef std::shared_ptr<tdata2_csr_t> tdata2_csr_t_p;
diff --git a/riscv/processor.cc b/riscv/processor.cc
index e32acda..2fa9118 100644
--- a/riscv/processor.cc
+++ b/riscv/processor.cc
@@ -497,8 +497,8 @@ void state_t::reset(processor_t* const proc, reg_t max_isa)
csrmap[CSR_SSTATUS] = sstatus = std::make_shared<sstatus_csr_t>(proc, nonvirtual_sstatus, vsstatus);
dpc = 0;
- dscratch0 = 0;
- dscratch1 = 0;
+ csrmap[CSR_DSCRATCH0] = std::make_shared<debug_mode_csr_t>(proc, CSR_DSCRATCH0);
+ csrmap[CSR_DSCRATCH1] = std::make_shared<debug_mode_csr_t>(proc, CSR_DSCRATCH1);
memset(&this->dcsr, 0, sizeof(this->dcsr));
csrmap[CSR_TSELECT] = tselect = std::make_shared<tselect_csr_t>(proc, CSR_TSELECT);
@@ -1007,12 +1007,6 @@ void processor_t::set_csr(int which, reg_t val)
case CSR_DPC:
state.dpc = val & ~(reg_t)1;
break;
- case CSR_DSCRATCH0:
- state.dscratch0 = val;
- break;
- case CSR_DSCRATCH1:
- state.dscratch1 = val;
- break;
case CSR_VSTART:
dirty_vs_state;
VU.vstart = val & (VU.get_vlen() - 1);
@@ -1058,8 +1052,6 @@ void processor_t::set_csr(int which, reg_t val)
case CSR_DCSR:
case CSR_DPC:
- case CSR_DSCRATCH0:
- case CSR_DSCRATCH1:
case CSR_SENTROPY:
LOG_CSR(which);
break;
@@ -1144,14 +1136,6 @@ reg_t processor_t::get_csr(int which, insn_t insn, bool write, bool peek)
if (!state.debug_mode)
break;
ret(state.dpc & pc_alignment_mask());
- case CSR_DSCRATCH0:
- if (!state.debug_mode)
- break;
- ret(state.dscratch0);
- case CSR_DSCRATCH1:
- if (!state.debug_mode)
- break;
- ret(state.dscratch1);
case CSR_VSTART:
require_vector_vs;
if (!extension_enabled('V'))
diff --git a/riscv/processor.h b/riscv/processor.h
index b2aadf5..bd1c85b 100644
--- a/riscv/processor.h
+++ b/riscv/processor.h
@@ -202,7 +202,6 @@ struct state_t
csr_t_p vsatp;
reg_t dpc;
- reg_t dscratch0, dscratch1;
dcsr_t dcsr;
csr_t_p tselect;
mcontrol_t mcontrol[num_triggers];