ChangeSet 1.1350, 2005/03/22 20:04:01+00:00, kaf24@xxxxxxxxxxxxxxxxxxxx
Fix XCHG instruction emulation.
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
tools/tests/test_x86_emulator.c | 37 +++++++++++++++++++++++++++++++++++--
xen/arch/x86/x86_emulate.c | 8 ++++++++
2 files changed, 43 insertions(+), 2 deletions(-)
diff -Nru a/tools/tests/test_x86_emulator.c b/tools/tests/test_x86_emulator.c
--- a/tools/tests/test_x86_emulator.c 2005-03-22 16:03:17 -05:00
+++ b/tools/tests/test_x86_emulator.c 2005-03-22 16:03:17 -05:00
@@ -134,9 +134,42 @@
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 = 0xAABBCC77UL;
+ regs.ecx = 0xFF;
+ cr2 = (unsigned long)&res;
+ rc = x86_emulate_memop(®s, cr2, &emulops, 4);
+ if ( (rc != 0) ||
+ (res != 0x923456AA) ||
+ ((regs.eflags&0x240) != 0x200) ||
+ (regs.eax != 0xAABBCCAA) ||
+ (regs.ecx != 0xFF) ||
+ (regs.eip != (unsigned long)&instr[4]) )
+ goto fail;
+ printf("okay\n");
+
+ printf("%-40s", "Testing xchgl %%ecx,(%%eax)...");
+ instr[0] = 0x87; instr[1] = 0x08;
+ regs.eflags = 0x200;
+ regs.eip = (unsigned long)&instr[0];
+ regs.ecx = 0x12345678;
+ cr2 = (unsigned long)&res;
+ rc = x86_emulate_memop(®s, cr2, &emulops, 4);
+ if ( (rc != 0) ||
+ (res != 0x12345678) ||
+ (regs.eflags != 0x200) ||
+ (regs.ecx != 0x923456AA) ||
+ (regs.eip != (unsigned long)&instr[2]) )
+ goto fail;
+ printf("okay\n");
+
printf("%-40s", "Testing lock cmpxchgl %%ecx,(%%eax)...");
instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb1; instr[3] = 0x08;
regs.eflags = 0x200;
+ res = 0x923456AA;
regs.eip = (unsigned long)&instr[0];
regs.eax = 0x923456AAUL;
regs.ecx = 0xDDEEFF00L;
@@ -186,7 +219,7 @@
goto fail;
printf("okay\n");
- printf("%-40s", "Testing cmpxchg (%edi) [succeeding]...");
+ printf("%-40s", "Testing cmpxchg8b (%edi) [succeeding]...");
instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
regs.eflags = 0x200;
regs.eax = cmpxchg8b_res[0];
@@ -205,7 +238,7 @@
goto fail;
printf("okay\n");
- printf("%-40s", "Testing cmpxchg (%edi) [failing]...");
+ 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;
diff -Nru a/xen/arch/x86/x86_emulate.c b/xen/arch/x86/x86_emulate.c
--- a/xen/arch/x86/x86_emulate.c 2005-03-22 16:03:17 -05:00
+++ b/xen/arch/x86/x86_emulate.c 2005-03-22 16:03:17 -05:00
@@ -672,6 +672,14 @@
dst.val ^= src.val;
src.val ^= dst.val;
lock_prefix = 1;
+ /* Write back the source (temporary register location). */
+ switch ( dst.bytes )
+ {
+ case 1: *(u8 *)src.ptr = (u8)src.val; break;
+ case 2: *(u16 *)src.ptr = (u16)src.val; break;
+ case 4: *src.ptr = (u32)src.val; break; /* 64b mode: zero-extend */
+ case 8: *src.ptr = src.val; break;
+ }
break;
case 0xa0 ... 0xa1: /* mov */
dst.ptr = (unsigned long *)&_regs.eax;
-------------------------------------------------------
This SF.net email is sponsored by: 2005 Windows Mobile Application Contest
Submit applications for Windows Mobile(tm)-based Pocket PCs or Smartphones
for the chance to win $25,000 and application distribution. Enter today at
http://ads.osdn.com/?ad_id=6882&alloc_id=15148&op=click
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/xen-changelog
|