PGMSavedState.cpp revision 8e0f079384d0e8445e59e4660763bdce27b42dd9
/* $Id$ */
/** @file
* PGM - Page Manager and Monitor, The Saved State Part.
*/
/*
* Copyright (C) 2006-2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_PGM
#include "PGMInternal.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Saved state data unit version. */
#define PGM_SAVED_STATE_VERSION 11
/** Saved state data unit version used during 3.1 development, misses the RAM
* config. */
#define PGM_SAVED_STATE_VERSION_NO_RAM_CFG 10
/** Saved state data unit version for 3.0 (pre teleportation). */
#define PGM_SAVED_STATE_VERSION_3_0_0 9
/** Saved state data unit version for 2.2.2 and later. */
#define PGM_SAVED_STATE_VERSION_2_2_2 8
/** Saved state data unit version for 2.2.0. */
#define PGM_SAVED_STATE_VERSION_RR_DESC 7
/** Saved state data unit version. */
#define PGM_SAVED_STATE_VERSION_OLD_PHYS_CODE 6
/** @name Sparse state record types
* @{ */
/** Zero page. No data. */
/** Raw page. */
/** Raw MMIO2 page. */
/** Zero MMIO2 page. */
/** Virgin ROM page. Followed by protection (8-bit) and the raw bits. */
/** Raw shadowed ROM page. The protection (8-bit) preceeds the raw bits. */
/** Zero shadowed ROM page. The protection (8-bit) is the only payload. */
/** ROM protection (8-bit). */
/** The last record type. */
/** End marker. */
/** Flag indicating that the data is preceeded by the page address.
* For RAW pages this is a RTGCPHYS. For MMIO2 and ROM pages this is a 8-bit
* range ID and a 32-bit page index.
*/
/** @} */
/** The CRC-32 for a zero page. */
/** The CRC-32 for a zero half page. */
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** For loading old saved states. (pre-smp) */
typedef struct
{
/** If set no conflict checks are required. (boolean) */
bool fMappingsFixed;
/** Size of fixed mapping */
/** Base address (GC) of fixed mapping */
/** A20 gate mask.
* Our current approach to A20 emulation is to let REM do it and don't bother
* anywhere else. The interesting Guests will be operating with it enabled anyway.
* But whould need arrise, we'll subject physical addresses to this mask. */
/** A20 gate state - boolean! */
bool fA20Enabled;
/** The guest paging mode. */
} PGMOLD;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static const SSMFIELD s_aPGMFields[] =
{
};
static const SSMFIELD s_aPGMCpuFields[] =
{
};
static const SSMFIELD s_aPGMFields_Old[] =
{
};
/**
* Find the ROM tracking structure for the given page.
*
* @returns Pointer to the ROM page structure. NULL if the caller didn't check
* that it's a ROM page.
* @param pVM The VM handle.
* @param GCPhys The address of the ROM page.
*/
static PPGMROMPAGE pgmR3GetRomPage(PVM pVM, RTGCPHYS GCPhys) /** @todo change this to take a hint. */
{
{
}
return NULL;
}
/**
* Prepares the ROM pages for a live save.
*
* @returns VBox status code.
* @param pVM The VM handle.
*/
{
/*
* Initialize the live save tracking in the ROM page descriptors.
*/
{
{
{
else
{
if (RT_SUCCESS(rc))
else
}
}
}
}
return VINF_SUCCESS;
}
/**
* Assigns IDs to the ROM ranges and saves them.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM Saved state handle.
*/
{
{
if (RT_FAILURE(rc))
break;
}
}
/**
* Loads the ROM range ID assignments.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pSSM The saved state handle.
*/
{
for (;;)
{
/*
* Read the data.
*/
if (RT_FAILURE(rc))
return rc;
{
return VINF_SUCCESS; /* the end */
}
char szDesc[64];
if (RT_FAILURE(rc))
return rc;
AssertLogRelMsgReturn(!(GCPhys & PAGE_OFFSET_MASK), ("GCPhys=%RGp %s\n", GCPhys, szDesc), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
AssertLogRelMsgReturn(!(cb & PAGE_OFFSET_MASK), ("cb=%RGp %s\n", cb, szDesc), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
/*
* Locate a matching ROM range.
*/
&& iRegion == 0
&& szDevName[0] == '\0',
{
{
break;
}
}
if (!pRom)
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("ROM at %RGp by the name '%s' was not found"), GCPhys, szDesc);
} /* forever */
}
/**
* Scan ROM pages.
*
* @param pVM The VM handle.
*/
{
/*
* The shadow ROMs.
*/
{
{
{
{
{
}
}
else
}
}
}
}
/**
* Takes care of the virgin ROM pages in the first pass.
*
* This is an attempt at simplifying the handling of ROM pages a little bit.
* This ASSUMES that no new ROM ranges will be added and that they won't be
* relinked in any way.
*
* @param pVM The VM handle.
* @param pSSM The SSM handle.
* @param fLiveSave Whether we're in a live save or not.
*/
{
{
{
/* Get the virgin page descriptor. */
if (PGMROMPROT_IS_ROM(enmProt))
else
/* Get the page bits. (Cannot use pgmPhysGCPhys2CCPtrInternalReadOnly here!) */
int rc = VINF_SUCCESS;
if (!PGM_PAGE_IS_ZERO(pPage))
{
void const *pvPage;
if (RT_SUCCESS(rc))
}
else
/* Save it. */
if (iPage > 0)
else
{
}
if (RT_FAILURE(rc))
return rc;
/* Update state. */
if (fLiveSave)
{
}
}
}
return VINF_SUCCESS;
}
/**
* Saves dirty pages in the shadowed ROM ranges.
*
* Used by pgmR3LiveExecPart2 and pgmR3SaveExecMemory.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM The SSM handle.
* @param fLiveSave Whether it's a live save or not.
* @param fFinalPass Whether this is the final pass or not.
*/
{
/*
* The Shadowed ROMs.
*
* ASSUMES that the ROM ranges are fixed.
* ASSUMES that all the ROM ranges are mapped.
*/
{
{
{
if ( !fLiveSave
|| fFinalPass
)
)
)
{
PPGMPAGE pPage = PGMROMPROT_IS_ROM(enmProt) ? &pRomPage->Shadow : pgmPhysGetPage(&pVM->pgm.s, GCPhys);
int rc = VINF_SUCCESS;
if (!fZero)
{
void const *pvPage;
if (RT_SUCCESS(rc))
}
{
}
else
{
SSMR3PutU8(pSSM, (fZero ? PGM_STATE_REC_ROM_SHW_ZERO : PGM_STATE_REC_ROM_SHW_RAW) | PGM_STATE_REC_FLAG_ADDR);
}
if (!fZero)
if (RT_FAILURE(rc))
return rc;
}
/*
* In the final pass, make sure the protection is in sync.
*/
else if ( fFinalPass
{
else
{
}
if (RT_FAILURE(rc))
return rc;
}
}
}
}
return VINF_SUCCESS;
}
/**
* Cleans up ROM pages after a live save.
*
* @param pVM The VM handle.
*/
{
}
/**
* Prepares the MMIO2 pages for a live save.
*
* @returns VBox status code.
* @param pVM The VM handle.
*/
{
/*
* Initialize the live save tracking in the MMIO2 ranges.
* ASSUME nothing changes here.
*/
{
PPGMLIVESAVEMMIO2PAGE paLSPages = (PPGMLIVESAVEMMIO2PAGE)MMR3HeapAllocZ(pVM, MM_TAG_PGM, sizeof(PGMLIVESAVEMMIO2PAGE) * cPages);
if (!paLSPages)
return VERR_NO_MEMORY;
{
/* Initialize it as a dirty zero page. */
}
}
return VINF_SUCCESS;
}
/**
* Assigns IDs to the MMIO2 ranges and saves them.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM Saved state handle.
*/
{
{
if (RT_FAILURE(rc))
break;
}
}
/**
* Loads the MMIO2 range ID assignments.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pSSM The saved state handle.
*/
{
for (;;)
{
/*
* Read the data.
*/
if (RT_FAILURE(rc))
return rc;
{
return VINF_SUCCESS; /* the end */
}
char szDesc[64];
AssertLogRelMsgReturn(!(cb & PAGE_OFFSET_MASK), ("cb=%RGp %s\n", cb, szDesc), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
/*
* Locate a matching MMIO2 range.
*/
{
{
break;
}
}
if (!pMmio2)
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Failed to locate a MMIO2 range called '%s' owned by %s/%u, region %d"),
/*
* Validate the configuration, the size of the MMIO2 region should be
* the same.
*/
{
LogRel(("PGM: MMIO2 region \"%s\" size mismatch: saved=%RGp config=%RGp\n",
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("MMIO2 region \"%s\" size mismatch: saved=%RGp config=%RGp"),
}
} /* forever */
}
/**
* Scans one MMIO2 page.
*
* @returns True if changed, false if unchanged.
*
* @param pVM The VM handle
* @param pbPage The page bits.
* @param pLSPage The live save tracking structure for the page.
*
*/
{
/*
* Special handling of zero pages.
*/
if (fZero)
{
if (ASMMemIsZeroPage(pbPage))
{
/* Not modified. */
return false;
}
}
else
{
/*
* CRC the first half, if it doesn't match the page is dirty and
* we won't check the 2nd half (we'll do that next time).
*/
{
{
/* Probably not modified. */
return false;
}
}
else
{
&& ASMMemIsZeroPage(pbPage))
{
}
}
}
/* dirty page path */
pLSPage->cUnchangedScans = 0;
{
if (fZero)
}
return true;
}
/**
* Scan for MMIO2 page modifications.
*
* @param pVM The VM handle.
* @param uPass The pass number.
*/
{
/*
* Since this is a bit expensive we lower the scan rate after a little while.
*/
if ( ( (uPass & 3) != 0
&& uPass > 10)
|| uPass == SSM_PASS_FINAL)
return;
{
{
}
}
}
/**
* Save quiescent MMIO2 pages.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM The SSM handle.
* @param fLiveSave Whether it's a live save or not.
* @param uPass The pass number.
*/
{
/** @todo implement live saving of MMIO2 pages. (Need some way of telling the
* device that we wish to know about changes.) */
int rc = VINF_SUCCESS;
if (uPass == SSM_PASS_FINAL)
{
/*
* The mop up round.
*/
{
{
if (!fLiveSave)
else
{
/* Try figure if it's a clean page, compare the SHA-1 to be really sure. */
{
continue;
continue;
}
}
else
{
}
if (u8Type == PGM_STATE_REC_MMIO2_RAW)
if (RT_FAILURE(rc))
break;
}
}
}
/*
* Reduce the rate after a little while since the current MMIO2 approach is
* a bit expensive.
* We position it two passes after the scan pass to avoid saving busy pages.
*/
else if ( uPass <= 10
{
{
{
/* Skip clean pages and pages which hasn't quiesced. */
continue;
continue;
continue;
/* Save it. */
if (!fZero)
{
}
else
{
}
if (u8Type == PGM_STATE_REC_MMIO2_RAW)
if (RT_FAILURE(rc))
break;
/* Housekeeping. */
if (u8Type == PGM_STATE_REC_MMIO2_ZERO)
}
}
}
return rc;
}
/**
* Cleans up MMIO2 pages after a live save.
*
* @param pVM The VM handle.
*/
{
/*
* Free the tracking structures for the MMIO2 pages.
* We do the freeing outside the lock in case the VM is running.
*/
{
if (pvMmio2ToFree)
{
}
}
}
/**
* Prepares the RAM pages for a live save.
*
* @returns VBox status code.
* @param pVM The VM handle.
*/
{
/*
* Try allocating tracking structures for the ram ranges.
*
* To avoid lock contention, we leave the lock every time we're allocating
* a new array. This means we'll have to ditch the allocation and start
* all over again if the RAM range list changes in-between.
*
* Note! pgmR3SaveDone will always be called and it is therefore responsible
* for cleaning up.
*/
do
{
{
&& !PGM_RAM_RANGE_IS_AD_HOC(pCur))
{
PPGMLIVESAVERAMPAGE paLSPages = (PPGMLIVESAVERAMPAGE)MMR3HeapAllocZ(pVM, MM_TAG_PGM, cPages * sizeof(PGMLIVESAVERAMPAGE));
if (!paLSPages)
return VERR_NO_MEMORY;
{
break; /* try again */
}
/*
* Initialize the array.
*/
while (iPage-- > 0)
{
/** @todo yield critsect! (after moving this away from EMT0) */
switch (PGM_PAGE_GET_TYPE(pPage))
{
case PGMPAGETYPE_RAM:
if (PGM_PAGE_IS_ZERO(pPage))
{
#endif
}
else if (PGM_PAGE_IS_SHARED(pPage))
{
#endif
}
else
{
#endif
}
break;
case PGMPAGETYPE_ROM_SHADOW:
case PGMPAGETYPE_ROM:
{
#endif
break;
}
default:
case PGMPAGETYPE_MMIO2:
#endif
break;
case PGMPAGETYPE_MMIO:
#endif
break;
}
}
}
}
} while (pCur);
return VINF_SUCCESS;
}
/**
* Saves the RAM configuration.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM The saved state handle.
*/
{
int rc = CFGMR3QueryU32Def(CFGMR3GetRoot(pVM), "RamHoleSize", &cbRamHole, MM_RAM_HOLE_SIZE_DEFAULT);
}
/**
* Loads and verifies the RAM configuration.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM The saved state handle.
*/
{
uint32_t cbRamHoleCfg = 0;
int rc = CFGMR3QueryU32Def(CFGMR3GetRoot(pVM), "RamHoleSize", &cbRamHoleCfg, MM_RAM_HOLE_SIZE_DEFAULT);
if ( cbRamHoleCfg != cbRamHoleSaved
|| cbRamCfg != cbRamSaved)
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Ram config mismatch: saved=%RX64/%RX32 config=%RX64/%RX32 (RAM/Hole)"),
return VINF_SUCCESS;
}
/**
* Calculates the CRC-32 for a RAM page and updates the live save page tracking
* info with it.
*
* @param pVM The VM handle.
* @param pCur The current RAM range.
* @param paLSPages The current array of live save page tracking
* structures.
* @param iPage The page index.
*/
static void pgmR3StateCalcCrc32ForRamPage(PVM pVM, PPGMRAMRANGE pCur, PPGMLIVESAVERAMPAGE paLSPages, uint32_t iPage)
{
void const *pvPage;
if (RT_SUCCESS(rc))
else
}
/**
* Verifies the CRC-32 for a page given it's raw bits.
*
* @param pvPage The page bits.
* @param pCur The current RAM range.
* @param paLSPages The current array of live save page tracking
* structures.
* @param iPage The page index.
*/
static void pgmR3StateVerifyCrc32ForPage(void const *pvPage, PPGMRAMRANGE pCur, PPGMLIVESAVERAMPAGE paLSPages, uint32_t iPage)
{
{
}
}
/**
* Verfies the CRC-32 for a RAM page.
*
* @param pVM The VM handle.
* @param pCur The current RAM range.
* @param paLSPages The current array of live save page tracking
* structures.
* @param iPage The page index.
*/
static void pgmR3StateVerifyCrc32ForRamPage(PVM pVM, PPGMRAMRANGE pCur, PPGMLIVESAVERAMPAGE paLSPages, uint32_t iPage)
{
{
void const *pvPage;
if (RT_SUCCESS(rc))
}
}
#endif /* PGMLIVESAVERAMPAGE_WITH_CRC32 */
/**
* Scan for RAM page modifications and reprotect them.
*
* @param pVM The VM handle.
* @param fFinalPass Whether this is the final pass or not.
*/
{
/*
* The RAM.
*/
do
{
{
&& !PGM_RAM_RANGE_IS_AD_HOC(pCur))
{
GCPhysCur = 0;
{
/* Do yield first. */
if ( !fFinalPass
#ifndef PGMLIVESAVERAMPAGE_WITH_CRC32
#endif
{
break; /* restart */
}
/* Skip already ignored pages. */
continue;
{
/*
* A RAM page.
*/
{
case PGM_PAGE_STATE_ALLOCATED:
/** @todo Optimize this: Don't always re-enable write
* monitoring if the page is known to be very busy. */
{
}
else
{
}
{
}
#endif
break;
{
else
#endif
}
else
{
#endif
{
}
}
break;
case PGM_PAGE_STATE_ZERO:
{
{
}
#endif
}
break;
case PGM_PAGE_STATE_SHARED:
{
{
}
#endif
}
break;
}
}
else
{
/*
* All other types => Ignore the page.
*/
{
/** @todo this doesn't hold water when we start monitoring MMIO2 and ROM shadow
* pages! */
{
}
{
}
}
/** @todo the counting doesn't quite work out here. fix later? */
else
{
}
}
} /* for each page in range */
if (GCPhysCur != 0)
break; /* Yield + ramrange change */
}
} /* for each range */
} while (pCur);
}
/**
* Save quiescent RAM pages.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM The SSM handle.
* @param fLiveSave Whether it's a live save or not.
* @param uPass The pass number.
*/
{
/*
* The RAM.
*/
do
{
{
&& !PGM_RAM_RANGE_IS_AD_HOC(pCur))
{
GCPhysCur = 0;
{
/* Do yield first. */
if ( uPass != SSM_PASS_FINAL
{
break; /* restart */
}
/*
* Only save pages that hasn't changed since last scan and are dirty.
*/
if ( uPass != SSM_PASS_FINAL
&& paLSPages)
{
continue;
continue;
continue;
continue;
continue;
continue;
}
else
{
if ( paLSPages
{
#endif
continue;
}
continue;
}
/*
* Do the saving outside the PGM critsect since SSM may block on I/O.
*/
int rc;
if (!fZero)
{
/*
* Copy the page and then save it outside the lock (since any
* SSM call may block).
*/
void const *pvPage;
if (RT_SUCCESS(rc))
{
if (paLSPages)
#endif
}
else
{
}
}
else
{
/*
* Dirty zero page.
*/
if (paLSPages)
#endif
else
{
}
}
if (RT_FAILURE(rc))
return rc;
GCPhysLast = GCPhys;
if (paLSPages)
{
if (fZero)
}
{
break; /* restart */
}
} /* for each page in range */
if (GCPhysCur != 0)
break; /* Yield + ramrange change */
}
} /* for each range */
} while (pCur);
return VINF_SUCCESS;
}
/**
* Cleans up RAM pages after a live save.
*
* @param pVM The VM handle.
*/
{
/*
* Free the tracking arrays and disable write monitoring.
*
* Play nice with the PGM lock in case we're called while the VM is still
* running. This means we have to delay the freeing since we wish to use
* paLSPages as an indicator of which RAM ranges which we need to scan for
* write monitored pages.
*/
uint32_t cMonitoredPages = 0;
do
{
{
{
if (pvToFree)
{
break; /* start over again. */
}
while (iPage--)
{
{
}
}
}
}
} while (pCur);
else
}
/**
* Execute a live save pass.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pSSM The SSM handle.
*/
{
int rc;
/*
* Save the MMIO2 and ROM range IDs in pass 0.
*/
if (uPass == 0)
{
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
}
/*
* Reset the page-per-second estimate to avoid inflation by the initial
* load of zero pages. pgmR3LiveVote ASSUMES this is done at pass 7.
*/
else if (uPass == 7)
{
}
/*
* Do the scanning.
*/
/*
* Save the pages.
*/
if (uPass == 0)
else
rc = VINF_SUCCESS;
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
return rc;
}
/**
* Votes on whether the live save phase is done or not.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pSSM The SSM handle.
* @param uPass The data pass.
*/
{
/*
* Update and calculate parameters used in the decision making.
*/
/* update history. */
/* calc shortterm average (4 passes). */
/* calc longterm average. */
cTotal = 0;
if (uPass < cHistoryEntries)
for (i = 0; i < cHistoryEntries && i <= uPass; i++)
else
for (i = 0; i < cHistoryEntries; i++)
/* estimate the speed */
/ ((long double)cNsElapsed / 1000000000.0) );
/*
* Try make a decision.
*/
if (cDirtyPagesShort <= cDirtyPagesLong)
{
if (uPass > 10)
{
if (cMsMaxDowntime < 32)
cMsMaxDowntime = 32;
if ( ( cMsLeftLong <= cMsMaxDowntime
&& cMsLeftShort < cMsMaxDowntime)
)
{
Log(("pgmR3LiveVote: VINF_SUCCESS - pass=%d cDirtyPagesShort=%u|%ums cDirtyPagesLong=%u|%ums cMsMaxDowntime=%u\n",
return VINF_SUCCESS;
}
}
else
{
if ( ( cDirtyPagesShort <= 128
&& cDirtyPagesLong <= 1024)
|| cDirtyPagesLong <= 256
)
{
Log(("pgmR3LiveVote: VINF_SUCCESS - pass=%d cDirtyPagesShort=%u cDirtyPagesLong=%u\n", uPass, cDirtyPagesShort, cDirtyPagesLong));
return VINF_SUCCESS;
}
}
}
return VINF_SSM_VOTE_FOR_ANOTHER_PASS;
}
/**
* Prepare for a live save operation.
*
* This will attempt to allocate and initialize the tracking structures. It
* will also prepare for write monitoring of pages and initialize PGM::LiveSave.
* pgmR3SaveDone will do the cleanups.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pSSM The SSM handle.
*/
{
/*
* Indicate that we will be using the write monitoring.
*/
/** @todo find a way of mediating this when more users are added. */
{
}
/*
* Initialize the statistics.
*/
/*
* Per page type.
*/
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
return rc;
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
{
int rc;
unsigned i;
/*
* Lock PGM and set the no-more-writes indicator.
*/
/*
* Save basic data (required / unaffected by relocation).
*/
{
}
/*
* The guest mappings.
*/
i = 0;
{
SSMR3PutU32( pSSM, i);
}
/*
* Save the (remainder of the) memory.
*/
if (RT_SUCCESS(rc))
{
{
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
}
else
{
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
}
}
return rc;
}
/**
* Cleans up after an save state operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
{
/*
* Do per page type cleanups first.
*/
{
}
/*
* Clear the live save indicator and disengage write monitoring.
*/
/** @todo this is blindly assuming that we're the only user of write
* monitoring. Fix this when more users are added. */
return VINF_SUCCESS;
}
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
{
/*
* Call the reset function to make sure all the memory is cleared.
*/
return VINF_SUCCESS;
}
/**
* Load an ignored page.
*
* @returns VBox status code.
* @param pSSM The saved state handle.
*/
{
}
/**
* Loads a page without any bits in the saved state, i.e. making sure it's
* really zero.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param uType The page type or PGMPAGETYPE_INVALID (old saved
* state).
* @param pPage The guest page tracking structure.
* @param GCPhys The page address.
* @param pRam The ram range (logging).
*/
static int pgmR3LoadPageZeroOld(PVM pVM, uint8_t uType, PPGMPAGE pPage, RTGCPHYS GCPhys, PPGMRAMRANGE pRam)
{
&& uType != PGMPAGETYPE_INVALID)
return VERR_SSM_UNEXPECTED_DATA;
/* I think this should be sufficient. */
if (!PGM_PAGE_IS_ZERO(pPage))
return VERR_SSM_UNEXPECTED_DATA;
return VINF_SUCCESS;
}
/**
* Loads a page from the saved state.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pSSM The SSM handle.
* @param uType The page type or PGMPAGETYEP_INVALID (old saved
* state).
* @param pPage The guest page tracking structure.
* @param GCPhys The page address.
* @param pRam The ram range (logging).
*/
static int pgmR3LoadPageBitsOld(PVM pVM, PSSMHANDLE pSSM, uint8_t uType, PPGMPAGE pPage, RTGCPHYS GCPhys, PPGMRAMRANGE pRam)
{
/*
* Match up the type, dealing with MMIO2 aliases (dropped).
*/
|| uType == PGMPAGETYPE_INVALID,
/*
* Load the page.
*/
void *pvPage;
if (RT_SUCCESS(rc))
return rc;
}
/**
* Loads a page (counter part to pgmR3SavePage).
*
* @returns VBox status code, fully bitched errors.
* @param pVM The VM handle.
* @param pSSM The SSM handle.
* @param uType The page type.
* @param pPage The page.
* @param GCPhys The page address.
* @param pRam The RAM range (for error messages).
*/
static int pgmR3LoadPageOld(PVM pVM, PSSMHANDLE pSSM, uint8_t uType, PPGMPAGE pPage, RTGCPHYS GCPhys, PPGMRAMRANGE pRam)
{
AssertLogRelMsgRCReturn(rc, ("pPage=%R[pgmpage] GCPhys=%#x %s rc=%Rrc\n", pPage, GCPhys, pRam->pszDesc, rc), rc);
if (uState == 0 /* zero */)
else if (uState == 1)
else
rc);
return VINF_SUCCESS;
}
/**
* Loads a shadowed ROM page.
*
* @returns VBox status code, errors are fully bitched.
* @param pVM The VM handle.
* @param pSSM The saved state handle.
* @param pPage The page.
* @param GCPhys The page address.
* @param pRam The RAM range (for error messages).
*/
static int pgmR3LoadShadowedRomPageOld(PVM pVM, PSSMHANDLE pSSM, PPGMPAGE pPage, RTGCPHYS GCPhys, PPGMRAMRANGE pRam)
{
/*
* Load and set the protection first, then load the two pages, the first
* one is the active the other is the passive.
*/
AssertLogRelMsgRCReturn(rc, ("pPage=%R[pgmpage] GCPhys=%#x %s\n", pPage, GCPhys, pRam->pszDesc), rc);
&& enmProt < PGMROMPROT_END,
{
}
/** @todo this isn't entirely correct as long as pgmPhysGCPhys2CCPtrInternal is
* used down the line (will the 2nd page will be written to the first
* one because of a false TLB hit since the TLB is using GCPhys and
* doesn't check the HCPhys of the desired page). */
if (RT_SUCCESS(rc))
{
*pPageActive = *pPage;
}
return rc;
}
/**
* Ram range flags and bits for older versions of the saved state.
*
* @returns VBox status code.
*
* @param pVM The VM handle
* @param pSSM The SSM handle.
* @param uVersion The saved state version.
*/
{
/*
* Ram range flags and bits.
*/
uint32_t i = 0;
{
/* Check the seqence number / separator. */
if (RT_FAILURE(rc))
return rc;
if (u32Sep == ~0U)
break;
if (u32Sep != i)
{
}
/* Get the range details. */
if (RT_FAILURE(rc))
return rc;
if (fHaveBits & ~1)
{
}
char szDesc[256];
szDesc[0] = '\0';
{
if (RT_FAILURE(rc))
return rc;
/* Since we've modified the description strings in r45878, only compare
them if the saved state is more recent. */
}
/*
* Match it up with the current range.
*
* Note there is a hack for dealing with the high BIOS mapping
* in the old saved state format, this means we might not have
* a 1:1 match on success.
*/
|| ( cchDesc
/* Hack for PDMDevHlpPhysReserve(pDevIns, 0xfff80000, 0x80000, "High ROM Region"); */
|| !fHaveBits)
)
{
LogRel(("Ram range: %RGp-%RGp %RGp bytes %s %s\n"
"State : %RGp-%RGp %RGp bytes %s %s\n",
/*
* If we're loading a state for debugging purpose, don't make a fuss if
* the MMIO and ROM stuff isn't 100% right, just skip the mismatches.
*/
N_("RAM range mismatch; saved={%RGp-%RGp %RGp bytes %s %s} config={%RGp-%RGp %RGp bytes %s %s}"),
AssertMsgFailed(("debug skipping not implemented, sorry\n"));
continue;
}
{
/*
* Load the pages one by one.
*/
{
AssertLogRelMsgRCReturn(rc, ("pPage=%R[pgmpage] iPage=%#x GCPhysPage=%#x %s\n", pPage, iPage, GCPhysPage, pRam->pszDesc), rc);
if (uType == PGMPAGETYPE_ROM_SHADOW)
else
AssertLogRelMsgRCReturn(rc, ("rc=%Rrc iPage=%#x GCPhysPage=%#x %s\n", rc, iPage, GCPhysPage, pRam->pszDesc), rc);
}
}
else
{
/*
* Old format.
*/
The rest is generally irrelevant and wrong since the stuff have to match registrations. */
{
AssertLogRelMsgRCReturn(rc, ("rc=%Rrc iPage=%#x GCPhys=%#x %s\n", rc, iPage, pRam->GCPhys, pRam->pszDesc), rc);
}
/* Load the bits */
if ( !fHaveBits
{
/*
* Dynamic chunks.
*/
{
AssertLogRelMsgRCReturn(rc, ("rc=%Rrc iPage=%#x GCPhys=%#x %s\n", rc, iPage, pRam->GCPhys, pRam->pszDesc), rc);
{
if (fPresent)
{
else
}
else
AssertLogRelMsgRCReturn(rc, ("rc=%Rrc iPage=%#x GCPhysPage=%#x %s\n", rc, iPage, GCPhysPage, pRam->pszDesc), rc);
}
}
}
{
/*
* MMIO2.
*/
}
{
/*
* PCI MMIO, no pages saved.
*/
}
else
{
/*
* Load the 0xfff80000..0xffffffff BIOS range.
* It starts with X reserved pages that we have to skip over since
* the RAMRANGE create by the new code won't include those.
*/
/* Skip wasted reserved pages before the ROM. */
{
}
/* Load the bios pages. */
{
AssertLogRelMsgRCReturn(rc, ("rc=%Rrc iPage=%#x GCPhys=%#x %s\n", rc, iPage, pRam->GCPhys, pRam->pszDesc), rc);
}
}
}
}
return VINF_SUCCESS;
}
/**
* Worker for pgmR3Load and pgmR3LoadLocked.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pSSM The SSM handle.
* @param uVersion The saved state version.
*
* @todo This needs splitting up if more record types or code twists are
* added...
*/
{
/*
* Process page records until we hit the terminator.
*/
for (;;)
{
/*
* Get the record type and flags.
*/
if (RT_FAILURE(rc))
return rc;
if (u8 == PGM_STATE_REC_END)
return VINF_SUCCESS;
AssertLogRelMsgReturn((u8 & ~PGM_STATE_REC_FLAG_ADDR) <= PGM_STATE_REC_LAST, ("%#x\n", u8), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
switch (u8 & ~PGM_STATE_REC_FLAG_ADDR)
{
/*
* RAM page.
*/
case PGM_STATE_REC_RAM_ZERO:
case PGM_STATE_REC_RAM_RAW:
{
/*
* Get the address and resolve it into a page descriptor.
*/
if (!(u8 & PGM_STATE_REC_FLAG_ADDR))
else
{
if (RT_FAILURE(rc))
return rc;
}
AssertLogRelMsgReturn(!(GCPhys & PAGE_OFFSET_MASK), ("%RGp\n", GCPhys), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
/*
* Take action according to the record type.
*/
switch (u8 & ~PGM_STATE_REC_FLAG_ADDR)
{
case PGM_STATE_REC_RAM_ZERO:
{
if (PGM_PAGE_IS_ZERO(pPage))
break;
/** @todo implement zero page replacing. */
AssertLogRelMsgReturn(PGM_PAGE_GET_STATE(pPage) == PGM_PAGE_STATE_ALLOCATED, ("GCPhys=%RGp %R[pgmpage]\n", GCPhys, pPage), VERR_INTERNAL_ERROR_5);
void *pvDstPage;
break;
}
case PGM_STATE_REC_RAM_RAW:
{
void *pvDstPage;
if (RT_FAILURE(rc))
return rc;
break;
}
default:
}
break;
}
/*
* MMIO2 page.
*/
case PGM_STATE_REC_MMIO2_RAW:
case PGM_STATE_REC_MMIO2_ZERO:
{
/*
* Get the ID + page number and resolved that into a MMIO2 page.
*/
if (!(u8 & PGM_STATE_REC_FLAG_ADDR))
iPage++;
else
{
if (RT_FAILURE(rc))
return rc;
}
if ( !pMmio2
{
break;
}
AssertLogRelMsgReturn(iPage < (pMmio2->RamRange.cb >> PAGE_SHIFT), ("iPage=%#x cb=%RGp %s\n", iPage, pMmio2->RamRange.cb, pMmio2->RamRange.pszDesc), VERR_INTERNAL_ERROR);
/*
* Load the page bits.
*/
else
{
if (RT_FAILURE(rc))
return rc;
}
break;
}
/*
* ROM pages.
*/
case PGM_STATE_REC_ROM_VIRGIN:
case PGM_STATE_REC_ROM_PROT:
{
/*
* Get the ID + page number and resolved that into a ROM page descriptor.
*/
if (!(u8 & PGM_STATE_REC_FLAG_ADDR))
iPage++;
else
{
if (RT_FAILURE(rc))
return rc;
}
if ( !pRom
{
break;
}
AssertLogRelMsgReturn(iPage < (pRom->cb >> PAGE_SHIFT), ("iPage=%#x cb=%RGp %s\n", iPage, pRom->cb, pRom->pszDesc), VERR_INTERNAL_ERROR);
/*
* Get and set the protection.
*/
if (RT_FAILURE(rc))
return rc;
AssertLogRelMsgReturn(enmProt > PGMROMPROT_INVALID && enmProt < PGMROMPROT_END, ("GCPhys=%RGp enmProt=%d\n", GCPhys, enmProt), VERR_INTERNAL_ERROR);
{
N_("Protection change of unshadowed ROM page: GCPhys=%RGp enmProt=%d %s"),
}
break; /* done */
/*
* Get the right page descriptor.
*/
switch (u8 & ~PGM_STATE_REC_FLAG_ADDR)
{
case PGM_STATE_REC_ROM_VIRGIN:
if (!PGMROMPROT_IS_ROM(enmProt))
else
break;
N_("Shadowed / non-shadowed page type mismatch: GCPhys=%RGp enmProt=%d %s"),
if (PGMROMPROT_IS_ROM(enmProt))
else
break;
}
if (!pRealPage)
{
}
/*
* Make it writable and map it (if necessary).
*/
switch (u8 & ~PGM_STATE_REC_FLAG_ADDR)
{
if (PGM_PAGE_IS_ZERO(pRealPage))
break;
/** @todo implement zero page replacing. */
/* fall thru */
case PGM_STATE_REC_ROM_VIRGIN:
{
break;
}
}
/*
* Load the bits.
*/
switch (u8 & ~PGM_STATE_REC_FLAG_ADDR)
{
if (pvDstPage)
break;
case PGM_STATE_REC_ROM_VIRGIN:
if (RT_FAILURE(rc))
return rc;
break;
}
break;
}
/*
* Unknown type.
*/
default:
}
} /* forever */
}
/**
* Worker for pgmR3Load.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pSSM The SSM handle.
* @param uVersion The saved state version.
*/
{
int rc;
/*
* Load basic data (required / unaffected by relocation).
*/
{
{
}
}
else if (uVersion >= PGM_SAVED_STATE_VERSION_RR_DESC)
{
}
else
{
if (RT_FAILURE(rc))
return rc;
/* check separator. */
if (RT_FAILURE(rc))
return rc;
{
}
}
/*
* The guest mappings.
*/
uint32_t i = 0;
for (;; i++)
{
/* Check the seqence number / separator. */
if (RT_FAILURE(rc))
return rc;
if (u32Sep == ~0U)
break;
if (u32Sep != i)
{
}
/* get the mapping details. */
char szDesc[256];
szDesc[0] = '\0';
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
/* find matching range. */
{
break;
#ifdef DEBUG_sandervl
&& HWACCMIsEnabled(pVM))
break;
#endif
}
if (!pMapping)
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Couldn't find mapping: cPTs=%#x szDesc=%s (GCPtr=%RGv)"),
/* relocate it. */
#ifdef DEBUG_sandervl
#endif
)
{
}
else
}
/*
* Load the RAM contents.
*/
{
{
{
if (RT_FAILURE(rc))
return rc;
}
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
}
}
}
/**
* Execute state load operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
* @param uVersion Data layout version.
* @param uPass The data pass.
*/
{
int rc;
/*
* Validate version.
*/
if ( ( uPass != SSM_PASS_FINAL
|| ( uVersion != PGM_SAVED_STATE_VERSION
)
{
AssertMsgFailed(("pgmR3Load: Invalid version uVersion=%d (current %d)!\n", uVersion, PGM_SAVED_STATE_VERSION));
}
/*
* Do the loading while owning the lock because a bunch of the functions
* we're using requires this.
*/
if (uPass != SSM_PASS_FINAL)
{
if (uPass != 0)
else
{
else
rc = VINF_SUCCESS;
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
}
}
else
{
if (RT_SUCCESS(rc))
{
/*
* We require a full resync now.
*/
{
}
{
/*
* Change the paging mode.
*/
/* Restore pVM->pgm.s.GCPhysCR3. */
else
}
}
}
return rc;
}
/**
* Registers the saved state callbacks with SSM.
*
* @returns VBox status code.
* @param pVM Pointer to VM structure.
* @param cbRam The RAM size.
*/
{
}