From 8ce912ef039c4e5a3d6d7b49af03e6392bfa1858 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Fri, 2 Jun 2017 20:13:09 +0200 Subject: [PATCH] before writing to UART, check if the fifo is free --- arch/x86/kernel/uart.c | 10 ++++++++++ arch/x86/loader/uart.c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/arch/x86/kernel/uart.c b/arch/x86/kernel/uart.c index 1962b885d..7631dc88e 100644 --- a/arch/x86/kernel/uart.c +++ b/arch/x86/kernel/uart.c @@ -111,8 +111,18 @@ static inline unsigned char read_from_uart(uint32_t off) return c; } +static inline int is_transmit_empty(void) +{ + if (uartport) + return inportb(uartport + UART_LSR) & 0x20; + + return 1; +} + static inline void write_to_uart(uint32_t off, unsigned char c) { + while (is_transmit_empty() == 0) { PAUSE; } + if (uartport) outportb(uartport + off, c); } diff --git a/arch/x86/loader/uart.c b/arch/x86/loader/uart.c index 3130260ba..8141a61a6 100644 --- a/arch/x86/loader/uart.c +++ b/arch/x86/loader/uart.c @@ -104,8 +104,18 @@ static inline unsigned char read_from_uart(uint32_t off) return c; } +static inline int is_transmit_empty(void) +{ + if (uartport) + return inportb(uartport + UART_LSR) & 0x20; + + return 1; +} + static void write_to_uart(uint32_t off, unsigned char c) { + while (is_transmit_empty() == 0) ; + if (uartport) outportb(uartport + off, c); }