VirtualBox

Changeset 41943 in vbox


Ignore:
Timestamp:
Jun 28, 2012 2:33:43 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
78811
Message:

VMM: Avoid stale selector issues in RC so there will be no need to try fix them by recursive trapping (this was broken for GS since forever anyways).

Location:
trunk
Files:
8 edited

Legend:

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

    r41940 r41943  
    357357VMMDECL(PCPUMCTX)       CPUMQueryGuestCtxPtr(PVMCPU pVCpu);
    358358VMMDECL(PCCPUMCTXCORE)  CPUMGetGuestCtxCore(PVMCPU pVCpu);
    359 VMMDECL(void)           CPUMSetGuestCtxCore(PVMCPU pVCpu, PCCPUMCTXCORE pCtxCore);
    360359VMMR3DECL(int)          CPUMR3RawEnter(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore);
    361360VMMR3DECL(int)          CPUMR3RawLeave(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, int rc);
  • trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp

    r41940 r41943  
    380380{
    381381    return CPUMCTX2CORE(&pVCpu->cpum.s.Guest);
    382 }
    383 
    384 
    385 /**
    386  * Sets the guest context core registers.
    387  *
    388  * @param   pVCpu       Handle to the virtual cpu.
    389  * @param   pCtxCore    The new context core values.
    390  */
    391 VMMDECL(void) CPUMSetGuestCtxCore(PVMCPU pVCpu, PCCPUMCTXCORE pCtxCore)
    392 {
    393     /** @todo #1410 requires selectors to be checked. (huh? 1410?) */
    394 
    395     PCPUMCTXCORE pCtxCoreDst = CPUMCTX2CORE(&pVCpu->cpum.s.Guest);
    396     *pCtxCoreDst = *pCtxCore;
    397 
    398     /* Mask away invalid parts of the cpu context. */
    399     if (!CPUMIsGuestInLongMode(pVCpu))
    400     {
    401         uint64_t u64Mask = UINT64_C(0xffffffff);
    402 
    403         pCtxCoreDst->rip        &= u64Mask;
    404         pCtxCoreDst->rax        &= u64Mask;
    405         pCtxCoreDst->rbx        &= u64Mask;
    406         pCtxCoreDst->rcx        &= u64Mask;
    407         pCtxCoreDst->rdx        &= u64Mask;
    408         pCtxCoreDst->rsi        &= u64Mask;
    409         pCtxCoreDst->rdi        &= u64Mask;
    410         pCtxCoreDst->rbp        &= u64Mask;
    411         pCtxCoreDst->rsp        &= u64Mask;
    412         pCtxCoreDst->rflags.u   &= u64Mask;
    413 
    414         pCtxCoreDst->r8         = 0;
    415         pCtxCoreDst->r9         = 0;
    416         pCtxCoreDst->r10        = 0;
    417         pCtxCoreDst->r11        = 0;
    418         pCtxCoreDst->r12        = 0;
    419         pCtxCoreDst->r13        = 0;
    420         pCtxCoreDst->r14        = 0;
    421         pCtxCoreDst->r15        = 0;
    422     }
    423382}
    424383
  • trunk/src/VBox/VMM/VMMRC/CPUMRC.cpp

    r41906 r41943  
    11/* $Id$ */
    22/** @file
    3  * CPUM - Guest Context Code.
     3 * CPUM - Raw-mode Context Code.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3535*******************************************************************************/
    3636RT_C_DECLS_BEGIN /* addressed from asm (not called so no DECLASM). */
    37 DECLCALLBACK(int) cpumGCHandleNPAndGP(PVM pVM, PCPUMCTXCORE pRegFrame, uintptr_t uUser);
     37DECLCALLBACK(int) cpumRCHandleNPAndGP(PVM pVM, PCPUMCTXCORE pRegFrame, uintptr_t uUser);
    3838RT_C_DECLS_END
    3939
    4040
    4141/**
    42  * Deal with traps occurring during segment loading and IRET
    43  * when resuming guest context.
     42 * Deal with traps occurring during segment loading and IRET when resuming guest
     43 * context execution.
    4444 *
    4545 * @returns VBox status code.
     
    4949 *                      CPUM_HANDLER_* \#defines.
    5050 */
    51 DECLCALLBACK(int) cpumGCHandleNPAndGP(PVM pVM, PCPUMCTXCORE pRegFrame, uintptr_t uUser)
     51DECLCALLBACK(int) cpumRCHandleNPAndGP(PVM pVM, PCPUMCTXCORE pRegFrame, uintptr_t uUser)
    5252{
    5353    Log(("********************************************************\n"));
    54     Log(("cpumGCHandleNPAndGP: eip=%RX32 uUser=%#x\n", pRegFrame->eip, uUser));
     54    Log(("cpumRCHandleNPAndGP: eip=%RX32 uUser=%#x\n", pRegFrame->eip, uUser));
    5555    Log(("********************************************************\n"));
    56 
    57     PVMCPU pVCpu = VMMGetCpu0(pVM);
    58 
    59     /*
    60      * Update the guest cpu state.
    61      */
    62     if (uUser & CPUM_HANDLER_CTXCORE_IN_EBP)
    63     {
    64         PCPUMCTXCORE  pGstCtxCore = (PCPUMCTXCORE)CPUMGetGuestCtxCore(pVCpu);
    65         PCCPUMCTXCORE pGstCtxCoreSrc = (PCPUMCTXCORE)pRegFrame->ebp;
    66         *pGstCtxCore = *pGstCtxCoreSrc;
    67     }
    6856
    6957    /*
     
    7361    {
    7462        case CPUM_HANDLER_GS:
    75         //    if (!pVM->cpum.s.Guest.ldtr)
    76         //    {
    77         //        pRegFrame->gs = 0;
    78         //        pRegFrame->eip += 6; /* mov gs, [edx + CPUM.Guest.gs] */
    79         //        return VINF_SUCCESS;
    80         //    }
    8163        case CPUM_HANDLER_DS:
    8264        case CPUM_HANDLER_ES:
     
    8567            break;
    8668
    87         /* Make sure we restore the guest context from the interrupt stack frame. */
    8869        case CPUM_HANDLER_IRET:
    89         {
    90             PCPUMCTXCORE  pGstCtxCore = (PCPUMCTXCORE)CPUMGetGuestCtxCore(pVCpu);
    91             uint32_t     *pEsp = (uint32_t *)pRegFrame->esp;
    92 
    93             /* Sync general purpose registers */
    94             *pGstCtxCore = *pRegFrame;
    95 
    96             pGstCtxCore->eip        = *pEsp++;
    97             pGstCtxCore->cs.Sel     = (RTSEL)*pEsp++;
    98             pGstCtxCore->eflags.u32 = *pEsp++;
    99             pGstCtxCore->esp        = *pEsp++;
    100             pGstCtxCore->ss.Sel     = (RTSEL)*pEsp++;
    101             if (pGstCtxCore->eflags.Bits.u1VM)
    102             {
    103                 pGstCtxCore->es.Sel = (RTSEL)*pEsp++;
    104                 pGstCtxCore->ds.Sel = (RTSEL)*pEsp++;
    105                 pGstCtxCore->fs.Sel = (RTSEL)*pEsp++;
    106                 pGstCtxCore->gs.Sel = (RTSEL)*pEsp++;
    107             }
    108 
    10970            TRPMGCHyperReturnToHost(pVM, VINF_EM_RAW_IRET_TRAP);
    11071            break;
    111         }
    11272    }
     73
     74    AssertMsgFailed(("uUser=%#x eip=%#x\n", uUser, pRegFrame->eip));
    11375    return VERR_TRPM_DONT_PANIC;
    11476}
  • trunk/src/VBox/VMM/VMMRC/CPUMRCA.asm

    r41931 r41943  
    11; $Id$
    22;; @file
    3 ; CPUM - Guest Context Assembly Routines.
    4 ;
    5 
    6 ; Copyright (C) 2006-2007 Oracle Corporation
     3; CPUM - Raw-mode Context Assembly Routines.
     4;
     5
     6; Copyright (C) 2006-2012 Oracle Corporation
    77;
    88; This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232extern IMPNAME(g_CPUM)                 ; VMM GC Builtin import
    3333extern IMPNAME(g_VM)                   ; VMM GC Builtin import
    34 extern NAME(cpumGCHandleNPAndGP)       ; CPUMGC.cpp
     34extern NAME(cpumRCHandleNPAndGP)       ; CPUMGC.cpp
    3535
    3636;
     
    8686
    8787    ;; @todo  load segment registers *before* enabling WP.
    88     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_GS | CPUM_HANDLER_CTXCORE_IN_EBP
     88    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_GS | CPUM_HANDLER_CTXCORE_IN_EBP
    8989    mov     gs, [ebp + CPUMCTXCORE.gs.Sel]
    90     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_FS | CPUM_HANDLER_CTXCORE_IN_EBP
     90    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_FS | CPUM_HANDLER_CTXCORE_IN_EBP
    9191    mov     fs, [ebp + CPUMCTXCORE.fs.Sel]
    92     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_ES | CPUM_HANDLER_CTXCORE_IN_EBP
     92    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_ES | CPUM_HANDLER_CTXCORE_IN_EBP
    9393    mov     es, [ebp + CPUMCTXCORE.es.Sel]
    94     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_DS | CPUM_HANDLER_CTXCORE_IN_EBP
     94    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_DS | CPUM_HANDLER_CTXCORE_IN_EBP
    9595    mov     ds, [ebp + CPUMCTXCORE.ds.Sel]
    9696
     
    9898    mov     ebp, [ebp + CPUMCTXCORE.ebp]
    9999
    100     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_IRET
     100    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_IRET
    101101    iret
    102102ENDPROC CPUMGCCallGuestTrapHandler
     
    145145    mov     ebp, [ebp + CPUMCTXCORE.ebp]
    146146
    147     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_IRET
     147    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_IRET
    148148    iret
    149149ENDPROC CPUMGCCallV86Code
     
    177177    ; Restore registers.
    178178    ;
    179     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_ES
     179    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_ES
    180180    mov     es,  [edx + CPUMCPU.Guest.es.Sel]
    181     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_FS
     181    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_FS
    182182    mov     fs,  [edx + CPUMCPU.Guest.fs.Sel]
    183     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_GS
     183    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_GS
    184184    mov     gs,  [edx + CPUMCPU.Guest.gs.Sel]
    185185
     
    219219    push    dword [edx + CPUMCPU.Guest.ds.Sel]
    220220    mov     edx, [edx + CPUMCPU.Guest.edx]
    221     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_DS
     221    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_DS
    222222    pop     ds
    223223
    224224    ; restart execution.
    225     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_IRET
     225    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_IRET
    226226    iretd
    227227ENDPROC     CPUMGCResumeGuest
     
    298298
    299299    ; restart execution.
    300     TRPM_NP_GP_HANDLER NAME(cpumGCHandleNPAndGP), CPUM_HANDLER_IRET
     300    TRPM_NP_GP_HANDLER NAME(cpumRCHandleNPAndGP), CPUM_HANDLER_IRET
    301301    iretd
    302302ENDPROC     CPUMGCResumeGuestV86
  • trunk/src/VBox/VMM/VMMRC/TRPMRCHandlers.cpp

    r41940 r41943  
    11/* $Id$ */
    22/** @file
    3  * TRPM - Guest Context Trap Handlers, CPP part
     3 * TRPM - Raw-mode Context Trap Handlers, CPP part
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    114114*******************************************************************************/
    115115RT_C_DECLS_BEGIN /* addressed from asm (not called so no DECLASM). */
    116 DECLCALLBACK(int) trpmGCTrapInGeneric(PVM pVM, PCPUMCTXCORE pRegFrame, uintptr_t uUser);
     116DECLCALLBACK(int) trpmRCTrapInGeneric(PVM pVM, PCPUMCTXCORE pRegFrame, uintptr_t uUser);
    117117RT_C_DECLS_END
    118118
     
    12711271 * Deal with hypervisor traps occurring when resuming execution on a trap.
    12721272 *
    1273  * @returns VBox status code.
     1273 * There is a little problem with recursive RC (hypervisor) traps.  We deal with
     1274 * this by not allowing recursion without it being the subject of a guru
     1275 * meditation.  (We used to / tried to handle this but there isn't any reason
     1276 * for it.)
     1277 *
     1278 * So, do NOT use this for handling RC traps!
     1279 *
     1280 * @returns VBox status code.  (Anything but VINF_SUCCESS will cause guru.)
    12741281 * @param   pVM         Pointer to the VM.
    12751282 * @param   pRegFrame   Register frame.
    12761283 * @param   uUser       User arg.
    12771284 */
    1278 DECLCALLBACK(int) trpmGCTrapInGeneric(PVM pVM, PCPUMCTXCORE pRegFrame, uintptr_t uUser)
     1285DECLCALLBACK(int) trpmRCTrapInGeneric(PVM pVM, PCPUMCTXCORE pRegFrame, uintptr_t uUser)
    12791286{
    12801287    Log(("********************************************************\n"));
    1281     Log(("trpmGCTrapInGeneric: eip=%RX32 uUser=%#x\n", pRegFrame->eip, uUser));
     1288    Log(("trpmRCTrapInGeneric: eip=%RX32 uUser=%#x\n", pRegFrame->eip, uUser));
    12821289    Log(("********************************************************\n"));
    12831290
    1284     if (uUser & TRPM_TRAP_IN_HYPER)
    1285     {
    1286         /*
    1287          * Check that there is still some stack left, if not we'll flag
    1288          * a guru meditation (the alternative is a triple fault).
    1289          */
    1290         RTRCUINTPTR cbStackUsed = (RTRCUINTPTR)VMMGetStackRC(VMMGetCpu(pVM)) - pRegFrame->esp;
    1291         if (cbStackUsed > VMM_STACK_SIZE - _1K)
    1292         {
    1293             LogRel(("trpmGCTrapInGeneric: ran out of stack: esp=#x cbStackUsed=%#x\n", pRegFrame->esp, cbStackUsed));
    1294             return VERR_TRPM_DONT_PANIC;
    1295         }
    1296 
    1297         /*
    1298          * Just zero the register containing the selector in question.
    1299          * We'll deal with the actual stale or troublesome selector value in
    1300          * the outermost trap frame.
    1301          */
    1302         switch (uUser & TRPM_TRAP_IN_OP_MASK)
    1303         {
    1304             case TRPM_TRAP_IN_MOV_GS:
    1305                 pRegFrame->eax    = 0;
    1306                 pRegFrame->gs.Sel = 0; /* prevent recursive trouble. */
    1307                 break;
    1308             case TRPM_TRAP_IN_MOV_FS:
    1309                 pRegFrame->eax    = 0;
    1310                 pRegFrame->fs.Sel = 0; /* prevent recursive trouble. */
    1311                 return VINF_SUCCESS;
    1312 
    1313             default:
    1314                 AssertMsgFailed(("Invalid uUser=%#x\n", uUser));
    1315                 return VERR_TRPM_BAD_TRAP_IN_OP;
    1316         }
    1317     }
    1318     else
    1319     {
    1320         /*
    1321          * Reconstruct the guest context and switch to the recompiler.
    1322          * We ASSUME we're only at
    1323          */
    1324         CPUMCTXCORE  CtxCore = *pRegFrame;
    1325         uint32_t    *pEsp = (uint32_t *)pRegFrame->esp;
    1326         int          rc;
    1327 
    1328         switch (uUser)
    1329         {
    1330             /*
    1331              * This will only occur when resuming guest code in a trap handler!
    1332              */
    1333             /* @note ASSUMES esp points to the temporary guest CPUMCTXCORE!!! */
    1334             case TRPM_TRAP_IN_MOV_GS:
    1335             case TRPM_TRAP_IN_MOV_FS:
    1336             case TRPM_TRAP_IN_MOV_ES:
    1337             case TRPM_TRAP_IN_MOV_DS:
    1338             {
    1339                 PCPUMCTXCORE pTempGuestCtx = (PCPUMCTXCORE)pEsp;
    1340 
    1341                 /* Just copy the whole thing; several selector registers, eip (etc) and eax are not yet in pRegFrame. */
    1342                 CtxCore = *pTempGuestCtx;
    1343                 rc = VINF_EM_RAW_STALE_SELECTOR;
    1344                 break;
    1345             }
    1346 
    1347             /*
    1348              * This will only occur when resuming guest code!
    1349              */
    1350             case TRPM_TRAP_IN_IRET:
    1351                 CtxCore.eip        = *pEsp++;
    1352                 CtxCore.cs.Sel     = (RTSEL)*pEsp++;
    1353                 CtxCore.eflags.u32 = *pEsp++;
    1354                 CtxCore.esp        = *pEsp++;
    1355                 CtxCore.ss.Sel     = (RTSEL)*pEsp++;
    1356                 rc = VINF_EM_RAW_IRET_TRAP;
    1357                 break;
    1358 
    1359             /*
    1360              * This will only occur when resuming V86 guest code!
    1361              */
    1362             case TRPM_TRAP_IN_IRET | TRPM_TRAP_IN_V86:
    1363                 CtxCore.eip        = *pEsp++;
    1364                 CtxCore.cs.Sel     = (RTSEL)*pEsp++;
    1365                 CtxCore.eflags.u32 = *pEsp++;
    1366                 CtxCore.esp        = *pEsp++;
    1367                 CtxCore.ss.Sel     = (RTSEL)*pEsp++;
    1368                 CtxCore.es.Sel     = (RTSEL)*pEsp++;
    1369                 CtxCore.ds.Sel     = (RTSEL)*pEsp++;
    1370                 CtxCore.fs.Sel     = (RTSEL)*pEsp++;
    1371                 CtxCore.gs.Sel     = (RTSEL)*pEsp++;
    1372                 rc = VINF_EM_RAW_IRET_TRAP;
    1373                 break;
    1374 
    1375             default:
    1376                 AssertMsgFailed(("Invalid uUser=%#x\n", uUser));
    1377                 return VERR_TRPM_BAD_TRAP_IN_OP;
    1378         }
    1379 
    1380 
    1381         CPUMSetGuestCtxCore(VMMGetCpu0(pVM), &CtxCore);
    1382         TRPMGCHyperReturnToHost(pVM, rc);
     1291    /*
     1292     * This used to be kind of complicated, but since we stopped storing
     1293     * the register frame on the stack and instead storing it directly
     1294     * in the CPUMCPU::Guest structure, we just have to figure out which
     1295     * status to hand on to the host and let the recompiler/IEM do its
     1296     * job.
     1297     */
     1298    switch (uUser)
     1299    {
     1300        case TRPM_TRAP_IN_MOV_GS:
     1301        case TRPM_TRAP_IN_MOV_FS:
     1302        case TRPM_TRAP_IN_MOV_ES:
     1303        case TRPM_TRAP_IN_MOV_DS:
     1304            TRPMGCHyperReturnToHost(pVM, VINF_EM_RAW_STALE_SELECTOR);
     1305            break;
     1306
     1307        case TRPM_TRAP_IN_IRET:
     1308        case TRPM_TRAP_IN_IRET | TRPM_TRAP_IN_V86:
     1309            TRPMGCHyperReturnToHost(pVM, VINF_EM_RAW_IRET_TRAP);
     1310            break;
     1311
     1312        default:
     1313            AssertMsgFailed(("Invalid uUser=%#x\n", uUser));
     1314            return VERR_TRPM_BAD_TRAP_IN_OP;
    13831315    }
    13841316
  • trunk/src/VBox/VMM/VMMRC/TRPMRCHandlersA.asm

    r41931 r41943  
    11; $Id$
    22;; @file
    3 ; TRPM - Guest Context Trap Handlers
    4 ;
    5 
    6 ; Copyright (C) 2006-2010 Oracle Corporation
     3; TRPM - Raw-mode Context Trap Handlers
     4;
     5
     6;
     7; Copyright (C) 2006-2012 Oracle Corporation
    78;
    89; This file is part of VirtualBox Open Source Edition (OSE), as
     
    3637extern IMPNAME(g_trpmGuestCtxCore)
    3738extern IMPNAME(g_trpmHyperCtxCore)
    38 extern NAME(trpmGCTrapInGeneric)
     39extern NAME(trpmRCTrapInGeneric)
    3940extern NAME(TRPMGCTrap01Handler)
    4041extern NAME(TRPMGCHyperTrap01Handler)
     
    247248
    248249    ;
    249     ; Save ds, es, eax and ebx so we have a context pointer (ebx) and
     250    ; Save ds, es, fs, gs, eax and ebx so we have a context pointer (ebx) and
    250251    ; scratch (eax) register to work with.  A sideeffect of using ebx is that
    251252    ; it's preserved accross cdecl calls.
    252253    ;
    253254    ; In order to safely access data, we need to load our flat DS & ES selector,
    254     ; and clear make sure CR0.WP is cleared.
    255     ;
    256     push    ds                          ; +0ch
    257     push    es                          ; +08h
     255    ; clear FS and GS (stale guest selector prevention), and clear make sure
     256    ; that CR0.WP is cleared.
     257    ;
     258    push    ds                          ; +14h
     259    push    es                          ; +10h
     260    push    fs                          ; +0ch
     261    push    gs                          ; +08h
    258262    push    eax                         ; +04h
    259263    push    ebx                         ; +00h
    260 %push foobar
     264%push StackFrame
    261265%define %$STK_SAVED_EBX   esp
    262266%define %$STK_SAVED_EAX   esp + 04h
    263 %define %$STK_SAVED_ES    esp + 08h
    264 %define %$STK_SAVED_DS    esp + 0ch
    265 %define %$ESPOFF                10h
     267%define %$STK_SAVED_GS    esp + 08h
     268%define %$STK_SAVED_FS    esp + 0ch
     269%define %$STK_SAVED_ES    esp + 10h
     270%define %$STK_SAVED_DS    esp + 14h
     271%define %$ESPOFF                18h
    266272%define %$STK_VECTOR      esp + 00h + %$ESPOFF
    267273%define %$STK_ERRCD       esp + 04h + %$ESPOFF
     
    276282%define %$STK_V86_GS      esp + 28h + %$ESPOFF
    277283
    278     push    ss
    279     pop     ds
    280     push    ss
    281     pop     es
     284    mov     bx, ss                      ; load
     285    mov     ds, bx
     286    mov     es, bx
     287
     288    xor     bx, bx                      ; load 0 into gs and fs.
     289    mov     gs, bx
     290    mov     fs, bx
    282291
    283292    mov     eax, cr0                        ;; @todo elimitate this read?
     
    286295
    287296    mov     ebx, IMP(g_trpmGuestCtxCore)    ; Assume GC as the most common.
    288     test    byte [%$STK_CS], 3h               ; check RPL of the cs selector
     297    test    byte [%$STK_CS], 3h             ; check RPL of the cs selector
    289298    ;; @todo check this for conforming segments.
    290299    jnz     .save_state
    291     test    dword [%$STK_EFLAGS], X86_EFL_VM  ; If in V86, then guest.
     300    test    dword [%$STK_EFLAGS], X86_EFL_VM; If in V86, then guest.
    292301    jnz     .save_state
    293302    mov     ebx, IMP(g_trpmHyperCtxCore)    ; It's raw-mode context, actually.
     
    341350    mov     cx, [%$STK_SAVED_DS]
    342351    mov     [ebx + CPUMCTXCORE.ds.Sel], cx
    343     mov     cx, fs
     352    mov     cx, [%$STK_SAVED_FS]
    344353    mov     [ebx + CPUMCTXCORE.fs.Sel], cx
    345     mov     cx, gs
     354    mov     cx, [%$STK_SAVED_GS]
    346355    mov     [ebx + CPUMCTXCORE.gs.Sel], cx
    347356    jmp     .done_saving
     
    496505
    497506    mov     ax, [ebx + CPUMCTXCORE.gs.Sel]
    498     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_GS
     507    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_MOV_GS
    499508    mov     gs, ax
    500509
    501510    mov     ax, [ebx + CPUMCTXCORE.fs.Sel]
    502     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_FS
     511    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_MOV_FS
    503512    mov     fs, ax
    504513
    505514    mov     ax, [ebx + CPUMCTXCORE.es.Sel]
    506     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_ES
     515    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_MOV_ES
    507516    mov     es, ax
    508517
    509518    mov     ax, [ebx + CPUMCTXCORE.ds.Sel]
    510     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_DS
     519    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_MOV_DS
    511520    mov     ds, ax
    512521
     
    514523    pop     ebx
    515524    pop     eax
    516 
    517     add     esp, 8 + 8                          ; skip ds, es, the error code, and vector number.
    518 
    519     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_IRET
     525    add     esp, 16 + 8                 ; skip segregs, error code, and vector number.
     526
     527    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_IRET
    520528    iret
    521529
     
    534542    pop     ebx
    535543    pop     eax
    536 
    537     add     esp, 8 + 8                          ; skip ds, es, the error code, and vector number.
    538 
    539     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_IRET | TRPM_TRAP_IN_V86
     544    add     esp, 16 + 8                 ; skip segregs, error code, and vector number.
     545
     546    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_IRET | TRPM_TRAP_IN_V86
    540547    iret
    541548
     
    651658
    652659    mov     ax, [ebx + CPUMCTXCORE.gs.Sel]
    653     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_GS | TRPM_TRAP_IN_HYPER
    654660    mov     gs, ax
    655661
    656662    mov     ax, [ebx + CPUMCTXCORE.fs.Sel]
    657     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_FS | TRPM_TRAP_IN_HYPER
    658663    mov     fs, ax
    659664
    660665    mov     ax, [ebx + CPUMCTXCORE.es.Sel]
    661     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_ES | TRPM_TRAP_IN_HYPER
    662666    mov     es, ax
    663667
    664668    mov     ax, [ebx + CPUMCTXCORE.ds.Sel]
    665     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_DS | TRPM_TRAP_IN_HYPER
    666669    mov     ds, ax
    667670
     
    669672    pop     ebx
    670673    pop     eax
    671 
    672     add     esp, 8 + 8                          ; skip ds, es, the error code, and vector number.
     674    add     esp, 16 + 8                 ; skip segregs, error code, and vector number.
    673675
    674676    iret
     
    735737
    736738    ;
    737     ; Save ds, es, eax and ebx so we have a context pointer (ebx) and
     739    ; Save ds, es, fs, gs, eax and ebx so we have a context pointer (ebx) and
    738740    ; scratch (eax) register to work with.  A sideeffect of using ebx is that
    739741    ; it's preserved accross cdecl calls.
    740742    ;
    741743    ; In order to safely access data, we need to load our flat DS & ES selector,
    742     ; and clear make sure CR0.WP is cleared.
    743     ;
    744     push    ds                          ; +0ch
    745     push    es                          ; +08h
     744    ; clear FS and GS (stale guest selector prevention), and clear make sure
     745    ; that CR0.WP is cleared.
     746    ;
     747    push    ds                          ; +14h
     748    push    es                          ; +10h
     749    push    fs                          ; +0ch
     750    push    gs                          ; +08h
    746751    push    eax                         ; +04h
    747752    push    ebx                         ; +00h
    748 %push foobar
     753%push StackFrame
    749754%define %$STK_SAVED_EBX   esp
    750755%define %$STK_SAVED_EAX   esp + 04h
    751 %define %$STK_SAVED_ES    esp + 08h
    752 %define %$STK_SAVED_DS    esp + 0ch
    753 %define %$ESPOFF                10h
     756%define %$STK_SAVED_GS    esp + 08h
     757%define %$STK_SAVED_FS    esp + 0ch
     758%define %$STK_SAVED_ES    esp + 10h
     759%define %$STK_SAVED_DS    esp + 14h
     760%define %$ESPOFF                18h
    754761%define %$STK_VECTOR      esp + 00h + %$ESPOFF
    755762%define %$STK_EIP         esp + 04h + %$ESPOFF
     
    763770%define %$STK_V86_GS      esp + 24h + %$ESPOFF
    764771
    765     push    ss
    766     pop     ds
    767     push    ss
    768     pop     es
     772    mov     bx, ss                      ; load
     773    mov     ds, bx
     774    mov     es, bx
     775
     776    xor     bx, bx                      ; load 0 into gs and fs.
     777    mov     gs, bx
     778    mov     fs, bx
    769779
    770780    mov     eax, cr0                        ;; @todo elimitate this read?
     
    828838    mov     cx, [%$STK_SAVED_DS]
    829839    mov     [ebx + CPUMCTXCORE.ds.Sel], cx
    830     mov     cx, fs
     840    mov     cx, [%$STK_SAVED_FS]
    831841    mov     [ebx + CPUMCTXCORE.fs.Sel], cx
    832     mov     cx, gs
     842    mov     cx, [%$STK_SAVED_GS]
    833843    mov     [ebx + CPUMCTXCORE.gs.Sel], cx
    834844    jmp     .done_saving
     
    945955
    946956    mov     ax, [ebx + CPUMCTXCORE.gs.Sel]
    947     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_GS
     957    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_MOV_GS
    948958    mov     gs, ax
    949959
    950960    mov     ax, [ebx + CPUMCTXCORE.fs.Sel]
    951     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_FS
     961    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_MOV_FS
    952962    mov     fs, ax
    953963
    954964    mov     ax, [ebx + CPUMCTXCORE.es.Sel]
    955     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_ES
     965    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_MOV_ES
    956966    mov     es, ax
    957967
    958968    mov     ax, [ebx + CPUMCTXCORE.ds.Sel]
    959     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_DS
     969    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_MOV_DS
    960970    mov     ds, ax
    961971
     
    963973    pop     ebx
    964974    pop     eax
    965 
    966     add     esp, 8 + 4                          ; skip ds, es, and vector number.
    967 
    968     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_IRET
     975    add     esp, 16 + 4                 ; skip segregs, and vector number.
     976
     977    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_IRET
    969978    iret
    970979
     
    983992    pop     ebx
    984993    pop     eax
    985 
    986     add     esp, 8 + 4                          ; skip ds, es, and vector number.
    987 
    988     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_IRET | TRPM_TRAP_IN_V86
     994    add     esp, 16 + 4                 ; skip segregs, and vector number.
     995
     996    TRPM_NP_GP_HANDLER NAME(trpmRCTrapInGeneric), TRPM_TRAP_IN_IRET | TRPM_TRAP_IN_V86
    989997    iret
    990998
     
    10411049    mov     edi, [ebx + CPUMCTXCORE.edi]
    10421050
    1043                                                 ; skipping esp & ss.
     1051                                        ; skipping esp & ss.
    10441052
    10451053    mov     eax, [ebx + CPUMCTXCORE.eflags]
     
    10511059
    10521060    mov     ax, [ebx + CPUMCTXCORE.gs.Sel]
    1053     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_GS | TRPM_TRAP_IN_HYPER
    10541061    mov     gs, ax
    10551062
    10561063    mov     ax, [ebx + CPUMCTXCORE.fs.Sel]
    1057     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_FS | TRPM_TRAP_IN_HYPER
    10581064    mov     fs, ax
    10591065
    10601066    mov     ax, [ebx + CPUMCTXCORE.es.Sel]
    1061     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_ES | TRPM_TRAP_IN_HYPER
    10621067    mov     es, ax
    10631068
    10641069    mov     ax, [ebx + CPUMCTXCORE.ds.Sel]
    1065     TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_DS | TRPM_TRAP_IN_HYPER
    10661070    mov     ds, ax
    10671071
     
    10691073    pop     ebx
    10701074    pop     eax
    1071 
    1072     add     esp, 8 + 4                          ; skip ds, es, and vector number.
     1075    add     esp, 16 + 4                 ; skip segregs, and vector number.
     1076
    10731077    iret
    10741078%pop
  • trunk/src/VBox/VMM/include/TRPMInternal.h

    r41801 r41943  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    5858/** Set if this is a V86 resume. */
    5959#define TRPM_TRAP_IN_V86        RT_BIT(30)
    60 /** If set this is a hypervisor register set. If cleared it's a guest set. */
    61 #define TRPM_TRAP_IN_HYPER      RT_BIT(31)
    6260/** @} */
    6361
  • trunk/src/VBox/VMM/include/TRPMInternal.mac

    r38867 r41943  
    55
    66;
    7 ; Copyright (C) 2006-2007 Oracle Corporation
     7; Copyright (C) 2006-2012 Oracle Corporation
    88;
    99; This file is part of VirtualBox Open Source Edition (OSE), as
     
    2626%define TRPM_TRAP_IN_IRET       5
    2727%define TRPM_TRAP_IN_V86        RT_BIT(30)
    28 %define TRPM_TRAP_IN_HYPER      RT_BIT(31)
    2928
    3029struc TRPM
Note: See TracChangeset for help on using the changeset viewer.

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