From 197419ed4305607dae3a3f041246ca30c9f9b83c Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Thu, 12 Feb 2026 03:25:39 -0300 Subject: [PATCH] fix: add timeout to UART busy-wait in hal_uart_putc() 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hal/x86/uart.c b/src/hal/x86/uart.c index eafea8d2..f45845b4 100644 --- a/src/hal/x86/uart.c +++ b/src/hal/x86/uart.c @@ -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); } -- 2.43.0