forked from pxk27/riscv-hyp-tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wfi_tests.c
100 lines (82 loc) · 2.42 KB
/
wfi_tests.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <rvh_test.h>
#include <csrs.h>
bool wfi_exception_tests() {
TEST_START();
TEST_SETUP_EXCEPT();
goto_priv(PRIV_HU);
wfi();
TEST_ASSERT("U-mode wfi causes illegal instruction exception",
excpt.triggered == true &&
excpt.cause == CAUSE_ILI
);
goto_priv(PRIV_VU);
TEST_SETUP_EXCEPT();
wfi();
TEST_ASSERT("VU-mode wfi causes illegal instruction exception",
excpt.triggered == true &&
excpt.cause == CAUSE_VRTI
);
/* Keep an interrupt pending so we don't get stuck when wfi succeeds */
goto_priv(PRIV_M);
CSRS(mie, 0b0100);
CSRS(mip, 0b0100);
goto_priv(PRIV_M);
TEST_SETUP_EXCEPT();
wfi();
TEST_ASSERT("machine mode wfi does not trigger exception",
excpt.triggered == false
);
/**
* Delegate the pending interrupt to hs mode so it doesnt immediately
* trigger a trap to machine when we jump to hs.
*/
goto_priv(PRIV_M);
CSRS(mideleg, 0b0100);
CSRS(CSR_HIE, 0b0100);
goto_priv(PRIV_HS);
TEST_SETUP_EXCEPT();
wfi();
TEST_ASSERT("S-mode wfi does not trigger exception",
excpt.triggered == false
);
goto_priv(PRIV_M);
CSRS(mstatus, MSTATUS_TW);
goto_priv(PRIV_HS);
TEST_SETUP_EXCEPT();
wfi();
TEST_ASSERT("S-mode wfi triggers illegal instructions exception when mstatus.tw = 1",
excpt.triggered == true &&
excpt.cause == CAUSE_ILI
);
/**
* Delegate the pending interrupt to hs mode so it doesnt immediately
* trigger a trap to machine when we jump to vs.
*/
CSRS(CSR_HIDELEG, 0b0100);
CSRS(CSR_VSIE, 0b0010);
goto_priv(PRIV_VS);
TEST_SETUP_EXCEPT();
wfi();
TEST_ASSERT("VS-mode wfi causes illegal instruction exception when mstatus.tw = 1",
excpt.triggered == true &&
excpt.cause == CAUSE_ILI
);
goto_priv(PRIV_M);
CSRC(mstatus, MSTATUS_TW);
goto_priv(PRIV_VS);
TEST_SETUP_EXCEPT();
wfi();
TEST_ASSERT("VS-mode wfi does not trap when mstatus.tw = 0 and hstatus.vtw = 0",
excpt.triggered == false
);
goto_priv(PRIV_M);
CSRS(CSR_HSTATUS, HSTATUS_VTW);
goto_priv(PRIV_VS);
TEST_SETUP_EXCEPT();
wfi();
TEST_ASSERT("VS-mode wfi triggers virtual inst. exception when hstatus.vtw = 1",
excpt.triggered == true &&
excpt.cause == CAUSE_VRTI
);
TEST_END();
}