ptos/amd64: cpu: Add MP trampoline stub
Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
@@ -37,7 +37,8 @@ build_verify() {
|
|||||||
check_deps \
|
check_deps \
|
||||||
clang \
|
clang \
|
||||||
rsync \
|
rsync \
|
||||||
xorriso
|
xorriso \
|
||||||
|
nasm
|
||||||
|
|
||||||
# We need build envs !!
|
# We need build envs !!
|
||||||
if [ -z "${PT_BUILD_SOURCED}" ]
|
if [ -z "${PT_BUILD_SOURCED}" ]
|
||||||
|
|||||||
@@ -33,12 +33,21 @@ CFLAGS = \
|
|||||||
-I$(PT_PROJECT_ROOT)/service/spkg/head/
|
-I$(PT_PROJECT_ROOT)/service/spkg/head/
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: bin
|
all: trampoline bin
|
||||||
|
|
||||||
.PHONY: bin
|
.PHONY: bin
|
||||||
bin: $(OFILES) $(ASMOFILES)
|
bin: $(OFILES) $(ASMOFILES)
|
||||||
$(PROMPT) "LD" $(KERNEL_PATH)
|
$(PROMPT) "LD" $(KERNEL_PATH)
|
||||||
$(SYS_LD) -Tdev/link.ld $(MISC_OFILES) -o $(KERNEL_PATH)
|
$(SYS_LD) -Tdev/link.ld $(MISC_OFILES) -o $(KERNEL_PATH)
|
||||||
|
# Copy the MP trampoline
|
||||||
|
objcopy \
|
||||||
|
--update-section .mp_trampoline=cpu/mp_trampoline.bin \
|
||||||
|
$(KERNEL_PATH) \
|
||||||
|
$(KERNEL_PATH)
|
||||||
|
|
||||||
|
.PHONY: trampoline
|
||||||
|
trampoline:
|
||||||
|
nasm -fbin cpu/mp_trampoline.asm -o cpu/mp_trampoline.bin
|
||||||
|
|
||||||
-include $(CDFILES)
|
-include $(CDFILES)
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
|
|||||||
@@ -7,11 +7,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ptdef.h>
|
#include <ptdef.h>
|
||||||
|
#include <hal/page.h>
|
||||||
#include <ex/trace.h>
|
#include <ex/trace.h>
|
||||||
#include <drivers/acpi/acpi.h>
|
#include <drivers/acpi/acpi.h>
|
||||||
#include <drivers/acpi/tables.h>
|
#include <drivers/acpi/tables.h>
|
||||||
#include <ke/bugcheck.h>
|
#include <ke/bugcheck.h>
|
||||||
|
#include <mm/vm.h>
|
||||||
#include <machine/lapic.h>
|
#include <machine/lapic.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* Bring up region */
|
||||||
|
#define BUA_BASE 0x9000
|
||||||
|
#define BUA_LENGTH PAGESIZE
|
||||||
|
|
||||||
/* Max processors to bootstrap */
|
/* Max processors to bootstrap */
|
||||||
#define CPU_MAX 64
|
#define CPU_MAX 64
|
||||||
@@ -22,6 +29,13 @@
|
|||||||
/* Number of processor cores */
|
/* Number of processor cores */
|
||||||
static USHORT CoreCount = 0;
|
static USHORT CoreCount = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The multiprocessor trampoline should fit within a single
|
||||||
|
* page and be no larger than such.
|
||||||
|
*/
|
||||||
|
ALIGN(8) SECTION(".mp_trampoline")
|
||||||
|
static UCHAR MpTrampoline[BUA_LENGTH];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bootstrap a single core
|
* Bootstrap a single core
|
||||||
*
|
*
|
||||||
@@ -32,10 +46,18 @@ static USHORT CoreCount = 0;
|
|||||||
static VOID
|
static VOID
|
||||||
BootstrapCore(ACPI_LOCAL_APIC *LocalApic)
|
BootstrapCore(ACPI_LOCAL_APIC *LocalApic)
|
||||||
{
|
{
|
||||||
|
ULONG SelfId;
|
||||||
|
|
||||||
if (LocalApic == NULL) {
|
if (LocalApic == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Let's not shoot ourselves in the face */
|
||||||
|
SelfId = MdLapicId();
|
||||||
|
if (LocalApic->ApicId == SelfId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
++CoreCount;
|
++CoreCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,5 +100,34 @@ MpBootstrap(VOID)
|
|||||||
VOID
|
VOID
|
||||||
HalMpBootstrap(VOID)
|
HalMpBootstrap(VOID)
|
||||||
{
|
{
|
||||||
|
MMU_VAS Vas;
|
||||||
|
MM_RANGE TrampolineRange;
|
||||||
|
PT_STATUS Status;
|
||||||
|
VOID *BuaDest;
|
||||||
|
|
||||||
|
/* Map the BUA page */
|
||||||
|
HalMmuReadVas(&Vas);
|
||||||
|
TrampolineRange.VirtualBase = BUA_BASE;
|
||||||
|
TrampolineRange.PhysicalBase = BUA_BASE;
|
||||||
|
TrampolineRange.Length = BUA_LENGTH;
|
||||||
|
Status = MmMapRange(
|
||||||
|
&Vas,
|
||||||
|
&TrampolineRange,
|
||||||
|
PAGE_READ | PAGE_WRITE | PAGE_EXEC,
|
||||||
|
PAGESIZE_4K
|
||||||
|
);
|
||||||
|
|
||||||
|
if (PT_ERROR(Status)) {
|
||||||
|
KeBugCheck(
|
||||||
|
BUGCHECK_MISC,
|
||||||
|
"failed to map mp bringup area\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy trampoline to the BUA page */
|
||||||
|
BuaDest = (VOID *)BUA_BASE;
|
||||||
|
RtlMemCpy(BuaDest, MpTrampoline, BUA_LENGTH);
|
||||||
|
|
||||||
|
/* Start up the APs */
|
||||||
MpBootstrap();
|
MpBootstrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
;;
|
||||||
|
;; Copyright (c) 2026, Chloe M.
|
||||||
|
;; Provided under the BSD-3 clause.
|
||||||
|
;;
|
||||||
|
|
||||||
|
[org 0x9000]
|
||||||
|
[global _start]
|
||||||
|
|
||||||
|
_start:
|
||||||
|
cli
|
||||||
|
hlt
|
||||||
|
jmp _start
|
||||||
|
|
||||||
|
times 4096 - ($ - $$) db 0
|
||||||
@@ -41,6 +41,12 @@ SECTIONS
|
|||||||
|
|
||||||
. += CONSTANT(MAXPAGESIZE);
|
. += CONSTANT(MAXPAGESIZE);
|
||||||
|
|
||||||
|
.mp_trampoline : ALIGN(8) {
|
||||||
|
KEEP(*(.mp_trampoline))
|
||||||
|
}
|
||||||
|
|
||||||
|
. += CONSTANT(MAXPAGESIZE);
|
||||||
|
|
||||||
.data : {
|
.data : {
|
||||||
*(.data)
|
*(.data)
|
||||||
} :data
|
} :data
|
||||||
|
|||||||
Reference in New Issue
Block a user