]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/BaseLibInternals.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseLib / BaseLibInternals.h
index 3d47a2153551c105f75bcbfd9fb67d94987d65a5..d61e60438531664bb3d197603ba81794140f567c 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Declaration of internal functions in BaseLib.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation<BR>\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
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -19,7 +13,6 @@
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
-#include <Library/TimerLib.h>\r
 #include <Library/PcdLib.h>\r
 \r
 //\r
 UINT64\r
 EFIAPI\r
 InternalMathLShiftU64 (\r
-  IN      UINT64                    Operand,\r
-  IN      UINTN                     Count\r
+  IN      UINT64  Operand,\r
+  IN      UINTN   Count\r
   );\r
 \r
 /**\r
-  Shifts a 64-bit integer right between 0 and 63 bits. This high bits\r
+  Shifts a 64-bit integer right between 0 and 63 bits. The high bits\r
   are filled with zeros. The shifted value is returned.\r
 \r
   This function shifts the 64-bit value Operand to the right by Count bits. The\r
@@ -62,8 +55,8 @@ InternalMathLShiftU64 (
 UINT64\r
 EFIAPI\r
 InternalMathRShiftU64 (\r
-  IN      UINT64                    Operand,\r
-  IN      UINTN                     Count\r
+  IN      UINT64  Operand,\r
+  IN      UINTN   Count\r
   );\r
 \r
 /**\r
@@ -82,8 +75,8 @@ InternalMathRShiftU64 (
 UINT64\r
 EFIAPI\r
 InternalMathARShiftU64 (\r
-  IN      UINT64                    Operand,\r
-  IN      UINTN                     Count\r
+  IN      UINT64  Operand,\r
+  IN      UINTN   Count\r
   );\r
 \r
 /**\r
@@ -91,7 +84,7 @@ InternalMathARShiftU64 (
   the low bits with the high bits that were rotated.\r
 \r
   This function rotates the 64-bit value Operand to the left by Count bits. The\r
-  low Count bits are fill with the high Count bits of Operand. The rotated\r
+  low Count bits are filled with the high Count bits of Operand. The rotated\r
   value is returned.\r
 \r
   @param  Operand The 64-bit operand to rotate left.\r
@@ -103,8 +96,8 @@ InternalMathARShiftU64 (
 UINT64\r
 EFIAPI\r
 InternalMathLRotU64 (\r
-  IN      UINT64                    Operand,\r
-  IN      UINTN                     Count\r
+  IN      UINT64  Operand,\r
+  IN      UINTN   Count\r
   );\r
 \r
 /**\r
@@ -112,7 +105,7 @@ InternalMathLRotU64 (
   the high bits with the high low bits that were rotated.\r
 \r
   This function rotates the 64-bit value Operand to the right by Count bits.\r
-  The high Count bits are fill with the low Count bits of Operand. The rotated\r
+  The high Count bits are filled with the low Count bits of Operand. The rotated\r
   value is returned.\r
 \r
   @param  Operand The 64-bit operand to rotate right.\r
@@ -124,8 +117,8 @@ InternalMathLRotU64 (
 UINT64\r
 EFIAPI\r
 InternalMathRRotU64 (\r
-  IN      UINT64                    Operand,\r
-  IN      UINTN                     Count\r
+  IN      UINT64  Operand,\r
+  IN      UINTN   Count\r
   );\r
 \r
 /**\r
@@ -143,14 +136,14 @@ InternalMathRRotU64 (
 UINT64\r
 EFIAPI\r
 InternalMathSwapBytes64 (\r
-  IN      UINT64                    Operand\r
+  IN      UINT64  Operand\r
   );\r
 \r
 /**\r
-  Multiples a 64-bit unsigned integer by a 32-bit unsigned integer\r
+  Multiplies a 64-bit unsigned integer by a 32-bit unsigned integer\r
   and generates a 64-bit unsigned result.\r
 \r
-  This function multiples the 64-bit unsigned value Multiplicand by the 32-bit\r
+  This function multiplies the 64-bit unsigned value Multiplicand by the 32-bit\r
   unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r
   bit unsigned result is returned.\r
 \r
@@ -163,12 +156,12 @@ InternalMathSwapBytes64 (
 UINT64\r
 EFIAPI\r
 InternalMathMultU64x32 (\r
-  IN      UINT64                    Multiplicand,\r
-  IN      UINT32                    Multiplier\r
+  IN      UINT64  Multiplicand,\r
+  IN      UINT32  Multiplier\r
   );\r
 \r
 /**\r
-  Multiples a 64-bit unsigned integer by a 64-bit unsigned integer\r
+  Multiplies a 64-bit unsigned integer by a 64-bit unsigned integer\r
   and generates a 64-bit unsigned result.\r
 \r
   This function multiples the 64-bit unsigned value Multiplicand by the 64-bit\r
@@ -184,8 +177,8 @@ InternalMathMultU64x32 (
 UINT64\r
 EFIAPI\r
 InternalMathMultU64x64 (\r
-  IN      UINT64                    Multiplicand,\r
-  IN      UINT64                    Multiplier\r
+  IN      UINT64  Multiplicand,\r
+  IN      UINT64  Multiplier\r
   );\r
 \r
 /**\r
@@ -205,8 +198,8 @@ InternalMathMultU64x64 (
 UINT64\r
 EFIAPI\r
 InternalMathDivU64x32 (\r
-  IN      UINT64                    Dividend,\r
-  IN      UINT32                    Divisor\r
+  IN      UINT64  Dividend,\r
+  IN      UINT32  Divisor\r
   );\r
 \r
 /**\r
@@ -226,8 +219,8 @@ InternalMathDivU64x32 (
 UINT32\r
 EFIAPI\r
 InternalMathModU64x32 (\r
-  IN      UINT64                    Dividend,\r
-  IN      UINT32                    Divisor\r
+  IN      UINT64  Dividend,\r
+  IN      UINT32  Divisor\r
   );\r
 \r
 /**\r
@@ -250,9 +243,9 @@ InternalMathModU64x32 (
 UINT64\r
 EFIAPI\r
 InternalMathDivRemU64x32 (\r
-  IN      UINT64                    Dividend,\r
-  IN      UINT32                    Divisor,\r
-  OUT     UINT32                    *Remainder OPTIONAL\r
+  IN      UINT64  Dividend,\r
+  IN      UINT32  Divisor,\r
+  OUT     UINT32  *Remainder OPTIONAL\r
   );\r
 \r
 /**\r
@@ -275,9 +268,9 @@ InternalMathDivRemU64x32 (
 UINT64\r
 EFIAPI\r
 InternalMathDivRemU64x64 (\r
-  IN      UINT64                    Dividend,\r
-  IN      UINT64                    Divisor,\r
-  OUT     UINT64                    *Remainder OPTIONAL\r
+  IN      UINT64  Dividend,\r
+  IN      UINT64  Divisor,\r
+  OUT     UINT64  *Remainder OPTIONAL\r
   );\r
 \r
 /**\r
@@ -300,10 +293,10 @@ InternalMathDivRemU64x64 (
 INT64\r
 EFIAPI\r
 InternalMathDivRemS64x64 (\r
-  IN      INT64                     Dividend,\r
-  IN      INT64                     Divisor,\r
-  OUT     INT64                     *Remainder  OPTIONAL\r
- );\r
+  IN      INT64  Dividend,\r
+  IN      INT64  Divisor,\r
+  OUT     INT64  *Remainder  OPTIONAL\r
 );\r
 \r
 /**\r
   Transfers control to a function starting with a new stack.\r
@@ -333,133 +326,12 @@ VOID
 EFIAPI\r
 InternalSwitchStack (\r
   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,\r
-  IN      VOID                      *Context1,   OPTIONAL\r
-  IN      VOID                      *Context2,   OPTIONAL\r
+  IN      VOID                      *Context1    OPTIONAL,\r
+  IN      VOID                      *Context2    OPTIONAL,\r
   IN      VOID                      *NewStack,\r
   IN      VA_LIST                   Marker\r
   );\r
 \r
-\r
-/**\r
-  Worker function that locates the Node in the List.\r
-\r
-  By searching the List, finds the location of the Node in List. At the same time,\r
-  verifies the validity of this list.\r
-\r
-  If List is NULL, then ASSERT().\r
-  If List->ForwardLink is NULL, then ASSERT().\r
-  If List->backLink is NULL, then ASSERT().\r
-  If Node is NULL, 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
-\r
-  @param  List  A pointer to a node in a linked list.\r
-  @param  Node  A pointer to one nod.\r
-\r
-  @retval TRUE   Node is in List\r
-  @retval FALSE  Node isn't in List, or List is invalid\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-IsNodeInList (\r
-  IN      CONST LIST_ENTRY      *List,\r
-  IN      CONST LIST_ENTRY      *Node\r
-  );\r
-\r
-\r
-/**\r
-  Performs an atomic increment of an 32-bit unsigned integer.\r
-\r
-  Performs an atomic increment of the 32-bit unsigned integer specified by\r
-  Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
-\r
-  @param  Value A pointer to the 32-bit value to increment.\r
-\r
-  @return The incremented value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncIncrement (\r
-  IN      volatile UINT32           *Value\r
-  );\r
-\r
-\r
-/**\r
-  Performs an atomic decrement of an 32-bit unsigned integer.\r
-\r
-  Performs an atomic decrement of the 32-bit unsigned integer specified by\r
-  Value and returns the decrement value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
-\r
-  @param  Value A pointer to the 32-bit value to decrement.\r
-\r
-  @return The decrement value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncDecrement (\r
-  IN      volatile UINT32           *Value\r
-  );\r
-\r
-\r
-/**\r
-  Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
-\r
-  Performs an atomic compare exchange operation on the 32-bit unsigned integer\r
-  specified by Value.  If Value is equal to CompareValue, then Value is set to\r
-  ExchangeValue and CompareValue is returned.  If Value is not equal to CompareValue,\r
-  then Value is returned.  The compare exchange operation must be performed using\r
-  MP safe mechanisms.\r
-\r
-  @param  Value         A pointer to the 32-bit value for the compare exchange\r
-                        operation.\r
-  @param  CompareValue  32-bit value used in compare operation.\r
-  @param  ExchangeValue 32-bit value used in exchange operation.\r
-\r
-  @return The original *Value before exchange.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncCompareExchange32 (\r
-  IN      volatile UINT32           *Value,\r
-  IN      UINT32                    CompareValue,\r
-  IN      UINT32                    ExchangeValue\r
-  );\r
-\r
-\r
-/**\r
-  Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
-\r
-  Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r
-  by Value.  If Value is equal to CompareValue, then Value is set to ExchangeValue and\r
-  CompareValue is returned.  If Value is not equal to CompareValue, then Value is returned.\r
-  The compare exchange operation must be performed using MP safe mechanisms.\r
-\r
-  @param  Value         A pointer to the 64-bit value for the compare exchange\r
-                        operation.\r
-  @param  CompareValue  64-bit value used in compare operation.\r
-  @param  ExchangeValue 64-bit value used in exchange operation.\r
-\r
-  @return The original *Value before exchange.\r
-\r
-**/\r
-UINT64\r
-EFIAPI\r
-InternalSyncCompareExchange64 (\r
-  IN      volatile UINT64           *Value,\r
-  IN      UINT64                    CompareValue,\r
-  IN      UINT64                    ExchangeValue\r
-  );\r
-\r
-\r
 /**\r
   Worker function that returns a bit field from Operand.\r
 \r
@@ -475,12 +347,11 @@ InternalSyncCompareExchange64 (
 UINTN\r
 EFIAPI\r
 BitFieldReadUint (\r
-  IN      UINTN                     Operand,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit\r
+  IN      UINTN  Operand,\r
+  IN      UINTN  StartBit,\r
+  IN      UINTN  EndBit\r
   );\r
 \r
-\r
 /**\r
   Worker function that reads a bit field from Operand, performs a bitwise OR,\r
   and returns the result.\r
@@ -500,13 +371,12 @@ BitFieldReadUint (
 UINTN\r
 EFIAPI\r
 BitFieldOrUint (\r
-  IN      UINTN                     Operand,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      UINTN                     OrData\r
+  IN      UINTN  Operand,\r
+  IN      UINTN  StartBit,\r
+  IN      UINTN  EndBit,\r
+  IN      UINTN  OrData\r
   );\r
 \r
-\r
 /**\r
   Worker function that reads a bit field from Operand, performs a bitwise AND,\r
   and returns the result.\r
@@ -526,13 +396,12 @@ BitFieldOrUint (
 UINTN\r
 EFIAPI\r
 BitFieldAndUint (\r
-  IN      UINTN                     Operand,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      UINTN                     AndData\r
+  IN      UINTN  Operand,\r
+  IN      UINTN  StartBit,\r
+  IN      UINTN  EndBit,\r
+  IN      UINTN  AndData\r
   );\r
 \r
-\r
 /**\r
   Worker function that checks ASSERT condition for JumpBuffer\r
 \r
@@ -550,7 +419,6 @@ InternalAssertJumpBuffer (
   IN      BASE_LIBRARY_JUMP_BUFFER  *JumpBuffer\r
   );\r
 \r
-\r
 /**\r
   Restores the CPU context that was saved with SetJump().\r
 \r
@@ -569,6 +437,121 @@ InternalLongJump (
   IN      UINTN                     Value\r
   );\r
 \r
+/**\r
+  Check if a Unicode character is a decimal character.\r
+\r
+  This internal function checks if a Unicode character is a\r
+  decimal character. The valid decimal character is from\r
+  L'0' to L'9'.\r
+\r
+  @param  Char  The character to check against.\r
+\r
+  @retval TRUE  If the Char is a decmial character.\r
+  @retval FALSE If the Char is not a decmial character.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalIsDecimalDigitCharacter (\r
+  IN      CHAR16  Char\r
+  );\r
+\r
+/**\r
+  Convert a Unicode character to numerical value.\r
+\r
+  This internal function only deal with Unicode character\r
+  which maps to a valid hexadecimal ASII character, i.e.\r
+  L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r
+  Unicode character, the value returned does not make sense.\r
+\r
+  @param  Char  The character to convert.\r
+\r
+  @return The numerical value converted.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+InternalHexCharToUintn (\r
+  IN      CHAR16  Char\r
+  );\r
+\r
+/**\r
+  Check if a Unicode character is a hexadecimal character.\r
+\r
+  This internal function checks if a Unicode character is a\r
+  decimal character.  The valid hexadecimal character is\r
+  L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r
+\r
+\r
+  @param  Char  The character to check against.\r
+\r
+  @retval TRUE  If the Char is a hexadecmial character.\r
+  @retval FALSE If the Char is not a hexadecmial character.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalIsHexaDecimalDigitCharacter (\r
+  IN      CHAR16  Char\r
+  );\r
+\r
+/**\r
+  Check if a ASCII character is a decimal character.\r
+\r
+  This internal function checks if a Unicode character is a\r
+  decimal character. The valid decimal character is from\r
+  '0' to '9'.\r
+\r
+  @param  Char  The character to check against.\r
+\r
+  @retval TRUE  If the Char is a decmial character.\r
+  @retval FALSE If the Char is not a decmial character.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalAsciiIsDecimalDigitCharacter (\r
+  IN      CHAR8  Char\r
+  );\r
+\r
+/**\r
+  Check if a ASCII character is a hexadecimal character.\r
+\r
+  This internal function checks if a ASCII character is a\r
+  decimal character.  The valid hexadecimal character is\r
+  L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r
+\r
+\r
+  @param  Char  The character to check against.\r
+\r
+  @retval TRUE  If the Char is a hexadecmial character.\r
+  @retval FALSE If the Char is not a hexadecmial character.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalAsciiIsHexaDecimalDigitCharacter (\r
+  IN      CHAR8  Char\r
+  );\r
+\r
+/**\r
+  Convert a ASCII character to numerical value.\r
+\r
+  This internal function only deal with Unicode character\r
+  which maps to a valid hexadecimal ASII character, i.e.\r
+  '0' to '9', 'a' to 'f' or 'A' to 'F'. For other\r
+  ASCII character, the value returned does not make sense.\r
+\r
+  @param  Char  The character to convert.\r
+\r
+  @return The numerical value converted.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+InternalAsciiHexCharToUintn (\r
+  IN      CHAR8  Char\r
+  );\r
 \r
 //\r
 // Ia32 and x64 specific functions\r
@@ -579,60 +562,60 @@ InternalLongJump (
   Reads the current Global Descriptor Table Register(GDTR) descriptor.\r
 \r
   Reads and returns the current GDTR descriptor and returns it in Gdtr. This\r
-  function is only available on IA-32 and X64.\r
+  function is only available on IA-32 and x64.\r
 \r
-  @param  Gdtr  Pointer to a GDTR descriptor.\r
+  @param  Gdtr  The pointer to a GDTR descriptor.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 InternalX86ReadGdtr (\r
-  OUT     IA32_DESCRIPTOR           *Gdtr\r
+  OUT     IA32_DESCRIPTOR  *Gdtr\r
   );\r
 \r
 /**\r
   Writes the current Global Descriptor Table Register (GDTR) descriptor.\r
 \r
   Writes and the current GDTR descriptor specified by Gdtr. This function is\r
-  only available on IA-32 and X64.\r
+  only available on IA-32 and x64.\r
 \r
-  @param  Gdtr  Pointer to a GDTR descriptor.\r
+  @param  Gdtr  The pointer to a GDTR descriptor.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 InternalX86WriteGdtr (\r
-  IN      CONST IA32_DESCRIPTOR     *Gdtr\r
+  IN      CONST IA32_DESCRIPTOR  *Gdtr\r
   );\r
 \r
 /**\r
   Reads the current Interrupt Descriptor Table Register(GDTR) 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
+  function is only available on IA-32 and x64.\r
 \r
-  @param  Idtr  Pointer to a IDTR descriptor.\r
+  @param  Idtr  The pointer to an IDTR descriptor.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 InternalX86ReadIdtr (\r
-  OUT     IA32_DESCRIPTOR           *Idtr\r
+  OUT     IA32_DESCRIPTOR  *Idtr\r
   );\r
 \r
 /**\r
   Writes the current Interrupt Descriptor Table Register(GDTR) 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
+  only available on IA-32 and x64.\r
 \r
-  @param  Idtr  Pointer to a IDTR descriptor.\r
+  @param  Idtr  The pointer to an IDTR descriptor.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 InternalX86WriteIdtr (\r
-  IN      CONST IA32_DESCRIPTOR     *Idtr\r
+  IN      CONST IA32_DESCRIPTOR  *Idtr\r
   );\r
 \r
 /**\r
@@ -640,15 +623,15 @@ InternalX86WriteIdtr (
 \r
   Saves the current floating point/SSE/SSE2 state to the buffer specified by\r
   Buffer. Buffer must be aligned on a 16-byte boundary. This function is only\r
-  available on IA-32 and X64.\r
+  available on IA-32 and x64.\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
 EFIAPI\r
 InternalX86FxSave (\r
-  OUT     IA32_FX_BUFFER            *Buffer\r
+  OUT     IA32_FX_BUFFER  *Buffer\r
   );\r
 \r
 /**\r
@@ -656,15 +639,15 @@ InternalX86FxSave (
 \r
   Restores the current floating point/SSE/SSE2 state from the buffer specified\r
   by Buffer. Buffer must be aligned on a 16-byte boundary. This function is\r
-  only available on IA-32 and X64.\r
+  only available on IA-32 and x64.\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
 EFIAPI\r
 InternalX86FxRestore (\r
-  IN      CONST IA32_FX_BUFFER      *Buffer\r
+  IN      CONST IA32_FX_BUFFER  *Buffer\r
   );\r
 \r
 /**\r
@@ -704,8 +687,8 @@ VOID
 EFIAPI\r
 InternalX86EnablePaging32 (\r
   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,\r
-  IN      VOID                      *Context1,  OPTIONAL\r
-  IN      VOID                      *Context2,  OPTIONAL\r
+  IN      VOID                      *Context1   OPTIONAL,\r
+  IN      VOID                      *Context2   OPTIONAL,\r
   IN      VOID                      *NewStack\r
   );\r
 \r
@@ -743,8 +726,8 @@ VOID
 EFIAPI\r
 InternalX86DisablePaging32 (\r
   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,\r
-  IN      VOID                      *Context1,  OPTIONAL\r
-  IN      VOID                      *Context2,  OPTIONAL\r
+  IN      VOID                      *Context1   OPTIONAL,\r
+  IN      VOID                      *Context2   OPTIONAL,\r
   IN      VOID                      *NewStack\r
   );\r
 \r
@@ -778,11 +761,11 @@ InternalX86DisablePaging32 (
 VOID\r
 EFIAPI\r
 InternalX86EnablePaging64 (\r
-  IN      UINT16                    Cs,\r
-  IN      UINT64                    EntryPoint,\r
-  IN      UINT64                    Context1,  OPTIONAL\r
-  IN      UINT64                    Context2,  OPTIONAL\r
-  IN      UINT64                    NewStack\r
+  IN      UINT16  Cs,\r
+  IN      UINT64  EntryPoint,\r
+  IN      UINT64  Context1   OPTIONAL,\r
+  IN      UINT64  Context2   OPTIONAL,\r
+  IN      UINT64  NewStack\r
   );\r
 \r
 /**\r
@@ -790,7 +773,7 @@ InternalX86EnablePaging64 (
 \r
   Disables the 64-bit paging mode on the CPU and returns to 32-bit protected\r
   mode. This function assumes the current execution mode is 64-paging mode.\r
-  This function is only available on X64. After the 64-bit paging mode is\r
+  This function is only available on x64. After the 64-bit paging mode is\r
   disabled, control is transferred to the function specified by EntryPoint\r
   using the new stack specified by NewStack and passing in the parameters\r
   specified by Context1 and Context2. Context1 and Context2 are optional and\r
@@ -814,51 +797,59 @@ InternalX86EnablePaging64 (
 VOID\r
 EFIAPI\r
 InternalX86DisablePaging64 (\r
-  IN      UINT16                    Cs,\r
-  IN      UINT32                    EntryPoint,\r
-  IN      UINT32                    Context1,  OPTIONAL\r
-  IN      UINT32                    Context2,  OPTIONAL\r
-  IN      UINT32                    NewStack\r
+  IN      UINT16  Cs,\r
+  IN      UINT32  EntryPoint,\r
+  IN      UINT32  Context1   OPTIONAL,\r
+  IN      UINT32  Context2   OPTIONAL,\r
+  IN      UINT32  NewStack\r
   );\r
 \r
+/**\r
+  Generates a 16-bit random number through RDRAND instruction.\r
+\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
 \r
-#elif defined (MDE_CPU_IPF)\r
-//\r
-//\r
-// IPF specific functions\r
-//\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
+\r
+ **/\r
+BOOLEAN\r
+EFIAPI\r
+InternalX86RdRand16 (\r
+  OUT     UINT16  *Rand\r
+  );\r
 \r
 /**\r
-  Transfers control to a function starting with a new stack.\r
+  Generates a 32-bit random number through RDRAND instruction.\r
 \r
-  Transfers control to the function specified by EntryPoint using the new stack\r
-  specified by NewStack and passing in the parameters specified by Context1 and\r
-  Context2. Context1 and Context2 are optional and may be NULL. The function\r
-  EntryPoint must never return.\r
+  @param[out]  Rand     Buffer pointer to store the random result.\r
 \r
-  If EntryPoint is NULL, then ASSERT().\r
-  If NewStack is NULL, then ASSERT().\r
+  @retval TRUE          RDRAND call was successful.\r
+  @retval FALSE         Failed attempts to call RDRAND.\r
 \r
-  @param  EntryPoint  A pointer to function to call with the new stack.\r
-  @param  Context1    A pointer to the context to pass into the EntryPoint\r
-                      function.\r
-  @param  Context2    A pointer to the context to pass into the EntryPoint\r
-                      function.\r
-  @param  NewStack    A pointer to the new stack to use for the EntryPoint\r
-                      function.\r
-  @param  NewBsp      A pointer to the new memory location for RSE backing\r
-                      store.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalX86RdRand32 (\r
+  OUT     UINT32  *Rand\r
+  );\r
+\r
+/**\r
+  Generates a 64-bit random number through RDRAND instruction.\r
+\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
-VOID\r
+BOOLEAN\r
 EFIAPI\r
-AsmSwitchStackAndBackingStore (\r
-  IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,\r
-  IN      VOID                      *Context1,  OPTIONAL\r
-  IN      VOID                      *Context2,  OPTIONAL\r
-  IN      VOID                      *NewStack,\r
-  IN      VOID                      *NewBsp\r
+InternalX86RdRand64  (\r
+  OUT     UINT64  *Rand\r
   );\r
+\r
 #else\r
 \r
 #endif\r