(big) real mode emulation - jmp rel
PATCH 1/1 (big) real mode emulation - jmp rel
Hi Avi,
The patch to implement "jmp rel" emulation is attached.
Thanks & Regards,
Nitin
Open Source Technology Center, Intel Corporation.
-------------------------------------------------------------------------
The mind is like a parachute; it works much better when it's open.
commit 1d77b7ad2bcb20858dd66d9653952a8d1cc0a153
Author: Nitin A Kamble <[email protected]> Date: Fri Aug 10 18:36:12 2007 -0700
Implement instruction "jmp rel" opcode 0xe9
drivers/kvm/x86_emulate.c +14 -2
@@ -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,
@@ -447,6 +449,12 @@ struct operand { (((reg) + _inc) & ((1UL << (ad_bytes <<3 )) -1 )); \ } while (0) +#define jmp_rel (rel) \ +do { \ + _eip += (int)(rel); \ + _eip = ((op_bytes == 2) ? (uint16_t)_eip : (uint32_t)_eip); \ +} while (0) +/* * Given the 'reg' portion of a ModRM byte, and a register block, return a * pointer into the block that addresses the relevant register.
@@ -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;
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
A message that is not in the archive (sent off-list or not yet received): 1186785157.6097.19.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org
drivers/kvm/x86_emulate.c struct operand { · line 457
Quoted 10 lines · Nitin A Kamble
Hi Avi,
The patch to implement "jmp rel" emulation is attached.drivers/kvm/x86_emulate.c +6
-0+#define jmp_rel (rel) \ +do { \ + _eip += (int)(rel); \ + _eip = ((op_bytes == 2) ? (uint16_t)_eip : (uint32_t)_eip); \ +} while (0) +
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)
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 46C01B0E.7080304-atKUWr5tajBWk0Htik3J/[email protected]
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.
Quoted 10 lines · Avi Kivity
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 compilingcommittee.c: too many arguments to function
commit dd675f122c14adac40c9ac1eb5864de60330cc8c
Author: Nitin A Kamble <[email protected]> Date: Wed Aug 15 20:52:41 2007 -0700
Implement instruction "jmp rel" opcode 0xe9
drivers/kvm/x86_emulate.c +14 -2
@@ -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;
commit 38f7db6830c862cd0470aaa07cabe616ff741d69
Author: Nitin A Kamble <[email protected]> Date: Fri Aug 10 18:48:05 2007 -0700
Implement "jmp rel short" opcode: 0xeb
drivers/kvm/x86_emulate.c +2 -1
@@ -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. */
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
A message that is not in the archive (sent off-list or not yet received): 1187226935.24576.5.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org
drivers/kvm/x86_emulate.c x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) · line 514
Quoted 13 lines · Nitin A Kamble
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.drivers/kvm/x86_emulate.c +6
-0+inline void jmp_rel (int rel) + { + _eip += (int )(rel); + _eip = ((op_bytes ==2 ) ? (uint16_t )_eip : (uint32_t )_eip); + }; +
This is a nested function which we don't use (in the kernel or userspace).
It needs to be a file-scope function (static, too).
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 46C42610.8020707-atKUWr5tajBWk0Htik3J/[email protected]
Avi,
In my opinion converting this small function to file-scope function,
would make code look ugly. I think the earlier Macro definition was better.
Quoted 12 lines · Avi Kivity
drivers/kvm/x86_emulate.c x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
Quoted 4 lines
drivers/kvm/x86_emulate.c +4
-0+inline void jmp_rel (int rel) + { + _eip += (int )(rel); + _eip = ((op_bytes == 2) ? (uint16_t)_eip :(uint32_t)_eip);
drivers/kvm/x86_emulate.c x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) · line 514
Quoted 2 lines
drivers/kvm/x86_emulate.c +2
-0+ }; +This is a nested function which we don't use (in the kernel or userspace).
It needs to be a file-scope function (static, too).
Signature · 5 lines
Thanks & Regards, Nitin Open Source Technology Center, Intel Corporation ----------------------------------------------------------------- The mind is like a parachute; it works much better when it's open
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
A message that is not in the archive (sent off-list or not yet received): 1187296469.5500.7.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org
Hi Avi,
If you are fine with macro then attached are the updated patches for
"jmp rel" & "jmp rel short" instruction emulation.
Quoted 4 lines · Nitin A Kamble
Avi,
In my opinion converting this small function to file-scope function,
would make code look ugly. I think the earlier Macro definition was better.
Signature · 5 lines
Thanks & Regards, Nitin Open Source Technology Center, Intel Corporation ----------------------------------------------------------------- The mind is like a parachute; it works much better when it's open
commit 38177680ad53b330d0f8b4fcec20953a7a7dfa2d
Author: Nitin A Kamble <[email protected]> Date: Thu Aug 16 19:10:14 2007 -0700
Implement instruction "jmp rel" opcode 0xe9
drivers/kvm/x86_emulate.c +14 -2
@@ -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,
@@ -447,6 +449,12 @@ struct operand { (((reg) + _inc) & ((1UL << (ad_bytes <<3 )) -1 )); \ } while (0) +#define jmp_rel (rel) \ + do { \ + _eip += (int)(rel); \ + _eip = ((op_bytes == 2) ? (uint16_t)_eip : (uint32_t)_eip); \ + } while (0) +/* * Given the 'reg' portion of a ModRM byte, and a register block, return a * pointer into the block that addresses the relevant register.
@@ -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;
commit 38f7db6830c862cd0470aaa07cabe616ff741d69
Author: Nitin A Kamble <[email protected]> Date: Fri Aug 10 18:48:05 2007 -0700
Implement "jmp rel short" opcode: 0xeb
drivers/kvm/x86_emulate.c +2 -1
@@ -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. */
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
Quoted 6 lines · Nitin A Kamble
Avi,
In my opinion converting this small function to file-scope function,
would make code look ugly. I think the earlier Macro definition was better.
A file scope function would indeed be uglier. But the macro has more serious problems; it's impossible to understand how variables are affected since nobody expects function local variables whose address is not taken to change after something that looks like a macro is called.
At the very least, it needs to be in uppercase so that people know something funny is going on. But it's really better as a function.
(and yes, the rest of the file uses macros. and yes, the rest of the file is an unmaintainable mess)
Quoted 19 lines · Avi Kivity
Quoted 16 lines
drivers/kvm/x86_emulate.c x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
Quoted 6 lines
drivers/kvm/x86_emulate.c +4
-0+inline void jmp_rel (int rel) + { + _eip += (int )(rel); + _eip = ((op_bytes == 2) ? (uint16_t)_eip :(uint32_t)_eip);
drivers/kvm/x86_emulate.c x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) · line 514
Quoted 3 lines
drivers/kvm/x86_emulate.c +2
-0+ }; +This is a nested function which we don't use (in the kernel or userspace).
It needs to be a file-scope function (static, too).
Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
A message that is not in the archive (sent off-list or not yet received): 46C59385.6060108-atKUWr5tajBWk0Htik3J/[email protected]
Quoted 11 lines · Avi Kivity
A file scope function would indeed be uglier. But the macro has more serious problems; it's impossible to understand how variables are affected since nobody expects function local variables whose address is
not taken to change after something that looks like a macro is called.At the very least, it needs to be in uppercase so that people know something funny is going on. But it's really better as a function.
(and yes, the rest of the file uses macros. and yes, the rest of the file is an unmaintainable mess)
Hi Avi,
I tried either ways, and to me the macro looks cleaner. Now I have
upper-cased it for your satisfaction. :)
Also attached the "jmp rel short" emulation patch.
Signature · 5 lines
Thanks & Regards, Nitin Open Source Technology Center, Intel Corporation ----------------------------------------------------------------- The mind is like a parachute; it works much better when it's open
commit 47259a989606e37e5ba24f6722a8258368e6d0a2
Author: Nitin A Kamble <[email protected]> Date: Fri Aug 17 18:39:29 2007 -0700
Implementing emulation of instruction
jmp rel short imm8
opcode: 0xeb
drivers/kvm/x86_emulate.c +2 -1
@@ -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,
@@ -1029,6 +1029,7 @@ grp2: /* Grp2 */ src.val = _regs[VCPU_REGS_RCX ]; goto grp2;case 0xe9 :/* jmp rel */ +case 0xeb :/* jmp rel short */ JMP_REL (src.val); no_wb =1 ;/* Disable writeback. */ break ;
commit 17994104bef0da3d182d2b8736fbd1cf8d4a77f0
Author: Nitin A Kamble <[email protected]> Date: Fri Aug 17 18:33:07 2007 -0700
Implement emulation of instruction "jmp rel" opcode 0xe9
drivers/kvm/x86_emulate.c +14 -2
@@ -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,
@@ -447,6 +449,12 @@ struct operand { (((reg) + _inc) & ((1UL << (ad_bytes <<3 )) -1 )); \ } while (0) +#define JMP_REL (rel) \ + do { \ + _eip += (int)(rel); \ + _eip = ((op_bytes == 2) ? (uint16_t)_eip : (uint32_t)_eip); \ + } while (0) +/* * Given the 'reg' portion of a ModRM byte, and a register block, return a * pointer into the block that addresses the relevant register.
@@ -1020,6 +1028,10 @@ grp2: /* Grp2 */ case 0xd2 ... 0xd3: /* Grp2 */ src.val = _regs[VCPU_REGS_RCX ]; goto grp2; +case 0xe9 :/* jmp rel */ +JMP_REL (src.val); + no_wb =1 ;/* Disable writeback. */ +break ; case 0xf6 ... 0xf7: /* Grp3 */switch (modrm_reg) { case 0 ... 1: /* test */
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel
A message that is not in the archive (sent off-list or not yet received): 1187389499.9011.14.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org
Quoted 11 lines · Nitin A Kamble
Quoted 9 lines · Avi Kivity
A file scope function would indeed be uglier. But the macro has more serious problems; it's impossible to understand how variables are affected since nobody expects function local variables whose address is
not taken to change after something that looks like a macro is called.At the very least, it needs to be in uppercase so that people know something funny is going on. But it's really better as a function.
Quoted 10 lines
Quoted 3 lines
(and yes, the rest of the file uses macros. and yes, the rest of the file is an unmaintainable mess)
Hi Avi,
I tried either ways, and to me the macro looks cleaner. Now I have
upper-cased it for your satisfaction. :)
Also attached the "jmp rel short" emulation patch.
Okay, applied both -- thanks.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/