Changeset 42707 in vbox for trunk/src/VBox/VMM/VMMAll/EMAll.cpp
- Timestamp:
- Aug 9, 2012 8:05:58 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/EMAll.cpp
r42374 r42707 47 47 #include <iprt/string.h> 48 48 49 #ifdef VBOX_WITH_IEM 50 # define VBOX_COMPARE_IEM_AND_EM /* debugging... */ 51 # define VBOX_SAME_AS_EM 52 #endif 49 53 50 54 /******************************************************************************* … … 70 74 * Internal Functions * 71 75 *******************************************************************************/ 72 #if ndef VBOX_WITH_IEM76 #if !defined(VBOX_WITH_IEM) || defined(VBOX_COMPARE_IEM_AND_EM) 73 77 DECLINLINE(VBOXSTRICTRC) emInterpretInstructionCPUOuter(PVMCPU pVCpu, PDISCPUSTATE pDis, PCPUMCTXCORE pRegFrame, 74 78 RTGCPTR pvFault, EMCODETYPE enmCodeType, uint32_t *pcbSize); 75 79 #endif 76 80 81 82 /******************************************************************************* 83 * Global Variables * 84 *******************************************************************************/ 85 #ifdef VBOX_COMPARE_IEM_AND_EM 86 static CPUMCTX g_IncomingCtx; 87 static CPUMCTX g_EmOutgoingCtx; 88 static bool g_fIgnoreRaxRdx = false; 89 #endif 77 90 78 91 … … 427 440 428 441 442 #ifdef VBOX_COMPARE_IEM_AND_EM 443 static void emCompareWithIem(PVMCPU pVCpu, PCCPUMCTX pIemCtx, VBOXSTRICTRC rcEm, VBOXSTRICTRC rcIem, 444 uint32_t cbEm, uint32_t cbIem) 445 { 446 /* Quick compare. */ 447 PCCPUMCTX pEmCtx = &g_EmOutgoingCtx; 448 if ( rcEm == rcIem 449 && cbEm == cbIem 450 && memcmp(pIemCtx, pEmCtx, sizeof(*pIemCtx)) == 0) 451 return; 452 453 /* Report exact differences. */ 454 RTLogPrintf("!! EM and IEM differs at %04x:%08RGv !!\n", g_IncomingCtx.cs.Sel, g_IncomingCtx.rip); 455 if (rcEm != rcIem) 456 RTLogPrintf(" * rcIem=%Rrc rcEm=%Rrc\n", VBOXSTRICTRC_VAL(rcIem), VBOXSTRICTRC_VAL(rcEm)); 457 else if (cbEm != cbIem) 458 RTLogPrintf(" * cbIem=%#x cbEm=%#x\n", cbIem, cbEm); 459 460 if (rcEm == rcIem) 461 { 462 # define CHECK_FIELD(a_Field) \ 463 do \ 464 { \ 465 if (pEmCtx->a_Field != pIemCtx->a_Field) \ 466 { \ 467 switch (sizeof(pEmCtx->a_Field)) \ 468 { \ 469 case 1: RTLogPrintf(" %8s differs - iem=%02x - em=%02x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \ 470 case 2: RTLogPrintf(" %8s differs - iem=%04x - em=%04x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \ 471 case 4: RTLogPrintf(" %8s differs - iem=%08x - em=%08x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \ 472 case 8: RTLogPrintf(" %8s differs - iem=%016llx - em=%016llx\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); break; \ 473 default: RTLogPrintf(" %8s differs\n", #a_Field); break; \ 474 } \ 475 cDiffs++; \ 476 } \ 477 } while (0) 478 479 # define CHECK_BIT_FIELD(a_Field) \ 480 do \ 481 { \ 482 if (pEmCtx->a_Field != pIemCtx->a_Field) \ 483 { \ 484 RTLogPrintf(" %8s differs - iem=%02x - em=%02x\n", #a_Field, pIemCtx->a_Field, pEmCtx->a_Field); \ 485 cDiffs++; \ 486 } \ 487 } while (0) 488 489 # define CHECK_SEL(a_Sel) \ 490 do \ 491 { \ 492 CHECK_FIELD(a_Sel.Sel); \ 493 CHECK_FIELD(a_Sel.Attr.u); \ 494 CHECK_FIELD(a_Sel.u64Base); \ 495 CHECK_FIELD(a_Sel.u32Limit); \ 496 CHECK_FIELD(a_Sel.fFlags); \ 497 } while (0) 498 499 unsigned cDiffs = 0; 500 if (memcmp(&pEmCtx->fpu, &pIemCtx->fpu, sizeof(pIemCtx->fpu))) 501 { 502 RTLogPrintf(" the FPU state differs\n"); 503 cDiffs++; 504 CHECK_FIELD(fpu.FCW); 505 CHECK_FIELD(fpu.FSW); 506 CHECK_FIELD(fpu.FTW); 507 CHECK_FIELD(fpu.FOP); 508 CHECK_FIELD(fpu.FPUIP); 509 CHECK_FIELD(fpu.CS); 510 CHECK_FIELD(fpu.Rsrvd1); 511 CHECK_FIELD(fpu.FPUDP); 512 CHECK_FIELD(fpu.DS); 513 CHECK_FIELD(fpu.Rsrvd2); 514 CHECK_FIELD(fpu.MXCSR); 515 CHECK_FIELD(fpu.MXCSR_MASK); 516 CHECK_FIELD(fpu.aRegs[0].au64[0]); CHECK_FIELD(fpu.aRegs[0].au64[1]); 517 CHECK_FIELD(fpu.aRegs[1].au64[0]); CHECK_FIELD(fpu.aRegs[1].au64[1]); 518 CHECK_FIELD(fpu.aRegs[2].au64[0]); CHECK_FIELD(fpu.aRegs[2].au64[1]); 519 CHECK_FIELD(fpu.aRegs[3].au64[0]); CHECK_FIELD(fpu.aRegs[3].au64[1]); 520 CHECK_FIELD(fpu.aRegs[4].au64[0]); CHECK_FIELD(fpu.aRegs[4].au64[1]); 521 CHECK_FIELD(fpu.aRegs[5].au64[0]); CHECK_FIELD(fpu.aRegs[5].au64[1]); 522 CHECK_FIELD(fpu.aRegs[6].au64[0]); CHECK_FIELD(fpu.aRegs[6].au64[1]); 523 CHECK_FIELD(fpu.aRegs[7].au64[0]); CHECK_FIELD(fpu.aRegs[7].au64[1]); 524 CHECK_FIELD(fpu.aXMM[ 0].au64[0]); CHECK_FIELD(fpu.aXMM[ 0].au64[1]); 525 CHECK_FIELD(fpu.aXMM[ 1].au64[0]); CHECK_FIELD(fpu.aXMM[ 1].au64[1]); 526 CHECK_FIELD(fpu.aXMM[ 2].au64[0]); CHECK_FIELD(fpu.aXMM[ 2].au64[1]); 527 CHECK_FIELD(fpu.aXMM[ 3].au64[0]); CHECK_FIELD(fpu.aXMM[ 3].au64[1]); 528 CHECK_FIELD(fpu.aXMM[ 4].au64[0]); CHECK_FIELD(fpu.aXMM[ 4].au64[1]); 529 CHECK_FIELD(fpu.aXMM[ 5].au64[0]); CHECK_FIELD(fpu.aXMM[ 5].au64[1]); 530 CHECK_FIELD(fpu.aXMM[ 6].au64[0]); CHECK_FIELD(fpu.aXMM[ 6].au64[1]); 531 CHECK_FIELD(fpu.aXMM[ 7].au64[0]); CHECK_FIELD(fpu.aXMM[ 7].au64[1]); 532 CHECK_FIELD(fpu.aXMM[ 8].au64[0]); CHECK_FIELD(fpu.aXMM[ 8].au64[1]); 533 CHECK_FIELD(fpu.aXMM[ 9].au64[0]); CHECK_FIELD(fpu.aXMM[ 9].au64[1]); 534 CHECK_FIELD(fpu.aXMM[10].au64[0]); CHECK_FIELD(fpu.aXMM[10].au64[1]); 535 CHECK_FIELD(fpu.aXMM[11].au64[0]); CHECK_FIELD(fpu.aXMM[11].au64[1]); 536 CHECK_FIELD(fpu.aXMM[12].au64[0]); CHECK_FIELD(fpu.aXMM[12].au64[1]); 537 CHECK_FIELD(fpu.aXMM[13].au64[0]); CHECK_FIELD(fpu.aXMM[13].au64[1]); 538 CHECK_FIELD(fpu.aXMM[14].au64[0]); CHECK_FIELD(fpu.aXMM[14].au64[1]); 539 CHECK_FIELD(fpu.aXMM[15].au64[0]); CHECK_FIELD(fpu.aXMM[15].au64[1]); 540 for (unsigned i = 0; i < RT_ELEMENTS(pEmCtx->fpu.au32RsrvdRest); i++) 541 CHECK_FIELD(fpu.au32RsrvdRest[i]); 542 } 543 CHECK_FIELD(rip); 544 if (pEmCtx->rflags.u != pIemCtx->rflags.u) 545 { 546 RTLogPrintf(" rflags differs - iem=%08llx em=%08llx\n", pIemCtx->rflags.u, pEmCtx->rflags.u); 547 CHECK_BIT_FIELD(rflags.Bits.u1CF); 548 CHECK_BIT_FIELD(rflags.Bits.u1Reserved0); 549 CHECK_BIT_FIELD(rflags.Bits.u1PF); 550 CHECK_BIT_FIELD(rflags.Bits.u1Reserved1); 551 CHECK_BIT_FIELD(rflags.Bits.u1AF); 552 CHECK_BIT_FIELD(rflags.Bits.u1Reserved2); 553 CHECK_BIT_FIELD(rflags.Bits.u1ZF); 554 CHECK_BIT_FIELD(rflags.Bits.u1SF); 555 CHECK_BIT_FIELD(rflags.Bits.u1TF); 556 CHECK_BIT_FIELD(rflags.Bits.u1IF); 557 CHECK_BIT_FIELD(rflags.Bits.u1DF); 558 CHECK_BIT_FIELD(rflags.Bits.u1OF); 559 CHECK_BIT_FIELD(rflags.Bits.u2IOPL); 560 CHECK_BIT_FIELD(rflags.Bits.u1NT); 561 CHECK_BIT_FIELD(rflags.Bits.u1Reserved3); 562 CHECK_BIT_FIELD(rflags.Bits.u1RF); 563 CHECK_BIT_FIELD(rflags.Bits.u1VM); 564 CHECK_BIT_FIELD(rflags.Bits.u1AC); 565 CHECK_BIT_FIELD(rflags.Bits.u1VIF); 566 CHECK_BIT_FIELD(rflags.Bits.u1VIP); 567 CHECK_BIT_FIELD(rflags.Bits.u1ID); 568 } 569 570 if (!g_fIgnoreRaxRdx) 571 CHECK_FIELD(rax); 572 CHECK_FIELD(rcx); 573 if (!g_fIgnoreRaxRdx) 574 CHECK_FIELD(rdx); 575 CHECK_FIELD(rbx); 576 CHECK_FIELD(rsp); 577 CHECK_FIELD(rbp); 578 CHECK_FIELD(rsi); 579 CHECK_FIELD(rdi); 580 CHECK_FIELD(r8); 581 CHECK_FIELD(r9); 582 CHECK_FIELD(r10); 583 CHECK_FIELD(r11); 584 CHECK_FIELD(r12); 585 CHECK_FIELD(r13); 586 CHECK_SEL(cs); 587 CHECK_SEL(ss); 588 CHECK_SEL(ds); 589 CHECK_SEL(es); 590 CHECK_SEL(fs); 591 CHECK_SEL(gs); 592 CHECK_FIELD(cr0); 593 CHECK_FIELD(cr2); 594 CHECK_FIELD(cr3); 595 CHECK_FIELD(cr4); 596 CHECK_FIELD(dr[0]); 597 CHECK_FIELD(dr[1]); 598 CHECK_FIELD(dr[2]); 599 CHECK_FIELD(dr[3]); 600 CHECK_FIELD(dr[6]); 601 CHECK_FIELD(dr[7]); 602 CHECK_FIELD(gdtr.cbGdt); 603 CHECK_FIELD(gdtr.pGdt); 604 CHECK_FIELD(idtr.cbIdt); 605 CHECK_FIELD(idtr.pIdt); 606 CHECK_SEL(ldtr); 607 CHECK_SEL(tr); 608 CHECK_FIELD(SysEnter.cs); 609 CHECK_FIELD(SysEnter.eip); 610 CHECK_FIELD(SysEnter.esp); 611 CHECK_FIELD(msrEFER); 612 CHECK_FIELD(msrSTAR); 613 CHECK_FIELD(msrPAT); 614 CHECK_FIELD(msrLSTAR); 615 CHECK_FIELD(msrCSTAR); 616 CHECK_FIELD(msrSFMASK); 617 CHECK_FIELD(msrKERNELGSBASE); 618 619 # undef CHECK_FIELD 620 # undef CHECK_BIT_FIELD 621 } 622 } 623 #endif /* VBOX_COMPARE_IEM_AND_EM */ 624 625 429 626 /** 430 627 * Interprets the current instruction. … … 451 648 #ifdef VBOX_WITH_IEM 452 649 NOREF(pvFault); 453 VBOXSTRICTRC rc = IEMExecOneEx(pVCpu, pRegFrame, NULL); 650 651 # ifdef VBOX_COMPARE_IEM_AND_EM 652 PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu); 653 g_IncomingCtx = *pCtx; 654 655 /* EM */ 656 RTGCPTR pbCode; 657 VBOXSTRICTRC rcEm = SELMToFlatEx(pVCpu, DISSELREG_CS, pRegFrame, pRegFrame->rip, 0, &pbCode); 658 if (RT_SUCCESS(rcEm)) 659 { 660 uint32_t cbOp; 661 PDISCPUSTATE pDis = &pVCpu->em.s.DisState; 662 pDis->uCpuMode = CPUMGetGuestDisMode(pVCpu); 663 rcEm = emDisCoreOne(pVCpu->CTX_SUFF(pVM), pVCpu, pDis, (RTGCUINTPTR)pbCode, &cbOp); 664 if (RT_SUCCESS(rcEm)) 665 { 666 Assert(cbOp == pDis->cbInstr); 667 uint32_t cbIgnored; 668 rcEm = emInterpretInstructionCPUOuter(pVCpu, pDis, pRegFrame, pvFault, EMCODETYPE_SUPERVISOR, &cbIgnored); 669 if (RT_SUCCESS(rcEm)) 670 pRegFrame->rip += cbOp; /* Move on to the next instruction. */ 671 672 } 673 rcEm = VERR_EM_INTERPRETER; 674 } 675 else 676 rcEm = VERR_EM_INTERPRETER; 677 # ifdef VBOX_SAME_AS_EM 678 if (rcEm == VERR_EM_INTERPRETER) 679 { 680 Log(("EMInterpretInstruction: returns %Rrc\n", VBOXSTRICTRC_VAL(rcEm))); 681 return rcEm; 682 } 683 # endif 684 685 g_EmOutgoingCtx = *pCtx; 686 *pCtx = g_IncomingCtx; 687 688 /* IEM */ 689 # endif /* VBOX_COMPARE_IEM_AND_EM */ 690 VBOXSTRICTRC rc = IEMExecOneBypassEx(pVCpu, pRegFrame, NULL); 454 691 if (RT_UNLIKELY( rc == VERR_IEM_ASPECT_NOT_IMPLEMENTED 455 692 || rc == VERR_IEM_INSTR_NOT_IMPLEMENTED)) 456 return VERR_EM_INTERPRETER; 693 rc = VERR_EM_INTERPRETER; 694 695 # ifdef VBOX_COMPARE_IEM_AND_EM 696 emCompareWithIem(pVCpu, pCtx, rcEm, rc, 0, 0); 697 # endif 698 if (rc != VINF_SUCCESS) 699 Log(("EMInterpretInstruction: returns %Rrc\n", VBOXSTRICTRC_VAL(rc))); 700 457 701 return rc; 458 702 #else … … 506 750 #ifdef VBOX_WITH_IEM 507 751 NOREF(pvFault); 508 VBOXSTRICTRC rc = IEMExecOneEx(pVCpu, pRegFrame, pcbWritten); 752 753 # ifdef VBOX_COMPARE_IEM_AND_EM 754 PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu); 755 g_IncomingCtx = *pCtx; 756 757 /* EM */ 758 uint32_t cbEmWritten = 0; 759 RTGCPTR pbCode; 760 VBOXSTRICTRC rcEm = SELMToFlatEx(pVCpu, DISSELREG_CS, pRegFrame, pRegFrame->rip, 0, &pbCode); 761 if (RT_SUCCESS(rcEm)) 762 { 763 uint32_t cbOp; 764 PDISCPUSTATE pDis = &pVCpu->em.s.DisState; 765 pDis->uCpuMode = CPUMGetGuestDisMode(pVCpu); 766 rcEm = emDisCoreOne(pVCpu->CTX_SUFF(pVM), pVCpu, pDis, (RTGCUINTPTR)pbCode, &cbOp); 767 if (RT_SUCCESS(rcEm)) 768 { 769 Assert(cbOp == pDis->cbInstr); 770 rcEm = emInterpretInstructionCPUOuter(pVCpu, pDis, pRegFrame, pvFault, EMCODETYPE_SUPERVISOR, &cbEmWritten); 771 if (RT_SUCCESS(rcEm)) 772 pRegFrame->rip += cbOp; /* Move on to the next instruction. */ 773 774 } 775 else 776 rcEm = VERR_EM_INTERPRETER; 777 } 778 else 779 rcEm = VERR_EM_INTERPRETER; 780 # ifdef VBOX_SAME_AS_EM 781 if (rcEm == VERR_EM_INTERPRETER) 782 { 783 Log(("EMInterpretInstruction: returns %Rrc\n", VBOXSTRICTRC_VAL(rcEm))); 784 return rcEm; 785 } 786 # endif 787 788 g_EmOutgoingCtx = *pCtx; 789 *pCtx = g_IncomingCtx; 790 791 /* IEM */ 792 # endif /* VBOX_COMPARE_IEM_AND_EM */ 793 VBOXSTRICTRC rc = IEMExecOneBypassEx(pVCpu, pRegFrame, pcbWritten); 509 794 if (RT_UNLIKELY( rc == VERR_IEM_ASPECT_NOT_IMPLEMENTED 510 795 || rc == VERR_IEM_INSTR_NOT_IMPLEMENTED)) 511 return VERR_EM_INTERPRETER; 796 rc = VERR_EM_INTERPRETER; 797 798 # ifdef VBOX_COMPARE_IEM_AND_EM 799 emCompareWithIem(pVCpu, pCtx, rcEm, rc, cbEmWritten, *pcbWritten); 800 # endif 801 if (rc != VINF_SUCCESS) 802 Log(("EMInterpretInstructionEx: returns %Rrc\n", VBOXSTRICTRC_VAL(rc))); 803 512 804 return rc; 513 805 #else … … 570 862 #ifdef VBOX_WITH_IEM 571 863 NOREF(pDis); NOREF(pvFault); NOREF(enmCodeType); 572 VBOXSTRICTRC rc = IEMExecOneWithPrefetchedByPC(pVCpu, pRegFrame, pRegFrame->rip, pDis->abInstr, pDis->cbCachedInstr); 864 865 # ifdef VBOX_COMPARE_IEM_AND_EM 866 PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu); 867 g_IncomingCtx = *pCtx; 868 869 /* EM */ 870 uint32_t cbIgnored; 871 VBOXSTRICTRC rcEm = emInterpretInstructionCPUOuter(pVCpu, pDis, pRegFrame, pvFault, enmCodeType, &cbIgnored); 872 if (RT_SUCCESS(rcEm)) 873 pRegFrame->rip += pDis->cbInstr; /* Move on to the next instruction. */ 874 # ifdef VBOX_SAME_AS_EM 875 if (rcEm == VERR_EM_INTERPRETER) 876 { 877 Log(("EMInterpretInstruction: returns %Rrc\n", VBOXSTRICTRC_VAL(rcEm))); 878 return rcEm; 879 } 880 # endif 881 882 g_EmOutgoingCtx = *pCtx; 883 *pCtx = g_IncomingCtx; 884 885 /* IEM */ 886 # endif 887 VBOXSTRICTRC rc = IEMExecOneBypassWithPrefetchedByPC(pVCpu, pRegFrame, pRegFrame->rip, pDis->abInstr, pDis->cbCachedInstr); 573 888 if (RT_UNLIKELY( rc == VERR_IEM_ASPECT_NOT_IMPLEMENTED 574 889 || rc == VERR_IEM_INSTR_NOT_IMPLEMENTED)) 575 return VERR_EM_INTERPRETER; 890 rc = VERR_EM_INTERPRETER; 891 892 # ifdef VBOX_COMPARE_IEM_AND_EM 893 emCompareWithIem(pVCpu, pCtx, rcEm, rc, 0, 0); 894 # endif 895 if (rc != VINF_SUCCESS) 896 Log(("EMInterpretInstructionDisasState: returns %Rrc\n", VBOXSTRICTRC_VAL(rc))); 897 576 898 return rc; 577 899 #else … … 715 1037 pRegFrame->rax = (uint32_t)uTicks; 716 1038 pRegFrame->rdx = (uTicks >> 32ULL); 1039 #ifdef VBOX_COMPARE_IEM_AND_EM 1040 g_fIgnoreRaxRdx = true; 1041 #endif 717 1042 718 1043 NOREF(pVM); … … 748 1073 pCtx->rax = (uint32_t)uTicks; 749 1074 pCtx->rdx = (uTicks >> 32ULL); 1075 #ifdef VBOX_COMPARE_IEM_AND_EM 1076 g_fIgnoreRaxRdx = true; 1077 #endif 750 1078 /* Low dword of the TSC_AUX msr only. */ 751 1079 CPUMQueryGuestMsr(pVCpu, MSR_K8_TSC_AUX, &pCtx->rcx); … … 921 1249 #endif 922 1250 rc = VINF_SUCCESS; 1251 #ifndef VBOX_COMPARE_IEM_AND_EM 923 1252 CPUMSetGuestCR0(pVCpu, val); 1253 #else 1254 CPUMQueryGuestCtxPtr(pVCpu)->cr0 = val | X86_CR0_ET; 1255 #endif 924 1256 val = CPUMGetGuestCR0(pVCpu); 925 1257 if ( (oldval & (X86_CR0_PG | X86_CR0_WP | X86_CR0_PE)) … … 1207 1539 1208 1540 1209 #if ndef VBOX_WITH_IEM1541 #if !defined(VBOX_WITH_IEM) || defined(VBOX_COMPARE_IEM_AND_EM) 1210 1542 1211 1543 … … 1247 1579 pages or write monitored pages. */ 1248 1580 NOREF(pVM); 1581 #ifndef VBOX_COMPARE_IEM_AND_EM 1249 1582 return PGMPhysInterpretedWriteNoHandlers(pVCpu, pCtxCore, GCPtrDst, pvSrc, cb, /*fMayTrap*/ false); 1583 #else 1584 return VINF_SUCCESS; 1585 #endif 1250 1586 } 1251 1587 … … 1701 2037 1702 2038 2039 #ifndef VBOX_COMPARE_IEM_AND_EM 1703 2040 /** 1704 2041 * LOCK XOR/OR/AND Emulation. … … 1773 2110 return VINF_SUCCESS; 1774 2111 } 2112 #endif /* !VBOX_COMPARE_IEM_AND_EM */ 1775 2113 1776 2114 … … 1960 2298 1961 2299 2300 #ifndef VBOX_COMPARE_IEM_AND_EM 1962 2301 /** 1963 2302 * LOCK BTR/C/S Emulation. … … 2022 2361 return VINF_SUCCESS; 2023 2362 } 2363 #endif /* !VBOX_COMPARE_IEM_AND_EM */ 2024 2364 2025 2365 … … 2367 2707 LogFlow(("%s %RGv rax=%RX64 %RX64\n", emGetMnemonic(pDis), GCPtrPar1, pRegFrame->rax, valpar)); 2368 2708 2709 #ifndef VBOX_COMPARE_IEM_AND_EM 2369 2710 if (pDis->fPrefix & DISPREFIX_LOCK) 2370 2711 eflags = EMEmulateLockCmpXchg(pvParam1, &pRegFrame->rax, valpar, pDis->Param2.cb); 2371 2712 else 2372 2713 eflags = EMEmulateCmpXchg(pvParam1, &pRegFrame->rax, valpar, pDis->Param2.cb); 2714 #else /* VBOX_COMPARE_IEM_AND_EM */ 2715 uint64_t u64; 2716 switch (pDis->Param2.cb) 2717 { 2718 case 1: u64 = *(uint8_t *)pvParam1; break; 2719 case 2: u64 = *(uint16_t *)pvParam1; break; 2720 case 4: u64 = *(uint32_t *)pvParam1; break; 2721 default: 2722 case 8: u64 = *(uint64_t *)pvParam1; break; 2723 } 2724 eflags = EMEmulateCmpXchg(&u64, &pRegFrame->rax, valpar, pDis->Param2.cb); 2725 #endif /* VBOX_COMPARE_IEM_AND_EM */ 2373 2726 2374 2727 LogFlow(("%s %RGv rax=%RX64 %RX64 ZF=%d\n", emGetMnemonic(pDis), GCPtrPar1, pRegFrame->rax, valpar, !!(eflags & X86_EFL_ZF))); … … 2420 2773 LogFlow(("%s %RGv=%08x eax=%08x\n", emGetMnemonic(pDis), pvParam1, pRegFrame->eax)); 2421 2774 2775 #ifndef VBOX_COMPARE_IEM_AND_EM 2422 2776 if (pDis->fPrefix & DISPREFIX_LOCK) 2423 2777 eflags = EMEmulateLockCmpXchg8b(pvParam1, &pRegFrame->eax, &pRegFrame->edx, pRegFrame->ebx, pRegFrame->ecx); 2424 2778 else 2425 2779 eflags = EMEmulateCmpXchg8b(pvParam1, &pRegFrame->eax, &pRegFrame->edx, pRegFrame->ebx, pRegFrame->ecx); 2780 #else /* VBOX_COMPARE_IEM_AND_EM */ 2781 uint64_t u64 = *(uint64_t *)pvParam1; 2782 eflags = EMEmulateCmpXchg8b(&u64, &pRegFrame->eax, &pRegFrame->edx, pRegFrame->ebx, pRegFrame->ecx); 2783 #endif /* VBOX_COMPARE_IEM_AND_EM */ 2426 2784 2427 2785 LogFlow(("%s %RGv=%08x eax=%08x ZF=%d\n", emGetMnemonic(pDis), pvParam1, pRegFrame->eax, !!(eflags & X86_EFL_ZF))); … … 2489 2847 LogFlow(("XAdd %RGv=%p reg=%08llx\n", GCPtrPar1, pvParam1, *(uint64_t *)pvParamReg2)); 2490 2848 2849 #ifndef VBOX_COMPARE_IEM_AND_EM 2491 2850 if (pDis->fPrefix & DISPREFIX_LOCK) 2492 2851 eflags = EMEmulateLockXAdd(pvParam1, pvParamReg2, cbParamReg2); 2493 2852 else 2494 2853 eflags = EMEmulateXAdd(pvParam1, pvParamReg2, cbParamReg2); 2854 #else /* VBOX_COMPARE_IEM_AND_EM */ 2855 uint64_t u64; 2856 switch (cbParamReg2) 2857 { 2858 case 1: u64 = *(uint8_t *)pvParam1; break; 2859 case 2: u64 = *(uint16_t *)pvParam1; break; 2860 case 4: u64 = *(uint32_t *)pvParam1; break; 2861 default: 2862 case 8: u64 = *(uint64_t *)pvParam1; break; 2863 } 2864 eflags = EMEmulateXAdd(&u64, pvParamReg2, cbParamReg2); 2865 #endif /* VBOX_COMPARE_IEM_AND_EM */ 2495 2866 2496 2867 LogFlow(("XAdd %RGv=%p reg=%08llx ZF=%d\n", GCPtrPar1, pvParam1, *(uint64_t *)pvParamReg2, !!(eflags & X86_EFL_ZF) )); … … 3000 3371 /* Get the current privilege level. */ 3001 3372 if (CPUMGetGuestCPL(pVCpu) != 0) 3373 { 3374 Log4(("EM: Refuse RDMSR: CPL != 0\n")); 3002 3375 return VERR_EM_INTERPRETER; /* supervisor only */ 3376 } 3003 3377 3004 3378 uint64_t uValue; … … 3007 3381 { 3008 3382 Assert(rc == VERR_CPUM_RAISE_GP_0); 3383 Log4(("EM: Refuse RDMSR: rc=%Rrc\n", rc)); 3009 3384 return VERR_EM_INTERPRETER; 3010 3385 } … … 3043 3418 /* Check the current privilege level, this instruction is supervisor only. */ 3044 3419 if (CPUMGetGuestCPL(pVCpu) != 0) 3420 { 3421 Log4(("EM: Refuse WRMSR: CPL != 0\n")); 3045 3422 return VERR_EM_INTERPRETER; /** @todo raise \#GP(0) */ 3423 } 3046 3424 3047 3425 int rc = CPUMSetGuestMsr(pVCpu, pRegFrame->ecx, RT_MAKE_U64(pRegFrame->eax, pRegFrame->edx)); … … 3049 3427 { 3050 3428 Assert(rc == VERR_CPUM_RAISE_GP_0); 3429 Log4(("EM: Refuse WRMSR: rc=%d\n", rc)); 3051 3430 return VERR_EM_INTERPRETER; 3052 3431 } … … 3129 3508 //Log(("EMInterpretInstruction: wrong prefix!!\n")); 3130 3509 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,FailedPrefix)); 3510 Log4(("EM: Refuse %u on REP/REPNE/LOCK prefix grounds\n", pDis->pCurInstr->uOpcode)); 3131 3511 return VERR_EM_INTERPRETER; 3132 3512 } … … 3208 3588 } 3209 3589 # endif /* VBOX_WITH_STATISTICS */ 3590 Log4(("EM: Refuse %u on grounds of accessing %u bytes\n", pDis->pCurInstr->uOpcode, pDis->Param1.cb)); 3210 3591 return VERR_EM_INTERPRETER; 3211 3592 } … … 3222 3603 * Macros for generating the right case statements. 3223 3604 */ 3224 # define INTERPRET_CASE_EX_LOCK_PARAM3(opcode, Instr, InstrFn, pfnEmulate, pfnEmulateLock) \ 3605 # ifndef VBOX_COMPARE_IEM_AND_EM 3606 # define INTERPRET_CASE_EX_LOCK_PARAM3(opcode, Instr, InstrFn, pfnEmulate, pfnEmulateLock) \ 3225 3607 case opcode:\ 3226 3608 if (pDis->fPrefix & DISPREFIX_LOCK) \ … … 3233 3615 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,Failed##Instr)); \ 3234 3616 return rc 3617 # else /* VBOX_COMPARE_IEM_AND_EM */ 3618 # define INTERPRET_CASE_EX_LOCK_PARAM3(opcode, Instr, InstrFn, pfnEmulate, pfnEmulateLock) \ 3619 case opcode:\ 3620 rc = emInterpret##InstrFn(pVM, pVCpu, pDis, pRegFrame, pvFault, pcbSize, pfnEmulate); \ 3621 if (RT_SUCCESS(rc)) \ 3622 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,Instr)); \ 3623 else \ 3624 STAM_COUNTER_INC(&pVCpu->em.s.CTX_SUFF(pStats)->CTX_MID_Z(Stat,Failed##Instr)); \ 3625 return rc 3626 # endif /* VBOX_COMPARE_IEM_AND_EM*/ 3627 3235 3628 #define INTERPRET_CASE_EX_PARAM3(opcode, Instr, InstrFn, pfnEmulate) \ 3236 3629 case opcode:\
Note:
See TracChangeset
for help on using the changeset viewer.