From 582510249f2fb1334e507b99421b9485f6b89159 Mon Sep 17 00:00:00 2001 From: xli24 Date: Thu, 25 Jan 2007 06:05:36 +0000 Subject: Make MDE package pass intel IPF compiler with /W4 /WX switched on. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2312 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/BaseLib/BaseLibInternals.h | 215 +++++++++++++++++++++++++++ MdePkg/Library/BaseLib/BitField.c | 22 ++- MdePkg/Library/BaseLib/Ipf/Synchronization.c | 25 +--- MdePkg/Library/BaseLib/Ipf/Unaligned.c | 22 ++- MdePkg/Library/BaseLib/LinkedList.c | 2 + MdePkg/Library/BaseLib/LongJump.c | 34 +---- MdePkg/Library/BaseLib/Math64.c | 16 +- MdePkg/Library/BaseLib/SetJump.c | 2 + MdePkg/Library/BaseLib/String.c | 18 ++- MdePkg/Library/BaseLib/SwapBytes16.c | 2 +- MdePkg/Library/BaseLib/SwapBytes32.c | 11 +- MdePkg/Library/BaseLib/Synchronization.c | 95 +----------- 12 files changed, 291 insertions(+), 173 deletions(-) (limited to 'MdePkg/Library/BaseLib') diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h b/MdePkg/Library/BaseLib/BaseLibInternals.h index e9caef3e58..d0b9ef6f20 100644 --- a/MdePkg/Library/BaseLib/BaseLibInternals.h +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h @@ -575,4 +575,219 @@ InternalX86DisablePaging64 ( IN UINT32 NewStack ); +/** + 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 +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 + + Returns the bitfield specified by the StartBit and the EndBit from Operand. + + @param Operand Operand on which to perform the bitfield operation. + @param StartBit The ordinal of the least significant bit in the bit field. + @param EndBit The ordinal of the most significant bit in the bit field. + + @return The bit field read. + +**/ +unsigned int +BitFieldReadUint ( + IN unsigned int Operand, + IN UINTN StartBit, + IN UINTN EndBit + ); + +/** + Worker function that reads a bit field from Operand, performs a bitwise OR, + and returns the result. + + Performs a bitwise OR between the bit field specified by StartBit and EndBit + in Operand and the value specified by AndData. All other bits in Operand are + preserved. The new value is returned. + + @param Operand Operand on which to perform the bitfield operation. + @param StartBit The ordinal of the least significant bit in the bit field. + @param EndBit The ordinal of the most significant bit in the bit field. + @param OrData The value to OR with the read value from the value + + @return The new value. + +**/ +unsigned int +BitFieldOrUint ( + IN unsigned int Operand, + IN UINTN StartBit, + IN UINTN EndBit, + IN unsigned int OrData + ); + +/** + Worker function that reads a bit field from Operand, performs a bitwise AND, + and returns the result. + + Performs a bitwise AND between the bit field specified by StartBit and EndBit + in Operand and the value specified by AndData. All other bits in Operand are + preserved. The new value is returned. + + @param Operand Operand on which to perform the bitfield operation. + @param StartBit The ordinal of the least significant bit in the bit field. + @param EndBit The ordinal of the most significant bit in the bit field. + @param AndData The value to And with the read value from the value + + @return The new value. + +**/ +unsigned int +BitFieldAndUint ( + IN unsigned int Operand, + IN UINTN StartBit, + IN UINTN EndBit, + IN unsigned int AndData + ); + +/** + Worker function that checks ASSERT condition for JumpBuffer + + Checks ASSERT condition for JumpBuffer. + + If JumpBuffer is NULL, then ASSERT(). + For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT(). + + @param JumpBuffer A pointer to CPU context buffer. + +**/ +VOID +InternalAssertJumpBuffer ( + IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer + ); + +/** + Restores the CPU context that was saved with SetJump(). + + Restores the CPU context from the buffer specified by JumpBuffer. + This function never returns to the caller. + Instead is resumes execution based on the state of JumpBuffer. + + @param JumpBuffer A pointer to CPU context buffer. + @param Value The value to return when the SetJump() context is restored. + +**/ +VOID +EFIAPI +InternalLongJump ( + IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer, + IN UINTN Value + ); + #endif diff --git a/MdePkg/Library/BaseLib/BitField.c b/MdePkg/Library/BaseLib/BitField.c index 0b517aa974..3db8a23c95 100644 --- a/MdePkg/Library/BaseLib/BitField.c +++ b/MdePkg/Library/BaseLib/BitField.c @@ -14,6 +14,8 @@ **/ +#include "BaseLibInternals.h" + /** Worker function that returns a bit field from Operand @@ -763,10 +765,16 @@ BitFieldOr64 ( IN UINT64 OrData ) { + UINT64 Value1; + UINT64 Value2; + ASSERT (EndBit < sizeof (Operand) * 8); ASSERT (StartBit <= EndBit); - return Operand | - (LShiftU64 (OrData, StartBit) & ~LShiftU64 ((UINT64)-2, EndBit)); + + Value1 = LShiftU64 (OrData, StartBit); + Value2 = LShiftU64 ((UINT64) - 2, EndBit); + + return Operand | (Value1 & ~Value2); } /** @@ -801,10 +809,16 @@ BitFieldAnd64 ( IN UINT64 AndData ) { + UINT64 Value1; + UINT64 Value2; + ASSERT (EndBit < sizeof (Operand) * 8); ASSERT (StartBit <= EndBit); - return Operand & - ~(LShiftU64 (~AndData, StartBit) & ~LShiftU64 ((UINT64)-2, EndBit)); + + Value1 = LShiftU64 (~AndData, StartBit); + Value2 = LShiftU64 ((UINT64)-2, EndBit); + + return Operand & ~(Value1 & ~Value2); } /** diff --git a/MdePkg/Library/BaseLib/Ipf/Synchronization.c b/MdePkg/Library/BaseLib/Ipf/Synchronization.c index 44593e1778..c29a8763d3 100644 --- a/MdePkg/Library/BaseLib/Ipf/Synchronization.c +++ b/MdePkg/Library/BaseLib/Ipf/Synchronization.c @@ -14,30 +14,7 @@ **/ -/** - 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 - ); +#include "BaseLibInternals.h" /** Performs an atomic increment of an 32-bit unsigned integer. diff --git a/MdePkg/Library/BaseLib/Ipf/Unaligned.c b/MdePkg/Library/BaseLib/Ipf/Unaligned.c index 30e5b15c5f..fc634044b9 100644 --- a/MdePkg/Library/BaseLib/Ipf/Unaligned.c +++ b/MdePkg/Library/BaseLib/Ipf/Unaligned.c @@ -143,12 +143,15 @@ ReadUnaligned32 ( IN CONST UINT32 *Buffer ) { + UINT16 LowerBytes; + UINT16 HigherBytes; + ASSERT (Buffer != NULL); - return (UINT32)( - ReadUnaligned16 ((UINT16*)Buffer) | - (ReadUnaligned16 ((UINT16*)Buffer + 1) << 16) - ); + LowerBytes = ReadUnaligned16 ((UINT16*) Buffer); + HigherBytes = ReadUnaligned16 ((UINT16*) Buffer + 1); + + return (UINT32) (LowerBytes | (HigherBytes << 16)); } /** @@ -199,12 +202,15 @@ ReadUnaligned64 ( IN CONST UINT64 *Buffer ) { + UINT32 LowerBytes; + UINT32 HigherBytes; + ASSERT (Buffer != NULL); - return (UINT64)( - ReadUnaligned32 ((UINT32*)Buffer) | - LShiftU64 (ReadUnaligned32 ((UINT32*)Buffer + 1), 32) - ); + LowerBytes = ReadUnaligned32 ((UINT32*) Buffer); + HigherBytes = ReadUnaligned32 ((UINT32*) Buffer + 1); + + return (UINT64) (LowerBytes | LShiftU64 (HigherBytes, 32)); } /** diff --git a/MdePkg/Library/BaseLib/LinkedList.c b/MdePkg/Library/BaseLib/LinkedList.c index 9347a2b579..f588eacd0c 100644 --- a/MdePkg/Library/BaseLib/LinkedList.c +++ b/MdePkg/Library/BaseLib/LinkedList.c @@ -14,6 +14,8 @@ **/ +#include "BaseLibInternals.h" + /** Worker function that locates the Node in the List diff --git a/MdePkg/Library/BaseLib/LongJump.c b/MdePkg/Library/BaseLib/LongJump.c index a18c974e91..90a915e233 100644 --- a/MdePkg/Library/BaseLib/LongJump.c +++ b/MdePkg/Library/BaseLib/LongJump.c @@ -14,39 +14,7 @@ **/ -/** - Worker function that checks ASSERT condition for JumpBuffer - - Checks ASSERT condition for JumpBuffer. - - If JumpBuffer is NULL, then ASSERT(). - For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT(). - - @param JumpBuffer A pointer to CPU context buffer. - -**/ -VOID -InternalAssertJumpBuffer ( - IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer - ); - -/** - Restores the CPU context that was saved with SetJump(). - - Restores the CPU context from the buffer specified by JumpBuffer. - This function never returns to the caller. - Instead is resumes execution based on the state of JumpBuffer. - - @param JumpBuffer A pointer to CPU context buffer. - @param Value The value to return when the SetJump() context is restored. - -**/ -VOID -EFIAPI -InternalLongJump ( - IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer, - IN UINTN Value - ); +#include "BaseLibInternals.h" /** Restores the CPU context that was saved with SetJump(). diff --git a/MdePkg/Library/BaseLib/Math64.c b/MdePkg/Library/BaseLib/Math64.c index 3312d789ac..514ae99020 100644 --- a/MdePkg/Library/BaseLib/Math64.c +++ b/MdePkg/Library/BaseLib/Math64.c @@ -85,10 +85,13 @@ InternalMathARShiftU64 ( IN UINTN Count ) { + INTN TestValue; + // // Test if this compiler supports arithmetic shift // - if ((((-1) << (sizeof (-1) * 8 - 1)) >> (sizeof (-1) * 8 - 1)) == -1) { + TestValue = (((-1) << (sizeof (-1) * 8 - 1)) >> (sizeof (-1) * 8 - 1)); + if (TestValue == -1) { // // Arithmetic shift is supported // @@ -169,10 +172,13 @@ InternalMathSwapBytes64 ( IN UINT64 Operand ) { - return (UINT64)( - ((UINT64)SwapBytes32 ((UINT32)Operand) << 32) | - ((UINT64)SwapBytes32 ((UINT32)(Operand >> 32))) - ); + UINT64 LowerBytes; + UINT64 HigherBytes; + + LowerBytes = (UINT64) SwapBytes32 ((UINT32) Operand); + HigherBytes = (UINT64) SwapBytes32 ((UINT32) (Operand >> 32)); + + return (LowerBytes << 32 | HigherBytes); } /** diff --git a/MdePkg/Library/BaseLib/SetJump.c b/MdePkg/Library/BaseLib/SetJump.c index f03479ae81..cb77d09611 100644 --- a/MdePkg/Library/BaseLib/SetJump.c +++ b/MdePkg/Library/BaseLib/SetJump.c @@ -14,6 +14,8 @@ **/ +#include "BaseLibInternals.h" + /** Worker function that checks ASSERT condition for JumpBuffer diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c index 2ac32254fc..7db468aee5 100644 --- a/MdePkg/Library/BaseLib/String.c +++ b/MdePkg/Library/BaseLib/String.c @@ -636,7 +636,7 @@ AsciiToUpper ( IN CHAR8 Chr ) { - return (Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr; + return (UINT8) ((Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr); } /** @@ -675,19 +675,25 @@ AsciiStriCmp ( IN CONST CHAR8 *SecondString ) { + CHAR8 UpperFirstString; + CHAR8 UpperSecondString; + // // ASSERT both strings are less long than PcdMaximumAsciiStringLength // ASSERT (AsciiStrSize (FirstString)); ASSERT (AsciiStrSize (SecondString)); - while ((*FirstString != '\0') && - (AsciiToUpper (*FirstString) == AsciiToUpper (*SecondString))) { + UpperFirstString = AsciiToUpper (*FirstString); + UpperSecondString = AsciiToUpper (*SecondString); + while ((*FirstString != '\0') && (UpperFirstString == UpperSecondString)) { FirstString++; SecondString++; + UpperFirstString = AsciiToUpper (*FirstString); + UpperSecondString = AsciiToUpper (*SecondString); } - return AsciiToUpper (*FirstString) - AsciiToUpper (*SecondString); + return UpperFirstString - UpperSecondString; } /** @@ -861,7 +867,7 @@ DecimalToBcd8 ( ) { ASSERT (Value < 100); - return ((Value / 10) << 4) | (Value % 10); + return (UINT8) (((Value / 10) << 4) | (Value % 10)); } /** @@ -886,5 +892,5 @@ BcdToDecimal8 ( { ASSERT (Value < 0xa0); ASSERT ((Value & 0xf) < 0xa); - return (Value >> 4) * 10 + (Value & 0xf); + return (UINT8) ((Value >> 4) * 10 + (Value & 0xf)); } diff --git a/MdePkg/Library/BaseLib/SwapBytes16.c b/MdePkg/Library/BaseLib/SwapBytes16.c index c8460a28f7..134ccb1ef0 100644 --- a/MdePkg/Library/BaseLib/SwapBytes16.c +++ b/MdePkg/Library/BaseLib/SwapBytes16.c @@ -32,5 +32,5 @@ SwapBytes16 ( IN UINT16 Operand ) { - return (Operand << 8) | (Operand >> 8); + return (UINT16) ((Operand << 8) | (Operand >> 8)); } diff --git a/MdePkg/Library/BaseLib/SwapBytes32.c b/MdePkg/Library/BaseLib/SwapBytes32.c index 4e683b09d1..09396dba4e 100644 --- a/MdePkg/Library/BaseLib/SwapBytes32.c +++ b/MdePkg/Library/BaseLib/SwapBytes32.c @@ -32,8 +32,11 @@ SwapBytes32 ( IN UINT32 Operand ) { - return (UINT32)( - ((UINT32)SwapBytes16 ((UINT16)Operand) << 16) | - ((UINT32)SwapBytes16 ((UINT16)(Operand >> 16))) - ); + UINT32 LowerBytes; + UINT32 HigherBytes; + + LowerBytes = (UINT32) SwapBytes16 ((UINT16) Operand); + HigherBytes = (UINT32) SwapBytes16 ((UINT16) (Operand >> 16)); + + return (LowerBytes << 16 | HigherBytes); } diff --git a/MdePkg/Library/BaseLib/Synchronization.c b/MdePkg/Library/BaseLib/Synchronization.c index 18812e242f..e08aa62cf9 100644 --- a/MdePkg/Library/BaseLib/Synchronization.c +++ b/MdePkg/Library/BaseLib/Synchronization.c @@ -14,96 +14,11 @@ **/ +#include "BaseLibInternals.h" + #define SPIN_LOCK_RELEASED ((SPIN_LOCK)1) #define SPIN_LOCK_ACQUIRED ((SPIN_LOCK)2) -/** - 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 - ); - /** Retrieves the architecture specific spin lock alignment requirements for optimal spin lock performance. @@ -419,7 +334,11 @@ InterlockedCompareExchangePointer ( IN VOID *ExchangeValue ) { - switch (sizeof (*Value)) { + UINT8 SizeOfValue; + + SizeOfValue = sizeof (*Value); + + switch (SizeOfValue) { case sizeof (UINT32): return (VOID*)(UINTN)InterlockedCompareExchange32 ( (UINT32*)Value, -- cgit v1.2.3