Changeset 82684 in vbox for trunk/include/VBox
- Timestamp:
- Jan 9, 2020 8:01:50 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 135601
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/vmm/hmvmxinline.h
r80364 r82684 457 457 458 458 459 #if 0460 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)461 DECLASM(int) VMXEnable(RTHCPHYS HCPhysVmxOn);462 #else463 DECLINLINE(int) VMXEnable(RTHCPHYS HCPhysVmxOn)464 {465 # if RT_INLINE_ASM_GNU_STYLE466 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_INTRINSICS488 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 # else494 int rc = VINF_SUCCESS;495 __asm496 {497 push dword ptr [HCPhysVmxOn + 4]498 push dword ptr [HCPhysVmxOn]499 _emit 0xf3500 _emit 0x0f501 _emit 0xc7502 _emit 0x34503 _emit 0x24 /* VMXON [esp] */504 jnc vmxon_good505 mov dword ptr [rc], VERR_VMX_INVALID_VMXON_PTR506 jmp the_end507 508 vmxon_good:509 jnz the_end510 mov dword ptr [rc], VERR_VMX_VMXON_FAILED511 the_end:512 add esp, 8513 }514 return rc;515 # endif516 }517 #endif518 #endif519 520 521 459 /** 522 460 * Executes VMXOFF. … … 547 485 # endif 548 486 } 549 #endif550 551 552 #if 0553 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)554 DECLASM(void) VMXDisable(void);555 #else556 DECLINLINE(void) VMXDisable(void)557 {558 # if RT_INLINE_ASM_GNU_STYLE559 __asm__ __volatile__ (560 ".byte 0x0f, 0x01, 0xc4 # VMXOFF \n\t"561 );562 563 # elif VMX_USE_MSC_INTRINSICS564 __vmx_off();565 566 # else567 __asm568 {569 _emit 0x0f570 _emit 0x01571 _emit 0xc4 /* VMXOFF */572 }573 # endif574 }575 #endif576 487 #endif 577 488 … … 655 566 656 567 657 #if 0658 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)659 DECLASM(int) VMXClearVmcs(RTHCPHYS HCPhysVmcs);660 #else661 DECLINLINE(int) VMXClearVmcs(RTHCPHYS HCPhysVmcs)662 {663 # if RT_INLINE_ASM_GNU_STYLE664 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_INTRINSICS682 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 # else688 int rc = VINF_SUCCESS;689 __asm690 {691 push dword ptr [HCPhysVmcs + 4]692 push dword ptr [HCPhysVmcs]693 _emit 0x66694 _emit 0x0f695 _emit 0xc7696 _emit 0x34697 _emit 0x24 /* VMCLEAR [esp] */698 jnc success699 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR700 success:701 add esp, 8702 }703 return rc;704 # endif705 }706 #endif707 #endif708 709 710 568 /** 711 569 * Executes VMPTRLD. … … 782 640 # endif 783 641 } 784 #endif785 786 #if 0787 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)788 DECLASM(int) VMXLoadVmcs(RTHCPHYS HCPhysVmcs);789 #else790 DECLINLINE(int) VMXLoadVmcs(RTHCPHYS HCPhysVmcs)791 {792 # if RT_INLINE_ASM_GNU_STYLE793 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_INTRINSICS810 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 # else816 int rc = VINF_SUCCESS;817 __asm818 {819 push dword ptr [HCPhysVmcs + 4]820 push dword ptr [HCPhysVmcs]821 _emit 0x0f822 _emit 0xc7823 _emit 0x34824 _emit 0x24 /* VMPTRLD [esp] */825 jnc success826 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR827 828 success:829 add esp, 8830 }831 return rc;832 # endif833 }834 #endif835 642 #endif 836 643 … … 932 739 933 740 934 #if 0935 #if ((RT_INLINE_ASM_EXTERNAL || !defined(RT_ARCH_X86)) && !VMX_USE_MSC_INTRINSICS)936 DECLASM(int) VMXWriteVmcs32(uint32_t uFieldEnc, uint32_t u32Val);937 #else938 DECLINLINE(int) VMXWriteVmcs32(uint32_t uFieldEnc, uint32_t u32Val)939 {940 # if RT_INLINE_ASM_GNU_STYLE941 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_INTRINSICS959 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 #else965 int rc = VINF_SUCCESS;966 __asm967 {968 push dword ptr [u32Val]969 mov eax, [uFieldEnc]970 _emit 0x0f971 _emit 0x79972 _emit 0x04973 _emit 0x24 /* VMWRITE eax, [esp] */974 jnc valid_vmcs975 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR976 jmp the_end977 978 valid_vmcs:979 jnz the_end980 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_FIELD981 the_end:982 add esp, 4983 }984 return rc;985 # endif986 }987 #endif988 #endif989 990 991 741 /** 992 742 * Executes VMWRITE for a 64-bit field. … … 1051 801 # endif 1052 802 } 1053 #endif1054 1055 1056 #if 01057 #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 #else1066 DECLASM(int) VMXWriteVmcs64(uint32_t uFieldEnc, uint64_t u64Val);1067 #endif1068 803 #endif 1069 804 … … 1213 948 #endif 1214 949 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) 966 DECLASM(int) VMXReadVmcs64(uint32_t uFieldEnc, uint64_t *pData); 1218 967 #else 1219 DECLINLINE(int) VMXReadVmcs32(uint32_t uFieldEnc, uint32_t *pData) 1220 { 1221 # if RT_INLINE_ASM_GNU_STYLE 1222 int rc = VINF_SUCCESS; 968 DECLINLINE(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; 1223 993 __asm__ __volatile__ ( 1224 994 "movl $" RT_XSTR(VINF_SUCCESS)", %0 \n\t" … … 1237 1007 ); 1238 1008 return rc; 1239 1240 # elif VMX_USE_MSC_INTRINSICS1241 unsigned char rcMsc;1242 # ifdef RT_ARCH_X861243 rcMsc = __vmx_vmread(uFieldEnc, pData);1244 # else1245 uint64_t u64Tmp;1246 rcMsc = __vmx_vmread(uFieldEnc, &u64Tmp);1247 *pData = (uint32_t)u64Tmp;1248 # endif1249 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 #else1254 int rc = VINF_SUCCESS;1255 __asm1256 {1257 sub esp, 41258 mov dword ptr [esp], 01259 mov eax, [uFieldEnc]1260 _emit 0x0f1261 _emit 0x781262 _emit 0x041263 _emit 0x24 /* VMREAD eax, [esp] */1264 mov edx, pData1265 pop dword ptr [edx]1266 jnc valid_vmcs1267 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_PTR1268 jmp the_end1269 1270 valid_vmcs:1271 jnz the_end1272 mov dword ptr [rc], VERR_VMX_INVALID_VMCS_FIELD1273 the_end:1274 }1275 return rc;1276 # endif1277 }1278 #endif1279 #endif1280 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 result1294 * 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 #else1299 DECLINLINE(int) VMXReadVmcs64(uint32_t uFieldEnc, uint64_t *pData)1300 {1301 # if VMX_USE_MSC_INTRINSICS1302 # ifdef VBOX_WITH_VMREAD_VMWRITE_NOCHECK1303 __vmx_vmread(uFieldEnc, pData);1304 return VINF_SUCCESS;1305 # else1306 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 # endif1312 1313 # elif RT_INLINE_ASM_GNU_STYLE1314 # ifdef VBOX_WITH_VMREAD_VMWRITE_NOCHECK1315 __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 # else1323 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;1340 1009 # endif 1341 1010 # else … … 1343 1012 # endif 1344 1013 } 1345 #endif1346 1347 1348 #if 01349 #if (!defined(RT_ARCH_X86) && !VMX_USE_MSC_INTRINSICS)1350 DECLASM(int) VMXReadVmcs64(uint32_t uFieldEnc, uint64_t *pData);1351 #else1352 DECLINLINE(int) VMXReadVmcs64(uint32_t uFieldEnc, uint64_t *pData)1353 {1354 # if VMX_USE_MSC_INTRINSICS1355 unsigned char rcMsc;1356 # ifdef RT_ARCH_X861357 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 # else1363 rcMsc = __vmx_vmread(uFieldEnc, pData);1364 # endif1365 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 # else1379 # error "Shouldn't be here..."1380 # endif1381 }1382 #endif1383 1014 #endif 1384 1015
Note:
See TracChangeset
for help on using the changeset viewer.