]> 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 05458a58bd7cc4292ba6dc531db387c6a92f96ca..c256cf0fd1adcf538b77c98abcbb6442fcf38ab5 100644 (file)
@@ -16,6 +16,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);
 }