mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-22 07:51:16 +00:00
hypervisor: emulator: Decoding loop restructuring
In preparation for the instruction fetching step, we modify the decoding loop so that we can check what the last decoding error is. We also switch to explictly using decode_out() which removes a 32 bytes copy compared to decode(). Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
7a4edecd29
commit
7dc92d1dac
@ -513,9 +513,15 @@ impl<'a, T: CpuStateManager> Emulator<'a, T> {
|
|||||||
.cpu_state(cpu_id)
|
.cpu_state(cpu_id)
|
||||||
.map_err(EmulationError::PlatformEmulationError)?;
|
.map_err(EmulationError::PlatformEmulationError)?;
|
||||||
let mut decoder = Decoder::new(64, insn_stream, DecoderOptions::NONE);
|
let mut decoder = Decoder::new(64, insn_stream, DecoderOptions::NONE);
|
||||||
|
let mut insn = Instruction::default();
|
||||||
|
let mut num_insn_emulated: usize = 0;
|
||||||
|
|
||||||
decoder.set_ip(state.ip());
|
decoder.set_ip(state.ip());
|
||||||
|
|
||||||
for (index, insn) in &mut decoder.iter().enumerate() {
|
while decoder.can_decode() {
|
||||||
|
decoder.decode_out(&mut insn);
|
||||||
|
|
||||||
|
// Emulate the decoded instruction
|
||||||
self.insn_map
|
self.insn_map
|
||||||
.instructions
|
.instructions
|
||||||
.get(&insn.code())
|
.get(&insn.code())
|
||||||
@ -524,8 +530,10 @@ impl<'a, T: CpuStateManager> Emulator<'a, T> {
|
|||||||
})?
|
})?
|
||||||
.emulate(&insn, &mut state, self.platform)?;
|
.emulate(&insn, &mut state, self.platform)?;
|
||||||
|
|
||||||
|
num_insn_emulated += 1;
|
||||||
|
|
||||||
if let Some(num_insn) = num_insn {
|
if let Some(num_insn) = num_insn {
|
||||||
if index + 1 >= num_insn {
|
if num_insn_emulated >= num_insn {
|
||||||
// Exit the decoding loop, do not decode the next instruction.
|
// Exit the decoding loop, do not decode the next instruction.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user