Skip to contentSkip to conversation

(big) real mode emulation - mov rl/rh/r

PATCH In review Nitin A Kamble 2 participants 5 messages Oct 31, 2007 4 messages not in the archive KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 (big) real mode emulation - mov rl/rh/r

Hi Avi,
Attached is the patch to implement emulation of instructions mov rl, imm8 (opcodes 0xb0-0xb3)
mov rh, imm8 (opcodes 0xb4-0xb7)
mov r, imm (opcodes0xb8-0xbf)

please apply.

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

From 6d23ef752e157c5eff60531d8470b6102376be2b Mon Sep 17 00:00:00 2001
From: Nitin A Kamble <[email protected]>
Date: Tue, 30 Oct 2007 19:38:49 -0800
Subject: [PATCH] Implement emulation of instructions: mov rl/rh/r

        mov rl, imm8 (opcodes: 0xb0 ... 0xb3)
        mov rh, imm8 (opcodes: 0xb4 ... 0xb7)
        mov r, imm (opcodes: 0xb8 ... 0xbf)
---
 drivers/kvm/x86_emulate.c |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)
drivers/kvm/x86_emulate.c +26 -2
index ac35619..579cfcf 100644
@@ -146,8 +146,12 @@ static u16 opcode_table[256] = {
 	0, 0, ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
 	ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
 	ByteOp | ImplicitOps, ImplicitOps,
-	/* 0xB0 - 0xBF */
-	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	/* 0xB0 - 0xB7 */
+	Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte,
+	Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte,
+	/* 0xB8 - 0xBF */
+	Mov | SrcImm, Mov | SrcImm, Mov | SrcImm, Mov | SrcImm,
+	Mov | SrcImm, Mov | SrcImm, Mov | SrcImm, Mov | SrcImm,
 	/* 0xC0 - 0xC7 */
 	ByteOp | DstMem | SrcImm | ModRM, DstMem | SrcImmByte | ModRM,
 	0, ImplicitOps, 0, 0,
@@ -1407,6 +1411,26 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
 	case 0xa2 ... 0xa3:	/* mov */
 		c->dst.val = (unsigned long)c->regs[VCPU_REGS_RAX];
 		break;
+	case 0xb0 ... 0xb3:     /* mov rl, imm8 */
+		c->dst.ptr =
+			(unsigned long *)&c->regs[VCPU_REGS_RAX + (c->b & 0x3)];
+		c->dst.val = c->src.val;
+		c->dst.type = OP_REG;
+		c->dst.bytes = 1;
+		break;
+	case 0xb4 ... 0xb7:     /* mov rh, imm8 */
+		c->dst.ptr =
+			((void *)&c->regs[VCPU_REGS_RAX + (c->b & 0x3)] + 1);
+		c->dst.val = c->src.val;
+		c->dst.type = OP_REG;
+		c->dst.bytes = 1;
+		break;
+	case 0xb8 ... 0xbf:     /* mov r, imm */
+		c->dst.ptr =
+			(unsigned long *)&c->regs[VCPU_REGS_RAX + (c->b & 0x7)];
+		c->dst.val = c->src.val;
+		c->dst.type = OP_REG;
+		break;
 	case 0xc0 ... 0xc1:
 		emulate_grp2(ctxt);
 		break;
Signature · 1 line
1.5.2.2

-------------------------------------------------------------------------
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): 1193791385.9258.17.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org

#2 lore raw
Quoted 12 lines · Nitin A Kamble

Hi Avi,
Attached is the patch to implement emulation of instructions mov rl, imm8 (opcodes 0xb0-0xb3)
mov rh, imm8 (opcodes 0xb4-0xb7)
mov r, imm (opcodes0xb8-0xbf)

drivers/kvm/x86_emulate.c +0 -1
@@ -146,8 +146,12 @@ static u16 opcode_table[256] = {
        0, 0, ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
        ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
        ByteOp | ImplicitOps, ImplicitOps,
-       /* 0xB0 - 0xBF */

drivers/kvm/x86_emulate.c static u16 opcode_table[256] = { · line 157

Quoted 10 lines
drivers/kvm/x86_emulate.c +6 -1
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       /* 0xB0 - 0xB7 */
+       Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte, Mov | 
 SrcImmByte,
+       Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte, Mov | 
 SrcImmByte,
+       /* 0xB8 - 0xBF */
+       Mov | SrcImm, Mov | SrcImm, Mov | SrcImm, Mov | SrcImm,
+       Mov | SrcImm, Mov | SrcImm, Mov | SrcImm, Mov | SrcImm,
        /* 0xC0 - 0xC7 */

Perhaps adding DstReg would reduce the decoding code later on?

Signature · 8 lines
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
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): 4727D531.7090401-atKUWr5tajBWk0Htik3J/[email protected]

#4 lore raw
Quoted 17 lines · Avi Kivity
Quoted 16 lines · Nitin A Kamble

Hi Avi,
Attached is the patch to implement emulation of instructions mov rl, imm8 (opcodes 0xb0-0xb3)
mov rh, imm8 (opcodes 0xb4-0xb7)
mov r, imm (opcodes0xb8-0xbf)

drivers/kvm/x86_emulate.c +2 -2
@@ -146,8 +146,12 @@ static u16 opcode_table[256] = {
        0, 0, ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
        ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
        ByteOp | ImplicitOps, ImplicitOps,
-       /* 0xB0 - 0xBF */
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       /* 0xB0 - 0xB7 */
+       Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte, Mov |
 SrcImmByte,
Quoted 8 lines

drivers/kvm/x86_emulate.c static u16 opcode_table[256] = { · line 155

Quoted 6 lines
drivers/kvm/x86_emulate.c +4 -0
+       Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte, Mov |
 SrcImmByte,
+       /* 0xB8 - 0xBF */
+       Mov | SrcImm, Mov | SrcImm, Mov | SrcImm, Mov | SrcImm,
+       Mov | SrcImm, Mov | SrcImm, Mov | SrcImm, Mov | SrcImm,
        /* 0xC0 - 0xC7 */

Perhaps adding DstReg would reduce the decoding code later on?

Avi,
The decoding of register is significantly different for these instructions. It will be just moving code from one place to other place.

+ c->dst.ptr =
+ (unsigned long *)&c->regs[VCPU_REGS_RAX + (c->b
& 0x3)];
+ c->dst.ptr =
+ ((void *)&c->regs[VCPU_REGS_RAX + (c->b & 0x3)]
+ 1);
+ c->dst.ptr =
+ (unsigned long *)&c->regs[VCPU_REGS_RAX + (c->b
& 0x7)];

Quoted 4 lines

--
Any sufficiently difficult bug is indistinguishable from a feature.

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): 1193798626.9258.34.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org

#6 lore raw
Quoted 30 lines · Nitin A Kamble
Quoted 18 lines · Avi Kivity
Quoted 16 lines · Nitin A Kamble

Hi Avi,
Attached is the patch to implement emulation of instructions mov rl, imm8 (opcodes 0xb0-0xb3)
mov rh, imm8 (opcodes 0xb4-0xb7)
mov r, imm (opcodes0xb8-0xbf)

drivers/kvm/x86_emulate.c +2 -2
@@ -146,8 +146,12 @@ static u16 opcode_table[256] = {
        0, 0, ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
        ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
        ByteOp | ImplicitOps, ImplicitOps,
-       /* 0xB0 - 0xBF */
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       /* 0xB0 - 0xB7 */
+       Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte, Mov |
 SrcImmByte,
Quoted 9 lines

drivers/kvm/x86_emulate.c static u16 opcode_table[256] = { · line 155

Quoted 7 lines
drivers/kvm/x86_emulate.c +4 -0
+       Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte, Mov |
 SrcImmByte,
+       /* 0xB8 - 0xBF */
+       Mov | SrcImm, Mov | SrcImm, Mov | SrcImm, Mov | SrcImm,
+       Mov | SrcImm, Mov | SrcImm, Mov | SrcImm, Mov | SrcImm,
        /* 0xC0 - 0xC7 */

Perhaps adding DstReg would reduce the decoding code later on?

Quoted 5 lines

Avi,
The decoding of register is significantly different for these instructions. It will be just moving code from one place to other place.

Right.

But perhaps we can have a ShortReg modifier to make the decoding common. There are several instructions which can use this (inc, dec, xchg, push, mov).

I'll look into this.

Signature · 8 lines
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
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): 4728370E.3030401-atKUWr5tajBWk0Htik3J/[email protected]

#8 lore raw
Quoted 37 lines · Avi Kivity
Quoted 30 lines · Nitin A Kamble
Quoted 18 lines · Avi Kivity
Quoted 16 lines · Nitin A Kamble

Hi Avi,
Attached is the patch to implement emulation of instructions mov rl, imm8 (opcodes 0xb0-0xb3)
mov rh, imm8 (opcodes 0xb4-0xb7)
mov r, imm (opcodes0xb8-0xbf)

(quoted diff) +2 -2
@@ -146,8 +146,12 @@ static u16 opcode_table[256] = {
        0, 0, ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
        ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
        ByteOp | ImplicitOps, ImplicitOps,
-       /* 0xB0 - 0xBF */
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       /* 0xB0 - 0xB7 */
+       Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte, Mov |
 SrcImmByte,
Quoted 9 lines

Review static u16 opcode_table[256] = { · line 157

Quoted 7 lines
(quoted diff) +4 -0
+       Mov | SrcImmByte, Mov | SrcImmByte, Mov | SrcImmByte, Mov |
 SrcImmByte,
+       /* 0xB8 - 0xBF */
+       Mov | SrcImm, Mov | SrcImm, Mov | SrcImm, Mov | SrcImm,
+       Mov | SrcImm, Mov | SrcImm, Mov | SrcImm, Mov | SrcImm,
        /* 0xC0 - 0xC7 */

Perhaps adding DstReg would reduce the decoding code later on?

Quoted 5 lines

Avi,
The decoding of register is significantly different for these instructions. It will be just moving code from one place to other place.

Quoted 8 lines

Right.

But perhaps we can have a ShortReg modifier to make the decoding common. There are several instructions which can use this (inc, dec, xchg, push, mov).

I'll look into this.

I've committed a few patches which enable this. Now, a DstReg or SrcReg without ModRM will decode the opcode byte to get the register. It also fixes a minor issue with ignoring rex prefixes on 64-bit byte insns. mov, inc, dec, push, and pop have been converted.

Please review these patches carefully as I haven't been able to give them a real workout other than booting a few guests.

Signature · 8 lines
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
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/