VirtualBox

Changeset 82684 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Jan 9, 2020 8:01:50 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135601
Message:

hmvmxinline: Remove disabled code. The new assembly code has been tested sufficiently by now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/hmvmxinline.h

    r80364 r82684  
    457457
    458458
    459 #if 0
    460 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
    461 DECLASM(int) VMXEnable(RTHCPHYS HCPhysVmxOn);
    462 #else
    463 DECLINLINE(int) VMXEnable(RTHCPHYS HCPhysVmxOn)
    464 {
    465 # if RT_INLINE_ASM_GNU_STYLE
    466     int rc = VINF_SUCCESS;
    467     __asm__ __volatile__ (
    468        "push     %3                                             \n\t"
    469        "push     %2                                             \n\t"
    470        ".byte    0xf3, 0x0f, 0xc7, 0x34, 0x24  # VMXON [esp]    \n\t"
    471        "ja       2f                                             \n\t"
    472        "je       1f                                             \n\t"
    473        "movl     $" RT_XSTR(VERR_VMX_INVALID_VMXON_PTR)", %0    \n\t"
    474        "jmp      2f                                             \n\t"
    475        "1:                                                      \n\t"
    476        "movl     $" RT_XSTR(VERR_VMX_VMXON_FAILED)", %0         \n\t"
    477        "2:                                                      \n\t"
    478        "add      $8, %%esp                                      \n\t"
    479        :"=rm"(rc)
    480        :"0"(VINF_SUCCESS),
    481         "ir"((uint32_t)HCPhysVmxOn),        /* don't allow direct memory reference here, */
    482         "ir"((uint32_t)(HCPhysVmxOn >> 32)) /* this would not work with -fomit-frame-pointer */
    483        :"memory"
    484        );
    485     return rc;
    486 
    487 # elif VMX_USE_MSC_INTRINSICS
    488     unsigned char rcMsc = __vmx_on(&HCPhysVmxOn);
    489     if (RT_LIKELY(rcMsc == 0))
    490         return VINF_SUCCESS;
    491     return rcMsc == 2 ? VERR_VMX_INVALID_VMXON_PTR : VERR_VMX_VMXON_FAILED;
    492 
    493 # else
    494     int rc = VINF_SUCCESS;
    495     __asm
    496     {
    497         push    dword ptr [HCPhysVmxOn + 4]
    498         push    dword ptr [HCPhysVmxOn]
    499         _emit   0xf3
    500         _emit   0x0f
    501         _emit   0xc7
    502         _emit   0x34
    503         _emit   0x24     /* VMXON [esp] */
    504         jnc     vmxon_good
    505         mov     dword ptr [rc], VERR_VMX_INVALID_VMXON_PTR
    506         jmp     the_end
    507 
    508 vmxon_good:
    509         jnz     the_end
    510         mov     dword ptr [rc], VERR_VMX_VMXON_FAILED
    511 the_end:
    512         add     esp, 8
    513     }
    514     return rc;
    515 # endif
    516 }
    517 #endif
    518 #endif
    519 
    520 
    521459/**
    522460 * Executes VMXOFF.
     
    547485# endif
    548486}
    549 #endif
    550 
    551 
    552 #if 0
    553 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
    554 DECLASM(void) VMXDisable(void);
    555 #else
    556 DECLINLINE(void) VMXDisable(void)
    557 {
    558 # if RT_INLINE_ASM_GNU_STYLE
    559     __asm__ __volatile__ (
    560        ".byte 0x0f, 0x01, 0xc4  # VMXOFF                        \n\t"
    561        );
    562 
    563 # elif VMX_USE_MSC_INTRINSICS
    564     __vmx_off();
    565 
    566 # else
    567     __asm
    568     {
    569         _emit   0x0f
    570         _emit   0x01
    571         _emit   0xc4   /* VMXOFF */
    572     }
    573 # endif
    574 }
    575 #endif
    576487#endif
    577488
     
    655566
    656567
    657 #if 0
    658 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
    659 DECLASM(int) VMXClearVmcs(RTHCPHYS HCPhysVmcs);
    660 #else
    661 DECLINLINE(int) VMXClearVmcs(RTHCPHYS HCPhysVmcs)
    662 {
    663 # if RT_INLINE_ASM_GNU_STYLE
    664     int rc = VINF_SUCCESS;
    665     __asm__ __volatile__ (
    666        "push    %3                                              \n\t"
    667        "push    %2                                              \n\t"
    668        ".byte   0x66, 0x0f, 0xc7, 0x34, 0x24  # VMCLEAR [esp]   \n\t"
    669        "jnc     1f                                              \n\t"
    670        "movl    $" RT_XSTR(VERR_VMX_INVALID_VMCS_PTR)", %0      \n\t"
    671        "1:                                                      \n\t"
    672        "add     $8, %%esp                                       \n\t"
    673        :"=rm"(rc)
    674        :"0"(VINF_SUCCESS),
    675         "ir"((uint32_t)HCPhysVmcs),        /* don't allow direct memory reference here, */
    676         "ir"((uint32_t)(HCPhysVmcs >> 32)) /* this would not work with -fomit-frame-pointer */
    677        :"memory"
    678        );
    679     return rc;
    680 
    681 # elif VMX_USE_MSC_INTRINSICS
    682     unsigned char rcMsc = __vmx_vmclear(&HCPhysVmcs);
    683     if (RT_LIKELY(rcMsc == 0))
    684         return VINF_SUCCESS;
    685     return VERR_VMX_INVALID_VMCS_PTR;
    686 
    687 # else
    688     int rc = VINF_SUCCESS;
    689     __asm
    690     {
    691         push    dword ptr [HCPhysVmcs + 4]
    692         push    dword ptr [HCPhysVmcs]
    693         _emit   0x66
    694         _emit   0x0f
    695         _emit   0xc7
    696         _emit   0x34
    697         _emit   0x24     /* VMCLEAR [esp] */
    698         jnc     success
    699         mov     dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
    700 success:
    701         add     esp, 8
    702     }
    703     return rc;
    704 # endif
    705 }
    706 #endif
    707 #endif
    708 
    709 
    710568/**
    711569 * Executes VMPTRLD.
     
    782640# endif
    783641}
    784 #endif
    785 
    786 #if 0
    787 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
    788 DECLASM(int) VMXLoadVmcs(RTHCPHYS HCPhysVmcs);
    789 #else
    790 DECLINLINE(int) VMXLoadVmcs(RTHCPHYS HCPhysVmcs)
    791 {
    792 # if RT_INLINE_ASM_GNU_STYLE
    793     int rc = VINF_SUCCESS;
    794     __asm__ __volatile__ (
    795        "push    %3                                              \n\t"
    796        "push    %2                                              \n\t"
    797        ".byte   0x0f, 0xc7, 0x34, 0x24  # VMPTRLD [esp]         \n\t"
    798        "jnc     1f                                              \n\t"
    799        "movl    $" RT_XSTR(VERR_VMX_INVALID_VMCS_PTR)", %0      \n\t"
    800        "1:                                                      \n\t"
    801        "add     $8, %%esp                                       \n\t"
    802        :"=rm"(rc)
    803        :"0"(VINF_SUCCESS),
    804         "ir"((uint32_t)HCPhysVmcs),        /* don't allow direct memory reference here, */
    805         "ir"((uint32_t)(HCPhysVmcs >> 32)) /* this will not work with -fomit-frame-pointer */
    806        );
    807     return rc;
    808 
    809 # elif VMX_USE_MSC_INTRINSICS
    810     unsigned char rcMsc = __vmx_vmptrld(&HCPhysVmcs);
    811     if (RT_LIKELY(rcMsc == 0))
    812         return VINF_SUCCESS;
    813     return VERR_VMX_INVALID_VMCS_PTR;
    814 
    815 # else
    816     int rc = VINF_SUCCESS;
    817     __asm
    818     {
    819         push    dword ptr [HCPhysVmcs + 4]
    820         push    dword ptr [HCPhysVmcs]
    821         _emit   0x0f
    822         _emit   0xc7
    823         _emit   0x34
    824         _emit   0x24     /* VMPTRLD [esp] */
    825         jnc     success
    826         mov     dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
    827 
    828 success:
    829         add     esp, 8
    830     }
    831     return rc;
    832 # endif
    833 }
    834 #endif
    835642#endif
    836643
     
    932739
    933740
    934 #if 0
    935 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
    936 DECLASM(int) VMXWriteVmcs32(uint32_t uFieldEnc, uint32_t u32Val);
    937 #else
    938 DECLINLINE(int) VMXWriteVmcs32(uint32_t uFieldEnc, uint32_t u32Val)
    939 {
    940 # if RT_INLINE_ASM_GNU_STYLE
    941     int rc = VINF_SUCCESS;
    942     __asm__ __volatile__ (
    943        ".byte  0x0f, 0x79, 0xc2        # VMWRITE eax, edx       \n\t"
    944        "ja     2f                                               \n\t"
    945        "je     1f                                               \n\t"
    946        "movl   $" RT_XSTR(VERR_VMX_INVALID_VMCS_PTR)", %0       \n\t"
    947        "jmp    2f                                               \n\t"
    948        "1:                                                      \n\t"
    949        "movl   $" RT_XSTR(VERR_VMX_INVALID_VMCS_FIELD)", %0     \n\t"
    950        "2:                                                      \n\t"
    951        :"=rm"(rc)
    952        :"0"(VINF_SUCCESS),
    953         "a"(uFieldEnc),
    954         "d"(u32Val)
    955        );
    956     return rc;
    957 
    958 # elif VMX_USE_MSC_INTRINSICS
    959      unsigned char rcMsc = __vmx_vmwrite(uFieldEnc, u32Val);
    960      if (RT_LIKELY(rcMsc == 0))
    961          return VINF_SUCCESS;
    962      return rcMsc == 2 ? VERR_VMX_INVALID_VMCS_PTR : VERR_VMX_INVALID_VMCS_FIELD;
    963 
    964 #else
    965     int rc = VINF_SUCCESS;
    966     __asm
    967     {
    968         push   dword ptr [u32Val]
    969         mov    eax, [uFieldEnc]
    970         _emit  0x0f
    971         _emit  0x79
    972         _emit  0x04
    973         _emit  0x24     /* VMWRITE eax, [esp] */
    974         jnc    valid_vmcs
    975         mov    dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
    976         jmp    the_end
    977 
    978 valid_vmcs:
    979         jnz    the_end
    980         mov    dword ptr [rc], VERR_VMX_INVALID_VMCS_FIELD
    981 the_end:
    982         add    esp, 4
    983     }
    984     return rc;
    985 # endif
    986 }
    987 #endif
    988 #endif
    989 
    990 
    991741/**
    992742 * Executes VMWRITE for a 64-bit field.
     
    1051801# endif
    1052802}
    1053 #endif
    1054 
    1055 
    1056 #if 0
    1057 #if (defined(RT_ARCH_AMD64) && VMX_USE_MSC_INTRINSICS)
    1058 DECLINLINE(int) VMXWriteVmcs64(uint32_t uFieldEnc, uint64_t u64Val)
    1059 {
    1060     unsigned char rcMsc = __vmx_vmwrite(uFieldEnc, u64Val);
    1061     if (RT_LIKELY(rcMsc == 0))
    1062         return VINF_SUCCESS;
    1063     return rcMsc == 2 ? VERR_VMX_INVALID_VMCS_PTR : VERR_VMX_INVALID_VMCS_FIELD;
    1064 }
    1065 #else
    1066 DECLASM(int) VMXWriteVmcs64(uint32_t uFieldEnc, uint64_t u64Val);
    1067 #endif
    1068803#endif
    1069804
     
    1213948#endif
    1214949
    1215 #if 0
    1216 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)
    1217 DECLASM(int) VMXReadVmcs32(uint32_t uFieldEnc, uint32_t *pData);
     950
     951/**
     952 * Executes VMREAD for a 64-bit field.
     953 *
     954 * @returns VBox status code.
     955 * @retval  VINF_SUCCESS.
     956 * @retval  VERR_VMX_INVALID_VMCS_PTR.
     957 * @retval  VERR_VMX_INVALID_VMCS_FIELD.
     958 *
     959 * @param   uFieldEnc       The VMCS field encoding.
     960 * @param   pData           Where to store VMCS field value.
     961 *
     962 * @remarks The values of the two status codes can be OR'ed together, the result
     963 *          will be VERR_VMX_INVALID_VMCS_PTR.
     964 */
     965#if defined(RT_ARCH_X86) || (RT_INLINE_ASM_EXTERNAL && !VMX_USE_MSC_INTRINSICS)
     966DECLASM(int) VMXReadVmcs64(uint32_t uFieldEnc, uint64_t *pData);
    1218967#else
    1219 DECLINLINE(int) VMXReadVmcs32(uint32_t uFieldEnc, uint32_t *pData)
    1220 {
    1221 # if RT_INLINE_ASM_GNU_STYLE
    1222     int rc = VINF_SUCCESS;
     968DECLINLINE(int) VMXReadVmcs64(uint32_t uFieldEnc, uint64_t *pData)
     969{
     970# if VMX_USE_MSC_INTRINSICS
     971#  ifdef VBOX_WITH_VMREAD_VMWRITE_NOCHECK
     972    __vmx_vmread(uFieldEnc, pData);
     973    return VINF_SUCCESS;
     974#  else
     975    unsigned char rcMsc;
     976    rcMsc = __vmx_vmread(uFieldEnc, pData);
     977    if (RT_LIKELY(rcMsc == 0))
     978        return VINF_SUCCESS;
     979    return rcMsc == 2 ? VERR_VMX_INVALID_VMCS_PTR : VERR_VMX_INVALID_VMCS_FIELD;
     980#  endif
     981
     982# elif RT_INLINE_ASM_GNU_STYLE
     983#  ifdef VBOX_WITH_VMREAD_VMWRITE_NOCHECK
     984    __asm__ __volatile__ (
     985       ".byte  0x0f, 0x78, 0xc2        # VMREAD eax, edx         \n\t"
     986       :"=d"(*pData)
     987       :"a"(uFieldEnc),
     988        "d"(0)
     989       );
     990    return VINF_SUCCESS;
     991#  else
     992    int rc;
    1223993    __asm__ __volatile__ (
    1224994       "movl   $" RT_XSTR(VINF_SUCCESS)", %0                     \n\t"
     
    12371007       );
    12381008    return rc;
    1239 
    1240 # elif VMX_USE_MSC_INTRINSICS
    1241     unsigned char rcMsc;
    1242 #  ifdef RT_ARCH_X86
    1243     rcMsc = __vmx_vmread(uFieldEnc, pData);
    1244 #  else
    1245     uint64_t u64Tmp;
    1246     rcMsc = __vmx_vmread(uFieldEnc, &u64Tmp);
    1247     *pData = (uint32_t)u64Tmp;
    1248 #  endif
    1249     if (RT_LIKELY(rcMsc == 0))
    1250         return VINF_SUCCESS;
    1251     return rcMsc == 2 ? VERR_VMX_INVALID_VMCS_PTR : VERR_VMX_INVALID_VMCS_FIELD;
    1252 
    1253 #else
    1254     int rc = VINF_SUCCESS;
    1255     __asm
    1256     {
    1257         sub     esp, 4
    1258         mov     dword ptr [esp], 0
    1259         mov     eax, [uFieldEnc]
    1260         _emit   0x0f
    1261         _emit   0x78
    1262         _emit   0x04
    1263         _emit   0x24     /* VMREAD eax, [esp] */
    1264         mov     edx, pData
    1265         pop     dword ptr [edx]
    1266         jnc     valid_vmcs
    1267         mov     dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR
    1268         jmp     the_end
    1269 
    1270 valid_vmcs:
    1271         jnz     the_end
    1272         mov     dword ptr [rc], VERR_VMX_INVALID_VMCS_FIELD
    1273 the_end:
    1274     }
    1275     return rc;
    1276 # endif
    1277 }
    1278 #endif
    1279 #endif
    1280 
    1281 
    1282 /**
    1283  * Executes VMREAD for a 64-bit field.
    1284  *
    1285  * @returns VBox status code.
    1286  * @retval  VINF_SUCCESS.
    1287  * @retval  VERR_VMX_INVALID_VMCS_PTR.
    1288  * @retval  VERR_VMX_INVALID_VMCS_FIELD.
    1289  *
    1290  * @param   uFieldEnc       The VMCS field encoding.
    1291  * @param   pData           Where to store VMCS field value.
    1292  *
    1293  * @remarks The values of the two status codes can be OR'ed together, the result
    1294  *          will be VERR_VMX_INVALID_VMCS_PTR.
    1295  */
    1296 #if defined(RT_ARCH_X86) || (RT_INLINE_ASM_EXTERNAL && !VMX_USE_MSC_INTRINSICS)
    1297 DECLASM(int) VMXReadVmcs64(uint32_t uFieldEnc, uint64_t *pData);
    1298 #else
    1299 DECLINLINE(int) VMXReadVmcs64(uint32_t uFieldEnc, uint64_t *pData)
    1300 {
    1301 # if VMX_USE_MSC_INTRINSICS
    1302 #  ifdef VBOX_WITH_VMREAD_VMWRITE_NOCHECK
    1303     __vmx_vmread(uFieldEnc, pData);
    1304     return VINF_SUCCESS;
    1305 #  else
    1306     unsigned char rcMsc;
    1307     rcMsc = __vmx_vmread(uFieldEnc, pData);
    1308     if (RT_LIKELY(rcMsc == 0))
    1309         return VINF_SUCCESS;
    1310     return rcMsc == 2 ? VERR_VMX_INVALID_VMCS_PTR : VERR_VMX_INVALID_VMCS_FIELD;
    1311 #  endif
    1312 
    1313 # elif RT_INLINE_ASM_GNU_STYLE
    1314 #  ifdef VBOX_WITH_VMREAD_VMWRITE_NOCHECK
    1315     __asm__ __volatile__ (
    1316        ".byte  0x0f, 0x78, 0xc2        # VMREAD eax, edx         \n\t"
    1317        :"=d"(*pData)
    1318        :"a"(uFieldEnc),
    1319         "d"(0)
    1320        );
    1321     return VINF_SUCCESS;
    1322 #  else
    1323     int rc;
    1324     __asm__ __volatile__ (
    1325        "movl   $" RT_XSTR(VINF_SUCCESS)", %0                     \n\t"
    1326        ".byte  0x0f, 0x78, 0xc2        # VMREAD eax, edx         \n\t"
    1327        "ja     2f                                                \n\t"
    1328        "je     1f                                                \n\t"
    1329        "movl   $" RT_XSTR(VERR_VMX_INVALID_VMCS_PTR)", %0        \n\t"
    1330        "jmp    2f                                                \n\t"
    1331        "1:                                                       \n\t"
    1332        "movl   $" RT_XSTR(VERR_VMX_INVALID_VMCS_FIELD)", %0      \n\t"
    1333        "2:                                                       \n\t"
    1334        :"=&r"(rc),
    1335         "=d"(*pData)
    1336        :"a"(uFieldEnc),
    1337         "d"(0)
    1338        );
    1339     return rc;
    13401009#  endif
    13411010# else
     
    13431012# endif
    13441013}
    1345 #endif
    1346 
    1347 
    1348 #if 0
    1349 #if (!defined(RT_ARCH_X86) && !VMX_USE_MSC_INTRINSICS)
    1350 DECLASM(int) VMXReadVmcs64(uint32_t uFieldEnc, uint64_t *pData);
    1351 #else
    1352 DECLINLINE(int) VMXReadVmcs64(uint32_t uFieldEnc, uint64_t *pData)
    1353 {
    1354 # if VMX_USE_MSC_INTRINSICS
    1355     unsigned char rcMsc;
    1356 #  ifdef RT_ARCH_X86
    1357     size_t        uLow;
    1358     size_t        uHigh;
    1359     rcMsc  = __vmx_vmread(uFieldEnc, &uLow);
    1360     rcMsc |= __vmx_vmread(uFieldEnc + 1, &uHigh);
    1361     *pData = RT_MAKE_U64(uLow, uHigh);
    1362 # else
    1363     rcMsc = __vmx_vmread(uFieldEnc, pData);
    1364 # endif
    1365     if (RT_LIKELY(rcMsc == 0))
    1366         return VINF_SUCCESS;
    1367     return rcMsc == 2 ? VERR_VMX_INVALID_VMCS_PTR : VERR_VMX_INVALID_VMCS_FIELD;
    1368 
    1369 # elif defined(RT_ARCH_X86)
    1370     int rc;
    1371     uint32_t val_hi, val;
    1372     rc  = VMXReadVmcs32(uFieldEnc, &val);
    1373     rc |= VMXReadVmcs32(uFieldEnc + 1, &val_hi);
    1374     AssertRC(rc);
    1375     *pData = RT_MAKE_U64(val, val_hi);
    1376     return rc;
    1377 
    1378 # else
    1379 #  error "Shouldn't be here..."
    1380 # endif
    1381 }
    1382 #endif
    13831014#endif
    13841015
Note: See TracChangeset for help on using the changeset viewer.

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