hypervisor: x86: use a macro to generate emulate function for movs

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu
2023-01-26 16:24:27 +00:00
committed by Liu Wei
parent 8e682bcb00
commit 1bfa07f48e

View File

@@ -15,8 +15,8 @@ use crate::arch::x86::emulator::instructions::*;
use crate::arch::x86::regs::DF; use crate::arch::x86::regs::DF;
use crate::arch::x86::Exception; use crate::arch::x86::Exception;
pub struct Movsd_m32_m32; macro_rules! movs {
impl<T: CpuStateManager> InstructionHandler<T> for Movsd_m32_m32 { ($bound:ty) => {
fn emulate( fn emulate(
&self, &self,
insn: &Instruction, insn: &Instruction,
@@ -39,7 +39,7 @@ impl<T: CpuStateManager> InstructionHandler<T> for Movsd_m32_m32 {
.map_err(|e| EmulationError::InvalidOperand(anyhow!(e)))?; .map_err(|e| EmulationError::InvalidOperand(anyhow!(e)))?;
let df = (state.flags() & DF) != 0; let df = (state.flags() & DF) != 0;
let len = std::mem::size_of::<u32>(); let len = std::mem::size_of::<$bound>();
while count > 0 { while count > 0 {
let mut memory: [u8; 4] = [0; 4]; let mut memory: [u8; 4] = [0; 4];
@@ -82,6 +82,12 @@ impl<T: CpuStateManager> InstructionHandler<T> for Movsd_m32_m32 {
Ok(()) Ok(())
} }
};
}
pub struct Movsd_m32_m32;
impl<T: CpuStateManager> InstructionHandler<T> for Movsd_m32_m32 {
movs!(u32);
} }
#[cfg(test)] #[cfg(test)]