From e7ef29b7a225b08cc509ed5ca6111a9ffdcd8d17 Mon Sep 17 00:00:00 2001 From: Utkarsh Adhran Date: Tue, 7 Jul 2026 10:05:38 +0530 Subject: [PATCH 1/2] platform: set up syscall trap on SMP application processors Pull syscall MSR setup into init_syscall_trap() and call it from both the BSP libc init path and revenant_main so AP cores get a handler instead of nothing. Related: #2358 --- src/platform/x86_pc/apic_revenant.cpp | 2 ++ src/platform/x86_pc/init_libc.cpp | 27 +++++++++++++++------------ src/platform/x86_pc/init_libc.hpp | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/platform/x86_pc/apic_revenant.cpp b/src/platform/x86_pc/apic_revenant.cpp index 02cc18aa72..526130d4a5 100644 --- a/src/platform/x86_pc/apic_revenant.cpp +++ b/src/platform/x86_pc/apic_revenant.cpp @@ -3,6 +3,7 @@ #include "apic_timer.hpp" #include "clocks.hpp" #include "idt.hpp" +#include "init_libc.hpp" #include //#include #include @@ -90,6 +91,7 @@ void revenant_main(int cpu) SMP::global_unlock(); // initialize exceptions before asserts x86::idt_initialize_for_cpu(cpu); + x86::init_syscall_trap(); assert(cpu == SMP::cpu_id()); assert(stack >= this_stack_end && stack < this_stack); // relates to [[maybe_unused]] diff --git a/src/platform/x86_pc/init_libc.cpp b/src/platform/x86_pc/init_libc.cpp index ae39c919ae..154f8101a0 100644 --- a/src/platform/x86_pc/init_libc.cpp +++ b/src/platform/x86_pc/init_libc.cpp @@ -153,18 +153,8 @@ namespace x86 aux[i++].set_long(AT_NULL, 0); #ifdef PLATFORM_x86_pc - // SYSCALL instruction - #if defined(__x86_64__) - KDEBUG("* Initialize syscall MSR (64-bit)\n"); - uint64_t star_kernel_cs = 8ull << 32; - uint64_t star_user_cs = 8ull << 48; - uint64_t star = star_kernel_cs | star_user_cs; - x86::CPU::write_msr(IA32_STAR, star); - x86::CPU::write_msr(IA32_LSTAR, (uintptr_t)&__syscall_entry); - #elif defined(__i386__) - KDEBUG("Initialize syscall intr (32-bit)\n"); - #warning Classical syscall interface missing for 32-bit - #endif + KDEBUG("* Initialize syscall trap\n"); + x86::init_syscall_trap(); #endif // GDB_ENTRY; @@ -173,3 +163,16 @@ namespace x86 __libc_start_main(kernel_main, argc, argv.data()); } } + +void x86::init_syscall_trap() +{ +#if defined(PLATFORM_x86_pc) && defined(__x86_64__) + uint64_t star_kernel_cs = 8ull << 32; + uint64_t star_user_cs = 8ull << 48; + uint64_t star = star_kernel_cs | star_user_cs; + x86::CPU::write_msr(IA32_STAR, star); + x86::CPU::write_msr(IA32_LSTAR, (uintptr_t)&__syscall_entry); +#elif defined(PLATFORM_x86_pc) && defined(__i386__) + #warning Classical syscall interface missing for 32-bit +#endif +} diff --git a/src/platform/x86_pc/init_libc.hpp b/src/platform/x86_pc/init_libc.hpp index c71daa9089..2e92aa2b46 100644 --- a/src/platform/x86_pc/init_libc.hpp +++ b/src/platform/x86_pc/init_libc.hpp @@ -4,6 +4,7 @@ namespace x86 { extern void init_libc(uint32_t magic, uint32_t address); + void init_syscall_trap(); } extern "C" { From 536d3e1875ebaa098316394147e645d9f538c66b Mon Sep 17 00:00:00 2001 From: Utkarsh Adhran Date: Tue, 7 Jul 2026 10:15:10 +0530 Subject: [PATCH 2/2] arch: move init_syscall_trap into src/arch/x86_64 MSR setup for the syscall entry point lives next to __syscall_entry and syscall_entry.cpp. Platform code only calls x86::init_syscall_trap(). --- api/arch/x86/syscall.hpp | 5 +++++ src/arch/x86_64/CMakeLists.txt | 1 + src/arch/x86_64/syscall_trap.cpp | 17 +++++++++++++++++ src/platform/x86_pc/apic_revenant.cpp | 2 +- src/platform/x86_pc/init_libc.cpp | 14 +------------- src/platform/x86_pc/init_libc.hpp | 1 - 6 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 api/arch/x86/syscall.hpp create mode 100644 src/arch/x86_64/syscall_trap.cpp diff --git a/api/arch/x86/syscall.hpp b/api/arch/x86/syscall.hpp new file mode 100644 index 0000000000..011a014538 --- /dev/null +++ b/api/arch/x86/syscall.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace x86 { + void init_syscall_trap(); +} \ No newline at end of file diff --git a/src/arch/x86_64/CMakeLists.txt b/src/arch/x86_64/CMakeLists.txt index ce9be1e0d7..90c98314f9 100644 --- a/src/arch/x86_64/CMakeLists.txt +++ b/src/arch/x86_64/CMakeLists.txt @@ -11,6 +11,7 @@ set(ARCH_OBJECTS fiber_asm.asm __syscall_entry.asm syscall_entry.cpp + syscall_trap.cpp ist.cpp paging.cpp init_paging.cpp diff --git a/src/arch/x86_64/syscall_trap.cpp b/src/arch/x86_64/syscall_trap.cpp new file mode 100644 index 0000000000..a6bcba9373 --- /dev/null +++ b/src/arch/x86_64/syscall_trap.cpp @@ -0,0 +1,17 @@ +#include +#include + +extern "C" void __syscall_entry(); + +namespace x86 { + +void init_syscall_trap() +{ + uint64_t star_kernel_cs = 8ull << 32; + uint64_t star_user_cs = 8ull << 48; + uint64_t star = star_kernel_cs | star_user_cs; + CPU::write_msr(IA32_STAR, star); + CPU::write_msr(IA32_LSTAR, (uintptr_t)&__syscall_entry); +} + +} \ No newline at end of file diff --git a/src/platform/x86_pc/apic_revenant.cpp b/src/platform/x86_pc/apic_revenant.cpp index 526130d4a5..62e56a2c9b 100644 --- a/src/platform/x86_pc/apic_revenant.cpp +++ b/src/platform/x86_pc/apic_revenant.cpp @@ -3,7 +3,7 @@ #include "apic_timer.hpp" #include "clocks.hpp" #include "idt.hpp" -#include "init_libc.hpp" +#include #include //#include #include diff --git a/src/platform/x86_pc/init_libc.cpp b/src/platform/x86_pc/init_libc.cpp index 154f8101a0..45ad0a7a86 100644 --- a/src/platform/x86_pc/init_libc.cpp +++ b/src/platform/x86_pc/init_libc.cpp @@ -1,6 +1,7 @@ #include "init_libc.hpp" #include +#include #include #include #include @@ -163,16 +164,3 @@ namespace x86 __libc_start_main(kernel_main, argc, argv.data()); } } - -void x86::init_syscall_trap() -{ -#if defined(PLATFORM_x86_pc) && defined(__x86_64__) - uint64_t star_kernel_cs = 8ull << 32; - uint64_t star_user_cs = 8ull << 48; - uint64_t star = star_kernel_cs | star_user_cs; - x86::CPU::write_msr(IA32_STAR, star); - x86::CPU::write_msr(IA32_LSTAR, (uintptr_t)&__syscall_entry); -#elif defined(PLATFORM_x86_pc) && defined(__i386__) - #warning Classical syscall interface missing for 32-bit -#endif -} diff --git a/src/platform/x86_pc/init_libc.hpp b/src/platform/x86_pc/init_libc.hpp index 2e92aa2b46..c71daa9089 100644 --- a/src/platform/x86_pc/init_libc.hpp +++ b/src/platform/x86_pc/init_libc.hpp @@ -4,7 +4,6 @@ namespace x86 { extern void init_libc(uint32_t magic, uint32_t address); - void init_syscall_trap(); } extern "C" {