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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use bit_field::BitField;
#[derive(Clone, Copy, Debug)]
pub struct Mxstatus {
bits: usize,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum PM {
Machine = 3,
Supervisor = 1,
User = 0,
}
impl Mxstatus {
#[inline]
pub fn pmdu(&self) -> bool {
self.bits.get_bit(10)
}
#[inline]
pub fn pmds(&self) -> bool {
self.bits.get_bit(11)
}
#[inline]
pub fn pmdm(&self) -> bool {
self.bits.get_bit(12)
}
#[inline]
pub fn pmp4k(&self) -> bool {
self.bits.get_bit(14)
}
#[inline]
pub fn mm(&self) -> bool {
self.bits.get_bit(15)
}
#[inline]
pub fn ucme(&self) -> bool {
self.bits.get_bit(16)
}
#[inline]
pub fn clintee(&self) -> bool {
self.bits.get_bit(17)
}
#[inline]
pub fn mhrd(&self) -> bool {
self.bits.get_bit(18)
}
#[inline]
pub fn maee(&self) -> bool {
self.bits.get_bit(21)
}
#[inline]
pub fn theadisaee(&self) -> bool {
self.bits.get_bit(22)
}
#[inline]
pub fn pm(&self) -> PM {
match self.bits.get_bits(30..=31) {
0b00 => PM::User,
0b01 => PM::Supervisor,
0b11 => PM::Machine,
_ => unreachable!(),
}
}
}
set!(0x7C0);
clear!(0x7C0);
read_csr_as!(Mxstatus, 0x7C0);
set_clear_csr! {
, set_pmdu, clear_pmdu, 1 << 10
}
set_clear_csr! {
, set_pmds, clear_pmds, 1 << 11
}
set_clear_csr! {
, set_pmdm, clear_pmdm, 1 << 13
}
set_clear_csr! {
, set_mm, clear_mm, 1 << 15
}
set_clear_csr! {
, set_ucme, clear_ucme, 1 << 16
}
set_clear_csr! {
, set_clintee, clear_clintee, 1 << 17
}
set_clear_csr! {
, set_mhrd, clear_mhrd, 1 << 18
}
set_clear_csr! {
, set_maee, clear_maee, 1 << 21
}
set_clear_csr! {
, set_theadisaee, clear_theadisaee, 1 << 22
}