direct-io.hg

changeset 10241:2dd8e7c44728

Fix negation of unsigned quantities in the Xen x86 emulator.
This fixes the problems left behind by c/s 10171. Again pointed
out by Jan Beulich; and again different from his suggested patch.
Hopefully this one will be less embarrassing.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@dhcp93.uk.xensource.com
date Thu Jun 01 16:31:37 2006 +0100 (2006-06-01)
parents 4142bfd01e02
children ab627e9da8fb
files xen/arch/x86/traps.c xen/arch/x86/x86_emulate.c
line diff
     1.1 --- a/xen/arch/x86/traps.c	Thu Jun 01 11:25:02 2006 +0100
     1.2 +++ b/xen/arch/x86/traps.c	Thu Jun 01 16:31:37 2006 +0100
     1.3 @@ -876,7 +876,7 @@ static int emulate_privileged_op(struct 
     1.4                      PAGE_FAULT(regs->edi, USER_WRITE_FAULT);
     1.5                  break;
     1.6              }
     1.7 -            regs->edi += (regs->eflags & EF_DF) ? -(int)op_bytes : op_bytes;
     1.8 +            regs->edi += (int)((regs->eflags & EF_DF) ? -op_bytes : op_bytes);
     1.9              break;
    1.10  
    1.11          case 0x6e: /* OUTSB */
    1.12 @@ -902,7 +902,7 @@ static int emulate_privileged_op(struct 
    1.13                  outl_user((u32)data, (u16)regs->edx, v, regs);
    1.14                  break;
    1.15              }
    1.16 -            regs->esi += (regs->eflags & EF_DF) ? -(int)op_bytes : op_bytes;
    1.17 +            regs->esi += (int)((regs->eflags & EF_DF) ? -op_bytes : op_bytes);
    1.18              break;
    1.19          }
    1.20  
     2.1 --- a/xen/arch/x86/x86_emulate.c	Thu Jun 01 11:25:02 2006 +0100
     2.2 +++ b/xen/arch/x86/x86_emulate.c	Thu Jun 01 16:31:37 2006 +0100
     2.3 @@ -380,11 +380,12 @@ do{ __asm__ __volatile__ (              
     2.4        ((reg) & ((1UL << (ad_bytes << 3)) - 1))))
     2.5  #define register_address_increment(reg, inc)                            \
     2.6  do {                                                                    \
     2.7 +    int _inc = (inc); /* signed type ensures sign extension to long */  \
     2.8      if ( ad_bytes == sizeof(unsigned long) )                            \
     2.9 -        (reg) += (inc);                                                 \
    2.10 +        (reg) += _inc;                                                  \
    2.11      else                                                                \
    2.12          (reg) = ((reg) & ~((1UL << (ad_bytes << 3)) - 1)) |             \
    2.13 -                (((reg) + (inc)) & ((1UL << (ad_bytes << 3)) - 1));     \
    2.14 +                (((reg) + _inc) & ((1UL << (ad_bytes << 3)) - 1));      \
    2.15  } while (0)
    2.16  
    2.17  void *
    2.18 @@ -858,7 +859,7 @@ x86_emulate_memop(
    2.19                                           &dst.val, 8, ctxt)) != 0 )
    2.20                      goto done;
    2.21              }
    2.22 -            register_address_increment(_regs.esp, -(int)dst.bytes);
    2.23 +            register_address_increment(_regs.esp, -dst.bytes);
    2.24              if ( (rc = ops->write_std(register_address(_regs.ss, _regs.esp),
    2.25                                        dst.val, dst.bytes, ctxt)) != 0 )
    2.26                  goto done;
    2.27 @@ -942,9 +943,9 @@ x86_emulate_memop(
    2.28                  goto done;
    2.29          }
    2.30          register_address_increment(
    2.31 -            _regs.esi, (_regs.eflags & EFLG_DF) ? -(int)dst.bytes : dst.bytes);
    2.32 +            _regs.esi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
    2.33          register_address_increment(
    2.34 -            _regs.edi, (_regs.eflags & EFLG_DF) ? -(int)dst.bytes : dst.bytes);
    2.35 +            _regs.edi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
    2.36          break;
    2.37      case 0xa6 ... 0xa7: /* cmps */
    2.38          DPRINTF("Urk! I don't handle CMPS.\n");
    2.39 @@ -955,7 +956,7 @@ x86_emulate_memop(
    2.40          dst.ptr   = (unsigned long *)cr2;
    2.41          dst.val   = _regs.eax;
    2.42          register_address_increment(
    2.43 -            _regs.edi, (_regs.eflags & EFLG_DF) ? -(int)dst.bytes : dst.bytes);
    2.44 +            _regs.edi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
    2.45          break;
    2.46      case 0xac ... 0xad: /* lods */
    2.47          dst.type  = OP_REG;
    2.48 @@ -964,7 +965,7 @@ x86_emulate_memop(
    2.49          if ( (rc = ops->read_emulated(cr2, &dst.val, dst.bytes, ctxt)) != 0 )
    2.50              goto done;
    2.51          register_address_increment(
    2.52 -            _regs.esi, (_regs.eflags & EFLG_DF) ? -(int)dst.bytes : dst.bytes);
    2.53 +            _regs.esi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
    2.54          break;
    2.55      case 0xae ... 0xaf: /* scas */
    2.56          DPRINTF("Urk! I don't handle SCAS.\n");