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