]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/BaseLibInternals.h
Updated to support compiler intrinsics properly. I had to comment out some of the...
[mirror_edk2.git] / MdePkg / Library / BaseLib / BaseLibInternals.h
index d0b9ef6f20de6416476b62d2979b45d3b75d02d4..b3952ec16baeac60e043520a48546600f6ae5e78 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Declaration of internal functions in BaseLib.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
+  Copyright (c) 2006 - 2007, 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
   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
-  Module Name:  BaseLibInternals.h\r
-\r
 **/\r
 \r
 #ifndef __BASE_LIB_INTERNALS__\r
 #define __BASE_LIB_INTERNALS__\r
 \r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#define QUIENT_MAX_UINTN_DIVIDED_BY_10      ((UINTN) -1 / 10)\r
+#define REMINDER_MAX_UINTN_DIVIDED_BY_10    ((UINTN) -1 % 10)\r
+\r
+#define QUIENT_MAX_UINTN_DIVIDED_BY_16      ((UINTN) -1 / 16)\r
+#define REMINDER_MAX_UINTN_DIVIDED_BY_16    ((UINTN) -1 % 16)\r
+\r
+#define QUIENT_MAX_UINT64_DIVIDED_BY_10      ((UINT64) -1 / 10)\r
+#define REMINDER_MAX_UINT64_DIVIDED_BY_10    ((UINT64) -1 % 10)\r
+\r
+#define QUIENT_MAX_UINT64_DIVIDED_BY_16      ((UINT64) -1 / 16)\r
+#define REMINDER_MAX_UINT64_DIVIDED_BY_16    ((UINT64) -1 % 16)\r
+\r
 //\r
 // Math functions\r
 //\r
@@ -302,10 +317,16 @@ InternalMathDivRemS64x64 (
 /**\r
   Transfers control to a function starting with a new stack.\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
+  Transfers control to the function specified by EntryPoint using the\r
+  new stack specified by NewStack and passing in the parameters specified\r
+  by Context1 and Context2.  Context1 and Context2 are optional and may\r
+  be NULL.  The function EntryPoint must never return.\r
+  Marker will be ignored on IA-32, x64, and EBC.\r
+  IPF CPUs expect one additional parameter of type VOID * that specifies\r
+  the new backing store pointer.\r
+\r
+  If EntryPoint is NULL, then ASSERT().\r
+  If NewStack is NULL, then ASSERT().\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
@@ -314,20 +335,249 @@ InternalMathDivRemS64x64 (
                       function.\r
   @param  NewStack    A pointer to the new stack to use for the EntryPoint\r
                       function.\r
+  @param  Marker      VA_LIST marker for the variable argument list.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 InternalSwitchStack (\r
   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,\r
-  IN      VOID                      *Context1,\r
-  IN      VOID                      *Context2,\r
-  IN      VOID                      *NewStack\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
+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
+  Returns the bitfield specified by the StartBit and the EndBit from Operand.\r
+\r
+  @param  Operand   Operand on which to perform the bitfield operation.\r
+  @param  StartBit  The ordinal of the least significant bit in the bit field.\r
+  @param  EndBit    The ordinal of the most significant bit in the bit field.\r
+\r
+  @return The bit field read.\r
+\r
+**/\r
+unsigned int\r
+BitFieldReadUint (\r
+  IN      unsigned int              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
+\r
+  Performs a bitwise OR between the bit field specified by StartBit and EndBit\r
+  in Operand and the value specified by AndData. All other bits in Operand are\r
+  preserved. The new value is returned.\r
+\r
+  @param  Operand   Operand on which to perform the bitfield operation.\r
+  @param  StartBit  The ordinal of the least significant bit in the bit field.\r
+  @param  EndBit    The ordinal of the most significant bit in the bit field.\r
+  @param  OrData    The value to OR with the read value from the value\r
+\r
+  @return The new value.\r
+\r
+**/\r
+unsigned int\r
+BitFieldOrUint (\r
+  IN      unsigned int              Operand,\r
+  IN      UINTN                     StartBit,\r
+  IN      UINTN                     EndBit,\r
+  IN      unsigned int              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
+\r
+  Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
+  in Operand and the value specified by AndData. All other bits in Operand are\r
+  preserved. The new value is returned.\r
+\r
+  @param  Operand   Operand on which to perform the bitfield operation.\r
+  @param  StartBit  The ordinal of the least significant bit in the bit field.\r
+  @param  EndBit    The ordinal of the most significant bit in the bit field.\r
+  @param  AndData    The value to And with the read value from the value\r
+\r
+  @return The new value.\r
+\r
+**/\r
+unsigned int\r
+BitFieldAndUint (\r
+  IN      unsigned int              Operand,\r
+  IN      UINTN                     StartBit,\r
+  IN      UINTN                     EndBit,\r
+  IN      unsigned int              AndData\r
+  );\r
+\r
+\r
+/**\r
+  Worker function that checks ASSERT condition for JumpBuffer\r
+\r
+  Checks ASSERT condition for JumpBuffer.\r
+\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
+  @param  JumpBuffer    A pointer to CPU context buffer.\r
+\r
+**/\r
+VOID\r
+InternalAssertJumpBuffer (\r
+  IN      BASE_LIBRARY_JUMP_BUFFER  *JumpBuffer\r
+  );\r
+\r
+\r
+/**\r
+  Restores the CPU context that was saved with SetJump().\r
+\r
+  Restores the CPU context from the buffer specified by JumpBuffer.\r
+  This function never returns to the caller.\r
+  Instead is resumes execution based on the state of JumpBuffer.\r
+\r
+  @param  JumpBuffer    A pointer to CPU context buffer.\r
+  @param  Value         The value to return when the SetJump() context is restored.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+InternalLongJump (\r
+  IN      BASE_LIBRARY_JUMP_BUFFER  *JumpBuffer,\r
+  IN      UINTN                     Value\r
+  );\r
+\r
+\r
 //\r
 // Ia32 and x64 specific functions\r
 //\r
+#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
 \r
 /**\r
   Reads the current Global Descriptor Table Register(GDTR) descriptor.\r
@@ -575,219 +825,46 @@ InternalX86DisablePaging64 (
   IN      UINT32                    NewStack\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
-IsNodeInList (\r
-  IN      CONST LIST_ENTRY      *List,\r
-  IN      CONST LIST_ENTRY      *Node\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
-  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
-  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
-  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
-  Worker function that returns a bit field from Operand\r
-\r
-  Returns the bitfield specified by the StartBit and the EndBit from Operand.\r
-\r
-  @param  Operand   Operand on which to perform the bitfield operation.\r
-  @param  StartBit  The ordinal of the least significant bit in the bit field.\r
-  @param  EndBit    The ordinal of the most significant bit in the bit field.\r
-\r
-  @return The bit field read.\r
-\r
-**/\r
-unsigned int\r
-BitFieldReadUint (\r
-  IN      unsigned int              Operand,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit\r
-  );\r
-\r
-/**\r
-  Worker function that reads a bit field from Operand, performs a bitwise OR, \r
-  and returns the result.\r
-\r
-  Performs a bitwise OR between the bit field specified by StartBit and EndBit\r
-  in Operand and the value specified by AndData. All other bits in Operand are\r
-  preserved. The new value is returned.\r
-\r
-  @param  Operand   Operand on which to perform the bitfield operation.\r
-  @param  StartBit  The ordinal of the least significant bit in the bit field.\r
-  @param  EndBit    The ordinal of the most significant bit in the bit field.\r
-  @param  OrData    The value to OR with the read value from the value\r
-\r
-  @return The new value.\r
-\r
-**/\r
-unsigned int\r
-BitFieldOrUint (\r
-  IN      unsigned int              Operand,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      unsigned int              OrData\r
-  );\r
-\r
-/**\r
-  Worker function that reads a bit field from Operand, performs a bitwise AND, \r
-  and returns the result.\r
-\r
-  Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
-  in Operand and the value specified by AndData. All other bits in Operand are\r
-  preserved. The new value is returned.\r
-\r
-  @param  Operand   Operand on which to perform the bitfield operation.\r
-  @param  StartBit  The ordinal of the least significant bit in the bit field.\r
-  @param  EndBit    The ordinal of the most significant bit in the bit field.\r
-  @param  AndData    The value to And with the read value from the value\r
-\r
-  @return The new value.\r
 \r
-**/\r
-unsigned int\r
-BitFieldAndUint (\r
-  IN      unsigned int              Operand,\r
-  IN      UINTN                     StartBit,\r
-  IN      UINTN                     EndBit,\r
-  IN      unsigned int              AndData\r
-  );\r
+#elif defined (MDE_CPU_IPF)\r
+//\r
+//\r
+// IPF specific functions\r
+//\r
 \r
 /**\r
-  Worker function that checks ASSERT condition for JumpBuffer\r
-\r
-  Checks ASSERT condition for JumpBuffer.\r
-\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
-  @param  JumpBuffer    A pointer to CPU context buffer.\r
-\r
-**/\r
-VOID\r
-InternalAssertJumpBuffer (\r
-  IN      BASE_LIBRARY_JUMP_BUFFER  *JumpBuffer\r
-  );\r
+  Transfers control to a function starting with a new stack.\r
 \r
-/**\r
-  Restores the CPU context that was saved with SetJump().\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
 \r
-  Restores the CPU context from the buffer specified by JumpBuffer.\r
-  This function never returns to the caller.\r
-  Instead is resumes execution based on the state of JumpBuffer.\r
+  If EntryPoint is NULL, then ASSERT().\r
+  If NewStack is NULL, then ASSERT().\r
 \r
-  @param  JumpBuffer    A pointer to CPU context buffer.\r
-  @param  Value         The value to return when the SetJump() context is restored.\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
 **/\r
 VOID\r
 EFIAPI\r
-InternalLongJump (\r
-  IN      BASE_LIBRARY_JUMP_BUFFER  *JumpBuffer,\r
-  IN      UINTN                     Value\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
   );\r
+#else\r
+\r
+#endif\r
 \r
 #endif\r