Esempio n. 1
0
UINT64
DtResolveLabel (
    char                    *LabelString)
{
    DT_FIELD                *LabelField;


    DbgPrint (ASL_DEBUG_OUTPUT, "Resolve Label: %s\n", LabelString);

    /* Resolve a label reference to an integer (table offset) */

    if (*LabelString != '$')
    {
        return (0);
    }

    LabelField = DtLookupLabel (LabelString);
    if (!LabelField)
    {
        DtError (ASL_ERROR, ASL_MSG_UNKNOWN_LABEL,
            Gbl_CurrentField, LabelString);
        return (0);
    }

    /* All we need from the label is the offset in the table */

    DbgPrint (ASL_DEBUG_OUTPUT, "Resolved Label: 0x%8.8X\n",
        LabelField->TableOffset);

    return (LabelField->TableOffset);
}
Esempio n. 2
0
UINT32
DtCompileBuffer (
    UINT8                   *Buffer,
    char                    *StringValue,
    DT_FIELD                *Field,
    UINT32                  ByteLength)
{
    char                    *Substring;
    ACPI_STATUS             Status;
    UINT32                  Count;
    UINT32                  i;


    /* Allow several different types of value separators */

    StringValue = DtNormalizeBuffer (StringValue, &Count);
    Substring = StringValue;

    /* Each element of StringValue is now three chars (2 hex + 1 space) */

    for (i = 0; i < Count; i++, Substring += 3)
    {
        /* Check for byte value too long */

        if (*(&Substring[2]) &&
           (*(&Substring[2]) != ' '))
        {
            DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, Substring);
            goto Exit;
        }

        /* Convert two ASCII characters to one hex byte */

        Status = AcpiUtAsciiToHexByte (Substring, &Buffer[i]);
        if (ACPI_FAILURE (Status))
        {
            DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, Substring);
            goto Exit;
        }
    }

Exit:
    ACPI_FREE (StringValue);
    return (ByteLength - Count);
}
Esempio n. 3
0
void
DtFatal (
    UINT8                   MessageId,
    DT_FIELD                *FieldObject,
    char                    *ExtraMessage)
{

    DtError (ASL_ERROR, MessageId, FieldObject, ExtraMessage);

    CmCleanupAndExit ();
    exit (1);
}
Esempio n. 4
0
UINT32
DtCompileBuffer (
    UINT8                   *Buffer,
    char                    *StringValue,
    DT_FIELD                *Field,
    UINT32                  ByteLength)
{
    ACPI_STATUS             Status;
    char                    Hex[3];
    UINT64                  Value;
    UINT32                  i;
    UINT32                  Count;


    /* Allow several different types of value separators */

    StringValue = DtNormalizeBuffer (StringValue, &Count);

    Hex[2] = 0;
    for (i = 0; i < Count; i++)
    {
        /* Each element of StringValue is three chars */

        Hex[0] = StringValue[(3 * i)];
        Hex[1] = StringValue[(3 * i) + 1];

        /* Convert one hex byte */

        Value = 0;
        Status = DtStrtoul64 (Hex, &Value);
        if (ACPI_FAILURE (Status))
        {
            DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, MsgBuffer);
            goto Exit;
        }

        Buffer[i] = (UINT8) Value;
    }

Exit:
    ACPI_FREE (StringValue);
    return (ByteLength - Count);
}
Esempio n. 5
0
void
DtFatal (
    UINT16                  MessageId,
    DT_FIELD                *FieldObject,
    char                    *ExtraMessage)
{

    DtError (ASL_ERROR, MessageId, FieldObject, ExtraMessage);

/*
 * TBD: remove this entire function, DtFatal
 *
 * We cannot abort the compiler on error, because we may be compiling a
 * list of files. We must move on to the next file.
 */
#ifdef __OBSOLETE
    CmCleanupAndExit ();
    exit (1);
#endif
}
Esempio n. 6
0
static void
DtCompileString (
    UINT8                   *Buffer,
    DT_FIELD                *Field,
    UINT32                  ByteLength)
{
    UINT32                  Length;


    Length = ACPI_STRLEN (Field->Value);

    /* Check if the string is too long for the field */

    if (Length > ByteLength)
    {
        sprintf (MsgBuffer, "Maximum %u characters", ByteLength);
        DtError (ASL_ERROR, ASL_MSG_STRING_LENGTH, Field, MsgBuffer);
        Length = ByteLength;
    }

    ACPI_MEMCPY (Buffer, Field->Value, Length);
}
Esempio n. 7
0
ACPI_STATUS
DtDoCompile (
    void)
{
    ACPI_STATUS             Status;
    UINT8                   Event;
    DT_FIELD                *FieldList;


    /* Initialize globals */

    Status = DtInitialize ();
    if (ACPI_FAILURE (Status))
    {
        printf ("Error during compiler initialization, 0x%X\n", Status);
        return (Status);
    }

    /* Preprocessor */

    Event = UtBeginEvent ("Preprocess input file");
    PrDoPreprocess ();
    UtEndEvent (Event);

    if (Gbl_PreprocessOnly)
    {
        return (AE_OK);
    }

    /*
     * Scan the input file (file is already open) and
     * build the parse tree
     */
    Event = UtBeginEvent ("Scan and parse input file");
    FieldList = DtScanFile (Gbl_Files[ASL_FILE_INPUT].Handle);
    UtEndEvent (Event);

    /* Did the parse tree get successfully constructed? */

    if (!FieldList)
    {
        /* TBD: temporary error message. Msgs should come from function above */

        DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
            "Input file does not appear to be an ASL or data table source file");

        Status = AE_ERROR;
        goto CleanupAndExit;
    }

    Event = UtBeginEvent ("Compile parse tree");

    /*
     * Compile the parse tree
     */
    Status = DtCompileDataTable (&FieldList);
    UtEndEvent (Event);

    DtFreeFieldList ();

    if (ACPI_FAILURE (Status))
    {
        /* TBD: temporary error message. Msgs should come from function above */

        DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL,
            "Could not compile input file");

        goto CleanupAndExit;
    }

    /* Create/open the binary output file */

    Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL;
    Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix);
    if (ACPI_FAILURE (Status))
    {
        goto CleanupAndExit;
    }

    /* Write the binary, then the optional hex file */

    DtOutputBinary (Gbl_RootTable);
    HxDoHexOutput ();
    DtWriteTableToListing ();

CleanupAndExit:

    CmCleanupAndExit ();
    return (Status);
}
Esempio n. 8
0
ACPI_STATUS
DtCompileFadt (
    void                    **List)
{
    ACPI_STATUS             Status;
    DT_SUBTABLE             *Subtable;
    DT_SUBTABLE             *ParentTable;
    DT_FIELD                **PFieldList = (DT_FIELD **) List;
    ACPI_TABLE_HEADER       *Table;
    UINT8                   FadtRevision;
    UINT32                  i;


    /* Minimum table is the FADT version 1 (ACPI 1.0) */

    Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt1,
        &Subtable, TRUE);
    if (ACPI_FAILURE (Status))
    {
        return (Status);
    }

    ParentTable = DtPeekSubtable ();
    DtInsertSubtable (ParentTable, Subtable);

    Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, ParentTable->Buffer);
    FadtRevision = Table->Revision;

    /* Revision 0 and 2 are illegal */

    if ((FadtRevision == 0) ||
        (FadtRevision == 2))
    {
        DtError (ASL_ERROR, 0, NULL,
            "Invalid value for FADT revision");

        return (AE_BAD_VALUE);
    }

    /* Revision out of supported range? */

    if (FadtRevision > ACPI_FADT_MAX_VERSION)
    {
        DtError (ASL_ERROR, 0, NULL,
            "Unknown or unsupported value for FADT revision");

        return (AE_BAD_VALUE);
    }

    /* Compile individual sub-parts of the FADT, per-revision */

    for (i = 3; i <= ACPI_FADT_MAX_VERSION; i++)
    {
        if (i > FadtRevision)
        {
            break;
        }

        /* Compile the fields specific to this FADT revision */

        Status = DtCompileTable (PFieldList, FadtRevisionInfo[i],
            &Subtable, TRUE);
        if (ACPI_FAILURE (Status))
        {
            return (Status);
        }

        DtInsertSubtable (ParentTable, Subtable);
    }

    return (AE_OK);
}
Esempio n. 9
0
UINT64
DtDoOperator (
    UINT64                  LeftValue,
    UINT32                  Operator,
    UINT64                  RightValue)
{
    UINT64                  Result;


    /* Perform the requested operation */

    switch (Operator)
    {
    case EXPOP_ONES_COMPLIMENT:

        Result = ~RightValue;
        break;

    case EXPOP_LOGICAL_NOT:

        Result = !RightValue;
        break;

    case EXPOP_MULTIPLY:

        Result = LeftValue * RightValue;
        break;

    case EXPOP_DIVIDE:

        if (!RightValue)
        {
            DtError (ASL_ERROR, ASL_MSG_DIVIDE_BY_ZERO,
                Gbl_CurrentField, NULL);
            return (0);
        }
        Result = LeftValue / RightValue;
        break;

    case EXPOP_MODULO:

        if (!RightValue)
        {
            DtError (ASL_ERROR, ASL_MSG_DIVIDE_BY_ZERO,
                Gbl_CurrentField, NULL);
            return (0);
        }
        Result = LeftValue % RightValue;
        break;

    case EXPOP_ADD:
        Result = LeftValue + RightValue;
        break;

    case EXPOP_SUBTRACT:

        Result = LeftValue - RightValue;
        break;

    case EXPOP_SHIFT_RIGHT:

        Result = LeftValue >> RightValue;
        break;

    case EXPOP_SHIFT_LEFT:

        Result = LeftValue << RightValue;
        break;

    case EXPOP_LESS:

        Result = LeftValue < RightValue;
        break;

    case EXPOP_GREATER:

        Result = LeftValue > RightValue;
        break;

    case EXPOP_LESS_EQUAL:

        Result = LeftValue <= RightValue;
        break;

    case EXPOP_GREATER_EQUAL:

        Result = LeftValue >= RightValue;
        break;

    case EXPOP_EQUAL:

        Result = LeftValue == RightValue;
        break;

    case EXPOP_NOT_EQUAL:

        Result = LeftValue != RightValue;
        break;

    case EXPOP_AND:

        Result = LeftValue & RightValue;
        break;

    case EXPOP_XOR:

        Result = LeftValue ^ RightValue;
        break;

    case EXPOP_OR:

        Result = LeftValue | RightValue;
        break;

    case EXPOP_LOGICAL_AND:

        Result = LeftValue && RightValue;
        break;

    case EXPOP_LOGICAL_OR:

        Result = LeftValue || RightValue;
        break;

   default:

        /* Unknown operator */

        DtFatal (ASL_MSG_INVALID_EXPRESSION,
            Gbl_CurrentField, NULL);
        return (0);
    }

    DbgPrint (ASL_DEBUG_OUTPUT,
        "IntegerEval: (%8.8X%8.8X %s %8.8X%8.8X) = %8.8X%8.8X\n",
        ACPI_FORMAT_UINT64 (LeftValue),
        DtGetOpName (Operator),
        ACPI_FORMAT_UINT64 (RightValue),
        ACPI_FORMAT_UINT64 (Result));

    return (Result);
}
Esempio n. 10
0
void
DtCompileFlag (
    UINT8                   *Buffer,
    DT_FIELD                *Field,
    ACPI_DMTABLE_INFO       *Info)
{
    UINT64                  Value = 0;
    UINT32                  BitLength = 1;
    UINT8                   BitPosition = 0;
    ACPI_STATUS             Status;


    Status = DtStrtoul64 (Field->Value, &Value);
    if (ACPI_FAILURE (Status))
    {
        DtError (ASL_ERROR, ASL_MSG_INVALID_HEX_INTEGER, Field, NULL);
    }

    switch (Info->Opcode)
    {
    case ACPI_DMT_FLAG0:
    case ACPI_DMT_FLAG1:
    case ACPI_DMT_FLAG2:
    case ACPI_DMT_FLAG3:
    case ACPI_DMT_FLAG4:
    case ACPI_DMT_FLAG5:
    case ACPI_DMT_FLAG6:
    case ACPI_DMT_FLAG7:

        BitPosition = Info->Opcode;
        BitLength = 1;
        break;

    case ACPI_DMT_FLAGS0:

        BitPosition = 0;
        BitLength = 2;
        break;


    case ACPI_DMT_FLAGS1:

        BitPosition = 1;
        BitLength = 2;
        break;


    case ACPI_DMT_FLAGS2:

        BitPosition = 2;
        BitLength = 2;
        break;

    case ACPI_DMT_FLAGS4:

        BitPosition = 4;
        BitLength = 2;
        break;

    default:

        DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid flag opcode");
        break;
    }

    /* Check range of the input flag value */

    if (Value >= ((UINT64) 1 << BitLength))
    {
        sprintf (MsgBuffer, "Maximum %u bit", BitLength);
        DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, MsgBuffer);
        Value = 0;
    }

    *Buffer |= (UINT8) (Value << BitPosition);
}
Esempio n. 11
0
void
DtCompileInteger (
    UINT8                   *Buffer,
    DT_FIELD                *Field,
    UINT32                  ByteLength,
    UINT8                   Flags)
{
    UINT64                  Value;
    UINT64                  MaxValue;
    ACPI_STATUS             Status;


    /* Output buffer byte length must be in range 1-8 */

    if ((ByteLength > 8) || (ByteLength == 0))
    {
        DtFatal (ASL_MSG_COMPILER_INTERNAL, Field,
            "Invalid internal Byte length");
        return;
    }

    /* Resolve integer expression to a single integer value */

    Status = DtResolveIntegerExpression (Field, &Value);
    if (ACPI_FAILURE (Status))
    {
        return;
    }

    /*
     * 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" */

    if (!ACPI_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;
        }
    }

    /* Check if the value must be non-zero */

    else if ((Flags & DT_NON_ZERO) && (Value == 0))
    {
        DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, Field, NULL);
    }

    /*
     * Generate the maximum value for the data type (ByteLength)
     * Note: construct chosen for maximum portability
     */
    MaxValue = ((UINT64) (-1)) >> (64 - (ByteLength * 8));

    /* Validate that the input value is within range of the target */

    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);
    }

    ACPI_MEMCPY (Buffer, &Value, ByteLength);
    return;
}
Esempio n. 12
0
void
DtCompileFlag (
    UINT8                   *Buffer,
    DT_FIELD                *Field,
    ACPI_DMTABLE_INFO       *Info)
{
    UINT64                  Value = 0;
    UINT32                  BitLength = 1;
    UINT8                   BitPosition = 0;


    Value = AcpiUtImplicitStrtoul64 (Field->Value);

    switch (Info->Opcode)
    {
    case ACPI_DMT_FLAG0:
    case ACPI_DMT_FLAG1:
    case ACPI_DMT_FLAG2:
    case ACPI_DMT_FLAG3:
    case ACPI_DMT_FLAG4:
    case ACPI_DMT_FLAG5:
    case ACPI_DMT_FLAG6:
    case ACPI_DMT_FLAG7:

        BitPosition = Info->Opcode;
        BitLength = 1;
        break;

    case ACPI_DMT_FLAGS0:

        BitPosition = 0;
        BitLength = 2;
        break;


    case ACPI_DMT_FLAGS1:

        BitPosition = 1;
        BitLength = 2;
        break;


    case ACPI_DMT_FLAGS2:

        BitPosition = 2;
        BitLength = 2;
        break;

    case ACPI_DMT_FLAGS4:

        BitPosition = 4;
        BitLength = 2;
        break;

    case ACPI_DMT_FLAGS4_0:

        BitPosition = 0;
        BitLength = 4;
        break;

    case ACPI_DMT_FLAGS4_4:

        BitPosition = 4;
        BitLength = 4;
        break;

    case ACPI_DMT_FLAGS4_8:

        BitPosition = 8;
        BitLength = 4;
        break;

    case ACPI_DMT_FLAGS4_12:

        BitPosition = 12;
        BitLength = 4;
        break;

    case ACPI_DMT_FLAGS16_16:

        BitPosition = 16;
        BitLength = 16;
        break;

    default:

        DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid flag opcode");
        break;
    }

    /* Check range of the input flag value */

    if (Value >= ((UINT64) 1 << BitLength))
    {
        sprintf (AslGbl_MsgBuffer, "Maximum %u bit", BitLength);
        DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, AslGbl_MsgBuffer);
        Value = 0;
    }

    *Buffer |= (UINT8) (Value << BitPosition);
}
Esempio n. 13
0
void
DtCompileInteger (
    UINT8                   *Buffer,
    DT_FIELD                *Field,
    UINT32                  ByteLength,
    UINT8                   Flags)
{
    UINT64                  Value;
    UINT64                  MaxValue;
    ACPI_STATUS             Status;


    /* Output buffer byte length must be in range 1-8 */

    if ((ByteLength > 8) || (ByteLength == 0))
    {
        DtFatal (ASL_MSG_COMPILER_INTERNAL, Field,
            "Invalid internal Byte length");
        return;
    }

    /* Resolve integer expression to a single integer value */

    Status = DtResolveIntegerExpression (Field, &Value);
    if (ACPI_FAILURE (Status))
    {
        return;
    }

    /* Ensure that reserved fields are set to zero */
    /* TBD: should we set to zero, or just make this an ERROR? */
    /* TBD: Probably better to use a flag */

    if (!ACPI_STRCMP (Field->Name, "Reserved") &&
        (Value != 0))
    {
        DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field,
            "Setting to zero");
        Value = 0;
    }

    /* Check if the value must be non-zero */

    if ((Value == 0) && (Flags & DT_NON_ZERO))
    {
        DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, Field, NULL);
    }

    /*
     * Generate the maximum value for the data type (ByteLength)
     * Note: construct chosen for maximum portability
     */
    MaxValue = ((UINT64) (-1)) >> (64 - (ByteLength * 8));

    /* Validate that the input value is within range of the target */

    if (Value > MaxValue)
    {
        snprintf (MsgBuffer, sizeof(MsgBuffer), "%8.8X%8.8X - max %u bytes",
            ACPI_FORMAT_UINT64 (Value), ByteLength);
        DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer);
    }

    ACPI_MEMCPY (Buffer, &Value, ByteLength);
    return;
}