direct-io.hg

changeset 8405:c259492dfb43

Add support for MOVSX/MOVSXD/MOVZX (move-with-extend)
instructions to the generic x86 emulator. Also add
preliminary support for 16-bit addressing: decode the
ModR/M byte properly but still need to access and update
implicit memory operands (esp,esi,edi) with correct width.
Work is also needed to support real-mode addressing.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Dec 21 14:29:23 2005 +0100 (2005-12-21)
parents 6e24488a89f7
children 4d729134a0a4 5a790011259e
files tools/tests/Makefile tools/tests/test_x86_emulator.c xen/arch/x86/x86_emulate.c xen/include/asm-x86/x86_emulate.h
line diff
     1.1 --- a/tools/tests/Makefile	Tue Dec 20 18:45:29 2005 +0100
     1.2 +++ b/tools/tests/Makefile	Wed Dec 21 14:29:23 2005 +0100
     1.3 @@ -7,6 +7,8 @@ TARGET := test_x86_emulator
     1.4  CC     := gcc
     1.5  CFLAGS := -O2 -Wall -Werror -D__TEST_HARNESS__
     1.6  
     1.7 +all: $(TARGET)
     1.8 +
     1.9  $(TARGET): x86_emulate.o test_x86_emulator.o
    1.10  	$(CC) -o $@ $^
    1.11  
     2.1 --- a/tools/tests/test_x86_emulator.c	Tue Dec 20 18:45:29 2005 +0100
     2.2 +++ b/tools/tests/test_x86_emulator.c	Wed Dec 21 14:29:23 2005 +0100
     2.3 @@ -254,6 +254,36 @@ int main(int argc, char **argv)
     2.4          goto fail;
     2.5      printf("okay\n");
     2.6  
     2.7 +    printf("%-40s", "Testing movsxbd (%%eax),%%ecx...");
     2.8 +    instr[0] = 0x0f; instr[1] = 0xbe; instr[2] = 0x08;
     2.9 +    regs.eip    = (unsigned long)&instr[0];
    2.10 +    regs.ecx    = 0x12345678;
    2.11 +    cr2         = (unsigned long)&res;
    2.12 +    res         = 0x82;
    2.13 +    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);
    2.14 +    if ( (rc != 0) ||
    2.15 +         (res != 0x82) ||
    2.16 +         (regs.ecx != 0xFFFFFF82) ||
    2.17 +         ((regs.eflags&0x240) != 0x200) ||
    2.18 +         (regs.eip != (unsigned long)&instr[3]) )
    2.19 +        goto fail;
    2.20 +    printf("okay\n");
    2.21 +
    2.22 +    printf("%-40s", "Testing movzxwd (%%eax),%%ecx...");
    2.23 +    instr[0] = 0x0f; instr[1] = 0xb7; instr[2] = 0x08;
    2.24 +    regs.eip    = (unsigned long)&instr[0];
    2.25 +    regs.ecx    = 0x12345678;
    2.26 +    cr2         = (unsigned long)&res;
    2.27 +    res         = 0x1234aa82;
    2.28 +    rc = x86_emulate_memop(&regs, cr2, &emulops, 4);
    2.29 +    if ( (rc != 0) ||
    2.30 +         (res != 0x1234aa82) ||
    2.31 +         (regs.ecx != 0xaa82) ||
    2.32 +         ((regs.eflags&0x240) != 0x200) ||
    2.33 +         (regs.eip != (unsigned long)&instr[3]) )
    2.34 +        goto fail;
    2.35 +    printf("okay\n");
    2.36 +
    2.37      return 0;
    2.38  
    2.39   fail:
     3.1 --- a/xen/arch/x86/x86_emulate.c	Tue Dec 20 18:45:29 2005 +0100
     3.2 +++ b/xen/arch/x86/x86_emulate.c	Wed Dec 21 14:29:23 2005 +0100
     3.3 @@ -9,14 +9,6 @@
     3.4  #ifdef __TEST_HARNESS__
     3.5  #include <stdio.h>
     3.6  #include <stdint.h>
     3.7 -typedef uint8_t            u8;
     3.8 -typedef uint16_t           u16;
     3.9 -typedef uint32_t           u32;
    3.10 -typedef uint64_t           u64;
    3.11 -typedef int8_t             s8;
    3.12 -typedef int16_t            s16;
    3.13 -typedef int32_t            s32;
    3.14 -typedef int64_t            s64;
    3.15  #include <public/xen.h>
    3.16  #define DPRINTF(_f, _a...) printf( _f , ## _a )
    3.17  #else
    3.18 @@ -50,15 +42,17 @@ typedef int64_t            s64;
    3.19  #define SrcImplicit (0<<3) /* Source operand is implicit in the opcode. */
    3.20  #define SrcReg      (1<<3) /* Register operand. */
    3.21  #define SrcMem      (2<<3) /* Memory operand. */
    3.22 -#define SrcImm      (3<<3) /* Immediate operand. */
    3.23 -#define SrcImmByte  (4<<3) /* 8-bit sign-extended immediate operand. */
    3.24 +#define SrcMem16    (3<<3) /* Memory operand (16-bit). */
    3.25 +#define SrcMem32    (4<<3) /* Memory operand (32-bit). */
    3.26 +#define SrcImm      (5<<3) /* Immediate operand. */
    3.27 +#define SrcImmByte  (6<<3) /* 8-bit sign-extended immediate operand. */
    3.28  #define SrcMask     (7<<3)
    3.29  /* Generic ModRM decode. */
    3.30  #define ModRM       (1<<6)
    3.31  /* Destination is only written; never read. */
    3.32  #define Mov         (1<<7)
    3.33  
    3.34 -static u8 opcode_table[256] = {
    3.35 +static uint8_t opcode_table[256] = {
    3.36      /* 0x00 - 0x07 */
    3.37      ByteOp|DstMem|SrcReg|ModRM, DstMem|SrcReg|ModRM,
    3.38      ByteOp|DstReg|SrcMem|ModRM, DstReg|SrcMem|ModRM,
    3.39 @@ -96,7 +90,8 @@ static u8 opcode_table[256] = {
    3.40      /* 0x50 - 0x5F */
    3.41      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    3.42      /* 0x60 - 0x6F */
    3.43 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    3.44 +    0, 0, 0, DstReg|SrcMem32|ModRM|Mov /* movsxd (x86/64) */,
    3.45 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    3.46      /* 0x70 - 0x7F */
    3.47      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    3.48      /* 0x80 - 0x87 */
    3.49 @@ -142,7 +137,7 @@ static u8 opcode_table[256] = {
    3.50      0, 0, ByteOp|DstMem|SrcNone|ModRM, DstMem|SrcNone|ModRM
    3.51  };
    3.52  
    3.53 -static u8 twobyte_table[256] = {
    3.54 +static uint8_t twobyte_table[256] = {
    3.55      /* 0x00 - 0x0F */
    3.56      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ImplicitOps|ModRM, 0, 0,
    3.57      /* 0x10 - 0x1F */
    3.58 @@ -177,9 +172,10 @@ static u8 twobyte_table[256] = {
    3.59      0, 0, 0, DstMem|SrcReg|ModRM, 0, 0, 0, 0,
    3.60      /* 0xB0 - 0xB7 */
    3.61      ByteOp|DstMem|SrcReg|ModRM, DstMem|SrcReg|ModRM, 0, DstMem|SrcReg|ModRM,
    3.62 -    0, 0, 0, 0,
    3.63 +    0, 0, ByteOp|DstReg|SrcMem|ModRM|Mov, DstReg|SrcMem16|ModRM|Mov,
    3.64      /* 0xB8 - 0xBF */
    3.65 -    0, 0, DstMem|SrcImmByte|ModRM, DstMem|SrcReg|ModRM, 0, 0, 0, 0,
    3.66 +    0, 0, DstMem|SrcImmByte|ModRM, DstMem|SrcReg|ModRM,
    3.67 +    0, 0, ByteOp|DstReg|SrcMem|ModRM|Mov, DstReg|SrcMem16|ModRM|Mov,
    3.68      /* 0xC0 - 0xCF */
    3.69      0, 0, 0, 0, 0, 0, 0, ImplicitOps|ModRM, 0, 0, 0, 0, 0, 0, 0, 0,
    3.70      /* 0xD0 - 0xDF */
    3.71 @@ -377,7 +373,7 @@ do{ __asm__ __volatile__ (              
    3.72  
    3.73  void *
    3.74  decode_register(
    3.75 -    u8 modrm_reg, struct cpu_user_regs *regs, int highbyte_regs)
    3.76 +    uint8_t modrm_reg, struct cpu_user_regs *regs, int highbyte_regs)
    3.77  {
    3.78      void *p;
    3.79  
    3.80 @@ -422,8 +418,8 @@ x86_emulate_memop(
    3.81      struct x86_mem_emulator *ops,
    3.82      int mode)
    3.83  {
    3.84 -    u8 b, d, sib, twobyte = 0, rex_prefix = 0;
    3.85 -    u8 modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
    3.86 +    uint8_t b, d, sib, twobyte = 0, rex_prefix = 0;
    3.87 +    uint8_t modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
    3.88      unsigned int op_bytes = (mode == 8) ? 4 : mode, ad_bytes = mode;
    3.89      unsigned int lock_prefix = 0, rep_prefix = 0, i;
    3.90      int rc = 0;
    3.91 @@ -435,7 +431,7 @@ x86_emulate_memop(
    3.92      /* Legacy prefixes. */
    3.93      for ( i = 0; i < 8; i++ )
    3.94      {
    3.95 -        switch ( b = insn_fetch(u8, 1, _regs.eip) )
    3.96 +        switch ( b = insn_fetch(uint8_t, 1, _regs.eip) )
    3.97          {
    3.98          case 0x66: /* operand-size override */
    3.99              op_bytes ^= 6;                    /* switch between 2/4 bytes */
   3.100 @@ -465,12 +461,6 @@ x86_emulate_memop(
   3.101      }
   3.102   done_prefixes:
   3.103  
   3.104 -    if ( ad_bytes == 2 )
   3.105 -    {
   3.106 -        DPRINTF("Cannot parse 16-bit effective addresses.\n");
   3.107 -        goto cannot_emulate;
   3.108 -    }
   3.109 -
   3.110      /* REX prefix. */
   3.111      if ( (mode == 8) && ((b & 0xf0) == 0x40) )
   3.112      {
   3.113 @@ -479,7 +469,7 @@ x86_emulate_memop(
   3.114              op_bytes = 8;          /* REX.W */
   3.115          modrm_reg = (b & 4) << 1;  /* REX.R */
   3.116          /* REX.B and REX.X do not need to be decoded. */
   3.117 -        b = insn_fetch(u8, 1, _regs.eip);
   3.118 +        b = insn_fetch(uint8_t, 1, _regs.eip);
   3.119      }
   3.120  
   3.121      /* Opcode byte(s). */
   3.122 @@ -490,7 +480,7 @@ x86_emulate_memop(
   3.123          if ( b == 0x0f )
   3.124          {
   3.125              twobyte = 1;
   3.126 -            b = insn_fetch(u8, 1, _regs.eip);
   3.127 +            b = insn_fetch(uint8_t, 1, _regs.eip);
   3.128              d = twobyte_table[b];
   3.129          }
   3.130  
   3.131 @@ -502,33 +492,58 @@ x86_emulate_memop(
   3.132      /* ModRM and SIB bytes. */
   3.133      if ( d & ModRM )
   3.134      {
   3.135 -        modrm = insn_fetch(u8, 1, _regs.eip);
   3.136 +        modrm = insn_fetch(uint8_t, 1, _regs.eip);
   3.137          modrm_mod |= (modrm & 0xc0) >> 6;
   3.138          modrm_reg |= (modrm & 0x38) >> 3;
   3.139          modrm_rm  |= (modrm & 0x07);
   3.140 -        switch ( modrm_mod )
   3.141 +
   3.142 +        if ( modrm_mod == 3 )
   3.143          {
   3.144 -        case 0:
   3.145 -            if ( (modrm_rm == 4) && 
   3.146 -                 (((sib = insn_fetch(u8, 1, _regs.eip)) & 7) == 5) )
   3.147 -                _regs.eip += 4; /* skip disp32 specified by SIB.base */
   3.148 -            else if ( modrm_rm == 5 )
   3.149 -                _regs.eip += 4; /* skip disp32 */
   3.150 -            break;
   3.151 -        case 1:
   3.152 -            if ( modrm_rm == 4 )
   3.153 -                sib = insn_fetch(u8, 1, _regs.eip);
   3.154 -            _regs.eip += 1; /* skip disp8 */
   3.155 -            break;
   3.156 -        case 2:
   3.157 -            if ( modrm_rm == 4 )
   3.158 -                sib = insn_fetch(u8, 1, _regs.eip);
   3.159 -            _regs.eip += 4; /* skip disp32 */
   3.160 -            break;
   3.161 -        case 3:
   3.162              DPRINTF("Cannot parse ModRM.mod == 3.\n");
   3.163              goto cannot_emulate;
   3.164          }
   3.165 +
   3.166 +        if ( ad_bytes == 2 )
   3.167 +        {
   3.168 +            /* 16-bit ModR/M decode. */
   3.169 +            switch ( modrm_mod )
   3.170 +            {
   3.171 +            case 0:
   3.172 +                if ( modrm_rm == 6 )
   3.173 +                    _regs.eip += 2; /* skip disp16 */
   3.174 +                break;
   3.175 +            case 1:
   3.176 +                _regs.eip += 1; /* skip disp8 */
   3.177 +                break;
   3.178 +            case 2:
   3.179 +                _regs.eip += 2; /* skip disp16 */
   3.180 +                break;
   3.181 +            }
   3.182 +        }
   3.183 +        else
   3.184 +        {
   3.185 +            /* 32/64-bit ModR/M decode. */
   3.186 +            switch ( modrm_mod )
   3.187 +            {
   3.188 +            case 0:
   3.189 +                if ( (modrm_rm == 4) && 
   3.190 +                     (((sib = insn_fetch(uint8_t, 1, _regs.eip)) & 7) == 5) )
   3.191 +                    _regs.eip += 4; /* skip disp32 specified by SIB.base */
   3.192 +                else if ( modrm_rm == 5 )
   3.193 +                    _regs.eip += 4; /* skip disp32 */
   3.194 +                break;
   3.195 +            case 1:
   3.196 +                if ( modrm_rm == 4 )
   3.197 +                    sib = insn_fetch(uint8_t, 1, _regs.eip);
   3.198 +                _regs.eip += 1; /* skip disp8 */
   3.199 +                break;
   3.200 +            case 2:
   3.201 +                if ( modrm_rm == 4 )
   3.202 +                    sib = insn_fetch(uint8_t, 1, _regs.eip);
   3.203 +                _regs.eip += 4; /* skip disp32 */
   3.204 +                break;
   3.205 +            }
   3.206 +        }
   3.207      }
   3.208  
   3.209      /* Decode and fetch the destination operand: register or memory. */
   3.210 @@ -542,7 +557,7 @@ x86_emulate_memop(
   3.211          if ( d & ByteOp )
   3.212          {
   3.213              dst.ptr = decode_register(modrm_reg, &_regs, (rex_prefix == 0));
   3.214 -            dst.val = *(u8 *)dst.ptr;
   3.215 +            dst.val = *(uint8_t *)dst.ptr;
   3.216              dst.bytes = 1;
   3.217          }
   3.218          else
   3.219 @@ -550,9 +565,9 @@ x86_emulate_memop(
   3.220              dst.ptr = decode_register(modrm_reg, &_regs, 0);
   3.221              switch ( (dst.bytes = op_bytes) )
   3.222              {
   3.223 -            case 2: dst.val = *(u16 *)dst.ptr; break;
   3.224 -            case 4: dst.val = *(u32 *)dst.ptr; break;
   3.225 -            case 8: dst.val = *(u64 *)dst.ptr; break;
   3.226 +            case 2: dst.val = *(uint16_t *)dst.ptr; break;
   3.227 +            case 4: dst.val = *(uint32_t *)dst.ptr; break;
   3.228 +            case 8: dst.val = *(uint64_t *)dst.ptr; break;
   3.229              }
   3.230          }
   3.231          break;
   3.232 @@ -578,7 +593,7 @@ x86_emulate_memop(
   3.233          if ( d & ByteOp )
   3.234          {
   3.235              src.ptr = decode_register(modrm_reg, &_regs, (rex_prefix == 0));
   3.236 -            src.val = src.orig_val = *(u8 *)src.ptr;
   3.237 +            src.val = src.orig_val = *(uint8_t *)src.ptr;
   3.238              src.bytes = 1;
   3.239          }
   3.240          else
   3.241 @@ -586,16 +601,23 @@ x86_emulate_memop(
   3.242              src.ptr = decode_register(modrm_reg, &_regs, 0);
   3.243              switch ( (src.bytes = op_bytes) )
   3.244              {
   3.245 -            case 2: src.val = src.orig_val = *(u16 *)src.ptr; break;
   3.246 -            case 4: src.val = src.orig_val = *(u32 *)src.ptr; break;
   3.247 -            case 8: src.val = src.orig_val = *(u64 *)src.ptr; break;
   3.248 +            case 2: src.val = src.orig_val = *(uint16_t *)src.ptr; break;
   3.249 +            case 4: src.val = src.orig_val = *(uint32_t *)src.ptr; break;
   3.250 +            case 8: src.val = src.orig_val = *(uint64_t *)src.ptr; break;
   3.251              }
   3.252          }
   3.253          break;
   3.254 +    case SrcMem16:
   3.255 +        src.bytes = 2;
   3.256 +        goto srcmem_common;
   3.257 +    case SrcMem32:
   3.258 +        src.bytes = 4;
   3.259 +        goto srcmem_common;
   3.260      case SrcMem:
   3.261 +        src.bytes = (d & ByteOp) ? 1 : op_bytes;
   3.262 +    srcmem_common:
   3.263          src.type  = OP_MEM;
   3.264          src.ptr   = (unsigned long *)cr2;
   3.265 -        src.bytes = (d & ByteOp) ? 1 : op_bytes;
   3.266          if ( (rc = ops->read_emulated((unsigned long)src.ptr, 
   3.267                                        &src.val, src.bytes)) != 0 )
   3.268              goto done;
   3.269 @@ -609,16 +631,16 @@ x86_emulate_memop(
   3.270          /* NB. Immediates are sign-extended as necessary. */
   3.271          switch ( src.bytes )
   3.272          {
   3.273 -        case 1: src.val = insn_fetch(s8,  1, _regs.eip); break;
   3.274 -        case 2: src.val = insn_fetch(s16, 2, _regs.eip); break;
   3.275 -        case 4: src.val = insn_fetch(s32, 4, _regs.eip); break;
   3.276 +        case 1: src.val = insn_fetch(int8_t,  1, _regs.eip); break;
   3.277 +        case 2: src.val = insn_fetch(int16_t, 2, _regs.eip); break;
   3.278 +        case 4: src.val = insn_fetch(int32_t, 4, _regs.eip); break;
   3.279          }
   3.280          break;
   3.281      case SrcImmByte:
   3.282          src.type  = OP_IMM;
   3.283          src.ptr   = (unsigned long *)_regs.eip;
   3.284          src.bytes = 1;
   3.285 -        src.val   = insn_fetch(s8,  1, _regs.eip);
   3.286 +        src.val   = insn_fetch(int8_t,  1, _regs.eip);
   3.287          break;
   3.288      }
   3.289  
   3.290 @@ -651,6 +673,11 @@ x86_emulate_memop(
   3.291      case 0x38 ... 0x3d: cmp: /* cmp */
   3.292          emulate_2op_SrcV("cmp", src, dst, _regs.eflags);
   3.293          break;
   3.294 +    case 0x63: /* movsxd */
   3.295 +        if ( mode != 8 ) /* x86/64 long mode only */
   3.296 +            goto cannot_emulate;
   3.297 +        dst.val = (int32_t)src.val;
   3.298 +        break;
   3.299      case 0x80 ... 0x83: /* Grp1 */
   3.300          switch ( modrm_reg )
   3.301          {
   3.302 @@ -671,9 +698,9 @@ x86_emulate_memop(
   3.303          /* Write back the register source. */
   3.304          switch ( dst.bytes )
   3.305          {
   3.306 -        case 1: *(u8  *)src.ptr = (u8)dst.val; break;
   3.307 -        case 2: *(u16 *)src.ptr = (u16)dst.val; break;
   3.308 -        case 4: *src.ptr = (u32)dst.val; break; /* 64b mode: zero-extend */
   3.309 +        case 1: *(uint8_t  *)src.ptr = (uint8_t)dst.val; break;
   3.310 +        case 2: *(uint16_t *)src.ptr = (uint16_t)dst.val; break;
   3.311 +        case 4: *src.ptr = (uint32_t)dst.val; break; /* 64b reg: zero-extend */
   3.312          case 8: *src.ptr = dst.val; break;
   3.313          }
   3.314          /* Write back the memory destination with implicit LOCK prefix. */
   3.315 @@ -745,9 +772,9 @@ x86_emulate_memop(
   3.316              if ( src.bytes == 8 ) src.bytes = 4;
   3.317              switch ( src.bytes )
   3.318              {
   3.319 -            case 1: src.val = insn_fetch(s8,  1, _regs.eip); break;
   3.320 -            case 2: src.val = insn_fetch(s16, 2, _regs.eip); break;
   3.321 -            case 4: src.val = insn_fetch(s32, 4, _regs.eip); break;
   3.322 +            case 1: src.val = insn_fetch(int8_t,  1, _regs.eip); break;
   3.323 +            case 2: src.val = insn_fetch(int16_t, 2, _regs.eip); break;
   3.324 +            case 4: src.val = insn_fetch(int32_t, 4, _regs.eip); break;
   3.325              }
   3.326              goto test;
   3.327          case 2: /* not */
   3.328 @@ -798,9 +825,9 @@ x86_emulate_memop(
   3.329              /* The 4-byte case *is* correct: in 64-bit mode we zero-extend. */
   3.330              switch ( dst.bytes )
   3.331              {
   3.332 -            case 1: *(u8  *)dst.ptr = (u8)dst.val; break;
   3.333 -            case 2: *(u16 *)dst.ptr = (u16)dst.val; break;
   3.334 -            case 4: *dst.ptr = (u32)dst.val; break; /* 64b mode: zero-extend */
   3.335 +            case 1: *(uint8_t  *)dst.ptr = (uint8_t)dst.val; break;
   3.336 +            case 2: *(uint16_t *)dst.ptr = (uint16_t)dst.val; break;
   3.337 +            case 4: *dst.ptr = (uint32_t)dst.val; break; /* 64b: zero-ext */
   3.338              case 8: *dst.ptr = dst.val; break;
   3.339              }
   3.340              break;
   3.341 @@ -953,6 +980,10 @@ x86_emulate_memop(
   3.342          src.val &= (dst.bytes << 3) - 1; /* only subword offset */
   3.343          emulate_2op_SrcV_nobyte("bts", src, dst, _regs.eflags);
   3.344          break;
   3.345 +    case 0xb6 ... 0xb7: /* movzx */
   3.346 +        dst.bytes = op_bytes;
   3.347 +        dst.val = (d & ByteOp) ? (uint8_t)src.val : (uint16_t)src.val;
   3.348 +        break;
   3.349      case 0xbb: btc: /* btc */
   3.350          src.val &= (dst.bytes << 3) - 1; /* only subword offset */
   3.351          emulate_2op_SrcV_nobyte("btc", src, dst, _regs.eflags);
   3.352 @@ -966,6 +997,10 @@ x86_emulate_memop(
   3.353          case 3: goto btc;
   3.354          }
   3.355          break;
   3.356 +    case 0xbe ... 0xbf: /* movsx */
   3.357 +        dst.bytes = op_bytes;
   3.358 +        dst.val = (d & ByteOp) ? (int8_t)src.val : (int16_t)src.val;
   3.359 +        break;
   3.360      }
   3.361      goto writeback;
   3.362  
   3.363 @@ -1009,16 +1044,16 @@ x86_emulate_memop(
   3.364          unsigned long old, new;
   3.365          if ( (rc = ops->read_emulated(cr2, &old, 8)) != 0 )
   3.366              goto done;
   3.367 -        if ( ((u32)(old>>0) != (u32)_regs.eax) ||
   3.368 -             ((u32)(old>>32) != (u32)_regs.edx) )
   3.369 +        if ( ((uint32_t)(old>>0) != (uint32_t)_regs.eax) ||
   3.370 +             ((uint32_t)(old>>32) != (uint32_t)_regs.edx) )
   3.371          {
   3.372 -            _regs.eax = (u32)(old>>0);
   3.373 -            _regs.edx = (u32)(old>>32);
   3.374 +            _regs.eax = (uint32_t)(old>>0);
   3.375 +            _regs.edx = (uint32_t)(old>>32);
   3.376              _regs.eflags &= ~EFLG_ZF;
   3.377          }
   3.378          else
   3.379          {
   3.380 -            new = (_regs.ecx<<32)|(u32)_regs.ebx;
   3.381 +            new = (_regs.ecx<<32)|(uint32_t)_regs.ebx;
   3.382              if ( (rc = ops->cmpxchg_emulated(cr2, old, new, 8)) != 0 )
   3.383                  goto done;
   3.384              _regs.eflags |= EFLG_ZF;
     4.1 --- a/xen/include/asm-x86/x86_emulate.h	Tue Dec 20 18:45:29 2005 +0100
     4.2 +++ b/xen/include/asm-x86/x86_emulate.h	Wed Dec 21 14:29:23 2005 +0100
     4.3 @@ -164,6 +164,6 @@ x86_emulate_memop(
     4.4   */
     4.5  extern void *
     4.6  decode_register(
     4.7 -    u8 modrm_reg, struct cpu_user_regs *regs, int highbyte_regs);
     4.8 +    uint8_t modrm_reg, struct cpu_user_regs *regs, int highbyte_regs);
     4.9  
    4.10  #endif /* __X86_EMULATE_H__ */