# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxxxx
# Node ID 2dd8e7c4472897a86cac635b6982fa55f1ab6e07
# Parent 4142bfd01e0212afb8834b01a146ddfb609e6ac5
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@xxxxxxxxxxxxx>
---
xen/arch/x86/traps.c | 4 ++--
xen/arch/x86/x86_emulate.c | 15 ++++++++-------
2 files changed, 10 insertions(+), 9 deletions(-)
diff -r 4142bfd01e02 -r 2dd8e7c44728 xen/arch/x86/traps.c
--- a/xen/arch/x86/traps.c Thu Jun 01 11:25:02 2006 +0100
+++ b/xen/arch/x86/traps.c Thu Jun 01 16:31:37 2006 +0100
@@ -876,7 +876,7 @@ static int emulate_privileged_op(struct
PAGE_FAULT(regs->edi, USER_WRITE_FAULT);
break;
}
- regs->edi += (regs->eflags & EF_DF) ? -(int)op_bytes : op_bytes;
+ regs->edi += (int)((regs->eflags & EF_DF) ? -op_bytes : op_bytes);
break;
case 0x6e: /* OUTSB */
@@ -902,7 +902,7 @@ static int emulate_privileged_op(struct
outl_user((u32)data, (u16)regs->edx, v, regs);
break;
}
- regs->esi += (regs->eflags & EF_DF) ? -(int)op_bytes : op_bytes;
+ regs->esi += (int)((regs->eflags & EF_DF) ? -op_bytes : op_bytes);
break;
}
diff -r 4142bfd01e02 -r 2dd8e7c44728 xen/arch/x86/x86_emulate.c
--- a/xen/arch/x86/x86_emulate.c Thu Jun 01 11:25:02 2006 +0100
+++ b/xen/arch/x86/x86_emulate.c Thu Jun 01 16:31:37 2006 +0100
@@ -380,11 +380,12 @@ do{ __asm__ __volatile__ (
((reg) & ((1UL << (ad_bytes << 3)) - 1))))
#define register_address_increment(reg, inc) \
do { \
+ int _inc = (inc); /* signed type ensures sign extension to long */ \
if ( ad_bytes == sizeof(unsigned long) ) \
- (reg) += (inc); \
+ (reg) += _inc; \
else \
(reg) = ((reg) & ~((1UL << (ad_bytes << 3)) - 1)) | \
- (((reg) + (inc)) & ((1UL << (ad_bytes << 3)) - 1)); \
+ (((reg) + _inc) & ((1UL << (ad_bytes << 3)) - 1)); \
} while (0)
void *
@@ -858,7 +859,7 @@ x86_emulate_memop(
&dst.val, 8, ctxt)) != 0 )
goto done;
}
- register_address_increment(_regs.esp, -(int)dst.bytes);
+ register_address_increment(_regs.esp, -dst.bytes);
if ( (rc = ops->write_std(register_address(_regs.ss, _regs.esp),
dst.val, dst.bytes, ctxt)) != 0 )
goto done;
@@ -942,9 +943,9 @@ x86_emulate_memop(
goto done;
}
register_address_increment(
- _regs.esi, (_regs.eflags & EFLG_DF) ? -(int)dst.bytes : dst.bytes);
+ _regs.esi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
register_address_increment(
- _regs.edi, (_regs.eflags & EFLG_DF) ? -(int)dst.bytes : dst.bytes);
+ _regs.edi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
break;
case 0xa6 ... 0xa7: /* cmps */
DPRINTF("Urk! I don't handle CMPS.\n");
@@ -955,7 +956,7 @@ x86_emulate_memop(
dst.ptr = (unsigned long *)cr2;
dst.val = _regs.eax;
register_address_increment(
- _regs.edi, (_regs.eflags & EFLG_DF) ? -(int)dst.bytes : dst.bytes);
+ _regs.edi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
break;
case 0xac ... 0xad: /* lods */
dst.type = OP_REG;
@@ -964,7 +965,7 @@ x86_emulate_memop(
if ( (rc = ops->read_emulated(cr2, &dst.val, dst.bytes, ctxt)) != 0 )
goto done;
register_address_increment(
- _regs.esi, (_regs.eflags & EFLG_DF) ? -(int)dst.bytes : dst.bytes);
+ _regs.esi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
break;
case 0xae ... 0xaf: /* scas */
DPRINTF("Urk! I don't handle SCAS.\n");
_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel
|