]> 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 943edd31ded2264b1f4f16e34c238171f633e0ee..b1ac16c207d62152344fec785e45acb76bcf756d 100644 (file)
@@ -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
index 9bda83f71009f1d5a677bec311c12085fdf61961..dfe8d216a42da6293dd825d4a6b440fdef718a08 100644 (file)
@@ -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) {
 }
 
index fcc5199e95cea9175b4f3edcd19fe4a9f05e5a46..c6b4c3f4cb6ac03d5893ce9281733f1155982835 100644 (file)
@@ -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();
         }
     }