ptos: vm: Initialize valloc range + zero pagemap lvls

Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
2026-07-11 20:26:24 -04:00
parent a9f411b750
commit ffe001821c
4 changed files with 63 additions and 0 deletions
+53
View File
@@ -7,9 +7,22 @@
*/
#include <mm/vm.h>
#include <mm/pm.h>
#include <ex/trace.h>
#include <hal/page.h>
#include <hal/mmu.h>
#include <ke/bugcheck.h>
#include <ptdef.h>
#define DTRACE(Fmt, ...) \
TRACE("[ VM ]: " Fmt, ##__VA_ARGS__)
/*
* Number of pages we start with that can be valloc'd
* total.
*/
#define INITIAL_VALLOC_PAGES 128
/* Use to safely convert page size */
#define PAGE_SIZE(PS) \
((PS) >= NELEM(PageSizeTable)) \
@@ -21,6 +34,9 @@ static USIZE PageSizeTable[] = {
[PAGESIZE_4K] = 0x1000
};
/* Bump pointer */
static UPTR VallocBump = VALLOC_BASE;
PT_STATUS MmUnmapRange(MMU_VAS *Vas, const MM_RANGE *Range, MMU_PAGESIZE PageSize)
{
PT_STATUS Status;
@@ -86,3 +102,40 @@ MmMapRange(MMU_VAS *Vas, const MM_RANGE *Range, MM_PROT Prot, MMU_PAGESIZE PageS
return STATUS_SUCCESS;
}
VOID
MmVmInit(VOID)
{
PT_STATUS Status;
MMU_VAS VasCurrent;
UPTR VirtualStart;
UPTR VirtualEnd, Off;
UPTR PhysicalBase;
USIZE NumPages;
MM_PFN Pfn;
HalMmuReadVas(&VasCurrent);
VirtualStart = VallocBump;
VallocBump += INITIAL_VALLOC_PAGES * PAGESIZE;
VirtualEnd = VallocBump;
NumPages = (VirtualEnd - VirtualStart) / PAGESIZE;
for (Off = 0; Off < NumPages * PAGESIZE; Off += PAGESIZE) {
Pfn = MmRequestFrame();
PhysicalBase = PFN_TO_ADDRESS(Pfn);
Status = HalMmuMapPage(
&VasCurrent,
VirtualStart + Off,
PhysicalBase + Off,
PAGE_READ | PAGE_WRITE,
PAGESIZE_4K
);
if (PT_ERROR(Status)) {
KeBugCheck(BUGCHECK_OOM, "failed to map valloc pages\n");
}
}
DTRACE("initialized %d valloc pages\n", NumPages);
}