VirtualBox

Changeset 17537 in vbox for trunk/src/recompiler_new


Ignore:
Timestamp:
Mar 8, 2009 5:22:28 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
43971
Message:

REM: Added REMR3InitFinalize and moved the dirty page bit map allocation over there. REMR3NotifyPhysRamRegister now just tracks the highest ram address. Removed some old obsolete bits in REMInternal.h.

Location:
trunk/src/recompiler_new
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/recompiler_new/VBoxREM.def

    r17251 r17537  
    2424EXPORTS
    2525    REMR3Init
     26    REMR3InitFinalize
    2627    REMR3Term
    2728    REMR3Reset
  • trunk/src/recompiler_new/VBoxREMWrapper.cpp

    r17530 r17537  
    333333 * @{ */
    334334static DECLCALLBACKPTR(int, pfnREMR3Init)(PVM);
     335static DECLCALLBACKPTR(int, pfnREMR3InitFinalize)(PVM);
    335336static DECLCALLBACKPTR(int, pfnREMR3Term)(PVM);
    336337static DECLCALLBACKPTR(void, pfnREMR3Reset)(PVM);
     
    346347static DECLCALLBACKPTR(void, pfnREMR3ReplayInvalidatedPages)(PVM);
    347348static DECLCALLBACKPTR(void, pfnREMR3ReplayHandlerNotifications)(PVM pVM);
    348 static DECLCALLBACKPTR(void, pfnREMR3NotifyPhysRamRegister)(PVM, RTGCPHYS, RTUINT, unsigned);
     349static DECLCALLBACKPTR(void, pfnREMR3NotifyPhysRamRegister)(PVM, RTGCPHYS, RTGCPHYS, unsigned);
    349350#ifndef VBOX_WITH_NEW_PHYS_CODE
    350351static DECLCALLBACKPTR(void, pfnREMR3NotifyPhysRamChunkRegister)(PVM, RTGCPHYS, RTUINT, RTHCUINTPTR, unsigned);
     
    400401    { REMPARMDESC_FLAGS_INT,        sizeof(PVM), NULL },
    401402    { REMPARMDESC_FLAGS_GCPHYS,     sizeof(RTGCPHYS), NULL },
    402     { REMPARMDESC_FLAGS_INT,        sizeof(RTUINT), NULL },
     403    { REMPARMDESC_FLAGS_GCPHYS,     sizeof(RTGCPHYS), NULL },
    403404    { REMPARMDESC_FLAGS_INT,        sizeof(void *), NULL },
    404405    { REMPARMDESC_FLAGS_INT,        sizeof(unsigned), NULL }
     
    558559    { REMPARMDESC_FLAGS_INT,        sizeof(char *), NULL }
    559560};
    560 
    561561static const REMPARMDESC g_aArgsDBGFR3Info[] =
    562562{
     
    798798    { REMPARMDESC_FLAGS_GCPHYS,     sizeof(RTGCPHYS), NULL },
    799799    { REMPARMDESC_FLAGS_INT,        sizeof(uint64_t), NULL }
    800 };
    801 static const REMPARMDESC g_aArgsPGMR3DbgR3Ptr2GCPhys[] =
    802 {
    803     { REMPARMDESC_FLAGS_INT,        sizeof(PVM), NULL },
    804     { REMPARMDESC_FLAGS_INT,        sizeof(void*), NULL },
    805     { REMPARMDESC_FLAGS_INT,        sizeof(PRTGCPHYS), NULL }
    806800};
    807801static const REMPARMDESC g_aArgsRTMemRealloc[] =
     
    10241018 */
    10251019static const REMFNDESC g_aExports[] =
    1026 {  /* pszName,                                  (void *)pv,                                         pParams,                                    cParams,                                            fFlags,                     cb,             pvWrapper. */
     1020{  /* pszName,                                  (void *)pv,                                         pParams,                                    cParams,                                               fFlags,                     cb,             pvWrapper. */
    10271021    { "REMR3Init",                              (void *)&pfnREMR3Init,                              &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_INT,    sizeof(int),    NULL },
     1022    { "REMR3InitFinalize",                      (void *)&pfnREMR3InitFinalize,                      &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_INT,    sizeof(int),    NULL },
    10281023    { "REMR3Term",                              (void *)&pfnREMR3Term,                              &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_INT,    sizeof(int),    NULL },
    10291024    { "REMR3Reset",                             (void *)&pfnREMR3Reset,                             &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_VOID,   0,              NULL },
     
    11441139    { "PGMR3PhysWriteU32",                      (void *)(uintptr_t)&PGMR3PhysWriteU32,              &g_aArgsPGMR3PhysWriteU32[0],               RT_ELEMENTS(g_aArgsPGMR3PhysWriteU32),                 REMFNDESC_FLAGS_RET_VOID,   0,                  NULL },
    11451140    { "PGMR3PhysWriteU64",                      (void *)(uintptr_t)&PGMR3PhysWriteU64,              &g_aArgsPGMR3PhysWriteU64[0],               RT_ELEMENTS(g_aArgsPGMR3PhysWriteU32),                 REMFNDESC_FLAGS_RET_VOID,   0,                  NULL },
    1146     { "PGMR3DbgR3Ptr2GCPhys",                   (void *)(uintptr_t)&PGMR3DbgR3Ptr2GCPhys,           &g_aArgsPGMR3DbgR3Ptr2GCPhys[0],            RT_ELEMENTS(g_aArgsPGMR3DbgR3Ptr2GCPhys),              REMFNDESC_FLAGS_RET_INT,    sizeof(int),        NULL },
    11471141    { "PGMR3PhysTlbGCPhys2Ptr",                 (void *)(uintptr_t)&PGMR3PhysTlbGCPhys2Ptr,         &g_aArgsPGMR3PhysTlbGCPhys2Ptr[0],          RT_ELEMENTS(g_aArgsPGMR3PhysTlbGCPhys2Ptr),            REMFNDESC_FLAGS_RET_INT,    sizeof(int),        NULL },
    11481142    { "SSMR3GetGCPtr",                          (void *)(uintptr_t)&SSMR3GetGCPtr,                  &g_aArgsSSMR3GetGCPtr[0],                   RT_ELEMENTS(g_aArgsSSMR3GetGCPtr),                     REMFNDESC_FLAGS_RET_INT,    sizeof(int),        NULL },
     
    11981192    { "RTLogPrintf",                            (void *)(uintptr_t)&RTLogPrintf,                    &g_aArgsRTLogPrintf[0],                     RT_ELEMENTS(g_aArgsRTLogPrintf),                       REMFNDESC_FLAGS_RET_VOID,   0,                  NULL },
    11991193    { "RTMemAlloc",                             (void *)(uintptr_t)&RTMemAlloc,                     &g_aArgsSIZE_T[0],                          RT_ELEMENTS(g_aArgsSIZE_T),                            REMFNDESC_FLAGS_RET_INT,    sizeof(void *),     NULL },
    1200     { "RTMemAllocZ",                            (void *)(uintptr_t)&RTMemAllocZ,                     &g_aArgsSIZE_T[0],                          RT_ELEMENTS(g_aArgsSIZE_T),                            REMFNDESC_FLAGS_RET_INT,    sizeof(void *),     NULL },
    1201     { "RTMemRealloc",                           (void *)(uintptr_t)&RTMemRealloc,                     &g_aArgsRTMemRealloc[0],                          RT_ELEMENTS(g_aArgsRTMemRealloc),                            REMFNDESC_FLAGS_RET_INT,    sizeof(void *),     NULL },
     1194    { "RTMemAllocZ",                            (void *)(uintptr_t)&RTMemAllocZ,                    &g_aArgsSIZE_T[0],                          RT_ELEMENTS(g_aArgsSIZE_T),                            REMFNDESC_FLAGS_RET_INT,    sizeof(void *),     NULL },
     1195    { "RTMemRealloc",                           (void *)(uintptr_t)&RTMemRealloc,                   &g_aArgsRTMemRealloc[0],                    RT_ELEMENTS(g_aArgsRTMemRealloc),                      REMFNDESC_FLAGS_RET_INT,    sizeof(void *),     NULL },
    12021196    { "RTMemExecAlloc",                         (void *)(uintptr_t)&RTMemExecAlloc,                 &g_aArgsSIZE_T[0],                          RT_ELEMENTS(g_aArgsSIZE_T),                            REMFNDESC_FLAGS_RET_INT,    sizeof(void *),     NULL },
    1203 
    12041197    { "RTMemExecFree",                          (void *)(uintptr_t)&RTMemExecFree,                  &g_aArgsPTR[0],                             RT_ELEMENTS(g_aArgsPTR),                               REMFNDESC_FLAGS_RET_VOID,   0,                  NULL },
    12051198    { "RTMemFree",                              (void *)(uintptr_t)&RTMemFree,                      &g_aArgsPTR[0],                             RT_ELEMENTS(g_aArgsPTR),                               REMFNDESC_FLAGS_RET_VOID,   0,                  NULL },
     
    20252018}
    20262019
     2020REMR3DECL(int) REMR3InitFinalize(PVM pVM)
     2021{
     2022#ifndef USE_REM_STUBS
     2023    Assert(VALID_PTR(pfnREMR3InitFinalize));
     2024    return pfnREMR3InitFinalize(pVM);
     2025#endif
     2026}
     2027
    20272028REMR3DECL(int) REMR3Term(PVM pVM)
    20282029{
     
    21662167}
    21672168
    2168 REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, unsigned fFlags)
     2169REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, unsigned fFlags)
    21692170{
    21702171#ifndef USE_REM_STUBS
  • trunk/src/recompiler_new/VBoxRecompiler.c

    r17459 r17537  
    9090static DECLCALLBACK(int) remR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version);
    9191static void     remR3StateUpdate(PVM pVM);
     92static int      remR3InitPhysRamSizeAndDirtyMap(PVM pVM, bool fGuarded);
    9293
    9394static uint32_t remR3MMIOReadU8(void *pvVM, target_phys_addr_t GCPhys);
     
    258259    Assert(!testmath());
    259260#endif
     261
    260262    /*
    261263     * Init some internal data members.
     
    396398#endif
    397399
     400    return rc;
     401}
     402
     403
     404/**
     405 * Finalizes the REM initialization.
     406 *
     407 * This is called after all components, devices and drivers has
     408 * been initialized. Its main purpose it to finish the RAM related
     409 * initialization.
     410 *
     411 * @returns VBox status code.
     412 *
     413 * @param   pVM         The VM handle.
     414 */
     415REMR3DECL(int) REMR3InitFinalize(PVM pVM)
     416{
     417    int rc;
     418
     419    /*
     420     * Ram size & dirty bit map.
     421     */
     422    Assert(!pVM->rem.s.fGCPhysLastRamFixed);
     423    pVM->rem.s.fGCPhysLastRamFixed = true;
     424#ifdef RT_STRICT
     425    rc = remR3InitPhysRamSizeAndDirtyMap(pVM, true /* fGuarded */);
     426#else
     427    rc = remR3InitPhysRamSizeAndDirtyMap(pVM, false /* fGuarded */);
     428#endif
     429    return rc;
     430}
     431
     432
     433/**
     434 * Initializes phys_ram_size, phys_ram_dirty and phys_ram_dirty_size.
     435 *
     436 * @returns VBox status code.
     437 * @param   pVM         The VM handle.
     438 * @param   fGuarded    Whether to guard the map.
     439 */
     440static int remR3InitPhysRamSizeAndDirtyMap(PVM pVM, bool fGuarded)
     441{
     442    int      rc = VINF_SUCCESS;
     443    RTGCPHYS cb;
     444
     445    cb = pVM->rem.s.GCPhysLastRam + 1;
     446    AssertLogRelMsgReturn(cb > pVM->rem.s.GCPhysLastRam,
     447                          ("GCPhysLastRam=%RGp - out of range\n", pVM->rem.s.GCPhysLastRam),
     448                          VERR_OUT_OF_RANGE);
     449    phys_ram_size = cb;
     450    phys_ram_dirty_size = cb >> PAGE_SHIFT;
     451    AssertMsg(((RTGCPHYS)phys_ram_dirty_size << PAGE_SHIFT) == cb, ("%RGp\n", cb));
     452
     453    if (!fGuarded)
     454    {
     455        phys_ram_dirty = MMR3HeapAlloc(pVM, MM_TAG_REM, phys_ram_dirty_size);
     456        AssertLogRelMsgReturn(phys_ram_dirty, ("Failed to allocate %u bytes of dirty page map bytes\n", phys_ram_dirty_size), VERR_NO_MEMORY);
     457    }
     458    else
     459    {
     460        /*
     461         * Fill it up the nearest 4GB RAM and leave at least _64KB of guard after it.
     462         */
     463        uint32_t cbBitmapAligned = RT_ALIGN_32(phys_ram_dirty_size, PAGE_SIZE);
     464        uint32_t cbBitmapFull    = RT_ALIGN_32(phys_ram_dirty_size, (_4G >> PAGE_SHIFT));
     465        if (cbBitmapFull == cbBitmapAligned)
     466            cbBitmapFull += _4G >> PAGE_SHIFT;
     467        else if (cbBitmapFull - cbBitmapAligned < _64K)
     468            cbBitmapFull += _64K;
     469
     470        phys_ram_dirty = RTMemPageAlloc(cbBitmapFull);
     471        AssertLogRelMsgReturn(phys_ram_dirty, ("Failed to allocate %u bytes of dirty page map bytes\n", cbBitmapFull), VERR_NO_MEMORY);
     472
     473        rc = RTMemProtect(phys_ram_dirty + cbBitmapAligned, cbBitmapFull - cbBitmapAligned, RTMEM_PROT_NONE);
     474        if (RT_FAILURE(rc))
     475        {
     476            RTMemPageFree(phys_ram_dirty);
     477            AssertLogRelRCReturn(rc, rc);
     478        }
     479
     480        phys_ram_dirty += cbBitmapAligned - phys_ram_dirty_size;
     481    }
     482
     483    /* initialize it. */
     484    memset(phys_ram_dirty, 0xff, phys_ram_dirty_size);
    398485    return rc;
    399486}
     
    15731660 *
    15741661 * @param   pVM         VM Handle.
    1575  * @param   fFlushTBs   Flush all translation blocks before executing code
    15761662 *
    15771663 * @remark  The caller has to check for important FFs before calling REMR3Run. REMR3State will
     
    17121798        pVM->rem.s.Env.hflags &= ~(HF_LMA_MASK | HF_CS64_MASK);
    17131799#endif
    1714 
    17151800
    17161801    /*
     
    26372722 * @param   fFlags      Flags of the MM_RAM_FLAGS_* defines.
    26382723 */
    2639 REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, unsigned fFlags)
    2640 {
    2641     uint32_t cbBitmap;
    2642     int rc;
    2643     Log(("REMR3NotifyPhysRamRegister: GCPhys=%RGp cb=%d fFlags=%d\n", GCPhys, cb, fFlags));
     2724REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, unsigned fFlags)
     2725{
     2726    Log(("REMR3NotifyPhysRamRegister: GCPhys=%RGp cb=%RGp fFlags=%d\n", GCPhys, cb, fFlags));
    26442727    VM_ASSERT_EMT(pVM);
    26452728
     
    26522735
    26532736    /*
    2654      * Base ram?
    2655      */
    2656     if (!GCPhys)
    2657     {
    2658         phys_ram_size = cb;
    2659         phys_ram_dirty_size = cb >> PAGE_SHIFT;
    2660 #ifndef VBOX_STRICT
    2661         phys_ram_dirty = MMR3HeapAlloc(pVM, MM_TAG_REM, phys_ram_dirty_size);
    2662         AssertReleaseMsg(phys_ram_dirty, ("failed to allocate %d bytes of dirty bytes\n", phys_ram_dirty_size));
    2663 #else /* VBOX_STRICT: allocate a full map and make the out of bounds pages invalid. */
    2664         phys_ram_dirty = RTMemPageAlloc(_4G >> PAGE_SHIFT);
    2665         AssertReleaseMsg(phys_ram_dirty, ("failed to allocate %d bytes of dirty bytes\n", _4G >> PAGE_SHIFT));
    2666         cbBitmap = RT_ALIGN_32(phys_ram_dirty_size, PAGE_SIZE);
    2667         rc = RTMemProtect(phys_ram_dirty + cbBitmap, (_4G >> PAGE_SHIFT) - cbBitmap, RTMEM_PROT_NONE);
    2668         AssertRC(rc);
    2669         phys_ram_dirty += cbBitmap - phys_ram_dirty_size;
    2670 #endif
    2671         memset(phys_ram_dirty, 0xff, phys_ram_dirty_size);
     2737     * Base ram? Update GCPhysLastRam.
     2738     */
     2739    if (!GCPhys) /** @todo add a flag for identifying MMIO2 memory here (new phys code)*/
     2740    {
     2741        if (GCPhys + (cb - 1) > pVM->rem.s.GCPhysLastRam)
     2742        {
     2743            AssertReleaseMsg(!pVM->rem.s.fGCPhysLastRamFixed, ("GCPhys=%RGp cb=%RGp\n", GCPhys, cb));
     2744            pVM->rem.s.GCPhysLastRam = GCPhys + (cb - 1);
     2745        }
    26722746    }
    26732747
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