2007-06-22 05:21:45 +02:00
|
|
|
/** @file
|
|
|
|
Bit field functions of BaseLib.
|
|
|
|
|
2013-07-22 08:35:48 +02:00
|
|
|
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
|
2010-04-23 18:00:47 +02:00
|
|
|
This program and the accompanying materials
|
2007-06-22 05:21:45 +02:00
|
|
|
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
|
2010-06-24 02:20:35 +02:00
|
|
|
http://opensource.org/licenses/bsd-license.php.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "BaseLibInternals.h"
|
|
|
|
|
|
|
|
/**
|
2008-12-11 03:59:41 +01:00
|
|
|
Worker function that returns a bit field from Operand.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
**/
|
2008-09-24 10:31:38 +02:00
|
|
|
UINTN
|
2008-07-08 11:38:43 +02:00
|
|
|
EFIAPI
|
2009-07-23 03:43:04 +02:00
|
|
|
InternalBaseLibBitFieldReadUint (
|
2008-09-24 10:31:38 +02:00
|
|
|
IN UINTN Operand,
|
2007-06-22 05:21:45 +02:00
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
2008-09-24 10:31:38 +02:00
|
|
|
// ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
|
2007-06-22 05:21:45 +02:00
|
|
|
// are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
|
|
|
|
//
|
2008-09-24 10:31:38 +02:00
|
|
|
return (Operand & ~((UINTN)-2 << EndBit)) >> StartBit;
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-11 03:59:41 +01:00
|
|
|
Worker function that reads a bit field from Operand, performs a bitwise OR,
|
2007-06-22 05:21:45 +02:00
|
|
|
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.
|
|
|
|
|
2012-12-25 03:25:50 +01:00
|
|
|
If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
|
|
|
|
2007-06-22 05:21:45 +02:00
|
|
|
@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.
|
2010-06-24 02:20:35 +02:00
|
|
|
@param OrData The value to OR with the read value from the value.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new value.
|
|
|
|
|
|
|
|
**/
|
2008-09-24 10:31:38 +02:00
|
|
|
UINTN
|
2008-07-08 11:38:43 +02:00
|
|
|
EFIAPI
|
2009-07-23 03:43:04 +02:00
|
|
|
InternalBaseLibBitFieldOrUint (
|
2008-09-24 10:31:38 +02:00
|
|
|
IN UINTN Operand,
|
2007-06-22 05:21:45 +02:00
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
2008-09-24 10:31:38 +02:00
|
|
|
IN UINTN OrData
|
2007-06-22 05:21:45 +02:00
|
|
|
)
|
|
|
|
{
|
2012-12-25 03:25:50 +01:00
|
|
|
//
|
|
|
|
// Higher bits in OrData those are not used must be zero.
|
|
|
|
//
|
2013-07-22 08:41:52 +02:00
|
|
|
// EndBit - StartBit + 1 might be 32 while the result right shifting 32 on a 32bit integer is undefined,
|
|
|
|
// So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
|
2013-07-22 08:35:48 +02:00
|
|
|
//
|
|
|
|
ASSERT ((OrData >> (EndBit - StartBit)) == ((OrData >> (EndBit - StartBit)) & 1));
|
2012-12-25 03:25:50 +01:00
|
|
|
|
2007-06-22 05:21:45 +02:00
|
|
|
//
|
2008-09-24 10:31:38 +02:00
|
|
|
// ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
|
2007-06-22 05:21:45 +02:00
|
|
|
// are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
|
|
|
|
//
|
2008-09-24 10:31:38 +02:00
|
|
|
return Operand | ((OrData << StartBit) & ~((UINTN) -2 << EndBit));
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-11 03:59:41 +01:00
|
|
|
Worker function that reads a bit field from Operand, performs a bitwise AND,
|
2007-06-22 05:21:45 +02:00
|
|
|
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.
|
|
|
|
|
2012-12-25 03:25:50 +01:00
|
|
|
If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
|
|
|
|
2007-06-22 05:21:45 +02:00
|
|
|
@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.
|
2010-06-24 02:20:35 +02:00
|
|
|
@param AndData The value to And with the read value from the value.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new value.
|
|
|
|
|
|
|
|
**/
|
2008-09-24 10:31:38 +02:00
|
|
|
UINTN
|
2008-07-08 11:38:43 +02:00
|
|
|
EFIAPI
|
2009-07-23 03:43:04 +02:00
|
|
|
InternalBaseLibBitFieldAndUint (
|
2008-09-24 10:31:38 +02:00
|
|
|
IN UINTN Operand,
|
2007-06-22 05:21:45 +02:00
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
2008-09-24 10:31:38 +02:00
|
|
|
IN UINTN AndData
|
2007-06-22 05:21:45 +02:00
|
|
|
)
|
|
|
|
{
|
2012-12-25 03:25:50 +01:00
|
|
|
//
|
|
|
|
// Higher bits in AndData those are not used must be zero.
|
|
|
|
//
|
2013-07-22 08:41:52 +02:00
|
|
|
// EndBit - StartBit + 1 might be 32 while the result right shifting 32 on a 32bit integer is undefined,
|
|
|
|
// So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
|
2013-07-22 08:35:48 +02:00
|
|
|
//
|
|
|
|
ASSERT ((AndData >> (EndBit - StartBit)) == ((AndData >> (EndBit - StartBit)) & 1));
|
2012-12-25 03:25:50 +01:00
|
|
|
|
2007-06-22 05:21:45 +02:00
|
|
|
//
|
2008-09-24 10:31:38 +02:00
|
|
|
// ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]
|
2007-06-22 05:21:45 +02:00
|
|
|
// are 1's while bit[EndBit + 1] thru the most significant bit are 0's.
|
|
|
|
//
|
2008-09-24 10:31:38 +02:00
|
|
|
return Operand & ~((~AndData << StartBit) & ~((UINTN)-2 << EndBit));
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a bit field from an 8-bit value.
|
|
|
|
|
|
|
|
Returns the bitfield specified by the StartBit and the EndBit from Operand.
|
|
|
|
|
|
|
|
If 8-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 7, then ASSERT().
|
|
|
|
If EndBit is greater than 7, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..7.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..7.
|
|
|
|
|
|
|
|
@return The bit field read.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT8
|
|
|
|
EFIAPI
|
|
|
|
BitFieldRead8 (
|
|
|
|
IN UINT8 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 8);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2009-07-23 03:43:04 +02:00
|
|
|
return (UINT8)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBit);
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Writes a bit field to an 8-bit value, and returns the result.
|
|
|
|
|
|
|
|
Writes Value to the bit field specified by the StartBit and the EndBit in
|
|
|
|
Operand. All other bits in Operand are preserved. The new 8-bit value is
|
|
|
|
returned.
|
|
|
|
|
|
|
|
If 8-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 7, then ASSERT().
|
|
|
|
If EndBit is greater than 7, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..7.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..7.
|
2010-06-25 23:56:02 +02:00
|
|
|
@param Value The new value of the bit field.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new 8-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT8
|
|
|
|
EFIAPI
|
|
|
|
BitFieldWrite8 (
|
|
|
|
IN UINT8 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT8 Value
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 8);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
|
|
|
return BitFieldAndThenOr8 (Operand, StartBit, EndBit, 0, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
|
|
|
|
result.
|
|
|
|
|
2008-12-05 10:50:02 +01:00
|
|
|
Performs a bitwise OR between the bit field specified by StartBit
|
2007-06-22 05:21:45 +02:00
|
|
|
and EndBit in Operand and the value specified by OrData. All other bits in
|
|
|
|
Operand are preserved. The new 8-bit value is returned.
|
|
|
|
|
|
|
|
If 8-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 7, then ASSERT().
|
|
|
|
If EndBit is greater than 7, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..7.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..7.
|
2010-06-24 02:20:35 +02:00
|
|
|
@param OrData The value to OR with the read value from the value.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new 8-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT8
|
|
|
|
EFIAPI
|
|
|
|
BitFieldOr8 (
|
|
|
|
IN UINT8 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT8 OrData
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 8);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2009-07-23 03:43:04 +02:00
|
|
|
return (UINT8)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit, OrData);
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from an 8-bit value, 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 8-bit value is returned.
|
|
|
|
|
|
|
|
If 8-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 7, then ASSERT().
|
|
|
|
If EndBit is greater than 7, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..7.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..7.
|
|
|
|
@param AndData The value to AND with the read value from the value.
|
|
|
|
|
|
|
|
@return The new 8-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT8
|
|
|
|
EFIAPI
|
|
|
|
BitFieldAnd8 (
|
|
|
|
IN UINT8 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT8 AndData
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 8);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2009-07-23 03:43:04 +02:00
|
|
|
return (UINT8)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit, AndData);
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
|
|
|
|
bitwise OR, and returns the result.
|
|
|
|
|
|
|
|
Performs a bitwise AND between the bit field specified by StartBit and EndBit
|
2008-12-05 10:50:02 +01:00
|
|
|
in Operand and the value specified by AndData, followed by a bitwise
|
|
|
|
OR with value specified by OrData. All other bits in Operand are
|
2007-06-22 05:21:45 +02:00
|
|
|
preserved. The new 8-bit value is returned.
|
|
|
|
|
|
|
|
If 8-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 7, then ASSERT().
|
|
|
|
If EndBit is greater than 7, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
|
|
|
If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..7.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..7.
|
|
|
|
@param AndData The value to AND with the read value from the value.
|
|
|
|
@param OrData The value to OR with the result of the AND operation.
|
|
|
|
|
|
|
|
@return The new 8-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT8
|
|
|
|
EFIAPI
|
|
|
|
BitFieldAndThenOr8 (
|
|
|
|
IN UINT8 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT8 AndData,
|
|
|
|
IN UINT8 OrData
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 8);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
|
|
|
return BitFieldOr8 (
|
|
|
|
BitFieldAnd8 (Operand, StartBit, EndBit, AndData),
|
|
|
|
StartBit,
|
|
|
|
EndBit,
|
|
|
|
OrData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a bit field from a 16-bit value.
|
|
|
|
|
|
|
|
Returns the bitfield specified by the StartBit and the EndBit from Operand.
|
|
|
|
|
|
|
|
If 16-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 15, then ASSERT().
|
|
|
|
If EndBit is greater than 15, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..15.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..15.
|
|
|
|
|
|
|
|
@return The bit field read.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT16
|
|
|
|
EFIAPI
|
|
|
|
BitFieldRead16 (
|
|
|
|
IN UINT16 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 16);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2009-07-23 03:43:04 +02:00
|
|
|
return (UINT16)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBit);
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Writes a bit field to a 16-bit value, and returns the result.
|
|
|
|
|
|
|
|
Writes Value to the bit field specified by the StartBit and the EndBit in
|
|
|
|
Operand. All other bits in Operand are preserved. The new 16-bit value is
|
|
|
|
returned.
|
|
|
|
|
|
|
|
If 16-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 15, then ASSERT().
|
|
|
|
If EndBit is greater than 15, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..15.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..15.
|
2010-06-25 23:56:02 +02:00
|
|
|
@param Value The new value of the bit field.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new 16-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT16
|
|
|
|
EFIAPI
|
|
|
|
BitFieldWrite16 (
|
|
|
|
IN UINT16 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT16 Value
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 16);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
|
|
|
return BitFieldAndThenOr16 (Operand, StartBit, EndBit, 0, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
|
|
|
|
result.
|
|
|
|
|
2008-12-05 10:50:02 +01:00
|
|
|
Performs a bitwise OR between the bit field specified by StartBit
|
2007-06-22 05:21:45 +02:00
|
|
|
and EndBit in Operand and the value specified by OrData. All other bits in
|
|
|
|
Operand are preserved. The new 16-bit value is returned.
|
|
|
|
|
|
|
|
If 16-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 15, then ASSERT().
|
|
|
|
If EndBit is greater than 15, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..15.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..15.
|
2010-06-24 02:20:35 +02:00
|
|
|
@param OrData The value to OR with the read value from the value.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new 16-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT16
|
|
|
|
EFIAPI
|
|
|
|
BitFieldOr16 (
|
|
|
|
IN UINT16 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT16 OrData
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 16);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2009-07-23 03:43:04 +02:00
|
|
|
return (UINT16)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit, OrData);
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from a 16-bit value, 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 16-bit value is returned.
|
|
|
|
|
|
|
|
If 16-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 15, then ASSERT().
|
|
|
|
If EndBit is greater than 15, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..15.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..15.
|
2010-06-24 02:20:35 +02:00
|
|
|
@param AndData The value to AND with the read value from the value.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new 16-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT16
|
|
|
|
EFIAPI
|
|
|
|
BitFieldAnd16 (
|
|
|
|
IN UINT16 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT16 AndData
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 16);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2009-07-23 03:43:04 +02:00
|
|
|
return (UINT16)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit, AndData);
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
|
|
|
|
bitwise OR, and returns the result.
|
|
|
|
|
|
|
|
Performs a bitwise AND between the bit field specified by StartBit and EndBit
|
2008-12-05 10:50:02 +01:00
|
|
|
in Operand and the value specified by AndData, followed by a bitwise
|
|
|
|
OR with value specified by OrData. All other bits in Operand are
|
2007-06-22 05:21:45 +02:00
|
|
|
preserved. The new 16-bit value is returned.
|
|
|
|
|
|
|
|
If 16-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 15, then ASSERT().
|
|
|
|
If EndBit is greater than 15, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
|
|
|
If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..15.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..15.
|
|
|
|
@param AndData The value to AND with the read value from the value.
|
|
|
|
@param OrData The value to OR with the result of the AND operation.
|
|
|
|
|
|
|
|
@return The new 16-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT16
|
|
|
|
EFIAPI
|
|
|
|
BitFieldAndThenOr16 (
|
|
|
|
IN UINT16 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT16 AndData,
|
|
|
|
IN UINT16 OrData
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 16);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
|
|
|
return BitFieldOr16 (
|
|
|
|
BitFieldAnd16 (Operand, StartBit, EndBit, AndData),
|
|
|
|
StartBit,
|
|
|
|
EndBit,
|
|
|
|
OrData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a bit field from a 32-bit value.
|
|
|
|
|
|
|
|
Returns the bitfield specified by the StartBit and the EndBit from Operand.
|
|
|
|
|
|
|
|
If 32-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 31, then ASSERT().
|
|
|
|
If EndBit is greater than 31, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..31.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..31.
|
|
|
|
|
|
|
|
@return The bit field read.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
EFIAPI
|
|
|
|
BitFieldRead32 (
|
|
|
|
IN UINT32 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 32);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2009-07-23 03:43:04 +02:00
|
|
|
return (UINT32)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBit);
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Writes a bit field to a 32-bit value, and returns the result.
|
|
|
|
|
|
|
|
Writes Value to the bit field specified by the StartBit and the EndBit in
|
|
|
|
Operand. All other bits in Operand are preserved. The new 32-bit value is
|
|
|
|
returned.
|
|
|
|
|
|
|
|
If 32-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 31, then ASSERT().
|
|
|
|
If EndBit is greater than 31, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..31.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..31.
|
2010-06-25 23:56:02 +02:00
|
|
|
@param Value The new value of the bit field.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new 32-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
EFIAPI
|
|
|
|
BitFieldWrite32 (
|
|
|
|
IN UINT32 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT32 Value
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 32);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
|
|
|
return BitFieldAndThenOr32 (Operand, StartBit, EndBit, 0, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
|
|
|
|
result.
|
|
|
|
|
2008-12-05 10:50:02 +01:00
|
|
|
Performs a bitwise OR between the bit field specified by StartBit
|
2007-06-22 05:21:45 +02:00
|
|
|
and EndBit in Operand and the value specified by OrData. All other bits in
|
|
|
|
Operand are preserved. The new 32-bit value is returned.
|
|
|
|
|
|
|
|
If 32-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 31, then ASSERT().
|
|
|
|
If EndBit is greater than 31, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..31.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..31.
|
2010-06-24 02:20:35 +02:00
|
|
|
@param OrData The value to OR with the read value from the value.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new 32-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
EFIAPI
|
|
|
|
BitFieldOr32 (
|
|
|
|
IN UINT32 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT32 OrData
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 32);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2009-07-23 03:43:04 +02:00
|
|
|
return (UINT32)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit, OrData);
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from a 32-bit value, 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 32-bit value is returned.
|
|
|
|
|
|
|
|
If 32-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 31, then ASSERT().
|
|
|
|
If EndBit is greater than 31, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..31.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..31.
|
2010-06-24 02:20:35 +02:00
|
|
|
@param AndData The value to AND with the read value from the value.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new 32-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
EFIAPI
|
|
|
|
BitFieldAnd32 (
|
|
|
|
IN UINT32 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT32 AndData
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 32);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2009-07-23 03:43:04 +02:00
|
|
|
return (UINT32)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit, AndData);
|
2007-06-22 05:21:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
|
|
|
|
bitwise OR, and returns the result.
|
|
|
|
|
|
|
|
Performs a bitwise AND between the bit field specified by StartBit and EndBit
|
2008-12-05 10:50:02 +01:00
|
|
|
in Operand and the value specified by AndData, followed by a bitwise
|
|
|
|
OR with value specified by OrData. All other bits in Operand are
|
2007-06-22 05:21:45 +02:00
|
|
|
preserved. The new 32-bit value is returned.
|
|
|
|
|
|
|
|
If 32-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 31, then ASSERT().
|
|
|
|
If EndBit is greater than 31, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
|
|
|
If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..31.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..31.
|
|
|
|
@param AndData The value to AND with the read value from the value.
|
|
|
|
@param OrData The value to OR with the result of the AND operation.
|
|
|
|
|
|
|
|
@return The new 32-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
EFIAPI
|
|
|
|
BitFieldAndThenOr32 (
|
|
|
|
IN UINT32 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT32 AndData,
|
|
|
|
IN UINT32 OrData
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 32);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
|
|
|
return BitFieldOr32 (
|
|
|
|
BitFieldAnd32 (Operand, StartBit, EndBit, AndData),
|
|
|
|
StartBit,
|
|
|
|
EndBit,
|
|
|
|
OrData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a bit field from a 64-bit value.
|
|
|
|
|
|
|
|
Returns the bitfield specified by the StartBit and the EndBit from Operand.
|
|
|
|
|
|
|
|
If 64-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 63, then ASSERT().
|
|
|
|
If EndBit is greater than 63, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..63.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..63.
|
|
|
|
|
|
|
|
@return The bit field read.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT64
|
|
|
|
EFIAPI
|
|
|
|
BitFieldRead64 (
|
|
|
|
IN UINT64 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 64);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
|
|
|
return RShiftU64 (Operand & ~LShiftU64 ((UINT64)-2, EndBit), StartBit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Writes a bit field to a 64-bit value, and returns the result.
|
|
|
|
|
|
|
|
Writes Value to the bit field specified by the StartBit and the EndBit in
|
|
|
|
Operand. All other bits in Operand are preserved. The new 64-bit value is
|
|
|
|
returned.
|
|
|
|
|
|
|
|
If 64-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 63, then ASSERT().
|
|
|
|
If EndBit is greater than 63, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..63.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..63.
|
2010-06-25 23:56:02 +02:00
|
|
|
@param Value The new value of the bit field.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new 64-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT64
|
|
|
|
EFIAPI
|
|
|
|
BitFieldWrite64 (
|
|
|
|
IN UINT64 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT64 Value
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 64);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
|
|
|
return BitFieldAndThenOr64 (Operand, StartBit, EndBit, 0, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
|
|
|
|
result.
|
|
|
|
|
2008-12-05 10:50:02 +01:00
|
|
|
Performs a bitwise OR between the bit field specified by StartBit
|
2007-06-22 05:21:45 +02:00
|
|
|
and EndBit in Operand and the value specified by OrData. All other bits in
|
|
|
|
Operand are preserved. The new 64-bit value is returned.
|
|
|
|
|
|
|
|
If 64-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 63, then ASSERT().
|
|
|
|
If EndBit is greater than 63, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..63.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..63.
|
|
|
|
@param OrData The value to OR with the read value from the value
|
|
|
|
|
|
|
|
@return The new 64-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT64
|
|
|
|
EFIAPI
|
|
|
|
BitFieldOr64 (
|
|
|
|
IN UINT64 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT64 OrData
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT64 Value1;
|
|
|
|
UINT64 Value2;
|
|
|
|
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 64);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2013-07-22 08:35:48 +02:00
|
|
|
//
|
|
|
|
// Higher bits in OrData those are not used must be zero.
|
|
|
|
//
|
2013-07-22 08:41:52 +02:00
|
|
|
// EndBit - StartBit + 1 might be 64 while the result right shifting 64 on RShiftU64() API is invalid,
|
|
|
|
// So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
|
2013-07-22 08:35:48 +02:00
|
|
|
//
|
|
|
|
ASSERT (RShiftU64 (OrData, EndBit - StartBit) == (RShiftU64 (OrData, EndBit - StartBit) & 1));
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
Value1 = LShiftU64 (OrData, StartBit);
|
|
|
|
Value2 = LShiftU64 ((UINT64) - 2, EndBit);
|
|
|
|
|
|
|
|
return Operand | (Value1 & ~Value2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from a 64-bit value, 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 64-bit value is returned.
|
|
|
|
|
|
|
|
If 64-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 63, then ASSERT().
|
|
|
|
If EndBit is greater than 63, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..63.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..63.
|
2010-06-24 02:20:35 +02:00
|
|
|
@param AndData The value to AND with the read value from the value.
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@return The new 64-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT64
|
|
|
|
EFIAPI
|
|
|
|
BitFieldAnd64 (
|
|
|
|
IN UINT64 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT64 AndData
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT64 Value1;
|
|
|
|
UINT64 Value2;
|
|
|
|
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 64);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
2013-07-22 08:35:48 +02:00
|
|
|
//
|
|
|
|
// Higher bits in AndData those are not used must be zero.
|
|
|
|
//
|
2013-07-22 08:41:52 +02:00
|
|
|
// EndBit - StartBit + 1 might be 64 while the right shifting 64 on RShiftU64() API is invalid,
|
|
|
|
// So the logic is updated to right shift (EndBit - StartBit) bits and compare the last bit directly.
|
2013-07-22 08:35:48 +02:00
|
|
|
//
|
|
|
|
ASSERT (RShiftU64 (AndData, EndBit - StartBit) == (RShiftU64 (AndData, EndBit - StartBit) & 1));
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
Value1 = LShiftU64 (~AndData, StartBit);
|
|
|
|
Value2 = LShiftU64 ((UINT64)-2, EndBit);
|
|
|
|
|
|
|
|
return Operand & ~(Value1 & ~Value2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
|
|
|
|
bitwise OR, and returns the result.
|
|
|
|
|
|
|
|
Performs a bitwise AND between the bit field specified by StartBit and EndBit
|
2008-12-05 10:50:02 +01:00
|
|
|
in Operand and the value specified by AndData, followed by a bitwise
|
|
|
|
OR with value specified by OrData. All other bits in Operand are
|
2007-06-22 05:21:45 +02:00
|
|
|
preserved. The new 64-bit value is returned.
|
|
|
|
|
|
|
|
If 64-bit operations are not supported, then ASSERT().
|
|
|
|
If StartBit is greater than 63, then ASSERT().
|
|
|
|
If EndBit is greater than 63, then ASSERT().
|
|
|
|
If EndBit is less than StartBit, then ASSERT().
|
2012-12-25 03:25:50 +01:00
|
|
|
If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
|
|
|
If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
|
2007-06-22 05:21:45 +02:00
|
|
|
|
|
|
|
@param Operand Operand on which to perform the bitfield operation.
|
|
|
|
@param StartBit The ordinal of the least significant bit in the bit field.
|
|
|
|
Range 0..63.
|
|
|
|
@param EndBit The ordinal of the most significant bit in the bit field.
|
|
|
|
Range 0..63.
|
|
|
|
@param AndData The value to AND with the read value from the value.
|
|
|
|
@param OrData The value to OR with the result of the AND operation.
|
|
|
|
|
|
|
|
@return The new 64-bit value.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT64
|
|
|
|
EFIAPI
|
|
|
|
BitFieldAndThenOr64 (
|
|
|
|
IN UINT64 Operand,
|
|
|
|
IN UINTN StartBit,
|
|
|
|
IN UINTN EndBit,
|
|
|
|
IN UINT64 AndData,
|
|
|
|
IN UINT64 OrData
|
|
|
|
)
|
|
|
|
{
|
2008-09-24 07:30:40 +02:00
|
|
|
ASSERT (EndBit < 64);
|
2007-06-22 05:21:45 +02:00
|
|
|
ASSERT (StartBit <= EndBit);
|
|
|
|
return BitFieldOr64 (
|
|
|
|
BitFieldAnd64 (Operand, StartBit, EndBit, AndData),
|
|
|
|
StartBit,
|
|
|
|
EndBit,
|
|
|
|
OrData
|
|
|
|
);
|
|
|
|
}
|