Commit 8cfa5a06 authored by Avi Kivity's avatar Avi Kivity Committed by Marcelo Tosatti
Browse files

emulator: test rip-relative insn with immediate operand



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: default avatarAvi Kivity <avi@redhat.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent d7f3ee3c
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment