]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Library/BaseLib.h
Remove checking for overflow in several Multiple functions in BaseLib, for it is...
[mirror_edk2.git] / MdePkg / Include / Library / BaseLib.h
index 83bdc3a168f10f3e8bd9591db5d411eb53c1fdc9..2ea6b6194ee6fa149a0c981e419c597def467a13 100644 (file)
@@ -1,34 +1,33 @@
 /** @file\r
-  Memory-only library functions with no library constructor/destructor\r
+  Provides string functions, linked list functions, math functions, synchronization\r
+  functions, and CPU architecture specific functions.\r
 \r
-  Copyright (c) 2006 - 2007, Intel Corporation\r
-  All rights reserved. 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
+Copyright (c) 2006 - 2008, Intel Corporation\r
+All rights reserved. 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
 \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
+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
 \r
 **/\r
 \r
 #ifndef __BASE_LIB__\r
 #define __BASE_LIB__\r
 \r
-//\r
-// Definitions for architecture specific types\r
-// These include SPIN_LOCK and BASE_LIBRARY_JUMP_BUFFER\r
-//\r
-\r
-//\r
-// SPIN_LOCK\r
-//\r
+///\r
+/// Definitions for SPIN_LOCK\r
+///\r
 typedef volatile UINTN              SPIN_LOCK;\r
 \r
-#if   defined (MDE_CPU_IA32)\r
 //\r
-// IA32 context buffer used by SetJump() and LongJump()\r
+// Definitions for architecture specific types\r
 //\r
+#if   defined (MDE_CPU_IA32)\r
+///\r
+/// IA32 context buffer used by SetJump() and LongJump()\r
+///\r
 typedef struct {\r
   UINT32                            Ebx;\r
   UINT32                            Esi;\r
@@ -42,9 +41,9 @@ typedef struct {
 \r
 #elif defined (MDE_CPU_IPF)\r
 \r
-//\r
-// IPF context buffer used by SetJump() and LongJump()\r
-//\r
+///\r
+/// IPF context buffer used by SetJump() and LongJump()\r
+///\r
 typedef struct {\r
   UINT64                            F2[2];\r
   UINT64                            F3[2];\r
@@ -89,9 +88,9 @@ typedef struct {
 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 0x10\r
 \r
 #elif defined (MDE_CPU_X64)\r
-//\r
-// X64 context buffer used by SetJump() and LongJump()\r
-//\r
+///\r
+/// X64 context buffer used by SetJump() and LongJump()\r
+///\r
 typedef struct {\r
   UINT64                            Rbx;\r
   UINT64                            Rsp;\r
@@ -108,9 +107,9 @@ typedef struct {
 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8\r
 \r
 #elif defined (MDE_CPU_EBC)\r
-//\r
-// EBC context buffer used by SetJump() and LongJump()\r
-//\r
+///\r
+/// EBC context buffer used by SetJump() and LongJump()\r
+///\r
 typedef struct {\r
   UINT64                            R0;\r
   UINT64                            R1;\r
@@ -149,7 +148,7 @@ typedef struct {
   @param  Destination Pointer to a Null-terminated Unicode string.\r
   @param  Source      Pointer to a Null-terminated Unicode string.\r
 \r
-  @return Destiantion\r
+  @return Destination.\r
 \r
 **/\r
 CHAR16 *\r
@@ -161,9 +160,8 @@ StrCpy (
 \r
 \r
 /**\r
-  Copies one Null-terminated Unicode string with a maximum length to another\r
-  Null-terminated Unicode string with a maximum length and returns the new\r
-  Unicode string.\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
   string Destination, and returns Destination. At most, Length Unicode\r
@@ -186,7 +184,7 @@ StrCpy (
   @param  Source      Pointer to a Null-terminated Unicode string.\r
   @param  Length      Maximum number of Unicode characters to copy.\r
 \r
-  @return Destination\r
+  @return Destination.\r
 \r
 **/\r
 CHAR16 *\r
@@ -226,8 +224,8 @@ StrLen (
   Returns the size of a Null-terminated Unicode string in bytes, including the\r
   Null terminator.\r
 \r
-  This function returns the size, in bytes, of the Null-terminated Unicode\r
-  string specified by String.\r
+  This function returns the size, in bytes, of the Null-terminated Unicode string \r
+  specified by String.\r
 \r
   If String is NULL, then ASSERT().\r
   If String is not aligned on a 16-bit boundary, then ASSERT().\r
@@ -271,8 +269,8 @@ StrSize (
   @param  FirstString   Pointer to a Null-terminated Unicode string.\r
   @param  SecondString  Pointer to a Null-terminated Unicode string.\r
 \r
-  @retval 0   FirstString is identical to SecondString.\r
-  @retval !=0 FirstString is not identical to SecondString.\r
+  @retval 0      FirstString is identical to SecondString.\r
+  @return others FirstString is not identical to SecondString.\r
 \r
 **/\r
 INTN\r
@@ -284,9 +282,9 @@ StrCmp (
 \r
 \r
 /**\r
-  Compares two Null-terminated Unicode strings with maximum lengths, and\r
-  returns the difference between the first mismatched Unicode characters.\r
-\r
+  Compares up to a specified length the contents of two Null-terminated Unicode strings,\r
+  and returns the difference between the first mismatched Unicode characters.\r
+  \r
   This function compares the Null-terminated Unicode string FirstString to the\r
   Null-terminated Unicode string SecondString. At most, Length Unicode\r
   characters will be compared. If Length is 0, then 0 is returned. If\r
@@ -309,8 +307,8 @@ StrCmp (
   @param  SecondString  Pointer to a Null-terminated Unicode string.\r
   @param  Length        Maximum number of Unicode characters to compare.\r
 \r
-  @retval 0   FirstString is identical to SecondString.\r
-  @retval !=0 FirstString is not identical to SecondString.\r
+  @retval 0      FirstString is identical to SecondString.\r
+  @return others FirstString is not identical to SecondString.\r
 \r
 **/\r
 INTN\r
@@ -351,7 +349,7 @@ StrnCmp (
   @param  Destination Pointer to a Null-terminated Unicode string.\r
   @param  Source      Pointer to a Null-terminated Unicode string.\r
 \r
-  @return Destination\r
+  @return Destination.\r
 \r
 **/\r
 CHAR16 *\r
@@ -363,8 +361,8 @@ StrCat (
 \r
 \r
 /**\r
-  Concatenates one Null-terminated Unicode string with a maximum length to the\r
-  end of another Null-terminated Unicode string, and returns the concatenated\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
 \r
   This function concatenates two Null-terminated Unicode strings. The contents\r
@@ -396,7 +394,7 @@ StrCat (
   @param  Length      Maximum number of Unicode characters to concatenate from\r
                       Source.\r
 \r
-  @return Destination\r
+  @return Destination.\r
 \r
 **/\r
 CHAR16 *\r
@@ -408,7 +406,7 @@ StrnCat (
   );\r
 \r
 /**\r
-  Returns the first occurance of a Null-terminated Unicode sub-string\r
+  Returns the first occurrence of a Null-terminated Unicode sub-string\r
   in a Null-terminated Unicode string.\r
 \r
   This function scans the contents of the Null-terminated Unicode string\r
@@ -426,18 +424,18 @@ StrnCat (
   or String contains more than PcdMaximumUnicodeStringLength Unicode\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          Pointer to a Null-terminated Unicode string.\r
+  @param  SearchString    Pointer to a Null-terminated Unicode string to search for.\r
 \r
   @retval NULL            If the SearchString does not appear in String.\r
-  @retval !NULL           If there is a match.\r
+  @return others          If there is a match.\r
 \r
 **/\r
 CHAR16 *\r
 EFIAPI\r
 StrStr (\r
-  IN      CONST CHAR16               *String,\r
-  IN      CONST CHAR16               *SearchString\r
+  IN      CONST CHAR16              *String,\r
+  IN      CONST CHAR16              *SearchString\r
   );\r
 \r
 /**\r
@@ -469,7 +467,7 @@ StrStr (
   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      Pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -477,7 +475,7 @@ StrStr (
 UINTN\r
 EFIAPI\r
 StrDecimalToUintn (\r
-  IN      CONST CHAR16               *String\r
+  IN      CONST CHAR16              *String\r
   );\r
 \r
 /**\r
@@ -509,7 +507,7 @@ StrDecimalToUintn (
   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          Pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -517,7 +515,7 @@ StrDecimalToUintn (
 UINT64\r
 EFIAPI\r
 StrDecimalToUint64 (\r
-  IN      CONST CHAR16               *String\r
+  IN      CONST CHAR16              *String\r
   );\r
  \r
 \r
@@ -551,7 +549,7 @@ StrDecimalToUint64 (
   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          Pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -559,7 +557,7 @@ StrDecimalToUint64 (
 UINTN\r
 EFIAPI\r
 StrHexToUintn (\r
-  IN      CONST CHAR16               *String\r
+  IN      CONST CHAR16              *String\r
   );\r
 \r
 \r
@@ -593,7 +591,7 @@ StrHexToUintn (
   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          Pointer to a Null-terminated Unicode string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -601,7 +599,7 @@ StrHexToUintn (
 UINT64\r
 EFIAPI\r
 StrHexToUint64 (\r
-  IN      CONST CHAR16               *String\r
+  IN      CONST CHAR16             *String\r
   );\r
 \r
 /**\r
@@ -622,13 +620,12 @@ CHAR16
 EFIAPI\r
 NibbleToHexChar (\r
   IN UINT8      Nibble\r
-  )\r
-;\r
+  );\r
 \r
 /** \r
   Convert binary buffer to a Unicode String in a specified sequence. \r
 \r
-  This function converts bytes in the binary Buffer Buf to a Unicode String Str. \r
+  This function converts bytes in the memory block pointed by Buffer to a Unicode String Str. \r
   Each byte will be represented by two Unicode characters. For example, byte 0xA1 will \r
   be converted into two Unicode character L'A' and L'1'. In the output String, the Unicode Character \r
   for the Most Significant Nibble will be put before the Unicode Character for the Least Significant\r
@@ -637,7 +634,7 @@ NibbleToHexChar (
   the last character in the output string. The one next to first byte will be put into the\r
   character before the last character. This rules applies to the rest of the bytes. The Unicode\r
   character by the last byte will be put into the first character in the output string. For example,\r
-  the input buffer for a 64-bits unsigned integrer 0x12345678abcdef1234 will be converted to\r
+  the input buffer for a 64-bits unsigned integer 0x12345678abcdef1234 will be converted to\r
   a Unicode string equal to L"12345678abcdef1234".\r
 \r
   @param String                        On input, String is pointed to the buffer allocated for the convertion.\r
@@ -645,10 +642,10 @@ NibbleToHexChar (
                                        The StringLen required to convert a N bytes Buffer will be a least equal to or greater \r
                                        than 2*N + 1.\r
   @param Buffer                        The pointer to a input buffer.\r
-  @param BufferSizeInBytes             Lenth in bytes of the input buffer.\r
+  @param BufferSizeInBytes             Length in bytes of the input buffer.\r
   \r
 \r
-  @retval  EFI_SUCCESS                 The convertion is successfull. All bytes in Buffer has been convert to the corresponding\r
+  @retval  EFI_SUCCESS                 The convertion is successful. All bytes in Buffer has been convert to the corresponding\r
                                        Unicode character and placed into the right place in String.\r
   @retval  EFI_BUFFER_TOO_SMALL        StringSizeInBytes is smaller than 2 * N + 1the number of bytes required to\r
                                        complete the convertion. \r
@@ -660,8 +657,7 @@ BufToHexString (
   IN OUT       UINTN                *StringLen,\r
   IN     CONST UINT8                *Buffer,\r
   IN           UINTN                BufferSizeInBytes\r
-  )\r
-;\r
+  );\r
 \r
 \r
 /**\r
@@ -705,8 +701,7 @@ HexStringToBuf (
   IN OUT       UINTN                    *BufferSizeInBytes,\r
   IN     CONST CHAR16                   *String,\r
   OUT          UINTN                    *ConvertedStrLen  OPTIONAL\r
-  )\r
-;\r
+  );\r
 \r
 \r
 /**\r
@@ -719,6 +714,10 @@ HexStringToBuf (
 \r
   If Digit is NULL, then ASSERT.\r
 \r
+  @param  Digit       The output hexadecimal digit.\r
+\r
+  @param  Char        The input Unicode character.\r
+\r
   @retval TRUE        Char is in the range of Hexadecimal number. Digit is updated\r
                       to the byte value of the number.\r
   @retval FALSE       Char is not in the range of Hexadecimal number. Digit is keep\r
@@ -730,11 +729,10 @@ EFIAPI
 IsHexDigit (\r
   OUT UINT8      *Digit,\r
   IN  CHAR16      Char\r
-  )\r
-;\r
+  );\r
 \r
 /**\r
-  Convert one Null-terminated Unicode string to a Null-terminated\r
+  Convert a Null-terminated Unicode string to a Null-terminated\r
   ASCII string and returns the ASCII string.\r
 \r
   This function converts the content of the Unicode string Source\r
@@ -760,14 +758,14 @@ IsHexDigit (
   @param  Source        Pointer to a Null-terminated Unicode string.\r
   @param  Destination   Pointer to a Null-terminated ASCII string.\r
 \r
-  @return Destination\r
+  @return Destination.\r
 \r
 **/\r
 CHAR8 *\r
 EFIAPI\r
 UnicodeStrToAsciiStr (\r
-  IN      CONST CHAR16               *Source,\r
-  OUT    CHAR8                           *Destination\r
+  IN      CONST CHAR16              *Source,\r
+  OUT     CHAR8                     *Destination\r
   );\r
 \r
 \r
@@ -801,9 +799,8 @@ AsciiStrCpy (
 \r
 \r
 /**\r
-  Copies one Null-terminated ASCII string with a maximum length to another\r
-  Null-terminated ASCII string with a maximum length and returns the new ASCII\r
-  string.\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
   This function copies the contents of the ASCII string Source to the ASCII\r
   string Destination, and returns Destination. At most, Length ASCII characters\r
@@ -905,8 +902,8 @@ AsciiStrSize (
   @param  FirstString   Pointer to a Null-terminated ASCII string.\r
   @param  SecondString  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
+  @retval ==0      FirstString is identical to SecondString.\r
+  @retval !=0      FirstString is not identical to SecondString.\r
 \r
 **/\r
 INTN\r
@@ -940,10 +937,10 @@ AsciiStrCmp (
   @param  FirstString   Pointer to a Null-terminated ASCII string.\r
   @param  SecondString  Pointer to a Null-terminated ASCII string.\r
 \r
-  @retval 0   FirstString is identical to SecondString using case insensitive\r
-              comparisons.\r
-  @retval !=0 FirstString is not identical to SecondString using case\r
-              insensitive comparisons.\r
+  @retval ==0    FirstString is identical to SecondString using case insensitive\r
+                 comparisons.\r
+  @retval !=0    FirstString is not identical to SecondString using case\r
+                 insensitive comparisons.\r
 \r
 **/\r
 INTN\r
@@ -978,8 +975,8 @@ AsciiStriCmp (
   @param  SecondString  Pointer to a Null-terminated ASCII string.\r
   @param  Length        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
+  @retval ==0       FirstString is identical to SecondString.\r
+  @retval !=0       FirstString is not identical to SecondString.\r
 \r
 **/\r
 INTN\r
@@ -1027,9 +1024,9 @@ AsciiStrCat (
 \r
 \r
 /**\r
-  Concatenates one Null-terminated ASCII string with a maximum length to the\r
-  end of another Null-terminated ASCII string, and returns the concatenated\r
-  ASCII string.\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
 \r
   This function concatenates two Null-terminated ASCII strings. The contents\r
   of Null-terminated ASCII string Source are concatenated to the end of Null-\r
@@ -1070,7 +1067,7 @@ AsciiStrnCat (
 \r
 \r
 /**\r
-  Returns the first occurance of a Null-terminated ASCII sub-string\r
+  Returns the first occurrence of a Null-terminated ASCII sub-string\r
   in a Null-terminated ASCII string.\r
 \r
   This function scans the contents of the ASCII string specified by String\r
@@ -1085,18 +1082,19 @@ 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          Pointer to a Null-terminated ASCII string.\r
+  @param  SearchString    Pointer to a Null-terminated ASCII string to search for.\r
 \r
   @retval NULL            If the SearchString does not appear in String.\r
-  @retval !NULL           If there is a match.\r
+  @retval others          If there is a match return the first occurrence of SearchingString.\r
+                          If the length of SearchString is zero,return String.\r
 \r
 **/\r
 CHAR8 *\r
 EFIAPI\r
 AsciiStrStr (\r
-  IN      CONST CHAR8                  *String,\r
-  IN      CONST CHAR8                  *SearchString\r
+  IN      CONST CHAR8               *String,\r
+  IN      CONST CHAR8               *SearchString\r
   );\r
 \r
 \r
@@ -1125,7 +1123,7 @@ AsciiStrStr (
   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          Pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1162,7 +1160,7 @@ AsciiStrDecimalToUintn (
   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          Pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1170,7 +1168,7 @@ AsciiStrDecimalToUintn (
 UINT64\r
 EFIAPI\r
 AsciiStrDecimalToUint64 (\r
-  IN      CONST CHAR8                *String\r
+  IN      CONST CHAR8               *String\r
   );\r
 \r
 \r
@@ -1203,7 +1201,7 @@ AsciiStrDecimalToUint64 (
   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          Pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1211,7 +1209,7 @@ AsciiStrDecimalToUint64 (
 UINTN\r
 EFIAPI\r
 AsciiStrHexToUintn (\r
-  IN      CONST CHAR8                *String\r
+  IN      CONST CHAR8               *String\r
   );\r
 \r
 \r
@@ -1244,7 +1242,7 @@ AsciiStrHexToUintn (
   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          Pointer to a Null-terminated ASCII string.\r
 \r
   @retval Value translated from String.\r
 \r
@@ -1252,7 +1250,7 @@ AsciiStrHexToUintn (
 UINT64\r
 EFIAPI\r
 AsciiStrHexToUint64 (\r
-  IN      CONST CHAR8                  *String\r
+  IN      CONST CHAR8                *String\r
   );\r
 \r
 \r
@@ -1280,14 +1278,14 @@ AsciiStrHexToUint64 (
   @param  Source        Pointer to a Null-terminated ASCII string.\r
   @param  Destination   Pointer to a Null-terminated Unicode string.\r
 \r
-  @return Destination\r
+  @return Destination.\r
 \r
 **/\r
 CHAR16 *\r
 EFIAPI\r
 AsciiStrToUnicodeStr (\r
-  IN      CONST CHAR8                *Source,\r
-  OUT    CHAR16                        *Destination\r
+  IN      CONST CHAR8               *Source,\r
+  OUT     CHAR16                    *Destination\r
   );\r
 \r
 \r
@@ -1301,7 +1299,7 @@ AsciiStrToUnicodeStr (
 \r
   @param  Value The 8-bit value to convert to BCD. Range 0..99.\r
 \r
-  @return The BCD value\r
+  @return The BCD value.\r
 \r
 **/\r
 UINT8\r
@@ -1350,7 +1348,7 @@ BcdToDecimal8 (
   @param  ListHead  The head note of a list to initiailize.\r
 \r
 **/\r
-#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)  {&ListHead, &ListHead}\r
+#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)  {&(ListHead), &(ListHead)}\r
 \r
 \r
 /**\r
@@ -1372,7 +1370,7 @@ BcdToDecimal8 (
 LIST_ENTRY *\r
 EFIAPI\r
 InitializeListHead (\r
-  IN      LIST_ENTRY                *ListHead\r
+  IN OUT  LIST_ENTRY                *ListHead\r
   );\r
 \r
 \r
@@ -1385,7 +1383,8 @@ InitializeListHead (
 \r
   If ListHead is NULL, then ASSERT().\r
   If Entry is NULL, then ASSERT().\r
-  If ListHead was not initialized with InitializeListHead(), 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
   of nodes in ListHead, including the ListHead node, is greater than or\r
   equal to PcdMaximumLinkedListLength, then ASSERT().\r
@@ -1400,8 +1399,8 @@ InitializeListHead (
 LIST_ENTRY *\r
 EFIAPI\r
 InsertHeadList (\r
-  IN      LIST_ENTRY                *ListHead,\r
-  IN      LIST_ENTRY                *Entry\r
+  IN OUT  LIST_ENTRY                *ListHead,\r
+  IN OUT  LIST_ENTRY                *Entry\r
   );\r
 \r
 \r
@@ -1414,7 +1413,8 @@ InsertHeadList (
 \r
   If ListHead is NULL, then ASSERT().\r
   If Entry is NULL, then ASSERT().\r
-  If ListHead was not initialized with InitializeListHead(), 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
   of nodes in ListHead, including the ListHead node, is greater than or\r
   equal to PcdMaximumLinkedListLength, then ASSERT().\r
@@ -1429,20 +1429,21 @@ InsertHeadList (
 LIST_ENTRY *\r
 EFIAPI\r
 InsertTailList (\r
-  IN      LIST_ENTRY                *ListHead,\r
-  IN      LIST_ENTRY                *Entry\r
+  IN OUT  LIST_ENTRY                *ListHead,\r
+  IN OUT  LIST_ENTRY                *Entry\r
   );\r
 \r
 \r
 /**\r
   Retrieves the first node of a doubly linked list.\r
 \r
-  Returns the first node of a doubly linked list. List must have been\r
-  initialized with InitializeListHead(). If List is empty, then NULL is\r
-  returned.\r
+  Returns the first node of a doubly linked list.  List must have been \r
+  initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
+  If List is empty, then List is returned.\r
 \r
   If List is NULL, then ASSERT().\r
-  If List was not initialized with InitializeListHead(), 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
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
@@ -1463,13 +1464,14 @@ GetFirstNode (
 /**\r
   Retrieves the next node of a doubly linked list.\r
 \r
-  Returns the node of a doubly linked list that follows Node. List must have\r
-  been initialized with InitializeListHead(). If List is empty, then List is\r
-  returned.\r
+  Returns the node of a doubly linked list that follows 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 InitializeListHead(), 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 Node is not a node in List, then ASSERT().\r
@@ -1496,7 +1498,8 @@ GetNextNode (
   zero nodes, this function returns TRUE. Otherwise, it returns FALSE.\r
 \r
   If ListHead is NULL, then ASSERT().\r
-  If ListHead was not initialized with InitializeListHead(), 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
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
@@ -1515,15 +1518,18 @@ IsListEmpty (
 \r
 \r
 /**\r
-  Determines if a node in a doubly linked list is null.\r
+  Determines if a node in a doubly linked list is the head node of a the same\r
+  doubly linked list.  This function is typically used to terminate a loop that\r
+  traverses all the nodes in a doubly linked list starting with the head node.\r
 \r
-  Returns FALSE if Node is one of the nodes in the doubly linked list specified\r
-  by List. Otherwise, TRUE is returned. List must have been initialized with\r
-  InitializeListHead().\r
+  Returns TRUE if Node is equal to List.  Returns FALSE if Node is one of the\r
+  nodes in the doubly linked list specified by List.  List must have been\r
+  initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
 \r
   If List is NULL, then ASSERT().\r
   If Node is NULL, then ASSERT().\r
-  If List was not initialized with InitializeListHead(), 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
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
@@ -1549,11 +1555,12 @@ IsNull (
 \r
   Returns TRUE if Node is the last node in the doubly linked list specified by\r
   List. Otherwise, FALSE is returned. List must have been initialized with\r
-  InitializeListHead().\r
+  INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
 \r
   If List is NULL, then ASSERT().\r
   If Node is NULL, then ASSERT().\r
-  If List was not initialized with InitializeListHead(), 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
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
@@ -1582,8 +1589,8 @@ IsNodeAtEnd (
   Otherwise, the location of the FirstEntry node is swapped with the location\r
   of the SecondEntry node in a doubly linked list. SecondEntry must be in the\r
   same double linked list as FirstEntry and that double linked list must have\r
-  been initialized with InitializeListHead(). SecondEntry is returned after the\r
-  nodes are swapped.\r
+  been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(). \r
+  SecondEntry is returned after the nodes are swapped.\r
 \r
   If FirstEntry is NULL, then ASSERT().\r
   If SecondEntry is NULL, then ASSERT().\r
@@ -1596,14 +1603,14 @@ IsNodeAtEnd (
   @param  FirstEntry  A pointer to a node in a linked list.\r
   @param  SecondEntry A pointer to another node in the same linked list.\r
   \r
-  @return SecondEntry\r
+  @return SecondEntry.\r
 \r
 **/\r
 LIST_ENTRY *\r
 EFIAPI\r
 SwapListEntries (\r
-  IN      LIST_ENTRY                *FirstEntry,\r
-  IN      LIST_ENTRY                *SecondEntry\r
+  IN OUT  LIST_ENTRY                *FirstEntry,\r
+  IN OUT  LIST_ENTRY                *SecondEntry\r
   );\r
 \r
 \r
@@ -1623,9 +1630,9 @@ SwapListEntries (
   linked list containing Entry, including the Entry node, is greater than\r
   or equal to PcdMaximumLinkedListLength, then ASSERT().\r
 \r
-  @param  Entry A pointer to a node in a linked list\r
+  @param  Entry A pointer to a node in a linked list.\r
 \r
-  @return Entry\r
+  @return Entry.\r
 \r
 **/\r
 LIST_ENTRY *\r
@@ -1650,7 +1657,7 @@ RemoveEntryList (
   @param  Operand The 64-bit operand to shift left.\r
   @param  Count   The number of bits to shift left.\r
 \r
-  @return Operand << Count\r
+  @return Operand << Count.\r
 \r
 **/\r
 UINT64\r
@@ -1720,7 +1727,7 @@ ARShiftU64 (
   @param  Operand The 32-bit operand to rotate left.\r
   @param  Count   The number of bits to rotate left.\r
 \r
-  @return Operand <<< Count\r
+  @return Operand << Count\r
 \r
 **/\r
 UINT32\r
@@ -1768,7 +1775,7 @@ RRotU32 (
   @param  Operand The 64-bit operand to rotate left.\r
   @param  Count   The number of bits to rotate left.\r
 \r
-  @return Operand <<< Count\r
+  @return Operand << Count\r
 \r
 **/\r
 UINT64\r
@@ -1792,7 +1799,7 @@ LRotU64 (
   @param  Operand The 64-bit operand to rotate right.\r
   @param  Count   The number of bits to rotate right.\r
 \r
-  @return Operand >>> Count\r
+  @return Operand >> Count\r
 \r
 **/\r
 UINT64\r
@@ -1812,8 +1819,8 @@ RRotU64 (
 \r
   @param  Operand The 32-bit operand to evaluate.\r
 \r
-  @return Position of the lowest bit set in Operand if found.\r
-  @retval -1 Operand is zero.\r
+  @retval 0..31  The lowest bit set in Operand was found.\r
+  @retval -1    Operand is zero.\r
 \r
 **/\r
 INTN\r
@@ -1832,8 +1839,9 @@ LowBitSet32 (
 \r
   @param  Operand The 64-bit operand to evaluate.\r
 \r
-  @return Position of the lowest bit set in Operand if found.\r
-  @retval -1  Operand is zero.\r
+  @retval 0..63  The lowest bit set in Operand was found.\r
+  @retval -1    Operand is zero.\r
+\r
 \r
 **/\r
 INTN\r
@@ -1853,8 +1861,8 @@ LowBitSet64 (
 \r
   @param  Operand The 32-bit operand to evaluate.\r
 \r
-  @return Position of the highest bit set in Operand if found.\r
-  @retval -1  Operand is zero.\r
+  @retval 0..31  Position of the highest bit set in Operand if found.\r
+  @retval -1    Operand is zero.\r
 \r
 **/\r
 INTN\r
@@ -1874,8 +1882,8 @@ HighBitSet32 (
 \r
   @param  Operand The 64-bit operand to evaluate.\r
 \r
-  @return Position of the highest bit set in Operand if found.\r
-  @retval -1  Operand is zero.\r
+  @retval 0..63   Position of the highest bit set in Operand if found.\r
+  @retval -1     Operand is zero.\r
 \r
 **/\r
 INTN\r
@@ -1887,7 +1895,7 @@ HighBitSet64 (
 \r
 /**\r
   Returns the value of the highest bit set in a 32-bit value. Equivalent to\r
-  1 << HighBitSet32(x).\r
+  1 << log2(x).\r
 \r
   This function computes the value of the highest bit set in the 32-bit value\r
   specified by Operand. If Operand is zero, then zero is returned.\r
@@ -1907,7 +1915,7 @@ GetPowerOfTwo32 (
 \r
 /**\r
   Returns the value of the highest bit set in a 64-bit value. Equivalent to\r
-  1 << HighBitSet64(x).\r
+  1 << log2(x).\r
 \r
   This function computes the value of the highest bit set in the 64-bit value\r
   specified by Operand. If Operand is zero, then zero is returned.\r
@@ -1934,7 +1942,7 @@ GetPowerOfTwo64 (
 \r
   @param  Value Operand A 16-bit unsigned value.\r
 \r
-  @return The byte swaped Operand.\r
+  @return The byte swapped Operand.\r
 \r
 **/\r
 UINT16\r
@@ -1953,7 +1961,7 @@ SwapBytes16 (
 \r
   @param  Value Operand A 32-bit unsigned value.\r
 \r
-  @return The byte swaped Operand.\r
+  @return The byte swapped Operand.\r
 \r
 **/\r
 UINT32\r
@@ -1972,7 +1980,7 @@ SwapBytes32 (
 \r
   @param  Value Operand A 64-bit unsigned value.\r
 \r
-  @return The byte swaped Operand.\r
+  @return The byte swapped Operand.\r
 \r
 **/\r
 UINT64\r
@@ -1990,8 +1998,6 @@ SwapBytes64 (
   unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r
   bit unsigned result is returned.\r
 \r
-  If the result overflows, then ASSERT().\r
-\r
   @param  Multiplicand  A 64-bit unsigned value.\r
   @param  Multiplier    A 32-bit unsigned value.\r
 \r
@@ -2038,8 +2044,6 @@ MultU64x64 (
   signed value Multiplier and generates a 64-bit signed result. This 64-bit\r
   signed result is returned.\r
 \r
-  If the result overflows, then ASSERT().\r
-\r
   @param  Multiplicand  A 64-bit signed value.\r
   @param  Multiplier    A 64-bit signed value.\r
 \r
@@ -2167,6 +2171,10 @@ DivU64x64Remainder (
   NULL, then the 64-bit signed remainder is returned in Remainder. This\r
   function returns the 64-bit signed quotient.\r
 \r
+  It is the caller's responsibility to not call this function with a Divisor of 0.\r
+  If Divisor is 0, then the quotient and remainder should be assumed to be \r
+  the largest negative integer.\r
+\r
   If Divisor is 0, then ASSERT().\r
 \r
   @param  Dividend  A 64-bit signed value.\r
@@ -2194,15 +2202,15 @@ DivS64x64Remainder (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Uint16  Pointer to a 16-bit value that may be unaligned.\r
+  @param  Buffer  Pointer to a 16-bit value that may be unaligned.\r
 \r
-  @return *Uint16\r
+  @return The 16-bit value read from Buffer.\r
 \r
 **/\r
 UINT16\r
 EFIAPI\r
 ReadUnaligned16 (\r
-  IN      CONST UINT16              *Uint16\r
+  IN CONST UINT16              *Buffer\r
   );\r
 \r
 \r
@@ -2215,17 +2223,17 @@ ReadUnaligned16 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Uint16  Pointer to a 16-bit value that may be unaligned.\r
+  @param  Buffer  Pointer to a 16-bit value that may be unaligned.\r
   @param  Value   16-bit value to write to Buffer.\r
 \r
-  @return Value\r
+  @return The 16-bit value to write to Buffer.\r
 \r
 **/\r
 UINT16\r
 EFIAPI\r
 WriteUnaligned16 (\r
-  OUT     UINT16                    *Uint16,\r
-  IN      UINT16                    Value\r
+  OUT UINT16                    *Buffer,\r
+  IN  UINT16                    Value\r
   );\r
 \r
 \r
@@ -2239,13 +2247,13 @@ WriteUnaligned16 (
 \r
   @param  Buffer  Pointer to a 24-bit value that may be unaligned.\r
 \r
-  @return The value read from Buffer.\r
+  @return The 24-bit value read from Buffer.\r
 \r
 **/\r
 UINT32\r
 EFIAPI\r
 ReadUnaligned24 (\r
-  IN      CONST UINT32              *Buffer\r
+  IN CONST UINT32              *Buffer\r
   );\r
 \r
 \r
@@ -2261,14 +2269,14 @@ ReadUnaligned24 (
   @param  Buffer  Pointer to a 24-bit value that may be unaligned.\r
   @param  Value   24-bit value to write to Buffer.\r
 \r
-  @return The value written to Buffer.\r
+  @return The 24-bit value to write to Buffer.\r
 \r
 **/\r
 UINT32\r
 EFIAPI\r
 WriteUnaligned24 (\r
-  OUT     UINT32                    *Buffer,\r
-  IN      UINT32                    Value\r
+  OUT UINT32                    *Buffer,\r
+  IN  UINT32                    Value\r
   );\r
 \r
 \r
@@ -2280,15 +2288,15 @@ WriteUnaligned24 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Uint32  Pointer to a 32-bit value that may be unaligned.\r
+  @param  Buffer  Pointer to a 32-bit value that may be unaligned.\r
 \r
-  @return Value read from Uint32\r
+  @return The 32-bit value read from Buffer.\r
 \r
 **/\r
 UINT32\r
 EFIAPI\r
 ReadUnaligned32 (\r
-  IN      CONST UINT32              *Uint32\r
+  IN CONST UINT32              *Buffer\r
   );\r
 \r
 \r
@@ -2301,17 +2309,17 @@ ReadUnaligned32 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Uint32  Pointer to a 32-bit value that may be unaligned.\r
+  @param  Buffer  Pointer to a 32-bit value that may be unaligned.\r
   @param  Value   32-bit value to write to Buffer.\r
 \r
-  @return Value written to Uint32.\r
+  @return The 32-bit value to write to Buffer.\r
 \r
 **/\r
 UINT32\r
 EFIAPI\r
 WriteUnaligned32 (\r
-  OUT     UINT32                    *Uint32,\r
-  IN      UINT32                    Value\r
+  OUT UINT32                    *Buffer,\r
+  IN  UINT32                    Value\r
   );\r
 \r
 \r
@@ -2323,15 +2331,15 @@ WriteUnaligned32 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Uint64  Pointer to a 64-bit value that may be unaligned.\r
+  @param  Buffer  Pointer to a 64-bit value that may be unaligned.\r
 \r
-  @return Value read from Uint64.\r
+  @return The 64-bit value read from Buffer.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 ReadUnaligned64 (\r
-  IN      CONST UINT64              *Uint64\r
+  IN CONST UINT64              *Buffer\r
   );\r
 \r
 \r
@@ -2344,17 +2352,17 @@ ReadUnaligned64 (
 \r
   If the Buffer is NULL, then ASSERT().\r
 \r
-  @param  Uint64  Pointer to a 64-bit value that may be unaligned.\r
+  @param  Buffer  Pointer to a 64-bit value that may be unaligned.\r
   @param  Value   64-bit value to write to Buffer.\r
 \r
-  @return Value written to Uint64.\r
+  @return The 64-bit value to write to Buffer.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 WriteUnaligned64 (\r
-  OUT     UINT64                    *Uint64,\r
-  IN      UINT64                    Value\r
+  OUT UINT64                    *Buffer,\r
+  IN  UINT64                    Value\r
   );\r
 \r
 \r
@@ -3056,7 +3064,7 @@ GetSpinLockProperties (
 SPIN_LOCK *\r
 EFIAPI\r
 InitializeSpinLock (\r
-  IN      SPIN_LOCK                 *SpinLock\r
+  OUT      SPIN_LOCK                 *SpinLock\r
   );\r
 \r
 \r
@@ -3077,13 +3085,13 @@ InitializeSpinLock (
 \r
   @param  SpinLock  A pointer to the spin lock to place in the acquired state.\r
 \r
-  @return SpinLock accquired lock.\r
+  @return SpinLock acquired lock.\r
 \r
 **/\r
 SPIN_LOCK *\r
 EFIAPI\r
 AcquireSpinLock (\r
-  IN      SPIN_LOCK                 *SpinLock\r
+  IN OUT  SPIN_LOCK                 *SpinLock\r
   );\r
 \r
 \r
@@ -3107,7 +3115,7 @@ AcquireSpinLock (
 BOOLEAN\r
 EFIAPI\r
 AcquireSpinLockOrFail (\r
-  IN      SPIN_LOCK                 *SpinLock\r
+  IN OUT  SPIN_LOCK                 *SpinLock\r
   );\r
 \r
 \r
@@ -3128,7 +3136,7 @@ AcquireSpinLockOrFail (
 SPIN_LOCK *\r
 EFIAPI\r
 ReleaseSpinLock (\r
-  IN      SPIN_LOCK                 *SpinLock\r
+  IN OUT  SPIN_LOCK                 *SpinLock\r
   );\r
 \r
 \r
@@ -3263,7 +3271,7 @@ InterlockedCompareExchangePointer (
 //\r
 \r
 /**\r
-  Calculate the sum of all elements in a buffer in unit of UINT8.\r
+  Returns the sum of all elements in a buffer in unit of UINT8.\r
   During calculation, the carry bits are dropped.\r
 \r
   This function calculates the sum of all elements in a buffer\r
@@ -3274,8 +3282,8 @@ InterlockedCompareExchangePointer (
   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  Length           The size, in bytes, of Buffer .\r
+  @param  Buffer      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
 \r
@@ -3283,8 +3291,8 @@ InterlockedCompareExchangePointer (
 UINT8\r
 EFIAPI\r
 CalculateSum8 (\r
-  IN      CONST UINT8                  *Buffer,\r
-  IN      UINTN                                      Length\r
+  IN      CONST UINT8              *Buffer,\r
+  IN      UINTN                     Length\r
   );\r
 \r
 \r
@@ -3300,18 +3308,17 @@ 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  Length      The size, in bytes, of Buffer.\r
 \r
-  @param  Buffer                       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 2's complement checksum of Buffer.\r
 \r
 **/\r
 UINT8\r
 EFIAPI\r
 CalculateCheckSum8 (\r
-  IN      CONST UINT8                  *Buffer,\r
-  IN      UINTN                                      Length\r
+  IN      CONST UINT8              *Buffer,\r
+  IN      UINTN                     Length\r
   );\r
 \r
 \r
@@ -3328,8 +3335,8 @@ 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  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      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
 \r
@@ -3337,8 +3344,8 @@ CalculateCheckSum8 (
 UINT16\r
 EFIAPI\r
 CalculateSum16 (\r
-  IN      CONST UINT16                 *Buffer,\r
-  IN      UINTN                                      Length\r
+  IN      CONST UINT16             *Buffer,\r
+  IN      UINTN                     Length\r
   );\r
 \r
 \r
@@ -3356,35 +3363,35 @@ 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  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      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 2's complement checksum of Buffer.\r
 \r
 **/\r
 UINT16\r
 EFIAPI\r
 CalculateCheckSum16 (\r
-  IN      CONST UINT16                 *Buffer,\r
-  IN      UINTN                                      Length\r
+  IN      CONST UINT16             *Buffer,\r
+  IN      UINTN                     Length\r
   );\r
 \r
 \r
 /**\r
-  Returns the sum of all elements in a buffer of 32-bit values.  During\r
+  Returns the sum of all elements in a buffer of 32-bit values. During\r
   calculation, the carry bits are dropped.\r
 \r
   This function calculates the sum of the 32-bit values in the buffer\r
   specified by Buffer and Length. The carry bits in result of addition are dropped.\r
-  The 32-bit result is returned.  If Length is 0, then 0 is returned.\r
+  The 32-bit result is returned. If Length is 0, then 0 is returned.\r
 \r
   If Buffer is NULL, then ASSERT().\r
   If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
   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  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      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
 \r
@@ -3392,8 +3399,8 @@ CalculateCheckSum16 (
 UINT32\r
 EFIAPI\r
 CalculateSum32 (\r
-  IN      CONST UINT32                 *Buffer,\r
-  IN      UINTN                                      Length\r
+  IN      CONST UINT32             *Buffer,\r
+  IN      UINTN                     Length\r
   );\r
 \r
 \r
@@ -3411,17 +3418,17 @@ 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  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      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 2's complement checksum of Buffer.\r
 \r
 **/\r
 UINT32\r
 EFIAPI\r
 CalculateCheckSum32 (\r
-  IN      CONST UINT32                 *Buffer,\r
-  IN      UINTN                                      Length\r
+  IN      CONST UINT32             *Buffer,\r
+  IN      UINTN                     Length\r
   );\r
 \r
 \r
@@ -3438,8 +3445,8 @@ 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  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      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
 \r
@@ -3447,8 +3454,8 @@ CalculateCheckSum32 (
 UINT64\r
 EFIAPI\r
 CalculateSum64 (\r
-  IN      CONST UINT64                 *Buffer,\r
-  IN      UINTN                                      Length\r
+  IN      CONST UINT64             *Buffer,\r
+  IN      UINTN                     Length\r
   );\r
 \r
 \r
@@ -3466,26 +3473,26 @@ 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  Length           The size, in bytes, of Buffer.\r
+  @param  Buffer      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 2's complement checksum of Buffer.\r
 \r
 **/\r
 UINT64\r
 EFIAPI\r
 CalculateCheckSum64 (\r
-  IN      CONST UINT64                 *Buffer,\r
-  IN      UINTN                                      Length\r
+  IN      CONST UINT64             *Buffer,\r
+  IN      UINTN                     Length\r
   );\r
 \r
 \r
-//\r
-// Base Library CPU Functions\r
-//\r
+///\r
+/// Base Library CPU Functions\r
+///\r
 typedef\r
 VOID\r
-(EFIAPI *SWITCH_STACK_ENTRY_POINT) (\r
+(EFIAPI *SWITCH_STACK_ENTRY_POINT)(\r
   IN      VOID                      *Context1,  OPTIONAL\r
   IN      VOID                      *Context2   OPTIONAL\r
   );\r
@@ -3515,6 +3522,11 @@ MemoryFence (
 \r
   If JumpBuffer is NULL, then ASSERT().\r
   For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r
+  \r
+  NOTE: The structure BASE_LIBRARY_JUMP_BUFFER is CPU architecture specific.\r
+  The same structure must never be used for more than one CPU architecture context.\r
+  For example, a BASE_LIBRARY_JUMP_BUFFER allocated by an IA-32 module must never be used from an x64 module. \r
+  SetJump()/LongJump() is not currently supported for the EBC processor type.   \r
 \r
   @param  JumpBuffer  A pointer to CPU context buffer.\r
 \r
@@ -3675,7 +3687,10 @@ CpuPause (
                       function.\r
   @param  NewStack    A pointer to the new stack to use for the EntryPoint\r
                       function.\r
-  @param  ...         Extended parameters.\r
+  @param  ...         This variable argument list is ignored for IA32, x64, and EBC.  \r
+                      For IPF, this variable argument list is expected to contain \r
+                      a single parameter of type VOID * that specifies the new backing \r
+                      store pointer.\r
 \r
 \r
 **/\r
@@ -3719,7 +3734,6 @@ CpuDeadLoop (
   VOID\r
   );\r
 \r
-\r
 #if defined (MDE_CPU_IPF)\r
 \r
 /**\r
@@ -3761,7 +3775,7 @@ IpfFlushCacheRange (
   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 IPF.\r
 \r
-  @param Address       The Address of cache line to be flushed.\r
+  @param Address    The Address of cache line to be flushed.\r
 \r
   @return The address of FC instruction executed.\r
 \r
@@ -3779,7 +3793,7 @@ AsmFc (
   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 IPF.\r
 \r
-  @param Address       The Address of cache line to be flushed.\r
+  @param Address    The Address of cache line to be flushed.\r
 \r
   @return The address of FC.I instruction executed.\r
 \r
@@ -3793,6 +3807,8 @@ AsmFci (
 \r
 /**\r
   Reads the current value of a Processor Identifier Register (CPUID).\r
+  \r
+  Reads and returns the current value of Processor Identifier Register specified by Index. \r
   The Index of largest implemented CPUID (One less than the number of implemented CPUID\r
   registers) is determined by CPUID [3] bits {7:0}.\r
   No parameter checking is performed on Index.  If the Index value is beyond the\r
@@ -3800,7 +3816,7 @@ AsmFci (
   must either guarantee that Index is valid, or the caller must set up fault handlers to\r
   catch the faults.  This function is only available on IPF.\r
 \r
-  @param Index         The 8-bit Processor Identifier Register index to read.\r
+  @param Index    The 8-bit Processor Identifier Register index to read.\r
 \r
   @return The current value of Processor Identifier Register specified by Index.\r
 \r
@@ -3828,11 +3844,13 @@ AsmReadPsr (
 \r
 /**\r
   Writes the current value of 64-bit Processor Status Register (PSR).\r
+\r
   No parameter checking is performed on Value.  All bits of Value corresponding to\r
-  reserved fields of PSR must be 0 or a Reserved Register/Field fault may occur.  The caller must either guarantee that Value is valid, or the caller must set up fault handlers to catch the faults.\r
-  This function is only available on IPF.\r
+  reserved fields of PSR must be 0 or a Reserved Register/Field fault may occur.\r
+  The caller must either guarantee that Value is valid, or the caller must set up\r
+  fault handlers to catch the faults. This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to PSR.\r
+  @param Value    The 64-bit value to write to PSR.\r
 \r
   @return The 64-bit value written to the PSR.\r
 \r
@@ -3960,7 +3978,7 @@ AsmReadKr7 (
   Write the current value of 64-bit Kernel Register #0 (KR0).\r
   This function is only available on IPF.\r
 \r
-  @param  Value        The 64-bit value to write to KR0.\r
+  @param  Value   The 64-bit value to write to KR0.\r
 \r
   @return The 64-bit value written to the KR0.\r
 \r
@@ -3976,7 +3994,7 @@ AsmWriteKr0 (
   Write the current value of 64-bit Kernel Register #1 (KR1).\r
   This function is only available on IPF.\r
 \r
-  @param  Value        The 64-bit value to write to KR1.\r
+  @param  Value   The 64-bit value to write to KR1.\r
 \r
   @return The 64-bit value written to the KR1.\r
 \r
@@ -3992,7 +4010,7 @@ AsmWriteKr1 (
   Write the current value of 64-bit Kernel Register #2 (KR2).\r
   This function is only available on IPF.\r
 \r
-  @param  Value        The 64-bit value to write to KR2.\r
+  @param  Value   The 64-bit value to write to KR2.\r
 \r
   @return The 64-bit value written to the KR2.\r
 \r
@@ -4008,7 +4026,7 @@ AsmWriteKr2 (
   Write the current value of 64-bit Kernel Register #3 (KR3).\r
   This function is only available on IPF.\r
 \r
-  @param  Value        The 64-bit value to write to KR3.\r
+  @param  Value   The 64-bit value to write to KR3.\r
 \r
   @return The 64-bit value written to the KR3.\r
 \r
@@ -4024,7 +4042,7 @@ AsmWriteKr3 (
   Write the current value of 64-bit Kernel Register #4 (KR4).\r
   This function is only available on IPF.\r
 \r
-  @param  Value        The 64-bit value to write to KR4.\r
+  @param  Value   The 64-bit value to write to KR4.\r
 \r
   @return The 64-bit value written to the KR4.\r
 \r
@@ -4040,7 +4058,7 @@ AsmWriteKr4 (
   Write the current value of 64-bit Kernel Register #5 (KR5).\r
   This function is only available on IPF.\r
 \r
-  @param  Value        The 64-bit value to write to KR5.\r
+  @param  Value   The 64-bit value to write to KR5.\r
 \r
   @return The 64-bit value written to the KR5.\r
 \r
@@ -4056,7 +4074,7 @@ AsmWriteKr5 (
   Write the current value of 64-bit Kernel Register #6 (KR6).\r
   This function is only available on IPF.\r
 \r
-  @param  Value        The 64-bit value to write to KR6.\r
+  @param  Value   The 64-bit value to write to KR6.\r
 \r
   @return The 64-bit value written to the KR6.\r
 \r
@@ -4072,7 +4090,7 @@ AsmWriteKr6 (
   Write the current value of 64-bit Kernel Register #7 (KR7).\r
   This function is only available on IPF.\r
 \r
-  @param  Value        The 64-bit value to write to KR7.\r
+  @param  Value   The 64-bit value to write to KR7.\r
 \r
   @return The 64-bit value written to the KR7.\r
 \r
@@ -4129,7 +4147,7 @@ AsmReadItm (
   Writes the current value of 64-bit Interval Timer Counter Register (ITC).\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to ITC.\r
+  @param Value    The 64-bit value to write to ITC.\r
 \r
   @return The 64-bit value written to the ITC.\r
 \r
@@ -4145,7 +4163,7 @@ AsmWriteItc (
   Writes the current value of 64-bit Interval Timer Match Register (ITM).\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to ITM.\r
+  @param Value    The 64-bit value to write to ITM.\r
 \r
   @return The 64-bit value written to the ITM.\r
 \r
@@ -4165,7 +4183,7 @@ AsmWriteItm (
   fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to ITV.\r
+  @param Value    The 64-bit value to write to ITV.\r
 \r
   @return The 64-bit value written to the ITV.\r
 \r
@@ -4226,7 +4244,7 @@ AsmReadPta (
   fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to DCR.\r
+  @param Value    The 64-bit value to write to DCR.\r
 \r
   @return The 64-bit value written to the DCR.\r
 \r
@@ -4244,7 +4262,7 @@ AsmWriteDcr (
   the low 15 bits of Value is ignored when written.\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to IVA.\r
+  @param Value    The 64-bit value to write to IVA.\r
 \r
   @return The 64-bit value written to the IVA.\r
 \r
@@ -4264,7 +4282,7 @@ AsmWriteIva (
   fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to PTA.\r
+  @param Value    The 64-bit value to write to PTA.\r
 \r
   @return The 64-bit value written to the PTA.\r
 **/\r
@@ -4437,7 +4455,7 @@ AsmReadLrr1 (
   fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to LID.\r
+  @param Value    The 64-bit value to write to LID.\r
 \r
   @return The 64-bit value written to the LID.\r
 \r
@@ -4457,7 +4475,7 @@ AsmWriteLid (
   fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to TPR.\r
+  @param Value    The 64-bit value to write to TPR.\r
 \r
   @return The 64-bit value written to the TPR.\r
 \r
@@ -4489,7 +4507,7 @@ AsmWriteEoi (
   fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to PMV.\r
+  @param Value    The 64-bit value to write to PMV.\r
 \r
   @return The 64-bit value written to the PMV.\r
 \r
@@ -4509,7 +4527,7 @@ AsmWritePmv (
   fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to CMCV.\r
+  @param Value    The 64-bit value to write to CMCV.\r
 \r
   @return The 64-bit value written to the CMCV.\r
 \r
@@ -4529,7 +4547,7 @@ AsmWriteCmcv (
   fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to LRR0.\r
+  @param Value    The 64-bit value to write to LRR0.\r
 \r
   @return The 64-bit value written to the LRR0.\r
 \r
@@ -4549,7 +4567,7 @@ AsmWriteLrr0 (
   set up fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Value         The 64-bit value to write to LRR1.\r
+  @param Value    The 64-bit value to write to LRR1.\r
 \r
   @return The 64-bit value written to the LRR1.\r
 \r
@@ -4574,7 +4592,7 @@ AsmWriteLrr1 (
   set up fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Index         The 8-bit Instruction Breakpoint Register index to read.\r
+  @param Index    The 8-bit Instruction Breakpoint Register index to read.\r
 \r
   @return The current value of Instruction Breakpoint Register specified by Index.\r
 \r
@@ -4599,7 +4617,7 @@ AsmReadIbr (
   fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Index         The 8-bit Data Breakpoint Register index to read.\r
+  @param Index    The 8-bit Data Breakpoint Register index to read.\r
 \r
   @return The current value of Data Breakpoint Register specified by Index.\r
 \r
@@ -4624,7 +4642,7 @@ AsmReadDbr (
   zero value will be returned.\r
   This function is only available on IPF.\r
 \r
-  @param Index         The 8-bit Performance Monitor Configuration Register index to read.\r
+  @param Index    The 8-bit Performance Monitor Configuration Register index to read.\r
 \r
   @return The current value of Performance Monitor Configuration Register\r
   specified by Index.\r
@@ -4650,7 +4668,7 @@ AsmReadPmc (
   zero value will be returned.\r
   This function is only available on IPF.\r
 \r
-  @param Index         The 8-bit Performance Monitor Data Register index to read.\r
+  @param Index    The 8-bit Performance Monitor Data Register index to read.\r
 \r
   @return The current value of Performance Monitor Data Register specified by Index.\r
 \r
@@ -4676,8 +4694,8 @@ AsmReadPmd (
   set up fault handlers to catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Index         The 8-bit Instruction Breakpoint Register index to write.\r
-  @param Value         The 64-bit value to write to IBR.\r
+  @param Index    The 8-bit Instruction Breakpoint Register index to write.\r
+  @param Value    The 64-bit value to write to IBR.\r
 \r
   @return The 64-bit value written to the IBR.\r
 \r
@@ -4704,8 +4722,8 @@ AsmWriteIbr (
   catch the faults.\r
   This function is only available on IPF.\r
 \r
-  @param Index         The 8-bit Data Breakpoint Register index to write.\r
-  @param Value         The 64-bit value to write to DBR.\r
+  @param Index    The 8-bit Data Breakpoint Register index to write.\r
+  @param Value    The 64-bit value to write to DBR.\r
 \r
   @return The 64-bit value written to the DBR.\r
 \r
@@ -4731,8 +4749,8 @@ AsmWriteDbr (
   beyond the implemented PMC register range, the write is ignored.\r
   This function is only available on IPF.\r
 \r
-  @param Index         The 8-bit Performance Monitor Configuration Register index to write.\r
-  @param Value         The 64-bit value to write to PMC.\r
+  @param Index    The 8-bit Performance Monitor Configuration Register index to write.\r
+  @param Value    The 64-bit value to write to PMC.\r
 \r
   @return The 64-bit value written to the PMC.\r
 \r
@@ -4758,8 +4776,8 @@ AsmWritePmc (
   Index value is beyond the implemented PMD register range, the write is ignored.\r
   This function is only available on IPF.\r
 \r
-  @param Index         The 8-bit Performance Monitor Data Register index to write.\r
-  @param Value         The 64-bit value to write to PMD.\r
+  @param Index    The 8-bit Performance Monitor Data Register index to write.\r
+  @param Value    The 64-bit value to write to PMD.\r
 \r
   @return The 64-bit value written to the PMD.\r
 \r
@@ -4833,9 +4851,9 @@ AsmReadSp (
   and -1 is returned.\r
   This function is only available on IPF.\r
 \r
-  @return  1  The CPU is in virtual mode.\r
-  @return  0  The CPU is in physical mode.\r
-  @return -1  The CPU is in mixed mode.\r
+  @retval  1  The CPU is in virtual mode.\r
+  @retval  0  The CPU is in physical mode.\r
+  @retval -1  The CPU is in mixed mode.\r
 \r
 **/\r
 INT64\r
@@ -4867,11 +4885,11 @@ AsmCpuVirtual (
   PAL entry point then the system behavior is undefined.  This function is only\r
   available on IPF.\r
 \r
-  @param PalEntryPoint The PAL procedure calls entry point.\r
-  @param Index                     The PAL procedure Index number.\r
-  @param Arg2                        The 2nd parameter for PAL procedure calls.\r
-  @param Arg3                        The 3rd parameter for PAL procedure calls.\r
-  @param Arg4                        The 4th parameter for PAL procedure calls.\r
+  @param PalEntryPoint  The PAL procedure calls entry point.\r
+  @param Index          The PAL procedure Index number.\r
+  @param Arg2           The 2nd parameter for PAL procedure calls.\r
+  @param Arg3           The 3rd parameter for PAL procedure calls.\r
+  @param Arg4           The 4th parameter for PAL procedure calls.\r
 \r
   @return structure returned from the PAL Call procedure, including the status and return value.\r
 \r
@@ -4919,12 +4937,10 @@ AsmSwitchStackAndBackingStore (
   IN      VOID                      *NewBsp\r
   );\r
 \r
-\r
-//\r
-// Bugbug: This call should be removed after\r
-//         the PalCall Instance issue has been fixed.\r
-//\r
 /**\r
+  @todo   This call should be removed after the PalCall\r
+          Instance issue has been fixed.\r
+\r
   Performs a PAL call using static calling convention.\r
 \r
   An internal function to perform a PAL call using static calling convention.\r
@@ -4949,125 +4965,124 @@ PalCallStatic (
   );\r
 \r
 \r
+\r
 #elif defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
-//\r
-// IA32 and X64 Specific Functions\r
-//\r
-//\r
-// Byte packed structure for 16-bit Real Mode EFLAGS\r
-//\r
+///\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
-//\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
+///\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
-//\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
+///\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
-//\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
+///\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  PCE:1;          // Performance Monitoring Counter\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
-    UINT32  VMXE:1;         // VMX Enable\r
-    UINT32  Reserved_1:18;  // Reseved\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
+    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
+    UINT32  VMXE:1;         /// VMX Enable\r
+    UINT32  Reserved_1:18;  /// Reseved\r
   } Bits;\r
   UINTN     UintN;\r
 } IA32_CR4;\r
 \r
-//\r
-// Byte packed structure for an IDTR, GDTR, LDTR descriptor\r
-/// @bug  How to make this structure byte-packed in a compiler independent way?\r
-//\r
+///\r
+/// Byte packed structure for an IDTR, GDTR, LDTR descriptor\r
+/// @todo  How to make this structure byte-packed in a compiler independent way?\r
+///\r
 #pragma pack (1)\r
 typedef struct {\r
   UINT16  Limit;\r
@@ -5081,9 +5096,11 @@ typedef struct {
 #define IA32_IDT_GATE_TYPE_INTERRUPT_32  0x8E\r
 #define IA32_IDT_GATE_TYPE_TRAP_32       0x8F\r
 \r
-//\r
-// Byte packed structure for an Interrupt Gate Descriptor\r
-//\r
+///\r
+/// Byte packed structure for an Interrupt Gate Descriptor\r
+///\r
+#if defined (MDE_CPU_IA32)\r
+\r
 typedef union {\r
   struct {\r
     UINT32  OffsetLow:16;   // Offset bits 15..0\r
@@ -5095,16 +5112,36 @@ typedef union {
   UINT64  Uint64;\r
 } IA32_IDT_GATE_DESCRIPTOR;\r
 \r
-//\r
-// Byte packed structure for an FP/SSE/SSE2 context\r
-//\r
+#endif\r
+\r
+#if defined (MDE_CPU_X64)\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
+  } Bits;\r
+  UINT64  Uint64;\r
+  UINT64  Uint64_1;\r
+} IA32_IDT_GATE_DESCRIPTOR;\r
+\r
+#endif\r
+\r
+///\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
-//\r
+///\r
+/// Structures for the 16-bit real mode thunks\r
+///\r
 typedef struct {\r
   UINT32                            Reserved1;\r
   UINT32                            Reserved2;\r
@@ -5168,9 +5205,9 @@ typedef union {
   IA32_BYTE_REGS                    H;\r
 } IA32_REGISTER_SET;\r
 \r
-//\r
-// Byte packed structure for an 16-bit real mode thunks\r
-//\r
+///\r
+/// Byte packed structure for an 16-bit real mode thunks\r
+///\r
 typedef struct {\r
   IA32_REGISTER_SET                 *RealModeState;\r
   VOID                              *RealModeBuffer;\r
@@ -5284,7 +5321,8 @@ AsmReadMsr32 (
 \r
 \r
 /**\r
-  Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).\r
+  Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.\r
+  The upper 32-bits of the MSR are set to zero.\r
 \r
   Writes the 32-bit value specified by Value to the MSR specified by Index. The\r
   upper 32-bits of the MSR write are set to zero. The 32-bit value written to\r
@@ -6460,7 +6498,7 @@ AsmWriteGdtr (
 \r
 \r
 /**\r
-  Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.\r
+  Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.\r
 \r
   Reads and returns the current IDTR descriptor and returns it in Idtr. This\r
   function is only available on IA-32 and X64.\r
@@ -6478,7 +6516,7 @@ AsmReadIdtr (
 \r
 \r
 /**\r
-  Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.\r
+  Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.\r
 \r
   Writes the current IDTR descriptor and returns it in Idtr. This function is\r
   only available on IA-32 and X64.\r
@@ -6512,7 +6550,7 @@ AsmReadLdtr (
 \r
 \r
 /**\r
-  Writes the current Local Descriptor Table Register (GDTR) selector.\r
+  Writes the current Local Descriptor Table Register (LDTR) selector.\r
 \r
   Writes and the current LDTR descriptor specified by Ldtr. This function is\r
   only available on IA-32 and X64.\r
@@ -7063,7 +7101,7 @@ AsmDisablePaging32 (
   If EntryPoint is 0, then ASSERT().\r
   If NewStack is 0, then ASSERT().\r
 \r
-  @param  CodeSelector The 16-bit selector to load in the CS before EntryPoint\r
+  @param  Cs          The 16-bit selector to load in the CS before EntryPoint\r
                       is called. The descriptor in the GDT that this selector\r
                       references must be setup for long mode.\r
   @param  EntryPoint  The 64-bit virtual address of the function to call with\r
@@ -7081,7 +7119,7 @@ AsmDisablePaging32 (
 VOID\r
 EFIAPI\r
 AsmEnablePaging64 (\r
-  IN      UINT16                    CodeSelector,\r
+  IN      UINT16                    Cs,\r
   IN      UINT64                    EntryPoint,\r
   IN      UINT64                    Context1,  OPTIONAL\r
   IN      UINT64                    Context2,  OPTIONAL\r
@@ -7104,7 +7142,7 @@ AsmEnablePaging64 (
   If EntryPoint is 0, then ASSERT().\r
   If NewStack is 0, then ASSERT().\r
 \r
-  @param  CodeSelector The 16-bit selector to load in the CS before EntryPoint\r
+  @param  Cs          The 16-bit selector to load in the CS before EntryPoint\r
                       is called. The descriptor in the GDT that this selector\r
                       references must be setup for 32-bit protected mode.\r
   @param  EntryPoint  The 64-bit virtual address of the function to call with\r
@@ -7122,7 +7160,7 @@ AsmEnablePaging64 (
 VOID\r
 EFIAPI\r
 AsmDisablePaging64 (\r
-  IN      UINT16                    CodeSelector,\r
+  IN      UINT16                    Cs,\r
   IN      UINT32                    EntryPoint,\r
   IN      UINT32                    Context1,  OPTIONAL\r
   IN      UINT32                    Context2,  OPTIONAL\r
@@ -7185,11 +7223,47 @@ AsmPrepareThunk16 (
   Transfers control to a 16-bit real mode entry point and returns the results.\r
 \r
   Transfers control to a 16-bit real mode entry point and returns the results.\r
-  AsmPrepareThunk16() must be called with ThunkContext before this function is\r
-  used.\r
-\r
+  AsmPrepareThunk16() must be called with ThunkContext before this function is used.\r
+  This function must be called with interrupts disabled.\r
+\r
+  The register state from the RealModeState field of ThunkContext is restored just prior \r
+  to calling the 16-bit real mode entry point.  This includes the EFLAGS field of RealModeState, \r
+  which is used to set the interrupt state when a 16-bit real mode entry point is called.\r
+  Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.\r
+  The stack is initialized to the SS and ESP fields of RealModeState.  Any parameters passed to \r
+  the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.  \r
+  The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,\r
+  so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment \r
+  and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry \r
+  point must exit with a RETF instruction. The register state is captured into RealModeState immediately \r
+  after the RETF instruction is executed.\r
+  \r
+  If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts, \r
+  or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure \r
+  the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode. \r
+  \r
+  If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts, \r
+  then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.  \r
+  This includes the base vectors, the interrupt masks, and the edge/level trigger mode.\r
+  \r
+  If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code \r
+  is invoked in big real mode.  Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.\r
+  \r
+  If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in \r
+  ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to \r
+  disable the A20 mask.\r
+  \r
+  If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in \r
+  ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask.  If this INT 15 call fails, \r
+  then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.\r
+  \r
+  If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in \r
+  ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.\r
+    \r
   If ThunkContext is NULL, then ASSERT().\r
   If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().\r
+  If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in \r
+  ThunkAttributes, then ASSERT().\r
 \r
   @param  ThunkContext  A pointer to the context structure that describes the\r
                         16-bit real mode code to call.\r
@@ -7213,7 +7287,7 @@ AsmThunk16 (
   real mode thunk, then it is more efficient if AsmPrepareThunk16() is called\r
   once and AsmThunk16() can be called for each 16-bit real mode thunk.\r
 \r
-  If ThunkContext is NULL, then ASSERT().\r
+  See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.\r
 \r
   @param  ThunkContext  A pointer to the context structure that describes the\r
                         16-bit real mode code to call.\r
@@ -7225,10 +7299,7 @@ AsmPrepareAndThunk16 (
   IN OUT  THUNK_CONTEXT             *ThunkContext\r
   );\r
 \r
-#else\r
-\r
 #endif\r
-\r
 #endif\r
 \r
 \r