All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86 emulator: add JrCXZ instruction emulation
@ 2010-08-19  6:25 Wei Yongjun
  2010-08-19  6:28 ` [PATCH] Add realmode test for jcxz instruction Wei Yongjun
  0 siblings, 1 reply; 7+ messages in thread
From: Wei Yongjun @ 2010-08-19  6:25 UTC (permalink / raw)
  To: Avi Kivity, kvm

Add JrCXZ instruction emulation (opcode 0xe3)
Used by FreeBSD boot loader.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index cbf6209..6ccc584 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2331,7 +2331,7 @@ static struct opcode opcode_table[256] = {
 	/* 0xD8 - 0xDF */
 	N, N, N, N, N, N, N, N,
 	/* 0xE0 - 0xE7 */
-	X3(D(SrcImmByte)), N,
+	X4(D(SrcImmByte)),
 	D(ByteOp | SrcImmUByte | DstAcc), D(SrcImmUByte | DstAcc),
 	D(ByteOp | SrcAcc | DstImmUByte), D(SrcAcc | DstImmUByte),
 	/* 0xE8 - 0xEF */
@@ -3092,6 +3092,10 @@ special_insn:
 		    (c->b == 0xe2 || test_cc(c->b ^ 0x5, ctxt->eflags)))
 			jmp_rel(c, c->src.val);
 		break;
+	case 0xe3:	/* jcxz/jecxz/jrcxz */
+		if (address_mask(c, c->regs[VCPU_REGS_RCX]) == 0)
+			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] 7+ messages in thread

* [PATCH] Add realmode test for jcxz instruction
  2010-08-19  6:25 [PATCH] KVM: x86 emulator: add JrCXZ instruction emulation Wei Yongjun
@ 2010-08-19  6:28 ` Wei Yongjun
  2010-08-19 13:05   ` Avi Kivity
  0 siblings, 1 reply; 7+ messages in thread
From: Wei Yongjun @ 2010-08-19  6:28 UTC (permalink / raw)
  To: Avi Kivity, kvm

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>

diff --git a/x86/realmode.c b/x86/realmode.c
index ce8fb18..0caf388 100644
--- a/x86/realmode.c
+++ b/x86/realmode.c
@@ -1262,6 +1262,32 @@ void test_cbw(void)
 		print_serial("cwde test 1: PASS\n");
 }
 
+void test_jcxz(void)
+{
+	struct regs inregs = { 0 }, outregs;
+
+	MK_INSN(jcxz, "jcxz 1f\n\t"
+		      "mov $0x1234, %eax\n\t"
+		      "1:\n\t");
+	MK_INSN(jecxz, "jecxz 1f\n\t"
+		       "mov $0x1234, %eax\n\t"
+		       "1:\n\t");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			insn_jcxz, insn_jcxz_end - insn_jcxz);
+	if(!regs_equal(&inregs, &outregs, 0))
+		print_serial("JCXZ short Test 1: FAIL\n");
+	else
+		print_serial("JCXZ short Test 1: PASS\n");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			insn_jecxz, insn_jecxz_end - insn_jecxz);
+	if(!regs_equal(&inregs, &outregs, 0))
+		print_serial("JECXZ short Test 1: FAIL\n");
+	else
+		print_serial("JECXZ short Test 1: PASS\n");
+}
+
 void realmode_start(void)
 {
 	test_null();
@@ -1291,6 +1317,7 @@ void realmode_start(void)
 	test_idiv();
 	test_loopcc();
 	test_cbw();
+	test_jcxz();
 
 	exit(0);
 }
-- 
1.7.0.4



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

* Re: [PATCH] Add realmode test for jcxz instruction
  2010-08-19  6:28 ` [PATCH] Add realmode test for jcxz instruction Wei Yongjun
@ 2010-08-19 13:05   ` Avi Kivity
  2010-08-20  0:52     ` [PATCH v2] " Wei Yongjun
  0 siblings, 1 reply; 7+ messages in thread
From: Avi Kivity @ 2010-08-19 13:05 UTC (permalink / raw)
  To: Wei Yongjun; +Cc: kvm

 On 08/19/2010 09:28 AM, Wei Yongjun wrote:
> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
>
> diff --git a/x86/realmode.c b/x86/realmode.c
> index ce8fb18..0caf388 100644
> --- a/x86/realmode.c
> +++ b/x86/realmode.c
> @@ -1262,6 +1262,32 @@ void test_cbw(void)
>  		print_serial("cwde test 1: PASS\n");
>  }
>  
> +void test_jcxz(void)
> +{
> +	struct regs inregs = { 0 }, outregs;
> +
> +	MK_INSN(jcxz, "jcxz 1f\n\t"
> +		      "mov $0x1234, %eax\n\t"
> +		      "1:\n\t");
> +	MK_INSN(jecxz, "jecxz 1f\n\t"
> +		       "mov $0x1234, %eax\n\t"
> +		       "1:\n\t");
> +
> +	exec_in_big_real_mode(&inregs, &outregs,
> +			insn_jcxz, insn_jcxz_end - insn_jcxz);
> +	if(!regs_equal(&inregs, &outregs, 0))
> +		print_serial("JCXZ short Test 1: FAIL\n");
> +	else
> +		print_serial("JCXZ short Test 1: PASS\n");
> +
> +	exec_in_big_real_mode(&inregs, &outregs,
> +			insn_jecxz, insn_jecxz_end - insn_jecxz);
> +	if(!regs_equal(&inregs, &outregs, 0))
> +		print_serial("JECXZ short Test 1: FAIL\n");
> +	else
> +		print_serial("JECXZ short Test 1: PASS\n");
> +}
> +

What about tests for jump-not-taken?

As a bonus, check jcxz with ecx=0x10000 and jecxz with ecx=0x10000.

-- 
error compiling committee.c: too many arguments to function


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

* [PATCH v2] Add realmode test for jcxz instruction
  2010-08-19 13:05   ` Avi Kivity
@ 2010-08-20  0:52     ` Wei Yongjun
  2010-08-24  0:00       ` Marcelo Tosatti
  0 siblings, 1 reply; 7+ messages in thread
From: Wei Yongjun @ 2010-08-20  0:52 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm

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

diff --git a/x86/realmode.c b/x86/realmode.c
index ce8fb18..75d77bd 100644
--- a/x86/realmode.c
+++ b/x86/realmode.c
@@ -1262,6 +1262,67 @@ void test_cbw(void)
 		print_serial("cwde test 1: PASS\n");
 }
 
+void test_jcxz(void)
+{
+	struct regs inregs = { 0 }, outregs;
+
+	MK_INSN(jcxz1, "jcxz 1f\n\t"
+		       "mov $0x1234, %eax\n\t"
+		       "1:\n\t");
+	MK_INSN(jcxz2, "mov $0x100, %ecx\n\t"
+		       "jcxz 1f\n\t"
+		       "mov $0x1234, %eax\n\t"
+		       "mov $0, %ecx\n\t"
+		       "1:\n\t");
+	MK_INSN(jcxz3, "mov $0x10000, %ecx\n\t"
+		       "jcxz 1f\n\t"
+		       "mov $0x1234, %eax\n\t"
+		       "1:\n\t");
+	MK_INSN(jecxz1, "jecxz 1f\n\t"
+			"mov $0x1234, %eax\n\t"
+			"1:\n\t");
+	MK_INSN(jecxz2, "mov $0x10000, %ecx\n\t"
+			"jecxz 1f\n\t"
+			"mov $0x1234, %eax\n\t"
+			"mov $0, %ecx\n\t"
+			"1:\n\t");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			insn_jcxz1, insn_jcxz1_end - insn_jcxz1);
+	if(!regs_equal(&inregs, &outregs, 0))
+		print_serial("JCXZ short Test 1: FAIL\n");
+	else
+		print_serial("JCXZ short Test 1: PASS\n");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			insn_jcxz2, insn_jcxz2_end - insn_jcxz2);
+	if(!regs_equal(&inregs, &outregs, R_AX) || outregs.eax != 0x1234)
+		print_serial("JCXZ short Test 2: FAIL\n");
+	else
+		print_serial("JCXZ short Test 2: PASS\n");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			insn_jcxz3, insn_jcxz3_end - insn_jcxz3);
+	if(!regs_equal(&inregs, &outregs, R_CX) || outregs.ecx != 0x10000)
+		print_serial("JCXZ short Test 3: FAIL\n");
+	else
+		print_serial("JCXZ short Test 3: PASS\n");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			insn_jecxz1, insn_jecxz1_end - insn_jecxz1);
+	if(!regs_equal(&inregs, &outregs, 0))
+		print_serial("JECXZ short Test 1: FAIL\n");
+	else
+		print_serial("JECXZ short Test 1: PASS\n");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			insn_jecxz2, insn_jecxz2_end - insn_jecxz2);
+	if(!regs_equal(&inregs, &outregs, R_AX) || outregs.eax != 0x1234)
+		print_serial("JECXZ short Test 2: FAIL\n");
+	else
+		print_serial("JECXZ short Test 2: PASS\n");
+}
+
 void realmode_start(void)
 {
 	test_null();
@@ -1291,6 +1352,7 @@ void realmode_start(void)
 	test_idiv();
 	test_loopcc();
 	test_cbw();
+	test_jcxz();
 
 	exit(0);
 }
-- 
1.7.0.4



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

* Re: [PATCH v2] Add realmode test for jcxz instruction
  2010-08-20  0:52     ` [PATCH v2] " Wei Yongjun
@ 2010-08-24  0:00       ` Marcelo Tosatti
  2010-08-24  2:57         ` [PATCH v3] " Wei Yongjun
  0 siblings, 1 reply; 7+ messages in thread
From: Marcelo Tosatti @ 2010-08-24  0:00 UTC (permalink / raw)
  To: Wei Yongjun; +Cc: Avi Kivity, kvm

On Fri, Aug 20, 2010 at 08:52:56AM +0800, Wei Yongjun wrote:
> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
> ---
>  x86/realmode.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 62 insertions(+), 0 deletions(-)

Please rebase.


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

* [PATCH v3] Add realmode test for jcxz instruction
  2010-08-24  0:00       ` Marcelo Tosatti
@ 2010-08-24  2:57         ` Wei Yongjun
  2010-08-24 13:18           ` Marcelo Tosatti
  0 siblings, 1 reply; 7+ messages in thread
From: Wei Yongjun @ 2010-08-24  2:57 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: Avi Kivity, kvm

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

diff --git a/x86/realmode.c b/x86/realmode.c
index 8c771fc..a833829 100644
--- a/x86/realmode.c
+++ b/x86/realmode.c
@@ -1242,6 +1242,47 @@ void test_lds_lss()
 		outregs.ebx == desc.sel);
 }
 
+void test_jcxz(void)
+{
+	MK_INSN(jcxz1, "jcxz 1f\n\t"
+		       "mov $0x1234, %eax\n\t"
+		       "1:\n\t");
+	MK_INSN(jcxz2, "mov $0x100, %ecx\n\t"
+		       "jcxz 1f\n\t"
+		       "mov $0x1234, %eax\n\t"
+		       "mov $0, %ecx\n\t"
+		       "1:\n\t");
+	MK_INSN(jcxz3, "mov $0x10000, %ecx\n\t"
+		       "jcxz 1f\n\t"
+		       "mov $0x1234, %eax\n\t"
+		       "1:\n\t");
+	MK_INSN(jecxz1, "jecxz 1f\n\t"
+			"mov $0x1234, %eax\n\t"
+			"1:\n\t");
+	MK_INSN(jecxz2, "mov $0x10000, %ecx\n\t"
+			"jecxz 1f\n\t"
+			"mov $0x1234, %eax\n\t"
+			"mov $0, %ecx\n\t"
+			"1:\n\t");
+
+	inregs = (struct regs){ 0 };
+
+	exec_in_big_real_mode(&insn_jcxz1);
+	report("jcxz short 1", 0, 1);
+
+	exec_in_big_real_mode(&insn_jcxz2);
+	report("jcxz short 2", R_AX, outregs.eax == 0x1234);
+
+	exec_in_big_real_mode(&insn_jcxz3);
+	report("jcxz short 3", R_CX, outregs.ecx == 0x10000);
+
+	exec_in_big_real_mode(&insn_jecxz1);
+	report("jecxz short 1", 0, 1);
+
+	exec_in_big_real_mode(&insn_jecxz2);
+	report("jecxz short 2", R_AX, outregs.eax == 0x1234);
+}
+
 void realmode_start(void)
 {
 	test_null();
@@ -1274,6 +1315,7 @@ void realmode_start(void)
 	test_cwd_cdq();
 	test_das();
 	test_lds_lss();
+	test_jcxz();
 
 	exit(0);
 }
-- 
1.7.0.4



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

* Re: [PATCH v3] Add realmode test for jcxz instruction
  2010-08-24  2:57         ` [PATCH v3] " Wei Yongjun
@ 2010-08-24 13:18           ` Marcelo Tosatti
  0 siblings, 0 replies; 7+ messages in thread
From: Marcelo Tosatti @ 2010-08-24 13:18 UTC (permalink / raw)
  To: Wei Yongjun; +Cc: Avi Kivity, kvm

On Tue, Aug 24, 2010 at 10:57:12AM +0800, Wei Yongjun wrote:
> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
> ---
> v2 -> v3: rebased
> ---
>  x86/realmode.c |   42 ++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 42 insertions(+), 0 deletions(-)

Applied, thanks.


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

end of thread, other threads:[~2010-08-24 14:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-19  6:25 [PATCH] KVM: x86 emulator: add JrCXZ instruction emulation Wei Yongjun
2010-08-19  6:28 ` [PATCH] Add realmode test for jcxz instruction Wei Yongjun
2010-08-19 13:05   ` Avi Kivity
2010-08-20  0:52     ` [PATCH v2] " Wei Yongjun
2010-08-24  0:00       ` Marcelo Tosatti
2010-08-24  2:57         ` [PATCH v3] " Wei Yongjun
2010-08-24 13:18           ` Marcelo Tosatti

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.