VirtualBox

Changeset 41931 in vbox for trunk


Ignore:
Timestamp:
Jun 27, 2012 4:12:16 PM (13 years ago)
Author:
vboxsync
Message:

TRPM: Save state directly to the CPUMCPU context member instead of putting on the stack. this avoid copying the state around before returning to host context to service an IRQ, or before using IEM.

Location:
trunk
Files:
16 edited

Legend:

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

    r41906 r41931  
    352352
    353353VMMDECL(void)           CPUMPushHyper(PVMCPU pVCpu, uint32_t u32);
    354 VMMDECL(void)           CPUMHyperSetCtxCore(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore);
    355354VMMDECL(int)            CPUMQueryHyperCtxPtr(PVMCPU pVCpu, PCPUMCTX *ppCtx);
     355VMMDECL(PCPUMCTX)       CPUMGetHyperCtxPtr(PVMCPU pVCpu);
    356356VMMDECL(PCCPUMCTXCORE)  CPUMGetHyperCtxCore(PVMCPU pVCpu);
    357357VMMDECL(PCPUMCTX)       CPUMQueryGuestCtxPtr(PVMCPU pVCpu);
  • trunk/include/VBox/vmm/trpm.h

    r41732 r41931  
    9797VMMR3DECL(void)     TRPMR3ResetCpu(PVMCPU pVCpu);
    9898VMMR3DECL(void)     TRPMR3Reset(PVM pVM);
     99VMMR3_INT_DECL(int) TRPMR3GetImportRC(PVM pVM, const char *pszSymbol, PRTRCPTR pRCPtrValue);
    99100VMMR3DECL(int)      TRPMR3Term(PVM pVM);
    100101VMMR3DECL(int)      TRPMR3EnableGuestTrapHandler(PVM pVM, unsigned iTrap);
  • trunk/src/VBox/Debugger/testcase/tstDBGCStubs.cpp

    r41565 r41931  
    366366}
    367367
    368 VMMDECL(PCCPUMCTXCORE) CPUMGetHyperCtxCore(PVMCPU pVCpu)
    369 {
    370     return NULL;
    371 }
    372 
    373368VMMDECL(uint32_t) CPUMGetHyperEIP(PVMCPU pVCpu)
    374369{
     
    381376}
    382377
    383 VMMDECL(int) CPUMQueryHyperCtxPtr(PVMCPU pVCpu, PCPUMCTX *ppCtx)
    384 {
    385     return VERR_INTERNAL_ERROR;
    386 }
    387 
    388378
    389379
  • trunk/src/VBox/VMM/VMMAll/CPUMAllRegs.cpp

    r41906 r41931  
    4848
    4949/**
    50  * Sets or resets an alternative hypervisor context core.
    51  *
    52  * This is called when we get a hypervisor trap set switch the context
    53  * core with the trap frame on the stack. It is called again to reset
    54  * back to the default context core when resuming hypervisor execution.
    55  *
    56  * @param   pVCpu       Pointer to the VMCPU.
    57  * @param   pCtxCore    Pointer to the alternative context core or NULL
    58  *                      to go back to the default context core.
    59  */
    60 VMMDECL(void) CPUMHyperSetCtxCore(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore)
    61 {
    62     PVM pVM = pVCpu->CTX_SUFF(pVM);
    63 
    64     LogFlow(("CPUMHyperSetCtxCore: %p/%p/%p -> %p\n", pVCpu->cpum.s.CTX_SUFF(pHyperCore), pCtxCore));
    65     if (!pCtxCore)
    66     {
    67         pCtxCore = CPUMCTX2CORE(&pVCpu->cpum.s.Hyper);
    68         pVCpu->cpum.s.pHyperCoreR3 = (R3PTRTYPE(PCPUMCTXCORE))VM_R3_ADDR(pVM, pCtxCore);
    69         pVCpu->cpum.s.pHyperCoreR0 = (R0PTRTYPE(PCPUMCTXCORE))VM_R0_ADDR(pVM, pCtxCore);
    70         pVCpu->cpum.s.pHyperCoreRC = (RCPTRTYPE(PCPUMCTXCORE))VM_RC_ADDR(pVM, pCtxCore);
    71     }
    72     else
    73     {
    74         pVCpu->cpum.s.pHyperCoreR3 = (R3PTRTYPE(PCPUMCTXCORE))MMHyperCCToR3(pVM, pCtxCore);
    75         pVCpu->cpum.s.pHyperCoreR0 = (R0PTRTYPE(PCPUMCTXCORE))MMHyperCCToR0(pVM, pCtxCore);
    76         pVCpu->cpum.s.pHyperCoreRC = (RCPTRTYPE(PCPUMCTXCORE))MMHyperCCToRC(pVM, pCtxCore);
    77     }
    78 }
    79 
    80 
    81 /**
    82  * Gets the pointer to the internal CPUMCTXCORE structure for the hypervisor.
    83  * This is only for reading in order to save a few calls.
     50 * Obsolete.
     51 *
     52 * We don't support nested hypervisor context interrupts or traps.  Life is much
     53 * simpler when we don't.  It's also slightly faster at times.
    8454 *
    8555 * @param   pVM         Handle to the virtual machine.
     
    8757VMMDECL(PCCPUMCTXCORE) CPUMGetHyperCtxCore(PVMCPU pVCpu)
    8858{
    89     return pVCpu->cpum.s.CTX_SUFF(pHyperCore);
    90 }
    91 
    92 
    93 /**
    94  * Queries the pointer to the internal CPUMCTX structure for the hypervisor.
    95  *
    96  * @returns VBox status code.
    97  * @param   pVM         Handle to the virtual machine.
    98  * @param   ppCtx       Receives the hyper CPUMCTX pointer when successful.
    99  *
    100  * @deprecated  This will *not* (and has never) given the right picture of the
    101  *              hypervisor register state. With CPUMHyperSetCtxCore() this is
    102  *              getting much worse. So, use the individual functions for getting
    103  *              and esp. setting the hypervisor registers.
    104  */
    105 VMMDECL(int) CPUMQueryHyperCtxPtr(PVMCPU pVCpu, PCPUMCTX *ppCtx)
    106 {
    107     *ppCtx = &pVCpu->cpum.s.Hyper;
    108     return VINF_SUCCESS;
     59    return CPUMCTX2CORE(&pVCpu->cpum.s.Hyper);
     60}
     61
     62
     63/**
     64 * Gets the pointer to the hypervisor CPU context structure of a virtual CPU.
     65 *
     66 * @param   pVCpu       Pointer to the virtual CPU.
     67 */
     68VMMDECL(PCPUMCTX) CPUMGetHyperCtxPtr(PVMCPU pVCpu)
     69{
     70    return &pVCpu->cpum.s.Hyper;
    10971}
    11072
     
    12082{
    12183    pVCpu->cpum.s.Hyper.idtr.cbIdt = limit;
    122     pVCpu->cpum.s.Hyper.idtr.pIdt = addr;
     84    pVCpu->cpum.s.Hyper.idtr.pIdt  = addr;
    12385}
    12486
     
    142104VMMDECL(void) CPUMSetHyperCS(PVMCPU pVCpu, RTSEL SelCS)
    143105{
    144     pVCpu->cpum.s.CTX_SUFF(pHyperCore)->cs.Sel = SelCS;
     106    pVCpu->cpum.s.Hyper.cs.Sel = SelCS;
    145107}
    146108
     
    148110VMMDECL(void) CPUMSetHyperDS(PVMCPU pVCpu, RTSEL SelDS)
    149111{
    150     pVCpu->cpum.s.CTX_SUFF(pHyperCore)->ds.Sel = SelDS;
     112    pVCpu->cpum.s.Hyper.ds.Sel = SelDS;
    151113}
    152114
     
    154116VMMDECL(void) CPUMSetHyperES(PVMCPU pVCpu, RTSEL SelES)
    155117{
    156     pVCpu->cpum.s.CTX_SUFF(pHyperCore)->es.Sel = SelES;
     118    pVCpu->cpum.s.Hyper.es.Sel = SelES;
    157119}
    158120
     
    160122VMMDECL(void) CPUMSetHyperFS(PVMCPU pVCpu, RTSEL SelFS)
    161123{
    162     pVCpu->cpum.s.CTX_SUFF(pHyperCore)->fs.Sel = SelFS;
     124    pVCpu->cpum.s.Hyper.fs.Sel = SelFS;
    163125}
    164126
     
    166128VMMDECL(void) CPUMSetHyperGS(PVMCPU pVCpu, RTSEL SelGS)
    167129{
    168     pVCpu->cpum.s.CTX_SUFF(pHyperCore)->gs.Sel = SelGS;
     130    pVCpu->cpum.s.Hyper.gs.Sel = SelGS;
    169131}
    170132
     
    172134VMMDECL(void) CPUMSetHyperSS(PVMCPU pVCpu, RTSEL SelSS)
    173135{
    174     pVCpu->cpum.s.CTX_SUFF(pHyperCore)->ss.Sel = SelSS;
     136    pVCpu->cpum.s.Hyper.ss.Sel = SelSS;
    175137}
    176138
     
    178140VMMDECL(void) CPUMSetHyperESP(PVMCPU pVCpu, uint32_t u32ESP)
    179141{
    180     pVCpu->cpum.s.CTX_SUFF(pHyperCore)->esp = u32ESP;
     142    pVCpu->cpum.s.Hyper.esp = u32ESP;
    181143}
    182144
     
    184146VMMDECL(int) CPUMSetHyperEFlags(PVMCPU pVCpu, uint32_t Efl)
    185147{
    186     pVCpu->cpum.s.CTX_SUFF(pHyperCore)->eflags.u32 = Efl;
     148    pVCpu->cpum.s.Hyper.eflags.u32 = Efl;
    187149    return VINF_SUCCESS;
    188150}
     
    191153VMMDECL(void) CPUMSetHyperEIP(PVMCPU pVCpu, uint32_t u32EIP)
    192154{
    193     pVCpu->cpum.s.CTX_SUFF(pHyperCore)->eip = u32EIP;
     155    pVCpu->cpum.s.Hyper.eip = u32EIP;
    194156}
    195157
     
    251213VMMDECL(RTSEL) CPUMGetHyperCS(PVMCPU pVCpu)
    252214{
    253     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->cs.Sel;
     215    return pVCpu->cpum.s.Hyper.cs.Sel;
    254216}
    255217
     
    257219VMMDECL(RTSEL) CPUMGetHyperDS(PVMCPU pVCpu)
    258220{
    259     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->ds.Sel;
     221    return pVCpu->cpum.s.Hyper.ds.Sel;
    260222}
    261223
     
    263225VMMDECL(RTSEL) CPUMGetHyperES(PVMCPU pVCpu)
    264226{
    265     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->es.Sel;
     227    return pVCpu->cpum.s.Hyper.es.Sel;
    266228}
    267229
     
    269231VMMDECL(RTSEL) CPUMGetHyperFS(PVMCPU pVCpu)
    270232{
    271     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->fs.Sel;
     233    return pVCpu->cpum.s.Hyper.fs.Sel;
    272234}
    273235
     
    275237VMMDECL(RTSEL) CPUMGetHyperGS(PVMCPU pVCpu)
    276238{
    277     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->gs.Sel;
     239    return pVCpu->cpum.s.Hyper.gs.Sel;
    278240}
    279241
     
    281243VMMDECL(RTSEL) CPUMGetHyperSS(PVMCPU pVCpu)
    282244{
    283     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->ss.Sel;
     245    return pVCpu->cpum.s.Hyper.ss.Sel;
    284246}
    285247
     
    287249VMMDECL(uint32_t) CPUMGetHyperEAX(PVMCPU pVCpu)
    288250{
    289     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->eax;
     251    return pVCpu->cpum.s.Hyper.eax;
    290252}
    291253
     
    293255VMMDECL(uint32_t) CPUMGetHyperEBX(PVMCPU pVCpu)
    294256{
    295     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->ebx;
     257    return pVCpu->cpum.s.Hyper.ebx;
    296258}
    297259
     
    299261VMMDECL(uint32_t) CPUMGetHyperECX(PVMCPU pVCpu)
    300262{
    301     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->ecx;
     263    return pVCpu->cpum.s.Hyper.ecx;
    302264}
    303265
     
    305267VMMDECL(uint32_t) CPUMGetHyperEDX(PVMCPU pVCpu)
    306268{
    307     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->edx;
     269    return pVCpu->cpum.s.Hyper.edx;
    308270}
    309271
     
    311273VMMDECL(uint32_t) CPUMGetHyperESI(PVMCPU pVCpu)
    312274{
    313     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->esi;
     275    return pVCpu->cpum.s.Hyper.esi;
    314276}
    315277
     
    317279VMMDECL(uint32_t) CPUMGetHyperEDI(PVMCPU pVCpu)
    318280{
    319     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->edi;
     281    return pVCpu->cpum.s.Hyper.edi;
    320282}
    321283
     
    323285VMMDECL(uint32_t) CPUMGetHyperEBP(PVMCPU pVCpu)
    324286{
    325     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->ebp;
     287    return pVCpu->cpum.s.Hyper.ebp;
    326288}
    327289
     
    329291VMMDECL(uint32_t) CPUMGetHyperESP(PVMCPU pVCpu)
    330292{
    331     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->esp;
     293    return pVCpu->cpum.s.Hyper.esp;
    332294}
    333295
     
    335297VMMDECL(uint32_t) CPUMGetHyperEFlags(PVMCPU pVCpu)
    336298{
    337     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->eflags.u32;
     299    return pVCpu->cpum.s.Hyper.eflags.u32;
    338300}
    339301
     
    341303VMMDECL(uint32_t) CPUMGetHyperEIP(PVMCPU pVCpu)
    342304{
    343     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->eip;
     305    return pVCpu->cpum.s.Hyper.eip;
    344306}
    345307
     
    347309VMMDECL(uint64_t) CPUMGetHyperRIP(PVMCPU pVCpu)
    348310{
    349     return pVCpu->cpum.s.CTX_SUFF(pHyperCore)->rip;
     311    return pVCpu->cpum.s.Hyper.rip;
    350312}
    351313
  • trunk/src/VBox/VMM/VMMR3/CPUM.cpp

    r41906 r41931  
    426426        PVMCPU pVCpu = &pVM->aCpus[i];
    427427
    428         /*
    429          * Setup any fixed pointers and offsets.
    430          */
    431         pVCpu->cpum.s.pHyperCoreR3 = CPUMCTX2CORE(&pVCpu->cpum.s.Hyper);
    432         pVCpu->cpum.s.pHyperCoreR0 = VM_R0_ADDR(pVM, CPUMCTX2CORE(&pVCpu->cpum.s.Hyper));
    433 
    434         pVCpu->cpum.s.offCPUM      = RT_OFFSETOF(VM, aCpus[i].cpum) - RT_OFFSETOF(VM, cpum);
     428        pVCpu->cpum.s.offCPUM = RT_OFFSETOF(VM, aCpus[i].cpum) - RT_OFFSETOF(VM, cpum);
    435429        Assert((uintptr_t)&pVCpu->cpum - pVCpu->cpum.s.offCPUM == (uintptr_t)&pVM->cpum);
    436430    }
     
    12691263{
    12701264    LogFlow(("CPUMR3Relocate\n"));
    1271     for (VMCPUID i = 0; i < pVM->cCpus; i++)
    1272     {
    1273         /*
    1274          * Switcher pointers.
    1275          */
    1276         PVMCPU pVCpu = &pVM->aCpus[i];
    1277         pVCpu->cpum.s.pHyperCoreRC = MMHyperCCToRC(pVM, pVCpu->cpum.s.pHyperCoreR3);
    1278         Assert(pVCpu->cpum.s.pHyperCoreRC != NIL_RTRCPTR);
    1279 
    1280     }
     1265    /* nothing to do any more. */
    12811266}
    12821267
     
    29232908    cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
    29242909    pHlp->pfnPrintf(pHlp, "Hypervisor CPUM state: %s\n", pszComment);
    2925     cpumR3InfoOne(pVM, &pVCpu->cpum.s.Hyper, pVCpu->cpum.s.pHyperCoreR3, pHlp, enmType, ".");
     2910    cpumR3InfoOne(pVM, &pVCpu->cpum.s.Hyper, CPUMCTX2CORE(&pVCpu->cpum.s.Hyper), pHlp, enmType, ".");
    29262911    pHlp->pfnPrintf(pHlp, "CR4OrMask=%#x CR4AndMask=%#x\n", pVM->cpum.s.CR4.OrMask, pVM->cpum.s.CR4.AndMask);
    29272912}
  • trunk/src/VBox/VMM/VMMR3/PDMLdr.cpp

    r41800 r41931  
    2525#include <VBox/vmm/pdm.h>
    2626#include <VBox/vmm/mm.h>
     27#include <VBox/vmm/trpm.h>
    2728#include <VBox/vmm/vmm.h>
    2829#include <VBox/vmm/vm.h>
     
    355356        else if (!strcmp(pszSymbol, "g_CPUM"))
    356357            *pValue = VM_RC_ADDR(pVM, &pVM->cpum);
    357         else if (!strcmp(pszSymbol, "g_TRPM"))
    358             *pValue = VM_RC_ADDR(pVM, &pVM->trpm);
    359         else if (!strcmp(pszSymbol, "g_TRPMCPU"))
    360             *pValue = VM_RC_ADDR(pVM, &pVM->aCpus[0].trpm);
     358        else if (   !strncmp(pszSymbol, "g_TRPM", 6)
     359                 || !strncmp(pszSymbol, "g_trpm", 6)
     360                 || !strncmp(pszSymbol, "TRPM", 4))
     361        {
     362            RTRCPTR RCPtr = 0;
     363            rc = TRPMR3GetImportRC(pVM, pszSymbol, &RCPtr);
     364            if (RT_SUCCESS(rc))
     365                *pValue = RCPtr;
     366        }
    361367        else if (   !strncmp(pszSymbol, "VMM", 3)
    362368                 || !strcmp(pszSymbol, "g_Logger")
  • trunk/src/VBox/VMM/VMMR3/TRPM.cpp

    r41803 r41931  
    782782
    783783/**
     784 * Resolve a builtin RC symbol.
     785 *
     786 * Called by PDM when loading or relocating RC modules.
     787 *
     788 * @returns VBox status
     789 * @param   pVM             Pointer to the VM.
     790 * @param   pszSymbol       Symbol to resolv
     791 * @param   pRCPtrValue     Where to store the symbol value.
     792 *
     793 * @remark  This has to work before VMMR3Relocate() is called.
     794 */
     795VMMR3_INT_DECL(int) TRPMR3GetImportRC(PVM pVM, const char *pszSymbol, PRTRCPTR pRCPtrValue)
     796{
     797    if (!strcmp(pszSymbol, "g_TRPM"))
     798        *pRCPtrValue = VM_RC_ADDR(pVM, &pVM->trpm);
     799    else if (!strcmp(pszSymbol, "g_TRPMCPU"))
     800        *pRCPtrValue = VM_RC_ADDR(pVM, &pVM->aCpus[0].trpm);
     801    else if (!strcmp(pszSymbol, "g_trpmGuestCtxCore"))
     802    {
     803        PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(VMMGetCpu0(pVM));
     804        *pRCPtrValue = VM_RC_ADDR(pVM, CPUMCTX2CORE(pCtx));
     805    }
     806    else if (!strcmp(pszSymbol, "g_trpmHyperCtxCore"))
     807    {
     808        PCPUMCTX pCtx = CPUMGetHyperCtxPtr(VMMGetCpu0(pVM));
     809        *pRCPtrValue = VM_RC_ADDR(pVM, CPUMCTX2CORE(pCtx));
     810    }
     811    else
     812        return VERR_SYMBOL_NOT_FOUND;
     813    return VINF_SUCCESS;
     814}
     815
     816
     817/**
    784818 * Execute state save operation.
    785819 *
  • trunk/src/VBox/VMM/VMMR3/VMM.cpp

    r41906 r41931  
    561561    if (RT_SUCCESS(rc))
    562562    {
    563         CPUMHyperSetCtxCore(pVCpu, NULL);
    564563        CPUMSetHyperESP(pVCpu, pVCpu->vmm.s.pbEMTStackBottomRC); /* Clear the stack. */
    565564        uint64_t u64TS = RTTimeProgramStartNanoTS();
     
    18741873     * Setup the call frame using the trampoline.
    18751874     */
    1876     CPUMHyperSetCtxCore(pVCpu, NULL);
    18771875    memset(pVCpu->vmm.s.pbEMTStackR3, 0xaa, VMM_STACK_SIZE); /* Clear the stack. */
    18781876    CPUMSetHyperESP(pVCpu, pVCpu->vmm.s.pbEMTStackBottomRC - cArgs * sizeof(RTGCUINTPTR32));
  • trunk/src/VBox/VMM/VMMR3/VMMTests.cpp

    r41906 r41931  
    6161        return rc;
    6262
    63     CPUMHyperSetCtxCore(pVCpu, NULL);
    6463    memset(pVCpu->vmm.s.pbEMTStackR3, 0xaa, VMM_STACK_SIZE);
    6564    CPUMSetHyperESP(pVCpu, pVCpu->vmm.s.pbEMTStackBottomRC); /* Clear the stack. */
     
    101100        return rc;
    102101
    103     CPUMHyperSetCtxCore(pVCpu, NULL);
    104102    memset(pVCpu->vmm.s.pbEMTStackR3, 0xaa, VMM_STACK_SIZE);
    105103    CPUMSetHyperESP(pVCpu, pVCpu->vmm.s.pbEMTStackBottomRC); /* Clear the stack. */
     
    339337         * Interrupt forwarding.
    340338         */
    341         CPUMHyperSetCtxCore(pVCpu, NULL);
    342339        CPUMSetHyperESP(pVCpu, pVCpu->vmm.s.pbEMTStackBottomRC); /* Clear the stack. */
    343340        CPUMPushHyper(pVCpu, 0);
     
    403400        for (i = 0; i < 1000000; i++)
    404401        {
    405             CPUMHyperSetCtxCore(pVCpu, NULL);
    406402            CPUMSetHyperESP(pVCpu, pVCpu->vmm.s.pbEMTStackBottomRC); /* Clear the stack. */
    407403            CPUMPushHyper(pVCpu, 0);
     
    495491    AssertRCReturn(rc, rc);
    496492
    497     CPUMQueryHyperCtxPtr(pVCpu, &pHyperCtx);
     493    pHyperCtx = CPUMGetHyperCtxPtr(pVCpu);
    498494
    499495    pHyperCtx->cr0 = X86_CR0_PE | X86_CR0_WP | X86_CR0_PG | X86_CR0_TS | X86_CR0_ET | X86_CR0_NE | X86_CR0_MP;
     
    516512        RTPrintf("VMM: VMMGCEntry=%RRv\n", RCPtrEP);
    517513
    518         CPUMQueryHyperCtxPtr(pVCpu, &pHyperCtx);
     514        pHyperCtx = CPUMGetHyperCtxPtr(pVCpu);
    519515
    520516        /* Fill in hidden selector registers for the hypervisor state. */
     
    537533        for (i = 0; i < 1000000; i++)
    538534        {
    539             CPUMHyperSetCtxCore(pVCpu, NULL);
    540 
    541535            CPUMSetHyperESP(pVCpu, pVCpu->vmm.s.pbEMTStackBottomRC); /* Clear the stack. */
    542536            CPUMPushHyper(pVCpu, 0);
     
    547541            CPUMSetHyperEIP(pVCpu, pVM->vmm.s.pfnCallTrampolineRC);
    548542
    549             CPUMQueryHyperCtxPtr(pVCpu, &pHyperCtx);
     543            pHyperCtx = CPUMGetHyperCtxPtr(pVCpu);
    550544            pGuestCtx = CPUMQueryGuestCtxPtr(pVCpu);
    551545
  • trunk/src/VBox/VMM/VMMRC/CPUMRCA.asm

    r41906 r41931  
    4444
    4545;;
    46 ; Restores GC context before doing iret.
    47 ;
    48 ; @param    [esp + 4]   Pointer to interrupt stack frame, i.e. pointer
    49 ;                       to the a struct with this layout:
    50 ;                           00h eip
    51 ;                           04h cs
    52 ;                           08h eflags
    53 ;                           0ch esp
    54 ;                           10h ss
    55 ;                           14h es (V86 only)
    56 ;                           18h ds (V86 only)
    57 ;                           1Ch fs (V86 only)
    58 ;                           20h gs (V86 only)
    59 ;
    60 ; @uses     everything but cs, ss, esp, and eflags.
    61 ;
    62 ; @remark   Assumes we're restoring in Ring-0 a context which is not Ring-0.
    63 ;           Further assumes flat stack and valid ds.
    64 
    65 BEGINPROC CPUMGCRestoreInt
    66     ;
    67     ; Update iret frame.
    68     ;
    69     mov     eax, [esp + 4]              ; get argument
    70     mov     edx, IMP(g_CPUM)
    71     ; Convert to CPUMCPU pointer
    72     add     edx, [edx + CPUM.offCPUMCPU0]
    73 
    74     mov     ecx, [edx + CPUMCPU.Guest.eip]
    75     mov     [eax +  0h], ecx
    76     mov     ecx, [edx + CPUMCPU.Guest.cs.Sel]
    77     mov     [eax +  4h], ecx
    78     mov     ecx, [edx + CPUMCPU.Guest.eflags]
    79     mov     [eax +  8h], ecx
    80     mov     ecx, [edx + CPUMCPU.Guest.esp]
    81     mov     [eax + 0ch], ecx
    82     mov     ecx, [edx + CPUMCPU.Guest.ss.Sel]
    83     mov     [eax + 10h], ecx
    84 
    85     test    dword [edx + CPUMCPU.Guest.eflags], X86_EFL_VM
    86     jnz short CPUMGCRestoreInt_V86
    87 
    88     ;
    89     ; Load registers.
    90     ;
    91     ; todo: potential trouble loading invalid es,fs,gs,ds because
    92     ;       of a VMM imposed exception?
    93     mov     es,  [edx + CPUMCPU.Guest.es.Sel]
    94     mov     fs,  [edx + CPUMCPU.Guest.fs.Sel]
    95     mov     gs,  [edx + CPUMCPU.Guest.gs.Sel]
    96     mov     esi, [edx + CPUMCPU.Guest.esi]
    97     mov     edi, [edx + CPUMCPU.Guest.edi]
    98     mov     ebp, [edx + CPUMCPU.Guest.ebp]
    99     mov     ebx, [edx + CPUMCPU.Guest.ebx]
    100     mov     ecx, [edx + CPUMCPU.Guest.ecx]
    101     mov     eax, [edx + CPUMCPU.Guest.eax]
    102     push    dword [edx + CPUMCPU.Guest.ds.Sel]
    103     mov     edx, [edx + CPUMCPU.Guest.edx]
    104     pop     ds
    105 
    106     ret
    107 
    108 CPUMGCRestoreInt_V86:
    109     ; iret restores ds, es, fs & gs
    110     mov     ecx, [edx + CPUMCPU.Guest.es.Sel]
    111     mov     [eax + 14h], ecx
    112     mov     ecx, [edx + CPUMCPU.Guest.ds.Sel]
    113     mov     [eax + 18h], ecx
    114     mov     ecx, [edx + CPUMCPU.Guest.fs.Sel]
    115     mov     [eax + 1Ch], ecx
    116     mov     ecx, [edx + CPUMCPU.Guest.gs.Sel]
    117     mov     [eax + 20h], ecx
    118     mov     esi, [edx + CPUMCPU.Guest.esi]
    119     mov     edi, [edx + CPUMCPU.Guest.edi]
    120     mov     ebp, [edx + CPUMCPU.Guest.ebp]
    121     mov     ebx, [edx + CPUMCPU.Guest.ebx]
    122     mov     ecx, [edx + CPUMCPU.Guest.ecx]
    123     mov     eax, [edx + CPUMCPU.Guest.eax]
    124     mov     edx, [edx + CPUMCPU.Guest.edx]
    125     ret
    126 
    127 ENDPROC CPUMGCRestoreInt
    128 
    129 
    130 ;;
    13146; Calls a guest trap/interrupt handler directly
    13247; Assumes a trap stack frame has already been setup on the guest's stack!
  • trunk/src/VBox/VMM/VMMRC/TRPMRC.cpp

    r41823 r41931  
    8585    LogFlow(("TRPMGCHyperReturnToHost: rc=%Rrc\n", rc));
    8686    TRPMResetTrap(pVCpu);
    87     CPUMHyperSetCtxCore(pVCpu, NULL);
    8887    VMMGCGuestToHost(pVM, rc);
    8988    AssertReleaseFailed();
  • trunk/src/VBox/VMM/VMMRC/TRPMRCHandlersA.asm

    r41906 r41931  
    3131;* External Symbols                                                            *
    3232;*******************************************************************************
    33 extern IMPNAME(g_CPUM)                  ; These IMPNAME(g_*) symbols resolve to the import table
    34 extern IMPNAME(g_TRPM)                  ; where there is a pointer to the real symbol. PE imports
    35 extern IMPNAME(g_TRPMCPU)               ; are a bit confusing at first... :-)
    36 extern IMPNAME(g_VM)
    37 extern NAME(CPUMGCRestoreInt)
    38 extern NAME(cpumHandleLazyFPUAsm)
    39 extern NAME(CPUMHyperSetCtxCore)
     33extern IMPNAME(g_TRPM)                  ; These IMPNAME(g_*) symbols resolve to the import table
     34extern IMPNAME(g_TRPMCPU)               ; where there is a pointer to the real symbol. PE imports
     35extern IMPNAME(g_VM)                    ; are a bit confusing at first... :-)
     36extern IMPNAME(g_trpmGuestCtxCore)
     37extern IMPNAME(g_trpmHyperCtxCore)
    4038extern NAME(trpmGCTrapInGeneric)
    4139extern NAME(TRPMGCTrap01Handler)
     
    5654extern NAME(TRPMGCHyperTrap0eHandler)
    5755
    58 ;; IMPORTANT all COM_ functions trashes esi, some edi and the LOOP_SHORT_WHILE kills ecx.
     56
     57;*******************************************************************************
     58;*  Defined Constants And Macros                                               *
     59;*******************************************************************************
     60;; Some conditional COM port debugging.
    5961;%define DEBUG_STUFF 1
    6062;%define DEBUG_STUFF_TRPG 1
    6163;%define DEBUG_STUFF_INT 1
     64
    6265
    6366BEGINCODE
     
    244247
    245248    ;
    246     ; Setup CPUMCTXCORE frame
     249    ; Save ds, es, eax and ebx so we have a context pointer (ebx) and
     250    ; scratch (eax) register to work with.  A sideeffect of using ebx is that
     251    ; it's preserved accross cdecl calls.
     252    ;
     253    ; 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
     258    push    eax                         ; +04h
     259    push    ebx                         ; +00h
     260%push foobar
     261%define %$STK_SAVED_EBX   esp
     262%define %$STK_SAVED_EAX   esp + 04h
     263%define %$STK_SAVED_ES    esp + 08h
     264%define %$STK_SAVED_DS    esp + 0ch
     265%define %$ESPOFF                10h
     266%define %$STK_VECTOR      esp + 00h + %$ESPOFF
     267%define %$STK_ERRCD       esp + 04h + %$ESPOFF
     268%define %$STK_EIP         esp + 08h + %$ESPOFF
     269%define %$STK_CS          esp + 0ch + %$ESPOFF
     270%define %$STK_EFLAGS      esp + 10h + %$ESPOFF
     271%define %$STK_ESP         esp + 14h + %$ESPOFF
     272%define %$STK_SS          esp + 18h + %$ESPOFF
     273%define %$STK_V86_ES      esp + 1ch + %$ESPOFF
     274%define %$STK_V86_DS      esp + 20h + %$ESPOFF
     275%define %$STK_V86_FS      esp + 24h + %$ESPOFF
     276%define %$STK_V86_GS      esp + 28h + %$ESPOFF
     277
     278    push    ss
     279    pop     ds
     280    push    ss
     281    pop     es
     282
     283    mov     eax, cr0                        ;; @todo elimitate this read?
     284    and     eax, ~X86_CR0_WRITE_PROTECT
     285    mov     cr0, eax
     286
     287    mov     ebx, IMP(g_trpmGuestCtxCore)    ; Assume GC as the most common.
     288    test    byte [%$STK_CS], 3h               ; check RPL of the cs selector
     289    ;; @todo check this for conforming segments.
     290    jnz     .save_state
     291    test    dword [%$STK_EFLAGS], X86_EFL_VM  ; If in V86, then guest.
     292    jnz     .save_state
     293    mov     ebx, IMP(g_trpmHyperCtxCore)    ; It's raw-mode context, actually.
     294
     295    ;
     296    ; Save the state.
    247297    ;
    248298    ;   ASSUMPTION: If trap in hypervisor, we assume that we can read two dword
    249299    ;               under the bottom of the stack. This is atm safe.
    250     ;   ASSUMPTION: There is sufficient stack space.
    251     ;   ASSUMPTION: The stack is not write protected.
    252     ;
    253 %define ESPOFF CPUMCTXCORE_size
    254 
    255     sub     esp, CPUMCTXCORE_size
    256     mov     [esp + CPUMCTXCORE.eax], eax
    257     mov     [esp + CPUMCTXCORE.ecx], ecx
    258     mov     [esp + CPUMCTXCORE.edx], edx
    259     mov     [esp + CPUMCTXCORE.ebx], ebx
    260     mov     [esp + CPUMCTXCORE.esi], esi
    261     mov     [esp + CPUMCTXCORE.edi], edi
    262     mov     [esp + CPUMCTXCORE.ebp], ebp
    263 
    264     mov     eax, [esp + 14h + ESPOFF]           ; esp
    265     mov     [esp + CPUMCTXCORE.esp], eax
    266     mov     eax, [esp + 18h + ESPOFF]           ; ss
    267     mov     dword [esp + CPUMCTXCORE.ss.Sel], eax
    268 
    269     mov     eax, [esp + 0ch + ESPOFF]           ; cs
    270     mov     dword [esp + CPUMCTXCORE.cs.Sel], eax
    271     mov     eax, [esp + 08h + ESPOFF]           ; eip
    272     mov     [esp + CPUMCTXCORE.eip], eax
    273     mov     eax, [esp + 10h + ESPOFF]           ; eflags
    274     mov     [esp + CPUMCTXCORE.eflags], eax
    275 
    276 %if GC_ARCH_BITS == 64
    277     ; zero out the high dwords
    278     mov     dword [esp + CPUMCTXCORE.eax + 4], 0
    279     mov     dword [esp + CPUMCTXCORE.ecx + 4], 0
    280     mov     dword [esp + CPUMCTXCORE.edx + 4], 0
    281     mov     dword [esp + CPUMCTXCORE.ebx + 4], 0
    282     mov     dword [esp + CPUMCTXCORE.esi + 4], 0
    283     mov     dword [esp + CPUMCTXCORE.edi + 4], 0
    284     mov     dword [esp + CPUMCTXCORE.ebp + 4], 0
    285     mov     dword [esp + CPUMCTXCORE.esp + 4], 0
    286     mov     dword [esp + CPUMCTXCORE.eip + 4], 0
    287 %endif
    288 
    289     mov     eax, es
    290     mov     dword [esp + CPUMCTXCORE.es.Sel], eax
    291     mov     eax, ds
    292     mov     dword [esp + CPUMCTXCORE.ds.Sel], eax
    293     mov     eax, fs
    294     mov     dword [esp + CPUMCTXCORE.fs.Sel], eax
    295     mov     eax, gs
    296     mov     dword [esp + CPUMCTXCORE.gs.Sel], eax
    297 
    298     test    dword [esp + CPUMCTXCORE.eflags], X86_EFL_VM
    299     jz short gt_SkipV86Entry
    300 
    301     ;
    302     ; The DS, ES, FS and GS registers are zeroed in V86 mode and their real values are on the stack
    303     ;
    304     mov     eax, dword [esp + ESPOFF + 1Ch]
    305     mov     dword [esp + CPUMCTXCORE.es.Sel], eax
    306 
    307     mov     eax, dword [esp + ESPOFF + 20h]
    308     mov     dword [esp + CPUMCTXCORE.ds.Sel], eax
    309 
    310     mov     eax, dword [esp + ESPOFF + 24h]
    311     mov     dword [esp + CPUMCTXCORE.fs.Sel], eax
    312 
    313     mov     eax, dword [esp + ESPOFF + 28h]
    314     mov     dword [esp + CPUMCTXCORE.gs.Sel], eax
    315 
    316 gt_SkipV86Entry:
    317     ;
    318     ; Disable Ring-0 WP
    319     ;
    320     mov     eax, cr0                    ;; @todo elimitate this read?
    321     and     eax, ~X86_CR0_WRITE_PROTECT
    322     mov     cr0, eax
    323 
    324     ;
    325     ; Load Hypervisor DS and ES (get it from the SS)
    326     ;
    327     mov     eax, ss
    328     mov     ds, eax
    329     mov     es, eax
     300    ;
     301.save_state:
     302    mov     eax, [%$STK_SAVED_EAX]
     303    mov     [ebx + CPUMCTXCORE.eax], eax
     304    mov     [ebx + CPUMCTXCORE.ecx], ecx
     305    mov     [ebx + CPUMCTXCORE.edx], edx
     306    mov     eax, [%$STK_SAVED_EBX]
     307    mov     [ebx + CPUMCTXCORE.ebx], eax
     308    mov     [ebx + CPUMCTXCORE.esi], esi
     309    mov     [ebx + CPUMCTXCORE.edi], edi
     310    mov     [ebx + CPUMCTXCORE.ebp], ebp
     311
     312    mov     eax, [%$STK_ESP]
     313    mov     [ebx + CPUMCTXCORE.esp], eax
     314    mov     cx, [%$STK_SS]
     315    mov     [ebx + CPUMCTXCORE.ss.Sel], cx
     316
     317    mov     cx, [%$STK_CS]
     318    mov     [ebx + CPUMCTXCORE.cs.Sel], cx
     319    mov     eax, [%$STK_EIP]
     320    mov     [ebx + CPUMCTXCORE.eip], eax
     321    mov     eax, [%$STK_EFLAGS]
     322    mov     [ebx + CPUMCTXCORE.eflags], eax
     323
     324%if GC_ARCH_BITS == 64 ; zero out the high dwords - probably not necessary any more.
     325    mov     dword [ebx + CPUMCTXCORE.eax + 4], 0
     326    mov     dword [ebx + CPUMCTXCORE.ecx + 4], 0
     327    mov     dword [ebx + CPUMCTXCORE.edx + 4], 0
     328    mov     dword [ebx + CPUMCTXCORE.ebx + 4], 0
     329    mov     dword [ebx + CPUMCTXCORE.esi + 4], 0
     330    mov     dword [ebx + CPUMCTXCORE.edi + 4], 0
     331    mov     dword [ebx + CPUMCTXCORE.ebp + 4], 0
     332    mov     dword [ebx + CPUMCTXCORE.esp + 4], 0
     333    mov     dword [ebx + CPUMCTXCORE.eip + 4], 0
     334%endif
     335
     336    test    dword [%$STK_EFLAGS], X86_EFL_VM
     337    jnz     .save_V86_segregs
     338
     339    mov     cx, [%$STK_SAVED_ES]
     340    mov     [ebx + CPUMCTXCORE.es.Sel], cx
     341    mov     cx, [%$STK_SAVED_DS]
     342    mov     [ebx + CPUMCTXCORE.ds.Sel], cx
     343    mov     cx, fs
     344    mov     [ebx + CPUMCTXCORE.fs.Sel], cx
     345    mov     cx, gs
     346    mov     [ebx + CPUMCTXCORE.gs.Sel], cx
     347    jmp     .done_saving
     348
     349    ;
     350    ; The DS, ES, FS and GS registers are zeroed in V86 mode and their real
     351    ; values are on the stack.
     352    ;
     353.save_V86_segregs:
     354    mov     cx, [%$STK_V86_ES]
     355    mov     [ebx + CPUMCTXCORE.es.Sel], cx
     356    mov     cx, [%$STK_V86_DS]
     357    mov     [ebx + CPUMCTXCORE.ds.Sel], cx
     358    mov     cx, [%$STK_V86_FS]
     359    mov     [ebx + CPUMCTXCORE.fs.Sel], cx
     360    mov     cx, [%$STK_V86_GS]
     361    mov     [ebx + CPUMCTXCORE.gs.Sel], cx
     362
     363.done_saving:
    330364
    331365%ifdef VBOX_WITH_STATISTICS
     
    333367    ; Start profiling.
    334368    ;
    335     mov     edx, [esp +  0h + ESPOFF]   ; vector number
     369    mov     edx, [%$STK_VECTOR]
    336370    imul    edx, edx, byte STAMPROFILEADV_size ; assumes < 128.
    337371    add     edx, TRPM.aStatGCTraps
     
    343377    ; Store the information about the active trap/interrupt.
    344378    ;
    345     mov     eax, IMP(g_TRPMCPU)
    346     movzx   edx, byte [esp + 0h + ESPOFF]  ; vector number
    347     mov     [eax + TRPMCPU.uActiveVector], edx
    348     mov     edx, [esp + 4h + ESPOFF]       ; error code
    349     mov     [eax + TRPMCPU.uActiveErrorCode], edx
    350     mov     dword [eax + TRPMCPU.enmActiveType], TRPM_TRAP
     379    mov     esi, IMP(g_TRPMCPU)         ; esi = TRPMCPU until resume!
     380    movzx   edx, byte [%$STK_VECTOR]
     381    mov     [esi + TRPMCPU.uActiveVector], edx
     382    mov     edx, [%$STK_ERRCD]
     383    mov     [esi + TRPMCPU.uActiveErrorCode], edx
     384    mov     dword [esi + TRPMCPU.enmActiveType], TRPM_TRAP
    351385    mov     edx, cr2                       ;; @todo Check how expensive cr2 reads are!
    352     mov     dword [eax + TRPMCPU.uActiveCR2], edx
    353 
    354 %if GC_ARCH_BITS == 64
    355     ; zero out the high dword
    356     mov     dword [eax + TRPMCPU.uActiveErrorCode + 4], 0
    357     mov     dword [eax + TRPMCPU.uActiveCR2 + 4], 0
    358 %endif
    359 
    360     ;
    361     ; Check if we're in Hypervisor when this happened.
    362     ;
    363     test    dword [esp + CPUMCTXCORE.eflags], X86_EFL_VM
    364     jnz short gt_NotHyperVisor
    365 
    366     test    byte [esp + 0ch + ESPOFF], 3h ; check CPL of the cs selector
    367     jz      near gt_InHypervisor
     386    mov     dword [esi + TRPMCPU.uActiveCR2], edx
     387%if GC_ARCH_BITS == 64 ; zero out the high dwords.
     388    mov     dword [esi + TRPMCPU.uActiveErrorCode + 4], 0
     389    mov     dword [esi + TRPMCPU.uActiveCR2 + 4], 0
     390%endif
     391
     392    ;
     393    ; Check if we're in the raw-mode context (RC / hypervisor) when this happened.
     394    ;
     395    test    dword [%$STK_EFLAGS], X86_EFL_VM
     396    jnz short .gc_not_raw_mode_context
     397
     398    test    byte [%$STK_CS], 3h           ; check RPL of the cs selector
     399    jz      .rc_in_raw_mode_context
    368400
    369401    ;
    370402    ; Trap in guest code.
    371403    ;
    372 gt_NotHyperVisor:
     404.gc_not_raw_mode_context:
    373405%ifdef DEBUG_STUFF_TRPG
    374     mov     ebx, [esp +  4h + ESPOFF]   ; error code
     406    mov     eax, [%$STK_ERRCD]
    375407    mov     ecx, 'trpG'                 ; indicate trap.
    376     mov     edx, [esp +  0h + ESPOFF]   ; vector number
    377     lea     eax, [esp]
     408    mov     edx, [%$STK_VECTOR]
    378409    call    trpmDbgDumpRegisterFrame
    379410%endif
     
    382413    ; Do we have a GC handler for these traps?
    383414    ;
    384     mov     edx, [esp +  0h + ESPOFF]   ; vector number
     415    mov     edx, [%$STK_VECTOR]
    385416    mov     eax, [g_apfnStaticTrapHandlersGuest + edx * 4]
    386417    or      eax, eax
    387     jnz short gt_HaveHandler
     418    jnz short .gc_have_static_handler
    388419    mov     eax, VINF_EM_RAW_GUEST_TRAP
    389     jmp short gt_GuestTrap
     420    jmp short .gc_guest_trap
    390421
    391422    ;
    392423    ; Call static handler.
    393424    ;
    394 gt_HaveHandler:
    395     push    esp                         ; Param 2 - CPUMCTXCORE pointer.
    396     push    dword IMP(g_TRPMCPU)        ; Param 1 - Pointer to TRPMCPU
     425.gc_have_static_handler:
     426    push    ebx                         ; Param 2 - CPUMCTXCORE pointer.
     427    push    esi                         ; Param 1 - Pointer to TRPMCPU.
    397428    call    eax
    398429    add     esp, byte 8                 ; cleanup stack (cdecl)
    399430    or      eax, eax
    400     je near gt_continue_guest
     431    je near .gc_continue_guest
    401432
    402433    ;
    403434    ; Switch back to the host and process it there.
    404435    ;
    405 gt_GuestTrap:
     436.gc_guest_trap:
    406437%ifdef VBOX_WITH_STATISTICS
    407     mov     edx, [esp +  0h + ESPOFF]   ; vector number
     438    mov     edx, [%$STK_VECTOR]
    408439    imul    edx, edx, byte STAMPROFILEADV_size ; assume < 128
    409440    add     edx, IMP(g_TRPM)
     
    412443%endif
    413444    mov     edx, IMP(g_VM)
    414     call    [edx + VM.pfnVMMGCGuestToHostAsmGuestCtx]
    415 
    416     ;; @todo r=bird: is this path actually every taken? if not we should replace this code with a panic.
    417     ;
    418     ; We've returned!
    419     ; N.B. The stack has been changed now! No CPUMCTXCORE any longer. esp = vector number.
    420     ; N.B. Current scheduling design causes this code path to be unused.
    421     ; N.B. Better not use it when in V86 mode!
    422     ;
    423 
    424     ; Enable WP
    425     mov     eax, cr0                    ;; @todo try elimiate this read.
    426     or      eax, X86_CR0_WRITE_PROTECT
    427     mov     cr0, eax
    428     ; Restore guest context and continue execution.
    429     mov     edx, IMP(g_CPUM)
    430     lea     eax, [esp + 8]
    431     push    eax
    432     call    NAME(CPUMGCRestoreInt)
    433     lea     esp, [esp + 0ch]            ; cleanup call and skip vector & error code.
    434 
    435     iret
    436 
     445    call    [edx + VM.pfnVMMGCGuestToHostAsm]
     446
     447    ; We shouldn't ever return this way. So, raise a special IPE if we do.
     448.gc_panic_again:
     449    mov     eax, VERR_TRPM_IPE_3
     450    mov     edx, IMP(g_VM)
     451    call    [edx + VM.pfnVMMGCGuestToHostAsm]
     452    jmp     .gc_panic_again
    437453
    438454    ;
     
    440456    ;
    441457ALIGNCODE(16)
    442 gt_continue_guest:
     458.gc_continue_guest:
    443459%ifdef VBOX_WITH_STATISTICS
    444     mov     edx, [esp +  0h + ESPOFF]   ; vector number
     460    mov     edx, [%$STK_VECTOR]
    445461    imul    edx, edx, byte STAMPROFILEADV_size ; assumes < 128
    446462    add     edx, TRPM.aStatGCTraps
     
    455471
    456472    ; restore guest state and start executing again.
    457     test    dword [esp + CPUMCTXCORE.eflags], X86_EFL_VM
    458     jnz     gt_V86Return
    459 
    460     mov     ecx, [esp + CPUMCTXCORE.ecx]
    461     mov     edx, [esp + CPUMCTXCORE.edx]
    462     mov     ebx, [esp + CPUMCTXCORE.ebx]
    463     mov     ebp, [esp + CPUMCTXCORE.ebp]
    464     mov     esi, [esp + CPUMCTXCORE.esi]
    465     mov     edi, [esp + CPUMCTXCORE.edi]
    466 
    467     mov     eax, [esp + CPUMCTXCORE.esp]
    468     mov     [esp + 14h + ESPOFF], eax           ; esp
    469     mov     eax, dword [esp + CPUMCTXCORE.ss.Sel]
    470     mov     [esp + 18h + ESPOFF], eax           ; ss
    471 
    472     mov     eax, dword [esp + CPUMCTXCORE.gs.Sel]
     473    mov     eax, [ebx + CPUMCTXCORE.eax]
     474    mov     [%$STK_SAVED_EAX], eax
     475    mov     ecx, [ebx + CPUMCTXCORE.ecx]
     476    mov     edx, [ebx + CPUMCTXCORE.edx]
     477    mov     eax, [ebx + CPUMCTXCORE.ebx]
     478    mov     [%$STK_SAVED_EBX], eax
     479    mov     ebp, [ebx + CPUMCTXCORE.ebp]
     480    mov     esi, [ebx + CPUMCTXCORE.esi]
     481    mov     edi, [ebx + CPUMCTXCORE.edi]
     482
     483    mov     eax, [ebx + CPUMCTXCORE.esp]
     484    mov     [%$STK_ESP], eax
     485    mov     eax, dword [ebx + CPUMCTXCORE.ss.Sel]
     486    mov     [%$STK_SS], eax
     487    mov     eax, [ebx + CPUMCTXCORE.eflags]
     488    mov     [%$STK_EFLAGS], eax
     489    mov     eax, dword [ebx + CPUMCTXCORE.cs.Sel]
     490    mov     [%$STK_CS], eax
     491    mov     eax, [ebx + CPUMCTXCORE.eip]
     492    mov     [%$STK_EIP], eax
     493
     494    test    dword [ebx + CPUMCTXCORE.eflags], X86_EFL_VM
     495    jnz     .gc_V86_return
     496
     497    mov     ax, [ebx + CPUMCTXCORE.gs.Sel]
    473498    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_GS
    474     mov     gs, eax
    475 
    476     mov     eax, dword [esp + CPUMCTXCORE.fs.Sel]
     499    mov     gs, ax
     500
     501    mov     ax, [ebx + CPUMCTXCORE.fs.Sel]
    477502    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_FS
    478     mov     fs, eax
    479 
    480     mov     eax, dword [esp + CPUMCTXCORE.es.Sel]
     503    mov     fs, ax
     504
     505    mov     ax, [ebx + CPUMCTXCORE.es.Sel]
    481506    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_ES
    482     mov     es, eax
    483 
    484     mov     eax, dword [esp + CPUMCTXCORE.ds.Sel]
     507    mov     es, ax
     508
     509    mov     ax, [ebx + CPUMCTXCORE.ds.Sel]
    485510    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_DS
    486     mov     ds, eax
    487 
    488     mov     eax, dword [esp + CPUMCTXCORE.cs.Sel]
    489     mov     [esp + 0ch + ESPOFF], eax           ; cs
    490     mov     eax, [esp + CPUMCTXCORE.eflags]
    491     mov     [esp + 10h + ESPOFF], eax           ; eflags
    492     mov     eax, [esp + CPUMCTXCORE.eip]
    493     mov     [esp + 08h + ESPOFF], eax           ; eip
    494 
    495     ; finally restore our scratch register eax
    496     mov     eax, [esp + CPUMCTXCORE.eax]
    497 
    498     add     esp, ESPOFF + 8                     ; skip CPUMCTXCORE structure, error code and vector number
     511    mov     ds, ax
     512
     513    ; finally restore our scratch register eax and ebx.
     514    pop     ebx
     515    pop     eax
     516
     517    add     esp, 8 + 8                          ; skip ds, es, the error code, and vector number.
    499518
    500519    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_IRET
     
    502521
    503522ALIGNCODE(16)
    504 gt_V86Return:
    505     mov     ecx, [esp + CPUMCTXCORE.ecx]
    506     mov     edx, [esp + CPUMCTXCORE.edx]
    507     mov     ebx, [esp + CPUMCTXCORE.ebx]
    508     mov     ebp, [esp + CPUMCTXCORE.ebp]
    509     mov     esi, [esp + CPUMCTXCORE.esi]
    510     mov     edi, [esp + CPUMCTXCORE.edi]
    511 
    512     mov     eax, [esp + CPUMCTXCORE.esp]
    513     mov     [esp + 14h + ESPOFF], eax           ; esp
    514     mov     eax, dword [esp + CPUMCTXCORE.ss.Sel]
    515     mov     [esp + 18h + ESPOFF], eax           ; ss
    516 
    517     mov     eax, dword [esp + CPUMCTXCORE.es.Sel]
    518     mov     [esp + 1ch + ESPOFF], eax           ; es
    519     mov     eax, dword [esp + CPUMCTXCORE.ds.Sel]
    520     mov     [esp + 20h + ESPOFF], eax           ; ds
    521     mov     eax, dword [esp + CPUMCTXCORE.fs.Sel]
    522     mov     [esp + 24h + ESPOFF], eax           ; fs
    523     mov     eax, dword [esp + CPUMCTXCORE.gs.Sel]
    524     mov     [esp + 28h + ESPOFF], eax           ; gs
    525 
    526     mov     eax, [esp + CPUMCTXCORE.eip]
    527     mov     [esp + 08h + ESPOFF], eax           ; eip
    528     mov     eax, dword [esp + CPUMCTXCORE.cs.Sel]
    529     mov     [esp + 0ch + ESPOFF], eax           ; cs
    530     mov     eax, [esp + CPUMCTXCORE.eflags]
    531     mov     [esp + 10h + ESPOFF], eax           ; eflags
    532 
    533     ; finally restore our scratch register eax
    534     mov     eax, [esp + CPUMCTXCORE.eax]
    535 
    536     add     esp, ESPOFF + 8                     ; skip CPUMCTXCORE structure, error code and vector number
     523.gc_V86_return:
     524    mov     eax, dword [ebx + CPUMCTXCORE.es.Sel]
     525    mov     [%$STK_V86_ES], eax
     526    mov     eax, dword [ebx + CPUMCTXCORE.ds.Sel]
     527    mov     [%$STK_V86_DS], eax
     528    mov     eax, dword [ebx + CPUMCTXCORE.fs.Sel]
     529    mov     [%$STK_V86_FS], eax
     530    mov     eax, dword [ebx + CPUMCTXCORE.gs.Sel]
     531    mov     [%$STK_V86_GS], eax
     532
     533    ; finally restore our scratch register eax and ebx.
     534    pop     ebx
     535    pop     eax
     536
     537    add     esp, 8 + 8                          ; skip ds, es, the error code, and vector number.
    537538
    538539    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_IRET | TRPM_TRAP_IN_V86
     
    545546    ;
    546547ALIGNCODE(16)
    547 gt_InHypervisor:
     548.rc_in_raw_mode_context:
    548549    ; fix ss:esp.
    549     lea     ebx, [esp + 14h + ESPOFF]   ; calc esp at trap
    550     mov     [esp + CPUMCTXCORE.esp], ebx; update esp in register frame
    551     mov     [esp + CPUMCTXCORE.ss.Sel], ss ; update ss in register frame
    552 
    553     ; tell cpum about the context core.
    554     xchg    esi, eax                    ; save pTRPMCPU - @todo reallocate this variable to esi, edi, or ebx
    555     push    esp                         ; Param 2 - The new CPUMCTXCORE pointer.
    556     mov     eax, IMP(g_VM)              ; Param 1 - Pointer to the VMCPU.
    557     add     eax, [eax + VM.offVMCPU]
    558     push    eax
    559     call    NAME(CPUMHyperSetCtxCore)
    560     add     esp, byte 8                 ; stack cleanup (cdecl)
    561     xchg    eax, esi                    ; restore pTRPMCPU
     550    lea     ecx, [%$STK_ESP]              ; calc esp at trap
     551    mov     [ebx + CPUMCTXCORE.esp], ecx; update esp in register frame
     552    mov     [ebx + CPUMCTXCORE.ss.Sel], ss ; update ss in register frame
    562553
    563554    ; check for temporary handler.
    564     movzx   ebx, byte [eax + TRPMCPU.uActiveVector]
    565     mov     esi, IMP(g_TRPM)            ; keep eax == pTRPMCPU
     555    movzx   edx, byte [esi + TRPMCPU.uActiveVector]
     556    mov     edi, IMP(g_TRPM)
    566557    xor     ecx, ecx
    567     xchg    ecx, [esi + TRPM.aTmpTrapHandlers + ebx * 4]    ; ecx = Temp handler pointer or 0
     558    xchg    ecx, [edi + TRPM.aTmpTrapHandlers + edx * 4]    ; ecx = Temp handler pointer or 0
    568559    or      ecx, ecx
    569     jnz short gt_Hyper_HaveTemporaryHandler
     560    jnz short .rc_have_temporary_handler
    570561
    571562    ; check for static trap handler.
    572     mov     ecx, [g_apfnStaticTrapHandlersHyper + ebx * 4]  ; ecx = Static handler pointer or 0
     563    mov     ecx, [g_apfnStaticTrapHandlersHyper + edx * 4]  ; ecx = Static handler pointer or 0
    573564    or      ecx, ecx
    574     jnz short gt_Hyper_HaveStaticHandler
    575     jmp     gt_Hyper_AbandonShip
     565    jnz short .rc_have_static_handler
     566    jmp     .rc_abandon_ship
    576567
    577568
     
    579570    ; Temporary trap handler present, call it (CDECL).
    580571    ;
    581 gt_Hyper_HaveTemporaryHandler:
    582     push    esp                         ; Param 2 - Pointer to CPUMCTXCORE.
     572.rc_have_temporary_handler:
     573    push    ebx                         ; Param 2 - Pointer to CPUMCTXCORE.
    583574    push    IMP(g_VM)                   ; Param 1 - Pointer to VM.
    584575    call    ecx
     
    586577
    587578    cmp     eax, byte VINF_SUCCESS      ; If completely handled Then resume execution.
    588     je      near gt_Hyper_Continue
    589     ;; @todo Handle ALL returns types from temporary handlers!
    590     jmp     gt_Hyper_AbandonShip
     579    je      near .rc_continue
     580    jmp     .rc_abandon_ship
    591581
    592582
     
    594584    ; Static trap handler present, call it (CDECL).
    595585    ;
    596 gt_Hyper_HaveStaticHandler:
    597     push    esp                         ; Param 2 - Pointer to CPUMCTXCORE.
    598     push    eax                         ; Param 1 - Pointer to TRPMCPU
     586.rc_have_static_handler:
     587    push    ebx                         ; Param 2 - Pointer to CPUMCTXCORE.
     588    push    esi                         ; Param 1 - Pointer to TRPMCPU
    599589    call    ecx
    600590    add     esp, byte 8                 ; cleanup stack (cdecl)
    601591
    602592    cmp     eax, byte VINF_SUCCESS      ; If completely handled Then resume execution.
    603     je short gt_Hyper_Continue
     593    je short .rc_continue
    604594    cmp     eax, VINF_EM_DBG_HYPER_STEPPED
    605     je short gt_Hyper_ToHost
     595    je short .rc_to_host
    606596    cmp     eax, VINF_EM_DBG_HYPER_BREAKPOINT
    607     je short gt_Hyper_ToHost
     597    je short .rc_to_host
    608598    cmp     eax, VINF_EM_DBG_HYPER_ASSERTION
    609     je short gt_Hyper_ToHost
    610     jmp     gt_Hyper_AbandonShip
     599    je short .rc_to_host
     600    jmp     .rc_abandon_ship
    611601
    612602    ;
    613603    ; Pop back to the host to service the error.
    614604    ;
    615 gt_Hyper_ToHost:
    616     mov     ecx, esp
     605.rc_to_host:
     606    mov     ecx, ebx
    617607    mov     edx, IMP(g_VM)
    618608    call    [edx + VM.pfnVMMGCGuestToHostAsm]
    619     jmp short gt_Hyper_Continue
     609    jmp short .rc_continue
    620610
    621611    ;
     
    624614    ;
    625615ALIGNCODE(16)
    626 gt_Hyper_Continue:
     616.rc_continue:
    627617%ifdef DEBUG_STUFF
    628     mov     ebx, [esp +  4h + ESPOFF]   ; error code
     618    mov     eax, [%$STK_ERRCD]
    629619    mov     ecx, 'resH'                 ; indicate trap.
    630     mov     edx, [esp +  0h + ESPOFF]   ; vector number
    631     lea     eax, [esp]
     620    mov     edx, [%$STK_VECTOR]
    632621    call    trpmDbgDumpRegisterFrame
    633622%endif
    634     ; tell CPUM to use the default CPUMCTXCORE.
    635     push    byte 0                      ; Param 2 - NULL indicating use default context core.
    636     mov     eax, IMP(g_VM)              ; Param 1 - Pointer to the VMCPU.
    637     add     eax, [eax + VM.offVMCPU]
    638     push    eax
    639     call    NAME(CPUMHyperSetCtxCore)
    640     add     esp, byte 8                 ; stack cleanup (cdecl)
    641623
    642624%ifdef VBOX_WITH_STATISTICS
    643     mov     edx, [esp +  0h + ESPOFF]   ; vector number
     625    mov     edx, [%$STK_VECTOR]
    644626    imul    edx, edx, byte STAMPROFILEADV_size ; assumes < 128
    645627    add     edx, TRPM.aStatGCTraps
     
    649631
    650632    ; restore
    651     mov     ecx, [esp + CPUMCTXCORE.ecx]
    652     mov     edx, [esp + CPUMCTXCORE.edx]
    653     mov     ebx, [esp + CPUMCTXCORE.ebx]
    654     mov     ebp, [esp + CPUMCTXCORE.ebp]
    655     mov     esi, [esp + CPUMCTXCORE.esi]
    656     mov     edi, [esp + CPUMCTXCORE.edi]
    657 
    658     mov     eax, dword [esp + CPUMCTXCORE.gs.Sel]
     633    mov     eax, [ebx + CPUMCTXCORE.eax]
     634    mov     [%$STK_SAVED_EAX], eax
     635    mov     ecx, [ebx + CPUMCTXCORE.ecx]
     636    mov     edx, [ebx + CPUMCTXCORE.edx]
     637    mov     eax, [ebx + CPUMCTXCORE.ebx]
     638    mov     [%$STK_SAVED_EBX], eax
     639    mov     ebp, [ebx + CPUMCTXCORE.ebp]
     640    mov     esi, [ebx + CPUMCTXCORE.esi]
     641    mov     edi, [ebx + CPUMCTXCORE.edi]
     642
     643                                                ; skipping esp & ss.
     644
     645    mov     eax, [ebx + CPUMCTXCORE.eflags]
     646    mov     [%$STK_EFLAGS], eax
     647    mov     eax, dword [ebx + CPUMCTXCORE.cs.Sel]
     648    mov     [%$STK_CS], eax
     649    mov     eax, [ebx + CPUMCTXCORE.eip]
     650    mov     [%$STK_EIP], eax
     651
     652    mov     ax, [ebx + CPUMCTXCORE.gs.Sel]
    659653    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_GS | TRPM_TRAP_IN_HYPER
    660     mov     gs, eax
    661 
    662     mov     eax, dword [esp + CPUMCTXCORE.fs.Sel]
     654    mov     gs, ax
     655
     656    mov     ax, [ebx + CPUMCTXCORE.fs.Sel]
    663657    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_FS | TRPM_TRAP_IN_HYPER
    664     mov     fs, eax
    665 
    666     mov     eax, dword [esp + CPUMCTXCORE.es.Sel]
    667     mov     es, eax
    668     mov     eax, dword [esp + CPUMCTXCORE.ds.Sel]
    669     mov     ds, eax
    670 
    671     ; skip esp & ss
    672 
    673     mov     eax, [esp + CPUMCTXCORE.eip]
    674     mov     [esp + 08h + ESPOFF], eax           ; eip
    675     mov     eax, dword [esp + CPUMCTXCORE.cs.Sel]
    676     mov     [esp + 0ch + ESPOFF], eax           ; cs
    677     mov     eax, [esp + CPUMCTXCORE.eflags]
    678     mov     [esp + 10h + ESPOFF], eax           ; eflags
    679 
    680     ; finally restore our scratch register eax
    681     mov     eax, [esp + CPUMCTXCORE.eax]
    682 
    683     add     esp, ESPOFF + 8                     ; skip CPUMCTXCORE structure, error code and vector number
     658    mov     fs, ax
     659
     660    mov     ax, [ebx + CPUMCTXCORE.es.Sel]
     661    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_ES | TRPM_TRAP_IN_HYPER
     662    mov     es, ax
     663
     664    mov     ax, [ebx + CPUMCTXCORE.ds.Sel]
     665    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_DS | TRPM_TRAP_IN_HYPER
     666    mov     ds, ax
     667
     668    ; finally restore our scratch register eax and ebx.
     669    pop     ebx
     670    pop     eax
     671
     672    add     esp, 8 + 8                          ; skip ds, es, the error code, and vector number.
    684673
    685674    iret
     
    687676
    688677    ;
    689     ; ABANDON SHIP! DON'T PANIC!
    690     ;
    691 gt_Hyper_AbandonShip:
     678    ; Internal processing error - don't panic, start meditating!
     679    ;
     680.rc_abandon_ship:
    692681%ifdef DEBUG_STUFF
    693     mov     ebx, [esp +  4h + ESPOFF]   ; error code
     682    mov     eax, [%$STK_ERRCD]
    694683    mov     ecx, 'trpH'                 ; indicate trap.
    695     mov     edx, [esp +  0h + ESPOFF]   ; vector number
    696     lea     eax, [esp]
     684    mov     edx, [%$STK_VECTOR]
    697685    call    trpmDbgDumpRegisterFrame
    698686%endif
    699687
    700 gt_Hyper_DontPanic:
    701     mov     ecx, esp
     688.rc_do_not_panic:
    702689    mov     edx, IMP(g_VM)
    703690    mov     eax, VERR_TRPM_DONT_PANIC
    704     call    [edx + VM.pfnVMMGCGuestToHostAsmHyperCtx]
     691    call    [edx + VM.pfnVMMGCGuestToHostAsm]
    705692%ifdef DEBUG_STUFF
    706693    COM_S_PRINT 'bad!!!'
    707694%endif
    708     jmp     gt_Hyper_DontPanic          ; this shall never ever happen!
    709 %undef ESPOFF
     695    jmp     .rc_do_not_panic            ; this shall never ever happen!
     696%pop
    710697ENDPROC TRPMGCHandlerGeneric
    711698
     
    748735
    749736    ;
    750     ; Setup CPUMCTXCORE frame
     737    ; Save ds, es, eax and ebx so we have a context pointer (ebx) and
     738    ; scratch (eax) register to work with.  A sideeffect of using ebx is that
     739    ; it's preserved accross cdecl calls.
     740    ;
     741    ; 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
     746    push    eax                         ; +04h
     747    push    ebx                         ; +00h
     748%push foobar
     749%define %$STK_SAVED_EBX   esp
     750%define %$STK_SAVED_EAX   esp + 04h
     751%define %$STK_SAVED_ES    esp + 08h
     752%define %$STK_SAVED_DS    esp + 0ch
     753%define %$ESPOFF                10h
     754%define %$STK_VECTOR      esp + 00h + %$ESPOFF
     755%define %$STK_EIP         esp + 04h + %$ESPOFF
     756%define %$STK_CS          esp + 08h + %$ESPOFF
     757%define %$STK_EFLAGS      esp + 0ch + %$ESPOFF
     758%define %$STK_ESP         esp + 10h + %$ESPOFF
     759%define %$STK_SS          esp + 14h + %$ESPOFF
     760%define %$STK_V86_ES      esp + 18h + %$ESPOFF
     761%define %$STK_V86_DS      esp + 1ch + %$ESPOFF
     762%define %$STK_V86_FS      esp + 20h + %$ESPOFF
     763%define %$STK_V86_GS      esp + 24h + %$ESPOFF
     764
     765    push    ss
     766    pop     ds
     767    push    ss
     768    pop     es
     769
     770    mov     eax, cr0                        ;; @todo elimitate this read?
     771    and     eax, ~X86_CR0_WRITE_PROTECT
     772    mov     cr0, eax
     773
     774    mov     ebx, IMP(g_trpmGuestCtxCore)    ; Assume GC as the most common.
     775    test    byte [%$STK_CS], 3h               ; check RPL of the cs selector
     776    ;; @todo check this for conforming segments.
     777    jnz     .save_state
     778    test    dword [%$STK_EFLAGS], X86_EFL_VM  ; If in V86, then guest.
     779    jnz     .save_state
     780    mov     ebx, IMP(g_trpmHyperCtxCore)    ; It's raw-mode context, actually.
     781
     782    ;
     783    ; Save the state.
    751784    ;
    752785    ;   ASSUMPTION: If trap in hypervisor, we assume that we can read two dword
    753786    ;               under the bottom of the stack. This is atm safe.
    754     ;   ASSUMPTION: There is sufficient stack space.
    755     ;   ASSUMPTION: The stack is not write protected.
    756     ;
    757 %define ESPOFF CPUMCTXCORE_size
    758 
    759     sub     esp, CPUMCTXCORE_size
    760     mov     [esp + CPUMCTXCORE.eax], eax
    761     mov     [esp + CPUMCTXCORE.ecx], ecx
    762     mov     [esp + CPUMCTXCORE.edx], edx
    763     mov     [esp + CPUMCTXCORE.ebx], ebx
    764     mov     [esp + CPUMCTXCORE.esi], esi
    765     mov     [esp + CPUMCTXCORE.edi], edi
    766     mov     [esp + CPUMCTXCORE.ebp], ebp
    767 
    768     mov     eax, [esp + 04h + ESPOFF]           ; eip
    769     mov     [esp + CPUMCTXCORE.eip], eax
    770     mov     eax, dword [esp + 08h + ESPOFF]     ; cs
    771     mov     [esp + CPUMCTXCORE.cs.Sel], eax
    772     mov     eax, [esp + 0ch + ESPOFF]           ; eflags
    773     mov     [esp + CPUMCTXCORE.eflags], eax
    774 
    775     mov     eax, [esp + 10h + ESPOFF]           ; esp
    776     mov     [esp + CPUMCTXCORE.esp], eax
    777     mov     eax, dword [esp + 14h + ESPOFF]     ; ss
    778     mov     [esp + CPUMCTXCORE.ss.Sel], eax
    779 
    780 %if GC_ARCH_BITS == 64
    781     ; zero out the high dwords
    782     mov     dword [esp + CPUMCTXCORE.eax + 4], 0
    783     mov     dword [esp + CPUMCTXCORE.ecx + 4], 0
    784     mov     dword [esp + CPUMCTXCORE.edx + 4], 0
    785     mov     dword [esp + CPUMCTXCORE.ebx + 4], 0
    786     mov     dword [esp + CPUMCTXCORE.esi + 4], 0
    787     mov     dword [esp + CPUMCTXCORE.edi + 4], 0
    788     mov     dword [esp + CPUMCTXCORE.ebp + 4], 0
    789     mov     dword [esp + CPUMCTXCORE.esp + 4], 0
    790     mov     dword [esp + CPUMCTXCORE.eip + 4], 0
    791 %endif
    792 
    793     mov     eax, es
    794     mov     dword [esp + CPUMCTXCORE.es.Sel], eax
    795     mov     eax, ds
    796     mov     dword [esp + CPUMCTXCORE.ds.Sel], eax
    797     mov     eax, fs
    798     mov     dword [esp + CPUMCTXCORE.fs.Sel], eax
    799     mov     eax, gs
    800     mov     dword [esp + CPUMCTXCORE.gs.Sel], eax
    801 
    802     test    dword [esp + CPUMCTXCORE.eflags], X86_EFL_VM
    803     jz short ti_SkipV86Entry
    804 
    805     ;
    806     ; The DS, ES, FS and GS registers are zeroed in V86 mode and their real values are on the stack
    807     ;
    808     mov     eax, dword [esp + ESPOFF + 18h]
    809     mov     dword [esp + CPUMCTXCORE.es.Sel], eax
    810 
    811     mov     eax, dword [esp + ESPOFF + 1Ch]
    812     mov     dword [esp + CPUMCTXCORE.ds.Sel], eax
    813 
    814     mov     eax, dword [esp + ESPOFF + 20h]
    815     mov     dword [esp + CPUMCTXCORE.fs.Sel], eax
    816 
    817     mov     eax, dword [esp + ESPOFF + 24h]
    818     mov     dword [esp + CPUMCTXCORE.gs.Sel], eax
    819 
    820 ti_SkipV86Entry:
    821 
    822     ;
    823     ; Disable Ring-0 WP
    824     ;
    825     mov     eax, cr0                    ;; @todo try elimiate this read.
    826     and     eax, ~X86_CR0_WRITE_PROTECT
    827     mov     cr0, eax
    828 
    829     ;
    830     ; Load Hypervisor DS and ES (get it from the SS)
    831     ;
    832     mov     eax, ss
    833     mov     ds, eax
    834     mov     es, eax
     787    ;
     788.save_state:
     789    mov     eax, [%$STK_SAVED_EAX]
     790    mov     [ebx + CPUMCTXCORE.eax], eax
     791    mov     [ebx + CPUMCTXCORE.ecx], ecx
     792    mov     [ebx + CPUMCTXCORE.edx], edx
     793    mov     eax, [%$STK_SAVED_EBX]
     794    mov     [ebx + CPUMCTXCORE.ebx], eax
     795    mov     [ebx + CPUMCTXCORE.esi], esi
     796    mov     [ebx + CPUMCTXCORE.edi], edi
     797    mov     [ebx + CPUMCTXCORE.ebp], ebp
     798
     799    mov     eax, [%$STK_ESP]
     800    mov     [ebx + CPUMCTXCORE.esp], eax
     801    mov     cx, [%$STK_SS]
     802    mov     [ebx + CPUMCTXCORE.ss.Sel], cx
     803
     804    mov     cx, [%$STK_CS]
     805    mov     [ebx + CPUMCTXCORE.cs.Sel], cx
     806    mov     eax, [%$STK_EIP]
     807    mov     [ebx + CPUMCTXCORE.eip], eax
     808    mov     eax, [%$STK_EFLAGS]
     809    mov     [ebx + CPUMCTXCORE.eflags], eax
     810
     811%if GC_ARCH_BITS == 64 ; zero out the high dwords - probably not necessary any more.
     812    mov     dword [ebx + CPUMCTXCORE.eax + 4], 0
     813    mov     dword [ebx + CPUMCTXCORE.ecx + 4], 0
     814    mov     dword [ebx + CPUMCTXCORE.edx + 4], 0
     815    mov     dword [ebx + CPUMCTXCORE.ebx + 4], 0
     816    mov     dword [ebx + CPUMCTXCORE.esi + 4], 0
     817    mov     dword [ebx + CPUMCTXCORE.edi + 4], 0
     818    mov     dword [ebx + CPUMCTXCORE.ebp + 4], 0
     819    mov     dword [ebx + CPUMCTXCORE.esp + 4], 0
     820    mov     dword [ebx + CPUMCTXCORE.eip + 4], 0
     821%endif
     822
     823    test    dword [%$STK_EFLAGS], X86_EFL_VM
     824    jnz     .save_V86_segregs
     825
     826    mov     cx, [%$STK_SAVED_ES]
     827    mov     [ebx + CPUMCTXCORE.es.Sel], cx
     828    mov     cx, [%$STK_SAVED_DS]
     829    mov     [ebx + CPUMCTXCORE.ds.Sel], cx
     830    mov     cx, fs
     831    mov     [ebx + CPUMCTXCORE.fs.Sel], cx
     832    mov     cx, gs
     833    mov     [ebx + CPUMCTXCORE.gs.Sel], cx
     834    jmp     .done_saving
     835
     836    ;
     837    ; The DS, ES, FS and GS registers are zeroed in V86 mode and their real
     838    ; values are on the stack.
     839    ;
     840.save_V86_segregs:
     841    mov     cx, [%$STK_V86_ES]
     842    mov     [ebx + CPUMCTXCORE.es.Sel], cx
     843    mov     cx, [%$STK_V86_DS]
     844    mov     [ebx + CPUMCTXCORE.ds.Sel], cx
     845    mov     cx, [%$STK_V86_FS]
     846    mov     [ebx + CPUMCTXCORE.fs.Sel], cx
     847    mov     cx, [%$STK_V86_GS]
     848    mov     [ebx + CPUMCTXCORE.gs.Sel], cx
     849
     850.done_saving:
    835851
    836852    ;
    837853    ; Store the information about the active trap/interrupt.
    838854    ;
    839     mov     eax, IMP(g_TRPMCPU)
    840     movzx   edx, byte [esp + 0h + ESPOFF]  ; vector number
    841     mov     [eax + TRPMCPU.uActiveVector], edx
    842     xor     edx, edx
    843     mov     dword [eax + TRPMCPU.enmActiveType], TRPM_HARDWARE_INT
    844     dec     edx
    845     mov     [eax + TRPMCPU.uActiveErrorCode], edx
    846     mov     [eax + TRPMCPU.uActiveCR2], edx
    847 %if GC_ARCH_BITS == 64
    848     ; zero out the high dword
    849     mov     dword [eax + TRPMCPU.uActiveErrorCode + 4], 0
    850     mov     dword [eax + TRPMCPU.uActiveCR2 + 4], 0
     855    mov     esi, IMP(g_TRPMCPU)         ; esi = TRPMCPU until resume!
     856    movzx   edx, byte [%$STK_VECTOR]
     857    mov     [esi + TRPMCPU.uActiveVector], edx
     858    mov     dword [esi + TRPMCPU.uActiveErrorCode], 0
     859    mov     dword [esi + TRPMCPU.enmActiveType], TRPM_TRAP
     860    mov     dword [esi + TRPMCPU.uActiveCR2], edx
     861%if GC_ARCH_BITS == 64 ; zero out the high dwords.
     862    mov     dword [esi + TRPMCPU.uActiveErrorCode + 4], 0
     863    mov     dword [esi + TRPMCPU.uActiveCR2 + 4], 0
    851864%endif
    852865
     
    855868    ; Update statistics.
    856869    ;
    857     mov     eax, IMP(g_TRPM)
    858     movzx   edx, byte [esp + 0h + ESPOFF]   ; vector number
     870    mov     edi, IMP(g_TRPM)
     871    movzx   edx, byte [%$STK_VECTOR]   ; vector number
    859872    imul    edx, edx, byte STAMCOUNTER_size
    860     add     edx, [eax + TRPM.paStatHostIrqRC]
     873    add     edx, [edi + TRPM.paStatHostIrqRC]
    861874    STAM_COUNTER_INC edx
    862875%endif
    863876
    864877    ;
    865     ; Check if we're in Hypervisor when this happened.
    866     ;
    867     test    byte [esp + 08h + ESPOFF], 3h ; check CPL of the cs selector
    868     jnz short gi_NotHyperVisor
    869     jmp     gi_HyperVisor
     878    ; Check if we're in the raw-mode context (RC / hypervisor) when this happened.
     879    ;
     880    test    dword [%$STK_EFLAGS], X86_EFL_VM
     881    jnz short .gc_not_raw_mode_context
     882
     883    test    byte [%$STK_CS], 3h           ; check RPL of the cs selector
     884    jz      .rc_in_raw_mode_context
    870885
    871886    ;
    872887    ; Trap in guest code.
    873888    ;
    874 gi_NotHyperVisor:
    875     and     dword [esp + CPUMCTXCORE.eflags], ~010000h ; Clear RF (Resume Flag). @todo make %defines for eflags.
     889.gc_not_raw_mode_context:
     890    and     dword [ebx + CPUMCTXCORE.eflags], ~X86_EFL_RF ; Clear RF.
    876891                                           ; The guest shall not see this in it's state.
    877892%ifdef DEBUG_STUFF_INT
    878     mov     ecx, 'intG'                    ; indicate trap.
    879     movzx   edx, byte [esp +  0h + ESPOFF] ; vector number
    880     lea     eax, [esp]
     893    xor     eax, eax
     894    mov     ecx, 'intG'                    ; indicate trap in GC.
     895    movzx   edx, byte [%$STK_VECTOR]
    881896    call    trpmDbgDumpRegisterFrame
    882897%endif
     
    887902    mov     edx, IMP(g_VM)
    888903    mov     eax, VINF_EM_RAW_INTERRUPT
    889     call    [edx + VM.pfnVMMGCGuestToHostAsmGuestCtx]
     904    call    [edx + VM.pfnVMMGCGuestToHostAsm]
    890905
    891906    ;
    892907    ; We've returned!
    893     ; NOTE that the stack has been changed now!
    894     ;      there is no longer any CPUMCTXCORE around and esp points to vector number!
    895     ;
     908    ;
     909
    896910    ; Reset TRPM state
    897     mov     eax, IMP(g_TRPMCPU)
    898911    xor     edx, edx
    899912    dec     edx                         ; edx = 0ffffffffh
    900     xchg    [eax + TRPMCPU.uActiveVector], edx
    901     mov     [eax + TRPMCPU.uPrevVector], edx
    902 
    903     ; Enable WP
     913    xchg    [esi + TRPMCPU.uActiveVector], edx
     914    mov     [esi + TRPMCPU.uPrevVector], edx
     915
     916    ; enable WP
    904917    mov     eax, cr0                    ;; @todo try elimiate this read.
    905918    or      eax, X86_CR0_WRITE_PROTECT
    906919    mov     cr0, eax
    907     ; restore guest context and continue execution.
    908     lea     eax, [esp + 8]
    909     push    eax
    910     call    NAME(CPUMGCRestoreInt)
    911     lea     esp, [esp + 0ch]            ; cleanup call and skip vector & error code.
    912 
     920
     921    ; restore guest state and start executing again.
     922    mov     eax, [ebx + CPUMCTXCORE.eax]
     923    mov     [%$STK_SAVED_EAX], eax
     924    mov     ecx, [ebx + CPUMCTXCORE.ecx]
     925    mov     edx, [ebx + CPUMCTXCORE.edx]
     926    mov     eax, [ebx + CPUMCTXCORE.ebx]
     927    mov     [%$STK_SAVED_EBX], eax
     928    mov     ebp, [ebx + CPUMCTXCORE.ebp]
     929    mov     esi, [ebx + CPUMCTXCORE.esi]
     930    mov     edi, [ebx + CPUMCTXCORE.edi]
     931
     932    mov     eax, [ebx + CPUMCTXCORE.esp]
     933    mov     [%$STK_ESP], eax
     934    mov     eax, dword [ebx + CPUMCTXCORE.ss.Sel]
     935    mov     [%$STK_SS], eax
     936    mov     eax, [ebx + CPUMCTXCORE.eflags]
     937    mov     [%$STK_EFLAGS], eax
     938    mov     eax, dword [ebx + CPUMCTXCORE.cs.Sel]
     939    mov     [%$STK_CS], eax
     940    mov     eax, [ebx + CPUMCTXCORE.eip]
     941    mov     [%$STK_EIP], eax
     942
     943    test    dword [ebx + CPUMCTXCORE.eflags], X86_EFL_VM
     944    jnz     .gc_V86_return
     945
     946    mov     ax, [ebx + CPUMCTXCORE.gs.Sel]
     947    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_GS
     948    mov     gs, ax
     949
     950    mov     ax, [ebx + CPUMCTXCORE.fs.Sel]
     951    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_FS
     952    mov     fs, ax
     953
     954    mov     ax, [ebx + CPUMCTXCORE.es.Sel]
     955    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_ES
     956    mov     es, ax
     957
     958    mov     ax, [ebx + CPUMCTXCORE.ds.Sel]
     959    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_DS
     960    mov     ds, ax
     961
     962    ; finally restore our scratch register eax and ebx.
     963    pop     ebx
     964    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
     969    iret
     970
     971ALIGNCODE(16)
     972.gc_V86_return:
     973    mov     eax, dword [ebx + CPUMCTXCORE.es.Sel]
     974    mov     [%$STK_V86_ES], eax
     975    mov     eax, dword [ebx + CPUMCTXCORE.ds.Sel]
     976    mov     [%$STK_V86_DS], eax
     977    mov     eax, dword [ebx + CPUMCTXCORE.fs.Sel]
     978    mov     [%$STK_V86_FS], eax
     979    mov     eax, dword [ebx + CPUMCTXCORE.gs.Sel]
     980    mov     [%$STK_V86_GS], eax
     981
     982    ; finally restore our scratch register eax and ebx.
     983    pop     ebx
     984    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
    913989    iret
    914990
     
    922998    ; We make ASSUMPTIONS about this in respects to the WP CR0 bit
    923999    ;
    924 gi_HyperVisor:
    925     lea     eax, [esp + 14h + ESPOFF]      ; calc esp at trap
    926     mov     [esp + CPUMCTXCORE.esp], eax   ; update esp in register frame
    927     mov     [esp + CPUMCTXCORE.ss.Sel], ss ; update ss in register frame
     1000ALIGNCODE(16)
     1001.rc_in_raw_mode_context:
     1002    ; fix ss:esp.
     1003    lea     ecx, [%$STK_ESP]                ; calc esp at trap
     1004    mov     [ebx + CPUMCTXCORE.esp], ecx    ; update esp in register frame
     1005    mov     [ebx + CPUMCTXCORE.ss.Sel], ss  ; update ss in register frame
    9281006
    9291007%ifdef DEBUG_STUFF_INT
    930     mov     ebx, [esp +  4h + ESPOFF]      ; error code
    931     mov     ecx, 'intH'                    ; indicate hypervisor interrupt.
    932     movzx   edx, byte [esp +  0h + ESPOFF] ; vector number
    933     lea     eax, [esp]
     1008    xor     eax, eax
     1009    mov     ecx, 'intH'                    ; indicate trap in RC.
     1010    movzx   edx, byte [%$STK_VECTOR]
    9341011    call    trpmDbgDumpRegisterFrame
    9351012%endif
    9361013
    937     mov     ecx, esp
    9381014    mov     edx, IMP(g_VM)
    9391015    mov     eax, VINF_EM_RAW_INTERRUPT_HYPER
    9401016    call    [edx + VM.pfnVMMGCGuestToHostAsm]
    9411017%ifdef DEBUG_STUFF_INT
    942     COM_CHAR '!'
     1018    COM_S_CHAR '!'
    9431019%endif
    9441020
    9451021    ;
    9461022    ; We've returned!
    947     ;
     1023    ; Continue(/Resume/Restart/Whatever) hypervisor execution.
     1024    ;
     1025
    9481026    ; Reset TRPM state - don't record this.
    949     mov     eax, IMP(g_TRPMCPU)
    950     mov     dword [eax + TRPMCPU.uActiveVector], 0ffffffffh
     1027    ;mov     esi, IMP(g_TRPMCPU)
     1028    mov     dword [esi + TRPMCPU.uActiveVector], 0ffffffffh
    9511029
    9521030    ;
    9531031    ; Restore the hypervisor context and return.
    9541032    ;
    955     mov     ecx, [esp + CPUMCTXCORE.ecx]
    956     mov     edx, [esp + CPUMCTXCORE.edx]
    957     mov     ebx, [esp + CPUMCTXCORE.ebx]
    958     mov     ebp, [esp + CPUMCTXCORE.ebp]
    959     mov     esi, [esp + CPUMCTXCORE.esi]
    960     mov     edi, [esp + CPUMCTXCORE.edi]
    961 
    962     ; In V86 mode DS, ES, FS & GS are restored by the iret
    963     test    dword [esp + CPUMCTXCORE.eflags], X86_EFL_VM
    964     jnz     short ti_SkipSelRegs
    965 
    966     mov     eax, [esp + CPUMCTXCORE.gs.Sel]
     1033    mov     eax, [ebx + CPUMCTXCORE.eax]
     1034    mov     [%$STK_SAVED_EAX], eax
     1035    mov     ecx, [ebx + CPUMCTXCORE.ecx]
     1036    mov     edx, [ebx + CPUMCTXCORE.edx]
     1037    mov     eax, [ebx + CPUMCTXCORE.ebx]
     1038    mov     [%$STK_SAVED_EBX], eax
     1039    mov     ebp, [ebx + CPUMCTXCORE.ebp]
     1040    mov     esi, [ebx + CPUMCTXCORE.esi]
     1041    mov     edi, [ebx + CPUMCTXCORE.edi]
     1042
     1043                                                ; skipping esp & ss.
     1044
     1045    mov     eax, [ebx + CPUMCTXCORE.eflags]
     1046    mov     [%$STK_EFLAGS], eax
     1047    mov     eax, dword [ebx + CPUMCTXCORE.cs.Sel]
     1048    mov     [%$STK_CS], eax
     1049    mov     eax, [ebx + CPUMCTXCORE.eip]
     1050    mov     [%$STK_EIP], eax
     1051
     1052    mov     ax, [ebx + CPUMCTXCORE.gs.Sel]
    9671053    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_GS | TRPM_TRAP_IN_HYPER
    968     mov     gs, eax
    969 
    970     mov     eax, [esp + CPUMCTXCORE.fs.Sel]
     1054    mov     gs, ax
     1055
     1056    mov     ax, [ebx + CPUMCTXCORE.fs.Sel]
    9711057    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_FS | TRPM_TRAP_IN_HYPER
    972     mov     fs, eax
    973 
    974     mov     eax, [esp + CPUMCTXCORE.es.Sel]
    975     mov     es, eax
    976     mov     eax, [esp + CPUMCTXCORE.ds.Sel]
    977     mov     ds, eax
    978 
    979 ti_SkipSelRegs:
    980     ; finally restore our scratch register eax
    981     mov     eax, [esp + CPUMCTXCORE.eax]
    982 
    983     ; skip esp, ss, cs, eip & eflags. Done by iret
    984 
    985     add     esp, ESPOFF + 4h                    ; skip CPUMCTXCORE structure & vector number.
    986 
     1058    mov     fs, ax
     1059
     1060    mov     ax, [ebx + CPUMCTXCORE.es.Sel]
     1061    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_ES | TRPM_TRAP_IN_HYPER
     1062    mov     es, ax
     1063
     1064    mov     ax, [ebx + CPUMCTXCORE.ds.Sel]
     1065    TRPM_NP_GP_HANDLER NAME(trpmGCTrapInGeneric), TRPM_TRAP_IN_MOV_DS | TRPM_TRAP_IN_HYPER
     1066    mov     ds, ax
     1067
     1068    ; finally restore our scratch register eax and ebx.
     1069    pop     ebx
     1070    pop     eax
     1071
     1072    add     esp, 8 + 4                          ; skip ds, es, and vector number.
    9871073    iret
    988 %undef ESPOFF
     1074%pop
    9891075ENDPROC TRPMGCHandlerInterupt
    9901076
     
    10561142
    10571143    ;
     1144    ; Disable write protection.
     1145    ;
     1146    mov     eax, cr0
     1147    and     eax, ~X86_CR0_WRITE_PROTECT
     1148    mov     cr0, eax
     1149
     1150    ;
    10581151    ; Load Hypervisor DS and ES (get it from the SS) - paranoia, but the TSS could be overwritten.. :)
    10591152    ;
     
    10631156
    10641157    COM_S_PRINT 10,13,'*** Guru Meditation 00000008 - Double Fault! ***',10,13
    1065 
    1066     ;
    1067     ; Disable write protection.
    1068     ;
    1069     mov     eax, cr0
    1070     and     eax, ~X86_CR0_WRITE_PROTECT
    1071     mov     cr0, eax
    1072 
    10731158
    10741159    COM_S_PRINT 'VM='
     
    10871172    ; Create CPUMCTXCORE structure.
    10881173    ;
    1089     sub     esp, CPUMCTXCORE_size
     1174    mov     ebx, IMP(g_trpmHyperCtxCore)    ; It's raw-mode context, actually.
    10901175
    10911176    mov     eax, [ecx + VBOXTSS.eip]
    1092     mov     [esp + CPUMCTXCORE.eip], eax
     1177    mov     [ebx + CPUMCTXCORE.eip], eax
    10931178%if GC_ARCH_BITS == 64
    10941179    ; zero out the high dword
    1095     mov     dword [esp + CPUMCTXCORE.eip + 4], 0
     1180    mov     dword [ebx + CPUMCTXCORE.eip + 4], 0
    10961181%endif
    10971182    mov     eax, [ecx + VBOXTSS.eflags]
    1098     mov     [esp + CPUMCTXCORE.eflags], eax
     1183    mov     [ebx + CPUMCTXCORE.eflags], eax
    10991184
    11001185    movzx   eax, word [ecx + VBOXTSS.cs]
    1101     mov     dword [esp + CPUMCTXCORE.cs.Sel], eax
     1186    mov     dword [ebx + CPUMCTXCORE.cs.Sel], eax
    11021187    movzx   eax, word [ecx + VBOXTSS.ds]
    1103     mov     dword [esp + CPUMCTXCORE.ds.Sel], eax
     1188    mov     dword [ebx + CPUMCTXCORE.ds.Sel], eax
    11041189    movzx   eax, word [ecx + VBOXTSS.es]
    1105     mov     dword [esp + CPUMCTXCORE.es.Sel], eax
     1190    mov     dword [ebx + CPUMCTXCORE.es.Sel], eax
    11061191    movzx   eax, word [ecx + VBOXTSS.fs]
    1107     mov     dword [esp + CPUMCTXCORE.fs.Sel], eax
     1192    mov     dword [ebx + CPUMCTXCORE.fs.Sel], eax
    11081193    movzx   eax, word [ecx + VBOXTSS.gs]
    1109     mov     dword [esp + CPUMCTXCORE.gs.Sel], eax
     1194    mov     dword [ebx + CPUMCTXCORE.gs.Sel], eax
    11101195    movzx   eax, word [ecx + VBOXTSS.ss]
    1111     mov     [esp + CPUMCTXCORE.ss.Sel], eax
     1196    mov     [ebx + CPUMCTXCORE.ss.Sel], eax
    11121197    mov     eax, [ecx + VBOXTSS.esp]
    1113     mov     [esp + CPUMCTXCORE.esp], eax
     1198    mov     [ebx + CPUMCTXCORE.esp], eax
    11141199%if GC_ARCH_BITS == 64
    11151200    ; zero out the high dword
    1116     mov     dword [esp + CPUMCTXCORE.esp + 4], 0
     1201    mov     dword [ebx + CPUMCTXCORE.esp + 4], 0
    11171202%endif
    11181203    mov     eax, [ecx + VBOXTSS.ecx]
    1119     mov     [esp + CPUMCTXCORE.ecx], eax
     1204    mov     [ebx + CPUMCTXCORE.ecx], eax
    11201205    mov     eax, [ecx + VBOXTSS.edx]
    1121     mov     [esp + CPUMCTXCORE.edx], eax
     1206    mov     [ebx + CPUMCTXCORE.edx], eax
    11221207    mov     eax, [ecx + VBOXTSS.ebx]
    1123     mov     [esp + CPUMCTXCORE.ebx], eax
     1208    mov     [ebx + CPUMCTXCORE.ebx], eax
    11241209    mov     eax, [ecx + VBOXTSS.eax]
    1125     mov     [esp + CPUMCTXCORE.eax], eax
     1210    mov     [ebx + CPUMCTXCORE.eax], eax
    11261211    mov     eax, [ecx + VBOXTSS.ebp]
    1127     mov     [esp + CPUMCTXCORE.ebp], eax
     1212    mov     [ebx + CPUMCTXCORE.ebp], eax
    11281213    mov     eax, [ecx + VBOXTSS.esi]
    1129     mov     [esp + CPUMCTXCORE.esi], eax
     1214    mov     [ebx + CPUMCTXCORE.esi], eax
    11301215    mov     eax, [ecx + VBOXTSS.edi]
    1131     mov     [esp + CPUMCTXCORE.edi], eax
     1216    mov     [ebx + CPUMCTXCORE.edi], eax
    11321217
    11331218    ;
    11341219    ; Show regs
    11351220    ;
    1136     mov     ebx, 0ffffffffh
     1221    mov     eax, 0ffffffffh
    11371222    mov     ecx, 'trpH'                 ; indicate trap.
    11381223    mov     edx, 08h                    ; vector number
    1139     lea     eax, [esp]
    11401224    call    trpmDbgDumpRegisterFrame
    11411225
     
    11541238df_to_host:
    11551239    COM_S_PRINT 'Trying to return to host...',10,13
    1156     mov     ecx, esp
    11571240    mov     edx, IMP(g_VM)
    11581241    mov     eax, VERR_TRPM_PANIC
    1159     call    [edx + VM.pfnVMMGCGuestToHostAsmHyperCtx]
     1242    call    [edx + VM.pfnVMMGCGuestToHostAsm]
    11601243    jmp short df_to_host
    11611244
     
    11821265; Internal procedure used to dump registers.
    11831266;
    1184 ; @param    eax     Pointer to CPUMCTXCORE.
     1267; @param    ebx     Pointer to CPUMCTXCORE.
    11851268; @param    edx     Vector number
    11861269; @param    ecx     'trap' if trap, 'int' if interrupt.
    1187 ; @param    ebx     Error code if trap.
     1270; @param    eax     Error code if trap.
    11881271;
    11891272trpmDbgDumpRegisterFrame:
     
    12531336    COM_S_DWORD_REG edx
    12541337    COM_S_PRINT ' ErrorCode='
    1255     COM_S_DWORD_REG ebx
     1338    COM_S_DWORD_REG eax
    12561339    COM_S_PRINT ' cr2='
    12571340    mov ecx, cr2
     
    12601343tddrf_regs:
    12611344    COM_S_PRINT ' ***',10,13,'cs:eip='
    1262     movzx   ecx, word [eax + CPUMCTXCORE.cs.Sel]
     1345    movzx   ecx, word [ebx + CPUMCTXCORE.cs.Sel]
    12631346    COM_S_DWORD_REG ecx
    12641347    COM_S_CHAR ':'
    1265     mov     ecx, [eax + CPUMCTXCORE.eip]
     1348    mov     ecx, [ebx + CPUMCTXCORE.eip]
    12661349    COM_S_DWORD_REG ecx
    12671350
    12681351    COM_S_PRINT '    ss:esp='
    1269     movzx   ecx, word [eax + CPUMCTXCORE.ss.Sel]
     1352    movzx   ecx, word [ebx + CPUMCTXCORE.ss.Sel]
    12701353    COM_S_DWORD_REG ecx
    12711354    COM_S_CHAR ':'
    1272     mov     ecx, [eax + CPUMCTXCORE.esp]
     1355    mov     ecx, [ebx + CPUMCTXCORE.esp]
    12731356    COM_S_DWORD_REG ecx
    12741357
     
    13021385
    13031386    COM_S_PRINT '  eflags='
    1304     mov     ecx, [eax + CPUMCTXCORE.eflags]
     1387    mov     ecx, [ebx + CPUMCTXCORE.eflags]
    13051388    COM_S_DWORD_REG ecx
    13061389
     
    13231406
    13241407    COM_S_PRINT 10,13,' ds='
    1325     movzx   ecx, word [eax + CPUMCTXCORE.ds.Sel]
     1408    movzx   ecx, word [ebx + CPUMCTXCORE.ds.Sel]
    13261409    COM_S_DWORD_REG ecx
    13271410
    13281411    COM_S_PRINT '   es='
    1329     movzx   ecx, word [eax + CPUMCTXCORE.es.Sel]
     1412    movzx   ecx, word [ebx + CPUMCTXCORE.es.Sel]
    13301413    COM_S_DWORD_REG ecx
    13311414
    13321415    COM_S_PRINT '   fs='
    1333     movzx   ecx, word [eax + CPUMCTXCORE.fs.Sel]
     1416    movzx   ecx, word [ebx + CPUMCTXCORE.fs.Sel]
    13341417    COM_S_DWORD_REG ecx
    13351418
    13361419    COM_S_PRINT '   gs='
    1337     movzx   ecx, word [eax + CPUMCTXCORE.gs.Sel]
     1420    movzx   ecx, word [ebx + CPUMCTXCORE.gs.Sel]
    13381421    COM_S_DWORD_REG ecx
    13391422
    13401423
    13411424    COM_S_PRINT 10,13,'eax='
    1342     mov     ecx, [eax + CPUMCTXCORE.eax]
     1425    mov     ecx, [ebx + CPUMCTXCORE.eax]
    13431426    COM_S_DWORD_REG ecx
    13441427
    13451428    COM_S_PRINT '  ebx='
    1346     mov     ecx, [eax + CPUMCTXCORE.ebx]
     1429    mov     ecx, [ebx + CPUMCTXCORE.ebx]
    13471430    COM_S_DWORD_REG ecx
    13481431
    13491432    COM_S_PRINT '  ecx='
    1350     mov     ecx, [eax + CPUMCTXCORE.ecx]
     1433    mov     ecx, [ebx + CPUMCTXCORE.ecx]
    13511434    COM_S_DWORD_REG ecx
    13521435
    13531436    COM_S_PRINT '  edx='
    1354     mov     ecx, [eax + CPUMCTXCORE.edx]
     1437    mov     ecx, [ebx + CPUMCTXCORE.edx]
    13551438    COM_S_DWORD_REG ecx
    13561439
    13571440
    13581441    COM_S_PRINT 10,13,'esi='
    1359     mov     ecx, [eax + CPUMCTXCORE.esi]
     1442    mov     ecx, [ebx + CPUMCTXCORE.esi]
    13601443    COM_S_DWORD_REG ecx
    13611444
    13621445    COM_S_PRINT '  edi='
    1363     mov     ecx, [eax + CPUMCTXCORE.edi]
     1446    mov     ecx, [ebx + CPUMCTXCORE.edi]
    13641447    COM_S_DWORD_REG ecx
    13651448
    13661449    COM_S_PRINT '  ebp='
    1367     mov     ecx, [eax + CPUMCTXCORE.ebp]
     1450    mov     ecx, [ebx + CPUMCTXCORE.ebp]
    13681451    COM_S_DWORD_REG ecx
    13691452
  • trunk/src/VBox/VMM/VMMRC/VMMRCBuiltin.def

    r35345 r41931  
    2525    g_RelLogger                     DATA
    2626    g_pSUPGlobalInfoPage            DATA
     27    g_trpmGuestCtxCore              DATA ; for TRPMRCHandlersA.asm only
     28    g_trpmHyperCtxCore              DATA ; for TRPMRCHandlersA.asm only
    2729
    2830    ; code
  • trunk/src/VBox/VMM/include/CPUMInternal.h

    r41905 r41931  
    369369    CPUMCTXMSRS             GuestMsrs;
    370370
    371     /** Pointer to the current hypervisor core context - R3Ptr. */
    372     R3PTRTYPE(PCPUMCTXCORE) pHyperCoreR3;
    373     /** Pointer to the current hypervisor core context - R0Ptr. */
    374     R0PTRTYPE(PCPUMCTXCORE) pHyperCoreR0;
    375     /** Pointer to the current hypervisor core context - RCPtr. */
    376     RCPTRTYPE(PCPUMCTXCORE) pHyperCoreRC;
    377 
    378371    /** Use flags.
    379372     * These flags indicates both what is to be used and what has been used.
     
    401394
    402395    /** Align the structure on a 64-byte boundary. */
    403     uint8_t                 abPadding2[HC_ARCH_BITS == 32 ? 34 : 26];
     396    uint8_t                 abPadding2[HC_ARCH_BITS == 32 ? 48 : 46];
    404397} CPUMCPU;
    405398/** Pointer to the CPUMCPU instance data residing in the shared VMCPU structure. */
  • trunk/src/VBox/VMM/include/CPUMInternal.mac

    r41906 r41931  
    424424    ; Other stuff.
    425425    ;
    426     ; hypervisor core context.
    427     .pHyperCoreR3         RTR3PTR_RES   1
    428     .pHyperCoreR0         RTR0PTR_RES   1
    429     .pHyperCoreRC         RTRCPTR_RES   1
    430 
    431426    .fUseFlags            resd    1
    432427    .fChanged             resd    1
     
    437432
    438433%if RTHCPTR_CB == 8
    439     .abPadding2           resb    26
     434    .abPadding2           resb    46
    440435%else
    441     .abPadding2           resb    34
     436    .abPadding2           resb    48
    442437%endif
    443438
  • trunk/src/VBox/VMM/testcase/tstVMStruct.h

    r41906 r41931  
    5959    GEN_CHECK_OFF(CPUMCPU, Guest);
    6060    GEN_CHECK_OFF(CPUMCPU, GuestMsrs);
    61     GEN_CHECK_OFF(CPUMCPU, pHyperCoreR3);
    62     GEN_CHECK_OFF(CPUMCPU, pHyperCoreR0);
    63     GEN_CHECK_OFF(CPUMCPU, pHyperCoreRC);
    6461    GEN_CHECK_OFF(CPUMCPU, fUseFlags);
    6562    GEN_CHECK_OFF(CPUMCPU, fChanged);
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