// // Unmap the page at the provided virtual address and release its // underlying physical page // internal static void UnmapAndReleasePage(UIntPtr virtualAddr) { DebugStub.Assert(VMManager.IsPageMapped(virtualAddr), "Trying to unmap an unmapped page"); PhysicalAddress phys = VMManager.UnmapPage(virtualAddr); DebugStub.Assert(phys != PhysicalAddress.Null); PhysicalPages.FreePage(phys); }
// // Get a new physical page and map it to the provided virtual address // private static bool CommitAndMapNewPage(UIntPtr virtualAddr, ProtectionDomain inDomain) { DebugStub.Assert(IsPageAligned(virtualAddr)); PhysicalAddress newPage = PhysicalPages.AllocPage(); if (newPage == PhysicalAddress.Null) { // Failed. return(false); } VMManager.MapPage(newPage, virtualAddr, inDomain); return(true); }
public static ulong GetMaxPhysicalMemory() { return(useAddressTranslation ? PhysicalPages.GetMaxMemory() : (ulong)FlatPages.GetMaxMemory()); }
///////////////////////////////////// // PUBLIC METHODS ///////////////////////////////////// internal static void Initialize() { DebugStub.WriteLine("Initializing memory subsystem..."); // Only allow paging in HALs which support running in Ring 0 // but always force paging in the HIP builds for compatibility #if !PAGING useAddressTranslation = UseAddressTranslationInCmdLine(); #else useAddressTranslation = true; #endif if (useAddressTranslation) { DebugStub.WriteLine("Using address translation...\n"); Platform p = Platform.ThePlatform; // Set up the hardware-pages table and reserve a range for // I/O memory IOMemoryBaseAddr = PhysicalPages.Initialize(Platform.IO_MEMORY_SIZE); // Set up the I/O memory heap KernelIOMemoryHeap = new PhysicalHeap((UIntPtr)IOMemoryBaseAddr.Value, (UIntPtr)(IOMemoryBaseAddr.Value + Platform.IO_MEMORY_SIZE)); // Set up virtual memory. ** This enables paging ** ! VMManager.Initialize(); // Set up the kernel's memory ranges. // // The kernel's general-purpose range is special because // it *describes* low memory as well as the GC range proper // so the kernel's GC doesn't get confused by pointers to // static data in the kernel image. KernelRange = new VirtualMemoryRange_struct( VMManager.KernelHeapBase, VMManager.KernelHeapLimit, UIntPtr.Zero, VMManager.KernelHeapLimit, null); // no concurrent access to page descriptors yet // Mark the kernel's special areas. First, record the kernel memory. if (p.KernelDllSize != 0) { UIntPtr kernelDllLimit = p.KernelDllBase + p.KernelDllSize; KernelRange.SetRange(p.KernelDllBase, kernelDllLimit, MemoryManager.KernelPageNonGC); } // Record the boot allocated kernel memory. if (p.BootAllocatedMemorySize != 0) { UIntPtr bootAllocatedMemoryLimit = p.BootAllocatedMemory + p.BootAllocatedMemorySize; KernelRange.SetRange(p.BootAllocatedMemory, bootAllocatedMemoryLimit, MemoryManager.KernelPageNonGC); } // Set stack page for CPU 0 KernelRange.SetRange(Platform.BootCpu.KernelStackLimit, (Platform.BootCpu.KernelStackBegin - Platform.BootCpu.KernelStackLimit), MemoryManager.KernelPageStack); DebugStub.WriteLine("MemoryManager initialized with {0} physical pages still free", __arglist(PhysicalPages.GetFreePageCount())); KernelRange.Dump("Initialized"); isInitialized = true; } else { FlatPages.Initialize(); DebugStub.WriteLine("KernelBaseAddr: {0:x8} KernelLimitAddr {1:x8}", __arglist(KernelBaseAddr, KernelBaseAddr + BytesFromPages(KernelPageCount))); } }