From 6154318ab33b12fc481d94819c90b9aebf83045a Mon Sep 17 00:00:00 2001 From: 8infy <99danilt@gmail.com> Date: Sun, 1 Sep 2024 19:36:17 +0300 Subject: [PATCH] kernel: add a helper to retrieve the bsp CPU This is useful to be able to e.g. set affinity for the BSP CPU. --- kernel-src/arch/x86-64/main.c | 4 ++++ kernel-src/include/x86-64/arch/cpu.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/kernel-src/arch/x86-64/main.c b/kernel-src/arch/x86-64/main.c index 654bdeba..a7ee64f0 100644 --- a/kernel-src/arch/x86-64/main.c +++ b/kernel-src/arch/x86-64/main.c @@ -124,3 +124,7 @@ void kernel_entry() { sched_runinit(); sched_threadexit(); } + +cpu_t *_bsp(void) { + return &bsp_cpu; +} diff --git a/kernel-src/include/x86-64/arch/cpu.h b/kernel-src/include/x86-64/arch/cpu.h index 132bf8c4..26bda0fb 100644 --- a/kernel-src/include/x86-64/arch/cpu.h +++ b/kernel-src/include/x86-64/arch/cpu.h @@ -54,6 +54,8 @@ static inline uint16_t be_to_cpu_w(uint16_t w) { return __builtin_bswap16(w); } +cpu_t *_bsp(void); + static inline cpu_t *_cpu() { cpu_t *cpu; asm volatile ("mov %%gs:0, %%rax" : "=a"(cpu) : : "memory");