stos/amd64: cpu: Save KPCR in IA32_GS_BASE

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
Chloe M.
2026-06-24 05:49:59 +00:00
parent 5beb6f1d62
commit 9b1f4dde43
2 changed files with 26 additions and 0 deletions
+20
View File
@@ -13,6 +13,7 @@
#include <ke/knot.h>
#include <machine/cpuid.h>
#include <machine/idt.h>
#include <machine/msr.h>
#include <stdef.h>
#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;
}