PGMSavedState.cpp revision 56487a6406822c7d8dba63b58474e4a413830f84
/* $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 for 2.5.x and later. */
#define PGM_SAVED_STATE_VERSION 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
/*******************************************************************************
* 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.
*/
{
{
}
return NULL;
}
/**
* Save zero indicator + bits for the specified page.
*
* @param pVM The VM handle.
* @param pSSH The saved state handle.
* @param pPage The page to save.
* @param GCPhys The address of the page.
* @param pRam The ram range (for error logging).
*/
static int pgmR3SavePage(PVM pVM, PSSMHANDLE pSSM, PPGMPAGE pPage, RTGCPHYS GCPhys, PPGMRAMRANGE pRam)
{
int rc;
if (PGM_PAGE_IS_ZERO(pPage))
else
{
void const *pvPage;
AssertLogRelMsgRCReturn(rc, ("pPage=%R[pgmpage] GCPhys=%#x %s\n", pPage, GCPhys, pRam->pszDesc), rc);
}
return rc;
}
/**
* Save a shadowed ROM page.
*
* Format: Type, protection, and two pages with zero indicators.
*
* @param pVM The VM handle.
* @param pSSH The saved state handle.
* @param pPage The page to save.
* @param GCPhys The address of the page.
* @param pRam The ram range (for error logging).
*/
static int pgmR3SaveShadowedRomPage(PVM pVM, PSSMHANDLE pSSM, PPGMPAGE pPage, RTGCPHYS GCPhys, PPGMRAMRANGE pRam)
{
/* Need to save both pages and the current state. */
if (RT_SUCCESS(rc))
{
PPGMPAGE pPagePassive = PGMROMPROT_IS_ROM(pRomPage->enmProt) ? &pRomPage->Shadow : &pRomPage->Virgin;
}
return rc;
}
/**
* 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.
*/
/*
* 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))
{
PPGMLIVESAVEPAGE paLSPages = (PPGMLIVESAVEPAGE)MMR3HeapAllocZ(pVM, MM_TAG_PGM, cPages * sizeof(PGMLIVESAVEPAGE));
if (!paLSPages)
return VERR_NO_MEMORY;
{
break; /* try again */
}
/*
* Initialize the array.
*/
while (iPage-- > 0)
{
switch (PGM_PAGE_GET_TYPE(pPage))
{
case PGMPAGETYPE_RAM:
case PGMPAGETYPE_ROM_SHADOW:
case PGMPAGETYPE_ROM:
if (PGM_PAGE_IS_ZERO(pPage))
{
}
else
{
}
break;
default:
case PGMPAGETYPE_MMIO2:
break;
case PGMPAGETYPE_MMIO:
break;
}
}
}
}
} while (pCur);
return VINF_SUCCESS;
}
/**
* Execute a live save pass.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pSSM The SSM handle.
*/
{
return VINF_SUCCESS;
}
/**
* 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.
*/
{
return VINF_SUCCESS;
}
/**
* 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);
}
/*
* Ram ranges and the memory they describe.
*/
i = 0;
{
/*
* Save the ram range details.
*/
SSMR3PutU32(pSSM, i);
/*
* Iterate the pages, only two special case.
*/
{
if (uType == PGMPAGETYPE_ROM_SHADOW)
else if (uType == PGMPAGETYPE_MMIO2_ALIAS_MMIO)
{
/* MMIO2 alias -> MMIO; the device will just have to deal with this. */
}
else
{
}
if (RT_FAILURE(rc))
break;
}
if (RT_FAILURE(rc))
break;
}
}
/**
* Cleans up after an save state operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation 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);
/** @todo this is blindly assuming that we're the only user of write
* monitoring. Fix this when more users are added. */
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 pgmR3LoadPageZero(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 pgmR3LoadPageBits(PVM pVM, PSSMHANDLE pSSM, uint8_t uType, PPGMPAGE pPage, RTGCPHYS GCPhys, PPGMRAMRANGE pRam)
{
int rc;
/*
* 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 pgmR3LoadPage(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 pgmR3LoadShadowedRomPage(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,
{
}
if (RT_SUCCESS(rc))
{
*pPageActive = *pPage;
}
return rc;
}
/**
* 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).
*/
if (uVersion >= PGM_SAVED_STATE_VERSION)
{
{
}
}
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;
/* relocate it. */
{
}
else
}
/*
* Ram range flags and bits.
*/
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.
*/
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 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 ( uVersion != PGM_SAVED_STATE_VERSION
{
AssertMsgFailed(("pgmR3Load: Invalid version uVersion=%d (current %d)!\n", uVersion, PGM_SAVED_STATE_VERSION));
}
/*
* Call the reset function to make sure all the memory is cleared.
*/
/*
* Do the loading while owning the lock because a bunch of the functions
* we're using requires this.
*/
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.
*/
{
}