From 331e9b0973e9f6c719eb6a1187e557adf3a7626e Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Fri, 13 Feb 2026 16:48:51 -0300 Subject: [PATCH] refactor: move syscall_init arch dispatch to arch/x86/sysenter_init.c MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Add arch_syscall_init() that registers INT 0x80 handler and calls x86_sysenter_init() - syscall_init() now just calls arch_syscall_init() — zero #ifdef in syscall.c - x86_sysenter_init() made static (internal to sysenter_init.c) - syscall.c contains ZERO architecture-specific code or #ifdefs 20/20 smoke, cppcheck clean --- include/arch_syscall.h | 7 +++++++ src/arch/x86/sysenter_init.c | 13 ++++++++++++- src/kernel/syscall.c | 8 +------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/arch_syscall.h b/include/arch_syscall.h index 2e23c02..0ff3b78 100644 --- a/include/arch_syscall.h +++ b/include/arch_syscall.h @@ -42,4 +42,11 @@ extern uint32_t __arch_syscall_stub_sink; #endif +/* + * arch_syscall_init — Register the syscall entry point(s) for this + * architecture (e.g. INT 0x80 + SYSENTER on x86). + * Called once from the generic syscall_init(). + */ +void arch_syscall_init(void); + #endif /* ARCH_SYSCALL_H */ diff --git a/src/arch/x86/sysenter_init.c b/src/arch/x86/sysenter_init.c index 942c261..f983731 100644 --- a/src/arch/x86/sysenter_init.c +++ b/src/arch/x86/sysenter_init.c @@ -1,4 +1,5 @@ #include "hal/cpu_features.h" +#include "interrupts.h" #include "console.h" #include @@ -29,7 +30,17 @@ static inline uint64_t rdmsr(uint32_t msr) { static uint8_t sysenter_stack[4096] __attribute__((aligned(16))); static int sysenter_enabled = 0; -void x86_sysenter_init(void) { +static void x86_sysenter_init(void); + +/* Generic syscall_handler defined in src/kernel/syscall.c */ +extern void syscall_handler(struct registers*); + +void arch_syscall_init(void) { + register_interrupt_handler(128, syscall_handler); + x86_sysenter_init(); +} + +static void x86_sysenter_init(void) { const struct cpu_features* f = hal_cpu_get_features(); if (!f->has_sysenter) { kprintf("[SYSENTER] CPU does not support SYSENTER/SYSEXIT.\n"); diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index 8c92023..5ab2e7f 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -16,9 +16,6 @@ #include "shm.h" #include "socket.h" -#if defined(__i386__) -extern void x86_sysenter_init(void); -#endif #include "elf.h" #include "stat.h" #include "vmm.h" @@ -2763,8 +2760,5 @@ static void socket_syscall_dispatch(struct registers* regs, uint32_t syscall_no) } void syscall_init(void) { -#if defined(__i386__) - register_interrupt_handler(128, syscall_handler); - x86_sysenter_init(); -#endif + arch_syscall_init(); } -- 2.43.0