ia64/xen-unstable

changeset 10312:89d7acdd8951

[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>
author kfraser@dhcp93.uk.xensource.com
date Tue Jun 06 08:05:13 2006 +0100 (2006-06-06)
parents 5e3827f7a93a
children 3913a119477d
files tools/tests/test_x86_emulator.c xen/arch/x86/x86_emulate.c
line diff
     1.1 --- a/tools/tests/test_x86_emulator.c	Mon Jun 05 17:17:27 2006 +0100
     1.2 +++ b/tools/tests/test_x86_emulator.c	Tue Jun 06 08:05:13 2006 +0100
     1.3 @@ -13,6 +13,7 @@ typedef int32_t            s32;
     1.4  typedef int64_t            s64;
     1.5  #include <public/xen.h>
     1.6  #include <asm-x86/x86_emulate.h>
     1.7 +#include <sys/mman.h>
     1.8  
     1.9  static int read_any(
    1.10      unsigned long addr,
    1.11 @@ -85,23 +86,30 @@ int main(int argc, char **argv)
    1.12      struct x86_emulate_ctxt ctxt;
    1.13      struct cpu_user_regs regs;
    1.14      char instr[20] = { 0x01, 0x08 }; /* add %ecx,(%eax) */
    1.15 -    unsigned int res = 0x7FFFFFFF;
    1.16 -    u32 cmpxchg8b_res[2] = { 0x12345678, 0x87654321 };
    1.17 +    unsigned int *res;
    1.18      int rc;
    1.19  
    1.20      ctxt.regs = &regs;
    1.21      ctxt.mode = X86EMUL_MODE_PROT32;
    1.22  
    1.23 +    res = mmap((void *)0x100000, 0x1000, PROT_READ|PROT_WRITE,
    1.24 +               MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
    1.25 +    if ( res == MAP_FAILED )
    1.26 +    {
    1.27 +        fprintf(stderr, "mmap to low address failed\n");
    1.28 +        exit(1);
    1.29 +    }
    1.30 +
    1.31      printf("%-40s", "Testing addl %%ecx,(%%eax)...");
    1.32      instr[0] = 0x01; instr[1] = 0x08;
    1.33      regs.eflags = 0x200;
    1.34      regs.eip    = (unsigned long)&instr[0];
    1.35      regs.ecx    = 0x12345678;
    1.36 -    ctxt.cr2    = (unsigned long)&res;
    1.37 -    res         = 0x7FFFFFFF;
    1.38 +    ctxt.cr2    = (unsigned long)res;
    1.39 +    *res        = 0x7FFFFFFF;
    1.40      rc = x86_emulate_memop(&ctxt, &emulops);
    1.41      if ( (rc != 0) || 
    1.42 -         (res != 0x92345677) || 
    1.43 +         (*res != 0x92345677) || 
    1.44           (regs.eflags != 0xa94) ||
    1.45           (regs.eip != (unsigned long)&instr[2]) )
    1.46          goto fail;
    1.47 @@ -116,25 +124,39 @@ int main(int argc, char **argv)
    1.48  #else
    1.49      regs.ecx    = 0x12345678UL;
    1.50  #endif
    1.51 -    ctxt.cr2    = (unsigned long)&res;
    1.52 +    ctxt.cr2    = (unsigned long)res;
    1.53      rc = x86_emulate_memop(&ctxt, &emulops);
    1.54      if ( (rc != 0) || 
    1.55 -         (res != 0x92345677) || 
    1.56 +         (*res != 0x92345677) || 
    1.57           (regs.ecx != 0x8000000FUL) ||
    1.58           (regs.eip != (unsigned long)&instr[2]) )
    1.59          goto fail;
    1.60      printf("okay\n");
    1.61  
    1.62 +    printf("%-40s", "Testing movl (%%eax),%%ecx...");
    1.63 +    instr[0] = 0x8b; instr[1] = 0x08;
    1.64 +    regs.eflags = 0x200;
    1.65 +    regs.eip    = (unsigned long)&instr[0];
    1.66 +    regs.ecx    = ~0UL;
    1.67 +    ctxt.cr2    = (unsigned long)res;
    1.68 +    rc = x86_emulate_memop(&ctxt, &emulops);
    1.69 +    if ( (rc != 0) || 
    1.70 +         (*res != 0x92345677) || 
    1.71 +         (regs.ecx != 0x92345677UL) ||
    1.72 +         (regs.eip != (unsigned long)&instr[2]) )
    1.73 +        goto fail;
    1.74 +    printf("okay\n");
    1.75 +
    1.76      printf("%-40s", "Testing lock cmpxchgb %%cl,(%%eax)...");
    1.77      instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb0; instr[3] = 0x08;
    1.78      regs.eflags = 0x200;
    1.79      regs.eip    = (unsigned long)&instr[0];
    1.80      regs.eax    = 0x92345677UL;
    1.81      regs.ecx    = 0xAA;
    1.82 -    ctxt.cr2    = (unsigned long)&res;
    1.83 +    ctxt.cr2    = (unsigned long)res;
    1.84      rc = x86_emulate_memop(&ctxt, &emulops);
    1.85      if ( (rc != 0) || 
    1.86 -         (res != 0x923456AA) || 
    1.87 +         (*res != 0x923456AA) || 
    1.88           (regs.eflags != 0x244) ||
    1.89           (regs.eax != 0x92345677UL) ||
    1.90           (regs.eip != (unsigned long)&instr[4]) )
    1.91 @@ -147,10 +169,10 @@ int main(int argc, char **argv)
    1.92      regs.eip    = (unsigned long)&instr[0];
    1.93      regs.eax    = 0xAABBCC77UL;
    1.94      regs.ecx    = 0xFF;
    1.95 -    ctxt.cr2    = (unsigned long)&res;
    1.96 +    ctxt.cr2    = (unsigned long)res;
    1.97      rc = x86_emulate_memop(&ctxt, &emulops);
    1.98      if ( (rc != 0) || 
    1.99 -         (res != 0x923456AA) || 
   1.100 +         (*res != 0x923456AA) || 
   1.101           ((regs.eflags&0x240) != 0x200) ||
   1.102           (regs.eax != 0xAABBCCAA) ||
   1.103           (regs.ecx != 0xFF) ||
   1.104 @@ -163,10 +185,10 @@ int main(int argc, char **argv)
   1.105      regs.eflags = 0x200;
   1.106      regs.eip    = (unsigned long)&instr[0];
   1.107      regs.ecx    = 0x12345678;
   1.108 -    ctxt.cr2    = (unsigned long)&res;
   1.109 +    ctxt.cr2    = (unsigned long)res;
   1.110      rc = x86_emulate_memop(&ctxt, &emulops);
   1.111      if ( (rc != 0) || 
   1.112 -         (res != 0x12345678) || 
   1.113 +         (*res != 0x12345678) || 
   1.114           (regs.eflags != 0x200) ||
   1.115           (regs.ecx != 0x923456AA) ||
   1.116           (regs.eip != (unsigned long)&instr[2]) )
   1.117 @@ -176,14 +198,14 @@ int main(int argc, char **argv)
   1.118      printf("%-40s", "Testing lock cmpxchgl %%ecx,(%%eax)...");
   1.119      instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb1; instr[3] = 0x08;
   1.120      regs.eflags = 0x200;
   1.121 -    res         = 0x923456AA;
   1.122 +    *res        = 0x923456AA;
   1.123      regs.eip    = (unsigned long)&instr[0];
   1.124      regs.eax    = 0x923456AAUL;
   1.125      regs.ecx    = 0xDDEEFF00L;
   1.126 -    ctxt.cr2    = (unsigned long)&res;
   1.127 +    ctxt.cr2    = (unsigned long)res;
   1.128      rc = x86_emulate_memop(&ctxt, &emulops);
   1.129      if ( (rc != 0) || 
   1.130 -         (res != 0xDDEEFF00) || 
   1.131 +         (*res != 0xDDEEFF00) || 
   1.132           (regs.eflags != 0x244) ||
   1.133           (regs.eax != 0x923456AAUL) ||
   1.134           (regs.eip != (unsigned long)&instr[4]) )
   1.135 @@ -192,54 +214,57 @@ int main(int argc, char **argv)
   1.136  
   1.137      printf("%-40s", "Testing rep movsw...");
   1.138      instr[0] = 0xf3; instr[1] = 0x66; instr[2] = 0xa5;
   1.139 -    res         = 0x22334455;
   1.140 +    *res        = 0x22334455;
   1.141      regs.eflags = 0x200;
   1.142      regs.ecx    = 23;
   1.143      regs.eip    = (unsigned long)&instr[0];
   1.144 -    regs.esi    = (unsigned long)&res + 0;
   1.145 -    regs.edi    = (unsigned long)&res + 2;
   1.146 +    regs.esi    = (unsigned long)res + 0;
   1.147 +    regs.edi    = (unsigned long)res + 2;
   1.148      regs.error_code = 0; /* read fault */
   1.149      ctxt.cr2    = regs.esi;
   1.150      rc = x86_emulate_memop(&ctxt, &emulops);
   1.151      if ( (rc != 0) || 
   1.152 -         (res != 0x44554455) ||
   1.153 +         (*res != 0x44554455) ||
   1.154           (regs.eflags != 0x200) ||
   1.155           (regs.ecx != 22) || 
   1.156 -         (regs.esi != ((unsigned long)&res + 2)) ||
   1.157 -         (regs.edi != ((unsigned long)&res + 4)) ||
   1.158 +         (regs.esi != ((unsigned long)res + 2)) ||
   1.159 +         (regs.edi != ((unsigned long)res + 4)) ||
   1.160           (regs.eip != (unsigned long)&instr[0]) )
   1.161          goto fail;
   1.162      printf("okay\n");
   1.163  
   1.164      printf("%-40s", "Testing btrl $0x1,(%edi)...");
   1.165      instr[0] = 0x0f; instr[1] = 0xba; instr[2] = 0x37; instr[3] = 0x01;
   1.166 -    res         = 0x2233445F;
   1.167 +    *res        = 0x2233445F;
   1.168      regs.eflags = 0x200;
   1.169      regs.eip    = (unsigned long)&instr[0];
   1.170 -    regs.edi    = (unsigned long)&res;
   1.171 +    regs.edi    = (unsigned long)res;
   1.172      ctxt.cr2    = regs.edi;
   1.173      rc = x86_emulate_memop(&ctxt, &emulops);
   1.174      if ( (rc != 0) || 
   1.175 -         (res != 0x2233445D) ||
   1.176 +         (*res != 0x2233445D) ||
   1.177           ((regs.eflags&0x201) != 0x201) ||
   1.178           (regs.eip != (unsigned long)&instr[4]) )
   1.179          goto fail;
   1.180      printf("okay\n");
   1.181  
   1.182 +    res[0] = 0x12345678;
   1.183 +    res[1] = 0x87654321;
   1.184 +
   1.185      printf("%-40s", "Testing cmpxchg8b (%edi) [succeeding]...");
   1.186      instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
   1.187      regs.eflags = 0x200;
   1.188 -    regs.eax    = cmpxchg8b_res[0];
   1.189 -    regs.edx    = cmpxchg8b_res[1];
   1.190 +    regs.eax    = res[0];
   1.191 +    regs.edx    = res[1];
   1.192      regs.ebx    = 0x9999AAAA;
   1.193      regs.ecx    = 0xCCCCFFFF;
   1.194      regs.eip    = (unsigned long)&instr[0];
   1.195 -    regs.edi    = (unsigned long)cmpxchg8b_res;
   1.196 +    regs.edi    = (unsigned long)res;
   1.197      ctxt.cr2    = regs.edi;
   1.198      rc = x86_emulate_memop(&ctxt, &emulops);
   1.199      if ( (rc != 0) || 
   1.200 -         (cmpxchg8b_res[0] != 0x9999AAAA) ||
   1.201 -         (cmpxchg8b_res[1] != 0xCCCCFFFF) ||
   1.202 +         (res[0] != 0x9999AAAA) ||
   1.203 +         (res[1] != 0xCCCCFFFF) ||
   1.204           ((regs.eflags&0x240) != 0x240) ||
   1.205           (regs.eip != (unsigned long)&instr[3]) )
   1.206          goto fail;
   1.207 @@ -248,12 +273,12 @@ int main(int argc, char **argv)
   1.208      printf("%-40s", "Testing cmpxchg8b (%edi) [failing]...");
   1.209      instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
   1.210      regs.eip    = (unsigned long)&instr[0];
   1.211 -    regs.edi    = (unsigned long)cmpxchg8b_res;
   1.212 +    regs.edi    = (unsigned long)res;
   1.213      ctxt.cr2    = regs.edi;
   1.214      rc = x86_emulate_memop(&ctxt, &emulops);
   1.215      if ( (rc != 0) || 
   1.216 -         (cmpxchg8b_res[0] != 0x9999AAAA) ||
   1.217 -         (cmpxchg8b_res[1] != 0xCCCCFFFF) ||
   1.218 +         (res[0] != 0x9999AAAA) ||
   1.219 +         (res[1] != 0xCCCCFFFF) ||
   1.220           (regs.eax != 0x9999AAAA) ||
   1.221           (regs.edx != 0xCCCCFFFF) ||
   1.222           ((regs.eflags&0x240) != 0x200) ||
   1.223 @@ -265,11 +290,11 @@ int main(int argc, char **argv)
   1.224      instr[0] = 0x0f; instr[1] = 0xbe; instr[2] = 0x08;
   1.225      regs.eip    = (unsigned long)&instr[0];
   1.226      regs.ecx    = 0x12345678;
   1.227 -    ctxt.cr2    = (unsigned long)&res;
   1.228 -    res         = 0x82;
   1.229 +    ctxt.cr2    = (unsigned long)res;
   1.230 +    *res        = 0x82;
   1.231      rc = x86_emulate_memop(&ctxt, &emulops);
   1.232      if ( (rc != 0) ||
   1.233 -         (res != 0x82) ||
   1.234 +         (*res != 0x82) ||
   1.235           (regs.ecx != 0xFFFFFF82) ||
   1.236           ((regs.eflags&0x240) != 0x200) ||
   1.237           (regs.eip != (unsigned long)&instr[3]) )
   1.238 @@ -280,11 +305,11 @@ int main(int argc, char **argv)
   1.239      instr[0] = 0x0f; instr[1] = 0xb7; instr[2] = 0x08;
   1.240      regs.eip    = (unsigned long)&instr[0];
   1.241      regs.ecx    = 0x12345678;
   1.242 -    ctxt.cr2    = (unsigned long)&res;
   1.243 -    res         = 0x1234aa82;
   1.244 +    ctxt.cr2    = (unsigned long)res;
   1.245 +    *res        = 0x1234aa82;
   1.246      rc = x86_emulate_memop(&ctxt, &emulops);
   1.247      if ( (rc != 0) ||
   1.248 -         (res != 0x1234aa82) ||
   1.249 +         (*res != 0x1234aa82) ||
   1.250           (regs.ecx != 0xaa82) ||
   1.251           ((regs.eflags&0x240) != 0x200) ||
   1.252           (regs.eip != (unsigned long)&instr[3]) )
     2.1 --- a/xen/arch/x86/x86_emulate.c	Mon Jun 05 17:17:27 2006 +0100
     2.2 +++ b/xen/arch/x86/x86_emulate.c	Tue Jun 06 08:05:13 2006 +0100
     2.3 @@ -100,8 +100,8 @@ static uint8_t opcode_table[256] = {
     2.4      ByteOp|DstMem|SrcReg|ModRM, DstMem|SrcReg|ModRM,
     2.5      ByteOp|DstMem|SrcReg|ModRM, DstMem|SrcReg|ModRM,
     2.6      /* 0x88 - 0x8F */
     2.7 -    ByteOp|DstMem|SrcReg|ModRM, DstMem|SrcReg|ModRM,
     2.8 -    ByteOp|DstReg|SrcMem|ModRM, DstReg|SrcMem|ModRM,
     2.9 +    ByteOp|DstMem|SrcReg|ModRM|Mov, DstMem|SrcReg|ModRM|Mov,
    2.10 +    ByteOp|DstReg|SrcMem|ModRM|Mov, DstReg|SrcMem|ModRM|Mov,
    2.11      0, 0, 0, DstMem|SrcNone|ModRM|Mov,
    2.12      /* 0x90 - 0x9F */
    2.13      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,