Skip to content

Commit

Permalink
fix(aia): add support for aia xtopei csr (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinceforYy authored Nov 21, 2024
1 parent 14117b1 commit 7d3d2fb
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ coherence via RefillTest.
| `DiffNonRegInterruptPengingEvent` | Non-register interrupts pending | No |
| `DiffMhpmeventOverflowEvent` | Mhpmevent-register overflow | No |
| `DiffCriticalErrorEvent` | Raise critical-error | No |
| `DiffAIAXtopeiEvent` | xtopei from IMSIC | No |

The DiffTest framework comes with a simulation framework with some top-level IOs.
They will be automatically created when calling `DifftestModule.finish(cpu: String)`.
Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/Bundles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,9 @@ class TraceInfo extends DifftestBaseBundle with HasValid {
class CriticalErrorEvent extends DifftestBaseBundle with HasValid {
val criticalError = Bool()
}

class AIAXtopeiEvent extends DifftestBaseBundle with HasValid {
val mtopei = UInt(64.W)
val stopei = UInt(64.W)
val vstopei = UInt(64.W)
}
4 changes: 4 additions & 0 deletions src/main/scala/Difftest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ class DiffCriticalErrorEvent extends CriticalErrorEvent with DifftestBundle {
override val desiredCppName: String = "critical_error"
}

class DiffAIAXtopeiEvent extends AIAXtopeiEvent with DifftestBundle {
override val desiredCppName: String = "aia_xtopei"
}

class DiffTraceInfo(config: GatewayConfig) extends TraceInfo with DifftestBundle {
override val desiredCppName: String = "trace_info"

Expand Down
16 changes: 16 additions & 0 deletions src/test/csrc/difftest/difftest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ int Difftest::step() {
#ifdef CONFIG_DIFFTEST_CRITICALERROREVENT
do_raise_critical_error();
#endif
#ifdef CONFIG_DIFFTEST_AIAXTOPEIEVENT
do_aia_xtopei();
#endif

num_commit = 0; // reset num_commit this cycle to 0
if (dut->event.valid) {
Expand Down Expand Up @@ -1322,6 +1325,19 @@ void Difftest::do_raise_critical_error() {
}
#endif

#ifdef CONFIG_DIFFTEST_AIAXTOPEIEVENT
void Difftest::do_aia_xtopei() {
if (dut->aia_xtopei.valid) {
struct AIAXtopei xtopei;
xtopei.mtopei = dut->aia_xtopei.mtopei;
xtopei.stopei = dut->aia_xtopei.stopei;
xtopei.vstopei = dut->aia_xtopei.vstopei;
proxy->aia_xtopei(xtopei);
dut->aia_xtopei.valid = 0;
}
}
#endif

void Difftest::display() {
printf("\n============== In the last commit group ==============\n");
printf("the first commit instr pc of DUT is 0x%016lx\nthe first commit instr pc of REF is 0x%016lx\n",
Expand Down
3 changes: 3 additions & 0 deletions src/test/csrc/difftest/difftest.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ class Difftest {
#ifdef CONFIG_DIFFTEST_CRITICALERROREVENT
void do_raise_critical_error();
#endif
#ifdef CONFIG_DIFFTEST_AIAXTOPEIEVENT
void do_aia_xtopei();
#endif
#ifdef CONFIG_DIFFTEST_REPLAY
struct {
bool in_replay = false;
Expand Down
17 changes: 16 additions & 1 deletion src/test/csrc/difftest/refproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ class RefProxyConfig {
f(ref_non_reg_interrupt_pending, difftest_non_reg_interrupt_pending, void, void*) \
f(raise_mhpmevent_overflow, difftest_raise_mhpmevent_overflow, void, uint64_t) \
f(ref_raise_critical_error, difftest_raise_critical_error, bool) \
f(ref_get_store_event_other_info, difftest_get_store_event_other_info, void, void*)
f(ref_get_store_event_other_info, difftest_get_store_event_other_info, void, void*) \
f(ref_aia_xtopei, difftest_aia_xtopei, void, void*)
#define RefFunc(func, ret, ...) ret func(__VA_ARGS__)
#define DeclRefFunc(this_func, dummy, ret, ...) RefFunc((*this_func), ret, __VA_ARGS__);
/* clang-format on */
Expand Down Expand Up @@ -263,6 +264,14 @@ class RefProxy : public AbstractRefProxy {
return ref_raise_critical_error ? ref_raise_critical_error() : false;
}

inline void aia_xtopei(struct AIAXtopei &xtopei) {
if (ref_aia_xtopei) {
ref_aia_xtopei(&xtopei);
} else {
printf("Does not support the out-of-core part of AIA.\n");
}
}

inline void guided_exec(struct ExecutionGuide &guide) {
return ref_guided_exec ? ref_guided_exec(&guide) : ref_exec(1);
}
Expand Down Expand Up @@ -391,6 +400,12 @@ struct NonRegInterruptPending {
bool localCounterOverflowInterruptReq;
};

struct AIAXtopei {
uint64_t mtopei;
uint64_t stopei;
uint64_t vstopei;
};

extern const char *difftest_ref_so;
extern uint8_t *ref_golden_mem;

Expand Down
1 change: 1 addition & 0 deletions src/test/scala/DifftestTop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class DifftestTop extends Module {
val difftest_non_reg_interrupt_pending_event = DifftestModule(new DiffNonRegInterruptPendingEvent, dontCare = true)
val difftest_mhpmevent_overflow_event = DifftestModule(new DiffMhpmeventOverflowEvent, dontCare = true)
val difftest_critical_error_event = DifftestModule(new DiffCriticalErrorEvent, dontCare = true)
val difftest_aia_xtopei_event = DifftestModule(new DiffAIAXtopeiEvent, dontCare = true)

DifftestModule.finish("demo")
}
Expand Down

0 comments on commit 7d3d2fb

Please sign in to comment.