Skip to content

Commit

Permalink
feat(dbltrp): add support for critical-error
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislzh committed Oct 28, 2024
1 parent 0f6d775 commit 5ce068b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ coherence via RefillTest.
| `DiffLrScEvent` | Executed LR/SC instructions | No |
| `DiffNonRegInterruptPengingEvent` | Non-register interrupts pending | No |
| `DiffMhpmeventOverflowEvent` | Mhpmevent-register overflow | No |
| `DiffDiffCriticalErrorEvent` | Raise critical-error | 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
4 changes: 4 additions & 0 deletions src/main/scala/Bundles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,7 @@ class TraceInfo extends DifftestBaseBundle with HasValid {
val trace_head = UInt(16.W)
val trace_size = UInt(16.W)
}

class CriticalErrorEvent extends DifftestBaseBundle with HasValid {
val criticalError = Bool()
}
4 changes: 4 additions & 0 deletions src/main/scala/Difftest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ class DiffMhpmeventOverflowEvent extends MhpmeventOverflowEvent with DifftestBun
override val desiredCppName: String = "mhpmevent_overflow"
}

class DiffCriticalErrorEvent extends CriticalErrorEvent with DifftestBundle {
override val desiredCppName: String = "critical_error"
}

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

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

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

#ifdef CONFIG_DIFFTEST_CRITICALERROREVENT
void Difftest::do_raise_critical_error() {
if (dut->critical_error.valid) {
display();
Info("Core %d dump: critical_error raise \n", this->id);
raise_trap(STATE_ABORT);
}
}
#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 @@ -422,6 +422,9 @@ class Difftest {
#ifdef CONFIG_DIFFTEST_MHPMEVENTOVERFLOWEVENT
void do_mhpmevent_overflow();
#endif
#ifdef CONFIG_DIFFTEST_CRITICALERROREVENT
void do_raise_critical_error();
#endif
#ifdef CONFIG_DIFFTEST_REPLAY
struct {
bool in_replay = false;
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 @@ -58,6 +58,7 @@ class DifftestTop extends Module {
val difftest_runahead_redirect_event = DifftestModule(new DiffRunaheadRedirectEvent, dontCare = true)
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)

DifftestModule.finish("demo")
}
Expand Down

0 comments on commit 5ce068b

Please sign in to comment.