Skip to content

Commit 6392fa9

Browse files
bors[bot]luojia65
andauthored
Merge #52
52: Add CSR register `medeleg`; small doc fix r=Disasm a=luojia65 mideleg is at 0x303; medeleg is at 0x302. Co-authored-by: luojia65 <me@luojia.cc>
2 parents 4d16f14 + 7309236 commit 6392fa9

File tree

3 files changed

+164
-16
lines changed

3 files changed

+164
-16
lines changed

src/register/medeleg.rs

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
//! medeleg register
2+
3+
use bit_field::BitField;
4+
5+
/// medeleg register
6+
#[derive(Clone, Copy, Debug)]
7+
pub struct Medeleg {
8+
bits: usize,
9+
}
10+
11+
impl Medeleg {
12+
/// Returns the contents of the register as raw bits
13+
#[inline]
14+
pub fn bits(&self) -> usize {
15+
self.bits
16+
}
17+
18+
/// Instruction Address Misaligned Delegate
19+
#[inline]
20+
pub fn instruction_misaligned(&self) -> bool {
21+
self.bits.get_bit(0)
22+
}
23+
24+
/// Instruction Access Fault Delegate
25+
#[inline]
26+
pub fn instruction_fault(&self) -> bool {
27+
self.bits.get_bit(1)
28+
}
29+
30+
/// Illegal Instruction Delegate
31+
#[inline]
32+
pub fn illegal_instruction(&self) -> bool {
33+
self.bits.get_bit(2)
34+
}
35+
36+
/// Breakpoint Delegate
37+
#[inline]
38+
pub fn breakpoint(&self) -> bool {
39+
self.bits.get_bit(3)
40+
}
41+
42+
/// Load Address Misaligned Delegate
43+
#[inline]
44+
pub fn load_misaligned(&self) -> bool {
45+
self.bits.get_bit(4)
46+
}
47+
48+
/// Load Access Fault Delegate
49+
#[inline]
50+
pub fn load_fault(&self) -> bool {
51+
self.bits.get_bit(5)
52+
}
53+
54+
/// Store/AMO Address Misaligned Delegate
55+
#[inline]
56+
pub fn store_misaligned(&self) -> bool {
57+
self.bits.get_bit(6)
58+
}
59+
60+
/// Store/AMO Access Fault Delegate
61+
#[inline]
62+
pub fn store_fault(&self) -> bool {
63+
self.bits.get_bit(7)
64+
}
65+
66+
/// Environment Call from U-mode Delegate
67+
#[inline]
68+
pub fn user_env_call(&self) -> bool {
69+
self.bits.get_bit(8)
70+
}
71+
72+
/// Environment Call from S-mode Delegate
73+
#[inline]
74+
pub fn supervisor_env_call(&self) -> bool {
75+
self.bits.get_bit(9)
76+
}
77+
78+
/// Environment Call from M-mode Delegate
79+
#[inline]
80+
pub fn machine_env_call(&self) -> bool {
81+
self.bits.get_bit(11)
82+
}
83+
84+
/// Instruction Page Fault Delegate
85+
#[inline]
86+
pub fn instruction_page_fault(&self) -> bool {
87+
self.bits.get_bit(12)
88+
}
89+
90+
/// Load Page Fault Delegate
91+
#[inline]
92+
pub fn load_page_fault(&self) -> bool {
93+
self.bits.get_bit(13)
94+
}
95+
96+
/// Store/AMO Page Fault Delegate
97+
#[inline]
98+
pub fn store_page_fault(&self) -> bool {
99+
self.bits.get_bit(15)
100+
}
101+
}
102+
103+
read_csr_as!(Medeleg, 0x302, __read_medeleg);
104+
set!(0x302, __set_medeleg);
105+
clear!(0x302, __clear_medeleg);
106+
107+
set_clear_csr!(
108+
/// Instruction Address Misaligned Delegate
109+
, set_instruction_misaligned, clear_instruction_misaligned, 1 << 0);
110+
set_clear_csr!(
111+
/// Instruction Access Fault Delegate
112+
, set_instruction_fault, clear_instruction_fault, 1 << 1);
113+
set_clear_csr!(
114+
/// Illegal Instruction Delegate
115+
, set_illegal_instruction, clear_illegal_instruction, 1 << 2);
116+
set_clear_csr!(
117+
/// Breakpoint Delegate
118+
, set_breakpoint, clear_breakpoint, 1 << 3);
119+
set_clear_csr!(
120+
/// Load Address Misaligned Delegate
121+
, set_load_misaligned, clear_load_misaligned, 1 << 4);
122+
set_clear_csr!(
123+
/// Load Access Fault Delegate
124+
, set_load_fault, clear_load_fault, 1 << 5);
125+
set_clear_csr!(
126+
/// Store/AMO Address Misaligned Delegate
127+
, set_store_misaligned, clear_store_misaligned, 1 << 6);
128+
set_clear_csr!(
129+
/// Store/AMO Access fault
130+
, set_store_fault, clear_store_fault, 1 << 7);
131+
set_clear_csr!(
132+
/// Environment Call from U-mode Delegate
133+
, set_user_env_call, clear_user_env_call, 1 << 8);
134+
set_clear_csr!(
135+
/// Environment Call from S-mode Delegate
136+
, set_supervisor_env_call, clear_supervisor_env_call, 1 << 9);
137+
set_clear_csr!(
138+
/// Environment Call from M-mode Delegate
139+
, set_machine_env_call, clear_machine_env_call, 1 << 11);
140+
set_clear_csr!(
141+
/// Instruction Page Fault Delegate
142+
, set_instruction_page_fault, clear_instruction_page_fault, 1 << 12);
143+
set_clear_csr!(
144+
/// Load Page Fault Delegate
145+
, set_load_page_fault, clear_load_page_fault, 1 << 13);
146+
set_clear_csr!(
147+
/// Store/AMO Page Fault Delegate
148+
, set_store_page_fault, clear_store_page_fault, 1 << 15);

src/register/mideleg.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,62 @@ impl Mideleg {
1515
self.bits
1616
}
1717

18-
/// User Software Interrupt Enable
18+
/// User Software Interrupt Delegate
1919
#[inline]
2020
pub fn usoft(&self) -> bool {
2121
self.bits.get_bit(0)
2222
}
2323

24-
/// Supervisor Software Interrupt Enable
24+
/// Supervisor Software Interrupt Delegate
2525
#[inline]
2626
pub fn ssoft(&self) -> bool {
2727
self.bits.get_bit(1)
2828
}
2929

30-
/// User Timer Interrupt Enable
30+
/// User Timer Interrupt Delegate
3131
#[inline]
3232
pub fn utimer(&self) -> bool {
3333
self.bits.get_bit(4)
3434
}
3535

36-
/// Supervisor Timer Interrupt Enable
36+
/// Supervisor Timer Interrupt Delegate
3737
#[inline]
3838
pub fn stimer(&self) -> bool {
3939
self.bits.get_bit(5)
4040
}
4141

42-
/// User External Interrupt Enable
42+
/// User External Interrupt Delegate
4343
#[inline]
4444
pub fn uext(&self) -> bool {
4545
self.bits.get_bit(8)
4646
}
4747

48-
/// Supervisor External Interrupt Enable
48+
/// Supervisor External Interrupt Delegate
4949
#[inline]
5050
pub fn sext(&self) -> bool {
5151
self.bits.get_bit(9)
5252
}
5353
}
5454

55-
read_csr_as!(Mideleg, 0x304, __read_mideleg);
55+
read_csr_as!(Mideleg, 0x303, __read_mideleg);
5656
set!(0x303, __set_mideleg);
5757
clear!(0x303, __clear_mideleg);
5858

5959
set_clear_csr!(
60-
/// User Software Interrupt Pending
60+
/// User Software Interrupt Delegate
6161
, set_usoft, clear_usoft, 1 << 0);
6262
set_clear_csr!(
63-
/// Supervisor Software Interrupt Pending
63+
/// Supervisor Software Interrupt Delegate
6464
, set_ssoft, clear_ssoft, 1 << 1);
6565
set_clear_csr!(
66-
/// User Timer Interrupt Pending
66+
/// User Timer Interrupt Delegate
6767
, set_utimer, clear_utimer, 1 << 4);
6868
set_clear_csr!(
69-
/// Supervisor Timer Interrupt Pending
69+
/// Supervisor Timer Interrupt Delegate
7070
, set_stimer, clear_stimer, 1 << 5);
7171
set_clear_csr!(
72-
/// User External Interrupt Pending
72+
/// User External Interrupt Delegate
7373
, set_uext, clear_uext, 1 << 8);
7474
set_clear_csr!(
75-
/// Supervisor External Interrupt Pending
75+
/// Supervisor External Interrupt Delegate
7676
, set_sext, clear_sext, 1 << 9);

src/register/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ pub mod mimpid;
6161
pub mod mvendorid;
6262

6363
// Machine Trap Setup
64-
pub mod misa;
65-
pub mod mstatus;
66-
// TODO: medeleg
64+
pub mod medeleg;
6765
pub mod mideleg;
6866
pub mod mie;
67+
pub mod misa;
68+
pub mod mstatus;
6969
pub mod mtvec;
7070
// TODO: mcounteren
7171

0 commit comments

Comments
 (0)