Add AllocateRealModeMemory routine for low memory allocations
All checks were successful
Builds / ExectOS (amd64, release) (push) Successful in -59m29s
Builds / ExectOS (amd64, debug) (push) Successful in -59m28s
Builds / ExectOS (i686, debug) (push) Successful in -59m28s
Builds / ExectOS (i686, release) (push) Successful in -59m30s

This commit is contained in:
2026-05-13 10:08:30 +02:00
parent 58981e0087
commit c8868ead47
2 changed files with 48 additions and 0 deletions

View File

@@ -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,

View File

@@ -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.
*