[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] x86: eliminate x86_emulate's private EFLAGS definitions



.. in favor of using one of the two (i.e. already redundant) ones
found in the headers.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>

Index: 2007-06-18/xen/arch/x86/x86_emulate.c
===================================================================
--- 2007-06-18.orig/xen/arch/x86/x86_emulate.c  2007-06-18 11:35:06.000000000 
+0200
+++ 2007-06-18/xen/arch/x86/x86_emulate.c       2007-06-18 11:35:19.000000000 
+0200
@@ -261,16 +261,6 @@ struct operand {
     };
 };
 
-/* EFLAGS bit definitions. */
-#define EFLG_OF (1<<11)
-#define EFLG_DF (1<<10)
-#define EFLG_IF (1<<9)
-#define EFLG_SF (1<<7)
-#define EFLG_ZF (1<<6)
-#define EFLG_AF (1<<4)
-#define EFLG_PF (1<<2)
-#define EFLG_CF (1<<0)
-
 /* Exception definitions. */
 #define EXC_DE  0
 #define EXC_BR  5
@@ -296,7 +286,7 @@ struct operand {
  * These EFLAGS bits are restored from saved value during emulation, and
  * any changes are written back to the saved value after emulation.
  */
-#define EFLAGS_MASK (EFLG_OF|EFLG_SF|EFLG_ZF|EFLG_AF|EFLG_PF|EFLG_CF)
+#define EFLAGS_MASK (EF_OF|EF_SF|EF_ZF|EF_AF|EF_PF|EF_CF)
 
 /* Before executing instruction: restore necessary bits in EFLAGS. */
 #define _PRE_EFLAGS(_sav, _msk, _tmp)           \
@@ -645,28 +635,28 @@ test_cc(
     switch ( (condition & 15) >> 1 )
     {
     case 0: /* o */
-        rc |= (flags & EFLG_OF);
+        rc |= (flags & EF_OF);
         break;
     case 1: /* b/c/nae */
-        rc |= (flags & EFLG_CF);
+        rc |= (flags & EF_CF);
         break;
     case 2: /* z/e */
-        rc |= (flags & EFLG_ZF);
+        rc |= (flags & EF_ZF);
         break;
     case 3: /* be/na */
-        rc |= (flags & (EFLG_CF|EFLG_ZF));
+        rc |= (flags & (EF_CF|EF_ZF));
         break;
     case 4: /* s */
-        rc |= (flags & EFLG_SF);
+        rc |= (flags & EF_SF);
         break;
     case 5: /* p/pe */
-        rc |= (flags & EFLG_PF);
+        rc |= (flags & EF_PF);
         break;
     case 7: /* le/ng */
-        rc |= (flags & EFLG_ZF);
+        rc |= (flags & EF_ZF);
         /* fall through */
     case 6: /* l/nge */
-        rc |= (!(flags & EFLG_SF) != !(flags & EFLG_OF));
+        rc |= (!(flags & EF_SF) != !(flags & EF_OF));
         break;
     }
 
@@ -1196,9 +1186,9 @@ x86_emulate(
             /* arpl */
             uint16_t src_val = dst.val;
             dst = src;
-            _regs.eflags &= ~EFLG_ZF;
-            _regs.eflags |= ((src_val & 3) > (dst.val & 3)) ? EFLG_ZF : 0;
-            if ( _regs.eflags & EFLG_ZF )
+            _regs.eflags &= ~EF_ZF;
+            _regs.eflags |= ((src_val & 3) > (dst.val & 3)) ? EF_ZF : 0;
+            if ( _regs.eflags & EF_ZF )
                 dst.val  = (dst.val & ~3) | (src_val & 3);
             else
                 dst.type = OP_NONE;
@@ -1208,27 +1198,27 @@ x86_emulate(
     case 0x69: /* imul imm16/32 */
     case 0x6b: /* imul imm8 */ {
         unsigned long reg = *(long *)decode_register(modrm_reg, &_regs, 0);
-        _regs.eflags &= ~(EFLG_OF|EFLG_CF);
+        _regs.eflags &= ~(EF_OF|EF_CF);
         switch ( dst.bytes )
         {
         case 2:
             dst.val = ((uint32_t)(int16_t)src.val *
                        (uint32_t)(int16_t)reg);
             if ( (int16_t)dst.val != (uint32_t)dst.val )
-                _regs.eflags |= EFLG_OF|EFLG_CF;
+                _regs.eflags |= EF_OF|EF_CF;
             break;
 #ifdef __x86_64__
         case 4:
             dst.val = ((uint64_t)(int32_t)src.val *
                        (uint64_t)(int32_t)reg);
             if ( (int32_t)dst.val != dst.val )
-                _regs.eflags |= EFLG_OF|EFLG_CF;
+                _regs.eflags |= EF_OF|EF_CF;
             break;
 #endif
         default: {
             unsigned long m[2] = { src.val, reg };
             if ( imul_dbl(m) )
-                _regs.eflags |= EFLG_OF|EFLG_CF;
+                _regs.eflags |= EF_OF|EF_CF;
             dst.val = m[0];
             break;
         }
@@ -1372,32 +1362,32 @@ x86_emulate(
             dst.type = OP_REG;
             dst.reg  = (unsigned long *)&_regs.eax;
             dst.val  = *dst.reg;
-            _regs.eflags &= ~(EFLG_OF|EFLG_CF);
+            _regs.eflags &= ~(EF_OF|EF_CF);
             switch ( src.bytes )
             {
             case 1:
                 dst.val *= src.val;
                 if ( (uint8_t)dst.val != (uint16_t)dst.val )
-                    _regs.eflags |= EFLG_OF|EFLG_CF;
+                    _regs.eflags |= EF_OF|EF_CF;
                 break;
             case 2:
                 dst.val *= src.val;
                 if ( (uint16_t)dst.val != (uint32_t)dst.val )
-                    _regs.eflags |= EFLG_OF|EFLG_CF;
+                    _regs.eflags |= EF_OF|EF_CF;
                 *(uint16_t *)&_regs.edx = dst.val >> 16;
                 break;
 #ifdef __x86_64__
             case 4:
                 dst.val *= src.val;
                 if ( (uint32_t)dst.val != dst.val )
-                    _regs.eflags |= EFLG_OF|EFLG_CF;
+                    _regs.eflags |= EF_OF|EF_CF;
                 _regs.edx = (uint32_t)(dst.val >> 32);
                 break;
 #endif
             default: {
                 unsigned long m[2] = { src.val, dst.val };
                 if ( mul_dbl(m) )
-                    _regs.eflags |= EFLG_OF|EFLG_CF;
+                    _regs.eflags |= EF_OF|EF_CF;
                 _regs.edx = m[1];
                 dst.val  = m[0];
                 break;
@@ -1409,20 +1399,20 @@ x86_emulate(
             dst.type = OP_REG;
             dst.reg  = (unsigned long *)&_regs.eax;
             dst.val  = *dst.reg;
-            _regs.eflags &= ~(EFLG_OF|EFLG_CF);
+            _regs.eflags &= ~(EF_OF|EF_CF);
             switch ( src.bytes )
             {
             case 1:
                 dst.val = ((uint16_t)(int8_t)src.val *
                            (uint16_t)(int8_t)dst.val);
                 if ( (int8_t)dst.val != (uint16_t)dst.val )
-                    _regs.eflags |= EFLG_OF|EFLG_CF;
+                    _regs.eflags |= EF_OF|EF_CF;
                 break;
             case 2:
                 dst.val = ((uint32_t)(int16_t)src.val *
                            (uint32_t)(int16_t)dst.val);
                 if ( (int16_t)dst.val != (uint32_t)dst.val )
-                    _regs.eflags |= EFLG_OF|EFLG_CF;
+                    _regs.eflags |= EF_OF|EF_CF;
                 *(uint16_t *)&_regs.edx = dst.val >> 16;
                 break;
 #ifdef __x86_64__
@@ -1430,14 +1420,14 @@ x86_emulate(
                 dst.val = ((uint64_t)(int32_t)src.val *
                            (uint64_t)(int32_t)dst.val);
                 if ( (int32_t)dst.val != dst.val )
-                    _regs.eflags |= EFLG_OF|EFLG_CF;
+                    _regs.eflags |= EF_OF|EF_CF;
                 _regs.edx = (uint32_t)(dst.val >> 32);
                 break;
 #endif
             default: {
                 unsigned long m[2] = { src.val, dst.val };
                 if ( imul_dbl(m) )
-                    _regs.eflags |= EFLG_OF|EFLG_CF;
+                    _regs.eflags |= EF_OF|EF_CF;
                 _regs.edx = m[1];
                 dst.val  = m[0];
                 break;
@@ -1657,21 +1647,21 @@ x86_emulate(
         uint8_t al = _regs.eax;
         unsigned long eflags = _regs.eflags;
         generate_exception_if(mode_64bit(), EXC_UD);
-        _regs.eflags &= ~(EFLG_CF|EFLG_AF);
-        if ( ((al & 0x0f) > 9) || (eflags & EFLG_AF) )
+        _regs.eflags &= ~(EF_CF|EF_AF);
+        if ( ((al & 0x0f) > 9) || (eflags & EF_AF) )
         {
             *(uint8_t *)&_regs.eax += 6;
-            _regs.eflags |= EFLG_AF;
+            _regs.eflags |= EF_AF;
         }
-        if ( (al > 0x99) || (eflags & EFLG_CF) )
+        if ( (al > 0x99) || (eflags & EF_CF) )
         {
             *(uint8_t *)&_regs.eax += 0x60;
-            _regs.eflags |= EFLG_CF;
+            _regs.eflags |= EF_CF;
         }
-        _regs.eflags &= ~(EFLG_SF|EFLG_ZF|EFLG_PF);
-        _regs.eflags |= ((uint8_t)_regs.eax == 0) ? EFLG_ZF : 0;
-        _regs.eflags |= (( int8_t)_regs.eax <  0) ? EFLG_SF : 0;
-        _regs.eflags |= even_parity(_regs.eax) ? EFLG_PF : 0;
+        _regs.eflags &= ~(EF_SF|EF_ZF|EF_PF);
+        _regs.eflags |= ((uint8_t)_regs.eax == 0) ? EF_ZF : 0;
+        _regs.eflags |= (( int8_t)_regs.eax <  0) ? EF_SF : 0;
+        _regs.eflags |= even_parity(_regs.eax) ? EF_PF : 0;
         break;
     }
 
@@ -1679,35 +1669,35 @@ x86_emulate(
         uint8_t al = _regs.eax;
         unsigned long eflags = _regs.eflags;
         generate_exception_if(mode_64bit(), EXC_UD);
-        _regs.eflags &= ~(EFLG_CF|EFLG_AF);
-        if ( ((al & 0x0f) > 9) || (eflags & EFLG_AF) )
+        _regs.eflags &= ~(EF_CF|EF_AF);
+        if ( ((al & 0x0f) > 9) || (eflags & EF_AF) )
         {
-            _regs.eflags |= EFLG_AF;
-            if ( (al < 6) || (eflags & EFLG_CF) )
-                _regs.eflags |= EFLG_CF;
+            _regs.eflags |= EF_AF;
+            if ( (al < 6) || (eflags & EF_CF) )
+                _regs.eflags |= EF_CF;
             *(uint8_t *)&_regs.eax -= 6;
         }
-        if ( (al > 0x99) || (eflags & EFLG_CF) )
+        if ( (al > 0x99) || (eflags & EF_CF) )
         {
             *(uint8_t *)&_regs.eax -= 0x60;
-            _regs.eflags |= EFLG_CF;
+            _regs.eflags |= EF_CF;
         }
-        _regs.eflags &= ~(EFLG_SF|EFLG_ZF|EFLG_PF);
-        _regs.eflags |= ((uint8_t)_regs.eax == 0) ? EFLG_ZF : 0;
-        _regs.eflags |= (( int8_t)_regs.eax <  0) ? EFLG_SF : 0;
-        _regs.eflags |= even_parity(_regs.eax) ? EFLG_PF : 0;
+        _regs.eflags &= ~(EF_SF|EF_ZF|EF_PF);
+        _regs.eflags |= ((uint8_t)_regs.eax == 0) ? EF_ZF : 0;
+        _regs.eflags |= (( int8_t)_regs.eax <  0) ? EF_SF : 0;
+        _regs.eflags |= even_parity(_regs.eax) ? EF_PF : 0;
         break;
     }
 
     case 0x37: /* aaa */
     case 0x3f: /* aas */
         generate_exception_if(mode_64bit(), EXC_UD);
-        _regs.eflags &= ~EFLG_CF;
-        if ( ((uint8_t)_regs.eax > 9) || (_regs.eflags & EFLG_AF) )
+        _regs.eflags &= ~EF_CF;
+        if ( ((uint8_t)_regs.eax > 9) || (_regs.eflags & EF_AF) )
         {
             ((uint8_t *)&_regs.eax)[0] += (b == 0x37) ? 6 : -6;
             ((uint8_t *)&_regs.eax)[1] += (b == 0x37) ? 1 : -1;
-            _regs.eflags |= EFLG_CF | EFLG_AF;
+            _regs.eflags |= EF_CF | EF_AF;
         }
         ((uint8_t *)&_regs.eax)[0] &= 0x0f;
         break;
@@ -1799,7 +1789,7 @@ x86_emulate(
                                 &dst.val, ctxt)) != 0 )
             goto done;
         register_address_increment(
-            _regs.edi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
+            _regs.edi, (_regs.eflags & EF_DF) ? -dst.bytes : dst.bytes);
         break;
 
     case 0x6e ... 0x6f: /* outs %esi,%dx */
@@ -1814,7 +1804,7 @@ x86_emulate(
                                  dst.val, ctxt)) != 0 )
             goto done;
         register_address_increment(
-            _regs.esi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
+            _regs.esi, (_regs.eflags & EF_DF) ? -dst.bytes : dst.bytes);
         break;
 
     case 0x70 ... 0x7f: /* jcc (short) */ {
@@ -1899,9 +1889,9 @@ x86_emulate(
                              &dst.val, dst.bytes, ctxt)) != 0 )
             goto done;
         register_address_increment(
-            _regs.esi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
+            _regs.esi, (_regs.eflags & EF_DF) ? -dst.bytes : dst.bytes);
         register_address_increment(
-            _regs.edi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
+            _regs.edi, (_regs.eflags & EF_DF) ? -dst.bytes : dst.bytes);
         break;
 
     case 0xaa ... 0xab: /* stos */
@@ -1912,7 +1902,7 @@ x86_emulate(
         dst.mem.off = truncate_ea(_regs.edi);
         dst.val   = _regs.eax;
         register_address_increment(
-            _regs.edi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
+            _regs.edi, (_regs.eflags & EF_DF) ? -dst.bytes : dst.bytes);
         break;
 
     case 0xac ... 0xad: /* lods */
@@ -1924,7 +1914,7 @@ x86_emulate(
                              &dst.val, dst.bytes, ctxt)) != 0 )
             goto done;
         register_address_increment(
-            _regs.esi, (_regs.eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
+            _regs.esi, (_regs.eflags & EF_DF) ? -dst.bytes : dst.bytes);
         break;
 
     case 0xc2: /* ret imm16 (near) */
@@ -1944,10 +1934,10 @@ x86_emulate(
         generate_exception_if(mode_64bit(), EXC_UD);
         generate_exception_if(base == 0, EXC_DE);
         *(uint16_t *)&_regs.eax = ((al / base) << 8) | (al % base);
-        _regs.eflags &= ~(EFLG_SF|EFLG_ZF|EFLG_PF);
-        _regs.eflags |= ((uint8_t)_regs.eax == 0) ? EFLG_ZF : 0;
-        _regs.eflags |= (( int8_t)_regs.eax <  0) ? EFLG_SF : 0;
-        _regs.eflags |= even_parity(_regs.eax) ? EFLG_PF : 0;
+        _regs.eflags &= ~(EF_SF|EF_ZF|EF_PF);
+        _regs.eflags |= ((uint8_t)_regs.eax == 0) ? EF_ZF : 0;
+        _regs.eflags |= (( int8_t)_regs.eax <  0) ? EF_SF : 0;
+        _regs.eflags |= even_parity(_regs.eax) ? EF_PF : 0;
         break;
     }
 
@@ -1956,16 +1946,16 @@ x86_emulate(
         uint16_t ax = _regs.eax;
         generate_exception_if(mode_64bit(), EXC_UD);
         *(uint16_t *)&_regs.eax = (uint8_t)(ax + ((ax >> 8) * base));
-        _regs.eflags &= ~(EFLG_SF|EFLG_ZF|EFLG_PF);
-        _regs.eflags |= ((uint8_t)_regs.eax == 0) ? EFLG_ZF : 0;
-        _regs.eflags |= (( int8_t)_regs.eax <  0) ? EFLG_SF : 0;
-        _regs.eflags |= even_parity(_regs.eax) ? EFLG_PF : 0;
+        _regs.eflags &= ~(EF_SF|EF_ZF|EF_PF);
+        _regs.eflags |= ((uint8_t)_regs.eax == 0) ? EF_ZF : 0;
+        _regs.eflags |= (( int8_t)_regs.eax <  0) ? EF_SF : 0;
+        _regs.eflags |= even_parity(_regs.eax) ? EF_PF : 0;
         break;
     }
 
     case 0xd6: /* salc */
         generate_exception_if(mode_64bit(), EXC_UD);
-        *(uint8_t *)&_regs.eax = (_regs.eflags & EFLG_CF) ? 0xff : 0x00;
+        *(uint8_t *)&_regs.eax = (_regs.eflags & EF_CF) ? 0xff : 0x00;
         break;
 
     case 0xd7: /* xlat */ {
@@ -1979,7 +1969,7 @@ x86_emulate(
 
     case 0xe0 ... 0xe2: /* loop{,z,nz} */ {
         int rel = insn_fetch_type(int8_t);
-        int do_jmp = !(_regs.eflags & EFLG_ZF); /* loopnz */
+        int do_jmp = !(_regs.eflags & EF_ZF); /* loopnz */
         if ( b == 0xe1 )
             do_jmp = !do_jmp; /* loopz */
         else if ( b == 0xe2 )
@@ -2067,37 +2057,37 @@ x86_emulate(
         break;
 
     case 0xf5: /* cmc */
-        _regs.eflags ^= EFLG_CF;
+        _regs.eflags ^= EF_CF;
         break;
 
     case 0xf8: /* clc */
-        _regs.eflags &= ~EFLG_CF;
+        _regs.eflags &= ~EF_CF;
         break;
 
     case 0xf9: /* stc */
-        _regs.eflags |= EFLG_CF;
+        _regs.eflags |= EF_CF;
         break;
 
     case 0xfa: /* cli */
         generate_exception_if(!mode_iopl(), EXC_GP);
         fail_if(ops->write_rflags == NULL);
-        if ( (rc = ops->write_rflags(_regs.eflags & ~EFLG_IF, ctxt)) != 0 )
+        if ( (rc = ops->write_rflags(_regs.eflags & ~EF_IE, ctxt)) != 0 )
             goto done;
         break;
 
     case 0xfb: /* sti */
         generate_exception_if(!mode_iopl(), EXC_GP);
         fail_if(ops->write_rflags == NULL);
-        if ( (rc = ops->write_rflags(_regs.eflags | EFLG_IF, ctxt)) != 0 )
+        if ( (rc = ops->write_rflags(_regs.eflags | EF_IE, ctxt)) != 0 )
             goto done;
         break;
 
     case 0xfc: /* cld */
-        _regs.eflags &= ~EFLG_DF;
+        _regs.eflags &= ~EF_DF;
         break;
 
     case 0xfd: /* std */
-        _regs.eflags |= EFLG_DF;
+        _regs.eflags |= EF_DF;
         break;
     }
     goto writeback;
@@ -2122,7 +2112,7 @@ x86_emulate(
         emulate_2op_SrcV("cmp", src, dst, _regs.eflags);
         /* Always write back. The question is: where to? */
         d |= Mov;
-        if ( _regs.eflags & EFLG_ZF )
+        if ( _regs.eflags & EF_ZF )
         {
             /* Success: write back to memory. */
             dst.val = src.orig_val;
@@ -2148,27 +2138,27 @@ x86_emulate(
         break;
 
     case 0xaf: /* imul */
-        _regs.eflags &= ~(EFLG_OF|EFLG_CF);
+        _regs.eflags &= ~(EF_OF|EF_CF);
         switch ( dst.bytes )
         {
         case 2:
             dst.val = ((uint32_t)(int16_t)src.val *
                        (uint32_t)(int16_t)dst.val);
             if ( (int16_t)dst.val != (uint32_t)dst.val )
-                _regs.eflags |= EFLG_OF|EFLG_CF;
+                _regs.eflags |= EF_OF|EF_CF;
             break;
 #ifdef __x86_64__
         case 4:
             dst.val = ((uint64_t)(int32_t)src.val *
                        (uint64_t)(int32_t)dst.val);
             if ( (int32_t)dst.val != dst.val )
-                _regs.eflags |= EFLG_OF|EFLG_CF;
+                _regs.eflags |= EF_OF|EF_CF;
             break;
 #endif
         default: {
             unsigned long m[2] = { src.val, dst.val };
             if ( imul_dbl(m) )
-                _regs.eflags |= EFLG_OF|EFLG_CF;
+                _regs.eflags |= EF_OF|EF_CF;
             dst.val = m[0];
             break;
         }
@@ -2187,8 +2177,8 @@ x86_emulate(
         asm ( "bsf %2,%0; setz %b1"
               : "=r" (dst.val), "=q" (zf)
               : "r" (src.val), "1" (0) );
-        _regs.eflags &= ~EFLG_ZF;
-        _regs.eflags |= zf ? EFLG_ZF : 0;
+        _regs.eflags &= ~EF_ZF;
+        _regs.eflags |= zf ? EF_ZF : 0;
         break;
     }
 
@@ -2197,8 +2187,8 @@ x86_emulate(
         asm ( "bsr %2,%0; setz %b1"
               : "=r" (dst.val), "=q" (zf)
               : "r" (src.val), "1" (0) );
-        _regs.eflags &= ~EFLG_ZF;
-        _regs.eflags |= zf ? EFLG_ZF : 0;
+        _regs.eflags &= ~EF_ZF;
+        _regs.eflags |= zf ? EF_ZF : 0;
         break;
     }
 
@@ -2349,7 +2339,7 @@ x86_emulate(
         {
             _regs.eax = old_lo;
             _regs.edx = old_hi;
-            _regs.eflags &= ~EFLG_ZF;
+            _regs.eflags &= ~EF_ZF;
         }
         else if ( ops->cmpxchg8b == NULL )
         {
@@ -2361,7 +2351,7 @@ x86_emulate(
             if ( (rc = ops->cmpxchg8b(ea.mem.seg, ea.mem.off, old_lo, old_hi,
                                       _regs.ebx, _regs.ecx, ctxt)) != 0 )
                 goto done;
-            _regs.eflags |= EFLG_ZF;
+            _regs.eflags |= EF_ZF;
         }
         break;
     }
@@ -2376,7 +2366,7 @@ x86_emulate(
         {
             _regs.eax = (uint32_t)(old>>0);
             _regs.edx = (uint32_t)(old>>32);
-            _regs.eflags &= ~EFLG_ZF;
+            _regs.eflags &= ~EF_ZF;
         }
         else
         {
@@ -2384,7 +2374,7 @@ x86_emulate(
             if ( (rc = ops->cmpxchg(ea.mem.seg, ea.mem.off, old,
                                     new, 8, ctxt)) != 0 )
                 goto done;
-            _regs.eflags |= EFLG_ZF;
+            _regs.eflags |= EF_ZF;
         }
         break;
     }



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.