summaryrefslogtreecommitdiffstats
path: root/EmulatorPkg
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2018-08-23 13:13:21 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2018-08-27 15:20:52 +0800
commit5601e90d5cdbc4cea748e00e34ae07ce39bd700f (patch)
tree359d5743a49eafd921fdbf5b43d2ba928ae6ea55 /EmulatorPkg
parent0d9b5c461a311a1001192a01084ec579510b2048 (diff)
downloadedk2-5601e90d5cdbc4cea748e00e34ae07ce39bd700f.tar.gz
edk2-5601e90d5cdbc4cea748e00e34ae07ce39bd700f.tar.bz2
edk2-5601e90d5cdbc4cea748e00e34ae07ce39bd700f.zip
EmulatorPkg/Win: Enable native OS console as firmware console
The patch implements Stdin/Stdout/Stderr access so that the native OS console (cmd.exe) can be used as the firmware console and debug message can also be routed to it. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com> Cc: Andrew Fish <afish@apple.com>
Diffstat (limited to 'EmulatorPkg')
-rw-r--r--EmulatorPkg/Win/Host/WinThunk.c109
1 files changed, 105 insertions, 4 deletions
diff --git a/EmulatorPkg/Win/Host/WinThunk.c b/EmulatorPkg/Win/Host/WinThunk.c
index 5ec5d439d4..69a61258f3 100644
--- a/EmulatorPkg/Win/Host/WinThunk.c
+++ b/EmulatorPkg/Win/Host/WinThunk.c
@@ -42,7 +42,19 @@ SecWriteStdErr (
IN UINTN NumberOfBytes
)
{
- return 0;
+ BOOL Success;
+ DWORD CharCount;
+
+ CharCount = (DWORD)NumberOfBytes;
+ Success = WriteFile (
+ GetStdHandle (STD_ERROR_HANDLE),
+ Buffer,
+ CharCount,
+ &CharCount,
+ NULL
+ );
+
+ return Success ? CharCount : 0;
}
@@ -51,7 +63,32 @@ SecConfigStdIn (
VOID
)
{
- return EFI_SUCCESS;
+ BOOL Success;
+ DWORD Mode;
+
+ Success = GetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), &Mode);
+ if (Success) {
+ //
+ // Disable buffer (line input), echo, mouse, window
+ //
+ Success = SetConsoleMode (
+ GetStdHandle (STD_INPUT_HANDLE),
+ Mode | ENABLE_VIRTUAL_TERMINAL_INPUT & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT)
+ );
+ }
+ if (Success) {
+ //
+ // Enable terminal mode
+ //
+ Success = GetConsoleMode (GetStdHandle (STD_OUTPUT_HANDLE), &Mode);
+ if (Success) {
+ Success = SetConsoleMode (
+ GetStdHandle (STD_OUTPUT_HANDLE),
+ Mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN
+ );
+ }
+ }
+ return Success ? EFI_SUCCESS : EFI_DEVICE_ERROR;
}
UINTN
@@ -60,7 +97,19 @@ SecWriteStdOut (
IN UINTN NumberOfBytes
)
{
- return 0;
+ BOOL Success;
+ DWORD CharCount;
+
+ CharCount = (DWORD)NumberOfBytes;
+ Success = WriteFile (
+ GetStdHandle (STD_OUTPUT_HANDLE),
+ Buffer,
+ CharCount,
+ &CharCount,
+ NULL
+ );
+
+ return Success ? CharCount : 0;
}
BOOLEAN
@@ -68,6 +117,38 @@ SecPollStdIn (
VOID
)
{
+ BOOL Success;
+ INPUT_RECORD Record;
+ DWORD RecordNum;
+
+ do {
+ Success = GetNumberOfConsoleInputEvents (GetStdHandle (STD_INPUT_HANDLE), &RecordNum);
+ if (!Success || (RecordNum == 0)) {
+ break;
+ }
+ Success = PeekConsoleInput (
+ GetStdHandle (STD_INPUT_HANDLE),
+ &Record,
+ 1,
+ &RecordNum
+ );
+ if (Success && (RecordNum == 1)) {
+ if (Record.EventType == KEY_EVENT && Record.Event.KeyEvent.bKeyDown) {
+ return TRUE;
+ } else {
+ //
+ // Consume the non-key event.
+ //
+ Success = ReadConsoleInput (
+ GetStdHandle (STD_INPUT_HANDLE),
+ &Record,
+ 1,
+ &RecordNum
+ );
+ }
+ }
+ } while (Success);
+
return FALSE;
}
@@ -77,7 +158,27 @@ SecReadStdIn (
IN UINTN NumberOfBytes
)
{
- return 0;
+ BOOL Success;
+ INPUT_RECORD Record;
+ DWORD RecordNum;
+ UINTN BytesReturn;
+
+ if (!SecPollStdIn ()) {
+ return 0;
+ }
+ Success = ReadConsoleInput (
+ GetStdHandle (STD_INPUT_HANDLE),
+ &Record,
+ 1,
+ &RecordNum
+ );
+ ASSERT (Success && (RecordNum == 1) && (Record.EventType == KEY_EVENT) && (Record.Event.KeyEvent.bKeyDown));
+ NumberOfBytes = MIN (Record.Event.KeyEvent.wRepeatCount, NumberOfBytes);
+ BytesReturn = NumberOfBytes;
+ while (NumberOfBytes-- != 0) {
+ Buffer[NumberOfBytes] = Record.Event.KeyEvent.uChar.AsciiChar;
+ }
+ return BytesReturn;
}