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
+1
View File
@@ -13,6 +13,7 @@
#include <mm/vm.h> #include <mm/vm.h>
#include <ke/bugcheck.h> #include <ke/bugcheck.h>
#include <ptdef.h> #include <ptdef.h>
#include <string.h>
/* /*
* Valid paging structure levels * Valid paging structure levels
+5
View File
@@ -67,4 +67,9 @@ PT_STATUS MmMapRange(
MM_PROT Prot, MMU_PAGESIZE PageSize MM_PROT Prot, MMU_PAGESIZE PageSize
); );
/*
* Initialize virtual memory
*/
VOID MmVmInit(VOID);
#endif /* !_MM_VM_H_ */ #endif /* !_MM_VM_H_ */
+4
View File
@@ -10,6 +10,7 @@
#include <ke/bpal.h> #include <ke/bpal.h>
#include <ex/trace.h> #include <ex/trace.h>
#include <mm/pm.h> #include <mm/pm.h>
#include <mm/vm.h>
#include <hal/serial.h> #include <hal/serial.h>
#include <hal/kpcr.h> #include <hal/kpcr.h>
#include <drivers/bootvid/fbio.h> #include <drivers/bootvid/fbio.h>
@@ -55,4 +56,7 @@ KiKernelInit(VOID)
/* Phase 1 init of bootstrap core */ /* Phase 1 init of bootstrap core */
HalKpcrP1Init(&BootstrapCore); HalKpcrP1Init(&BootstrapCore);
/* Initialize virtual memory */
MmVmInit();
} }
+53
View File
@@ -7,9 +7,22 @@
*/ */
#include <mm/vm.h> #include <mm/vm.h>
#include <mm/pm.h>
#include <ex/trace.h>
#include <hal/page.h> #include <hal/page.h>
#include <hal/mmu.h>
#include <ke/bugcheck.h>
#include <ptdef.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 */ /* Use to safely convert page size */
#define PAGE_SIZE(PS) \ #define PAGE_SIZE(PS) \
((PS) >= NELEM(PageSizeTable)) \ ((PS) >= NELEM(PageSizeTable)) \
@@ -21,6 +34,9 @@ static USIZE PageSizeTable[] = {
[PAGESIZE_4K] = 0x1000 [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 MmUnmapRange(MMU_VAS *Vas, const MM_RANGE *Range, MMU_PAGESIZE PageSize)
{ {
PT_STATUS Status; PT_STATUS Status;
@@ -86,3 +102,40 @@ MmMapRange(MMU_VAS *Vas, const MM_RANGE *Range, MM_PROT Prot, MMU_PAGESIZE PageS
return STATUS_SUCCESS; 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);
}