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
|
/* default exception model */
type ext_exception = unit
function handle_trap_extension(p : Privilege, pc : xlenbits, u : option(unit)) -> unit = ()
/* used for traps and ECALL */
function prepare_trap_vector(p : Privilege, cause : Mcause) -> xlenbits = {
let tvec : Mtvec = match p {
Machine => mtvec,
Supervisor => stvec,
User => utvec
};
match tvec_addr(tvec, cause) {
Some(epc) => epc,
None() => internal_error("Invalid tvec mode")
}
}
/* xRET handling involves three functions:
*
* get_xret_target: used to read the value of the xret target (no control flow transfer)
* set_xret_target: used to write a value of the xret target (no control flow transfer)
* prepare_xret_target: used to get the value for control transfer to the xret target
*/
val get_xret_target : Privilege -> xlenbits effect {rreg}
function get_xret_target(p) =
match p {
Machine => mepc,
Supervisor => sepc,
User => uepc
}
val set_xret_target : (Privilege, xlenbits) -> xlenbits effect {rreg, wreg}
function set_xret_target(p, value) = {
let target = legalize_xepc(value);
match p {
Machine => mepc = target,
Supervisor => sepc = target,
User => uepc = target
};
target
}
val prepare_xret_target : (Privilege) -> xlenbits effect {rreg, wreg}
function prepare_xret_target(p) =
get_xret_target(p)
/* other trap-related CSRs */
function get_mtvec() -> xlenbits =
mtvec.bits()
function get_stvec() -> xlenbits =
stvec.bits()
function get_utvec() -> xlenbits =
utvec.bits()
function set_mtvec(value : xlenbits) -> xlenbits = {
mtvec = legalize_tvec(mtvec, value);
mtvec.bits()
}
function set_stvec(value : xlenbits) -> xlenbits = {
stvec = legalize_tvec(stvec, value);
stvec.bits()
}
function set_utvec(value : xlenbits) -> xlenbits = {
utvec = legalize_tvec(utvec, value);
utvec.bits()
}
|