ptos: vad: Add VAD insertions and create VALLOC VADs
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -9,8 +9,9 @@
|
|||||||
#ifndef _MM_VAD_H_
|
#ifndef _MM_VAD_H_
|
||||||
#define _MM_VAD_H_ 1
|
#define _MM_VAD_H_ 1
|
||||||
|
|
||||||
|
#include <ptapi/status.h>
|
||||||
#include <ptdef.h>
|
#include <ptdef.h>
|
||||||
#include <mm/vmm.h>
|
#include <mm/vm.h>
|
||||||
#include <tree.h>
|
#include <tree.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -37,4 +38,20 @@ typedef struct {
|
|||||||
USIZE Elements;
|
USIZE Elements;
|
||||||
} MM_VAD_TREE;
|
} MM_VAD_TREE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize a virtual address descriptor tree
|
||||||
|
*
|
||||||
|
* @Tree: Tree to initialize
|
||||||
|
*/
|
||||||
|
VOID MmVadTreeInit(MM_VAD_TREE *Tree);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Insert a virtual address descriptor into a virtual address
|
||||||
|
* descriptor tree.
|
||||||
|
*
|
||||||
|
* @Tree: VAD tree to be inserted into
|
||||||
|
* @Vad: VAD to insert
|
||||||
|
*/
|
||||||
|
PT_STATUS MmVadTreeInsert(MM_VAD_TREE *Tree, MM_VAD *Vad);
|
||||||
|
|
||||||
#endif /* !_MM_VAD_H_ */
|
#endif /* !_MM_VAD_H_ */
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Chloe M.
|
||||||
|
* Provided under the BSD-3 clause.
|
||||||
|
*
|
||||||
|
* Description: Virtual address descriptor management
|
||||||
|
* Author: Chloe M.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mm/vad.h>
|
||||||
|
|
||||||
|
/* Prototypes */
|
||||||
|
static LONG VadCmp(MM_VAD *V0, MM_VAD *V1);
|
||||||
|
|
||||||
|
/* RBT generation */
|
||||||
|
RB_PROTOTYPE(VadTree, _MM_VAD, TreeLink, VadCmp);
|
||||||
|
RB_GENERATE(VadTree, _MM_VAD, TreeLink, VadCmp);
|
||||||
|
|
||||||
|
static LONG
|
||||||
|
VadCmp(MM_VAD *V0, MM_VAD *V1)
|
||||||
|
{
|
||||||
|
MM_RANGE *Range0, *Range1;
|
||||||
|
|
||||||
|
Range0 = &V0->Range;
|
||||||
|
Range1 = &V1->Range;
|
||||||
|
|
||||||
|
return (Range0->VirtualBase < Range1->VirtualBase)
|
||||||
|
? -1
|
||||||
|
: Range0->VirtualBase > Range1->VirtualBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID
|
||||||
|
MmVadTreeInit(MM_VAD_TREE *Tree)
|
||||||
|
{
|
||||||
|
if (Tree == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tree->Elements = 0;
|
||||||
|
RB_INIT(&Tree->Head);
|
||||||
|
}
|
||||||
|
|
||||||
|
PT_STATUS
|
||||||
|
MmVadTreeInsert(MM_VAD_TREE *Tree, MM_VAD *Vad)
|
||||||
|
{
|
||||||
|
if (Tree == NULL || Vad == NULL) {
|
||||||
|
return STATUS_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_INSERT(VadTree, &Tree->Head, Vad);
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
+28
-4
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <mm/vm.h>
|
#include <mm/vm.h>
|
||||||
#include <mm/pm.h>
|
#include <mm/pm.h>
|
||||||
|
#include <mm/vad.h>
|
||||||
#include <ex/trace.h>
|
#include <ex/trace.h>
|
||||||
#include <hal/page.h>
|
#include <hal/page.h>
|
||||||
#include <hal/mmu.h>
|
#include <hal/mmu.h>
|
||||||
@@ -34,8 +35,10 @@ static USIZE PageSizeTable[] = {
|
|||||||
[PAGESIZE_4K] = 0x1000
|
[PAGESIZE_4K] = 0x1000
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Bump pointer */
|
/* Bump pointer and vad tree */
|
||||||
static UPTR VallocBump = VALLOC_BASE;
|
static UPTR VallocBump = VALLOC_BASE;
|
||||||
|
static MM_VAD_TREE VadTree;
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
@@ -113,8 +116,12 @@ MmVmInit(VOID)
|
|||||||
UPTR PhysicalBase;
|
UPTR PhysicalBase;
|
||||||
USIZE NumPages;
|
USIZE NumPages;
|
||||||
MM_PFN Pfn;
|
MM_PFN Pfn;
|
||||||
|
MM_RANGE *CurrentRange;
|
||||||
|
MM_VAD *CurrentVad;
|
||||||
|
|
||||||
HalMmuReadVas(&VasCurrent);
|
HalMmuReadVas(&VasCurrent);
|
||||||
|
MmVadTreeInit(&VadTree);
|
||||||
|
|
||||||
VirtualStart = VallocBump;
|
VirtualStart = VallocBump;
|
||||||
VallocBump += INITIAL_VALLOC_PAGES * PAGESIZE;
|
VallocBump += INITIAL_VALLOC_PAGES * PAGESIZE;
|
||||||
VirtualEnd = VallocBump;
|
VirtualEnd = VallocBump;
|
||||||
@@ -122,19 +129,36 @@ MmVmInit(VOID)
|
|||||||
|
|
||||||
for (Off = 0; Off < NumPages * PAGESIZE; Off += PAGESIZE) {
|
for (Off = 0; Off < NumPages * PAGESIZE; Off += PAGESIZE) {
|
||||||
Pfn = MmRequestFrame();
|
Pfn = MmRequestFrame();
|
||||||
PhysicalBase = PFN_TO_ADDRESS(Pfn);
|
if (Pfn == 0) {
|
||||||
|
KeBugCheck(BUGCHECK_OOM, "out of memory\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
PhysicalBase = PFN_TO_ADDRESS(Pfn);
|
||||||
Status = HalMmuMapPage(
|
Status = HalMmuMapPage(
|
||||||
&VasCurrent,
|
&VasCurrent,
|
||||||
VirtualStart + Off,
|
VirtualStart + Off,
|
||||||
PhysicalBase + Off,
|
PhysicalBase,
|
||||||
PAGE_READ | PAGE_WRITE,
|
PAGE_READ| PAGE_WRITE,
|
||||||
PAGESIZE_4K
|
PAGESIZE_4K
|
||||||
);
|
);
|
||||||
|
|
||||||
if (PT_ERROR(Status)) {
|
if (PT_ERROR(Status)) {
|
||||||
KeBugCheck(BUGCHECK_OOM, "failed to map valloc pages\n");
|
KeBugCheck(BUGCHECK_OOM, "failed to map valloc pages\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CurrentVad = (MM_VAD *)(VirtualStart + Off);
|
||||||
|
CurrentRange = &CurrentVad->Range;
|
||||||
|
CurrentRange->VirtualBase = VirtualStart + Off;
|
||||||
|
CurrentRange->PhysicalBase = PhysicalBase;
|
||||||
|
CurrentRange->Length = PAGESIZE;
|
||||||
|
Status = MmVadTreeInsert(
|
||||||
|
&VadTree,
|
||||||
|
CurrentVad
|
||||||
|
);
|
||||||
|
|
||||||
|
if (PT_ERROR(Status)) {
|
||||||
|
KeBugCheck(BUGCHECK_MISC, "failed to initialize vad tree\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DTRACE("initialized %d valloc pages\n", NumPages);
|
DTRACE("initialized %d valloc pages\n", NumPages);
|
||||||
|
|||||||
Reference in New Issue
Block a user