summaryrefslogtreecommitdiff
path: root/MdePkg/Library/BasePrintLib
diff options
context:
space:
mode:
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2006-06-22 06:08:00 +0000
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2006-06-22 06:08:00 +0000
commit4ba61e5e2a1b3cec7faaad36c252738f6f57f8a6 (patch)
treeee885b41f6738849dbe28aa291c2e4df0d1fb98f /MdePkg/Library/BasePrintLib
parentf7c3054530a4603d3d611e7433ed8768a6076909 (diff)
downloadedk2-platforms-4ba61e5e2a1b3cec7faaad36c252738f6f57f8a6.tar.xz
1. UINTN & INTN issue for EBC architecture:
The MAX_BIT of EBC will no longer be fixed to bit 63. It is defined as (1ULL << (sizeof (INTN) * 8 - 1)). Make EdkModulePkg & MdePkg EBC compiler clean: treat all EFI_STATUS error code as variable. 2. PrintLib Complete all missing ASSERT()s. Fix “\n” & “%\n” issue thanks to the clarification of MWG 0.56d. Adjust StatusString array to support EBC build. 3. BaseMemoryLib Adjust ASSERT () & function header of ComparaMem, SetMemXX, ScanMemXX to synchronize with MWG 0.56d. 4.SmbusLib Change Pec bit to bit 22 SmBusAddress to synchronize MWG 0.56d. Add ASSERT()s to check if length is illegal for SmBusBlockWrite() & SmBusProcessBlock() since it is 6 bit now. 5. PerformanceLib Rename “EdkDxePerformanceLib” & “EdkPeiPerformanceLib” to “DxePerformanceLib” & “PeiPerformanceLib” respectively. Synchronize the function header of GetPerformanceMeasurement() with MWG 0.56d. 6. BasePeCoffLoaderLib. Make PeCoffLoaderLoadImage () Assert() if ImageContext is NULL> Make PeCoffLoaderLoadImage () return RETURN_INVALID_PARAMETER if the ImageAddress in ImageContext is 0. Adjust some coding style. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@593 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library/BasePrintLib')
-rw-r--r--MdePkg/Library/BasePrintLib/PrintLib.c116
1 files changed, 73 insertions, 43 deletions
diff --git a/MdePkg/Library/BasePrintLib/PrintLib.c b/MdePkg/Library/BasePrintLib/PrintLib.c
index e940bedb34..0a8c22ed16 100644
--- a/MdePkg/Library/BasePrintLib/PrintLib.c
+++ b/MdePkg/Library/BasePrintLib/PrintLib.c
@@ -16,45 +16,41 @@
#include "PrintLibInternal.h"
-typedef struct {
- RETURN_STATUS Status;
- CHAR8 *String;
-} STATUS_LOOKUP_TABLE_ENTRY;
-
-static CONST STATUS_LOOKUP_TABLE_ENTRY StatusString[] = {
- { RETURN_SUCCESS, "Success" },
- { RETURN_LOAD_ERROR, "Load Error" },
- { RETURN_INVALID_PARAMETER, "Invalid Parameter" },
- { RETURN_UNSUPPORTED, "Unsupported" },
- { RETURN_BAD_BUFFER_SIZE, "Bad Buffer Size" },
- { RETURN_BUFFER_TOO_SMALL, "Buffer Too Small" },
- { RETURN_NOT_READY, "Not Ready" },
- { RETURN_DEVICE_ERROR, "Device Error" },
- { RETURN_WRITE_PROTECTED, "Write Protected" },
- { RETURN_OUT_OF_RESOURCES, "Out of Resources" },
- { RETURN_VOLUME_CORRUPTED, "Volume Corrupt" },
- { RETURN_VOLUME_FULL, "Volume Full" },
- { RETURN_NO_MEDIA, "No Media" },
- { RETURN_MEDIA_CHANGED, "Media changed" },
- { RETURN_NOT_FOUND, "Not Found" },
- { RETURN_ACCESS_DENIED, "Access Denied" },
- { RETURN_NO_RESPONSE, "No Response" },
- { RETURN_NO_MAPPING, "No mapping" },
- { RETURN_TIMEOUT, "Time out" },
- { RETURN_NOT_STARTED, "Not started" },
- { RETURN_ALREADY_STARTED, "Already started" },
- { RETURN_ABORTED, "Aborted" },
- { RETURN_ICMP_ERROR, "ICMP Error" },
- { RETURN_TFTP_ERROR, "TFTP Error" },
- { RETURN_PROTOCOL_ERROR, "Protocol Error" },
- { RETURN_WARN_UNKNOWN_GLYPH, "Warning Unknown Glyph" },
- { RETURN_WARN_DELETE_FAILURE, "Warning Delete Failure" },
- { RETURN_WARN_WRITE_FAILURE, "Warning Write Failure" },
- { RETURN_WARN_BUFFER_TOO_SMALL, "Warning Buffer Too Small" },
- { 0, NULL }
+#define WARNING_STATUS_NUMBER 4
+#define ERROR_STATUS_NUMBER 24
+
+STATIC CONST CHAR8 *StatusString [] = {
+ "Success", // RETURN_SUCCESS = 0
+ "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1
+ "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2
+ "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3
+ "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4
+ "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
+ "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
+ "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
+ "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
+ "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
+ "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
+ "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
+ "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
+ "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
+ "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
+ "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
+ "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
+ "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
+ "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
+ "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
+ "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
+ "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
+ "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
+ "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
+ "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
+ "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
+ "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
+ "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
+ "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
};
-
/**
Worker function that produces a Null-terminated string in an output buffer
based on a Null-terminated format string and a VA_LIST argument list.
@@ -92,7 +88,7 @@ BasePrintLibVSPrint (
UINTN Width;
UINTN Precision;
INT64 Value;
- CHAR8 *ArgumentString;
+ CONST CHAR8 *ArgumentString;
UINTN Character;
GUID *TmpGuid;
TIME *TmpTime;
@@ -113,7 +109,6 @@ BasePrintLibVSPrint (
return 0;
}
ASSERT (Buffer != NULL);
- ASSERT (Format != NULL);
OriginalBuffer = Buffer;
@@ -123,9 +118,19 @@ BasePrintLibVSPrint (
BytesPerOutputCharacter = 1;
}
if ((Flags & FORMAT_UNICODE) != 0) {
+ //
+ // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
+ // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
+ //
+ ASSERT (StrSize ((CHAR16 *) Format) != 0);
BytesPerFormatCharacter = 2;
FormatMask = 0xffff;
} else {
+ //
+ // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
+ // Ascii characters if PcdMaximumUnicodeStringLength is not zero.
+ //
+ ASSERT (AsciiStrSize (Format) != 0);
BytesPerFormatCharacter = 1;
FormatMask = 0xff;
}
@@ -381,9 +386,18 @@ BasePrintLibVSPrint (
case 'r':
Status = VA_ARG (Marker, RETURN_STATUS);
ArgumentString = ValueBuffer;
- for (Index = 0; StatusString[Index].String != NULL; Index++) {
- if (Status == StatusString[Index].Status) {
- ArgumentString = StatusString[Index].String;
+ if (RETURN_ERROR (Status)) {
+ //
+ // Clear error bit
+ //
+ Index = Status & ~MAX_BIT;
+ if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {
+ ArgumentString = StatusString [Index + WARNING_STATUS_NUMBER];
+ }
+ } else {
+ Index = Status;
+ if (Index <= WARNING_STATUS_NUMBER) {
+ ArgumentString = StatusString [Index];
}
}
if (ArgumentString == ValueBuffer) {
@@ -392,7 +406,7 @@ BasePrintLibVSPrint (
break;
case '\n':
- ArgumentString = "\r\n";
+ ArgumentString = "\n\r";
break;
case '%':
@@ -405,6 +419,11 @@ BasePrintLibVSPrint (
break;
}
break;
+
+ case '\n':
+ ArgumentString = "\n\r";
+ break;
+
default:
ArgumentString = (CHAR8 *)&FormatCharacter;
Flags |= ARGUMENT_UNICODE;
@@ -521,7 +540,18 @@ BasePrintLibVSPrint (
// Null terminate the Unicode or ASCII string
//
Buffer = BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter);
+ //
+ // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
+ // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
+ //
+ ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0));
+ //
+ // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
+ // Ascii characters if PcdMaximumUnicodeStringLength is not zero.
+ //
+ ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));
+
return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);
}