ia64/xen-unstable

changeset 12645:a98bec6aacac

[XEN] Emulator fixes.

1. Fix RIP-relative EA calculation. Immediate operands are never 64-bit.
2. Displacements are sign-extended so used signed types.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Nov 29 10:48:06 2006 +0000 (2006-11-29)
parents 81c9213b3d39
children ec2af46f9472
files xen/arch/x86/x86_emulate.c
line diff
     1.1 --- a/xen/arch/x86/x86_emulate.c	Tue Nov 28 18:41:42 2006 +0000
     1.2 +++ b/xen/arch/x86/x86_emulate.c	Wed Nov 29 10:48:06 2006 +0000
     1.3 @@ -615,9 +615,9 @@ x86_emulate_memop(
     1.4              }
     1.5              switch ( modrm_mod )
     1.6              {
     1.7 -            case 0: if ( modrm_rm == 6 ) ea = insn_fetch(uint16_t); break;
     1.8 -            case 1: ea += insn_fetch(uint8_t);  break;
     1.9 -            case 2: ea += insn_fetch(uint16_t); break;
    1.10 +            case 0: if ( modrm_rm == 6 ) ea = insn_fetch(int16_t); break;
    1.11 +            case 1: ea += insn_fetch(int8_t);  break;
    1.12 +            case 2: ea += insn_fetch(int16_t); break;
    1.13              }
    1.14          }
    1.15          else
    1.16 @@ -632,7 +632,7 @@ x86_emulate_memop(
    1.17                      ea = *(long *)decode_register(sib_index, &_regs, 0);
    1.18                  ea <<= (sib >> 6) & 3;
    1.19                  if ( (modrm_mod == 0) && ((sib_base & 7) == 5) )
    1.20 -                    ea += insn_fetch(uint32_t);
    1.21 +                    ea += insn_fetch(int32_t);
    1.22                  else
    1.23                      ea += *(long *)decode_register(sib_base, &_regs, 0);
    1.24              }
    1.25 @@ -646,13 +646,13 @@ x86_emulate_memop(
    1.26              case 0:
    1.27                  if ( (modrm_rm & 7) != 5 )
    1.28                      break;
    1.29 -                ea = insn_fetch(uint32_t);
    1.30 +                ea = insn_fetch(int32_t);
    1.31                  if ( mode != X86EMUL_MODE_PROT64 )
    1.32                      break;
    1.33                  /* Relative to RIP of next instruction. Argh! */
    1.34                  ea += _regs.eip;
    1.35                  if ( (d & SrcMask) == SrcImm )
    1.36 -                    ea += (d & ByteOp) ? 1 : op_bytes;
    1.37 +                    ea += (d & ByteOp) ? 1 : ((op_bytes == 8) ? 4 : op_bytes);
    1.38                  else if ( (d & SrcMask) == SrcImmByte )
    1.39                      ea += 1;
    1.40                  else if ( ((b == 0xf6) || (b == 0xf7)) &&
    1.41 @@ -661,8 +661,8 @@ x86_emulate_memop(
    1.42                      ea += (d & ByteOp) ? 1
    1.43                          : ((op_bytes == 8) ? 4 : op_bytes);
    1.44                  break;
    1.45 -            case 1: ea += insn_fetch(uint8_t);  break;
    1.46 -            case 2: ea += insn_fetch(uint32_t); break;
    1.47 +            case 1: ea += insn_fetch(int8_t);  break;
    1.48 +            case 2: ea += insn_fetch(int32_t); break;
    1.49              }
    1.50          }
    1.51