FreeBSD/sys/contrib/dev/acpica/compiler/dtfield.c
/******************************************************************************
 *
 * FUNCTION:    DtCompileInteger
 *
 * PARAMETERS:  Buffer              - Output buffer
 *              Field               - Field obj with Integer to be compiled
 *              ByteLength          - Byte length of the integer
 *              Flags               - Additional compile info
 *
 * RETURN:      None
 *
 * DESCRIPTION: Compile an integer. Supports integer expressions with C-style
 *              operators.
 *
 *****************************************************************************/
DtCompileInteger
PARAMETERS:  Buffer              - Output buffer
Field               - Field obj with Integer to be compiled
ByteLength          - Byte length of the integer
Flags               - Additional compile info

None

Compile an integer. Supports integer expressions with C-style
operators.
DtCompileInteger PARAMETERS : Buffer - Output buffer Field - Field obj with Integer to be compiled ByteLength - Byte length of the integer Flags - Additional compile info None Compile an integer . Supports integer expressions with C - style operators .
void
DtCompileInteger (
    UINT8                   *Buffer,
    DT_FIELD                *Field,
    UINT32                  ByteLength,
    UINT8                   Flags)
{
    UINT64                  Value;
    UINT64                  MaxValue;
    ACPI_STATUS             Status;
    if ((ByteLength > 8) || (ByteLength == 0))
    {
        DtFatal (ASL_MSG_COMPILER_INTERNAL, Field,
            "Invalid internal Byte length");
        return;
    }
    Status = DtResolveIntegerExpression (Field, &Value);
    if (ACPI_FAILURE (Status))
    {
        return;
    }
    if (!strcmp (Field->Name, "Reserved"))
    {
        if (Flags & DT_NON_ZERO)
        {
            if (Value != 1)
            {
                DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field,
                    "Must be one, setting to one");
                Value = 1;
            }
        }
        else if (Value != 0)
        {
            DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field,
                "Must be zero, setting to zero");
            Value = 0;
        }
    }
    else if ((Flags & DT_NON_ZERO) && (Value == 0))
    {
        DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, Field, NULL);
    }
    MaxValue = ((UINT64) (-1)) >> (64 - (ByteLength * 8));
    if (Value > MaxValue)
    {
        sprintf (MsgBuffer, "%8.8X%8.8X - max %u bytes",
            ACPI_FORMAT_UINT64 (Value), ByteLength);
        DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer);
    }
    memcpy (Buffer, &Value, ByteLength);
    return;
}
void DtCompileInteger ( UINT8 * Buffer , DT_FIELD * Field , UINT32 ByteLength , UINT8 Flags ) { UINT64 Value ; UINT64 MaxValue ; ACPI_STATUS Status ; if ( ( ByteLength > 8 ) || ( ByteLength == 0 ) ) { DtFatal ( ASL_MSG_COMPILER_INTERNAL , Field , " " ) ; return ; } Status = DtResolveIntegerExpression ( Field , & Value ) ; if ( ACPI_FAILURE ( Status ) ) { return ; } if ( ! strcmp ( Field -> Name , " " ) ) { if ( Flags & DT_NON_ZERO ) { if ( Value != 1 ) { DtError ( ASL_WARNING , ASL_MSG_RESERVED_VALUE , Field , " " ) ; Value = 1 ; } } else if ( Value != 0 ) { DtError ( ASL_WARNING , ASL_MSG_RESERVED_VALUE , Field , " " ) ; Value = 0 ; } } else if ( ( Flags & DT_NON_ZERO ) && ( Value == 0 ) ) { DtError ( ASL_ERROR , ASL_MSG_ZERO_VALUE , Field , NULL ) ; } MaxValue = ( ( UINT64 ) ( -1 ) ) >> ( 64 - ( ByteLength * 8 ) ) ; if ( Value > MaxValue ) { sprintf ( MsgBuffer , " " , ACPI_FORMAT_UINT64 ( Value ) , ByteLength ) ; DtError ( ASL_ERROR , ASL_MSG_INTEGER_SIZE , Field , MsgBuffer ) ; } memcpy ( Buffer , & Value , ByteLength ) ; return ; }
FUNCTION:    DtCompileInteger
 PARAMETERS:  Buffer              - Output buffer
              Field               - Field obj with Integer to be compiled
              ByteLength          - Byte length of the integer
              Flags               - Additional compile info
FUNCTION : DtCompileInteger PARAMETERS : Buffer - Output buffer Field - Field obj with Integer to be compiled ByteLength - Byte length of the integer Flags - Additional compile info
/* Output buffer byte length must be in range 1-8 */ /* Resolve integer expression to a single integer value */ /*
     * Ensure that reserved fields are set properly. Note: uses
     * the DT_NON_ZERO flag to indicate that the reserved value
     * must be exactly one. Otherwise, the value must be zero.
     * This is sufficient for now.
     */ /* TBD: Should use a flag rather than compare "Reserved" */ /* Check if the value must be non-zero */ /*
     * Generate the maximum value for the data type (ByteLength)
     * Note: construct chosen for maximum portability
     */ /* Validate that the input value is within range of the target */