From: Tulio A M Mendes Date: Tue, 10 Feb 2026 04:58:10 +0000 (-0300) Subject: fix: replace x86 'cli; hlt' asm in syscall.c with HAL calls X-Git-Url: https://projects.tadryanom.me/docs/POSIX_ROADMAP.md?a=commitdiff_plain;h=a8b4dfae4d71cb5b44fa4ce6c6681c3690e37b31;p=AdrOS.git 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. --- diff --git a/include/hal/cpu.h b/include/hal/cpu.h index c7812b0..3fee40c 100644 --- a/include/hal/cpu.h +++ b/include/hal/cpu.h @@ -10,6 +10,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 36252d8..718fbfc 100644 --- a/src/hal/x86/cpu.c +++ b/src/hal/x86/cpu.c @@ -40,6 +40,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"); } @@ -65,6 +69,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 447f6f0..b484440 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -1671,7 +1671,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(); } }