ptos: Initialize per-processor pool regions
Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
@@ -61,3 +61,9 @@ HalKpcrP1Init(KPCR *Kpcr)
|
||||
/* Save the current KPCR */
|
||||
MdWrmsr(IA32_GS_BASE, (UPTR)Kpcr);
|
||||
}
|
||||
|
||||
VOID
|
||||
HalKpcrP2Init(KPCR *Kpcr)
|
||||
{
|
||||
ExPoolRegionInit(&Kpcr->PoolRegion);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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_ */
|
||||
|
||||
@@ -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
|
||||
* @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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -59,4 +59,7 @@ KiKernelInit(VOID)
|
||||
|
||||
/* Initialize virtual memory */
|
||||
MmVmInit();
|
||||
|
||||
/* Phase 2 init of bootstrap core */
|
||||
HalKpcrP2Init(&BootstrapCore);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user