From 8debc64b83ea1517fc3616ec281e4751dc44165a 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 2a6f8bb3..07cbe946 100644 --- a/include/arch_syscall.h +++ b/include/arch_syscall.h @@ -51,4 +51,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 265e1bd7..01a68880 100644 --- a/src/arch/x86/sysenter_init.c +++ b/src/arch/x86/sysenter_init.c @@ -8,6 +8,7 @@ */ #include "hal/cpu_features.h" +#include "interrupts.h" #include "console.h" #include @@ -38,7 +39,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 d554db70..6b1b9b4b 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -25,9 +25,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" @@ -2772,8 +2769,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