mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-22 16:01:15 +00:00
hypervisor: x86: only calculate address when necessary in MOV emulation
Only calculate the address when the operand is memory. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
parent
c6aea5af5d
commit
66b001665f
@ -30,8 +30,6 @@ macro_rules! mov_rm_r {
|
|||||||
let src_reg_value = state
|
let src_reg_value = state
|
||||||
.read_reg(insn.op1_register())
|
.read_reg(insn.op1_register())
|
||||||
.map_err(EmulationError::PlatformEmulationError)?;
|
.map_err(EmulationError::PlatformEmulationError)?;
|
||||||
let addr = memory_operand_address(insn, state)
|
|
||||||
.map_err(EmulationError::PlatformEmulationError)?;
|
|
||||||
|
|
||||||
match insn.op0_kind() {
|
match insn.op0_kind() {
|
||||||
OpKind::Register => state
|
OpKind::Register => state
|
||||||
@ -39,7 +37,10 @@ macro_rules! mov_rm_r {
|
|||||||
.map_err(EmulationError::PlatformEmulationError)?,
|
.map_err(EmulationError::PlatformEmulationError)?,
|
||||||
|
|
||||||
OpKind::Memory => {
|
OpKind::Memory => {
|
||||||
|
let addr = memory_operand_address(insn, state)
|
||||||
|
.map_err(EmulationError::PlatformEmulationError)?;
|
||||||
let src_reg_value_type: $bound = src_reg_value as $bound;
|
let src_reg_value_type: $bound = src_reg_value as $bound;
|
||||||
|
|
||||||
platform
|
platform
|
||||||
.write_memory(addr, &src_reg_value_type.to_le_bytes())
|
.write_memory(addr, &src_reg_value_type.to_le_bytes())
|
||||||
.map_err(EmulationError::PlatformEmulationError)?
|
.map_err(EmulationError::PlatformEmulationError)?
|
||||||
@ -64,16 +65,19 @@ macro_rules! mov_rm_imm {
|
|||||||
platform: &mut dyn PlatformEmulator<CpuState = T>,
|
platform: &mut dyn PlatformEmulator<CpuState = T>,
|
||||||
) -> Result<(), EmulationError<Exception>> {
|
) -> Result<(), EmulationError<Exception>> {
|
||||||
let imm = imm_op!($type, insn);
|
let imm = imm_op!($type, insn);
|
||||||
let addr = memory_operand_address(insn, state)
|
|
||||||
.map_err(EmulationError::PlatformEmulationError)?;
|
|
||||||
|
|
||||||
match insn.op0_kind() {
|
match insn.op0_kind() {
|
||||||
OpKind::Register => state
|
OpKind::Register => state
|
||||||
.write_reg(insn.op0_register(), imm as u64)
|
.write_reg(insn.op0_register(), imm as u64)
|
||||||
.map_err(EmulationError::PlatformEmulationError)?,
|
.map_err(EmulationError::PlatformEmulationError)?,
|
||||||
OpKind::Memory => platform
|
OpKind::Memory => {
|
||||||
.write_memory(addr, &imm.to_le_bytes())
|
let addr = memory_operand_address(insn, state)
|
||||||
.map_err(EmulationError::PlatformEmulationError)?,
|
.map_err(EmulationError::PlatformEmulationError)?;
|
||||||
|
|
||||||
|
platform
|
||||||
|
.write_memory(addr, &imm.to_le_bytes())
|
||||||
|
.map_err(EmulationError::PlatformEmulationError)?
|
||||||
|
}
|
||||||
k => return Err(EmulationError::InvalidOperand(anyhow!("{:?}", k))),
|
k => return Err(EmulationError::InvalidOperand(anyhow!("{:?}", k))),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user