mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
hypervisor: Implement getter/setter for StandardRegisters
This would be used to abstract away differences in KVM/MSHV representation of StandardRegisters. Signed-off-by: Jinank Jain <jinankjain@microsoft.com>
This commit is contained in:
@@ -49,6 +49,7 @@ mod cpu;
|
||||
mod device;
|
||||
|
||||
pub use crate::hypervisor::{Hypervisor, HypervisorError};
|
||||
use concat_idents::concat_idents;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub use cpu::CpuVendor;
|
||||
pub use cpu::{HypervisorCpuError, Vcpu, VmExit};
|
||||
@@ -195,3 +196,77 @@ pub enum StandardRegisters {
|
||||
#[cfg(all(feature = "mshv", target_arch = "x86_64"))]
|
||||
Mshv(mshv_bindings::StandardRegisters),
|
||||
}
|
||||
|
||||
macro_rules! set_x86_64_reg {
|
||||
($reg_name:ident) => {
|
||||
concat_idents!(method_name = "set_", $reg_name {
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
impl StandardRegisters {
|
||||
pub fn method_name(&mut self, val: u64) {
|
||||
match self {
|
||||
#[cfg(feature = "kvm")]
|
||||
StandardRegisters::Kvm(s) => s.$reg_name = val,
|
||||
#[cfg(feature = "mshv")]
|
||||
StandardRegisters::Mshv(s) => s.$reg_name = val,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! get_x86_64_reg {
|
||||
($reg_name:ident) => {
|
||||
concat_idents!(method_name = "get_", $reg_name {
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
impl StandardRegisters {
|
||||
pub fn method_name(&self) -> u64 {
|
||||
match self {
|
||||
#[cfg(feature = "kvm")]
|
||||
StandardRegisters::Kvm(s) => s.$reg_name,
|
||||
#[cfg(feature = "mshv")]
|
||||
StandardRegisters::Mshv(s) => s.$reg_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
set_x86_64_reg!(rax);
|
||||
set_x86_64_reg!(rbx);
|
||||
set_x86_64_reg!(rcx);
|
||||
set_x86_64_reg!(rdx);
|
||||
set_x86_64_reg!(rsi);
|
||||
set_x86_64_reg!(rdi);
|
||||
set_x86_64_reg!(rsp);
|
||||
set_x86_64_reg!(rbp);
|
||||
set_x86_64_reg!(r8);
|
||||
set_x86_64_reg!(r9);
|
||||
set_x86_64_reg!(r10);
|
||||
set_x86_64_reg!(r11);
|
||||
set_x86_64_reg!(r12);
|
||||
set_x86_64_reg!(r13);
|
||||
set_x86_64_reg!(r14);
|
||||
set_x86_64_reg!(r15);
|
||||
set_x86_64_reg!(rip);
|
||||
set_x86_64_reg!(rflags);
|
||||
|
||||
get_x86_64_reg!(rax);
|
||||
get_x86_64_reg!(rbx);
|
||||
get_x86_64_reg!(rcx);
|
||||
get_x86_64_reg!(rdx);
|
||||
get_x86_64_reg!(rsi);
|
||||
get_x86_64_reg!(rdi);
|
||||
get_x86_64_reg!(rsp);
|
||||
get_x86_64_reg!(rbp);
|
||||
get_x86_64_reg!(r8);
|
||||
get_x86_64_reg!(r9);
|
||||
get_x86_64_reg!(r10);
|
||||
get_x86_64_reg!(r11);
|
||||
get_x86_64_reg!(r12);
|
||||
get_x86_64_reg!(r13);
|
||||
get_x86_64_reg!(r14);
|
||||
get_x86_64_reg!(r15);
|
||||
get_x86_64_reg!(rip);
|
||||
get_x86_64_reg!(rflags);
|
||||
|
||||
Reference in New Issue
Block a user