-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclint.c
49 lines (41 loc) · 947 Bytes
/
clint.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
#include "clint.h"
struct rv32_clint *clint_init()
{
struct rv32_clint *clint = malloc(sizeof(struct rv32_clint));
clint->mtimecmp = 0;
clint->mtime = 0;
return clint;
}
exception_t read_clint(struct rv32_clint *clint,
u32 addr,
u32 size,
u32 *result)
{
if (size != 32)
return LOAD_ACCESS_FAULT;
switch (addr) {
case CLINT_MTIMECMP:
*result = clint->mtimecmp;
break;
case CLINT_MTIME:
*result = clint->mtime;
break;
default:
*result = 0;
}
return OK;
}
exception_t write_clint(struct rv32_clint *clint, u32 addr, u32 size, u32 value)
{
if (size != 32)
return STORE_AMO_ACCESS_FAULT;
switch (addr) {
case CLINT_MTIMECMP:
clint->mtimecmp = value;
break;
case CLINT_MTIME:
clint->mtime = value;
break;
}
return OK;
}