Skip to content

Commit

Permalink
fix(csr): htinst/mtinst are always written 0 when trap in XiangShan
Browse files Browse the repository at this point in the history
Currently, XiangShan only support writing 0 to htinst & mtinst CSRs when trap occurs. To align with XiangShan, this patch wraps the update of htinst & mtinst CSRs in take_trap function.
  • Loading branch information
cebarobot authored and huxuan0307 committed Sep 10, 2024
1 parent 9f65bc1 commit 347cd0e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions riscv/processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,11 @@ void processor_t::take_trap(trap_t& t, reg_t epc)
#endif
state.nonvirtual_stval->write(t.get_tval());
state.htval->write(t.get_tval2());
#ifdef CPU_XIANGSHAN
state.htinst->write(0);
#else
state.htinst->write(t.get_tinst());
#endif

reg_t s = state.nonvirtual_sstatus->read();
s = set_field(s, MSTATUS_SPIE, get_field(s, MSTATUS_SIE));
Expand Down Expand Up @@ -553,7 +557,11 @@ void processor_t::take_trap(trap_t& t, reg_t epc)
state.mcause->write(supv_double_trap ? CAUSE_DOUBLE_TRAP : t.cause());
state.mtval->write(t.get_tval());
state.mtval2->write(supv_double_trap ? t.cause() : t.get_tval2());
#ifdef CPU_XIANGSHAN
state.mtinst->write(0);
#else
state.mtinst->write(t.get_tinst());
#endif

s = set_field(s, MSTATUS_MPIE, get_field(s, MSTATUS_MIE));
s = set_field(s, MSTATUS_MPP, state.prv);
Expand Down

0 comments on commit 347cd0e

Please sign in to comment.