aboutsummaryrefslogtreecommitdiffstats
path: root/tools/tests
diff options
context:
space:
mode:
authorkfraser@dhcp93.uk.xensource.com <kfraser@dhcp93.uk.xensource.com>2006-06-06 08:05:13 +0100
committerkfraser@dhcp93.uk.xensource.com <kfraser@dhcp93.uk.xensource.com>2006-06-06 08:05:13 +0100
commitd82a7836f687b820d1fc0df8e78f67685adafc6f (patch)
tree16d45a680e2162d4d4ffdda2543ae06869f6fa15 /tools/tests
parentff476d8ed1e0a5742efea9bde70ea0b8c4db157e (diff)
downloadxen-d82a7836f687b820d1fc0df8e78f67685adafc6f.tar.gz
xen-d82a7836f687b820d1fc0df8e78f67685adafc6f.tar.bz2
xen-d82a7836f687b820d1fc0df8e78f67685adafc6f.zip
[X86EMUL] Mark MOV instruction as not needing writeback.
Fix the test harness for x86/64 -- map emulated addresses to low 4GB of address space. Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'tools/tests')
-rw-r--r--tools/tests/test_x86_emulator.c103
1 files changed, 64 insertions, 39 deletions
diff --git a/tools/tests/test_x86_emulator.c b/tools/tests/test_x86_emulator.c
index 5fef349fab..11755c3373 100644
--- a/tools/tests/test_x86_emulator.c
+++ b/tools/tests/test_x86_emulator.c
@@ -13,6 +13,7 @@ typedef int32_t s32;
typedef int64_t s64;
#include <public/xen.h>
#include <asm-x86/x86_emulate.h>
+#include <sys/mman.h>
static int read_any(
unsigned long addr,
@@ -85,23 +86,30 @@ int main(int argc, char **argv)
struct x86_emulate_ctxt ctxt;
struct cpu_user_regs regs;
char instr[20] = { 0x01, 0x08 }; /* add %ecx,(%eax) */
- unsigned int res = 0x7FFFFFFF;
- u32 cmpxchg8b_res[2] = { 0x12345678, 0x87654321 };
+ unsigned int *res;
int rc;
ctxt.regs = &regs;
ctxt.mode = X86EMUL_MODE_PROT32;
+ res = mmap((void *)0x100000, 0x1000, PROT_READ|PROT_WRITE,
+ MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
+ if ( res == MAP_FAILED )
+ {
+ fprintf(stderr, "mmap to low address failed\n");
+ exit(1);
+ }
+
printf("%-40s", "Testing addl %%ecx,(%%eax)...");
instr[0] = 0x01; instr[1] = 0x08;
regs.eflags = 0x200;
regs.eip = (unsigned long)&instr[0];
regs.ecx = 0x12345678;
- ctxt.cr2 = (unsigned long)&res;
- res = 0x7FFFFFFF;
+ ctxt.cr2 = (unsigned long)res;
+ *res = 0x7FFFFFFF;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (res != 0x92345677) ||
+ (*res != 0x92345677) ||
(regs.eflags != 0xa94) ||
(regs.eip != (unsigned long)&instr[2]) )
goto fail;
@@ -116,25 +124,39 @@ int main(int argc, char **argv)
#else
regs.ecx = 0x12345678UL;
#endif
- ctxt.cr2 = (unsigned long)&res;
+ ctxt.cr2 = (unsigned long)res;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (res != 0x92345677) ||
+ (*res != 0x92345677) ||
(regs.ecx != 0x8000000FUL) ||
(regs.eip != (unsigned long)&instr[2]) )
goto fail;
printf("okay\n");
+ printf("%-40s", "Testing movl (%%eax),%%ecx...");
+ instr[0] = 0x8b; instr[1] = 0x08;
+ regs.eflags = 0x200;
+ regs.eip = (unsigned long)&instr[0];
+ regs.ecx = ~0UL;
+ ctxt.cr2 = (unsigned long)res;
+ rc = x86_emulate_memop(&ctxt, &emulops);
+ if ( (rc != 0) ||
+ (*res != 0x92345677) ||
+ (regs.ecx != 0x92345677UL) ||
+ (regs.eip != (unsigned long)&instr[2]) )
+ goto fail;
+ printf("okay\n");
+
printf("%-40s", "Testing lock cmpxchgb %%cl,(%%eax)...");
instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb0; instr[3] = 0x08;
regs.eflags = 0x200;
regs.eip = (unsigned long)&instr[0];
regs.eax = 0x92345677UL;
regs.ecx = 0xAA;
- ctxt.cr2 = (unsigned long)&res;
+ ctxt.cr2 = (unsigned long)res;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (res != 0x923456AA) ||
+ (*res != 0x923456AA) ||
(regs.eflags != 0x244) ||
(regs.eax != 0x92345677UL) ||
(regs.eip != (unsigned long)&instr[4]) )
@@ -147,10 +169,10 @@ int main(int argc, char **argv)
regs.eip = (unsigned long)&instr[0];
regs.eax = 0xAABBCC77UL;
regs.ecx = 0xFF;
- ctxt.cr2 = (unsigned long)&res;
+ ctxt.cr2 = (unsigned long)res;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (res != 0x923456AA) ||
+ (*res != 0x923456AA) ||
((regs.eflags&0x240) != 0x200) ||
(regs.eax != 0xAABBCCAA) ||
(regs.ecx != 0xFF) ||
@@ -163,10 +185,10 @@ int main(int argc, char **argv)
regs.eflags = 0x200;
regs.eip = (unsigned long)&instr[0];
regs.ecx = 0x12345678;
- ctxt.cr2 = (unsigned long)&res;
+ ctxt.cr2 = (unsigned long)res;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (res != 0x12345678) ||
+ (*res != 0x12345678) ||
(regs.eflags != 0x200) ||
(regs.ecx != 0x923456AA) ||
(regs.eip != (unsigned long)&instr[2]) )
@@ -176,14 +198,14 @@ int main(int argc, char **argv)
printf("%-40s", "Testing lock cmpxchgl %%ecx,(%%eax)...");
instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb1; instr[3] = 0x08;
regs.eflags = 0x200;
- res = 0x923456AA;
+ *res = 0x923456AA;
regs.eip = (unsigned long)&instr[0];
regs.eax = 0x923456AAUL;
regs.ecx = 0xDDEEFF00L;
- ctxt.cr2 = (unsigned long)&res;
+ ctxt.cr2 = (unsigned long)res;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (res != 0xDDEEFF00) ||
+ (*res != 0xDDEEFF00) ||
(regs.eflags != 0x244) ||
(regs.eax != 0x923456AAUL) ||
(regs.eip != (unsigned long)&instr[4]) )
@@ -192,54 +214,57 @@ int main(int argc, char **argv)
printf("%-40s", "Testing rep movsw...");
instr[0] = 0xf3; instr[1] = 0x66; instr[2] = 0xa5;
- res = 0x22334455;
+ *res = 0x22334455;
regs.eflags = 0x200;
regs.ecx = 23;
regs.eip = (unsigned long)&instr[0];
- regs.esi = (unsigned long)&res + 0;
- regs.edi = (unsigned long)&res + 2;
+ regs.esi = (unsigned long)res + 0;
+ regs.edi = (unsigned long)res + 2;
regs.error_code = 0; /* read fault */
ctxt.cr2 = regs.esi;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (res != 0x44554455) ||
+ (*res != 0x44554455) ||
(regs.eflags != 0x200) ||
(regs.ecx != 22) ||
- (regs.esi != ((unsigned long)&res + 2)) ||
- (regs.edi != ((unsigned long)&res + 4)) ||
+ (regs.esi != ((unsigned long)res + 2)) ||
+ (regs.edi != ((unsigned long)res + 4)) ||
(regs.eip != (unsigned long)&instr[0]) )
goto fail;
printf("okay\n");
printf("%-40s", "Testing btrl $0x1,(%edi)...");
instr[0] = 0x0f; instr[1] = 0xba; instr[2] = 0x37; instr[3] = 0x01;
- res = 0x2233445F;
+ *res = 0x2233445F;
regs.eflags = 0x200;
regs.eip = (unsigned long)&instr[0];
- regs.edi = (unsigned long)&res;
+ regs.edi = (unsigned long)res;
ctxt.cr2 = regs.edi;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (res != 0x2233445D) ||
+ (*res != 0x2233445D) ||
((regs.eflags&0x201) != 0x201) ||
(regs.eip != (unsigned long)&instr[4]) )
goto fail;
printf("okay\n");
+ res[0] = 0x12345678;
+ res[1] = 0x87654321;
+
printf("%-40s", "Testing cmpxchg8b (%edi) [succeeding]...");
instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
regs.eflags = 0x200;
- regs.eax = cmpxchg8b_res[0];
- regs.edx = cmpxchg8b_res[1];
+ regs.eax = res[0];
+ regs.edx = res[1];
regs.ebx = 0x9999AAAA;
regs.ecx = 0xCCCCFFFF;
regs.eip = (unsigned long)&instr[0];
- regs.edi = (unsigned long)cmpxchg8b_res;
+ regs.edi = (unsigned long)res;
ctxt.cr2 = regs.edi;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (cmpxchg8b_res[0] != 0x9999AAAA) ||
- (cmpxchg8b_res[1] != 0xCCCCFFFF) ||
+ (res[0] != 0x9999AAAA) ||
+ (res[1] != 0xCCCCFFFF) ||
((regs.eflags&0x240) != 0x240) ||
(regs.eip != (unsigned long)&instr[3]) )
goto fail;
@@ -248,12 +273,12 @@ int main(int argc, char **argv)
printf("%-40s", "Testing cmpxchg8b (%edi) [failing]...");
instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
regs.eip = (unsigned long)&instr[0];
- regs.edi = (unsigned long)cmpxchg8b_res;
+ regs.edi = (unsigned long)res;
ctxt.cr2 = regs.edi;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (cmpxchg8b_res[0] != 0x9999AAAA) ||
- (cmpxchg8b_res[1] != 0xCCCCFFFF) ||
+ (res[0] != 0x9999AAAA) ||
+ (res[1] != 0xCCCCFFFF) ||
(regs.eax != 0x9999AAAA) ||
(regs.edx != 0xCCCCFFFF) ||
((regs.eflags&0x240) != 0x200) ||
@@ -265,11 +290,11 @@ int main(int argc, char **argv)
instr[0] = 0x0f; instr[1] = 0xbe; instr[2] = 0x08;
regs.eip = (unsigned long)&instr[0];
regs.ecx = 0x12345678;
- ctxt.cr2 = (unsigned long)&res;
- res = 0x82;
+ ctxt.cr2 = (unsigned long)res;
+ *res = 0x82;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (res != 0x82) ||
+ (*res != 0x82) ||
(regs.ecx != 0xFFFFFF82) ||
((regs.eflags&0x240) != 0x200) ||
(regs.eip != (unsigned long)&instr[3]) )
@@ -280,11 +305,11 @@ int main(int argc, char **argv)
instr[0] = 0x0f; instr[1] = 0xb7; instr[2] = 0x08;
regs.eip = (unsigned long)&instr[0];
regs.ecx = 0x12345678;
- ctxt.cr2 = (unsigned long)&res;
- res = 0x1234aa82;
+ ctxt.cr2 = (unsigned long)res;
+ *res = 0x1234aa82;
rc = x86_emulate_memop(&ctxt, &emulops);
if ( (rc != 0) ||
- (res != 0x1234aa82) ||
+ (*res != 0x1234aa82) ||
(regs.ecx != 0xaa82) ||
((regs.eflags&0x240) != 0x200) ||
(regs.eip != (unsigned long)&instr[3]) )