From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Hao A Wu <hao.a.wu@intel.com>, Andrew Fish <afish@apple.com>
Subject: [PATCH 04/12] EmulatorPkg/Win: Enable native OS console as firmware console
Date: Thu, 23 Aug 2018 17:52:07 +0800 [thread overview]
Message-ID: <20180823095215.274248-5-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20180823095215.274248-1-ruiyu.ni@intel.com>
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>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Andrew Fish <afish@apple.com>
---
EmulatorPkg/Win/Host/WinThunk.c | 109 ++++++++++++++++++++++++++++++++++++++--
1 file 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;
}
--
2.16.1.windows.1
next prev parent reply other threads:[~2018-08-23 9:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-23 9:52 [PATCH 00/12] Add WinHost support in EmulatorPkg Ruiyu Ni
2018-08-23 9:52 ` [PATCH 01/12] EmulatorPkg/ThunkProtocolList: Fix VS build failure Ruiyu Ni
2018-08-23 9:52 ` [PATCH 02/12] EmulatorPkg/Win: Add Windows host support Ruiyu Ni
2018-08-23 9:52 ` [PATCH 03/12] EmulatorPkg/Win: Enable source level debugging Ruiyu Ni
2018-08-23 9:52 ` Ruiyu Ni [this message]
2018-08-23 9:52 ` [PATCH 05/12] EmulatorPkg/Win: Add input/output support Ruiyu Ni
2018-08-23 9:52 ` [PATCH 06/12] EmulatorPkg/Win: Add timer and interrupt support Ruiyu Ni
2018-08-23 9:52 ` [PATCH 07/12] EmulatorPkg/Win: Add RTC support Ruiyu Ni
2018-08-23 9:52 ` [PATCH 08/12] EmulatorPkg/Win: Add SimpleFileSystem support Ruiyu Ni
2018-08-23 9:52 ` [PATCH 09/12] EmulatorPkg/Win: Add BlockIo support Ruiyu Ni
2018-08-23 9:52 ` [PATCH 10/12] EmulatorPkg/PlatformBds: Signal EndOfDxe in platform BDS Ruiyu Ni
2018-08-23 9:52 ` [PATCH 11/12] EmulatorPkg/EmuFileSystem: Fix a bug that causes Close() assertion Ruiyu Ni
2018-08-23 9:52 ` [PATCH 12/12] EmulatorPkg/DSC: Remove FS mapping to EDK Shell bin directory Ruiyu Ni
2018-08-23 9:56 ` [PATCH 00/12] Add WinHost support in EmulatorPkg Ni, Ruiyu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180823095215.274248-5-ruiyu.ni@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox