stos/amd64: cpu: Add Local APIC driver stub
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include <machine/cpuid.h>
|
#include <machine/cpuid.h>
|
||||||
#include <machine/idt.h>
|
#include <machine/idt.h>
|
||||||
#include <machine/msr.h>
|
#include <machine/msr.h>
|
||||||
|
#include <machine/lapic.h>
|
||||||
#include <stdef.h>
|
#include <stdef.h>
|
||||||
|
|
||||||
#define DTRACE(Fmt, ...) \
|
#define DTRACE(Fmt, ...) \
|
||||||
@@ -157,6 +158,12 @@ HalKpcrP2Init(KPCR *Kpcr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOID
|
||||||
|
HalKpcrP3Init(KPCR *Kpcr)
|
||||||
|
{
|
||||||
|
MdLapicInit(Kpcr);
|
||||||
|
}
|
||||||
|
|
||||||
KPCR *
|
KPCR *
|
||||||
HalKpcrCurrent(VOID)
|
HalKpcrCurrent(VOID)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Chloe M.
|
||||||
|
* Provided under the BSD-3 clause.
|
||||||
|
*
|
||||||
|
* Description: Local APIC driver
|
||||||
|
* Author: Chloe M.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MACHINE_LAPIC_H_
|
||||||
|
#define _MACHINE_LAPIC_H_ 1
|
||||||
|
|
||||||
|
#include <stdef.h>
|
||||||
|
#include <hal/kpcr.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize the Local APIC unit for the current
|
||||||
|
* processor.
|
||||||
|
*
|
||||||
|
* @Kpcr: KPCR of current processor
|
||||||
|
*/
|
||||||
|
VOID MdLapicInit(KPCR *Kpcr);
|
||||||
|
|
||||||
|
#endif /* !_MACHINE_LAPIC_H_ */
|
||||||
@@ -41,6 +41,13 @@ VOID HalKpcrP1Init(KPCR *Kpcr);
|
|||||||
*/
|
*/
|
||||||
VOID HalKpcrP2Init(KPCR *Kpcr);
|
VOID HalKpcrP2Init(KPCR *Kpcr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Phase 3 initialization of processor
|
||||||
|
*
|
||||||
|
* @Kpcr: KPCR to initialize
|
||||||
|
*/
|
||||||
|
VOID HalKpcrP3Init(KPCR *Kpcr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Obtain the KPCR for the current processor, it is never to
|
* Obtain the KPCR for the current processor, it is never to
|
||||||
* be of a NULL value.
|
* be of a NULL value.
|
||||||
|
|||||||
@@ -86,4 +86,7 @@ KiKernelEntry(VOID)
|
|||||||
|
|
||||||
/* Initialize the board */
|
/* Initialize the board */
|
||||||
HalBoardInit();
|
HalBoardInit();
|
||||||
|
|
||||||
|
/* Phase 3 initialization of the bootstrap core */
|
||||||
|
HalKpcrP3Init(&BootstrapCore);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user