From 579b338ce43a0f084d22b082c82e341f81ed7e2f Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 23 Dec 2025 01:44:33 -0500 Subject: mos/x86_64+mu: Add processor control region Signed-off-by: Ian Moffett --- mos/sys/arch/x86_64/cpu/cpu.c | 22 ++++++++++++++++++++++ mos/sys/inc/mu/cpu.h | 17 +++++++++++++++++ mos/sys/kern/kern_init.c | 6 ++++++ 3 files changed, 45 insertions(+) create mode 100644 mos/sys/arch/x86_64/cpu/cpu.c diff --git a/mos/sys/arch/x86_64/cpu/cpu.c b/mos/sys/arch/x86_64/cpu/cpu.c new file mode 100644 index 0000000..e5f7479 --- /dev/null +++ b/mos/sys/arch/x86_64/cpu/cpu.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025, Ian Moffett. + * Provided under the BSD-3 clause. + */ + +#include +#include +#include +#include + +#define dtrace(fmt, ...) trace("cpu: " fmt, ##__VA_ARGS__) + +void +mu_cpu_conf(PCR *pcr) +{ + if (pcr == NULL) { + return; + } + + md_wrmsr(IA32_GS_BASE, (UPTR)pcr); + dtrace("pcr engaged\n"); +} diff --git a/mos/sys/inc/mu/cpu.h b/mos/sys/inc/mu/cpu.h index 9856df8..2fb4e6e 100644 --- a/mos/sys/inc/mu/cpu.h +++ b/mos/sys/inc/mu/cpu.h @@ -8,6 +8,16 @@ #include +/* + * The processor control region represents the currently + * running processor + * + * @logical_id: Assigned by us + */ +typedef struct { + UBYTE logical_id; +} PCR; + /* * Get the current IRQ state * @@ -33,6 +43,13 @@ void mu_irq_setmask(BOOL mask); */ USIZE mu_cpu_aswap(USIZE *p, USIZE val); +/* + * Configure the current processor + * + * @pcr: Processor control region + */ +void mu_cpu_conf(PCR *pcr); + /* * Halt the current processor core */ diff --git a/mos/sys/kern/kern_init.c b/mos/sys/kern/kern_init.c index 2502dc2..c8f9283 100644 --- a/mos/sys/kern/kern_init.c +++ b/mos/sys/kern/kern_init.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #define write_boot_header() \ @@ -19,6 +20,8 @@ /* Forward declaration */ void kern_main(void); +static PCR bsp_pcr; + void kern_main(void) { @@ -33,4 +36,7 @@ kern_main(void) /* Initialize the physical memory manager */ pmm_init(); + + /* Initialize the BSP PCR */ + mu_cpu_conf(&bsp_pcr); } -- cgit v1.2.3