-
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.
In the RISC-V architecture, the Hypervisor extension (often referred to as H-extension) introduces a new privilege mode (HS-mode) that provides a virtualized environment. This allows a hypervisor to manage virtual machines, trapping certain privileged instructions and handling them in a way that maintains isolation between the host and guest operating systems. This commit emulates the behavior of this ISA extension in Miralis.
- Loading branch information
1 parent
0e5cc95
commit 758c58c
Showing
18 changed files
with
835 additions
and
42 deletions.
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,14 @@ | ||
[package] | ||
name = "hypervisor" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
license = "MIT" | ||
|
||
[[bin]] | ||
name = "hypervisor" | ||
path = "main.rs" | ||
|
||
[dependencies] | ||
miralis_abi = { path = "../../crates/abi" } | ||
log = { workspace = true } |
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,60 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::arch::asm; | ||
|
||
use miralis_abi::{setup_binary, success}; | ||
|
||
setup_binary!(main); | ||
|
||
fn main() -> ! { | ||
log::info!("Hello from hypervisor firmware!"); | ||
|
||
let misa: u64; | ||
unsafe { | ||
// Read the misa CSR into the variable misa | ||
asm!("csrr {}, misa", out(reg) misa); | ||
} | ||
|
||
if (misa & (1 << 7)) == 0 { | ||
log::info!("H extension is not available skipping the hypervisor payload"); | ||
success(); | ||
} | ||
|
||
unsafe { | ||
asm!( | ||
// Read the Hypervisor Status Register (hstatus) | ||
"csrr t0, hstatus", // Store hstatus in t0 | ||
"csrw hstatus, t0", // Write t0 back into hstatus (just for demonstration) | ||
|
||
// Read Hypervisor Exception Delegation Register (hedeleg) | ||
"csrr t1, hedeleg", // Store hedeleg in t1 | ||
"csrw hedeleg, t1", // Write t1 back into hedeleg | ||
|
||
// Read Hypervisor Interrupt Delegation Register (hideleg) | ||
"csrr t2, hideleg", // Store hideleg in t2 | ||
"csrw hideleg, t2", // Write t2 back into hideleg | ||
|
||
// Example of hypervisor trap handling (setting the virtual supervisor address) | ||
"csrr t3, htval", // Read htval (Hypervisor Trap Value Register) | ||
"csrw htval, t3", // Write back to htval | ||
|
||
// Hypervisor virtual interrupt enable | ||
"csrr t4, hvip", // Read Hypervisor Virtual Interrupt Pending Register | ||
"csrw hvip, t4", // Write back to hvip | ||
|
||
// Insert fences for hypervisor virtual memory synchronization | ||
// HFENCE.VVMA vaddr, asid | ||
"li t5, 0", // Load immediate 0 into t7 (representing ASID = 0 for all guests) | ||
"hfence.vvma zero, t5", // Synchronize virtual memory for all guest virtual machines | ||
|
||
// HFENCE.GVMA gaddr, gpid | ||
"li t5, 0", // Load immediate 0 into t8 (representing GPID = 0 for all guest physical addresses) | ||
"hfence.gvma zero, t5", // Synchronize virtual memory for the hypervisor | ||
|
||
out("t0") _, out("t1") _, out("t2") _, out("t3") _, out("t4") _, out("t5") _, | ||
); | ||
} | ||
|
||
success(); | ||
} |
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
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
Oops, something went wrong.