From 0a187107e7004389e4b43d8ace038b5d6ea60600 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 13 Jun 2011 18:25:08 +0000 Subject: [PATCH] arch_debug_serial_[try_]getchar(): Look at the line status we read a bit closer before assuming we have data. If the I/O port isn't valid (e.g. because there is no serial port) 0xff seems to be a typical value to read. In that case fail. Fixes KDL input on machines without serial port -- kgetc() would always think it read something from the serial port, never trying any other input. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42153 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/arch/x86/arch_debug_console.cpp | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/system/kernel/arch/x86/arch_debug_console.cpp b/src/system/kernel/arch/x86/arch_debug_console.cpp index 9972a2362e..8309a9967b 100644 --- a/src/system/kernel/arch/x86/arch_debug_console.cpp +++ b/src/system/kernel/arch/x86/arch_debug_console.cpp @@ -324,7 +324,14 @@ arch_debug_blue_screen_getchar(void) int arch_debug_serial_try_getchar(void) { - if ((in8(sSerialBasePort + SERIAL_LINE_STATUS) & 0x1) == 0) + uint8 lineStatus = in8(sSerialBasePort + SERIAL_LINE_STATUS); + if (lineStatus == 0xff) { + // The "data available" bit is set, but also all error bits. Likely we + // don't have a valid I/O port. + return -1; + } + + if ((lineStatus & 0x1) == 0) return -1; return in8(sSerialBasePort + SERIAL_RECEIVE_BUFFER); @@ -334,8 +341,19 @@ arch_debug_serial_try_getchar(void) char arch_debug_serial_getchar(void) { - while ((in8(sSerialBasePort + SERIAL_LINE_STATUS) & 0x1) == 0) - asm volatile ("pause;"); + while (true) { + uint8 lineStatus = in8(sSerialBasePort + SERIAL_LINE_STATUS); + if (lineStatus == 0xff) { + // The "data available" bit is set, but also all error bits. Likely + // we don't have a valid I/O port. + return 0; + } + + if ((lineStatus & 0x1) != 0) + break; + + PAUSE(); + } return in8(sSerialBasePort + SERIAL_RECEIVE_BUFFER); }