public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org
Cc: <xin.li@intel.com>
Subject: [PATCH kvm-unit-tests] emulator: test rip-relative insn with immediate operand
Date: Sun, 19 Jun 2011 19:50:55 +0300	[thread overview]
Message-ID: <1308502255-11318-1-git-send-email-avi@redhat.com> (raw)

kvm has a bug with instructions of the form

  opcode $imm, displ(%%rip)

Where the effective address was not calculated correctly.  Test
it now.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 x86/emulator.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/x86/emulator.c b/x86/emulator.c
index 967f2a4..d4f0363 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -627,15 +627,31 @@ static void test_sse(sse_union *mem)
     report("movdqu (write)", sseeq(mem, &v));
 }
 
+static void test_rip_relative(unsigned *mem, char *insn_ram)
+{
+    /* movb $1, mem+2(%rip) */
+    insn_ram[0] = 0xc6;
+    insn_ram[1] = 0x05;
+    *(unsigned *)&insn_ram[2] = 2 + (char *)mem - (insn_ram + 7);
+    insn_ram[6] = 0x01;
+    /* ret */
+    insn_ram[7] = 0xc3;
+
+    *mem = 0;
+    asm("callq *%1" : "+m"(*mem) : "r"(insn_ram));
+    report("movb $imm, 0(%rip)", *mem == 0x10000);
+}
 
 int main()
 {
 	void *mem;
+	void *insn_ram;
 	unsigned long t1, t2;
 
 	setup_vm();
 	setup_idt();
 	mem = vmap(IORAM_BASE_PHYS, IORAM_LEN);
+	insn_ram = vmalloc(4096);
 
 	// test mov reg, r/m and mov r/m, reg
 	t1 = 0x123456789abcdef;
@@ -667,6 +683,7 @@ int main()
 	test_imul(mem);
 	test_div(mem);
 	test_sse(mem);
+	test_rip_relative(mem, insn_ram);
 
 	printf("\nSUMMARY: %d tests, %d failures\n", tests, fails);
 	return fails ? 1 : 0;
-- 
1.7.5.3


             reply	other threads:[~2011-06-19 16:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-19 16:50 Avi Kivity [this message]
2011-06-21 15:49 ` [PATCH kvm-unit-tests] emulator: test rip-relative insn with immediate operand Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1308502255-11318-1-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=xin.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox