From 99219a06658557e2ae163f046c7005f4352f0f52 Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Tue, 10 Feb 2026 01:58:10 -0300 Subject: [PATCH] fix: replace x86 'cli; hlt' asm in syscall.c with HAL calls syscall.c used raw x86 inline assembly ('cli; hlt') in the exit syscall idle loop. This would not compile on ARM/RISC-V/MIPS. Add hal_cpu_disable_interrupts() to the HAL CPU interface with implementations for x86 (cli) and stubs for other architectures. Replace the raw asm with hal_cpu_disable_interrupts() + hal_cpu_idle(). Passes: make, cppcheck, QEMU smoke test. --- include/hal/cpu.h | 1 + src/hal/x86/cpu.c | 7 +++++++ src/kernel/syscall.c | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/hal/cpu.h b/include/hal/cpu.h index 943edd31..b1ac16c2 100644 --- a/include/hal/cpu.h +++ b/include/hal/cpu.h @@ -19,6 +19,7 @@ void hal_cpu_set_address_space(uintptr_t as); void hal_cpu_set_kernel_stack(uintptr_t sp_top); void hal_cpu_enable_interrupts(void); +void hal_cpu_disable_interrupts(void); void hal_cpu_idle(void); #endif diff --git a/src/hal/x86/cpu.c b/src/hal/x86/cpu.c index 9bda83f7..dfe8d216 100644 --- a/src/hal/x86/cpu.c +++ b/src/hal/x86/cpu.c @@ -49,6 +49,10 @@ void hal_cpu_enable_interrupts(void) { __asm__ volatile("sti"); } +void hal_cpu_disable_interrupts(void) { + __asm__ volatile("cli"); +} + void hal_cpu_idle(void) { __asm__ volatile("hlt"); } @@ -74,6 +78,9 @@ void hal_cpu_set_kernel_stack(uintptr_t sp_top) { void hal_cpu_enable_interrupts(void) { } +void hal_cpu_disable_interrupts(void) { +} + void hal_cpu_idle(void) { } diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index fcc5199e..c6b4c3f4 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -1680,7 +1680,8 @@ static void syscall_handler(struct registers* regs) { hal_cpu_enable_interrupts(); schedule(); for(;;) { - __asm__ volatile("cli; hlt"); + hal_cpu_disable_interrupts(); + hal_cpu_idle(); } } -- 2.43.0