]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
fix: add timeout to UART busy-wait in hal_uart_putc()
authorTulio A M Mendes <[email protected]>
Thu, 12 Feb 2026 06:25:39 +0000 (03:25 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 02:44:55 +0000 (23:44 -0300)
The UART transmit loop now gives up after ~100k iterations instead
of spinning forever. This prevents the kernel from hanging with
the console spinlock held if the UART hardware is unresponsive,
which would otherwise deadlock all CPUs attempting kprintf (including
panic and debug output paths).

src/hal/x86/uart.c

index eafea8d29128154f61517e7bbe88edebd2d2d9fd..f45845b4acba3b0c04abda7ecf7ae714164e13be 100644 (file)
@@ -25,6 +25,7 @@ void hal_uart_init(void) {
 }
 
 void hal_uart_putc(char c) {
-    while ((inb(UART_BASE + 5) & 0x20) == 0) { }
+    int timeout = 100000;
+    while ((inb(UART_BASE + 5) & 0x20) == 0 && --timeout > 0) { }
     outb(UART_BASE, (uint8_t)c);
 }