use super::Hcl;
use super::HclVp;
use super::NoRunner;
use super::ProcessorRunner;
use crate::GuestVtl;
use crate::protocol::hcl_cpu_context_aarch64;
use hvdef::HvArm64RegisterName;
use hvdef::HvRegisterName;
use hvdef::HvRegisterValue;
use sidecar_client::SidecarVp;
use thiserror::Error;
#[derive(Error, Debug)]
#[error("translate gva to gpa returned non-successful code {code:?}")]
pub struct TranslateErrorAarch64 {
pub code: u32,
}
#[non_exhaustive]
pub struct MshvArm64 {}
impl ProcessorRunner<'_, MshvArm64> {
pub fn cpu_context(&self) -> &hcl_cpu_context_aarch64 {
unsafe { &*(&raw mut (*self.run.get()).context).cast() }
}
pub fn cpu_context_mut(&mut self) -> &mut hcl_cpu_context_aarch64 {
unsafe { &mut *(&raw mut (*self.run.get()).context).cast() }
}
}
impl<'a> super::BackingPrivate<'a> for MshvArm64 {
fn new(vp: &HclVp, sidecar: Option<&SidecarVp<'_>>, _hcl: &Hcl) -> Result<Self, NoRunner> {
assert!(sidecar.is_none());
let super::BackingState::Mshv { reg_page: _ } = &vp.backing else {
unreachable!()
};
Ok(Self {})
}
fn try_set_reg(
runner: &mut ProcessorRunner<'a, Self>,
_vtl: GuestVtl,
name: HvRegisterName,
value: HvRegisterValue,
) -> Result<bool, super::Error> {
let set = match name.into() {
HvArm64RegisterName::X0
| HvArm64RegisterName::X1
| HvArm64RegisterName::X2
| HvArm64RegisterName::X3
| HvArm64RegisterName::X4
| HvArm64RegisterName::X5
| HvArm64RegisterName::X6
| HvArm64RegisterName::X7
| HvArm64RegisterName::X8
| HvArm64RegisterName::X9
| HvArm64RegisterName::X10
| HvArm64RegisterName::X11
| HvArm64RegisterName::X12
| HvArm64RegisterName::X13
| HvArm64RegisterName::X14
| HvArm64RegisterName::X15
| HvArm64RegisterName::X16
| HvArm64RegisterName::X17
| HvArm64RegisterName::X19
| HvArm64RegisterName::X20
| HvArm64RegisterName::X21
| HvArm64RegisterName::X22
| HvArm64RegisterName::X23
| HvArm64RegisterName::X24
| HvArm64RegisterName::X25
| HvArm64RegisterName::X26
| HvArm64RegisterName::X27
| HvArm64RegisterName::X28
| HvArm64RegisterName::XFp
| HvArm64RegisterName::XLr => {
runner.cpu_context_mut().x[(name.0 - HvArm64RegisterName::X0.0) as usize] =
value.as_u64();
true
}
HvArm64RegisterName::X18 => {
runner.cpu_context_mut().x[18] = value.as_u64();
false
}
_ => false,
};
Ok(set)
}
fn must_flush_regs_on(_runner: &ProcessorRunner<'a, Self>, _name: HvRegisterName) -> bool {
false
}
fn try_get_reg(
runner: &ProcessorRunner<'a, Self>,
_vtl: GuestVtl,
name: HvRegisterName,
) -> Result<Option<HvRegisterValue>, super::Error> {
let value = match name.into() {
HvArm64RegisterName::X0
| HvArm64RegisterName::X1
| HvArm64RegisterName::X2
| HvArm64RegisterName::X3
| HvArm64RegisterName::X4
| HvArm64RegisterName::X5
| HvArm64RegisterName::X6
| HvArm64RegisterName::X7
| HvArm64RegisterName::X8
| HvArm64RegisterName::X9
| HvArm64RegisterName::X10
| HvArm64RegisterName::X11
| HvArm64RegisterName::X12
| HvArm64RegisterName::X13
| HvArm64RegisterName::X14
| HvArm64RegisterName::X15
| HvArm64RegisterName::X16
| HvArm64RegisterName::X17
| HvArm64RegisterName::X19
| HvArm64RegisterName::X20
| HvArm64RegisterName::X21
| HvArm64RegisterName::X22
| HvArm64RegisterName::X23
| HvArm64RegisterName::X24
| HvArm64RegisterName::X25
| HvArm64RegisterName::X26
| HvArm64RegisterName::X27
| HvArm64RegisterName::X28
| HvArm64RegisterName::XFp
| HvArm64RegisterName::XLr => {
Some(runner.cpu_context().x[(name.0 - HvArm64RegisterName::X0.0) as usize].into())
}
_ => None,
};
Ok(value)
}
fn flush_register_page(_runner: &mut ProcessorRunner<'a, Self>) {}
}