28#if defined (NTDDI_VERSION) && defined (NTDDI_WIN10_TH2) && (NTDDI_VERSION > NTDDI_WIN10_TH2)
29STATIC DWORD mOldStdOutMode;
32STATIC UINT64 mPerformanceFrequency = 0;
43 CharCount = (DWORD)NumberOfBytes;
45 GetStdHandle (STD_ERROR_HANDLE),
52 return Success ? CharCount : 0;
63 Success = GetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), &Mode);
65 if (!mEmulatorStdInConfigured) {
75 Mode &= ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT);
77 #if defined (NTDDI_VERSION) && defined (NTDDI_WIN10_TH2) && (NTDDI_VERSION > NTDDI_WIN10_TH2)
81 Mode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
84 Success = SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), Mode);
87 #if defined (NTDDI_VERSION) && defined (NTDDI_WIN10_TH2) && (NTDDI_VERSION > NTDDI_WIN10_TH2)
92 Success = GetConsoleMode (GetStdHandle (STD_OUTPUT_HANDLE), &Mode);
93 if (!mEmulatorStdInConfigured) {
97 mOldStdOutMode = Mode;
101 Success = SetConsoleMode (
102 GetStdHandle (STD_OUTPUT_HANDLE),
103 Mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN
110 mEmulatorStdInConfigured =
TRUE;
125 CharCount = (DWORD)NumberOfBytes;
126 Success = WriteFile (
127 GetStdHandle (STD_OUTPUT_HANDLE),
134 return Success ? CharCount : 0;
147 Success = GetNumberOfConsoleInputEvents (GetStdHandle (STD_INPUT_HANDLE), &RecordNum);
148 if (!Success || (RecordNum == 0)) {
152 Success = PeekConsoleInput (
153 GetStdHandle (STD_INPUT_HANDLE),
158 if (Success && (RecordNum == 1)) {
159 if ((Record.EventType == KEY_EVENT) && Record.Event.KeyEvent.bKeyDown) {
165 Success = ReadConsoleInput (
166 GetStdHandle (STD_INPUT_HANDLE),
189 if (!SecPollStdIn ()) {
193 Success = ReadConsoleInput (
194 GetStdHandle (STD_INPUT_HANDLE),
199 ASSERT (Success && (RecordNum == 1) && (Record.EventType == KEY_EVENT) && (Record.Event.KeyEvent.bKeyDown));
200 NumberOfBytes =
MIN (Record.Event.KeyEvent.wRepeatCount, NumberOfBytes);
201 BytesReturn = NumberOfBytes;
202 while (NumberOfBytes-- != 0) {
203 Buffer[NumberOfBytes] = Record.Event.KeyEvent.uChar.AsciiChar;
214 return malloc ((
size_t)Size);
222 if (EfiSystemMemoryRange (Ptr)) {
236BOOLEAN mCancelTimerThread =
FALSE;
241EMU_SET_TIMER_CALLBACK *mTimerNotifyFunction =
NULL;
246HANDLE mNtMainThreadHandle;
257CRITICAL_SECTION mNtCriticalSection;
262UINT mMMTimerThreadID = 0;
264volatile BOOLEAN mInterruptEnabled =
FALSE;
279 if (!mCancelTimerThread) {
286 EnterCriticalSection (&mNtCriticalSection);
287 SuspendThread (mNtMainThreadHandle);
294 if (mCancelTimerThread) {
295 ResumeThread (mNtMainThreadHandle);
296 LeaveCriticalSection (&mNtCriticalSection);
297 timeKillEvent (wTimerID);
298 mMMTimerThreadID = 0;
302 while (!mInterruptEnabled) {
306 ResumeThread (mNtMainThreadHandle);
307 LeaveCriticalSection (&mNtCriticalSection);
312 while (!mInterruptEnabled) {
319 EnterCriticalSection (&mNtCriticalSection);
320 SuspendThread (mNtMainThreadHandle);
326 CurrentTick = GetTickCount ();
327 Delta = CurrentTick - mNtLastTick;
328 mNtLastTick = CurrentTick;
338 if (mTimerNotifyFunction !=
NULL) {
339 mTimerNotifyFunction (Delta);
346 ResumeThread (mNtMainThreadHandle);
347 LeaveCriticalSection (&mNtCriticalSection);
349 timeKillEvent (wTimerID);
350 mMMTimerThreadID = 0;
356 IN UINT64 TimerPeriod,
357 IN EMU_SET_TIMER_CALLBACK Callback
363 if (TimerPeriod == 0) {
367 EnterCriticalSection (&mNtCriticalSection);
369 mCancelTimerThread =
TRUE;
371 LeaveCriticalSection (&mNtCriticalSection);
377 if (mMMTimerThreadID != 0) {
378 timeKillEvent (mMMTimerThreadID);
379 mMMTimerThreadID = 0;
385 EnterCriticalSection (&mNtCriticalSection);
387 mCancelTimerThread =
FALSE;
389 LeaveCriticalSection (&mNtCriticalSection);
394 mNtLastTick = GetTickCount ();
396 if (mMMTimerThreadID) {
397 timeKillEvent (mMMTimerThreadID);
402 THREAD_PRIORITY_HIGHEST
405 mMMTimerThreadID = timeSetEvent (
410 TIME_PERIODIC | TIME_KILL_SYNCHRONOUS | TIME_CALLBACK_FUNCTION
414 mTimerNotifyFunction = Callback;
422 InitializeCriticalSection (&mNtCriticalSection);
425 GetCurrentProcess (),
427 GetCurrentProcess (),
428 &mNtMainThreadHandle,
431 DUPLICATE_SAME_ACCESS
440 mInterruptEnabled =
TRUE;
448 mInterruptEnabled =
FALSE;
452SecQueryPerformanceFrequency (
456 if (mPerformanceFrequency) {
457 return mPerformanceFrequency;
460 QueryPerformanceFrequency ((LARGE_INTEGER *)&mPerformanceFrequency);
462 return mPerformanceFrequency;
466SecQueryPerformanceCounter (
470 UINT64 PerformanceCount;
472 QueryPerformanceCounter ((LARGE_INTEGER *)&PerformanceCount);
474 return PerformanceCount;
479 IN UINT64 Nanoseconds
482 Sleep ((DWORD)
DivU64x32 (Nanoseconds, 1000000));
498 if (mEmulatorStdInConfigured) {
502 #if defined (NTDDI_VERSION) && defined (NTDDI_WIN10_TH2) && (NTDDI_VERSION > NTDDI_WIN10_TH2)
503 BOOL Success = SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), mOldStdInMode);
505 SetConsoleMode (GetStdHandle (STD_OUTPUT_HANDLE), mOldStdOutMode);
509 SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), mOldStdInMode);
522 SYSTEMTIME SystemTime;
523 TIME_ZONE_INFORMATION TimeZone;
525 GetLocalTime (&SystemTime);
526 GetTimeZoneInformation (&TimeZone);
528 Time->Year = (UINT16)SystemTime.wYear;
529 Time->Month = (UINT8)SystemTime.wMonth;
530 Time->Day = (UINT8)SystemTime.wDay;
531 Time->Hour = (UINT8)SystemTime.wHour;
532 Time->Minute = (UINT8)SystemTime.wMinute;
533 Time->Second = (UINT8)SystemTime.wSecond;
534 Time->Nanosecond = (UINT32)(SystemTime.wMilliseconds * 1000000);
535 Time->TimeZone = (INT16)TimeZone.Bias;
537 if (Capabilities !=
NULL) {
538 Capabilities->Resolution = 1;
539 Capabilities->Accuracy = 50000000;
540 Capabilities->SetsToZero =
FALSE;
544 if (TimeZone.StandardDate.wMonth) {
545 Time->Daylight = (UINT8)TimeZone.StandardDate.wMonth;
554 TIME_ZONE_INFORMATION TimeZone;
555 SYSTEMTIME SystemTime;
561 GetTimeZoneInformation (&TimeZone);
562 TimeZone.StandardDate.wMonth = Time->Daylight;
563 TimeZone.Bias = Time->TimeZone;
564 Flag = SetTimeZoneInformation (&TimeZone);
566 return EFI_DEVICE_ERROR;
569 SystemTime.wYear = Time->Year;
570 SystemTime.wMonth = Time->Month;
571 SystemTime.wDay = Time->Day;
572 SystemTime.wHour = Time->Hour;
573 SystemTime.wMinute = Time->Minute;
574 SystemTime.wSecond = Time->Second;
575 SystemTime.wMilliseconds = (INT16)(Time->Nanosecond / 1000000);
577 Flag = SetLocalTime (&SystemTime);
580 return EFI_DEVICE_ERROR;
595 SecPeCoffGetEntryPoint,
600 SecQueryPerformanceFrequency,
601 SecQueryPerformanceCounter,
611#pragma warning(default : 4996)
612#pragma warning(default : 4232)
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)