From a987c3d0fcaf006877bd6c9514c6dff7edf89612 Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Wed, 28 Aug 2024 10:49:46 +0000 Subject: [PATCH] hypervisor: Define helper function for setting ARM64 KVM regs This change is along the lines of x86 platform which defined similar convinence macros to access the StandardRegisters. Signed-off-by: Jinank Jain --- hypervisor/src/lib.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/hypervisor/src/lib.rs b/hypervisor/src/lib.rs index cc8b4272e..d83eeabca 100644 --- a/hypervisor/src/lib.rs +++ b/hypervisor/src/lib.rs @@ -270,3 +270,45 @@ get_x86_64_reg!(r14); get_x86_64_reg!(r15); get_x86_64_reg!(rip); get_x86_64_reg!(rflags); + +macro_rules! set_aarch64_reg { + ($reg_name:ident, $type:ty) => { + concat_idents!(method_name = "set_", $reg_name { + #[cfg(target_arch = "aarch64")] + impl StandardRegisters { + pub fn method_name(&mut self, val: $type) { + match self { + #[cfg(feature = "kvm")] + StandardRegisters::Kvm(s) => s.regs.$reg_name = val, + } + } + } + }); + } +} + +macro_rules! get_aarch64_reg { + ($reg_name:ident, $type:ty) => { + concat_idents!(method_name = "get_", $reg_name { + #[cfg(target_arch = "aarch64")] + impl StandardRegisters { + pub fn method_name(&self) -> $type { + match self { + #[cfg(feature = "kvm")] + StandardRegisters::Kvm(s) => s.regs.$reg_name, + } + } + } + }); + } +} + +set_aarch64_reg!(regs, [u64; 31usize]); +set_aarch64_reg!(sp, u64); +set_aarch64_reg!(pc, u64); +set_aarch64_reg!(pstate, u64); + +get_aarch64_reg!(regs, [u64; 31usize]); +get_aarch64_reg!(sp, u64); +get_aarch64_reg!(pc, u64); +get_aarch64_reg!(pstate, u64);