X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FBaseLib%2FBaseLibInternals.h;h=6837d67d90cf2772da0db2fec2fedf37fcee20e9;hp=9c6044b606908d12e73b9317f201fb6045286817;hb=9344f0921518309295da89c221d10cbead8531aa;hpb=24dcb5e50a4492ae2c4616d04e99794f6c19cfac diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h b/MdePkg/Library/BaseLib/BaseLibInternals.h index 9c6044b606..6837d67d90 100644 --- a/MdePkg/Library/BaseLib/BaseLibInternals.h +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h @@ -1,14 +1,8 @@ /** @file Declaration of internal functions in BaseLib. - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -19,7 +13,6 @@ #include #include #include -#include #include // @@ -47,7 +40,7 @@ InternalMathLShiftU64 ( ); /** - Shifts a 64-bit integer right between 0 and 63 bits. This high bits + Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled with zeros. The shifted value is returned. This function shifts the 64-bit value Operand to the right by Count bits. The @@ -91,7 +84,7 @@ InternalMathARShiftU64 ( the low bits with the high bits that were rotated. This function rotates the 64-bit value Operand to the left by Count bits. The - low Count bits are fill with the high Count bits of Operand. The rotated + low Count bits are filled with the high Count bits of Operand. The rotated value is returned. @param Operand The 64-bit operand to rotate left. @@ -112,7 +105,7 @@ InternalMathLRotU64 ( the high bits with the high low bits that were rotated. This function rotates the 64-bit value Operand to the right by Count bits. - The high Count bits are fill with the low Count bits of Operand. The rotated + The high Count bits are filled with the low Count bits of Operand. The rotated value is returned. @param Operand The 64-bit operand to rotate right. @@ -147,10 +140,10 @@ InternalMathSwapBytes64 ( ); /** - Multiples a 64-bit unsigned integer by a 32-bit unsigned integer + Multiplies a 64-bit unsigned integer by a 32-bit unsigned integer and generates a 64-bit unsigned result. - This function multiples the 64-bit unsigned value Multiplicand by the 32-bit + This function multiplies the 64-bit unsigned value Multiplicand by the 32-bit unsigned value Multiplier and generates a 64-bit unsigned result. This 64- bit unsigned result is returned. @@ -168,7 +161,7 @@ InternalMathMultU64x32 ( ); /** - Multiples a 64-bit unsigned integer by a 64-bit unsigned integer + Multiplies a 64-bit unsigned integer by a 64-bit unsigned integer and generates a 64-bit unsigned result. This function multiples the 64-bit unsigned value Multiplicand by the 64-bit @@ -303,7 +296,7 @@ InternalMathDivRemS64x64 ( IN INT64 Dividend, IN INT64 Divisor, OUT INT64 *Remainder OPTIONAL - ); + ); /** Transfers control to a function starting with a new stack. @@ -340,126 +333,6 @@ InternalSwitchStack ( ); -/** - Worker function that locates the Node in the List. - - By searching the List, finds the location of the Node in List. At the same time, - verifies the validity of this list. - - If List is NULL, then ASSERT(). - If List->ForwardLink is NULL, then ASSERT(). - If List->backLink is NULL, then ASSERT(). - If Node is NULL, then ASSERT(); - If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number - of nodes in ListHead, including the ListHead node, is greater than or - equal to PcdMaximumLinkedListLength, then ASSERT(). - - @param List A pointer to a node in a linked list. - @param Node A pointer to one nod. - - @retval TRUE Node is in List - @retval FALSE Node isn't in List, or List is invalid - -**/ -BOOLEAN -EFIAPI -IsNodeInList ( - IN CONST LIST_ENTRY *List, - IN CONST LIST_ENTRY *Node - ); - - -/** - Performs an atomic increment of an 32-bit unsigned integer. - - Performs an atomic increment of the 32-bit unsigned integer specified by - Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. - - @param Value A pointer to the 32-bit value to increment. - - @return The incremented value. - -**/ -UINT32 -EFIAPI -InternalSyncIncrement ( - IN volatile UINT32 *Value - ); - - -/** - Performs an atomic decrement of an 32-bit unsigned integer. - - Performs an atomic decrement of the 32-bit unsigned integer specified by - Value and returns the decrement value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. - - @param Value A pointer to the 32-bit value to decrement. - - @return The decrement value. - -**/ -UINT32 -EFIAPI -InternalSyncDecrement ( - IN volatile UINT32 *Value - ); - - -/** - Performs an atomic compare exchange operation on a 32-bit unsigned integer. - - Performs an atomic compare exchange operation on the 32-bit unsigned integer - specified by Value. If Value is equal to CompareValue, then Value is set to - ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue, - then Value is returned. The compare exchange operation must be performed using - MP safe mechanisms. - - @param Value A pointer to the 32-bit value for the compare exchange - operation. - @param CompareValue 32-bit value used in compare operation. - @param ExchangeValue 32-bit value used in exchange operation. - - @return The original *Value before exchange. - -**/ -UINT32 -EFIAPI -InternalSyncCompareExchange32 ( - IN volatile UINT32 *Value, - IN UINT32 CompareValue, - IN UINT32 ExchangeValue - ); - - -/** - Performs an atomic compare exchange operation on a 64-bit unsigned integer. - - Performs an atomic compare exchange operation on the 64-bit unsigned integer specified - by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and - CompareValue is returned. If Value is not equal to CompareValue, then Value is returned. - The compare exchange operation must be performed using MP safe mechanisms. - - @param Value A pointer to the 64-bit value for the compare exchange - operation. - @param CompareValue 64-bit value used in compare operation. - @param ExchangeValue 64-bit value used in exchange operation. - - @return The original *Value before exchange. - -**/ -UINT64 -EFIAPI -InternalSyncCompareExchange64 ( - IN volatile UINT64 *Value, - IN UINT64 CompareValue, - IN UINT64 ExchangeValue - ); - - /** Worker function that returns a bit field from Operand. @@ -472,10 +345,10 @@ InternalSyncCompareExchange64 ( @return The bit field read. **/ -unsigned int +UINTN EFIAPI BitFieldReadUint ( - IN unsigned int Operand, + IN UINTN Operand, IN UINTN StartBit, IN UINTN EndBit ); @@ -497,13 +370,13 @@ BitFieldReadUint ( @return The new value. **/ -unsigned int +UINTN EFIAPI BitFieldOrUint ( - IN unsigned int Operand, + IN UINTN Operand, IN UINTN StartBit, IN UINTN EndBit, - IN unsigned int OrData + IN UINTN OrData ); @@ -523,13 +396,13 @@ BitFieldOrUint ( @return The new value. **/ -unsigned int +UINTN EFIAPI BitFieldAndUint ( - IN unsigned int Operand, + IN UINTN Operand, IN UINTN StartBit, IN UINTN EndBit, - IN unsigned int AndData + IN UINTN AndData ); @@ -570,6 +443,128 @@ InternalLongJump ( ); +/** + Check if a Unicode character is a decimal character. + + This internal function checks if a Unicode character is a + decimal character. The valid decimal character is from + L'0' to L'9'. + + @param Char The character to check against. + + @retval TRUE If the Char is a decmial character. + @retval FALSE If the Char is not a decmial character. + +**/ +BOOLEAN +EFIAPI +InternalIsDecimalDigitCharacter ( + IN CHAR16 Char + ); + + +/** + Convert a Unicode character to numerical value. + + This internal function only deal with Unicode character + which maps to a valid hexadecimal ASII character, i.e. + L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other + Unicode character, the value returned does not make sense. + + @param Char The character to convert. + + @return The numerical value converted. + +**/ +UINTN +EFIAPI +InternalHexCharToUintn ( + IN CHAR16 Char + ); + + +/** + Check if a Unicode character is a hexadecimal character. + + This internal function checks if a Unicode character is a + decimal character. The valid hexadecimal character is + L'0' to L'9', L'a' to L'f', or L'A' to L'F'. + + + @param Char The character to check against. + + @retval TRUE If the Char is a hexadecmial character. + @retval FALSE If the Char is not a hexadecmial character. + +**/ +BOOLEAN +EFIAPI +InternalIsHexaDecimalDigitCharacter ( + IN CHAR16 Char + ); + + +/** + Check if a ASCII character is a decimal character. + + This internal function checks if a Unicode character is a + decimal character. The valid decimal character is from + '0' to '9'. + + @param Char The character to check against. + + @retval TRUE If the Char is a decmial character. + @retval FALSE If the Char is not a decmial character. + +**/ +BOOLEAN +EFIAPI +InternalAsciiIsDecimalDigitCharacter ( + IN CHAR8 Char + ); + + +/** + Check if a ASCII character is a hexadecimal character. + + This internal function checks if a ASCII character is a + decimal character. The valid hexadecimal character is + L'0' to L'9', L'a' to L'f', or L'A' to L'F'. + + + @param Char The character to check against. + + @retval TRUE If the Char is a hexadecmial character. + @retval FALSE If the Char is not a hexadecmial character. + +**/ +BOOLEAN +EFIAPI +InternalAsciiIsHexaDecimalDigitCharacter ( + IN CHAR8 Char + ); + + +/** + Convert a ASCII character to numerical value. + + This internal function only deal with Unicode character + which maps to a valid hexadecimal ASII character, i.e. + '0' to '9', 'a' to 'f' or 'A' to 'F'. For other + ASCII character, the value returned does not make sense. + + @param Char The character to convert. + + @return The numerical value converted. + +**/ +UINTN +EFIAPI +InternalAsciiHexCharToUintn ( + IN CHAR8 Char + ); + + // // Ia32 and x64 specific functions // @@ -579,9 +574,9 @@ InternalLongJump ( Reads the current Global Descriptor Table Register(GDTR) descriptor. Reads and returns the current GDTR descriptor and returns it in Gdtr. This - function is only available on IA-32 and X64. + function is only available on IA-32 and x64. - @param Gdtr Pointer to a GDTR descriptor. + @param Gdtr The pointer to a GDTR descriptor. **/ VOID @@ -594,9 +589,9 @@ InternalX86ReadGdtr ( Writes the current Global Descriptor Table Register (GDTR) descriptor. Writes and the current GDTR descriptor specified by Gdtr. This function is - only available on IA-32 and X64. + only available on IA-32 and x64. - @param Gdtr Pointer to a GDTR descriptor. + @param Gdtr The pointer to a GDTR descriptor. **/ VOID @@ -609,9 +604,9 @@ InternalX86WriteGdtr ( Reads the current Interrupt Descriptor Table Register(GDTR) descriptor. Reads and returns the current IDTR descriptor and returns it in Idtr. This - function is only available on IA-32 and X64. + function is only available on IA-32 and x64. - @param Idtr Pointer to a IDTR descriptor. + @param Idtr The pointer to an IDTR descriptor. **/ VOID @@ -624,9 +619,9 @@ InternalX86ReadIdtr ( Writes the current Interrupt Descriptor Table Register(GDTR) descriptor. Writes the current IDTR descriptor and returns it in Idtr. This function is - only available on IA-32 and X64. + only available on IA-32 and x64. - @param Idtr Pointer to a IDTR descriptor. + @param Idtr The pointer to an IDTR descriptor. **/ VOID @@ -640,9 +635,9 @@ InternalX86WriteIdtr ( Saves the current floating point/SSE/SSE2 state to the buffer specified by Buffer. Buffer must be aligned on a 16-byte boundary. This function is only - available on IA-32 and X64. + available on IA-32 and x64. - @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context. + @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context. **/ VOID @@ -656,9 +651,9 @@ InternalX86FxSave ( Restores the current floating point/SSE/SSE2 state from the buffer specified by Buffer. Buffer must be aligned on a 16-byte boundary. This function is - only available on IA-32 and X64. + only available on IA-32 and x64. - @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context. + @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context. **/ VOID @@ -790,7 +785,7 @@ InternalX86EnablePaging64 ( Disables the 64-bit paging mode on the CPU and returns to 32-bit protected mode. This function assumes the current execution mode is 64-paging mode. - This function is only available on X64. After the 64-bit paging mode is + This function is only available on x64. After the 64-bit paging mode is disabled, control is transferred to the function specified by EntryPoint using the new stack specified by NewStack and passing in the parameters specified by Context1 and Context2. Context1 and Context2 are optional and @@ -821,44 +816,52 @@ InternalX86DisablePaging64 ( IN UINT32 NewStack ); +/** + Generates a 16-bit random number through RDRAND instruction. -#elif defined (MDE_CPU_IPF) -// -// -// IPF specific functions -// + @param[out] Rand Buffer pointer to store the random result. + + @retval TRUE RDRAND call was successful. + @retval FALSE Failed attempts to call RDRAND. + + **/ +BOOLEAN +EFIAPI +InternalX86RdRand16 ( + OUT UINT16 *Rand + ); /** - Transfers control to a function starting with a new stack. + Generates a 32-bit random number through RDRAND instruction. - Transfers control to the function specified by EntryPoint using the new stack - specified by NewStack and passing in the parameters specified by Context1 and - Context2. Context1 and Context2 are optional and may be NULL. The function - EntryPoint must never return. + @param[out] Rand Buffer pointer to store the random result. - If EntryPoint is NULL, then ASSERT(). - If NewStack is NULL, then ASSERT(). + @retval TRUE RDRAND call was successful. + @retval FALSE Failed attempts to call RDRAND. - @param EntryPoint A pointer to function to call with the new stack. - @param Context1 A pointer to the context to pass into the EntryPoint - function. - @param Context2 A pointer to the context to pass into the EntryPoint - function. - @param NewStack A pointer to the new stack to use for the EntryPoint - function. - @param NewBsp A pointer to the new memory location for RSE backing - store. +**/ +BOOLEAN +EFIAPI +InternalX86RdRand32 ( + OUT UINT32 *Rand + ); + +/** + Generates a 64-bit random number through RDRAND instruction. + + + @param[out] Rand Buffer pointer to store the random result. + + @retval TRUE RDRAND call was successful. + @retval FALSE Failed attempts to call RDRAND. **/ -VOID +BOOLEAN EFIAPI -AsmSwitchStackAndBackingStore ( - IN SWITCH_STACK_ENTRY_POINT EntryPoint, - IN VOID *Context1, OPTIONAL - IN VOID *Context2, OPTIONAL - IN VOID *NewStack, - IN VOID *NewBsp +InternalX86RdRand64 ( + OUT UINT64 *Rand ); + #else #endif