X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FConsole%2FTerminalDxe%2FTerminalConOut.c;h=8f2675228ff7f3350c4c5681ed2cff4bff764723;hb=f0368006b0d04820a44ae21b0d55ee2d0f5aee3d;hp=65fbfc1ef47f7ce9b9bb1ec11e36eb85e5ce3cc6;hpb=fb0b259e4e440577dcd6ba6722c252d90605b3e9;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c index 65fbfc1ef4..8f2675228f 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/TerminalConOut.c @@ -1,8 +1,8 @@ /** @file Implementation for EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL protocol. -Copyright (c) 2006 - 2008, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+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 http://opensource.org/licenses/bsd-license.php @@ -20,7 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // ASCII. The ASCII mapping we just made up. // // -STATIC UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = { +UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = { { BOXDRAW_HORIZONTAL, 0xc4, L'-' }, { BOXDRAW_VERTICAL, 0xb3, L'|' }, { BOXDRAW_DOWN_RIGHT, 0xda, L'/' }, @@ -70,10 +70,10 @@ STATIC UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = { { GEOMETRICSHAPE_DOWN_TRIANGLE, 0x1f, L'v' }, { GEOMETRICSHAPE_LEFT_TRIANGLE, 0x11, L'<' }, - { ARROW_LEFT, 0x3c, L'<' }, - { ARROW_UP, 0x18, L'^' }, - { ARROW_RIGHT, 0x3e, L'>' }, - { ARROW_DOWN, 0x19, L'v' }, + { ARROW_LEFT, 0x3c, L'<' }, + { ARROW_UP, 0x18, L'^' }, + { ARROW_RIGHT, 0x3e, L'>' }, + { ARROW_DOWN, 0x19, L'v' }, { 0x0000, 0x00, L'\0' } }; @@ -86,36 +86,29 @@ CHAR16 mSetCursorPositionString[] = { ESC, '[', '0', '0', ';', '0', '0', 'H', 0 // // Body of the ConOut functions // + +/** + Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset(). + + If ExtendeVerification is TRUE, then perform dependent serial device reset, + and set display mode to mode 0. + If ExtendedVerification is FALSE, only set display mode to mode 0. + + @param This Indicates the calling context. + @param ExtendedVerification Indicates that the driver may perform a more + exhaustive verification operation of the device + during reset. + + @retval EFI_SUCCESS The reset operation succeeds. + @retval EFI_DEVICE_ERROR The terminal is not functioning correctly or the serial port reset fails. + +**/ EFI_STATUS EFIAPI TerminalConOutReset ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN BOOLEAN ExtendedVerification ) -/*++ - Routine Description: - - Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset(). - If ExtendeVerification is TRUE, then perform dependent serial device reset, - and set display mode to mode 0. - If ExtendedVerification is FALSE, only set display mode to mode 0. - - Arguments: - - This - Indicates the calling context. - - ExtendedVerification - Indicates that the driver may perform a more exhaustive - verification operation of the device during reset. - - Returns: - - EFI_SUCCESS - The reset operation succeeds. - - EFI_DEVICE_ERROR - The terminal is not functioning correctly or the serial port reset fails. - ---*/ { EFI_STATUS Status; TERMINAL_DEV *TerminalDevice; @@ -131,7 +124,7 @@ TerminalConOutReset ( // REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, - PcdGet32 (PcdStatusCodeValueRemoteConsoleReset), + (EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_PC_RESET), TerminalDevice->DevicePath ); @@ -142,7 +135,7 @@ TerminalConOutReset ( // REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_ERROR_CODE | EFI_ERROR_MINOR, - PcdGet32 (PcdStatusCodeValueRemoteConsoleError), + (EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_CONTROLLER_ERROR), TerminalDevice->DevicePath ); @@ -150,49 +143,37 @@ TerminalConOutReset ( } } - This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK)); + This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BLACK)); Status = This->SetMode (This, 0); return Status; } + +/** + Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString(). + + The Unicode string will be converted to terminal expressible data stream + and send to terminal via serial port. + + @param This Indicates the calling context. + @param WString The Null-terminated Unicode string to be displayed + on the terminal screen. + + @retval EFI_SUCCESS The string is output successfully. + @retval EFI_DEVICE_ERROR The serial port fails to send the string out. + @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not + be rendered and are skipped. + @retval EFI_UNSUPPORTED If current display mode is out of range. + +**/ EFI_STATUS EFIAPI TerminalConOutOutputString ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN CHAR16 *WString ) -/*++ - Routine Description: - - Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString(). - The Unicode string will be converted to terminal expressible data stream - and send to terminal via serial port. - - - Arguments: - - This - Indicates the calling context. - - WString - The Null-terminated Unicode string to be displayed on - the terminal screen. - - Returns: - - EFI_SUCCESS - The string is output successfully. - - EFI_DEVICE_ERROR - The serial port fails to send the string out. - - EFI_WARN_UNKNOWN_GLYPH - Indicates that some of the characters in the Unicode string could not - be rendered and are skipped. - - EFI_UNSUPPORTED - ---*/ { TERMINAL_DEV *TerminalDevice; EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode; @@ -212,6 +193,7 @@ TerminalConOutOutputString ( ValidBytes = 0; Warning = FALSE; + AsciiChar = 0; // // get Terminal device data structure pointer. @@ -223,7 +205,7 @@ TerminalConOutOutputString ( // Mode = This->Mode; - if (Mode->Mode > 2) { + if (Mode->Mode >= TERMINAL_MAX_MODE) { return EFI_UNSUPPORTED; } @@ -238,9 +220,9 @@ TerminalConOutOutputString ( switch (TerminalDevice->TerminalType) { - case PcAnsiType: - case VT100Type: - case VT100PlusType: + case PCANSITYPE: + case VT100TYPE: + case VT100PLUSTYPE: if (!TerminalIsValidTextGraphics (*WString, &GraphicChar, &AsciiChar)) { // @@ -266,7 +248,7 @@ TerminalConOutOutputString ( } - if (TerminalDevice->TerminalType != PcAnsiType) { + if (TerminalDevice->TerminalType != PCANSITYPE) { GraphicChar = AsciiChar; } @@ -284,7 +266,7 @@ TerminalConOutOutputString ( break; - case VTUTF8Type: + case VTUTF8TYPE: UnicodeToUtf8 (*WString, &Utf8Char, &ValidBytes); Length = ValidBytes; Status = TerminalDevice->SerialIo->Write ( @@ -346,44 +328,35 @@ TerminalConOutOutputString ( OutputError: REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_ERROR_CODE | EFI_ERROR_MINOR, - PcdGet32 (PcdStatusCodeValueRemoteConsoleOutputError), + (EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_OUTPUT_ERROR), TerminalDevice->DevicePath ); return EFI_DEVICE_ERROR; } + +/** + Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString(). + + If one of the characters in the *Wstring is + neither valid Unicode drawing characters, + not ASCII code, then this function will return + EFI_UNSUPPORTED. + + @param This Indicates the calling context. + @param WString The Null-terminated Unicode string to be tested. + + @retval EFI_SUCCESS The terminal is capable of rendering the output string. + @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered. + +**/ EFI_STATUS EFIAPI TerminalConOutTestString ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN CHAR16 *WString ) -/*++ - Routine Description: - - Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString(). - If one of the characters in the *Wstring is - neither valid Unicode drawing characters, - not ASCII code, then this function will return - EFI_UNSUPPORTED. - - - Arguments: - - This - Indicates the calling context. - - WString - The Null-terminated Unicode string to be tested. - - Returns: - - EFI_SUCCESS - The terminal is capable of rendering the output string. - - EFI_UNSUPPORTED - Some of the characters in the Unicode string cannot be rendered. - ---*/ { TERMINAL_DEV *TerminalDevice; EFI_STATUS Status; @@ -395,13 +368,13 @@ TerminalConOutTestString ( switch (TerminalDevice->TerminalType) { - case PcAnsiType: - case VT100Type: - case VT100PlusType: + case PCANSITYPE: + case VT100TYPE: + case VT100PLUSTYPE: Status = AnsiTestString (TerminalDevice, WString); break; - case VTUTF8Type: + case VTUTF8TYPE: Status = VTUTF8TestString (TerminalDevice, WString); break; @@ -413,6 +386,25 @@ TerminalConOutTestString ( return Status; } + +/** + Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode(). + + It returns information for an available text mode + that the terminal supports. + In this driver, we support text mode 80x25 (mode 0), + 80x50 (mode 1), 100x31 (mode 2). + + @param This Indicates the calling context. + @param ModeNumber The mode number to return information on. + @param Columns The returned columns of the requested mode. + @param Rows The returned rows of the requested mode. + + @retval EFI_SUCCESS The requested mode information is returned. + @retval EFI_UNSUPPORTED The mode number is not valid. + @retval EFI_DEVICE_ERROR + +**/ EFI_STATUS EFIAPI TerminalConOutQueryMode ( @@ -421,43 +413,8 @@ TerminalConOutQueryMode ( OUT UINTN *Columns, OUT UINTN *Rows ) -/*++ - Routine Description: - - Implements EFI_SIMPLE_TEXT_OUT_PROTOCOL.QueryMode(). - It returns information for an available text mode - that the terminal supports. - In this driver, we support text mode 80x25 (mode 0), - 80x50 (mode 1), 100x31 (mode 2). - - - Arguments: - - *This - Indicates the calling context. - - ModeNumber - The mode number to return information on. - - Columns - The returned columns of the requested mode. - - Rows - The returned rows of the requested mode. - - Returns: - - EFI_SUCCESS - The requested mode information is returned. - - EFI_UNSUPPORTED - The mode number is not valid. - - EFI_DEVICE_ERROR - ---*/ { - if (This->Mode->MaxMode > 3) { + if (This->Mode->MaxMode > TERMINAL_MAX_MODE) { return EFI_DEVICE_ERROR; } @@ -473,44 +430,43 @@ TerminalConOutQueryMode ( *Columns = MODE2_COLUMN_COUNT; *Rows = MODE2_ROW_COUNT; return EFI_SUCCESS; + } else if (ModeNumber == 3) { + *Columns = (UINTN) PcdGet32 (PcdConOutColumn); + if (*Columns == 0) { + *Columns = MODE0_COLUMN_COUNT; + } + *Rows = (UINTN) PcdGet32 (PcdConOutRow); + if (*Rows == 0) { + *Rows = MODE0_ROW_COUNT; + } + return EFI_SUCCESS; } return EFI_UNSUPPORTED; } + +/** + Implements EFI_SIMPLE_TEXT_OUT.SetMode(). + + Set the terminal to a specified display mode. + In this driver, we only support mode 0. + + @param This Indicates the calling context. + @param ModeNumber The text mode to set. + + @retval EFI_SUCCESS The requested text mode is set. + @retval EFI_DEVICE_ERROR The requested text mode cannot be set + because of serial device error. + @retval EFI_UNSUPPORTED The text mode number is not valid. + +**/ EFI_STATUS EFIAPI TerminalConOutSetMode ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN ModeNumber ) -/*++ - Routine Description: - - Implements EFI_SIMPLE_TEXT_OUT.SetMode(). - Set the terminal to a specified display mode. - In this driver, we only support mode 0. - - Arguments: - - This - Indicates the calling context. - - ModeNumber - The text mode to set. - - Returns: - - EFI_SUCCESS - The requested text mode is set. - - EFI_DEVICE_ERROR - The requested text mode cannot be set because of serial device error. - - EFI_UNSUPPORTED - The text mode number is not valid. - ---*/ { EFI_STATUS Status; TERMINAL_DEV *TerminalDevice; @@ -520,7 +476,7 @@ TerminalConOutSetMode ( // TerminalDevice = TERMINAL_CON_OUT_DEV_FROM_THIS (This); - if (ModeNumber > 2) { + if (ModeNumber >= TERMINAL_MAX_MODE) { return EFI_UNSUPPORTED; } @@ -550,38 +506,25 @@ TerminalConOutSetMode ( } + +/** + Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute(). + + @param This Indicates the calling context. + @param Attribute The attribute to set. Only bit0..6 are valid, all other bits + are undefined and must be zero. + + @retval EFI_SUCCESS The requested attribute is set. + @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error. + @retval EFI_UNSUPPORTED The attribute requested is not defined by EFI spec. + +**/ EFI_STATUS EFIAPI TerminalConOutSetAttribute ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN Attribute ) -/*++ - Routine Description: - - Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute(). - - Arguments: - - This - Indicates the calling context. - - Attribute - The attribute to set. Only bit0..6 are valid, all other bits - are undefined and must be zero. - - Returns: - - EFI_SUCCESS - The requested attribute is set. - - EFI_DEVICE_ERROR - The requested attribute cannot be set due to serial port error. - - EFI_UNSUPPORTED - The attribute requested is not defined by EFI spec. - ---*/ { UINT8 ForegroundControl; UINT8 BackgroundControl; @@ -605,6 +548,15 @@ TerminalConOutSetAttribute ( if ((Attribute | 0x7f) != 0x7f) { return EFI_UNSUPPORTED; } + + // + // Skip outputting the command string for the same attribute + // It improves the terminal performance significantly + // + if (This->Mode->Attribute == (INT32) Attribute) { + return EFI_SUCCESS; + } + // // convert Attribute value to terminal emulator // understandable foreground color @@ -727,36 +679,24 @@ TerminalConOutSetAttribute ( } + +/** + Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen(). + It clears the ANSI terminal's display to the + currently selected background color. + + @param This Indicates the calling context. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error. + @retval EFI_UNSUPPORTED The terminal is not in a valid display mode. + +**/ EFI_STATUS EFIAPI TerminalConOutClearScreen ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This ) -/*++ - Routine Description: - - Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen(). - It clears the ANSI terminal's display to the - currently selected background color. - - - Arguments: - - This - Indicates the calling context. - - Returns: - - EFI_SUCCESS - The operation completed successfully. - - EFI_DEVICE_ERROR - The terminal screen cannot be cleared due to serial port error. - - EFI_UNSUPPORTED - The terminal is not in a valid display mode. - ---*/ { EFI_STATUS Status; TERMINAL_DEV *TerminalDevice; @@ -779,6 +719,20 @@ TerminalConOutClearScreen ( return Status; } + +/** + Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition(). + + @param This Indicates the calling context. + @param Column The row to set cursor to. + @param Row The column to set cursor to. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_DEVICE_ERROR The request fails due to serial port error. + @retval EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position + is invalid for current mode. + +**/ EFI_STATUS EFIAPI TerminalConOutSetCursorPosition ( @@ -786,35 +740,6 @@ TerminalConOutSetCursorPosition ( IN UINTN Column, IN UINTN Row ) -/*++ - Routine Description: - - Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition(). - - Arguments: - - This - Indicates the calling context. - - Column - The row to set cursor to. - - Row - The column to set cursor to. - - Returns: - - EFI_SUCCESS - The operation completed successfully. - - EFI_DEVICE_ERROR - The request fails due to serial port error. - - EFI_UNSUPPORTED - The terminal is not in a valid text mode, or the cursor position - is invalid for current mode. - ---*/ { EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode; UINTN MaxColumn; @@ -870,36 +795,26 @@ TerminalConOutSetCursorPosition ( return EFI_SUCCESS; } + +/** + Implements SIMPLE_TEXT_OUTPUT.EnableCursor(). + + In this driver, the cursor cannot be hidden. + + @param This Indicates the calling context. + @param Visible If TRUE, the cursor is set to be visible, + If FALSE, the cursor is set to be invisible. + + @retval EFI_SUCCESS The request is valid. + @retval EFI_UNSUPPORTED The terminal does not support cursor hidden. + +**/ EFI_STATUS EFIAPI TerminalConOutEnableCursor ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN BOOLEAN Visible ) -/*++ - Routine Description: - - Implements SIMPLE_TEXT_OUTPUT.EnableCursor(). - In this driver, the cursor cannot be hidden. - - Arguments: - - This - Indicates the calling context. - - Visible - If TRUE, the cursor is set to be visible, - If FALSE, the cursor is set to be invisible. - - Returns: - - EFI_SUCCESS - The request is valid. - - EFI_UNSUPPORTED - The terminal does not support cursor hidden. - ---*/ { if (!Visible) { return EFI_UNSUPPORTED; @@ -908,31 +823,25 @@ TerminalConOutEnableCursor ( return EFI_SUCCESS; } + +/** + Detects if a Unicode char is for Box Drawing text graphics. + + @param Graphic Unicode char to test. + @param PcAnsi Optional pointer to return PCANSI equivalent of + Graphic. + @param Ascii Optional pointer to return ASCII equivalent of + Graphic. + + @retval TRUE If Graphic is a supported Unicode Box Drawing character. + +**/ BOOLEAN TerminalIsValidTextGraphics ( IN CHAR16 Graphic, OUT CHAR8 *PcAnsi, OPTIONAL OUT CHAR8 *Ascii OPTIONAL ) -/*++ - -Routine Description: - - Detects if a Unicode char is for Box Drawing text graphics. - -Arguments: - - Graphic - Unicode char to test. - - PcAnsi - Optional pointer to return PCANSI equivalent of Graphic. - - Ascii - Optional pointer to return ASCII equivalent of Graphic. - -Returns: - - TRUE if Graphic is a supported Unicode Box Drawing character. - ---*/ { UNICODE_TO_CHAR *Table; @@ -961,6 +870,15 @@ Returns: return FALSE; } +/** + Detects if a valid ASCII char. + + @param Ascii An ASCII character. + + @retval TRUE If it is a valid ASCII character. + @retval FALSE If it is not a valid ASCII character. + +**/ BOOLEAN TerminalIsValidAscii ( IN CHAR16 Ascii @@ -976,6 +894,15 @@ TerminalIsValidAscii ( return FALSE; } +/** + Detects if a valid EFI control character. + + @param CharC An input EFI Control character. + + @retval TRUE If it is a valid EFI control character. + @retval FALSE If it is not a valid EFI control character. + +**/ BOOLEAN TerminalIsValidEfiCntlChar ( IN CHAR16 CharC