VirtualBox

Changeset 1986 in vbox


Ignore:
Timestamp:
Apr 9, 2007 10:22:30 AM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
20273
Message:

Btr emulation added. (possibly dangerous; not well tested)

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

Legend:

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

    r1943 r1986  
    11841184                /* All done! */
    11851185                *pcbSize = param2.size;
     1186                return VINF_SUCCESS;
     1187            }
     1188#ifdef IN_GC
     1189        }
     1190    }
     1191#endif
     1192    return VERR_EM_INTERPRETER;
     1193}
     1194
     1195/**
     1196 * BTR Emulation.
     1197 */
     1198static int emInterpretBtr(PVM pVM, PDISCPUSTATE pCpu, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, uint32_t *pcbSize)
     1199{
     1200    OP_PARAMVAL param1, param2;
     1201    int rc = DISQueryParamVal(pRegFrame, pCpu, &pCpu->param1, &param1, PARAM_DEST);
     1202    if(VBOX_FAILURE(rc))
     1203        return VERR_EM_INTERPRETER;
     1204
     1205    rc = DISQueryParamVal(pRegFrame, pCpu, &pCpu->param2, &param2, PARAM_SOURCE);
     1206    if(VBOX_FAILURE(rc))
     1207        return VERR_EM_INTERPRETER;
     1208
     1209#ifdef IN_GC
     1210    if (TRPMHasTrap(pVM))
     1211    {
     1212        if (TRPMGetErrorCode(pVM) & X86_TRAP_PF_RW)
     1213        {
     1214#endif
     1215            RTGCPTR  pParam1;
     1216            uint32_t valpar1, valpar2;
     1217
     1218            /* The destination is always a virtual address */
     1219            if (param1.type != PARMTYPE_ADDRESS)
     1220                return VERR_EM_INTERPRETER;
     1221
     1222            pParam1 = (RTGCPTR)param1.val.val32;
     1223            pParam1 = emConvertToFlatAddr(pVM, pRegFrame, pCpu, &pCpu->param1, pParam1);
     1224
     1225            /* Register or immediate data */
     1226            switch(param2.type)
     1227            {
     1228            case PARMTYPE_IMMEDIATE:    /* both immediate data and register (ugly) */
     1229                valpar2 = param2.val.val32;
     1230                break;
     1231
     1232            default:
     1233                AssertFailed();
     1234                return VERR_EM_INTERPRETER;
     1235            }
     1236
     1237            pParam1 = (RTGCPTR)((RTGCUINTPTR)pParam1 + valpar2/8);
     1238#ifdef IN_GC
     1239            /* Safety check. */
     1240            /** @todo cpu may access two or four bytes */
     1241            AssertReturn(pParam1 == pvFault, VERR_EM_INTERPRETER);
     1242#endif
     1243            rc = emRamRead(pVM, &valpar1, pParam1, 1);
     1244            if (VBOX_FAILURE(rc))
     1245            {
     1246                AssertMsgFailed(("emRamRead %VGv size=%d failed with %Vrc\n", pParam1, param1.size, rc));
     1247                return VERR_EM_INTERPRETER;
     1248            }
     1249
     1250            /* Data read, emulate BTR. */
     1251            uint32_t eflags = EMEmulateBtr(&valpar1, valpar2 & 0x7);
     1252
     1253            /* Update guest's eflags and finish. */
     1254            pRegFrame->eflags.u32 = (pRegFrame->eflags.u32 & ~(X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF))
     1255                                  | (eflags                &  (X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF | X86_EFL_OF));
     1256
     1257            /* And write it back */
     1258            rc = emRamWrite(pVM, pParam1, &valpar1, 1);
     1259            if (VBOX_SUCCESS(rc))
     1260            {
     1261                /* All done! */
     1262                *pcbSize = 1;
    11861263                return VINF_SUCCESS;
    11871264            }
     
    19432020        INTERPRET_CASE(OP_ADC,Adc);
    19442021        INTERPRET_CASE(OP_SUB,Sub);
     2022        INTERPRET_CASE(OP_BTR,Btr);
    19452023#ifdef IN_GC
    19462024        INTERPRET_CASE(OP_RDTSC,Rdtsc);
     
    19502028        INTERPRET_CASE(OP_IRET,Iret);
    19512029#ifdef VBOX_WITH_STATISTICS
    1952         INTERPRET_STAT_CASE(OP_BTR,Btr);
    19532030        INTERPRET_STAT_CASE(OP_BTS,Bts);
    19542031        INTERPRET_STAT_CASE(OP_CMPXCHG,CmpXchg);
  • trunk/src/VBox/VMM/VMMAll/EMAllA.asm

    r19 r1986  
    623623    retn
    624624ENDPROC     EMEmulateSub
     625
     626
     627;;
     628; Emulate BTR instruction, CDECL calling conv.
     629; EMDECL(uint32_t) EMEmulateBtr(uint32_t *pu32Param1, uint32_t u32Param2);
     630;
     631; @returns EFLAGS after the operation, only arithmetic flags is valid.
     632; @param    [esp + 04h]    Param 1 - First parameter - pointer to data item.
     633; @param    [esp + 08h]    Param 2 - Second parameter.
     634; @uses     eax, ecx, edx
     635;
     636align 16
     637BEGINPROC   EMEmulateBtr
     638%ifdef __AMD64__
     639%ifndef __WIN64__
     640    mov     rcx, rdi                    ; rcx = first parameter
     641    mov     rdx, rsi                    ; rdx = second parameter
     642%endif  ; !__WIN64__
     643%else   ; !__AMD64__
     644    mov     ecx, [esp + 04h]            ; ecx = first parameter
     645    mov     edx, [esp + 08h]            ; edx = second parameter
     646%endif
     647
     648    and     edx, 7
     649    btr    [MY_PTR_REG], edx
     650
     651    ; collect flags and return.
     652    pushf
     653    pop     MY_RET_REG
     654    retn
     655ENDPROC     EMEmulateBtr
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