]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
fix: replace x86 'cli; hlt' asm in syscall.c with HAL calls
authorTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 04:58:10 +0000 (01:58 -0300)
committerTulio A M Mendes <[email protected]>
Tue, 10 Feb 2026 04:58:10 +0000 (01:58 -0300)
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
src/hal/x86/cpu.c
src/kernel/syscall.c

index c7812b025a49e7ee75d8debc7da46a81df5fad06..3fee40cca015b489cddefd3ec4635ec10be81dfa 100644 (file)
@@ -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
index 36252d8c4f22724e89bef7feb62481c7d7b8f16c..718fbfcc64d4f8f16a6b67490de1a234f9a3cb2b 100644 (file)
@@ -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) {
 }
 
index 447f6f0f27294ccd966f4f1d1bc764a79d2cfc8f..b484440ed49bad603dcf0429d1f0838cb6e2aa86 100644 (file)
@@ -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();
         }
     }