Skip to content

Commit 262d3b3

Browse files
committed
Fix register configuration and documents
1 parent 1fab9a9 commit 262d3b3

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

src/register/satp.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! satp register
22
3-
#[cfg(riscv)]
43
use bit_field::BitField;
54

65
/// satp register
@@ -18,7 +17,7 @@ impl Satp {
1817

1918
/// Current address-translation scheme
2019
#[inline]
21-
#[cfg(riscv32)]
20+
#[cfg(target_pointer_width = "32")]
2221
pub fn mode(&self) -> Mode {
2322
match self.bits.get_bit(31) {
2423
false => Mode::Bare,
@@ -28,7 +27,7 @@ impl Satp {
2827

2928
/// Current address-translation scheme
3029
#[inline]
31-
#[cfg(riscv64)]
30+
#[cfg(target_pointer_width = "64")]
3231
pub fn mode(&self) -> Mode {
3332
match self.bits.get_bits(60..64) {
3433
0 => Mode::Bare,
@@ -42,55 +41,65 @@ impl Satp {
4241

4342
/// Address space identifier
4443
#[inline]
45-
#[cfg(riscv32)]
44+
#[cfg(target_pointer_width = "32")]
4645
pub fn asid(&self) -> usize {
4746
self.bits.get_bits(22..31)
4847
}
4948

5049
/// Address space identifier
5150
#[inline]
52-
#[cfg(riscv64)]
51+
#[cfg(target_pointer_width = "64")]
5352
pub fn asid(&self) -> usize {
5453
self.bits.get_bits(44..60)
5554
}
5655

5756
/// Physical page number
5857
#[inline]
59-
#[cfg(riscv32)]
58+
#[cfg(target_pointer_width = "32")]
6059
pub fn ppn(&self) -> usize {
6160
self.bits.get_bits(0..22)
6261
}
6362

6463
/// Physical page number
6564
#[inline]
66-
#[cfg(riscv64)]
65+
#[cfg(target_pointer_width = "64")]
6766
pub fn ppn(&self) -> usize {
6867
self.bits.get_bits(0..44)
6968
}
7069
}
7170

72-
#[cfg(riscv32)]
71+
/// 32-bit satp mode
72+
#[cfg(target_pointer_width = "32")]
7373
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7474
pub enum Mode {
75+
/// No translation or protection
7576
Bare = 0,
77+
/// Page-based 32-bit virtual addressing
7678
Sv32 = 1,
7779
}
7880

79-
#[cfg(riscv64)]
81+
/// 64-bit satp mode
82+
#[cfg(target_pointer_width = "64")]
8083
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8184
pub enum Mode {
85+
/// No translation or protection
8286
Bare = 0,
87+
/// Page-based 32-bit virtual addressing
8388
Sv39 = 8,
89+
/// Page-based 48-bit virtual addressing
8490
Sv48 = 9,
91+
/// Page-based 57-bit virtual addressing
8592
Sv57 = 10,
93+
/// Page-based 64-bit virtual addressing
8694
Sv64 = 11,
8795
}
8896

8997
read_csr_as!(Satp, 0x180, __read_satp);
9098
write_csr_as_usize!(0x180, __write_satp);
9199

100+
/// Sets the register to corresponding page table mode, physical page number and address space id.
92101
#[inline]
93-
#[cfg(riscv32)]
102+
#[cfg(target_pointer_width = "32")]
94103
pub unsafe fn set(mode: Mode, asid: usize, ppn: usize) {
95104
let mut bits = 0usize;
96105
bits.set_bits(31..32, mode as usize);
@@ -99,8 +108,9 @@ pub unsafe fn set(mode: Mode, asid: usize, ppn: usize) {
99108
_write(bits);
100109
}
101110

111+
/// Sets the register to corresponding page table mode, physical page number and address space id.
102112
#[inline]
103-
#[cfg(riscv64)]
113+
#[cfg(target_pointer_width = "64")]
104114
pub unsafe fn set(mode: Mode, asid: usize, ppn: usize) {
105115
let mut bits = 0usize;
106116
bits.set_bits(60..64, mode as usize);

src/register/scause.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ read_csr_as!(Scause, 0x142, __read_scause);
118118
write_csr!(0x142, __write_scause);
119119

120120
/// Writes the CSR
121+
#[inline]
121122
pub unsafe fn write(bits: usize) {
122123
_write(bits)
123124
}
124125

125126
/// Set supervisor cause register to corresponding cause.
127+
#[inline]
126128
pub unsafe fn set(cause: Trap) {
127129
let bits = match cause {
128130
Trap::Interrupt(i) => match i {

src/register/stval.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ read_csr_as_usize!(0x143, __read_stval);
44
write_csr!(0x143, __write_stval);
55

66
/// Writes the CSR
7+
#[inline]
78
pub unsafe fn write(bits: usize) {
89
_write(bits)
910
}

src/register/ucause.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ read_csr_as!(Ucause, 0x042, __read_ucause);
1818
write_csr!(0x042, __write_ucause);
1919

2020
/// Writes the CSR
21+
#[inline]
2122
pub unsafe fn write(bits: usize) {
2223
_write(bits)
2324
}

src/register/utval.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ read_csr_as_usize!(0x043, __read_utval);
44
write_csr!(0x043, __write_utval);
55

66
/// Writes the CSR
7+
#[inline]
78
pub unsafe fn write(bits: usize) {
89
_write(bits)
910
}

0 commit comments

Comments
 (0)