Add AllocateRealModeMemory routine for low memory allocations
All checks were successful
All checks were successful
This commit is contained in:
@@ -27,6 +27,8 @@ namespace MM
|
||||
IN BOOLEAN Aligned,
|
||||
IN ULONGLONG MaximumAddress,
|
||||
OUT PPHYSICAL_ADDRESS Buffer);
|
||||
STATIC XTAPI XTSTATUS AllocateRealModeMemory(IN PFN_NUMBER PageCount,
|
||||
OUT PVOID *MemoryAddress);
|
||||
STATIC XTAPI XTSTATUS MapHardwareMemory(IN PHYSICAL_ADDRESS PhysicalAddress,
|
||||
IN PFN_NUMBER PageCount,
|
||||
IN BOOLEAN FlushTlb,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* FILE: xtoskrnl/mm/hlpool.cc
|
||||
* DESCRIPTION: Hardware layer pool memory management
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
* Aiken Harris <harraiken91@gmail.com>
|
||||
*/
|
||||
|
||||
#include <xtos.hh>
|
||||
@@ -146,6 +147,51 @@ MM::HardwarePool::AllocateHardwareMemory(IN PFN_NUMBER PageCount,
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a physical page in low memory (addressable in real-mode) and maps it into the virtual address space.
|
||||
*
|
||||
* @param TrampolineAddress
|
||||
* Supplies a pointer to a variable that receives the identity-mapped virtual address of the allocated memory.
|
||||
*
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
MM::HardwarePool::AllocateRealModeMemory(IN PFN_NUMBER PageCount,
|
||||
OUT PVOID *MemoryAddress)
|
||||
{
|
||||
PHYSICAL_ADDRESS PhysicalAddress;
|
||||
PFN_NUMBER PageFrameNumber;
|
||||
PVOID VirtualAddress;
|
||||
XTSTATUS Status;
|
||||
|
||||
/* Allocate physical memory in first 1MB */
|
||||
Status = AllocateHardwareMemory(PageCount, TRUE, 0x100000, &PhysicalAddress);
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
/* Failed to allocate memory, return error */
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* Calculate virtual address and page frame number */
|
||||
VirtualAddress = (PVOID)(ULONG_PTR)PhysicalAddress.QuadPart;
|
||||
PageFrameNumber = PhysicalAddress.QuadPart >> MM_PAGE_SHIFT;
|
||||
|
||||
/* Identity map the memory to the virtual address */
|
||||
Status = MM::Paging::MapVirtualAddress(VirtualAddress, PageFrameNumber, MM_PTE_EXECUTE_READWRITE);
|
||||
if(Status != STATUS_SUCCESS)
|
||||
{
|
||||
/* Failed to map memory, return error */
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* Set the trampoline virtual address and return success */
|
||||
*MemoryAddress = VirtualAddress;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps physical address to the virtual memory area used by kernel hardware layer.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user