]> git.baikalelectronics.ru Git - kernel.git/commit
KVM: x86 emulator: framework for streamlining arithmetic opcodes
authorAvi Kivity <avi.kivity@gmail.com>
Fri, 4 Jan 2013 14:18:48 +0000 (16:18 +0200)
committerMarcelo Tosatti <mtosatti@redhat.com>
Wed, 9 Jan 2013 19:39:17 +0000 (17:39 -0200)
commit2ba5a6d747a6227e64f40c728247d8ffcb759ab9
treeba58057fd3ad51430fffe57e41d7bc3be62b91db
parent87bb293b45b49e4dd17961b172d12f3d2b254468
KVM: x86 emulator: framework for streamlining arithmetic opcodes

We emulate arithmetic opcodes by executing a "similar" (same operation,
different operands) on the cpu.  This ensures accurate emulation, esp. wrt.
eflags.  However, the prologue and epilogue around the opcode is fairly long,
consisting of a switch (for the operand size) and code to load and save the
operands.  This is repeated for every opcode.

This patch introduces an alternative way to emulate arithmetic opcodes.
Instead of the above, we have four (three on i386) functions consisting
of just the opcode and a ret; one for each operand size.  For example:

   .align 8
   em_notb:
not %al
ret

   .align 8
   em_notw:
not %ax
ret

   .align 8
   em_notl:
not %eax
ret

   .align 8
   em_notq:
not %rax
ret

The prologue and epilogue are shared across all opcodes.  Note the functions
use a special calling convention; notably eflags is an input/output parameter
and is not clobbered.  Rather than dispatching the four functions through a
jump table, the functions are declared as a constant size (8) so their address
can be calculated.

Acked-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi.kivity@gmail.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/x86/kvm/emulate.c