direct-io.hg

changeset 4269:affc97a3b3e5

bitkeeper revision 1.1236.1.114 (42407a31Nf9p7AkNdYSNJUqcXa7-NA)

Fix XCHG instruction emulation.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Mar 22 20:04:01 2005 +0000 (2005-03-22)
parents 4a49af0cc9d9
children 33569fbfdfed
files tools/tests/test_x86_emulator.c xen/arch/x86/x86_emulate.c
line diff
     1.1 --- a/tools/tests/test_x86_emulator.c	Tue Mar 22 19:35:36 2005 +0000
     1.2 +++ b/tools/tests/test_x86_emulator.c	Tue Mar 22 20:04:01 2005 +0000
     1.3 @@ -134,9 +134,42 @@ int main(int argc, char **argv)
     1.4          goto fail;
     1.5      printf("okay\n");
     1.6  
     1.7 +    printf("%-40s", "Testing lock cmpxchgb %%cl,(%%eax)...");
     1.8 +    instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb0; instr[3] = 0x08;
     1.9 +    regs.eflags = 0x200;
    1.10 +    regs.eip    = (unsigned long)&instr[0];
    1.11 +    regs.eax    = 0xAABBCC77UL;
    1.12 +    regs.ecx    = 0xFF;
    1.13 +    cr2         = (unsigned long)&res;
    1.14 +    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);    
    1.15 +    if ( (rc != 0) || 
    1.16 +         (res != 0x923456AA) || 
    1.17 +         ((regs.eflags&0x240) != 0x200) ||
    1.18 +         (regs.eax != 0xAABBCCAA) ||
    1.19 +         (regs.ecx != 0xFF) ||
    1.20 +         (regs.eip != (unsigned long)&instr[4]) )
    1.21 +        goto fail;
    1.22 +    printf("okay\n");
    1.23 +
    1.24 +    printf("%-40s", "Testing xchgl %%ecx,(%%eax)...");
    1.25 +    instr[0] = 0x87; instr[1] = 0x08;
    1.26 +    regs.eflags = 0x200;
    1.27 +    regs.eip    = (unsigned long)&instr[0];
    1.28 +    regs.ecx    = 0x12345678;
    1.29 +    cr2         = (unsigned long)&res;
    1.30 +    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);    
    1.31 +    if ( (rc != 0) || 
    1.32 +         (res != 0x12345678) || 
    1.33 +         (regs.eflags != 0x200) ||
    1.34 +         (regs.ecx != 0x923456AA) ||
    1.35 +         (regs.eip != (unsigned long)&instr[2]) )
    1.36 +        goto fail;
    1.37 +    printf("okay\n");
    1.38 +
    1.39      printf("%-40s", "Testing lock cmpxchgl %%ecx,(%%eax)...");
    1.40      instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb1; instr[3] = 0x08;
    1.41      regs.eflags = 0x200;
    1.42 +    res         = 0x923456AA;
    1.43      regs.eip    = (unsigned long)&instr[0];
    1.44      regs.eax    = 0x923456AAUL;
    1.45      regs.ecx    = 0xDDEEFF00L;
    1.46 @@ -186,7 +219,7 @@ int main(int argc, char **argv)
    1.47          goto fail;
    1.48      printf("okay\n");
    1.49  
    1.50 -    printf("%-40s", "Testing cmpxchg (%edi) [succeeding]...");
    1.51 +    printf("%-40s", "Testing cmpxchg8b (%edi) [succeeding]...");
    1.52      instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
    1.53      regs.eflags = 0x200;
    1.54      regs.eax    = cmpxchg8b_res[0];
    1.55 @@ -205,7 +238,7 @@ int main(int argc, char **argv)
    1.56          goto fail;
    1.57      printf("okay\n");
    1.58  
    1.59 -    printf("%-40s", "Testing cmpxchg (%edi) [failing]...");
    1.60 +    printf("%-40s", "Testing cmpxchg8b (%edi) [failing]...");
    1.61      instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
    1.62      regs.eip    = (unsigned long)&instr[0];
    1.63      regs.edi    = (unsigned long)cmpxchg8b_res;
     2.1 --- a/xen/arch/x86/x86_emulate.c	Tue Mar 22 19:35:36 2005 +0000
     2.2 +++ b/xen/arch/x86/x86_emulate.c	Tue Mar 22 20:04:01 2005 +0000
     2.3 @@ -672,6 +672,14 @@ x86_emulate_memop(
     2.4          dst.val ^= src.val;
     2.5          src.val ^= dst.val;
     2.6          lock_prefix = 1;
     2.7 +        /* Write back the source (temporary register location). */
     2.8 +        switch ( dst.bytes )
     2.9 +        {
    2.10 +        case 1: *(u8  *)src.ptr = (u8)src.val; break;
    2.11 +        case 2: *(u16 *)src.ptr = (u16)src.val; break;
    2.12 +        case 4: *src.ptr = (u32)src.val; break; /* 64b mode: zero-extend */
    2.13 +        case 8: *src.ptr = src.val; break;
    2.14 +        }
    2.15          break;
    2.16      case 0xa0 ... 0xa1: /* mov */
    2.17          dst.ptr = (unsigned long *)&_regs.eax;