VirtualBox

Changeset 1125 in vbox


Ignore:
Timestamp:
Mar 1, 2007 12:30:38 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
19022
Message:

Forward iret to V86 code to our trap handler for emulation.

Location:
trunk/src/VBox/VMM/PATM
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PATM/PATM.cpp

    r1086 r1125  
    243243    STAM_REG(pVM, &pVM->patm.s.StatSysEnter,          STAMTYPE_COUNTER, "/PATM/Emul/SysEnter",         STAMUNIT_OCCURENCES,     "Number of times sysenter was emulated.");
    244244    STAM_REG(pVM, &pVM->patm.s.StatSysExit,           STAMTYPE_COUNTER, "/PATM/Emul/SysExit" ,         STAMUNIT_OCCURENCES,     "Number of times sysexit was emulated.");
     245    STAM_REG(pVM, &pVM->patm.s.StatEmulIret,          STAMTYPE_COUNTER, "/PATM/Emul/Iret/Success",     STAMUNIT_OCCURENCES,     "Number of times iret was emulated.");
     246    STAM_REG(pVM, &pVM->patm.s.StatEmulIretFailed,    STAMTYPE_COUNTER, "/PATM/Emul/Iret/Failed",      STAMUNIT_OCCURENCES,     "Number of times iret was emulated.");
    245247
    246248    STAM_REG(pVM, &pVM->patm.s.StatGenRet,            STAMTYPE_COUNTER, "/PATM/Gen/Ret" ,         STAMUNIT_OCCURENCES,     "Number of generated ret instructions.");
  • trunk/src/VBox/VMM/PATM/PATMA.asm

    r1122 r1125  
    11281128    jnz     iret_fault1
    11291129
    1130     ; we can't do an iret to v86 code, as we run with CPL=1. The iret will attempt a protected mode iret and will (most likely) fault.
     1130    ; we can't do an iret to v86 code, as we run with CPL=1. The iret would attempt a protected mode iret and (most likely) fault.
    11311131    test    dword [esp+12], X86_EFL_VM
    11321132    jnz     iret_fault1
     1133;;    jnz     iret_return_to_v86
    11331134
    11341135    ;;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     
    11801181    ; Set IF again; below we make sure this won't cause problems.
    11811182    or      dword [ss:PATM_VMFLAGS], X86_EFL_IF
    1182     popfd
    11831183
    11841184    ; make sure iret is executed fully (including the iret below; cli ... iret can otherwise be interrupted)
    11851185    mov     dword [ss:PATM_INHIBITIRQADDR], PATM_CURINSTRADDR
     1186
     1187    popfd
    11861188    mov     dword [ss:PATM_INTERRUPTFLAG], 1
    11871189    iretd
     
    12371239    iretd
    12381240
     1241iret_return_to_v86:   
     1242    ; Go to our hypervisor trap handler to perform the iret to v86 code
     1243    mov     dword [ss:PATM_TEMP_EAX], eax
     1244    mov     dword [ss:PATM_TEMP_ECX], ecx
     1245    mov     dword [ss:PATM_TEMP_RESTORE_FLAGS], PATM_RESTORE_EAX | PATM_RESTORE_ECX
     1246    mov     eax, PATM_ACTION_DO_V86_IRET
     1247    lock    or dword [ss:PATM_PENDINGACTION], eax
     1248    mov     ecx, PATM_ACTION_MAGIC
     1249
     1250    popfd
     1251
     1252    db      0fh, 0bh        ; illegal instr (hardcoded assumption in PATMHandleIllegalInstrTrap)
     1253    ; does not return
     1254
     1255
    12391256iret_fault3:
    12401257    pop     eax
     
    12611278    DD      PATMIretEnd- PATMIretStart
    12621279%ifdef PATM_LOG_PATCHIRET
    1263     DD      22
     1280    DD      26
    12641281%else
    1265     DD      21
     1282    DD      25
    12661283%endif
    12671284    DD      PATM_INTERRUPTFLAG
     
    13101327    DD      0
    13111328    DD      PATM_VMFLAGS
     1329    DD      0
     1330    DD      PATM_TEMP_EAX
     1331    DD      0
     1332    DD      PATM_TEMP_ECX
     1333    DD      0
     1334    DD      PATM_TEMP_RESTORE_FLAGS
     1335    DD      0
     1336    DD      PATM_PENDINGACTION
    13121337    DD      0
    13131338    DD      0ffffffffh
  • trunk/src/VBox/VMM/PATM/PATMA.h

    r742 r1125  
    8484#define PATM_ACTION_DISPATCH_PENDING_IRQ        2
    8585#define PATM_ACTION_PENDING_IRQ_AFTER_IRET      3
    86 #define PATM_ACTION_LOG_IF1                     4
    87 #define PATM_ACTION_LOG_CLI                     5
    88 #define PATM_ACTION_LOG_STI                     6
    89 #define PATM_ACTION_LOG_POPF_IF1                7
    90 #define PATM_ACTION_LOG_POPF_IF0                8
    91 #define PATM_ACTION_LOG_PUSHF                   9
    92 #define PATM_ACTION_LOG_IRET                    10
    93 #define PATM_ACTION_LOG_RET                     11
    94 #define PATM_ACTION_LOG_CALL                    12
     86#define PATM_ACTION_DO_V86_IRET                 4
     87#define PATM_ACTION_LOG_IF1                     5
     88#define PATM_ACTION_LOG_CLI                     6
     89#define PATM_ACTION_LOG_STI                     7
     90#define PATM_ACTION_LOG_POPF_IF1                8
     91#define PATM_ACTION_LOG_POPF_IF0                9
     92#define PATM_ACTION_LOG_PUSHF                   10
     93#define PATM_ACTION_LOG_IRET                    11
     94#define PATM_ACTION_LOG_RET                     12
     95#define PATM_ACTION_LOG_CALL                    13
    9596
    9697/* Magic dword found in ecx for patm pending actions. */
  • trunk/src/VBox/VMM/PATM/PATMA.mac

    r742 r1125  
    8383%define PATM_ACTION_DISPATCH_PENDING_IRQ        2
    8484%define PATM_ACTION_PENDING_IRQ_AFTER_IRET      3
    85 %define PATM_ACTION_LOG_IF1                     4
    86 %define PATM_ACTION_LOG_CLI                     5
    87 %define PATM_ACTION_LOG_STI                     6
    88 %define PATM_ACTION_LOG_POPF_IF1                7
    89 %define PATM_ACTION_LOG_POPF_IF0                8
    90 %define PATM_ACTION_LOG_PUSHF                   9
    91 %define PATM_ACTION_LOG_IRET                    10
    92 %define PATM_ACTION_LOG_RET                     11
    93 %define PATM_ACTION_LOG_CALL                    12
     85%define PATM_ACTION_DO_V86_IRET                 4
     86%define PATM_ACTION_LOG_IF1                     5
     87%define PATM_ACTION_LOG_CLI                     6
     88%define PATM_ACTION_LOG_STI                     7
     89%define PATM_ACTION_LOG_POPF_IF1                8
     90%define PATM_ACTION_LOG_POPF_IF0                9
     91%define PATM_ACTION_LOG_PUSHF                   10
     92%define PATM_ACTION_LOG_IRET                    11
     93%define PATM_ACTION_LOG_RET                     12
     94%define PATM_ACTION_LOG_CALL                    13
    9495
    9596;/* Magic dword found in ecx for patm pending actions. */
  • trunk/src/VBox/VMM/PATM/PATMInternal.h

    r742 r1125  
    3737
    3838
    39 #define PATM_SSM_VERSION                    51
     39#define PATM_SSM_VERSION                    52
    4040
    4141/* Enable for call patching. */
     
    475475    STAMCOUNTER             StatSysEnter;
    476476    STAMCOUNTER             StatSysExit;
     477    STAMCOUNTER             StatEmulIret;
     478    STAMCOUNTER             StatEmulIretFailed;
    477479
    478480    STAMCOUNTER             StatInstrDirty;
  • trunk/src/VBox/VMM/PATM/VMMAll/PATMAll.cpp

    r1110 r1125  
    586586                return VINF_PATM_PENDING_IRQ_AFTER_IRET;
    587587
     588            case PATM_ACTION_DO_V86_IRET:
     589            {
     590                Log(("PATMGC: Do iret to V86 code; eip=%VGv\n", pRegFrame->eip));
     591                Assert(pVM->patm.s.CTXSUFF(pGCState)->Restore.uFlags == (PATM_RESTORE_EAX|PATM_RESTORE_ECX));
     592                Assert(pVM->patm.s.CTXSUFF(pGCState)->fPIF == 0);
     593
     594                pRegFrame->eax = pVM->patm.s.CTXSUFF(pGCState)->Restore.uEAX;
     595                pRegFrame->ecx = pVM->patm.s.CTXSUFF(pGCState)->Restore.uECX;
     596                pVM->patm.s.CTXSUFF(pGCState)->Restore.uFlags = 0;
     597
     598                /* We are no longer executing PATM code; set PIF again. */
     599                pVM->patm.s.CTXSUFF(pGCState)->fPIF = 1;
     600                rc = EMInterpretIret(pVM, pRegFrame);
     601                if (VBOX_SUCCESS(rc))
     602                    STAM_COUNTER_INC(&pVM->patm.s.StatEmulIret);
     603                else
     604                    STAM_COUNTER_INC(&pVM->patm.s.StatEmulIretFailed);
     605                return rc;
     606            }
     607
    588608#ifdef DEBUG
    589609            case PATM_ACTION_LOG_CLI:
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