From d79b33f5be78839a0b6b9b616d5fbb33ea8838c7 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Wed, 15 Jul 2026 23:10:04 +0000 Subject: [PATCH] ptos/amd64: mp: Add MP bootstrap stub / groundwork Signed-off-by: Chloe M. --- service/ptos/arch/amd64/cpu/mp.c | 82 ++++++++++++++++++++++++++++++++ service/ptos/head/hal/mp.h | 20 ++++++++ service/ptos/ke/init.c | 4 ++ 3 files changed, 106 insertions(+) create mode 100644 service/ptos/arch/amd64/cpu/mp.c create mode 100644 service/ptos/head/hal/mp.h diff --git a/service/ptos/arch/amd64/cpu/mp.c b/service/ptos/arch/amd64/cpu/mp.c new file mode 100644 index 0000000..eb78e24 --- /dev/null +++ b/service/ptos/arch/amd64/cpu/mp.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Multi-processing + * Author: Chloe M. + */ + +#include +#include +#include +#include +#include +#include + +/* Max processors to bootstrap */ +#define CPU_MAX 64 + +#define DTRACE(Fmt, ...) \ + TRACE("[ MP ]: " Fmt, ##__VA_ARGS__) + +/* Number of processor cores */ +static USHORT CoreCount = 0; + +/* + * Bootstrap a single core + * + * @LocalApic: Local APIC descriptor of core to bootstrap + * + * TODO: This is a stub + */ +static VOID +BootstrapCore(ACPI_LOCAL_APIC *LocalApic) +{ + if (LocalApic == NULL) { + return; + } + + ++CoreCount; +} + +static VOID +MpBootstrap(VOID) +{ + ACPI_MADT *Madt; + UCHAR *Ptr, *EndPtr; + ACPI_APIC_HEADER *Header; + ACPI_LOCAL_APIC *LocalApic; + + Madt = AcpiQuery("APIC"); + if (Madt == NULL) { + KeBugCheck( + BUGCHECK_MISC, + "unable to detect ACPI MADT table\n" + ); + } + + Ptr = PTR_OFFSET(Madt, sizeof(ACPI_MADT)); + EndPtr = PTR_OFFSET(Ptr, Madt->Header.Length); + + /* Iterate every interrupt controller entry */ + while (Ptr < EndPtr) { + Header = (ACPI_APIC_HEADER *)Ptr; + + switch (Header->Type) { + case APIC_TYPE_LOCAL_APIC: + LocalApic = (ACPI_LOCAL_APIC *)Header; + BootstrapCore(LocalApic); + break; + } + + Ptr = PTR_OFFSET(Ptr, Header->Length); + } + + DTRACE("detected %d processor core(s)\n", CoreCount); +} + +VOID +HalMpBootstrap(VOID) +{ + MpBootstrap(); +} diff --git a/service/ptos/head/hal/mp.h b/service/ptos/head/hal/mp.h new file mode 100644 index 0000000..8aef8b5 --- /dev/null +++ b/service/ptos/head/hal/mp.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Multi-processing HAL layer + * Author: Chloe M. + */ + +#ifndef _HAL_MP_H_ +#define _HAL_MP_H_ 1 + +#include + +/* + * Bring up all application processors on a multicore + * system. + */ +VOID HalMpBootstrap(VOID); + +#endif /* !_HAL_MP_H_ */ diff --git a/service/ptos/ke/init.c b/service/ptos/ke/init.c index b93e238..2a42434 100644 --- a/service/ptos/ke/init.c +++ b/service/ptos/ke/init.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -144,6 +145,9 @@ KiKernelInit(VOID) /* Initialize the root process */ InitializeRootProcess(); + /* Bootstrap all other cores */ + HalMpBootstrap(); + /* Prime the scheduler timer */ HalPrimeThreadTimer(SCHED_MIN_QUANTUM);