From 895521c510fa4d0854e48bf7321c5637724e34e2 Mon Sep 17 00:00:00 2001 From: Chloe M Date: Mon, 13 Jul 2026 18:35:39 -0400 Subject: [PATCH] ptos: Initialize per-processor pool regions Signed-off-by: Chloe M --- service/ptos/arch/amd64/cpu/init.c | 6 +++ service/ptos/ex/pool.c | 66 ++++++++++++++++++++++++++++++ service/ptos/head/ex/pool.h | 7 ++++ service/ptos/head/hal/kpcr.h | 12 +++++- service/ptos/ke/Makefile | 1 + service/ptos/ke/init.c | 3 ++ 6 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 service/ptos/ex/pool.c diff --git a/service/ptos/arch/amd64/cpu/init.c b/service/ptos/arch/amd64/cpu/init.c index cdbf781..f1c91f9 100644 --- a/service/ptos/arch/amd64/cpu/init.c +++ b/service/ptos/arch/amd64/cpu/init.c @@ -61,3 +61,9 @@ HalKpcrP1Init(KPCR *Kpcr) /* Save the current KPCR */ MdWrmsr(IA32_GS_BASE, (UPTR)Kpcr); } + +VOID +HalKpcrP2Init(KPCR *Kpcr) +{ + ExPoolRegionInit(&Kpcr->PoolRegion); +} diff --git a/service/ptos/ex/pool.c b/service/ptos/ex/pool.c new file mode 100644 index 0000000..598b75e --- /dev/null +++ b/service/ptos/ex/pool.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Pool allocator + * Author: Chloe M. + */ + +#include +#include +#include +#include + +/* + * 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 + ); + } + } +} diff --git a/service/ptos/head/ex/pool.h b/service/ptos/head/ex/pool.h index 61ca137..fb2ca2c 100644 --- a/service/ptos/head/ex/pool.h +++ b/service/ptos/head/ex/pool.h @@ -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_ */ diff --git a/service/ptos/head/hal/kpcr.h b/service/ptos/head/hal/kpcr.h index 55a52ad..b5807b9 100644 --- a/service/ptos/head/hal/kpcr.h +++ b/service/ptos/head/hal/kpcr.h @@ -10,15 +10,18 @@ #define _HAL_KPCR_H_ 1 #include +#include /* * 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 diff --git a/service/ptos/ke/Makefile b/service/ptos/ke/Makefile index 5048929..3b31665 100644 --- a/service/ptos/ke/Makefile +++ b/service/ptos/ke/Makefile @@ -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) diff --git a/service/ptos/ke/init.c b/service/ptos/ke/init.c index d24aaa4..834a8c5 100644 --- a/service/ptos/ke/init.c +++ b/service/ptos/ke/init.c @@ -59,4 +59,7 @@ KiKernelInit(VOID) /* Initialize virtual memory */ MmVmInit(); + + /* Phase 2 init of bootstrap core */ + HalKpcrP2Init(&BootstrapCore); }