From 4ea439fb1de2b5df753866ef989208441917c320 Mon Sep 17 00:00:00 2001 From: mdkinney Date: Mon, 14 Jun 2010 23:32:07 +0000 Subject: [PATCH] Sync FrameworkUefiLib with the MdePkg UefiLib git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10583 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Library/FrameworkUefiLib/Console.c | 183 ++++++++++++- .../FrameworkUefiLib/UefiDriverModel.c | 21 +- .../Library/FrameworkUefiLib/UefiLib.c | 249 +++++++++++++++++- .../FrameworkUefiLib/UefiLibInternal.h | 2 + .../Library/FrameworkUefiLib/UefiLibPrint.c | 50 +++- 5 files changed, 477 insertions(+), 28 deletions(-) diff --git a/IntelFrameworkPkg/Library/FrameworkUefiLib/Console.c b/IntelFrameworkPkg/Library/FrameworkUefiLib/Console.c index fa14135cc8..a8ecc27e64 100644 --- a/IntelFrameworkPkg/Library/FrameworkUefiLib/Console.c +++ b/IntelFrameworkPkg/Library/FrameworkUefiLib/Console.c @@ -1,7 +1,7 @@ /** @file This module provide help function for displaying unicode string. - Copyright (c) 2006, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2009, 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 @@ -12,6 +12,9 @@ **/ + + + #include "UefiLibInternal.h" typedef struct { @@ -196,6 +199,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = { @retval 0 The width if UnicodeChar could not be determined. @retval 1 UnicodeChar is a narrow glyph. @retval 2 UnicodeChar is a wide glyph. + **/ UINTN EFIAPI @@ -211,7 +215,6 @@ GetGlyphWidth ( Item = NULL; Low = 0; High = (sizeof (mUnicodeWidthTable)) / (sizeof (UNICODE_WIDTH_ENTRY)) - 1; - while (Low <= High) { Index = (Low + High) >> 1; Item = &(mUnicodeWidthTable[Index]); @@ -219,6 +222,7 @@ GetGlyphWidth ( if (UnicodeChar <= Item->WChar) { break; } + return 0; } @@ -255,6 +259,7 @@ GetGlyphWidth ( @param String A pointer to a Null-terminated Unicode string. @return The display length of the Null-terminated Unicode string specified by String. + **/ UINTN EFIAPI @@ -282,3 +287,177 @@ UnicodeStringDisplayLength ( return Length; } + +/** + Draws a dialog box to the console output device specified by + ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke + from the console input device specified by ConIn defined in the + EFI_SYSTEM_TABLE. + + If there are no strings in the variable argument list, then ASSERT(). + If all the strings in the variable argument list are empty, then ASSERT(). + + @param[in] Attribute Specifies the foreground and background color of the popup. + @param[out] Key A pointer to the EFI_KEY value of the key that was + pressed. This is an optional parameter that may be NULL. + If it is NULL then no wait for a keypress will be performed. + @param[in] ... The variable argument list that contains pointers to Null- + terminated Unicode strings to display in the dialog box. + The variable argument list is terminated by a NULL. + +**/ +VOID +EFIAPI +CreatePopUp ( + IN UINTN Attribute, + OUT EFI_INPUT_KEY *Key, OPTIONAL + ... + ) +{ + VA_LIST Args; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; + EFI_SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode; + UINTN Columns; + UINTN Rows; + UINTN Column; + UINTN Row; + UINTN NumberOfLines; + UINTN MaxLength; + CHAR16 *String; + UINTN Length; + CHAR16 *Line; + UINTN EventIndex; + + // + // Determine the length of the longest line in the popup and the the total + // number of lines in the popup + // + VA_START (Args, Key); + MaxLength = 0; + NumberOfLines = 0; + while ((String = VA_ARG (Args, CHAR16 *)) != NULL) { + MaxLength = MAX (MaxLength, StrLen (String)); + NumberOfLines++; + } + VA_END (Args); + + // + // If the total number of lines in the popup is zero, then ASSERT() + // + ASSERT (NumberOfLines != 0); + + // + // If the maximum length of all the strings is zero, then ASSERT() + // + ASSERT (MaxLength != 0); + + // + // Cache a pointer to the Simple Text Output Protocol in the EFI System Table + // + ConOut = gST->ConOut; + + // + // Save the current console cursor position and attributes + // + CopyMem (&SavedConsoleMode, ConOut->Mode, sizeof (SavedConsoleMode)); + + // + // Retrieve the number of columns and rows in the current console mode + // + ConOut->QueryMode (ConOut, SavedConsoleMode.Mode, &Columns, &Rows); + + // + // Disable cursor and set the foreground and background colors specified by Attribute + // + ConOut->EnableCursor (ConOut, FALSE); + ConOut->SetAttribute (ConOut, Attribute); + + // + // Limit NumberOfLines to height of the screen minus 3 rows for the box itself + // + NumberOfLines = MIN (NumberOfLines, Rows - 3); + + // + // Limit MaxLength to width of the screen minus 2 columns for the box itself + // + MaxLength = MIN (MaxLength, Columns - 2); + + // + // Compute the starting row and starting column for the popup + // + Row = (Rows - (NumberOfLines + 3)) / 2; + Column = (Columns - (MaxLength + 2)) / 2; + + // + // Allocate a buffer for a single line of the popup with borders and a Null-terminator + // + Line = AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16)); + ASSERT (Line != NULL); + + // + // Draw top of popup box + // + SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL); + Line[0] = BOXDRAW_DOWN_RIGHT; + Line[MaxLength + 1] = BOXDRAW_DOWN_LEFT; + Line[MaxLength + 2] = L'\0'; + ConOut->SetCursorPosition (ConOut, Column, Row++); + ConOut->OutputString (ConOut, Line); + + // + // Draw middle of the popup with strings + // + VA_START (Args, Key); + while ((String = VA_ARG (Args, CHAR16 *)) != NULL && NumberOfLines > 0) { + Length = StrLen (String); + SetMem16 (Line, (MaxLength + 2) * 2, L' '); + if (Length <= MaxLength) { + // + // Length <= MaxLength + // + CopyMem (Line + 1 + (MaxLength - Length) / 2, String , Length * sizeof (CHAR16)); + } else { + // + // Length > MaxLength + // + CopyMem (Line + 1, String + (Length - MaxLength) / 2 , MaxLength * sizeof (CHAR16)); + } + Line[0] = BOXDRAW_VERTICAL; + Line[MaxLength + 1] = BOXDRAW_VERTICAL; + Line[MaxLength + 2] = L'\0'; + ConOut->SetCursorPosition (ConOut, Column, Row++); + ConOut->OutputString (ConOut, Line); + NumberOfLines--; + } + VA_END (Args); + + // + // Draw bottom of popup box + // + SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL); + Line[0] = BOXDRAW_UP_RIGHT; + Line[MaxLength + 1] = BOXDRAW_UP_LEFT; + Line[MaxLength + 2] = L'\0'; + ConOut->SetCursorPosition (ConOut, Column, Row++); + ConOut->OutputString (ConOut, Line); + + // + // Free the allocated line buffer + // + FreePool (Line); + + // + // Restore the cursor visibility, position, and attributes + // + ConOut->EnableCursor (ConOut, SavedConsoleMode.CursorVisible); + ConOut->SetCursorPosition (ConOut, SavedConsoleMode.CursorColumn, SavedConsoleMode.CursorRow); + ConOut->SetAttribute (ConOut, SavedConsoleMode.Attribute); + + // + // Wait for a keystroke + // + if (Key != NULL) { + gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); + gST->ConIn->ReadKeyStroke (gST->ConIn, Key); + } +} diff --git a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiDriverModel.c b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiDriverModel.c index 6b36f3d78f..39ab8deb49 100644 --- a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiDriverModel.c +++ b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiDriverModel.c @@ -13,6 +13,7 @@ **/ + #include "UefiLibInternal.h" /** @@ -35,6 +36,7 @@ @retval EFI_SUCCESS The protocol installation is completed successfully. @retval EFI_OUT_OF_RESOURCES There was not enough system resources to install the protocol. @retval Others Status from gBS->InstallMultipleProtocolInterfaces(). + **/ EFI_STATUS EFIAPI @@ -54,6 +56,9 @@ EfiLibInstallDriverBinding ( &gEfiDriverBindingProtocolGuid, DriverBinding, NULL ); + // + // ASSERT if the call to InstallMultipleProtocolInterfaces() failed + // ASSERT_EFI_ERROR (Status); // @@ -65,6 +70,7 @@ EfiLibInstallDriverBinding ( return Status; } + /** Installs and completes the initialization of a Driver Binding Protocol instance and optionally installs the Component Name, Driver Configuration and Driver Diagnostics Protocols. @@ -105,9 +111,7 @@ EfiLibInstallAllDriverProtocols ( { EFI_STATUS Status; - if (DriverBinding == NULL) { - return EFI_INVALID_PARAMETER; - } + ASSERT (DriverBinding != NULL); if (DriverDiagnostics == NULL || FeaturePcdGet(PcdDriverDiagnosticsDisable)) { if (DriverConfiguration == NULL) { @@ -291,17 +295,18 @@ EfiLibInstallDriverBindingComponentName2 ( Configuration, Driver Configuration 2, Driver Diagnostics, and Driver Diagnostics 2 Protocols. Initializes a driver by installing the Driver Binding Protocol together with the optional - Component Name, optional Component Name 2, optional Driver Configuration, optional Driver - Configuration 2, optional Driver Diagnostic, and optional Driver Diagnostic 2 Protocols - onto the driver's DriverBindingHandle. DriverBindingHandle is typically the same as the - driver's ImageHandle, but it can be different if the driver produces multiple Driver Binding Protocols. + Component Name, optional Component Name 2, optional Driver Configuration, optional Driver Configuration 2, + optional Driver Diagnostic, and optional Driver Diagnostic 2 Protocols onto the driver's DriverBindingHandle. + DriverBindingHandle is typically the same as the driver's ImageHandle, but it can be different if the driver + produces multiple Driver Binding Protocols. If DriverBinding is NULL, then ASSERT(). If the installation fails, then ASSERT(). + @param ImageHandle The image handle of the driver. @param SystemTable The EFI System Table that was passed to the driver's entry point. @param DriverBinding A Driver Binding Protocol instance that this driver is producing. - @param DriverBindingHandle The handle that DriverBinding is to be installe onto. If this + @param DriverBindingHandle The handle that DriverBinding is to be installed onto. If this parameter is NULL, then a new handle is created. @param ComponentName A Component Name Protocol instance that this driver is producing. @param ComponentName2 A Component Name 2 Protocol instance that this driver is producing. diff --git a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c index 7d28b700dc..554af2281e 100644 --- a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c +++ b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c @@ -5,7 +5,7 @@ EFI Driver Model related protocols, manage Unicode string tables for UEFI Drivers, and print messages on the console output and standard error devices. - Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2008, 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 @@ -92,15 +92,17 @@ EfiGetSystemConfigurationTable ( instances specified by ProtocolGuid. This function causes the notification function to be executed for every protocol of type - ProtocolGuid instance that exists in the system when this function is invoked. - In addition, every time a protocol of type ProtocolGuid instance is installed or reinstalled, - the notification function is also executed. This function returns the notification event - that was created. + ProtocolGuid instance that exists in the system when this function is invoked. If there are + no instances of ProtocolGuid in the handle database at the time this function is invoked, + then the notification function is still executed one time. In addition, every time a protocol + of type ProtocolGuid instance is installed or reinstalled, the notification function is also + executed. This function returns the notification event that was created. If ProtocolGuid is NULL, then ASSERT(). If NotifyTpl is not a legal TPL value, then ASSERT(). If NotifyFunction is NULL, then ASSERT(). If Registration is NULL, then ASSERT(). + @param ProtocolGuid Supplies GUID of the protocol upon whose installation the event is fired. @param NotifyTpl Supplies the task priority level of the event notifications. @param NotifyFunction Supplies the function to notify when the event is signaled. @@ -143,7 +145,7 @@ EfiCreateProtocolNotifyEvent( ASSERT_EFI_ERROR (Status); // - // Register for protocol notifactions on this event + // Register for protocol notifications on this event // Status = gBS->RegisterProtocolNotify ( @@ -454,9 +456,9 @@ EfiReleaseLock ( function. @retval EFI_SUCCESS ControllerHandle is managed by the driver - specifed by DriverBindingHandle. + specified by DriverBindingHandle. @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver - specifed by DriverBindingHandle. + specified by DriverBindingHandle. **/ EFI_STATUS @@ -579,7 +581,7 @@ EfiTestChildHandle ( @retval EFI_SUCCESS The Unicode string that matches the language specified by Language was found - in the table of Unicoide strings UnicodeStringTable, + in the table of Unicode strings UnicodeStringTable, and it was returned in UnicodeString. @retval EFI_INVALID_PARAMETER Language is NULL. @retval EFI_INVALID_PARAMETER UnicodeString is NULL. @@ -659,7 +661,7 @@ LookupUnicodeString ( RFC 4646 language code for the Unicode string to look up and return. If Iso639Language is TRUE, then this ASCII string is not assumed to be Null-terminated, and only the first three - chacters are used. If Iso639Language is FALSE, then this ASCII + characters are used. If Iso639Language is FALSE, then this ASCII string must be Null-terminated. @param SupportedLanguages A pointer to a Null-terminated ASCII string that contains a set of ISO 639-2 or RFC 4646 language codes that the Unicode @@ -689,7 +691,6 @@ LookupUnicodeString ( **/ EFI_STATUS - EFIAPI LookupUnicodeString2 ( IN CONST CHAR8 *Language, @@ -1188,3 +1189,229 @@ FreeUnicodeStringTable ( return EFI_SUCCESS; } + +/** + Returns a pointer to an allocated buffer that contains the contents of a + variable retrieved through the UEFI Runtime Service GetVariable(). The + returned buffer is allocated using AllocatePool(). The caller is responsible + for freeing this buffer with FreePool(). + + If Name is NULL, then ASSERT(). + If Guid is NULL, then ASSERT(). + + @param[in] Name Pointer to a Null-terminated Unicode string. + @param[in] Guid Pointer to an EFI_GUID structure + + @retval NULL The variable could not be retrieved. + @retval NULL There are not enough resources available for the variable contents. + @retval Other A pointer to allocated buffer containing the variable contents. + +**/ +VOID * +EFIAPI +GetVariable ( + IN CONST CHAR16 *Name, + IN CONST EFI_GUID *Guid + ) +{ + EFI_STATUS Status; + UINTN Size; + VOID *Value; + + ASSERT (Name != NULL); + ASSERT (Guid != NULL); + + // + // Try to get the variable size. + // + Value = NULL; + Size = 0; + Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &Size, Value); + if (Status != EFI_BUFFER_TOO_SMALL) { + return NULL; + } + + // + // Allocate buffer to get the variable. + // + Value = AllocatePool (Size); + if (Value == NULL) { + return NULL; + } + + // + // Get the variable data. + // + Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &Size, Value); + if (EFI_ERROR (Status)) { + FreePool(Value); + return NULL; + } + + return Value; +} + + +/** + Returns a pointer to an allocated buffer that contains the contents of a + variable retrieved through the UEFI Runtime Service GetVariable(). This + function always uses the EFI_GLOBAL_VARIABLE GUID to retrieve variables. + The returned buffer is allocated using AllocatePool(). The caller is + responsible for freeing this buffer with FreePool(). + + If Name is NULL, then ASSERT(). + + @param[in] Name Pointer to a Null-terminated Unicode string. + + @retval NULL The variable could not be retrieved. + @retval NULL There are not enough resources available for the variable contents. + @retval Other A pointer to allocated buffer containing the variable contents. + +**/ +VOID * +EFIAPI +GetEfiGlobalVariable ( + IN CONST CHAR16 *Name + ) +{ + return GetVariable (Name, &gEfiGlobalVariableGuid); +} + + +/** + Returns a pointer to an allocated buffer that contains the best matching language + from a set of supported languages. + + This function supports both ISO 639-2 and RFC 4646 language codes, but language + code types may not be mixed in a single call to this function. The language + code returned is allocated using AllocatePool(). The caller is responsible for + freeing the allocated buffer using FreePool(). This function supports a variable + argument list that allows the caller to pass in a prioritized list of language + codes to test against all the language codes in SupportedLanguages. + + If SupportedLanguages is NULL, then ASSERT(). + + @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string that + contains a set of language codes in the format + specified by Iso639Language. + @param[in] Iso639Language If TRUE, then all language codes are assumed to be + in ISO 639-2 format. If FALSE, then all language + codes are assumed to be in RFC 4646 language format + @param[in] ... A variable argument list that contains pointers to + Null-terminated ASCII strings that contain one or more + language codes in the format specified by Iso639Language. + The first language code from each of these language + code lists is used to determine if it is an exact or + close match to any of the language codes in + SupportedLanguages. Close matches only apply to RFC 4646 + language codes, and the matching algorithm from RFC 4647 + is used to determine if a close match is present. If + an exact or close match is found, then the matching + language code from SupportedLanguages is returned. If + no matches are found, then the next variable argument + parameter is evaluated. The variable argument list + is terminated by a NULL. + + @retval NULL The best matching language could not be found in SupportedLanguages. + @retval NULL There are not enough resources available to return the best matching + language. + @retval Other A pointer to a Null-terminated ASCII string that is the best matching + language in SupportedLanguages. + +**/ +CHAR8 * +EFIAPI +GetBestLanguage ( + IN CONST CHAR8 *SupportedLanguages, + IN BOOLEAN Iso639Language, + ... + ) +{ + VA_LIST Args; + CHAR8 *Language; + UINTN CompareLength; + UINTN LanguageLength; + CONST CHAR8 *Supported; + CHAR8 *BestLanguage; + + ASSERT (SupportedLanguages != NULL); + + VA_START (Args, Iso639Language); + while ((Language = VA_ARG (Args, CHAR8 *)) != NULL) { + // + // Default to ISO 639-2 mode + // + CompareLength = 3; + LanguageLength = MIN (3, AsciiStrLen (Language)); + + // + // If in RFC 4646 mode, then determine the length of the first RFC 4646 language code in Language + // + if (!Iso639Language) { + for (LanguageLength = 0; Language[LanguageLength] != 0 && Language[LanguageLength] != ';'; LanguageLength++); + } + + // + // Trim back the length of Language used until it is empty + // + while (LanguageLength > 0) { + // + // Loop through all language codes in SupportedLanguages + // + for (Supported = SupportedLanguages; *Supported != '\0'; Supported += CompareLength) { + // + // In RFC 4646 mode, then Loop through all language codes in SupportedLanguages + // + if (!Iso639Language) { + // + // Skip ';' characters in Supported + // + for (; *Supported != '\0' && *Supported == ';'; Supported++); + // + // Determine the length of the next language code in Supported + // + for (CompareLength = 0; Supported[CompareLength] != 0 && Supported[CompareLength] != ';'; CompareLength++); + // + // If Language is longer than the Supported, then skip to the next language + // + if (LanguageLength > CompareLength) { + continue; + } + } + // + // See if the first LanguageLength characters in Supported match Language + // + if (AsciiStrnCmp (Supported, Language, LanguageLength) == 0) { + VA_END (Args); + // + // Allocate, copy, and return the best matching language code from SupportedLanguages + // + BestLanguage = AllocateZeroPool (CompareLength + 1); + if (BestLanguage == NULL) { + return NULL; + } + return CopyMem (BestLanguage, Supported, CompareLength); + } + } + + if (Iso639Language) { + // + // If ISO 639 mode, then each language can only be tested once + // + LanguageLength = 0; + } else { + // + // If RFC 4646 mode, then trim Language from the right to the next '-' character + // + for (LanguageLength--; LanguageLength > 0 && Language[LanguageLength] != '-'; LanguageLength--); + } + } + } + VA_END (Args); + + // + // No matches were found + // + return NULL; +} + diff --git a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibInternal.h b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibInternal.h index 60767a0dbb..e4bc433be4 100644 --- a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibInternal.h +++ b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibInternal.h @@ -29,8 +29,10 @@ #include #include +#include #include #include +#include #include #include #include diff --git a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibPrint.c b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibPrint.c index 6d1fda6dc2..3f4f4f5f57 100644 --- a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibPrint.c +++ b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibPrint.c @@ -59,12 +59,14 @@ InternalPrint ( IN VA_LIST Marker ) { + EFI_STATUS Status; UINTN Return; CHAR16 *Buffer; UINTN BufferSize; ASSERT (Format != NULL); ASSERT (((UINTN) Format & BIT0) == 0); + ASSERT (Console != NULL); BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16); @@ -77,7 +79,10 @@ InternalPrint ( // // To be extra safe make sure Console has been initialized // - Console->OutputString (Console, Buffer); + Status = Console->OutputString (Console, Buffer); + if (EFI_ERROR (Status)) { + Return = 0; + } } FreePool (Buffer); @@ -96,6 +101,7 @@ InternalPrint ( PcdUefiLibMaxPrintBufferSize characters are sent to ConOut. If Format is NULL, then ASSERT(). If Format is not aligned on a 16-bit boundary, then ASSERT(). + If gST->ConOut is NULL, then ASSERT(). @param Format Null-terminated Unicode format string. @param ... Variable argument list whose contents are accessed based @@ -134,6 +140,7 @@ Print ( PcdUefiLibMaxPrintBufferSize characters are sent to StdErr. If Format is NULL, then ASSERT(). If Format is not aligned on a 16-bit boundary, then ASSERT(). + If gST->StdErr is NULL, then ASSERT(). @param Format Null-terminated Unicode format string. @param ... Variable argument list whose contents are accessed based @@ -188,11 +195,13 @@ AsciiInternalPrint ( IN VA_LIST Marker ) { + EFI_STATUS Status; UINTN Return; CHAR16 *Buffer; UINTN BufferSize; ASSERT (Format != NULL); + ASSERT (Console != NULL); BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16); @@ -205,7 +214,10 @@ AsciiInternalPrint ( // // To be extra safe make sure Console has been initialized // - Console->OutputString (Console, Buffer); + Status = Console->OutputString (Console, Buffer); + if (EFI_ERROR (Status)) { + Return = 0; + } } FreePool (Buffer); @@ -223,6 +235,7 @@ AsciiInternalPrint ( string is greater than PcdUefiLibMaxPrintBufferSize, then only the first PcdUefiLibMaxPrintBufferSize characters are sent to ConOut. If Format is NULL, then ASSERT(). + If gST->ConOut is NULL, then ASSERT(). @param Format Null-terminated ASCII format string. @param ... Variable argument list whose contents are accessed based @@ -261,6 +274,7 @@ AsciiPrint ( string is greater than PcdUefiLibMaxPrintBufferSize, then only the first PcdUefiLibMaxPrintBufferSize characters are sent to StdErr. If Format is NULL, then ASSERT(). + If gST->StdErr is NULL, then ASSERT(). @param Format Null-terminated ASCII format string. @param ... Variable argument list whose contents are accessed based @@ -347,6 +361,9 @@ InternalPrintGraphic ( EFI_UGA_DRAW_PROTOCOL *UgaDraw; EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto; EFI_HANDLE ConsoleHandle; + UINTN Width; + UINTN Height; + UINTN Delta; HorizontalResolution = 0; VerticalResolution = 0; @@ -355,6 +372,8 @@ InternalPrintGraphic ( ConsoleHandle = gST->ConsoleOutHandle; + ASSERT( ConsoleHandle != NULL); + Status = gBS->HandleProtocol ( ConsoleHandle, &gEfiGraphicsOutputProtocolGuid, @@ -464,7 +483,9 @@ InternalPrintGraphic ( // Status = HiiFont->StringToImage ( HiiFont, - EFI_HII_IGNORE_IF_NO_GLYPH, + EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP | + EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y | + EFI_HII_IGNORE_LINE_BREAK, Buffer, &FontInfo, &Blt, @@ -478,11 +499,20 @@ InternalPrintGraphic ( if (!EFI_ERROR (Status)) { ASSERT (RowInfoArray != NULL); // - // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will + // Explicit Line break characters are ignored, so the updated parameter RowInfoArraySize by StringToImage will // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure. // ASSERT (RowInfoArraySize <= 1); + if (RowInfoArraySize != 0) { + Width = RowInfoArray[0].LineWidth; + Height = RowInfoArray[0].LineHeight; + Delta = Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL); + } else { + Width = 0; + Height = 0; + Delta = 0; + } Status = UgaDraw->Blt ( UgaDraw, (EFI_UGA_PIXEL *) Blt->Image.Bitmap, @@ -491,9 +521,9 @@ InternalPrintGraphic ( PointY, PointX, PointY, - RowInfoArray[0].LineWidth, - RowInfoArray[0].LineHeight, - Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) + Width, + Height, + Delta ); } else { goto Error; @@ -505,7 +535,11 @@ InternalPrintGraphic ( // // Calculate the number of actual printed characters // + if (RowInfoArraySize != 0) { PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1; + } else { + PrintNum = 0; + } FreePool (RowInfoArray); FreePool (Blt); @@ -540,6 +574,7 @@ Error: string is printed, and 0 is returned. If Format is NULL, then ASSERT(). If Format is not aligned on a 16-bit boundary, then ASSERT(). + If gST->ConsoleOutputHandle is NULL, then ASSERT(). @param PointX X coordinate to print the string. @param PointY Y coordinate to print the string. @@ -616,6 +651,7 @@ PrintXY ( If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no string is printed, and 0 is returned. If Format is NULL, then ASSERT(). + If gST->ConsoleOutputHandle is NULL, then ASSERT(). @param PointX X coordinate to print the string. @param PointY Y coordinate to print the string. -- 2.39.2