]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Library/BaseLib.h
MdePkg/BaseLib: add PatchInstructionX86()
[mirror_edk2.git] / MdePkg / Include / Library / BaseLib.h
index 05014a3b6d79f4cbfdbf5c9edd83a7c610a3f3fe..eb2899f8524e7a8e1856d68f0c25ced58c4253fb 100644 (file)
@@ -1,13 +1,13 @@
 /** @file\r
   Provides string functions, linked list functions, math functions, synchronization\r
-  functions, and CPU architecture-specific functions.\r
+  functions, file path functions, and CPU architecture-specific functions.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
-Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
+http://opensource.org/licenses/bsd-license.php.\r
 \r
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -22,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 #if   defined (MDE_CPU_IA32)\r
 ///\r
-/// IA-32 architecture context buffer used by SetJump() and LongJump()\r
+/// The IA-32 architecture context buffer used by SetJump() and LongJump().\r
 ///\r
 typedef struct {\r
   UINT32                            Ebx;\r
@@ -40,7 +40,7 @@ typedef struct {
 #if defined (MDE_CPU_IPF)\r
 \r
 ///\r
-/// Itanium architecture context buffer used by SetJump() and LongJump()\r
+/// The Itanium architecture context buffer used by SetJump() and LongJump().\r
 ///\r
 typedef struct {\r
   UINT64                            F2[2];\r
@@ -89,7 +89,7 @@ typedef struct {
 \r
 #if defined (MDE_CPU_X64)\r
 ///\r
-/// x64 architecture context buffer used by SetJump() and LongJump()\r
+/// The x64 architecture context buffer used by SetJump() and LongJump().\r
 ///\r
 typedef struct {\r
   UINT64                            Rbx;\r
@@ -103,7 +103,7 @@ typedef struct {
   UINT64                            R15;\r
   UINT64                            Rip;\r
   UINT64                            MxCsr;\r
-  UINT8                             XmmBuffer[160]; ///< XMM6-XMM15\r
+  UINT8                             XmmBuffer[160]; ///< XMM6-XMM15.\r
 } BASE_LIBRARY_JUMP_BUFFER;\r
 \r
 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8\r
@@ -112,7 +112,7 @@ typedef struct {
 \r
 #if defined (MDE_CPU_EBC)\r
 ///\r
-/// EBC context buffer used by SetJump() and LongJump()\r
+/// The EBC context buffer used by SetJump() and LongJump().\r
 ///\r
 typedef struct {\r
   UINT64                            R0;\r
@@ -129,7 +129,7 @@ typedef struct {
 #if defined (MDE_CPU_ARM)\r
 \r
 typedef struct {\r
-  UINT32    R3;  ///< Copy of R13\r
+  UINT32    R3;  ///< A copy of R13.\r
   UINT32    R4;\r
   UINT32    R5;\r
   UINT32    R6;\r
@@ -146,11 +146,910 @@ typedef struct {
 \r
 #endif  // defined (MDE_CPU_ARM)\r
 \r
+#if defined (MDE_CPU_AARCH64)\r
+typedef struct {\r
+  // GP regs\r
+  UINT64    X19;\r
+  UINT64    X20;\r
+  UINT64    X21;\r
+  UINT64    X22;\r
+  UINT64    X23;\r
+  UINT64    X24;\r
+  UINT64    X25;\r
+  UINT64    X26;\r
+  UINT64    X27;\r
+  UINT64    X28;\r
+  UINT64    FP;\r
+  UINT64    LR;\r
+  UINT64    IP0;\r
+\r
+  // FP regs\r
+  UINT64    D8;\r
+  UINT64    D9;\r
+  UINT64    D10;\r
+  UINT64    D11;\r
+  UINT64    D12;\r
+  UINT64    D13;\r
+  UINT64    D14;\r
+  UINT64    D15;\r
+} BASE_LIBRARY_JUMP_BUFFER;\r
+\r
+#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8\r
+\r
+#endif  // defined (MDE_CPU_AARCH64)\r
+\r
+\r
 //\r
 // String Services\r
 //\r
 \r
+\r
+/**\r
+  Returns the length of a Null-terminated Unicode string.\r
+\r
+  This function is similar as strlen_s defined in C11.\r
+\r
+  If String is not aligned on a 16-bit boundary, then ASSERT().\r
+\r
+  @param  String   A pointer to a Null-terminated Unicode string.\r
+  @param  MaxSize  The maximum number of Destination Unicode\r
+                   char, including terminating null char.\r
+\r
+  @retval 0        If String is NULL.\r
+  @retval MaxSize  If there is no null character in the first MaxSize characters of String.\r
+  @return The number of characters that percede the terminating null character.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+StrnLenS (\r
+  IN CONST CHAR16              *String,\r
+  IN UINTN                     MaxSize\r
+  );\r
+\r
+/**\r
+  Returns the size of a Null-terminated Unicode string in bytes, including the\r
+  Null terminator.\r
+\r
+  This function returns the size of the Null-terminated Unicode string\r
+  specified by String in bytes, including the Null terminator.\r
+\r
+  If String is not aligned on a 16-bit boundary, then ASSERT().\r
+\r
+  @param  String   A pointer to a Null-terminated Unicode string.\r
+  @param  MaxSize  The maximum number of Destination Unicode\r
+                   char, including the Null terminator.\r
+\r
+  @retval 0  If String is NULL.\r
+  @retval (sizeof (CHAR16) * (MaxSize + 1))\r
+             If there is no Null terminator in the first MaxSize characters of\r
+             String.\r
+  @return The size of the Null-terminated Unicode string in bytes, including\r
+          the Null terminator.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+StrnSizeS (\r
+  IN CONST CHAR16              *String,\r
+  IN UINTN                     MaxSize\r
+  );\r
+\r
+/**\r
+  Copies the string pointed to by Source (including the terminating null char)\r
+  to the array pointed to by Destination.\r
+\r
+  This function is similar as strcpy_s defined in C11.\r
+\r
+  If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
+  If Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Destination              A pointer to a Null-terminated Unicode string.\r
+  @param  DestMax                  The maximum number of Destination Unicode\r
+                                   char, including terminating null char.\r
+  @param  Source                   A pointer to a Null-terminated Unicode string.\r
+\r
+  @retval RETURN_SUCCESS           String is copied.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than StrLen(Source).\r
+  @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
+                                   If Source is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not zero,\r
+                                    and DestMax is greater than \r
+                                    PcdMaximumUnicodeStringLength.\r
+                                   If DestMax is 0.\r
+  @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrCpyS (\r
+  OUT CHAR16       *Destination,\r
+  IN  UINTN        DestMax,\r
+  IN  CONST CHAR16 *Source\r
+  );\r
+\r
+/**\r
+  Copies not more than Length successive char from the string pointed to by\r
+  Source to the array pointed to by Destination. If no null char is copied from\r
+  Source, then Destination[Length] is always set to null.\r
+\r
+  This function is similar as strncpy_s defined in C11.\r
+\r
+  If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().\r
+  If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Destination              A pointer to a Null-terminated Unicode string.\r
+  @param  DestMax                  The maximum number of Destination Unicode\r
+                                   char, including terminating null char.\r
+  @param  Source                   A pointer to a Null-terminated Unicode string.\r
+  @param  Length                   The maximum number of Unicode characters to copy.\r
+\r
+  @retval RETURN_SUCCESS           String is copied.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than \r
+                                   MIN(StrLen(Source), Length).\r
+  @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
+                                   If Source is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not zero,\r
+                                    and DestMax is greater than \r
+                                    PcdMaximumUnicodeStringLength.\r
+                                   If DestMax is 0.\r
+  @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrnCpyS (\r
+  OUT CHAR16       *Destination,\r
+  IN  UINTN        DestMax,\r
+  IN  CONST CHAR16 *Source,\r
+  IN  UINTN        Length\r
+  );\r
+\r
+/**\r
+  Appends a copy of the string pointed to by Source (including the terminating\r
+  null char) to the end of the string pointed to by Destination.\r
+\r
+  This function is similar as strcat_s defined in C11.\r
+\r
+  If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
+  If Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Destination              A pointer to a Null-terminated Unicode string.\r
+  @param  DestMax                  The maximum number of Destination Unicode\r
+                                   char, including terminating null char.\r
+  @param  Source                   A pointer to a Null-terminated Unicode string.\r
+\r
+  @retval RETURN_SUCCESS           String is appended.\r
+  @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than \r
+                                   StrLen(Destination).\r
+  @retval RETURN_BUFFER_TOO_SMALL  If (DestMax - StrLen(Destination)) is NOT\r
+                                   greater than StrLen(Source).\r
+  @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
+                                   If Source is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not zero,\r
+                                    and DestMax is greater than \r
+                                    PcdMaximumUnicodeStringLength.\r
+                                   If DestMax is 0.\r
+  @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrCatS (\r
+  IN OUT CHAR16       *Destination,\r
+  IN     UINTN        DestMax,\r
+  IN     CONST CHAR16 *Source\r
+  );\r
+\r
+/**\r
+  Appends not more than Length successive char from the string pointed to by\r
+  Source to the end of the string pointed to by Destination. If no null char is\r
+  copied from Source, then Destination[StrLen(Destination) + Length] is always\r
+  set to null.\r
+\r
+  This function is similar as strncat_s defined in C11.\r
+\r
+  If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
+  If Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Destination              A pointer to a Null-terminated Unicode string.\r
+  @param  DestMax                  The maximum number of Destination Unicode\r
+                                   char, including terminating null char.\r
+  @param  Source                   A pointer to a Null-terminated Unicode string.\r
+  @param  Length                   The maximum number of Unicode characters to copy.\r
+\r
+  @retval RETURN_SUCCESS           String is appended.\r
+  @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than\r
+                                   StrLen(Destination).\r
+  @retval RETURN_BUFFER_TOO_SMALL  If (DestMax - StrLen(Destination)) is NOT\r
+                                   greater than MIN(StrLen(Source), Length).\r
+  @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
+                                   If Source is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not zero,\r
+                                    and DestMax is greater than \r
+                                    PcdMaximumUnicodeStringLength.\r
+                                   If DestMax is 0.\r
+  @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrnCatS (\r
+  IN OUT CHAR16       *Destination,\r
+  IN     UINTN        DestMax,\r
+  IN     CONST CHAR16 *Source,\r
+  IN     UINTN        Length\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated Unicode decimal string to a value of type UINTN.\r
+\r
+  This function outputs a value of type UINTN by interpreting the contents of\r
+  the Unicode string specified by String as a decimal number. The format of the\r
+  input Unicode string String is:\r
+\r
+                  [spaces] [decimal digits].\r
+\r
+  The valid decimal digit character is in the range [0-9]. The function will\r
+  ignore the pad space, which includes spaces or tab characters, before\r
+  [decimal digits]. The running zero in the beginning of [decimal digits] will\r
+  be ignored. Then, the function stops at the first character that is a not a\r
+  valid decimal character or a Null-terminator, whichever one comes first.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Data is NULL, then ASSERT().\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If String has no valid decimal digits in the above format, then 0 is stored\r
+  at the location pointed to by Data.\r
+  If the number represented by String exceeds the range defined by UINTN, then\r
+  MAX_UINTN is stored at the location pointed to by Data.\r
+\r
+  If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+  is stored at the location pointed to by EndPointer. If String has no valid\r
+  decimal digits right after the optional pad spaces, the value of String is\r
+  stored at the location pointed to by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Data                     Pointer to the converted value.\r
+\r
+  @retval RETURN_SUCCESS           Value is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not\r
+                                   zero, and String contains more than\r
+                                   PcdMaximumUnicodeStringLength Unicode\r
+                                   characters, not including the\r
+                                   Null-terminator.\r
+  @retval RETURN_UNSUPPORTED       If the number represented by String exceeds\r
+                                   the range defined by UINTN.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrDecimalToUintnS (\r
+  IN  CONST CHAR16             *String,\r
+  OUT       CHAR16             **EndPointer,  OPTIONAL\r
+  OUT       UINTN              *Data\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated Unicode decimal string to a value of type UINT64.\r
+\r
+  This function outputs a value of type UINT64 by interpreting the contents of\r
+  the Unicode string specified by String as a decimal number. The format of the\r
+  input Unicode string String is:\r
+\r
+                  [spaces] [decimal digits].\r
+\r
+  The valid decimal digit character is in the range [0-9]. The function will\r
+  ignore the pad space, which includes spaces or tab characters, before\r
+  [decimal digits]. The running zero in the beginning of [decimal digits] will\r
+  be ignored. Then, the function stops at the first character that is a not a\r
+  valid decimal character or a Null-terminator, whichever one comes first.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Data is NULL, then ASSERT().\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If String has no valid decimal digits in the above format, then 0 is stored\r
+  at the location pointed to by Data.\r
+  If the number represented by String exceeds the range defined by UINT64, then\r
+  MAX_UINT64 is stored at the location pointed to by Data.\r
+\r
+  If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+  is stored at the location pointed to by EndPointer. If String has no valid\r
+  decimal digits right after the optional pad spaces, the value of String is\r
+  stored at the location pointed to by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Data                     Pointer to the converted value.\r
+\r
+  @retval RETURN_SUCCESS           Value is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not\r
+                                   zero, and String contains more than\r
+                                   PcdMaximumUnicodeStringLength Unicode\r
+                                   characters, not including the\r
+                                   Null-terminator.\r
+  @retval RETURN_UNSUPPORTED       If the number represented by String exceeds\r
+                                   the range defined by UINT64.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrDecimalToUint64S (\r
+  IN  CONST CHAR16             *String,\r
+  OUT       CHAR16             **EndPointer,  OPTIONAL\r
+  OUT       UINT64             *Data\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated Unicode hexadecimal string to a value of type\r
+  UINTN.\r
+\r
+  This function outputs a value of type UINTN by interpreting the contents of\r
+  the Unicode string specified by String as a hexadecimal number. The format of\r
+  the input Unicode string String is:\r
+\r
+                  [spaces][zeros][x][hexadecimal digits].\r
+\r
+  The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
+  The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.\r
+  If "x" appears in the input string, it must be prefixed with at least one 0.\r
+  The function will ignore the pad space, which includes spaces or tab\r
+  characters, before [zeros], [x] or [hexadecimal digit]. The running zero\r
+  before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts\r
+  after [x] or the first valid hexadecimal digit. Then, the function stops at\r
+  the first character that is a not a valid hexadecimal character or NULL,\r
+  whichever one comes first.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Data is NULL, then ASSERT().\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If String has no valid hexadecimal digits in the above format, then 0 is\r
+  stored at the location pointed to by Data.\r
+  If the number represented by String exceeds the range defined by UINTN, then\r
+  MAX_UINTN is stored at the location pointed to by Data.\r
+\r
+  If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+  is stored at the location pointed to by EndPointer. If String has no valid\r
+  hexadecimal digits right after the optional pad spaces, the value of String\r
+  is stored at the location pointed to by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Data                     Pointer to the converted value.\r
+\r
+  @retval RETURN_SUCCESS           Value is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not\r
+                                   zero, and String contains more than\r
+                                   PcdMaximumUnicodeStringLength Unicode\r
+                                   characters, not including the\r
+                                   Null-terminator.\r
+  @retval RETURN_UNSUPPORTED       If the number represented by String exceeds\r
+                                   the range defined by UINTN.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrHexToUintnS (\r
+  IN  CONST CHAR16             *String,\r
+  OUT       CHAR16             **EndPointer,  OPTIONAL\r
+  OUT       UINTN              *Data\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated Unicode hexadecimal string to a value of type\r
+  UINT64.\r
+\r
+  This function outputs a value of type UINT64 by interpreting the contents of\r
+  the Unicode string specified by String as a hexadecimal number. The format of\r
+  the input Unicode string String is:\r
+\r
+                  [spaces][zeros][x][hexadecimal digits].\r
+\r
+  The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
+  The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.\r
+  If "x" appears in the input string, it must be prefixed with at least one 0.\r
+  The function will ignore the pad space, which includes spaces or tab\r
+  characters, before [zeros], [x] or [hexadecimal digit]. The running zero\r
+  before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts\r
+  after [x] or the first valid hexadecimal digit. Then, the function stops at\r
+  the first character that is a not a valid hexadecimal character or NULL,\r
+  whichever one comes first.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Data is NULL, then ASSERT().\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If String has no valid hexadecimal digits in the above format, then 0 is\r
+  stored at the location pointed to by Data.\r
+  If the number represented by String exceeds the range defined by UINT64, then\r
+  MAX_UINT64 is stored at the location pointed to by Data.\r
+\r
+  If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+  is stored at the location pointed to by EndPointer. If String has no valid\r
+  hexadecimal digits right after the optional pad spaces, the value of String\r
+  is stored at the location pointed to by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Data                     Pointer to the converted value.\r
+\r
+  @retval RETURN_SUCCESS           Value is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not\r
+                                   zero, and String contains more than\r
+                                   PcdMaximumUnicodeStringLength Unicode\r
+                                   characters, not including the\r
+                                   Null-terminator.\r
+  @retval RETURN_UNSUPPORTED       If the number represented by String exceeds\r
+                                   the range defined by UINT64.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrHexToUint64S (\r
+  IN  CONST CHAR16             *String,\r
+  OUT       CHAR16             **EndPointer,  OPTIONAL\r
+  OUT       UINT64             *Data\r
+  );\r
+\r
+/**\r
+  Returns the length of a Null-terminated Ascii string.\r
+\r
+  This function is similar as strlen_s defined in C11.\r
+\r
+  @param  String   A pointer to a Null-terminated Ascii string.\r
+  @param  MaxSize  The maximum number of Destination Ascii\r
+                   char, including terminating null char.\r
+\r
+  @retval 0        If String is NULL.\r
+  @retval MaxSize  If there is no null character in the first MaxSize characters of String.\r
+  @return The number of characters that percede the terminating null character.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+AsciiStrnLenS (\r
+  IN CONST CHAR8               *String,\r
+  IN UINTN                     MaxSize\r
+  );\r
+\r
+/**\r
+  Returns the size of a Null-terminated Ascii string in bytes, including the\r
+  Null terminator.\r
+\r
+  This function returns the size of the Null-terminated Ascii string specified\r
+  by String in bytes, including the Null terminator.\r
+\r
+  @param  String   A pointer to a Null-terminated Ascii string.\r
+  @param  MaxSize  The maximum number of Destination Ascii\r
+                   char, including the Null terminator.\r
+\r
+  @retval 0  If String is NULL.\r
+  @retval (sizeof (CHAR8) * (MaxSize + 1))\r
+             If there is no Null terminator in the first MaxSize characters of\r
+             String.\r
+  @return The size of the Null-terminated Ascii string in bytes, including the\r
+          Null terminator.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+AsciiStrnSizeS (\r
+  IN CONST CHAR8               *String,\r
+  IN UINTN                     MaxSize\r
+  );\r
+\r
+/**\r
+  Copies the string pointed to by Source (including the terminating null char)\r
+  to the array pointed to by Destination.\r
+\r
+  This function is similar as strcpy_s defined in C11.\r
+\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Destination              A pointer to a Null-terminated Ascii string.\r
+  @param  DestMax                  The maximum number of Destination Ascii\r
+                                   char, including terminating null char.\r
+  @param  Source                   A pointer to a Null-terminated Ascii string.\r
+\r
+  @retval RETURN_SUCCESS           String is copied.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than StrLen(Source).\r
+  @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
+                                   If Source is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                    and DestMax is greater than \r
+                                    PcdMaximumAsciiStringLength.\r
+                                   If DestMax is 0.\r
+  @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrCpyS (\r
+  OUT CHAR8        *Destination,\r
+  IN  UINTN        DestMax,\r
+  IN  CONST CHAR8  *Source\r
+  );\r
+\r
+/**\r
+  Copies not more than Length successive char from the string pointed to by\r
+  Source to the array pointed to by Destination. If no null char is copied from\r
+  Source, then Destination[Length] is always set to null.\r
+\r
+  This function is similar as strncpy_s defined in C11.\r
+\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Destination              A pointer to a Null-terminated Ascii string.\r
+  @param  DestMax                  The maximum number of Destination Ascii\r
+                                   char, including terminating null char.\r
+  @param  Source                   A pointer to a Null-terminated Ascii string.\r
+  @param  Length                   The maximum number of Ascii characters to copy.\r
+\r
+  @retval RETURN_SUCCESS           String is copied.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than \r
+                                   MIN(StrLen(Source), Length).\r
+  @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
+                                   If Source is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                    and DestMax is greater than \r
+                                    PcdMaximumAsciiStringLength.\r
+                                   If DestMax is 0.\r
+  @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrnCpyS (\r
+  OUT CHAR8        *Destination,\r
+  IN  UINTN        DestMax,\r
+  IN  CONST CHAR8  *Source,\r
+  IN  UINTN        Length\r
+  );\r
+\r
+/**\r
+  Appends a copy of the string pointed to by Source (including the terminating\r
+  null char) to the end of the string pointed to by Destination.\r
+\r
+  This function is similar as strcat_s defined in C11.\r
+\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Destination              A pointer to a Null-terminated Ascii string.\r
+  @param  DestMax                  The maximum number of Destination Ascii\r
+                                   char, including terminating null char.\r
+  @param  Source                   A pointer to a Null-terminated Ascii string.\r
+\r
+  @retval RETURN_SUCCESS           String is appended.\r
+  @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than \r
+                                   StrLen(Destination).\r
+  @retval RETURN_BUFFER_TOO_SMALL  If (DestMax - StrLen(Destination)) is NOT\r
+                                   greater than StrLen(Source).\r
+  @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
+                                   If Source is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                    and DestMax is greater than \r
+                                    PcdMaximumAsciiStringLength.\r
+                                   If DestMax is 0.\r
+  @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrCatS (\r
+  IN OUT CHAR8        *Destination,\r
+  IN     UINTN        DestMax,\r
+  IN     CONST CHAR8  *Source\r
+  );\r
+\r
+/**\r
+  Appends not more than Length successive char from the string pointed to by\r
+  Source to the end of the string pointed to by Destination. If no null char is\r
+  copied from Source, then Destination[StrLen(Destination) + Length] is always\r
+  set to null.\r
+\r
+  This function is similar as strncat_s defined in C11.\r
+\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Destination              A pointer to a Null-terminated Ascii string.\r
+  @param  DestMax                  The maximum number of Destination Ascii\r
+                                   char, including terminating null char.\r
+  @param  Source                   A pointer to a Null-terminated Ascii string.\r
+  @param  Length                   The maximum number of Ascii characters to copy.\r
+\r
+  @retval RETURN_SUCCESS           String is appended.\r
+  @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than\r
+                                   StrLen(Destination).\r
+  @retval RETURN_BUFFER_TOO_SMALL  If (DestMax - StrLen(Destination)) is NOT\r
+                                   greater than MIN(StrLen(Source), Length).\r
+  @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
+                                   If Source is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                    and DestMax is greater than \r
+                                    PcdMaximumAsciiStringLength.\r
+                                   If DestMax is 0.\r
+  @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrnCatS (\r
+  IN OUT CHAR8        *Destination,\r
+  IN     UINTN        DestMax,\r
+  IN     CONST CHAR8  *Source,\r
+  IN     UINTN        Length\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated Ascii decimal string to a value of type UINTN.\r
+\r
+  This function outputs a value of type UINTN by interpreting the contents of\r
+  the Ascii string specified by String as a decimal number. The format of the\r
+  input Ascii string String is:\r
+\r
+                  [spaces] [decimal digits].\r
+\r
+  The valid decimal digit character is in the range [0-9]. The function will\r
+  ignore the pad space, which includes spaces or tab characters, before\r
+  [decimal digits]. The running zero in the beginning of [decimal digits] will\r
+  be ignored. Then, the function stops at the first character that is a not a\r
+  valid decimal character or a Null-terminator, whichever one comes first.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Data is NULL, then ASSERT().\r
+  If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
+  PcdMaximumAsciiStringLength Ascii characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If String has no valid decimal digits in the above format, then 0 is stored\r
+  at the location pointed to by Data.\r
+  If the number represented by String exceeds the range defined by UINTN, then\r
+  MAX_UINTN is stored at the location pointed to by Data.\r
+\r
+  If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+  is stored at the location pointed to by EndPointer. If String has no valid\r
+  decimal digits right after the optional pad spaces, the value of String is\r
+  stored at the location pointed to by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Ascii string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Data                     Pointer to the converted value.\r
+\r
+  @retval RETURN_SUCCESS           Value is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                   and String contains more than\r
+                                   PcdMaximumAsciiStringLength Ascii\r
+                                   characters, not including the\r
+                                   Null-terminator.\r
+  @retval RETURN_UNSUPPORTED       If the number represented by String exceeds\r
+                                   the range defined by UINTN.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrDecimalToUintnS (\r
+  IN  CONST CHAR8              *String,\r
+  OUT       CHAR8              **EndPointer,  OPTIONAL\r
+  OUT       UINTN              *Data\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated Ascii decimal string to a value of type UINT64.\r
+\r
+  This function outputs a value of type UINT64 by interpreting the contents of\r
+  the Ascii string specified by String as a decimal number. The format of the\r
+  input Ascii string String is:\r
+\r
+                  [spaces] [decimal digits].\r
+\r
+  The valid decimal digit character is in the range [0-9]. The function will\r
+  ignore the pad space, which includes spaces or tab characters, before\r
+  [decimal digits]. The running zero in the beginning of [decimal digits] will\r
+  be ignored. Then, the function stops at the first character that is a not a\r
+  valid decimal character or a Null-terminator, whichever one comes first.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Data is NULL, then ASSERT().\r
+  If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
+  PcdMaximumAsciiStringLength Ascii characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If String has no valid decimal digits in the above format, then 0 is stored\r
+  at the location pointed to by Data.\r
+  If the number represented by String exceeds the range defined by UINT64, then\r
+  MAX_UINT64 is stored at the location pointed to by Data.\r
+\r
+  If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+  is stored at the location pointed to by EndPointer. If String has no valid\r
+  decimal digits right after the optional pad spaces, the value of String is\r
+  stored at the location pointed to by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Ascii string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Data                     Pointer to the converted value.\r
+\r
+  @retval RETURN_SUCCESS           Value is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                   and String contains more than\r
+                                   PcdMaximumAsciiStringLength Ascii\r
+                                   characters, not including the\r
+                                   Null-terminator.\r
+  @retval RETURN_UNSUPPORTED       If the number represented by String exceeds\r
+                                   the range defined by UINT64.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrDecimalToUint64S (\r
+  IN  CONST CHAR8              *String,\r
+  OUT       CHAR8              **EndPointer,  OPTIONAL\r
+  OUT       UINT64             *Data\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated Ascii hexadecimal string to a value of type UINTN.\r
+\r
+  This function outputs a value of type UINTN by interpreting the contents of\r
+  the Ascii string specified by String as a hexadecimal number. The format of\r
+  the input Ascii string String is:\r
+\r
+                  [spaces][zeros][x][hexadecimal digits].\r
+\r
+  The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
+  The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If\r
+  "x" appears in the input string, it must be prefixed with at least one 0. The\r
+  function will ignore the pad space, which includes spaces or tab characters,\r
+  before [zeros], [x] or [hexadecimal digits]. The running zero before [x] or\r
+  [hexadecimal digits] will be ignored. Then, the decoding starts after [x] or\r
+  the first valid hexadecimal digit. Then, the function stops at the first\r
+  character that is a not a valid hexadecimal character or Null-terminator,\r
+  whichever on comes first.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Data is NULL, then ASSERT().\r
+  If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
+  PcdMaximumAsciiStringLength Ascii characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If String has no valid hexadecimal digits in the above format, then 0 is\r
+  stored at the location pointed to by Data.\r
+  If the number represented by String exceeds the range defined by UINTN, then\r
+  MAX_UINTN is stored at the location pointed to by Data.\r
+\r
+  If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+  is stored at the location pointed to by EndPointer. If String has no valid\r
+  hexadecimal digits right after the optional pad spaces, the value of String\r
+  is stored at the location pointed to by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Ascii string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Data                     Pointer to the converted value.\r
+\r
+  @retval RETURN_SUCCESS           Value is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                   and String contains more than\r
+                                   PcdMaximumAsciiStringLength Ascii\r
+                                   characters, not including the\r
+                                   Null-terminator.\r
+  @retval RETURN_UNSUPPORTED       If the number represented by String exceeds\r
+                                   the range defined by UINTN.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrHexToUintnS (\r
+  IN  CONST CHAR8              *String,\r
+  OUT       CHAR8              **EndPointer,  OPTIONAL\r
+  OUT       UINTN              *Data\r
+  );\r
+\r
 /**\r
+  Convert a Null-terminated Ascii hexadecimal string to a value of type UINT64.\r
+\r
+  This function outputs a value of type UINT64 by interpreting the contents of\r
+  the Ascii string specified by String as a hexadecimal number. The format of\r
+  the input Ascii string String is:\r
+\r
+                  [spaces][zeros][x][hexadecimal digits].\r
+\r
+  The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
+  The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If\r
+  "x" appears in the input string, it must be prefixed with at least one 0. The\r
+  function will ignore the pad space, which includes spaces or tab characters,\r
+  before [zeros], [x] or [hexadecimal digits]. The running zero before [x] or\r
+  [hexadecimal digits] will be ignored. Then, the decoding starts after [x] or\r
+  the first valid hexadecimal digit. Then, the function stops at the first\r
+  character that is a not a valid hexadecimal character or Null-terminator,\r
+  whichever on comes first.\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Data is NULL, then ASSERT().\r
+  If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
+  PcdMaximumAsciiStringLength Ascii characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If String has no valid hexadecimal digits in the above format, then 0 is\r
+  stored at the location pointed to by Data.\r
+  If the number represented by String exceeds the range defined by UINT64, then\r
+  MAX_UINT64 is stored at the location pointed to by Data.\r
+\r
+  If EndPointer is not NULL, a pointer to the character that stopped the scan\r
+  is stored at the location pointed to by EndPointer. If String has no valid\r
+  hexadecimal digits right after the optional pad spaces, the value of String\r
+  is stored at the location pointed to by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Ascii string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Data                     Pointer to the converted value.\r
+\r
+  @retval RETURN_SUCCESS           Value is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                   and String contains more than\r
+                                   PcdMaximumAsciiStringLength Ascii\r
+                                   characters, not including the\r
+                                   Null-terminator.\r
+  @retval RETURN_UNSUPPORTED       If the number represented by String exceeds\r
+                                   the range defined by UINT64.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrHexToUint64S (\r
+  IN  CONST CHAR8              *String,\r
+  OUT       CHAR8              **EndPointer,  OPTIONAL\r
+  OUT       UINT64             *Data\r
+  );\r
+\r
+\r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
+\r
+/**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Copies one Null-terminated Unicode string to another Null-terminated Unicode\r
   string and returns the new Unicode string.\r
 \r
@@ -167,8 +1066,8 @@ typedef struct {
   PcdMaximumUnicodeStringLength Unicode characters not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated Unicode string.\r
-  @param  Source      Pointer to a Null-terminated Unicode string.\r
+  @param  Destination The pointer to a Null-terminated Unicode string.\r
+  @param  Source      The pointer to a Null-terminated Unicode string.\r
 \r
   @return Destination.\r
 \r
@@ -182,7 +1081,9 @@ StrCpy (
 \r
 \r
 /**\r
-  Copies up to a specified length from one Null-terminated Unicode string  to \r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
+  Copies up to a specified length from one Null-terminated Unicode string to \r
   another Null-terminated Unicode string and returns the new Unicode string.\r
 \r
   This function copies the contents of the Unicode string Source to the Unicode\r
@@ -204,9 +1105,9 @@ StrCpy (
   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated Unicode string.\r
-  @param  Source      Pointer to a Null-terminated Unicode string.\r
-  @param  Length      Maximum number of Unicode characters to copy.\r
+  @param  Destination The pointer to a Null-terminated Unicode string.\r
+  @param  Source      The pointer to a Null-terminated Unicode string.\r
+  @param  Length      The maximum number of Unicode characters to copy.\r
 \r
   @return Destination.\r
 \r
@@ -218,7 +1119,7 @@ StrnCpy (
   IN      CONST CHAR16              *Source,\r
   IN      UINTN                     Length\r
   );\r
-\r
+#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES)\r
 \r
 /**\r
   Returns the length of a Null-terminated Unicode string.\r
@@ -257,7 +1158,7 @@ StrLen (
   PcdMaximumUnicodeStringLength Unicode characters not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  String  Pointer to a Null-terminated Unicode string.\r
+  @param  String  The pointer to a Null-terminated Unicode string.\r
 \r
   @return The size of String.\r
 \r
@@ -287,11 +1188,11 @@ StrSize (
   than PcdMaximumUnicodeStringLength Unicode characters not including the\r
   Null-terminator, then ASSERT().\r
   If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more\r
-  than PcdMaximumUnicodeStringLength Unicode characters not including the\r
+  than PcdMaximumUnicodeStringLength Unicode characters, not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  FirstString   Pointer to a Null-terminated Unicode string.\r
-  @param  SecondString  Pointer to a Null-terminated Unicode string.\r
+  @param  FirstString   The pointer to a Null-terminated Unicode string.\r
+  @param  SecondString  The pointer to a Null-terminated Unicode string.\r
 \r
   @retval 0      FirstString is identical to SecondString.\r
   @return others FirstString is not identical to SecondString.\r
@@ -329,9 +1230,9 @@ StrCmp (
   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  FirstString   Pointer to a Null-terminated Unicode string.\r
-  @param  SecondString  Pointer to a Null-terminated Unicode string.\r
-  @param  Length        Maximum number of Unicode characters to compare.\r
+  @param  FirstString   The pointer to a Null-terminated Unicode string.\r
+  @param  SecondString  The pointer to a Null-terminated Unicode string.\r
+  @param  Length        The maximum number of Unicode characters to compare.\r
 \r
   @retval 0      FirstString is identical to SecondString.\r
   @return others FirstString is not identical to SecondString.\r
@@ -346,7 +1247,11 @@ StrnCmp (
   );\r
 \r
 \r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
+\r
 /**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Concatenates one Null-terminated Unicode string to another Null-terminated\r
   Unicode string, and returns the concatenated Unicode string.\r
 \r
@@ -362,18 +1267,18 @@ StrnCmp (
   If Source is not aligned on a 16-bit boundary, then ASSERT().\r
   If Source and Destination overlap, then ASSERT().\r
   If PcdMaximumUnicodeStringLength is not zero, and Destination contains more\r
-  than PcdMaximumUnicodeStringLength Unicode characters not including the\r
+  than PcdMaximumUnicodeStringLength Unicode characters, not including the\r
   Null-terminator, then ASSERT().\r
   If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
-  PcdMaximumUnicodeStringLength Unicode characters not including the\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
   Null-terminator, then ASSERT().\r
   If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination\r
   and Source results in a Unicode string with more than\r
-  PcdMaximumUnicodeStringLength Unicode characters not including the\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated Unicode string.\r
-  @param  Source      Pointer to a Null-terminated Unicode string.\r
+  @param  Destination The pointer to a Null-terminated Unicode string.\r
+  @param  Source      The pointer to a Null-terminated Unicode string.\r
 \r
   @return Destination.\r
 \r
@@ -387,6 +1292,8 @@ StrCat (
 \r
 \r
 /**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Concatenates up to a specified length one Null-terminated Unicode to the end \r
   of another Null-terminated Unicode string, and returns the concatenated \r
   Unicode string.\r
@@ -416,9 +1323,9 @@ StrCat (
   and Source results in a Unicode string with more than PcdMaximumUnicodeStringLength\r
   Unicode characters, not including the Null-terminator, then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated Unicode string.\r
-  @param  Source      Pointer to a Null-terminated Unicode string.\r
-  @param  Length      Maximum number of Unicode characters to concatenate from\r
+  @param  Destination The pointer to a Null-terminated Unicode string.\r
+  @param  Source      The pointer to a Null-terminated Unicode string.\r
+  @param  Length      The maximum number of Unicode characters to concatenate from\r
                       Source.\r
 \r
   @return Destination.\r
@@ -431,6 +1338,7 @@ StrnCat (
   IN      CONST CHAR16              *Source,\r
   IN      UINTN                     Length\r
   );\r
+#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES)\r
 \r
 /**\r
   Returns the first occurrence of a Null-terminated Unicode sub-string\r
@@ -439,8 +1347,7 @@ StrnCat (
   This function scans the contents of the Null-terminated Unicode string\r
   specified by String and returns the first occurrence of SearchString.\r
   If SearchString is not found in String, then NULL is returned.  If\r
-  the length of SearchString is zero, then String is\r
-  returned.\r
+  the length of SearchString is zero, then String is returned.\r
 \r
   If String is NULL, then ASSERT().\r
   If String is not aligned on a 16-bit boundary, then ASSERT().\r
@@ -449,10 +1356,10 @@ StrnCat (
 \r
   If PcdMaximumUnicodeStringLength is not zero, and SearchString\r
   or String contains more than PcdMaximumUnicodeStringLength Unicode\r
-  characters not including the Null-terminator, then ASSERT().\r
+  characters, not including the Null-terminator, then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated Unicode string.\r
-  @param  SearchString    Pointer to a Null-terminated Unicode string to search for.\r
+  @param  String          The pointer to a Null-terminated Unicode string.\r
+  @param  SearchString    The pointer to a Null-terminated Unicode string to search for.\r
 \r
   @retval NULL            If the SearchString does not appear in String.\r
   @return others          If there is a match.\r
@@ -488,13 +1395,13 @@ StrStr (
   If String has no pad spaces or valid decimal digits,\r
   then 0 is returned.\r
   If the number represented by String overflows according\r
-  to the range defined by UINTN, then ASSERT().\r
+  to the range defined by UINTN, then MAX_UINTN is returned.\r
 \r
   If PcdMaximumUnicodeStringLength is not zero, and String contains\r
   more than PcdMaximumUnicodeStringLength Unicode characters not including\r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String      Pointer to a Null-terminated Unicode string.\r
+  @param  String      The pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -528,13 +1435,13 @@ StrDecimalToUintn (
   If String has no pad spaces or valid decimal digits,\r
   then 0 is returned.\r
   If the number represented by String overflows according\r
-  to the range defined by UINT64, then ASSERT().\r
+  to the range defined by UINT64, then MAX_UINT64 is returned.\r
 \r
   If PcdMaximumUnicodeStringLength is not zero, and String contains\r
   more than PcdMaximumUnicodeStringLength Unicode characters not including\r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated Unicode string.\r
+  @param  String          The pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -561,8 +1468,8 @@ StrDecimalToUint64 (
   The function will ignore the pad space, which includes spaces or tab characters,\r
   before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or\r
   [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the\r
-  first valid hexadecimal digit. Then, the function stops at the first character that is\r
-  a not a valid hexadecimal character or NULL, whichever one comes first.\r
+  first valid hexadecimal digit. Then, the function stops at the first character \r
+  that is a not a valid hexadecimal character or NULL, whichever one comes first.\r
 \r
   If String is NULL, then ASSERT().\r
   If String is not aligned in a 16-bit boundary, then ASSERT().\r
@@ -570,13 +1477,13 @@ StrDecimalToUint64 (
   If String has no leading pad spaces, leading zeros or valid hexadecimal digits,\r
   then zero is returned.\r
   If the number represented by String overflows according to the range defined by\r
-  UINTN, then ASSERT().\r
+  UINTN, then MAX_UINTN is returned.\r
 \r
   If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
   PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated Unicode string.\r
+  @param  String          The pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -612,13 +1519,13 @@ StrHexToUintn (
   If String has no leading pad spaces, leading zeros or valid hexadecimal digits,\r
   then zero is returned.\r
   If the number represented by String overflows according to the range defined by\r
-  UINT64, then ASSERT().\r
+  UINT64, then MAX_UINT64 is returned.\r
 \r
   If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
   PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated Unicode string.\r
+  @param  String          The pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -630,6 +1537,241 @@ StrHexToUint64 (
   );\r
 \r
 /**\r
+  Convert a Null-terminated Unicode string to IPv6 address and prefix length.\r
+\r
+  This function outputs a value of type IPv6_ADDRESS and may output a value\r
+  of type UINT8 by interpreting the contents of the Unicode string specified\r
+  by String. The format of the input Unicode string String is as follows:\r
+\r
+                  X:X:X:X:X:X:X:X[/P]\r
+\r
+  X contains one to four hexadecimal digit characters in the range [0-9], [a-f] and\r
+  [A-F]. X is converted to a value of type UINT16, whose low byte is stored in low\r
+  memory address and high byte is stored in high memory address. P contains decimal\r
+  digit characters in the range [0-9]. The running zero in the beginning of P will\r
+  be ignored. /P is optional.\r
+\r
+  When /P is not in the String, the function stops at the first character that is\r
+  not a valid hexadecimal digit character after eight X's are converted.\r
+\r
+  When /P is in the String, the function stops at the first character that is not\r
+  a valid decimal digit character after P is converted.\r
+\r
+  "::" can be used to compress one or more groups of X when X contains only 0.\r
+  The "::" can only appear once in the String.\r
+\r
+  If String is NULL, then ASSERT().\r
+\r
+  If Address is NULL, then ASSERT().\r
+\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+\r
+  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If EndPointer is not NULL and Address is translated from String, a pointer\r
+  to the character that stopped the scan is stored at the location pointed to\r
+  by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Address                  Pointer to the converted IPv6 address.\r
+  @param  PrefixLength             Pointer to the converted IPv6 address prefix\r
+                                   length. MAX_UINT8 is returned when /P is\r
+                                   not in the String.\r
+\r
+  @retval RETURN_SUCCESS           Address is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+  @retval RETURN_UNSUPPORTED       If X contains more than four hexadecimal\r
+                                    digit characters.\r
+                                   If String contains "::" and number of X\r
+                                    is not less than 8.\r
+                                   If P starts with character that is not a\r
+                                    valid decimal digit character.\r
+                                   If the decimal number converted from P\r
+                                    exceeds 128.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrToIpv6Address (\r
+  IN  CONST CHAR16       *String,\r
+  OUT CHAR16             **EndPointer, OPTIONAL\r
+  OUT IPv6_ADDRESS       *Address,\r
+  OUT UINT8              *PrefixLength OPTIONAL\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated Unicode string to IPv4 address and prefix length.\r
+\r
+  This function outputs a value of type IPv4_ADDRESS and may output a value\r
+  of type UINT8 by interpreting the contents of the Unicode string specified\r
+  by String. The format of the input Unicode string String is as follows:\r
+\r
+                  D.D.D.D[/P]\r
+\r
+  D and P are decimal digit characters in the range [0-9]. The running zero in\r
+  the beginning of D and P will be ignored. /P is optional.\r
+\r
+  When /P is not in the String, the function stops at the first character that is\r
+  not a valid decimal digit character after four D's are converted.\r
+\r
+  When /P is in the String, the function stops at the first character that is not\r
+  a valid decimal digit character after P is converted.\r
+\r
+  If String is NULL, then ASSERT().\r
+\r
+  If Address is NULL, then ASSERT().\r
+\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+\r
+  If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
+  PcdMaximumUnicodeStringLength Unicode characters, not including the\r
+  Null-terminator, then ASSERT().\r
+\r
+  If EndPointer is not NULL and Address is translated from String, a pointer\r
+  to the character that stopped the scan is stored at the location pointed to\r
+  by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Address                  Pointer to the converted IPv4 address.\r
+  @param  PrefixLength             Pointer to the converted IPv4 address prefix\r
+                                   length. MAX_UINT8 is returned when /P is\r
+                                   not in the String.\r
+\r
+  @retval RETURN_SUCCESS           Address is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+  @retval RETURN_UNSUPPORTED       If String is not in the correct format.\r
+                                   If any decimal number converted from D\r
+                                    exceeds 255.\r
+                                   If the decimal number converted from P\r
+                                    exceeds 32.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrToIpv4Address (\r
+  IN  CONST CHAR16       *String,\r
+  OUT CHAR16             **EndPointer, OPTIONAL\r
+  OUT IPv4_ADDRESS       *Address,\r
+  OUT UINT8              *PrefixLength OPTIONAL\r
+  );\r
+\r
+#define GUID_STRING_LENGTH  36\r
+\r
+/**\r
+  Convert a Null-terminated Unicode GUID string to a value of type\r
+  EFI_GUID.\r
+\r
+  This function outputs a GUID value by interpreting the contents of\r
+  the Unicode string specified by String. The format of the input\r
+  Unicode string String consists of 36 characters, as follows:\r
+\r
+                  aabbccdd-eeff-gghh-iijj-kkllmmnnoopp\r
+\r
+  The pairs aa - pp are two characters in the range [0-9], [a-f] and\r
+  [A-F], with each pair representing a single byte hexadecimal value.\r
+\r
+  The mapping between String and the EFI_GUID structure is as follows:\r
+                  aa          Data1[24:31]\r
+                  bb          Data1[16:23]\r
+                  cc          Data1[8:15]\r
+                  dd          Data1[0:7]\r
+                  ee          Data2[8:15]\r
+                  ff          Data2[0:7]\r
+                  gg          Data3[8:15]\r
+                  hh          Data3[0:7]\r
+                  ii          Data4[0:7]\r
+                  jj          Data4[8:15]\r
+                  kk          Data4[16:23]\r
+                  ll          Data4[24:31]\r
+                  mm          Data4[32:39]\r
+                  nn          Data4[40:47]\r
+                  oo          Data4[48:55]\r
+                  pp          Data4[56:63]\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Guid is NULL, then ASSERT().\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  Guid                     Pointer to the converted GUID.\r
+\r
+  @retval RETURN_SUCCESS           Guid is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+  @retval RETURN_UNSUPPORTED       If String is not as the above format.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrToGuid (\r
+  IN  CONST CHAR16       *String,\r
+  OUT GUID               *Guid\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated Unicode hexadecimal string to a byte array.\r
+\r
+  This function outputs a byte array by interpreting the contents of\r
+  the Unicode string specified by String in hexadecimal format. The format of\r
+  the input Unicode string String is:\r
+\r
+                  [XX]*\r
+\r
+  X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F].\r
+  The function decodes every two hexadecimal digit characters as one byte. The\r
+  decoding stops after Length of characters and outputs Buffer containing\r
+  (Length / 2) bytes.\r
+\r
+  If String is not aligned in a 16-bit boundary, then ASSERT().\r
+\r
+  If String is NULL, then ASSERT().\r
+\r
+  If Buffer is NULL, then ASSERT().\r
+\r
+  If Length is not multiple of 2, then ASSERT().\r
+\r
+  If PcdMaximumUnicodeStringLength is not zero and Length is greater than\r
+  PcdMaximumUnicodeStringLength, then ASSERT().\r
+\r
+  If MaxBufferSize is less than (Length / 2), then ASSERT().\r
+\r
+  @param  String                   Pointer to a Null-terminated Unicode string.\r
+  @param  Length                   The number of Unicode characters to decode.\r
+  @param  Buffer                   Pointer to the converted bytes array.\r
+  @param  MaxBufferSize            The maximum size of Buffer.\r
+\r
+  @retval RETURN_SUCCESS           Buffer is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If Length is not multiple of 2.\r
+                                   If PcdMaximumUnicodeStringLength is not zero,\r
+                                    and Length is greater than\r
+                                    PcdMaximumUnicodeStringLength.\r
+  @retval RETURN_UNSUPPORTED       If Length of characters from String contain\r
+                                    a character that is not valid hexadecimal\r
+                                    digit characters, or a Null-terminator.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If MaxBufferSize is less than (Length / 2).\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StrHexToBytes (\r
+  IN  CONST CHAR16       *String,\r
+  IN  UINTN              Length,\r
+  OUT UINT8              *Buffer,\r
+  IN  UINTN              MaxBufferSize\r
+  );\r
+\r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
+\r
+/**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Convert a Null-terminated Unicode string to a Null-terminated\r
   ASCII string and returns the ASCII string.\r
 \r
@@ -637,6 +1779,9 @@ StrHexToUint64 (
   to the ASCII string Destination by copying the lower 8 bits of\r
   each Unicode character. It returns Destination.\r
 \r
+  The caller is responsible to make sure Destination points to a buffer with size\r
+  equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.\r
+\r
   If any Unicode characters in Source contain non-zero value in\r
   the upper 8 bits, then ASSERT().\r
 \r
@@ -653,8 +1798,8 @@ StrHexToUint64 (
   than PcdMaximumAsciiStringLength Unicode characters not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  Source        Pointer to a Null-terminated Unicode string.\r
-  @param  Destination   Pointer to a Null-terminated ASCII string.\r
+  @param  Source        The pointer to a Null-terminated Unicode string.\r
+  @param  Destination   The pointer to a Null-terminated ASCII string.\r
 \r
   @return Destination.\r
 \r
@@ -663,11 +1808,119 @@ CHAR8 *
 EFIAPI\r
 UnicodeStrToAsciiStr (\r
   IN      CONST CHAR16              *Source,\r
-  OUT     CHAR8                     *Destination\r
+  OUT     CHAR8                     *Destination\r
+  );\r
+\r
+#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES)\r
+\r
+/**\r
+  Convert a Null-terminated Unicode string to a Null-terminated\r
+  ASCII string.\r
+\r
+  This function is similar to AsciiStrCpyS.\r
+\r
+  This function converts the content of the Unicode string Source\r
+  to the ASCII string Destination by copying the lower 8 bits of\r
+  each Unicode character. The function terminates the ASCII string\r
+  Destination by appending a Null-terminator character at the end.\r
+\r
+  The caller is responsible to make sure Destination points to a buffer with size\r
+  equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.\r
+\r
+  If any Unicode characters in Source contain non-zero value in\r
+  the upper 8 bits, then ASSERT().\r
+\r
+  If Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Source        The pointer to a Null-terminated Unicode string.\r
+  @param  Destination   The pointer to a Null-terminated ASCII string.\r
+  @param  DestMax       The maximum number of Destination Ascii\r
+                        char, including terminating null char.\r
+\r
+  @retval RETURN_SUCCESS           String is converted.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than StrLen(Source).\r
+  @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
+                                   If Source is NULL.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                    and DestMax is greater than\r
+                                    PcdMaximumAsciiStringLength.\r
+                                   If PcdMaximumUnicodeStringLength is not zero,\r
+                                    and DestMax is greater than\r
+                                    PcdMaximumUnicodeStringLength.\r
+                                   If DestMax is 0.\r
+  @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+UnicodeStrToAsciiStrS (\r
+  IN      CONST CHAR16              *Source,\r
+  OUT     CHAR8                     *Destination,\r
+  IN      UINTN                     DestMax\r
+  );\r
+\r
+/**\r
+  Convert not more than Length successive characters from a Null-terminated\r
+  Unicode string to a Null-terminated Ascii string. If no null char is copied\r
+  from Source, then Destination[Length] is always set to null.\r
+\r
+  This function converts not more than Length successive characters from the\r
+  Unicode string Source to the Ascii string Destination by copying the lower 8\r
+  bits of each Unicode character. The function terminates the Ascii string\r
+  Destination by appending a Null-terminator character at the end.\r
+\r
+  The caller is responsible to make sure Destination points to a buffer with size\r
+  equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.\r
+\r
+  If any Unicode characters in Source contain non-zero value in the upper 8\r
+  bits, then ASSERT().\r
+  If Source is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Source             The pointer to a Null-terminated Unicode string.\r
+  @param  Length             The maximum number of Unicode characters to\r
+                             convert.\r
+  @param  Destination        The pointer to a Null-terminated Ascii string.\r
+  @param  DestMax            The maximum number of Destination Ascii\r
+                             char, including terminating null char.\r
+  @param  DestinationLength  The number of Unicode characters converted.\r
+\r
+  @retval RETURN_SUCCESS            String is converted.\r
+  @retval RETURN_INVALID_PARAMETER  If Destination is NULL.\r
+                                    If Source is NULL.\r
+                                    If DestinationLength is NULL.\r
+                                    If PcdMaximumAsciiStringLength is not zero,\r
+                                    and Length or DestMax is greater than\r
+                                    PcdMaximumAsciiStringLength.\r
+                                    If PcdMaximumUnicodeStringLength is not\r
+                                    zero, and Length or DestMax is greater than\r
+                                    PcdMaximumUnicodeStringLength.\r
+                                    If DestMax is 0.\r
+  @retval RETURN_BUFFER_TOO_SMALL   If DestMax is NOT greater than\r
+                                    MIN(StrLen(Source), Length).\r
+  @retval RETURN_ACCESS_DENIED      If Source and Destination overlap.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+UnicodeStrnToAsciiStrS (\r
+  IN      CONST CHAR16              *Source,\r
+  IN      UINTN                     Length,\r
+  OUT     CHAR8                     *Destination,\r
+  IN      UINTN                     DestMax,\r
+  OUT     UINTN                     *DestinationLength\r
   );\r
 \r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
 \r
 /**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Copies one Null-terminated ASCII string to another Null-terminated ASCII\r
   string and returns the new ASCII string.\r
 \r
@@ -682,8 +1935,8 @@ UnicodeStrToAsciiStr (
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated ASCII string.\r
-  @param  Source      Pointer to a Null-terminated ASCII string.\r
+  @param  Destination The pointer to a Null-terminated ASCII string.\r
+  @param  Source      The pointer to a Null-terminated ASCII string.\r
 \r
   @return Destination\r
 \r
@@ -697,6 +1950,8 @@ AsciiStrCpy (
 \r
 \r
 /**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Copies up to a specified length one Null-terminated ASCII string to another \r
   Null-terminated ASCII string and returns the new ASCII string.\r
 \r
@@ -716,9 +1971,9 @@ AsciiStrCpy (
   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated ASCII string.\r
-  @param  Source      Pointer to a Null-terminated ASCII string.\r
-  @param  Length      Maximum number of ASCII characters to copy.\r
+  @param  Destination The pointer to a Null-terminated ASCII string.\r
+  @param  Source      The pointer to a Null-terminated ASCII string.\r
+  @param  Length      The maximum number of ASCII characters to copy.\r
 \r
   @return Destination\r
 \r
@@ -730,7 +1985,7 @@ AsciiStrnCpy (
   IN      CONST CHAR8               *Source,\r
   IN      UINTN                     Length\r
   );\r
-\r
+#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES)\r
 \r
 /**\r
   Returns the length of a Null-terminated ASCII string.\r
@@ -744,7 +1999,7 @@ AsciiStrnCpy (
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String  Pointer to a Null-terminated ASCII string.\r
+  @param  String  The pointer to a Null-terminated ASCII string.\r
 \r
   @return The length of String.\r
 \r
@@ -768,7 +2023,7 @@ AsciiStrLen (
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String  Pointer to a Null-terminated ASCII string.\r
+  @param  String  The pointer to a Null-terminated ASCII string.\r
 \r
   @return The size of String.\r
 \r
@@ -799,8 +2054,8 @@ AsciiStrSize (
   than PcdMaximumAsciiStringLength ASCII characters not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  FirstString   Pointer to a Null-terminated ASCII string.\r
-  @param  SecondString  Pointer to a Null-terminated ASCII string.\r
+  @param  FirstString   The pointer to a Null-terminated ASCII string.\r
+  @param  SecondString  The pointer to a Null-terminated ASCII string.\r
 \r
   @retval ==0      FirstString is identical to SecondString.\r
   @retval !=0      FirstString is not identical to SecondString.\r
@@ -834,8 +2089,8 @@ AsciiStrCmp (
   than PcdMaximumAsciiStringLength ASCII characters not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  FirstString   Pointer to a Null-terminated ASCII string.\r
-  @param  SecondString  Pointer to a Null-terminated ASCII string.\r
+  @param  FirstString   The pointer to a Null-terminated ASCII string.\r
+  @param  SecondString  The pointer to a Null-terminated ASCII string.\r
 \r
   @retval ==0    FirstString is identical to SecondString using case insensitive\r
                  comparisons.\r
@@ -873,9 +2128,9 @@ AsciiStriCmp (
   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  FirstString   Pointer to a Null-terminated ASCII string.\r
-  @param  SecondString  Pointer to a Null-terminated ASCII string.\r
-  @param  Length        Maximum number of ASCII characters for compare.\r
+  @param  FirstString   The pointer to a Null-terminated ASCII string.\r
+  @param  SecondString  The pointer to a Null-terminated ASCII string.\r
+  @param  Length        The maximum number of ASCII characters for compare.\r
   \r
   @retval ==0       FirstString is identical to SecondString.\r
   @retval !=0       FirstString is not identical to SecondString.\r
@@ -890,7 +2145,11 @@ AsciiStrnCmp (
   );\r
 \r
 \r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
+\r
 /**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Concatenates one Null-terminated ASCII string to another Null-terminated\r
   ASCII string, and returns the concatenated ASCII string.\r
 \r
@@ -911,8 +2170,8 @@ AsciiStrnCmp (
   Source results in a ASCII string with more than PcdMaximumAsciiStringLength\r
   ASCII characters, then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated ASCII string.\r
-  @param  Source      Pointer to a Null-terminated ASCII string.\r
+  @param  Destination The pointer to a Null-terminated ASCII string.\r
+  @param  Source      The pointer to a Null-terminated ASCII string.\r
 \r
   @return Destination\r
 \r
@@ -926,6 +2185,8 @@ AsciiStrCat (
 \r
 \r
 /**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Concatenates up to a specified length one Null-terminated ASCII string to \r
   the end of another Null-terminated ASCII string, and returns the \r
   concatenated ASCII string.\r
@@ -953,9 +2214,9 @@ AsciiStrCat (
   Source results in a ASCII string with more than PcdMaximumAsciiStringLength\r
   ASCII characters, not including the Null-terminator, then ASSERT().\r
 \r
-  @param  Destination Pointer to a Null-terminated ASCII string.\r
-  @param  Source      Pointer to a Null-terminated ASCII string.\r
-  @param  Length      Maximum number of ASCII characters to concatenate from\r
+  @param  Destination The pointer to a Null-terminated ASCII string.\r
+  @param  Source      The pointer to a Null-terminated ASCII string.\r
+  @param  Length      The maximum number of ASCII characters to concatenate from\r
                       Source.\r
 \r
   @return Destination\r
@@ -968,7 +2229,7 @@ AsciiStrnCat (
   IN      CONST CHAR8               *Source,\r
   IN      UINTN                     Length\r
   );\r
-\r
+#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES)\r
 \r
 /**\r
   Returns the first occurrence of a Null-terminated ASCII sub-string\r
@@ -986,8 +2247,8 @@ AsciiStrnCat (
   String contains more than PcdMaximumAsciiStringLength Unicode characters\r
   not including the Null-terminator, then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated ASCII string.\r
-  @param  SearchString    Pointer to a Null-terminated ASCII string to search for.\r
+  @param  String          The pointer to a Null-terminated ASCII string.\r
+  @param  SearchString    The pointer to a Null-terminated ASCII string to search for.\r
 \r
   @retval NULL            If the SearchString does not appear in String.\r
   @retval others          If there is a match return the first occurrence of SearchingString.\r
@@ -1021,15 +2282,15 @@ AsciiStrStr (
   If String has only pad spaces, then 0 is returned.\r
   If String has no pad spaces or valid decimal digits, then 0 is returned.\r
   If the number represented by String overflows according to the range defined by\r
-  UINTN, then ASSERT().\r
+  UINTN, then MAX_UINTN is returned.\r
   If String is NULL, then ASSERT().\r
   If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated ASCII string.\r
+  @param  String          The pointer to a Null-terminated ASCII string.\r
 \r
-  @retval Value translated from String.\r
+  @retval The value translated from String.\r
 \r
 **/\r
 UINTN\r
@@ -1058,13 +2319,13 @@ AsciiStrDecimalToUintn (
   If String has only pad spaces, then 0 is returned.\r
   If String has no pad spaces or valid decimal digits, then 0 is returned.\r
   If the number represented by String overflows according to the range defined by\r
-  UINT64, then ASSERT().\r
+  UINT64, then MAX_UINT64 is returned.\r
   If String is NULL, then ASSERT().\r
   If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
   then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated ASCII string.\r
+  @param  String          The pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1099,13 +2360,13 @@ AsciiStrDecimalToUint64 (
   0 is returned.\r
 \r
   If the number represented by String overflows according to the range defined by UINTN,\r
-  then ASSERT().\r
+  then MAX_UINTN is returned.\r
   If String is NULL, then ASSERT().\r
   If PcdMaximumAsciiStringLength is not zero,\r
   and String contains more than PcdMaximumAsciiStringLength ASCII characters not including\r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated ASCII string.\r
+  @param  String          The pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1140,13 +2401,13 @@ AsciiStrHexToUintn (
   0 is returned.\r
 \r
   If the number represented by String overflows according to the range defined by UINT64,\r
-  then ASSERT().\r
+  then MAX_UINT64 is returned.\r
   If String is NULL, then ASSERT().\r
   If PcdMaximumAsciiStringLength is not zero,\r
   and String contains more than PcdMaximumAsciiStringLength ASCII characters not including\r
   the Null-terminator, then ASSERT().\r
 \r
-  @param  String          Pointer to a Null-terminated ASCII string.\r
+  @param  String          The pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1157,8 +2418,225 @@ AsciiStrHexToUint64 (
   IN      CONST CHAR8                *String\r
   );\r
 \r
+/**\r
+  Convert a Null-terminated ASCII string to IPv6 address and prefix length.\r
+\r
+  This function outputs a value of type IPv6_ADDRESS and may output a value\r
+  of type UINT8 by interpreting the contents of the ASCII string specified\r
+  by String. The format of the input ASCII string String is as follows:\r
+\r
+                  X:X:X:X:X:X:X:X[/P]\r
+\r
+  X contains one to four hexadecimal digit characters in the range [0-9], [a-f] and\r
+  [A-F]. X is converted to a value of type UINT16, whose low byte is stored in low\r
+  memory address and high byte is stored in high memory address. P contains decimal\r
+  digit characters in the range [0-9]. The running zero in the beginning of P will\r
+  be ignored. /P is optional.\r
+\r
+  When /P is not in the String, the function stops at the first character that is\r
+  not a valid hexadecimal digit character after eight X's are converted.\r
+\r
+  When /P is in the String, the function stops at the first character that is not\r
+  a valid decimal digit character after P is converted.\r
+\r
+  "::" can be used to compress one or more groups of X when X contains only 0.\r
+  The "::" can only appear once in the String.\r
+\r
+  If String is NULL, then ASSERT().\r
+\r
+  If Address is NULL, then ASSERT().\r
+\r
+  If EndPointer is not NULL and Address is translated from String, a pointer\r
+  to the character that stopped the scan is stored at the location pointed to\r
+  by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated ASCII string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Address                  Pointer to the converted IPv6 address.\r
+  @param  PrefixLength             Pointer to the converted IPv6 address prefix\r
+                                   length. MAX_UINT8 is returned when /P is\r
+                                   not in the String.\r
+\r
+  @retval RETURN_SUCCESS           Address is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+  @retval RETURN_UNSUPPORTED       If X contains more than four hexadecimal\r
+                                    digit characters.\r
+                                   If String contains "::" and number of X\r
+                                    is not less than 8.\r
+                                   If P starts with character that is not a\r
+                                    valid decimal digit character.\r
+                                   If the decimal number converted from P\r
+                                    exceeds 128.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrToIpv6Address (\r
+  IN  CONST CHAR8        *String,\r
+  OUT CHAR8              **EndPointer, OPTIONAL\r
+  OUT IPv6_ADDRESS       *Address,\r
+  OUT UINT8              *PrefixLength OPTIONAL\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated ASCII string to IPv4 address and prefix length.\r
+\r
+  This function outputs a value of type IPv4_ADDRESS and may output a value\r
+  of type UINT8 by interpreting the contents of the ASCII string specified\r
+  by String. The format of the input ASCII string String is as follows:\r
+\r
+                  D.D.D.D[/P]\r
+\r
+  D and P are decimal digit characters in the range [0-9]. The running zero in\r
+  the beginning of D and P will be ignored. /P is optional.\r
+\r
+  When /P is not in the String, the function stops at the first character that is\r
+  not a valid decimal digit character after four D's are converted.\r
+\r
+  When /P is in the String, the function stops at the first character that is not\r
+  a valid decimal digit character after P is converted.\r
+\r
+  If String is NULL, then ASSERT().\r
+\r
+  If Address is NULL, then ASSERT().\r
+\r
+  If EndPointer is not NULL and Address is translated from String, a pointer\r
+  to the character that stopped the scan is stored at the location pointed to\r
+  by EndPointer.\r
+\r
+  @param  String                   Pointer to a Null-terminated ASCII string.\r
+  @param  EndPointer               Pointer to character that stops scan.\r
+  @param  Address                  Pointer to the converted IPv4 address.\r
+  @param  PrefixLength             Pointer to the converted IPv4 address prefix\r
+                                   length. MAX_UINT8 is returned when /P is\r
+                                   not in the String.\r
+\r
+  @retval RETURN_SUCCESS           Address is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+  @retval RETURN_UNSUPPORTED       If String is not in the correct format.\r
+                                   If any decimal number converted from D\r
+                                    exceeds 255.\r
+                                   If the decimal number converted from P\r
+                                    exceeds 32.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrToIpv4Address (\r
+  IN  CONST CHAR8        *String,\r
+  OUT CHAR8              **EndPointer, OPTIONAL\r
+  OUT IPv4_ADDRESS       *Address,\r
+  OUT UINT8              *PrefixLength OPTIONAL\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated ASCII GUID string to a value of type\r
+  EFI_GUID.\r
+\r
+  This function outputs a GUID value by interpreting the contents of\r
+  the ASCII string specified by String. The format of the input\r
+  ASCII string String consists of 36 characters, as follows:\r
+\r
+                  aabbccdd-eeff-gghh-iijj-kkllmmnnoopp\r
+\r
+  The pairs aa - pp are two characters in the range [0-9], [a-f] and\r
+  [A-F], with each pair representing a single byte hexadecimal value.\r
+\r
+  The mapping between String and the EFI_GUID structure is as follows:\r
+                  aa          Data1[24:31]\r
+                  bb          Data1[16:23]\r
+                  cc          Data1[8:15]\r
+                  dd          Data1[0:7]\r
+                  ee          Data2[8:15]\r
+                  ff          Data2[0:7]\r
+                  gg          Data3[8:15]\r
+                  hh          Data3[0:7]\r
+                  ii          Data4[0:7]\r
+                  jj          Data4[8:15]\r
+                  kk          Data4[16:23]\r
+                  ll          Data4[24:31]\r
+                  mm          Data4[32:39]\r
+                  nn          Data4[40:47]\r
+                  oo          Data4[48:55]\r
+                  pp          Data4[56:63]\r
+\r
+  If String is NULL, then ASSERT().\r
+  If Guid is NULL, then ASSERT().\r
+\r
+  @param  String                   Pointer to a Null-terminated ASCII string.\r
+  @param  Guid                     Pointer to the converted GUID.\r
+\r
+  @retval RETURN_SUCCESS           Guid is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+  @retval RETURN_UNSUPPORTED       If String is not as the above format.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrToGuid (\r
+  IN  CONST CHAR8        *String,\r
+  OUT GUID               *Guid\r
+  );\r
+\r
+/**\r
+  Convert a Null-terminated ASCII hexadecimal string to a byte array.\r
+\r
+  This function outputs a byte array by interpreting the contents of\r
+  the ASCII string specified by String in hexadecimal format. The format of\r
+  the input ASCII string String is:\r
+\r
+                  [XX]*\r
+\r
+  X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F].\r
+  The function decodes every two hexadecimal digit characters as one byte. The\r
+  decoding stops after Length of characters and outputs Buffer containing\r
+  (Length / 2) bytes.\r
+\r
+  If String is NULL, then ASSERT().\r
+\r
+  If Buffer is NULL, then ASSERT().\r
+\r
+  If Length is not multiple of 2, then ASSERT().\r
+\r
+  If PcdMaximumAsciiStringLength is not zero and Length is greater than\r
+  PcdMaximumAsciiStringLength, then ASSERT().\r
+\r
+  If MaxBufferSize is less than (Length / 2), then ASSERT().\r
+\r
+  @param  String                   Pointer to a Null-terminated ASCII string.\r
+  @param  Length                   The number of ASCII characters to decode.\r
+  @param  Buffer                   Pointer to the converted bytes array.\r
+  @param  MaxBufferSize            The maximum size of Buffer.\r
+\r
+  @retval RETURN_SUCCESS           Buffer is translated from String.\r
+  @retval RETURN_INVALID_PARAMETER If String is NULL.\r
+                                   If Data is NULL.\r
+                                   If Length is not multiple of 2.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                    and Length is greater than\r
+                                    PcdMaximumAsciiStringLength.\r
+  @retval RETURN_UNSUPPORTED       If Length of characters from String contain\r
+                                    a character that is not valid hexadecimal\r
+                                    digit characters, or a Null-terminator.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If MaxBufferSize is less than (Length / 2).\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrHexToBytes (\r
+  IN  CONST CHAR8        *String,\r
+  IN  UINTN              Length,\r
+  OUT UINT8              *Buffer,\r
+  IN  UINTN              MaxBufferSize\r
+  );\r
+\r
+#ifndef DISABLE_NEW_DEPRECATED_INTERFACES\r
 \r
 /**\r
+  [ATTENTION] This function is deprecated for security reason.\r
+\r
   Convert one Null-terminated ASCII string to a Null-terminated\r
   Unicode string and returns the Unicode string.\r
 \r
@@ -1179,8 +2657,8 @@ AsciiStrHexToUint64 (
   PcdMaximumUnicodeStringLength ASCII characters not including the\r
   Null-terminator, then ASSERT().\r
 \r
-  @param  Source        Pointer to a Null-terminated ASCII string.\r
-  @param  Destination   Pointer to a Null-terminated Unicode string.\r
+  @param  Source        The pointer to a Null-terminated ASCII string.\r
+  @param  Destination   The pointer to a Null-terminated Unicode string.\r
 \r
   @return Destination.\r
 \r
@@ -1192,6 +2670,105 @@ AsciiStrToUnicodeStr (
   OUT     CHAR16                    *Destination\r
   );\r
 \r
+#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES)\r
+\r
+/**\r
+  Convert one Null-terminated ASCII string to a Null-terminated\r
+  Unicode string.\r
+\r
+  This function is similar to StrCpyS.\r
+\r
+  This function converts the contents of the ASCII string Source to the Unicode\r
+  string Destination. The function terminates the Unicode string Destination by\r
+  appending a Null-terminator character at the end.\r
+\r
+  The caller is responsible to make sure Destination points to a buffer with size\r
+  equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.\r
+\r
+  If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then the Destination is unmodified.\r
+\r
+  @param  Source        The pointer to a Null-terminated ASCII string.\r
+  @param  Destination   The pointer to a Null-terminated Unicode string.\r
+  @param  DestMax       The maximum number of Destination Unicode\r
+                        char, including terminating null char.\r
+\r
+  @retval RETURN_SUCCESS           String is converted.\r
+  @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than StrLen(Source).\r
+  @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
+                                   If Source is NULL.\r
+                                   If PcdMaximumUnicodeStringLength is not zero,\r
+                                    and DestMax is greater than\r
+                                    PcdMaximumUnicodeStringLength.\r
+                                   If PcdMaximumAsciiStringLength is not zero,\r
+                                    and DestMax is greater than\r
+                                    PcdMaximumAsciiStringLength.\r
+                                   If DestMax is 0.\r
+  @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrToUnicodeStrS (\r
+  IN      CONST CHAR8               *Source,\r
+  OUT     CHAR16                    *Destination,\r
+  IN      UINTN                     DestMax\r
+  );\r
+\r
+/**\r
+  Convert not more than Length successive characters from a Null-terminated\r
+  Ascii string to a Null-terminated Unicode string. If no null char is copied\r
+  from Source, then Destination[Length] is always set to null.\r
+\r
+  This function converts not more than Length successive characters from the\r
+  Ascii string Source to the Unicode string Destination. The function\r
+  terminates the Unicode string Destination by appending a Null-terminator\r
+  character at the end.\r
+\r
+  The caller is responsible to make sure Destination points to a buffer with\r
+  size not smaller than\r
+  ((MIN(AsciiStrLen(Source), Length) + 1) * sizeof (CHAR8)) in bytes.\r
+\r
+  If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
+  If an error would be returned, then the function will also ASSERT().\r
+\r
+  If an error is returned, then Destination and DestinationLength are\r
+  unmodified.\r
+\r
+  @param  Source             The pointer to a Null-terminated Ascii string.\r
+  @param  Length             The maximum number of Ascii characters to convert.\r
+  @param  Destination        The pointer to a Null-terminated Unicode string.\r
+  @param  DestMax            The maximum number of Destination Unicode char,\r
+                             including terminating null char.\r
+  @param  DestinationLength  The number of Ascii characters converted.\r
+\r
+  @retval RETURN_SUCCESS            String is converted.\r
+  @retval RETURN_INVALID_PARAMETER  If Destination is NULL.\r
+                                    If Source is NULL.\r
+                                    If DestinationLength is NULL.\r
+                                    If PcdMaximumUnicodeStringLength is not\r
+                                    zero, and Length or DestMax is greater than\r
+                                    PcdMaximumUnicodeStringLength.\r
+                                    If PcdMaximumAsciiStringLength is not zero,\r
+                                    and Length or DestMax is greater than\r
+                                    PcdMaximumAsciiStringLength.\r
+                                    If DestMax is 0.\r
+  @retval RETURN_BUFFER_TOO_SMALL   If DestMax is NOT greater than\r
+                                    MIN(AsciiStrLen(Source), Length).\r
+  @retval RETURN_ACCESS_DENIED      If Source and Destination overlap.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+AsciiStrnToUnicodeStrS (\r
+  IN      CONST CHAR8               *Source,\r
+  IN      UINTN                     Length,\r
+  OUT     CHAR16                    *Destination,\r
+  IN      UINTN                     DestMax,\r
+  OUT     UINTN                     *DestinationLength\r
+  );\r
 \r
 /**\r
   Converts an 8-bit value to an 8-bit BCD value.\r
@@ -1233,6 +2810,42 @@ BcdToDecimal8 (
   IN      UINT8                     Value\r
   );\r
 \r
+//\r
+//  File Path Manipulation Functions\r
+//\r
+\r
+/**\r
+  Removes the last directory or file entry in a path.\r
+\r
+  @param[in, out] Path    The pointer to the path to modify.\r
+\r
+  @retval FALSE     Nothing was found to remove.\r
+  @retval TRUE      A directory or file was removed.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PathRemoveLastItem(\r
+  IN OUT CHAR16 *Path\r
+  );\r
+\r
+/**\r
+  Function to clean up paths.\r
+    - Single periods in the path are removed.\r
+    - Double periods in the path are removed along with a single parent directory.\r
+    - Forward slashes L'/' are converted to backward slashes L'\'.\r
+\r
+  This will be done inline and the existing buffer may be larger than required\r
+  upon completion.\r
+\r
+  @param[in] Path       The pointer to the string containing the path.\r
+\r
+  @return       Returns Path, otherwise returns NULL to indicate that an error has occurred.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+PathCleanUpDirectories(\r
+  IN CHAR16 *Path\r
+  );\r
 \r
 //\r
 // Linked List Functions and Macros\r
@@ -1255,6 +2868,33 @@ BcdToDecimal8 (
 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)  {&(ListHead), &(ListHead)}\r
 \r
 \r
+/**\r
+  Checks whether FirstEntry and SecondEntry are part of the same doubly-linked\r
+  list.\r
+\r
+  If FirstEntry is NULL, then ASSERT().\r
+  If FirstEntry->ForwardLink is NULL, then ASSERT().\r
+  If FirstEntry->BackLink is NULL, then ASSERT().\r
+  If SecondEntry is NULL, then ASSERT();\r
+  If PcdMaximumLinkedListLength is not zero, and List contains more than\r
+  PcdMaximumLinkedListLength nodes, then ASSERT().\r
+\r
+  @param  FirstEntry   A pointer to a node in a linked list.\r
+  @param  SecondEntry  A pointer to the node to locate.\r
+\r
+  @retval TRUE   SecondEntry is in the same doubly-linked list as FirstEntry.\r
+  @retval FALSE  SecondEntry isn't in the same doubly-linked list as FirstEntry,\r
+                 or FirstEntry is invalid.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsNodeInList (\r
+  IN      CONST LIST_ENTRY      *FirstEntry,\r
+  IN      CONST LIST_ENTRY      *SecondEntry\r
+  );\r
+\r
+\r
 /**\r
   Initializes the head node of a doubly linked list, and returns the pointer to\r
   the head node of the doubly linked list.\r
@@ -1289,7 +2929,7 @@ InitializeListHead (
   If Entry is NULL, then ASSERT().\r
   If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
   InitializeListHead(), then ASSERT().\r
-  If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number\r
+  If PcdMaximumLinkedListLength is not zero, and prior to insertion the number\r
   of nodes in ListHead, including the ListHead node, is greater than or\r
   equal to PcdMaximumLinkedListLength, then ASSERT().\r
 \r
@@ -1319,7 +2959,7 @@ InsertHeadList (
   If Entry is NULL, then ASSERT().\r
   If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
   InitializeListHead(), then ASSERT().\r
-  If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number\r
+  If PcdMaximumLinkedListLength is not zero, and prior to insertion the number\r
   of nodes in ListHead, including the ListHead node, is greater than or\r
   equal to PcdMaximumLinkedListLength, then ASSERT().\r
 \r
@@ -1348,14 +2988,14 @@ InsertTailList (
   If List is NULL, then ASSERT().\r
   If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
   InitializeListHead(), then ASSERT().\r
-  If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
+  If PcdMaximumLinkedListLength is not zero, and the number of nodes\r
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
 \r
   @param  List  A pointer to the head node of a doubly linked list.\r
 \r
   @return The first node of a doubly linked list.\r
-  @retval NULL  The list is empty.\r
+  @retval List  The list is empty.\r
 \r
 **/\r
 LIST_ENTRY *\r
@@ -1376,15 +3016,14 @@ GetFirstNode (
   If Node is NULL, then ASSERT().\r
   If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
   InitializeListHead(), then ASSERT().\r
-  If PcdMaximumLinkedListLenth is not zero, and List contains more than\r
-  PcdMaximumLinkedListLenth nodes, then ASSERT().\r
+  If PcdMaximumLinkedListLength is not zero, and List contains more than\r
+  PcdMaximumLinkedListLength nodes, then ASSERT().\r
   If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().\r
 \r
   @param  List  A pointer to the head node of a doubly linked list.\r
   @param  Node  A pointer to a node in the doubly linked list.\r
 \r
-  @return Pointer to the next node if one exists. Otherwise a null value which\r
-          is actually List is returned.\r
+  @return The pointer to the next node if one exists. Otherwise List is returned.\r
 \r
 **/\r
 LIST_ENTRY *\r
@@ -1394,7 +3033,36 @@ GetNextNode (
   IN      CONST LIST_ENTRY          *Node\r
   );\r
 \r
+  \r
+/**\r
+  Retrieves the previous node of a doubly linked list.\r
\r
+  Returns the node of a doubly linked list that precedes Node.  \r
+  List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()\r
+  or InitializeListHead().  If List is empty, then List is returned.\r
\r
+  If List is NULL, then ASSERT().\r
+  If Node is NULL, then ASSERT().\r
+  If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
+  InitializeListHead(), then ASSERT().\r
+  If PcdMaximumLinkedListLength is not zero, and List contains more than\r
+  PcdMaximumLinkedListLength nodes, then ASSERT().\r
+  If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().\r
\r
+  @param  List  A pointer to the head node of a doubly linked list.\r
+  @param  Node  A pointer to a node in the doubly linked list.\r
\r
+  @return The pointer to the previous node if one exists. Otherwise List is returned.\r
\r
+**/\r
+LIST_ENTRY *\r
+EFIAPI\r
+GetPreviousNode (\r
+  IN      CONST LIST_ENTRY          *List,\r
+  IN      CONST LIST_ENTRY          *Node\r
+  );\r
 \r
+  \r
 /**\r
   Checks to see if a doubly linked list is empty or not.\r
 \r
@@ -1404,7 +3072,7 @@ GetNextNode (
   If ListHead is NULL, then ASSERT().\r
   If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
   InitializeListHead(), then ASSERT().\r
-  If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
+  If PcdMaximumLinkedListLength is not zero, and the number of nodes\r
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
 \r
@@ -1434,7 +3102,7 @@ IsListEmpty (
   If Node is NULL, then ASSERT().\r
   If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), \r
   then ASSERT().\r
-  If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
+  If PcdMaximumLinkedListLength is not zero, and the number of nodes\r
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
   If PcdVerifyNodeInList is TRUE and Node is not a node in List the and Node is not equal \r
@@ -1443,8 +3111,8 @@ IsListEmpty (
   @param  List  A pointer to the head node of a doubly linked list.\r
   @param  Node  A pointer to a node in the doubly linked list.\r
 \r
-  @retval TRUE  Node is one of the nodes in the doubly linked list.\r
-  @retval FALSE Node is not one of the nodes in the doubly linked list.\r
+  @retval TRUE  Node is the head of the doubly-linked list pointed by List.\r
+  @retval FALSE Node is not the head of the doubly-linked list pointed by List.\r
 \r
 **/\r
 BOOLEAN\r
@@ -1466,7 +3134,7 @@ IsNull (
   If Node is NULL, then ASSERT().\r
   If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
   InitializeListHead(), then ASSERT().\r
-  If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
+  If PcdMaximumLinkedListLength is not zero, and the number of nodes\r
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
   If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().\r
@@ -1840,7 +3508,7 @@ GetPowerOfTwo64 (
 \r
 \r
 /**\r
-  Switches the endianess of a 16-bit integer.\r
+  Switches the endianness of a 16-bit integer.\r
 \r
   This function swaps the bytes in a 16-bit unsigned value to switch the value\r
   from little endian to big endian or vice versa. The byte swapped value is\r
@@ -1859,7 +3527,7 @@ SwapBytes16 (
 \r
 \r
 /**\r
-  Switches the endianess of a 32-bit integer.\r
+  Switches the endianness of a 32-bit integer.\r
 \r
   This function swaps the bytes in a 32-bit unsigned value to switch the value\r
   from little endian to big endian or vice versa. The byte swapped value is\r
@@ -1878,7 +3546,7 @@ SwapBytes32 (
 \r
 \r
 /**\r
-  Switches the endianess of a 64-bit integer.\r
+  Switches the endianness of a 64-bit integer.\r
 \r
   This function swaps the bytes in a 64-bit unsigned value to switch the value\r
   from little endian to big endian or vice versa. The byte swapped value is\r
@@ -1929,7 +3597,7 @@ MultU64x32 (
   @param  Multiplicand  A 64-bit unsigned value.\r
   @param  Multiplier    A 64-bit unsigned value.\r
 \r
-  @return Multiplicand * Multiplier\r
+  @return Multiplicand * Multiplier.\r
 \r
 **/\r
 UINT64\r
@@ -1975,7 +3643,7 @@ MultS64x64 (
   @param  Dividend  A 64-bit unsigned value.\r
   @param  Divisor   A 32-bit unsigned value.\r
 \r
-  @return Dividend / Divisor\r
+  @return Dividend / Divisor.\r
 \r
 **/\r
 UINT64\r
@@ -1999,7 +3667,7 @@ DivU64x32 (
   @param  Dividend  A 64-bit unsigned value.\r
   @param  Divisor   A 32-bit unsigned value.\r
 \r
-  @return Dividend % Divisor\r
+  @return Dividend % Divisor.\r
 \r
 **/\r
 UINT32\r
@@ -2026,7 +3694,7 @@ ModU64x32 (
   @param  Remainder A pointer to a 32-bit unsigned value. This parameter is\r
                     optional and may be NULL.\r
 \r
-  @return Dividend / Divisor\r
+  @return Dividend / Divisor.\r
 \r
 **/\r
 UINT64\r
@@ -2054,7 +3722,7 @@ DivU64x32Remainder (
   @param  Remainder A pointer to a 64-bit unsigned value. This parameter is\r
                     optional and may be NULL.\r
 \r
-  @return Dividend / Divisor\r
+  @return Dividend / Divisor.\r
 \r
 **/\r
 UINT64\r
@@ -2086,7 +3754,7 @@ DivU64x64Remainder (
   @param  Remainder A pointer to a 64-bit signed value. This parameter is\r
                     optional and may be NULL.\r
 \r
-  @return Dividend / Divisor\r
+  @return Dividend / Divisor.\r
 \r
 **/\r
 INT64\r
@@ -2106,7 +3774,7 @@ DivS64x64Remainder (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Buffer  Pointer to a 16-bit value that may be unaligned.\r
+  @param  Buffer  The pointer to a 16-bit value that may be unaligned.\r
 \r
   @return The 16-bit value read from Buffer.\r
 \r
@@ -2127,7 +3795,7 @@ ReadUnaligned16 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Buffer  Pointer to a 16-bit value that may be unaligned.\r
+  @param  Buffer  The pointer to a 16-bit value that may be unaligned.\r
   @param  Value   16-bit value to write to Buffer.\r
 \r
   @return The 16-bit value to write to Buffer.\r
@@ -2149,7 +3817,7 @@ WriteUnaligned16 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Buffer  Pointer to a 24-bit value that may be unaligned.\r
+  @param  Buffer  The pointer to a 24-bit value that may be unaligned.\r
 \r
   @return The 24-bit value read from Buffer.\r
 \r
@@ -2170,7 +3838,7 @@ ReadUnaligned24 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Buffer  Pointer to a 24-bit value that may be unaligned.\r
+  @param  Buffer  The pointer to a 24-bit value that may be unaligned.\r
   @param  Value   24-bit value to write to Buffer.\r
 \r
   @return The 24-bit value to write to Buffer.\r
@@ -2192,7 +3860,7 @@ WriteUnaligned24 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Buffer  Pointer to a 32-bit value that may be unaligned.\r
+  @param  Buffer  The pointer to a 32-bit value that may be unaligned.\r
 \r
   @return The 32-bit value read from Buffer.\r
 \r
@@ -2213,7 +3881,7 @@ ReadUnaligned32 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Buffer  Pointer to a 32-bit value that may be unaligned.\r
+  @param  Buffer  The pointer to a 32-bit value that may be unaligned.\r
   @param  Value   32-bit value to write to Buffer.\r
 \r
   @return The 32-bit value to write to Buffer.\r
@@ -2235,7 +3903,7 @@ WriteUnaligned32 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Buffer  Pointer to a 64-bit value that may be unaligned.\r
+  @param  Buffer  The pointer to a 64-bit value that may be unaligned.\r
 \r
   @return The 64-bit value read from Buffer.\r
 \r
@@ -2256,7 +3924,7 @@ ReadUnaligned64 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Buffer  Pointer to a 64-bit value that may be unaligned.\r
+  @param  Buffer  The pointer to a 64-bit value that may be unaligned.\r
   @param  Value   64-bit value to write to Buffer.\r
 \r
   @return The 64-bit value to write to Buffer.\r
@@ -2313,6 +3981,7 @@ BitFieldRead8 (
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2346,6 +4015,7 @@ BitFieldWrite8 (
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2379,6 +4049,7 @@ BitFieldOr8 (
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2413,6 +4084,8 @@ BitFieldAnd8 (
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2475,6 +4148,7 @@ BitFieldRead16 (
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2508,6 +4182,7 @@ BitFieldWrite16 (
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2541,6 +4216,7 @@ BitFieldOr16 (
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2575,6 +4251,8 @@ BitFieldAnd16 (
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2637,6 +4315,7 @@ BitFieldRead32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2670,13 +4349,14 @@ BitFieldWrite32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..31.\r
-  @param  OrData    The value to OR with the read value from the value\r
+  @param  OrData    The value to OR with the read value from the value.\r
 \r
   @return The new 32-bit value.\r
 \r
@@ -2703,6 +4383,7 @@ BitFieldOr32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2737,6 +4418,8 @@ BitFieldAnd32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2799,6 +4482,7 @@ BitFieldRead64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2832,6 +4516,7 @@ BitFieldWrite64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2865,6 +4550,7 @@ BitFieldOr64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2899,6 +4585,8 @@ BitFieldAnd64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Operand   Operand on which to perform the bitfield operation.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -2937,7 +4625,7 @@ BitFieldAndThenOr64 (
   If Buffer is NULL, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer      Pointer to the buffer to carry out the sum operation.\r
+  @param  Buffer      The pointer to the buffer to carry out the sum operation.\r
   @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Sum         The sum of Buffer with carry bits dropped during additions.\r
@@ -2963,10 +4651,10 @@ CalculateSum8 (
   If Buffer is NULL, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer      Pointer to the buffer to carry out the checksum operation.\r
+  @param  Buffer      The pointer to the buffer to carry out the checksum operation.\r
   @param  Length      The size, in bytes, of Buffer.\r
 \r
-  @return Checksum    The 2's complement checksum of Buffer.\r
+  @return Checksum    The two's complement checksum of Buffer.\r
 \r
 **/\r
 UINT8\r
@@ -2990,7 +4678,7 @@ CalculateCheckSum8 (
   If Length is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer      Pointer to the buffer to carry out the sum operation.\r
+  @param  Buffer      The pointer to the buffer to carry out the sum operation.\r
   @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Sum         The sum of Buffer with carry bits dropped during additions.\r
@@ -3018,10 +4706,10 @@ CalculateSum16 (
   If Length is not aligned on a 16-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer      Pointer to the buffer to carry out the checksum operation.\r
+  @param  Buffer      The pointer to the buffer to carry out the checksum operation.\r
   @param  Length      The size, in bytes, of Buffer.\r
 \r
-  @return Checksum    The 2's complement checksum of Buffer.\r
+  @return Checksum    The two's complement checksum of Buffer.\r
 \r
 **/\r
 UINT16\r
@@ -3045,7 +4733,7 @@ CalculateCheckSum16 (
   If Length is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer      Pointer to the buffer to carry out the sum operation.\r
+  @param  Buffer      The pointer to the buffer to carry out the sum operation.\r
   @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Sum         The sum of Buffer with carry bits dropped during additions.\r
@@ -3073,10 +4761,10 @@ CalculateSum32 (
   If Length is not aligned on a 32-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer      Pointer to the buffer to carry out the checksum operation.\r
+  @param  Buffer      The pointer to the buffer to carry out the checksum operation.\r
   @param  Length      The size, in bytes, of Buffer.\r
 \r
-  @return Checksum    The 2's complement checksum of Buffer.\r
+  @return Checksum    The two's complement checksum of Buffer.\r
 \r
 **/\r
 UINT32\r
@@ -3100,7 +4788,7 @@ CalculateCheckSum32 (
   If Length is not aligned on a 64-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer      Pointer to the buffer to carry out the sum operation.\r
+  @param  Buffer      The pointer to the buffer to carry out the sum operation.\r
   @param  Length      The size, in bytes, of Buffer.\r
 \r
   @return Sum         The sum of Buffer with carry bits dropped during additions.\r
@@ -3128,10 +4816,10 @@ CalculateSum64 (
   If Length is not aligned on a 64-bit boundary, then ASSERT().\r
   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
 \r
-  @param  Buffer      Pointer to the buffer to carry out the checksum operation.\r
+  @param  Buffer      The pointer to the buffer to carry out the checksum operation.\r
   @param  Length      The size, in bytes, of Buffer.\r
 \r
-  @return Checksum    The 2's complement checksum of Buffer.\r
+  @return Checksum    The two's complement checksum of Buffer.\r
 \r
 **/\r
 UINT64\r
@@ -3141,6 +4829,25 @@ CalculateCheckSum64 (
   IN      UINTN                     Length\r
   );\r
 \r
+/**\r
+  Computes and returns a 32-bit CRC for a data buffer.\r
+  CRC32 value bases on ITU-T V.42.\r
+\r
+  If Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param[in]  Buffer       A pointer to the buffer on which the 32-bit CRC is to be computed.\r
+  @param[in]  Length       The number of bytes in the buffer Data.\r
+\r
+  @retval Crc32            The 32-bit CRC was computed for the data buffer.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+CalculateCrc32(\r
+  IN  VOID                         *Buffer,\r
+  IN  UINTN                        Length\r
+  );\r
 \r
 //\r
 // Base Library CPU Functions\r
@@ -3196,6 +4903,7 @@ MemoryFence (
   @retval 0 Indicates a return from SetJump().\r
 \r
 **/\r
+RETURNS_TWICE\r
 UINTN\r
 EFIAPI\r
 SetJump (\r
@@ -3279,7 +4987,7 @@ EnableDisableInterrupts (
 /**\r
   Retrieves the current CPU interrupt state.\r
 \r
-  Returns TRUE is interrupts are currently enabled. Otherwise\r
+  Returns TRUE if interrupts are currently enabled. Otherwise\r
   returns FALSE.\r
 \r
   @retval TRUE  CPU interrupts are enabled.\r
@@ -3350,10 +5058,10 @@ CpuPause (
                       function.\r
   @param  NewStack    A pointer to the new stack to use for the EntryPoint\r
                       function.\r
-  @param  ...         This variable argument list is ignored for IA-32, x64, and EBC architectures.  \r
-                      For Itanium processors, this variable argument list is expected to contain \r
-                      a single parameter of type VOID * that specifies the new backing \r
-                      store pointer.\r
+  @param  ...         This variable argument list is ignored for IA-32, x64, and \r
+                      EBC architectures.  For Itanium processors, this variable \r
+                      argument list is expected to contain a single parameter of \r
+                      type VOID * that specifies the new backing store pointer.\r
 \r
 \r
 **/\r
@@ -3432,8 +5140,8 @@ AsmFlushCacheRange (
 \r
 \r
 /**\r
-  Executes a FC instruction\r
-  Executes a FC instruction on the cache line specified by Address.\r
+  Executes an FC instruction.\r
+  Executes an FC instruction on the cache line specified by Address.\r
   The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).\r
   An implementation may flush a larger region.  This function is only available on Itanium processors.\r
 \r
@@ -3450,14 +5158,14 @@ AsmFc (
 \r
 \r
 /**\r
-  Executes a FC.I instruction.\r
-  Executes a FC.I instruction on the cache line specified by Address.\r
+  Executes an FC.I instruction.\r
+  Executes an FC.I instruction on the cache line specified by Address.\r
   The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).\r
   An implementation may flush a larger region.  This function is only available on Itanium processors.\r
 \r
   @param Address    The Address of cache line to be flushed.\r
 \r
-  @return The address of FC.I instruction executed.\r
+  @return The address of the FC.I instruction executed.\r
 \r
 **/\r
 UINT64\r
@@ -4323,7 +6031,7 @@ AsmWriteLrr1 (
   \r
   The Instruction Breakpoint Registers are used in pairs.  The even numbered\r
   registers contain breakpoint addresses, and the odd numbered registers contain\r
-  breakpoint mask conditions.  At least 4 instruction registers pairs are implemented\r
+  breakpoint mask conditions.  At least four instruction registers pairs are implemented\r
   on all processor models.   Implemented registers are contiguous starting with\r
   register 0.  No parameter checking is performed on Index, and if the Index value\r
   is beyond the implemented IBR register range, a Reserved Register/Field fault may\r
@@ -4348,7 +6056,7 @@ AsmReadIbr (
 \r
   The Data Breakpoint Registers are used in pairs.  The even numbered registers\r
   contain breakpoint addresses, and odd numbered registers contain breakpoint\r
-  mask conditions.  At least 4 data registers pairs are implemented on all processor\r
+  mask conditions.  At least four data registers pairs are implemented on all processor\r
   models.  Implemented registers are contiguous starting with register 0.\r
   No parameter checking is performed on Index.  If the Index value is beyond\r
   the implemented DBR register range, a Reserved Register/Field fault may occur.\r
@@ -4371,8 +6079,8 @@ AsmReadDbr (
 /**\r
   Reads the current value of Performance Monitor Configuration Register (PMC).\r
 \r
-  All processor implementations provide at least 4 performance counters\r
-  (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow\r
+  All processor implementations provide at least four performance counters\r
+  (PMC/PMD [4]...PMC/PMD [7] pairs), and four performance monitor counter overflow\r
   status registers (PMC [0]... PMC [3]).  Processor implementations may provide\r
   additional implementation-dependent PMC and PMD to increase the number of\r
   'generic' performance counters (PMC/PMD pairs).  The remainder of PMC and PMD\r
@@ -4425,7 +6133,7 @@ AsmReadPmd (
   Writes current value of Instruction Breakpoint Register specified by Index.\r
   The Instruction Breakpoint Registers are used in pairs.  The even numbered\r
   registers contain breakpoint addresses, and odd numbered registers contain\r
-  breakpoint mask conditions.  At least 4 instruction registers pairs are implemented\r
+  breakpoint mask conditions.  At least four instruction registers pairs are implemented\r
   on all processor models.  Implemented registers are contiguous starting with\r
   register 0.  No parameter checking is performed on Index.  If the Index value\r
   is beyond the implemented IBR register range, a Reserved Register/Field fault may\r
@@ -4453,7 +6161,7 @@ AsmWriteIbr (
   Writes current value of Data Breakpoint Register specified by Index.\r
   The Data Breakpoint Registers are used in pairs.  The even numbered registers\r
   contain breakpoint addresses, and odd numbered registers contain breakpoint\r
-  mask conditions.  At least 4 data registers pairs are implemented on all processor\r
+  mask conditions.  At least four data registers pairs are implemented on all processor\r
   models.  Implemented registers are contiguous starting with register 0.  No parameter\r
   checking is performed on Index.  If the Index value is beyond the implemented\r
   DBR register range, a Reserved Register/Field fault may occur.  The caller must\r
@@ -4479,8 +6187,8 @@ AsmWriteDbr (
   Writes the current value of 64-bit Performance Monitor Configuration Register (PMC).\r
 \r
   Writes current value of Performance Monitor Configuration Register specified by Index.\r
-  All processor implementations provide at least 4 performance counters\r
-  (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow status\r
+  All processor implementations provide at least four performance counters\r
+  (PMC/PMD [4]...PMC/PMD [7] pairs), and four performance monitor counter overflow status\r
   registers (PMC [0]... PMC [3]).  Processor implementations may provide additional\r
   implementation-dependent PMC and PMD to increase the number of 'generic' performance\r
   counters (PMC/PMD pairs).  The remainder of PMC and PMD register set is implementation\r
@@ -4506,8 +6214,8 @@ AsmWritePmc (
   Writes the current value of 64-bit Performance Monitor Data Register (PMD).\r
 \r
   Writes current value of Performance Monitor Data Register specified by Index.\r
-  All processor implementations provide at least 4 performance counters\r
-  (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow\r
+  All processor implementations provide at least four performance counters\r
+  (PMC/PMD [4]...PMC/PMD [7] pairs), and four performance monitor counter overflow\r
   status registers (PMC [0]... PMC [3]).  Processor implementations may provide\r
   additional implementation-dependent PMC and PMD to increase the number of 'generic'\r
   performance counters (PMC/PMD pairs).  The remainder of PMC and PMD register set\r
@@ -4581,7 +6289,7 @@ AsmReadSp (
 \r
 \r
 ///\r
-/// Valid Index value for AsmReadControlRegister()\r
+/// Valid Index value for AsmReadControlRegister().\r
 ///\r
 #define IPF_CONTROL_REGISTER_DCR   0\r
 #define IPF_CONTROL_REGISTER_ITM   1\r
@@ -4613,9 +6321,10 @@ AsmReadSp (
 /**\r
   Reads a 64-bit control register.\r
 \r
-  Reads and returns the control register specified by Index. The valid Index valued are defined\r
-  above in "Related Definitions".\r
-  If Index is invalid then 0xFFFFFFFFFFFFFFFF is returned.  This function is only available on Itanium processors.\r
+  Reads and returns the control register specified by Index. The valid Index valued \r
+  are defined above in "Related Definitions".\r
+  If Index is invalid then 0xFFFFFFFFFFFFFFFF is returned.  This function is only \r
+  available on Itanium processors.\r
 \r
   @param  Index                     The index of the control register to read.\r
 \r
@@ -4630,7 +6339,7 @@ AsmReadControlRegister (
 \r
 \r
 ///\r
-/// Valid Index value for AsmReadApplicationRegister()\r
+/// Valid Index value for AsmReadApplicationRegister().\r
 ///\r
 #define IPF_APPLICATION_REGISTER_K0        0\r
 #define IPF_APPLICATION_REGISTER_K1        1\r
@@ -4663,9 +6372,10 @@ AsmReadControlRegister (
 /**\r
   Reads a 64-bit application register.\r
 \r
-  Reads and returns the application register specified by Index. The valid Index valued are defined\r
-  above in "Related Definitions".\r
-  If Index is invalid then 0xFFFFFFFFFFFFFFFF is returned.  This function is only available on Itanium processors.\r
+  Reads and returns the application register specified by Index. The valid Index \r
+  valued are defined above in "Related Definitions".\r
+  If Index is invalid then 0xFFFFFFFFFFFFFFFF is returned.  This function is only \r
+  available on Itanium processors.\r
 \r
   @param  Index                     The index of the application register to read.\r
 \r
@@ -4785,123 +6495,145 @@ AsmPalCall (
   IN UINT64  Arg3,\r
   IN UINT64  Arg4\r
   );\r
-#endif\r
+#endif // defined (MDE_CPU_IPF)\r
 \r
 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
 ///\r
-/// IA32 and x64 Specific Functions\r
-/// Byte packed structure for 16-bit Real Mode EFLAGS\r
+/// IA32 and x64 Specific Functions.\r
+/// Byte packed structure for 16-bit Real Mode EFLAGS.\r
 ///\r
 typedef union {\r
   struct {\r
-    UINT32  CF:1;           ///< Carry Flag\r
-    UINT32  Reserved_0:1;   ///< Reserved\r
-    UINT32  PF:1;           ///< Parity Flag\r
-    UINT32  Reserved_1:1;   ///< Reserved\r
-    UINT32  AF:1;           ///< Auxiliary Carry Flag\r
-    UINT32  Reserved_2:1;   ///< Reserved\r
-    UINT32  ZF:1;           ///< Zero Flag\r
-    UINT32  SF:1;           ///< Sign Flag\r
-    UINT32  TF:1;           ///< Trap Flag\r
-    UINT32  IF:1;           ///< Interrupt Enable Flag\r
-    UINT32  DF:1;           ///< Direction Flag\r
-    UINT32  OF:1;           ///< Overflow Flag\r
-    UINT32  IOPL:2;         ///< I/O Privilege Level\r
-    UINT32  NT:1;           ///< Nested Task\r
-    UINT32  Reserved_3:1;   ///< Reserved\r
+    UINT32  CF:1;           ///< Carry Flag.\r
+    UINT32  Reserved_0:1;   ///< Reserved.\r
+    UINT32  PF:1;           ///< Parity Flag.\r
+    UINT32  Reserved_1:1;   ///< Reserved.\r
+    UINT32  AF:1;           ///< Auxiliary Carry Flag.\r
+    UINT32  Reserved_2:1;   ///< Reserved.\r
+    UINT32  ZF:1;           ///< Zero Flag.\r
+    UINT32  SF:1;           ///< Sign Flag.\r
+    UINT32  TF:1;           ///< Trap Flag.\r
+    UINT32  IF:1;           ///< Interrupt Enable Flag.\r
+    UINT32  DF:1;           ///< Direction Flag.\r
+    UINT32  OF:1;           ///< Overflow Flag.\r
+    UINT32  IOPL:2;         ///< I/O Privilege Level.\r
+    UINT32  NT:1;           ///< Nested Task.\r
+    UINT32  Reserved_3:1;   ///< Reserved.\r
   } Bits;\r
   UINT16    Uint16;\r
 } IA32_FLAGS16;\r
 \r
 ///\r
-/// Byte packed structure for EFLAGS/RFLAGS\r
-/// 32-bits on IA-32\r
-/// 64-bits on x64.  The upper 32-bits on x64 are reserved\r
+/// Byte packed structure for EFLAGS/RFLAGS.\r
+/// 32-bits on IA-32.\r
+/// 64-bits on x64.  The upper 32-bits on x64 are reserved.\r
 ///\r
 typedef union {\r
   struct {\r
-    UINT32  CF:1;           ///< Carry Flag\r
-    UINT32  Reserved_0:1;   ///< Reserved\r
-    UINT32  PF:1;           ///< Parity Flag\r
-    UINT32  Reserved_1:1;   ///< Reserved\r
-    UINT32  AF:1;           ///< Auxiliary Carry Flag\r
-    UINT32  Reserved_2:1;   ///< Reserved\r
-    UINT32  ZF:1;           ///< Zero Flag\r
-    UINT32  SF:1;           ///< Sign Flag\r
-    UINT32  TF:1;           ///< Trap Flag\r
-    UINT32  IF:1;           ///< Interrupt Enable Flag\r
-    UINT32  DF:1;           ///< Direction Flag\r
-    UINT32  OF:1;           ///< Overflow Flag\r
-    UINT32  IOPL:2;         ///< I/O Privilege Level\r
-    UINT32  NT:1;           ///< Nested Task\r
-    UINT32  Reserved_3:1;   ///< Reserved\r
-    UINT32  RF:1;           ///< Resume Flag\r
-    UINT32  VM:1;           ///< Virtual 8086 Mode\r
-    UINT32  AC:1;           ///< Alignment Check\r
-    UINT32  VIF:1;          ///< Virtual Interrupt Flag\r
-    UINT32  VIP:1;          ///< Virtual Interrupt Pending\r
-    UINT32  ID:1;           ///< ID Flag\r
-    UINT32  Reserved_4:10;  ///< Reserved\r
+    UINT32  CF:1;           ///< Carry Flag.\r
+    UINT32  Reserved_0:1;   ///< Reserved.\r
+    UINT32  PF:1;           ///< Parity Flag.\r
+    UINT32  Reserved_1:1;   ///< Reserved.\r
+    UINT32  AF:1;           ///< Auxiliary Carry Flag.\r
+    UINT32  Reserved_2:1;   ///< Reserved.\r
+    UINT32  ZF:1;           ///< Zero Flag.\r
+    UINT32  SF:1;           ///< Sign Flag.\r
+    UINT32  TF:1;           ///< Trap Flag.\r
+    UINT32  IF:1;           ///< Interrupt Enable Flag.\r
+    UINT32  DF:1;           ///< Direction Flag.\r
+    UINT32  OF:1;           ///< Overflow Flag.\r
+    UINT32  IOPL:2;         ///< I/O Privilege Level.\r
+    UINT32  NT:1;           ///< Nested Task.\r
+    UINT32  Reserved_3:1;   ///< Reserved.\r
+    UINT32  RF:1;           ///< Resume Flag.\r
+    UINT32  VM:1;           ///< Virtual 8086 Mode.\r
+    UINT32  AC:1;           ///< Alignment Check.\r
+    UINT32  VIF:1;          ///< Virtual Interrupt Flag.\r
+    UINT32  VIP:1;          ///< Virtual Interrupt Pending.\r
+    UINT32  ID:1;           ///< ID Flag.\r
+    UINT32  Reserved_4:10;  ///< Reserved.\r
   } Bits;\r
   UINTN     UintN;\r
 } IA32_EFLAGS32;\r
 \r
 ///\r
-/// Byte packed structure for Control Register 0 (CR0)\r
-/// 32-bits on IA-32\r
-/// 64-bits on x64.  The upper 32-bits on x64 are reserved\r
+/// Byte packed structure for Control Register 0 (CR0).\r
+/// 32-bits on IA-32.\r
+/// 64-bits on x64.  The upper 32-bits on x64 are reserved.\r
 ///\r
 typedef union {\r
   struct {\r
-    UINT32  PE:1;           ///< Protection Enable\r
-    UINT32  MP:1;           ///< Monitor Coprocessor\r
-    UINT32  EM:1;           ///< Emulation\r
-    UINT32  TS:1;           ///< Task Switched\r
-    UINT32  ET:1;           ///< Extension Type\r
-    UINT32  NE:1;           ///< Numeric Error\r
-    UINT32  Reserved_0:10;  ///< Reserved\r
-    UINT32  WP:1;           ///< Write Protect\r
-    UINT32  Reserved_1:1;   ///< Reserved\r
-    UINT32  AM:1;           ///< Alignment Mask\r
-    UINT32  Reserved_2:10;  ///< Reserved\r
-    UINT32  NW:1;           ///< Mot Write-through\r
-    UINT32  CD:1;           ///< Cache Disable\r
-    UINT32  PG:1;           ///< Paging\r
+    UINT32  PE:1;           ///< Protection Enable.\r
+    UINT32  MP:1;           ///< Monitor Coprocessor.\r
+    UINT32  EM:1;           ///< Emulation.\r
+    UINT32  TS:1;           ///< Task Switched.\r
+    UINT32  ET:1;           ///< Extension Type.\r
+    UINT32  NE:1;           ///< Numeric Error.\r
+    UINT32  Reserved_0:10;  ///< Reserved.\r
+    UINT32  WP:1;           ///< Write Protect.\r
+    UINT32  Reserved_1:1;   ///< Reserved.\r
+    UINT32  AM:1;           ///< Alignment Mask.\r
+    UINT32  Reserved_2:10;  ///< Reserved.\r
+    UINT32  NW:1;           ///< Mot Write-through.\r
+    UINT32  CD:1;           ///< Cache Disable.\r
+    UINT32  PG:1;           ///< Paging.\r
   } Bits;\r
   UINTN     UintN;\r
 } IA32_CR0;\r
 \r
 ///\r
-/// Byte packed structure for Control Register 4 (CR4)\r
-/// 32-bits on IA-32\r
-/// 64-bits on x64.  The upper 32-bits on x64 are reserved\r
+/// Byte packed structure for Control Register 4 (CR4).\r
+/// 32-bits on IA-32.\r
+/// 64-bits on x64.  The upper 32-bits on x64 are reserved.\r
 ///\r
 typedef union {\r
   struct {\r
-    UINT32  VME:1;          ///< Virtual-8086 Mode Extensions\r
-    UINT32  PVI:1;          ///< Protected-Mode Virtual Interrupts\r
-    UINT32  TSD:1;          ///< Time Stamp Disable\r
-    UINT32  DE:1;           ///< Debugging Extensions\r
-    UINT32  PSE:1;          ///< Page Size Extensions\r
-    UINT32  PAE:1;          ///< Physical Address Extension\r
-    UINT32  MCE:1;          ///< Machine Check Enable\r
-    UINT32  PGE:1;          ///< Page Global Enable\r
+    UINT32  VME:1;          ///< Virtual-8086 Mode Extensions.\r
+    UINT32  PVI:1;          ///< Protected-Mode Virtual Interrupts.\r
+    UINT32  TSD:1;          ///< Time Stamp Disable.\r
+    UINT32  DE:1;           ///< Debugging Extensions.\r
+    UINT32  PSE:1;          ///< Page Size Extensions.\r
+    UINT32  PAE:1;          ///< Physical Address Extension.\r
+    UINT32  MCE:1;          ///< Machine Check Enable.\r
+    UINT32  PGE:1;          ///< Page Global Enable.\r
     UINT32  PCE:1;          ///< Performance Monitoring Counter\r
-                            ///< Enable\r
+                            ///< Enable.\r
     UINT32  OSFXSR:1;       ///< Operating System Support for\r
                             ///< FXSAVE and FXRSTOR instructions\r
     UINT32  OSXMMEXCPT:1;   ///< Operating System Support for\r
                             ///< Unmasked SIMD Floating Point\r
-                            ///< Exceptions\r
-    UINT32  Reserved_0:2;   ///< Reserved\r
+                            ///< Exceptions.\r
+    UINT32  Reserved_0:2;   ///< Reserved.\r
     UINT32  VMXE:1;         ///< VMX Enable\r
-    UINT32  Reserved_1:18;  ///< Reserved\r
+    UINT32  Reserved_1:18;  ///< Reserved.\r
   } Bits;\r
   UINTN     UintN;\r
 } IA32_CR4;\r
 \r
 ///\r
-/// Byte packed structure for an IDTR, GDTR, LDTR descriptor\r
+/// Byte packed structure for a segment descriptor in a GDT/LDT.\r
+///\r
+typedef union {\r
+  struct {\r
+    UINT32  LimitLow:16;\r
+    UINT32  BaseLow:16;\r
+    UINT32  BaseMid:8;\r
+    UINT32  Type:4;\r
+    UINT32  S:1;\r
+    UINT32  DPL:2;\r
+    UINT32  P:1;\r
+    UINT32  LimitHigh:4;\r
+    UINT32  AVL:1;\r
+    UINT32  L:1;\r
+    UINT32  DB:1;\r
+    UINT32  G:1;\r
+    UINT32  BaseHigh:8;\r
+  } Bits;\r
+  UINT64  Uint64;\r
+} IA32_SEGMENT_DESCRIPTOR;\r
+\r
+///\r
+/// Byte packed structure for an IDTR, GDTR, LDTR descriptor.\r
 ///\r
 #pragma pack (1)\r
 typedef struct {\r
@@ -4916,37 +6648,103 @@ typedef struct {
 #define IA32_IDT_GATE_TYPE_INTERRUPT_32  0x8E\r
 #define IA32_IDT_GATE_TYPE_TRAP_32       0x8F\r
 \r
+#define IA32_GDT_TYPE_TSS               0x9\r
+#define IA32_GDT_ALIGNMENT              8\r
 \r
 #if defined (MDE_CPU_IA32)\r
 ///\r
-/// Byte packed structure for an IA-32 Interrupt Gate Descriptor\r
+/// Byte packed structure for an IA-32 Interrupt Gate Descriptor.\r
 ///\r
 typedef union {\r
   struct {\r
-    UINT32  OffsetLow:16;   ///< Offset bits 15..0\r
-    UINT32  Selector:16;    ///< Selector\r
-    UINT32  Reserved_0:8;   ///< Reserved\r
-    UINT32  GateType:8;     ///< Gate Type.  See #defines above\r
-    UINT32  OffsetHigh:16;  ///< Offset bits 31..16\r
+    UINT32  OffsetLow:16;   ///< Offset bits 15..0.\r
+    UINT32  Selector:16;    ///< Selector.\r
+    UINT32  Reserved_0:8;   ///< Reserved.\r
+    UINT32  GateType:8;     ///< Gate Type.  See #defines above.\r
+    UINT32  OffsetHigh:16;  ///< Offset bits 31..16.\r
   } Bits;\r
   UINT64  Uint64;\r
 } IA32_IDT_GATE_DESCRIPTOR;\r
 \r
-#endif\r
+#pragma pack (1)\r
+//\r
+// IA32 Task-State Segment Definition\r
+//\r
+typedef struct {\r
+  UINT16    PreviousTaskLink;\r
+  UINT16    Reserved_2;\r
+  UINT32    ESP0;\r
+  UINT16    SS0;\r
+  UINT16    Reserved_10;\r
+  UINT32    ESP1;\r
+  UINT16    SS1;\r
+  UINT16    Reserved_18;\r
+  UINT32    ESP2;\r
+  UINT16    SS2;\r
+  UINT16    Reserved_26;\r
+  UINT32    CR3;\r
+  UINT32    EIP;\r
+  UINT32    EFLAGS;\r
+  UINT32    EAX;\r
+  UINT32    ECX;\r
+  UINT32    EDX;\r
+  UINT32    EBX;\r
+  UINT32    ESP;\r
+  UINT32    EBP;\r
+  UINT32    ESI;\r
+  UINT32    EDI;\r
+  UINT16    ES;\r
+  UINT16    Reserved_74;\r
+  UINT16    CS;\r
+  UINT16    Reserved_78;\r
+  UINT16    SS;\r
+  UINT16    Reserved_82;\r
+  UINT16    DS;\r
+  UINT16    Reserved_86;\r
+  UINT16    FS;\r
+  UINT16    Reserved_90;\r
+  UINT16    GS;\r
+  UINT16    Reserved_94;\r
+  UINT16    LDTSegmentSelector;\r
+  UINT16    Reserved_98;\r
+  UINT16    T;\r
+  UINT16    IOMapBaseAddress;\r
+} IA32_TASK_STATE_SEGMENT;\r
+\r
+typedef union {\r
+  struct {\r
+    UINT32  LimitLow:16;    ///< Segment Limit 15..00\r
+    UINT32  BaseLow:16;     ///< Base Address  15..00\r
+    UINT32  BaseMid:8;      ///< Base Address  23..16\r
+    UINT32  Type:4;         ///< Type (1 0 B 1)\r
+    UINT32  Reserved_43:1;  ///< 0\r
+    UINT32  DPL:2;          ///< Descriptor Privilege Level\r
+    UINT32  P:1;            ///< Segment Present\r
+    UINT32  LimitHigh:4;    ///< Segment Limit 19..16\r
+    UINT32  AVL:1;          ///< Available for use by system software\r
+    UINT32  Reserved_52:2;  ///< 0 0\r
+    UINT32  G:1;            ///< Granularity\r
+    UINT32  BaseHigh:8;     ///< Base Address 31..24\r
+  } Bits;\r
+  UINT64  Uint64;\r
+} IA32_TSS_DESCRIPTOR;\r
+#pragma pack ()\r
+\r
+#endif // defined (MDE_CPU_IA32)\r
 \r
 #if defined (MDE_CPU_X64)\r
 ///\r
-/// Byte packed structure for an x64 Interrupt Gate Descriptor\r
+/// Byte packed structure for an x64 Interrupt Gate Descriptor.\r
 ///\r
 typedef union {\r
   struct {\r
-    UINT32  OffsetLow:16;   ///< Offset bits 15..0\r
-    UINT32  Selector:16;    ///< Selector\r
-    UINT32  Reserved_0:8;   ///< Reserved\r
-    UINT32  GateType:8;     ///< Gate Type.  See #defines above\r
-    UINT32  OffsetHigh:16;  ///< Offset bits 31..16\r
-    UINT32  OffsetUpper:32; ///< Offset bits 63..32\r
-    UINT32  Reserved_1:32;  ///< Reserved\r
+    UINT32  OffsetLow:16;   ///< Offset bits 15..0.\r
+    UINT32  Selector:16;    ///< Selector.\r
+    UINT32  Reserved_0:8;   ///< Reserved.\r
+    UINT32  GateType:8;     ///< Gate Type.  See #defines above.\r
+    UINT32  OffsetHigh:16;  ///< Offset bits 31..16.\r
+    UINT32  OffsetUpper:32; ///< Offset bits 63..32.\r
+    UINT32  Reserved_1:32;  ///< Reserved.\r
   } Bits;\r
   struct {\r
     UINT64  Uint64;\r
@@ -4954,17 +6752,57 @@ typedef union {
   } Uint128;   \r
 } IA32_IDT_GATE_DESCRIPTOR;\r
 \r
-#endif\r
+#pragma pack (1)\r
+//\r
+// IA32 Task-State Segment Definition\r
+//\r
+typedef struct {\r
+  UINT32    Reserved_0;\r
+  UINT64    RSP0;\r
+  UINT64    RSP1;\r
+  UINT64    RSP2;\r
+  UINT64    Reserved_28;\r
+  UINT64    IST[7];\r
+  UINT64    Reserved_92;\r
+  UINT16    Reserved_100;\r
+  UINT16    IOMapBaseAddress;\r
+} IA32_TASK_STATE_SEGMENT;\r
+\r
+typedef union {\r
+  struct {\r
+    UINT32  LimitLow:16;    ///< Segment Limit 15..00\r
+    UINT32  BaseLow:16;     ///< Base Address  15..00\r
+    UINT32  BaseMidl:8;     ///< Base Address  23..16\r
+    UINT32  Type:4;         ///< Type (1 0 B 1)\r
+    UINT32  Reserved_43:1;  ///< 0\r
+    UINT32  DPL:2;          ///< Descriptor Privilege Level\r
+    UINT32  P:1;            ///< Segment Present\r
+    UINT32  LimitHigh:4;    ///< Segment Limit 19..16\r
+    UINT32  AVL:1;          ///< Available for use by system software\r
+    UINT32  Reserved_52:2;  ///< 0 0\r
+    UINT32  G:1;            ///< Granularity\r
+    UINT32  BaseMidh:8;     ///< Base Address  31..24\r
+    UINT32  BaseHigh:32;    ///< Base Address  63..32\r
+    UINT32  Reserved_96:32; ///< Reserved\r
+  } Bits;\r
+  struct {\r
+    UINT64  Uint64;\r
+    UINT64  Uint64_1;\r
+  } Uint128;\r
+} IA32_TSS_DESCRIPTOR;\r
+#pragma pack ()\r
+\r
+#endif // defined (MDE_CPU_X64)\r
 \r
 ///\r
-/// Byte packed structure for an FP/SSE/SSE2 context\r
+/// Byte packed structure for an FP/SSE/SSE2 context.\r
 ///\r
 typedef struct {\r
   UINT8  Buffer[512];\r
 } IA32_FX_BUFFER;\r
 \r
 ///\r
-/// Structures for the 16-bit real mode thunks\r
+/// Structures for the 16-bit real mode thunks.\r
 ///\r
 typedef struct {\r
   UINT32                            Reserved1;\r
@@ -5030,7 +6868,7 @@ typedef union {
 } IA32_REGISTER_SET;\r
 \r
 ///\r
-/// Byte packed structure for an 16-bit real mode thunks\r
+/// Byte packed structure for an 16-bit real mode thunks.\r
 ///\r
 typedef struct {\r
   IA32_REGISTER_SET                 *RealModeState;\r
@@ -5043,6 +6881,20 @@ typedef struct {
 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15   0x00000002\r
 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004\r
 \r
+///\r
+/// Type definition for representing labels in NASM source code that allow for\r
+/// the patching of immediate operands of IA32 and X64 instructions.\r
+///\r
+/// While the type is technically defined as a function type (note: not a\r
+/// pointer-to-function type), such labels in NASM source code never stand for\r
+/// actual functions, and identifiers declared with this function type should\r
+/// never be called. This is also why the EFIAPI calling convention specifier\r
+/// is missing from the typedef, and why the typedef does not follow the usual\r
+/// edk2 coding style for function (or pointer-to-function) typedefs. The VOID\r
+/// return type and the VOID argument list are merely artifacts.\r
+///\r
+typedef VOID (X86_ASSEMBLY_PATCH_LABEL) (VOID);\r
+\r
 /**\r
   Retrieves CPUID information.\r
 \r
@@ -5056,13 +6908,13 @@ typedef struct {
 \r
   @param  Index The 32-bit value to load into EAX prior to invoking the CPUID\r
                 instruction.\r
-  @param  Eax   Pointer to the 32-bit EAX value returned by the CPUID\r
+  @param  Eax   The pointer to the 32-bit EAX value returned by the CPUID\r
                 instruction. This is an optional parameter that may be NULL.\r
-  @param  Ebx   Pointer to the 32-bit EBX value returned by the CPUID\r
+  @param  Ebx   The pointer to the 32-bit EBX value returned by the CPUID\r
                 instruction. This is an optional parameter that may be NULL.\r
-  @param  Ecx   Pointer to the 32-bit ECX value returned by the CPUID\r
+  @param  Ecx   The pointer to the 32-bit ECX value returned by the CPUID\r
                 instruction. This is an optional parameter that may be NULL.\r
-  @param  Edx   Pointer to the 32-bit EDX value returned by the CPUID\r
+  @param  Edx   The pointer to the 32-bit EDX value returned by the CPUID\r
                 instruction. This is an optional parameter that may be NULL.\r
 \r
   @return Index.\r
@@ -5095,16 +6947,16 @@ AsmCpuid (
                     CPUID instruction.\r
   @param  SubIndex  The 32-bit value to load into ECX prior to invoking the\r
                     CPUID instruction.\r
-  @param  Eax       Pointer to the 32-bit EAX value returned by the CPUID\r
+  @param  Eax       The pointer to the 32-bit EAX value returned by the CPUID\r
                     instruction. This is an optional parameter that may be\r
                     NULL.\r
-  @param  Ebx       Pointer to the 32-bit EBX value returned by the CPUID\r
+  @param  Ebx       The pointer to the 32-bit EBX value returned by the CPUID\r
                     instruction. This is an optional parameter that may be\r
                     NULL.\r
-  @param  Ecx       Pointer to the 32-bit ECX value returned by the CPUID\r
+  @param  Ecx       The pointer to the 32-bit ECX value returned by the CPUID\r
                     instruction. This is an optional parameter that may be\r
                     NULL.\r
-  @param  Edx       Pointer to the 32-bit EDX value returned by the CPUID\r
+  @param  Edx       The pointer to the 32-bit EDX value returned by the CPUID\r
                     instruction. This is an optional parameter that may be\r
                     NULL.\r
 \r
@@ -5326,6 +7178,7 @@ AsmMsrBitFieldRead32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -5362,6 +7215,7 @@ AsmMsrBitFieldWrite32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -5398,6 +7252,7 @@ AsmMsrBitFieldOr32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -5436,6 +7291,8 @@ AsmMsrBitFieldAnd32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -5630,6 +7487,7 @@ AsmMsrBitFieldRead64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -5666,6 +7524,7 @@ AsmMsrBitFieldWrite64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -5702,6 +7561,7 @@ AsmMsrBitFieldOr64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -5739,6 +7599,8 @@ AsmMsrBitFieldAnd64 (
   If StartBit is greater than 63, then ASSERT().\r
   If EndBit is greater than 63, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
   @param  Index     The 32-bit MSR index to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -6319,7 +8181,7 @@ AsmReadTr (
 \r
   If Gdtr is NULL, then ASSERT().\r
 \r
-  @param  Gdtr  Pointer to a GDTR descriptor.\r
+  @param  Gdtr  The pointer to a GDTR descriptor.\r
 \r
 **/\r
 VOID\r
@@ -6337,7 +8199,7 @@ AsmReadGdtr (
 \r
   If Gdtr is NULL, then ASSERT().\r
 \r
-  @param  Gdtr  Pointer to a GDTR descriptor.\r
+  @param  Gdtr  The pointer to a GDTR descriptor.\r
 \r
 **/\r
 VOID\r
@@ -6355,7 +8217,7 @@ AsmWriteGdtr (
 \r
   If Idtr is NULL, then ASSERT().\r
 \r
-  @param  Idtr  Pointer to a IDTR descriptor.\r
+  @param  Idtr  The pointer to a IDTR descriptor.\r
 \r
 **/\r
 VOID\r
@@ -6373,7 +8235,7 @@ AsmReadIdtr (
 \r
   If Idtr is NULL, then ASSERT().\r
 \r
-  @param  Idtr  Pointer to a IDTR descriptor.\r
+  @param  Idtr  The pointer to a IDTR descriptor.\r
 \r
 **/\r
 VOID\r
@@ -6425,7 +8287,7 @@ AsmWriteLdtr (
   If Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 16-byte boundary, then ASSERT().\r
 \r
-  @param  Buffer  Pointer to a buffer to save the floating point/SSE/SSE2 context.\r
+  @param  Buffer  The pointer to a buffer to save the floating point/SSE/SSE2 context.\r
 \r
 **/\r
 VOID\r
@@ -6446,7 +8308,7 @@ AsmFxSave (
   If Buffer is not aligned on a 16-byte boundary, then ASSERT().\r
   If Buffer was not saved with AsmFxSave(), then ASSERT().\r
 \r
-  @param  Buffer  Pointer to a buffer to save the floating point/SSE/SSE2 context.\r
+  @param  Buffer  The pointer to a buffer to save the floating point/SSE/SSE2 context.\r
 \r
 **/\r
 VOID\r
@@ -6834,7 +8696,7 @@ AsmInvd (
                         addressing mode, then LinearAddress is a virtual\r
                         address.\r
 \r
-  @return LinearAddress\r
+  @return LinearAddress.\r
 **/\r
 VOID *\r
 EFIAPI\r
@@ -7068,7 +8930,7 @@ AsmGetThunk16Properties (
 VOID\r
 EFIAPI\r
 AsmPrepareThunk16 (\r
-  OUT     THUNK_CONTEXT             *ThunkContext\r
+  IN OUT  THUNK_CONTEXT             *ThunkContext\r
   );\r
 \r
 \r
@@ -7119,7 +8981,7 @@ AsmPrepareThunk16 (
   ThunkAttributes, then ASSERT().\r
 \r
   This interface is limited to be used in either physical mode or virtual modes with paging enabled where the\r
-  virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.\r
+  virtual to physical mappings for ThunkContext.RealModeBuffer are mapped 1:1.\r
 \r
   @param  ThunkContext  A pointer to the context structure that describes the\r
                         16-bit real mode code to call.\r
@@ -7158,7 +9020,109 @@ AsmPrepareAndThunk16 (
   IN OUT  THUNK_CONTEXT             *ThunkContext\r
   );\r
 \r
-#endif\r
-#endif\r
+/**\r
+  Generates a 16-bit random number through RDRAND instruction.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+ **/\r
+BOOLEAN\r
+EFIAPI\r
+AsmRdRand16 (\r
+  OUT     UINT16                    *Rand\r
+  );\r
+\r
+/**\r
+  Generates a 32-bit random number through RDRAND instruction.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+AsmRdRand32 (\r
+  OUT     UINT32                    *Rand\r
+  );\r
+\r
+/**\r
+  Generates a 64-bit random number through RDRAND instruction.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
+\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+AsmRdRand64  (\r
+  OUT     UINT64                    *Rand\r
+  );\r
+\r
+/**\r
+  Load given selector into TR register.\r
+\r
+  @param[in] Selector     Task segment selector\r
+**/\r
+VOID\r
+EFIAPI\r
+AsmWriteTr (\r
+  IN UINT16 Selector\r
+  );\r
+\r
+/**\r
+  Patch the immediate operand of an IA32 or X64 instruction such that the byte,\r
+  word, dword or qword operand is encoded at the end of the instruction's\r
+  binary representation.\r
+\r
+  This function should be used to update object code that was compiled with\r
+  NASM from assembly source code. Example:\r
+\r
+  NASM source code:\r
+\r
+        mov     eax, strict dword 0 ; the imm32 zero operand will be patched\r
+    ASM_PFX(gPatchCr3):\r
+        mov     cr3, eax\r
 \r
+  C source code:\r
+\r
+    X86_ASSEMBLY_PATCH_LABEL gPatchCr3;\r
+    PatchInstructionX86 (gPatchCr3, AsmReadCr3 (), 4);\r
+\r
+  @param[out] InstructionEnd  Pointer right past the instruction to patch. The\r
+                              immediate operand to patch is expected to\r
+                              comprise the trailing bytes of the instruction.\r
+                              If InstructionEnd is closer to address 0 than\r
+                              ValueSize permits, then ASSERT().\r
+\r
+  @param[in] PatchValue       The constant to write to the immediate operand.\r
+                              The caller is responsible for ensuring that\r
+                              PatchValue can be represented in the byte, word,\r
+                              dword or qword operand (as indicated through\r
+                              ValueSize); otherwise ASSERT().\r
+\r
+  @param[in] ValueSize        The size of the operand in bytes; must be 1, 2,\r
+                              4, or 8. ASSERT() otherwise.\r
+**/\r
+VOID\r
+EFIAPI\r
+PatchInstructionX86 (\r
+  OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd,\r
+  IN  UINT64                   PatchValue,\r
+  IN  UINTN                    ValueSize\r
+  );\r
 \r
+#endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
+#endif // !defined (__BASE_LIB__)\r