ptos: Initialize per-processor pool regions

Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
2026-07-13 18:35:39 -04:00
parent 7a8fbe7025
commit 895521c510
6 changed files with 94 additions and 1 deletions
+6
View File
@@ -61,3 +61,9 @@ HalKpcrP1Init(KPCR *Kpcr)
/* Save the current KPCR */
MdWrmsr(IA32_GS_BASE, (UPTR)Kpcr);
}
VOID
HalKpcrP2Init(KPCR *Kpcr)
{
ExPoolRegionInit(&Kpcr->PoolRegion);
}
+66
View File
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause.
*
* Description: Pool allocator
* Author: Chloe M.
*/
#include <ex/pool.h>
#include <ke/bugcheck.h>
#include <mm/vm.h>
#include <ptapi/status.h>
/*
* Initialize a pool segment
*
* @Segment: Pool segment to initialize
*/
static PT_STATUS
PoolSegmentInit(POOL_SEGMENT *Segment)
{
PT_STATUS Status;
MM_RANGE Range;
if (Segment == NULL) {
return STATUS_INVALID_PARAM;
}
Status = MmAllocatePages(1, &Range);
if (Status != STATUS_SUCCESS) {
return Status;
}
Segment->PageCount = 1;
Segment->LastPage = RANGE_PTR(&Range);
return STATUS_SUCCESS;
}
VOID
ExPoolRegionInit(POOL_REGION *Region)
{
UCHAR Level;
POOL_SEGMENT *Segment;
PT_STATUS Status;
if (Region == NULL) {
KeBugCheck(
BUGCHECK_UNBOUND_RESRC,
"unbound region in ExPoolRegionInit()\n"
);
}
/* Initialize each segment level */
for (Level = 0; Level < POOL_LEVEL_MAX; ++Level) {
Segment = &Region->Level[Level];
Status = PoolSegmentInit(Segment);
if (PT_ERROR(Status)) {
KeBugCheck(
BUGCHECK_MISC,
"failed to initialize segment level %d\n",
Level
);
}
}
}
+7
View File
@@ -55,4 +55,11 @@ typedef struct {
POOL_SEGMENT Level[POOL_LEVEL_MAX];
} POOL_REGION;
/*
* Initialize a pool region
*
* @Region: Pool region to initialize
*/
VOID ExPoolRegionInit(POOL_REGION *Region);
#endif /* !_EX_POOL_H_ */
+11 -1
View File
@@ -10,15 +10,18 @@
#define _HAL_KPCR_H_ 1
#include <ptdef.h>
#include <ex/pool.h>
/*
* The kernel processor control region contains MI
* processor information.
*
* @Id: Logical processor ID assigned by us
* @Id: Logical processor ID assigned by us
* @PoolRegion: Allocator pool region
*/
typedef struct {
USHORT Id;
POOL_REGION PoolRegion;
} KPCR;
/*
@@ -28,6 +31,13 @@ typedef struct {
*/
VOID HalKpcrP1Init(KPCR *Kpcr);
/*
* Phase 2 processor initialization
*
* @Kpcr: KPCR of processor to initialize
*/
VOID HalKpcrP2Init(KPCR *Kpcr);
/*
* Obtain the KPCR of the current processor
* core
+1
View File
@@ -14,6 +14,7 @@ CFILES += $(shell find ../lib -name "*.c")
CFILES += $(shell find ../xt -name "*.c")
CFILES += $(shell find ../drivers -name "*.c")
CFILES += $(shell find ../mm -name "*.c")
CFILES += $(shell find ../ex -name "*.c")
DFILES = $(CFILES:.c=.d)
OFILES = $(CFILES:.c=.o)
+3
View File
@@ -59,4 +59,7 @@ KiKernelInit(VOID)
/* Initialize virtual memory */
MmVmInit();
/* Phase 2 init of bootstrap core */
HalKpcrP2Init(&BootstrapCore);
}