forked from pxk27/riscv-hyp-tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
83 lines (67 loc) · 3.01 KB
/
main.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
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <rvh_test.h>
bool check_csr_field_spec(){
TEST_START();
/* this assumes machine mode */
//check_csr_wrrd("mstatus", mstatus, (uint64_t) -1, 0x800000ca007e79aaULL);
//check_csr_wrrd("mideleg", mideleg, (uint64_t) -1, 0x1666);
//check_csr_wrrd("medeleg", medeleg, (uint64_t) -1, 0xb15d);
check_csr_wrrd("mideleg", mideleg, (uint64_t)0, 0x444);
//check_csr_wrrd("mip", mip, (uint64_t) -1, 0x6e6);
//check_csr_wrrd("mie", mie, (uint64_t) -1, 0x1eee);
check_csr_wrrd("mtinst", CSR_MTINST, (uint64_t) -1, (uint64_t) -1);
check_csr_wrrd("mtval2", CSR_MTVAL2, (uint64_t) -1, (uint64_t) -1);
//check_csr_wrrd("hstatus", CSR_HSTATUS, (uint64_t) -1, 0x30053f3e0);
//check_csr_wrrd("hideleg", CSR_HIDELEG, (uint64_t) -1, 0x444);
//check_csr_wrrd("hedeleg", CSR_HEDELEG, (uint64_t) -1, 0xb1ff);
//check_csr_wrrd("hvip", CSR_HVIP, (uint64_t) -1, 0x444);
//check_csr_wrrd("hip", CSR_HIP, (uint64_t) -1, 0x4);
check_csr_wrrd("hie", CSR_HIE, (uint64_t) -1, 0x444);
check_csr_wrrd("htval", CSR_HTVAL, (uint64_t) -1, (uint64_t) -1);
check_csr_wrrd("htinst", CSR_HTINST, (uint64_t) -1, (uint64_t) -1);
//check_csr_wrrd("hgatp", CSR_HGATP, (8ULL << 60) | (1ULL << 60)-1, 0x80000000000fffffULL);
//check_csr_wrrd("vsstatus", CSR_VSSTATUS, (uint64_t) -1, 0x80000000000c6122ULL);
//check_csr_wrrd("vsip", CSR_VSIP, (uint64_t) -1, 0x0);
//check_csr_wrrd("vsie", CSR_VSIE, (uint64_t) -1, 0x0);
//check_csr_wrrd("vstvec", CSR_VSTVEC, (uint64_t) -1, 0xffffffffffffff01ULL);
check_csr_wrrd("vsscratch", CSR_VSSCRATCH, (uint64_t) -1, (uint64_t) -1);
//check_csr_wrrd("vsepc", CSR_VSEPC, (uint64_t) -1, 0xfffffffffffffffeULL);
//check_csr_wrrd("vscause", CSR_VSCAUSE, (uint64_t) -1, 0x800000000000001fULL);
check_csr_wrrd("vstval", CSR_VSTVAL, (uint64_t) -1, 0xffffffffffffffffULL);
//check_csr_wrrd("vsatp", CSR_VSATP, (uint64_t) -1, 0x0);
//check_csr_wrrd("vsatp", CSR_VSATP, (8ULL << 60) | (1ULL << 60)-1, 0x80000000000fffffULL);
TEST_END();
}
bool check_misa_h(){
TEST_START();
uint64_t misa = CSRR(misa);
CSRS(misa, (1ULL << 7));
bool hyp_ext_present = CSRR(misa) & (1ULL << 7);
TEST_ASSERT("check h bit after setting it", hyp_ext_present, "hypervisor extensions not present");
if(!hyp_ext_present)
return false;
/*nemu don't support that misa control whether an extension is enabled or not*/
// CSRC(misa, (1ULL << 7));
// if(((CSRR(misa) & (1ULL << 7)))){
// VERBOSE("misa h bit is hardwired");
// }
// CSRW(misa, misa);
TEST_END();
}
void main(){
if (hyp_test_table_size > 0) {
INFO("risc-v hypervisor extension tests");
if(check_misa_h()){
reset_state();
for(int i = 0; i < hyp_test_table_size; i++)
hyp_test_table[i]();
}else{
printf("hypervisor extension is not supported!\n");
}
INFO("end");
}
exit(0);
}