Re: [Patch] (big) real mode emulation - jmp rel

Nitin A Kamble
2007-08-16T01:15:35Z

[-- Attachment #1.1.1: Type: text/plain, Size: 764 bytes --]

Hi Avi,
I modified the patch as per your suggestions. Attached is the update
patch for the "jmp rel" instruction. Also the "jmp rel short" patch
would go on top of it.

Thanks & Regards,
Nitin
Open Source Technology Center, Intel Corporation
-----------------------------------------------------------------
The mind is like a parachute; it works much better when it's open.
On Mon, 2007-08-13 at 01:49 -0700, Avi Kivity wrote:
> Please use an inline function instead of a macro. That will help when
> we later make large scale changes (for example, splitting the emulator
> into a decoder and executor).
>
> (and, when defining the macro, indent the contents)
>
> --
> error compiling committee.c: too many arguments to function
>
>

[-- Attachment #1.1.2: jmprel.patch --]
[-- Type: text/x-patch, Size: 1517 bytes --]

commit dd675f122c14adac40c9ac1eb5864de60330cc8c
Author: Nitin A Kamble <nitin.a.kamble@intel.com>
Date: Wed Aug 15 20:52:41 2007 -0700

Implement instruction "jmp rel" opcode 0xe9

Signed-off-by: Nitin A Kamble <nitin.a.kamble@intel.com>

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index b4f439c..9130fd5 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -145,8 +145,10 @@ static u8 opcode_table[256] = {
0, 0, 0, 0,
/* 0xD8 - 0xDF */
0, 0, 0, 0, 0, 0, 0, 0,
- /* 0xE0 - 0xEF */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ /* 0xE0 - 0xE7 */
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ /* 0xE8 - 0xEF */
+ 0, SrcImm|ImplicitOps, 0, 0, 0, 0, 0, 0,
/* 0xF0 - 0xF7 */
0, 0, 0, 0,
ImplicitOps, 0,
@@ -504,6 +506,12 @@ x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
unsigned long _eip = ctxt->vcpu->rip, _eflags = ctxt->eflags;
unsigned long modrm_val = 0;

+ inline void jmp_rel(int rel)
+ {
+ _eip += (int)(rel);
+ _eip = ((op_bytes == 2) ? (uint16_t)_eip : (uint32_t)_eip);
+ };
+
memcpy(_regs, ctxt->vcpu->regs, sizeof _regs);

switch (mode) {
@@ -1200,6 +1208,10 @@ special_insn:
case 0xae ... 0xaf: /* scas */
DPRINTF("Urk! I don't handle SCAS.\n");
goto cannot_emulate;
+ case 0xe9: /* jmp rel */
+ jmp_rel(src.val);
+ no_wb = 1; /* Disable writeback. */
+ break;
case 0xf4: /* hlt */
ctxt->vcpu->halt_request = 1;
goto done;

[-- Attachment #1.1.3: jmp_rel_short.patch --]
[-- Type: text/x-patch, Size: 971 bytes --]

commit 38f7db6830c862cd0470aaa07cabe616ff741d69
Author: Nitin A Kamble <nitin.a.kamble@intel.com>
Date: Fri Aug 10 18:48:05 2007 -0700

Implement "jmp rel short" opcode: 0xeb

Signed-off-by: Nitin A Kamble <nitin.a.kamble@intel.com>

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index 40fb6ee..16ea385 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -148,7 +148,7 @@ static u8 opcode_table[256] = {
/* 0xE0 - 0xE7 */
0, 0, 0, 0, 0, 0, 0, 0,
/* 0xE8 - 0xEF */
- 0, SrcImm|ImplicitOps, 0, 0, 0, 0, 0, 0,
+ 0, SrcImm|ImplicitOps, 0, SrcImmByte|ImplicitOps, 0, 0, 0, 0,
/* 0xF0 - 0xF7 */
0, 0, 0, 0,
ImplicitOps, 0,
@@ -1208,6 +1208,7 @@ special_insn:
case 0xae ... 0xaf: /* scas */
DPRINTF("Urk! I don't handle SCAS.\n");
goto cannot_emulate;
+ case 0xeb: /* jmp rel short */
case 0xe9: /* jmp rel */
jmp_rel(src.val);
no_wb = 1; /* Disable writeback. */