diff --git a/hypervisor/src/arch/aarch64/regs.rs b/hypervisor/src/arch/aarch64/regs.rs index 0c79e1531..73eab69bb 100644 --- a/hypervisor/src/arch/aarch64/regs.rs +++ b/hypervisor/src/arch/aarch64/regs.rs @@ -164,3 +164,14 @@ pub enum ExceptionClass { VECTOR_CATCH_32 = 0b111010, BRK = 0b111100, } + +#[allow(non_upper_case_globals)] +// PSR (Processor State Register) bits. +// Taken from arch/arm64/include/uapi/asm/ptrace.h. +const PSR_MODE_EL1h: u64 = 0x0000_0005; +const PSR_F_BIT: u64 = 0x0000_0040; +const PSR_I_BIT: u64 = 0x0000_0080; +const PSR_A_BIT: u64 = 0x0000_0100; +const PSR_D_BIT: u64 = 0x0000_0200; +// Taken from arch/arm64/kvm/inject_fault.c. +pub const PSTATE_FAULT_BITS_64: u64 = PSR_MODE_EL1h | PSR_A_BIT | PSR_F_BIT | PSR_I_BIT | PSR_D_BIT; diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 750f9671c..69b83b30b 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -77,6 +77,8 @@ pub mod aarch64; #[cfg(target_arch = "riscv64")] pub mod riscv64; #[cfg(target_arch = "aarch64")] +use crate::arch::aarch64::regs; +#[cfg(target_arch = "aarch64")] use std::mem; /// @@ -2289,18 +2291,6 @@ impl cpu::Vcpu for KvmVcpu { /// #[cfg(target_arch = "aarch64")] fn setup_regs(&self, cpu_id: u8, boot_ip: u64, fdt_start: u64) -> cpu::Result<()> { - #[allow(non_upper_case_globals)] - // PSR (Processor State Register) bits. - // Taken from arch/arm64/include/uapi/asm/ptrace.h. - const PSR_MODE_EL1h: u64 = 0x0000_0005; - const PSR_F_BIT: u64 = 0x0000_0040; - const PSR_I_BIT: u64 = 0x0000_0080; - const PSR_A_BIT: u64 = 0x0000_0100; - const PSR_D_BIT: u64 = 0x0000_0200; - // Taken from arch/arm64/kvm/inject_fault.c. - const PSTATE_FAULT_BITS_64: u64 = - PSR_MODE_EL1h | PSR_A_BIT | PSR_F_BIT | PSR_I_BIT | PSR_D_BIT; - let kreg_off = offset_of!(kvm_regs, regs); // Get the register index of the PSTATE (Processor State) register. @@ -2310,7 +2300,7 @@ impl cpu::Vcpu for KvmVcpu { .unwrap() .set_one_reg( arm64_core_reg_id!(KVM_REG_SIZE_U64, pstate), - &PSTATE_FAULT_BITS_64.to_le_bytes(), + ®s::PSTATE_FAULT_BITS_64.to_le_bytes(), ) .map_err(|e| cpu::HypervisorCpuError::SetAarchCoreRegister(e.into()))?;