Skip to content

Commit ddddaa1

Browse files
committed
fix: Add timeout to write_serial to prevent hang on hardware without COM1
The while loop waiting for TX buffer ready would hang forever if COM1 doesn't exist. Added 10000 iteration timeout - silently skips if reached.
1 parent 02ef994 commit ddddaa1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

esp/EFI/BOOT/BOOTX64.EFI

-2 KB
Binary file not shown.

src/drivers/console.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,20 @@ pub fn is_data_ready() -> bool {
6161
}
6262

6363
/// Write a byte to serial port (for stdout output)
64+
/// Has timeout to prevent hanging on hardware without COM1
6465
pub fn write_serial(byte: u8) {
6566
unsafe {
6667
let mut port_lsr = Port::<u8>::new(COM1 + 5);
67-
// Wait for transmit buffer to be empty
68-
while port_lsr.read() & 0x20 == 0 {}
69-
let mut port_data = Port::<u8>::new(COM1);
70-
port_data.write(byte);
68+
// Wait for transmit buffer to be empty (with timeout)
69+
let mut timeout = 10000u32;
70+
while port_lsr.read() & 0x20 == 0 && timeout > 0 {
71+
timeout -= 1;
72+
}
73+
if timeout > 0 {
74+
let mut port_data = Port::<u8>::new(COM1);
75+
port_data.write(byte);
76+
}
77+
// If timeout reached, silently skip (no COM1 available)
7178
}
7279
}
80+

0 commit comments

Comments
 (0)