kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: x86 emulator: add LOOP/LOOPcc instruction emulation
@ 2010-08-18  8:38 Wei Yongjun
  2010-08-18  8:41 ` [PATCH] test: Add realmode test for loopcc instruction Wei Yongjun
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Yongjun @ 2010-08-18  8:38 UTC (permalink / raw)
  To: Avi Kivity, kvm

Add LOOP/LOOPcc instruction emulation (opcode 0xe0~0xe2).

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
---
 arch/x86/kvm/emulate.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index ac13831..46b7da8 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2320,7 +2320,7 @@ static struct opcode opcode_table[256] = {
 	/* 0xD8 - 0xDF */
 	N, N, N, N, N, N, N, N,
 	/* 0xE0 - 0xE7 */
-	N, N, N, N,
+	X3(D(SrcImmByte)), N,
 	D(ByteOp | SrcImmUByte | DstAcc), D(SrcImmUByte | DstAcc),
 	D(ByteOp | SrcAcc | DstImmUByte), D(SrcAcc | DstImmUByte),
 	/* 0xE8 - 0xEF */
@@ -3086,6 +3086,12 @@ special_insn:
 		c->src.val = c->regs[VCPU_REGS_RCX];
 		emulate_grp2(ctxt);
 		break;
+	case 0xe0 ... 0xe2:	/* loop/loopz/loopnz */
+		register_address_increment(c, &c->regs[VCPU_REGS_RCX], -1);
+		if (address_mask(c, c->regs[VCPU_REGS_RCX]) != 0 &&
+		    (c->b == 0xe2 || test_cc(c->b ^ 0x5, ctxt->eflags)))
+			jmp_rel(c, c->src.val);
+		break;
 	case 0xe4: 	/* inb */
 	case 0xe5: 	/* in */
 		goto do_io_in;
-- 
1.7.0.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] test: Add realmode test for loopcc instruction
  2010-08-18  8:38 [PATCH] KVM: x86 emulator: add LOOP/LOOPcc instruction emulation Wei Yongjun
@ 2010-08-18  8:41 ` Wei Yongjun
  2010-08-18 10:33   ` Avi Kivity
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Yongjun @ 2010-08-18  8:41 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
---
 x86/realmode.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/x86/realmode.c b/x86/realmode.c
index 35f6a16..bedd175 100644
--- a/x86/realmode.c
+++ b/x86/realmode.c
@@ -1194,6 +1194,48 @@ void test_idiv()
 		print_serial("idiv Test 3: PASS\n");
 }
 
+void test_loopcc(void)
+{
+	struct regs inregs = { 0 }, outregs;
+
+	MK_INSN(loop, "mov $10, %ecx\n\t"
+		      "1: inc %eax\n\t"
+		      "loop 1b\n\t");
+
+	MK_INSN(loope, "mov $10, %ecx\n\t"
+		       "mov $1, %eax\n\t"
+		       "1: dec %eax\n\t"
+		       "loope 1b\n\t");
+
+	MK_INSN(loopne, "mov $10, %ecx\n\t"
+		        "mov $5, %eax\n\t"
+		        "1: dec %eax\n\t"
+			"loopne 1b\n\t");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			insn_loop, insn_loop_end - insn_loop);
+	if(!regs_equal(&inregs, &outregs, R_AX) || outregs.eax != 10)
+		print_serial("LOOPcc short Test 1: FAIL\n");
+	else
+		print_serial("LOOPcc short Test 1: PASS\n");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			insn_loope, insn_loope_end - insn_loope);
+	if(!regs_equal(&inregs, &outregs, R_AX | R_CX) ||
+	   outregs.eax != -1 || outregs.ecx != 8)
+		print_serial("LOOPcc short Test 2: FAIL\n");
+	else
+		print_serial("LOOPcc short Test 2: PASS\n");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			insn_loopne, insn_loopne_end - insn_loopne);
+	if(!regs_equal(&inregs, &outregs, R_AX | R_CX) ||
+	   outregs.eax != 0 || outregs.ecx != 5)
+		print_serial("LOOPcc short Test 3: FAIL\n");
+	else
+		print_serial("LOOPcc short Test 3: PASS\n");
+}
+
 void realmode_start(void)
 {
 	test_null();
@@ -1221,6 +1263,7 @@ void realmode_start(void)
 	test_mul();
 	test_div();
 	test_idiv();
+	test_loopcc();
 
 	exit(0);
 }
-- 
1.7.0.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] test: Add realmode test for loopcc instruction
  2010-08-18  8:41 ` [PATCH] test: Add realmode test for loopcc instruction Wei Yongjun
@ 2010-08-18 10:33   ` Avi Kivity
  0 siblings, 0 replies; 3+ messages in thread
From: Avi Kivity @ 2010-08-18 10:33 UTC (permalink / raw)
  To: Wei Yongjun; +Cc: kvm

 On 08/18/2010 11:41 AM, Wei Yongjun wrote:


Applied, thanks.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-18 10:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-18  8:38 [PATCH] KVM: x86 emulator: add LOOP/LOOPcc instruction emulation Wei Yongjun
2010-08-18  8:41 ` [PATCH] test: Add realmode test for loopcc instruction Wei Yongjun
2010-08-18 10:33   ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).