3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 #include <Common/StatusCode.h>
30 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*This
,
31 IN BOOLEAN ExtendedVerification
36 Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.Reset().
37 This driver only perform dependent serial device reset regardless of
38 the value of ExtendeVerification
42 This - Indicates the calling context.
44 ExtendedVerification - Skip by this driver.
49 The reset operation succeeds.
52 The dependent serial port reset fails.
57 TERMINAL_DEV
*TerminalDevice
;
59 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
62 // Report progress code here
64 Status
= REPORT_STATUS_CODE_WITH_DEVICE_PATH (
66 EFI_PERIPHERAL_REMOTE_CONSOLE
| EFI_P_PC_RESET
,
67 TerminalDevice
->DevicePath
70 Status
= TerminalDevice
->SerialIo
->Reset (TerminalDevice
->SerialIo
);
73 // clear all the internal buffer for keys
75 InitializeRawFiFo (TerminalDevice
);
76 InitializeUnicodeFiFo (TerminalDevice
);
77 InitializeEfiKeyFiFo (TerminalDevice
);
79 if (EFI_ERROR (Status
)) {
80 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
81 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
82 EFI_PERIPHERAL_LOCAL_CONSOLE
| EFI_P_EC_CONTROLLER_ERROR
,
83 TerminalDevice
->DevicePath
92 TerminalConInReadKeyStroke (
93 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*This
,
94 OUT EFI_INPUT_KEY
*Key
99 Implements EFI_SIMPLE_TEXT_IN_PROTOCOL.ReadKeyStroke().
103 This - Indicates the calling context.
105 Key - A pointer to a buffer that is filled in with the keystroke
106 information for the key that was sent from terminal.
111 The keystroke information is returned successfully.
114 There is no keystroke data available.
117 The dependent serial device encounters error.
121 TERMINAL_DEV
*TerminalDevice
;
125 // Initialize *Key to nonsense value.
127 Key
->ScanCode
= SCAN_NULL
;
128 Key
->UnicodeChar
= 0;
130 // get TERMINAL_DEV from "This" parameter.
132 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
134 Status
= TerminalConInCheckForKey (This
);
135 if (EFI_ERROR (Status
)) {
136 return EFI_NOT_READY
;
139 EfiKeyFiFoRemoveOneKey (TerminalDevice
, Key
);
146 TranslateRawDataToEfiKey (
147 IN TERMINAL_DEV
*TerminalDevice
150 Step1: Turn raw data into Unicode (according to different encode).
151 Step2: Translate Unicode into key information.
152 (according to different terminal standard).
155 switch (TerminalDevice
->TerminalType
) {
160 AnsiRawDataToUnicode (TerminalDevice
);
161 UnicodeToEfiKey (TerminalDevice
);
166 // Process all the raw data in the RawFIFO,
167 // put the processed key into UnicodeFIFO.
169 VTUTF8RawDataToUnicode (TerminalDevice
);
172 // Translate all the Unicode data in the UnicodeFIFO to Efi key,
173 // then put into EfiKeyFIFO.
175 UnicodeToEfiKey (TerminalDevice
);
183 TerminalConInWaitForKey (
190 Event notification function for EFI_SIMPLE_TEXT_IN_PROTOCOL.WaitForKey event
191 Signal the event if there is key available
195 Event - Indicates the event that invoke this function.
197 Context - Indicates the calling context.
206 // Someone is waiting on the keystroke event, if there's
207 // a key pending, signal the event
209 // Context is the pointer to EFI_SIMPLE_TEXT_IN_PROTOCOL
211 if (!EFI_ERROR (TerminalConInCheckForKey (Context
))) {
213 gBS
->SignalEvent (Event
);
218 TerminalConInCheckForKey (
219 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*This
224 Check for a pending key in the Efi Key FIFO or Serial device buffer.
228 This - Indicates the calling context.
233 There is key pending.
236 There is no key pending.
243 TERMINAL_DEV
*TerminalDevice
;
246 EFI_SERIAL_IO_MODE
*Mode
;
247 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
248 UINTN SerialInTimeOut
;
250 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
252 SerialIo
= TerminalDevice
->SerialIo
;
253 if (SerialIo
== NULL
) {
254 return EFI_DEVICE_ERROR
;
257 // if current timeout value for serial device is not identical with
258 // the value saved in TERMINAL_DEV structure, then recalculate the
259 // timeout value again and set serial attribute according to this value.
261 Mode
= SerialIo
->Mode
;
262 if (Mode
->Timeout
!= TerminalDevice
->SerialInTimeOut
) {
265 if (Mode
->BaudRate
!= 0) {
266 SerialInTimeOut
= (1 + Mode
->DataBits
+ Mode
->StopBits
) * 2 * 1000000 / (UINTN
) Mode
->BaudRate
;
269 Status
= SerialIo
->SetAttributes (
272 Mode
->ReceiveFifoDepth
,
273 (UINT32
) SerialInTimeOut
,
275 (UINT8
) Mode
->DataBits
,
279 if (EFI_ERROR (Status
)) {
280 TerminalDevice
->SerialInTimeOut
= 0;
282 TerminalDevice
->SerialInTimeOut
= SerialInTimeOut
;
286 // check whether serial buffer is empty
288 Status
= SerialIo
->GetControl (SerialIo
, &Control
);
290 if (Control
& EFI_SERIAL_INPUT_BUFFER_EMPTY
) {
292 // Translate all the raw data in RawFIFO into EFI Key,
293 // according to different terminal type supported.
295 TranslateRawDataToEfiKey (TerminalDevice
);
298 // if there is pre-fetched Efi Key in EfiKeyFIFO buffer,
301 if (!IsEfiKeyFiFoEmpty (TerminalDevice
)) {
304 return EFI_NOT_READY
;
308 // Fetch all the keys in the serial buffer,
309 // and insert the byte stream into RawFIFO.
313 Status
= GetOneKeyFromSerial (TerminalDevice
->SerialIo
, &Input
);
315 if (EFI_ERROR (Status
)) {
316 if (Status
== EFI_DEVICE_ERROR
) {
317 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
318 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
319 EFI_PERIPHERAL_REMOTE_CONSOLE
| EFI_P_EC_INPUT_ERROR
,
320 TerminalDevice
->DevicePath
326 RawFiFoInsertOneKey (TerminalDevice
, Input
);
330 // Translate all the raw data in RawFIFO into EFI Key,
331 // according to different terminal type supported.
333 TranslateRawDataToEfiKey (TerminalDevice
);
335 if (IsEfiKeyFiFoEmpty (TerminalDevice
)) {
336 return EFI_NOT_READY
;
343 GetOneKeyFromSerial (
344 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
348 Get one key out of serial buffer.
349 If serial buffer is empty, return EFI_NOT_READY;
350 if reading serial buffer encounter error, returns EFI_DEVICE_ERROR;
351 if reading serial buffer successfully, put the fetched key to
352 the parameter "Input", and return EFI_SUCCESS.
361 Status
= SerialIo
->Read (SerialIo
, &Size
, Input
);
363 if (EFI_ERROR (Status
)) {
365 if (Status
== EFI_TIMEOUT
) {
366 return EFI_NOT_READY
;
369 return EFI_DEVICE_ERROR
;
374 return EFI_NOT_READY
;
381 RawFiFoInsertOneKey (
382 TERMINAL_DEV
*TerminalDevice
,
386 Insert one byte raw data into the Raw Data FIFO.
387 If FIFO is FULL before data insertion,
388 return FALSE, and the key is lost.
393 Tail
= TerminalDevice
->RawFiFo
.Tail
;
395 if (IsRawFiFoFull (TerminalDevice
)) {
402 TerminalDevice
->RawFiFo
.Data
[Tail
] = Input
;
404 TerminalDevice
->RawFiFo
.Tail
= (UINT8
) ((Tail
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1));
410 RawFiFoRemoveOneKey (
411 TERMINAL_DEV
*TerminalDevice
,
415 Remove one byte raw data out of the Raw Data FIFO.
416 If FIFO buffer is empty before remove operation,
422 Head
= TerminalDevice
->RawFiFo
.Head
;
424 if (IsRawFiFoEmpty (TerminalDevice
)) {
432 *Output
= TerminalDevice
->RawFiFo
.Data
[Head
];
434 TerminalDevice
->RawFiFo
.Head
= (UINT8
) ((Head
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1));
441 TERMINAL_DEV
*TerminalDevice
444 Clarify whether FIFO buffer is empty.
447 if (TerminalDevice
->RawFiFo
.Head
== TerminalDevice
->RawFiFo
.Tail
) {
456 TERMINAL_DEV
*TerminalDevice
459 Clarify whether FIFO buffer is full.
465 Tail
= TerminalDevice
->RawFiFo
.Tail
;
466 Head
= TerminalDevice
->RawFiFo
.Head
;
468 if (((Tail
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1)) == Head
) {
477 EfiKeyFiFoInsertOneKey (
478 TERMINAL_DEV
*TerminalDevice
,
482 Insert one pre-fetched key into the FIFO buffer.
483 If FIFO buffer is FULL before key insertion,
484 return FALSE, and the key is lost.
489 Tail
= TerminalDevice
->EfiKeyFiFo
.Tail
;
491 if (IsEfiKeyFiFoFull (TerminalDevice
)) {
493 // Efi Key FIFO is full
498 TerminalDevice
->EfiKeyFiFo
.Data
[Tail
] = Key
;
500 TerminalDevice
->EfiKeyFiFo
.Tail
= (UINT8
) ((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1));
506 EfiKeyFiFoRemoveOneKey (
507 TERMINAL_DEV
*TerminalDevice
,
508 EFI_INPUT_KEY
*Output
511 Remove one pre-fetched key out of the FIFO buffer.
512 If FIFO buffer is empty before remove operation,
518 Head
= TerminalDevice
->EfiKeyFiFo
.Head
;
520 if (IsEfiKeyFiFoEmpty (TerminalDevice
)) {
524 Output
->ScanCode
= SCAN_NULL
;
525 Output
->UnicodeChar
= 0;
529 *Output
= TerminalDevice
->EfiKeyFiFo
.Data
[Head
];
531 TerminalDevice
->EfiKeyFiFo
.Head
= (UINT8
) ((Head
+ 1) % (FIFO_MAX_NUMBER
+ 1));
538 TERMINAL_DEV
*TerminalDevice
541 Clarify whether FIFO buffer is empty.
544 if (TerminalDevice
->EfiKeyFiFo
.Head
== TerminalDevice
->EfiKeyFiFo
.Tail
) {
553 TERMINAL_DEV
*TerminalDevice
556 Clarify whether FIFO buffer is full.
562 Tail
= TerminalDevice
->EfiKeyFiFo
.Tail
;
563 Head
= TerminalDevice
->EfiKeyFiFo
.Head
;
565 if (((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1)) == Head
) {
574 UnicodeFiFoInsertOneKey (
575 TERMINAL_DEV
*TerminalDevice
,
579 Insert one pre-fetched key into the FIFO buffer.
580 If FIFO buffer is FULL before key insertion,
581 return FALSE, and the key is lost.
586 Tail
= TerminalDevice
->UnicodeFiFo
.Tail
;
588 if (IsUnicodeFiFoFull (TerminalDevice
)) {
590 // Unicode FIFO is full
595 TerminalDevice
->UnicodeFiFo
.Data
[Tail
] = Input
;
597 TerminalDevice
->UnicodeFiFo
.Tail
= (UINT8
) ((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1));
603 UnicodeFiFoRemoveOneKey (
604 TERMINAL_DEV
*TerminalDevice
,
608 Remove one pre-fetched key out of the FIFO buffer.
609 If FIFO buffer is empty before remove operation,
615 Head
= TerminalDevice
->UnicodeFiFo
.Head
;
617 if (IsUnicodeFiFoEmpty (TerminalDevice
)) {
625 *Output
= TerminalDevice
->UnicodeFiFo
.Data
[Head
];
627 TerminalDevice
->UnicodeFiFo
.Head
= (UINT8
) ((Head
+ 1) % (FIFO_MAX_NUMBER
+ 1));
634 TERMINAL_DEV
*TerminalDevice
637 Clarify whether FIFO buffer is empty.
640 if (TerminalDevice
->UnicodeFiFo
.Head
== TerminalDevice
->UnicodeFiFo
.Tail
) {
649 TERMINAL_DEV
*TerminalDevice
652 Clarify whether FIFO buffer is full.
658 Tail
= TerminalDevice
->UnicodeFiFo
.Tail
;
659 Head
= TerminalDevice
->UnicodeFiFo
.Head
;
661 if (((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1)) == Head
) {
670 UnicodeFiFoGetKeyCount (
671 TERMINAL_DEV
*TerminalDevice
677 Tail
= TerminalDevice
->UnicodeFiFo
.Tail
;
678 Head
= TerminalDevice
->UnicodeFiFo
.Head
;
681 return (UINT8
) (Tail
- Head
);
683 return (UINT8
) (Tail
+ FIFO_MAX_NUMBER
+ 1 - Head
);
688 UnicodeToEfiKeyFlushState (
689 IN TERMINAL_DEV
*TerminalDevice
694 if (TerminalDevice
->InputState
& INPUT_STATE_ESC
) {
695 Key
.ScanCode
= SCAN_ESC
;
697 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
700 if (TerminalDevice
->InputState
& INPUT_STATE_CSI
) {
701 Key
.ScanCode
= SCAN_NULL
;
702 Key
.UnicodeChar
= CSI
;
703 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
706 if (TerminalDevice
->InputState
& INPUT_STATE_LEFTOPENBRACKET
) {
707 Key
.ScanCode
= SCAN_NULL
;
708 Key
.UnicodeChar
= LEFTOPENBRACKET
;
709 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
712 if (TerminalDevice
->InputState
& INPUT_STATE_O
) {
713 Key
.ScanCode
= SCAN_NULL
;
714 Key
.UnicodeChar
= 'O';
715 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
718 if (TerminalDevice
->InputState
& INPUT_STATE_2
) {
719 Key
.ScanCode
= SCAN_NULL
;
720 Key
.UnicodeChar
= '2';
721 EfiKeyFiFoInsertOneKey (TerminalDevice
, Key
);
725 TerminalDevice
->TwoSecondTimeOut
,
730 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
735 IN TERMINAL_DEV
*TerminalDevice
740 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
741 can be read through the Simple Input Protocol. The table below shows the keyboard
742 input mappings that this function supports. If the ESC sequence listed in one of the
743 columns is presented, then it is translated into the coorespoding EFI Scan Code. If a
744 matching sequence is not found, then the raw key strokes are converted into EFI Keys.
746 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
747 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
748 converted into EFI Keys.
750 There is one special input sequence that will force the system to reset.
751 This is ESC R ESC r ESC R.
755 TerminaDevice : The terminal device to use to translate raw input into EFI Keys
761 Symbols used in table below
762 ===========================
768 +=========+======+===========+==========+==========+
769 | | EFI | EFI 1.10 | | |
770 | | Scan | | VT100+ | |
771 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
772 +=========+======+===========+==========+==========+
773 | NULL | 0x00 | | | |
774 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
775 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
776 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
777 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
778 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
779 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
780 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
781 | | | ESC [ L | | ESC [ L |
782 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
783 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
785 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
787 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
788 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
789 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
790 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
791 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
792 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
793 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
794 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
795 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
796 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
797 | Escape | 0x17 | ESC | ESC | ESC |
798 +=========+======+===========+==========+=========+
802 ESC R ESC r ESC R = Reset System
807 EFI_STATUS TimerStatus
;
810 BOOLEAN SetDefaultResetState
;
812 TimerStatus
= gBS
->CheckEvent (TerminalDevice
->TwoSecondTimeOut
);
814 if (!EFI_ERROR (TimerStatus
)) {
815 UnicodeToEfiKeyFlushState (TerminalDevice
);
816 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
819 while (!IsUnicodeFiFoEmpty(TerminalDevice
)) {
821 if (TerminalDevice
->InputState
!= INPUT_STATE_DEFAULT
) {
823 // Check to see if the 2 second timer has expired
825 TimerStatus
= gBS
->CheckEvent (TerminalDevice
->TwoSecondTimeOut
);
826 if (!EFI_ERROR (TimerStatus
)) {
827 UnicodeToEfiKeyFlushState (TerminalDevice
);
828 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
833 // Fetch one Unicode character from the Unicode FIFO
835 UnicodeFiFoRemoveOneKey (TerminalDevice
,&UnicodeChar
);
837 SetDefaultResetState
= TRUE
;
839 switch (TerminalDevice
->InputState
) {
840 case INPUT_STATE_DEFAULT
:
844 case INPUT_STATE_ESC
:
846 if (UnicodeChar
== LEFTOPENBRACKET
) {
847 TerminalDevice
->InputState
|= INPUT_STATE_LEFTOPENBRACKET
;
848 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
852 if (UnicodeChar
== 'O' && TerminalDevice
->TerminalType
== VT100Type
) {
853 TerminalDevice
->InputState
|= INPUT_STATE_O
;
854 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
858 Key
.ScanCode
= SCAN_NULL
;
860 if (TerminalDevice
->TerminalType
== VT100PlusType
||
861 TerminalDevice
->TerminalType
== VTUTF8Type
) {
862 switch (UnicodeChar
) {
864 Key
.ScanCode
= SCAN_F1
;
867 Key
.ScanCode
= SCAN_F2
;
870 Key
.ScanCode
= SCAN_F3
;
873 Key
.ScanCode
= SCAN_F4
;
876 Key
.ScanCode
= SCAN_F5
;
879 Key
.ScanCode
= SCAN_F6
;
882 Key
.ScanCode
= SCAN_F7
;
885 Key
.ScanCode
= SCAN_F8
;
888 Key
.ScanCode
= SCAN_F9
;
891 Key
.ScanCode
= SCAN_F10
;
894 Key
.ScanCode
= SCAN_HOME
;
897 Key
.ScanCode
= SCAN_END
;
900 Key
.ScanCode
= SCAN_INSERT
;
903 Key
.ScanCode
= SCAN_DELETE
;
906 Key
.ScanCode
= SCAN_PAGE_DOWN
;
909 Key
.ScanCode
= SCAN_PAGE_UP
;
916 switch (UnicodeChar
) {
918 if (TerminalDevice
->ResetState
== RESET_STATE_DEFAULT
) {
919 TerminalDevice
->ResetState
= RESET_STATE_ESC_R
;
920 SetDefaultResetState
= FALSE
;
921 } else if (TerminalDevice
->ResetState
== RESET_STATE_ESC_R_ESC_r
) {
922 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
924 Key
.ScanCode
= SCAN_NULL
;
927 if (TerminalDevice
->ResetState
== RESET_STATE_ESC_R
) {
928 TerminalDevice
->ResetState
= RESET_STATE_ESC_R_ESC_r
;
929 SetDefaultResetState
= FALSE
;
931 Key
.ScanCode
= SCAN_NULL
;
937 if (SetDefaultResetState
) {
938 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
941 if (Key
.ScanCode
!= SCAN_NULL
) {
943 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);
944 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
945 UnicodeToEfiKeyFlushState (TerminalDevice
);
949 UnicodeToEfiKeyFlushState (TerminalDevice
);
953 case INPUT_STATE_ESC
| INPUT_STATE_O
:
955 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
957 Key
.ScanCode
= SCAN_NULL
;
959 if (TerminalDevice
->TerminalType
== VT100Type
) {
960 switch (UnicodeChar
) {
962 Key
.ScanCode
= SCAN_F1
;
965 Key
.ScanCode
= SCAN_F2
;
968 Key
.ScanCode
= SCAN_F3
;
971 Key
.ScanCode
= SCAN_F4
;
974 Key
.ScanCode
= SCAN_F5
;
977 Key
.ScanCode
= SCAN_F6
;
980 Key
.ScanCode
= SCAN_F7
;
983 Key
.ScanCode
= SCAN_F8
;
986 Key
.ScanCode
= SCAN_F9
;
989 Key
.ScanCode
= SCAN_F10
;
996 if (Key
.ScanCode
!= SCAN_NULL
) {
998 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);
999 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
1000 UnicodeToEfiKeyFlushState (TerminalDevice
);
1004 UnicodeToEfiKeyFlushState (TerminalDevice
);
1008 case INPUT_STATE_ESC
| INPUT_STATE_LEFTOPENBRACKET
:
1010 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1012 Key
.ScanCode
= SCAN_NULL
;
1014 if (TerminalDevice
->TerminalType
== PcAnsiType
||
1015 TerminalDevice
->TerminalType
== VT100Type
||
1016 TerminalDevice
->TerminalType
== VT100PlusType
||
1017 TerminalDevice
->TerminalType
== VTUTF8Type
) {
1018 switch (UnicodeChar
) {
1020 Key
.ScanCode
= SCAN_UP
;
1023 Key
.ScanCode
= SCAN_DOWN
;
1026 Key
.ScanCode
= SCAN_RIGHT
;
1029 Key
.ScanCode
= SCAN_LEFT
;
1032 if (TerminalDevice
->TerminalType
== PcAnsiType
||
1033 TerminalDevice
->TerminalType
== VT100Type
) {
1034 Key
.ScanCode
= SCAN_HOME
;
1038 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1039 Key
.ScanCode
= SCAN_END
;
1043 if (TerminalDevice
->TerminalType
== VT100Type
) {
1044 Key
.ScanCode
= SCAN_END
;
1049 if (TerminalDevice
->TerminalType
== PcAnsiType
||
1050 TerminalDevice
->TerminalType
== VT100Type
) {
1051 Key
.ScanCode
= SCAN_INSERT
;
1055 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1056 Key
.ScanCode
= SCAN_DELETE
;
1060 if (TerminalDevice
->TerminalType
== VT100Type
) {
1061 Key
.ScanCode
= SCAN_DELETE
;
1062 } else if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1063 Key
.ScanCode
= SCAN_F4
;
1067 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1068 Key
.ScanCode
= SCAN_PAGE_UP
;
1072 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1073 Key
.ScanCode
= SCAN_F10
;
1076 if (TerminalDevice
->TerminalType
== VT100Type
) {
1077 Key
.ScanCode
= SCAN_PAGE_UP
;
1081 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1082 Key
.ScanCode
= SCAN_PAGE_DOWN
;
1086 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1087 Key
.ScanCode
= SCAN_F9
;
1090 if (TerminalDevice
->TerminalType
== VT100Type
) {
1091 Key
.ScanCode
= SCAN_PAGE_DOWN
;
1095 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1096 Key
.ScanCode
= SCAN_F1
;
1100 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1101 Key
.ScanCode
= SCAN_F2
;
1105 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1106 Key
.ScanCode
= SCAN_F3
;
1110 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1111 Key
.ScanCode
= SCAN_F5
;
1115 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1116 Key
.ScanCode
= SCAN_F6
;
1120 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1121 Key
.ScanCode
= SCAN_F7
;
1125 if (TerminalDevice
->TerminalType
== PcAnsiType
) {
1126 Key
.ScanCode
= SCAN_F8
;
1134 if (Key
.ScanCode
!= SCAN_NULL
) {
1135 Key
.UnicodeChar
= 0;
1136 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);
1137 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
1138 UnicodeToEfiKeyFlushState (TerminalDevice
);
1142 UnicodeToEfiKeyFlushState (TerminalDevice
);
1149 // Invalid state. This should never happen.
1153 UnicodeToEfiKeyFlushState (TerminalDevice
);
1158 if (UnicodeChar
== ESC
) {
1159 TerminalDevice
->InputState
= INPUT_STATE_ESC
;
1162 if (TerminalDevice
->InputState
!= INPUT_STATE_DEFAULT
) {
1163 Status
= gBS
->SetTimer(
1164 TerminalDevice
->TwoSecondTimeOut
,
1171 if (SetDefaultResetState
) {
1172 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1175 if (UnicodeChar
== DEL
) {
1176 Key
.ScanCode
= SCAN_DELETE
;
1177 Key
.UnicodeChar
= 0;
1179 Key
.ScanCode
= SCAN_NULL
;
1180 Key
.UnicodeChar
= UnicodeChar
;
1183 EfiKeyFiFoInsertOneKey (TerminalDevice
,Key
);