diff options
-rw-r--r-- | StdLib/Include/sys/termios.h | 6 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/Devices/Console/daConsole.c | 207 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/InteractiveIO/CanonRead.c | 8 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h | 6 | ||||
-rw-r--r-- | StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c | 4 | ||||
-rw-r--r-- | StdLibPrivateInternalFiles/Include/Device/Console.h | 4 |
6 files changed, 149 insertions, 86 deletions
diff --git a/StdLib/Include/sys/termios.h b/StdLib/Include/sys/termios.h index e144d52..671a5c0 100644 --- a/StdLib/Include/sys/termios.h +++ b/StdLib/Include/sys/termios.h @@ -2,7 +2,7 @@ Macros and declarations for terminal oriented ioctls and
I/O discipline.
- Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
@@ -421,6 +421,8 @@ typedef enum { } TtyFunKey;
// Non-UEFI character definitions
-#define CHAR_EOT 0x0004 /* End of Text (EOT) character */
+#define CHAR_EOT 0x0004 /* End of Text (EOT) character -- Unix End-of-File character */
+#define CHAR_SUB 0x001a /* MSDOS End-of-File character */
+#define CHAR_ESC 0x001b /* Escape (ESC) character */
#endif /* !_SYS_TERMIOS_H_ */
diff --git a/StdLib/LibC/Uefi/Devices/Console/daConsole.c b/StdLib/LibC/Uefi/Devices/Console/daConsole.c index 927ec94..1f40177 100644 --- a/StdLib/LibC/Uefi/Devices/Console/daConsole.c +++ b/StdLib/LibC/Uefi/Devices/Console/daConsole.c @@ -10,7 +10,7 @@ The devices status as a wide device is indicatd by _S_IWTTY being set in
f_iflags.
- Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
@@ -24,6 +24,7 @@ #include <Library/BaseLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/SimpleTextOut.h>
@@ -35,6 +36,7 @@ #include <stdarg.h>
#include <sys/fcntl.h>
#include <unistd.h>
+#include <sys/termios.h>
#include <kfile.h>
#include <Device/Device.h>
#include <Device/IIO.h>
@@ -238,7 +240,6 @@ da_ConWrite( // Depending on status, update BufferSize and return
if(!RETURN_ERROR(Status)) {
- //BufferSize = NumChar;
NumChar = BufferSize;
Stream->NumWritten += NumChar;
}
@@ -248,11 +249,83 @@ da_ConWrite( /** Read a wide character from the console input device.
+ Returns NUL or a translated input character.
+
+ @param[in] filp Pointer to file descriptor for this file.
+ @param[out] Buffer Buffer in which to place the read character.
+
+ @retval EFI_DEVICE_ERROR A hardware error has occurred.
+ @retval EFI_NOT_READY No data is available. Try again later.
+ @retval EFI_SUCCESS One wide character has been placed in Character
+ - 0x0000 NUL, ignore this
+ - Otherwise, should be a good wide character in Character
+**/
+static
+EFI_STATUS
+da_ConRawRead (
+ IN OUT struct __filedes *filp,
+ OUT wchar_t *Character
+)
+{
+ EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Proto;
+ ConInstance *Stream;
+ cIIO *Self;
+ EFI_STATUS Status;
+ EFI_INPUT_KEY Key = {0,0};
+ wchar_t RetChar;
+
+ Self = (cIIO *)filp->devdata;
+ Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
+ Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;
+
+ if(Stream->UnGetKey == CHAR_NULL) {
+ Status = Proto->ReadKeyStroke(Proto, &Key);
+ }
+ else {
+ Status = EFI_SUCCESS;
+ // Use the data in the Un-get buffer
+ // Guaranteed that ScanCode and UnicodeChar are not both NUL
+ Key.ScanCode = SCAN_NULL;
+ Key.UnicodeChar = Stream->UnGetKey;
+ Stream->UnGetKey = CHAR_NULL;
+ }
+ if(Status == EFI_SUCCESS) {
+ // Translate the Escape Scan Code to an ESC character
+ if (Key.ScanCode != 0) {
+ if (Key.ScanCode == SCAN_ESC) {
+ RetChar = CHAR_ESC;
+ }
+ else if((Self->Termio.c_iflag & IGNSPEC) != 0) {
+ // If we are ignoring special characters, return a NUL
+ RetChar = 0;
+ }
+ else {
+ // Must be a control, function, or other non-printable key.
+ // Map it into the Platform portion of the Unicode private use area
+ RetChar = TtyFunKeyMax - Key.ScanCode;
+ }
+ }
+ else {
+ RetChar = Key.UnicodeChar;
+ }
+ *Character = RetChar;
+ }
+ else {
+ *Character = 0;
+ }
+ return Status;
+}
+
+/** Read a wide character from the console input device.
+
NOTE: The UEFI Console is a wide device, _S_IWTTY, so characters returned
by da_ConRead are WIDE characters. It is the responsibility of the
higher-level function(s) to perform any necessary conversions.
- @param[in,out] BufferSize Number of characters in Buffer.
+ A NUL character, 0x0000, is never returned. In the event that such a character
+ is encountered, the read is either retried or -1 is returned with errno set
+ to EAGAIN.
+
@param[in] filp Pointer to file descriptor for this file.
@param[in] offset Ignored.
@param[in] BufferSize Buffer size, in bytes.
@@ -274,79 +347,63 @@ da_ConRead( {
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *Proto;
ConInstance *Stream;
- cIIO *Self;
- EFI_INPUT_KEY Key = {0,0};
- EFI_STATUS Status = RETURN_SUCCESS;
+ //cIIO *Self;
+ EFI_STATUS Status;
UINTN Edex;
ssize_t NumRead;
- int Flags;
- wchar_t RetChar; // Default to No Data
+ BOOLEAN BlockingMode;
+ wchar_t RetChar;
NumRead = -1;
if(BufferSize < sizeof(wchar_t)) {
errno = EINVAL; // Buffer is too small to hold one character
}
else {
- Self = (cIIO *)filp->devdata;
- Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
- Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;
- Flags = filp->Oflags;
- if((Stream->UnGetKey.UnicodeChar == CHAR_NULL) && (Stream->UnGetKey.ScanCode == SCAN_NULL)) {
- // No data pending in the Un-get buffer. Get a char from the hardware.
- if((Flags & O_NONBLOCK) == 0) {
+ Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);
+ Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;
+ BlockingMode = ((filp->Oflags & O_NONBLOCK) == 0);
+
+ do {
+ Status = EFI_SUCCESS;
+ if(BlockingMode) {
// Read a byte in Blocking mode
- Status = gBS->WaitForEvent( 1, &Proto->WaitForKey, &Edex);
- EFIerrno = Status;
- if(Status != EFI_SUCCESS) {
- errno = EINVAL;
- }
- else {
- Status = Proto->ReadKeyStroke(Proto, &Key);
- if(Status == EFI_SUCCESS) {
- NumRead = 1; // Indicate that Key holds the data
- }
- else {
- errno = EIO;
- }
- }
- }
- else {
- // Read a byte in Non-Blocking mode
- Status = Proto->ReadKeyStroke(Proto, &Key);
- EFIerrno = Status;
- if(Status == EFI_SUCCESS) {
- // Got a keystroke.
- NumRead = 1; // Indicate that Key holds the data
- }
- else if(Status == EFI_NOT_READY) {
- // Keystroke data is not available
- errno = EAGAIN;
- }
- else {
- // Hardware error
- errno = EIO;
- }
+ Status = gBS->WaitForEvent( 1, &Proto->WaitForKey, &Edex);
}
+
+ /* WaitForEvent should not be able to fail since
+ NumberOfEvents is set to constant 1 so is never 0
+ Event is set by the Simple Text Input protocol so should never be EVT_NOTIFY_SIGNAL
+ Current TPL should be TPL_APPLICATION.
+ ASSERT so that we catch any problems during development.
+ */
+ ASSERT(Status == EFI_SUCCESS);
+
+ Status = da_ConRawRead (filp, &RetChar);
+ } while ( BlockingMode &&
+ (RetChar == 0) &&
+ (Status != EFI_DEVICE_ERROR));
+
+ EFIerrno = Status;
+ if(Status == EFI_SUCCESS) {
+ // Got a keystroke.
+ NumRead = 1; // Indicate that Key holds the data
+ }
+ else if(Status == EFI_NOT_READY) {
+ // Keystroke data is not available
+ errno = EAGAIN;
}
else {
- // Use the data in the Un-get buffer
- Key.ScanCode = Stream->UnGetKey.ScanCode;
- Key.UnicodeChar = Stream->UnGetKey.UnicodeChar;
- Stream->UnGetKey.ScanCode = SCAN_NULL;
- Stream->UnGetKey.UnicodeChar = CHAR_NULL;
- NumRead = 1; // Indicate that Key holds the data
+ // Hardware error
+ errno = EIO;
}
- // If we have data, prepare it for return.
- if(NumRead == 1) {
- RetChar = Key.UnicodeChar;
- if((RetChar == 0) && ((Self->Termio.c_iflag & IGNSPEC) == 0)) {
- // Must be a control, function, or other non-printable key.
- // Map it into the Platform portion of the Unicode private use area
- RetChar = (Key.ScanCode == 0) ? 0 : 0xF900U - Key.ScanCode;
- }
+ if (RetChar == 0) {
+ NumRead = -1;
+ errno = EAGAIN;
+ }
+ else {
*((wchar_t *)Buffer) = RetChar;
- }
}
+ }
return NumRead;
}
@@ -542,24 +599,23 @@ da_ConPoll( return POLLNVAL; // Looks like a bad filp pointer
}
if(Stream->InstanceNum == 0) {
- // Only input is supported for this device
+ // STDIN: Only input is supported for this device
Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;
- if((Stream->UnGetKey.UnicodeChar == CHAR_NULL) && (Stream->UnGetKey.ScanCode == SCAN_NULL)) {
- Status = Proto->ReadKeyStroke(Proto, &Stream->UnGetKey);
- if(Status == RETURN_SUCCESS) {
- RdyMask = POLLIN;
- if(Stream->UnGetKey.UnicodeChar != CHAR_NULL) {
- RdyMask |= POLLRDNORM;
- }
- }
- else {
- Stream->UnGetKey.ScanCode = SCAN_NULL;
- Stream->UnGetKey.UnicodeChar = CHAR_NULL;
+ Status = da_ConRawRead (filp, &Stream->UnGetKey);
+ if(Status == RETURN_SUCCESS) {
+ RdyMask = POLLIN;
+ if ((Stream->UnGetKey < TtyFunKeyMin) ||
+ (Stream->UnGetKey >= TtyFunKeyMax))
+ {
+ RdyMask |= POLLRDNORM;
}
}
+ else {
+ Stream->UnGetKey = CHAR_NULL;
+ }
}
else if(Stream->InstanceNum < NUM_SPECIAL) { // Not 0, is it 1 or 2?
- // Only output is supported for this device
+ // (STDOUT || STDERR): Only output is supported for this device
RdyMask = POLLOUT;
}
else {
@@ -638,8 +694,7 @@ __Cons_construct( Stream->NumRead = 0;
Stream->NumWritten = 0;
- Stream->UnGetKey.ScanCode = SCAN_NULL;
- Stream->UnGetKey.UnicodeChar = CHAR_NULL;
+ Stream->UnGetKey = CHAR_NULL;
if(Stream->Dev == NULL) {
continue; // No device for this stream.
diff --git a/StdLib/LibC/Uefi/InteractiveIO/CanonRead.c b/StdLib/LibC/Uefi/InteractiveIO/CanonRead.c index db6af6e..8c8e076 100644 --- a/StdLib/LibC/Uefi/InteractiveIO/CanonRead.c +++ b/StdLib/LibC/Uefi/InteractiveIO/CanonRead.c @@ -3,7 +3,7 @@ The functions assume that isatty() is TRUE at the time they are called.
- Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
@@ -87,6 +87,10 @@ IIO_CanonRead ( // Input and process characters until BufferSize is exhausted.
do {
InChar = IIO_GetInChar(filp, FirstRead);
+ if (InChar == WEOF) {
+ NumRead = 0;
+ break;
+ }
FirstRead = FALSE;
Activate = TRUE;
if(InChar == CHAR_CARRIAGE_RETURN) {
@@ -128,6 +132,8 @@ IIO_CanonRead ( }
else if(CCEQ(Termio->c_cc[VEOF], InChar)) {
InChar = WEOF;
+ NumRead = 0;
+ EchoIsOK = FALSE; // Buffer, but don't echo this character
}
else if(CCEQ(Termio->c_cc[VEOL], InChar)) {
EchoIsOK = FALSE; // Buffer, but don't echo this character
diff --git a/StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h b/StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h index 69d040a..068a720 100644 --- a/StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h +++ b/StdLib/LibC/Uefi/InteractiveIO/IIOechoCtrl.h @@ -1,7 +1,7 @@ /** @file
Constants and declarations for the Echo function.
- Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
@@ -18,10 +18,10 @@ __BEGIN_DECLS /* These constants are assigned values within the Unicode Private Use range.
The value of IIO_ECHO_MIN must be adjusted to ensure that IIO_ECHO_MAX
- never exceeds the value of 0xF900.
+ never exceeds the value of (TtyFunKeyMin - 1).
*/
typedef enum {
- IIO_ECHO_MIN = (TtyFunKeyMin - 3),
+ IIO_ECHO_MIN = (TtySpecKeyMin),
IIO_ECHO_DISCARD = IIO_ECHO_MIN, // Ignore this character completely
IIO_ECHO_ERASE, // Erase previous character
IIO_ECHO_KILL, // Kill the entire line
diff --git a/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c b/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c index 1c978ea..0e80ff0 100644 --- a/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c +++ b/StdLib/LibC/Uefi/InteractiveIO/IIOutilities.c @@ -3,7 +3,7 @@ The functions assume that isatty() is TRUE at the time they are called.
- Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
@@ -104,7 +104,7 @@ IIO_GetInChar ( else {
RetVal = (wint_t)InChar;
}
- return InChar;
+ return RetVal;
}
/** Get the current cursor position.
diff --git a/StdLibPrivateInternalFiles/Include/Device/Console.h b/StdLibPrivateInternalFiles/Include/Device/Console.h index 9b4eb52..dce2630 100644 --- a/StdLibPrivateInternalFiles/Include/Device/Console.h +++ b/StdLibPrivateInternalFiles/Include/Device/Console.h @@ -1,7 +1,7 @@ /** @file
Declarations and macros for the console abstraction.
- Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
@@ -32,8 +32,8 @@ typedef struct { UINTN Reserved_1; // Ensure that next member starts on an 8-byte boundary
UINT64 NumRead; ///< Number of characters Read.
UINT64 NumWritten; ///< Number of characters Written.
- EFI_INPUT_KEY UnGetKey; ///< One-key pushback, for poll().
__mbstate_t CharState; ///< Character state for the byte stream passing through this device
+ CHAR16 UnGetKey; ///< One-key pushback, for poll().
} ConInstance;
__BEGIN_DECLS
|