Skip to contentSkip to conversation

x86_64: properly update RSI/RDI after emulated ins/outs (again)

PATCH In review Jan Beulich 2 participants 2 messages Jun 1, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86_64: properly update RSI/RDI after emulated ins/outs (again)

Unfortunately, the previous patch to address this wasn't taken unmodified, and the modification (c/s 10171, including most of the additions over the original patch) made the changes useless - the conditional operator yields unsigned if either of the operands is unsigned and the other is signed.

xen/arch/x86/traps.c renamed from home/jbeulich/src/xen/2006-05-31/xen/arch/x86/traps.c +2 -2
@@ -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 += (regs->eflags & EF_DF) ? -(long)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 += (regs->eflags & EF_DF) ? -(long)op_bytes : op_bytes;
             break;
         }
 
xen/arch/x86/x86_emulate.c renamed from home/jbeulich/src/xen/2006-05-31/xen/arch/x86/x86_emulate.c +4 -4
@@ -942,9 +942,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) ? -(long)dst.bytes : dst.bytes);
         register_address_increment(
-            _regs.edi, (_regs.eflags & EFLG_DF) ? -(int)dst.bytes : dst.bytes);
+            _regs.edi, (_regs.eflags & EFLG_DF) ? -(long)dst.bytes : dst.bytes);
         break;
     case 0xa6 ... 0xa7: /* cmps */
         DPRINTF("Urk! I don't handle CMPS.\n");
@@ -955,7 +955,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) ? -(long)dst.bytes : dst.bytes);
         break;
     case 0xac ... 0xad: /* lods */
         dst.type  = OP_REG;
@@ -964,7 +964,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) ? -(long)dst.bytes : dst.bytes);
         break;
     case 0xae ... 0xaf: /* scas */
         DPRINTF("Urk! I don't handle SCAS.\n");

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 3 lines · Jan Beulich

Unfortunately, the previous patch to address this wasn't taken unmodified, and the modification (c/s 10171, including most of the additions over the original patch) made the changes useless - the conditional operator yields unsigned if either of the operands is unsigned and the other is signed.

Maybe we should just make the variable a signed type to start with, or hide this behind a macro. It does crop up in quite a few places.

-- Keir