Skip to content

Commit bd50b4b

Browse files
committed
feat(exception): add hardware error exception
* Since the hardware error exception can only be generated by XiangShan, it can be handled similarly to an interrupt — by directly forcing NEMU to trigger the corresponding exception handler.
1 parent 826fe99 commit bd50b4b

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/test/csrc/difftest/difftest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ void Difftest::do_interrupt() {
477477

478478
void Difftest::do_exception() {
479479
state->record_exception(dut->event.exceptionPC, dut->event.exceptionInst, dut->event.exception);
480-
if (dut->event.exception == 12 || dut->event.exception == 13 || dut->event.exception == 15 ||
481-
dut->event.exception == 20 || dut->event.exception == 21 || dut->event.exception == 23) {
480+
if (dut->event.exception == EX_IPF || dut->event.exception == EX_LPF || dut->event.exception == EX_SPF ||
481+
dut->event.exception == EX_IGPF || dut->event.exception == EX_LGPF || dut->event.exception == EX_SGPF) {
482482
struct ExecutionGuide guide;
483483
guide.force_raise_exception = true;
484484
guide.exception_num = dut->event.exception;
@@ -491,6 +491,8 @@ void Difftest::do_exception() {
491491
#endif // CONFIG_DIFFTEST_HCSRSTATE
492492
guide.force_set_jump_target = false;
493493
proxy->guided_exec(guide);
494+
} else if (dut->event.exception == EX_HWE) {
495+
proxy->raise_intr(dut->event.exception);
494496
} else {
495497
#ifdef DEBUG_MODE_DIFF
496498
if (DEBUG_MEM_REGION(true, dut->event.exceptionPC)) {

src/test/csrc/difftest/difftest.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@
2929
#include "emu.h"
3030
#endif // FUZZING
3131

32+
enum {
33+
EX_IAM, // instruction address misaligned
34+
EX_IAF, // instruction address fault
35+
EX_II, // illegal instruction
36+
EX_BP, // breakpoint
37+
EX_LAM, // load address misaligned
38+
EX_LAF, // load address fault
39+
EX_SAM, // store/amo address misaligned
40+
EX_SAF, // store/amo address fault
41+
EX_ECU, // ecall from U-mode or VU-mode
42+
EX_ECS, // ecall from HS-mode
43+
EX_ECVS, // ecall from VS-mode, H-extention
44+
EX_ECM, // ecall from M-mode
45+
EX_IPF, // instruction page fault
46+
EX_LPF, // load page fault
47+
EX_RS0, // reserved
48+
EX_SPF, // store/amo page fault
49+
EX_DT, // double trap
50+
EX_RS1, // reserved
51+
EX_SWC, // software check
52+
EX_HWE, // hardware error
53+
EX_IGPF = 20, // instruction guest-page fault, H-extention
54+
EX_LGPF, // load guest-page fault, H-extention
55+
EX_VI, // virtual instruction, H-extention
56+
EX_SGPF // store/amo guest-page fault, H-extention
57+
};
58+
3259
enum {
3360
ICACHEID,
3461
DCACHEID,

0 commit comments

Comments
 (0)