VirtualBox

Changeset 17537 in vbox


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
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/rem.h

    r17251 r17537  
    6262 */
    6363REMR3DECL(int)  REMR3Init(PVM pVM);
     64REMR3DECL(int)  REMR3InitFinalize(PVM pVM);
    6465REMR3DECL(int)  REMR3Term(PVM pVM);
    6566REMR3DECL(void) REMR3Reset(PVM pVM);
     
    7778REMR3DECL(void) REMR3ReplayHandlerNotifications(PVM pVM);
    7879REMR3DECL(int)  REMR3NotifyCodePageChanged(PVM pVM, RTGCPTR pvCodePage);
    79 REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, unsigned fFlags);
     80REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, unsigned fFlags);
    8081#ifndef VBOX_WITH_NEW_PHYS_CODE
    8182REMR3DECL(void) REMR3NotifyPhysRamChunkRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, RTHCUINTPTR pvRam, unsigned fFlags);
  • trunk/src/VBox/VMM/REMInternal.h

    r17429 r17537  
    110110
    111111/**
    112  * Dynamically allocated guest RAM chunk information
    113  * HC virt to GC Phys
    114  *
    115  * A RAM chunk can spawn two chunk regions as we don't align them on chunk boundaries.
    116  */
    117 typedef struct REMCHUNKINFO
    118 {
    119     RTHCUINTPTR pChunk1;
    120     RTHCUINTPTR pChunk2;
    121     RTGCPHYS    GCPhys1;
    122     RTGCPHYS    GCPhys2;
    123 } REMCHUNKINFO, *PREMCHUNKINFO;
    124 
    125 /** Maximum number of external guest RAM/ROM registrations. */
    126 #define REM_MAX_PHYS_REGISTRATIONS              16
    127 
    128 /**
    129  * Registration record for external guest RAM & ROM
    130  */
    131 typedef struct REMPHYSREGISTRATION
    132 {
    133     RTGCPHYS        GCPhys;
    134     RTHCUINTPTR     HCVirt;
    135     RTUINT          cb;
    136 #if HC_ARCH_BITS == 64
    137     uint32_t        u32Padding;
    138 #endif
    139 } REMPHYSREGISTRATION, *PREMPHYSREGISTRATION;
    140 
    141 /**
    142112 * Converts a REM pointer into a VM pointer.
    143113 * @returns Pointer to the VM structure the REM is part of.
     
    182152    /** Number of times REMR3CanExecuteRaw has been called.
    183153     * It is used to prevent rescheduling on the first call. */
    184     RTUINT                  cCanExecuteRaw;
     154    uint32_t                cCanExecuteRaw;
    185155
    186156    /** Pending interrupt (~0 -> nothing). */
    187     RTUINT                  u32PendingInterrupt;
     157    uint32_t                u32PendingInterrupt;
    188158
    189159#if HC_ARCH_BITS == 64
     
    192162#endif
    193163    /** Number of recorded invlpg instructions. */
    194     RTUINT                  cInvalidatedPages;
     164    uint32_t                cInvalidatedPages;
    195165    /** Array of recorded invlpg instruction.
    196166     * These instructions are replayed when entering REM. */
     
    203173    REMHANDLERNOTIFICATION  aHandlerNotifications[32];
    204174
    205     /** Pointer to an array of hc virt to gc phys records. */
    206     R3PTRTYPE(PREMCHUNKINFO) paHCVirtToGCPhys;
    207     /** Pointer to a GC Phys to HC Virt lookup table. */
    208     R3PTRTYPE(PRTHCUINTPTR) paGCPhysToHCVirt;
    209 
    210     /** Array of external RAM and ROM registrations (excluding guest RAM). */
    211     REMPHYSREGISTRATION     aPhysReg[REM_MAX_PHYS_REGISTRATIONS];
    212     /** Number of external RAM and ROM registrations (excluding guest RAM). */
    213     RTUINT                  cPhysRegistrations;
    214 
    215175    /** MMIO memory type.
    216176     * This is used to register MMIO physical access handlers. */
    217     RTINT                   iMMIOMemType;
     177    int32_t                 iMMIOMemType;
    218178    /** Handler memory type.
    219179     * This is used to register non-MMIO physical access handlers which are executed in HC. */
    220     RTINT                   iHandlerMemType;
     180    int32_t                 iHandlerMemType;
    221181
    222182    /** Pending exception */
    223183    uint32_t                uPendingException;
     184    /** Nr of pending exceptions */
     185    uint32_t                cPendingExceptions;
    224186    /** Pending exception's EIP */
    225187    uint32_t                uPendingExcptEIP;
     188    uint32_t                reserved_for_future_uPendingExcptRIP;
    226189    /** Pending exception's CR2 */
    227190    uint32_t                uPendingExcptCR2;
    228     /** Nr of pending exceptions */
    229     uint32_t                cPendingExceptions;
     191    uint32_t                reserved_for_future_64bit_uPendingExcptCR2;
     192
     193    /** The highest known RAM address. */
     194    RTGCPHYS                GCPhysLastRam;
     195    /** Whether GCPhysLastRam has been fixed (see REMR3Init()). */
     196    bool                    fGCPhysLastRamFixed;
    230197
    231198    /** Pending rc. */
    232     RTINT                   rc;
     199    int32_t                 rc;
    233200
    234201    /** Time spent in QEMU. */
     
    241208    STAMPROFILE             StatsStateBack;
    242209
    243 #if HC_ARCH_BITS != 32
    244210    /** Padding the CPUX86State structure to 32 byte. */
    245     uint32_t                abPadding[HC_ARCH_BITS == 32 ? 0 : 4];
    246 #endif
     211    uint32_t                abPadding[HC_ARCH_BITS == 32 ? 6 : 4];
    247212
    248213#ifdef VBOX_WITH_NEW_RECOMPILER
  • trunk/src/VBox/VMM/VM.cpp

    r16584 r17537  
    749749                                                                        rc = VMMR3InitFinalize(pVM);
    750750                                                                    if (RT_SUCCESS(rc))
     751                                                                        rc = REMR3InitFinalize(pVM);
     752                                                                    if (RT_SUCCESS(rc))
    751753                                                                        rc = vmR3InitDoCompleted(pVM, VMINITCOMPLETED_RING3);
    752754                                                                    if (RT_SUCCESS(rc))
  • trunk/src/VBox/VMM/testcase/tstVMStructGC.cpp

    r17513 r17537  
    746746    GEN_CHECK_OFF(REM, cHandlerNotifications);
    747747    GEN_CHECK_OFF(REM, aHandlerNotifications);
    748     GEN_CHECK_OFF(REM, paHCVirtToGCPhys);
    749     GEN_CHECK_OFF(REM, cPhysRegistrations);
    750     GEN_CHECK_OFF(REM, aPhysReg);
    751748    GEN_CHECK_OFF(REM, rc);
    752749    GEN_CHECK_OFF(REM, StatsInQEMU);
  • trunk/src/VBox/VMM/testcase/tstVMStructSize.cpp

    r14411 r17537  
    175175    CHECK_MEMBER_ALIGNMENT(VM, vmm.s.StatRunRC, 8);
    176176    CHECK_MEMBER_ALIGNMENT(VM, StatTotalQemuToGC, 8);
     177    CHECK_MEMBER_ALIGNMENT(VM, rem.s.uPendingExcptCR2, 8);
    177178    CHECK_MEMBER_ALIGNMENT(VM, rem.s.StatsInQEMU, 8);
    178179    CHECK_MEMBER_ALIGNMENT(VM, rem.s.Env, 32);
  • trunk/src/recompiler/VBoxREM.def

    r17251 r17537  
    2424EXPORTS
    2525    REMR3Init
     26    REMR3InitFinalize
    2627    REMR3Term
    2728    REMR3Reset
  • trunk/src/recompiler/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 }
     
    413414};
    414415static const REMPARMDESC g_aArgsNotifyPhysReserve[] =
     416{
     417    { REMPARMDESC_FLAGS_INT,        sizeof(PVM), NULL },
     418    { REMPARMDESC_FLAGS_GCPHYS,     sizeof(RTGCPHYS), NULL },
     419    { REMPARMDESC_FLAGS_INT,        sizeof(RTUINT), NULL }
     420};
     421static const REMPARMDESC g_aArgsNotifyPhysRamDeregister[] =
    415422{
    416423    { REMPARMDESC_FLAGS_INT,        sizeof(PVM), NULL },
     
    552559    { REMPARMDESC_FLAGS_INT,        sizeof(uint32_t), NULL },
    553560    { REMPARMDESC_FLAGS_INT,        sizeof(uint32_t *), NULL }
     561};
     562static const REMPARMDESC g_aArgsDBGFR3DisasInstrCurrentLogInternal[] =
     563{
     564    { REMPARMDESC_FLAGS_INT,        sizeof(PVM), NULL },
     565    { REMPARMDESC_FLAGS_INT,        sizeof(char *), NULL }
    554566};
    555567static const REMPARMDESC g_aArgsDBGFR3Info[] =
     
    10001012 */
    10011013static const REMFNDESC g_aExports[] =
    1002 {  /* pszName,                                  (void *)pv,                                         pParams,                                    cParams,                                            fFlags,                     cb,             pvWrapper. */
     1014{  /* pszName,                                  (void *)pv,                                         pParams,                                    cParams,                                               fFlags,                     cb,             pvWrapper. */
    10031015    { "REMR3Init",                              (void *)&pfnREMR3Init,                              &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_INT,    sizeof(int),    NULL },
     1016    { "REMR3InitFinalize",                      (void *)&pfnREMR3InitFinalize,                      &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_INT,    sizeof(int),    NULL },
    10041017    { "REMR3Term",                              (void *)&pfnREMR3Term,                              &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_INT,    sizeof(int),    NULL },
    10051018    { "REMR3Reset",                             (void *)&pfnREMR3Reset,                             &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_VOID,   0,              NULL },
     
    10691082#endif
    10701083    { "DBGFR3DisasInstrEx",                     (void *)(uintptr_t)&DBGFR3DisasInstrEx,             &g_aArgsDBGFR3DisasInstrEx[0],              RT_ELEMENTS(g_aArgsDBGFR3DisasInstrEx),                REMFNDESC_FLAGS_RET_INT,    sizeof(int),        NULL },
     1084    { "DBGFR3DisasInstrCurrentLogInternal",     (void *)(uintptr_t)&DBGFR3DisasInstrCurrentLogInternal, &g_aArgsDBGFR3DisasInstrCurrentLogInternal[0],  RT_ELEMENTS(g_aArgsDBGFR3DisasInstrCurrentLogInternal),REMFNDESC_FLAGS_RET_INT,    sizeof(int),        NULL },
    10711085    { "DBGFR3Info",                             (void *)(uintptr_t)&DBGFR3Info,                     &g_aArgsDBGFR3Info[0],                      RT_ELEMENTS(g_aArgsDBGFR3Info),                        REMFNDESC_FLAGS_RET_INT,    sizeof(int),        NULL },
    10721086    { "DBGFR3InfoLogRelHlp",                    (void *)(uintptr_t)&DBGFR3InfoLogRelHlp,            NULL,                                       0,                                                     REMFNDESC_FLAGS_RET_INT,    sizeof(void *),     NULL },
     
    19922006}
    19932007
     2008REMR3DECL(int) REMR3InitFinalize(PVM pVM)
     2009{
     2010#ifndef USE_REM_STUBS
     2011    Assert(VALID_PTR(pfnREMR3InitFinalize));
     2012    return pfnREMR3InitFinalize(pVM);
     2013#endif
     2014}
     2015
    19942016REMR3DECL(int) REMR3Term(PVM pVM)
    19952017{
     
    21332155}
    21342156
    2135 REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, unsigned fFlags)
     2157REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, unsigned fFlags)
    21362158{
    21372159#ifndef USE_REM_STUBS
  • trunk/src/recompiler/VBoxRecompiler.c

    r17426 r17537  
    8686static DECLCALLBACK(int) remR3Load(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version);
    8787static void     remR3StateUpdate(PVM pVM);
     88static int      remR3InitPhysRamSizeAndDirtyMap(PVM pVM, bool fGuarded);
    8889
    8990static uint32_t remR3MMIOReadU8(void *pvVM, target_phys_addr_t GCPhys);
     
    401402#endif
    402403
     404    return rc;
     405}
     406
     407
     408/**
     409 * Finalizes the REM initialization.
     410 *
     411 * This is called after all components, devices and drivers has
     412 * been initialized. Its main purpose it to finish the RAM related
     413 * initialization.
     414 *
     415 * @returns VBox status code.
     416 *
     417 * @param   pVM         The VM handle.
     418 */
     419REMR3DECL(int) REMR3InitFinalize(PVM pVM)
     420{
     421    int rc;
     422
     423    /*
     424     * Ram size & dirty bit map.
     425     */
     426    Assert(!pVM->rem.s.fGCPhysLastRamFixed);
     427    pVM->rem.s.fGCPhysLastRamFixed = true;
     428#ifdef RT_STRICT
     429    rc = remR3InitPhysRamSizeAndDirtyMap(pVM, true /* fGuarded */);
     430#else
     431    rc = remR3InitPhysRamSizeAndDirtyMap(pVM, false /* fGuarded */);
     432#endif
     433    return rc;
     434}
     435
     436
     437/**
     438 * Initializes phys_ram_size, phys_ram_dirty and phys_ram_dirty_size.
     439 *
     440 * @returns VBox status code.
     441 * @param   pVM         The VM handle.
     442 * @param   fGuarded    Whether to guard the map.
     443 */
     444static int remR3InitPhysRamSizeAndDirtyMap(PVM pVM, bool fGuarded)
     445{
     446    int      rc = VINF_SUCCESS;
     447    RTGCPHYS cb;
     448
     449    cb = pVM->rem.s.GCPhysLastRam + 1;
     450    AssertLogRelMsgReturn(cb > pVM->rem.s.GCPhysLastRam,
     451                          ("GCPhysLastRam=%RGp - out of range\n", pVM->rem.s.GCPhysLastRam),
     452                          VERR_OUT_OF_RANGE);
     453    phys_ram_size = cb;
     454    phys_ram_dirty_size = cb >> PAGE_SHIFT;
     455    AssertMsg(((RTGCPHYS)phys_ram_dirty_size << PAGE_SHIFT) == cb, ("%RGp\n", cb));
     456
     457    if (!fGuarded)
     458    {
     459        phys_ram_dirty = MMR3HeapAlloc(pVM, MM_TAG_REM, phys_ram_dirty_size);
     460        AssertLogRelMsgReturn(phys_ram_dirty, ("Failed to allocate %u bytes of dirty page map bytes\n", phys_ram_dirty_size), VERR_NO_MEMORY);
     461    }
     462    else
     463    {
     464        /*
     465         * Fill it up the nearest 4GB RAM and leave at least _64KB of guard after it.
     466         */
     467        uint32_t cbBitmapAligned = RT_ALIGN_32(phys_ram_dirty_size, PAGE_SIZE);
     468        uint32_t cbBitmapFull    = RT_ALIGN_32(phys_ram_dirty_size, (_4G >> PAGE_SHIFT));
     469        if (cbBitmapFull == cbBitmapAligned)
     470            cbBitmapFull += _4G >> PAGE_SHIFT;
     471        else if (cbBitmapFull - cbBitmapAligned < _64K)
     472            cbBitmapFull += _64K;
     473
     474        phys_ram_dirty = RTMemPageAlloc(cbBitmapFull);
     475        AssertLogRelMsgReturn(phys_ram_dirty, ("Failed to allocate %u bytes of dirty page map bytes\n", cbBitmapFull), VERR_NO_MEMORY);
     476
     477        rc = RTMemProtect(phys_ram_dirty + cbBitmapAligned, cbBitmapFull - cbBitmapAligned, RTMEM_PROT_NONE);
     478        if (RT_FAILURE(rc))
     479        {
     480            RTMemPageFree(phys_ram_dirty);
     481            AssertLogRelRCReturn(rc, rc);
     482        }
     483
     484        phys_ram_dirty += cbBitmapAligned - phys_ram_dirty_size;
     485    }
     486
     487    /* initialize it. */
     488    memset(phys_ram_dirty, 0xff, phys_ram_dirty_size);
    403489    return rc;
    404490}
     
    14191505}
    14201506
     1507
    14211508/**
    14221509 * Called from tlb_unprotect_code in order to clear write monitoring for a code page.
     
    18631950        }
    18641951
    1865         /* Sync FPU state after CR4 and CPUID. */
     1952        /* Sync FPU state after CR4, CPUID and EFER (!). */
    18661953        if (fFlags & CPUM_CHANGED_FPU_REM)
    18671954            save_raw_fp_state(&pVM->rem.s.Env, (uint8_t *)&pCtx->fpu); /* 'save' is an excellent name. */
     
    26982785 * @param   fFlags      Flags of the MM_RAM_FLAGS_* defines.
    26992786 */
    2700 REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, unsigned fFlags)
    2701 {
    2702     Log(("REMR3NotifyPhysRamRegister: GCPhys=%RGp cb=%d fFlags=%d\n", GCPhys, cb, fFlags));
     2787REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cb, unsigned fFlags)
     2788{
     2789    Log(("REMR3NotifyPhysRamRegister: GCPhys=%RGp cb=%RGp fFlags=%d\n", GCPhys, cb, fFlags));
    27032790    VM_ASSERT_EMT(pVM);
    27042791
     
    27132800     * Base ram?
    27142801     */
    2715     if (!GCPhys)
    2716     {
    2717         phys_ram_size = cb;
    2718         phys_ram_dirty_size = cb >> PAGE_SHIFT;
    2719 #ifndef VBOX_STRICT
    2720         phys_ram_dirty = MMR3HeapAlloc(pVM, MM_TAG_REM, phys_ram_dirty_size);
    2721         AssertReleaseMsg(phys_ram_dirty, ("failed to allocate %d bytes of dirty bytes\n", phys_ram_dirty_size));
    2722 #else /* VBOX_STRICT: allocate a full map and make the out of bounds pages invalid. */
    2723         phys_ram_dirty = RTMemPageAlloc(_4G >> PAGE_SHIFT);
    2724         AssertReleaseMsg(phys_ram_dirty, ("failed to allocate %d bytes of dirty bytes\n", _4G >> PAGE_SHIFT));
    2725         uint32_t cbBitmap = RT_ALIGN_32(phys_ram_dirty_size, PAGE_SIZE);
    2726         int rc = RTMemProtect(phys_ram_dirty + cbBitmap, (_4G >> PAGE_SHIFT) - cbBitmap, RTMEM_PROT_NONE);
    2727         AssertRC(rc);
    2728         phys_ram_dirty += cbBitmap - phys_ram_dirty_size;
    2729 #endif
    2730         memset(phys_ram_dirty, 0xff, phys_ram_dirty_size);
     2802    if (!GCPhys) /** @todo add a flag for identifying MMIO2 memory here (new phys code)*/
     2803    {
     2804        if (GCPhys + (cb - 1) > pVM->rem.s.GCPhysLastRam)
     2805        {
     2806            AssertReleaseMsg(!pVM->rem.s.fGCPhysLastRamFixed, ("GCPhys=%RGp cb=%RGp\n", GCPhys, cb));
     2807            pVM->rem.s.GCPhysLastRam = GCPhys + (cb - 1);
     2808        }
    27312809    }
    27322810
     
    27382816
    27392817#ifdef VBOX_WITH_NEW_PHYS_CODE
    2740     if (fFlags & MM_RAM_FLAGS_RESERVED)
    2741         cpu_register_physical_memory(GCPhys, cb, IO_MEM_UNASSIGNED);
    2742     else
    2743         cpu_register_physical_memory(GCPhys, cb, GCPhys);
     2818    cpu_register_physical_memory(GCPhys, cb, GCPhys);
    27442819#else
    27452820    if (!GCPhys)
  • 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