Skip to content

Commit 9bcda41

Browse files
authored
Merge pull request #1688 from YenHaoChen/pr-tcontrol
triggers: implement tcontrol
2 parents 00dfa28 + db76232 commit 9bcda41

File tree

5 files changed

+9
-1
lines changed

5 files changed

+9
-1
lines changed

riscv/insn_template.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
#include "specialize.h"
99
#include "tracer.h"
1010
#include "v_ext_macros.h"
11+
#include "debug_defines.h"
1112
#include <assert.h>

riscv/insns/mret.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ if (ZICFILP_xLPE(prev_virt, prev_prv)) {
1515
s = set_field(s, MSTATUS_MPELP, elp_t::NO_LP_EXPECTED);
1616
STATE.mstatus->write(s);
1717
if (STATE.mstatush) STATE.mstatush->write(s >> 32); // log mstatush change
18+
STATE.tcontrol->write((STATE.tcontrol->read() & CSR_TCONTROL_MPTE) ? (CSR_TCONTROL_MPTE | CSR_TCONTROL_MTE) : 0);
1819
p->set_privilege(prev_prv, prev_virt);

riscv/processor.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "disasm.h"
1212
#include "platform.h"
1313
#include "vector_unit.h"
14+
#include "debug_defines.h"
1415
#include <cinttypes>
1516
#include <cmath>
1617
#include <cstdlib>
@@ -403,11 +404,13 @@ void state_t::reset(processor_t* const proc, reg_t max_isa)
403404
csrmap[CSR_TDATA2] = tdata2 = std::make_shared<tdata2_csr_t>(proc, CSR_TDATA2);
404405
csrmap[CSR_TDATA3] = std::make_shared<tdata3_csr_t>(proc, CSR_TDATA3);
405406
csrmap[CSR_TINFO] = std::make_shared<tinfo_csr_t>(proc, CSR_TINFO);
407+
csrmap[CSR_TCONTROL] = tcontrol = std::make_shared<masked_csr_t>(proc, CSR_TCONTROL, CSR_TCONTROL_MPTE | CSR_TCONTROL_MTE, 0);
406408
} else {
407409
csrmap[CSR_TDATA1] = std::make_shared<const_csr_t>(proc, CSR_TDATA1, 0);
408410
csrmap[CSR_TDATA2] = tdata2 = std::make_shared<const_csr_t>(proc, CSR_TDATA2, 0);
409411
csrmap[CSR_TDATA3] = std::make_shared<const_csr_t>(proc, CSR_TDATA3, 0);
410412
csrmap[CSR_TINFO] = std::make_shared<const_csr_t>(proc, CSR_TINFO, 0);
413+
csrmap[CSR_TCONTROL] = tcontrol = std::make_shared<const_csr_t>(proc, CSR_TCONTROL, 0);
411414
}
412415
unsigned scontext_length = (xlen == 32 ? 16 : 32); // debug spec suggests 16-bit for RV32 and 32-bit for RV64
413416
csrmap[CSR_SCONTEXT] = scontext = std::make_shared<masked_csr_t>(proc, CSR_SCONTEXT, (reg_t(1) << scontext_length) - 1, 0);
@@ -951,6 +954,7 @@ void processor_t::take_trap(trap_t& t, reg_t epc)
951954
state.elp = elp_t::NO_LP_EXPECTED;
952955
state.mstatus->write(s);
953956
if (state.mstatush) state.mstatush->write(s >> 32); // log mstatush change
957+
state.tcontrol->write((state.tcontrol->read() & CSR_TCONTROL_MTE) ? CSR_TCONTROL_MPTE : 0);
954958
set_privilege(PRV_M, false);
955959
}
956960
}

riscv/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct state_t
141141
dcsr_csr_t_p dcsr;
142142
csr_t_p tselect;
143143
csr_t_p tdata2;
144+
csr_t_p tcontrol;
144145
csr_t_p scontext;
145146
csr_t_p mcontext;
146147

riscv/triggers.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ bool trigger_t::common_match(processor_t * const proc, bool use_prev_prv) const
5959
auto state = proc->get_state();
6060
auto prv = use_prev_prv ? state->prev_prv : state->prv;
6161
auto v = use_prev_prv ? state->prev_v : state->v;
62-
return mode_match(prv, v) && textra_match(proc);
62+
auto m_enabled = get_action() != 0 || (state->tcontrol->read() & CSR_TCONTROL_MTE);
63+
return (prv < PRV_M || m_enabled) && mode_match(prv, v) && textra_match(proc);
6364
}
6465

6566
bool trigger_t::mode_match(reg_t prv, bool v) const noexcept

0 commit comments

Comments
 (0)