-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for menvcgf and mseccfg CSRs
This commit adds basic support for menvcgf and mseccfg, note that they change execution behavior for modes above M so there is nothing special to do to emulate those.
- Loading branch information
Showing
8 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "menv_msec" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
mirage_abi = { path = "../../crates/mirage_abi" } |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::arch::{asm, global_asm}; | ||
use core::panic::PanicInfo; | ||
use core::usize; | ||
|
||
use mirage_abi::{failure, success}; | ||
|
||
global_asm!( | ||
r#" | ||
.text | ||
.align 4 | ||
.global _start | ||
_start: | ||
j {entry} | ||
"#, | ||
entry = sym entry, | ||
); | ||
|
||
extern "C" fn entry() -> ! { | ||
let secret: usize = 0x42; | ||
let mut res: usize; | ||
unsafe { | ||
asm!( | ||
"li {0}, 0x42", | ||
"csrw menvcfg, {0}", | ||
"csrr {1}, menvcfg", | ||
in(reg) secret, | ||
out(reg) res, | ||
); | ||
} | ||
|
||
read_test(res, secret); | ||
|
||
unsafe { | ||
asm!( | ||
"li {0}, 0x42", | ||
"csrw mseccfg, {0}", | ||
"csrr {1}, mseccfg", | ||
in(reg) secret, | ||
out(reg) res, | ||
); | ||
} | ||
|
||
read_test(res, secret); | ||
|
||
success() | ||
} | ||
|
||
fn read_test(out_csr: usize, expected: usize) { | ||
assert_eq!(out_csr, expected); | ||
} | ||
|
||
#[panic_handler] | ||
fn panic(_info: &PanicInfo) -> ! { | ||
failure(); | ||
} |
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