diff --git a/README.md b/README.md index 03d92df6f..017f51936 100644 --- a/README.md +++ b/README.md @@ -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)`. diff --git a/src/main/scala/Bundles.scala b/src/main/scala/Bundles.scala index 3450f790f..40beca3ee 100644 --- a/src/main/scala/Bundles.scala +++ b/src/main/scala/Bundles.scala @@ -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() +} diff --git a/src/main/scala/Difftest.scala b/src/main/scala/Difftest.scala index eeac31c24..0b2b077ed 100644 --- a/src/main/scala/Difftest.scala +++ b/src/main/scala/Difftest.scala @@ -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" diff --git a/src/test/csrc/difftest/difftest.cpp b/src/test/csrc/difftest/difftest.cpp index 32fa07d00..c7de0b270 100644 --- a/src/test/csrc/difftest/difftest.cpp +++ b/src/test/csrc/difftest/difftest.cpp @@ -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) { @@ -1292,6 +1295,16 @@ void Difftest::do_mhpmevent_overflow() { if (dut->mhpmevent_overflow.valid) { proxy->mhpmevent_overflow(dut->mhpmevent_overflow.mhpmeventOverflow); dut->mhpmevent_overflow.valid = 0; + } + } +#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 diff --git a/src/test/csrc/difftest/difftest.h b/src/test/csrc/difftest/difftest.h index 9a8150e12..a853f2448 100644 --- a/src/test/csrc/difftest/difftest.h +++ b/src/test/csrc/difftest/difftest.h @@ -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; diff --git a/src/test/scala/DifftestTop.scala b/src/test/scala/DifftestTop.scala index 296f68e97..bd55b5471 100644 --- a/src/test/scala/DifftestTop.scala +++ b/src/test/scala/DifftestTop.scala @@ -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") }