Skip to content

Commit

Permalink
Merge pull request #1688 from YenHaoChen/pr-tcontrol
Browse files Browse the repository at this point in the history
triggers: implement tcontrol
  • Loading branch information
aswaterman committed Jun 11, 2024
2 parents 00dfa28 + db76232 commit 9bcda41
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions riscv/insn_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
#include "specialize.h"
#include "tracer.h"
#include "v_ext_macros.h"
#include "debug_defines.h"
#include <assert.h>
1 change: 1 addition & 0 deletions riscv/insns/mret.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ if (ZICFILP_xLPE(prev_virt, prev_prv)) {
s = set_field(s, MSTATUS_MPELP, elp_t::NO_LP_EXPECTED);
STATE.mstatus->write(s);
if (STATE.mstatush) STATE.mstatush->write(s >> 32); // log mstatush change
STATE.tcontrol->write((STATE.tcontrol->read() & CSR_TCONTROL_MPTE) ? (CSR_TCONTROL_MPTE | CSR_TCONTROL_MTE) : 0);
p->set_privilege(prev_prv, prev_virt);
4 changes: 4 additions & 0 deletions riscv/processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "disasm.h"
#include "platform.h"
#include "vector_unit.h"
#include "debug_defines.h"
#include <cinttypes>
#include <cmath>
#include <cstdlib>
Expand Down Expand Up @@ -403,11 +404,13 @@ void state_t::reset(processor_t* const proc, reg_t max_isa)
csrmap[CSR_TDATA2] = tdata2 = std::make_shared<tdata2_csr_t>(proc, CSR_TDATA2);
csrmap[CSR_TDATA3] = std::make_shared<tdata3_csr_t>(proc, CSR_TDATA3);
csrmap[CSR_TINFO] = std::make_shared<tinfo_csr_t>(proc, CSR_TINFO);
csrmap[CSR_TCONTROL] = tcontrol = std::make_shared<masked_csr_t>(proc, CSR_TCONTROL, CSR_TCONTROL_MPTE | CSR_TCONTROL_MTE, 0);
} else {
csrmap[CSR_TDATA1] = std::make_shared<const_csr_t>(proc, CSR_TDATA1, 0);
csrmap[CSR_TDATA2] = tdata2 = std::make_shared<const_csr_t>(proc, CSR_TDATA2, 0);
csrmap[CSR_TDATA3] = std::make_shared<const_csr_t>(proc, CSR_TDATA3, 0);
csrmap[CSR_TINFO] = std::make_shared<const_csr_t>(proc, CSR_TINFO, 0);
csrmap[CSR_TCONTROL] = tcontrol = std::make_shared<const_csr_t>(proc, CSR_TCONTROL, 0);
}
unsigned scontext_length = (xlen == 32 ? 16 : 32); // debug spec suggests 16-bit for RV32 and 32-bit for RV64
csrmap[CSR_SCONTEXT] = scontext = std::make_shared<masked_csr_t>(proc, CSR_SCONTEXT, (reg_t(1) << scontext_length) - 1, 0);
Expand Down Expand Up @@ -951,6 +954,7 @@ void processor_t::take_trap(trap_t& t, reg_t epc)
state.elp = elp_t::NO_LP_EXPECTED;
state.mstatus->write(s);
if (state.mstatush) state.mstatush->write(s >> 32); // log mstatush change
state.tcontrol->write((state.tcontrol->read() & CSR_TCONTROL_MTE) ? CSR_TCONTROL_MPTE : 0);
set_privilege(PRV_M, false);
}
}
Expand Down
1 change: 1 addition & 0 deletions riscv/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ struct state_t
dcsr_csr_t_p dcsr;
csr_t_p tselect;
csr_t_p tdata2;
csr_t_p tcontrol;
csr_t_p scontext;
csr_t_p mcontext;

Expand Down
3 changes: 2 additions & 1 deletion riscv/triggers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ bool trigger_t::common_match(processor_t * const proc, bool use_prev_prv) const
auto state = proc->get_state();
auto prv = use_prev_prv ? state->prev_prv : state->prv;
auto v = use_prev_prv ? state->prev_v : state->v;
return mode_match(prv, v) && textra_match(proc);
auto m_enabled = get_action() != 0 || (state->tcontrol->read() & CSR_TCONTROL_MTE);
return (prv < PRV_M || m_enabled) && mode_match(prv, v) && textra_match(proc);
}

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

0 comments on commit 9bcda41

Please sign in to comment.