stos/amd64: cpu: Add Local APIC driver stub

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
Chloe M.
2026-06-26 19:56:41 +00:00
parent 0028d63608
commit 221cfc1893
5 changed files with 92 additions and 0 deletions
+7
View File
@@ -14,6 +14,7 @@
#include <machine/cpuid.h>
#include <machine/idt.h>
#include <machine/msr.h>
#include <machine/lapic.h>
#include <stdef.h>
#define DTRACE(Fmt, ...) \
@@ -157,6 +158,12 @@ HalKpcrP2Init(KPCR *Kpcr)
}
}
VOID
HalKpcrP3Init(KPCR *Kpcr)
{
MdLapicInit(Kpcr);
}
KPCR *
HalKpcrCurrent(VOID)
{
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause.
*
* Description: Local APIC driver
* Author: Chloe M.
*/
#include <machine/lapic.h>
#include <machine/msr.h>
#include <machine/cpuid.h>
#include <ex/trace.h>
#include <ke/knot.h>
#include <stdef.h>
/*
* Trace only on the bootstrap processor but not on any others
* to avoid log spam...
*/
#define DTRACE_BSP(Fmt, ...) do { \
ULONG ApicBase; \
\
ApicBase = MdRdmsr(IA32_APIC_BASE_MSR); \
if (ISSET(ApicBase, BIT(8))) { \
TRACE("[ LAPIC ]: " Fmt, ##__VA_ARGS__); \
} \
} while (0);
/*
* Returns true if the Local APIC unit is supported on the
* current processor.
*/
static BOOLEAN
LapicIsSupported(VOID)
{
ULONG Edx, Unused;
CPUID(1, Unused, Unused, Unused, Edx);
return ISSET(Edx, BIT(9)) != 0;
}
VOID
MdLapicInit(KPCR *Kpcr)
{
if (Kpcr == NULL) {
KeKnot(KNOT_MISC, "failed to initialize lapic driver\n");
}
if (!LapicIsSupported()) {
KeKnot(KNOT_MISSING_HARDWARE, "local apic not supported\n");
}
}