VirtualBox

Changeset 18927 in vbox for trunk/src/VBox/VMM/CPUM.cpp


Ignore:
Timestamp:
Apr 16, 2009 11:41:38 AM (16 years ago)
Author:
vboxsync
Message:

Big step to separate VMM data structures for guest SMP. (pgm, em)

File:
1 edited

Legend:

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

    r17034 r18927  
    122122     * Assert alignment and sizes.
    123123     */
    124     AssertRelease(!(RT_OFFSETOF(VM, cpum.s) & 31));
    125     AssertRelease(sizeof(pVM->cpum.s) <= sizeof(pVM->cpum.padding));
    126 
    127     /*
    128      * Setup any fixed pointers and offsets.
    129      */
    130     pVM->cpum.s.pHyperCoreR3 = CPUMCTX2CORE(&pVM->cpum.s.Hyper);
    131     pVM->cpum.s.pHyperCoreR0 = VM_R0_ADDR(pVM, CPUMCTX2CORE(&pVM->cpum.s.Hyper));
    132 
    133     /* Hidden selector registers are invalid by default. */
    134     pVM->cpum.s.fValidHiddenSelRegs  = false;
     124    AssertCompile(!(RT_OFFSETOF(VM, cpum.s) & 31));
     125    AssertCompile(sizeof(pVM->cpum.s) <= sizeof(pVM->cpum.padding));
     126    AssertCompile(!(sizeof(CPUMCTX) & 63));
     127    AssertCompile(!(sizeof(CPUMCTXMSR) & 63));
     128    AssertCompile(!(sizeof(CPUMHOSTCTX) & 63));
     129    AssertCompile(!(RT_OFFSETOF(VM, cpum) & 63));
     130    AssertCompile(!(RT_OFFSETOF(VM, aCpus) & 63));
     131    AssertCompile(!(RT_OFFSETOF(VMCPU, cpum.s) & 63));
     132    AssertCompile(!(sizeof(pVM->aCpus[0].cpum.s) & 63));
    135133
    136134    /* Calculate the offset from CPUM to CPUMCPU for the first CPU. */
     
    141139    for (unsigned i=0;i<pVM->cCPUs;i++)
    142140    {
    143         pVM->aCpus[i].cpum.s.ulOffCPUM = RT_OFFSETOF(VM, aCpus[i].cpum) - RT_OFFSETOF(VM, cpum);
    144         Assert((uintptr_t)&pVM->aCpus[i].cpum - pVM->aCpus[i].cpum.s.ulOffCPUM == (uintptr_t)&pVM->cpum);
     141        PVMCPU pVCpu = &pVM->aCpus[i];
     142
     143        /*
     144         * Setup any fixed pointers and offsets.
     145         */
     146        pVCpu->cpum.s.pHyperCoreR3 = CPUMCTX2CORE(&pVCpu->cpum.s.Hyper);
     147        pVCpu->cpum.s.pHyperCoreR0 = VM_R0_ADDR(pVM, CPUMCTX2CORE(&pVCpu->cpum.s.Hyper));
     148
     149        pVCpu->cpum.s.ulOffCPUM   = RT_OFFSETOF(VM, aCpus[i].cpum) - RT_OFFSETOF(VM, cpum);
     150        Assert((uintptr_t)&pVCpu->cpum - pVCpu->cpum.s.ulOffCPUM == (uintptr_t)&pVM->cpum);
    145151    }
    146152
     
    637643{
    638644    LogFlow(("CPUMR3Relocate\n"));
    639     /*
    640      * Switcher pointers.
    641      */
    642     pVM->cpum.s.pHyperCoreRC = MMHyperCCToRC(pVM, pVM->cpum.s.pHyperCoreR3);
    643     Assert(pVM->cpum.s.pHyperCoreRC != NIL_RTRCPTR);
     645    for (unsigned i=0;i<pVM->cCPUs;i++)
     646    {
     647        PVMCPU pVCpu  = &pVM->aCpus[i];
     648        /*
     649         * Switcher pointers.
     650         */
     651        pVCpu->cpum.s.pHyperCoreRC = MMHyperCCToRC(pVM, pVCpu->cpum.s.pHyperCoreR3);
     652        Assert(pVCpu->cpum.s.pHyperCoreRC != NIL_RTRCPTR);
     653    }
    644654}
    645655
     
    675685    for (unsigned i=0;i<pVM->cCPUs;i++)
    676686    {
    677         PCPUMCTX pCtx = CPUMQueryGuestCtxPtrEx(pVM, &pVM->aCpus[i]);
    678 
    679         memset(pVM->aCpus[i].cpum.s.aMagic, 0, sizeof(pVM->aCpus[i].cpum.s.aMagic));
    680         pVM->aCpus[i].cpum.s.uMagic     = 0;
    681         pCtx->dr[5]                     = 0;
     687        PVMCPU pVCpu  = &pVM->aCpus[i];
     688        PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu);
     689
     690        memset(pVCpu->cpum.s.aMagic, 0, sizeof(pVCpu->cpum.s.aMagic));
     691        pVCpu->cpum.s.uMagic     = 0;
     692        pCtx->dr[5]              = 0;
    682693    }
    683694#endif
     
    697708    for (unsigned i=0;i<pVM->cCPUs;i++)
    698709    {
    699         PCPUMCTX pCtx = CPUMQueryGuestCtxPtrEx(pVM, &pVM->aCpus[i]);
     710        PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(&pVM->aCpus[i]);
    700711
    701712        /*
     
    793804     * Save.
    794805     */
    795     SSMR3PutMem(pSSM, &pVM->cpum.s.Hyper, sizeof(pVM->cpum.s.Hyper));
     806    for (unsigned i=0;i<pVM->cCPUs;i++)
     807    {
     808        PVMCPU pVCpu = &pVM->aCpus[i];
     809
     810        SSMR3PutMem(pSSM, &pVCpu->cpum.s.Hyper, sizeof(pVCpu->cpum.s.Hyper));
     811    }
    796812
    797813    SSMR3PutU32(pSSM, pVM->cCPUs);
    798814    for (unsigned i=0;i<pVM->cCPUs;i++)
    799815    {
    800         SSMR3PutMem(pSSM, &pVM->aCpus[i].cpum.s.Guest, sizeof(pVM->aCpus[i].cpum.s.Guest));
    801         SSMR3PutU32(pSSM, pVM->aCpus[i].cpum.s.fUseFlags);
    802         SSMR3PutU32(pSSM, pVM->aCpus[i].cpum.s.fChanged);
    803         SSMR3PutMem(pSSM, &pVM->aCpus[i].cpum.s.GuestMsr, sizeof(pVM->aCpus[i].cpum.s.GuestMsr));
     816        PVMCPU pVCpu = &pVM->aCpus[i];
     817
     818        SSMR3PutMem(pSSM, &pVCpu->cpum.s.Guest, sizeof(pVCpu->cpum.s.Guest));
     819        SSMR3PutU32(pSSM, pVCpu->cpum.s.fUseFlags);
     820        SSMR3PutU32(pSSM, pVCpu->cpum.s.fChanged);
     821        SSMR3PutMem(pSSM, &pVCpu->cpum.s.GuestMsr, sizeof(pVCpu->cpum.s.GuestMsr));
    804822    }
    805823
     
    949967     * Restore.
    950968     */
    951     uint32_t uCR3 = pVM->cpum.s.Hyper.cr3;
    952     uint32_t uESP = pVM->cpum.s.Hyper.esp; /* see VMMR3Relocate(). */
    953     SSMR3GetMem(pSSM, &pVM->cpum.s.Hyper, sizeof(pVM->cpum.s.Hyper));
    954     pVM->cpum.s.Hyper.cr3 = uCR3;
    955     pVM->cpum.s.Hyper.esp = uESP;
     969    for (unsigned i=0;i<pVM->cCPUs;i++)
     970    {
     971        PVMCPU   pVCpu = &pVM->aCpus[i];
     972        uint32_t uCR3  = pVCpu->cpum.s.Hyper.cr3;
     973        uint32_t uESP  = pVCpu->cpum.s.Hyper.esp; /* see VMMR3Relocate(). */
     974
     975        SSMR3GetMem(pSSM, &pVCpu->cpum.s.Hyper, sizeof(pVCpu->cpum.s.Hyper));
     976        pVCpu->cpum.s.Hyper.cr3 = uCR3;
     977        pVCpu->cpum.s.Hyper.esp = uESP;
     978    }
     979
    956980    if (u32Version == CPUM_SAVED_STATE_VERSION_VER1_6)
    957981    {
     
    11331157    {
    11341158        case CPUMDUMPTYPE_TERSE:
    1135             if (CPUMIsGuestIn64BitCode(pVM, pCtxCore))
     1159            if (CPUMIsGuestIn64BitCodeEx(pCtx))
    11361160                pHlp->pfnPrintf(pHlp,
    11371161                    "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
     
    11591183
    11601184        case CPUMDUMPTYPE_DEFAULT:
    1161             if (CPUMIsGuestIn64BitCode(pVM, pCtxCore))
     1185            if (CPUMIsGuestIn64BitCodeEx(pCtx))
    11621186                pHlp->pfnPrintf(pHlp,
    11631187                    "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
     
    11931217
    11941218        case CPUMDUMPTYPE_VERBOSE:
    1195             if (CPUMIsGuestIn64BitCode(pVM, pCtxCore))
     1219            if (CPUMIsGuestIn64BitCodeEx(pCtx))
    11961220                pHlp->pfnPrintf(pHlp,
    11971221                    "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
     
    13611385    cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
    13621386    pHlp->pfnPrintf(pHlp, "Guest CPUM state: %s\n", pszComment);
    1363     /* @todo SMP */
    1364     PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVM);
     1387
     1388    /* @todo SMP support! */
     1389    PVMCPU pVCpu = &pVM->aCpus[0];
     1390    PCPUMCTX pCtx = CPUMQueryGuestCtxPtr(pVCpu);
    13651391    cpumR3InfoOne(pVM, pCtx, CPUMCTX2CORE(pCtx), pHlp, enmType, "");
    13661392}
     
    13941420    CPUMDUMPTYPE enmType;
    13951421    const char *pszComment;
     1422    /* @todo SMP */
     1423    PVMCPU pVCpu = &pVM->aCpus[0];
     1424
    13961425    cpumR3InfoParseArg(pszArgs, &enmType, &pszComment);
    13971426    pHlp->pfnPrintf(pHlp, "Hypervisor CPUM state: %s\n", pszComment);
    1398     cpumR3InfoOne(pVM, &pVM->cpum.s.Hyper, pVM->cpum.s.pHyperCoreR3, pHlp, enmType, ".");
     1427    cpumR3InfoOne(pVM, &pVCpu->cpum.s.Hyper, pVCpu->cpum.s.pHyperCoreR3, pHlp, enmType, ".");
    13991428    pHlp->pfnPrintf(pHlp, "CR4OrMask=%#x CR4AndMask=%#x\n", pVM->cpum.s.CR4.OrMask, pVM->cpum.s.CR4.AndMask);
    14001429}
     
    21362165    /** The VM handle. */
    21372166    PVM             pVM;
     2167    /** The VMCPU handle. */
     2168    PVMCPU          pVCpu;
    21382169    /** Pointer to the first byte in the segemnt. */
    21392170    RTGCUINTPTR     GCPtrSegBase;
     
    21952226                if (pState->fLocked)
    21962227                    PGMPhysReleasePageMappingLock(pState->pVM, &pState->PageMapLock);
    2197                 rc = PGMPhysGCPtr2CCPtrReadOnly(pState->pVM, pState->pvPageGC, &pState->pvPageR3, &pState->PageMapLock);
     2228                rc = PGMPhysGCPtr2CCPtrReadOnly(pState->pVCpu, pState->pvPageGC, &pState->pvPageR3, &pState->PageMapLock);
    21982229                pState->fLocked = RT_SUCCESS_NP(rc);
    21992230            }
     
    22362267 * @returns VBox status code.
    22372268 * @param   pVM         VM Handle
     2269 * @param   pVCpu       VMCPU Handle
    22382270 * @param   pCtx        CPU context
    22392271 * @param   GCPtrPC     Program counter (relative to CS) to disassemble from.
     
    22422274 *
    22432275 */
    2244 VMMR3DECL(int) CPUMR3DisasmInstrCPU(PVM pVM, PCPUMCTX pCtx, RTGCPTR GCPtrPC, PDISCPUSTATE pCpu, const char *pszPrefix)
     2276VMMR3DECL(int) CPUMR3DisasmInstrCPU(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, RTGCPTR GCPtrPC, PDISCPUSTATE pCpu, const char *pszPrefix)
    22452277{
    22462278    CPUMDISASSTATE  State;
    22472279    int             rc;
    22482280
    2249     const PGMMODE enmMode = PGMGetGuestMode(pVM);
     2281    const PGMMODE enmMode = PGMGetGuestMode(pVCpu);
    22502282    State.pCpu            = pCpu;
    22512283    State.pvPageGC        = 0;
    22522284    State.pvPageR3        = NULL;
    22532285    State.pVM             = pVM;
     2286    State.pVCpu           = pVCpu;
    22542287    State.fLocked         = false;
    22552288    State.f64Bits         = false;
     
    23492382 * @returns VBox status code.
    23502383 * @param   pVM         VM Handle
     2384 * @param   pVCpu       VMCPU Handle
    23512385 * @param   pCtx        CPU context
    23522386 * @param   pc          GC instruction pointer
     
    23552389 * @deprecated  Use DBGFR3DisasInstrCurrentLog().
    23562390 */
    2357 VMMR3DECL(void) CPUMR3DisasmInstr(PVM pVM, PCPUMCTX pCtx, RTGCPTR pc, const char *pszPrefix)
     2391VMMR3DECL(void) CPUMR3DisasmInstr(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx, RTGCPTR pc, const char *pszPrefix)
    23582392{
    23592393    DISCPUSTATE Cpu;
    2360     CPUMR3DisasmInstrCPU(pVM, pCtx, pc, &Cpu, pszPrefix);
    2361 }
    2362 
    2363 
    2364 /**
    2365  * Disassemble an instruction and dump it to the log
    2366  *
    2367  * @returns VBox status code.
    2368  * @param   pVM         VM Handle
    2369  * @param   pCtx        CPU context
    2370  * @param   pc          GC instruction pointer
    2371  * @param   pszPrefix   String prefix for logging
    2372  * @param   nrInstructions
    2373  *
    2374  * @deprecated  Create new DBGFR3Disas function to do this.
    2375  */
    2376 VMMR3DECL(void) CPUMR3DisasmBlock(PVM pVM, PCPUMCTX pCtx, RTGCPTR pc, const char *pszPrefix, int nrInstructions)
    2377 {
    2378     for (int i = 0; i < nrInstructions; i++)
    2379     {
    2380         DISCPUSTATE cpu;
    2381 
    2382         CPUMR3DisasmInstrCPU(pVM, pCtx, pc, &cpu, pszPrefix);
    2383         pc += cpu.opsize;
    2384     }
     2394    CPUMR3DisasmInstrCPU(pVM, pVCpu, pCtx, pc, &Cpu, pszPrefix);
    23852395}
    23862396
     
    23932403VMMR3DECL(void) CPUMR3SaveEntryCtx(PVM pVM)
    23942404{
    2395     /* @todo SMP */
    2396     pVM->cpum.s.GuestEntry = *CPUMQueryGuestCtxPtr(pVM);
     2405    /* @todo SMP support!! */
     2406    pVM->cpum.s.GuestEntry = *CPUMQueryGuestCtxPtr(VMMGetCpu(pVM));
    23972407}
    23982408
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