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:
Samuel Ortiz 2020-11-26 11:16:53 +01:00 committed by Rob Bradford
parent 7a4edecd29
commit 7dc92d1dac

View File

@ -513,9 +513,15 @@ impl<'a, T: CpuStateManager> Emulator<'a, T> {
.cpu_state(cpu_id)
.map_err(EmulationError::PlatformEmulationError)?;
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());
for (index, insn) in &mut decoder.iter().enumerate() {
while decoder.can_decode() {
decoder.decode_out(&mut insn);
// Emulate the decoded instruction
self.insn_map
.instructions
.get(&insn.code())
@ -524,8 +530,10 @@ impl<'a, T: CpuStateManager> Emulator<'a, T> {
})?
.emulate(&insn, &mut state, self.platform)?;
num_insn_emulated += 1;
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.
break;
}