From 9b1f4dde432c74c3a8dfe429ef9985468f3cefe5 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Wed, 24 Jun 2026 05:49:59 +0000 Subject: [PATCH] stos/amd64: cpu: Save KPCR in IA32_GS_BASE Signed-off-by: Chloe M. --- paw/stos/arch/amd64/cpu/init.c | 20 ++++++++++++++++++++ paw/stos/head/hal/kpcr.h | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/paw/stos/arch/amd64/cpu/init.c b/paw/stos/arch/amd64/cpu/init.c index 61586cc..0349446 100644 --- a/paw/stos/arch/amd64/cpu/init.c +++ b/paw/stos/arch/amd64/cpu/init.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #define DTRACE(Fmt, ...) \ @@ -132,6 +133,9 @@ HalKpcrP1Init(KPCR *Kpcr) : "r" ((UQUAD)IRQL_PASSIVE) : "memory" ); + + /* Save the current KPCR */ + MdWrmsr(IA32_GS_BASE, (UPTR)Kpcr); } VOID @@ -152,3 +156,19 @@ HalKpcrP2Init(KPCR *Kpcr) ); } } + +KPCR * +HalKpcrCurrent(VOID) +{ + KPCR *Kpcr; + + Kpcr = (KPCR *)MdRdmsr(IA32_GS_BASE); + if (Kpcr == NULL) { + KeKnot( + KNOT_UNBOUND_RSRC, + "current kpcr is NULL\n" + ); + } + + return Kpcr; +} diff --git a/paw/stos/head/hal/kpcr.h b/paw/stos/head/hal/kpcr.h index 9e8aece..da06412 100644 --- a/paw/stos/head/hal/kpcr.h +++ b/paw/stos/head/hal/kpcr.h @@ -41,4 +41,10 @@ VOID HalKpcrP1Init(KPCR *Kpcr); */ VOID HalKpcrP2Init(KPCR *Kpcr); +/* + * Obtain the KPCR for the current processor, it is never to + * be of a NULL value. + */ +KPCR *HalKpcrCurrent(VOID); + #endif /* !_HAL_KPCR_H_ */