14#define PTE_BASE 0xC0000000
19#define MiAddressToPte(x) ((PMMPTE)(((((ULONG)(x)) >> 12) << 2) + (ULONG_PTR)MmPteBase))
20#define MiAddressToPde(x) ((PMMPDE)(((((ULONG)(x)) >> 22) << 2) + (ULONG_PTR)MmPdeBase))
21#define MiAddressToPteOffset(x) ((((ULONG)(x)) << 10) >> 22)
22#define MiAddressToPdeOffset(x) (((ULONG)(x)) / (1024 * PAGE_SIZE))
206 ULONG i, PageCount, PdeOffset;
222 for (
i = 0;
i < PageCount;
i++)
419 EfiPrintf(
L"Cache checking not yet enabled\r\n");
439 ULONG_PTR CurrentAddress, VirtualAddressEnd;
443 if (!(PhysicalAddressPtr) || !(VirtualAddressPtr) || !(SizePtr))
450 if (
Size > 0xFFFFFFFF)
485 VirtualAddressEnd = CurrentAddress +
Size - 1;
486 while (CurrentAddress < VirtualAddressEnd)
499 EfiPrintf(
L"Existing mapping exists: %lx vs %lx\r\n",
591 MaxCount = 0xFFFFFFFF;
595 NextEntry = DescriptorList->First->
Flink;
596 while ((NextEntry != DescriptorList->First) && (MaxCount--))
617 EfiPrintf(
L"%p - [%08llx-%08llx @ %08llx-%08llx]:%x\r\n",
622 VirtualEndPage ? (VirtualEndPage <<
PAGE_SHIFT) - 1 : 0,
626 NextEntry = NextEntry->
Flink;
637 ULONG DescriptorCount;
672 FinalOffset = MemoryData->MdListOffset + MemoryData->DescriptorOffset;
677 DescriptorCount = MemoryData->DescriptorCount;
678 while (DescriptorCount != 0)
736 Head = FirmwareMdl.
First;
737 NextEntry = Head->
Flink;
738 while (NextEntry != Head)
760 NextEntry = NextEntry->
Flink;
764 NextEntry = Head->
Flink;
765 while (NextEntry != Head)
771 NextEntry = NextEntry->
Flink;
878 EfiPrintf(
L"Virtual->Virtual not yet supported\r\n");
881 else if (TranslationType !=
BlNone)
951 EfiPrintf(
L"PDPT at 0x%p Reference Page at 0x%p Self-map at 0x%p\r\n",
1036 ULONGLONG IncreaseUserVa, PerfCounter, CpuRandom;
1046 switch (RequestedTranslationType)
1096 if (CpuInfo.
Ecx & 0x40000000)
1098 EfiPrintf(
L"Your CPU can do RDRAND! Good for you!\r\n");
@ BcdOSLoaderInteger_IncreaseUserVa
NTSTATUS MmMdFreeDescriptor(_In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor)
NTSTATUS MmPapAllocatePhysicalPagesInRange(_Inout_ PPHYSICAL_ADDRESS BaseAddress, _In_ BL_MEMORY_TYPE MemoryType, _In_ ULONGLONG Pages, _In_ ULONG Attributes, _In_ ULONG Alignment, _In_ PBL_MEMORY_DESCRIPTOR_LIST NewList, _In_opt_ PBL_ADDRESS_RANGE Range, _In_ ULONG RangeType)
VOID BlpArchEnableTranslation(VOID)
VOID BlArchCpuId(_In_ ULONG Function, _In_ ULONG SubFunction, _Out_ PCPU_INFO Result)
VOID EfiPrintf(_In_ PWCHAR Format,...)
FORCEINLINE VOID MmMdInitializeListHead(_In_ PBL_MEMORY_DESCRIPTOR_LIST List)
NTSTATUS MmPaReserveSelfMapPages(_Inout_ PPHYSICAL_ADDRESS PhysicalAddress, _In_ ULONG Alignment, _In_ ULONG PageCount)
#define BL_MM_FLAG_REQUEST_COALESCING
#define BL_MM_INCLUDE_TRUNCATED_MEMORY
BOOLEAN(* PBL_MM_TRANSLATE_VIRTUAL_ADDRESS)(_In_ PVOID VirtualAddress, _Out_ PPHYSICAL_ADDRESS PhysicalAddress, _Out_opt_ PULONG CacheAttributes)
VOID(* PBL_MM_RELOCATE_SELF_MAP)(VOID)
struct _BL_MEMORY_DESCRIPTOR * PBL_MEMORY_DESCRIPTOR
BL_TRANSLATION_TYPE MmTranslationType
VOID MmMdRemoveDescriptorFromList(_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList, _In_ PBL_MEMORY_DESCRIPTOR Entry)
BOOLEAN BlArchIsCpuIdFunctionSupported(_In_ ULONG Function)
NTSTATUS BlMmFreePhysicalPages(_In_ PHYSICAL_ADDRESS Address)
BL_MEMORY_DESCRIPTOR_LIST MmMdlUnmappedAllocated
NTSTATUS MmPaReleaseSelfMapPages(_In_ PHYSICAL_ADDRESS Address)
NTSTATUS(* PBL_MM_REMAP_VIRTUAL_ADDRESS)(_In_ PPHYSICAL_ADDRESS PhysicalAddress, _Out_ PVOID VirtualAddress, _In_ ULONG Size, _In_ ULONG CacheAttributes)
NTSTATUS MmPaTruncateMemory(_In_ ULONGLONG BasePage)
NTSTATUS(* PBL_MM_UNMAP_VIRTUAL_ADDRESS)(_In_ PVOID VirtualAddress, _In_ ULONG Size)
#define BL_MM_REMOVE_PHYSICAL_REGION_FLAG
enum _BL_TRANSLATION_TYPE BL_TRANSLATION_TYPE
NTSTATUS(* PBL_MM_MOVE_VIRTUAL_ADDRESS_RANGE)(_In_ PVOID DestinationAddress, _In_ PVOID SourceAddress, _In_ ULONGLONG Size)
NTSTATUS EfiStall(_In_ ULONG StallTime)
PBL_ARCH_CONTEXT CurrentExecutionContext
ULONGLONG BlArchGetPerformanceCounter(VOID)
BL_MEMORY_DESCRIPTOR_LIST MmMdlFreeVirtual
VOID(* PBL_MM_DESTROY_SELF_MAP)(VOID)
NTSTATUS MmMdRemoveRegionFromMdlEx(__in PBL_MEMORY_DESCRIPTOR_LIST MdList, __in ULONG Flags, __in ULONGLONG BasePage, __in ULONGLONG PageCount, __in PBL_MEMORY_DESCRIPTOR_LIST NewMdList)
NTSTATUS MmUnmapVirtualAddress(_Inout_ PVOID *VirtualAddress, _Inout_ PULONGLONG Size)
NTSTATUS BlGetApplicationBaseAndSize(_Out_ PVOID *ImageBase, _Out_ PULONG ImageSize)
NTSTATUS(* PBL_MM_ZERO_VIRTUAL_ADDRESS_RANGE)(_In_ PVOID DestinationAddress, _In_ ULONGLONG Size)
BL_LOADED_APPLICATION_ENTRY BlpApplicationEntry
#define BL_MM_INCLUDE_NO_FIRMWARE_MEMORY
#define BL_CONTEXT_PAGING_ON
NTSTATUS MmFwGetMemoryMap(_Out_ PBL_MEMORY_DESCRIPTOR_LIST MemoryMap, _In_ ULONG Flags)
NTSTATUS BlGetBootOptionInteger(_In_ PBL_BCD_OPTION List, _In_ ULONG Type, _Out_ PULONGLONG Value)
VOID(* PBL_MM_FLUSH_TLB_ENTRY)(_In_ PVOID VirtualAddress)
VOID(* PBL_MM_FLUSH_TLB)(VOID)
NTSTATUS(* PBL_MM_MAP_PHYSICAL_ADDRESS)(_In_ PHYSICAL_ADDRESS PhysicalAddress, _Out_ PVOID VirtualAddress, _In_ ULONG Size, _In_ ULONG CacheAttributes)
PBL_MEMORY_DESCRIPTOR MmMdFindDescriptor(_In_ ULONG WhichList, _In_ ULONG Flags, _In_ ULONGLONG Page)
#define BL_MM_REMOVE_VIRTUAL_REGION_FLAG
#define STATUS_NOT_SUPPORTED
#define STATUS_NOT_IMPLEMENTED
#define NT_SUCCESS(StatCode)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_Check_return_ unsigned short __cdecl _rotl16(_In_ unsigned short _Value, _In_ unsigned char _Shift)
__INTRIN_INLINE void _sgdt(void *Destination)
__INTRIN_INLINE unsigned long __readcr3(void)
__INTRIN_INLINE void __invlpg(void *Address)
__INTRIN_INLINE void __writecr3(unsigned int Data)
__INTRIN_INLINE void __sidt(void *Destination)
NTSTATUS MmDefZeroVirtualAddressRange(_In_ PVOID DestinationAddress, _In_ ULONGLONG Size)
VOID MmDefpFlushTlbEntry(_In_ PVOID VirtualAddress)
#define MiAddressToPte(x)
ULONG_PTR MmArchTopOfApplicationAddressSpace
#define MiAddressToPteOffset(x)
VOID MmArchNullFunction(VOID)
NTSTATUS MmMapPhysicalAddress(_Inout_ PPHYSICAL_ADDRESS PhysicalAddressPtr, _Inout_ PVOID *VirtualAddressPtr, _Inout_ PULONGLONG SizePtr, _In_ ULONG CacheAttributes)
VOID MmDefpDestroySelfMap(VOID)
VOID MmMdDbgDumpList(_In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList, _In_opt_ ULONG MaxCount)
VOID MmDefRelocateSelfMap(VOID)
PBL_MM_MAP_PHYSICAL_ADDRESS Mmx86MapPhysicalAddress
VOID MmDefpFlushTlb(VOID)
PULONG MmArchReferencePage
PBL_MM_RELOCATE_SELF_MAP BlMmRelocateSelfMap
PBL_MM_MOVE_VIRTUAL_ADDRESS_RANGE BlMmMoveVirtualAddressRange
NTSTATUS Mmx86pMapMemoryRegions(_In_ ULONG Phase, _In_ PBL_MEMORY_DATA MemoryData)
BL_ADDRESS_RANGE MmArchKsegAddressRange
BOOLEAN MmArchTranslateVirtualAddress(_In_ PVOID VirtualAddress, _Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress, _Out_opt_ PULONG CachingFlags)
NTSTATUS Mmx86MapInitStructure(_In_ PVOID VirtualAddress, _In_ ULONGLONG Size, _In_ PHYSICAL_ADDRESS PhysicalAddress)
ULONG MmDeferredMappingCount
NTSTATUS MmDefpUnmapVirtualAddress(_In_ PVOID VirtualAddress, _In_ ULONG Size)
PBL_MM_FLUSH_TLB BlMmFlushTlb
PBL_MM_REMAP_VIRTUAL_ADDRESS Mmx86RemapVirtualAddress
NTSTATUS MmDefMoveVirtualAddressRange(_In_ PVOID DestinationAddress, _In_ PVOID SourceAddress, _In_ ULONGLONG Size)
NTSTATUS MmDefInitializeTranslation(_In_ PBL_MEMORY_DATA MemoryData, _In_ BL_TRANSLATION_TYPE TranslationType)
NTSTATUS MmArchInitialize(_In_ ULONG Phase, _In_ PBL_MEMORY_DATA MemoryData, _In_ BL_TRANSLATION_TYPE TranslationType, _In_ BL_TRANSLATION_TYPE RequestedTranslationType)
NTSTATUS MmDefpRemapVirtualAddress(_In_ PPHYSICAL_ADDRESS PhysicalAddress, _Out_ PVOID VirtualAddress, _In_ ULONG Size, _In_ ULONG CacheAttributes)
#define MiAddressToPdeOffset(x)
PBL_MM_ZERO_VIRTUAL_ADDRESS_RANGE BlMmZeroVirtualAddressRange
#define MiAddressToPde(x)
NTSTATUS MmDefpMapPhysicalAddress(_In_ PHYSICAL_ADDRESS PhysicalAddress, _In_ PVOID VirtualAddress, _In_ ULONG Size, _In_ ULONG CacheAttributes)
PBL_MM_UNMAP_VIRTUAL_ADDRESS Mmx86UnmapVirtualAddress
ULONG MmArchLargePageSize
NTSTATUS Mmx86InitializeMemoryMap(_In_ ULONG Phase, _In_ PBL_MEMORY_DATA MemoryData)
PBL_MM_FLUSH_TLB_ENTRY Mmx86FlushTlbEntry
PBL_MM_FLUSH_TLB Mmx86FlushTlb
PBL_MM_DESTROY_SELF_MAP Mmx86DestroySelfMap
PBL_MM_TRANSLATE_VIRTUAL_ADDRESS Mmx86TranslateVirtualAddress
PHYSICAL_ADDRESS Mmx86SelfMapBase
BOOLEAN BlMmIsTranslationEnabled(VOID)
ULONG MmArchReferencePageSize
BOOLEAN MmDefpTranslateVirtualAddress(_In_ PVOID VirtualAddress, _Out_ PPHYSICAL_ADDRESS PhysicalAddress, _Out_opt_ PULONG CacheAttributes)
#define PAGE_ROUND_DOWN(x)
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
struct _LIST_ENTRY * Flink
static PMEM_HOOK PageTable[TOTAL_PAGES]
#define FIELD_OFFSET(t, f)
#define RtlZeroMemory(Destination, Length)
#define CONTAINING_RECORD(address, type, field)
#define STATUS_INVALID_PARAMETER
#define STATUS_UNSUCCESSFUL
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR MemoryDescriptor
int WINAPI EndPage(_In_ HDC)
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Out_ PPHYSICAL_ADDRESS DestinationAddress
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS SourceAddress
#define ROUND_TO_PAGES(Size)