-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
riscv: register: fix smeh and smel register definitions
- always export smel register, but make `read` effective only on 64-bit architectures; - fix page_size definition on smeh register. Signed-off-by: Zhouqi Jiang <[email protected]>
- Loading branch information
Showing
4 changed files
with
43 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
//! smel, supervisor memory entry low register | ||
//! smel, supervisor memory entry low register. | ||
use crate::paging::Entry; | ||
use core::arch::asm; | ||
|
||
/// Reads the smel register | ||
/// Reads the smel register. | ||
/// | ||
/// The `xuantie-riscv`` crate assumes that the `smel` register is available only on | ||
/// 64-bit Xuantie architectures. Attempting to read the smel register on non-64-bit | ||
/// architectures using this function will result in an `unimplemented!` panic. | ||
#[inline] | ||
pub fn read() -> Entry { | ||
let bits: usize; | ||
unsafe { asm!("csrr {}, 0x9C1", out(reg) bits) } | ||
Entry::from_bits(bits) | ||
match () { | ||
// Only enable smel when 64-bit, as it would contain a page table entry | ||
#[cfg(target_pointer_width = "64")] | ||
() => { | ||
let bits: usize; | ||
unsafe { asm!("csrr {}, 0x9C1", out(reg) bits) } | ||
Entry::from_bits(bits as u64) | ||
} | ||
#[cfg(not(target_pointer_width = "64"))] | ||
() => { | ||
unimplemented!() | ||
} | ||
} | ||
} |