From 3645654c392f395a80f7cac329df204c6a9c94e2 Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Fri, 2 Aug 2024 09:45:57 +0530 Subject: [PATCH] hypervisor: Add an API to create default StandardRegisters This will be used to create StandardRegisters for a given vcpu in future. Signed-off-by: Jinank Jain --- hypervisor/src/cpu.rs | 6 ++++++ hypervisor/src/kvm/mod.rs | 7 +++++++ hypervisor/src/mshv/mod.rs | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/hypervisor/src/cpu.rs b/hypervisor/src/cpu.rs index f5cbe0e06..4d1cd784f 100644 --- a/hypervisor/src/cpu.rs +++ b/hypervisor/src/cpu.rs @@ -321,6 +321,12 @@ pub type Result = anyhow::Result; /// Trait to represent a generic Vcpu /// pub trait Vcpu: Send + Sync { + /// + /// Returns StandardRegisters with default value set + /// + fn create_standard_regs(&self) -> StandardRegisters { + unimplemented!(); + } /// /// Returns the vCPU general purpose registers. /// diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index a2df76769..3f8fc4469 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -1190,6 +1190,13 @@ pub struct KvmVcpu { /// let vcpu = vm.create_vcpu(0, None).unwrap(); /// ``` impl cpu::Vcpu for KvmVcpu { + /// + /// Returns StandardRegisters with default value set + /// + #[cfg(target_arch = "x86_64")] + fn create_standard_regs(&self) -> StandardRegisters { + kvm_bindings::kvm_regs::default().into() + } #[cfg(target_arch = "x86_64")] /// /// Returns the vCPU general purpose registers. diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index cb6ad2bb2..19dfe0a9a 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -413,6 +413,13 @@ pub struct MshvVcpu { /// let vcpu = vm.create_vcpu(0, None).unwrap(); /// ``` impl cpu::Vcpu for MshvVcpu { + /// + /// Returns StandardRegisters with default value set + /// + #[cfg(target_arch = "x86_64")] + fn create_standard_regs(&self) -> crate::arch::x86::StandardRegisters { + mshv_bindings::StandardRegisters::default().into() + } #[cfg(target_arch = "x86_64")] /// /// Returns the vCPU general purpose registers.