MMPhys.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
0N/A * MM - Memory Monitor(/Manager) - Physical Memory. 2362N/A * Copyright (C) 2006 InnoTek Systemberatung GmbH 2362N/A * This file is part of VirtualBox Open Source Edition (OSE), as 0N/A * you can redistribute it and/or modify it under the terms of the GNU 0N/A * General Public License as published by the Free Software Foundation, 0N/A * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE 0N/A * distribution. VirtualBox OSE is distributed in the hope that it will 0N/A * be useful, but WITHOUT ANY WARRANTY of any kind. 0N/A * If you received this file as part of a commercial VirtualBox 0N/A * distribution, then only the terms of your commercial VirtualBox 0N/A * license agreement apply instead of the previous paragraph. 2362N/A/******************************************************************************* 0N/A*******************************************************************************/ 0N/A * Register externally allocated RAM for the virtual machine. 0N/A * The memory registered with the VM thru this interface must not be freed 0N/A * before the virtual machine has been destroyed. Bad things may happen... :-) 0N/A * @return VBox status code. 0N/A * @param pVM VM handle. 0N/A * @param pvRam Virtual address of the guest's physical memory range Must be page aligned. 0N/A * @param GCPhys The physical address the ram shall be registered at. 0N/A * @param cb Size of the memory. Must be page aligend. 0N/A * @param fFlags Flags of the MM_RAM_FLAGS_* defines. 0N/A * @param pszDesc Description of the memory. 0N/A * Register externally allocated RAM for the virtual machine. 0N/A * The memory registered with the VM thru this interface must not be freed 0N/A * before the virtual machine has been destroyed. Bad things may happen... :-) 0N/A * @return VBox status code. 0N/A * @param pVM VM handle. 0N/A * @param pvRam Virtual address of the guest's physical memory range Must be page aligned. 0N/A * @param GCPhys The physical address the ram shall be registered at. 0N/A * @param cb Size of the memory. Must be page aligend. 0N/A * @param fFlags Flags of the MM_RAM_FLAGS_* defines. 0N/A * @param enmType Physical range type (MM_PHYS_TYPE_*) 0N/A * @param pszDesc Description of the memory. 0N/A * @thread The Emulation Thread. 0N/A/** @todo this function description is not longer up-to-date */ 0N/A * Check for conflicts. 0N/A * We do not support overlapping physical memory regions yet, 0N/A * even if that's what the MM_RAM_FLAGS_MMIO2 flags is trying to 0N/A * tell us to do. Provided that all MMIO2 addresses are very high 0N/A * there is no real danger we'll be able to assign so much memory 0N/A * for a guest that it'll ever be a problem. 0N/A (
"MMIO2 addresses should be above 3GB for avoiding conflicts with real RAM.\n"));
0N/A * Register the ram with PGM. 0N/A * Lock the memory. (fully allocated by caller) 0N/A * We set any page flags specified. 0N/A * Register the ram with PGM. /* Cleanup is done in VM destruction to which failure of this function will lead. */ * Relocate previously registered externally allocated RAM for the virtual machine. * Use this only for MMIO ranges or the guest will become very confused. * The memory registered with the VM thru this interface must not be freed * before the virtual machine has been destroyed. Bad things may happen... :-) * @return VBox status code. * @param GCPhysOld The physical address the ram was registered at. * @param GCPhysNew The physical address the ram shall be registered at. * @param cb Size of the memory. Must be page aligend. * Find the old memory region. * Region is already locked, just need to change GC address. /** @todo r=bird: check for conflicts? */ * Relocate the registered RAM range with PGM. /* Somewhat hackish way to relocate the region with REM. There * is unfortunately no official way to unregister anything with * REM, as there is no way to unregister memory with QEMU. * This implementation seems to work, but is not very pretty. */ /// @todo one day provide a proper MMIO relocation operation * Register a ROM (BIOS) region. * It goes without saying that this is read-only memory. The memory region must be * in unassigned memory. I.e. from the top of the address space or on the PC in * the 0xa0000-0xfffff range. * @param pDevIns The device instance owning the ROM region. * @param GCPhys First physical address in the range. * @param cbRange The size of the range (in bytes). * @param pvBinary Pointer to the binary data backing the ROM image. * This must be cbRange bytes big. * It will be copied and doesn't have to stick around. * @param pszDesc Pointer to description string. This must not be freed. * @remark There is no way to remove the rom, automatically on device cleanup or * manually from the device yet. At present I doubt we need such features... * Check if this can fit in an existing range. * We do not handle the case where a new chunk of locked memory is * required to accommodate the ROM since we assume MMR3PhysReserve() * have been called to reserve the memory first. * To make things even simpler, the pages in question must be AssertMsgFailed((
"The ROM range (%#VGp LB%#x) was crossing the end of the physical range (%#VGp LB%#x)\n",
/* flags must be all reserved. */ * Copy the ram and update the flags. /** @note we rely on the MM_RAM_FLAGS_ROM flag in PGMPhysRead now. Don't change to reserved! */ /** @todo r=bird: Noone ever talked about changing *to* _RESERVED. The question is whether * we should *clear* _RESERVED. I've no idea what the state of that flag is for ROM areas right * now, but I will find out later. */ * Prevent changes to the ROM memory when executing in raw mode by * registering a GC only write access handler. * ASSUMES that REMR3NotifyPhysRomRegister doesn't call cpu_register_physical_memory * when there is no HC handler. The result would probably be immediate boot failure. NULL,
"pgmGuestROMWriteHandler", 0,
NULL,
"pgmGuestROMWriteHandler", 0,
"ROM Write Access Handler");
return rc;
/* we're sloppy with error cleanup here, but we're toast anyway if this fails. */ * Reserve physical address space for ROM and MMIO ranges. * @returns VBox status code. * @param GCPhys Start physical address. * @param cbRange The size of the range. * @param pszDesc Description string. * Do we have an existing physical address range for the request? * No range, we'll just allocate backing pages and register * them as reserved using the Ram interface. AssertMsgFailed((
"The reserved range (%#VGp LB%#x) was crossing the end of the physical range (%#VGp LB%#x)\n",
* Get the size of the base RAM. * This usually means the size of the first contigous block of physical memory.