VirtualBox

Changeset 93866 in vbox for trunk


Ignore:
Timestamp:
Feb 21, 2022 12:02:48 PM (3 years ago)
Author:
vboxsync
Message:

VMM/IEM: Corrected undefined flag values for BT, BTC, BTR and BTS. bugref:9898

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllAImplC.cpp

    r93864 r93866  
    3737#  define IEM_WITHOUT_ASSEMBLY
    3838# endif
     39#endif
     40/* IEM_WITH_ASSEMBLY trumps IEM_WITHOUT_ASSEMBLY for tstIEMAImplAsm purposes. */
     41#ifdef IEM_WITH_ASSEMBLY
     42# undef IEM_WITHOUT_ASSEMBLY
    3943#endif
    4044
     
    912916IEM_DECL_IMPL_DEF(void, iemAImpl_bt_u64,(uint64_t *puDst, uint64_t uSrc, uint32_t *pfEFlags))
    913917{
    914     /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
    915        logical operation (AND/OR/whatever). */
     918    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  However, it seems they're
     919             not modified by either AMD (3990x) or Intel (i9-9980HK). */
    916920    Assert(uSrc < 64);
    917921    uint64_t uDst = *puDst;
    918922    if (uDst & RT_BIT_64(uSrc))
    919         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 64, X86_EFL_CF);
     923        *pfEFlags |= X86_EFL_CF;
    920924    else
    921         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 64, 0);
     925        *pfEFlags &= ~X86_EFL_CF;
    922926}
    923927
     
    926930IEM_DECL_IMPL_DEF(void, iemAImpl_bt_u32,(uint32_t *puDst, uint32_t uSrc, uint32_t *pfEFlags))
    927931{
    928     /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
    929        logical operation (AND/OR/whatever). */
     932    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  However, it seems they're
     933             not modified by either AMD (3990x) or Intel (i9-9980HK). */
    930934    Assert(uSrc < 32);
    931935    uint32_t uDst = *puDst;
    932936    if (uDst & RT_BIT_32(uSrc))
    933         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 32, X86_EFL_CF);
     937        *pfEFlags |= X86_EFL_CF;
    934938    else
    935         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 32, 0);
     939        *pfEFlags &= ~X86_EFL_CF;
    936940}
    937941
    938942IEM_DECL_IMPL_DEF(void, iemAImpl_bt_u16,(uint16_t *puDst, uint16_t uSrc, uint32_t *pfEFlags))
    939943{
    940     /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
    941        logical operation (AND/OR/whatever). */
     944    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  However, it seems they're
     945             not modified by either AMD (3990x) or Intel (i9-9980HK). */
    942946    Assert(uSrc < 16);
    943947    uint16_t uDst = *puDst;
    944948    if (uDst & RT_BIT_32(uSrc))
    945         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 16, X86_EFL_CF);
     949        *pfEFlags |= X86_EFL_CF;
    946950    else
    947         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 16, 0);
     951        *pfEFlags &= ~X86_EFL_CF;
    948952}
    949953
     
    955959
    956960IEM_DECL_IMPL_DEF(void, iemAImpl_btc_u64,(uint64_t *puDst, uint64_t uSrc, uint32_t *pfEFlags))
     961{
     962    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  However, it seems they're
     963             not modified by either AMD (3990x) or Intel (i9-9980HK). */
     964    Assert(uSrc < 64);
     965    uint64_t fMask = RT_BIT_64(uSrc);
     966    uint64_t uDst = *puDst;
     967    if (uDst & fMask)
     968    {
     969        uDst &= ~fMask;
     970        *puDst = uDst;
     971        *pfEFlags |= X86_EFL_CF;
     972    }
     973    else
     974    {
     975        uDst |= fMask;
     976        *puDst = uDst;
     977        *pfEFlags &= ~X86_EFL_CF;
     978    }
     979}
     980
     981# if !defined(RT_ARCH_X86) || defined(IEM_WITHOUT_ASSEMBLY)
     982
     983IEM_DECL_IMPL_DEF(void, iemAImpl_btc_u32,(uint32_t *puDst, uint32_t uSrc, uint32_t *pfEFlags))
     984{
     985    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  However, it seems they're
     986             not modified by either AMD (3990x) or Intel (i9-9980HK). */
     987    Assert(uSrc < 32);
     988    uint32_t fMask = RT_BIT_32(uSrc);
     989    uint32_t uDst = *puDst;
     990    if (uDst & fMask)
     991    {
     992        uDst &= ~fMask;
     993        *puDst = uDst;
     994        *pfEFlags |= X86_EFL_CF;
     995    }
     996    else
     997    {
     998        uDst |= fMask;
     999        *puDst = uDst;
     1000        *pfEFlags &= ~X86_EFL_CF;
     1001    }
     1002}
     1003
     1004
     1005IEM_DECL_IMPL_DEF(void, iemAImpl_btc_u16,(uint16_t *puDst, uint16_t uSrc, uint32_t *pfEFlags))
     1006{
     1007    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  However, it seems they're
     1008             not modified by either AMD (3990x) or Intel (i9-9980HK). */
     1009    Assert(uSrc < 16);
     1010    uint16_t fMask = RT_BIT_32(uSrc);
     1011    uint16_t uDst = *puDst;
     1012    if (uDst & fMask)
     1013    {
     1014        uDst &= ~fMask;
     1015        *puDst = uDst;
     1016        *pfEFlags |= X86_EFL_CF;
     1017    }
     1018    else
     1019    {
     1020        uDst |= fMask;
     1021        *puDst = uDst;
     1022        *pfEFlags &= ~X86_EFL_CF;
     1023    }
     1024}
     1025
     1026# endif /* !defined(RT_ARCH_X86) || defined(IEM_WITHOUT_ASSEMBLY) */
     1027
     1028/*
     1029 * BTR
     1030 */
     1031
     1032IEM_DECL_IMPL_DEF(void, iemAImpl_btr_u64,(uint64_t *puDst, uint64_t uSrc, uint32_t *pfEFlags))
    9571033{
    9581034    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
     
    9651041        uDst &= ~fMask;
    9661042        *puDst = uDst;
    967         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 64, X86_EFL_CF);
     1043        *pfEFlags |= X86_EFL_CF;
    9681044    }
    9691045    else
    970     {
    971         uDst |= fMask;
    972         *puDst = uDst;
    973         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 64, 0);
    974     }
    975 }
    976 
    977 # if !defined(RT_ARCH_X86) || defined(IEM_WITHOUT_ASSEMBLY)
    978 
    979 IEM_DECL_IMPL_DEF(void, iemAImpl_btc_u32,(uint32_t *puDst, uint32_t uSrc, uint32_t *pfEFlags))
     1046        *pfEFlags &= ~X86_EFL_CF;
     1047}
     1048
     1049# if !defined(RT_ARCH_X86) || defined(IEM_WITHOUT_ASSEMBLY)
     1050
     1051IEM_DECL_IMPL_DEF(void, iemAImpl_btr_u32,(uint32_t *puDst, uint32_t uSrc, uint32_t *pfEFlags))
    9801052{
    9811053    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
     
    9881060        uDst &= ~fMask;
    9891061        *puDst = uDst;
    990         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 32, X86_EFL_CF);
     1062        *pfEFlags |= X86_EFL_CF;
    9911063    }
    9921064    else
    993     {
    994         uDst |= fMask;
    995         *puDst = uDst;
    996         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 32, 0);
    997     }
    998 }
    999 
    1000 
    1001 IEM_DECL_IMPL_DEF(void, iemAImpl_btc_u16,(uint16_t *puDst, uint16_t uSrc, uint32_t *pfEFlags))
     1065        *pfEFlags &= ~X86_EFL_CF;
     1066}
     1067
     1068
     1069IEM_DECL_IMPL_DEF(void, iemAImpl_btr_u16,(uint16_t *puDst, uint16_t uSrc, uint32_t *pfEFlags))
    10021070{
    10031071    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
     
    10101078        uDst &= ~fMask;
    10111079        *puDst = uDst;
    1012         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 16, X86_EFL_CF);
     1080        *pfEFlags |= X86_EFL_CF;
    10131081    }
    10141082    else
    1015     {
    1016         uDst |= fMask;
    1017         *puDst = uDst;
    1018         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 16, 0);
    1019     }
     1083        *pfEFlags &= ~X86_EFL_CF;
    10201084}
    10211085
     
    10231087
    10241088/*
    1025  * BTR
    1026  */
    1027 
    1028 IEM_DECL_IMPL_DEF(void, iemAImpl_btr_u64,(uint64_t *puDst, uint64_t uSrc, uint32_t *pfEFlags))
     1089 * BTS
     1090 */
     1091
     1092IEM_DECL_IMPL_DEF(void, iemAImpl_bts_u64,(uint64_t *puDst, uint64_t uSrc, uint32_t *pfEFlags))
    10291093{
    10301094    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
     
    10341098    uint64_t uDst = *puDst;
    10351099    if (uDst & fMask)
    1036     {
    1037         uDst &= ~fMask;
     1100        *pfEFlags |= X86_EFL_CF;
     1101    else
     1102    {
     1103        uDst |= fMask;
    10381104        *puDst = uDst;
    1039         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 64, X86_EFL_CF);
    1040     }
    1041     else
    1042         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 64, 0);
    1043 }
    1044 
    1045 # if !defined(RT_ARCH_X86) || defined(IEM_WITHOUT_ASSEMBLY)
    1046 
    1047 IEM_DECL_IMPL_DEF(void, iemAImpl_btr_u32,(uint32_t *puDst, uint32_t uSrc, uint32_t *pfEFlags))
     1105        *pfEFlags &= ~X86_EFL_CF;
     1106    }
     1107}
     1108
     1109# if !defined(RT_ARCH_X86) || defined(IEM_WITHOUT_ASSEMBLY)
     1110
     1111IEM_DECL_IMPL_DEF(void, iemAImpl_bts_u32,(uint32_t *puDst, uint32_t uSrc, uint32_t *pfEFlags))
    10481112{
    10491113    /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
     
    10531117    uint32_t uDst = *puDst;
    10541118    if (uDst & fMask)
    1055     {
    1056         uDst &= ~fMask;
    1057         *puDst = uDst;
    1058         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 32, X86_EFL_CF);
    1059     }
    1060     else
    1061         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 32, 0);
    1062 }
    1063 
    1064 
    1065 IEM_DECL_IMPL_DEF(void, iemAImpl_btr_u16,(uint16_t *puDst, uint16_t uSrc, uint32_t *pfEFlags))
    1066 {
    1067     /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
    1068        logical operation (AND/OR/whatever). */
    1069     Assert(uSrc < 16);
    1070     uint16_t fMask = RT_BIT_32(uSrc);
    1071     uint16_t uDst = *puDst;
    1072     if (uDst & fMask)
    1073     {
    1074         uDst &= ~fMask;
    1075         *puDst = uDst;
    1076         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 16, X86_EFL_CF);
    1077     }
    1078     else
    1079         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 16, 0);
    1080 }
    1081 
    1082 # endif /* !defined(RT_ARCH_X86) || defined(IEM_WITHOUT_ASSEMBLY) */
    1083 
    1084 /*
    1085  * BTS
    1086  */
    1087 
    1088 IEM_DECL_IMPL_DEF(void, iemAImpl_bts_u64,(uint64_t *puDst, uint64_t uSrc, uint32_t *pfEFlags))
    1089 {
    1090     /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
    1091        logical operation (AND/OR/whatever). */
    1092     Assert(uSrc < 64);
    1093     uint64_t fMask = RT_BIT_64(uSrc);
    1094     uint64_t uDst = *puDst;
    1095     if (uDst & fMask)
    1096         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 64, X86_EFL_CF);
     1119        *pfEFlags |= X86_EFL_CF;
    10971120    else
    10981121    {
    10991122        uDst |= fMask;
    11001123        *puDst = uDst;
    1101         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 64, 0);
    1102     }
    1103 }
    1104 
    1105 # if !defined(RT_ARCH_X86) || defined(IEM_WITHOUT_ASSEMBLY)
    1106 
    1107 IEM_DECL_IMPL_DEF(void, iemAImpl_bts_u32,(uint32_t *puDst, uint32_t uSrc, uint32_t *pfEFlags))
    1108 {
    1109     /* Note! "undefined" flags: OF, SF, ZF, AF, PF.  We set them as after an
    1110        logical operation (AND/OR/whatever). */
    1111     Assert(uSrc < 32);
    1112     uint32_t fMask = RT_BIT_32(uSrc);
    1113     uint32_t uDst = *puDst;
    1114     if (uDst & fMask)
    1115         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 32, X86_EFL_CF);
    1116     else
    1117     {
    1118         uDst |= fMask;
    1119         *puDst = uDst;
    1120         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 32, 0);
     1124        *pfEFlags &= ~X86_EFL_CF;
    11211125    }
    11221126}
     
    11311135    uint32_t uDst = *puDst;
    11321136    if (uDst & fMask)
    1133         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 32, X86_EFL_CF);
     1137        *pfEFlags |= X86_EFL_CF;
    11341138    else
    11351139    {
    11361140        uDst |= fMask;
    11371141        *puDst = uDst;
    1138         IEM_EFL_UPDATE_STATUS_BITS_FOR_LOGIC(pfEFlags, uDst, 32, 0);
     1142        *pfEFlags &= ~X86_EFL_CF;
    11391143    }
    11401144}
     
    11641168{
    11651169    /* Note! "undefined" flags: OF, SF, AF, PF, CF. */
    1166     /** @todo check what real CPUs do. */
     1170    /* Intel & AMD differs here. This is is the AMD behaviour. */
    11671171    unsigned iBit = ASMBitFirstSetU64(uSrc);
    11681172    if (iBit)
     
    11801184{
    11811185    /* Note! "undefined" flags: OF, SF, AF, PF, CF. */
    1182     /** @todo check what real CPUs do. */
     1186    /* Intel & AMD differs here. This is is the AMD behaviour. */
    11831187    unsigned iBit = ASMBitFirstSetU32(uSrc);
    11841188    if (iBit)
     
    11951199{
    11961200    /* Note! "undefined" flags: OF, SF, AF, PF, CF. */
    1197     /** @todo check what real CPUs do. */
     1201    /* Intel & AMD differs here. This is is the AMD behaviour. */
    11981202    unsigned iBit = ASMBitFirstSetU16(uSrc);
    11991203    if (iBit)
     
    12151219{
    12161220    /* Note! "undefined" flags: OF, SF, AF, PF, CF. */
    1217     /** @todo check what real CPUs do. */
     1221    /* Intel & AMD differs here. This is is the AMD behaviour. */
    12181222    unsigned iBit = ASMBitLastSetU64(uSrc);
    12191223    if (uSrc)
     
    12311235{
    12321236    /* Note! "undefined" flags: OF, SF, AF, PF, CF. */
    1233     /** @todo check what real CPUs do. */
     1237    /* Intel & AMD differs here. This is is the AMD behaviour. */
    12341238    unsigned iBit = ASMBitLastSetU32(uSrc);
    12351239    if (uSrc)
     
    12461250{
    12471251    /* Note! "undefined" flags: OF, SF, AF, PF, CF. */
    1248     /** @todo check what real CPUs do. */
     1252    /* Intel & AMD differs here. This is is the AMD behaviour. */
    12491253    unsigned iBit = ASMBitLastSetU16(uSrc);
    12501254    if (uSrc)
  • trunk/src/VBox/VMM/testcase/Makefile.kmk

    r93862 r93866  
    252252# This variant mainly for generating data.
    253253tstIEMAImplAsm_TEMPLATE  = VBOXR3TSTEXE
    254 tstIEMAImplAsm_DEFS      = $(VMM_COMMON_DEFS) IN_TSTVMSTRUCT
     254tstIEMAImplAsm_DEFS      = $(VMM_COMMON_DEFS) IEM_WITH_ASSEMBLY IN_TSTVMSTRUCT
    255255tstIEMAImplAsm_INCS      = ../include
    256256tstIEMAImplAsm_SOURCES   = \
    257257        tstIEMAImpl.cpp \
    258        ../VMMAll/IEMAllAImpl.asm
     258       ../VMMAll/IEMAllAImpl.asm \
     259       ../VMMAll/IEMAllAImplC.cpp
    259260
    260261#
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette