OpenCore
1.0.4
OpenCore Bootloader
|
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/MtrrLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcMemoryLib.h>
#include <Register/Intel/Cpuid.h>
Go to the source code of this file.
Functions | |
CHAR8 * | OcGetMtrrTypeString (UINT8 MtrrType) |
CHAR8 * | OcGetPatTypeString (UINT8 PatType) |
BOOLEAN | OcIsPatSupported (VOID) |
PAGE_MAP_AND_DIRECTORY_POINTER * | OcGetCurrentPageTable (OUT UINTN *Flags OPTIONAL) |
STATIC BOOLEAN | DisablePageTableWriteProtection (VOID) |
STATIC VOID | EnablePageTableWriteProtection (VOID) |
EFI_STATUS | OcGetPhysicalAddress (IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, OUT EFI_PHYSICAL_ADDRESS *PhysicalAddr) |
EFI_STATUS | OcSetPatIndexForAddressRange (IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, IN UINT64 Length, IN PAT_INDEX *PatIndex) |
EFI_STATUS | OcGetSetPageTableInfoForAddress (IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, OUT EFI_PHYSICAL_ADDRESS *PhysicalAddr OPTIONAL, OUT UINT8 *Level OPTIONAL, OUT UINT64 *Bits OPTIONAL, IN OUT PAT_INDEX *PatIndex OPTIONAL, IN BOOLEAN SetPat) |
EFI_STATUS | OcModifyMtrrRange (IN EFI_PHYSICAL_ADDRESS Address, IN UINT8 MtrrType, OUT UINT64 *Length OPTIONAL) |
EFI_STATUS | VmAllocateMemoryPool (OUT OC_VMEM_CONTEXT *Context, IN UINTN NumPages, IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL) |
VOID * | VmAllocatePages (IN OUT OC_VMEM_CONTEXT *Context, IN UINTN NumPages) |
EFI_STATUS | VmMapVirtualPage (IN OUT OC_VMEM_CONTEXT *Context, IN OUT PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, IN EFI_PHYSICAL_ADDRESS PhysicalAddr) |
EFI_STATUS | VmMapVirtualPages (IN OUT OC_VMEM_CONTEXT *Context, IN OUT PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, IN UINT64 NumPages, IN EFI_PHYSICAL_ADDRESS PhysicalAddr) |
VOID | VmFlushCaches (VOID) |
Variables | |
STATIC CHAR8 * | MtrrTypeStrings [] |
STATIC CHAR8 * | PatTypeStrings [] |
Copyright (C) 2011, dmazar. All rights reserved. Copyright (C) 2019, vit9696. All rights reserved.
All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Definition in file VirtualMemory.c.
STATIC BOOLEAN DisablePageTableWriteProtection | ( | VOID | ) |
Definition at line 117 of file VirtualMemory.c.
STATIC VOID EnablePageTableWriteProtection | ( | VOID | ) |
Definition at line 135 of file VirtualMemory.c.
PAGE_MAP_AND_DIRECTORY_POINTER * OcGetCurrentPageTable | ( | OUT UINTN *Flags | OPTIONAL | ) |
Return pointer to PML4 table in PageTable and PWT and PCD flags in Flags.
[out] | Flags | Current page table PWT and PCT flags. |
Current | page table address. |
Definition at line 97 of file VirtualMemory.c.
CHAR8 * OcGetMtrrTypeString | ( | UINT8 | MtrrType | ) |
Return short string representation of MTRR cache type, as used in Intel tables.
[in] | MtrrType | MTRR type. |
String | representation. |
Definition at line 58 of file VirtualMemory.c.
CHAR8 * OcGetPatTypeString | ( | UINT8 | PatType | ) |
Return short string representation of PAT cache type, as used in Intel tables.
[in] | PatType | PAT type. |
String | representation. |
Definition at line 70 of file VirtualMemory.c.
EFI_STATUS OcGetPhysicalAddress | ( | IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable | OPTIONAL, |
IN EFI_VIRTUAL_ADDRESS | VirtualAddr, | ||
OUT EFI_PHYSICAL_ADDRESS * | PhysicalAddr ) |
Return physical address for given virtual address.
[in] | PageTable | Page table to use for solving. |
[in] | VirtualAddr | Virtual address to look up. |
[out] | PhysicalAddr | Physical address to return. |
EFI_SUCCESS | on successful lookup. |
Definition at line 146 of file VirtualMemory.c.
EFI_STATUS OcGetSetPageTableInfoForAddress | ( | IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable | OPTIONAL, |
IN EFI_VIRTUAL_ADDRESS | VirtualAddr, | ||
OUT EFI_PHYSICAL_ADDRESS *PhysicalAddr | OPTIONAL, | ||
OUT UINT8 *Level | OPTIONAL, | ||
OUT UINT64 *Bits | OPTIONAL, | ||
IN OUT PAT_INDEX *PatIndex | OPTIONAL, | ||
IN BOOLEAN | SetPat ) |
Get page table info for a given virtual address. Includes option to get or set Page Attribute Table (PAT) index for caching type.
[in] | PageTable | Page table to use for solving, and modify iff SetPat==TRUE. |
[in] | VirtualAddr | Virtual address to look up. |
[out] | PhysicalAddr | Physical address to return. |
[out] | Level | Page table mapping level, 1, 2 or 4 for 1Gb, 2Mb or 4kb. |
[out] | Bits | Page table mapping flag bits. |
[in,out] | PatIndex | PAT index to get or set. |
[in] | SetPat | If TRUE then set PatIndex if present, else get. |
EFI_SUCCESS | on success. |
Definition at line 221 of file VirtualMemory.c.
BOOLEAN OcIsPatSupported | ( | VOID | ) |
Checks if PAT is supported.
TRUE | PAT is supported. |
FALSE | PAT is not supported. |
Definition at line 82 of file VirtualMemory.c.
EFI_STATUS OcModifyMtrrRange | ( | IN EFI_PHYSICAL_ADDRESS | Address, |
IN UINT8 | MtrrType, | ||
OUT UINT64 *Length | OPTIONAL ) |
Attempt to set entire MTRR range which starts with address to new MTRR cache type. Use with caution - attempting to change cache-type on the fly of any region used for code or data is likely to hang. Works successfully to uncache GOP (i.e. WC->UC), producing visibly slower results, on newer firmware where GOP range is set to WC in the first place.
[in] | Address | Start of range. |
[in] | MtrrType | MTRR cache type to assign. |
[out] | Length | Length of range converted or attempted to be converted, when non-zero. |
EFI_SUCCESS | if cache type is set and system is still running. |
EFI_UNSUPPORTED | if MTRR is unsupported. |
error | - other error from methods called. |
Definition at line 410 of file VirtualMemory.c.
EFI_STATUS OcSetPatIndexForAddressRange | ( | IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable | OPTIONAL, |
IN EFI_VIRTUAL_ADDRESS | VirtualAddr, | ||
IN UINT64 | Length, | ||
IN PAT_INDEX * | PatIndex ) |
Set Page Attribute Table (PAT) index for an address range. Assumes UEFI identity mapping between physical and virtual addresses.
[in] | PageTable | Page table to use and modify. |
[in] | VirtualAddr | Address range start. |
[in] | Length | Address range length. |
[in] | PatIndex | PAT index to set. |
EFI_SUCCESS | on success. |
EFI_INVALID_PARAMETER | on invalid memory range. |
error | - other error from called methods. |
Definition at line 164 of file VirtualMemory.c.
EFI_STATUS VmAllocateMemoryPool | ( | OUT OC_VMEM_CONTEXT * | Context, |
IN UINTN | NumPages, | ||
IN EFI_GET_MEMORY_MAP GetMemoryMap | OPTIONAL ) |
Allocate EfiBootServicesData virtual memory pool from boot services in the end of BASE_4GB of RAM. Should be called while boot services are still usable.
[out] | Context | Virtual memory pool context. |
[in] | NumPages | Number of pages to be allocated in the pool. |
[in] | GetMemoryMap | Custom GetMemoryMap implementation to use, optional. |
EFI_SUCCESS | on successful allocation. |
Definition at line 441 of file VirtualMemory.c.
VOID * VmAllocatePages | ( | IN OUT OC_VMEM_CONTEXT * | Context, |
IN UINTN | NumPages ) |
Allocate pages for e.g. vm page maps.
[in,out] | Context | Virtual memory pool context. |
[in] | NumPages | Number of pages to allocate. |
allocated | pages or NULL. |
Definition at line 469 of file VirtualMemory.c.
VOID VmFlushCaches | ( | VOID | ) |
Flushes TLB caches.
Definition at line 726 of file VirtualMemory.c.
EFI_STATUS VmMapVirtualPage | ( | IN OUT OC_VMEM_CONTEXT * | Context, |
IN OUT PAGE_MAP_AND_DIRECTORY_POINTER *PageTable | OPTIONAL, | ||
IN EFI_VIRTUAL_ADDRESS | VirtualAddr, | ||
IN EFI_PHYSICAL_ADDRESS | PhysicalAddr ) |
Map (remap) given page at physical address to given virtual address in the specified page table.
[in,out] | Context | Virtual memory pool context. |
[in] | PageTable | Page table to update. |
[in] | VirtualAddr | Virtual memory address to map at. |
[in] | PhysicalAddr | Physical memory address to map from. |
EFI_SUCCESS | on success. |
Definition at line 488 of file VirtualMemory.c.
EFI_STATUS VmMapVirtualPages | ( | IN OUT OC_VMEM_CONTEXT * | Context, |
IN OUT PAGE_MAP_AND_DIRECTORY_POINTER *PageTable | OPTIONAL, | ||
IN EFI_VIRTUAL_ADDRESS | VirtualAddr, | ||
IN UINT64 | NumPages, | ||
IN EFI_PHYSICAL_ADDRESS | PhysicalAddr ) |
Map (remap) a range of 4K pages at physical address to given virtual address in the specified page table.
[in,out] | Context | Virtual memory pool context. |
[in] | PageTable | Page table to update. |
[in] | VirtualAddr | Virtual memory address to map at. |
[in] | NumPages | Number of 4K pages to map. |
[in] | PhysicalAddr | Physical memory address to map from. |
EFI_SUCCESS | on success. |
Definition at line 693 of file VirtualMemory.c.
STATIC CHAR8* MtrrTypeStrings[] |
Definition at line 31 of file VirtualMemory.c.
STATIC CHAR8* PatTypeStrings[] |
Definition at line 46 of file VirtualMemory.c.